8000 DEBUG: Add skip scan disable GUCs. · petergeoghegan/postgres@41599a7 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 41599a7

Browse files
DEBUG: Add skip scan disable GUCs.
1 parent c45a1db commit 41599a7

File tree

4 files changed

+79
-0
lines changed

4 files changed

+79
-0
lines changed

src/backend/access/nbtree/nbtpreprocesskeys.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,33 @@
2121
#include "utils/lsyscache.h"
2222
#include "utils/memutils.h"
2323

24+
/*
25+
* GUC parameters (temporary convenience for reviewers).
26+
*
27+
* To disable all skipping, set skipscan_prefix_cols=0. Otherwise set it to
28+
* the attribute number that you wish to make the last attribute number that
29+
* we can add a skip scan key for. For example, skipscan_prefix_cols=1 makes
30+
* an index scan with qual "WHERE b = 1 AND d = 42" generate a skip scan key
31+
* on the column 'a' (which is attnum 1) only, preventing us from adding one
32+
* for the column 'c'. And so only the scan key on 'b' (not the one on 'd')
33+
* gets marked required within _bt_preprocess_keys -- there is no 'c' skip
34+
* array to "anchor the required-ness" of 'b' through 'c' into 'd'.
35+
*/
36+
int skipscan_prefix_cols = INDEX_MAX_KEYS;
37+
38+
/*
39+
* skipscan_skipsupport_enabled can be used to avoid using skip support. Used
40+
* to quantify the performance benefit that comes from having dedicated skip
41+
* support, with a given opclass and test query.
42+
*/
43+
bool skipscan_skipsupport_enabled = true;
44+
45+
/*
46+
* skipscan_iprefix_enabled can be used to disable optimizations used when the
47+
* maintenance overhead of skip arrays stops paying for itself
48+
*/
49+
bool skipscan_iprefix_enabled = true;
50+
2451
typedef struct BTScanKeyPreproc
2552
{
2653
ScanKey inkey;
@@ -1651,6 +1678,10 @@ _bt_preprocess_array_keys(IndexScanDesc scan, int *new_numberOfKeys)
16511678
so->arrayKeys[numArrayKeys].low_compare = NULL; /* for now */
16521679
so->arrayKeys[numArrayKeys].high_compare = NULL; /* for now */
16531680

1681+
/* Temporary testing GUC can disable the use of skip support */
1682+
if (!skipscan_skipsupport_enabled)
1683+
so->arrayKeys[numArrayKeys].sksup = NULL;
1684+
16541685
/*
16551686
* We'll need a 3-way ORDER proc. Set that up now.
16561687
*/
@@ -2177,6 +2208,12 @@ _bt_num_array_keys(IndexScanDesc scan, Oid *skip_eq_ops_out,
21772208
if (attno_has_rowcompare)
21782209
break;
21792210

2211+
/*
2212+
* Apply temporary testing GUC that can be used to disable skipping
2213+
*/
2214+
if (attno_inkey > skipscan_prefix_cols)
2215+
break;
2216+
21802217
/*
21812218
* Now consider next attno_inkey (or keep going if this is an
21822219
* additional scan key against the same attribute)

src/backend/access/nbtree/nbtutils.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2523,6 +2523,9 @@ _bt_set_startikey(IndexScanDesc scan, BTReadPageState *pstate)
25232523
if (so->numberOfKeys == 0)
25242524
return;
25252525

2526+
if (!skipscan_iprefix_enabled)
2527+
return;
2528+
25262529
/* minoff is an offset to the lowest non-pivot tuple on the page */
25272530
iid = PageGetItemId(pstate->page, pstate->minoff);
25282531
firsttup = (IndexTuple) PageGetItem(pstate->page, iid);

src/backend/utils/misc/guc_tables.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include "access/commit_ts.h"
3333
#include "access/gin.h"
34+
#include "access/nbtree.h"
3435
#include "access/slru.h"
3536
#include "access/toast_compression.h"
3637
#include "access/twophase.h"
@@ -1800,6 +1801,28 @@ struct config_bool ConfigureNamesBool[] =
18001801
},
18011802
#endif
18021803

1804+
/* XXX Remove before commit */
1805+
{
1806+
{"skipscan_skipsupport_enabled", PGC_SUSET, DEVELOPER_OPTIONS,
1807+
NULL, NULL,
1808+
GUC_NOT_IN_SAMPLE
1809+
},
1810+
&skipscan_skipsupport_enabled,
1811+
true,
1812+
NULL, NULL, NULL
1813+
},
1814+
1815+
/* XXX Remove before commit */
1816+
{
1817+
{"skipscan_iprefix_enabled", PGC_SUSET, DEVELOPER_OPTIONS,
1818+
NULL, NULL,
1819+
GUC_NOT_IN_SAMPLE
1820+
},
1821+
&skipscan_iprefix_enabled,
1822+
true,
1823+
NULL, NULL, NULL
1824+
},
1825+
18031826
{
18041827
{"integer_datetimes", PGC_INTERNAL, PRESET_OPTIONS,
18051828
gettext_noop("Shows whether datetimes are integer based."),
@@ -3736,6 +3759,17 @@ struct config_int ConfigureNamesInt[] =
37363759
NULL, NULL, NULL
37373760
},
37383761

3762+
/* XXX Remove before commit */
3763+
{
3764+
{"skipscan_prefix_cols", PGC_SUSET, DEVELOPER_OPTIONS,
3765+
NULL, NULL,
3766+
GUC_NOT_IN_SAMPLE
3767+
},
3768+
&skipscan_prefix_cols,
3769+
INDEX_MAX_KEYS, 0, INDEX_MAX_KEYS,
3770+
NULL, NULL, NULL
3771+
},
3772+
37393773
{
37403774
/* Can't be set in postgresql.conf */
37413775
{"server_version_num", PGC_INTERNAL, PRESET_OPTIONS,

src/include/access/nbtree.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,11 @@ typedef struct BTOptions
11791179
#define PROGRESS_BTREE_PHASE_PERFORMSORT_2 4
11801180
#define PROGRESS_BTREE_PHASE_LEAF_LOAD 5
11811181

1182+
/* GUC parameters (just a temporary convenience for reviewers) */
1183+
extern PGDLLIMPORT int skipscan_prefix_cols;
1184+
extern PGDLLIMPORT bool skipscan_skipsupport_enabled;
1185+
extern PGDLLIMPORT bool skipscan_iprefix_enabled;
1186+
11821187
/*
11831188
* external entry points for btree, in nbtree.c
11841189
*/

0 commit comments

Comments
 (0)
0