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

Do not use the flattening optimization for a sub-query on the RHS of a LEFT

JOIN if that subquery reads data from a virtual table. Because it prevents the
planner from creating an automatic index on the results of the sub-query, the
flattening optimization sometimes slows things down in this case.

FossilOrigin-Name: 9dbae1df75219e2accd8993015ce0ffc21966d7e69d04178b1a2cc46207fe260
This commit is contained in:
dan
2017-07-18 17:34:41 +00:00
parent bbccd52143
commit 46133d98a6
4 changed files with 32 additions and 11 deletions

View File

@@ -3339,8 +3339,9 @@ static void substSelect(
** due to ticket [2f7170d73bf9abf80] from 2015-02-09.)
**
** (3) The subquery is not the right operand of a LEFT JOIN
** or the subquery is not itself a join and the outer query is not
** an aggregate.
** or (a) the subquery is not itself a join and (b) the FROM clause
** of the subquery does not contain a virtual table and (c) the
** outer query is not an aggregate.
**
** (4) The subquery is not DISTINCT.
**
@@ -3545,7 +3546,7 @@ static int flattenSubquery(
*/
if( (pSubitem->fg.jointype & JT_OUTER)!=0 ){
isLeftJoin = 1;
if( pSubSrc->nSrc>1 || isAgg ){
if( pSubSrc->nSrc>1 || isAgg || IsVirtual(pSubSrc->a[0].pTab) ){
return 0; /* Restriction (3) */
}
}