mirror of
https://github.com/tursodatabase/libsql.git
synced 2024-12-12 15:33:44 +00:00
ad79ef48a2
* add tests * add bench
290 lines
7.7 KiB
Plaintext
290 lines
7.7 KiB
Plaintext
|
|
CREATE TABLE t1_a(a INTEGER PRIMARY KEY, b TEXT);
|
|
CREATE TABLE t1_b(c INTEGER PRIMARY KEY, d TEXT);
|
|
CREATE TABLE t1_c(e INTEGER PRIMARY KEY, f TEXT);
|
|
|
|
INSERT INTO t1_a VALUES(1, 'one'), (4, 'four');
|
|
INSERT INTO t1_b VALUES(2, 'two'), (5, 'five');
|
|
INSERT INTO t1_c VALUES(3, 'three'), (6, 'six');
|
|
|
|
CREATE VIEW t1 AS
|
|
SELECT a, b FROM t1_a UNION ALL
|
|
SELECT c, d FROM t1_b UNION ALL
|
|
SELECT e, f FROM t1_c;
|
|
|
|
CREATE TABLE i1(x);
|
|
INSERT INTO i1 VALUES(2), (5), (6), (1);
|
|
|
|
|
|
SELECT a, b FROM (
|
|
SELECT a, b FROM t1_a UNION ALL
|
|
SELECT c, d FROM t1_b UNION ALL
|
|
SELECT e, f FROM t1_c
|
|
) ORDER BY a
|
|
|
|
|
|
SELECT a, b FROM t1 ORDER BY a
|
|
|
|
|
|
SELECT a, b FROM i1, t1 WHERE a=x ORDER BY a
|
|
|
|
|
|
CREATE TABLE t0(c0 INT);
|
|
INSERT INTO t0 VALUES(0);
|
|
CREATE TABLE t1_a(a INTEGER PRIMARY KEY, b TEXT);
|
|
INSERT INTO t1_a VALUES(1,'one');
|
|
CREATE TABLE t1_b(c INTEGER PRIMARY KEY, d TEXT);
|
|
INSERT INTO t1_b VALUES(2,'two');
|
|
CREATE VIEW t1 AS SELECT a, b FROM t1_a UNION ALL SELECT c, c FROM t1_b;
|
|
SELECT * FROM (SELECT t1.a, t1.b AS b, t0.c0 FROM t0, t1);
|
|
|
|
|
|
SELECT * FROM (SELECT t1.a, t1.b AS b, t0.c0 FROM t0, t1) WHERE b=2;
|
|
|
|
|
|
CREATE TABLE t1(x, y);
|
|
INSERT INTO t1 VALUES(1, 'one');
|
|
INSERT INTO t1 VALUES(1, 'ONE');
|
|
INSERT INTO t1 VALUES(2, 'two');
|
|
INSERT INTO t1 VALUES(2, 'TWO');
|
|
INSERT INTO t1 VALUES(3, 'three');
|
|
INSERT INTO t1 VALUES(3, 'THREE');
|
|
|
|
|
|
WITH s(i) AS (
|
|
SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<3
|
|
)
|
|
SELECT * FROM (
|
|
SELECT 0 AS i UNION ALL SELECT i FROM s UNION ALL SELECT 0
|
|
), t1 WHERE x=i;
|
|
|
|
|
|
CREATE TABLE t2_a(k INTEGER PRIMARY KEY, v TEXT);
|
|
CREATE TABLE t2_b(k INTEGER PRIMARY KEY, v TEXT);
|
|
|
|
CREATE VIEW t2 AS
|
|
SELECT * FROM t2_a
|
|
UNION ALL
|
|
SELECT * FROM t2_b;
|
|
|
|
CREATE TRIGGER t2_insert INSTEAD OF INSERT ON t2 BEGIN
|
|
INSERT INTO t2_a SELECT new.k, new.v WHERE (new.k%2)==0;
|
|
INSERT INTO t2_b SELECT new.k, new.v WHERE (new.k%2)==1;
|
|
END;
|
|
|
|
INSERT INTO t2 VALUES(5, 'v'), (4, 'iv'), (3, 'iii'), (2, 'ii');
|
|
|
|
|
|
SELECT * FROM t1, t2 WHERE x=k;
|
|
|
|
|
|
SELECT * FROM t1 LEFT JOIN t2 ON (x=k);
|
|
|
|
|
|
SELECT x1.*, x2.* FROM t2 AS x1, t2 AS x2 WHERE x1.k=x2.k+1
|
|
|
|
|
|
SELECT * FROM t1, t2 WHERE x=k ORDER BY y;
|
|
|
|
|
|
SELECT * FROM t1, t2 WHERE x=k ORDER BY y||'';
|
|
|
|
|
|
SELECT * FROM t1, t2 WHERE x=k ORDER BY v
|
|
|
|
|
|
SELECT * FROM t1, t2 WHERE x=k ORDER BY v||''
|
|
|
|
|
|
SELECT * FROM t1, t2 WHERE x=k ORDER BY k,v||''
|
|
|
|
|
|
SELECT * FROM t1, t2 ORDER BY +k
|
|
|
|
|
|
SELECT * FROM t1, t2 ORDER BY k
|
|
|
|
|
|
CREATE TABLE t1(c INTEGER PRIMARY KEY, d TEXT);
|
|
INSERT INTO t1 VALUES(1,2);
|
|
CREATE TABLE t3_a(k INTEGER PRIMARY KEY, v TEXT);
|
|
INSERT INTO t3_a VALUES(2,'ii');
|
|
CREATE TABLE t3_b(k INTEGER PRIMARY KEY, v TEXT);
|
|
CREATE VIEW t3 AS
|
|
SELECT * FROM t3_a
|
|
UNION ALL
|
|
SELECT * FROM t3_b;
|
|
|
|
|
|
SELECT * FROM t1, t3 ORDER BY k;
|
|
|
|
|
|
|
|
CREATE TABLE t1_a(a INTEGER PRIMARY KEY, b TEXT);
|
|
INSERT INTO t1_a VALUES(123, 't1_a');
|
|
CREATE TABLE t1_b(c INTEGER PRIMARY KEY, d TEXT);
|
|
|
|
CREATE VIEW t1 AS
|
|
SELECT a, b FROM t1_a
|
|
UNION ALL
|
|
SELECT c, d FROM t1_b;
|
|
|
|
CREATE TABLE t3_a(k INTEGER PRIMARY KEY, v TEXT);
|
|
INSERT INTO t3_a VALUES(456, 't3_a');
|
|
CREATE TABLE t3_b(k INTEGER PRIMARY KEY, v TEXT);
|
|
|
|
CREATE VIEW t3 AS
|
|
SELECT * FROM t3_a
|
|
UNION ALL
|
|
SELECT * FROM t3_b;
|
|
|
|
|
|
SELECT * FROM t1, t3 ORDER BY k;
|
|
|
|
|
|
SELECT * FROM (SELECT * FROM t1, t3) ORDER BY k;
|
|
|
|
|
|
SELECT * FROM (SELECT * FROM t1, t3), (
|
|
SELECT max(a) OVER () FROM t1
|
|
UNION ALL
|
|
SELECT min(a) OVER () FROM t1
|
|
)
|
|
ORDER BY k;
|
|
|
|
|
|
SELECT * FROM (SELECT * FROM t1, t3), (
|
|
SELECT group_concat(a) OVER (ORDER BY a),
|
|
group_concat(a) OVER (ORDER BY a),
|
|
group_concat(a) OVER (ORDER BY a),
|
|
group_concat(a) OVER (ORDER BY a),
|
|
group_concat(a) OVER (ORDER BY a),
|
|
group_concat(a) OVER (ORDER BY a),
|
|
group_concat(a) OVER (ORDER BY a),
|
|
group_concat(a) OVER (ORDER BY a),
|
|
group_concat(a) OVER (ORDER BY a)
|
|
FROM t1
|
|
)
|
|
ORDER BY k;
|
|
|
|
|
|
SELECT * FROM (SELECT * FROM t1, t3) AS o, (
|
|
SELECT * FROM t1 LEFT JOIN t3 ON a=k
|
|
);
|
|
|
|
|
|
CREATE TABLE t1_a(a INTEGER PRIMARY KEY, b TEXT);
|
|
INSERT INTO t1_a VALUES(1,'one');
|
|
INSERT INTO t1_a VALUES(0,NULL);
|
|
CREATE TABLE t1_b(c INTEGER PRIMARY KEY, d TEXT);
|
|
INSERT INTO t1_b VALUES(2,'two');
|
|
INSERT INTO t1_b VALUES(5,'five');
|
|
CREATE TABLE t1_c(e INTEGER PRIMARY KEY, f TEXT);
|
|
INSERT INTO t1_c VALUES(3,'three');
|
|
INSERT INTO t1_c VALUES(6,'six');
|
|
CREATE TABLE t2(k,v);
|
|
INSERT INTO t2 VALUES(5,'v');
|
|
INSERT INTO t2 VALUES(4,'iv');
|
|
INSERT INTO t2 VALUES(3,'iii');
|
|
INSERT INTO t2 VALUES(2,'ii');
|
|
CREATE TABLE t3_a(k INTEGER PRIMARY KEY, v TEXT);
|
|
INSERT INTO t3_a VALUES(2,'ii');
|
|
INSERT INTO t3_a VALUES(4,'iv');
|
|
CREATE TABLE t3_b(k INTEG5R PRIMARY KEY, v TEXT);
|
|
INSERT INTO t3_b VALUES(NULL,'iii');
|
|
INSERT INTO t3_b VALUES(NULL,'v');
|
|
CREATE VIEW t1 AS
|
|
SELECT a, b FROM t1_a UNION ALL
|
|
SELECT c, d FROM t1_b UNION ALL
|
|
SELECT e, f FROM t1_c;
|
|
CREATE VIEW t3 AS
|
|
SELECT * FROM t3_a
|
|
UNION ALL
|
|
SELECT * FROM t3_b;
|
|
CREATE TRIGGER t3_insert INSTEAD OF INSERT ON t3 BEGIN
|
|
INSERT INTO t3_a SELECT new.k, new.v WHERE (new.k%2)==0;
|
|
INSERT INTO t3_b SELECT new.k, new.v WHERE (new.k%2)==1;
|
|
END;
|
|
|
|
|
|
SELECT *, '+' FROM t1 LEFT JOIN t2 ON (a NOT IN(SELECT v FROM t1, t3 WHERE a=k)=NOT EXISTS(SELECT 1 FROM t1 LEFT JOIN t3 ON (a=k)));
|
|
|
|
|
|
SELECT *, '+' FROM t1 LEFT JOIN t3 ON (a NOT IN(SELECT v FROM t1 LEFT JOIN t2 ON (a=k))=k);
|
|
|
|
|
|
CREATE TABLE t1(a,b);
|
|
INSERT INTO t1 VALUES(1,2);
|
|
CREATE TABLE t2(a,b);
|
|
INSERT INTO t2 VALUES(3,4);
|
|
|
|
CREATE TABLE t3(a,b);
|
|
INSERT INTO t3 VALUES(5,6);
|
|
CREATE TABLE t4(a,b);
|
|
INSERT INTO t4 VALUES(7,8);
|
|
|
|
CREATE TABLE t5(a,b);
|
|
INSERT INTO t5 VALUES(9,10);
|
|
|
|
|
|
WITH x(c) AS (
|
|
SELECT 1000 FROM t1 UNION ALL SELECT 800 FROM t2
|
|
),
|
|
y(d) AS (
|
|
SELECT 100 FROM t3 UNION ALL SELECT 400 FROM t4
|
|
)
|
|
SELECT * FROM t5, x, y;
|
|
|
|
|
|
WITH c1(x) AS (VALUES(0) UNION ALL SELECT 100+x FROM c1 WHERE x<100 UNION ALL SELECT 1+x FROM c1 WHERE x<1)
|
|
SELECT x, y, '|'
|
|
FROM c1 AS x1, (SELECT x+1 AS y FROM c1 WHERE x<1 UNION ALL SELECT 1+x FROM c1 WHERE 1<x) AS x2
|
|
ORDER BY x, y;
|
|
|
|
|
|
CREATE TABLE t0(c0 INT);
|
|
INSERT INTO t0 VALUES(0);
|
|
CREATE TABLE t1_a(a INTEGER PRIMARY KEY, b TEXT);
|
|
INSERT INTO t1_a VALUES(1,'one');
|
|
INSERT INTO t1_a VALUES(4,'four');
|
|
CREATE TABLE t1_b(c INTEGER PRIMARY KEY, d TEXT);
|
|
INSERT INTO t1_b VALUES(2,'two');
|
|
INSERT INTO t1_b VALUES(5,'five');
|
|
CREATE TABLE t1_c(e INTEGER PRIMARY KEY, f TEXT);
|
|
INSERT INTO t1_c VALUES(3,'three');
|
|
INSERT INTO t1_c VALUES(6,'six');
|
|
CREATE VIEW v0(c0) AS SELECT CAST(t0.c0 AS INTEGER) FROM t0;
|
|
CREATE VIEW t1 AS
|
|
SELECT a, b FROM t1_a UNION ALL
|
|
SELECT c, c FROM t1_b UNION ALL
|
|
SELECT e, f FROM t1_c;
|
|
SELECT t1.a, t1.b, t0.c0 AS c, v0.c0 AS d FROM t0 LEFT JOIN v0 ON v0.c0>'0',t1;
|
|
|
|
|
|
SELECT * FROM (SELECT t1.a, t1.b, t0.c0 AS c, v0.c0 AS d FROM t0 LEFT JOIN v0 ON v0.c0>'0',t1) WHERE b=2;
|
|
|
|
|
|
SELECT * FROM (SELECT t1.a, t1.b, t0.c0 AS c, v0.c0 AS d FROM t0 LEFT JOIN v0 ON v0.c0>'0',t1) WHERE b=2.0;
|
|
|
|
|
|
SELECT * FROM (SELECT t1.a, t1.b, t0.c0 AS c, v0.c0 AS d FROM t0 LEFT JOIN v0 ON v0.c0>'0',t1) WHERE b='2';
|
|
|
|
|
|
SELECT * FROM (SELECT t1.a, t1.b, t0.c0 AS c, v0.c0 AS d FROM t0 LEFT JOIN v0 ON v0.c0>'0',t1) WHERE b=2;
|
|
|
|
|
|
SELECT * FROM (SELECT t1.a, t1.b, t0.c0 AS c, v0.c0 AS d FROM t0 LEFT JOIN v0 ON v0.c0>'0',t1) WHERE b=2.0;
|
|
|
|
|
|
SELECT * FROM (SELECT t1.a, t1.b, t0.c0 AS c, v0.c0 AS d FROM t0 LEFT JOIN v0 ON v0.c0>'0',t1) WHERE b='2';
|
|
|
|
|
|
SELECT * FROM (SELECT t1.a, t1.b, t0.c0 AS c, v0.c0 AS d FROM t0 LEFT JOIN v0 ON v0.c0>'0',t1) WHERE b=2;
|
|
|
|
|
|
SELECT * FROM (SELECT t1.a, t1.b, t0.c0 AS c, v0.c0 AS d FROM t0 LEFT JOIN v0 ON v0.c0>'0',t1) WHERE b=2.0;
|
|
|
|
|
|
SELECT * FROM (SELECT t1.a, t1.b, t0.c0 AS c, v0.c0 AS d FROM t0 LEFT JOIN v0 ON v0.c0>'0',t1) WHERE b='2';
|
|
|