Commit Graph

46 Commits

Author SHA1 Message Date
drh
e3ec00ccb8 Do not compute result columns of subqueries that are never used. Make those
columns NULL instead.  This optimization potentially resolves the enhancement
request described by [/tktview/baa5bb76c35a124c|ticket baa5bb76c35a124c].

FossilOrigin-Name: 5dec3cc0225296a043d17f73126d477d90a604f82b3180628176d8f950adbce8
2023-02-15 17:53:17 +00:00
drh
67f70bea06 Honor the MATERIALIZED keyword on a common table expression by not flattening
the CTE into an outer query.

FossilOrigin-Name: 8d631a6b9eb06b54b10eda595a4c588ca38f909b4afa653b24d1f720b55d72f7
2022-04-22 16:15:48 +00:00
drh
a76b7f5296 Enhance one test case to use various alternative definitions of DUAL.
FossilOrigin-Name: 179dcb6ba771f0e94e06b5e3c5534d8005d27b2c9b4601be20fd68abfbc5dfd0
2021-05-20 18:11:45 +00:00
drh
cd1499f47b Replace [0f0959c6f95046e8] with a new and better solution that also fixes the
CTE name resolution problem described in
[forum:/forumpost/8590e3f6dc|forum post 8590e3f6dc].
Test cases for both problems added.

FossilOrigin-Name: 5614279daff5007d6e047c5c1b3cc82ba80a5c91c529525b0fe68b79ee82dd2c
2021-05-20 00:44:04 +00:00
drh
8210233c7b Revise tests cases to align with the new EXPLAIN QUERY PLAN output.
FossilOrigin-Name: 50fbd532602d2c316813046ed6be8be2991c281eb5f295c4c28520a0de73862c
2021-03-20 15:11:29 +00:00
drh
340558540e Allow multiple recursive terms in the compound SELECT of a recursive CTE.
This facilitates writing a query to find find the connected components of
an undirected graph.

FossilOrigin-Name: 5481fa8c79c34f434e99ab633ff3d0942a309a74fb0cf38e3d3617b51d5d21dd
2020-10-19 01:23:48 +00:00
drh
f1ea425560 DISTINCT may not be ignored inside a UNION ALL common table expression.
Fix for ticket [c51489c3b8f919c5]

FossilOrigin-Name: 7d2b590d3abd66a7e6ae9046198eb669e0fd2f223f7691281e9ad795a12b8903
2020-09-17 00:46:09 +00:00
dan
70a32703ac Fix an assert() that could fail in SQLITE_MUTATION_TEST builds following an error in a query that uses CTEs.
FossilOrigin-Name: c7e29458a73bbe73a1429477d0c01d5a7b870ab75d3cb08a703be21714e439b7
2020-01-21 14:42:48 +00:00
drh
0cbec59c8b When generating the name of a view (or common table expression) because the
SQL does not specify a name, avoid the names "true" and "false" which might
be confused for the boolean literals of the same name, leading to an
inconsistent abstract syntax tree.

FossilOrigin-Name: ff9492d3ff733c222ea67f23d478df1547641b5e2e6dd870b0b29e25c13f3739
2020-01-03 02:20:37 +00:00
dan
c542fa8573 Add test cases for the fix in the previous commit.
FossilOrigin-Name: c1057b2a60add08e5c80ef2a53932a690b096f2eb03c7de863844deaa8fc9d53
2019-05-23 16:40:45 +00:00
drh
59145813d2 Renumber the Select.selId values in the copies of SELECT statements that
implement VIEWs when the VIEW is expanded, so that when the same VIEW is
used twice in the same join, each expansion as a distinct selId.
This fixes ticket [ce823231949d3abf42453c8].

FossilOrigin-Name: 3cacc4b940fd69776d930deec9512df47a2f22cb04fb955e354a0b25bdec287c
2019-05-22 22:49:23 +00:00
drh
4acd754c79 If the query flattener detects an error, cause the SELECT code generator
to abort immediately.

FossilOrigin-Name: 3d3b142f1045080beb775a9cfe88ec143aa460750132e20059fd510291449850
2019-02-06 00:55:47 +00:00
drh
29c992cb04 Revamp the SrcList allocator routines to be methods of Parse instead of
being methods of the "sqlite3" object, so that they can leave better error
messages when the SrcList object grows too large.

FossilOrigin-Name: df08d472b090b212fb77ce2aae0e1ffe79ae5db4b1accf55e6fdb18e8b0a7098
2019-01-17 15:40:41 +00:00
drh
0ad7aa8182 Limit the size of SrcList objects to 200 entries (compile-time configurable
using -DSQLITE_MAX_SRCLIST=n).  The maximum number of tables in a join has
always been 64, so this is not a real constraint on capability.  Limiting the
size of a SrcList prevents DOS attacks (discovered by OSSFuzz) using crazy
nexted CTE joins.

FossilOrigin-Name: 7cac614d5df55eb092b863163483b6782b942b21bd15fd787576fef5619fa849
2019-01-17 14:34:46 +00:00
drh
375afb8bda Fix a problem in the code generator for sorting results with SRT_EphemTab
and a LIMIT clause.

FossilOrigin-Name: 49fcde2f1f981ac0c75728bed3444e7c1d3167311db282d3375c96ce090b2210
2019-01-16 19:26:31 +00:00
drh
bdefaf08ee Fix a problem in which nested CTEs with the same table name trick the
code generator into thinking they are the same CTE, which then tries to
use the manifest them both into the same transient table.

FossilOrigin-Name: 202dd033019dd27428e3cc5f6e164c95b37efe39e2753515112b201ddefca67b
2018-12-27 02:16:01 +00:00
dan
6afa35c985 Disallow the use of window functions in the recursive part of a recursive CTE.
FossilOrigin-Name: 7fc2994434c7d9ed29c96a69c07e8eb4e97be776473c170c63f9a1bbaa09fa68
2018-09-27 12:14:15 +00:00
drh
fa16f5d9d6 Enhance EXPLAIN QUERY PLAN to report the generation of constant rows using
VALUES or just a SELECT without FROM.

FossilOrigin-Name: c75eee69fa8a9b56ee58a4cc539e80cc982f43390dc3a357344d58479dd89a41
2018-05-03 01:37:13 +00:00
drh
b3f0276b9e Fix test cases so that they work with the new EXPLAIN QUERY PLAN output
format.  Only some of the cases have been fixed.  This is an incremental
check-in.

FossilOrigin-Name: 5f0e803e33aa557865d5fc830d9202d628de9a94c9757058ca48f1a560702cd3
2018-05-02 18:00:17 +00:00
drh
6d6e76f75f Add test cases from OSSFuzz to prevent a regression in co-routine
processing.

FossilOrigin-Name: 689743d8e3fa81e65dcb067bbf61bab09210b3b39586c865c00d9f1d6692daf2
2017-10-28 12:20:09 +00:00
drh
d8a295669c Correctly initialize the iSelectId of FROM clause terms that are a self
join of a reused materialized subquery.  Without this, the EXPLAIN QUERY PLAN
output for the query will identify the subquery using the uninitialized
(and arbitrary) iSelectId.

FossilOrigin-Name: 43c9ae371f6250fee98a7c4011726eff8ad37f5a97add4f490ac3a2dd501a0d2
2017-05-29 13:09:24 +00:00
dan
b1d6b53694 Add a missing memAboutToChange() macro to vdbe.c, the lack of which was causing an assert() to fail incorrectly. Problem found by libfuzzer.
FossilOrigin-Name: 1a24791109da607d502ac41f179fe6c1dc46c774
2015-12-14 19:42:19 +00:00
dan
fe88fbfc82 Add test cases for WITH clauses.
FossilOrigin-Name: e7e65c7559ed43e7065adc2ec1bd242bf187b7c3
2015-11-07 17:51:39 +00:00
drh
b63ce02f57 Do not allow recursive CTEs that use aggregate queries in the recursive part.
FossilOrigin-Name: 6d2999afbc25b9c238e4028f637c10eaaf0ec75e
2015-07-05 22:15:10 +00:00
drh
fccda8a162 CTEs have never add working rowids. So disallow the use of the "rowid" column
within CTEs.

FossilOrigin-Name: 0055df0445932a43e42b318ef88672dcbe312c3a
2015-05-27 13:06:55 +00:00
drh
f932f7145e Fix a problem with a stale Select.pWith pointer when a CTE is used together
with a compound query and an ORDER BY clause.

FossilOrigin-Name: 9a453f52a2b30595891604ede7d4acf61c2736a1
2015-04-12 17:35:27 +00:00
drh
8f9d0b2b25 Correctly detect the error of having a "*" wildcard on a SELECT without
a FROM clause on the left-hand side of a recursive CTE.

FossilOrigin-Name: b11d1793a06a44931edcbf12a615b49794d53a62
2015-03-21 03:18:22 +00:00
drh
d227a291b2 Use the WITH clause to help resolve names for SELECT statements on the left
of a compound query.  Proposed fix for ticket [31a19d11b97088296a].

FossilOrigin-Name: 67bfd59d9087a987f15f6148efa1ff104983e1fb
2014-02-09 18:02:09 +00:00
dan
53bed45ecb Select collation sequences for ORDER BY expressions attached to recursive CTEs in the same way as they are selected for other compound SELECT statements.
FossilOrigin-Name: 9554519c126c5e714421a82fd2e8aa9b19e11493
2014-01-24 20:37:18 +00:00
dan
05d3dc29c5 Add test cases for LIMIT and ORDER BY on recursive CTEs.
FossilOrigin-Name: 67d6c42d44cb191368ce20f553b32fcb14bfc4d7
2014-01-24 16:57:42 +00:00
drh
b090352b5a Add test cases showing the use of ORDER BY on a recursive query to control
depth-first versus breath-first search of a tree.

FossilOrigin-Name: 83b0b2916589db0184435dbd4c304387f393ed60
2014-01-24 11:16:01 +00:00
drh
aa9ce7078a Add support for LIMIT and OFFSET in a recursive query.
FossilOrigin-Name: 1945484e6b9769c1943f750f5b09860417fb190a
2014-01-22 18:07:04 +00:00
drh
fe1c6bb9c2 Get ORDER BY working for recursive queries.
FossilOrigin-Name: 37b343b01841b338954ddfa9b76d92aa50037aec
2014-01-22 17:28:35 +00:00
drh
717c09c4a9 Add a sudoku solver to the recursive query tests in with1.test.
FossilOrigin-Name: 679eff8759aa25368b977c0d26b78a9fcd9486f5
2014-01-18 18:33:44 +00:00
drh
75303a2c68 Add asserts() for a couple of unreachable conditions. Add the Mandelbrot Set
query as a test case.

FossilOrigin-Name: 2ad4583c0cc7988f0dfe78fd0a2eb0fdb92d835a
2014-01-18 15:22:53 +00:00
drh
c59731c4ae Minor simplification of error message text for a couple of errors associated
with WITH clause processing.

FossilOrigin-Name: 2031004d960526d6426d50d7b732f37b281534e2
2014-01-17 18:34:28 +00:00
drh
727a99f1e3 Tweaks to error message text.
FossilOrigin-Name: 090a77d97808b86d1e9f5c63c743a2b159a15f5d
2014-01-16 21:59:51 +00:00
dan
f2655fe8b6 Improve the error messages used to report illegal recursive cte references.
FossilOrigin-Name: 54eee9fe99290e59469bd3e1a66bb749887d37ee
2014-01-16 21:02:02 +00:00
dan
eede6a538d Fixes so that SQLITE_OMIT_CTE builds work.
FossilOrigin-Name: 3908e2ea2e7e5f466cbbbffdc27e0fe8dc9751ac
2014-01-15 19:42:23 +00:00
dan
62ba4e418d Disable automatic indices on recursive CTE references.
FossilOrigin-Name: 28aa6db8c878655255dbfb618f8d65be78e3d7e5
2014-01-15 18:21:41 +00:00
dan
f43fe6e9f6 When resolving names, consider a reference to a recursive CTE column as equivalent to a reference to the outermost name-context. This ensures that correlated sub-queries are correctly identified as such.
FossilOrigin-Name: 61be2da0ae623c1572819481508b044e9d32f294
2014-01-15 18:12:00 +00:00
dan
60e7068d75 Return an error if a CTE specifies a different number of columns than its SELECT statement returns.
FossilOrigin-Name: 9a514b50e4b01f109fbdb0aabcbfe1ddab129b44
2014-01-15 15:27:51 +00:00
dan
bfe31e7f80 Disable the flattening optimization if the sub-query is a recursive CTE.
FossilOrigin-Name: 9472f6d820a7fb233936d9b8f7a39c9d4c4d6d73
2014-01-15 14:17:31 +00:00
dan
8ce7184bc2 Add code to handle recursive CTEs.
FossilOrigin-Name: a5c2a54a07d35166911abc792008c05dea897742
2014-01-14 20:14:09 +00:00
dan
4e9119d9e8 Add code to handle non-recursive CTEs in the same way as SQL views.
FossilOrigin-Name: a26f399ba485e8127c276c5f103ec6c555e11734
2014-01-13 15:12:23 +00:00
dan
7d562dbe02 Update the parser so that sub-queries and CTEs may have WITH clauses.
FossilOrigin-Name: 704d3931b855562a619769955969d439c42ca406
2014-01-11 19:19:36 +00:00