1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# 2024 March 20
#
# 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 eqp2
do_execsql_test 1.0 {
CREATE TABLE t1(a, b, c, d);
CREATE INDEX i1 ON t1(a, b, c);
}
do_eqp_test 1.1 {
SELECT * FROM t1 ORDER BY a, b, c
} {
QUERY PLAN
`--SCAN t1 USING INDEX i1
}
do_eqp_test 1.2 {
SELECT * FROM t1 ORDER BY a, b, +c
} {
QUERY PLAN
|--SCAN t1 USING INDEX i1
`--USE TEMP B-TREE FOR LAST TERM OF ORDER BY
}
do_eqp_test 1.3 {
SELECT * FROM t1 ORDER BY a, +b, +c
} {
QUERY PLAN
|--SCAN t1 USING INDEX i1
`--USE TEMP B-TREE FOR LAST 2 TERMS OF ORDER BY
}
#-------------------------------------------------------------------------
# Test that a bound value of 0 is handled in the same way as a literal
# 0 when estimating the probability of (x=<some-integer>).
#
reset_db
do_execsql_test 2.0 {
CREATE TABLE t1(a INT, b INT);
CREATE TABLE t2(x INT, y INT);
CREATE INDEX t1_a ON t1(a);
CREATE INDEX t1_b ON t1(b);
CREATE INDEX t2_x ON t2(x);
WITH s(i) AS ( SELECT 0 UNION ALL SELECT i+1 FROM s WHERE i<999)
INSERT INTO t1 SELECT i%33, i FROM s;
WITH s(i) AS ( SELECT 0 UNION ALL SELECT i+1 FROM s WHERE i<59)
INSERT INTO t2 SELECT i, i%3 FROM s;
ANALYZE;
}
set zero [expr 0]
if {[permutation] != "prepare"} {
do_eqp_test 2.1 {
SELECT * FROM t1 JOIN t2 ON t1.b = t2.x
WHERE t1.a = 5 AND t2.y = $zero
} {SEARCH t1 USING INDEX t1_a (a=?)*SEARCH t2 USING INDEX t2_x (x=?)}
}
do_eqp_test 2.2 {
SELECT * FROM t1 JOIN t2 ON t1.b = t2.x
WHERE t1.a = 5 AND t2.y = 0
} {SEARCH t1 USING INDEX t1_a (a=?)*SEARCH t2 USING INDEX t2_x (x=?)}
finish_test
|