Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Suppress superfluous OP_OpenTemps when flattening subqueries. (CVS 412) |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
000441c8fec48cc172894eb767ae9549 |
User & Date: | drh 2002-03-03 03:03:53.000 |
Context
2002-03-03
| ||
03:11 | Additional tests of flattening (CVS 413) (check-in: e1d93c5923 user: drh tags: trunk) | |
03:03 | Suppress superfluous OP_OpenTemps when flattening subqueries. (CVS 412) (check-in: 000441c8fe user: drh tags: trunk) | |
02:49 | Bug fixes and additional tests for the subquery flattener. (CVS 411) (check-in: 2c05389eda user: drh tags: trunk) | |
Changes
Changes to src/select.c.
︙ | ︙ | |||
8 9 10 11 12 13 14 | ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** This file contains C code routines that are called by the parser ** to handle SELECT statements in SQLite. ** | | | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** This file contains C code routines that are called by the parser ** to handle SELECT statements in SQLite. ** ** $Id: select.c,v 1.73 2002/03/03 03:03:53 drh Exp $ */ #include "sqliteInt.h" /* ** Allocate a new Select structure and return a pointer to that ** structure. */ |
︙ | ︙ | |||
159 160 161 162 163 164 165 | sqliteVdbeAddOp(v, OP_MakeRecord, nColumn, 0); sqliteVdbeAddOp(v, OP_String, iParm, 0); sqliteVdbeAddOp(v, OP_PutStrKey, iParm, 0); }else /* Store the result as data using a unique key. */ | | | 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | sqliteVdbeAddOp(v, OP_MakeRecord, nColumn, 0); sqliteVdbeAddOp(v, OP_String, iParm, 0); sqliteVdbeAddOp(v, OP_PutStrKey, iParm, 0); }else /* Store the result as data using a unique key. */ 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); sqliteVdbeAddOp(v, OP_PutIntKey, iParm, 0); }else /* Construct a record from the query result, but instead of |
︙ | ︙ | |||
1279 1280 1281 1282 1283 1284 1285 | v = sqliteGetVdbe(pParse); if( v==0 ) goto select_end; /* Generate code for all sub-queries in the FROM clause */ for(i=0; i<pTabList->nId; i++){ if( pTabList->a[i].pSelect==0 ) continue; | < | > > > > > > | 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 | v = sqliteGetVdbe(pParse); if( v==0 ) goto select_end; /* Generate code for all sub-queries in the FROM clause */ for(i=0; i<pTabList->nId; i++){ if( pTabList->a[i].pSelect==0 ) continue; sqliteSelect(pParse, pTabList->a[i].pSelect, SRT_TempTable, base+i, p, i, &isAgg); pTabList = p->pSrc; pWhere = p->pWhere; pOrderBy = p->pOrderBy; pGroupBy = p->pGroupBy; pHaving = p->pHaving; isDistinct = p->isDistinct; } /* Check to see if this is a subquery that can be "flattened" into its parent. ** If flattening is a possiblity, do so and return immediately. */ if( pParent && pParentAgg && flattenSubquery(pParent, parentTab, *pParentAgg, isAgg) ){ if( isAgg ) *pParentAgg = 1; 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); if( isAgg ){ assert( pParse->nAgg==0 ); for(i=0; i<pEList->nExpr; i++){ |
︙ | ︙ |
Changes to src/sqliteInt.h.
1 2 3 4 5 6 7 8 9 10 11 12 13 | /* ** 2001 September 15 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** Internal interface definitions for SQLite. ** | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | /* ** 2001 September 15 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** Internal interface definitions for SQLite. ** ** @(#) $Id: sqliteInt.h,v 1.99 2002/03/03 03:03:53 drh Exp $ */ #include "sqlite.h" #include "hash.h" #include "vdbe.h" #include "parse.h" #include "btree.h" #include <stdio.h> |
︙ | ︙ | |||
471 472 473 474 475 476 477 478 479 480 481 482 483 484 | */ #define SRT_Callback 1 /* Invoke a callback with each row of result */ #define SRT_Mem 2 /* Store result in a memory cell */ #define SRT_Set 3 /* Store result as unique keys in a table */ #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 */ /* ** When a SELECT uses aggregate functions (like "count(*)" or "avg(f1)") ** we have to do some additional analysis of expressions. An instance ** of the following structure holds information about a single subexpression ** somewhere in the SELECT statement. An array of these structures holds ** all the information we need to generate code for aggregate | > | 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 | */ #define SRT_Callback 1 /* Invoke a callback with each row of result */ #define SRT_Mem 2 /* Store result in a memory cell */ #define SRT_Set 3 /* Store result as unique keys in a table */ #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)") ** we have to do some additional analysis of expressions. An instance ** of the following structure holds information about a single subexpression ** somewhere in the SELECT statement. An array of these structures holds ** all the information we need to generate code for aggregate |
︙ | ︙ |
Changes to test/select6.test.
︙ | ︙ | |||
8 9 10 11 12 13 14 | # May you share freely, never taking more than you give. # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this file is testing SELECT statements that contain # subqueries in their FROM clause. # | | | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | # May you share freely, never taking more than you give. # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this file is testing SELECT statements that contain # subqueries in their FROM clause. # # $Id: select6.test,v 1.4 2002/03/03 03:03:54 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl do_test select6-1.0 { execsql { BEGIN; |
︙ | ︙ | |||
259 260 261 262 263 264 265 266 267 268 | } } {1 2 3 4} do_test select6-4.3 { execsql { SELECT DISTINCT y FROM (SELECT y FROM t1) WHERE y<5 ORDER BY y } } {1 2 3 4} finish_test | > > > > > > > > > > | 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | } } {1 2 3 4} do_test select6-4.3 { execsql { SELECT DISTINCT y FROM (SELECT y FROM t1) WHERE y<5 ORDER BY y } } {1 2 3 4} do_test select6-4.4 { execsql { SELECT avg(y) FROM (SELECT DISTINCT y FROM t1) WHERE y<5 ORDER BY y } } {2.5} do_test select6-4.5 { execsql { SELECT avg(y) FROM (SELECT DISTINCT y FROM t1 WHERE y<5) ORDER BY y } } {2.5} finish_test |