diff options
author | Tom Lane | 2005-11-26 03:03:07 +0000 |
---|---|---|
committer | Tom Lane | 2005-11-26 03:03:07 +0000 |
commit | 70f1482de3dd797eeee6093210c716115c38795b (patch) | |
tree | 781172ccd2c151515682c6157a89758bee73d021 /src/include | |
parent | 290166f93404d8759f4bf60ef1732c8ba9a52785 (diff) |
Change seqscan logic so that we check visibility of all tuples on a page
when we first read the page, rather than checking them one at a time.
This allows us to take and release the buffer content lock just once
per page, instead of once per tuple. Since it's a shared lock the
contention penalty for holding the lock longer shouldn't be too bad.
We can safely do this only when using an MVCC snapshot; else the
assumption that visibility won't change over time is uncool. Therefore
there are now two code paths depending on the snapshot type. I also
made the same change in nodeBitmapHeapscan.c, where it can be done always
because we only support MVCC snapshots for bitmap scans anyway.
Also make some incidental cleanups in the APIs of these functions.
Per a suggestion from Qingqing Zhou.
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/access/relscan.h | 11 | ||||
-rw-r--r-- | src/include/access/valid.h | 35 | ||||
-rw-r--r-- | src/include/nodes/execnodes.h | 8 | ||||
-rw-r--r-- | src/include/utils/tqual.h | 16 |
4 files changed, 25 insertions, 45 deletions
diff --git a/src/include/access/relscan.h b/src/include/access/relscan.h index 88f4078d24b..c0b7c92cd53 100644 --- a/src/include/access/relscan.h +++ b/src/include/access/relscan.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/access/relscan.h,v 1.41 2005/10/15 02:49:42 momjian Exp $ + * $PostgreSQL: pgsql/src/include/access/relscan.h,v 1.42 2005/11/26 03:03:07 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -26,14 +26,23 @@ typedef struct HeapScanDescData int rs_nkeys; /* number of scan keys */ ScanKey rs_key; /* array of scan key descriptors */ BlockNumber rs_nblocks; /* number of blocks to scan */ + bool rs_pageatatime; /* verify visibility page-at-a-time? */ /* scan current state */ + bool rs_inited; /* false = scan not init'd yet */ HeapTupleData rs_ctup; /* current tuple in scan, if any */ + BlockNumber rs_cblock; /* current block # in scan, if any */ Buffer rs_cbuf; /* current buffer in scan, if any */ /* NB: if rs_cbuf is not InvalidBuffer, we hold a pin on that buffer */ ItemPointerData rs_mctid; /* marked scan position, if any */ PgStat_Info rs_pgstat_info; /* statistics collector hook */ + + /* these fields only used in page-at-a-time mode */ + int rs_cindex; /* current tuple's index in vistuples */ + int rs_mindex; /* marked tuple's saved index */ + int rs_ntuples; /* number of visible tuples on page */ + OffsetNumber rs_vistuples[MaxHeapTuplesPerPage]; /* their offsets */ } HeapScanDescData; typedef HeapScanDescData *HeapScanDesc; diff --git a/src/include/access/valid.h b/src/include/access/valid.h index 8309c699178..cb9c6369a12 100644 --- a/src/include/access/valid.h +++ b/src/include/access/valid.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/access/valid.h,v 1.36 2004/12/31 22:03:21 pgsql Exp $ + * $PostgreSQL: pgsql/src/include/access/valid.h,v 1.37 2005/11/26 03:03:07 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -65,37 +65,4 @@ do \ } \ } while (0) -/* - * HeapTupleSatisfies - * - * res is set TRUE if the HeapTuple satisfies the timequal and keytest, - * otherwise it is set FALSE. Note that the hint bits in the HeapTuple's - * t_infomask may be updated as a side effect. - * - * on 8/21/92 mao says: i rearranged the tests here to do keytest before - * SatisfiesTimeQual. profiling indicated that even for vacuumed relations, - * time qual checking was more expensive than key testing. time qual is - * least likely to fail, too. we should really add the time qual test to - * the restriction and optimize it in the normal way. this has interactions - * with joey's expensive function work. - */ -#define HeapTupleSatisfies(tuple, \ - relation, \ - buffer, \ - disk_page, \ - snapshot, \ - nKeys, \ - key, \ - res) \ -do \ -{ \ - if ((key) != NULL) \ - HeapKeyTest(tuple, RelationGetDescr(relation), nKeys, key, res); \ - else \ - (res) = true; \ - \ - if ((res) && (relation)->rd_rel->relkind != RELKIND_UNCATALOGED) \ - (res) = HeapTupleSatisfiesVisibility(tuple, snapshot, buffer); \ -} while (0) - #endif /* VALID_H */ diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h index f70847798e6..82f182c3497 100644 --- a/src/include/nodes/execnodes.h +++ b/src/include/nodes/execnodes.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/nodes/execnodes.h,v 1.142 2005/11/25 19:47:50 tgl Exp $ + * $PostgreSQL: pgsql/src/include/nodes/execnodes.h,v 1.143 2005/11/26 03:03:07 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -958,9 +958,6 @@ typedef struct BitmapIndexScanState * bitmapqualorig execution state for bitmapqualorig expressions * tbm bitmap obtained from child index scan(s) * tbmres current-page data - * curslot current tbmres index or tuple offset on page - * minslot lowest tbmres index or tuple offset to try - * maxslot highest tbmres index or tuple offset to try * ---------------- */ typedef struct BitmapHeapScanState @@ -969,9 +966,6 @@ typedef struct BitmapHeapScanState List *bitmapqualorig; TIDBitmap *tbm; TBMIterateResult *tbmres; - int curslot; - int minslot; - int maxslot; } BitmapHeapScanState; /* ---------------- diff --git a/src/include/utils/tqual.h b/src/include/utils/tqual.h index bfd51cb72e6..5e3efa17967 100644 --- a/src/include/utils/tqual.h +++ b/src/include/utils/tqual.h @@ -8,7 +8,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/utils/tqual.h,v 1.59 2005/10/15 02:49:46 momjian Exp $ + * $PostgreSQL: pgsql/src/include/utils/tqual.h,v 1.60 2005/11/26 03:03:07 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -55,6 +55,15 @@ typedef SnapshotData *Snapshot; extern DLLIMPORT Snapshot SnapshotDirty; +/* This macro encodes the knowledge of which snapshots are MVCC-safe */ +#define IsMVCCSnapshot(snapshot) \ + ((snapshot) != SnapshotNow && \ + (snapshot) != SnapshotSelf && \ + (snapshot) != SnapshotAny && \ + (snapshot) != SnapshotToast && \ + (snapshot) != SnapshotDirty) + + extern DLLIMPORT Snapshot SerializableSnapshot; extern DLLIMPORT Snapshot LatestSnapshot; extern DLLIMPORT Snapshot ActiveSnapshot; @@ -69,8 +78,9 @@ extern TransactionId RecentGlobalXmin; * True iff heap tuple satisfies a time qual. * * Notes: - * Assumes heap tuple is valid. - * Beware of multiple evaluations of snapshot argument. + * Assumes heap tuple is valid. + * Beware of multiple evaluations of snapshot argument. + * Hint bits in the HeapTuple's t_infomask may be updated as a side effect. */ #define HeapTupleSatisfiesVisibility(tuple, snapshot, buffer) \ ((snapshot) == SnapshotNow ? \ |