Skip to content

Commit a2095f7

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 6595dd0 commit a2095f7

File tree

4 files changed

+7
-3
lines changed

4 files changed

+7
-3
lines changed

src/backend/nodes/outfuncs.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,10 +1700,12 @@ _outIndexOptInfo(StringInfo str, IndexOptInfo *node)
17001700
WRITE_UINT_FIELD(pages);
17011701
WRITE_FLOAT_FIELD(tuples, "%.0f");
17021702
WRITE_INT_FIELD(ncolumns);
1703+
WRITE_OID_FIELD(relam);
17031704
WRITE_NODE_FIELD(indexprs);
17041705
WRITE_NODE_FIELD(indpred);
17051706
WRITE_BOOL_FIELD(predOK);
17061707
WRITE_BOOL_FIELD(unique);
1708+
WRITE_BOOL_FIELD(hypothetical);
17071709
}
17081710

17091711
static void

src/backend/optimizer/util/plancat.c

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

320321
/*
321322
* 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
@@ -4562,10 +4562,10 @@ get_actual_variable_range(PlannerInfo *root, VariableStatData *vardata,
45624562
continue;
45634563

45644564
/*
4565-
* The index list might include fictitious indexes inserted by a
4565+
* The index list might include hypothetical indexes inserted by a
45664566
* get_relation_info hook --- don't try to access them.
45674567
*/
4568-
if (!OidIsValid(index->indexoid))
4568+
if (index->hypothetical)
45694569
continue;
45704570

45714571
/*

src/include/nodes/relation.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ typedef struct IndexOptInfo
455455
int ncolumns; /* number of columns in index */
456456
Oid *opfamily; /* OIDs of operator families for columns */
457457
int *indexkeys; /* column numbers of index's keys, or 0 */
458-
Oid *indexcollations;/* OIDs of the collations of the index columns */
458+
Oid *indexcollations; /* OIDs of collations of index columns */
459459
Oid *opcintype; /* OIDs of opclass declared input data types */
460460
Oid *sortopfamily; /* OIDs of btree opfamilies, if orderable */
461461
bool *reverse_sort; /* is sort order descending? */
@@ -469,6 +469,7 @@ typedef struct IndexOptInfo
469469

470470
bool predOK; /* true if predicate matches query */
471471
bool unique; /* true if a unique index */
472+
bool hypothetical; /* true if index doesn't really exist */
472473
bool amcanorderbyop; /* does AM support order by operator result? */
473474
bool amoptionalkey; /* can query omit key for the first column? */
474475
bool amsearchnulls; /* can AM search for NULL/NOT NULL entries? */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy