]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Coverage improvements for where.c. (CVS 3764)
authordanielk1977 <danielk1977@noemail.net>
Fri, 30 Mar 2007 14:56:34 +0000 (14:56 +0000)
committerdanielk1977 <danielk1977@noemail.net>
Fri, 30 Mar 2007 14:56:34 +0000 (14:56 +0000)
FossilOrigin-Name: 7e0aa964129612e2bad6fa45139d124f19cacd48

manifest
manifest.uuid
src/test8.c
src/where.c
test/misc7.test
test/vtab1.test

index ed247c742923ed70bb183da81db02fc1ff69a17a..f174cee4e3968c5b2fcf4a8b9b2f09297b5783a5 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Tease\sapart\sthe\stwo\sphases\sof\spager\scommit.\s(CVS\s3763)
-D 2007-03-30T14:46:01
+C Coverage\simprovements\sfor\swhere.c.\s(CVS\s3764)
+D 2007-03-30T14:56:35
 F Makefile.in 2f2c3bf69faf0ae7b8e8af4f94f1986849034530
 F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935
 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -108,7 +108,7 @@ F src/test4.c 8b784cd82de158a2317cb4ac4bc86f91ad315e25
 F src/test5.c 7162f8526affb771c4ed256826eee7bb9eca265f
 F src/test6.c 5957d249d437e4db74045ce2f1f661648d94bf94
 F src/test7.c 03fa8d787f6aebc6d1f72504d52f33013ad2c8e3
-F src/test8.c 628ec89f9fbf3bfb9c58a503d845a0719595d0ad
+F src/test8.c 2af036d73b5ebf1b74d19f36b1b1ab22e1d99df1
 F src/test9.c cb1a7b5a4a918bb0552fd0101fd3f88d85904cd2
 F src/test_async.c 9d326ceda4306bcab252b8f7e8e480ed45d7ccb6
 F src/test_autoext.c 855157d97aa28cf84233847548bfacda21807436
@@ -131,7 +131,7 @@ F src/vdbeaux.c 5efa6d0f6096f213fbdffa0b1bf0a4c8ae40d145
 F src/vdbefifo.c 3ca8049c561d5d67cbcb94dc909ae9bb68c0bf8f
 F src/vdbemem.c d3696b4b0e5f32272659816cdfa2348c650b1ba0
 F src/vtab.c 7fbda947e28cbe7adb3ba752a76ca9ef29936750
-F src/where.c b5f8e2a0b0758b631c236aef3c7ed9c3b197eae8
+F src/where.c 881cfd88a97dd9bdb366e5349a25a19ea89f40a1
 F tclinstaller.tcl 046e3624671962dc50f0481d7c25b38ef803eb42
 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
 F test/all.test 60267b055e82de4fb8b841eabb014bc2f836a4eb
@@ -274,7 +274,7 @@ F test/misc3.test 7bd937e2c62bcc6be71939faf068d506467b1e03
 F test/misc4.test b043a05dea037cca5989f3ae09552fa16119bc80
 F test/misc5.test c7d2d2a5a20dc37d3605a8067f0df5af2240122e
 F test/misc6.test 3de55ec5cadf466ada587173faa5d6a4790a8bb7
-F test/misc7.test c111c5cce45e2e7e7eada41675f9e42cfb4414e0
+F test/misc7.test 54b131b86086d018e805f40916755c5d08c0eb2e
 F test/misuse.test 30b3a458e5a70c31e74c291937b6c82204c59f33
 F test/notnull.test 44d600f916b770def8b095a9962dbe3be5a70d82
 F test/null.test 9503e1f63e959544c006d9f01709c5b5eab67d54
@@ -359,7 +359,7 @@ F test/vacuum.test cf839fc3ff24d601057319bbb5c700ce9c8e0fb0
 F test/vacuum2.test 5aea8c88a65cb29f7d175296e7c819c6158d838c
 F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102
 F test/view.test 852bd4101e6d171c46ad682eb5c5faf662b2eba4
-F test/vtab1.test 92410029a2679c8751635ecaa023cf54bc5ab4eb
+F test/vtab1.test bf129928444f1fe3d992894f6e0b4c6d4a534d49
 F test/vtab2.test 94bb3bf691ac10e34cf7dad46b1cf94b861d513c
 F test/vtab3.test f38d6d7d19f08bffdadce4d5b8cba078f8118587
 F test/vtab4.test a9d7104d41a787754a734740d7aa61c807a69f87
@@ -447,7 +447,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
 F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
-P 66b3ad09ea657d25d48cb75ec2671ea2dc1b6005
-R 87f3fb17b92b06ba0363d652e2c2e851
-U drh
-Z a7a4533761023a234a1b0962226a7a23
+P e5f17078a28b6a47d6943d40c526390c36258392
+R b56988b2a4f41fbf2d60eaa052f1ee98
+U danielk1977
+Z 4da0a0b65fb898aa87e0c0cc367ade9b
index 50b28b268ed5b63ee3c55caf549bd49675076abd..4db75ef8e3f4c2e8b6d18e8b3ada9be54c6fc1bd 100644 (file)
@@ -1 +1 @@
-e5f17078a28b6a47d6943d40c526390c36258392
\ No newline at end of file
+7e0aa964129612e2bad6fa45139d124f19cacd48
\ No newline at end of file
index 36465afd090afc9380c0dafa600c222f7f985713..d1081d7d39a63af8f7f93e25c6805182ce87bfad 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.44 2007/01/03 23:37:29 drh Exp $
+** $Id: test8.c,v 1.45 2007/03/30 14:56:35 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 #include "tcl.h"
@@ -27,12 +27,13 @@ typedef struct echo_vtab echo_vtab;
 typedef struct echo_cursor echo_cursor;
 
 /*
-** The test module defined in this file uses two global Tcl variables to
+** The test module defined in this file uses four global Tcl variables to
 ** commicate with test-scripts:
 **
 **     $::echo_module
 **     $::echo_module_sync_fail
 **     $::echo_module_begin_fail
+**     $::echo_module_cost
 **
 ** The variable ::echo_module is a list. Each time one of the following
 ** methods is called, one or more elements are appended to the list.
@@ -627,27 +628,35 @@ static int echoBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
   const char *zSep = "WHERE";
   echo_vtab *pVtab = (echo_vtab *)tab;
   sqlite3_stmt *pStmt = 0;
+  Tcl_Interp *interp = pVtab->interp;
 
   int nRow;
   int useIdx = 0;
   int rc = SQLITE_OK;
+  int useCost = 0;
+  double cost;
 
   /* 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 
   ** number of rows if the proposed scan uses an index.  
   */
-  zQuery = sqlite3_mprintf("SELECT count(*) FROM %Q", pVtab->zTableName);
-  rc = sqlite3_prepare(pVtab->db, zQuery, -1, &pStmt, 0);
-  sqlite3_free(zQuery);
-  if( rc!=SQLITE_OK ){
-    return rc;
-  }
-  sqlite3_step(pStmt);
-  nRow = sqlite3_column_int(pStmt, 0);
-  rc = sqlite3_finalize(pStmt);
-  if( rc!=SQLITE_OK ){
-    return rc;
+  if( Tcl_GetVar(interp, "echo_module_cost", TCL_GLOBAL_ONLY) ){
+    cost = atof(Tcl_GetVar(interp, "echo_module_cost", TCL_GLOBAL_ONLY));
+    useCost = 1;
+  } else {
+    zQuery = sqlite3_mprintf("SELECT count(*) FROM %Q", pVtab->zTableName);
+    rc = sqlite3_prepare(pVtab->db, zQuery, -1, &pStmt, 0);
+    sqlite3_free(zQuery);
+    if( rc!=SQLITE_OK ){
+      return rc;
+    }
+    sqlite3_step(pStmt);
+    nRow = sqlite3_column_int(pStmt, 0);
+    rc = sqlite3_finalize(pStmt);
+    if( rc!=SQLITE_OK ){
+      return rc;
+    }
   }
 
   zQuery = sqlite3_mprintf("SELECT rowid, * FROM %Q", pVtab->zTableName);
@@ -717,7 +726,9 @@ static int echoBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
   pIdxInfo->idxNum = hashString(zQuery);
   pIdxInfo->idxStr = zQuery;
   pIdxInfo->needToFreeIdxStr = 1;
-  if( useIdx ){
+  if (useCost) {
+    pIdxInfo->estimatedCost = cost;
+  } else if( useIdx ){
     /* Approximation of log2(nRow). */
     for( ii=0; ii<(sizeof(int)*8); ii++ ){
       if( nRow & (1<<ii) ){
index 8265eb7c94e926c02aaed7c02853228e116f27d2..2377e767e0c0e9a81af7195ef4be08e8a5e0392c 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.243 2007/03/30 09:13:14 danielk1977 Exp $
+** $Id: where.c,v 1.244 2007/03/30 14:56:35 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 
@@ -1832,6 +1832,10 @@ static void whereInfoFree(WhereInfo *pWInfo){
       sqlite3_index_info *pInfo = pWInfo->a[i].pIdxInfo;
       if( pInfo ){
         if( pInfo->needToFreeIdxStr ){
+          /* Coverage: Don't think this can be reached. By the time this
+          ** function is called, the index-strings have been passed
+          ** to the vdbe layer for deletion.
+          */
           sqlite3_free(pInfo->idxStr);
         }
         sqliteFree(pInfo);
index d83ff7a1b774dcc6cef3c527d61de5399d369b8f..79c2108e798fa396b09343745b47d9dc3a8cf3c1 100644 (file)
@@ -10,7 +10,7 @@
 #***********************************************************************
 # This file implements regression tests for SQLite library.
 #
-# $Id: misc7.test,v 1.5 2007/03/30 13:01:32 drh Exp $
+# $Id: misc7.test,v 1.6 2007/03/30 14:56:35 danielk1977 Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -164,9 +164,13 @@ do_test misc7-9 {
 } {}
 
 #--------------------------------------------------------------------
-# Improve reported coverage by running some debugging code:
+# Improve coverage for vtab code.
 #
 ifcapable vtab {
+  # Run some debug code to improve reported coverage
+  #
+
+  # set sqlite_where_trace 1
   do_test misc7-10 {
     register_echo_module [sqlite3_connection_pointer db]
     execsql {
@@ -174,6 +178,43 @@ ifcapable vtab {
       SELECT a FROM t1 WHERE a = 1 ORDER BY b;
     }
   } {1}
+  set sqlite_where_trace 0
+
+  # Specify an ORDER BY clause that cannot be indexed.
+  do_test misc7-11 {
+    execsql {
+      SELECT t1.a, t2.a FROM t1, t1 AS t2 ORDER BY 2 LIMIT 1;
+    }
+  } {1 1}
+
+  # The whole point of this is to test an error code other than
+  # SQLITE_NOMEM from the vtab xBestIndex callback.
+  #
+  do_ioerr_test misc7-12 -tclprep {
+    sqlite3 db2 test.db
+    register_echo_module [sqlite3_connection_pointer db2]
+    db2 eval {
+      CREATE TABLE abc(a PRIMARY KEY, b, c);
+      INSERT INTO abc VALUES(1, 2, 3);
+      CREATE VIRTUAL TABLE t1 USING echo(abc);
+    }
+    db2 close
+  } -tclbody {
+    register_echo_module [sqlite3_connection_pointer db]
+    execsql {SELECT * FROM t1 WHERE a = 1;}
+  } 
+
+  # The case where the virtual table module returns a very large number
+  # as the cost of a scan (greater than SQLITE_BIG_DOUBLE in the code).
+  #
+  do_test misc7-13 {
+    sqlite3 db test.db
+    register_echo_module [sqlite3_connection_pointer db]
+    set ::echo_module_cost 2.0e+99
+    execsql {SELECT * FROM t1 WHERE a = 1;}
+  } {1 2 3}
+  unset ::echo_module_cost
 }
 
+
 finish_test
index b451a773ec7633fa19a79d9296c516e8c47bd697..b0eb78365b7e4ef5f4c760b6fea42da499850619 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this file is creating and dropping virtual tables.
 #
-# $Id: vtab1.test,v 1.41 2007/03/02 08:12:23 danielk1977 Exp $
+# $Id: vtab1.test,v 1.42 2007/03/30 14:56:35 danielk1977 Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -557,7 +557,7 @@ do_test vtab1-5-6 {
   sqlite3 db test.db
   register_echo_module [sqlite3_connection_pointer db]
 
-  set echo_module ""
+  set ::echo_module ""
   execsql {
     SELECT * FROM et1, et2 WHERE et2.d = 2;
   }
@@ -566,7 +566,7 @@ do_test vtab1-5-6 {
   2 blue black 2 hearts diamonds \
 ]
 do_test vtab1-5-7 {
-  filter $echo_module
+  filter $::echo_module
 } [list \
   xFilter {SELECT rowid, * FROM 't2' WHERE d = ?} \
   xFilter {SELECT rowid, * FROM 't1'}             \