/ Check-in [823779d3]
Login

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

Overview
Comment:Fix an assertion failure triggered by a SELECT with a compound sub-query that contains an incorrectly placed ORDER BY clause. This problem is just an assert() failure - non-DEBUG builds are not affected. Problem found by OSSFuzz.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 823779d31eb09cda5effe747d9adb35e600a52d4274226586437f674e7824d91
User & Date: dan 2018-03-31 16:31:51
Context
2018-03-31
23:28
Fix a logic error discovered by OSSFuzz that can cause an assert() fault if a LIKE operator is used on an INTEGER PRIMARY KEY. check-in: fc06ddd4 user: drh tags: trunk
16:31
Fix an assertion failure triggered by a SELECT with a compound sub-query that contains an incorrectly placed ORDER BY clause. This problem is just an assert() failure - non-DEBUG builds are not affected. Problem found by OSSFuzz. check-in: 823779d3 user: dan tags: trunk
2018-03-30
16:34
Fix a bug in the spellfix extension causing it to compute suboptimal answers. The problem was introduced by check-in [afd6fbc01052ccfc9]. check-in: 3bf28fd9 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/select.c.

  3769   3769         ** (the only way this can happen is if the compound sub-query is
  3770   3770         ** currently part of pSub->pSrc). See ticket [d11a6e908f].  */
  3771   3771         ExprList *pOrderBy = pSub->pOrderBy;
  3772   3772         for(i=0; i<pOrderBy->nExpr; i++){
  3773   3773           pOrderBy->a[i].u.x.iOrderByCol = 0;
  3774   3774         }
  3775   3775         assert( pParent->pOrderBy==0 );
  3776         -      assert( pSub->pPrior==0 );
  3777   3776         pParent->pOrderBy = pOrderBy;
  3778   3777         pSub->pOrderBy = 0;
  3779   3778       }
  3780   3779       pWhere = sqlite3ExprDup(db, pSub->pWhere, 0);
  3781   3780       if( isLeftJoin>0 ){
  3782   3781         setJoinExpr(pWhere, iNewParent);
  3783   3782       }

Changes to test/subquery2.test.

   143    143   
   144    144     SELECT data, id FROM (
   145    145       SELECT id, data FROM (
   146    146          SELECT * FROM t3 UNION ALL SELECT * FROM t4
   147    147       ) ORDER BY data
   148    148     );
   149    149   } {a 4 b 3 c 2 d 1}
          150  +
          151  +#-------------------------------------------------------------------------
          152  +
          153  +do_execsql_test 4.0 {
          154  +  CREATE TABLE t6(x);
          155  +}
          156  +
          157  +foreach {tn sql} {
          158  +  1 {
          159  +    SELECT 'abc' FROM (
          160  +        SELECT x FROM t6 ORDER BY 1
          161  +        UNION ALL
          162  +        SELECT x FROM t6
          163  +    )
          164  +  }
          165  +  2 {
          166  +    SELECT 'abc' FROM (
          167  +        SELECT x FROM t6
          168  +        UNION ALL
          169  +        SELECT x FROM t6 ORDER BY 1
          170  +        UNION ALL
          171  +        SELECT x FROM t6
          172  +    )
          173  +  }
          174  +  3 {
          175  +    SELECT 'abc' FROM (
          176  +        SELECT x FROM t6 ORDER BY 1
          177  +        UNION ALL
          178  +        SELECT x FROM t6 ORDER BY 1
          179  +        UNION ALL
          180  +        SELECT x FROM t6
          181  +    )
          182  +  }
          183  +  4 {
          184  +    SELECT 'abc' FROM (
          185  +        SELECT x FROM t6
          186  +        UNION ALL
          187  +        SELECT x FROM t6 ORDER BY 1
          188  +        UNION ALL
          189  +        SELECT x FROM t6 ORDER BY 1
          190  +        UNION ALL
          191  +        SELECT x FROM t6
          192  +    )
          193  +  }
          194  +} {
          195  +  do_catchsql_test 4.$tn $sql [list {*}{
          196  +    1 {ORDER BY clause should come after UNION ALL not before}
          197  +  }]
          198  +}
   150    199   
   151    200   
   152    201   finish_test