Another fix to the indexed expressions in aggregate queries with GROUP BY
enhancement of ticket 99378177930f87bd and implemented by
check-in b9190d3da70c4171 to address a problem described by
forum post f34e32d120.
When setting the column types on a subquery, ensure that the COLFLAG_HASCOLL
flag is cleared from column names from when the collating sequence name has
been removed.
Work around a harmless assertion fault associated with
sqlite3VdbeMemAboutToChange() such that the detection of stale values
in registers is preserved in debugging builds, but we avoid a false-positive
assertion fault in cases involving a virtual table with a LIMIT clause
in an IN-operator loop.
In the CLI, during error processing while looking for a word boundary,
avoid being deceived by malformed input that has a very long sequence
of 0x80 characters.
Also fix a problem in the zipfile extension for when a corrupt
zipfile has a zero-length filename.
Fix the function that determines the collating function for an expression
tree to handle new cases that arise as a result of the recently added
ability to use indexed expressions in aggregate queries.
When translating arguments of aggregate functions into references to
expression indexes, make sure to only translate them for the current
aggregate when there are nested aggregates.
When changing a COLLATE expression node into TK_AGG_COLUMN because the nodes
value is contained in an indexed expression, be sure to clear the
EP_Collate property from the expression node.
drh [Tue, 28 Mar 2023 11:21:09 +0000 (11:21 +0000)]
Fix multiple problems with RETURNING on a DML statement against a view.
(1) Do not allow a RETURNING clause to trick the code generator into thinking
that the view being updated has an INSTEAD OF trigger.
(2) Generate all result columns for a view in a DML statement.
(3) The automatic covering index for a view should cover all result columns
of the view.
drh [Mon, 27 Mar 2023 13:27:25 +0000 (13:27 +0000)]
Do not allow constant factoring during PRAGMA integrity_check, since the
constants might be stored in registers that are later reused for other
purposes.
drh [Mon, 27 Mar 2023 13:10:43 +0000 (13:10 +0000)]
Improvements to register allocation, especially in the ANALYZE command.
New assert() statements added to help verify that memory allocation is
correct, and to help fuzzer find lingering errors.
drh [Sat, 25 Mar 2023 23:56:15 +0000 (23:56 +0000)]
When the left table of a RIGHT JOIN is used inside an aggregate function and the left table employs an index on expressions, then make sure the expressions evaluate to NULL for the cases where the left table should be NULL.
drh [Sat, 25 Mar 2023 19:46:21 +0000 (19:46 +0000)]
In the byte-code generator, when the result of an expression needs to be in a particular
register, always use the sqlite3ExprCode() routine because it has the smarts
to know whether to use OP_Copy or OP_SCopy. Do not try to OP_SCopy inline
because an OP_Copy might be required.
drh [Sat, 25 Mar 2023 18:33:42 +0000 (18:33 +0000)]
The fix at [13c8c60bb6b4447b] was incomplete in that it failed to clear
the reusable register cache that might contain registers in the STAT4
buffer region. This additional change corrects the problem.
drh [Fri, 24 Mar 2023 22:24:08 +0000 (22:24 +0000)]
Remove undocumented, vestigial SQL functions in the CLI that were once used
for the ".recover" command but are now no longer needed. This is a fix for
the problem described by [forum:/forumpost/be9c294ee0|forum post be9c294ee0].
drh [Thu, 23 Mar 2023 10:58:19 +0000 (10:58 +0000)]
The attempt to bring STAT4 up to 100% MC/DC at [55a26c67ed4a3a93] and
at [168fa2fb22b8c1ad] are incorrect. Back them out and replace them with
a simple NEVER() macro. Error reported by
[forum:/forumpost/dc4854437b|forum post dc4854437b].
drh [Mon, 20 Mar 2023 15:50:40 +0000 (15:50 +0000)]
Fix a problem causing a cursor to retain an out-of-date cell-info cache when processing a DISTINCT query on values that are identical according to their collation sequence, but different on disk.
drh [Fri, 17 Mar 2023 12:25:10 +0000 (12:25 +0000)]
Ensure that an error does not delete the Table object out from under
the xConstruct method of a virtual table.
dbsqlfuzz 7cc8804a1c6d4e3d554d79096e6ea75a7c1c7d2d
drh [Thu, 16 Mar 2023 10:21:52 +0000 (10:21 +0000)]
Do not use the one-pass optimization on an UPDATE if there is a subquery
in the WHERE clause, since if the subquery is hidden behind a short-circuit
operator, the subquery might not be evaluated until after one or more rows
have been updated.
drh [Thu, 9 Mar 2023 16:04:34 +0000 (16:04 +0000)]
In the Bloom filter optimization, hash all strings and blobs into the same
value, because we do not know if two different strings might compare equal
even if they have different byte sequences, due to collating functions.
Formerly, the hash of a string or blob was just its length. This could
all be improved.
drh [Wed, 8 Mar 2023 14:37:04 +0000 (14:37 +0000)]
Keep the historical datatype ("INT", not "NUM") for a table created as follows: "CREATE TABLE t1 AS SELECT CAST(123 AS INT) AS value;". The use of FLEXNUM only occurs on compound queries.
drh [Fri, 3 Mar 2023 18:47:29 +0000 (18:47 +0000)]
Enhance PRAGMA integrity_check so that it can detect when there are extra
bytes at the end of an index record, which might cause OP_IdxRowid to
malfunction.
drh [Fri, 3 Mar 2023 17:11:15 +0000 (17:11 +0000)]
When it is known when preparing a statement that X cannot be NULL, transform the expression (X IS NULL) to integer value 1 instead of 'true'. This is because under some circumstances, "Y IS TRUE" may not be equivalent to "Y IS 1".
drh [Thu, 2 Mar 2023 14:09:11 +0000 (14:09 +0000)]
When flattening the right operand of a LEFT JOIN,
ensure that the OP_IfNullRow opcode does not
NULL-out a subquery result that was computed within OP_Once.
drh [Wed, 1 Mar 2023 20:44:34 +0000 (20:44 +0000)]
When flattening a view that is the right operand of a LEFT JOIN
always insert the TK_IF_NULL_ROW expression nodes, even for TK_COLUMN
expressions, as the TK_COLUMN might be a column from an outer query
and hence still need to be NULLed out.
drh [Wed, 1 Mar 2023 15:28:34 +0000 (15:28 +0000)]
Make sure subtypes do not cross a subquery
boundary even if the function that returned the value with a subtype is
buried down inside a larger expression.
drh [Sun, 26 Feb 2023 21:09:45 +0000 (21:09 +0000)]
When a table-valued function appears as the right table of a RIGHT JOIN,
the argument constraints on the table-valued function should be considered
part of the ON clause of the RIGHT JOIN.
drh [Thu, 23 Feb 2023 17:12:07 +0000 (17:12 +0000)]
Provide -DHAVE_LOG2=0 and -DHAVE_LOG10=0 compile-time options for use on systems
that lack the log2() and log10() standard math library routines, to cause
SQLite to substitute its own alternatives.
drh [Tue, 21 Feb 2023 12:30:18 +0000 (12:30 +0000)]
Fix formatting and improved documentation on the various sqlite3_file_control()
opcodes. Other minor documentation changes. No changes to working code.
drh [Mon, 13 Feb 2023 12:46:22 +0000 (12:46 +0000)]
In the LIKE optimization, do not analyze the new virtual WHERE clause terms
until both have been added, since they are expected to be consecutive and
the analysis might add complementary terms.
This fixes a problem caused by [44200596aa943963] and discovered by dbsqlfuzz
and recorded as case 7e3b5983727d843b910b2d9ab556e4afcd777cfb.
drh [Fri, 10 Feb 2023 21:53:33 +0000 (21:53 +0000)]
Do a better job of detecting when a WHERE clause term might be useful to
an expression index. Fix for performance regression reported by
[forum:/forumpost/e65800d8cb|forum thread e65800d8cb].