Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit85d72f0

Browse files
committed
Teach heapam code to know the difference between a real seqscan and the
pseudo HeapScanDesc created for a bitmap heap scan. This avoids some uselessoverhead during a bitmap scan startup, in particular invoking the syncscancode. (We might someday want to do that, but right now it's merely uselesscontention for shared memory, to say nothing of possibly pushing usefulentries out of syncscan's small LRU list.) This also allows elimination ofugly pgstat_discount_heap_scan() kluge.
1 parent7063c46 commit85d72f0

File tree

5 files changed

+48
-34
lines changed

5 files changed

+48
-34
lines changed

‎src/backend/access/heap/heapam.c

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.235 2007/06/08 18:23:52 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.236 2007/06/09 18:49:54 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -58,6 +58,10 @@
5858
#include"utils/syscache.h"
5959

6060

61+
staticHeapScanDescheap_beginscan_internal(Relationrelation,
62+
Snapshotsnapshot,
63+
intnkeys,ScanKeykey,
64+
boolis_bitmapscan);
6165
staticXLogRecPtrlog_heap_update(Relationreln,Bufferoldbuf,
6266
ItemPointerDatafrom,Buffernewbuf,HeapTuplenewtup,boolmove);
6367

@@ -95,8 +99,9 @@ initscan(HeapScanDesc scan, ScanKey key)
9599
*
96100
* During a rescan, don't make a new strategy object if we don't have to.
97101
*/
98-
if (scan->rs_nblocks>NBuffers /4&&
99-
!scan->rs_rd->rd_istemp)
102+
if (!scan->rs_bitmapscan&&
103+
!scan->rs_rd->rd_istemp&&
104+
scan->rs_nblocks>NBuffers /4)
100105
{
101106
if (scan->rs_strategy==NULL)
102107
scan->rs_strategy=GetAccessStrategy(BAS_BULKREAD);
@@ -114,8 +119,6 @@ initscan(HeapScanDesc scan, ScanKey key)
114119
scan->rs_startblock=0;
115120
}
116121

117-
/* rs_pageatatime was set when the snapshot was filled in */
118-
119122
scan->rs_inited= false;
120123
scan->rs_ctup.t_data=NULL;
121124
ItemPointerSetInvalid(&scan->rs_ctup.t_self);
@@ -133,7 +136,12 @@ initscan(HeapScanDesc scan, ScanKey key)
133136
if (key!=NULL)
134137
memcpy(scan->rs_key,key,scan->rs_nkeys*sizeof(ScanKeyData));
135138

136-
pgstat_count_heap_scan(scan->rs_rd);
139+
/*
140+
* Currently, we don't have a stats counter for bitmap heap scans
141+
* (but the underlying bitmap index scans will be counted).
142+
*/
143+
if (!scan->rs_bitmapscan)
144+
pgstat_count_heap_scan(scan->rs_rd);
137145
}
138146

139147
/*
@@ -1037,11 +1045,30 @@ heap_openrv(const RangeVar *relation, LOCKMODE lockmode)
10371045

10381046
/* ----------------
10391047
*heap_beginscan- begin relation scan
1048+
*
1049+
* heap_beginscan_bm is an alternate entry point for setting up a HeapScanDesc
1050+
* for a bitmap heap scan. Although that scan technology is really quite
1051+
* unlike a standard seqscan, there is just enough commonality to make it
1052+
* worth using the same data structure.
10401053
* ----------------
10411054
*/
10421055
HeapScanDesc
10431056
heap_beginscan(Relationrelation,Snapshotsnapshot,
10441057
intnkeys,ScanKeykey)
1058+
{
1059+
returnheap_beginscan_internal(relation,snapshot,nkeys,key, false);
1060+
}
1061+
1062+
HeapScanDesc
1063+
heap_beginscan_bm(Relationrelation,Snapshotsnapshot,
1064+
intnkeys,ScanKeykey)
1065+
{
1066+
returnheap_beginscan_internal(relation,snapshot,nkeys,key, true);
1067+
}
1068+
1069+
staticHeapScanDesc
1070+
heap_beginscan_internal(Relationrelation,Snapshotsnapshot,
1071+
intnkeys,ScanKeykey,boolis_bitmapscan)
10451072
{
10461073
HeapScanDescscan;
10471074

@@ -1062,6 +1089,7 @@ heap_beginscan(Relation relation, Snapshot snapshot,
10621089
scan->rs_rd=relation;
10631090
scan->rs_snapshot=snapshot;
10641091
scan->rs_nkeys=nkeys;
1092+
scan->rs_bitmapscan=is_bitmapscan;
10651093
scan->rs_strategy=NULL;/* set in initscan */
10661094

10671095
/*

‎src/backend/executor/nodeBitmapHeapscan.c

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
*
2323
* IDENTIFICATION
24-
* $PostgreSQL: pgsql/src/backend/executor/nodeBitmapHeapscan.c,v 1.17 2007/05/27 03:50:39 tgl Exp $
24+
* $PostgreSQL: pgsql/src/backend/executor/nodeBitmapHeapscan.c,v 1.18 2007/06/09 18:49:55 tgl Exp $
2525
*
2626
*-------------------------------------------------------------------------
2727
*/
@@ -388,9 +388,6 @@ ExecBitmapHeapReScan(BitmapHeapScanState *node, ExprContext *exprCtxt)
388388
/* rescan to release any page pin */
389389
heap_rescan(node->ss.ss_currentScanDesc,NULL);
390390

391-
/* undo bogus "seq scan" count (see notes in ExecInitBitmapHeapScan) */
392-
pgstat_discount_heap_scan(node->ss.ss_currentScanDesc->rs_rd);
393-
394391
if (node->tbm)
395392
tbm_free(node->tbm);
396393
node->tbm=NULL;
@@ -522,20 +519,12 @@ ExecInitBitmapHeapScan(BitmapHeapScan *node, EState *estate, int eflags)
522519

523520
/*
524521
* Even though we aren't going to do a conventional seqscan, it is useful
525-
* to create a HeapScanDesc --- this checks the relation size and sets up
526-
* statistical infrastructure for us.
527-
*/
528-
scanstate->ss.ss_currentScanDesc=heap_beginscan(currentRelation,
529-
estate->es_snapshot,
530-
0,
531-
NULL);
532-
533-
/*
534-
* One problem is that heap_beginscan counts a "sequential scan" start,
535-
* when we actually aren't doing any such thing. Reverse out the added
536-
* scan count.(Eventually we may want to count bitmap scans separately.)
522+
* to create a HeapScanDesc --- most of the fields in it are usable.
537523
*/
538-
pgstat_discount_heap_scan(scanstate->ss.ss_currentScanDesc->rs_rd);
524+
scanstate->ss.ss_currentScanDesc=heap_beginscan_bm(currentRelation,
525+
estate->es_snapshot,
526+
0,
527+
NULL);
539528

540529
/*
541530
* get the scan type from the relation descriptor.

‎src/include/access/heapam.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/access/heapam.h,v 1.125 2007/06/08 18:23:53 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/access/heapam.h,v 1.126 2007/06/09 18:49:55 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -141,6 +141,8 @@ extern Relation heap_openrv(const RangeVar *relation, LOCKMODE lockmode);
141141

142142
externHeapScanDescheap_beginscan(Relationrelation,Snapshotsnapshot,
143143
intnkeys,ScanKeykey);
144+
externHeapScanDescheap_beginscan_bm(Relationrelation,Snapshotsnapshot,
145+
intnkeys,ScanKeykey);
144146
externvoidheap_rescan(HeapScanDescscan,ScanKeykey);
145147
externvoidheap_endscan(HeapScanDescscan);
146148
externHeapTupleheap_getnext(HeapScanDescscan,ScanDirectiondirection);

‎src/include/access/relscan.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/access/relscan.h,v 1.55 2007/06/08 18:23:53 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/access/relscan.h,v 1.56 2007/06/09 18:49:55 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -26,12 +26,13 @@ typedef struct HeapScanDescData
2626
Snapshotrs_snapshot;/* snapshot to see */
2727
intrs_nkeys;/* number of scan keys */
2828
ScanKeyrs_key;/* array of scan key descriptors */
29+
boolrs_bitmapscan;/* true if this is really a bitmap scan */
30+
boolrs_pageatatime;/* verify visibility page-at-a-time? */
2931

3032
/* state set up at initscan time */
3133
BlockNumberrs_nblocks;/* number of blocks to scan */
3234
BlockNumberrs_startblock;/* block # to start at */
3335
BufferAccessStrategyrs_strategy;/* access strategy for reads */
34-
boolrs_pageatatime;/* verify visibility page-at-a-time? */
3536
boolrs_syncscan;/* report location to syncscan logic? */
3637

3738
/* scan current state */
@@ -42,7 +43,7 @@ typedef struct HeapScanDescData
4243
/* NB: if rs_cbuf is not InvalidBuffer, we hold a pin on that buffer */
4344
ItemPointerDatars_mctid;/* marked scan position, if any */
4445

45-
/* these fields only used in page-at-a-time mode */
46+
/* these fields only used in page-at-a-time modeand for bitmap scans*/
4647
intrs_cindex;/* current tuple's index in vistuples */
4748
intrs_mindex;/* marked tuple's saved index */
4849
intrs_ntuples;/* number of visible tuples on page */

‎src/include/pgstat.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
*Copyright (c) 2001-2007, PostgreSQL Global Development Group
77
*
8-
*$PostgreSQL: pgsql/src/include/pgstat.h,v 1.61 2007/05/27 17:28:36 tgl Exp $
8+
*$PostgreSQL: pgsql/src/include/pgstat.h,v 1.62 2007/06/09 18:49:55 tgl Exp $
99
* ----------
1010
*/
1111
#ifndefPGSTAT_H
@@ -518,12 +518,6 @@ extern void pgstat_initstats(Relation rel);
518518
if (pgstat_collect_tuplelevel && (rel)->pgstat_info != NULL)\
519519
(rel)->pgstat_info->t_counts.t_numscans++;\
520520
} while (0)
521-
/* kluge for bitmap scans: */
522-
#definepgstat_discount_heap_scan(rel)\
523-
do {\
524-
if (pgstat_collect_tuplelevel && (rel)->pgstat_info != NULL)\
525-
(rel)->pgstat_info->t_counts.t_numscans--;\
526-
} while (0)
527521
#definepgstat_count_heap_getnext(rel)\
528522
do {\
529523
if (pgstat_collect_tuplelevel && (rel)->pgstat_info != NULL)\

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp