mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-18 10:21:03 +03:00
Simplifications to the initialization of the sqlite3_index_info structure
that is used to communicate with virtual table modules. Avoid adding unused constraints to the sqlite3_index_info structure. Extra constraints are harmless, but might be confusing to people trying to understand the code. FossilOrigin-Name: 5e6357fc953a955d8ebb5c1fcd72e04e4ae5e8bf5941810015c2fbc50de70535
This commit is contained in:
30
src/where.c
30
src/where.c
@@ -605,7 +605,7 @@ static void translateColumnToCopy(
|
||||
** are no-ops.
|
||||
*/
|
||||
#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(WHERETRACE_ENABLED)
|
||||
static void TRACE_IDX_INPUTS(sqlite3_index_info *p){
|
||||
static void whereTraceIndexInfoInputs(sqlite3_index_info *p){
|
||||
int i;
|
||||
if( !sqlite3WhereTrace ) return;
|
||||
for(i=0; i<p->nConstraint; i++){
|
||||
@@ -623,7 +623,7 @@ static void TRACE_IDX_INPUTS(sqlite3_index_info *p){
|
||||
p->aOrderBy[i].desc);
|
||||
}
|
||||
}
|
||||
static void TRACE_IDX_OUTPUTS(sqlite3_index_info *p){
|
||||
static void whereTraceIndexInfoOutputs(sqlite3_index_info *p){
|
||||
int i;
|
||||
if( !sqlite3WhereTrace ) return;
|
||||
for(i=0; i<p->nConstraint; i++){
|
||||
@@ -639,8 +639,8 @@ static void TRACE_IDX_OUTPUTS(sqlite3_index_info *p){
|
||||
sqlite3DebugPrintf(" estimatedRows=%lld\n", p->estimatedRows);
|
||||
}
|
||||
#else
|
||||
#define TRACE_IDX_INPUTS(A)
|
||||
#define TRACE_IDX_OUTPUTS(A)
|
||||
#define whereTraceIndexInfoInputs(A)
|
||||
#define whereTraceIndexInfoOutputs(A)
|
||||
#endif
|
||||
|
||||
#ifndef SQLITE_OMIT_AUTOMATIC_INDEX
|
||||
@@ -950,23 +950,14 @@ static sqlite3_index_info *allocateIndexInfo(
|
||||
sqlite3ErrorMsg(pParse, "out of memory");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Initialize the structure. The sqlite3_index_info structure contains
|
||||
** many fields that are declared "const" to prevent xBestIndex from
|
||||
** changing them. We have to do some funky casting in order to
|
||||
** initialize those fields.
|
||||
*/
|
||||
pHidden = (struct HiddenIndexInfo*)&pIdxInfo[1];
|
||||
pIdxCons = (struct sqlite3_index_constraint*)&pHidden[1];
|
||||
pIdxOrderBy = (struct sqlite3_index_orderby*)&pIdxCons[nTerm];
|
||||
pUsage = (struct sqlite3_index_constraint_usage*)&pIdxOrderBy[nOrderBy];
|
||||
*(int*)&pIdxInfo->nConstraint = nTerm;
|
||||
*(int*)&pIdxInfo->nOrderBy = nOrderBy;
|
||||
*(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint = pIdxCons;
|
||||
*(struct sqlite3_index_orderby**)&pIdxInfo->aOrderBy = pIdxOrderBy;
|
||||
*(struct sqlite3_index_constraint_usage**)&pIdxInfo->aConstraintUsage =
|
||||
pUsage;
|
||||
|
||||
pIdxInfo->nOrderBy = nOrderBy;
|
||||
pIdxInfo->aConstraint = pIdxCons;
|
||||
pIdxInfo->aOrderBy = pIdxOrderBy;
|
||||
pIdxInfo->aConstraintUsage = pUsage;
|
||||
pHidden->pWC = pWC;
|
||||
pHidden->pParse = pParse;
|
||||
for(i=j=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
|
||||
@@ -1026,6 +1017,7 @@ static sqlite3_index_info *allocateIndexInfo(
|
||||
|
||||
j++;
|
||||
}
|
||||
pIdxInfo->nConstraint = j;
|
||||
for(i=0; i<nOrderBy; i++){
|
||||
Expr *pExpr = pOrderBy->a[i].pExpr;
|
||||
pIdxOrderBy[i].iColumn = pExpr->iColumn;
|
||||
@@ -1056,9 +1048,9 @@ static int vtabBestIndex(Parse *pParse, Table *pTab, sqlite3_index_info *p){
|
||||
sqlite3_vtab *pVtab = sqlite3GetVTable(pParse->db, pTab)->pVtab;
|
||||
int rc;
|
||||
|
||||
TRACE_IDX_INPUTS(p);
|
||||
whereTraceIndexInfoInputs(p);
|
||||
rc = pVtab->pModule->xBestIndex(pVtab, p);
|
||||
TRACE_IDX_OUTPUTS(p);
|
||||
whereTraceIndexInfoOutputs(p);
|
||||
|
||||
if( rc!=SQLITE_OK && rc!=SQLITE_CONSTRAINT ){
|
||||
if( rc==SQLITE_NOMEM ){
|
||||
|
||||
Reference in New Issue
Block a user