Fix bogus test for hypothetical indexes in get_actual_variable_range().
authorTom Lane
Thu, 17 Feb 2011 00:24:50 +0000 (19:24 -0500)
committerTom Lane
Thu, 17 Feb 2011 00:24:50 +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 15a9aa2f939328673a5ddee21135ee0b9d31c1db..09dc9ccb5ece83b2870dcf45c555abb762881932 100644 (file)
@@ -1611,10 +1611,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 10800b488f6fe9df1630fdcdd405c658c32b0be5..d5d452475bfb88a63427cae0f4fd7d1e6ce6ffa9 100644 (file)
@@ -275,6 +275,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 c08310ba41561275c2756558a074330e8213afe9..5c7e8325a198e3b9b638edf66962c84ad0efce4c 100644 (file)
@@ -4555,10 +4555,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 f109a1de520921caf39c5987f2884901fb416e28..7d39e10747ac7bd05ffce0190ea616a93645a857 100644 (file)
@@ -471,6 +471,8 @@ typedef struct IndexOptInfo
    bool        amsearchnulls;  /* can AM search for NULL/NOT NULL entries? */
    bool        amhasgettuple;  /* does AM have amgettuple interface? */
    bool        amhasgetbitmap; /* does AM have amgetbitmap interface? */
+   /* added in 9.0.4: */
+   bool        hypothetical;   /* true if index doesn't really exist */
 } IndexOptInfo;