Skip to content

Commit 7422e00

Browse files
committed
Fix bogus test for hypothetical indexes in get_actual_variable_range().
That function was supposing that indexoid == 0 for a hypothetical index, but that is not likely to be true in any non-toy implementation of an index adviser, since assigning a fake OID is the only way to know at EXPLAIN time which hypothetical index got selected. Fix by adding a flag to IndexOptInfo to mark hypothetical indexes. Back-patch to 9.0 where get_actual_variable_range() was added. Gurjeet Singh
1 parent 8e4b147 commit 7422e00

File tree

4 files changed

+7
-2
lines changed

4 files changed

+7
-2
lines changed

src/backend/nodes/outfuncs.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,10 +1611,12 @@ _outIndexOptInfo(StringInfo str, IndexOptInfo *node)
16111611
WRITE_UINT_FIELD(pages);
16121612
WRITE_FLOAT_FIELD(tuples, "%.0f");
16131613
WRITE_INT_FIELD(ncolumns);
1614+
WRITE_OID_FIELD(relam);
16141615
WRITE_NODE_FIELD(indexprs);
16151616
WRITE_NODE_FIELD(indpred);
16161617
WRITE_BOOL_FIELD(predOK);
16171618
WRITE_BOOL_FIELD(unique);
1619+
WRITE_BOOL_FIELD(hypothetical);
16181620
}
16191621

16201622
static void

src/backend/optimizer/util/plancat.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
275275
ChangeVarNodes((Node *) info->indpred, 1, varno, 0);
276276
info->predOK = false; /* set later in indxpath.c */
277277
info->unique = index->indisunique;
278+
info->hypothetical = false;
278279

279280
/*
280281
* Estimate the index size. If it's not a partial index, we lock

src/backend/utils/adt/selfuncs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4555,10 +4555,10 @@ get_actual_variable_range(PlannerInfo *root, VariableStatData *vardata,
45554555
continue;
45564556

45574557
/*
4558-
* The index list might include fictitious indexes inserted by a
4558+
* The index list might include hypothetical indexes inserted by a
45594559
* get_relation_info hook --- don't try to access them.
45604560
*/
4561-
if (!OidIsValid(index->indexoid))
4561+
if (index->hypothetical)
45624562
continue;
45634563

45644564
/*

src/include/nodes/relation.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,8 @@ typedef struct IndexOptInfo
471471
bool amsearchnulls; /* can AM search for NULL/NOT NULL entries? */
472472
bool amhasgettuple; /* does AM have amgettuple interface? */
473473
bool amhasgetbitmap; /* does AM have amgetbitmap interface? */
474+
/* added in 9.0.4: */
475+
bool hypothetical; /* true if index doesn't really exist */
474476
} IndexOptInfo;
475477

476478

0 commit comments

Comments
 (0)