]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Disable the flattening optimization if the parent query is the recursive part of...
authordan <dan@noemail.net>
Thu, 16 Jan 2014 10:58:39 +0000 (10:58 +0000)
committerdan <dan@noemail.net>
Thu, 16 Jan 2014 10:58:39 +0000 (10:58 +0000)
FossilOrigin-Name: 6bfa387e82de47ca1f40225fe28d873e29d6f481

manifest
manifest.uuid
src/expr.c
src/select.c

index dce447d221877063391d68f1633aeacf55b2ef2d..86132841cd7803c14098dd2dea37f5cba828a811 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Merge\strunk\schanges.\s\sFix\sa\spossible\sNULL-pointer\sdeference\sin\sWITH\sclause\nname\sresolution.
-D 2014-01-16T04:37:13.145
+C Disable\sthe\sflattening\soptimization\sif\sthe\sparent\squery\sis\sthe\srecursive\spart\sof\sa\srecursive\sCTE\sand\sthe\ssub-query\sis\sa\scompound\squery.
+D 2014-01-16T10:58:39.954
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 2ef13430cd359f7b361bb863504e227b25cc7f81
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -175,7 +175,7 @@ F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac
 F src/ctime.c 77779efbe78dd678d84bfb4fc2e87b6b6ad8dccd
 F src/date.c 593c744b2623971e45affd0bde347631bdfa4625
 F src/delete.c 91e1321021db5dc266360531b8b6550009d771ff
-F src/expr.c 36c313049a716c3edcdd99d703f0f16ce96a4cc6
+F src/expr.c c09e34fa7c58995009135b81f83cb62a676ad181
 F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb
 F src/fkey.c 2ab0f5384b70594468ef3ac5c7ed8ca24bfd17d5
 F src/func.c 6325ac2ec10833ccf4d5c36d323709221d37ea19
@@ -219,7 +219,7 @@ F src/printf.c 85d07756e45d7496d19439dcae3e6e9e0090f269
 F src/random.c d10c1f85b6709ca97278428fd5db5bbb9c74eece
 F src/resolve.c ae278d8ce037883323f677e78c241f64289f12ec
 F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0
-F src/select.c c9af659146dd1fe924fbfb14a7477f6b2b90f03b
+F src/select.c 29976d169853492a20d3201e8a83eeefa39a868f
 F src/shell.c 9f3bc02a658b8f61d2cbe60cfc482f660c1c6c48
 F src/sqlite.h.in d94a8b89522f526ba711182ee161e06f8669bcc9
 F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e
@@ -1150,7 +1150,7 @@ F tool/vdbe-compress.tcl 0cf56e9263a152b84da86e75a5c0cdcdb7a47891
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01
 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff
-P c95823cd451f7721174393817a801403647467db f61a70589ac7e05008a362bd9d5b7bde5d07a758
-R 8a379a80b7992f91c6a6d54869d6bc5d
-U drh
-Z 69979a1b738527f03c61f40bf3b0d3cb
+P 7f953b568baa3eede0b9c144be0b9bc86496341a
+R 1f82ce2970e79b42a60992cde0f0f626
+U dan
+Z da04231961fbad92750efdf2d0f0da36
index b6146d545b721bd57f50776851d3e7e00226f026..23deb3b819c8059004e802a32fa22d0aa6f16164 100644 (file)
@@ -1 +1 @@
-7f953b568baa3eede0b9c144be0b9bc86496341a
\ No newline at end of file
+6bfa387e82de47ca1f40225fe28d873e29d6f481
\ No newline at end of file
index 68bb2fe53efe59059d6e88358425b6075a7f4109..897da77ed7af756badd8fc990128254ce70a7508 100644 (file)
@@ -1065,8 +1065,7 @@ Select *sqlite3SelectDup(sqlite3 *db, Select *p, int flags){
   pNew->addrOpenEphm[1] = -1;
   pNew->addrOpenEphm[2] = -1;
   pNew->pWith = withDup(db, p->pWith);
-  assert( p->pRecurse==0 );
-  pNew->pRecurse = 0;
+  pNew->pRecurse = p->pRecurse;
   return pNew;
 }
 #else
index 96eae3ff6a9689f88658bdf14a1f4d2f17c5baa2..c5fb15cd86b55b5e81e83b76181bcb38d2fdd044 100644 (file)
@@ -1849,9 +1849,11 @@ static int multiSelect(
     ** references to the current CTE.  */
     p->pPrior = 0;
     p->pRecurse->tnum = tmp1;
+    assert( (p->pRecurse->tabFlags & TF_Recursive)==0 );
     p->pRecurse->tabFlags |= TF_Recursive;
     rc = sqlite3Select(pParse, p, &tmp2dest);
     p->pRecurse->tabFlags &= ~TF_Recursive;
+    assert( p->pPrior==0 );
     p->pPrior = pPrior;
     if( rc ) goto multi_select_end;
 
@@ -2845,8 +2847,6 @@ static void substSelect(
 **
 ** Flattening is only attempted if all of the following are true:
 **
-**   (0)  The subquery is not a recursive CTE.
-**
 **   (1)  The subquery and the outer query do not both use aggregates.
 **
 **   (2)  The subquery is not an aggregate or the outer query is not a join.
@@ -2930,6 +2930,14 @@ static void substSelect(
 **  (21)  The subquery does not use LIMIT or the outer query is not
 **        DISTINCT.  (See ticket [752e1646fc]).
 **
+**  (22)  The subquery is not a recursive CTE.
+**
+**  (23)  The parent is not a recursive CTE, or the sub-query is not a
+**        compound query. This restriction is because transforming the
+**        parent to a compound query confuses the code that handles
+**        recursive queries in multiSelect().
+**
+**
 ** In this routine, the "p" parameter is a pointer to the outer query.
 ** The subquery is p->pSrc->a[iFrom].  isAgg is true if the outer query
 ** uses aggregates and subqueryIsAgg is true if the subquery uses aggregates.
@@ -2971,7 +2979,6 @@ static int flattenSubquery(
   iParent = pSubitem->iCursor;
   pSub = pSubitem->pSelect;
   assert( pSub!=0 );
-  if( pSub->pRecurse ) return 0;                         /* Restriction (0)  */
   if( isAgg && subqueryIsAgg ) return 0;                 /* Restriction (1)  */
   if( subqueryIsAgg && pSrc->nSrc>1 ) return 0;          /* Restriction (2)  */
   pSubSrc = pSub->pSrc;
@@ -3002,6 +3009,8 @@ static int flattenSubquery(
   if( pSub->pLimit && (p->selFlags & SF_Distinct)!=0 ){
      return 0;         /* Restriction (21) */
   }
+  if( pSub->pRecurse ) return 0;                         /* Restriction (22)  */
+  if( p->pRecurse && pSub->pPrior ) return 0;            /* Restriction (23)  */
 
   /* OBSOLETE COMMENT 1:
   ** Restriction 3:  If the subquery is a join, make sure the subquery is