xref: /sqlite-3.40.0/test/bloom1.test (revision 73ac958c)
1*73ac958cSdan# 2022 October 06
2*73ac958cSdan#
3*73ac958cSdan# The author disclaims copyright to this source code.  In place of
4*73ac958cSdan# a legal notice, here is a blessing:
5*73ac958cSdan#
6*73ac958cSdan#    May you do good and not evil.
7*73ac958cSdan#    May you find forgiveness for yourself and forgive others.
8*73ac958cSdan#    May you share freely, never taking more than you give.
9*73ac958cSdan#
10*73ac958cSdan#***********************************************************************
11*73ac958cSdan#
12*73ac958cSdan# Tests for queries that use bloom filters
13*73ac958cSdan
14*73ac958cSdanset testdir [file dirname $argv0]
15*73ac958cSdansource $testdir/tester.tcl
16*73ac958cSdansource $testdir/lock_common.tcl
17*73ac958cSdansource $testdir/malloc_common.tcl
18*73ac958cSdan
19*73ac958cSdanset testprefix bloom1
20*73ac958cSdan
21*73ac958cSdan# Tests 1.*  verify that the bloom filter code correctly handles the
22*73ac958cSdan# case where the RHS of an (<ipk-column> = ?) expression must be coerced
23*73ac958cSdan# to an integer before the comparison made.
24*73ac958cSdan#
25*73ac958cSdando_execsql_test 1.0 {
26*73ac958cSdan  CREATE TABLE t1(a, b);
27*73ac958cSdan  CREATE TABLE t2(c INTEGER PRIMARY KEY, d);
28*73ac958cSdan}
29*73ac958cSdan
30*73ac958cSdando_execsql_test 1.1 {
31*73ac958cSdan  INSERT INTO t1 VALUES('hello', 'world');
32*73ac958cSdan  INSERT INTO t2 VALUES(14, 'fourteen');
33*73ac958cSdan}
34*73ac958cSdan
35*73ac958cSdando_execsql_test 1.2 {
36*73ac958cSdan  ANALYZE sqlite_schema;
37*73ac958cSdan  INSERT INTO sqlite_stat1 VALUES('t2','idx1','6 6');
38*73ac958cSdan  ANALYZE sqlite_schema;
39*73ac958cSdan}
40*73ac958cSdan
41*73ac958cSdando_execsql_test 1.3 {
42*73ac958cSdan  SELECT 'affinity!' FROM t1 CROSS JOIN t2 WHERE t2.c = '14';
43*73ac958cSdan} {affinity!}
44*73ac958cSdan
45*73ac958cSdan
46*73ac958cSdanreset_db
47*73ac958cSdando_execsql_test 1.4 {
48*73ac958cSdan  CREATE TABLE t1(a, b TEXT);
49*73ac958cSdan  CREATE TABLE t2(c INTEGER PRIMARY KEY, d);
50*73ac958cSdan  CREATE TABLE t3(e INTEGER PRIMARY KEY, f);
51*73ac958cSdan
52*73ac958cSdan  ANALYZE sqlite_schema;
53*73ac958cSdan  INSERT INTO sqlite_stat1 VALUES('t1','idx1','600 6');
54*73ac958cSdan  INSERT INTO sqlite_stat1 VALUES('t2','idx1','6 6');
55*73ac958cSdan  INSERT INTO sqlite_stat1 VALUES('t3','idx2','6 6');
56*73ac958cSdan  ANALYZE sqlite_schema;
57*73ac958cSdan
58*73ac958cSdan  INSERT INTO t1 VALUES(1, '123');
59*73ac958cSdan  INSERT INTO t2 VALUES(123, 'one');
60*73ac958cSdan  INSERT INTO t3 VALUES(123, 'two');
61*73ac958cSdan}
62*73ac958cSdan
63*73ac958cSdando_execsql_test 1.5 {
64*73ac958cSdan  SELECT 'result' FROM t1, t2, t3
65*73ac958cSdan  WHERE t2.c=t1.b AND t2.d!='silly'
66*73ac958cSdan    AND t3.e=t1.b AND t3.f!='silly'
67*73ac958cSdan} {result}
68*73ac958cSdan
69*73ac958cSdanfinish_test
70*73ac958cSdan
71