Commit Graph

21665 Commits

Author SHA1 Message Date
drh
e2478dfa43 Do an early close of virtual table cursors to avoid unnecessary cursor
contention in UPDATE for some virtual table implementations.
Ticket [56a74875be799b85]

FossilOrigin-Name: eb95dac7f6482c36853a23234c5ce7af37c7beed8e3675d6a49c4d3a8307e076
2019-12-23 19:28:34 +00:00
drh
a2d50283db Early detection of database corruption in balance_deeper().
FossilOrigin-Name: 61c2233654158e65a3d3baeea947903a919a569fcc4a5b342b2e9a68cec1b6f3
2019-12-23 18:02:15 +00:00
dan
1d24a53125 Fix a case in which SQLite could fail to identify "x BETWEEN ? AND ?" being true as implying that x is not null. Ticket [dfd66334].
FossilOrigin-Name: 2f17974912ec5e99089dc0da803e7ff1bf033377a49762d2689a812c005f2641
2019-12-23 15:17:11 +00:00
dan
2811ea6be7 For expressions like (x, y) IN (SELECT ...) where the SELECT uses window-functions, require that all columns on the LHS be indexed before an index can be used. Fix for [d9ed4ebe].
FossilOrigin-Name: 0b1dbd60f5db3abe2097dbc0b6de9671685ca5eaf7d3fc8e3f87ff5065a9d114
2019-12-23 14:20:46 +00:00
drh
7edce5ecc0 Fix a shift-overflow problem in yesterday's check-in [36fdeb4f0a66970a]
that OSSFuzz helpfully discovered overnight.  Thanks Google.

FossilOrigin-Name: bff38e2b5318ed032aaf1d350903c3494b4531f2dc59a6997144ec8e23defef4
2019-12-23 13:24:34 +00:00
drh
0af6ddd3ca Fix the OP_Cast operator so that when casting to TEXT, it always leaves
the result in the encoding of the database.  Ticket [0911b5d161b039c6].
Test cases in TH3.

FossilOrigin-Name: f347744e0d576f0250c29259cca755e57afded8956224114c01603c1bca5b3a4
2019-12-23 03:37:46 +00:00
drh
3d8e7a2f97 Change the assert() back into a testcase(). See also check-ins
[9ab985a9c8160b90] and [ddb17d92df194337] and other check-ins that those
reference.  Fix for ticket [9d708e474201c001]

FossilOrigin-Name: 2c44c73499154bc57634a54cb743642d0aacc93a1336fbb8bb3eb5dbbf616357
2019-12-23 02:43:52 +00:00
drh
13d7950267 Enhance the sqlite3VdbeMemAboutToChange() shallow-copy validation mechanism
by adding the new OP_ReleaseReg opcode to tell MemAboutToChange() that a
range of registers is no longer needed so that the source register can be
freely changed.  This is a change to debugging and test builds only and
does not impact release builds.  Fix for ticket
[c62c5e58524b204d] and [5ad2aa6921faa1ee].  The previous fix to ticket
[5ad2aa6921faa1ee] is backed out by this change since this change is a better
fix.

FossilOrigin-Name: 36fdeb4f0a66970a35de688b617f90899c89cfdfab659f864df99aa7ebf854ea
2019-12-23 02:18:49 +00:00
drh
4799488e16 Change the code generator for the IN operator so that it avoids creating
OP_Eq and OP_Ne opcode with the same P1 and P3 arguments.  This enables us
to back out check-in [ddb17d92df194337] and also fix ticket [188f912b51cd802].

FossilOrigin-Name: 9ab985a9c8160b905730678f40ed440a246cdec549c798bafefaed5abbc0437f
2019-12-22 23:48:36 +00:00
drh
5d762b2d1d Make a hard copy of strings in constraint checks prior to applying
OP_RealAffinity, to avoid problems with a pointer accounting assert.
This change is not strictly necessary - the correct answer is obtained
without it and no UB occurs - however the pointer accounting asserts are
useful to prevent other problems so it is a simple matter to bring this
piece into compliance.  Ticket [5ad2aa6921faa1ee]

FossilOrigin-Name: 89a9dad6330270a4c3b962f86a208088d2ea9883c7d291351a77f058e0ed8b0c
2019-12-22 20:29:25 +00:00
drh
6e827fa27d When constructing the virtual MATCH term of the WHERE clause for a virtual
table that is in a LEFT JOIN, be sure to set the correct Expr.iRightJoinTable
value.  This value does not appear to ever be used, except inside of a single
assert().  But it is good to set it correctly, nevertheless.  This fixes
ticket [7929c1efb2d67e98], which as far as I can tell is completely harmless.

FossilOrigin-Name: ef604882a275d3d5ebd4d5a08e3fe43e148f169b7d5c3a81464fbe7f54f3582a
2019-12-22 20:03:29 +00:00
drh
d262c2db8f In the WHERE clause debugging output (the .wheretrace output) show the
parent index of any WhereTerm that is a child.

FossilOrigin-Name: 7fc733328c5914c747e048c830522ec13e433c0a86388bae47b198a3e220c6c2
2019-12-22 19:41:12 +00:00
drh
6c1c85ca48 Fix to the optimization of check-in [a47efb7c8520a011] that reads the values
of expressions used in an index-on-expression directly from the index rather
than recomputing the value.  If the expression has a top-level COLLATE or
unlikely() operator, be sure to clear the corresponding flags prior to
converting it into a TK_COLUMN expression.  Failure to do this is most likely
harmless in production, but might cause an assertion fault in debugging builds.
Ticket [b0cb8aff561a6dcd].  Test cases in TH3.

FossilOrigin-Name: 56539e1c132632c075efc217ad5951a35e4459605ac128914aec3a7be1e25718
2019-12-22 18:55:04 +00:00
drh
db1954be0a Back out the asserts of check-ins [a500893b6f64aced] and [d9c9fe9f5ad3fc91]
as ticket [1b06916e01c82b66] demonstrates a case that refutes them.

FossilOrigin-Name: ddb17d92df194337a103c561ef46ced00db5e67e4551e82de7cb5ad7f457dd5f
2019-12-22 18:23:30 +00:00
drh
9524a7ea9f When parsing a CREATE TABLE from the sqlite_master table, delete the CHECK
constraints if there are any errors, since there might otherwise be attempts
to use those CHECK constraints if PRAGMA writable_schema=ON is set.
This undoes the fix in check-in [ea721b34477ab8b4] for a more general
solution.

FossilOrigin-Name: a982e6434cd66bfbe94d455f538bcbc4360b91572062d92acae6b77e9560e65d
2019-12-22 18:06:49 +00:00
dan
69843342de Ensure sqlite3WindowRewrite() is called on a SELECT statement before any terms aremoved from it as part of IN() clause processing. Fix for [f00d096ca].
FossilOrigin-Name: 8c856404b4e98d295449a4e89a41495dc007319a8e9c35c1a763718d7c5f67e8
2019-12-22 17:32:25 +00:00
dan
7a1d7c3968 Fix "PRAGMA data_version" so that it works the same way with locking_mode=PERSIST and journal_mode=PERSIST configured. Fix for 7a458c2a5f.
FossilOrigin-Name: 45748e2db028ffbda5d3e747493721a5a89af3fbc06823081a2f27f570e40e73
2019-12-22 14:29:55 +00:00
dan
e88af0179e Fix a spurious report of corruption from the fts3/4 integrity-check triggered by using the languageid option.
FossilOrigin-Name: 70815e273f511481c310dc33b3b49079901d891078fad49b663fbce06c77ecc2
2019-12-21 20:43:34 +00:00
drh
f4f31df02d When creating a new virtual table, ensure that the OP_ParseSchema opcode
processes the correct entry in the sqlite_master table even if there is
a second entry with the same name and table values due to database corruption
and the use of writable_schema=ON.  Dbsqlfuzz find.

FossilOrigin-Name: 4dbb6e1cb094f3428c74ea8bdd86ab63341fecce978a062968ca01423f382e90
2019-12-21 19:37:09 +00:00
drh
b0cbcd0edf When a corrupt schema is loaded using writable_schema=ON, the CHECK constraints
(or other expressions in the table definition) might not be fully resolved.
Ensure that the code generator can deal with this if the table is subsequently
used in a DML statement.  dbsqlfuzz find.

FossilOrigin-Name: ea721b34477ab8b49d182352c4bc198245933b850e9b6248b4f97600e80bb44b
2019-12-21 14:09:30 +00:00
drh
ed0c34857a Do not try to access a generated column through an index if the collating
sequence for the generated column is non-standard.
Part 2 of ticket [e0a8120553f4b082]

FossilOrigin-Name: 056bb8dcbdc45989c5c6e86d2966200062e3c01c382ec52aae37c828104b4496
2019-12-20 22:46:41 +00:00
drh
67b9ba1732 Apply real affinity to generated columns of type REAL that are extract from
an index.  Ticket [e0a8120553f4b082]

FossilOrigin-Name: 728ad39e3bd07a2503a95c68ed5bbc3f28fd97551d59f12a5fab25dc68227e99
2019-12-20 20:45:02 +00:00
drh
a513e591ae Debugging enhancment: Show the Expr.y.pTab pointer on TK_COLUMN nodes of
an expression tree in the treeview.

FossilOrigin-Name: 64154ac450e4366d18e7e867841877a69c1f978d3ba9b8754cc133248966731d
2019-12-20 20:08:56 +00:00
dan
879f1a1ea6 Fix a bad interaction between RBU and [df51ae19].
FossilOrigin-Name: 0b9d8a1202c4220fd2ef299b6194533c1bf4018a0cd2d13da7e22c1a7de05ffa
2019-12-20 20:03:21 +00:00
dan
42ae633ab9 Fix two more cases in fts5 where sqlite3_value_bytes() was being called before sqlite3_value_text(). Fix for e431c355.
FossilOrigin-Name: a1ba9a37d7a68a6d31f8197c6350589ebe6a12f4e3c193a178dd7ead8bcd565a
2019-12-20 19:41:01 +00:00
mistachkin
e99cb2da5f Export the public RBU entry points from the Win32 DLL.
FossilOrigin-Name: e62d1791f428b7a9bb14a59483f12d8ee08afbf4061a5e3be8f64787444301e7
2019-12-20 17:41:15 +00:00
drh
5d73272340 Debugging improvement: when tracing the VDBE, output the register value for
OP_Cast after the cast is completed.

FossilOrigin-Name: dc5f1d282d1e75f8a3791b0c95cb8f143b2a956323cb6c889d76d20db7f89257
2019-12-20 17:25:10 +00:00
drh
8cc8feae7e When computing dependencies on WHERE-clause terms, be sure to take into
account the FILTER clause of aggregate functions.  Problem reported by
Manuel Rigger.

FossilOrigin-Name: 3cc2b5709e66ef605c3b85ed13ae6cc9c3090e864ebc18859db36284b8f715b6
2019-12-20 15:35:56 +00:00
drh
8c7715d1cc Improved assert() statements on the OP_Column opcode.
FossilOrigin-Name: c538601e4c979ee59f18d19e6eb6296cebfa580fb029a18d5a3f0dd9393acb75
2019-12-20 14:37:56 +00:00
drh
40e9c8328e Load new dbsqlfuzz test cases into test/fuzzdata8.db.
FossilOrigin-Name: 01aeeb5c4c70a0f19651448e94ad5c6810cab3d6957b5bc7a9b4b8e0b887f3de
2019-12-20 14:24:26 +00:00
dan
394aa710f2 Fix a potential problem with ALTER TABLE commands on schemas that contains a triggers or view featuring a sub-query that uses an ON clause with a join that is not a LEFT JOIN.
FossilOrigin-Name: 365dd8b663d5a28af33556b2b3820c6b5482114ef741a1d82b55c6e154f3043a
2019-12-20 14:18:29 +00:00
drh
b2ab3dcff0 Fix harmless compiler warnings.
FossilOrigin-Name: 2bbd014c900e0d71fd30ec647739b82c5dc3aa237a0203f5a1db50593dae199e
2019-12-20 14:08:34 +00:00
dan
73b21382d4 Ensure fts5 consistently calls sqlite3_value_text() before sqlite3_value_bytes(). This matters when storing blobs in fts5 tables within utf-16 databases. Fix for [cf36cb4e02].
FossilOrigin-Name: c16305eba0eb14368f2631b9a82b7eb4483c93f3b31257ee7c33f9b00c344379
2019-12-20 13:24:11 +00:00
drh
1548d5276f Do not continue an ALTER TABLE tree walk of a subquery if a prior error
is seen in the tree.  Report the problem immediately, without continuing.

FossilOrigin-Name: 01ca865f31c0c817ede7f357401ef76cf311ae662397908464f53e1c147f5b6b
2019-12-20 12:55:21 +00:00
drh
0e5ce8029d Fix an assert() in btree.c that can fail if an INSERT is attempted on
a corrupted database while in PRAGMA writable_schema=ON.

FossilOrigin-Name: 07beb3629e648e7feae4e786191514339ac1d8f6ba5bb6e7cc8a04bc1f1cd6ab
2019-12-20 12:33:17 +00:00
drh
8428b3b437 Continuation of [e2bddcd4c55ba3cb]: Add another spot where it is necessary
to abort early due to prior errors in sqlite3WindowRewrite().

FossilOrigin-Name: cba2a2a44cdf138a629109bb0ad088ed4ef67fc66bed3e0373554681a39615d2
2019-12-19 22:08:19 +00:00
drh
6ad0e25fa4 Fix the regexp extension so that it correctly translates all over-length
3-byte UTF8 sequences into 0xfffd.

FossilOrigin-Name: 3d4c0bf8904135fa68c75801bfa738715cacc3b19dc8ad6ef550b11798d4b121
2019-12-19 21:11:48 +00:00
drh
8654186b02 When an error occurs while rewriting the parser tree for window functions
in the sqlite3WindowRewrite() routine, make sure that pParse->nErr is set,
and make sure that this shuts down any subsequent code generation that might
depend on the transformations that were implemented.  This fixes a problem
discovered by the Yongheng and Rui fuzzer.

FossilOrigin-Name: e2bddcd4c55ba3cbe0130332679ff4b048630d0ced9a8899982edb5a3569ba7f
2019-12-19 20:37:32 +00:00
drh
34ab941e5b Detect the invalid use of NULLS LAST on an INTEGER PRIMARY KEY definition
of a WITHOUT ROWID table.

FossilOrigin-Name: 4417c5bf0aabb34ed174f01afd981c924ae965a42128719d8d6735536631d12f
2019-12-19 17:42:27 +00:00
drh
54d501092d Fix the zipfile extension so that INSERT works even if the pathname of
the file being inserted is a NULL.  Bug discovered by the
Yongheng and Rui fuzzer.

FossilOrigin-Name: a80f84b511231204658304226de3e075a55afc2e3f39ac063716f7a57f585c06
2019-12-19 15:15:40 +00:00
drh
59c5679691 Fix incorrect SQL generated by the Lemon change of the previous check-in.
FossilOrigin-Name: fccfb8a9ed3c1df9f23762bb8df6fdf36a21118899e3fae41f451169a5f2c08e
2019-12-19 13:17:07 +00:00
drh
3e5f7fef33 Modify the parse.sql output file from Lemon so that the RULE table contains
a column with the complete text of the rule.

FossilOrigin-Name: 329cbb372d4d77f774f01a87d104c40ef42d713afbe76195b65f5ca205c5ea7b
2019-12-19 12:29:31 +00:00
drh
c29af653e6 Change an unreachable testcase() into an assert()
FossilOrigin-Name: 062e00c4d7e30155299339eaefe6cbe01953894baebf0af6d7ab3295b7436eb7
2019-12-18 21:22:40 +00:00
drh
396afe6f6a Continue to back away from the LEFT JOIN optimization of check-in [41c27bc0ff1d3135]
by disallowing query flattening if the outer query is DISTINCT.  Without this fix,
if an index scan is run on the table within the view on the right-hand side of the
LEFT JOIN, stale result registers might be accessed yielding incorrect results,
and/or an OP_IfNullRow opcode might be invoked on the un-opened table, resulting
in a NULL-pointer dereference.  This problem was found by the Yongheng and Rui fuzzer.

FossilOrigin-Name: 862974312edf00e9d1068115d1a39b7235b7db68b6d86b81d38a12f025a4748e
2019-12-18 20:51:58 +00:00
drh
6e1c45ef2e Add the --vdbe-debug option to fuzzcheck.
FossilOrigin-Name: 289158aa24b066c453d2bce4bc2dead1c56fb0b23c3f7c4810b34b13627cef34
2019-12-18 13:42:04 +00:00
drh
a7648f02e0 Enhancements to fuzzcheck on unix so that it captures signals and prints
the current test file and test number prior to terminating.

FossilOrigin-Name: ae7cbb246bff3717c283869ccf27ce83611422f3801176819465a8d96f6481bf
2019-12-18 13:02:18 +00:00
drh
8c72afaf33 Add a test case for fix in check-in [1ca0bd982ab1183b]
FossilOrigin-Name: 519864da8bb671941a64bf333c2086ad9a068b5f85759e7abd368f0706d3aefd
2019-12-18 09:17:55 +00:00
drh
94649b6159 Correctly unwind the savepoint stack if the database goes read-only in
the middle of a savepoint.

FossilOrigin-Name: a96d02b4ab8c70cc20b322e4fa3a4b8814f05c51f5d8b071ec9d69e7379f3ea5
2019-12-18 02:12:04 +00:00
drh
50efa58600 Remove an assert() in the code generator that can fail due to an invalid
INSERT statement.  The same assert() appears again in the VDBE and will fire
there if the problem persists in an SQL statement that does not contain
errors.  Gramfuzz find.

FossilOrigin-Name: 9bdd57cb9ad8ac1f4a0f1a3942d94ca5193109eeb1975343c4f0c7abf7135946
2019-12-18 01:31:21 +00:00
drh
75e95e1fcd When processing constant integer values in ORDER BY clauses of window
definitions (see check-in [7e4809eadfe99ebf]) be sure to fully disable
the constant value to avoid an invalid pointer dereference if the expression
is ever duplicated. This fixes a crash report from Yongheng and Rui.

FossilOrigin-Name: 1ca0bd982ab1183bbafce0d260e4dceda5eb766ed2e7793374a88d1ae0bdd2ca
2019-12-18 00:05:50 +00:00