aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/sqlite.h.in13
-rw-r--r--src/test8.c38
-rw-r--r--src/update.c8
-rw-r--r--src/where.c1
4 files changed, 53 insertions, 7 deletions
diff --git a/src/sqlite.h.in b/src/sqlite.h.in
index 54ce42dee..6ad3da5df 100644
--- a/src/sqlite.h.in
+++ b/src/sqlite.h.in
@@ -5625,6 +5625,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
@@ -5704,6 +5715,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 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;
diff --git a/src/update.c b/src/update.c
index 1335c269e..a9735cadc 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 737bfc4e6..30ad58e01 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;