When testing non-indexed WHERE constraints, test those that involve
correlated sub-queries last of all. This increases the chances of not having to run the sub-query at all. FossilOrigin-Name: 1f9c1f359e4693954ba7e2bc7b172ef34eb046e4ca2796df8336975b9d6aa92b
This commit is contained in:
parent
9f6e14c1ef
commit
ebc63013b7
19
manifest
19
manifest
@ -1,5 +1,5 @@
|
||||
C For\ssqlite3TreeView()\sdebugging\soutput,\sshow\sthe\sExpr.flags\sfield\son\nscalar\ssubqueries.
|
||||
D 2017-07-10T13:24:58.019
|
||||
C When\stesting\snon-indexed\sWHERE\sconstraints,\stest\sthose\sthat\sinvolve\ncorrelated\ssub-queries\slast\sof\sall.\sThis\sincreases\sthe\schances\sof\snot\shaving\nto\srun\sthe\ssub-query\sat\sall.
|
||||
D 2017-07-10T14:33:00.503
|
||||
F Makefile.in 081e48dfe7f995d57ce1a88ddf4d2917b4349158648a6cd45b42beae30de3a12
|
||||
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
|
||||
F Makefile.msc 20850e3e8d4d4791e0531955852d768eb06f24138214870d543abb1a47346fba
|
||||
@ -453,7 +453,7 @@ F src/shell.c a7067f647aef4b81569bbfd025f4fd120a4e7576a647d2aad05028eb50e50e48
|
||||
F src/sqlite.h.in 03a422ba13da1dfef7f1aaa1ba344acf18dc867112620b1fdb2a1426cabba634
|
||||
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
|
||||
F src/sqlite3ext.h 58fd0676d3111d02e62e5a35992a7d3da5d3f88753acc174f2d37b774fbbdd28
|
||||
F src/sqliteInt.h 7a7cd6f682471cce4afe64216f71fd64c622712aeb9d947c33c38337a7cf19a9
|
||||
F src/sqliteInt.h 44398832c9eea319c618fd046678dd929127010a0923a0af97c6b2bc1a18fb81
|
||||
F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b
|
||||
F src/status.c a9e66593dfb28a9e746cba7153f84d49c1ddc4b1
|
||||
F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34
|
||||
@ -531,7 +531,7 @@ F src/wal.h 06b2a0b599cc0f53ea97f497cf8c6b758c999f71
|
||||
F src/walker.c a7ca64ce08a83a20d32186fbe06bca9234e348cfcf07959ee322fdc3e8a6173a
|
||||
F src/where.c e7cc80943459ade4ccaeb5c7c10f8a0db8b797e0b0f2509de7efc557b76bf7b6
|
||||
F src/whereInt.h 2a4b634d63ce488b46d4b0da8f2eaa8f9aeab202bc25ef76f007de5e3fba1f20
|
||||
F src/wherecode.c f17f5d51e372168db51af637e265aa5e80f99fcc81bfead96b66e71a7732bc62
|
||||
F src/wherecode.c 3eb2130872cb2c570b519dcb7fe34d2bfd1d515292c5131874e797044f8ef832
|
||||
F src/whereexpr.c fa51927cc6830b9d3155cafa4e589452ec023fe313a56550d2079dca6c52fbd8
|
||||
F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
|
||||
F test/affinity2.test a6d901b436328bd67a79b41bb0ac2663918fe3bd
|
||||
@ -1628,7 +1628,10 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
|
||||
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
||||
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
||||
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
||||
P f27b6370407842e2c175ea4aa9ce018723c57eaac0cccc1f8399bc20f33324be
|
||||
R fcaff20edc67c3421a07c8a2f98bc875
|
||||
U drh
|
||||
Z 4c32d3cf2874c5b6c91c344882e30f5e
|
||||
P dc857a96b00f13ffdf77bc222bc5acbbe14a36ca51e5368b568b3177d1be737a
|
||||
R 2c3079a102d9ba8d31221f8f910d8428
|
||||
T *branch * defer-where-subqueries
|
||||
T *sym-defer-where-subqueries *
|
||||
T -sym-trunk *
|
||||
U dan
|
||||
Z 903fd4acf5ba1f2541b4e3fb6b879043
|
||||
|
@ -1 +1 @@
|
||||
dc857a96b00f13ffdf77bc222bc5acbbe14a36ca51e5368b568b3177d1be737a
|
||||
1f9c1f359e4693954ba7e2bc7b172ef34eb046e4ca2796df8336975b9d6aa92b
|
@ -2398,7 +2398,7 @@ struct Expr {
|
||||
/*
|
||||
** Combinations of two or more EP_* flags
|
||||
*/
|
||||
#define EP_Propagate (EP_Collate|EP_Subquery) /* Propagate these bits up tree */
|
||||
#define EP_Propagate (EP_Collate|EP_Subquery|EP_VarSelect) /* Prop. up tree */
|
||||
|
||||
/*
|
||||
** These macros can be used to test, set, or clear bits in the
|
||||
|
@ -1130,7 +1130,7 @@ Bitmask sqlite3WhereCodeOneLoopStart(
|
||||
int iRowidReg = 0; /* Rowid is stored in this register, if not zero */
|
||||
int iReleaseReg = 0; /* Temp register to free before returning */
|
||||
Index *pIdx = 0; /* Index used by loop (if any) */
|
||||
int loopAgain; /* True if constraint generator loop should repeat */
|
||||
int iLoop; /* Iteration of constraint generator loop */
|
||||
|
||||
pParse = pWInfo->pParse;
|
||||
v = pParse->pVdbe;
|
||||
@ -2025,13 +2025,20 @@ Bitmask sqlite3WhereCodeOneLoopStart(
|
||||
/* Insert code to test every subexpression that can be completely
|
||||
** computed using the current set of tables.
|
||||
**
|
||||
** This loop may run either once (pIdx==0) or twice (pIdx!=0). If
|
||||
** it is run twice, then the first iteration codes those sub-expressions
|
||||
** that can be computed using columns from pIdx only (without seeking
|
||||
** the main table cursor).
|
||||
** This loop may run between one and three times, depending on the
|
||||
** constraints to be generated. The value of stack variable iLoop
|
||||
** determines the constraints coded by each iteration, as follows:
|
||||
**
|
||||
** iLoop==1: Code only expressions that are entirely covered by pIdx.
|
||||
** iLoop==2: Code remaining expressions that do not contain correlated
|
||||
** sub-queries.
|
||||
** iLoop==3: Code all remaining expressions.
|
||||
**
|
||||
** An effort is made to skip unnecessary iterations of the loop.
|
||||
*/
|
||||
iLoop = (pIdx ? 1 : 2);
|
||||
do{
|
||||
loopAgain = 0;
|
||||
int iNext = 0; /* Next value for iLoop */
|
||||
for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
|
||||
Expr *pE;
|
||||
int skipLikeAddr = 0;
|
||||
@ -2049,10 +2056,16 @@ Bitmask sqlite3WhereCodeOneLoopStart(
|
||||
if( pLevel->iLeftJoin && !ExprHasProperty(pE, EP_FromJoin) ){
|
||||
continue;
|
||||
}
|
||||
if( pIdx && !sqlite3ExprCoveredByIndex(pE, pLevel->iTabCur, pIdx) ){
|
||||
loopAgain = 1;
|
||||
|
||||
if( iNext==1 && !sqlite3ExprCoveredByIndex(pE, pLevel->iTabCur, pIdx) ){
|
||||
iNext = 2;
|
||||
continue;
|
||||
}
|
||||
if( iLoop<3 && (pE->flags & EP_VarSelect) ){
|
||||
if( iNext==0 ) iNext = 3;
|
||||
continue;
|
||||
}
|
||||
|
||||
if( pTerm->wtFlags & TERM_LIKECOND ){
|
||||
/* If the TERM_LIKECOND flag is set, that means that the range search
|
||||
** is sufficient to guarantee that the LIKE operator is true, so we
|
||||
@ -2072,8 +2085,8 @@ Bitmask sqlite3WhereCodeOneLoopStart(
|
||||
if( skipLikeAddr ) sqlite3VdbeJumpHere(v, skipLikeAddr);
|
||||
pTerm->wtFlags |= TERM_CODED;
|
||||
}
|
||||
pIdx = 0;
|
||||
}while( loopAgain );
|
||||
iLoop = iNext;
|
||||
}while( iLoop>0 );
|
||||
|
||||
/* Insert code to test for implied constraints based on transitivity
|
||||
** of the "==" operator.
|
||||
|
Loading…
x
Reference in New Issue
Block a user