diff options
Diffstat (limited to 'src/backend/rewrite/rewriteHandler.c')
-rw-r--r-- | src/backend/rewrite/rewriteHandler.c | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/src/backend/rewrite/rewriteHandler.c b/src/backend/rewrite/rewriteHandler.c index 7f527bd74a2..3c7974adc72 100644 --- a/src/backend/rewrite/rewriteHandler.c +++ b/src/backend/rewrite/rewriteHandler.c @@ -91,9 +91,8 @@ static Query *fireRIRrules(Query *parsetree, List *activeRIRs, * such a list in a stored rule to include references to dropped columns. * (If the column is not explicitly referenced anywhere else in the query, * the dependency mechanism won't consider it used by the rule and so won't - * prevent the column drop.) To support get_rte_attribute_is_dropped(), - * we replace join alias vars that reference dropped columns with NULL Const - * nodes. + * prevent the column drop.) To support get_rte_attribute_is_dropped(), we + * replace join alias vars that reference dropped columns with null pointers. * * (In PostgreSQL 8.0, we did not do this processing but instead had * get_rte_attribute_is_dropped() recurse to detect dropped columns in joins. @@ -160,8 +159,8 @@ AcquireRewriteLocks(Query *parsetree, bool forUpdatePushedDown) /* * Scan the join's alias var list to see if any columns have - * been dropped, and if so replace those Vars with NULL - * Consts. + * been dropped, and if so replace those Vars with null + * pointers. * * Since a join has only two inputs, we can expect to see * multiple references to the same input RTE; optimize away @@ -172,16 +171,20 @@ AcquireRewriteLocks(Query *parsetree, bool forUpdatePushedDown) curinputrte = NULL; foreach(ll, rte->joinaliasvars) { - Var *aliasvar = (Var *) lfirst(ll); + Var *aliasitem = (Var *) lfirst(ll); + Var *aliasvar = aliasitem; + + /* Look through any implicit coercion */ + aliasvar = (Var *) strip_implicit_coercions((Node *) aliasvar); /* * If the list item isn't a simple Var, then it must * represent a merged column, ie a USING column, and so it * couldn't possibly be dropped, since it's referenced in - * the join clause. (Conceivably it could also be a NULL - * constant already? But that's OK too.) + * the join clause. (Conceivably it could also be a null + * pointer already? But that's OK too.) */ - if (IsA(aliasvar, Var)) + if (aliasvar && IsA(aliasvar, Var)) { /* * The elements of an alias list have to refer to @@ -205,15 +208,11 @@ AcquireRewriteLocks(Query *parsetree, bool forUpdatePushedDown) if (get_rte_attribute_is_dropped(curinputrte, aliasvar->varattno)) { - /* - * can't use vartype here, since that might be a - * now-dropped type OID, but it doesn't really - * matter what type the Const claims to be. - */ - aliasvar = (Var *) makeNullConst(INT4OID, -1, InvalidOid); + /* Replace the join alias item with a NULL */ + aliasitem = NULL; } } - newaliasvars = lappend(newaliasvars, aliasvar); + newaliasvars = lappend(newaliasvars, aliasitem); } rte->joinaliasvars = newaliasvars; break; |