diff options
Diffstat (limited to 'src/backend/optimizer/util')
-rw-r--r-- | src/backend/optimizer/util/plancat.c | 17 | ||||
-rw-r--r-- | src/backend/optimizer/util/var.c | 45 |
2 files changed, 60 insertions, 2 deletions
diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c index 70b3d7d43f5..21dd342593a 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.136 2007/05/31 16:57:34 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.137 2007/09/20 17:56:31 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -19,6 +19,7 @@ #include "access/genam.h" #include "access/heapam.h" +#include "access/transam.h" #include "catalog/pg_inherits.h" #include "nodes/makefuncs.h" #include "optimizer/clauses.h" @@ -164,6 +165,20 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, continue; } + /* + * If the index is valid, but cannot yet be used, ignore it; + * but mark the plan we are generating as transient. + * See src/backend/access/heap/README.HOT for discussion. + */ + if (index->indcheckxmin && + !TransactionIdPrecedes(HeapTupleHeaderGetXmin(indexRelation->rd_indextuple->t_data), + TransactionXmin)) + { + root->glob->transientPlan = true; + index_close(indexRelation, NoLock); + continue; + } + info = makeNode(IndexOptInfo); info->indexoid = index->indexrelid; diff --git a/src/backend/optimizer/util/var.c b/src/backend/optimizer/util/var.c index c501c827922..efb1ad9343d 100644 --- a/src/backend/optimizer/util/var.c +++ b/src/backend/optimizer/util/var.c @@ -8,12 +8,13 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/util/var.c,v 1.70 2007/06/11 01:16:23 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/util/var.c,v 1.71 2007/09/20 17:56:31 tgl Exp $ * *------------------------------------------------------------------------- */ #include "postgres.h" +#include "access/htup.h" #include "optimizer/clauses.h" #include "optimizer/prep.h" #include "optimizer/var.h" @@ -54,6 +55,7 @@ typedef struct static bool pull_varnos_walker(Node *node, pull_varnos_context *context); +static bool pull_varattnos_walker(Node *node, Bitmapset **varattnos); static bool contain_var_reference_walker(Node *node, contain_var_reference_context *context); static bool contain_var_clause_walker(Node *node, void *context); @@ -134,6 +136,47 @@ pull_varnos_walker(Node *node, pull_varnos_context *context) (void *) context); } +/* + * pull_varattnos + * Find all the distinct attribute numbers present in an expression tree, + * and add them to the initial contents of *varattnos. + * Only Vars that reference RTE 1 of rtable level zero are considered. + * + * Attribute numbers are offset by FirstLowInvalidHeapAttributeNumber so that + * we can include system attributes (e.g., OID) in the bitmap representation. + * + * Currently, this does not support subqueries nor expressions containing + * references to multiple tables; not needed since it's only applied to + * index expressions and predicates. + */ +void +pull_varattnos(Node *node, Bitmapset **varattnos) +{ + (void) pull_varattnos_walker(node, varattnos); +} + +static bool +pull_varattnos_walker(Node *node, Bitmapset **varattnos) +{ + if (node == NULL) + return false; + if (IsA(node, Var)) + { + Var *var = (Var *) node; + + Assert(var->varno == 1); + *varattnos = bms_add_member(*varattnos, + var->varattno - FirstLowInvalidHeapAttributeNumber); + return false; + } + /* Should not find a subquery or subplan */ + Assert(!IsA(node, Query)); + Assert(!is_subplan(node)); + + return expression_tree_walker(node, pull_varattnos_walker, + (void *) varattnos); +} + /* * contain_var_reference |