diff options
author | drh <drh@noemail.net> | 2018-11-16 19:19:58 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2018-11-16 19:19:58 +0000 |
commit | d16f26a7088719f75b00f5a433d635770fcb941d (patch) | |
tree | 8ff25a94d28118e8e5ac12d5a0f74aa35c8e128c /ext/misc/explain.c | |
parent | 43579191e877219d00f2f39ab17b606f6ea8d6bb (diff) | |
download | sqlite-d16f26a7088719f75b00f5a433d635770fcb941d.tar.gz sqlite-d16f26a7088719f75b00f5a433d635770fcb941d.zip |
Update the explain virtual table to make use of SQLITE_CONSTRAINT.
FossilOrigin-Name: b2d41ff7027b44ccb5dffc303c47d42f1f6fd66ce22e90450d3a666c73fe8b8e
Diffstat (limited to 'ext/misc/explain.c')
-rw-r--r-- | ext/misc/explain.c | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/ext/misc/explain.c b/ext/misc/explain.c index dc0c9d766..7a2fc4776 100644 --- a/ext/misc/explain.c +++ b/ext/misc/explain.c @@ -18,6 +18,10 @@ ** .load ./explain ** SELECT p2 FROM explain('SELECT * FROM sqlite_master') ** WHERE opcode='OpenRead'; +** +** This module was originally written to help simplify SQLite testing, +** by providing an easier means of verifying certain patterns in the +** generated bytecode. */ #if !defined(SQLITEINT_H) #include "sqlite3ext.h" @@ -232,23 +236,31 @@ static int explainBestIndex( sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo ){ - int i; + int i; /* Loop counter */ + int idx = -1; /* Index of a usable == constraint against SQL */ + int unusable = 0; /* True if there are unusable constraints on SQL */ - pIdxInfo->estimatedCost = (double)1000000; pIdxInfo->estimatedRows = 500; for(i=0; i<pIdxInfo->nConstraint; i++){ struct sqlite3_index_constraint *p = &pIdxInfo->aConstraint[i]; - if( p->usable - && p->iColumn==EXPLN_COLUMN_SQL - && p->op==SQLITE_INDEX_CONSTRAINT_EQ - ){ - pIdxInfo->estimatedCost = 10.0; - pIdxInfo->idxNum = 1; - pIdxInfo->aConstraintUsage[i].argvIndex = 1; - pIdxInfo->aConstraintUsage[i].omit = 1; - break; + if( p->iColumn!=EXPLN_COLUMN_SQL ) continue; + if( !p->usable ){ + unusable = 1; + }else if( p->op==SQLITE_INDEX_CONSTRAINT_EQ ){ + idx = i; } } + if( idx>=0 ){ + /* There exists a usable == constraint against the SQL column */ + pIdxInfo->estimatedCost = 10.0; + pIdxInfo->idxNum = 1; + pIdxInfo->aConstraintUsage[idx].argvIndex = 1; + pIdxInfo->aConstraintUsage[idx].omit = 1; + }else if( unusable ){ + /* There are unusable constraints against the SQL column. Do not allow + ** this plan to continue forward. */ + return SQLITE_CONSTRAINT; + } return SQLITE_OK; } |