diff options
author | dan <dan@noemail.net> | 2018-08-03 20:19:52 +0000 |
---|---|---|
committer | dan <dan@noemail.net> | 2018-08-03 20:19:52 +0000 |
commit | a4b5fb55f3985d604ea67e604f53b2b6821bafd7 (patch) | |
tree | 3df72b8aa7d4dec6bbb46d5b614f388c7588192f /src | |
parent | e4fe6d4e628a23863f259fc1500550d315f01fa5 (diff) | |
download | sqlite-a4b5fb55f3985d604ea67e604f53b2b6821bafd7.tar.gz sqlite-a4b5fb55f3985d604ea67e604f53b2b6821bafd7.zip |
Fix the handling of sub-queries with LIMIT clauses by the optimization
activated by compile-time symbol SQLITE_COUNTOFVIEW_OPTIMIZATION.
FossilOrigin-Name: 21235d9a41567897418aa12f7bd6dd8d6ee363147527e1d8fbca14fc83e0f2c9
Diffstat (limited to 'src')
-rw-r--r-- | src/select.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/select.c b/src/select.c index 521e3b4a9..ef3052383 100644 --- a/src/select.c +++ b/src/select.c @@ -5495,6 +5495,7 @@ static struct SrcList_item *isSelfJoinView( ** The transformation only works if all of the following are true: ** ** * The subquery is a UNION ALL of two or more terms +** * The subquery does not have a LIMIT clause ** * There is no WHERE or GROUP BY or HAVING clauses on the subqueries ** * The outer query is a simple count(*) ** @@ -5518,6 +5519,7 @@ static int countOfViewOptimization(Parse *pParse, Select *p){ do{ if( pSub->op!=TK_ALL && pSub->pPrior ) return 0; /* Must be UNION ALL */ if( pSub->pWhere ) return 0; /* No WHERE clause */ + if( pSub->pLimit ) return 0; /* No LIMIT clause */ if( pSub->selFlags & SF_Aggregate ) return 0; /* Not an aggregate */ pSub = pSub->pPrior; /* Repeat over compound */ }while( pSub ); @@ -5779,6 +5781,16 @@ int sqlite3Select( SELECTTRACE(0x100,pParse,p,("Constant propagation not helpful\n")); } +#ifdef SQLITE_COUNTOFVIEW_OPTIMIZATION + if( OptimizationEnabled(db, SQLITE_QueryFlattener|SQLITE_CountOfView) + && countOfViewOptimization(pParse, p) + ){ + if( db->mallocFailed ) goto select_end; + pEList = p->pEList; + pTabList = p->pSrc; + } +#endif + /* For each term in the FROM clause, do two things: ** (1) Authorized unreferenced tables ** (2) Generate code for all sub-queries @@ -5957,16 +5969,6 @@ int sqlite3Select( } #endif -#ifdef SQLITE_COUNTOFVIEW_OPTIMIZATION - if( OptimizationEnabled(db, SQLITE_QueryFlattener|SQLITE_CountOfView) - && countOfViewOptimization(pParse, p) - ){ - if( db->mallocFailed ) goto select_end; - pEList = p->pEList; - pTabList = p->pSrc; - } -#endif - /* If the query is DISTINCT with an ORDER BY but is not an aggregate, and ** if the select-list is the same as the ORDER BY list, then this query ** can be rewritten as a GROUP BY. In other words, this: |