Have the planner detect cases where a MATCH constraint is applied to a virtual table, and ignore any plans that do not allow the virtual table implementation to implement the MATCH filtering.

FossilOrigin-Name: 19f3208b26597625728d1ef716d4e44407cf96ac
This commit is contained in:
dan 2014-01-04 14:16:06 +00:00
parent 5426d80948
commit 42899543f8
4 changed files with 83 additions and 8 deletions

View File

@ -1,5 +1,5 @@
C Avoid\ssome\sunnecessary\sOP_SCopy\soperations\swhen\sinserting\sinto\sa\stable\nwith\smultiple\sindices. C Have\sthe\splanner\sdetect\scases\swhere\sa\sMATCH\sconstraint\sis\sapplied\sto\sa\svirtual\stable,\sand\signore\sany\splans\sthat\sdo\snot\sallow\sthe\svirtual\stable\simplementation\sto\simplement\sthe\sMATCH\sfiltering.
D 2014-01-03T16:03:43.440 D 2014-01-04T14:16:06.902
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 2ef13430cd359f7b361bb863504e227b25cc7f81 F Makefile.in 2ef13430cd359f7b361bb863504e227b25cc7f81
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -293,7 +293,7 @@ F src/vtab.c 21b932841e51ebd7d075e2d0ad1415dce8d2d5fd
F src/wal.c 7dc3966ef98b74422267e7e6e46e07ff6c6eb1b4 F src/wal.c 7dc3966ef98b74422267e7e6e46e07ff6c6eb1b4
F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4
F src/walker.c e9e593d5bb798c3e67fc3893dfe7055c9e7d8d74 F src/walker.c e9e593d5bb798c3e67fc3893dfe7055c9e7d8d74
F src/where.c 8e3cb2030eaa242defb804aa30115b5d870e5cd4 F src/where.c 14403429f7ad11b13b6ae0e466d089b8875ba195
F src/whereInt.h 96a75c61f1d2b9d4a8e4bb17d89deb0cf7cba358 F src/whereInt.h 96a75c61f1d2b9d4a8e4bb17d89deb0cf7cba358
F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
@ -547,6 +547,7 @@ F test/fts3expr3.test 9e91b8edbcb197bf2e92161aa7696446d96dce5f
F test/fts3fault.test cb72dccb0a3b9f730f16c5240f3fcb9303eb1660 F test/fts3fault.test cb72dccb0a3b9f730f16c5240f3fcb9303eb1660
F test/fts3fault2.test 3198eef2804deea7cac8403e771d9cbcb752d887 F test/fts3fault2.test 3198eef2804deea7cac8403e771d9cbcb752d887
F test/fts3first.test dbdedd20914c8d539aa3206c9b34a23775644641 F test/fts3first.test dbdedd20914c8d539aa3206c9b34a23775644641
F test/fts3join.test bc8e5ca3e6b6577cf98e81b5271291e33e020e87
F test/fts3malloc.test b0e4c133b8d61d4f6d112d8110f8320e9e453ef6 F test/fts3malloc.test b0e4c133b8d61d4f6d112d8110f8320e9e453ef6
F test/fts3matchinfo.test ff423e73faab8fc6d7adeefedf74dd8e2b0b14e0 F test/fts3matchinfo.test ff423e73faab8fc6d7adeefedf74dd8e2b0b14e0
F test/fts3near.test 7e3354d46f155a822b59c0e957fd2a70c1d7e905 F test/fts3near.test 7e3354d46f155a822b59c0e957fd2a70c1d7e905
@ -1147,7 +1148,10 @@ F tool/vdbe-compress.tcl 0cf56e9263a152b84da86e75a5c0cdcdb7a47891
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01
F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff
P 9d05777fe24e1a5ce71762de38db840931ef0bc8 P 429018b19cb525a4bb0843d20955457b53900d4b
R 3a4d1de2d6235e13c562ba377a9da47e R 6571bb57c7cea9164f2f0721e5f9106f
U drh T *branch * avoid-unusable-match
Z f5e03e0d190fce062c51c7968e7436da T *sym-avoid-unusable-match *
T -sym-trunk *
U dan
Z 6e1a68d01b84e17020c8f255059d7b13

View File

@ -1 +1 @@
429018b19cb525a4bb0843d20955457b53900d4b 19f3208b26597625728d1ef716d4e44407cf96ac

View File

@ -4338,6 +4338,7 @@ static int whereLoopAddVirtual(
int nConstraint; int nConstraint;
int seenIn = 0; /* True if an IN operator is seen */ int seenIn = 0; /* True if an IN operator is seen */
int seenVar = 0; /* True if a non-constant constraint is seen */ int seenVar = 0; /* True if a non-constant constraint is seen */
int seenVarMatch = 0; /* If a non-constant MATCH constraint is seen */
int iPhase; /* 0: const w/o IN, 1: const, 2: no IN, 2: IN */ int iPhase; /* 0: const w/o IN, 1: const, 2: no IN, 2: IN */
WhereLoop *pNew; WhereLoop *pNew;
int rc = SQLITE_OK; int rc = SQLITE_OK;
@ -4382,6 +4383,7 @@ static int whereLoopAddVirtual(
} }
if( pTerm->prereqRight!=0 ){ if( pTerm->prereqRight!=0 ){
seenVar = 1; seenVar = 1;
if( pTerm->eOperator & WO_MATCH ) seenVarMatch = 1;
}else if( (pTerm->eOperator & WO_IN)==0 ){ }else if( (pTerm->eOperator & WO_IN)==0 ){
pIdxCons->usable = 1; pIdxCons->usable = 1;
} }
@ -4400,6 +4402,9 @@ static int whereLoopAddVirtual(
break; break;
} }
} }
/* The following line ensures that, if there exists a MATCH constraint,
** no plans for which the MATCH constraint is not usable are considered. */
if( seenVarMatch && iPhase<=1 ) continue;
memset(pUsage, 0, sizeof(pUsage[0])*pIdxInfo->nConstraint); memset(pUsage, 0, sizeof(pUsage[0])*pIdxInfo->nConstraint);
if( pIdxInfo->needToFreeIdxStr ) sqlite3_free(pIdxInfo->idxStr); if( pIdxInfo->needToFreeIdxStr ) sqlite3_free(pIdxInfo->idxStr);
pIdxInfo->idxStr = 0; pIdxInfo->idxStr = 0;

66
test/fts3join.test Normal file
View File

@ -0,0 +1,66 @@
# 2014 January 4
#
# 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 the FTS3 module.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
set ::testprefix fts3join
# If SQLITE_ENABLE_FTS3 is defined, omit this file.
ifcapable !fts3 {
finish_test
return
}
do_execsql_test 1.0 {
CREATE VIRTUAL TABLE ft1 USING fts4(x);
INSERT INTO ft1 VALUES('aaa aaa');
INSERT INTO ft1 VALUES('aaa bbb');
INSERT INTO ft1 VALUES('bbb aaa');
INSERT INTO ft1 VALUES('bbb bbb');
CREATE TABLE t1(id, y);
INSERT INTO t1 VALUES(1, 'aaa');
INSERT INTO t1 VALUES(2, 'bbb');
}
do_execsql_test 1.1 {
SELECT docid FROM ft1, t1 WHERE ft1 MATCH y AND id=1;
} {1 2 3}
do_execsql_test 1.2 {
SELECT docid FROM ft1, t1 WHERE ft1 MATCH y AND id=1 ORDER BY docid;
} {1 2 3}
do_execsql_test 2.0 {
CREATE VIRTUAL TABLE ft2 USING fts4(x);
CREATE VIRTUAL TABLE ft3 USING fts4(y);
INSERT INTO ft2 VALUES('abc');
INSERT INTO ft2 VALUES('def');
INSERT INTO ft3 VALUES('ghi');
INSERT INTO ft3 VALUES('abc');
}
do_execsql_test 2.1 { SELECT * FROM ft2, ft3 WHERE x MATCH y; } {abc abc}
do_execsql_test 2.2 { SELECT * FROM ft2, ft3 WHERE y MATCH x; } {abc abc}
do_execsql_test 2.3 { SELECT * FROM ft3, ft2 WHERE x MATCH y; } {abc abc}
do_execsql_test 2.4 { SELECT * FROM ft3, ft2 WHERE y MATCH x; } {abc abc}
do_catchsql_test 2.5 {
SELECT * FROM ft3, ft2 WHERE y MATCH x AND x MATCH y;
} {1 {no query solution}}
finish_test