]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Return an error when an xBestIndex() method indicates that it intends to use the...
authordanielk1977 <danielk1977@noemail.net>
Mon, 17 Mar 2008 09:36:44 +0000 (09:36 +0000)
committerdanielk1977 <danielk1977@noemail.net>
Mon, 17 Mar 2008 09:36:44 +0000 (09:36 +0000)
FossilOrigin-Name: ffd470279540b1b8e3fdce6eb14001bae489b16d

manifest
manifest.uuid
src/test8.c
src/where.c
test/vtab6.test

index 33cf8bd9643661946d0e0b09129ec1cf3e00328a..d4a252587906dc6ad6953598f484284b9b3142bd 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Skip\stests\sthat\srequire\ssetting\sdetailed\sunix\spermissions\son\sfiles\swhen\nrunning\son\sfilesystems\ssuch\sas\sAFP\sthat\sdo\snot\ssupport\sthat\scapability.\s(CVS\s4866)
-D 2008-03-15T14:53:05
+C Return\san\serror\swhen\san\sxBestIndex()\smethod\sindicates\sthat\sit\sintends\sto\suse\sthe\svalue\sof\san\sunusable\sconstraint.\sRelated\sto\s#2998.\s(CVS\s4867)
+D 2008-03-17T09:36:45
 F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7
 F Makefile.in 5be94fea84f1599672e5041de03b97990baca593
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -152,7 +152,7 @@ F src/test4.c c2c0f5dc907f1346f5d4b65eb5799f11eb9e4071
 F src/test5.c 3a6a5717a149d7ca2e6d14f5be72cf7555d54dc4
 F src/test6.c f8b34a6ff04937092327798ddf0ab46863535bc5
 F src/test7.c acec2256c7c2d279db5a8b5fa1a2a68fcc942c67
-F src/test8.c 25e127f0e21f59da24fa33cdbc645851cfb933f1
+F src/test8.c 7933b27f8d300512546ef6bdd25f2fe64c3c13f3
 F src/test9.c 4615ef08750245a2d96aaa7cbe2fb4aff2b57acc
 F src/test_async.c 3147c64c34721f088d5ab20f85dabd5d7732c007
 F src/test_autoext.c 855157d97aa28cf84233847548bfacda21807436
@@ -183,7 +183,7 @@ F src/vdbeblob.c 63c750acc7b5012479f508c0e9627372a82cb65d
 F src/vdbefifo.c a30c237b2a3577e1415fb6e288cbb6b8ed1e5736
 F src/vdbemem.c 7a39ad5579e0a9e7305a8fe9a2095840f0ab8454
 F src/vtab.c 00cd16317b29495c185ff40e4b227917d5a371b2
-F src/where.c c5eaca1f2d9caa20c5c7096434ccde2be03b325c
+F src/where.c dd72c822a96967fd7218abec498a70f94986adb0
 F tclinstaller.tcl 4356d9d94d2b5ed5e68f9f0c80c4df3048dd7617
 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
 F test/all.test d12210212bada2bde6d5aeb90969b86c1aa977d2
@@ -530,7 +530,7 @@ F test/vtab2.test 1da49b015582965a8fc386aa23d051a5a622b08e
 F test/vtab3.test f38d6d7d19f08bffdadce4d5b8cba078f8118587
 F test/vtab4.test a9d7104d41a787754a734740d7aa61c807a69f87
 F test/vtab5.test 26bc7a0a52c5c2bcfa849ba327f8a0d4abccdb23
-F test/vtab6.test ec0036f29f8a803da9935206f2d9d1b6a8026392
+F test/vtab6.test 8273e2c6e13c6f8d39b66cb7fc2591f4b97a9d44
 F test/vtab7.test a8c3c3cb3eb60be364991bd714e4927e26c4cd85
 F test/vtab8.test e19fa4a538fcd1bb66c22825fa8f71618fb13583
 F test/vtab9.test ea58d2b95d61955f87226381716b2d0b1d4e4f9b
@@ -623,7 +623,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
 F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
-P 5e4df441815ed7d02e9ad8ee2e1c2f937ee675d7
-R 4fc01bc578742338cb6e67ff251ecd70
-U drh
-Z 787508c13d0cfaee6008fe2953e61687
+P 5589b9d395fb8267a124d56dd5d7987e57505e3d
+R 5404f9fa9fd8ab644119c7147401ab02
+U danielk1977
+Z c0d9e9f0eaef6302049326fc96233904
index 87ad5baee955a5fda486258277381aca85065712..f94a853512fa54239b4e400947099030dd3d9742 100644 (file)
@@ -1 +1 @@
-5589b9d395fb8267a124d56dd5d7987e57505e3d
\ No newline at end of file
+ffd470279540b1b8e3fdce6eb14001bae489b16d
\ No newline at end of file
index 8c49571afa206707b0db8d3add2929ca34d20341..a0749cb22f3cf4d02d7969ddfedaede410cd0820 100644 (file)
@@ -13,7 +13,7 @@
 ** is not included in the SQLite library.  It is used for automated
 ** testing of the SQLite library.
 **
-** $Id: test8.c,v 1.60 2008/02/13 18:25:27 danielk1977 Exp $
+** $Id: test8.c,v 1.61 2008/03/17 09:36:45 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 #include "tcl.h"
@@ -730,6 +730,11 @@ static int echoBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
   int useCost = 0;
   double cost;
 
+  int isIgnoreUsable = 0;
+  if( Tcl_GetVar(interp, "echo_module_ignore_usable", TCL_GLOBAL_ONLY) ){
+    isIgnoreUsable = 1;
+  }
+
   /* Determine the number of rows in the table and store this value in local
   ** variable nRow. The 'estimated-cost' of the scan will be the number of
   ** rows in the table for a linear scan, or the log (base 2) of the 
@@ -768,6 +773,8 @@ static int echoBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
     pConstraint = &pIdxInfo->aConstraint[ii];
     pUsage = &pIdxInfo->aConstraintUsage[ii];
 
+    if( !isIgnoreUsable && !pConstraint->usable ) continue;
+
     iCol = pConstraint->iColumn;
     if( pVtab->aIndex[iCol] ){
       char *zCol = pVtab->aCol[iCol];
index f97f902eacf3c95582e670502f35f435084b65b6..37bf3eec9730260abbf29f3c72a4281a10b4805e 100644 (file)
@@ -16,7 +16,7 @@
 ** so is applicable.  Because this module is responsible for selecting
 ** indices, you might also think of this module as the "query optimizer".
 **
-** $Id: where.c,v 1.288 2008/03/04 17:45:02 mlcreech Exp $
+** $Id: where.c,v 1.289 2008/03/17 09:36:45 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 
@@ -1400,6 +1400,16 @@ static double bestVirtualIndex(
   TRACE_IDX_INPUTS(pIdxInfo);
   rc = pTab->pVtab->pModule->xBestIndex(pTab->pVtab, pIdxInfo);
   TRACE_IDX_OUTPUTS(pIdxInfo);
+  (void)sqlite3SafetyOn(pParse->db);
+
+  for(i=0; i<pIdxInfo->nConstraint; i++){
+    if( !pIdxInfo->aConstraint[i].usable && pUsage[i].argvIndex>0 ){
+      sqlite3ErrorMsg(pParse, 
+          "table %s: xBestIndex returned an invalid plan", pTab->zName);
+      return 0.0;
+    }
+  }
+
   if( rc!=SQLITE_OK ){
     if( rc==SQLITE_NOMEM ){
       pParse->db->mallocFailed = 1;
@@ -1407,7 +1417,6 @@ static double bestVirtualIndex(
       sqlite3ErrorMsg(pParse, "%s", sqlite3ErrStr(rc));
     }
   }
-  (void)sqlite3SafetyOn(pParse->db);
   *(int*)&pIdxInfo->nOrderBy = nOrderBy;
 
   return pIdxInfo->estimatedCost;
index e89ab852b8352173b3e6f3bc8c81310bfecd392b..02994ff7cbe561d20fc0a1fe34b0bef402db31cf 100644 (file)
@@ -14,7 +14,7 @@
 # virtual tables. The test cases in this file are copied from the file
 # join.test, and some of the comments still reflect that.
 #
-# $Id: vtab6.test,v 1.2 2006/06/28 18:18:10 drh Exp $
+# $Id: vtab6.test,v 1.3 2008/03/17 09:36:45 danielk1977 Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -454,4 +454,122 @@ do_test vtab6-10.1 {
 } {}
 } ;# ifcapable subquery
 
+do_test vtab6-11.1.0 {
+  execsql {
+    CREATE TABLE ab_r(a, b);
+    CREATE TABLE bc_r(b, c);
+
+    CREATE VIRTUAL TABLE ab USING echo(ab_r); 
+    CREATE VIRTUAL TABLE bc USING echo(bc_r); 
+
+    INSERT INTO ab VALUES(1, 2);
+    INSERT INTO bc VALUES(2, 3);
+  }
+} {}
+
+do_test vtab6-11.1.1 {
+  execsql {
+    SELECT a, b, c FROM ab NATURAL JOIN bc;
+  }
+} {1 2 3}
+do_test vtab6-11.1.2 {
+  execsql {
+    SELECT a, b, c FROM bc NATURAL JOIN ab;
+  }
+} {1 2 3}
+
+set ::echo_module_cost 1.0
+
+do_test vtab6-11.1.3 {
+  execsql {
+    SELECT a, b, c FROM ab NATURAL JOIN bc;
+  }
+} {1 2 3}
+do_test vtab6-11.1.4 {
+  execsql {
+    SELECT a, b, c FROM bc NATURAL JOIN ab;
+  }
+} {1 2 3}
+
+
+do_test vtab6-11.2.0 {
+  execsql {
+    CREATE INDEX ab_i ON ab_r(b);
+  }
+} {}
+
+unset ::echo_module_cost
+
+do_test vtab6-11.2.1 {
+  execsql {
+    SELECT a, b, c FROM ab NATURAL JOIN bc;
+  }
+} {1 2 3}
+do_test vtab6-11.2.2 {
+  execsql {
+    SELECT a, b, c FROM bc NATURAL JOIN ab;
+  }
+} {1 2 3}
+
+set ::echo_module_cost 1.0
+
+do_test vtab6-11.2.3 {
+  execsql {
+    SELECT a, b, c FROM ab NATURAL JOIN bc;
+  }
+} {1 2 3}
+do_test vtab6-11.2.4 {
+  execsql {
+    SELECT a, b, c FROM bc NATURAL JOIN ab;
+  }
+} {1 2 3}
+
+unset ::echo_module_cost
+db close
+sqlite3 db test.db
+register_echo_module [sqlite3_connection_pointer db]
+
+do_test vtab6-11.3.1 {
+  execsql {
+    SELECT a, b, c FROM ab NATURAL JOIN bc;
+  }
+} {1 2 3}
+
+do_test vtab6-11.3.2 {
+  execsql {
+    SELECT a, b, c FROM bc NATURAL JOIN ab;
+  }
+} {1 2 3}
+
+set ::echo_module_cost 1.0
+
+do_test vtab6-11.3.3 {
+  execsql {
+    SELECT a, b, c FROM ab NATURAL JOIN bc;
+  }
+} {1 2 3}
+do_test vtab6-11.3.4 {
+  execsql {
+    SELECT a, b, c FROM bc NATURAL JOIN ab;
+  }
+} {1 2 3}
+
+unset ::echo_module_cost
+
+set ::echo_module_ignore_usable 1
+db cache flush
+
+do_test vtab6-11.4.1 {
+  catchsql {
+    SELECT a, b, c FROM ab NATURAL JOIN bc;
+  }
+} {1 {table ab: xBestIndex returned an invalid plan}}
+do_test vtab6-11.4.2 {
+  catchsql {
+    SELECT a, b, c FROM bc NATURAL JOIN ab;
+  }
+} {1 {table ab: xBestIndex returned an invalid plan}}
+
+unset ::echo_module_ignore_usable
+
 finish_test