]> git.ipfire.org Git - thirdparty/sqlite.git/log
thirdparty/sqlite.git
4 years agoAdd an ALWAYS() on a branch that is now unreachable. as-materialize-redux
drh [Mon, 22 Feb 2021 14:25:40 +0000 (14:25 +0000)] 
Add an ALWAYS() on a branch that is now unreachable.

FossilOrigin-Name: ace54c5bd50176db7c60b7e3cf9293a86d9ecf2fea897467044020b9684c0af3

4 years agoFix inverted logic regarding the materialization hint on the push-down
drh [Mon, 22 Feb 2021 11:07:25 +0000 (11:07 +0000)] 
Fix inverted logic regarding the materialization hint on the push-down
optimization.

FossilOrigin-Name: b66a49570852cf118a372a6ac44be3070cf9b4254696f16315b7c79a614e6c35

4 years agoAdd the AS MATERIALIZED and AS NOT MATERIALIZED syntax that works like it
drh [Mon, 22 Feb 2021 03:04:25 +0000 (03:04 +0000)] 
Add the AS MATERIALIZED and AS NOT MATERIALIZED syntax that works like it
does in PostgreSQL.

FossilOrigin-Name: a6bb272ec0c758ab069bfc07443624e0ea7910b1f23224ee078d050fa3ccf068

4 years agoMaterialize any CTE that is used more than once.
drh [Sun, 21 Feb 2021 23:44:14 +0000 (23:44 +0000)] 
Materialize any CTE that is used more than once.

FossilOrigin-Name: ba59159fbe6b83fb6d79fbfee22d983768b0ebbaac7e99d2ac66c810e5e04100

4 years agoRename the "struct SrcList_item" object to the more succinct "SrcItem".
drh [Sun, 21 Feb 2021 21:04:54 +0000 (21:04 +0000)] 
Rename the "struct SrcList_item" object to the more succinct "SrcItem".
This is a symbolic change only.  The logic is unmodified.

FossilOrigin-Name: bfd5bf2c73110fcb36db9ba2a949ff516131fbd3e89325f88fe9f5c2b4ed87b2

4 years agoSimplified resolution of CTE names. Slightly faster and about 100 bytes
drh [Sun, 21 Feb 2021 01:19:42 +0000 (01:19 +0000)] 
Simplified resolution of CTE names.  Slightly faster and about 100 bytes
of code smaller.

FossilOrigin-Name: 0d2c992f3622a6272ca4a3caff6b21f619fe976b8df8b34eff066086f8df2202

4 years agoPerformance improvement in resolving the INDEXED BY index name for the common
drh [Sat, 20 Feb 2021 21:20:54 +0000 (21:20 +0000)] 
Performance improvement in resolving the INDEXED BY index name for the common
case where there is no INDEXED BY clause.

FossilOrigin-Name: 554b286ac208168bde91c6c6034cc7087410def76fce650b519661b2ee2c61b7

4 years agoFix a case where FTS3/4 could pass a NULL pointer to memcpy() when handling a corrupt db.
dan [Sat, 20 Feb 2021 19:22:32 +0000 (19:22 +0000)] 
Fix a case where FTS3/4 could pass a NULL pointer to memcpy() when handling a corrupt db.

FossilOrigin-Name: 68bb541a39833d7d4bf41aa91cb6cd9c98757d1fc8236299d09db7e9b14d8ec9

4 years agoUpdate sqlite3changeset_apply_v2() so that it handles no-op UPDATE changes (UPDATE...
dan [Sat, 20 Feb 2021 18:02:37 +0000 (18:02 +0000)] 
Update sqlite3changeset_apply_v2() so that it handles no-op UPDATE changes (UPDATE changes that modify no columns). This fixes a regression introduced by [e4ccfac09b]. Also modify sqlite3rebaser_rebase() so that it does not output changesets containing such UPDATEs.

FossilOrigin-Name: 0288a8013e00594e716a5fb0d9f684dcfeb03e877650630e2736565fa6261290

4 years agoBreak out the Cte object from the With object. This will make it simpler
drh [Sat, 20 Feb 2021 14:57:16 +0000 (14:57 +0000)] 
Break out the Cte object from the With object.  This will make it simpler
to add new kinds of Cte objects (ex: DML statements) and/or MATERIALIZED
keywords in the future.  It brings trunk into closer alignment with the
experimental as-materialize branch.

FossilOrigin-Name: f03efe905d7b40fb25f9f78b874bb56c6d6ccacb60f86b3b199d430d5eade8d2

4 years agoSimplification to where.c manually cherrypicked from the as-materialize
drh [Sat, 20 Feb 2021 13:36:14 +0000 (13:36 +0000)] 
Simplification to where.c manually cherrypicked from the as-materialize
branch.

FossilOrigin-Name: 03805a6117c813a33f9bca68bf4d9912997d6abd88ac9b3cb844c5d93ec68049

4 years agoFix another problem handling corrupt database files in the ALTER TABLE DROP COLUMN...
dan [Fri, 19 Feb 2021 18:39:32 +0000 (18:39 +0000)] 
Fix another problem handling corrupt database files in the ALTER TABLE DROP COLUMN code.

FossilOrigin-Name: 9edf2ddc4799c8830c4b7b91d7aacee50029a4b9db329fd4c5674fbedea33034

4 years agoAdd tests for ALTER TABLE DROP COLUMN commands.
dan [Fri, 19 Feb 2021 15:34:16 +0000 (15:34 +0000)] 
Add tests for ALTER TABLE DROP COLUMN commands.

FossilOrigin-Name: 05dbea9b26bdcb096194dc531816333f3784eca50b133fe3efede6ab0d233472

4 years agoAdd support for "ALTER TABLE ... DROP COLUMN ..." commands.
dan [Fri, 19 Feb 2021 14:32:58 +0000 (14:32 +0000)] 
Add support for "ALTER TABLE ... DROP COLUMN ..." commands.

FossilOrigin-Name: c844a331e78949850fde8ed95058cb34f863566944bc9e92e3ae042768f130e1

4 years agoFix a crash that could occur in ALTER TABLE DROP COLUMN if the sqlite_schema table... alter-table-drop-column
dan [Fri, 19 Feb 2021 14:13:40 +0000 (14:13 +0000)] 
Fix a crash that could occur in ALTER TABLE DROP COLUMN if the sqlite_schema table was corrupt.

FossilOrigin-Name: 126ee1ec4f3565c0cccca98885fa3665a641ea3df251511de16eed2a1c396124

4 years agoOmit an branch made unreachable by the improved error message from dropping
drh [Fri, 19 Feb 2021 09:46:52 +0000 (09:46 +0000)] 
Omit an branch made unreachable by the improved error message from dropping
the last column of a table.

FossilOrigin-Name: c5719fc5aa04c50bb01533f1cedb73dc80c4bf5315ff6a7206c8a10504afca8b

4 years agoThe COLUMN keyword in ALTER TABLE DROP COLUMN is optional.
drh [Fri, 19 Feb 2021 09:36:50 +0000 (09:36 +0000)] 
The COLUMN keyword in ALTER TABLE DROP COLUMN is optional.

FossilOrigin-Name: a22f87fb6c43dd6217691c8dd1cdcd7880068024fb779ca8a5def068d72c3e6b

4 years agoGive a better error message on DROP COLUMN when attempting to drop
drh [Fri, 19 Feb 2021 09:09:07 +0000 (09:09 +0000)] 
Give a better error message on DROP COLUMN when attempting to drop
the last column of a table.

FossilOrigin-Name: 5e1f362bc3e53c60f9e6f771346d10c6e6a6cb3ff1eec5608101f9c5d6d2a5a4

4 years agoAdd a NEVER() to an unreachable branch in the DROP COLUMN logic.
drh [Fri, 19 Feb 2021 02:30:02 +0000 (02:30 +0000)] 
Add a NEVER() to an unreachable branch in the DROP COLUMN logic.

FossilOrigin-Name: 963f498ae64cf7530fb7a405fa476c411ad66523f62f5eefa5a16596cd19a481

4 years agoAdd missing VdbeCoverage() macros.
drh [Thu, 18 Feb 2021 23:53:47 +0000 (23:53 +0000)] 
Add missing VdbeCoverage() macros.

FossilOrigin-Name: 9bb720e6590482bc9c2fbb273738808209e9651710dbee7572b0348cadf87e68

4 years agoEnhance renameParseSql() to better handle OOMs.
drh [Thu, 18 Feb 2021 23:03:50 +0000 (23:03 +0000)] 
Enhance renameParseSql() to better handle OOMs.

FossilOrigin-Name: 68bcde7ab57b2d4bdcfb2f6c7134a0b01a504b2e7cdf6ee5bf0df70fb4a517b0

4 years agoMerge changes from trunk into the alter-table-drop-column branch.
drh [Thu, 18 Feb 2021 22:47:34 +0000 (22:47 +0000)] 
Merge changes from trunk into the alter-table-drop-column branch.

FossilOrigin-Name: 9ea640073f8809dfe2612ae1ea384a938b433f884c54d9e5aa3712de79397ac1

4 years agoFix DROP COLUMN so that it works even if the user has registered an authorizer callback.
dan [Thu, 18 Feb 2021 20:27:46 +0000 (20:27 +0000)] 
Fix DROP COLUMN so that it works even if the user has registered an authorizer callback.

FossilOrigin-Name: e5f144182bbb3ba10c77151cf63c8bddf86374049fb6866387f85e335df298cb

4 years agoFix a problem with schema error detection when processing ALTER TABLE DROP COLUMN...
dan [Thu, 18 Feb 2021 19:25:44 +0000 (19:25 +0000)] 
Fix a problem with schema error detection when processing ALTER TABLE DROP COLUMN commands.

FossilOrigin-Name: 565a6fd0c95b438fea7bf84913b38de1718117e16e0d685534a8650e1dc8421b

4 years agoAdd test cases for ALTER TABLE DROP COLUMN.
dan [Thu, 18 Feb 2021 17:48:36 +0000 (17:48 +0000)] 
Add test cases for ALTER TABLE DROP COLUMN.

FossilOrigin-Name: 204ee5e28210738fb624a9cf85dc6f9b59de0d7eb4fddd46c8babe9beddd4944

4 years agoAvoid invoking the update or pre-update hooks during VACUUM operations.
dan [Thu, 18 Feb 2021 15:59:37 +0000 (15:59 +0000)] 
Avoid invoking the update or pre-update hooks during VACUUM operations.

FossilOrigin-Name: 3c25cb4ab8885a50e2a485fe76f5ffd5dd8ebe1306aca8c0989e0b7fd7dd18d2

4 years agoImprovement to the INSERT optimization of check-in [16ac213c57196361] so
drh [Thu, 18 Feb 2021 15:45:34 +0000 (15:45 +0000)] 
Improvement to the INSERT optimization of check-in [16ac213c57196361] so
that it works with SQLITE_ENABLE_HIDDEN_COLUMN but is also easier to maintain
and a little faster as well.

FossilOrigin-Name: f985a78ecc0c6d9ff671c730a109d97dc781b06e47a0ab03f441cea5d021a4c3

4 years agoDisable the optimization of [16ac213c57196361] when the
drh [Thu, 18 Feb 2021 14:27:43 +0000 (14:27 +0000)] 
Disable the optimization of [16ac213c57196361] when the
SQLITE_ENABLE_HIDDEN_COLUMN compile-time option is used, as the optimization
does not work in that case.

FossilOrigin-Name: 5168b06bcf283ef64cb9fd76330a743baf8bb0cd747c14eae23e607e0491cbce

4 years agoEnsure that the pre-update hook is invoked for INSERT operations on WITHOUT ROWID...
dan [Thu, 18 Feb 2021 12:18:10 +0000 (12:18 +0000)] 
Ensure that the pre-update hook is invoked for INSERT operations on WITHOUT ROWID tables that use the xfer optimization.

FossilOrigin-Name: 66bbad239b4527ac8ae8b487a0c71d88b1861a8dfe1edc25109600dc447c60c4

4 years agoAdd missing VdbeCoverage() macros to some of the new RETURNING code.
drh [Thu, 18 Feb 2021 01:02:03 +0000 (01:02 +0000)] 
Add missing VdbeCoverage() macros to some of the new RETURNING code.

FossilOrigin-Name: 53a5390909822b3aef8c5f522144bc2e86cc31318b2d3e310a064ae7202b4a15

4 years agoPerformance optimization in the resolver.
drh [Thu, 18 Feb 2021 00:59:16 +0000 (00:59 +0000)] 
Performance optimization in the resolver.

FossilOrigin-Name: 1aafb94d4e3f28a8322e5e43be737d84b1a09f0063408f4a466a6071fa95b39b

4 years agoPerformance optimization in the code generator for INSERT for the common
drh [Thu, 18 Feb 2021 00:26:11 +0000 (00:26 +0000)] 
Performance optimization in the code generator for INSERT for the common
case where the target table has neither generated nor hidden columns.
Also fix a redundant (and thus unreachable) branch in the resolver.

FossilOrigin-Name: 16ac213c57196361a9d14df4c0d1ccc6f67ac522365b345ea364d1aec61fa3f2

4 years agoUse the sqlite3ParserAddCleanup() mechanism to ensure that the AggInfo
drh [Wed, 17 Feb 2021 21:13:14 +0000 (21:13 +0000)] 
Use the sqlite3ParserAddCleanup() mechanism to ensure that the AggInfo
structure associated with an aggregate query is deallocated, for a performance
increase and size reduction.

FossilOrigin-Name: 7a1399671fa10c64d5358cc4d364d24c643fe9dd8da923356462267ee7962f61

4 years agoFix a problem with OOM error handling in the new code on this branch.
dan [Wed, 17 Feb 2021 20:46:44 +0000 (20:46 +0000)] 
Fix a problem with OOM error handling in the new code on this branch.

FossilOrigin-Name: ea999c9db59e4193b306a2e1b15fc94f8f04cb05e852bb0d068b7d5243a0849b

4 years agoMerge trunk changes into this branch.
dan [Wed, 17 Feb 2021 20:19:13 +0000 (20:19 +0000)] 
Merge trunk changes into this branch.

FossilOrigin-Name: 0cd5e2f9ce181f2c940ffca6fe69fda84f452613e66463d0d7c7413fc11b9772

4 years agoFix various issues with the changes on this branch. Add test cases for the same.
dan [Wed, 17 Feb 2021 20:08:22 +0000 (20:08 +0000)] 
Fix various issues with the changes on this branch. Add test cases for the same.

FossilOrigin-Name: 10538ec6fc1642dfc2ca6cef06ce6cb9e124847b421ccf01f5842064fad379ab

4 years agoEnhance the ".once" and ".output" commands in the CLI so that if the
drh [Wed, 17 Feb 2021 13:19:22 +0000 (13:19 +0000)] 
Enhance the ".once" and ".output" commands in the CLI so that if the
filename argument begins with "|" the name becomes the concatenation
of all subsequent arguments.  Hence, commands like ".once | open -f" become
possible without the need for quotes.

FossilOrigin-Name: c46a94a624c2cc6c49ac916a206a913081e1628c24805987cabc75c9057ea36b

4 years agoAdd experimental implementation of ALTER TABLE DROP COLUMN. Only some cases work...
dan [Tue, 16 Feb 2021 20:43:36 +0000 (20:43 +0000)] 
Add experimental implementation of ALTER TABLE DROP COLUMN. Only some cases work so far.

FossilOrigin-Name: f0217937d7306fb595727e61e871e8b03d8c881d339a0865bfd0117d90d42e4e

4 years agoSimplification to the resolveAlias() routine.
drh [Tue, 16 Feb 2021 20:32:17 +0000 (20:32 +0000)] 
Simplification to the resolveAlias() routine.

FossilOrigin-Name: 00bead3931135af80475c22f08cbb26c914518e8f2c7e73c2b8be1cee4ac4d5e

4 years agoNew SELECTTRACE macros more clearly deliniate when the query planner is
drh [Tue, 16 Feb 2021 20:01:08 +0000 (20:01 +0000)] 
New SELECTTRACE macros more clearly deliniate when the query planner is
invoked in the middle of PRAGMA vdbe_addoptrace output.

FossilOrigin-Name: 7c03ce49b74f72b63dd75c3a02625e671bfd771f71b24e808994322b00d97677

4 years agoFix an issue with the LIKE operator when it includes the "ESCAPE '_'" clause.
drh [Mon, 15 Feb 2021 17:02:01 +0000 (17:02 +0000)] 
Fix an issue with the LIKE operator when it includes the "ESCAPE '_'" clause.
Ticket [c0aeea67d58ae0fd].

FossilOrigin-Name: 27d4117980d125975b5e70eeea58a6ab07bcf066e71b5fcb81b822e05afdbab0

4 years agoAdd tests for sqlite3_column_count().
dan [Mon, 15 Feb 2021 14:32:05 +0000 (14:32 +0000)] 
Add tests for sqlite3_column_count().

FossilOrigin-Name: 7cc65ae57183b3c16f1102fca5603a36acda432e5d45e22a2996e5ebe069fc6a

4 years agoEnsure that the ALTER TABLE statements return 0 for
drh [Mon, 15 Feb 2021 13:17:19 +0000 (13:17 +0000)] 
Ensure that the ALTER TABLE statements return 0 for
sqlite3_column_count().

FossilOrigin-Name: 29c1932a47cd46c2585ebbf937c03544a8a355014776129662789e15db9ed4de

4 years agoFix an error in the test case fix in [ecd71203].
dan [Mon, 15 Feb 2021 11:14:53 +0000 (11:14 +0000)] 
Fix an error in the test case fix in [ecd71203].

FossilOrigin-Name: 5411bfa41ea9a492ca1f567327d8e0a1b3db047292fec1753bfef8a157cf8c1d

4 years agoFix incorrect test name labels in the select1.test script.
drh [Sat, 13 Feb 2021 18:14:15 +0000 (18:14 +0000)] 
Fix incorrect test name labels in the select1.test script.

FossilOrigin-Name: 179c79ea0deb0f5adaa8d369cfcad06d959a9cc18a8a41e01ef013b2d90acd61

4 years agoAvoid manifesting a CTE (or other view) multiple times when it is possible to
drh [Sat, 13 Feb 2021 16:39:24 +0000 (16:39 +0000)] 
Avoid manifesting a CTE (or other view) multiple times when it is possible to
reuse the first manifestation.

FossilOrigin-Name: 9692f510803c9b9725abb687d7c10fbc0d5ed784479ec6f3fcc55925a87fe16d

4 years agoFix a problem in the unreleased union-all flattening code.
dan [Sat, 13 Feb 2021 14:26:25 +0000 (14:26 +0000)] 
Fix a problem in the unreleased union-all flattening code.

FossilOrigin-Name: e4f8a79fd8b3be9bf8add5f5e1c66bc2fe78da4e50ea500ab0b8370d30e31ba5

4 years agoFix a test case to account for the fact that different versions of OpenBSD behave...
dan [Fri, 12 Feb 2021 21:22:01 +0000 (21:22 +0000)] 
Fix a test case to account for the fact that different versions of OpenBSD behave differently when a program tries to read() from a file-descriptor open on a directory.

FossilOrigin-Name: ecd712032f56a20d7df2bcf89b0d3b8d91dc72c552e27f0a4b23980bd49747b0

4 years agoEnsure RBU tests are run as part of release testing.
dan [Fri, 12 Feb 2021 11:37:13 +0000 (11:37 +0000)] 
Ensure RBU tests are run as part of release testing.

FossilOrigin-Name: a18dc08bafefd849e640086b18c41e06361d2e09d7dd2e9af4a394dc543e598b

4 years agoFix a longstanding problem causing an RBU vacuum to omit releasing some locks before...
dan [Wed, 10 Feb 2021 20:00:40 +0000 (20:00 +0000)] 
Fix a longstanding problem causing an RBU vacuum to omit releasing some locks before finishing.

FossilOrigin-Name: 66c07a07b21e46529780eec3c82a84c494d586f8b7ed80b78d358e23b80458c7

4 years agoRemove an assert() added by the previous commit that is sometimes false. shm-lock-fix
dan [Wed, 10 Feb 2021 19:49:35 +0000 (19:49 +0000)] 
Remove an assert() added by the previous commit that is sometimes false.

FossilOrigin-Name: fb36ac4dc60ccc6c5fba3f23e13fcab985f27ebef0527c929806cda5f9d3660c

4 years agoFix a longstanding problem causing an RBU vacuum to omit releasing some locks before...
dan [Wed, 10 Feb 2021 19:40:47 +0000 (19:40 +0000)] 
Fix a longstanding problem causing an RBU vacuum to omit releasing some locks before finishing.

FossilOrigin-Name: cb5bdf82fe0f90922dc34202be9d0aa34d899afff4200456623765da2877ca41

4 years agoIn RBU, avoid passing VFS xShmLock calls through to the underlying VFS in cases where...
dan [Wed, 10 Feb 2021 17:31:50 +0000 (17:31 +0000)] 
In RBU, avoid passing VFS xShmLock calls through to the underlying VFS in cases where xShmMap calls may not be. This fixes a bad interaction with ZipVFS.

FossilOrigin-Name: bd1e9e0a4c0e07901ef59fe3b7e6f7b9cc66ccfcd5192f576e1620820891de99

4 years agoCorrectly detect correlated subqueries when resolving names in RETURNING
drh [Mon, 8 Feb 2021 15:56:01 +0000 (15:56 +0000)] 
Correctly detect correlated subqueries when resolving names in RETURNING
clauses.

FossilOrigin-Name: b43cfa04922a401442b9d1708e3e4a88d3cfa2c591f9a6b253d99ba83f4b280a

4 years agoImproved name resolution for references to a table begin modified from
drh [Mon, 8 Feb 2021 13:41:17 +0000 (13:41 +0000)] 
Improved name resolution for references to a table begin modified from
within a subquery in the RETURNING clause.

FossilOrigin-Name: 799d205bfa7945ee4a92dfec5fbf90a00b9a535e3171aab2ec46404f7efb0f78

4 years agoDo not allow RETURNING in the DML statements of a trigger.
drh [Sun, 7 Feb 2021 23:28:20 +0000 (23:28 +0000)] 
Do not allow RETURNING in the DML statements of a trigger.

FossilOrigin-Name: 7a8fe6463a9728bc4e34465688a059afb74f3c373cde8fdf570d5d148fdde04d

4 years agoFix harmless compiler warnings.
drh [Sun, 7 Feb 2021 12:59:43 +0000 (12:59 +0000)] 
Fix harmless compiler warnings.

FossilOrigin-Name: 5f8bf99579e6663fc701cdc94f685584a86398c4687e25e7e241de755398f17d

4 years agoRemove an ALWAYS() and NEVER() in the authorizer that become reachable
drh [Sat, 6 Feb 2021 14:56:30 +0000 (14:56 +0000)] 
Remove an ALWAYS() and NEVER() in the authorizer that become reachable
as of [078dbff04a95a001].  Test case for coverage in TH3.

FossilOrigin-Name: b469327e2949352325d3db815bd4782f9734239c378f08afd2f00ffa54bef924

4 years agoFix the OSSFuzz-discovered shift problem from two days ago. This patch was
drh [Sat, 6 Feb 2021 14:37:36 +0000 (14:37 +0000)] 
Fix the OSSFuzz-discovered shift problem from two days ago.  This patch was
omitted from [078dbff04a95a001] apparently because I made the edit to
"sqlite3.c" rather than "resolve.c" where it belongs.

FossilOrigin-Name: 864772ffec4e91d8d73f9b97e6e1d7bd4e0537de19d11d30aed7eedd5b7d394a

4 years agoRemove unreachable code. Fix a shift UB problem introduced yesterday
drh [Fri, 5 Feb 2021 17:34:47 +0000 (17:34 +0000)] 
Remove unreachable code.  Fix a shift UB problem introduced yesterday
and discovered by OSSFuzz.

FossilOrigin-Name: 078dbff04a95a001bbd8690ab08038fbb5506899df8290991b53fd1122a4c30c

4 years agoChange the RETURNING algorithm so that outputs accumulate in an ephemeral
drh [Thu, 4 Feb 2021 23:20:13 +0000 (23:20 +0000)] 
Change the RETURNING algorithm so that outputs accumulate in an ephemeral
table until all modifications have been completed, and only then do results
start being returned.  This should help prevent problems with interleaved
sqlite3_step() calls on two separate DML statements.  It also seems to be
closer to how PostgreSQL works, which might prevent compatibility problems.

FossilOrigin-Name: c4615eb28c3dd2d473daf104f32e60d02799f3158d9d275a899c39129cc71401

4 years agoRemove dead code. Fix RETURNING for INSERT into a virtual table. returning-manifested
drh [Thu, 4 Feb 2021 22:59:19 +0000 (22:59 +0000)] 
Remove dead code.  Fix RETURNING for INSERT into a virtual table.

FossilOrigin-Name: dbfa38699c87ab4bf390666e411dda8d375c7b53b9b4fb131adacbf575867a72

4 years agoFix an issue with RETURNING from UPSERT.
drh [Thu, 4 Feb 2021 21:17:12 +0000 (21:17 +0000)] 
Fix an issue with RETURNING from UPSERT.

FossilOrigin-Name: 757b74ba0fd64634a365bd73955181191767ad8816a33a362e32ece250299a51

4 years agoSnapshot. New design appears to work on a simple test case.
drh [Thu, 4 Feb 2021 20:52:20 +0000 (20:52 +0000)] 
Snapshot.  New design appears to work on a simple test case.

FossilOrigin-Name: 8a65fbeecf3597e30853c5f0ccd9b8b46c508854fa521e58e0db279deebca7d4

4 years agoPreliminary changes for a new implementation of RETURNING that captures all
drh [Thu, 4 Feb 2021 17:29:04 +0000 (17:29 +0000)] 
Preliminary changes for a new implementation of RETURNING that captures all
results in a buffer and plays them all back after the DML statement
completes.  This avoids problems with interleaved DML statements.
This particular check-in is a non-functional work in progress.

FossilOrigin-Name: 04b77d63216ce11b4e797946953bcde504fc005807c7a5ac757fbf47d78698dc

4 years agoAdd NEVER() to a branch that check-in [5d54d9fd40638138] apparently made
drh [Thu, 4 Feb 2021 13:52:34 +0000 (13:52 +0000)] 
Add NEVER() to a branch that check-in [5d54d9fd40638138] apparently made
unreachable.

FossilOrigin-Name: 5c8e6296aa9f69a092364524b716ba894f113f7f1e6024b9a2eaa01c239e65c1

4 years agoPerformance optimization in sqlite3FinishCoding().
drh [Thu, 4 Feb 2021 13:44:42 +0000 (13:44 +0000)] 
Performance optimization in sqlite3FinishCoding().

FossilOrigin-Name: 0f34f241d37cc4f31dc657a6fc33815fa5e24298487121cb27c29118524b8ee7

4 years agoCorrections to the 'filepath_normalize' test suite helper procedure.
mistachkin [Wed, 3 Feb 2021 19:38:40 +0000 (19:38 +0000)] 
Corrections to the 'filepath_normalize' test suite helper procedure.

FossilOrigin-Name: 32f4d04470bf953b08eea285543f16e03de13d5448c1ebccbba1578ca3b5363e

4 years agoChange the name of Vdbe.magic to Vdbe.iVdbeMagic to disambiguate with
drh [Wed, 3 Feb 2021 18:32:25 +0000 (18:32 +0000)] 
Change the name of Vdbe.magic to Vdbe.iVdbeMagic to disambiguate with
sqlite3.magic.

FossilOrigin-Name: 6b29e549bb34933bfd0758e31085e65dcc0f75446c478fc775d96cf01c22cf43

4 years agoAvoid doing any foreign-key constraint related processing for an UPDATE statement...
dan [Wed, 3 Feb 2021 14:20:56 +0000 (14:20 +0000)] 
Avoid doing any foreign-key constraint related processing for an UPDATE statement that does not modify any columns that are part of FK constraints, even if the table has a self-referencing FK.

FossilOrigin-Name: 7f3b036e730153ac22933b03a52d4ec3978c9ecab1399d8cc79fe533893321e3

4 years agoFix a harmless compiler warning.
drh [Wed, 3 Feb 2021 13:20:12 +0000 (13:20 +0000)] 
Fix a harmless compiler warning.

FossilOrigin-Name: 1eb69c64ed4a11601698000573c507684bc4b0366336ba0748ebd661644d0902

4 years agoAdd support for the RETURNING clause following PostgreSQL syntax.
drh [Wed, 3 Feb 2021 13:08:09 +0000 (13:08 +0000)] 
Add support for the RETURNING clause following PostgreSQL syntax.

FossilOrigin-Name: 416c898bfb8ff9639ffbaefcfb47fce3782763af1fc67969fa91c5f01a336676

4 years agoFix an assert() that might be off-by-one in the case of a prior
drh [Wed, 3 Feb 2021 12:35:51 +0000 (12:35 +0000)] 
Fix an assert() that might be off-by-one in the case of a prior
errors in the parse.

FossilOrigin-Name: 06b15b17be38c804dd2641d8616a2a7bd396d2eb9901a0fbf94edd8bd508cf9c

4 years agoModify the SQLITE_DBCONFIG_ENABLE_TRIGGER setting so that it only disables returning
drh [Wed, 3 Feb 2021 00:55:34 +0000 (00:55 +0000)] 
Modify the SQLITE_DBCONFIG_ENABLE_TRIGGER setting so that it only disables
main-schema triggers and allows TEMP trigger to continue operating.  This is
safe, since only the application (not an attacker) can add TEMP triggers.
It will also all us to disengage SQLITE_DBCONFIG_ENABLE_TRIGGER on Fossil
databases since Fossil has no main-schema triggers but does use TEMP triggers.

FossilOrigin-Name: a10c5a2503ff2998f6ee40f721aab8c9579052e535dc141bd57d10551eaea387

4 years agoLoad enhancements from trunk into the returning branch.
drh [Wed, 3 Feb 2021 00:05:57 +0000 (00:05 +0000)] 
Load enhancements from trunk into the returning branch.

FossilOrigin-Name: b84c7f60c2e1e7debf9f50622087f87d60c6870061d61e14e59cc1ba0775ee92

4 years agoDo not allow aggregates in a RETURNING clause. Fix a memory leak that
drh [Tue, 2 Feb 2021 20:46:11 +0000 (20:46 +0000)] 
Do not allow aggregates in a RETURNING clause.  Fix a memory leak that
occurs when window functions are used in a RETURNING clause.

FossilOrigin-Name: 2e9bd94b9ad37c7e4123b7324f2fe42d3609a65af449eb8a0064057647709a73

4 years agoModify the sessions extension to use more efficient SQL when applying a changeset...
dan [Tue, 2 Feb 2021 20:41:13 +0000 (20:41 +0000)] 
Modify the sessions extension to use more efficient SQL when applying a changeset or patchset.

FossilOrigin-Name: e4ccfac09b6fe8cc3aec29d10f4e4c83097964f29882343db52ed91f6f0dde1c

4 years agoReport an error if RETURNING is used for DELETE or UPDATE of a virtual table.
drh [Tue, 2 Feb 2021 12:01:22 +0000 (12:01 +0000)] 
Report an error if RETURNING is used for DELETE or UPDATE of a virtual table.

FossilOrigin-Name: bd5dee8425327fde0429043ce325b910f1b7951988d9a448a8eeeb713a46bc81

4 years agoAllow the RETURNING trigger to exist for virtual tables.
drh [Tue, 2 Feb 2021 00:16:15 +0000 (00:16 +0000)] 
Allow the RETURNING trigger to exist for virtual tables.

FossilOrigin-Name: 2f244ab4a2ba2bdb608cf44ef02e00738ad58c10a76d9e4222dc843a17103d92

4 years agoAdd a few test cases for RETURNING together with UPDATE/DELETE LIMIT.
drh [Mon, 1 Feb 2021 21:26:09 +0000 (21:26 +0000)] 
Add a few test cases for RETURNING together with UPDATE/DELETE LIMIT.

FossilOrigin-Name: 7611c77d6baa84086ff18cbd045127fd682c6d5c434af5404e34fbe631fedfe1

4 years agoImproved corrupt database detection in balance_nonroot().
drh [Mon, 1 Feb 2021 12:39:50 +0000 (12:39 +0000)] 
Improved corrupt database detection in balance_nonroot().

FossilOrigin-Name: 5d54d9fd406381383afdf10612bfd590afc4142215d9bca09e227e3aa5baa102

4 years agoModify RETURNING so that it does not return changes implemented by
drh [Mon, 1 Feb 2021 01:57:55 +0000 (01:57 +0000)] 
Modify RETURNING so that it does not return changes implemented by
cascading foreign keys or by triggers.

FossilOrigin-Name: 6e62470a737cbde7f3fdcd027b98eb0b3dd11d063c63501d3c18448e93f5959f

4 years agoMark an unreachable branch as ALWAYS().
drh [Sun, 31 Jan 2021 16:45:10 +0000 (16:45 +0000)] 
Mark an unreachable branch as ALWAYS().

FossilOrigin-Name: cb8b797a64f65fca01c5faaeb30cbe4a53b56b81e696d1b62a90362d7ef8f924

4 years agoNew opcode OP_ChngCntRow used to output the result of PRAGMA change_count.
drh [Sun, 31 Jan 2021 15:50:36 +0000 (15:50 +0000)] 
New opcode OP_ChngCntRow used to output the result of PRAGMA change_count.
Only this new opcode, and not OP_ResultRow, checks for foreign key errors.
Faster performance, and now also works with RETURNING.

FossilOrigin-Name: 154fc2b15465c7c92a1af0a93851421aec42a81bab54840a9701f2c78068e14e

4 years agoWhen setting the number of result columns in a RETURNING trigger, be sure
drh [Sun, 31 Jan 2021 12:41:20 +0000 (12:41 +0000)] 
When setting the number of result columns in a RETURNING trigger, be sure
to set that value in the top-level bytecode program, not in the immediate
caller of the trigger.

FossilOrigin-Name: 1f1ce7ceb9807d22efea496f33908040ee196a31cd192f27ec0fb3e23afb729c

4 years agoImproved comments on the new code.
drh [Sat, 30 Jan 2021 21:55:38 +0000 (21:55 +0000)] 
Improved comments on the new code.

FossilOrigin-Name: a38f0c1d7c1d7635732ac370d8fbc7e6a2005378e4621da7bc4f51a2f99912d1

4 years agoAdd an ALWAYS() to an unreachable branch.
drh [Sat, 30 Jan 2021 16:16:42 +0000 (16:16 +0000)] 
Add an ALWAYS() to an unreachable branch.

FossilOrigin-Name: 6bb6de42b62acd35ade6c95a11bb4c9b35e7e9a24620731ae36364c4d5c3bc31

4 years agoChagne the OP_ResultRow opcode so that it does not cancel
drh [Sat, 30 Jan 2021 14:17:18 +0000 (14:17 +0000)] 
Chagne the OP_ResultRow opcode so that it does not cancel
pending statement transactions.

FossilOrigin-Name: fea91e3a511b14dafcc4da92c59188f927ec60ed91441335183da6b4e7866c1b

4 years agoFix a obsolete assert() in the bytecode engine. Improved OOM detection
drh [Sat, 30 Jan 2021 12:07:32 +0000 (12:07 +0000)] 
Fix a obsolete assert() in the bytecode engine.  Improved OOM detection
in sqlite3AddReturning().

FossilOrigin-Name: 138b10d54a83e1e7d5b3cdbe593a5073b05e632d1823e1b74d85835435b9ee3d

4 years agoFix handling of an OOM condition in sqlite3AddReturning().
drh [Sat, 30 Jan 2021 03:06:19 +0000 (03:06 +0000)] 
Fix handling of an OOM condition in sqlite3AddReturning().

FossilOrigin-Name: 52204cd768f115d13249ff0e3a252b716620f7ad16a6962e1192a09137a78596

4 years agoFix a memory deallocation problem that comes up when doing a RETURNING query
drh [Sat, 30 Jan 2021 02:43:26 +0000 (02:43 +0000)] 
Fix a memory deallocation problem that comes up when doing a RETURNING query
on a corrupt database.  I think I fixed this before, but it got unfixed with
stale editor content.

FossilOrigin-Name: 02b1415efb7d9849499afe4e9dbf7e470484bf144d6ca3d28fdc38fc0ac10afa

4 years agoAnother attempt to get trigger selection correct for RETURNING triggers.
drh [Sat, 30 Jan 2021 02:34:47 +0000 (02:34 +0000)] 
Another attempt to get trigger selection correct for RETURNING triggers.

FossilOrigin-Name: 1b8ed52275a54800df90682d694b482f55f26c6c4a420659f9a3b7bfc61e8abe

4 years agoWhen running the RETURNING trigger, if it is tagged as a DELETE trigger,
drh [Sat, 30 Jan 2021 02:22:38 +0000 (02:22 +0000)] 
When running the RETURNING trigger, if it is tagged as a DELETE trigger,
do not use it as INSERT or UPDATE.

FossilOrigin-Name: 3c7a6e04ddde34961d8e9d0443913e572a80853cf14a8263cec19523c39ca744

4 years agoTest cases added. RETURNING works with UPSERT as does PG.
drh [Sat, 30 Jan 2021 01:30:26 +0000 (01:30 +0000)] 
Test cases added.  RETURNING works with UPSERT as does PG.

FossilOrigin-Name: f5698f96e27c9b8669ec6016bb9920ef7580c4146eb61d628a0f62be5135ce94

4 years agoBetter handling of errors in RETURNING due to corrupt database files.
drh [Fri, 29 Jan 2021 22:33:05 +0000 (22:33 +0000)] 
Better handling of errors in RETURNING due to corrupt database files.

FossilOrigin-Name: 6aa2a058d136d0b24d94c5cbe1ce447eb435c1a1c7cdce5e435f1548bb3f05e7

4 years agoRETURNING works even if "PRAGMA count_changes=ON" is set.
drh [Fri, 29 Jan 2021 21:31:59 +0000 (21:31 +0000)] 
RETURNING works even if "PRAGMA count_changes=ON" is set.

FossilOrigin-Name: a9122d97577b239704cdee1a90a3b0dbff8bdf9dea2324d7315bd47238dcc8eb

4 years agoAllow "*" wildcards in the RETURNING clause.
drh [Fri, 29 Jan 2021 21:18:46 +0000 (21:18 +0000)] 
Allow "*" wildcards in the RETURNING clause.

FossilOrigin-Name: b0e3ae303db2a035583a05848ab7977e612d7e40c77e31ea9e0166de443c901f

4 years agoWorking prototype.
drh [Fri, 29 Jan 2021 19:32:17 +0000 (19:32 +0000)] 
Working prototype.

FossilOrigin-Name: b7ef4dc21f187ff4ff679e823782535188c3814aa6ce720b3a01c6d3ba4ef9f5

4 years agoFix possible division-by-zero in the new log() SQL functions.
drh [Fri, 29 Jan 2021 16:20:16 +0000 (16:20 +0000)] 
Fix possible division-by-zero in the new log() SQL functions.
Problemm discovered by OSSFuzz.

FossilOrigin-Name: 1ffd321a33b778e87614a26a91a8407ec7b9dec4f0f847b16b1dac4f3b910604

4 years agoIncorporate the sqlite3TriggerList() optimization from trunk. And move
drh [Fri, 29 Jan 2021 14:22:56 +0000 (14:22 +0000)] 
Incorporate the sqlite3TriggerList() optimization from trunk.  And move
the pReturning field to the uninitialized area in the Parse object, to
save memset() time.

FossilOrigin-Name: 29fbaf0e3eabda08500f350bc32e9f339e5732a65bfa62822eefb692a2ff0243