3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
11 # This file implements tests for indexes on large numeric values.
14 set testdir [file dirname $argv0]
15 source $testdir/tester.tcl
18 # Test cases from Zsbán Ambrus:
20 do_execsql_test numindex1-1.1 {
21 CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
22 CREATE INDEX t1b ON t1(b);
23 INSERT INTO t1(a,b) VALUES(100, 356282677878746339);
24 INSERT INTO t1(a,b) VALUES(50, 356282677878746339.0);
25 INSERT INTO t1(a,b) VALUES(0, 356282677878746340);
26 DELETE FROM t1 WHERE a=50;
27 PRAGMA integrity_check;
30 do_execsql_test numindex1-1.2 {
32 INSERT INTO t2(a,b) VALUES('b', 1<<58),
33 ('c', (1<<58)+1e-7), ('d', (1<<58)+1);
34 SELECT a, b, typeof(b), '|' FROM t2 ORDER BY +a;
35 } {b 288230376151711744 integer | c 2.88230376151712e+17 real | d 288230376151711745 integer |}
37 do_execsql_test numindex1-1.3 {
38 SELECT x.a || CASE WHEN x.b==y.b THEN '==' ELSE '<>' END || y.a
41 } {b==b b==c b<>d c==b c==c c<>d d<>b d<>c d==d}
45 do_execsql_test numindex1-2.1 {
46 DROP TABLE IF EXISTS t1;
47 CREATE TABLE t1(a INTEGER PRIMARY KEY,b);
48 CREATE INDEX t1b ON t1(b);
49 WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<100)
50 INSERT INTO t1(a,b) SELECT x, 10000000000000004.0 FROM c
51 WHERE x NOT IN (23,37);
52 INSERT INTO t1(a,b) VALUES(23,10000000000000005);
53 INSERT INTO t1(a,b) VALUES(37,10000000000000003);
54 DELETE FROM t1 WHERE a NOT IN (23,37);
55 PRAGMA integrity_check;
58 do_execsql_test numindex1-3.1 {
59 DROP TABLE IF EXISTS t1;
60 CREATE TABLE t1(a INTEGER PRIMARY KEY,b);
61 CREATE INDEX t1b ON t1(b);
62 WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<20)
63 INSERT INTO t1(a,b) SELECT x, 100000000000000005.0
64 FROM c WHERE x NOT IN (3,5,7,11,13,17,19);
65 INSERT INTO t1(a,b) VALUES(3,100000000000000005);
66 INSERT INTO t1(a,b) VALUES(5,100000000000000000);
67 INSERT INTO t1(a,b) VALUES(7,100000000000000008);
68 INSERT INTO t1(a,b) VALUES(11,100000000000000006);
69 INSERT INTO t1(a,b) VALUES(13,100000000000000001);
70 INSERT INTO t1(a,b) VALUES(17,100000000000000004);
71 INSERT INTO t1(a,b) VALUES(19,100000000000000003);
72 PRAGMA integrity_check;
75 do_execsql_test numindex1-3.2 {
76 SELECT a FROM t1 ORDER BY b;
77 } {1 2 4 5 6 8 9 10 12 14 15 16 18 20 13 19 17 3 11 7}