Commit Graph

23888 Commits

Author SHA1 Message Date
drh
d859dc2b25 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.

FossilOrigin-Name: 6f4d6f212a3558c27be6e9dcf71cec43c424d445e5889c6e91dde84a19c5a2c1
2022-04-02 14:30:58 +00:00
drh
b47b1f67dc The putVarint32() macro does not optimize well. So expand it into in-line
code in places were performance is an issue.

FossilOrigin-Name: 390c239e53cf936a97b268dce8171f0b17050542ae64735ca8ef375fec2c9544
2022-04-01 21:01:37 +00:00
drh
759e507ce5 Loop optimization in the OP_MakeRecord opcode.
FossilOrigin-Name: 47a61fbd63928021098fbe492283f1afda7c293b3b2706c001192ae4ff1b2cbe
2022-04-01 20:39:40 +00:00
drh
3b8b5be3b7 It is not necessary to de-ephermeralize the output registers in the
OP_ResultRow opcode.  Omit that step for a size reduction and performance
increase.

FossilOrigin-Name: 8a07745aed1d0a4eead55d43f1923597b12371f307ecf5bc19c5a1db9a107a50
2022-04-01 20:19:36 +00:00
drh
35e9e350ca There is no need for sqlite3_step() to check for an OOM condition prior
to starting up.

FossilOrigin-Name: 44be7f46ba89289683ed0e123169ca9adb1018de03071d66de480c910a23d074
2022-04-01 19:13:39 +00:00
drh
a24832b7b2 Omit the Vdbe.doingRerun field for a slight size reduction and performance gain.
FossilOrigin-Name: e93297a9d775688e6274c54ba75b19fc1fe8b29b73b9b5e7f94f3f2ca37f045f
2022-04-01 19:04:13 +00:00
drh
cf6e3fd787 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.

FossilOrigin-Name: d126f304cde66ebfe21a4967c22dcba0bac27cbce56318b14bd50051e49c978c
2022-04-01 18:45:11 +00:00
drh
473571b083 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.

FossilOrigin-Name: cb5e6f8e265c91221227e5f15b95798c688773262407dd138d414103184702f6
2022-04-01 18:19:04 +00:00
drh
2fb448f2c8 Remove an unnecessary branch from sqlite3VdbeReset().
FossilOrigin-Name: a7d79560a0efd6221ba59ce84bcb4fa94024a901ac4a45e192ddecc6e1b5c78c
2022-04-01 17:23:17 +00:00
drh
17c4865b83 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.

FossilOrigin-Name: 5a50a42fde9477868fad31099f5fe976437825fac44f8b3a4cf6c739c7667bbb
2022-04-01 17:01:57 +00:00
drh
00946d7953 Avoid a harmless uninitialized variable warning in PRAGMA incremental_vacuum.
FossilOrigin-Name: 6d976f90dfe4886c3f4c062151af5c5ca7454d34b71172401b8c67acd2d663a0
2022-04-01 16:22:41 +00:00
drh
659fdb4da8 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

FossilOrigin-Name: d4e19314f564126e180e091f9135c7bc55a10442edb46fbd3a4cfad21201dfa6
2022-04-01 15:31:58 +00:00
drh
99a218282c Split out the RUN state into separate READY and RUN states.
FossilOrigin-Name: d698826b08b88e227eb83f84b3cdb19f17306b532eccfa162090abccdf3c63d8
2022-03-31 21:15:09 +00:00
drh
66181ce2b8 Rename Vdbe.iVdbeMagic to eVdbeState. Remove unnecessary states. This is
a preliminary step toward splitting RUN_STATE out into several other states.

FossilOrigin-Name: ff91191d232305d44ae6c0fbca2542a749422dc716fa1fd5d54f58c7d6052c14
2022-03-31 20:04:49 +00:00
drh
c4c0ff8664 Fix harmless compiler warnings.
FossilOrigin-Name: b916087aacba53530d2bd19eef2a4fd7a253bf7fa87b49e0df17f7987d7164ae
2022-03-31 16:09:13 +00:00
drh
89cf958c00 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.

FossilOrigin-Name: f2d9262e4427ab37ba26c004fc7a4790c86c1856d695a6b4ec3e72732ea54c09
2022-03-31 11:12:56 +00:00
drh
7e62146b13 Faster and slightly smaller implementation of sqlite3Step().
FossilOrigin-Name: c6901a8c78838228f8135c9346b214e638b72086fd85367b9ff482273e62ece6
2022-03-30 17:56:27 +00:00
drh
66f58bf38d Small size reduction and performance increase in sqlite3FinishCoding().
FossilOrigin-Name: 9248ce50f57fb9c4ba67949fdf9c9567c3e626cd9dd1b41b71c602d29c77c43e
2022-03-30 17:36:40 +00:00
drh
c55b62d4cb In setResultStrOrError(), if the input string pointer is NULL and hence the
value gets set to an SQL NULL, then the Mem.enc field is uninitialized.  So
do not read it.  This is a harmless OSSFuzz/ASAN found problem.

FossilOrigin-Name: 47d0b1c4cfc3d2d8f57a02079276bb70a205ffd0f18007dd39c92f813d4c87f5
2022-03-29 22:57:00 +00:00
drh
4cb32b70ed Ensure that sqlite3VdbeMemSetStr() always leaves the value in a consistent
state even if there is an error.

FossilOrigin-Name: c86ab289ec31ce9ae0abaf103a829b8d1e5ed632f493456f1f40607aeb91b41c
2022-03-29 20:50:20 +00:00
drh
555db979f6 Reverse the order of two tests to stop a harmless initialized value
warning from MSAN - reported by OSSFuzz.

FossilOrigin-Name: 800b8fdad73b67105e416b4b5c6a5c5ded7d6a43b4eacd6b67d690cab7584b0b
2022-03-29 19:19:23 +00:00
drh
de9484858e Avoid unnecessary calls to balance() from sqlite3BtreeDelete().
FossilOrigin-Name: d0966d1bdd474e27cb048884d340184f0e81a4fab65eb6b74682b20630caddf8
2022-03-29 13:16:32 +00:00
drh
fb92e07186 Fix the sqlite3_result_xxxxx() routines so that they all check for and
perform any necessary text encoding conversions and check for oversize
strings and BLOBs.  Thus those checks can be done where they are most
efficient and avoided in cases like OP_Function where they are more
expensive.

FossilOrigin-Name: d50b162b2f2e320af0889b931351f9443580465a933f6657fa98f437b6579277
2022-03-29 01:43:09 +00:00
drh
bcedbb2781 Further size and performance optimizations for sqlite3VdbeMemSetStr().
FossilOrigin-Name: 310a3e102d8eedf92ee63ffffb48621abfb1e2736b96bd2a676d63cca0f40598
2022-03-28 18:34:40 +00:00
drh
f4dd18ea36 Slightly smaller and faster sqlite3VdbeMemSetStr().
FossilOrigin-Name: 06928e745c7bcb26ec46a17989f30efe3536fd48a74c8a1cd423cc9ff6feccb5
2022-03-28 17:34:46 +00:00
drh
60a512d923 Performance increase in the loop that frees an opcode array.
FossilOrigin-Name: 4ccebb86aae178dbce905d782f04d98211f8fce9aacd71c12b8694c92a4f5c40
2022-03-28 15:06:36 +00:00
drh
cea170ec96 Another small performance gain by using sqlite3DbFreeNN().
FossilOrigin-Name: daa924af987253345bdb1c71b13378681bd252521e94d01f5d4629601232c352
2022-03-28 14:56:47 +00:00
drh
da3ec15f3c Use sqlite3DbFreeNN() instead of sqlite3DbFree() in a few hot spots for
better performance.

FossilOrigin-Name: b12de0ecc78a4f654c8e7b2b17cc2201688808a4f516908e9563a216677e655c
2022-03-28 14:18:03 +00:00
drh
f5a8386c32 Performance optimization in the memsys5 memory allocator.
FossilOrigin-Name: 949133231f8f751aa86518d0d3f6f03d7827fec085bfef3929fa3d57369d0216
2022-03-28 13:22:54 +00:00
drh
be341502db Fix the Bloom-filter optimization so that it does not use IS NULL or
IS NOT NULL constraints from the WHERE clause when operating on a LEFT JOIN.
[forum:/forumpost/031e262a89b6a9d2|Forum thread 031e262a89b6a9d2].

FossilOrigin-Name: 1a6328f2a5b4973094e5f85787145d652119822c86ec01a61f3f985c9d2903f2
2022-03-25 01:23:37 +00:00
drh
5705b41fb8 The "PRAGMA writable_schema=ON" flag should not allow OOM errors to pass
while parsing the schema.
dbsqlfuzz 9cc49e1a53e1cef8e3a1496a88c683aa20483163.

FossilOrigin-Name: a7abb725c7c783331e73837597917e25e5ff692aac8ec97a0a8c0e30db62d68b
2022-03-24 14:01:55 +00:00
drh
8ad3c43257 Use trickery to code the UTF-8 BOM for the --bom option on .output, .once,
and .excel in the CLI, to work around a warning in some Microsoft compilers.
[https://fossil-scm.org/forum/forumpost/bd0844268f0fab71|Fossil forum post bd0844268f0fab71].

FossilOrigin-Name: 43143ad131f17734fd2eff849e0a1bc2e26daf6a28c7e07d697d38732e6af5fc
2022-03-23 10:04:52 +00:00
drh
500d7e542c Ensure that database corruption does not cause the cursor passed into
sqlite3BtreeDelete() to be invalid.
dbsqlfuzz 209bf3de9ee11ae440848ab9bc9c13858f9be2e4.

FossilOrigin-Name: a85126f96614c53b030c6e6c43ff239eae458048597a10e9a0361fcec8628ecf
2022-03-22 23:33:20 +00:00
drh
56d88aad29 Harden the xShmLock method of both the unix and Windows VFSes so that they
are robust against being invoked when the SHM file is not open.

FossilOrigin-Name: 67d8b434f628d44c4a90ce8ff5ab2e381f500bb42bdbfab9a17d21925a2ec6cd
2022-03-22 19:41:55 +00:00
drh
6fad5776c0 Make the sqlite3_serialize() and sqlite3_deserialize() interfaces accessible
to loadable extensions.

FossilOrigin-Name: 81f8746bc65828fb91e170393f22f1f4e9c587a8938e8c11b72315fcd6131403
2022-03-22 11:22:55 +00:00
larrybr
b5bb769c27 expose sqlite3_{deserialize,serialize}() in sqlite3ext.h
FossilOrigin-Name: da874180d35aacdeb9c06f5b425e8909d833e2765179c4337854d56b8a624fd5
2022-03-22 03:03:13 +00:00
larrybr
cb0854a380 Create new branch named "extapi-serializing"
FossilOrigin-Name: a1220a2170a09075a42d1d6c4b502ffa7cc92856779b9eb2ecb9e05c09ccedac
2022-03-22 02:53:34 +00:00
drh
a753a3a2be Do not allow an #ifdef inside of an assert(), as gcc tells us that is
not portable.

FossilOrigin-Name: c7a2047e93df36c172be0be773f9a04150dafe7ba1773269d74016418d262fc4
2022-03-21 20:08:13 +00:00
drh
c63e40956b Some branches are no longer reachable after the previous change. Mark them
accordingly.  Also improve comments.

FossilOrigin-Name: 88d69f60cceb22bde42cfe43c23259c7bad47b8e06f918a79bd089a77b480d46
2022-03-21 18:48:31 +00:00
drh
bd5fb3a888 Strengthen the defenses against corrupt databases in the
sqlite3BtreeInsert() function of the btree module.
[forum:/forumpost/c7ec29905f|Forum post c7ec29905f].

FossilOrigin-Name: 4df301c8610c4c36b4eb360d49ccaef873c63ea719ccb14b357754ff0b3ea5ef
2022-03-21 18:17:09 +00:00
drh
67aa2318c1 The previous assert() fix was not correct when building with
-DSQLITE_ENABLE_OFFSET_SQL_FUNC.  This is the fix.

FossilOrigin-Name: c0a4767fef27cfe4fdc1d8a29342998095894769a63d84e37ec47ced7ce4e5f7
2022-03-21 15:42:42 +00:00
drh
75c493f767 Fix the assert() that attempts to verify that the table-reference to
index-reference translator finds all required translations.
[forum:/forumpost/929168fdd6|Forum post 929168fdd6].

FossilOrigin-Name: fa9bd1fce47e8db1cfc4cd8efd2c09f8711ea917ce7d116dc7226c575cb9a6d4
2022-03-21 13:47:15 +00:00
drh
ef07f96faf Fix an assert() in sqlite3TableAffinity() that might have been false if there
was a prior syntax error in the query.

FossilOrigin-Name: 23fdb169ca1622369cd44fd641946c37fef09071625838b3b9c86c31244ed205
2022-03-21 11:32:45 +00:00
drh
9198f5afac In the CLI, disable the zipfile and sqlar extensions in --safe mode.
FossilOrigin-Name: d8b65a2dab97392ff81bcc33ff707b4e626a10d84a258c6452e45f90cd2c7f45
2022-03-19 15:19:35 +00:00
drh
d5c35f6d69 Fix the zipfile extension so that it knows that a zero-length BLOB returns
a NULL pointer.
[forum:/forumpost/ae86934905|Forum post ae86934905].

FossilOrigin-Name: 5f6d56737caefa78e542a7af2f95646e3a818e0ecdd8e838f3c2978500ce960c
2022-03-19 12:48:14 +00:00
drh
389e056bfe Change a conditional into an assert() due to the change in
[387ab17b8a0a4b87].

FossilOrigin-Name: 13b584869f40ea6aa2190dbac64709695ee8d72b27bc5afb8b39ab3763b9c46a
2022-03-17 23:49:58 +00:00
drh
b45e1d674a Add a 4th output code (value 3) from the sqlite3_vtab_distinct() interface
that indicates that SQLite wants distinct results that are sorted.

FossilOrigin-Name: 135d8b97b01f9b5204f486f828c274c2d779c17723e79171ca61f738746adf8e
2022-03-17 22:09:17 +00:00
drh
d6df8550b2 Updates a comment and an assert().
FossilOrigin-Name: 0c5be14aac07222b9cd2404ae485b6587f8cb2899e776bc45f1f1117bdd7e9b7
2022-03-17 18:03:08 +00:00
drh
494317ad57 Another fix for a corner-case in sqlite_offset() - this one having to
do with computed virtual columns in a WITHOUT ROWID table.

FossilOrigin-Name: 84ddd19bcec99f04b43b1a823477457758a2d93ea9beda43598e1234ea07776c
2022-03-17 11:23:13 +00:00
dan
247d09462e Add extra test cases.
FossilOrigin-Name: 0a922d141749cf3ef672f56449001e03f1a7e31822b66dcaf8550bb6e1b88cd3
2022-03-16 19:28:18 +00:00