Commit Graph

21665 Commits

Author SHA1 Message Date
drh
646975c521 Clean up the ExprList that holds the names of columns in a CTE before checking
for unused references in the ALTER TABLE implementation.

FossilOrigin-Name: 8223e79f987feda5c8e51ec52cec6798cca16d070b10558939e2888ca1a25b8e
2019-12-17 12:03:30 +00:00
drh
4dad7ed532 When a table is part of a LEFT JOIN and should be a completely NULL row due to
the semantics of a LEFT JOIN, make sure any generated columns on that row
evaluate to NULL.  Ticket [3b84b42943644d6f]

FossilOrigin-Name: 0271491438ad2a985aeff355173a8d0f1e5813954c82147bc68cb26cca5804c8
2019-12-16 16:52:22 +00:00
drh
d35bdd6c09 Ensure that all ON CONFLICT REPLACE indexes are sorted to the end of the list
of indexes for a table, even for weird cases where the same UNIQUE constraint
occurs twice with the ON CONFLICT REPLACE clause only on the second one.  This
avoids an out-of-order contraint processing problem that can arise due
to the optimization of check-in [469a62ca33081854].

FossilOrigin-Name: 1e3918ca2f2c1cfcfa44249b1d7b847d52cbb8d302a8d4a335c090cfdf22d7a1
2019-12-15 02:49:32 +00:00
drh
95866af326 Abort the OP_Savepoint opcode early if a virtual table xSync method fails,
perhaps due to an interrupt.

FossilOrigin-Name: 672e749aef7351de3c69b365c1f80c756fda4e261b5d2ac1faa01d3a7d5a4c49
2019-12-15 00:36:33 +00:00
drh
7e3f135c62 When a generated column expression is initially parsed, if it contains errors
convert the expression to a simple NULL.  This prevents additional pieces of
the expression tree that are allocated from lookaside from leaking into the
schema, where lookaside allocations are not allowed.

FossilOrigin-Name: a89b38605661e36d192df1d074383b704b34a959fcbc169837c0d4f6848f3208
2019-12-14 19:55:31 +00:00
drh
75f1076885 Due to the previous change, the p5 parameter to OP_VColumn no longer ever
contains extraneous bits, so change a testcase() into an assert() to show
as much.

FossilOrigin-Name: 5b4a88cd3b3a32b1242e0eb733cc0bc4becb830a887b8e6604a4c7452050e163
2019-12-14 18:08:22 +00:00
drh
99670abb82 Do not set OP_Column flags on the instructions generated by
sqlite3ExprCodeGetColumn() if the opcode generated is not really an
OP_Column, which might happen if the column is virtual.
Fix for ticket [b439bfcfb7deedc6]

FossilOrigin-Name: 2401e04730a156aa48787b91af4e516406cb7635145e430be62fd16481816237
2019-12-14 17:43:37 +00:00
drh
aac30f9b50 Make the sqlite3ExprCodeTarget() expression code generator routine robust
in the face of unknown opcodes - it simply generates a NULL value.

FossilOrigin-Name: f8e876c82a246ceed32b166f64e05dfe5ce4ab4c6820be60404109b43d36bb80
2019-12-14 15:01:55 +00:00
dan
5be1b20aec Fix problems in fts3 with processing corrupt records and undefined integer overflows.
FossilOrigin-Name: 3b873029ef1903f76442445343af3786cd59ee66b0e5e0e6b76a0b6b1b5eb88a
2019-12-14 14:15:21 +00:00
drh
e3a4f2cf77 Fix an utterly harmless "applying zero offset to null pointer" UB warning
in sqlite3AtoF():

FossilOrigin-Name: 052fdf5e58b41ccadaa5aac293ceb4d309ced661d46f3a52be9eb8d01d347a82
2019-12-13 23:38:57 +00:00
drh
0f1fa5de04 Patch to the page cache to avoid harmless pointer arithmetic that due to bugs
in the STD-C spec is technically UB.  This is to fix a harmless UBSAN
complaint that OSSFuzz is hitting.

FossilOrigin-Name: c29fc21288e37f81a1617c5e2961c575d3bca6a1d1b013b2e0a99774afb1dcdb
2019-12-13 21:24:46 +00:00
drh
d335bc40a6 Change the default lookaside configuration to 40 slots of 1200-bytes each.
This actually works out to 30 big slots and 93 small slots using the 
mini-lookaside allocator.  We get the same (or better) lookaside coverage
but with 72KB less memory per connection.

FossilOrigin-Name: 47b71a84d1262c4bf6ad4f4a91820fd63593f08ae9efa144199d44972225e073
2019-12-13 16:04:52 +00:00
drh
e6068027ca Cleanup and performance enhancements for mini-lookaside.
FossilOrigin-Name: 74805668430051032ae9b256c84e252755ee03075fc08293c948675ed40ec280
2019-12-13 15:48:21 +00:00
drh
ee5b6dd393 Merge fixes from trunk.
FossilOrigin-Name: 9c471195f6d3e4b00e2d0f909b306a4036352082dca5f016a8eece226e82163d
2019-12-13 12:14:23 +00:00
drh
2e2c8819f1 Ensure that there is a containing SELECT statement when processing a
normal aggregate function as if it were a window function.

FossilOrigin-Name: c1014e80b26131200a115beb86929a8f0ded2dd65b075e47373346c0f170576a
2019-12-13 11:42:56 +00:00
drh
0d98598507 *Remove* the macros, not just comment them out.
FossilOrigin-Name: e5dc2939d3e8694d648fc9b73b1174da5b1349e20fbb9cf1c91268939f308f89
2019-12-13 11:32:28 +00:00
drh
4ec4dd701f Remove unused macros formerly used to define built-in aggregate functions.
FossilOrigin-Name: 3ef0d44edd0354cda9b6237f992cb67a2170ee8f1f464b1f38ac36e3a133bc71
2019-12-13 11:31:47 +00:00
drh
85d9411c09 Reduce the size of ExprList to 24-bytes per entry, down from 32-bytes per
entry.  This helps keep lookaside allocations in the mini-size.

FossilOrigin-Name: bda92d92bf69a73bc6dd498f92578ad6e81111a3f97bc8724d1720e7283a83b6
2019-12-13 01:12:21 +00:00
drh
c4938ea2ba Tie up the loose ends in the ExprList size reduction.
FossilOrigin-Name: 59d0f3afe5249a2a6453fe7bc810c2c7beb896d3800174c7c90f9304c0b1ad88
2019-12-13 00:49:42 +00:00
drh
cbb9da337e Work toward reducing the incremental size of an ExprList object to 24-byte
per entry, from 32-bytes (on a 64-bit machine).  This helps the new
mini-lookaside allocator to run better by avoiding excessive reallocs.
The current change mostly works, but still has a few loose ends to tie up.
This check-in is merely a snapshot to save my work.

FossilOrigin-Name: fdda76cfb01bf2b19522ac4558b443634d28a69b0828677c42682b645eae1f3b
2019-12-12 22:11:33 +00:00
numist
1b47c9c98e Reduce the number of call sites to dbMallocRawFinish in the case where n > lookaside.sz
FossilOrigin-Name: e392e7f22861ce4b66e4bf84b59c8fd38568fc241a699e001f47fd82011f4d28
2019-12-12 20:58:32 +00:00
numist
c947d6a4dc Fix an issue where malloc could be used to fulfill a small allocation when a large lookaside slot could have beeen used instead.
FossilOrigin-Name: 611020e3378f4c81c277cccd84807ae51a816bbab6c3d887c91c5e5af3b5225f
2019-12-12 20:39:47 +00:00
drh
41cee66848 Change the name of the Expr.a.zName field to zEName, so that it has a name
that is distinct from other fields and variables and is hence easier to
grep for.

FossilOrigin-Name: d3783357f8fa76c42a86f12b214522f0388c37773c36ab8c5ce0623abbc4436a
2019-12-12 20:22:34 +00:00
drh
0225d819c4 Change the size of a mini-lookaside allocation to a macro (MINI_SZ) rather
than a magic number (128).

FossilOrigin-Name: 5e1949bca998f3c8c23a8ebf01c7a2e7a2af1fdad43886271e1fe0f25411551d
2019-12-12 17:17:24 +00:00
drh
20d6c1fe1b Merge enhancements from trunk.
FossilOrigin-Name: 6cb053f99b5be2ecc30e0733d8f1e4f2a89f642656d3883fc0c867b10a87ba6b
2019-12-12 16:49:10 +00:00
drh
77318a3c3f Factor out the conditional (which is only true for rare errors) from the
notValid() function in resolve.c, for a performance improvement and size
reduction.  Also cause failures to set the Expr node to a NULL operator so
that it does not cause problems later in case PRAGMA writable_schema=ON has
been set.  Test cases in TH3.

FossilOrigin-Name: c6af9f655b73200ecc0c4189698e421af6ca584babdc76e73a36d468b2eea1f9
2019-12-12 15:19:18 +00:00
numist
115d663c05 More efficient implementation of a lookaside allocator that supports mini (in this case, harcoded to 128B) slots.
FossilOrigin-Name: b02fdc09c838f355d9efce57f817d6a86153153b4a1f2b763914f4aaa34cb76e
2019-12-12 02:50:07 +00:00
drh
3ecc05bc3f Fix goofy string formatting in lemon.c that dates from the K&R-C days.
FossilOrigin-Name: 48ba5e5a2227257cebafacbb09e9dd91d9b89ab2d52a8b4e4113c1d017d95f41
2019-12-12 00:20:40 +00:00
drh
ce678c297b Improved tracing output from the LEMON-generated parser.
FossilOrigin-Name: 4d6d2fc046d586a1e5989bbb2757f13d0371fbfad0acf45a0e2fd77dffd8d8f9
2019-12-11 18:53:51 +00:00
drh
d4dae75f79 Strengthen check-in [83da4d4104ee1870] by ignoring *all* WHERE-clause
constraints for a virtual table that is the right table of a LEFT JOIN, 
as such constraints are never useful.
This fixes an issue discovered by Manuel Rigger.

FossilOrigin-Name: 840de36df1aaeb4bad9a7c18e97cc560ba3b8c629c4520a05bc456d67b3347b9
2019-12-11 16:22:53 +00:00
drh
a1ca00edd5 When trying to drop a virtual table that has no xDestroy method, invoke
the xDisconnect method rather than doing nothing, to avoid a memory leak.

FossilOrigin-Name: 1fa29a5f2a89b6a1ee067f9cb86de1b66455126349efe3502599fc7ad224170c
2019-12-11 15:07:09 +00:00
drh
31046a9f1f The xDestroy method of a module might be NULL if the schema is corrupt.
FossilOrigin-Name: 0457e7d1961ab1f63e31d9028a9064a895f5c3fcfb56ba25e4f37e90197e3a9f
2019-12-11 14:25:11 +00:00
drh
e94006eb42 Enhance LEMON to provide the ability to mark a rules as one that will never
reduce due to intervention of actions.  Use this new capability to designate
the EXPLAIN rule as NEVER-REDUCES.

FossilOrigin-Name: 136cdefb2f7b582ff1771ac7f9e733dc24c357605526cbfb1834937697c8a922
2019-12-10 20:41:48 +00:00
drh
8e8c88964c Use a statement journal on a CREATE VIRTUAL TABLE statement in case the
VCreate opcode fails.

FossilOrigin-Name: aa3b0eb8c3438ddd3b660bc6bce4b1f4a0e3b5ec897079445231ee1b61210d6a
2019-12-10 18:10:12 +00:00
drh
c075c505f3 Fix parser bugs: require a semicolon after an EXPLAIN command.
FossilOrigin-Name: 707a058a22bd00ef14431cee0d02048cf1be745c0ef5254eda76c325435738ff
2019-12-10 15:05:09 +00:00
dan
db5ed35609 Avoid a buffer overread in fts5 that could occur when parsing corrupt configuration records.
FossilOrigin-Name: 355afd77df21a2265871ca6d075f26b1fa121c7c2682cf512281944ff0c2186d
2019-12-10 03:40:11 +00:00
drh
b5f6243f6d Set the affinity of regular columns prior to computing the values of
generated columns.  Ticket [d7c3f125c925c522]

FossilOrigin-Name: d47d66e3d360d8aa6203a855228d2bc40d9a00d69c15f5066b7632d8fb1ed2cc
2019-12-10 02:48:41 +00:00
drh
0a8764ad7a Rename a local variable to avoid masking a function parameter and thus
causing a harmless compiler warning.

FossilOrigin-Name: f065cf003bd2a3a580cb5b9fa2eacd8be075fe8c2bbc5688e9a9406abbfb3804
2019-12-09 19:44:45 +00:00
drh
2bc5cf9ae9 Add a NEVER() to the ALTER TABLE fix in check-in [1d2e53a39b87e364]
FossilOrigin-Name: c7309ed3c7588c7e51e09418bf5cfd4611539b44c39cef9ed4ae0e385bae7625
2019-12-09 19:29:10 +00:00
drh
0824d5b9a5 The previous check-in was not quite correct, and introduced a new problem
with the USING clause.  Use this version instead.

FossilOrigin-Name: ed28aaa4851202111a502f883ca06359d89b25bba4055c29d7bce2b501cfcc68
2019-12-09 18:22:17 +00:00
drh
926f796e8f Ensure that the SrcList_item.colUsed field is set correctly (set to have a
1 for all columns of the table) when a generated column appears in the USING
clause of a join.

FossilOrigin-Name: 1923efb283e8840fa7436eb20b9d2174ef7cace1690d3b97b572a0db2048b8e3
2019-12-09 17:14:48 +00:00
drh
ebd70eedd5 Fix the NOT NULL verification logic in PRAGMA integrity_check so that it
works for generated columns whose value is the result of a comparison operator.
Ticket [bd8c280671ba44a7]

FossilOrigin-Name: f3b39c71b88cb6721f443de56cdce4c08252453a5e340b00a2bd88dc10c42400
2019-12-09 15:52:07 +00:00
drh
7a9698456d Fix a gramfuzz find. If a partial index that does not reference any column
of its table is used by an UPDATE statement in one-pass mode, then avoid the
use of OP_DeferredSeek since the seek might not be resolved prior to the
OP_Delete and OP_Insert that implement the UPDATE.

FossilOrigin-Name: e3398c5ffb060b2b26334b8598e2c63953741e2d6f5124dbd6bdfc8e94742539
2019-12-09 14:34:37 +00:00
dan
38096961c7 Avoid infinite recursion in the ALTER TABLE code when a view contains an unused CTE that references, directly or indirectly, the view itself.
FossilOrigin-Name: 1d2e53a39b87e364685e21de137655b6eee725e4c6d27fc90865072d7c5892b5
2019-12-09 08:13:43 +00:00
dan
c19e22f397 Fix possible null pointer dereferences in the fts5_expr() scalar function.
FossilOrigin-Name: c5d44143599f3fe98492b2b900fa3d77925c7be545096251055ceeab899a41f1
2019-12-09 02:20:37 +00:00
drh
bf9d0996b9 Fix incorrect column-usage accounting associated with generated columns
and added by check-in [6601da58032d18ae].  Fix for ticket [b92e5e8ec2cdbaa1].

FossilOrigin-Name: 9d75e1ccc72e9f536f45df3b24e9ecd25076cc1f7cf16b806b19e0e1b68e8326
2019-12-08 00:06:39 +00:00
drh
29cdbadf8a Correctly deal with multi-row VALUES clauses that contain window functions.
FossilOrigin-Name: 26d991f214db143976e2593d3564b5003eb3539a2728d1a0ccae2a2accece76f
2019-12-07 13:42:47 +00:00
drh
c7a046e282 Ignore type affinity for auxiliary columns in RTREE as it is too error-prone
to try to parse out the type from other constraints.
Ticket [8bf76328ac940d52]

FossilOrigin-Name: 7fa664ea0ea1e0283a9af50c9ff8dd360ee6042f9e491a136f53d9bcbbc9c7ef
2019-12-07 12:13:54 +00:00
drh
7fe2fc0dcb Fix a problem with foreign keys and generated columns discovered by
Manuel Rigger.

FossilOrigin-Name: 27c0fdab1ba4d4993b164eb4b777c63e82aa247c3fa406121dc8ed94970a0b35
2019-12-07 00:22:18 +00:00
drh
5102cf8df5 Early detection and reporting of too few columns in an rtree CREATE VIRTUAL
TABLE statement.

FossilOrigin-Name: ef73107f475e40e6bdd8b722e96992070f81fd2b7a3cb718ec8f251c89ca3e81
2019-12-06 19:07:44 +00:00