From 1acb539f4c255470e17ca639d144ca23570650f2 Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 26 Nov 2015 19:33:41 +0000 Subject: [PATCH] Add the "colUsed" field to the sqlite3_index_info structure passed to virtual table xBestIndex methods. To indicate the subset of the virtual table columns that may be required by the current scan. FossilOrigin-Name: 116b206494eb8ba963c7c5acfbf9e7b6db11c79c --- manifest | 30 ++++++----- manifest.uuid | 2 +- src/sqlite.h.in | 13 +++++ src/test8.c | 38 ++++++++++++-- src/update.c | 8 +-- src/where.c | 1 + test/tkt3871.test | 10 ++-- test/vtab1.test | 86 ++++++++++++++++--------------- test/vtab4.test | 32 ++++++------ test/vtabH.test | 8 +-- test/vtabI.test | 126 ++++++++++++++++++++++++++++++++++++++++++++++ 11 files changed, 267 insertions(+), 87 deletions(-) create mode 100644 test/vtabI.test diff --git a/manifest b/manifest index ca8c3ee0ee..f8aee8c533 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\swith\sthe\suserauth\sextension\sand\sno-authentication\sdatabases.\sRun\sthe\stests\sfor\sthis\sextension\sas\spart\sof\sthe\sDebug-One\smodule\sin\sreleasetest.tcl. -D 2015-11-26T15:51:55.157 +C Add\sthe\s"colUsed"\sfield\sto\sthe\ssqlite3_index_info\sstructure\spassed\sto\svirtual\stable\sxBestIndex\smethods.\sTo\sindicate\sthe\ssubset\sof\sthe\svirtual\stable\scolumns\sthat\smay\sbe\srequired\sby\sthe\scurrent\sscan. +D 2015-11-26T19:33:41.794 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -341,7 +341,7 @@ F src/resolve.c f4c897ca76ca6d5e0b3f0499c627392ffe657c8e F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c e10586c750d87211caa8f4b239e2bfa6a2049e5b F src/shell.c f0f59ea60ad297f671b7ae0fb957a736ad17c92c -F src/sqlite.h.in 1340aa105f53fbc6fd5b9918b54b64c64e910ee7 +F src/sqlite.h.in e7eed45d38f9426b7608b761260574d2c61873f1 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 41ef50b0418a7c5ad1337bb80db5a7928dee764f F src/sqliteInt.h 64256d193a16a147d9f6317cc4e095fdd3e0a2e9 @@ -356,7 +356,7 @@ F src/test4.c d168f83cc78d02e8d35567bb5630e40dcd85ac1e F src/test5.c 5a34feec76d9b3a86aab30fd4f6cc9c48cbab4c1 F src/test6.c 41cacf3b0dd180823919bf9e1fbab287c9266723 F src/test7.c 9c89a4f1ed6bb13af0ed805b8d782bd83fcd57e3 -F src/test8.c 85b8c6a0309130300d560e2334ee71e70391785e +F src/test8.c b3a416298dab54537d5aec68697a8b31f5ddf69c F src/test9.c bea1e8cf52aa93695487badedd6e1886c321ea60 F src/test_async.c 21e11293a2f72080eda70e1124e9102044531cd8 F src/test_autoext.c dea8a01a7153b9adc97bd26161e4226329546e12 @@ -398,7 +398,7 @@ F src/threads.c bbfb74450643cb5372a43ad4f6cffd7e9dfcecb0 F src/tokenize.c 5606871a377f390af7040ec3c12e0d183512d785 F src/treeview.c 78842e90c1f71269e7a73a1d4221b6fe360bab66 F src/trigger.c 322f23aad694e8f31d384dcfa386d52a48d3c52f -F src/update.c 40e51cd0883cb5bfd6abb7d8a7cd8aa47fab2945 +F src/update.c 17332f9fe818cbc0444c36a811800af8498af4c3 F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c F src/util.c e802e8e311a0d6c48cd1b3e89db164f6f0248d70 F src/vacuum.c 2ddd5cad2a7b9cef7f9e431b8c7771634c6b1701 @@ -416,7 +416,7 @@ F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb F src/wal.c 18b0ed49830cf04fe2d68224b41838a73ac6cd24 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c 2e14d17f592d176b6dc879c33fbdec4fbccaa2ba -F src/where.c 6687fb2675d9c1c1936ceca77529e2f21fb3a769 +F src/where.c 9c04982ba9ecfc7751c670ed5a3bddc81d7eb74c F src/whereInt.h 6afc0d70cf6213e58e8fbe10b6e50d1aa16f122f F src/wherecode.c 4c96182e7b25e4be54008dee2da5b9c2f8480b9b F src/whereexpr.c eebba8340c90de73b3d3bbe8c43b84559b8e6e2c @@ -1204,7 +1204,7 @@ F test/tkt3824.test 150aa00bb6220672e5f0eb14dc8eaa36750425f0 F test/tkt3832.test 2300d10d57562b89875b72148338ac3e14f8847d F test/tkt3838.test 292e72489101cd1320d7278dc111c173ebf334d4 F test/tkt3841.test 4659845bc53f809a5932c61c6ce8c5bb9d6b947f -F test/tkt3871.test 43ecbc8d90dc83908e2a454aef345acc9d160c6f +F test/tkt3871.test d921703d07c68f4fd5312073215a17fa34b0401d F test/tkt3879.test 2ad5bef2c87e9991ce941e054c31abe26ef7fb90 F test/tkt3911.test 74cd324f3ba653040cc6d94cc4857b290d12d633 F test/tkt3918.test ea78bf164e4d55cbde0d83c671ef6fbe930a0032 @@ -1259,10 +1259,10 @@ F test/vacuum4.test d3f8ecff345f166911568f397d2432c16d2867d9 F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102 F test/veryquick.test 57ab846bacf7b90cf4e9a672721ea5c5b669b661 F test/view.test f6c3a39e0c819891265e1d0754e99960d81ef6c9 -F test/vtab1.test ec5cb767277d7e0eff34d3a02824c1dd959a5959 +F test/vtab1.test 7c4b81abd88361ada9cbe414c459efca26be6bda F test/vtab2.test f8cd1bb9aba7143eba97812d9617880a36d247ad F test/vtab3.test b45f47d20f225ccc9c28dc915d92740c2dee311e -F test/vtab4.test 942f8b8280b3ea8a41dae20e7822d065ca1cb275 +F test/vtab4.test 8e73ed268f3d596bc3590f45fc948fb40f28e9c3 F test/vtab5.test 889f444970393c73f1e077e2bdc5d845e157a391 F test/vtab6.test d2986cf418dc51e7fb81d12366bea2caa8b812df F test/vtab7.test ae560ebea870ed04e9aa4177cc302f910faaabb5 @@ -1274,7 +1274,8 @@ F test/vtabC.test 4528f459a13136f982e75614d120aef165f17292 F test/vtabD.test 05b3f1d77117271671089e48719524b676842e96 F test/vtabE.test d5024aa42754962f6bb0afd261681686488e7afe F test/vtabF.test fd5ad376f5a34fe0891df1f3cddb4fe7c3eb077e -F test/vtabH.test 2030e7183e41c3cc7521c06aa7bc5a232f7e8986 +F test/vtabH.test 186f118d6a4dd25fdb36adfd471993003f83790c +F test/vtabI.test 751b07636700dbdea328e4265b6077ccd6811a3f F test/vtab_alter.test 9e374885248f69e251bdaacf480b04a197f125e5 F test/vtab_err.test 0d4d8eb4def1d053ac7c5050df3024fd47a3fbd8 F test/vtab_shared.test ea8778d5b0df200adef2ca7c00c3c37d4375f772 @@ -1405,7 +1406,10 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P eb180b4f04d412dcd0af138e2dd7f62fbb5ac439 -R f2567fd8ad211c2f6878e625db7a4000 +P 8b15621952889b4ba53b2ea3171fef7ef0479ddb +R 5ccf7ece7a7865caf2729b522847c5bb +T *branch * vtab-colused +T *sym-vtab-colused * +T -sym-trunk * U dan -Z 033052b1e1d9566ff82c655910d67041 +Z 5f2bf909c1f2bf69ad08297f10962d86 diff --git a/manifest.uuid b/manifest.uuid index ffee151b00..f1b8240b4f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8b15621952889b4ba53b2ea3171fef7ef0479ddb \ No newline at end of file +116b206494eb8ba963c7c5acfbf9e7b6db11c79c \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index d340c05bf9..ea23eb27e2 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -5615,6 +5615,17 @@ struct sqlite3_module { ** ^Information about the ORDER BY clause is stored in aOrderBy[]. ** ^Each term of aOrderBy records a column of the ORDER BY clause. ** +** The colUsed field indicates which columns of the virtual table may be +** required by the current scan. Virtual table columns are numbered from +** zero in the order in which they appear within the CREATE TABLE statement +** passed to sqlite3_declare_vtab(). For the first 63 columns (columns 0-62), +** the corresponding bit is set within the colUsed mask if the column may be +** required by SQLite. If the table has at least 64 columns and any column +** to the right of the first 63 is required, then bit 63 of colUsed is also +** set. In other words, column iCol may be required if the expression +** (colUsed & ((sqlite3_uint64)1 << (iCol>=63 ? 63 : iCol))) evaluates to +** non-zero. +** ** The [xBestIndex] method must fill aConstraintUsage[] with information ** about what parameters to pass to xFilter. ^If argvIndex>0 then ** the right-hand side of the corresponding aConstraint[] is evaluated @@ -5694,6 +5705,8 @@ struct sqlite3_index_info { sqlite3_int64 estimatedRows; /* Estimated number of rows returned */ /* Fields below are only available in SQLite 3.9.0 and later */ int idxFlags; /* Mask of SQLITE_INDEX_SCAN_* flags */ + /* Fields below are only available in SQLite 3.10.0 and later */ + sqlite3_uint64 colUsed; /* Input: Mask of columns used by statement */ }; /* diff --git a/src/test8.c b/src/test8.c index 0c5dc0206e..3e506e36b4 100644 --- a/src/test8.c +++ b/src/test8.c @@ -745,6 +745,34 @@ static void string_concat(char **pzStr, char *zAppend, int doFree, int *pRc){ } } +/* +** This function returns a pointer to an sqlite3_malloc()ed buffer +** containing the select-list (the thing between keywords SELECT and FROM) +** to query the underlying real table with for the scan described by +** argument pIdxInfo. +** +** If the current SQLite version is earlier than 3.10.0, this is just "*" +** (select all columns). Or, for version 3.10.0 and greater, the list of +** columns identified by the pIdxInfo->colUsed mask. +*/ +static char *echoSelectList(echo_vtab *pTab, sqlite3_index_info *pIdxInfo){ + char *zRet = 0; + if( sqlite3_libversion_number()<3010000 ){ + zRet = sqlite3_mprintf(", *"); + }else{ + int i; + for(i=0; inCol; i++){ + if( pIdxInfo->colUsed & ((sqlite3_uint64)1 << (i>=63 ? 63 : i)) ){ + zRet = sqlite3_mprintf("%z, %s", zRet, pTab->aCol[i]); + }else{ + zRet = sqlite3_mprintf("%z, NULL", zRet); + } + if( !zRet ) break; + } + } + return zRet; +} + /* ** The echo module implements the subset of query constraints and sort ** orders that may take advantage of SQLite indices on the underlying @@ -770,6 +798,7 @@ static void string_concat(char **pzStr, char *zAppend, int doFree, int *pRc){ static int echoBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){ int ii; char *zQuery = 0; + char *zCol = 0; char *zNew; int nArg = 0; const char *zSep = "WHERE"; @@ -817,10 +846,11 @@ static int echoBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){ } } - zQuery = sqlite3_mprintf("SELECT rowid, * FROM %Q", pVtab->zTableName); - if( !zQuery ){ - return SQLITE_NOMEM; - } + zCol = echoSelectList(pVtab, pIdxInfo); + if( !zCol ) return SQLITE_NOMEM; + zQuery = sqlite3_mprintf("SELECT rowid%z FROM %Q", zCol, pVtab->zTableName); + if( !zQuery ) return SQLITE_NOMEM; + for(ii=0; iinConstraint; ii++){ const struct sqlite3_index_constraint *pConstraint; struct sqlite3_index_constraint_usage *pUsage; diff --git a/src/update.c b/src/update.c index 1335c269ed..a9735cadca 100644 --- a/src/update.c +++ b/src/update.c @@ -263,10 +263,12 @@ void sqlite3Update( assert( chngPk==0 || chngPk==1 ); chngKey = chngRowid + chngPk; - /* The SET expressions are not actually used inside the WHERE loop. - ** So reset the colUsed mask + /* The SET expressions are not actually used inside the WHERE loop. + ** So reset the colUsed mask. Unless this is a virtual table. In that + ** case, set all bits of the colUsed mask (to ensure that the virtual + ** table implementation makes all columns available). */ - pTabList->a[0].colUsed = 0; + pTabList->a[0].colUsed = IsVirtual(pTab) ? (Bitmask)-1 : 0; hasFK = sqlite3FkRequired(pParse, pTab, aXRef, chngKey); diff --git a/src/where.c b/src/where.c index 737bfc4e6f..30ad58e01b 100644 --- a/src/where.c +++ b/src/where.c @@ -2864,6 +2864,7 @@ static int whereLoopAddVirtual( pIdxInfo->estimatedCost = SQLITE_BIG_DBL / (double)2; pIdxInfo->estimatedRows = 25; pIdxInfo->idxFlags = 0; + pIdxInfo->colUsed = (sqlite3_int64)pSrc->colUsed; rc = vtabBestIndex(pParse, pTab, pIdxInfo); if( rc ) goto whereLoopAddVtab_exit; pIdxCons = *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint; diff --git a/test/tkt3871.test b/test/tkt3871.test index e7dbfde714..d587910d39 100644 --- a/test/tkt3871.test +++ b/test/tkt3871.test @@ -32,8 +32,8 @@ do_test tkt3871-1.3 { execsql { SELECT * FROM e WHERE a = 1 OR a = 2 } set echo_module } [list \ - xFilter {SELECT rowid, * FROM 't1' WHERE a = ?} 1 \ - xFilter {SELECT rowid, * FROM 't1' WHERE a = ?} 2 \ + xFilter {SELECT rowid, a, b FROM 't1' WHERE a = ?} 1 \ + xFilter {SELECT rowid, a, b FROM 't1' WHERE a = ?} 2 \ ] do_test tkt3871-1.4 { @@ -44,9 +44,9 @@ do_test tkt3871-1.5 { execsql { SELECT * FROM e WHERE a = 1 OR a = 2 OR b = 9 } set echo_module } [list \ - xFilter {SELECT rowid, * FROM 't1' WHERE a = ?} 1 \ - xFilter {SELECT rowid, * FROM 't1' WHERE a = ?} 2 \ - xFilter {SELECT rowid, * FROM 't1' WHERE b = ?} 9 + xFilter {SELECT rowid, a, b FROM 't1' WHERE a = ?} 1 \ + xFilter {SELECT rowid, a, b FROM 't1' WHERE a = ?} 2 \ + xFilter {SELECT rowid, a, b FROM 't1' WHERE b = ?} 9 ] diff --git a/test/vtab1.test b/test/vtab1.test index d5fae941af..6b6a0e2683 100644 --- a/test/vtab1.test +++ b/test/vtab1.test @@ -393,7 +393,7 @@ do_test vtab1-3.7 { SELECT rowid, * FROM t1; } } {1 1 2 3 2 4 5 6} -do_test vtab1-3.8 { +do_test vtab1-3.8.1 { execsql { SELECT a AS d, b AS e, c AS f FROM t1; } @@ -404,14 +404,14 @@ do_test vtab1-3.8 { # in test8.c) to make sure the xBestIndex() and xFilter() methods were # called correctly. # -do_test vtab1-3.8 { +do_test vtab1-3.8.2 { set echo_module "" execsql { SELECT * FROM t1; } set echo_module -} [list xBestIndex {SELECT rowid, * FROM 'treal'} \ - xFilter {SELECT rowid, * FROM 'treal'} ] +} [list xBestIndex {SELECT rowid, a, b, c FROM 'treal'} \ + xFilter {SELECT rowid, a, b, c FROM 'treal'} ] do_test vtab1-3.9 { set echo_module "" execsql { @@ -420,8 +420,8 @@ do_test vtab1-3.9 { } {4 5 6} do_test vtab1-3.10 { set echo_module -} [list xBestIndex {SELECT rowid, * FROM 'treal' WHERE b = ?} \ - xFilter {SELECT rowid, * FROM 'treal' WHERE b = ?} 5 ] +} [list xBestIndex {SELECT rowid, a, b, c FROM 'treal' WHERE b = ?} \ + xFilter {SELECT rowid, a, b, c FROM 'treal' WHERE b = ?} 5 ] do_test vtab1-3.10 { set echo_module "" execsql { @@ -430,8 +430,9 @@ do_test vtab1-3.10 { } {4 5 6} do_test vtab1-3.11 { set echo_module -} [list xBestIndex {SELECT rowid, * FROM 'treal' WHERE b >= ? AND b <= ?} \ - xFilter {SELECT rowid, * FROM 'treal' WHERE b >= ? AND b <= ?} 5 10 ] +} [list xBestIndex {SELECT rowid, a, b, c FROM 'treal' WHERE b >= ? AND b <= ?}\ + xFilter {SELECT rowid, a, b, c FROM 'treal' WHERE b >= ? AND b <= ?}\ + 5 10 ] do_test vtab1-3.12 { set echo_module "" execsql { @@ -440,8 +441,9 @@ do_test vtab1-3.12 { } {1 2 3 4 5 6} do_test vtab1-3.13 { set echo_module -} [list xBestIndex {SELECT rowid, * FROM 'treal' WHERE b >= ? AND b <= ?} \ - xFilter {SELECT rowid, * FROM 'treal' WHERE b >= ? AND b <= ?} 2 10 ] +} [list xBestIndex {SELECT rowid, a, b, c FROM 'treal' WHERE b >= ? AND b <= ?}\ + xFilter {SELECT rowid, a, b, c FROM 'treal' WHERE b >= ? AND b <= ?}\ + 2 10 ] # Add a function for the MATCH operator. Everything always matches! #proc test_match {lhs rhs} { @@ -459,8 +461,8 @@ do_test vtab1-3.12 { } {1 {unable to use function MATCH in the requested context}} do_test vtab1-3.13 { set echo_module -} [list xBestIndex {SELECT rowid, * FROM 'treal'} \ - xFilter {SELECT rowid, * FROM 'treal'}] +} [list xBestIndex {SELECT rowid, a, b, c FROM 'treal'} \ + xFilter {SELECT rowid, a, b, c FROM 'treal'}] ifcapable subquery { # The echo module uses a subquery internally to implement the MATCH operator. do_test vtab1-3.14 { @@ -472,9 +474,9 @@ do_test vtab1-3.14 { do_test vtab1-3.15 { set echo_module } [list xBestIndex \ - {SELECT rowid, * FROM 'treal' WHERE b LIKE (SELECT '%'||?||'%')} \ + {SELECT rowid, a, b, c FROM 'treal' WHERE b LIKE (SELECT '%'||?||'%')} \ xFilter \ - {SELECT rowid, * FROM 'treal' WHERE b LIKE (SELECT '%'||?||'%')} \ + {SELECT rowid, a, b, c FROM 'treal' WHERE b LIKE (SELECT '%'||?||'%')} \ string ] }; #ifcapable subquery @@ -505,8 +507,8 @@ do_test vtab1-4.1 { } {2 5 nosort} do_test vtab1-4.2 { set echo_module -} [list xBestIndex {SELECT rowid, * FROM 'treal' ORDER BY b ASC} \ - xFilter {SELECT rowid, * FROM 'treal' ORDER BY b ASC} ] +} [list xBestIndex {SELECT rowid, NULL, b, NULL FROM 'treal' ORDER BY b ASC} \ + xFilter {SELECT rowid, NULL, b, NULL FROM 'treal' ORDER BY b ASC} ] do_test vtab1-4.3 { set echo_module "" cksort { @@ -515,8 +517,8 @@ do_test vtab1-4.3 { } {5 2 nosort} do_test vtab1-4.4 { set echo_module -} [list xBestIndex {SELECT rowid, * FROM 'treal' ORDER BY b DESC} \ - xFilter {SELECT rowid, * FROM 'treal' ORDER BY b DESC} ] +} [list xBestIndex {SELECT rowid, NULL, b, NULL FROM 'treal' ORDER BY b DESC} \ + xFilter {SELECT rowid, NULL, b, NULL FROM 'treal' ORDER BY b DESC} ] do_test vtab1-4.3 { set echo_module "" cksort { @@ -525,8 +527,8 @@ do_test vtab1-4.3 { } {2 5 sort} do_test vtab1-4.4 { set echo_module -} [list xBestIndex {SELECT rowid, * FROM 'treal'} \ - xFilter {SELECT rowid, * FROM 'treal'} ] +} [list xBestIndex {SELECT rowid, NULL, b, NULL FROM 'treal'} \ + xFilter {SELECT rowid, NULL, b, NULL FROM 'treal'} ] execsql { DROP TABLE t1; @@ -575,9 +577,9 @@ do_test vtab1-5-2 { do_test vtab1-5-3 { filter $echo_module } [list \ - xFilter {SELECT rowid, * FROM 't1'} \ - xFilter {SELECT rowid, * FROM 't2'} \ - xFilter {SELECT rowid, * FROM 't2'} \ + xFilter {SELECT rowid, a, b, c FROM 't1'} \ + xFilter {SELECT rowid, d, e, f FROM 't2'} \ + xFilter {SELECT rowid, d, e, f FROM 't2'} \ ] do_test vtab1-5-4 { set echo_module "" @@ -591,9 +593,9 @@ do_test vtab1-5-4 { do_test vtab1-5-5 { filter $echo_module } [list \ - xFilter {SELECT rowid, * FROM 't1'} \ - xFilter {SELECT rowid, * FROM 't2'} \ - xFilter {SELECT rowid, * FROM 't2'} \ + xFilter {SELECT rowid, a, b, c FROM 't1'} \ + xFilter {SELECT rowid, d, e, f FROM 't2'} \ + xFilter {SELECT rowid, d, e, f FROM 't2'} \ ] do_test vtab1-5-6 { execsql { @@ -615,9 +617,9 @@ do_test vtab1-5-6 { do_test vtab1-5-7 { filter $::echo_module } [list \ - xFilter {SELECT rowid, * FROM 't1'} \ - xFilter {SELECT rowid, * FROM 't2' WHERE d = ?} \ - xFilter {SELECT rowid, * FROM 't2' WHERE d = ?} \ + xFilter {SELECT rowid, a, b, c FROM 't1'} \ + xFilter {SELECT rowid, d, e, f FROM 't2' WHERE d = ?} \ + xFilter {SELECT rowid, d, e, f FROM 't2' WHERE d = ?} \ ] execsql { @@ -967,8 +969,8 @@ do_test vtab1.10-5 { } set echo_module } [list \ - xBestIndex {SELECT rowid, * FROM 'r'} \ - xFilter {SELECT rowid, * FROM 'r'} \ + xBestIndex {SELECT rowid, a, b, c FROM 'r'} \ + xFilter {SELECT rowid, a, b, c FROM 'r'} \ ] proc match_func {args} {return ""} do_test vtab1.10-6 { @@ -979,8 +981,8 @@ do_test vtab1.10-6 { } set echo_module } [list \ - xBestIndex {SELECT rowid, * FROM 'r'} \ - xFilter {SELECT rowid, * FROM 'r'} \ + xBestIndex {SELECT rowid, a, b, c FROM 'r'} \ + xFilter {SELECT rowid, a, b, c FROM 'r'} \ ] @@ -1153,13 +1155,15 @@ do_test vtab1-14.2 { set echo_module "" execsql { SELECT * FROM echo_c WHERE rowid = 1 } set echo_module -} [list xBestIndex {SELECT rowid, * FROM 'c' WHERE rowid = ?} xFilter {SELECT rowid, * FROM 'c' WHERE rowid = ?} 1] +} [list xBestIndex {SELECT rowid, a, b, c FROM 'c' WHERE rowid = ?} \ + xFilter {SELECT rowid, a, b, c FROM 'c' WHERE rowid = ?} 1] do_test vtab1-14.3 { set echo_module "" execsql { SELECT * FROM echo_c WHERE a = 1 } set echo_module -} [list xBestIndex {SELECT rowid, * FROM 'c' WHERE a = ?} xFilter {SELECT rowid, * FROM 'c' WHERE a = ?} 1] +} [list xBestIndex {SELECT rowid, a, b, c FROM 'c' WHERE a = ?} \ + xFilter {SELECT rowid, a, b, c FROM 'c' WHERE a = ?} 1] #do_test vtab1-14.4 { # set echo_module "" @@ -1300,16 +1304,16 @@ do_execsql_test 18.1.0 { foreach {tn sql res filter} { 1.1 "SELECT a FROM e6 WHERE b>'James'" {4 1 5} - {xFilter {SELECT rowid, * FROM 't6' WHERE b > ?} James} + {xFilter {SELECT rowid, a, b FROM 't6' WHERE b > ?} James} 1.2 "SELECT a FROM e6 WHERE b>='J' AND b<'K'" {3 4} - {xFilter {SELECT rowid, * FROM 't6' WHERE b >= ? AND b < ?} J K} + {xFilter {SELECT rowid, a, b FROM 't6' WHERE b >= ? AND b < ?} J K} 1.3 "SELECT a FROM e6 WHERE b LIKE 'J%'" {3 4} - {xFilter {SELECT rowid, * FROM 't6' WHERE b like ?} J%} + {xFilter {SELECT rowid, a, b FROM 't6' WHERE b like ?} J%} 1.4 "SELECT a FROM e6 WHERE b LIKE 'j%'" {3 4} - {xFilter {SELECT rowid, * FROM 't6' WHERE b like ?} j%} + {xFilter {SELECT rowid, a, b FROM 't6' WHERE b like ?} j%} } { set echo_module {} do_execsql_test 18.$tn.1 $sql $res @@ -1319,10 +1323,10 @@ foreach {tn sql res filter} { do_execsql_test 18.2.0 { PRAGMA case_sensitive_like = ON } foreach {tn sql res filter} { 2.1 "SELECT a FROM e6 WHERE b LIKE 'J%'" {3 4} - {xFilter {SELECT rowid, * FROM 't6' WHERE b like ?} J%} + {xFilter {SELECT rowid, a, b FROM 't6' WHERE b like ?} J%} 2.2 "SELECT a FROM e6 WHERE b LIKE 'j%'" {} - {xFilter {SELECT rowid, * FROM 't6' WHERE b like ?} j%} + {xFilter {SELECT rowid, a, b FROM 't6' WHERE b like ?} j%} } { set echo_module {} do_execsql_test 18.$tn.1 $sql $res diff --git a/test/vtab4.test b/test/vtab4.test index 07b6e839d7..d12ca33cc0 100644 --- a/test/vtab4.test +++ b/test/vtab4.test @@ -57,9 +57,9 @@ do_test vtab4-1.3 { UPDATE techo SET a = 2; } set echo_module -} [list xBestIndex {SELECT rowid, * FROM 'treal'} \ +} [list xBestIndex {SELECT rowid, a, b, c FROM 'treal'} \ xBegin echo(treal) \ - xFilter {SELECT rowid, * FROM 'treal'} \ + xFilter {SELECT rowid, a, b, c FROM 'treal'} \ xSync echo(treal) \ xCommit echo(treal) \ ] @@ -69,9 +69,9 @@ do_test vtab4-1.4 { DELETE FROM techo; } set echo_module -} [list xBestIndex {SELECT rowid, * FROM 'treal'} \ +} [list xBestIndex {SELECT rowid, NULL, NULL, NULL FROM 'treal'} \ xBegin echo(treal) \ - xFilter {SELECT rowid, * FROM 'treal'} \ + xFilter {SELECT rowid, NULL, NULL, NULL FROM 'treal'} \ xSync echo(treal) \ xCommit echo(treal) \ ] @@ -105,12 +105,12 @@ do_test vtab4-2.2 { COMMIT; } set echo_module -} [list xBestIndex {SELECT rowid, * FROM 'treal'} \ +} [list xBestIndex {SELECT rowid, a, b, c FROM 'treal'} \ xBegin echo(sreal) \ - xFilter {SELECT rowid, * FROM 'treal'} \ - xBestIndex {SELECT rowid, * FROM 'treal'} \ + xFilter {SELECT rowid, a, b, c FROM 'treal'} \ + xBestIndex {SELECT rowid, NULL, NULL, NULL FROM 'treal'} \ xBegin echo(treal) \ - xFilter {SELECT rowid, * FROM 'treal'} \ + xFilter {SELECT rowid, NULL, NULL, NULL FROM 'treal'} \ xSync echo(sreal) \ xSync echo(treal) \ xCommit echo(sreal) \ @@ -137,12 +137,12 @@ do_test vtab4-2.5 { ROLLBACK; } set echo_module -} [list xBestIndex {SELECT rowid, * FROM 'sreal'} \ +} [list xBestIndex {SELECT rowid, a, b, c FROM 'sreal'} \ xBegin echo(treal) \ - xFilter {SELECT rowid, * FROM 'sreal'} \ - xBestIndex {SELECT rowid, * FROM 'sreal'} \ + xFilter {SELECT rowid, a, b, c FROM 'sreal'} \ + xBestIndex {SELECT rowid, NULL, NULL, NULL FROM 'sreal'} \ xBegin echo(sreal) \ - xFilter {SELECT rowid, * FROM 'sreal'} \ + xFilter {SELECT rowid, NULL, NULL, NULL FROM 'sreal'} \ xRollback echo(treal) \ xRollback echo(sreal) \ ] @@ -178,12 +178,12 @@ do_test vtab4-3.3 { COMMIT; } set echo_module -} [list xBestIndex {SELECT rowid, * FROM 'sreal'} \ +} [list xBestIndex {SELECT rowid, a, b, c FROM 'sreal'} \ xBegin echo(treal) \ - xFilter {SELECT rowid, * FROM 'sreal'} \ - xBestIndex {SELECT rowid, * FROM 'sreal'} \ + xFilter {SELECT rowid, a, b, c FROM 'sreal'} \ + xBestIndex {SELECT rowid, NULL, NULL, NULL FROM 'sreal'} \ xBegin echo(sreal) \ - xFilter {SELECT rowid, * FROM 'sreal'} \ + xFilter {SELECT rowid, NULL, NULL, NULL FROM 'sreal'} \ xSync echo(treal) \ xSync echo(sreal) \ xRollback echo(treal) \ diff --git a/test/vtabH.test b/test/vtabH.test index dab5343da5..7216677d2a 100644 --- a/test/vtabH.test +++ b/test/vtabH.test @@ -32,13 +32,13 @@ do_execsql_test 1.0 { foreach {tn sql expect} { 1 "SELECT * FROM e6 WHERE b LIKE 'abc'" { - xBestIndex {SELECT rowid, * FROM 't6' WHERE b like ?} - xFilter {SELECT rowid, * FROM 't6' WHERE b like ?} abc + xBestIndex {SELECT rowid, a, b FROM 't6' WHERE b like ?} + xFilter {SELECT rowid, a, b FROM 't6' WHERE b like ?} abc } 2 "SELECT * FROM e6 WHERE b GLOB 'abc'" { - xBestIndex {SELECT rowid, * FROM 't6' WHERE b glob ?} - xFilter {SELECT rowid, * FROM 't6' WHERE b glob ?} abc + xBestIndex {SELECT rowid, a, b FROM 't6' WHERE b glob ?} + xFilter {SELECT rowid, a, b FROM 't6' WHERE b glob ?} abc } } { do_test 1.$tn { diff --git a/test/vtabI.test b/test/vtabI.test new file mode 100644 index 0000000000..4b5a0a8c32 --- /dev/null +++ b/test/vtabI.test @@ -0,0 +1,126 @@ +# 2015 Nov 26 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. Specifically, +# it tests the sqlite3_index_info.colUsed variable is set correctly. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix vtabI + +ifcapable !vtab { + finish_test + return +} + +register_echo_module db + +do_execsql_test 1.0 { + CREATE TABLE t1(a, b, c, d, e); + CREATE VIRTUAL TABLE e1 USING echo(t1); +} + +foreach {tn query filter} { + 1 {SELECT * FROM e1} + {SELECT rowid, a, b, c, d, e FROM 't1'} + + 2 {SELECT a, b FROM e1} + {SELECT rowid, a, b, NULL, NULL, NULL FROM 't1'} + + 3 {SELECT count(*) FROM e1 GROUP BY b} + {SELECT rowid, NULL, b, NULL, NULL, NULL FROM 't1'} + + 4 {SELECT count(*) FROM e1 GROUP BY b HAVING a=?} + {SELECT rowid, a, b, NULL, NULL, NULL FROM 't1'} + + 5 {SELECT a FROM e1 WHERE c=?} + {SELECT rowid, a, NULL, c, NULL, NULL FROM 't1'} + + 6 {SELECT a FROM e1 ORDER BY e} + {SELECT rowid, a, NULL, NULL, NULL, e FROM 't1'} + + 7 {SELECT a FROM e1 ORDER BY e, d} + {SELECT rowid, a, NULL, NULL, d, e FROM 't1'} +} { + do_test 1.$tn { + set ::echo_module [list] + execsql $query + set idx [lsearch -exact $::echo_module xFilter] + lindex $::echo_module [expr $idx+1] + } $filter +} + +#------------------------------------------------------------------------- +# Tests with a table with more than 64 columns. +# +proc all_col_list {} { + set L [list] + for {set i 1} {$i <= 100} {incr i} { lappend L "c$i" } + set L +} + +proc part_col_list {cols} { + set L [list] + for {set i 1} {$i <= 100} {incr i} { + set c "c$i" + if {[lsearch $cols $c]>=0} { + lappend L "c$i" + } else { + lappend L NULL + } + } + set L +} +proc CL {args} { + join [part_col_list $args] ", " +} +proc CLT {args} { + set cols $args + for {set i 64} {$i <= 100} {incr i} { + lappend cols "c$i" + } + join [part_col_list $cols] ", " +} + +do_test 2.0 { + execsql "CREATE TABLE t2([join [all_col_list] ,])" + execsql "CREATE VIRTUAL TABLE e2 USING echo(t2)" +} {} + +foreach {tn query filter} { + 1 {SELECT c1, c10, c20 FROM e2} + {SELECT rowid, [CL c1 c10 c20] FROM 't2'} + + 2 {SELECT c40, c50, c60 FROM e2} + {SELECT rowid, [CL c40 c50 c60] FROM 't2'} + + 3 {SELECT c7, c80, c90 FROM e2} + {SELECT rowid, [CLT c7] FROM 't2'} + + 4 {SELECT c64 FROM e2} + {SELECT rowid, [CLT c64] FROM 't2'} + + 5 {SELECT c63 FROM e2} + {SELECT rowid, [CL c63] FROM 't2'} + + 6 {SELECT c22 FROM e2 ORDER BY c50, c70} + {SELECT rowid, [CLT c22 c50] FROM 't2'} + +} { + do_test 2.$tn { + set ::echo_module [list] + execsql $query + set idx [lsearch -exact $::echo_module xFilter] + lindex $::echo_module [expr $idx+1] + } [subst $filter] +} + +finish_test