drh [Mon, 24 May 2021 00:17:04 +0000 (00:17 +0000)]
Additional defenses (above and beyond [b986600520696b0c]) to prevent an
invalid subquery from causing problems downstream. If an error is found
while analyzing a subquery expression, change the expression to TK_ERROR
so inhibit further processing on that expression.
dbsqlfuzz cf624b8c0484c66e0f552bf6475e3e3f2c22b24e.
drh [Sat, 22 May 2021 11:23:20 +0000 (11:23 +0000)]
Do not invoke sqlite3ExprAffinity() after a syntax error that might have
left the tree in an inconsistent state. See also [e8a1515b44380cc5] and
[forum:/forumpost/7e484e225c|forum post 7e484e225c].
drh [Sat, 22 May 2021 11:00:03 +0000 (11:00 +0000)]
The fix in the previous check-in was only correct if the OOM occurs on
the initial allocation. This changes should make it correct for a resize
as well.
drh [Fri, 21 May 2021 21:49:07 +0000 (21:49 +0000)]
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.
drh [Thu, 20 May 2021 00:44:04 +0000 (00:44 +0000)]
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.
drh [Wed, 19 May 2021 21:55:56 +0000 (21:55 +0000)]
When constructing the synthensized SELECT statement that is used to choose
the rows in an UPDATE FROM, make sure the first table is really the table
being updated, and not some common-table expression that happens to have the
same name. [forum:/forumpost/a274248080|forum post a274248080]. More
changes associated with CTE name resolution are pending.
drh [Tue, 18 May 2021 19:10:10 +0000 (19:10 +0000)]
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.
dan [Mon, 17 May 2021 16:20:41 +0000 (16:20 +0000)]
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.
drh [Mon, 17 May 2021 13:11:24 +0000 (13:11 +0000)]
When deleting an SQL function that does not exist, return without doing
anything at all rather than creating a tombstone function. In this way,
function deletes that happen inside virtual-table destructors that are run
when a database connection is closing do not create new tombstones in the
function table after the function table has already been purged.
[forum:/forumpost/726219164b|forum post 726219164b].
drh [Fri, 14 May 2021 14:26:57 +0000 (14:26 +0000)]
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].
drh [Thu, 13 May 2021 18:24:22 +0000 (18:24 +0000)]
Modify the sqlite3_stmt_readonly() interface so that it returns false for
CREATE TABLE IF NOT EXISTS statements even if the table already exists and
the statement is really a read-only no-op. Likewise for DROP TABLE,
CREATE INDEX, and DROP INDEX. Update the documentation for
sqlite3_stmt_readonly() to reflect this new behavior.
drh [Thu, 13 May 2021 13:43:40 +0000 (13:43 +0000)]
The content columns of the index-btree that implements a WITHOUT ROWID
table are not ordered and so the query planner should not assume they
are ordered. Fix for the issue identified by
[forum:/forumpost/6c8960f545|forum post 6c8960f545].
drh [Wed, 12 May 2021 22:02:14 +0000 (22:02 +0000)]
Fix the query plan for an indexed lookup on a WITHOUT ROWID table with
a DESC primary key when the primary key is constrained by an inequality.
See [forum:/forumpost/8988341615|forum post 8988341615]. Test cases in TH3.
drh [Wed, 12 May 2021 15:39:02 +0000 (15:39 +0000)]
Fix a race condition that can lead to deadlock in the memdb VFS if one
thread is trying to open an existing database at the same moment that
another thread that is the only prior user of that database is trying to
close it.
drh [Wed, 12 May 2021 14:17:20 +0000 (14:17 +0000)]
Add the new threadtest5 test program for stressing multiple database
connections in the same process hammering on a single database.
Primarily designed to test memdb, but works on any database.
drh [Wed, 12 May 2021 11:55:59 +0000 (11:55 +0000)]
Enhance the memdb VFS so that it is able to share databases among multiple
database connections in the same process, as long as the database filename
begins with "/". This provides a way for threads to share an in-memory
database without the use of shared-cache mode.
drh [Sat, 8 May 2021 17:18:23 +0000 (17:18 +0000)]
Enable the sqlite3_serialize() and sqlite3_deserialize() interfaces by
default. Omit the SQLITE_ENABLE_DESERIALIZE option and replace it with
the SQLITE_OMIT_DESERIALIZE option.
drh [Thu, 6 May 2021 11:02:55 +0000 (11:02 +0000)]
Improved detection of oversized cells in balance_nonroot(), especially in
index b-trees when a cell is being moved from a child page into the parent
page in order to become a new divider cell.
drh [Wed, 5 May 2021 19:46:50 +0000 (19:46 +0000)]
Provide the sqlite3PrintMem() routine on SQLITE_DEBUG builds, which can be
invoked from a debugger to get a summary of the status of an sqlite3_value
or Mem object.
drh [Tue, 4 May 2021 23:21:35 +0000 (23:21 +0000)]
When applying the optimization that disables WHERE clause terms that drive
indexes, make sure not to do so if the term being disabled is a transitive
constraint. Fix for the problem identified by
[forum:forumpost/eb8613976a|forum post eb8613976a].
drh [Tue, 4 May 2021 12:07:16 +0000 (12:07 +0000)]
Back out the EXISTS-to-IN optimization. It slows things down rather than
speeds them up depending on the query. And (see
[forum:/forumpost/8692d94725|forum post 8692d94725]) it sometimes results in
an incorrect answer. We may come back and revisit this optimization later,
but for now it seems best just to disable it.
Fix the IN-early-out optimization so that it works even for the corner case
where the NULL bypass fires before the affinity of the LHS operator has been
set. Fix for the problem described in
[forum:/forumpost/6a3ec138e9|forum post 6a3ec138e9].
Ignore the TEMP or TEMPORARY keyword on CREATE statements which parsing
the schema out of an existing database file. Those keywords should never be
there. This change simply adds robustness in case a legacy or damaged database
is seen.
RETURNING bug fix: Correctly deal with RETURNING statements on changes to
TEMP tables that also have triggers.
dbsqlfuzz 78b9400770ef8cc7d9427dfba26f4fcf46ea7dc2
When doing the optimization that attempts to avoid sorting on a
GROUP BY, do not assume that the values in an index on an expression are
non-NULL. Bug discovered by Wang Ke's fuzzer and reported at
[forum:/forumpost/74330094d8|forum post 74330094d8].
Treat byte-order marks (BOMs) at the start of a token as whitespace.
This enhancement is inspired by
[forum:/forumpost/ed8f696a20|forum post ed8f696a20].