mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-01 06:27:03 +03:00
Make handling of LIMIT clauses in correlated sub-queries on virtual tables more efficient.
FossilOrigin-Name: 7214cb2a5b35190a06a1040cd4c54f325d347f8d8e36a07fd76c0a421e266522
This commit is contained in:
@ -349,4 +349,67 @@ do_execsql_test 5.9 {
|
||||
three six seven
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
|
||||
reset_db
|
||||
register_tcl_module db
|
||||
|
||||
proc quote {str} {
|
||||
return "'[string map {' ''} $str]'"
|
||||
}
|
||||
|
||||
proc vtab_command {lVal method args} {
|
||||
switch -- $method {
|
||||
xConnect {
|
||||
return "CREATE TABLE t1(a, b, c, d)"
|
||||
}
|
||||
|
||||
xBestIndex {
|
||||
set hdl [lindex $args 0]
|
||||
set clist [$hdl constraints]
|
||||
|
||||
set idx 0
|
||||
set idxnum 0
|
||||
|
||||
foreach c $clist {
|
||||
array set a $c
|
||||
if {$a(usable)==0} continue
|
||||
|
||||
if {$a(op)=="limit"} {
|
||||
set idxnum 1
|
||||
}
|
||||
|
||||
incr idx
|
||||
}
|
||||
|
||||
return "cost 1000 rows 1000 idxnum $idxnum"
|
||||
|
||||
}
|
||||
|
||||
xFilter {
|
||||
foreach {idxnum idxstr lArg} $args {}
|
||||
return [list sql "SELECT 0, $idxnum, $idxnum, $idxnum, $idxnum"]
|
||||
}
|
||||
}
|
||||
|
||||
return {}
|
||||
}
|
||||
|
||||
do_execsql_test 6.0 {
|
||||
CREATE TABLE t1(x, y);
|
||||
INSERT INTO t1 VALUES(2, 2);
|
||||
CREATE VIRTUAL TABLE x1 USING tcl(vtab_command t1);
|
||||
}
|
||||
|
||||
do_execsql_test 6.1 { SELECT * FROM x1 LIMIT 5 } {1 1 1 1}
|
||||
|
||||
do_execsql_test 6.2 { SELECT * FROM x1 WHERE b=c LIMIT 5 } {0 0 0 0}
|
||||
|
||||
do_execsql_test 6.3 {
|
||||
SELECT (SELECT a FROM x1 WHERE t1.x=t1.y LIMIT 10) FROM t1
|
||||
} {0}
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user