/ Check-in [66629b2a]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Remove a redundant restriction from the query flattener.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 66629b2a0997ceedcfb38553f2200466b6c4e352ea00f8a0a7cb67a660c19523
User & Date: drh 2017-10-04 05:59:54
Context
2017-10-04
10:39
Add tests to verify that the busy-handler is invoked correctly when processing "PRAGMA optimize" and ANALYZE commands. check-in: fb83c3d8 user: dan tags: trunk
05:59
Remove a redundant restriction from the query flattener. check-in: 66629b2a user: drh tags: trunk
02:30
Fix a minor typo in the query flattener header comment. No code changes. check-in: d050dc60 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/select.c.

  3389   3389   **        have other optimizations in mind to deal with that case.
  3390   3390   **
  3391   3391   **  (21)  If the subquery uses LIMIT then the outer query may not be
  3392   3392   **        DISTINCT.  (See ticket [752e1646fc]).
  3393   3393   **
  3394   3394   **  (22)  The subquery may not be a recursive CTE.
  3395   3395   **
  3396         -**  (23)  If the outer query is a recursive CTE, then the sub-query may not be
  3397         -**        a compound query. This restriction is because transforming the
         3396  +**  (**)  Subsumed into restriction (17d3).  Was: If the outer query is
         3397  +**        a recursive CTE, then the sub-query may not be a compound query.
         3398  +**        This restriction is because transforming the
  3398   3399   **        parent to a compound query confuses the code that handles
  3399   3400   **        recursive queries in multiSelect().
  3400   3401   **
  3401   3402   **  (**)  We no longer attempt to flatten aggregate subqueries.  Was:
  3402   3403   **        The subquery may not be an aggregate that uses the built-in min() or 
  3403   3404   **        or max() functions.  (Without this restriction, a query like:
  3404   3405   **        "SELECT x FROM (SELECT max(y), x FROM t1)" would not necessarily
................................................................................
  3471   3472     if( pSub->pLimit && p->pWhere ) return 0;              /* Restriction (19) */
  3472   3473     if( pSub->pLimit && (p->selFlags & SF_Distinct)!=0 ){
  3473   3474        return 0;         /* Restriction (21) */
  3474   3475     }
  3475   3476     if( pSub->selFlags & (SF_Recursive) ){
  3476   3477       return 0; /* Restrictions (22) */
  3477   3478     }
  3478         -  if( (p->selFlags & SF_Recursive) && pSub->pPrior ){
  3479         -    return 0; /* Restriction (23) */
  3480         -  }
  3481   3479   
  3482   3480     /*
  3483   3481     ** If the subquery is the right operand of a LEFT JOIN, then the
  3484   3482     ** subquery may not be a join itself (3a). Example of why this is not
  3485   3483     ** allowed:
  3486   3484     **
  3487   3485     **         t1 LEFT OUTER JOIN (t2 JOIN t3)
................................................................................
  3547   3545         int ii;
  3548   3546         for(ii=0; ii<p->pOrderBy->nExpr; ii++){
  3549   3547           if( p->pOrderBy->a[ii].u.x.iOrderByCol==0 ) return 0;
  3550   3548         }
  3551   3549       }
  3552   3550     }
  3553   3551   
         3552  +  /* Ex-restriction (23):
         3553  +  ** The only way that the recursive part of a CTE can contain a compound
         3554  +  ** subquery is for the subquery to be one term of a join.  But if the
         3555  +  ** subquery is a join, then the flattening has already been stopped by
         3556  +  ** restriction (17d3)
         3557  +  */
         3558  +  assert( (p->selFlags & SF_Recursive)==0 || pSub->pPrior==0 );
         3559  +
  3554   3560     /***** If we reach this point, flattening is permitted. *****/
  3555   3561     SELECTTRACE(1,pParse,p,("flatten %s.%p from term %d\n",
  3556   3562                      pSub->zSelName, pSub, iFrom));
  3557   3563   
  3558   3564     /* Authorize the subquery */
  3559   3565     pParse->zAuthContext = pSubitem->zName;
  3560   3566     TESTONLY(i =) sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0);