]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix problems with handling constraints on the rowid column in sqlite3expert.c.
authordan <dan@noemail.net>
Sat, 15 Apr 2017 16:52:12 +0000 (16:52 +0000)
committerdan <dan@noemail.net>
Sat, 15 Apr 2017 16:52:12 +0000 (16:52 +0000)
FossilOrigin-Name: 2e6308798ae2db30564deb35ba3896597448edabbcac6efc4ff084552e42de30

ext/expert/expert1.test
ext/expert/sqlite3expert.c
manifest
manifest.uuid

index 437ba456003a6891841ea9bf305896c30a661277..bcde9b2dfd32f7a0b722c5e1e6cc321f0678d098 100644 (file)
@@ -78,14 +78,14 @@ foreach {tn setup} {
   eval $setup
 
 
-do_setup_rec_test $tn.1.1 { CREATE TABLE t1(a, b, c) } {
+do_setup_rec_test $tn.1 { CREATE TABLE t1(a, b, c) } {
   SELECT * FROM t1
 } {
   (no new indexes)
   0|0|0|SCAN TABLE t1
 }
 
-do_setup_rec_test $tn.1.2 {
+do_setup_rec_test $tn.2 {
   CREATE TABLE t1(a, b, c);
 } {
   SELECT * FROM t1 WHERE b>?;
@@ -94,7 +94,7 @@ do_setup_rec_test $tn.1.2 {
   0|0|0|SEARCH TABLE t1 USING INDEX t1_idx_00000062 (b>?)
 }
 
-do_setup_rec_test $tn.1.3 {
+do_setup_rec_test $tn.3 {
   CREATE TABLE t1(a, b, c);
 } {
   SELECT * FROM t1 WHERE b COLLATE nocase BETWEEN ? AND ?
@@ -103,7 +103,7 @@ do_setup_rec_test $tn.1.3 {
   0|0|0|SEARCH TABLE t1 USING INDEX t1_idx_3e094c27 (b>? AND b<?)
 }
 
-do_setup_rec_test $tn.1.4 {
+do_setup_rec_test $tn.4 {
   CREATE TABLE t1(a, b, c);
 } {
   SELECT a FROM t1 ORDER BY b;
@@ -112,7 +112,7 @@ do_setup_rec_test $tn.1.4 {
   0|0|0|SCAN TABLE t1 USING INDEX t1_idx_00000062
 }
 
-do_setup_rec_test $tn.1.5 {
+do_setup_rec_test $tn.5 {
   CREATE TABLE t1(a, b, c);
 } {
   SELECT a FROM t1 WHERE a=? ORDER BY b;
@@ -121,7 +121,7 @@ do_setup_rec_test $tn.1.5 {
   0|0|0|SEARCH TABLE t1 USING COVERING INDEX t1_idx_000123a7 (a=?)
 }
 
-do_setup_rec_test $tn.1.6 {
+do_setup_rec_test $tn.6 {
   CREATE TABLE t1(a, b, c);
 } {
   SELECT min(a) FROM t1
@@ -130,7 +130,7 @@ do_setup_rec_test $tn.1.6 {
   0|0|0|SEARCH TABLE t1 USING COVERING INDEX t1_idx_00000061
 }
 
-do_setup_rec_test $tn.1.7 {
+do_setup_rec_test $tn.7 {
   CREATE TABLE t1(a, b, c);
 } {
   SELECT * FROM t1 ORDER BY a, b, c;
@@ -148,7 +148,7 @@ do_setup_rec_test $tn.1.7 {
 #  0|0|0|SCAN TABLE t1 USING COVERING INDEX t1_idx_5be6e222
 #}
 
-do_setup_rec_test $tn.1.9 {
+do_setup_rec_test $tn.8.1 {
   CREATE TABLE t1(a COLLATE NOCase, b, c);
 } {
   SELECT * FROM t1 WHERE a=?
@@ -156,8 +156,7 @@ do_setup_rec_test $tn.1.9 {
   CREATE INDEX t1_idx_00000061 ON t1(a);
   0|0|0|SEARCH TABLE t1 USING INDEX t1_idx_00000061 (a=?)
 }
-
-do_setup_rec_test $tn.1.10 {
+do_setup_rec_test $tn.8.2 {
   CREATE TABLE t1(a, b COLLATE nocase, c);
 } {
   SELECT * FROM t1 ORDER BY a ASC, b DESC, c ASC;
@@ -169,7 +168,7 @@ do_setup_rec_test $tn.1.10 {
 
 # Tables with names that require quotes.
 #
-do_setup_rec_test $tn.8.1 {
+do_setup_rec_test $tn.9.1 {
   CREATE TABLE "t t"(a, b, c);
 } {
   SELECT * FROM "t t" WHERE a=?
@@ -178,7 +177,7 @@ do_setup_rec_test $tn.8.1 {
   0|0|0|SEARCH TABLE t t USING INDEX t t_idx_00000061 (a=?) 
 }
 
-do_setup_rec_test $tn.8.2 {
+do_setup_rec_test $tn.9.2 {
   CREATE TABLE "t t"(a, b, c);
 } {
   SELECT * FROM "t t" WHERE b BETWEEN ? AND ?
@@ -189,7 +188,7 @@ do_setup_rec_test $tn.8.2 {
 
 # Columns with names that require quotes.
 #
-do_setup_rec_test $tn.9.1 {
+do_setup_rec_test $tn.10.1 {
   CREATE TABLE t3(a, "b b", c);
 } {
   SELECT * FROM t3 WHERE "b b" = ?
@@ -198,7 +197,7 @@ do_setup_rec_test $tn.9.1 {
   0|0|0|SEARCH TABLE t3 USING INDEX t3_idx_00050c52 (b b=?)
 }
 
-do_setup_rec_test $tn.9.2 {
+do_setup_rec_test $tn.10.2 {
   CREATE TABLE t3(a, "b b", c);
 } {
   SELECT * FROM t3 ORDER BY "b b"
@@ -209,7 +208,7 @@ do_setup_rec_test $tn.9.2 {
 
 # Transitive constraints
 #
-do_setup_rec_test $tn.10.1 {
+do_setup_rec_test $tn.11.1 {
   CREATE TABLE t5(a, b);
   CREATE TABLE t6(c, d);
 } {
@@ -223,7 +222,7 @@ do_setup_rec_test $tn.10.1 {
 
 # OR terms.
 #
-do_setup_rec_test $tn.11.1 {
+do_setup_rec_test $tn.12.1 {
   CREATE TABLE t7(a, b);
 } {
   SELECT * FROM t7 WHERE a=? OR b=?
@@ -234,6 +233,33 @@ do_setup_rec_test $tn.11.1 {
   0|0|0|SEARCH TABLE t7 USING INDEX t7_idx_00000062 (b=?)
 }
 
+# rowid terms.
+#
+do_setup_rec_test $tn.13.1 {
+  CREATE TABLE t8(a, b);
+} {
+  SELECT * FROM t8 WHERE rowid=?
+} {
+  (no new indexes)
+  0|0|0|SEARCH TABLE t8 USING INTEGER PRIMARY KEY (rowid=?)
+}
+do_setup_rec_test $tn.13.2 {
+  CREATE TABLE t8(a, b);
+} {
+  SELECT * FROM t8 ORDER BY rowid
+} {
+  (no new indexes)
+  0|0|0|SCAN TABLE t8
+}
+do_setup_rec_test $tn.13.3 {
+  CREATE TABLE t8(a, b);
+} {
+  SELECT * FROM t8 WHERE a=? ORDER BY rowid
+} {
+  CREATE INDEX t8_idx_00000061 ON t8(a); 
+  0|0|0|SEARCH TABLE t8 USING INDEX t8_idx_00000061 (a=?)
+}
+
 }
 
 finish_test
index 153159fbbf96175d4ff44baaa5e21842f6692f06..ab419d3f08f6ef9fc32997661e6f0cc33a867857 100644 (file)
@@ -365,7 +365,7 @@ static int expertBestIndex(sqlite3_vtab *pVtab, sqlite3_index_info *pIdxInfo){
     /* Add the constraints to the IdxScan object */
     for(i=0; i<pIdxInfo->nConstraint; i++){
       struct sqlite3_index_constraint *pCons = &pIdxInfo->aConstraint[i];
-      if( pCons->usable && (pCons->op & opmask) ){
+      if( pCons->usable && pCons->iColumn>=0 && (pCons->op & opmask) ){
         IdxConstraint *pNew;
         const char *zColl = sqlite3_vtab_collation(dbv, i);
         pNew = idxNewConstraint(&rc, zColl);
@@ -388,14 +388,16 @@ static int expertBestIndex(sqlite3_vtab *pVtab, sqlite3_index_info *pIdxInfo){
     /* Add the ORDER BY to the IdxScan object */
     for(i=pIdxInfo->nOrderBy-1; i>=0; i--){
       int iCol = pIdxInfo->aOrderBy[i].iColumn;
-      IdxConstraint *pNew = idxNewConstraint(&rc, p->pTab->aCol[iCol].zColl);
-      if( pNew ){
-        pNew->iCol = iCol;
-        pNew->bDesc = pIdxInfo->aOrderBy[i].desc;
-        pNew->pNext = pScan->pOrder;
-        pNew->pLink = pScan->pOrder;
-        pScan->pOrder = pNew;
-        n++;
+      if( iCol>=0 ){
+        IdxConstraint *pNew = idxNewConstraint(&rc, p->pTab->aCol[iCol].zColl);
+        if( pNew ){
+          pNew->iCol = iCol;
+          pNew->bDesc = pIdxInfo->aOrderBy[i].desc;
+          pNew->pNext = pScan->pOrder;
+          pNew->pLink = pScan->pOrder;
+          pScan->pOrder = pNew;
+          n++;
+        }
       }
     }
   }
index a544938625b68d13c68f18ba004333c1359768a1..8f2777fd7d6ab6d446e26871adca0f72d464c898 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Merge\slatest\strunk\schanges\sinto\sthis\sbranch.
-D 2017-04-15T15:47:19.800
+C Fix\sproblems\swith\shandling\sconstraints\son\sthe\srowid\scolumn\sin\ssqlite3expert.c.
+D 2017-04-15T16:52:12.782
 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb
 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
 F Makefile.msc 6a8c838220f7c00820e1fc0ac1bccaaa8e5676067e1dbfa1bafa7a4ffecf8ae6
@@ -42,8 +42,8 @@ F ext/async/sqlite3async.c 0f3070cc3f5ede78f2b9361fb3b629ce200d7d74
 F ext/async/sqlite3async.h f489b080af7e72aec0e1ee6f1d98ab6cf2e4dcef
 F ext/expert/README.md 9f15075ec5ad772808eff55ef044c31140fd1146aa0a3c47eafd155e71851b01
 F ext/expert/expert.c 6349cf8d26c847f5f0fa7e25772b614c67f60f3c850dca0d75d55eb27cf3f69b
-F ext/expert/expert1.test cd630eda18a2508eade4c39a1eafe32e7437a33973391e5dddfc7fd0f3163684
-F ext/expert/sqlite3expert.c d4a0a45be58874b4cf54316e5d776726489967140399b1e77a17dbb66558cb38
+F ext/expert/expert1.test c08c95fd81e80073def8bdbf30b67934a9c20193b3632e5f27565ef88f964809
+F ext/expert/sqlite3expert.c d73a4813af4c8097bb574113c91abf9c0ec06a7af47c80227a160a7c413265b5
 F ext/expert/sqlite3expert.h b1c9eedeb647fd734c4206ae6851635284cfbfa5fb688eff74c3265c9f949b4d
 F ext/expert/test_expert.c bad0611732d07180d586bd589cbb7713dc3ab0338c52bff29680eb2007678c05
 F ext/fts1/README.txt 20ac73b006a70bcfd80069bdaf59214b6cf1db5e
@@ -1579,7 +1579,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 d238694ca445ccb4eeb3e3269a5f872f998f795945d0f9dd95c11d0e42d4d538 89f9e4363aa19f306e55f749c442eae2f8994f6a47c65e645a79b308b450d5e5
-R ee849516fe355a9533f6086faf663944
+P 2d0c458e013cb2d02fbeabed8dabd66f55141aac194611f0e599b3c95af1964f
+R d323d2b5ffa5632b2c495cb6bacbb016
 U dan
-Z 67dd241955788961a5e3c1b5613b9072
+Z 2344908fdbfea0ffd0d694cf678615cc
index 69d4418f083c2007c9a2aa9eff1e8748bcb7bea6..afc4462a6ba5e06f4209cceb77bb6346543fa809 100644 (file)
@@ -1 +1 @@
-2d0c458e013cb2d02fbeabed8dabd66f55141aac194611f0e599b3c95af1964f
\ No newline at end of file
+2e6308798ae2db30564deb35ba3896597448edabbcac6efc4ff084552e42de30
\ No newline at end of file