New test cases and minor fixes for the optimization on this branch.

FossilOrigin-Name: 70ac9ea1a6cb2f4906f00f1a04f668e5ba5eeed8d4d0fa4be57a9c9eb0683697
This commit is contained in:
dan 2017-04-13 18:33:33 +00:00
parent 839fa6d814
commit a74f5c2923
4 changed files with 85 additions and 18 deletions

View File

@ -1,5 +1,5 @@
C Only\suse\sthe\sskip-ahead-distinct\soptimization\sif\sthe\sindex\shas\sbeen\sanalyzed\nand\swe\sknow\sthat\sa\sskip-head\sis\slikely\sto\sskip\sover\sat\sleast\s11\srows.\s\sThe\nmagic\snumber\s11\swas\sdetermined\sby\sexperimentation.
D 2017-04-13T13:01:59.793
C New\stest\scases\sand\sminor\sfixes\sfor\sthe\soptimization\son\sthis\sbranch.
D 2017-04-13T18:33:33.610
F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
F Makefile.msc a4c0613a18663bda56d8cf76079ab6590a7c3602e54befb4bbdef76bcaa38b6a
@ -482,7 +482,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9
F src/wal.c 40c543f0a2195d1b0dc88ef12142bea690009344
F src/wal.h 06b2a0b599cc0f53ea97f497cf8c6b758c999f71
F src/walker.c b71a992b413b3a022572eccf29ef4b4890223791
F src/where.c 56111492a24dac936a4e5af7da18bdec6a8e0650a69bf0a8654a2a1b3241b247
F src/where.c b08b998bea4474754bbb54a4d22e9689e4372672f9cd8ccc4d41640ef5efecbf
F src/whereInt.h 7a21ef633e26acbf46df04add2eba6e0a2100c78dc5879049e93f981fc3344df
F src/wherecode.c 943e32e9dccd0af802e0683ae11071c8bd808364e5908a5fb66758bd404c8681
F src/whereexpr.c e913aaa7b73ffcce66abcea5f197e2c538d48b5df78d0b7bba8ff4d73cc2e745
@ -658,7 +658,7 @@ F test/descidx2.test 9f1a0c83fd57f8667c82310ca21b30a350888b5d
F test/descidx3.test 09ddbe3f5295f482d2f8b687cf6db8bad7acd9a2
F test/diskfull.test 106391384780753ea6896b7b4f005d10e9866b6e
F test/distinct.test a1783b960ad8c15a77cd9f207be072898db1026c
F test/distinct2.test 2d5245672d259c28a8b706cdc764c4cfa663e2ba
F test/distinct2.test 5bf7cb4233222cf275b72bcde9149107d300297dd88711aa7f7902d4884b6730
F test/distinctagg.test 1a6ef9c87a58669438fc771450d7a72577417376
F test/e_blobbytes.test 439a945953b35cb6948a552edaec4dc31fd70a05
F test/e_blobclose.test 4b3c8c60c2171164d472059c73e9f3c1844bb66d
@ -1572,7 +1572,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 132339a1fb0b9664df4d3eefbed6e77ef100ba95a91dcc622da7bd3fcdfcd6af
R 5c1ba5f3c1c29d44b68025e1a39bfee8
U drh
Z 06d9008ebfc7601c93a90ebae38b456d
P 0cf16decd534bf2d66620c293f8c8987f356305f2d97f8fd12d260bda1571385
R 576a06d609b733a5644f1c6a0bebf58e
U dan
Z e29dec34fd75469b8282367092cf6782

View File

@ -1 +1 @@
0cf16decd534bf2d66620c293f8c8987f356305f2d97f8fd12d260bda1571385
70ac9ea1a6cb2f4906f00f1a04f668e5ba5eeed8d4d0fa4be57a9c9eb0683697

View File

@ -4847,7 +4847,6 @@ void sqlite3WhereEnd(WhereInfo *pWInfo){
int addr;
pLevel = &pWInfo->a[i];
pLoop = pLevel->pWLoop;
sqlite3VdbeResolveLabel(v, pLevel->addrCont);
if( pLevel->op!=OP_Noop ){
#ifndef SQLITE_DISABLE_SKIPAHEAD_DISTINCT
int n = -1;
@ -4867,18 +4866,25 @@ void sqlite3WhereEnd(WhereInfo *pWInfo){
for(j=0; j<pX->nExpr; j++){
Expr *pE = sqlite3ExprSkipCollate(pX->a[j].pExpr);
if( pE->op==TK_COLUMN ){
if( pE->iTable!=pLevel->iTabCur ) continue;
k = 1+sqlite3ColumnOfIndex(pIdx, pE->iColumn);
if( pE->iTable==pLevel->iIdxCur ){
k = pE->iColumn+1;
}else{
if( pE->iTable!=pLevel->iTabCur ) continue;
k = 1+sqlite3ColumnOfIndex(pIdx, pE->iColumn);
}
if( k>n ) n = k;
}else if( pIdx->aColExpr ){
for(k=n+1; k<pIdx->nKeyCol; k++){
}
#ifdef SQLITE_DEBUG
/* Any expressions in the result-set that match columns of the
** index should have already been transformed to TK_COLUMN
** operations by whereIndexExprTrans(). */
else if( pIdx->aColExpr ){
for(k=0; k<pIdx->nKeyCol; k++){
Expr *pI = pIdx->aColExpr->a[k].pExpr;
if( pI && sqlite3ExprCompare(pE,pI,0)<2 ){
n = k+1;
break;
}
assert( pI==0 || sqlite3ExprCompare(pE, pI, pE->iTable)!=0 );
}
}
#endif
}
}
/* TUNING: Only try to skip ahead using OP_Seek if we expect to
@ -4895,11 +4901,14 @@ void sqlite3WhereEnd(WhereInfo *pWInfo){
VdbeCoverageIf(v, op==OP_SeekLT);
VdbeCoverageIf(v, op==OP_SeekGT);
sqlite3VdbeAddOp2(v, OP_Goto, 1, pLevel->p2);
sqlite3VdbeResolveLabel(v, pLevel->addrCont);
sqlite3VdbeAddOp3(v, pLevel->op, pLevel->p1, pLevel->p2, pLevel->p3);
sqlite3VdbeJumpHere(v, k);
}else
#endif /* SQLITE_DISABLE_SKIPAHEAD_DISTINCT */
{
/* The common case: Advance to the next row */
sqlite3VdbeResolveLabel(v, pLevel->addrCont);
sqlite3VdbeAddOp3(v, pLevel->op, pLevel->p1, pLevel->p2, pLevel->p3);
sqlite3VdbeChangeP5(v, pLevel->p5);
VdbeCoverage(v);
@ -4907,6 +4916,8 @@ void sqlite3WhereEnd(WhereInfo *pWInfo){
VdbeCoverageIf(v, pLevel->op==OP_Prev);
VdbeCoverageIf(v, pLevel->op==OP_VNext);
}
}else{
sqlite3VdbeResolveLabel(v, pLevel->addrCont);
}
if( pLoop->wsFlags & WHERE_IN_ABLE && pLevel->u.in.nIn>0 ){
struct InLoop *pIn;

View File

@ -85,4 +85,60 @@ do_execsql_test 600 {
SELECT DISTINCT x, x FROM t6a, t6b;
} {1 1}
do_execsql_test 700 {
CREATE TABLE t7(a, b, c);
WITH s(i) AS (
SELECT 1 UNION ALL SELECT i+1 FROM s WHERE (i+1)<200
)
INSERT INTO t7 SELECT i/100, i/50, i FROM s;
}
do_execsql_test 710 {
SELECT DISTINCT a, b FROM t7;
} {
0 0 0 1
1 2 1 3
}
do_execsql_test 720 {
SELECT DISTINCT a, b+1 FROM t7;
} {
0 1 0 2
1 3 1 4
}
do_execsql_test 730 {
CREATE INDEX i7 ON t7(a, b+1);
ANALYZE;
SELECT DISTINCT a, b+1 FROM t7;
} {
0 1 0 2
1 3 1 4
}
do_execsql_test 800 {
CREATE TABLE t8(a, b, c);
WITH s(i) AS (
SELECT 1 UNION ALL SELECT i+1 FROM s WHERE (i+1)<100
)
INSERT INTO t8 SELECT i/40, i/20, i/40 FROM s;
}
do_execsql_test 820 {
SELECT DISTINCT a, b, c FROM t8;
} {
0 0 0 0 1 0
1 2 1 1 3 1
2 4 2
}
do_execsql_test 820 {
SELECT DISTINCT a, b, c FROM t8 WHERE b=3;
} {1 3 1}
do_execsql_test 830 {
CREATE INDEX i8 ON t8(a, c);
ANALYZE;
SELECT DISTINCT a, b, c FROM t8 WHERE b=3;
} {1 3 1}
finish_test