diff options
author | drh <> | 2024-03-25 11:34:42 +0000 |
---|---|---|
committer | drh <> | 2024-03-25 11:34:42 +0000 |
commit | 41c9945c746018b3bcec1e6ecc3e900f7b209ce4 (patch) | |
tree | e1119cb67f8f9191aa0090c936986d892a1cafac /src | |
parent | 4397d2837889a5b9c8d6ac26b19281acba45ff61 (diff) | |
download | sqlite-41c9945c746018b3bcec1e6ecc3e900f7b209ce4.tar.gz sqlite-41c9945c746018b3bcec1e6ecc3e900f7b209ce4.zip |
Use the SQLITE_CONSTRAINT return value from xBestIndex to prohibit bad
query plans in the pragma virtual table.
FossilOrigin-Name: b1259d4448f744861e416f42328c1450854370e5c77102d2a5abe5cf6c7f12bd
Diffstat (limited to 'src')
-rw-r--r-- | src/pragma.c | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/src/pragma.c b/src/pragma.c index d14428f75..8af18cbf2 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -2870,9 +2870,9 @@ static int pragmaVtabBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){ seen[0] = 0; seen[1] = 0; for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){ - if( pConstraint->usable==0 ) continue; - if( pConstraint->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue; if( pConstraint->iColumn < pTab->iHidden ) continue; + if( pConstraint->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue; + if( pConstraint->usable==0 ) return SQLITE_CONSTRAINT; j = pConstraint->iColumn - pTab->iHidden; assert( j < 2 ); seen[j] = i+1; @@ -2885,16 +2885,13 @@ static int pragmaVtabBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){ j = seen[0]-1; pIdxInfo->aConstraintUsage[j].argvIndex = 1; pIdxInfo->aConstraintUsage[j].omit = 1; - if( seen[1]==0 ){ - pIdxInfo->estimatedCost = (double)1000; - pIdxInfo->estimatedRows = 1000; - return SQLITE_OK; - } pIdxInfo->estimatedCost = (double)20; pIdxInfo->estimatedRows = 20; - j = seen[1]-1; - pIdxInfo->aConstraintUsage[j].argvIndex = 2; - pIdxInfo->aConstraintUsage[j].omit = 1; + if( seen[1] ){ + j = seen[1]-1; + pIdxInfo->aConstraintUsage[j].argvIndex = 2; + pIdxInfo->aConstraintUsage[j].omit = 1; + } return SQLITE_OK; } |