diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2005-06-03 23:05:30 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2005-06-03 23:05:30 +0000 |
commit | ba42002461a82ff5aba240611fe5a2366b0f1f86 (patch) | |
tree | 904791114a5a2505b5a5bdf58d14551b916bf325 /src/include/nodes/parsenodes.h | |
parent | 7e209f6ce3a4eb2cba877e5e76597ecdb1596c2e (diff) |
Revise handling of dropped columns in JOIN alias lists to avoid a
performance problem pointed out by phil@vodafone: to wit, we were
spending O(N^2) time to check dropped-ness in an N-deep join tree,
even in the case where the tree was freshly constructed and couldn't
possibly mention any dropped columns. Instead of recursing in
get_rte_attribute_is_dropped(), change the data structure definition:
the joinaliasvars list of a JOIN RTE must have a NULL Const instead
of a Var at any position that references a now-dropped column. This
costs nothing during normal parse-rewrite-plan path, and instead we
have a linear-time update to make when loading a stored rule that
might contain now-dropped columns. While at it, move the responsibility
for acquring locks on relations referenced by rules into this separate
function (which I therefore chose to call AcquireRewriteLocks).
This saves effort --- namely, duplicated lock grabs in parser and rewriter
--- in the normal path at a cost of one extra non-locked heap_open()
in the stored-rule path; seems a good tradeoff. A fringe benefit is
that it is now *much* clearer that we acquire lock on relations referenced
in rules before we make any rewriter decisions based on their properties.
(I don't know of any bug of that ilk, but it wasn't exactly clear before.)
Diffstat (limited to 'src/include/nodes/parsenodes.h')
-rw-r--r-- | src/include/nodes/parsenodes.h | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 97d5df935ac..1208def12ce 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.278 2005/04/28 21:47:17 tgl Exp $ + * $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.279 2005/06/03 23:05:29 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -465,7 +465,10 @@ typedef struct DefElem * those columns are known to be dropped at parse time. Again, however, * a stored rule might contain entries for columns dropped since the rule * was created. (This is only possible for columns not actually referenced - * in the rule.) + * in the rule.) When loading a stored rule, we replace the joinaliasvars + * items for any such columns with NULL Consts. (We can't simply delete + * them from the joinaliasvars list, because that would affect the attnums + * of Vars referencing the rest of the list.) * * inh is TRUE for relation references that should be expanded to include * inheritance children, if the rel has any. This *must* be FALSE for @@ -535,7 +538,10 @@ typedef struct RangeTblEntry * to the columns of the join result. An alias Var referencing column * K of the join result can be replaced by the K'th element of * joinaliasvars --- but to simplify the task of reverse-listing - * aliases correctly, we do not do that until planning time. + * aliases correctly, we do not do that until planning time. In a Query + * loaded from a stored rule, it is also possible for joinaliasvars + * items to be NULL Consts, denoting columns dropped since the rule was + * made. */ JoinType jointype; /* type of join */ List *joinaliasvars; /* list of alias-var expansions */ |