From: dan Date: Mon, 14 Oct 2019 15:15:50 +0000 (+0000) Subject: Fix a problem with row-value IN(...) operators and virtual tables. X-Git-Tag: version-3.31.0~403 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2d82269ca8ccc13328af42cd9dad7edd565f9456;p=thirdparty%2Fsqlite.git Fix a problem with row-value IN(...) operators and virtual tables. FossilOrigin-Name: aa57d7abac0bb92d4d5fd4e093a11cf8efc04e4eed748b2a400d01f137250649 --- diff --git a/ext/fts5/test/fts5misc.test b/ext/fts5/test/fts5misc.test index d4e55f0974..9be73aeb3b 100644 --- a/ext/fts5/test/fts5misc.test +++ b/ext/fts5/test/fts5misc.test @@ -193,5 +193,31 @@ do_execsql_test 6.1 { INSERT INTO vt0(vt0) VALUES('rebuild'); } +#------------------------------------------------------------------------- +# +reset_db +do_execsql_test 7.0 { + CREATE VIRTUAL TABLE t1 USING fts5(x); + INSERT INTO t1(rowid, x) VALUES(1, 'hello world'); + INSERT INTO t1(rowid, x) VALUES(2, 'well said'); + INSERT INTO t1(rowid, x) VALUES(3, 'hello said'); + INSERT INTO t1(rowid, x) VALUES(4, 'well world'); + + CREATE TABLE t2 (a, b); + INSERT INTO t2 VALUES(1, 'hello'); + INSERT INTO t2 VALUES(2, 'world'); + INSERT INTO t2 VALUES(3, 'said'); + INSERT INTO t2 VALUES(4, 'hello'); +} + +do_execsql_test 7.1 { + SELECT rowid FROM t1 WHERE (rowid, x) IN (SELECT a, b FROM t2); +} + +do_execsql_test 7.2 { + SELECT rowid FROM t1 WHERE rowid=2 AND t1 = 'hello'; +} + + finish_test diff --git a/manifest b/manifest index bbdc0f15c4..e0c8adf7d1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\sSelect-Trace\sis\senabled\s(in\sdebugging\sbuilds\sonly)\sdo\snot\sshow\sthe\nresult\sof\sWindow\sfunction\stree\srewrites\sif\sthere\sare\sno\swindow\sfunctions. -D 2019-10-12T23:38:00.145 +C Fix\sa\sproblem\swith\srow-value\sIN(...)\soperators\sand\svirtual\stables. +D 2019-10-14T15:15:50.018 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -189,7 +189,7 @@ F ext/fts5/test/fts5leftjoin.test c0b4cafb9661379e576dc4405c0891d8fcc27826807405 F ext/fts5/test/fts5matchinfo.test 79129ff6c9a2d86943b287a5a8caa7ee639f6dcf004d8975d15c279374e82e35 F ext/fts5/test/fts5merge.test e92a8db28b45931e7a9c7b1bbd36101692759d00274df74d83fd29d25d53b3a6 F ext/fts5/test/fts5merge2.test 3ebad1a59d6ad3fb66eff6523a09e95dc6367cbefb3cd73196801dea0425c8e2 -F ext/fts5/test/fts5misc.test f3edb5e6a370d6045f1b28979ee581a44e81d5f15d4e1779db3d3069914171fd +F ext/fts5/test/fts5misc.test adfccd3f065df52e306778c815f873ab779b9db34e9817b1d4b819132f914701 F ext/fts5/test/fts5multi.test a15bc91cdb717492e6e1b66fec1c356cb57386b980c7ba5af1915f97fe878581 F ext/fts5/test/fts5multiclient.test 5ff811c028d6108045ffef737f1e9f05028af2458e456c0937c1d1b8dea56d45 F ext/fts5/test/fts5near.test 211477940142d733ac04fad97cb24095513ab2507073a99c2765c3ddd2ef58bd @@ -613,7 +613,7 @@ F src/wal.h 606292549f5a7be50b6227bd685fa76e3a4affad71bb8ac5ce4cb5c79f6a176a F src/walker.c d5a94907dcac990e31976be9dc769d17f6a806782593d6aec9d760ee01ec22cd F src/where.c 9f3f23efc45934e7b7ea6c0c1042420b73053e7c3264feef6faf9ce6fbd5df61 F src/whereInt.h 2c6bae136a7c0be6ff75dc36950d1968c67d005c8e51d7a9d77cb996bb4843d9 -F src/wherecode.c 535c8e228478fd971b9a5b6cb6773995b0fbf7020d5989508a5094ce5b8cd95b +F src/wherecode.c fde87356e0393d91cf29f27817ed02583e152517b5cc641cd0d0c94912a5603a F src/whereexpr.c 05c283d26aa9c3f5d1bf13a5f6a573b43295b9db280eff18e26f97d7d7f119b4 F src/window.c 064f251451c8e2a1c76b6269229d911a651e119c6a5f522b6eaebf8dc8714041 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 @@ -1270,6 +1270,7 @@ F test/rowvalue7.test c1cbdbf407029db01f87764097c6ac02a1c5a37efd2776eff32a9cdfdf F test/rowvalue8.test 5900eddad9e2c3c2e26f1a95f74aafc1232ee5e0 F test/rowvalue9.test d8dd2c6ecac432dadaa79e41dc2434f007be1b6b F test/rowvaluefault.test 7cd9ccc6c2fbdd881672984087aad0491bb75504 +F test/rowvaluevtab.test 751a224b86d5c66d1d0bfa9887da9d6ab9a1c09e1268b5abe0ffdfdd418f122f F test/rtree.test 0c8d9dd458d6824e59683c19ab2ffa9ef946f798 F test/run-wordcount.sh 891e89c4c2d16e629cd45951d4ed899ad12afc09 F test/savepoint.test 1f8a6b1aea9a0d05837adc463d4bf47bd9d0f1c842f1c2a9caccd639baf34bf9 @@ -1846,7 +1847,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 f5ee30426e8876e70304f852153b56991a2a66e0f6a82597e9dcccf49163272d -R efdbb8351c1ff37fb18793c0f98348de -U drh -Z aeb1a204a5f6f383373587bc05ae8c43 +P d1acf72ae1ea7484bb9c3a8630094f1a3a9597578c7b9d6e02fc0a4e3f59c57d +R 8aede2fd3a2b367bcf55d8d9cd88d2ac +U dan +Z 27a81d4430496f3d39af57caa874466b diff --git a/manifest.uuid b/manifest.uuid index b8e545826a..ca8fb25889 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d1acf72ae1ea7484bb9c3a8630094f1a3a9597578c7b9d6e02fc0a4e3f59c57d \ No newline at end of file +aa57d7abac0bb92d4d5fd4e093a11cf8efc04e4eed748b2a400d01f137250649 \ No newline at end of file diff --git a/src/wherecode.c b/src/wherecode.c index 2fbcba17e9..cf5ce5d4ae 100644 --- a/src/wherecode.c +++ b/src/wherecode.c @@ -1307,7 +1307,9 @@ Bitmask sqlite3WhereCodeOneLoopStart( pTerm = pLoop->aLTerm[j]; if( j<16 && (pLoop->u.vtab.omitMask>>j)&1 ){ disableTerm(pLevel, pTerm); - }else if( (pTerm->eOperator & WO_IN)!=0 ){ + }else if( (pTerm->eOperator & WO_IN)!=0 && + sqlite3ExprVectorSize(pTerm->pExpr->pLeft)==1 + ){ Expr *pCompare; /* The comparison operator */ Expr *pRight; /* RHS of the comparison */ VdbeOp *pOp; /* Opcode to access the value of the IN constraint */ diff --git a/test/rowvaluevtab.test b/test/rowvaluevtab.test new file mode 100644 index 0000000000..7d5dc52651 --- /dev/null +++ b/test/rowvaluevtab.test @@ -0,0 +1,91 @@ +# 2018 October 14 +# +# 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. +# +#*********************************************************************** +# + + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set ::testprefix rowvaluevtab + +register_echo_module db + +do_execsql_test 1.0 { + CREATE TABLE t1(a, b, c); + CREATE INDEX t1b ON t1(b); + INSERT INTO t1 VALUES('one', 1, 1); + INSERT INTO t1 VALUES('two', 1, 2); + INSERT INTO t1 VALUES('three', 1, 3); + INSERT INTO t1 VALUES('four', 2, 1); + INSERT INTO t1 VALUES('five', 2, 2); + INSERT INTO t1 VALUES('six', 2, 3); + INSERT INTO t1 VALUES('seven', 3, 1); + INSERT INTO t1 VALUES('eight', 3, 2); + INSERT INTO t1 VALUES('nine', 3, 3); + + WITH s(i) AS ( + SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<10000 + ) INSERT INTO t1 SELECT NULL, NULL, NULL FROM s; + CREATE VIRTUAL TABLE e1 USING echo(t1); +} + +proc do_vfilter4_test {tn sql expected} { + set res [list] + db eval "explain $sql" { + if {$opcode=="VFilter"} { + lappend res $p4 + } + } + uplevel [list do_test $tn [list set {} $res] [list {*}$expected]] +} + +do_execsql_test 1.1 { + SELECT a FROM e1 WHERE (b, c) = (2, 2) +} {five} +do_vfilter4_test 1.1f { + SELECT a FROM e1 WHERE (b, c) = (?, ?) +} {{SELECT rowid, a, b, c FROM 't1' WHERE b = ?}} + +do_execsql_test 1.2 { + SELECT a FROM e1 WHERE (b, c) > (2, 2) +} {six seven eight nine} +do_vfilter4_test 1.2f { + SELECT a FROM e1 WHERE (b, c) > (2, 2) +} { + {SELECT rowid, a, b, c FROM 't1' WHERE b >= ?} +} + +do_execsql_test 1.3 { + SELECT a FROM e1 WHERE (b, c) >= (2, 2) +} {five six seven eight nine} +do_vfilter4_test 1.3f { + SELECT a FROM e1 WHERE (b, c) >= (2, 2) +} { + {SELECT rowid, a, b, c FROM 't1' WHERE b >= ?} +} + +do_execsql_test 1.3 { + SELECT a FROM e1 WHERE (b, c) BETWEEN (1, 2) AND (2, 3) +} {two three four five six} +do_vfilter4_test 1.3f { + SELECT a FROM e1 WHERE (b, c) BETWEEN (1, 2) AND (2, 3) +} { + {SELECT rowid, a, b, c FROM 't1' WHERE b >= ? AND b <= ?} +} + +do_execsql_test 1.4 { + SELECT a FROM e1 WHERE (b, c) IN ( VALUES(2, 2) ) +} {five} +do_vfilter4_test 1.4f { + SELECT a FROM e1 WHERE (b, c) IN ( VALUES(2, 2) ) +} {{SELECT rowid, a, b, c FROM 't1' WHERE b = ?}} + +finish_test +