interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / test / eqp2.test

83 lines · 1966 bytes Raw Blame History
1# 2024 March 20
2#
3# The author disclaims copyright to this source code. In place of
4# a legal notice, here is a blessing:
5#
6# May you do good and not evil.
7# May you find forgiveness for yourself and forgive others.
8# May you share freely, never taking more than you give.
9#
10#***********************************************************************
11#
12
13set testdir [file dirname $argv0]
14source $testdir/tester.tcl
15
16set testprefix eqp2
17
18do_execsql_test 1.0 {
19 CREATE TABLE t1(a, b, c, d);
20 CREATE INDEX i1 ON t1(a, b, c);
21}
22
23do_eqp_test 1.1 {
24 SELECT * FROM t1 ORDER BY a, b, c
25} {
26 QUERY PLAN
27 `--SCAN t1 USING INDEX i1
28}
29
30
31do_eqp_test 1.2 {
32 SELECT * FROM t1 ORDER BY a, b, +c
33} {
34 QUERY PLAN
35 |--SCAN t1 USING INDEX i1
36 `--USE TEMP B-TREE FOR LAST TERM OF ORDER BY
37}
38
39do_eqp_test 1.3 {
40 SELECT * FROM t1 ORDER BY a, +b, +c
41} {
42 QUERY PLAN
43 |--SCAN t1 USING INDEX i1
44 `--USE TEMP B-TREE FOR LAST 2 TERMS OF ORDER BY
45}
46
47#-------------------------------------------------------------------------
48# Test that a bound value of 0 is handled in the same way as a literal
49# 0 when estimating the probability of (x=<some-integer>).
50#
51reset_db
52do_execsql_test 2.0 {
53 CREATE TABLE t1(a INT, b INT);
54 CREATE TABLE t2(x INT, y INT);
55 CREATE INDEX t1_a ON t1(a);
56 CREATE INDEX t1_b ON t1(b);
57 CREATE INDEX t2_x ON t2(x);
58
59 WITH s(i) AS ( SELECT 0 UNION ALL SELECT i+1 FROM s WHERE i<999)
60 INSERT INTO t1 SELECT i%33, i FROM s;
61
62 WITH s(i) AS ( SELECT 0 UNION ALL SELECT i+1 FROM s WHERE i<59)
63 INSERT INTO t2 SELECT i, i%3 FROM s;
64
65 ANALYZE;
66}
67
68set zero [expr 0]
69
70if {[permutation] != "prepare"} {
71 do_eqp_test 2.1 {
72 SELECT * FROM t1 JOIN t2 ON t1.b = t2.x
73 WHERE t1.a = 5 AND t2.y = $zero
74 } {SEARCH t1 USING INDEX t1_a (a=?)*SEARCH t2 USING INDEX t2_x (x=?)}
75}
76
77do_eqp_test 2.2 {
78 SELECT * FROM t1 JOIN t2 ON t1.b = t2.x
79 WHERE t1.a = 5 AND t2.y = 0
80} {SEARCH t1 USING INDEX t1_a (a=?)*SEARCH t2 USING INDEX t2_x (x=?)}
81
82
83finish_test