aboutsummaryrefslogtreecommitdiff
path: root/src/test8.c
diff options
context:
space:
mode:
authordan <dan@noemail.net>2015-11-26 19:33:41 +0000
committerdan <dan@noemail.net>2015-11-26 19:33:41 +0000
commit1acb539f4c255470e17ca639d144ca23570650f2 (patch)
tree8ee8cbe8a0759ca3861a2f97256d91b3bf31fb3e /src/test8.c
parentfab1d401f80e1646341727c50b91377e6f5eb80a (diff)
downloadsqlite-1acb539f4c255470e17ca639d144ca23570650f2.tar.gz
sqlite-1acb539f4c255470e17ca639d144ca23570650f2.zip
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
Diffstat (limited to 'src/test8.c')
-rw-r--r--src/test8.c38
1 files changed, 34 insertions, 4 deletions
diff --git a/src/test8.c b/src/test8.c
index 0c5dc0206..3e506e36b 100644
--- a/src/test8.c
+++ b/src/test8.c
@@ -746,6 +746,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; i<pTab->nCol; 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
** real table. For example, if the real table is declared as:
@@ -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; ii<pIdxInfo->nConstraint; ii++){
const struct sqlite3_index_constraint *pConstraint;
struct sqlite3_index_constraint_usage *pUsage;