Suppress superfluous OP_OpenTemps when flattening subqueries. (CVS 412)
FossilOrigin-Name: 000441c8fec48cc172894eb767ae9549b8ed8c34
diff --git a/src/select.c b/src/select.c
index fb55a3f..305c3e3 100644
--- a/src/select.c
+++ b/src/select.c
@@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite.
**
-** $Id: select.c,v 1.72 2002/03/03 02:49:51 drh Exp $
+** $Id: select.c,v 1.73 2002/03/03 03:03:53 drh Exp $
*/
#include "sqliteInt.h"
@@ -163,7 +163,7 @@
/* Store the result as data using a unique key.
*/
- if( eDest==SRT_Table ){
+ if( eDest==SRT_Table || eDest==SRT_TempTable ){
sqliteVdbeAddOp(v, OP_MakeRecord, nColumn, 0);
sqliteVdbeAddOp(v, OP_NewRecno, iParm, 0);
sqliteVdbeAddOp(v, OP_Pull, 1, 0);
@@ -1283,8 +1283,7 @@
*/
for(i=0; i<pTabList->nId; i++){
if( pTabList->a[i].pSelect==0 ) continue;
- sqliteVdbeAddOp(v, OP_OpenTemp, base+i, 0);
- sqliteSelect(pParse, pTabList->a[i].pSelect, SRT_Table, base+i,
+ sqliteSelect(pParse, pTabList->a[i].pSelect, SRT_TempTable, base+i,
p, i, &isAgg);
pTabList = p->pSrc;
pWhere = p->pWhere;
@@ -1303,6 +1302,12 @@
return rc;
}
+ /* If the output is destined for a temporary table, open that table.
+ */
+ if( eDest==SRT_TempTable ){
+ sqliteVdbeAddOp(v, OP_OpenTemp, iParm, 0);
+ }
+
/* Do an analysis of aggregate expressions.
*/
sqliteAggregateInfoReset(pParse);
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index bb6ee1a..28b106e 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -11,7 +11,7 @@
*************************************************************************
** Internal interface definitions for SQLite.
**
-** @(#) $Id: sqliteInt.h,v 1.98 2002/03/03 02:49:51 drh Exp $
+** @(#) $Id: sqliteInt.h,v 1.99 2002/03/03 03:03:53 drh Exp $
*/
#include "sqlite.h"
#include "hash.h"
@@ -475,6 +475,7 @@
#define SRT_Union 5 /* Store result as keys in a table */
#define SRT_Except 6 /* Remove result from a UNION table */
#define SRT_Table 7 /* Store result as data with a unique key */
+#define SRT_TempTable 8 /* Store result in a trasient table */
/*
** When a SELECT uses aggregate functions (like "count(*)" or "avg(f1)")