From e2159f384268e01282af60515582943bf595ba7b Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 22 May 2005 22:30:20 +0000 Subject: Teach the planner to remove SubqueryScan nodes from the plan if they aren't doing anything useful (ie, neither selection nor projection). Also, extend to SubqueryScan the hacks already in place to avoid unnecessary ExecProject calls when the result would just be the same tuple the subquery already delivered. This saves some overhead in UNION and other set operations, as well as avoiding overhead for unflatten-able subqueries. Per example from Sokolov Yura. --- src/backend/executor/execScan.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/backend/executor/execScan.c') diff --git a/src/backend/executor/execScan.c b/src/backend/executor/execScan.c index 1e80fa7be0..843aa15101 100644 --- a/src/backend/executor/execScan.c +++ b/src/backend/executor/execScan.c @@ -12,7 +12,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/execScan.c,v 1.35 2005/03/16 21:38:06 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/execScan.c,v 1.36 2005/05/22 22:30:19 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -48,7 +48,6 @@ TupleTableSlot * ExecScan(ScanState *node, ExecScanAccessMtd accessMtd) /* function returning a tuple */ { - EState *estate; ExprContext *econtext; List *qual; ProjectionInfo *projInfo; @@ -58,11 +57,16 @@ ExecScan(ScanState *node, /* * Fetch data from node */ - estate = node->ps.state; - econtext = node->ps.ps_ExprContext; qual = node->ps.qual; projInfo = node->ps.ps_ProjInfo; + /* + * If we have neither a qual to check nor a projection to do, + * just skip all the overhead and return the raw scan tuple. + */ + if (!qual && !projInfo) + return (*accessMtd) (node); + /* * Check to see if we're still projecting out tuples from a previous * scan tuple (because there is a function-returning-set in the @@ -83,6 +87,7 @@ ExecScan(ScanState *node, * storage allocated in the previous tuple cycle. Note this can't * happen until we're done projecting out tuples from a scan tuple. */ + econtext = node->ps.ps_ExprContext; ResetExprContext(econtext); /* -- cgit v1.2.1