0
0
mirror of https://github.com/tursodatabase/libsql.git synced 2024-12-12 15:33:44 +00:00
ad hoc ad79ef48a2
libsql wal tests (#1408)
* add tests

* add bench
2024-05-24 13:59:17 +00:00

227 lines
6.1 KiB
Plaintext

DROP TABLE IF EXISTS t1;
DROP TABLE IF EXISTS t2;
DROP TABLE IF EXISTS t3;
CREATE TABLE x1(a);
INSERT INTO x1 VALUES(1);
CREATE TABLE x2(b NOT NULL);
CREATE TABLE x3(c, d);
INSERT INTO x3 VALUES('a', NULL);
INSERT INTO x3 VALUES('b', NULL);
INSERT INTO x3 VALUES('c', NULL);
SELECT * FROM x1 LEFT JOIN x2 LEFT JOIN x3 ON x3.d = x2.b;
DROP TABLE IF EXISTS t1;
DROP TABLE IF EXISTS t2;
DROP TABLE IF EXISTS t3;
DROP TABLE IF EXISTS t4;
DROP TABLE IF EXISTS t5;
CREATE TABLE t1(x text NOT NULL, y text);
CREATE TABLE t2(u text NOT NULL, x text NOT NULL);
CREATE TABLE t3(w text NOT NULL, v text);
CREATE TABLE t4(w text NOT NULL, z text NOT NULL);
CREATE TABLE t5(z text NOT NULL, m text);
INSERT INTO t1 VALUES('f6d7661f-4efe-4c90-87b5-858e61cd178b',NULL);
INSERT INTO t1 VALUES('f6ea82c3-2cad-45ce-ae8f-3ddca4fb2f48',NULL);
INSERT INTO t1 VALUES('f6f47499-ecb4-474b-9a02-35be73c235e5',NULL);
INSERT INTO t1 VALUES('56f47499-ecb4-474b-9a02-35be73c235e5',NULL);
INSERT INTO t3 VALUES('007f2033-cb20-494c-b135-a1e4eb66130c',
'f6d7661f-4efe-4c90-87b5-858e61cd178b');
SELECT *
FROM t3
INNER JOIN t1 ON t1.x= t3.v AND t1.y IS NULL
LEFT JOIN t4 ON t4.w = t3.w
LEFT JOIN t5 ON t5.z = t4.z
LEFT JOIN t2 ON t2.u = t5.m
LEFT JOIN t1 xyz ON xyz.y = t2.x;
DROP TABLE IF EXISTS x1;
DROP TABLE IF EXISTS x2;
DROP TABLE IF EXISTS x3;
CREATE TABLE x1(a);
INSERT INTO x1 VALUES(1);
CREATE TABLE x2(b NOT NULL);
CREATE TABLE x3(c, d);
INSERT INTO x3 VALUES('a', NULL);
INSERT INTO x3 VALUES('b', NULL);
INSERT INTO x3 VALUES('c', NULL);
SELECT * FROM x1 LEFT JOIN x2 JOIN x3 WHERE x3.d = x2.b;
SELECT *
FROM (
SELECT 'apple' fruit
UNION ALL SELECT 'banana'
) a
JOIN (
SELECT 'apple' fruit
UNION ALL SELECT 'banana'
) b ON a.fruit=b.fruit
LEFT JOIN (
SELECT 1 isyellow
) c ON b.fruit='banana';
SELECT *
FROM (SELECT 'apple' fruit UNION ALL SELECT 'banana')
LEFT JOIN (SELECT 1) ON fruit='banana';
CREATE TABLE y1(x, y, z);
INSERT INTO y1 VALUES(0, 0, 1);
CREATE TABLE y2(a);
SELECT count(z) FROM y1 LEFT JOIN y2 ON x GROUP BY y;
SELECT count(z) FROM ( SELECT * FROM y1 ) LEFT JOIN y2 ON x GROUP BY y;
CREATE VIEW v1 AS SELECT x, y, z FROM y1;
SELECT count(z) FROM v1 LEFT JOIN y2 ON x GROUP BY y;
SELECT count(z) FROM ( SELECT * FROM y1 ) LEFT JOIN y2 ON x
SELECT * FROM ( SELECT * FROM y1 ) LEFT JOIN y2 ON x
CREATE TABLE t1(x);
INSERT INTO t1 VALUES(1);
CREATE TABLE t2(y INTEGER PRIMARY KEY,a,b);
INSERT INTO t2 VALUES(1,2,3);
CREATE INDEX t2a ON t2(a);
CREATE INDEX t2b ON t2(b);
SELECT * FROM t1 LEFT JOIN t2 ON a=2 OR b=3 WHERE y IS NULL;
CREATE TABLE t3(x);
INSERT INTO t3 VALUES(1);
CREATE TABLE t4(y, z);
SELECT ifnull(z, '!!!') FROM t3 LEFT JOIN t4 ON (x=y);
CREATE INDEX t4i ON t4(y, ifnull(z, '!!!'));
SELECT ifnull(z, '!!!') FROM t3 LEFT JOIN t4 ON (x=y);
CREATE TABLE t1(aa, bb);
CREATE INDEX t1x1 on t1(abs(aa), abs(bb));
INSERT INTO t1 VALUES(-2,-3),(+2,-3),(-2,+3),(+2,+3);
SELECT * FROM (t1)
WHERE ((abs(aa)=1 AND 1=2) OR abs(aa)=2)
AND abs(bb)=3
ORDER BY +1, +2;
CREATE TABLE t1(x);
INSERT INTO t1 VALUES(1);
CREATE TABLE t2(x, y, z);
CREATE INDEX t2xy ON t2(x, y);
WITH s(i) AS (
SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<50000
)
INSERT INTO t2 SELECT i/10, i, NULL FROM s;
ANALYZE;
CREATE TABLE t3(x);
INSERT INTO t3(x) VALUES(1);
CREATE INDEX t3x ON t3(x);
CREATE TABLE t4(x, y, z);
CREATE INDEX t4xy ON t4(x, y);
CREATE INDEX t4xz ON t4(x, z);
WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<50000)
INSERT INTO t4 SELECT i/10, i, i FROM s;
ANALYZE;
UPDATE sqlite_stat1 SET stat='1000000 10 1' WHERE idx='t3x';
ANALYZE sqlite_schema;
CREATE TABLE t0 (c0, c1, PRIMARY KEY (c0, c1));
CREATE TABLE t1 (c0);
INSERT INTO t1 VALUES (2);
INSERT INTO t0 VALUES(0, 10);
INSERT INTO t0 VALUES(1, 10);
INSERT INTO t0 VALUES(2, 10);
INSERT INTO t0 VALUES(3, 10);
SELECT * FROM t0, t1
WHERE (t0.c1 >= 1 OR t0.c1 < 1) AND t0.c0 IN (1, t1.c0) ORDER BY 1;
CREATE TABLE t1(a ,b FLOAT);
INSERT INTO t1 VALUES(1,1);
CREATE INDEX t1x1 ON t1(a,b,a,a,a,a,a,a,a,a,a,b);
ANALYZE sqlite_schema;
INSERT INTO sqlite_stat1 VALUES('t1','t1x1','648 324 81 81 81 81 81 81 81081 81 81 81');
ANALYZE sqlite_schema;
SELECT a FROM (SELECT a FROM t1 NATURAL LEFT JOIN t1) NATURAL LEFT JOIN t1 WHERE (rowid,1)<=(5,0);
CREATE TABLE t1(x INT);
WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<20)
INSERT INTO t1(x) SELECT 0 FROM c;
CREATE INDEX t1x1 ON t1(x BETWEEN 0 AND 10, x);
ANALYZE;
DELETE FROM t1;
INSERT INTO t1 VALUES(0),(0);
CREATE VIEW v1 AS SELECT * FROM t1 NATURAL JOIN t1 WHERE (x BETWEEN 0 AND 10) OR true;
CREATE VIEW v2 AS SELECT * FROM v1 NATURAL JOIN v1;
CREATE VIEW v3 AS SELECT * FROM v2, v1 USING (x) GROUP BY x;
SELECT x FROM v3;
CREATE TABLE t1(a INTEGER PRIMARY KEY, b INT);
CREATE TABLE t2(c INTEGER PRIMARY KEY, d INT);
WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<8)
INSERT INTO t1(a,b) SELECT x, 10*x FROM c;
INSERT INTO t2(c,d) SELECT b*2, 100*a FROM t1;
ANALYZE;
DELETE FROM sqlite_stat1;
INSERT INTO sqlite_stat1(tbl,idx,stat) VALUES
('t1',NULL,150105),('t2',NULL,98747);
ANALYZE sqlite_schema;
SELECT count(*) FROM t1 LEFT JOIN t2 ON c=b WHERE d IS NULL;
SELECT count(*) FROM t1 LEFT JOIN t2 ON c=b WHERE d=100;
SELECT count(*) FROM t1 LEFT JOIN t2 ON c=b WHERE d>=300;
CREATE TABLE t1(a INT, b INT, c INT);
WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<100)
INSERT INTO t1(a,b,c) SELECT x, x*1000, x*1000000 FROM c;
CREATE TABLE t2(b INT, x INT);
INSERT INTO t2(b,x) SELECT b, a FROM t1 WHERE a%3==0;
CREATE INDEX t2b ON t2(b);
CREATE TABLE t3(c INT, y INT);
INSERT INTO t3(c,y) SELECT c, a FROM t1 WHERE a%4==0;
CREATE INDEX t3c ON t3(c);
INSERT INTO t1(a,b,c) VALUES(200, 200000, NULL);
ANALYZE;
SELECT * FROM t1 NATURAL JOIN t2 NATURAL JOIN t3 WHERE x>0 AND y>0
ORDER BY +a;