1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-12 13:01:09 +03:00

Implement FROM-clause subqueries as co-routines whenever they are guaranteed

to be the outer-most loop of the join.

FossilOrigin-Name: c7bae50bdccb5bcf3bc22e8ac5bb6725ef13db39
This commit is contained in:
drh
2016-03-15 17:52:12 +00:00
parent 82f525406a
commit 0ff47e9e1b
4 changed files with 61 additions and 12 deletions

View File

@@ -4970,10 +4970,24 @@ int sqlite3Select(
}
/* Generate code to implement the subquery
**
** The subquery is implemented as a co-routine if all of these are true:
** (1) The subquery is guaranteed to be the outer loop (so that it
** does not need to be computed more than once)
** (2) The ALL keyword after SELECT is omitted. (Applications are
** allowed to say "SELECT ALL" instead of just "SELECT" to disable
** the use of co-routines.)
** (3) Co-routines are not disabled using sqlite3_test_control()
** with SQLITE_TESTCTRL_OPTIMIZATIONS.
**
** TODO: Are there other reasons beside (1) to use a co-routine
** implementation?
*/
if( pTabList->nSrc==1
&& (p->selFlags & SF_All)==0
&& OptimizationEnabled(db, SQLITE_SubqCoroutine)
if( i==0
&& (pTabList->nSrc==1
|| (pTabList->a[1].fg.jointype&(JT_LEFT|JT_CROSS))!=0) /* (1) */
&& (p->selFlags & SF_All)==0 /* (2) */
&& OptimizationEnabled(db, SQLITE_SubqCoroutine) /* (3) */
){
/* Implement a co-routine that will return a single row of the result
** set on each invocation.