1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-05 07:21:24 +03:00

Improve has_nullable_targetlist() to allow strict functions of simple

variables, not just simple variables.  This was foreseen in the original
coding of this routine, but not implemented until now.  Responds to
performance gripe from Laurent Perez.
This commit is contained in:
Tom Lane
2004-01-10 18:13:53 +00:00
parent 47f8f33409
commit a43f4307f7
2 changed files with 36 additions and 28 deletions

View File

@ -16,7 +16,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/prep/prepjointree.c,v 1.15 2004/01/10 00:30:21 tgl Exp $
* $PostgreSQL: pgsql/src/backend/optimizer/prep/prepjointree.c,v 1.16 2004/01/10 18:13:53 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -439,11 +439,13 @@ is_simple_subquery(Query *subquery)
/*
* has_nullable_targetlist
* Check a subquery in the range table to see if all the non-junk
* targetlist items are simple variables (and, hence, will correctly
* go to NULL when examined above the point of an outer join).
* targetlist items are simple variables or strict functions of simple
* variables (and, hence, will correctly go to NULL when examined above
* the point of an outer join).
*
* A possible future extension is to accept strict functions of simple
* variables, eg, "x + 1".
* NOTE: it would be correct (and useful) to ignore output columns that aren't
* actually referenced by the enclosing query ... but we do not have that
* information available at this point.
*/
static bool
has_nullable_targetlist(Query *subquery)
@ -458,11 +460,15 @@ has_nullable_targetlist(Query *subquery)
if (tle->resdom->resjunk)
continue;
/* Okay if tlist item is a simple Var */
if (tle->expr && IsA(tle->expr, Var))
continue;
/* Must contain a Var of current level */
if (!contain_vars_of_level((Node *) tle->expr, 0))
return false;
return false;
/* Must not contain any non-strict constructs */
if (contain_nonstrict_functions((Node *) tle->expr))
return false;
/* This one's OK, keep scanning */
}
return true;
}