]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Use the OP_Sequence opcode for generating unique rowid values for an
authordrh <drh@noemail.net>
Fri, 28 Jun 2019 07:08:13 +0000 (07:08 +0000)
committerdrh <drh@noemail.net>
Fri, 28 Jun 2019 07:08:13 +0000 (07:08 +0000)
autoindex on a co-routine implementation of a subquery.

FossilOrigin-Name: eab4297577e4d325fed4757867fc77860de7448998d86f098c8a50272e17d35e

manifest
manifest.uuid
src/where.c
test/autoindex5.test

index a70f6b5a896049f19315221debd222df28cf8088..a320ae1e9159174faf93d47657cf3192c18602bc 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Ensure\sthat\swhen\san\sephemeral\scursor\sis\sreopened\swith\sa\ssecond\sinvocation\sof\sto\sOP_OpenEphemeral,\sthe\ssequence\scounter\sis\sreset\sand\sthe\scache\smarked\sas\sstale.\sFix\sfor\s[9cdc5c46].
-D 2019-06-26T21:04:30.194
+C Use\sthe\sOP_Sequence\sopcode\sfor\sgenerating\sunique\srowid\svalues\sfor\san\nautoindex\son\sa\sco-routine\simplementation\sof\sa\ssubquery.
+D 2019-06-28T07:08:13.998
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -608,7 +608,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9
 F src/wal.c b09a2a9cab50efa08451a8c81d47052120ad5da174048c6d0b08d405384abdf2
 F src/wal.h 606292549f5a7be50b6227bd685fa76e3a4affad71bb8ac5ce4cb5c79f6a176a
 F src/walker.c 7607f1a68130c028255d8d56094ea602fc402c79e1e35a46e6282849d90d5fe4
-F src/where.c 99c7b718ef846ac952016083aaf4e22ede2290beceaf4730a2df55c023251369
+F src/where.c 2f11eeb14335b7640f886b2fb441f54a94c35ab5cde8b53461a1074bfd587081
 F src/whereInt.h 1b728f71654ebf8421a1715497a587f02d6f538e819af58dc826908f8577e810
 F src/wherecode.c 37a1004237d630d785c47bba2290eac652a7a8b0047518eba3cb7c808b604c4a
 F src/whereexpr.c 5e559bdd24b06e3bc2e68f258bf751302954dc1e432daf71fdd8098a71462326
@@ -672,7 +672,7 @@ F test/autoindex1.test 96185415f5faacd5b8d7a7f505efddd5abb1f111d58338e9c0b1dc40b
 F test/autoindex2.test 12ef578928102baaa0dc23ad397601a2f4ecb0df
 F test/autoindex3.test 2dd997d6590438b53e4f715f9278aa91c9299cf3f81246a0915269c35beb790e
 F test/autoindex4.test 49d3cd791a9baa16fb461d7ea3de80d019a819cf
-F test/autoindex5.test 1d8c1134e1488a35c6fa205b2f52e72fc220972d946c59492d10bba01d6fecd4
+F test/autoindex5.test a5d72fe8c217cc0ea356dc6fa06a282a8a3fc53aa807709d79dba07a8f248102
 F test/autovacuum.test 0831cd34e14695d297187f7f6519265e3121c5b0a1720e548e86829e796129e9
 F test/autovacuum_ioerr2.test 8a367b224183ad801e0e24dcb7d1501f45f244b4
 F test/avtrans.test b7dc25459ecbd86c6fa9c606ee3068f59d81e225118617dcf2bbb6ded2ade89e
@@ -1830,7 +1830,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 1c58522e49cd91426bca7efccf0d99e0f2803dcd5991ae5d56166fc5510e4c62
-R aa86bccf5d83f42eb7e88df9492939da
-U dan
-Z 83cefd86767b67dddce8adaf1f2cbca7
+P 5fd20e09a522b62a529cf4d76fbdf0a09426f67ffa30430cac6b81ebf32ba43e
+R d8e38b1a6647f90f85dd30ba60740431
+U drh
+Z 069759ad3085e2b5f17cc34ec369471a
index 483673e8b2a4174fa338a185e110cdb1686e7849..82a0a5af46c763a84850ae1bfa6825daaa6e7e30 100644 (file)
@@ -1 +1 @@
-5fd20e09a522b62a529cf4d76fbdf0a09426f67ffa30430cac6b81ebf32ba43e
\ No newline at end of file
+eab4297577e4d325fed4757867fc77860de7448998d86f098c8a50272e17d35e
\ No newline at end of file
index b421e4ae93d5a523978bec86c813139f54db7687..f2ab125d2d4b223cb25f190d71172027382fb983 100644 (file)
@@ -562,17 +562,17 @@ static LogEst estLog(LogEst N){
 ** opcodes into OP_Copy when the table is being accessed via co-routine 
 ** instead of via table lookup.
 **
-** If the bIncrRowid parameter is 0, then any OP_Rowid instructions on
-** cursor iTabCur are transformed into OP_Null. Or, if bIncrRowid is non-zero,
-** then each OP_Rowid is transformed into an instruction to increment the
-** value stored in its output register.
+** If the iAutoidxCur is not zero, then any OP_Rowid instructions on
+** cursor iTabCur are transformed into OP_Sequence opcode for the
+** iAutoidxCur cursor, in order to generate unique rowids for the
+** automatic index being generated.
 */
 static void translateColumnToCopy(
   Parse *pParse,      /* Parsing context */
   int iStart,         /* Translate from this opcode to the end */
   int iTabCur,        /* OP_Column/OP_Rowid references to this table */
   int iRegister,      /* The first column is in this register */
-  int bIncrRowid      /* If non-zero, transform OP_rowid to OP_AddImm(1) */
+  int iAutoidxCur     /* If non-zero, cursor of autoindex being generated */
 ){
   Vdbe *v = pParse->pVdbe;
   VdbeOp *pOp = sqlite3VdbeGetOp(v, iStart);
@@ -586,11 +586,9 @@ static void translateColumnToCopy(
       pOp->p2 = pOp->p3;
       pOp->p3 = 0;
     }else if( pOp->opcode==OP_Rowid ){
-      if( bIncrRowid ){
-        /* Increment the value stored in the P2 operand of the OP_Rowid. */
-        pOp->opcode = OP_AddImm;
-        pOp->p1 = pOp->p2;
-        pOp->p2 = 1;
+      if( iAutoidxCur ){
+        pOp->opcode = OP_Sequence;
+        pOp->p1 = iAutoidxCur;
       }else{
         pOp->opcode = OP_Null;
         pOp->p1 = 0;
@@ -864,8 +862,9 @@ static void constructAutomaticIndex(
   if( pTabItem->fg.viaCoroutine ){
     sqlite3VdbeChangeP2(v, addrCounter, regBase+n);
     testcase( pParse->db->mallocFailed );
+    assert( pLevel->iIdxCur>0 );
     translateColumnToCopy(pParse, addrTop, pLevel->iTabCur,
-                          pTabItem->regResult, 1);
+                          pTabItem->regResult, pLevel->iIdxCur);
     sqlite3VdbeGoto(v, addrTop);
     pTabItem->fg.viaCoroutine = 0;
   }else{
index eabdeae4829d697ea61e11a56038911350de6a77..94e220328c159bbe27f917d1094435b5f4b4f52d 100644 (file)
@@ -123,6 +123,20 @@ do_execsql_test 2.1 {
       SELECT sum(z) FROM vvv WHERE x='aaa'
   ) FROM one;
 } {8.0}
+do_execsql_test 2.2 {
+  DROP TABLE t1;
+  CREATE TABLE t1(aaa);
+  INSERT INTO t1(aaa) VALUES(9);
+  SELECT (
+    SELECT aaa FROM t1 GROUP BY (
+      SELECT bbb FROM (
+        SELECT ccc AS bbb FROM (
+           SELECT 1 ccc
+        ) WHERE rowid IS NOT 1
+      ) WHERE bbb = 1
+    )
+  );
+} {9}
 
 # Ticket https://www.sqlite.org/src/info/787fa716be3a7f65
 # Segfault due to multiple uses of the same subquery where the