aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2006-08-28 14:32:41 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2006-08-28 14:32:41 +0000
commitfcba3b82e2d4fe42a0acfb9251fd1a7b4862ca30 (patch)
treeaa0eb4f913189b0169254cbc37c548b525d6a5c6
parent88b811044322845aabe8362d7f442a04b1c4dbc7 (diff)
downloadpostgresql-fcba3b82e2d4fe42a0acfb9251fd1a7b4862ca30.tar.gz
postgresql-fcba3b82e2d4fe42a0acfb9251fd1a7b4862ca30.zip
Tweak trivial_subqueryscan() to consider a SubqueryScan's targetlist
trivial if it contains either Vars referencing the corresponding subplan columns, or Consts equaling the corresponding subplan columns. This lets the planner eliminate the SubqueryScan in some cases generated by generate_setop_tlist().
-rw-r--r--src/backend/optimizer/plan/setrefs.c32
1 files changed, 24 insertions, 8 deletions
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 96692544634..3f3a7199417 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/plan/setrefs.c,v 1.124 2006/08/12 02:52:05 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/plan/setrefs.c,v 1.125 2006/08/28 14:32:41 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -448,16 +448,32 @@ trivial_subqueryscan(SubqueryScan *plan)
{
TargetEntry *ptle = (TargetEntry *) lfirst(lp);
TargetEntry *ctle = (TargetEntry *) lfirst(lc);
- Var *var = (Var *) ptle->expr;
if (ptle->resjunk != ctle->resjunk)
return false; /* tlist doesn't match junk status */
- if (!var || !IsA(var, Var))
- return false; /* tlist item not a Var */
- Assert(var->varno == plan->scan.scanrelid);
- Assert(var->varlevelsup == 0);
- if (var->varattno != attrno)
- return false; /* out of order */
+
+ /*
+ * We accept either a Var referencing the corresponding element of
+ * the subplan tlist, or a Const equaling the subplan element.
+ * See generate_setop_tlist() for motivation.
+ */
+ if (ptle->expr && IsA(ptle->expr, Var))
+ {
+ Var *var = (Var *) ptle->expr;
+
+ Assert(var->varno == plan->scan.scanrelid);
+ Assert(var->varlevelsup == 0);
+ if (var->varattno != attrno)
+ return false; /* out of order */
+ }
+ else if (ptle->expr && IsA(ptle->expr, Const))
+ {
+ if (!equal(ptle->expr, ctle->expr))
+ return false;
+ }
+ else
+ return false;
+
attrno++;
}