Skip to content

Commit 9ef1851

Browse files
committed
Support non-btree indexes in get_actual_variable_range()
This was previously not supported because the btree strategy numbers were hardcoded. Now we can support this for any index that has the required strategy mapping support and the required operators. If an index scan used for get_actual_variable_range() requires recheck, we now just ignore it instead of erroring out. With btree we knew this couldn't happen, but now it might. Author: Mark Dilger <mark.dilger@enterprisedb.com> Co-authored-by: Peter Eisentraut <peter@eisentraut.org> Discussion: https://www.postgresql.org/message-id/flat/E72EAA49-354D-4C2E-8EB9-255197F55330@enterprisedb.com
1 parent 0d6c477 commit 9ef1851

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/backend/utils/adt/selfuncs.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6327,10 +6327,7 @@ get_actual_variable_range(PlannerInfo *root, VariableStatData *vardata,
63276327
{
63286328
IndexOptInfo *index = (IndexOptInfo *) lfirst(lc);
63296329
ScanDirection indexscandir;
6330-
6331-
/* Ignore non-btree indexes */
6332-
if (index->relam != BTREE_AM_OID)
6333-
continue;
6330+
StrategyNumber strategy;
63346331

63356332
/*
63366333
* Ignore partial indexes --- we only want stats that cover the entire
@@ -6354,15 +6351,16 @@ get_actual_variable_range(PlannerInfo *root, VariableStatData *vardata,
63546351
continue; /* test first 'cause it's cheapest */
63556352
if (!match_index_to_operand(vardata->var, 0, index))
63566353
continue;
6357-
switch (get_op_opfamily_strategy(sortop, index->sortopfamily[0]))
6354+
strategy = get_op_opfamily_strategy(sortop, index->sortopfamily[0]);
6355+
switch (IndexAmTranslateStrategy(strategy, index->relam, index->sortopfamily[0], true))
63586356
{
6359-
case BTLessStrategyNumber:
6357+
case COMPARE_LT:
63606358
if (index->reverse_sort[0])
63616359
indexscandir = BackwardScanDirection;
63626360
else
63636361
indexscandir = ForwardScanDirection;
63646362
break;
6365-
case BTGreaterStrategyNumber:
6363+
case COMPARE_GT:
63666364
if (index->reverse_sort[0])
63676365
indexscandir = ForwardScanDirection;
63686366
else
@@ -6602,13 +6600,17 @@ get_actual_variable_endpoint(Relation heapRel,
66026600
}
66036601

66046602
/*
6605-
* We expect that btree will return data in IndexTuple not HeapTuple
6606-
* format. It's not lossy either.
6603+
* We expect that the index will return data in IndexTuple not
6604+
* HeapTuple format.
66076605
*/
66086606
if (!index_scan->xs_itup)
66096607
elog(ERROR, "no data returned for index-only scan");
6608+
6609+
/*
6610+
* We do not yet support recheck here.
6611+
*/
66106612
if (index_scan->xs_recheck)
6611-
elog(ERROR, "unexpected recheck indication from btree");
6613+
break;
66126614

66136615
/* OK to deconstruct the index tuple */
66146616
index_deform_tuple(index_scan->xs_itup,

0 commit comments

Comments
 (0)