From 9978e6a680fb24a29ac25854e6948b9d8ab50c21 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 17 Jun 2014 02:46:55 +0000 Subject: [PATCH 1/5] Do not attempt to create an automatic index on a constant constraint, as doing so is pointless. FossilOrigin-Name: d6883e960f61365729f279a3c1f2c050beb49a55 --- manifest | 17 ++++++++++------- manifest.uuid | 2 +- src/where.c | 1 + 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 33d3388ac9..420bfeac91 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sCSV\simport\sissue,\sreported\svia\sthe\smailing\slist,\sin\sthe\sshell\swhen\sthe\sfile\sto\sbe\simported\sends\swith\san\sempty\sline. -D 2014-06-16T22:45:28.779 +C Do\snot\sattempt\sto\screate\san\sautomatic\sindex\son\sa\sconstant\sconstraint,\sas\ndoing\sso\sis\spointless. +D 2014-06-17T02:46:55.317 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in ed5e4aae4799f724699d5509fac2977786414dbb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -296,7 +296,7 @@ F src/vtab.c 21b932841e51ebd7d075e2d0ad1415dce8d2d5fd F src/wal.c 264df50a1b33124130b23180ded2e2c5663c652a F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c 11edb74d587bc87b33ca96a5173e3ec1b8389e45 -F src/where.c 5ee08882fdc1a4661766a6dae639bd79cabb28fa +F src/where.c 46e94a513fa783a950889e924b253339e498d600 F src/whereInt.h 929c1349b5355fd44f22cee5c14d72b3329c58a6 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -1177,7 +1177,10 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 3181d2069a788adc719decf65dc1bd2e16650c87 -R e15c594b7f416cdaa03cc5ded52dfa16 -U mistachkin -Z ca873ea75a4dc77a2f68671379d28791 +P fc918f7d332b8f7cabc79a0f1586bd6760d14d40 +R c05b0f400c5eb501cd2d5ddbdc6430c7 +T *branch * autoindex-improvements +T *sym-autoindex-improvements * +T -sym-trunk * +U drh +Z 93418c6f90150cfc0b0ae16a3328fb2a diff --git a/manifest.uuid b/manifest.uuid index 2f140ef165..7f4c5b13a3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fc918f7d332b8f7cabc79a0f1586bd6760d14d40 \ No newline at end of file +d6883e960f61365729f279a3c1f2c050beb49a55 \ No newline at end of file diff --git a/src/where.c b/src/where.c index 8c6f4bbbe3..d2723dd5b6 100644 --- a/src/where.c +++ b/src/where.c @@ -4529,6 +4529,7 @@ static int whereLoopAddBtree( WhereTerm *pWCEnd = pWC->a + pWC->nTerm; for(pTerm=pWC->a; rc==SQLITE_OK && pTermprereqRight & pNew->maskSelf ) continue; + if( pTerm->prereqRight==0 ) continue; if( termCanDriveIndex(pTerm, pSrc, 0) ){ pNew->u.btree.nEq = 1; pNew->u.btree.nSkip = 0; From 6b7ff748a1c20ee882a3ac6f3146e21be469983a Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 17 Jun 2014 09:00:54 +0000 Subject: [PATCH 2/5] Allow an automatic index on a WHERE constraint where the RHS is does not reference another table as long as the RHS is not a constant. FossilOrigin-Name: 58acc2a8b38c5f13175c191697b4d2b663db1872 --- ext/rtree/rtree6.test | 10 ++++++++-- manifest | 19 ++++++++----------- manifest.uuid | 2 +- src/where.c | 5 ++++- test/tpch01.test | 7 ++++++- 5 files changed, 27 insertions(+), 16 deletions(-) diff --git a/ext/rtree/rtree6.test b/ext/rtree/rtree6.test index c5a78bb3e3..9e51993bd8 100644 --- a/ext/rtree/rtree6.test +++ b/ext/rtree/rtree6.test @@ -92,12 +92,18 @@ do_eqp_test rtree6.2.3 { 0 1 1 {SEARCH TABLE t2 USING INTEGER PRIMARY KEY (rowid=?)} } -do_eqp_test rtree6.2.4 { - SELECT * FROM t1,t2 WHERE v=10 and x1<10 and x2>10 +do_eqp_test rtree6.2.4.1 { + SELECT * FROM t1,t2 WHERE v=+ii and x1<10 and x2>10 } { 0 0 0 {SCAN TABLE t1 VIRTUAL TABLE INDEX 2:C0E1} 0 1 1 {SEARCH TABLE t2 USING AUTOMATIC COVERING INDEX (v=?)} } +do_eqp_test rtree6.2.4.2 { + SELECT * FROM t1,t2 WHERE v=10 and x1<10 and x2>10 +} { + 0 0 0 {SCAN TABLE t1 VIRTUAL TABLE INDEX 2:C0E1} + 0 1 1 {SCAN TABLE t2} +} do_eqp_test rtree6.2.5 { SELECT * FROM t1,t2 WHERE k=ii AND x1a + pWC->nTerm; for(pTerm=pWC->a; rc==SQLITE_OK && pTermprereqRight & pNew->maskSelf ) continue; - if( pTerm->prereqRight==0 ) continue; + if( pTerm->prereqRight==0 + && sqlite3ExprIsConstant(pTerm->pExpr->pRight) ){ + continue; + } if( termCanDriveIndex(pTerm, pSrc, 0) ){ pNew->u.btree.nEq = 1; pNew->u.btree.nSkip = 0; diff --git a/test/tpch01.test b/test/tpch01.test index 2d099d63fb..ce48f8ec23 100644 --- a/test/tpch01.test +++ b/test/tpch01.test @@ -168,7 +168,10 @@ do_test tpch01-1.1 { } {/0 0 0 {SEARCH TABLE part USING INDEX bootleg_pti .P_TYPE=..} 0 1 2 {SEARCH TABLE lineitem USING INDEX lpki2 .L_PARTKEY=..}.*/} do_test tpch01-1.1b { set ::eqpres -} {/.* customer .* nation AS n1 .* nation AS n2 .*/} +} {/.* customer .* nation AS n1 .*/} +do_test tpch01-1.1c { + set ::eqpres +} {/.* supplier .* nation AS n2 .*/} do_eqp_test tpch01-1.2 { select @@ -185,3 +188,5 @@ group by order by revenue desc; } {0 0 1 {SEARCH TABLE orders USING INDEX odi (O_ORDERDATE>? AND O_ORDERDATE Date: Tue, 17 Jun 2014 09:52:26 +0000 Subject: [PATCH 3/5] Simplification to the logic that prevents automatic indexes from being formed on constant expressions. FossilOrigin-Name: 36d67e1dd2b4f4c22d02f3c3b8d372074de5523a --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/where.c | 5 +---- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 253d4bcb86..17c12ccb2d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Allow\san\sautomatic\sindex\son\sa\sWHERE\sconstraint\swhere\sthe\sRHS\sis\sdoes\snot\nreference\sanother\stable\sas\slong\sas\sthe\sRHS\sis\snot\sa\sconstant. -D 2014-06-17T09:00:54.229 +C Simplification\sto\sthe\slogic\sthat\sprevents\sautomatic\sindexes\sfrom\sbeing\sformed\non\sconstant\sexpressions. +D 2014-06-17T09:52:26.975 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in ed5e4aae4799f724699d5509fac2977786414dbb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -296,7 +296,7 @@ F src/vtab.c 21b932841e51ebd7d075e2d0ad1415dce8d2d5fd F src/wal.c 264df50a1b33124130b23180ded2e2c5663c652a F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c 11edb74d587bc87b33ca96a5173e3ec1b8389e45 -F src/where.c d6a284abd9a1b4c1e617e5208e695cd6f0616ae1 +F src/where.c 3214e390ca5ff0b19fb5084e5bd5870da623389d F src/whereInt.h 929c1349b5355fd44f22cee5c14d72b3329c58a6 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -1177,7 +1177,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P d6883e960f61365729f279a3c1f2c050beb49a55 -R e7b366f668336ead2394408b5846caa4 +P 58acc2a8b38c5f13175c191697b4d2b663db1872 +R 91ed31168e6ce0a5afee4b984323de5e U drh -Z ded0b7f99669cd2fc0f45c3d542cb907 +Z ee443673993fc3ea86368d30ccfb6dad diff --git a/manifest.uuid b/manifest.uuid index df61c8be5b..385f247806 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -58acc2a8b38c5f13175c191697b4d2b663db1872 \ No newline at end of file +36d67e1dd2b4f4c22d02f3c3b8d372074de5523a \ No newline at end of file diff --git a/src/where.c b/src/where.c index 8550231c30..1caaf73df7 100644 --- a/src/where.c +++ b/src/where.c @@ -4529,10 +4529,7 @@ static int whereLoopAddBtree( WhereTerm *pWCEnd = pWC->a + pWC->nTerm; for(pTerm=pWC->a; rc==SQLITE_OK && pTermprereqRight & pNew->maskSelf ) continue; - if( pTerm->prereqRight==0 - && sqlite3ExprIsConstant(pTerm->pExpr->pRight) ){ - continue; - } + if( sqlite3ExprIsConstant(pTerm->pExpr->pRight) ) continue; if( termCanDriveIndex(pTerm, pSrc, 0) ){ pNew->u.btree.nEq = 1; pNew->u.btree.nSkip = 0; From 9740726121e91ec19cc3438844d12cf25eaa2a95 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 17 Jun 2014 12:33:55 +0000 Subject: [PATCH 4/5] A different approach to the autoindex problem that deletes query-planner code rather than adding it. FossilOrigin-Name: f270fb6e9e0b5e77f918081962008c6195ab1e36 --- ext/rtree/rtree6.test | 2 +- manifest | 14 +++++++------- manifest.uuid | 2 +- src/where.c | 10 ++-------- 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/ext/rtree/rtree6.test b/ext/rtree/rtree6.test index 9e51993bd8..cec3a8da41 100644 --- a/ext/rtree/rtree6.test +++ b/ext/rtree/rtree6.test @@ -102,7 +102,7 @@ do_eqp_test rtree6.2.4.2 { SELECT * FROM t1,t2 WHERE v=10 and x1<10 and x2>10 } { 0 0 0 {SCAN TABLE t1 VIRTUAL TABLE INDEX 2:C0E1} - 0 1 1 {SCAN TABLE t2} + 0 1 1 {SEARCH TABLE t2 USING AUTOMATIC COVERING INDEX (v=?)} } do_eqp_test rtree6.2.5 { diff --git a/manifest b/manifest index 17c12ccb2d..374e71d7ac 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Simplification\sto\sthe\slogic\sthat\sprevents\sautomatic\sindexes\sfrom\sbeing\sformed\non\sconstant\sexpressions. -D 2014-06-17T09:52:26.975 +C A\sdifferent\sapproach\sto\sthe\sautoindex\sproblem\sthat\sdeletes\squery-planner\scode\nrather\sthan\sadding\sit. +D 2014-06-17T12:33:55.348 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in ed5e4aae4799f724699d5509fac2977786414dbb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -129,7 +129,7 @@ F ext/rtree/rtree2.test acbb3a4ce0f4fbc2c304d2b4b784cfa161856bba F ext/rtree/rtree3.test a494da55c30ee0bc9b01a91c80c81b387b22d2dc F ext/rtree/rtree4.test c8fe384f60ebd49540a5fecc990041bf452eb6e0 F ext/rtree/rtree5.test 6a510494f12454bf57ef28f45bc7764ea279431e -F ext/rtree/rtree6.test 83a997caf27eeca990291f66277e5a136428479a +F ext/rtree/rtree6.test 0cfbdf27ee086bf16a3da2c6f2d5b3d6473cb27e F ext/rtree/rtree7.test 1fa710b9e6bf997a0c1a537b81be7bb6fded1971 F ext/rtree/rtree8.test db79c812f9e4a11f9b1f3f9934007884610a713a F ext/rtree/rtree9.test d86ebf08ff6328895613ed577dd8a2a37c472c34 @@ -296,7 +296,7 @@ F src/vtab.c 21b932841e51ebd7d075e2d0ad1415dce8d2d5fd F src/wal.c 264df50a1b33124130b23180ded2e2c5663c652a F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c 11edb74d587bc87b33ca96a5173e3ec1b8389e45 -F src/where.c 3214e390ca5ff0b19fb5084e5bd5870da623389d +F src/where.c cd3110c7dca304ecbdf2ed07b23205e90b10475b F src/whereInt.h 929c1349b5355fd44f22cee5c14d72b3329c58a6 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -1177,7 +1177,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 58acc2a8b38c5f13175c191697b4d2b663db1872 -R 91ed31168e6ce0a5afee4b984323de5e +P 36d67e1dd2b4f4c22d02f3c3b8d372074de5523a +R f31fb5c411bc798b3e39eb24696f39dc U drh -Z ee443673993fc3ea86368d30ccfb6dad +Z d63276e1ce6bb05efdbf1c4b12bc995b diff --git a/manifest.uuid b/manifest.uuid index 385f247806..142b9c98b5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -36d67e1dd2b4f4c22d02f3c3b8d372074de5523a \ No newline at end of file +f270fb6e9e0b5e77f918081962008c6195ab1e36 \ No newline at end of file diff --git a/src/where.c b/src/where.c index 1caaf73df7..5fd4618bb1 100644 --- a/src/where.c +++ b/src/where.c @@ -4529,7 +4529,6 @@ static int whereLoopAddBtree( WhereTerm *pWCEnd = pWC->a + pWC->nTerm; for(pTerm=pWC->a; rc==SQLITE_OK && pTermprereqRight & pNew->maskSelf ) continue; - if( sqlite3ExprIsConstant(pTerm->pExpr->pRight) ) continue; if( termCanDriveIndex(pTerm, pSrc, 0) ){ pNew->u.btree.nEq = 1; pNew->u.btree.nSkip = 0; @@ -5279,7 +5278,6 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){ LogEst rCost; /* Cost of a path */ LogEst nOut; /* Number of outputs */ LogEst mxCost = 0; /* Maximum cost of a set of paths */ - LogEst mxOut = 0; /* Maximum nOut value on the set of paths */ int nTo, nFrom; /* Number of valid entries in aTo[] and aFrom[] */ WherePath *aFrom; /* All nFrom paths at the previous level */ WherePath *aTo; /* The nTo best paths at the current level */ @@ -5389,8 +5387,6 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){ for(jj=0, pTo=aTo; jjmaskLoop==maskNew && ((pTo->isOrdered^isOrdered)&80)==0 - && ((pTo->rCost<=rCost && pTo->nRow<=nOut) || - (pTo->rCost>=rCost && pTo->nRow>=nOut)) ){ testcase( jj==nTo-1 ); break; @@ -5424,7 +5420,7 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){ } #endif }else{ - if( pTo->rCost<=rCost && pTo->nRow<=nOut ){ + if( pTo->rCost<=rCost ){ #ifdef WHERETRACE_ENABLED /* 0x4 */ if( sqlite3WhereTrace&0x4 ){ sqlite3DebugPrintf( @@ -5464,11 +5460,9 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){ if( nTo>=mxChoice ){ mxI = 0; mxCost = aTo[0].rCost; - mxOut = aTo[0].nRow; for(jj=1, pTo=&aTo[1]; jjrCost>mxCost || (pTo->rCost==mxCost && pTo->nRow>mxOut) ){ + if( pTo->rCost>mxCost ){ mxCost = pTo->rCost; - mxOut = pTo->nRow; mxI = jj; } } From 2daa64cd631078a0c3c01be1c857de4d2eea1b28 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 17 Jun 2014 13:23:36 +0000 Subject: [PATCH 5/5] Add the autoindex2.test testing module. FossilOrigin-Name: ffe3fea47b8ba8ec4557f68243ef3ef5aac00dfd --- manifest | 11 +- manifest.uuid | 2 +- test/autoindex2.test | 271 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 278 insertions(+), 6 deletions(-) create mode 100644 test/autoindex2.test diff --git a/manifest b/manifest index 374e71d7ac..49473453ec 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C A\sdifferent\sapproach\sto\sthe\sautoindex\sproblem\sthat\sdeletes\squery-planner\scode\nrather\sthan\sadding\sit. -D 2014-06-17T12:33:55.348 +C Add\sthe\sautoindex2.test\stesting\smodule. +D 2014-06-17T13:23:36.416 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in ed5e4aae4799f724699d5509fac2977786414dbb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -335,6 +335,7 @@ F test/auth2.test c3b415b76c033bedb81292118fb7c01f5f10cbcd F test/auth3.test a4755e6a2a2fea547ffe63c874eb569e60a28eb5 F test/autoinc.test c58912526998a39e11f66b533e23cfabea7f25b7 F test/autoindex1.test 762ff3f8e25d852aae55c6462ca166a80c0cde61 +F test/autoindex2.test 60d2fc6f38364308ce73a9beb01b47ded38697de F test/autovacuum.test 941892505d2c0f410a0cb5970dfa1c7c4e5f6e74 F test/autovacuum_ioerr2.test 8a367b224183ad801e0e24dcb7d1501f45f244b4 F test/avtrans.test 0252654f4295ddda3b2cce0e894812259e655a85 @@ -1177,7 +1178,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 36d67e1dd2b4f4c22d02f3c3b8d372074de5523a -R f31fb5c411bc798b3e39eb24696f39dc +P f270fb6e9e0b5e77f918081962008c6195ab1e36 +R 4590197fe44138640af30c15c42aaab1 U drh -Z d63276e1ce6bb05efdbf1c4b12bc995b +Z c2b8b2abeb08d5199560396ab0f820e5 diff --git a/manifest.uuid b/manifest.uuid index 142b9c98b5..843a903c19 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f270fb6e9e0b5e77f918081962008c6195ab1e36 \ No newline at end of file +ffe3fea47b8ba8ec4557f68243ef3ef5aac00dfd \ No newline at end of file diff --git a/test/autoindex2.test b/test/autoindex2.test new file mode 100644 index 0000000000..f4da416745 --- /dev/null +++ b/test/autoindex2.test @@ -0,0 +1,271 @@ +# 2014-06-17 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#************************************************************************* +# +# This file implements regression tests for SQLite library. The +# focus of this script is testing automatic index creation logic. +# +# This file contains a single real-world test case that was giving +# suboptimal performance because of over-use of automatic indexes. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + + +do_execsql_test autoindex2-100 { + CREATE TABLE t1( + t1_id largeint, + did char(9), + ptime largeint, + exbyte char(4), + pe_id int, + field_id int, + mass float, + param10 float, + param11 float, + exmass float, + deviation float, + trange float, + vstatus int, + commit_status int, + formula char(329), + tier int DEFAULT 2, + ssid int DEFAULT 0, + last_operation largeint DEFAULT 0, + admin_uuid int DEFAULT 0, + previous_value float, + job_id largeint, + last_t1 largeint DEFAULT 0, + data_t1 int, + previous_date largeint DEFAULT 0, + flg8 int DEFAULT 1, + failed_fields char(100) + ); + CREATE INDEX t1x0 on t1 (t1_id); + CREATE INDEX t1x1 on t1 (ptime, vstatus); + CREATE INDEX t1x2 on t1 (did, ssid, ptime, vstatus, exbyte, t1_id); + CREATE INDEX t1x3 on t1 (job_id); + + CREATE TABLE t2( + did char(9), + client_did char(30), + description char(49), + uid int, + tzid int, + privilege int, + param2 int, + type char(30), + subtype char(32), + dparam1 char(7) DEFAULT '', + param5 char(3) DEFAULT '', + notional float DEFAULT 0.000000, + create_time largeint, + sample_time largeint DEFAULT 0, + param6 largeint, + frequency int, + expiration largeint, + uw_status int, + next_sample largeint, + last_sample largeint, + reserve1 char(29) DEFAULT '', + reserve2 char(29) DEFAULT '', + reserve3 char(29) DEFAULT '', + bxcdr char(19) DEFAULT 'XY', + ssid int DEFAULT 1, + last_t1_id largeint, + reserve4 char(29) DEFAULT '', + reserve5 char(29) DEFAULT '', + param12 int DEFAULT 0, + long_did char(100) DEFAULT '', + gr_code int DEFAULT 0, + drx char(100) DEFAULT '', + parent_id char(9) DEFAULT '', + param13 int DEFAULT 0, + position float DEFAULT 1.000000, + client_did3 char(100) DEFAULT '', + client_did4 char(100) DEFAULT '', + dlib_id char(9) DEFAULT '' + ); + CREATE INDEX t2x0 on t2 (did); + CREATE INDEX t2x1 on t2 (client_did); + CREATE INDEX t2x2 on t2 (long_did); + CREATE INDEX t2x3 on t2 (uid); + CREATE INDEX t2x4 on t2 (param2); + CREATE INDEX t2x5 on t2 (type); + CREATE INDEX t2x6 on t2 (subtype); + CREATE INDEX t2x7 on t2 (last_sample); + CREATE INDEX t2x8 on t2 (param6); + CREATE INDEX t2x9 on t2 (frequency); + CREATE INDEX t2x10 on t2 (privilege); + CREATE INDEX t2x11 on t2 (sample_time); + CREATE INDEX t2x12 on t2 (notional); + CREATE INDEX t2x13 on t2 (tzid); + CREATE INDEX t2x14 on t2 (gr_code); + CREATE INDEX t2x15 on t2 (parent_id); + + CREATE TABLE t3( + uid int, + param3 int, + uuid int, + acc_id int, + cust_num int, + numerix_id int, + pfy char(29), + param4 char(29), + param15 int DEFAULT 0, + flg7 int DEFAULT 0, + param21 int DEFAULT 0, + bxcdr char(2) DEFAULT 'PC', + c31 int DEFAULT 0, + c33 int DEFAULT 0, + c35 int DEFAULT 0, + c37 int, + mgr_uuid int, + back_up_uuid int, + priv_mars int DEFAULT 0, + is_qc int DEFAULT 0, + c41 int DEFAULT 0, + deleted int DEFAULT 0, + c47 int DEFAULT 1 + ); + CREATE INDEX t3x0 on t3 (uid); + CREATE INDEX t3x1 on t3 (param3); + CREATE INDEX t3x2 on t3 (uuid); + CREATE INDEX t3x3 on t3 (acc_id); + CREATE INDEX t3x4 on t3 (param4); + CREATE INDEX t3x5 on t3 (pfy); + CREATE INDEX t3x6 on t3 (is_qc); + SELECT count(*) FROM sqlite_master; +} {30} +do_execsql_test autoindex2-110 { + ANALYZE sqlite_master; + INSERT INTO sqlite_stat1 VALUES('t1','t1x3','10747267 260'); + INSERT INTO sqlite_stat1 VALUES('t1','t1x2','10747267 121 113 2 2 2 1'); + INSERT INTO sqlite_stat1 VALUES('t1','t1x1','10747267 50 40'); + INSERT INTO sqlite_stat1 VALUES('t1','t1x0','10747267 1'); + INSERT INTO sqlite_stat1 VALUES('t2','t2x15','39667 253'); + INSERT INTO sqlite_stat1 VALUES('t2','t2x14','39667 19834'); + INSERT INTO sqlite_stat1 VALUES('t2','t2x13','39667 13223'); + INSERT INTO sqlite_stat1 VALUES('t2','t2x12','39667 7'); + INSERT INTO sqlite_stat1 VALUES('t2','t2x11','39667 17'); + INSERT INTO sqlite_stat1 VALUES('t2','t2x10','39667 19834'); + INSERT INTO sqlite_stat1 VALUES('t2','t2x9','39667 7934'); + INSERT INTO sqlite_stat1 VALUES('t2','t2x8','39667 11'); + INSERT INTO sqlite_stat1 VALUES('t2','t2x7','39667 5'); + INSERT INTO sqlite_stat1 VALUES('t2','t2x6','39667 242'); + INSERT INTO sqlite_stat1 VALUES('t2','t2x5','39667 1984'); + INSERT INTO sqlite_stat1 VALUES('t2','t2x4','39667 4408'); + INSERT INTO sqlite_stat1 VALUES('t2','t2x3','39667 81'); + INSERT INTO sqlite_stat1 VALUES('t2','t2x2','39667 551'); + INSERT INTO sqlite_stat1 VALUES('t2','t2x1','39667 2'); + INSERT INTO sqlite_stat1 VALUES('t2','t2x0','39667 1'); + INSERT INTO sqlite_stat1 VALUES('t3','t3x6','569 285'); + INSERT INTO sqlite_stat1 VALUES('t3','t3x5','569 2'); + INSERT INTO sqlite_stat1 VALUES('t3','t3x4','569 2'); + INSERT INTO sqlite_stat1 VALUES('t3','t3x3','569 5'); + INSERT INTO sqlite_stat1 VALUES('t3','t3x2','569 3'); + INSERT INTO sqlite_stat1 VALUES('t3','t3x1','569 6'); + INSERT INTO sqlite_stat1 VALUES('t3','t3x0','569 1'); + ANALYZE sqlite_master; +} {} +do_execsql_test autoindex2-120 { + EXPLAIN QUERY PLAN + SELECT + t1_id, + t1.did, + param2, + param3, + t1.ptime, + t1.trange, + t1.exmass, + t1.mass, + t1.vstatus, + type, + subtype, + t1.deviation, + t1.formula, + dparam1, + reserve1, + reserve2, + param4, + t1.last_operation, + t1.admin_uuid, + t1.previous_value, + t1.job_id, + client_did, + t1.last_t1, + t1.data_t1, + t1.previous_date, + param5, + param6, + mgr_uuid + FROM + t1, + t2, + t3 + WHERE + t1.ptime > 1393520400 + AND param3<>9001 + AND t3.flg7 = 1 + AND t1.did = t2.did + AND t2.uid = t3.uid + ORDER BY t1.ptime desc LIMIT 500; +} {0 0 0 {SEARCH TABLE t1 USING INDEX t1x1 (ptime>?)} 0 1 1 {SEARCH TABLE t2 USING INDEX t2x0 (did=?)} 0 2 2 {SEARCH TABLE t3 USING INDEX t3x0 (uid=?)}} +# +# ^^^--- Before being fixed, the above was using an automatic covering +# on t3 and reordering the tables so that t3 was in the outer loop and +# implementing the ORDER BY clause using a B-Tree. + +do_execsql_test autoindex2-120 { + EXPLAIN QUERY PLAN + SELECT + t1_id, + t1.did, + param2, + param3, + t1.ptime, + t1.trange, + t1.exmass, + t1.mass, + t1.vstatus, + type, + subtype, + t1.deviation, + t1.formula, + dparam1, + reserve1, + reserve2, + param4, + t1.last_operation, + t1.admin_uuid, + t1.previous_value, + t1.job_id, + client_did, + t1.last_t1, + t1.data_t1, + t1.previous_date, + param5, + param6, + mgr_uuid + FROM + t3, + t2, + t1 + WHERE + t1.ptime > 1393520400 + AND param3<>9001 + AND t3.flg7 = 1 + AND t1.did = t2.did + AND t2.uid = t3.uid + ORDER BY t1.ptime desc LIMIT 500; +} {0 0 2 {SEARCH TABLE t1 USING INDEX t1x1 (ptime>?)} 0 1 1 {SEARCH TABLE t2 USING INDEX t2x0 (did=?)} 0 2 0 {SEARCH TABLE t3 USING INDEX t3x0 (uid=?)}} + +finish_test