mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-08 14:02:16 +03:00
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
This commit is contained in:
38
src/test8.c
38
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; 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
|
||||
@@ -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;
|
||||
|
Reference in New Issue
Block a user