1341 Commits

Author SHA1 Message Date
drh
146121f5cb Improved handling of OOM while reallocating a column name to add type
information.  dbsqlfuzz 5a195b4233649e49e0aa34f1b743ca192d85b198

FossilOrigin-Name: 5995dd4de4997c43b43befc1281ef6378f33f781134c7f368299d64db2344f1d
2021-11-12 14:39:49 +00:00
drh
a1c4c3c187 Remove an incorrect NEVER() reported at
[forum:/forumpost/5bbabfb7ce|forum post 5bbabfb7ce].  Also use this
opportunity to improve the isSimpleCount() function with better formatting,
an expanded header comment, and some extra assert() and textcase() macros.

FossilOrigin-Name: 2927185be81a5aa0dce70dd06040d05c2816a4d18b5094a6f709732cfd6968dc
2021-11-05 11:52:33 +00:00
drh
ffa5b054dd Fix an incorrect assert() in SQLITE_ENABLE_SORTER_REFERENCES logic - a new
assert() introduced 5 days ago by [87e2f5eb436fc448].

FossilOrigin-Name: 7cfc839e5f1f28514cba7d11b0c0eb56d5ea65caacb8893dcf9fcf2d409e2ba5
2021-10-12 18:05:55 +00:00
drh
0c1da68907 Detect any attempt to use an INDEXED BY clause on a CTE and report an
error.

FossilOrigin-Name: 35a9de2c97b9a386070e7827a0842bb1caf3af69ea0d6f67ce2a50be3426fb63
2021-10-09 16:00:56 +00:00
drh
dbfbb5a0c5 New assert() statements to protect the u1 and u2 unions of SrcList.
FossilOrigin-Name: 9b91fbcfcc14048f7d0755d47d9b7f9212fa2eaa6f3c04f417fa16c3a47943bf
2021-10-07 23:04:50 +00:00
drh
477572b9f1 Protect access to the Expr.y union using nearby assert()s and branches.
FossilOrigin-Name: 87e2f5eb436fc448427b0e24fb70f29688796b513b8c7b12f1a21540dae1e56d
2021-10-07 20:46:29 +00:00
drh
a4eeccdfdf Protect all accesses to the Expr.x union using nearby assert()s and branches.
FossilOrigin-Name: 8eaa1d4a98b24adf245bbd2fe9212aa6a924a0f09c445906d7f87574f36a7423
2021-10-07 17:43:30 +00:00
drh
f975107437 Protect all accesses to the FuncDef.u and Expr.u unions using nearby
assert()s or branches.

FossilOrigin-Name: 9af863f065e0bef491c2ab7525194505f9516f4e6dfc789d2e3a9d2c2438533a
2021-10-07 13:40:29 +00:00
drh
7d4c94bc0f Fix harmless static-analyzer warnings.
FossilOrigin-Name: 32f33f356931242b59c01b5df7e180941231e3d9c91577ad33aa4a01e9d59092
2021-10-04 22:34:38 +00:00
drh
aa6fe5bf10 Fix harmless static analyzer warnings.
FossilOrigin-Name: 6604a085964121113e7b7f57537a0ba64ba058d0eb12bf0a3aeb6d1b7a29d516
2021-10-04 13:18:44 +00:00
drh
e85e1da07b Fix harmless compiler warnings.
FossilOrigin-Name: 94b59691ee50a4666b25e36d1529fc52f714bbe94c3e8ccb35bf0a4ea11050db
2021-10-01 21:01:07 +00:00
dan
afaa660aef Fix a problem with view handling in SQLITE_OMIT_VIRTUAL_TABLE builds.
FossilOrigin-Name: 6e791a24ce259ff6cc46a7c2188aea094a5021e154368f57019a0653c8a81217
2021-09-30 18:42:52 +00:00
drh
82456a661d Add assert() statements to refute
[forum:/forumpost/9f4e7f58fbb66ddd|forum post 9f4e7f58fbb66ddd].

FossilOrigin-Name: 83a83475c5064ea62016a03e9173ecd2a1fec7f6296f1ee99896fa0a38b4196a
2021-09-13 18:16:15 +00:00
drh
5ced0a914e Correctly preserve the collating sequence for a column when changing
its datatype.  Fix for the problem reported by
[forum:/forumpost/e5c76b738e|forum post e5c76b738e].  Test cases
in TH3.

FossilOrigin-Name: c7f0813cabf9d8ab367bead5ba8cf20132b8bb9274d8e47b76ad66a10517dd2a
2021-08-24 17:07:44 +00:00
drh
ce68b6bfeb Defer deleting subqueries in the compound-SELECT code generator until the
end of code generation, in order to avoid deleting expressions out from under
the aggregation function sanity checking assert()s that occur near the
end of SELECT code generation.  This fixes the assertion fault described by
[forum:/forumpost/cfcb4b461d|forum post cfcb4b461d].

FossilOrigin-Name: 600f1991e5c0a5d89cd8776a157b6fd72c7489791085876925e8dd7ab146fe1f
2021-08-21 16:42:58 +00:00
drh
df67ec08ff Do not apply the push-down optimization to CTE subqueries that will be
reused in other contexts in where the same optimization is unlikely to
be valid.  Fix for the bug reported by
[forum:/forumpost/d496c3d29bc93736|forum post d496c3d29bc93736].

FossilOrigin-Name: a7ce29a6ef2e0362bbc9b23719d936dce07209b2651153c774682f599bbd888e
2021-08-11 13:48:56 +00:00
drh
834c688171 Improved comment on the OP_OpenDup used to get a new cursor for a
reused materialized CTE.

FossilOrigin-Name: b1926cc0ab2b81c7df30c4baa6014efcfddb9631f6e46a55c1cec0113ee1afdc
2021-08-11 13:19:13 +00:00
drh
65b400931d Store the collating sequence name for each column of a table as an
extension to the column name, for an additional savings in the heap space
needed to hold the schema.

FossilOrigin-Name: 832ac4c1ee384be0de72a4bdd55ed87e0f8294e7df5eefcf6b4942db3d85a69e
2021-08-05 15:27:19 +00:00
drh
cf9d36d1b3 Refactor field names in the Column object, zCnName and zCnColl, to make them
unique and thus easier to find amid all the other code.

FossilOrigin-Name: 8b781dcaf68e0cf12a844708c82eee00193e340195cbca915d077e4846983bf3
2021-08-02 18:03:43 +00:00
drh
f38524d20d Refactor the Table object to reduce its memory footprint.
FossilOrigin-Name: bbb6759bcf6e01d36dfc787a82a610d359f50aaeac8104b73883a84906d54e1f
2021-08-02 16:41:57 +00:00
drh
c6da6dba69 Fix a harmless uninitialized variable read that occurs after an error
associated with a subquery that uses DISTINCT.  Found by a fuzzer.

FossilOrigin-Name: e9719f975f61c4c9f40ea077b049eed97d0957b925a4b6149d9ee21ce827b6a1
2021-07-28 02:04:58 +00:00
drh
c8d214711f Improved robustness of cursor renumbering in the UNION ALL flattener
when operating on vector assignments of an UPDATE FROM.
dbsqlfuzz 417d2b053b9b3c9edaf22dd515564f06999e029c

FossilOrigin-Name: 60695359dc5d3bcba68a68e1842c40f4a01650eb5af408e02fb856fd8245e16d
2021-07-21 15:42:05 +00:00
dan
d59f983501 Avoid a malfunction that could occur if the same correlated column reference appears in both the GROUP BY and the HAVING clause of a sub-select. dbsqlfuzz a779227f721a834df95f4f42d0c31550a1f8b8a2.
FossilOrigin-Name: 1e35cc6d5c2f563c6bb163bb150d7bc6ede4c993efa828af1face3261bf65a2c
2021-07-20 14:57:49 +00:00
drh
0fb78f0cca Get the "omit ORDER BY in FROM-clause subqueries" optimization working for the
core test cases.

FossilOrigin-Name: e31c5888659ffd4c6d8b68627123df3bbb84bb010b7766b0a74877bf3ba1e52b
2021-07-16 01:19:19 +00:00
drh
bb30123178 Attempt to omit ORDER BY clauses from FROM-clause subqueries if those ORDER BY
clauses do not affect the output.  See
[forum:/forumpost/2d76f2bcf65d256a|forum thread 2d76f2bcf65d256a] for
discussion.  This can help the query flattener in
some cases, resulting in faster query plans.  The current implemention does
not always work.

FossilOrigin-Name: ef97c3e7c3ea2cf1a4db6591328fe7ce3f1d189afc2d578159135824ec89e620
2021-07-15 19:29:43 +00:00
dan
5daf69e5f4 Allow sub-queries in the FROM clause of an UPDATE...FROM statement to access the object being updated without using an alias, as is required in the parent query.
FossilOrigin-Name: 740cb43025449b7d7b47a97ad00885e54b7701cbcb14f4a50c7523022e3936d5
2021-07-05 11:27:13 +00:00
dan
ac67f56726 Fix an ALTER TABLE problem with handling infinite loops of CTEs in the database schema.
FossilOrigin-Name: c09d90eec2a49b948c60971294d146db5c82438855cd3fa48ddc3d2e6b44c26c
2021-06-14 20:08:48 +00:00
drh
24ce9446a8 This is an alternative approach to the use-after-free problem fixed
by [193b14a58e378ab3], saved here for historical reference.

FossilOrigin-Name: 6796b7a2485eca279db9d777595a886bc0d1dd7ec9551e1797e0032ef5493559
2021-06-12 17:45:32 +00:00
drh
75016050f3 Improved robustness following OOM in the constant propagation optimization.
dbsqlfuzz 001a20255c0df7495c21df62a20ea5b51e22c390.

FossilOrigin-Name: 8658a64d414db6900b55281f5e67180ea74b82627199b927634a727ed28030c2
2021-06-10 14:36:23 +00:00
drh
9025af1603 Add an assert() to prevent the value of the SQLITE_VTABRISK macros from being
changed in a way that would break logic.

FossilOrigin-Name: 33babdb582ca712cc089165a953972096b57d1cb683954fa830df5e7befaadba
2021-06-08 12:22:24 +00:00
drh
342cb33b23 Improved comment on the prpagateConstants() routine. No changes to executable
code.

FossilOrigin-Name: d61a875df48d8baab3ada0174c8e0312a9268bbd11bf104b4385eff9e2744266
2021-05-27 14:09:01 +00:00
drh
7d11e647ad Improvements to the constant-propagation optimization in order to better
deal with unusual affinities.  See
[forum:/forumpost/6a06202608|forum post 6a06202608] for more detail.

FossilOrigin-Name: 9be208a6d70582c6808abe6e016ab9cd8d10f0deefb8c7a8c0543372cca15b12
2021-05-26 23:10:19 +00:00
drh
a8ed515400 Minor optimization to opcode comparison logic in the fixes to
the constant-propagation optimization on this branch.

FossilOrigin-Name: f17dec40a0ccc044bd32e035fc10797552329af242408a45f36125ed8d2ef088
2021-05-26 19:52:21 +00:00
dan
40b82f9dc6 Avoid assuming that an expression like "x=10" in a WHERE clause implies that CASE(x AS TEXT)=='10'.
FossilOrigin-Name: 389ec669f416c74d651e25572f6e007c2a62ddd4027524f553107b06db5c55eb
2021-05-26 18:51:57 +00:00
drh
14c4d42874 Take care that the code is not generated for the same Select object more
than once, as transformations that apply during the first pass might
cause problems for the second pass.
dbsqlfuzz 836b625cd8a41809ef80fc7ebaa6554357bcb463.

FossilOrigin-Name: f30fb19ff763a7cbe768ea49954704e14d6400f69bb4257c9c890e1564e14835
2021-05-26 18:46:51 +00:00
drh
7cc73b399e Do not push a WITH clause onto the processing stack if prior errors have
occurred.  dbsqlfuzz 6b7a144674e215f06ddfeb9042c873d9ee956ac0.

FossilOrigin-Name: c2066dde53b9872dbb991e27419dd031791c942fe23826556f52efbd66c51662
2021-05-23 17:47:04 +00:00
drh
93c8139c1a If there are errors in a nested CTE, be sure to abandon processing. Do not
continue since the parse tree may have been left in a goofy state which could
cause use-after-free and segfaults.
See [forum:/forumpost/aa4a7a3980|forum post aa4a7a3980] for an example.

FossilOrigin-Name: 94225d693932eb0b5d7799d40513afbd31ed40e1e156675eb92ad7216f1ff20f
2021-05-21 21:49:07 +00:00
dan
90bc36fb30 Ensure that objects within view definitions are not incorrectly resolved to CTEs that are part of the statement using the view.
FossilOrigin-Name: f7dcc4b5197c6413be31384b390bb98a737d3f9edb7964433448c3b90b35a436
2021-05-20 17:15:06 +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
9088186bfb Improved column name and column type determination for the RETURNING clause.
FossilOrigin-Name: 699c33990a9438f28673ecf34f1e521d1af0b01c6ee30a608c0c91d2d593590e
2021-05-19 12:17:03 +00:00
drh
93ffb50fcd In the MULTI-INDEX OR query plan, code for sub-expressions can sometimes be
generated twice.  But for some subqueries, generating code off of the same
tree twice causes problems.  So now MULTI-INDEX OR makes a copy of the
sub-expressions it uses to avoid code-generating them more than once.
dbsqlfuzz 9ebd2140e7206ff724e665f172faea28af801635.

FossilOrigin-Name: 4a55f72542c8bcc80253aa77043314cecb29d73cb4f51aa80f7811e86cc8ef68
2021-05-18 19:10:10 +00:00
dan
be12083bc7 Fix problems with refering to CTEs from within sub-selects in PARTITION BY or ORDER BY clauses of window frame definitions. Also a problem with renaming a column when the schema contains a trigger containing a correlated sub-select within a window frames PARTITION BY or ORDER BY clause.
FossilOrigin-Name: 4c6cd54a8db78e5535912e76856bed4f797261aaca4248c69d2e2452194de297
2021-05-17 16:20:41 +00:00
drh
b775c97682 Attempt the [/info/f4229707ac08d66c|constant propagation optimization] on any
WHERE clause that has a top-level AND operator, even if the query is not
a join.  This is an attempt to partially address the concern raised in
[forum:/forumpost/830d37b928|forum post 830d37b928].

FossilOrigin-Name: e994c9f29f7a561dd5f30573865b0f793fb1388af09a2afb9b1a5b037ea52f89
2021-05-14 14:26:57 +00:00
drh
c7f5077e88 Fix the [/info/df1d6482f9e92daf|UNION ALL flattener optimization] so that it
works better with recursive CTEs.
dbsqlfuzz 88ed5c66789fced139d148aed823cba7c0926dd7

FossilOrigin-Name: f80d7bb2c305c1dd4658767660b33259032c048a91f18c654a6bda7332c54a0c
2021-04-26 21:23:01 +00:00
drh
9da977f1a5 In the sqlite3SelectDup() routine, do not do an incomplete duplication due
to OOM.  This in turn requires several new NEVER() and ALWAYS() macros for
unreachable branches.

FossilOrigin-Name: a61c0e6b78bd39f55464fafd257e68effded64995a66e8fa2d686e8c507ebe43
2021-04-20 12:14:12 +00:00
drh
8c6cb1bc6f Improvement to check-in [d564d8882ef18b55] to detect the OOM fault even
if it occurs deep down inside the duplicated expression.

FossilOrigin-Name: 3e863cd09355abd80c1053d6d4dabb55841f806e3c418f923d67d36bf8313cb0
2021-04-19 20:36:13 +00:00
drh
60b95335e2 In the query flattener, avoid invalidating an expression if an OOM occurs.
This prevents problems in higher-level routines that might not check for
the OOM after processing a subquery.
dbsqlfuzz fb70fa8602421f87673e0670b0712ff2b5240ea0

FossilOrigin-Name: d564d8882ef18b55ebf93e838426b485281c7ebe3a9b321a2f984ed0f229cc25
2021-04-19 15:05:27 +00:00
dan
44918c74cd Fix cases where code in expr.c was failing to handle OOM failures that occurred while processing sub-select expressions.
FossilOrigin-Name: 62efe2eee34fdb147cc456290576d8fc3801487867c78aadd4485f85468d9ffc
2021-04-17 14:42:37 +00:00
dan
cd0b245934 Avoid an assert() failure when a compound scalar sub-select is, due to a "WHERE (sub-select) AND (... OR ...)" clause, coded twice by the code generator.
FossilOrigin-Name: a4e3f13329332f91a250bc18459fd4100990a1ac0516f8a0a6b21ff117db9795
2021-04-12 12:02:49 +00:00
dan
bfd6f1bcd5 Fix a use-after-free error that could occur when processing "SELECT aggregate(DISTINCT <expr>)..." queries.
FossilOrigin-Name: 0e4789860b81c31d3a6d1f9f8340042ce1d08a82bf6119c783fcab85180b1b63
2021-04-08 20:29:12 +00:00