Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit df9e539

Browse files
committed
1. Run all pg_dump queries in single serializable transaction.
2. Get rid of locking when updating statistics in vacuum. 3. Use QuerySnapshot in COPY TO and call SetQuerySnashot in main tcop loop before FETCH and COPY TO.
1 parent bbbc211 commit df9e539

File tree

4 files changed

+42
-144
lines changed

4 files changed

+42
-144
lines changed

src/backend/commands/copy.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
*
88
* IDENTIFICATION
9-
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.78 1999/05/26 12:55:10 momjian Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.79 1999/05/29 10:25:29 vadim Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -381,7 +381,7 @@ CopyTo(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
381381
int32 ntuples;
382382
TupleDesc tupDesc;
383383

384-
scandesc = heap_beginscan(rel, 0, SnapshotNow, 0, NULL);
384+
scandesc = heap_beginscan(rel, 0, QuerySnapshot, 0, NULL);
385385

386386
attr_count = rel->rd_att->natts;
387387
attr = rel->rd_att->attrs;
@@ -1363,7 +1363,7 @@ CountTuples(Relation relation)
13631363

13641364
int i;
13651365

1366-
scandesc = heap_beginscan(relation, 0, SnapshotNow, 0, NULL);
1366+
scandesc = heap_beginscan(relation, 0, QuerySnapshot, 0, NULL);
13671367

13681368
i = 0;
13691369
while (HeapTupleIsValid(tuple = heap_getnext(scandesc, 0)))

src/backend/commands/vacuum.c

+5-19
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.104 1999/05/25 16:08:27 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.105 1999/05/29 10:25:30 vadim Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -93,7 +93,6 @@ static void vc_attrstats(Relation onerel, VRelStats *vacrelstats, HeapTuple tupl
9393
static void vc_bucketcpy(Form_pg_attribute attr, Datum value, Datum *bucket, int16 *bucket_len);
9494
static void vc_updstats(Oid relid, int num_pages, int num_tuples, bool hasindex, VRelStats *vacrelstats);
9595
static void vc_delhilowstats(Oid relid, int attcnt, int *attnums);
96-
static void vc_setpagelock(Relation rel, BlockNumber blkno);
9796
static VPageDescr vc_tidreapped(ItemPointer itemptr, VPageList vpl);
9897
static void vc_reappage(VPageList vpl, VPageDescr vpc);
9998
static void vc_vpinsert(VPageList vpl, VPageDescr vpnew);
@@ -2221,7 +2220,8 @@ vc_bucketcpy(Form_pg_attribute attr, Datum value, Datum *bucket, int16 *bucket_l
22212220
* tuple that's already on the page. The reason for this is that if
22222221
* we updated these tuples in the usual way, then every tuple in pg_class
22232222
* would be replaced every day. This would make planning and executing
2224-
* historical queries very expensive.
2223+
* historical queries very expensive. Note that we also don't use
2224+
* any locking while doing updation.
22252225
*/
22262226
static void
22272227
vc_updstats(Oid relid, int num_pages, int num_tuples, bool hasindex, VRelStats *vacrelstats)
@@ -2257,7 +2257,6 @@ vc_updstats(Oid relid, int num_pages, int num_tuples, bool hasindex, VRelStats *
22572257
pfree(ctup);
22582258

22592259
/* overwrite the existing statistics in the tuple */
2260-
vc_setpagelock(rd, ItemPointerGetBlockNumber(&(rtup.t_self)));
22612260
pgcform = (Form_pg_class) GETSTRUCT(&rtup);
22622261
pgcform->reltuples = num_tuples;
22632262
pgcform->relpages = num_pages;
@@ -2301,11 +2300,6 @@ vc_updstats(Oid relid, int num_pages, int num_tuples, bool hasindex, VRelStats *
23012300
/* overwrite the existing statistics in the tuple */
23022301
if (VacAttrStatsEqValid(stats))
23032302
{
2304-
Buffer abuffer = scan->rs_cbuf;
2305-
2306-
vc_setpagelock(ad, ItemPointerGetBlockNumber(&atup->t_self));
2307-
attp = (Form_pg_attribute) GETSTRUCT(atup);
2308-
23092303
if (stats->nonnull_cnt + stats->null_cnt == 0 ||
23102304
(stats->null_cnt <= 1 && stats->best_cnt == 1))
23112305
selratio = 0;
@@ -2338,7 +2332,7 @@ vc_updstats(Oid relid, int num_pages, int num_tuples, bool hasindex, VRelStats *
23382332
* Invalidate the cache for the tuple and write the buffer
23392333
*/
23402334
RelationInvalidateHeapTuple(ad, atup);
2341-
WriteNoReleaseBuffer(abuffer);
2335+
WriteNoReleaseBuffer(scan->rs_cbuf);
23422336

23432337
/* DO PG_STATISTIC INSERTS */
23442338

@@ -2396,9 +2390,7 @@ vc_updstats(Oid relid, int num_pages, int num_tuples, bool hasindex, VRelStats *
23962390
*/
23972391
RelationInvalidateHeapTuple(rd, &rtup);
23982392

2399-
WriteNoReleaseBuffer(buffer);
2400-
2401-
ReleaseBuffer(buffer);
2393+
WriteBuffer(buffer);
24022394

24032395
heap_close(rd);
24042396
}
@@ -2449,12 +2441,6 @@ vc_delhilowstats(Oid relid, int attcnt, int *attnums)
24492441
heap_close(pgstatistic);
24502442
}
24512443

2452-
static void
2453-
vc_setpagelock(Relation rel, BlockNumber blkno)
2454-
{
2455-
LockPage(rel, blkno, ExclusiveLock);
2456-
}
2457-
24582444
/*
24592445
* vc_reappage() -- save a page on the array of reapped pages.
24602446
*

src/backend/tcop/postgres.c

+11-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.117 1999/05/26 12:55:55 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.118 1999/05/29 10:25:30 vadim Exp $
1111
*
1212
* NOTES
1313
* this is the "main" module of the postgres backend and
@@ -73,6 +73,8 @@
7373
#include "utils/rel.h"
7474
#include "utils/ps_status.h"
7575
#include "utils/temprel.h"
76+
#include "nodes/parsenodes.h"
77+
#include "../backend/parser/parse.h"
7678

7779
#ifdef NOT_USED
7880
#include "nodes/relation.h"
@@ -715,6 +717,13 @@ pg_exec_query_dest(char *query_string, /* string to execute */
715717
else if (Verbose)
716718
TPRINTF(TRACE_VERBOSE, "ProcessUtility");
717719

720+
/*
721+
* We have to set query SnapShot in the case of FETCH or COPY TO.
722+
*/
723+
if (nodeTag(querytree->utilityStmt) == T_FetchStmt ||
724+
(nodeTag(querytree->utilityStmt) == T_CopyStmt &&
725+
((CopyStmt *)(querytree->utilityStmt))->direction != FROM))
726+
SetQuerySnapshot();
718727
ProcessUtility(querytree->utilityStmt, dest);
719728
}
720729
else
@@ -1527,7 +1536,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
15271536
if (!IsUnderPostmaster)
15281537
{
15291538
puts("\nPOSTGRES backend interactive interface ");
1530-
puts("$Revision: 1.117 $ $Date: 1999/05/26 12:55:55 $\n");
1539+
puts("$Revision: 1.118 $ $Date: 1999/05/29 10:25:30 $\n");
15311540
}
15321541

15331542
/* ----------------

0 commit comments

Comments
 (0)