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 regression tests for SQLite library. The
12 # focus of this file is testing the WITH clause.
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
17 set ::testprefix with3
24 # Test problems found by Kostya Serebryany using
25 # LibFuzzer. (http://llvm.org/docs/LibFuzzer.html)
27 do_catchsql_test 1.0 {
30 SELECT 5 FROM t0 UNION SELECT 8 FROM m
33 } {1 {no such table: m}}
35 # Additional test cases that came out of the work to
36 # fix for Kostya's problem.
43 SELECT * FROM x1 UNION ALL SELECT * FROM x2
58 x1(a) AS (values(100))
60 SELECT * FROM (WITH x2(y) AS (SELECT * FROM x1) SELECT y+a FROM x1, x2);
64 #-------------------------------------------------------------------------
65 # Test that the planner notices LIMIT clauses on recursive WITH queries.
69 do_execsql_test 3.1.1 {
70 CREATE TABLE y1(a, b);
71 CREATE INDEX y1a ON y1(a);
73 WITH cnt(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM cnt LIMIT 1000)
74 INSERT INTO y1 SELECT i%10, i FROM cnt;
80 WITH cnt(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM cnt LIMIT 1)
81 SELECT * FROM cnt, y1 WHERE i=a
82 } [string map {"\n " \n} {
86 | | `--SCAN CONSTANT ROW
89 |--SCAN SUBQUERY xxxxxx
90 `--SEARCH TABLE y1 USING INDEX y1a (a=?)
94 WITH cnt(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM cnt LIMIT 1000000)
95 SELECT * FROM cnt, y1 WHERE i=a
96 } [string map {"\n " \n} {
100 | | `--SCAN CONSTANT ROW
104 `--SEARCH SUBQUERY xxxxxx USING AUTOMATIC COVERING INDEX (i=?)
108 do_execsql_test 3.2.1 {
109 CREATE TABLE w1(pk INTEGER PRIMARY KEY, x INTEGER);
110 CREATE TABLE w2(pk INTEGER PRIMARY KEY);
114 WITH RECURSIVE c(w,id) AS (SELECT 0, (SELECT pk FROM w2 LIMIT 1)
115 UNION ALL SELECT c.w + 1, x FROM w1, c LIMIT 1)
116 SELECT * FROM c, w2, w1
117 WHERE c.id=w2.pk AND c.id=w1.pk;
120 |--MATERIALIZE xxxxxx
122 | | |--SCAN CONSTANT ROW
123 | | `--SCALAR SUBQUERY
128 |--SCAN SUBQUERY xxxxxx
129 |--SEARCH TABLE w2 USING INTEGER PRIMARY KEY (rowid=?)
130 `--SEARCH TABLE w1 USING INTEGER PRIMARY KEY (rowid=?)