]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix an invalid assert() in where.c. Also a crash that can occur in the EXPLAIN QUERY...
authordan <dan@noemail.net>
Tue, 20 Aug 2013 17:14:57 +0000 (17:14 +0000)
committerdan <dan@noemail.net>
Tue, 20 Aug 2013 17:14:57 +0000 (17:14 +0000)
FossilOrigin-Name: ef192abb82c2fc31135f875d7a19908d67c076b0

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

index f7304e3316ffee8380c0a324581fd5bb368bc785..58ac190c9800a2401d26c0c1a49961ea2d4ad40c 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Ignore\sIS\sNOT\sNULL\sand\sNOT\sNULL\sconstraints\son\sNOT\sNULL\scolumns.
-D 2013-08-20T17:00:55.048
+C Fix\san\sinvalid\sassert()\sin\swhere.c.\sAlso\sa\scrash\sthat\scan\soccur\sin\sthe\sEXPLAIN\sQUERY\sPLAN\scode\sunder\sobscure\scircumstances.
+D 2013-08-20T17:14:57.137
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -290,7 +290,7 @@ F src/vtab.c 2e8b489db47e20ae36cd247932dc671c9ded0624
 F src/wal.c 7dc3966ef98b74422267e7e6e46e07ff6c6eb1b4
 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4
 F src/walker.c 4fa43583d0a84b48f93b1e88f11adf2065be4e73
-F src/where.c 1a020a02c9062af8de011427461d1fb515dbba97
+F src/where.c 0ced8882cadbf1817904331a5d942b30ebe0e789
 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
 F test/aggnested.test 45c0201e28045ad38a530b5a144b73cd4aa2cfd6
@@ -591,7 +591,7 @@ F test/index3.test 423a25c789fc8cc51aaf2a4370bbdde2d9e9eed7
 F test/index4.test 2983216eb8c86ee62d9ed7cb206b5cc3331c0026
 F test/index5.test fc07c14193c0430814e7a08b5da46888ee795c33
 F test/index6.test f53a788b813eb6937346867bae9e587c434dd9a1
-F test/indexedby.test 0e959308707c808515c3a51363f7a9835027108c
+F test/indexedby.test b2f22f3e693a53813aa3f50b812eb609ba6df1ec
 F test/indexfault.test 31d4ab9a7d2f6e9616933eb079722362a883eb1d
 F test/init.test 15c823093fdabbf7b531fe22cf037134d09587a7
 F test/insert.test 489aa12a027c83d291f5034a83c8c32e6be1dca2
@@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae
 F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac
-P 0cede9f898bcd13dab51b25cb0e72213d988d3d2
-R 725f0aaaf1dfad075e5c9084063c2a98
-U drh
-Z e9e50abe87d60d38c6172ae130ead1c3
+P e476408e3c5ba5f3ba5e98ff264167c163d72e3f
+R 44efbb8237f8929e6aff522c9e736888
+U dan
+Z 8bb1f7038ca62fa90bbb1e1bf6c35d10
index 74afdfb909eb45900c22fa8a23ae27aa28b021f8..0e3f98b8b0312f75e9cc273d2e37e3ac5690822c 100644 (file)
@@ -1 +1 @@
-e476408e3c5ba5f3ba5e98ff264167c163d72e3f
\ No newline at end of file
+ef192abb82c2fc31135f875d7a19908d67c076b0
\ No newline at end of file
index 8f6494af682541fe44a0e442fadeec5c34862fdd..23a35fa79062d87d46a8c1a815b3486a4b9818ef 100644 (file)
@@ -3029,7 +3029,7 @@ static int codeAllEqualityTerms(
 
   /* Evaluate the equality constraints
   */
-  assert( pIdx->nColumn>=nEq );
+  assert( zAff==0 || strlen(zAff)>=nEq );
   for(j=0; j<nEq; j++){
     int r1;
     pTerm = pLoop->aLTerm[j];
@@ -3121,7 +3121,8 @@ static char *explainIndexRange(sqlite3 *db, WhereLoop *pLoop, Table *pTab){
   txt.db = db;
   sqlite3StrAccumAppend(&txt, " (", 2);
   for(i=0; i<nEq; i++){
-    explainAppendTerm(&txt, i, aCol[aiColumn[i]].zName, "=");
+    char *z = (i==pIndex->nColumn ) ? "rowid" : aCol[aiColumn[i]].zName;
+    explainAppendTerm(&txt, i, z, "=");
   }
 
   j = i;
index 5193da40ce14218acb5ad07066262ddaf6269cd1..f95c167f6411c0fb5f003ca4d9bc93995ec95c18 100644 (file)
@@ -13,6 +13,7 @@
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
+set ::testprefix indexedby
 
 # Create a schema with some indexes.
 #
@@ -274,4 +275,50 @@ do_test indexedby-10.3 {
   }
 } {1}
 
+#-------------------------------------------------------------------------
+# Ensure that the rowid at the end of each index entry may be used
+# for equality constraints in the same way as other indexed fields.
+#
+do_execsql_test 11.1 {
+  CREATE TABLE x1(a, b TEXT);
+  CREATE INDEX x1i ON x1(a, b);
+  INSERT INTO x1 VALUES(1, 1);
+  INSERT INTO x1 VALUES(1, 1);
+  INSERT INTO x1 VALUES(1, 1);
+  INSERT INTO x1 VALUES(1, 1);
+}
+do_execsql_test 11.2 {
+  SELECT a,b,rowid FROM x1 INDEXED BY x1i WHERE a=1 AND b=1 AND rowid=3;
+} {1 1 3}
+do_execsql_test 11.3 {
+  SELECT a,b,rowid FROM x1 INDEXED BY x1i WHERE a=1 AND b=1 AND rowid='3';
+} {1 1 3}
+do_execsql_test 11.4 {
+  SELECT a,b,rowid FROM x1 INDEXED BY x1i WHERE a=1 AND b=1 AND rowid='3.0';
+} {1 1 3}
+do_eqp_test 11.5 {
+  SELECT a,b,rowid FROM x1 INDEXED BY x1i WHERE a=1 AND b=1 AND rowid='3.0';
+} {0 0 0 {SEARCH TABLE x1 USING COVERING INDEX x1i (a=? AND b=? AND rowid=?)}}
+
+do_execsql_test 11.6 {
+  CREATE TABLE x2(c INTEGER PRIMARY KEY, a, b TEXT);
+  CREATE INDEX x2i ON x2(a, b);
+  INSERT INTO x2 VALUES(1, 1, 1);
+  INSERT INTO x2 VALUES(2, 1, 1);
+  INSERT INTO x2 VALUES(3, 1, 1);
+  INSERT INTO x2 VALUES(4, 1, 1);
+}
+do_execsql_test 11.7 {
+  SELECT a,b,c FROM x2 INDEXED BY x2i WHERE a=1 AND b=1 AND c=3;
+} {1 1 3}
+do_execsql_test 11.8 {
+  SELECT a,b,c FROM x2 INDEXED BY x2i WHERE a=1 AND b=1 AND c='3';
+} {1 1 3}
+do_execsql_test 11.9 {
+  SELECT a,b,c FROM x2 INDEXED BY x2i WHERE a=1 AND b=1 AND c='3.0';
+} {1 1 3}
+do_eqp_test 11.10 {
+  SELECT a,b,c FROM x2 INDEXED BY x2i WHERE a=1 AND b=1 AND c='3.0';
+} {0 0 0 {SEARCH TABLE x2 USING COVERING INDEX x2i (a=? AND b=? AND rowid=?)}}
+
 finish_test