]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Do not allow automatic indices for the RHS of IN expressions which are not
authordrh <drh@noemail.net>
Wed, 28 Jul 2010 02:53:36 +0000 (02:53 +0000)
committerdrh <drh@noemail.net>
Wed, 28 Jul 2010 02:53:36 +0000 (02:53 +0000)
correlated subqueries.  Ticket [8011086c85c6c404014c9]

FossilOrigin-Name: 267492d3a7eff7b7b24ed6bd6d6ff55148fe37f3

manifest
manifest.uuid
src/expr.c
test/autoindex1.test

index 3a65142d27e6564c94dd394b4c0ed443d9b70270..1bc984af6c790e18d5a733b00e935f0338ff5605 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,8 +1,8 @@
 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1
 
-C Update\sthe\smakefiles\sto\sprefer\sTCL\sversion\s8.5\sinstead\sof\s8.4.
-D 2010-07-27T16:42:23
+C Do\snot\sallow\sautomatic\sindices\sfor\sthe\sRHS\sof\sIN\sexpressions\swhich\sare\snot\ncorrelated\ssubqueries.\s\sTicket\s[8011086c85c6c404014c9]
+D 2010-07-28T02:53:37
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in ec08dc838fd8110fe24c92e5130bcd91cbb1ff2e
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -125,7 +125,7 @@ F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac
 F src/ctime.c 4f3aadad62c6c9f0d4e5a96718516ac4e3c598df
 F src/date.c 5dd8448a0bfea8d31fb14cff487d0c06ff8c8b20
 F src/delete.c 7ed8a8c8b5f748ece92df173d7e0f7810c899ebd
-F src/expr.c 7490fc3b16414d1a45d5acadf559317f9244891f
+F src/expr.c a0fd9c5e248229851077de92f2e9346f2c43ed46
 F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb
 F src/fkey.c cacfe3e24b311e4e089a9c470bdb73196af6f729
 F src/func.c 75dc1fd91e5692cadb80d257bab68d7343060467
@@ -258,7 +258,7 @@ F test/auth.test 8f21c160a4562f54f27618e85bac869efcecbcaf
 F test/auth2.test 270baddc8b9c273682760cffba6739d907bd2882
 F test/auth3.test a4755e6a2a2fea547ffe63c874eb569e60a28eb5
 F test/autoinc.test 85ef3180a737e6580086a018c09c6f1a52759b46
-F test/autoindex1.test ffb06a246e2c1f89cfbe3d93eca513c9e78d4063
+F test/autoindex1.test 7df441bf0e7a88644eb80993339dbf1db3a12c68
 F test/autovacuum.test bb7c0885e6f8f1d633045de48f2b66082162766d
 F test/autovacuum_ioerr2.test 598b0663074d3673a9c1bc9a16e80971313bafe6
 F test/avtrans.test 0252654f4295ddda3b2cce0e894812259e655a85
@@ -841,14 +841,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P 6df081adbfa581c477bd2c96bb3f7f44be131a8f
-R 2e30ee83ed26c6b6d858b65a1a40368a
+P 8118de2af33557f75b4f2f1b1194a21d46ccf7fe
+R 40c9c305c287d6d5baa795d30f2cf9ee
 U drh
-Z 7c9b71a765785eb5366a775431acbda9
+Z 937ef6a9e9466c178b83c982e778c20e
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.6 (GNU/Linux)
 
-iD8DBQFMTwxyoxKgR168RlERAoWhAKCIJmTkn9tifBBxLWcZZSTjSKv7hQCghz7k
-L9/hegUPu/Ry2mCj4VCVOlE=
-=kcSH
+iD8DBQFMT5u2oxKgR168RlERAsjPAJ4pDaNKroaW8Tnm1cU0jDkzKN0KwACePYGJ
+C5ZTN2Lh/obd8jivM7gzwas=
+=32EK
 -----END PGP SIGNATURE-----
index c1bb427adf8ec57ce7236eb10660c3c2b0593c20..6ff279484e712157e548e35455a9d0eb3b1ea932 100644 (file)
@@ -1 +1 @@
-8118de2af33557f75b4f2f1b1194a21d46ccf7fe
\ No newline at end of file
+267492d3a7eff7b7b24ed6bd6d6ff55148fe37f3
\ No newline at end of file
index bd28bf93944532be8d73ddca8694f9297ffa420f..153751f7cd51db8d64822a614e33414ac108c8de 100644 (file)
@@ -1512,14 +1512,20 @@ int sqlite3FindInIndex(Parse *pParse, Expr *pX, int *prNotFound){
     /* Could not found an existing table or index to use as the RHS b-tree.
     ** We will have to generate an ephemeral table to do the job.
     */
+    double savedNQueryLoop = pParse->nQueryLoop;
     int rMayHaveNull = 0;
     eType = IN_INDEX_EPH;
     if( prNotFound ){
       *prNotFound = rMayHaveNull = ++pParse->nMem;
-    }else if( pX->pLeft->iColumn<0 && !ExprHasAnyProperty(pX, EP_xIsSelect) ){
-      eType = IN_INDEX_ROWID;
+    }else{
+      testcase( pParse->nQueryLoop>(double)1 );
+      pParse->nQueryLoop = (double)1;
+      if( pX->pLeft->iColumn<0 && !ExprHasAnyProperty(pX, EP_xIsSelect) ){
+        eType = IN_INDEX_ROWID;
+      }
     }
     sqlite3CodeSubselect(pParse, pX, rMayHaveNull, eType==IN_INDEX_ROWID);
+    pParse->nQueryLoop = savedNQueryLoop;
   }else{
     pX->iTable = iTab;
   }
index 96b4f1a63afc032e1c48ea070552452706fb84fc..40e1936cd912ea2ad55a8bab11a28a5dd7e76063 100644 (file)
@@ -136,4 +136,34 @@ do_test autoindex1-401 {
   }
 } {4087}
 
+# Ticket [8011086c85c6c404014c947fcf3eb9f42b184a0d] from 2010-07-08
+# Make sure automatic indices are not created for the RHS of an IN expression
+# that is not a correlated subquery.
+#
+do_test autoindex1-500 {
+  db eval {
+    CREATE TABLE t501(a INTEGER PRIMARY KEY, b);
+    CREATE TABLE t502(x INTEGER PRIMARY KEY, y);
+    EXPLAIN QUERY PLAN
+    SELECT b FROM t501
+     WHERE t501.a IN (SELECT x FROM t502 WHERE y=?);
+  }
+} {0 0 {TABLE t501 USING PRIMARY KEY} 0 0 {TABLE t502}}
+do_test autoindex1-501 {
+  db eval {
+    EXPLAIN QUERY PLAN
+    SELECT b FROM t501
+     WHERE t501.a IN (SELECT x FROM t502 WHERE y=t501.b);
+  }
+} {0 0 {TABLE t501} 0 0 {TABLE t502 WITH AUTOMATIC INDEX}}
+do_test autoindex1-502 {
+  db eval {
+    EXPLAIN QUERY PLAN
+    SELECT b FROM t501
+     WHERE t501.a=123
+       AND t501.a IN (SELECT x FROM t502 WHERE y=t501.b);
+  }
+} {0 0 {TABLE t501 USING PRIMARY KEY} 0 0 {TABLE t502}}
+    
+
 finish_test