Updated testing of cursor-hints. Remove the test_cursorhint.c file and

associated logic in the core and do tests based purely on the newly enhanced
EXPLAIN output.

FossilOrigin-Name: bf383e665a191a4f33a540d1240960a922e22813
This commit is contained in:
drh
2015-08-14 20:08:13 +00:00
parent 2f2b02785a
commit 1eb6eeb829
7 changed files with 102 additions and 222 deletions
+92 -41
View File
@@ -16,57 +16,108 @@ source $testdir/tester.tcl
set testprefix cursorhint
do_execsql_test 1.0 {
CREATE TABLE t1(a,b);
CREATE TABLE t2(x,y);
INSERT INTO t1 VALUES(10, 15);
INSERT INTO t1 VALUES(20, 25);
INSERT INTO t2 VALUES('ten', 'fifteen');
INSERT INTO t2 VALUES('twenty', 'twentyfive');
CREATE TABLE t1(a,b,c,d);
CREATE TABLE t2(x,y,z);
INSERT INTO t1(a,b) VALUES(10, 15);
INSERT INTO t1(a,b) VALUES(20, 25);
INSERT INTO t2(x,y) VALUES('ten', 'fifteen');
INSERT INTO t2(x,y) VALUES('twenty', 'twentyfive');
CREATE TABLE t3(id TEXT PRIMARY KEY, a, b, c, d) WITHOUT ROWID;
INSERT INTO t3(id,a,b,c,d) SELECT rowid, a, b, c, d FROM t1;
PRAGMA automatic_index = 0;
}
proc H {expr} {
lappend ::cursorhint $expr
# Run EXPLAIN on $sql. Return a list of P4 values for all $opcode
# opcodes.
#
proc p4_of_opcode {db opcode sql} {
set res {}
$db eval "EXPLAIN $sql" x {
if {$x(opcode)==$opcode} {lappend res $x(p4)}
}
return $res
}
proc do_cursorhint_test {tn sql hints} {
cursorhint_hook H
set ::cursorhint [list]
set testbody [subst {
execsql {$sql}
set ::cursorhint
}]
uplevel [list do_test $tn $testbody [list {*}$hints]]
cursorhint_hook
# Run EXPLAIN on $sql. Return a list of P5 values for all $opcode
# opcodes that contain regexp $comment in their comment
#
proc p5_of_opcode {db opcode comment sql} {
set res {}
$db eval "EXPLAIN $sql" x {
if {$x(opcode)==$opcode && [regexp $comment $x(comment)]} {
lappend res $x(p5)
}
}
return $res
}
# Verify that when t1 is in the outer loop and t2 is in the inner loop,
# no cursor hints occur for t1 (since it is a full table scan) but that
# each t2 access has a cursor hint based on the current t1.a value.
#
do_test 1.1 {
p4_of_opcode db CursorHint {
SELECT * FROM t1 CROSS JOIN t2 WHERE a=x
}
} {/(r*==c0)/}
do_test 1.2 {
p5_of_opcode db OpenRead . {
SELECT * FROM t1 CROSS JOIN t2 WHERE a=x
}
} {00 00}
do_cursorhint_test 1.1 {
SELECT * FROM t1 CROSS JOIN t2 WHERE a=x;
} {
{(10 == col(0))}
{(20 == col(0))}
}
# Do the same test the other way around.
#
do_test 2.1 {
p4_of_opcode db CursorHint {
SELECT * FROM t2 CROSS JOIN t1 WHERE a=x
}
} {/(c0==r*)/}
do_test 2.2 {
p5_of_opcode db OpenRead . {
SELECT * FROM t2 CROSS JOIN t1 WHERE a=x
}
} {00 00}
do_cursorhint_test 1.2 {
SELECT * FROM t2 CROSS JOIN t1 WHERE a=x;
} {
{(col(0) == 'ten')}
{(col(0) == 'twenty')}
}
# Various expressions captured by CursorHint
#
do_test 3.1 {
p4_of_opcode db CursorHint {
SELECT * FROM t1 WHERE a=15 AND c=22 AND rowid!=98
}
} {/(c0==15).*(c2==22).*(rowid!=98)/}
do_test 3.2 {
p4_of_opcode db CursorHint {
SELECT * FROM t3 WHERE a<15 AND b>22 AND id!=98
}
} {/(c1<15).*(c2>22).*(c0!=98)/}
do_cursorhint_test 1.3 {
SELECT * FROM t1 CROSS JOIN t2 WHERE b=15;
} {
{(col(1) == 15)}
}
do_cursorhint_test 1.3 {
SELECT * FROM t1 CROSS JOIN t2 WHERE y=b+1;
} {
{(col(1) == (15 + 1))}
{(col(1) == (25 + 1))}
}
# Indexed queries
#
do_test 4.1 {
db eval {
CREATE INDEX t1bc ON t1(b,c);
CREATE INDEX t2yz ON t2(y,z);
}
p4_of_opcode db CursorHint {
SELECT * FROM t1 WHERE b>11;
}
} {/(c0>11)/}
do_test 4.2 {
p5_of_opcode db OpenRead . {
SELECT * FROM t1 WHERE b>11;
}
} {02 00}
do_test 4.3 {
p4_of_opcode db CursorHint {
SELECT c FROM t1 WHERE b>11;
}
} {/(c0>11)/}
do_test 4.4 {
p5_of_opcode db OpenRead . {
SELECT c FROM t1 WHERE b>11;
}
} {00}
finish_test