If the OP_NullRow opcode is given a cursor that has not yet been opened,
then go automatically open it to a special pseudo-cursor that allows returns
NULL for every column. Used by the new RIGHT JOIN implementation.
Move the explain comment for the RIGHT-JOIN post-processing loop to the
verify beginning of the loop - to make the start of the loop clearer to
human bytecode readers.
For the bad join type error message "unknown or unsupported join type"
remove the "or unsupported" clause, because we now support all valid join
types.
Factor out the RIGHT JOIN non-matched row loop from sqlite3WhereEnd(). This
reduces the register pressure on that routine and helps it to run faster
in the common case where there is no RIGHT JOIN.
Always explicitly set each table cursor to NullRow before doing the RIGHT-JOIN
unmatched row pass. This is a cheap opcode, and it adds an extra layer of
defense against incorrect results.
dan [Tue, 12 Apr 2022 11:02:06 +0000 (11:02 +0000)]
Modify utility function sqlite3SetString() so that it may be used safely on Parse.zErrMsg. Fuzzer test case "crash-1604e5d76c92574e21e437049dab9b672e06b767.txt".
The query flattener must add TK_IF_NULL_ROW opcodes on substituted values
that land on the left operand of a RIGHT JOIN, just as it already does for
the right operand of a LEFT JOIN.
Make a distinction between (1) WHERE clause constraints, (2) ON/USING
constraints on outer joins, and (3) ON/USING clause constraints on inner
joins. Formerly, there was no distinctionb between 1 and 3, but RIGHT JOIN
needs to know the difference. Make RIGHT JOIN aware of this difference and
add test cases.
Rename the Expr.w.iRightJoinTable to just Expr.w.iJoin, so that the words
"RightJoin" in the former name do not lead readers to believe that this has
something to do with RIGHT JOINs in particular.
Cannot use an automatic index on the right table of a RIGHT JOIN because
automatic indexes must be WHERE_IDX_ONLY, but the RIGHT JOIN post-processing
does not know how to work with an index-only scan.
Minor improvements to the sqlite3SrcListShiftJoinType() routine. This started
out to be an effort to convert RIGHT JOIN to LEFT JOIN if the join was on
the first pair of relations, but that messes up the "*" expansion and so won't
work.
When the left-most table of a RIGHT JOIN is implemented as a co-routine,
make sure all its columns are flushed to NULL when it finishes so that
they appear to be NULL during the RIGHT JOIN post-processing.
Add byte-code that computes unmatched rows on the right table of a RIGHT JOIN.
Compiles, and the code looks semi-reasonable, but still does not run.
Incremental check-in.
Preliminary code to support RIGHT JOIN. Everything seems to work, except that
the code to compute the unmatched rows for the RIGHT JOIN has not yet been
added, so the result of a RIGHT JOIN is currently the same as an INNER JOIN.
Enhance the sqlite_dbpage fix at [/info/642a0b4752743216|check-in 642a0b4752743]
from about a month ago such that it still takes a transaction on all attached
databases, but it only starts a read transaction for read-only operations,
rather than starting a write transaction for everything.
Improved explanation and commentary on the sqlite3JoinType() routine. One
of the error messages changes slightly, but besides that everything works
the same.
The ".testctrl optimizations 0x400000" command disables the generation of
OP_ReleaseReg opcodes. OP_ReleaseReg opcodes are usually only generated for
SQLITE_DEBUG builds and are used to verify that registers are descoped
propertly. But they can get in the way of code understanding when studying
bytecode dumps. So this new optimization setting is provided to
temporarily turn OP_ReleaseReg opcodes off.
Add the sqlite3Show() family of debugging interfaces under SQLITE_DEBUG.
No changes to deliverable builds. Rename SQLITE_ENABLE_SELECTTRACE to
SQLITE_ENABLE_TREETRACE in ctime.c.
Rename debugging defines and variables from SELECTTRACE to TREETRACE (and
similar) since the functionality has how expanded to include data structures
beyond SELECT statements. Should not affect deliverable builds.
Add new diagnostic "sqlite3TreeView" routines for IdList, Upsert, and for
INSERT statements. This is all debugging code. There are no changes to
release builds.
When constructing the JSON Path for the "fullpath" column of the
json_tree() and json_each() table-valued functions, be sure to quote
object labels where necessary.
Only invoke sqlite3VdbeClearObject() from a single location, so that the
compiler is more likely to in-line the code. Performance increase and
size reduction.
Omit the Vdbe.runOnlyOnce flag (simplifying the prepared statement
implementation) and accomplish the same result by adding an "OP_Expire 1 1"
opcode to prepared statements that would normally have runOnlyOnce set.
In-line the sqlite3VdbeSerialPut() routine into the OP_MakeRecord opcode.
This allows some duplicate comparisons to be omitted, resulting in a size
reduction and performance increase.
New macro ROUND8P() which works like ROUND8() but assumes that the input is
already a multiple of the size of a pointer. It becomes a no-op for
64-bit machines, giving a small size reduction and speed boost.
Provide and use a version of sqlite3VdbeFreeCursor() that guarantees the
cursor pointer is not NULL. This saves a few bytes of code space and a
few CPU cycles.
Refactor the Vdbe.iVdbeMagic field into Vdbe.eVdbeState. Split the RUNNING
state into separate RUNNING and READY. This gives a size reduction and
performance increase.
Have the sqlite3_context object carry the encoding for the prepared statement
that it represents, so that sqlite3_result() and similar can set the encoding
according to the prepared statement, even if the database encoding has
changed.
dbsqlfuzz c409b10d0a6bccf78ab00f47e1d29d42ee5b3565
drh [Thu, 31 Mar 2022 11:12:56 +0000 (11:12 +0000)]
Refinement to [3f9887d4a58cbfdb]: The SQLITE_CONSTRAINT error should only
be returned if the prepared statement came from sqlite3_prepare_v2(). The
legacy sqlite3_prepare() is documented to return only SQLITE_ERROR.