1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

Fix a dangling-else problem that was causing recursive CTEs to malfunction.

Begin fixing test cases to work with the new EQP output.

FossilOrigin-Name: 82ca44b82fed6814c84440ba8bfaa019488ab956e84ac165180e2fcece6facb2
This commit is contained in:
drh
2018-05-02 14:24:34 +00:00
parent c631ded5e8
commit 03c3905f94
10 changed files with 590 additions and 432 deletions

View File

@ -959,10 +959,81 @@ proc do_timed_execsql_test {testname sql {result {}}} {
uplevel do_test [list $testname] [list "execsql_timed {$sql}"]\
[list [list {*}$result]]
}
proc do_eqp_test {name sql res} {
uplevel do_execsql_test $name [list "EXPLAIN QUERY PLAN $sql"] [list $res]
# Run an EXPLAIN QUERY PLAN $sql in database "db". Then rewrite the output
# as an ASCII-art graph and return a string that is that graph.
#
# Hexadecimal literals in the output text are converted into "xxxxxx" since those
# literals are pointer values that might very from one run of the test to the
# next, yet we want the output to be consistent.
#
proc query_plan_graph {sql} {
db eval "EXPLAIN QUERY PLAN $sql" {
set dx($id) $detail
lappend cx($parent) $id
}
set a "\n QUERY PLAN\n"
append a [append_graph " " dx cx 0]
return [regsub -all { 0x[A-F0-9]+\y} $a { xxxxxx}]
}
# Helper routine for [query_plan_graph SQL]:
#
# Output rows of the graph that are children of $level.
#
# prefix: Prepend to every output line
#
# dxname: Name of an array variable that stores text describe
# The description for $id is $dx($id)
#
# cxname: Name of an array variable holding children of item.
# Children of $id are $cx($id)
#
# level: Render all lines that are children of $level
#
proc append_graph {prefix dxname cxname level} {
upvar $dxname dx $cxname cx
set a ""
set x $cx($level)
set n [llength $x]
for {set i 0} {$i<$n} {incr i} {
set id [lindex $x $i]
if {$i==$n-1} {
set p1 "`--"
set p2 " "
} else {
set p1 "|--"
set p2 "| "
}
append a $prefix$p1$dx($id)\n
if {[info exists cx($id)]} {
append a [append_graph "$prefix$p2" dx cx $id]
}
}
return $a
}
# Do an EXPLAIN QUERY PLAN test on input $sql with expected results $res
#
# If $res begins with a "\s+QUERY PLAN\n" then it is assumed to be the
# complete graph which must match the output of [query_plan_graph $sql]
# exactly.
#
# If $res does not begin with "\s+QUERY PLAN\n" then take it is a string
# that must be found somewhere in the query plan output.
#
proc do_eqp_test {name sql res} {
if {[regexp {^\s+QUERY PLAN\n} $res]} {
uplevel do_test $name [list [list query_plan_graph $sql]] [list $res]
} else {
if {[string index $res 0]!="/"} {
set res "/*$res*/"
}
uplevel do_execsql_test $name [list "EXPLAIN QUERY PLAN $sql"] [list $res]
}
}
#-------------------------------------------------------------------------
# Usage: do_select_tests PREFIX ?SWITCHES? TESTLIST
#