aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor/execMain.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2003-02-03 15:07:08 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2003-02-03 15:07:08 +0000
commit4cff59d8d540c441fb0c22dfaa517bc25aa5f794 (patch)
tree88b4c216d219582904d3d9d6a236bb9468fe148c /src/backend/executor/execMain.c
parent0d3e36b6687ae601551fb8047c10a68f2d6fb565 (diff)
downloadpostgresql-4cff59d8d540c441fb0c22dfaa517bc25aa5f794.tar.gz
postgresql-4cff59d8d540c441fb0c22dfaa517bc25aa5f794.zip
Tweak planner and executor to avoid doing ExecProject() in table scan
nodes where it's not really necessary. In many cases where the scan node is not the topmost plan node (eg, joins, aggregation), it's possible to just return the table tuple directly instead of generating an intermediate projection tuple. In preliminary testing, this reduced the CPU time needed for 'SELECT COUNT(*) FROM foo' by about 10%.
Diffstat (limited to 'src/backend/executor/execMain.c')
-rw-r--r--src/backend/executor/execMain.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c
index e1178cd6a69..9c4b6e74819 100644
--- a/src/backend/executor/execMain.c
+++ b/src/backend/executor/execMain.c
@@ -26,7 +26,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.199 2003/01/23 05:10:37 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.200 2003/02/03 15:07:06 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -612,9 +612,11 @@ InitPlan(QueryDesc *queryDesc)
tupType = ExecGetTupType(planstate);
/*
- * Initialize the junk filter if needed. SELECT and INSERT queries
- * need a filter if there are any junk attrs in the tlist. UPDATE and
- * DELETE always need one, since there's always a junk 'ctid'
+ * Initialize the junk filter if needed. SELECT and INSERT queries need a
+ * filter if there are any junk attrs in the tlist. INSERT and SELECT
+ * INTO also need a filter if the top plan node is a scan node that's not
+ * doing projection (else we'll be scribbling on the scan tuple!) UPDATE
+ * and DELETE always need a filter, since there's always a junk 'ctid'
* attribute present --- no need to look first.
*/
{
@@ -635,6 +637,19 @@ InitPlan(QueryDesc *queryDesc)
break;
}
}
+ if (!junk_filter_needed &&
+ (operation == CMD_INSERT || do_select_into))
+ {
+ if (IsA(planstate, SeqScanState) ||
+ IsA(planstate, IndexScanState) ||
+ IsA(planstate, TidScanState) ||
+ IsA(planstate, SubqueryScanState) ||
+ IsA(planstate, FunctionScanState))
+ {
+ if (planstate->ps_ProjInfo == NULL)
+ junk_filter_needed = true;
+ }
+ }
break;
case CMD_UPDATE:
case CMD_DELETE: