Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Fix bogus test for hypothetical indexes in get_actual_variable_range().
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 17 Feb 2011 00:24:45 +0000 (19:24 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 17 Feb 2011 00:24:45 +0000 (19:24 -0500)
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

src/backend/nodes/outfuncs.c
src/backend/optimizer/util/plancat.c
src/backend/utils/adt/selfuncs.c
src/include/nodes/relation.h

index 5c943bc2543b90ee678a51804473fc9aef700d66..192c04229137692be1e6bc35cdf21984bf924bb3 100644 (file)
@@ -1700,10 +1700,12 @@ _outIndexOptInfo(StringInfo str, IndexOptInfo *node)
    WRITE_UINT_FIELD(pages);
    WRITE_FLOAT_FIELD(tuples, "%.0f");
    WRITE_INT_FIELD(ncolumns);
+   WRITE_OID_FIELD(relam);
    WRITE_NODE_FIELD(indexprs);
    WRITE_NODE_FIELD(indpred);
    WRITE_BOOL_FIELD(predOK);
    WRITE_BOOL_FIELD(unique);
+   WRITE_BOOL_FIELD(hypothetical);
 }
 
 static void
index 1f79ba24fb3fdfb3534048afbe5afd667d14a696..40df626b62ff7c025117055923a203d3957b5fbf 100644 (file)
@@ -316,6 +316,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
                ChangeVarNodes((Node *) info->indpred, 1, varno, 0);
            info->predOK = false;       /* set later in indxpath.c */
            info->unique = index->indisunique;
+           info->hypothetical = false;
 
            /*
             * Estimate the index size.  If it's not a partial index, we lock
index b3299b56d836cb0e6c2ae8d00e5f1afc362894c7..f10110b1b7ea592a357ce9bbdbe16644c8406321 100644 (file)
@@ -4562,10 +4562,10 @@ get_actual_variable_range(PlannerInfo *root, VariableStatData *vardata,
            continue;
 
        /*
-        * The index list might include fictitious indexes inserted by a
+        * The index list might include hypothetical indexes inserted by a
         * get_relation_info hook --- don't try to access them.
         */
-       if (!OidIsValid(index->indexoid))
+       if (index->hypothetical)
            continue;
 
        /*
index 49ce441e6248424852a2a1592ee28a9b9f72f743..6f51b6c5fe403579788ec031bc60b9d6de7f0073 100644 (file)
@@ -455,7 +455,7 @@ typedef struct IndexOptInfo
    int         ncolumns;       /* number of columns in index */
    Oid        *opfamily;       /* OIDs of operator families for columns */
    int        *indexkeys;      /* column numbers of index's keys, or 0 */
-   Oid        *indexcollations;/* OIDs of the collations of the index columns */
+   Oid        *indexcollations;    /* OIDs of collations of index columns */
    Oid        *opcintype;      /* OIDs of opclass declared input data types */
    Oid        *sortopfamily;   /* OIDs of btree opfamilies, if orderable */
    bool       *reverse_sort;   /* is sort order descending? */
@@ -469,6 +469,7 @@ typedef struct IndexOptInfo
 
    bool        predOK;         /* true if predicate matches query */
    bool        unique;         /* true if a unique index */
+   bool        hypothetical;   /* true if index doesn't really exist */
    bool        amcanorderbyop; /* does AM support order by operator result? */
    bool        amoptionalkey;  /* can query omit key for the first column? */
    bool        amsearchnulls;  /* can AM search for NULL/NOT NULL entries? */