From: dan Date: Fri, 31 May 2024 20:32:10 +0000 (+0000) Subject: Further tests for OR constraints on virtual tables. X-Git-Tag: version-3.47.0~357^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=af354324005140bb1d002816d6035fbdcba9fdf7;p=thirdparty%2Fsqlite.git Further tests for OR constraints on virtual tables. FossilOrigin-Name: ff4a30056f8dbcbd045afdbee485f6671c3580b95187144aa9a77c97dfda2647 --- diff --git a/manifest b/manifest index 50e722946a..dc8a120397 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Better\shandle\sWHERE\sterms\sthat\sare\scommon\sto\stwo\sor\smore\sOR\sbranches\swhen\splanning\svirtual\stable\squeries. -D 2024-05-31T19:26:22.693 +C Further\stests\sfor\sOR\sconstraints\son\svirtual\stables. +D 2024-05-31T20:32:10.798 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -776,7 +776,7 @@ F src/test9.c 12e5ba554d2d1cbe0158f6ab3f7ffcd7a86ee4e5 F src/test_async.c 195ab49da082053fdb0f949c114b806a49ca770a F src/test_autoext.c 915d245e736652a219a907909bb6710f0d587871 F src/test_backup.c bf5da90c9926df0a4b941f2d92825a01bbe090a0 -F src/test_bestindex.c e8ae36817864ca80bd4608d109634cbc35cca099234313ff9f3c061a22783bd8 +F src/test_bestindex.c 1b5a1407b66c5caa67cfe1d93d96de5ec5d9d516bc69eb512482f85c037858c3 F src/test_blob.c ae4a0620b478548afb67963095a7417cd06a4ec0a56adb453542203bfdcb31ce F src/test_btree.c 8b2dc8b8848cf3a4db93f11578f075e82252a274 F src/test_config.c 5fa77ee6064ba546e144c4fea870c5ede2c54314616f81485c6a9c4192100c75 @@ -940,7 +940,7 @@ F test/bestindex8.test b63a4f171a2c83d481bb14c431a8b72e85d27b2ffdaa0435a95d58ca9 F test/bestindex9.test 1a4b93db117fd8abe74ae9be982f86aa72f01e60cd4ac541e6ede39673a451a0 F test/bestindexA.test e1b5def6b190797cacf008e6815ffb78fb30261999030d60a728d572eef44c7f F test/bestindexB.test 328b97b69cd1a20928d5997f9ecb04d2e00f1d18e19ab27f9e9adb44d7bc51ce -F test/bestindexC.test ae34a3ceb64b117cd20aba71ea8e9fadd639b021cf232e15a57fe2eefe1f29ea +F test/bestindexC.test 2df6ada16d8f00d9bb6a9664d9c323560aeed0e0ebc7a32b99d85d70037fd250 F test/between.test b9a65fb065391980119e8a781a7409d3fcf059d89968279c750e190a9a1d5263 F test/bigfile.test aa74f4e5db51c8e54a1d9de9fa65d01d1eb20b59 F test/bigfile2.test 1b489a3a39ae90c7f027b79110d6b4e1dbc71bfc @@ -2194,11 +2194,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P dcc2bb2c562e97e090174d4d0970bfa1551e5eb4db022e6d232c4dd786818e45 -R 586dbe3b8a77baf191835ccb84865021 -T *branch * xbestindex-or-terms -T *sym-xbestindex-or-terms * -T -sym-trunk * +P 4edd9b29f58621335b8a562280c991c34804bbba090f90c951261d043cff1965 +R 7e0b53e0bf1f5f31582edfc766b004d3 U dan -Z cae40e4fc9a5b7b19f7dc2f2cabe22f0 +Z 60bf1853e2bb5029309100d75a83bcc9 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 4309f282d1..4b2b009f72 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4edd9b29f58621335b8a562280c991c34804bbba090f90c951261d043cff1965 \ No newline at end of file +ff4a30056f8dbcbd045afdbee485f6671c3580b95187144aa9a77c97dfda2647 \ No newline at end of file diff --git a/src/test_bestindex.c b/src/test_bestindex.c index 072bff2e74..c89cab2e39 100644 --- a/src/test_bestindex.c +++ b/src/test_bestindex.c @@ -305,11 +305,9 @@ static int tclFilter( Tcl_IncrRefCount(pScript); Tcl_ListObjAppendElement(interp, pScript, Tcl_NewStringObj("xFilter", -1)); Tcl_ListObjAppendElement(interp, pScript, Tcl_NewIntObj(idxNum)); - if( idxStr ){ - Tcl_ListObjAppendElement(interp, pScript, Tcl_NewStringObj(idxStr, -1)); - }else{ - Tcl_ListObjAppendElement(interp, pScript, Tcl_NewStringObj("", -1)); - } + Tcl_ListObjAppendElement( + interp, pScript, Tcl_NewStringObj(idxStr ? idxStr : "", -1) + ); pArg = Tcl_NewObj(); Tcl_IncrRefCount(pArg); @@ -530,6 +528,7 @@ static int SQLITE_TCLAPI testBestIndexObj( "distinct", /* 3 */ "in", /* 4 */ "rhs_value", /* 5 */ + "collation", /* 6 */ 0 }; int ii; @@ -610,6 +609,17 @@ static int SQLITE_TCLAPI testBestIndexObj( Tcl_SetObjResult(interp, Tcl_NewStringObj(zVal, -1)); break; } + + case 6: assert( sqlite3_stricmp(azSub[ii], "collation")==0 ); { + int iCons = 0; + const char *zColl = ""; + if( Tcl_GetIntFromObj(interp, objv[2], &iCons) ){ + return TCL_ERROR; + } + zColl = sqlite3_vtab_collation(pIdxInfo, iCons); + Tcl_SetObjResult(interp, Tcl_NewStringObj(zColl, -1)); + break; + } } return TCL_OK; diff --git a/test/bestindexC.test b/test/bestindexC.test index a6f420cc2c..48f3a27655 100644 --- a/test/bestindexC.test +++ b/test/bestindexC.test @@ -214,6 +214,10 @@ do_catchsql_test 4.4 { reset_db register_tcl_module db +proc quote {str} { + return "'[string map {' ''} $str]'" +} + proc vtab_command {lVal method args} { switch -- $method { xConnect { @@ -232,16 +236,19 @@ proc vtab_command {lVal method args} { set cols(1) b set cols(2) c - #puts "xBestIndex: $clist" + set lCons [list] foreach c $clist { array set a $c if {$a(usable)==0} continue - if {$a(op)=="eq" || $a(op)=="is"} { - lappend res use $idx - catch { unset cols($a(column)) } + if {($a(op)=="eq" || $a(op)=="is") && [info exists cols($a(column))]} { + lappend res omit $idx + set coll [$hdl collation $idx] + lappend lCons "$cols($a(column)) = %[llength $lCons]% COLLATE $coll" + set idxnum [expr {$idx + (1 << $a(column))}] + catch { unset cols($a(column)) } } incr idx @@ -256,11 +263,20 @@ proc vtab_command {lVal method args} { return [list constraint $msg] } - return "cost 1000 rows 1000 idxnum $idxnum $res" + set idxstr [join $lCons " AND "] + return "cost 1000 rows 1000 idxnum $idxnum $res idxstr {$idxstr}" } xFilter { - return [list sql "SELECT 1, '', '', '' WHERE 0"] + foreach {idxnum idxstr lArg} $args {} + set i 0 + set where $idxstr + foreach a $lArg { + set where [string map [list %$i% [quote $a]] $where] + incr i + } + # puts $where + return [list sql "SELECT rowid, * FROM $lVal WHERE $where"] } } @@ -269,9 +285,11 @@ proc vtab_command {lVal method args} { do_execsql_test 5.1 { CREATE VIRTUAL TABLE x1 USING tcl(vtab_command t1); + CREATE TABLE t1(a, b, c, d); } foreach {tn where ok} { + 0 "WHERE a=? AND b=? AND c=? AND c=?" 1 1 "WHERE a=? AND b=? AND c=?" 1 2 "WHERE a=? AND b=? AND (c=? OR c=?)" 1 3 "WHERE a=? AND b=? AND (c=? OR c=? OR c=?)" 1 @@ -280,9 +298,55 @@ foreach {tn where ok} { 6 "WHERE a=? AND ((b=? AND c=?) OR (c=?))" 0 } { do_test 5.2.$tn { - catch { execsql "SELECT * FROM x1 $::where" } + catch { execsql "SELECT * FROM x1 $::where" } msg +# if {$tn==0 || $tn==2 || $tn==3} { puts "MSG: $msg" } } [expr !$ok] } +do_execsql_test 5.3 { + SELECT * FROM x1 WHERE (a, b, c) = (?, ?, ?); +} + +do_execsql_test 5.4 { + INSERT INTO t1(rowid, a, b, c, d) VALUES(1, 'x', 'y', 'z', 'one'); + INSERT INTO t1(rowid, a, b, c, d) VALUES(2, 'X', 'Y', 'Z', 'two'); + SELECT * FROM x1 WHERE (a, b, c) = ('X', 'Y', 'Z'); +} {X Y Z two} +do_execsql_test 5.5 { + SELECT * FROM x1 WHERE a='x' AND b='y' AND c='z'; +} {x y z one} +do_execsql_test 5.6 { + SELECT * FROM x1 + WHERE a='x' COLLATE nocase AND b='y' COLLATE nocase AND c='z'COLLATE nocase; +} {x y z one X Y Z two} + +do_execsql_test 5.7 { + DELETE FROM t1; + + INSERT INTO t1(rowid, a, b, c, d) VALUES(0, 'x', 'y', 'z', 'zero'); + INSERT INTO t1(rowid, a, b, c, d) VALUES(1, 'x', 'y', 'Z', 'one'); + INSERT INTO t1(rowid, a, b, c, d) VALUES(2, 'x', 'Y', 'z', 'two'); + INSERT INTO t1(rowid, a, b, c, d) VALUES(3, 'x', 'Y', 'Z', 'three'); + INSERT INTO t1(rowid, a, b, c, d) VALUES(4, 'X', 'y', 'z', 'four'); + INSERT INTO t1(rowid, a, b, c, d) VALUES(5, 'X', 'y', 'Z', 'five'); + INSERT INTO t1(rowid, a, b, c, d) VALUES(6, 'X', 'Y', 'z', 'six'); + INSERT INTO t1(rowid, a, b, c, d) VALUES(7, 'X', 'Y', 'z', 'seven'); +} + +do_execsql_test 5.8 { + SELECT d FROM x1 + WHERE a='x' AND ((b='y' AND c='z') OR (b='Y' AND c='z' COLLATE nocase)) +} { + zero two three +} + +do_execsql_test 5.9 { + SELECT d FROM x1 + WHERE a='x' COLLATE nocase + AND ((b='y' AND c='z') OR (b='Y' AND c='z' COLLATE nocase)) +} { + zero four two + three six seven +} finish_test