From f2a777fa5dc5f965d484c737a0b2dfe77a84bf56 Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 22 Feb 2022 20:29:31 +0000 Subject: [PATCH 01/75] For the "PRAGMA database_list" statement, do not check to see if the schema is up-to-date and do not try to reload the schema. FossilOrigin-Name: 710de6a2137c872812effa43ea888aa77d339362ca0b6c8990d4426c8fb20689 --- manifest | 16 +++++++--------- manifest.uuid | 2 +- src/pragma.h | 2 +- tool/mkpragmatab.tcl | 2 +- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index 5ca957c244..1ee93b5f40 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Version\s3.38.0 -D 2022-02-22T18:58:40.488 +C For\sthe\s"PRAGMA\sdatabase_list"\sstatement,\sdo\snot\scheck\sto\ssee\sif\sthe\sschema\nis\sup-to-date\sand\sdo\snot\stry\sto\sreload\sthe\sschema. +D 2022-02-22T20:29:31.035 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -546,7 +546,7 @@ F src/pcache.c 084e638432c610f95aea72b8509f0845d2791293f39d1b82f0c0a7e089c3bb6b F src/pcache.h 4f87acd914cef5016fae3030343540d75f5b85a1877eed1a2a19b9f284248586 F src/pcache1.c 54881292a9a5db202b2c0ac541c5e3ef9a5e8c4f1c1383adb2601d5499a60e65 F src/pragma.c 7c024d690a3dc93f61830f11f900e4af2357f31d081b0c79099ca5e28919cba7 -F src/pragma.h 87330ed2fbfa2a1274de93ca0ab850fba336189228cb256089202c3b52766fad +F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c a187dade741c1f09ae118fcbbf0302511807bfc0355880927d7152eb75b8260d F src/printf.c 05d8dfd2018bc4fc3ddb8b37eb97ccef7abf985643fa1caebdcf2916ca90fa32 F src/random.c 097dc8b31b8fba5a9aca1697aeb9fd82078ec91be734c16bffda620ced7ab83c @@ -1877,7 +1877,7 @@ F tool/mkmsvcmin.tcl 6ecab9fe22c2c8de4d82d4c46797bda3d2deac8e763885f5a38d0c44a89 F tool/mkopcodec.tcl 33d20791e191df43209b77d37f0ff0904620b28465cca6990cf8d60da61a07ef F tool/mkopcodeh.tcl 130b88697da6ec5b89b41844d955d08fb62c2552e889dec8c7bcecb28d8f50bd F tool/mkopts.tcl 680f785fdb09729fd9ac50632413da4eadbdf9071535e3f26d03795828ab07fa -F tool/mkpragmatab.tcl de206c64b6e9ac8cd5e3cbd0ffe456f07d5710605ef8385d677e60ce3335ea12 +F tool/mkpragmatab.tcl bd07bd59d45d0f3448e123d6937e9811195f9908a51e09d774609883055bfd3d F tool/mkshellc.tcl df5d249617f9cc94d5c48eb0401673eb3f31f383ecbc54e8a13ca3dd97e89450 F tool/mksourceid.c 36aa8020014aed0836fd13c51d6dc9219b0df1761d6b5f58ff5b616211b079b9 F tool/mkspeedsql.tcl a1a334d288f7adfe6e996f2e712becf076745c97 @@ -1944,10 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 7e3c9594390ac8defaf9825e14b4c19ef8c123b747971dd3d4df16110f443d3b -R 2222d568cabc2aa5ac864df535d62eb2 -T +sym-release * -T +sym-version-3.38.0 * +P 40fa792d359f84c3b9e9d6623743e1a59826274e221df1bde8f47086968a1bab +R 8e774d76a97f244938c2cd31e6e650dd U drh -Z 2297eaa4fd3e9ed1fd7ae8af6c650431 +Z 87215546f30ba5e5b58306e47d0efae5 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index b9b6e8d9ec..30ca50acbd 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -40fa792d359f84c3b9e9d6623743e1a59826274e221df1bde8f47086968a1bab \ No newline at end of file +710de6a2137c872812effa43ea888aa77d339362ca0b6c8990d4426c8fb20689 \ No newline at end of file diff --git a/src/pragma.h b/src/pragma.h index 6eb05763c8..7270db1db4 100644 --- a/src/pragma.h +++ b/src/pragma.h @@ -251,7 +251,7 @@ static const PragmaName aPragmaName[] = { #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) {/* zName: */ "database_list", /* ePragTyp: */ PragTyp_DATABASE_LIST, - /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0, + /* ePragFlg: */ PragFlg_Result0, /* ColNames: */ 47, 3, /* iArg: */ 0 }, #endif diff --git a/tool/mkpragmatab.tcl b/tool/mkpragmatab.tcl index a8a7ef66be..5c36df0497 100644 --- a/tool/mkpragmatab.tcl +++ b/tool/mkpragmatab.tcl @@ -262,7 +262,7 @@ set pragma_def { IF: !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) NAME: database_list - FLAG: NeedSchema Result0 + FLAG: Result0 COLS: seq name file IF: !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) From 584bfcaeb6bcc7cb1366499f2c31896bfe8597ba Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 23 Feb 2022 17:00:44 +0000 Subject: [PATCH 02/75] Store the page number for the PENDING_BYTE page in the Pager object, rather than computing the page number every time it is needed, because it turns out that number is needed quite frequently. This saves a few hundred thousand CPU cycles and a few bytes of code space. FossilOrigin-Name: 5aa9c3eb45514d5eb7b32696d25a9aeb7dad485e1ea5adb833fac6d1f2105f1a --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/btreeInt.h | 2 +- src/pager.c | 20 +++++++++++--------- src/pager.h | 5 +++-- 5 files changed, 24 insertions(+), 21 deletions(-) diff --git a/manifest b/manifest index 1ee93b5f40..b39cd4588c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C For\sthe\s"PRAGMA\sdatabase_list"\sstatement,\sdo\snot\scheck\sto\ssee\sif\sthe\sschema\nis\sup-to-date\sand\sdo\snot\stry\sto\sreload\sthe\sschema. -D 2022-02-22T20:29:31.035 +C Store\sthe\spage\snumber\sfor\sthe\sPENDING_BYTE\spage\sin\sthe\sPager\sobject,\srather\nthan\scomputing\sthe\spage\snumber\severy\stime\sit\sis\sneeded,\sbecause\sit\sturns\sout\nthat\snumber\sis\sneeded\squite\sfrequently.\s\sThis\ssaves\sa\sfew\shundred\sthousand\nCPU\scycles\sand\sa\sfew\sbytes\sof\scode\sspace. +D 2022-02-23T17:00:44.801 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -494,7 +494,7 @@ F src/bitvec.c 7c849aac407230278445cb069bebc5f89bf2ddd87c5ed9459b070a9175707b3d F src/btmutex.c 8acc2f464ee76324bf13310df5692a262b801808984c1b79defb2503bbafadb6 F src/btree.c 117808943727d27e38c69de4e79237e52c89ee40f6f1a70de4e6e14b5e596cbc F src/btree.h 74d64b8f28cfa4a894d14d4ed64fa432cd697b98b61708d4351482ae15913e22 -F src/btreeInt.h ee9348c4cb9077243b049edc93a82c1f32ca48baeabf2140d41362b9f9139ff7 +F src/btreeInt.h 7282a6e77775f93a6eb78d3a41dab372a01a4ec1d93d3b4728d191d15fda42e2 F src/build.c 9891c2160886cf7e344d7e8f1f7177f9612916c7c67ffeacd64cb34a92d387a8 F src/callback.c 4c19af69835787bfe790ac560f3071a824eb629f34e41f97b52ce5235c77de1c F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e @@ -539,8 +539,8 @@ F src/os_setup.h 0dbaea40a7d36bf311613d31342e0b99e2536586 F src/os_unix.c f5ad51cfd024116db8531feab9efd831c2621436dca1464e4ff1e8af9bf3252e F src/os_win.c 77d39873836f1831a9b0b91894fec45ab0e9ca8e067dc8c549e1d1eca1566fe9 F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a -F src/pager.c cda9e2d1df7c5fb4d777d09e23e69d78c518550d8873ed08b4a66c41d8cf2543 -F src/pager.h 4bf9b3213a4b2bebbced5eaa8b219cf25d4a82f385d093cd64b7e93e5285f66f +F src/pager.c 198e037aa1f945e19cc4b4e89a80a40c31fc6beafacfe068fb3ca88cb602b523 +F src/pager.h f82e9844166e1585f5786837ddc7709966138ced17f568c16af7ccf946c2baa3 F src/parse.y 0f02b27cdaa334441463153fff3ceb780fea006ab53ffd6ef566d4468f93e924 F src/pcache.c 084e638432c610f95aea72b8509f0845d2791293f39d1b82f0c0a7e089c3bb6b F src/pcache.h 4f87acd914cef5016fae3030343540d75f5b85a1877eed1a2a19b9f284248586 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 40fa792d359f84c3b9e9d6623743e1a59826274e221df1bde8f47086968a1bab -R 8e774d76a97f244938c2cd31e6e650dd +P 710de6a2137c872812effa43ea888aa77d339362ca0b6c8990d4426c8fb20689 +R 31db230ec1e00447c3c5dedc2a12edf4 U drh -Z 87215546f30ba5e5b58306e47d0efae5 +Z d8442a86814fe9e42893b593cc0d0a34 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 30ca50acbd..0daec02da3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -710de6a2137c872812effa43ea888aa77d339362ca0b6c8990d4426c8fb20689 \ No newline at end of file +5aa9c3eb45514d5eb7b32696d25a9aeb7dad485e1ea5adb833fac6d1f2105f1a \ No newline at end of file diff --git a/src/btreeInt.h b/src/btreeInt.h index 1076fd8f2c..e038f313e2 100644 --- a/src/btreeInt.h +++ b/src/btreeInt.h @@ -598,7 +598,7 @@ struct BtCursor { /* ** The database page the PENDING_BYTE occupies. This page is never used. */ -# define PENDING_BYTE_PAGE(pBt) PAGER_MJ_PGNO(pBt) +#define PENDING_BYTE_PAGE(pBt) ((Pgno)((PENDING_BYTE/((pBt)->pageSize))+1)) /* ** These macros define the location of the pointer-map entry for a diff --git a/src/pager.c b/src/pager.c index 15bd9a22fe..5d0aa73775 100644 --- a/src/pager.c +++ b/src/pager.c @@ -681,6 +681,7 @@ struct Pager { u32 vfsFlags; /* Flags for sqlite3_vfs.xOpen() */ u32 sectorSize; /* Assumed sector size during rollback */ Pgno mxPgno; /* Maximum allowed size of the database */ + Pgno lckPgno; /* Page number for the locking page */ i64 pageSize; /* Number of bytes in a page */ i64 journalSizeLimit; /* Size limit for persistent journal files */ char *zFilename; /* Name of the database file */ @@ -1667,7 +1668,7 @@ static int readJournalHdr( ** journal file descriptor is advanced to the next sector boundary before ** anything is written. The format is: ** -** + 4 bytes: PAGER_MJ_PGNO. +** + 4 bytes: PAGER_SJ_PGNO. ** + N bytes: super-journal filename in utf-8. ** + 4 bytes: N (length of super-journal name in bytes, no nul-terminator). ** + 4 bytes: super-journal name checksum. @@ -1715,7 +1716,7 @@ static int writeSuperJournal(Pager *pPager, const char *zSuper){ /* Write the super-journal data to the end of the journal file. If ** an error occurs, return the error code to the caller. */ - if( (0 != (rc = write32bits(pPager->jfd, iHdrOff, PAGER_MJ_PGNO(pPager)))) + if( (0 != (rc = write32bits(pPager->jfd, iHdrOff, PAGER_SJ_PGNO(pPager)))) || (0 != (rc = sqlite3OsWrite(pPager->jfd, zSuper, nSuper, iHdrOff+4))) || (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nSuper, nSuper))) || (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nSuper+4, cksum))) @@ -2225,7 +2226,7 @@ static u32 pager_cksum(Pager *pPager, const u8 *aData){ ** corrupted, SQLITE_DONE is returned. Data is considered corrupted in ** two circumstances: ** -** * If the record page-number is illegal (0 or PAGER_MJ_PGNO), or +** * If the record page-number is illegal (0 or PAGER_SJ_PGNO), or ** * If the record is being rolled back from the main journal file ** and the checksum field does not match the record content. ** @@ -2285,7 +2286,7 @@ static int pager_playback_one_page( ** it could cause invalid data to be written into the journal. We need to ** detect this invalid data (with high probability) and ignore it. */ - if( pgno==0 || pgno==PAGER_MJ_PGNO(pPager) ){ + if( pgno==0 || pgno==PAGER_SJ_PGNO(pPager) ){ assert( !isSavepnt ); return SQLITE_DONE; } @@ -3740,6 +3741,7 @@ int sqlite3PagerSetPagesize(Pager *pPager, u32 *pPageSize, int nReserve){ pPager->pTmpSpace = pNew; pPager->dbSize = (Pgno)((nByte+pageSize-1)/pageSize); pPager->pageSize = pageSize; + pPager->lckPgno = (Pgno)(PENDING_BYTE/pageSize) + 1; }else{ sqlite3PageFree(pNew); } @@ -5509,7 +5511,7 @@ static int getPageNormal( if( pPg->pPager && !noContent ){ /* In this case the pcache already contains an initialized copy of ** the page. Return without further ado. */ - assert( pgno!=PAGER_MJ_PGNO(pPager) ); + assert( pgno!=PAGER_SJ_PGNO(pPager) ); pPager->aStat[PAGER_STAT_HIT]++; return SQLITE_OK; @@ -5520,7 +5522,7 @@ static int getPageNormal( ** (*) obsolete. Was: maximum page number is 2^31 ** (2) Never try to fetch the locking page */ - if( pgno==PAGER_MJ_PGNO(pPager) ){ + if( pgno==PAGER_SJ_PGNO(pPager) ){ rc = SQLITE_CORRUPT_BKPT; goto pager_acquire_err; } @@ -5919,7 +5921,7 @@ static SQLITE_NOINLINE int pagerAddPageToRollbackJournal(PgHdr *pPg){ /* We should never write to the journal file the page that ** contains the database locks. The following assert verifies ** that we do not. */ - assert( pPg->pgno!=PAGER_MJ_PGNO(pPager) ); + assert( pPg->pgno!=PAGER_SJ_PGNO(pPager) ); assert( pPager->journalHdr<=pPager->journalOff ); pData2 = pPg->pData; @@ -6098,7 +6100,7 @@ static SQLITE_NOINLINE int pagerWriteLargeSector(PgHdr *pPg){ Pgno pg = pg1+ii; PgHdr *pPage; if( pg==pPg->pgno || !sqlite3BitvecTest(pPager->pInJournal, pg) ){ - if( pg!=PAGER_MJ_PGNO(pPager) ){ + if( pg!=PAGER_SJ_PGNO(pPager) ){ rc = sqlite3PagerGet(pPager, pg, &pPage, 0); if( rc==SQLITE_OK ){ rc = pager_write(pPage); @@ -6576,7 +6578,7 @@ int sqlite3PagerCommitPhaseOne( ** last page is never written out to disk, leaving the database file ** undersized. Fix this now if it is the case. */ if( pPager->dbSize>pPager->dbFileSize ){ - Pgno nNew = pPager->dbSize - (pPager->dbSize==PAGER_MJ_PGNO(pPager)); + Pgno nNew = pPager->dbSize - (pPager->dbSize==PAGER_SJ_PGNO(pPager)); assert( pPager->eState==PAGER_WRITER_DBMOD ); rc = pager_truncate(pPager, nNew); if( rc!=SQLITE_OK ) goto commit_phase_one_exit; diff --git a/src/pager.h b/src/pager.h index 8d899bd1a6..eb1306096c 100644 --- a/src/pager.h +++ b/src/pager.h @@ -43,14 +43,15 @@ typedef struct Pager Pager; typedef struct PgHdr DbPage; /* -** Page number PAGER_MJ_PGNO is never used in an SQLite database (it is +** Page number PAGER_SJ_PGNO is never used in an SQLite database (it is ** reserved for working around a windows/posix incompatibility). It is ** used in the journal to signify that the remainder of the journal file ** is devoted to storing a super-journal name - there are no more pages to ** roll back. See comments for function writeSuperJournal() in pager.c ** for details. */ -#define PAGER_MJ_PGNO(x) ((Pgno)((PENDING_BYTE/((x)->pageSize))+1)) +#define PAGER_SJ_PGNO_COMPUTED(x) ((Pgno)((PENDING_BYTE/((x)->pageSize))+1)) +#define PAGER_SJ_PGNO(x) ((x)->lckPgno) /* ** Allowed values for the flags parameter to sqlite3PagerOpen(). From eac750e9a670fa4493a1939d83d88ae832dfa465 Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 23 Feb 2022 17:16:30 +0000 Subject: [PATCH 03/75] Defer the check for error check Pgno zero until after the page fetch misses, to gain a few CPU cycles and a small size reduction. FossilOrigin-Name: ece326db50201937eb688809df39edc7fb97413b4614d2e2e783418192f7b02a --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/pager.c | 7 +++---- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index b39cd4588c..bde62d44f6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Store\sthe\spage\snumber\sfor\sthe\sPENDING_BYTE\spage\sin\sthe\sPager\sobject,\srather\nthan\scomputing\sthe\spage\snumber\severy\stime\sit\sis\sneeded,\sbecause\sit\sturns\sout\nthat\snumber\sis\sneeded\squite\sfrequently.\s\sThis\ssaves\sa\sfew\shundred\sthousand\nCPU\scycles\sand\sa\sfew\sbytes\sof\scode\sspace. -D 2022-02-23T17:00:44.801 +C Defer\sthe\scheck\sfor\serror\scheck\sPgno\szero\suntil\safter\sthe\spage\sfetch\smisses,\nto\sgain\sa\sfew\sCPU\scycles\sand\sa\ssmall\ssize\sreduction. +D 2022-02-23T17:16:30.735 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -539,7 +539,7 @@ F src/os_setup.h 0dbaea40a7d36bf311613d31342e0b99e2536586 F src/os_unix.c f5ad51cfd024116db8531feab9efd831c2621436dca1464e4ff1e8af9bf3252e F src/os_win.c 77d39873836f1831a9b0b91894fec45ab0e9ca8e067dc8c549e1d1eca1566fe9 F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a -F src/pager.c 198e037aa1f945e19cc4b4e89a80a40c31fc6beafacfe068fb3ca88cb602b523 +F src/pager.c 90a3721b4ab007a835c751a441c1b1fc68bfe68d99dd298f28d91cc163730194 F src/pager.h f82e9844166e1585f5786837ddc7709966138ced17f568c16af7ccf946c2baa3 F src/parse.y 0f02b27cdaa334441463153fff3ceb780fea006ab53ffd6ef566d4468f93e924 F src/pcache.c 084e638432c610f95aea72b8509f0845d2791293f39d1b82f0c0a7e089c3bb6b @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 710de6a2137c872812effa43ea888aa77d339362ca0b6c8990d4426c8fb20689 -R 31db230ec1e00447c3c5dedc2a12edf4 +P 5aa9c3eb45514d5eb7b32696d25a9aeb7dad485e1ea5adb833fac6d1f2105f1a +R 4a7be174abec3b1bd75c937cba4c1ec2 U drh -Z d8442a86814fe9e42893b593cc0d0a34 +Z 8b433f90acbe3d610b55829e1edc78df # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 0daec02da3..12eedaa720 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5aa9c3eb45514d5eb7b32696d25a9aeb7dad485e1ea5adb833fac6d1f2105f1a \ No newline at end of file +ece326db50201937eb688809df39edc7fb97413b4614d2e2e783418192f7b02a \ No newline at end of file diff --git a/src/pager.c b/src/pager.c index 5d0aa73775..c1866cac11 100644 --- a/src/pager.c +++ b/src/pager.c @@ -5491,7 +5491,6 @@ static int getPageNormal( assert( assert_pager_state(pPager) ); assert( pPager->hasHeldSharedLock==1 ); - if( pgno==0 ) return SQLITE_CORRUPT_BKPT; pBase = sqlite3PcacheFetch(pPager->pPCache, pgno, 3); if( pBase==0 ){ pPg = 0; @@ -5519,10 +5518,10 @@ static int getPageNormal( /* The pager cache has created a new page. Its content needs to ** be initialized. But first some error checks: ** - ** (*) obsolete. Was: maximum page number is 2^31 - ** (2) Never try to fetch the locking page + ** (1) Never try to fetch the locking page + ** (2) Never try to fetch page 0, which does not exist */ - if( pgno==PAGER_SJ_PGNO(pPager) ){ + if( pgno==PAGER_SJ_PGNO(pPager) || pgno==0 ){ rc = SQLITE_CORRUPT_BKPT; goto pager_acquire_err; } From 009a48e0ad49f82b63d7f4ee1dc63256b6cb4738 Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 23 Feb 2022 18:23:15 +0000 Subject: [PATCH 04/75] Optimize calls to get2byte() in btree.c for almost a one-million cycle performance gain and a few bytes less code. FossilOrigin-Name: 41061f29969dc546c2702f7f412127070a4dd54593827692df93a83c939dfb61 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/btree.c | 17 ++++++++++++----- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index bde62d44f6..65aab7e507 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Defer\sthe\scheck\sfor\serror\scheck\sPgno\szero\suntil\safter\sthe\spage\sfetch\smisses,\nto\sgain\sa\sfew\sCPU\scycles\sand\sa\ssmall\ssize\sreduction. -D 2022-02-23T17:16:30.735 +C Optimize\scalls\sto\sget2byte()\sin\sbtree.c\sfor\salmost\sa\sone-million\scycle\nperformance\sgain\sand\sa\sfew\sbytes\sless\scode. +D 2022-02-23T18:23:15.914 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -492,7 +492,7 @@ F src/auth.c f4fa91b6a90bbc8e0d0f738aa284551739c9543a367071f55574681e0f24f8cf F src/backup.c a2891172438e385fdbe97c11c9745676bec54f518d4447090af97189fd8e52d7 F src/bitvec.c 7c849aac407230278445cb069bebc5f89bf2ddd87c5ed9459b070a9175707b3d F src/btmutex.c 8acc2f464ee76324bf13310df5692a262b801808984c1b79defb2503bbafadb6 -F src/btree.c 117808943727d27e38c69de4e79237e52c89ee40f6f1a70de4e6e14b5e596cbc +F src/btree.c 35870e7059b2b5bd90b0e1ac482b632b41a81dbb9b466bc7c9f3e4086571391c F src/btree.h 74d64b8f28cfa4a894d14d4ed64fa432cd697b98b61708d4351482ae15913e22 F src/btreeInt.h 7282a6e77775f93a6eb78d3a41dab372a01a4ec1d93d3b4728d191d15fda42e2 F src/build.c 9891c2160886cf7e344d7e8f1f7177f9612916c7c67ffeacd64cb34a92d387a8 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 5aa9c3eb45514d5eb7b32696d25a9aeb7dad485e1ea5adb833fac6d1f2105f1a -R 4a7be174abec3b1bd75c937cba4c1ec2 +P ece326db50201937eb688809df39edc7fb97413b4614d2e2e783418192f7b02a +R 1c57a2dcd8f8c477175cc03c1d736930 U drh -Z 8b433f90acbe3d610b55829e1edc78df +Z 34e99039e8cc6255862cb2a477919b3e # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 12eedaa720..3d1ba05042 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ece326db50201937eb688809df39edc7fb97413b4614d2e2e783418192f7b02a \ No newline at end of file +41061f29969dc546c2702f7f412127070a4dd54593827692df93a83c939dfb61 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index fb7f025a16..1d3acdc51d 100644 --- a/src/btree.c +++ b/src/btree.c @@ -1586,7 +1586,8 @@ static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc){ const int hdr = pPg->hdrOffset; /* Offset to page header */ u8 * const aData = pPg->aData; /* Page data */ int iAddr = hdr + 1; /* Address of ptr to pc */ - int pc = get2byte(&aData[iAddr]); /* Address of a free slot */ + u8 *pTmp = &aData[iAddr]; /* Temporary ptr into aData[] */ + int pc = get2byte(pTmp); /* Address of a free slot */ int x; /* Excess size of the slot */ int maxPC = pPg->pBt->usableSize - nByte; /* Max address for a usable slot */ int size; /* Size of the free slot */ @@ -1596,7 +1597,8 @@ static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc){ /* EVIDENCE-OF: R-22710-53328 The third and fourth bytes of each ** freeblock form a big-endian integer which is the size of the freeblock ** in bytes, including the 4-byte header. */ - size = get2byte(&aData[pc+2]); + pTmp = &aData[pc+2]; + size = get2byte(pTmp); if( (x = size - nByte)>=0 ){ testcase( x==4 ); testcase( x==3 ); @@ -1621,7 +1623,8 @@ static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc){ return &aData[pc + x]; } iAddr = pc; - pc = get2byte(&aData[pc]); + pTmp = &aData[pc]; + pc = get2byte(pTmp); if( pc<=iAddr+size ){ if( pc ){ /* The next slot in the chain is not past the end of the current slot */ @@ -1655,6 +1658,7 @@ static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){ u8 * const data = pPage->aData; /* Local cache of pPage->aData */ int top; /* First byte of cell content area */ int rc = SQLITE_OK; /* Integer return code */ + u8 *pTmp; /* Temp ptr into data[] */ int gap; /* First byte of gap between cell pointers and cell content */ assert( sqlite3PagerIswriteable(pPage->pDbPage) ); @@ -1673,7 +1677,8 @@ static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){ ** then the cell content offset of an empty page wants to be 65536. ** However, that integer is too large to be stored in a 2-byte unsigned ** integer, so a value of 0 is used in its place. */ - top = get2byte(&data[hdr+5]); + pTmp = &data[hdr+5]; + top = get2byte(pTmp); assert( top<=(int)pPage->pBt->usableSize ); /* by btreeComputeFreeSpace() */ if( gap>top ){ if( top==0 && pPage->pBt->usableSize==65536 ){ @@ -1755,6 +1760,7 @@ static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){ u16 x; /* Offset to cell content area */ u32 iEnd = iStart + iSize; /* First byte past the iStart buffer */ unsigned char *data = pPage->aData; /* Page content */ + u8 *pTmp; /* Temporary ptr into data[] */ assert( pPage->pBt!=0 ); assert( sqlite3PagerIswriteable(pPage->pDbPage) ); @@ -1817,7 +1823,8 @@ static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){ if( nFrag>data[hdr+7] ) return SQLITE_CORRUPT_PAGE(pPage); data[hdr+7] -= nFrag; } - x = get2byte(&data[hdr+5]); + pTmp = &data[hdr+5]; + x = get2byte(pTmp); if( iStart<=x ){ /* The new freeblock is at the beginning of the cell content area, ** so just extend the cell content area rather than create another From 19ae01be130ffb706dc0a095683ee13d0524d6cf Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 23 Feb 2022 22:56:10 +0000 Subject: [PATCH 05/75] Add a new subclass for MemPage.xCellSize specifically for the case of a leaf page in a B+Tree, that is optimized for that cases. This gains a half million cycles or more at the cost of less than 200 bytes of code space. FossilOrigin-Name: 7ad829224adbec5d74ff9e5ab040eb2ad3e17fe45da7a2cf0cca770a0731401a --- manifest | 12 +++++----- manifest.uuid | 2 +- src/btree.c | 63 ++++++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 62 insertions(+), 15 deletions(-) diff --git a/manifest b/manifest index 65aab7e507..3c1e65c5d2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Optimize\scalls\sto\sget2byte()\sin\sbtree.c\sfor\salmost\sa\sone-million\scycle\nperformance\sgain\sand\sa\sfew\sbytes\sless\scode. -D 2022-02-23T18:23:15.914 +C Add\sa\snew\ssubclass\sfor\sMemPage.xCellSize\sspecifically\sfor\sthe\scase\sof\sa\sleaf\npage\sin\sa\sB+Tree,\sthat\sis\soptimized\sfor\sthat\scases.\s\sThis\sgains\sa\shalf\smillion\ncycles\sor\smore\sat\sthe\scost\sof\sless\sthan\s200\sbytes\sof\scode\sspace. +D 2022-02-23T22:56:10.399 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -492,7 +492,7 @@ F src/auth.c f4fa91b6a90bbc8e0d0f738aa284551739c9543a367071f55574681e0f24f8cf F src/backup.c a2891172438e385fdbe97c11c9745676bec54f518d4447090af97189fd8e52d7 F src/bitvec.c 7c849aac407230278445cb069bebc5f89bf2ddd87c5ed9459b070a9175707b3d F src/btmutex.c 8acc2f464ee76324bf13310df5692a262b801808984c1b79defb2503bbafadb6 -F src/btree.c 35870e7059b2b5bd90b0e1ac482b632b41a81dbb9b466bc7c9f3e4086571391c +F src/btree.c 50a8f846a1cad4e903aa31afe94df6ec329ac0cafba12977dcb7fc8b076a57d0 F src/btree.h 74d64b8f28cfa4a894d14d4ed64fa432cd697b98b61708d4351482ae15913e22 F src/btreeInt.h 7282a6e77775f93a6eb78d3a41dab372a01a4ec1d93d3b4728d191d15fda42e2 F src/build.c 9891c2160886cf7e344d7e8f1f7177f9612916c7c67ffeacd64cb34a92d387a8 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P ece326db50201937eb688809df39edc7fb97413b4614d2e2e783418192f7b02a -R 1c57a2dcd8f8c477175cc03c1d736930 +P 41061f29969dc546c2702f7f412127070a4dd54593827692df93a83c939dfb61 +R 0695953d4b2e50c110a18d3aed9c37a6 U drh -Z 34e99039e8cc6255862cb2a477919b3e +Z dd86536eafbb7b97b20458522e864263 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 3d1ba05042..56a9ce0972 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -41061f29969dc546c2702f7f412127070a4dd54593827692df93a83c939dfb61 \ No newline at end of file +7ad829224adbec5d74ff9e5ab040eb2ad3e17fe45da7a2cf0cca770a0731401a \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 1d3acdc51d..25bf8eaf9b 100644 --- a/src/btree.c +++ b/src/btree.c @@ -1327,6 +1327,7 @@ static void btreeParseCell( ** the space used by the cell pointer. ** ** cellSizePtrNoPayload() => table internal nodes +** cellSizePtrTableLeaf() => table leaf nodes ** cellSizePtr() => all index nodes & table leaf nodes */ static u16 cellSizePtr(MemPage *pPage, u8 *pCell){ @@ -1352,13 +1353,6 @@ static u16 cellSizePtr(MemPage *pPage, u8 *pCell){ }while( *(pIter)>=0x80 && pIterintKey ){ - /* pIter now points at the 64-bit integer key value, a variable length - ** integer. The following block moves pIter to point at the first byte - ** past the end of the key value. */ - pEnd = &pIter[9]; - while( (*pIter++)&0x80 && pItermaxLocal ); testcase( nSize==(u32)pPage->maxLocal+1 ); if( nSize<=pPage->maxLocal ){ @@ -1398,6 +1392,58 @@ static u16 cellSizePtrNoPayload(MemPage *pPage, u8 *pCell){ assert( debuginfo.nSize==(u16)(pIter - pCell) || CORRUPT_DB ); return (u16)(pIter - pCell); } +static u16 cellSizePtrTableLeaf(MemPage *pPage, u8 *pCell){ + u8 *pIter = pCell; /* For looping over bytes of pCell */ + u8 *pEnd; /* End mark for a varint */ + u32 nSize; /* Size value to return */ + +#ifdef SQLITE_DEBUG + /* The value returned by this function should always be the same as + ** the (CellInfo.nSize) value found by doing a full parse of the + ** cell. If SQLITE_DEBUG is defined, an assert() at the bottom of + ** this function verifies that this invariant is not violated. */ + CellInfo debuginfo; + pPage->xParseCell(pPage, pCell, &debuginfo); +#endif + + nSize = *pIter; + if( nSize>=0x80 ){ + pEnd = &pIter[8]; + nSize &= 0x7f; + do{ + nSize = (nSize<<7) | (*++pIter & 0x7f); + }while( *(pIter)>=0x80 && pItermaxLocal ); + testcase( nSize==(u32)pPage->maxLocal+1 ); + if( nSize<=pPage->maxLocal ){ + nSize += (u32)(pIter - pCell); + if( nSize<4 ) nSize = 4; + }else{ + int minLocal = pPage->minLocal; + nSize = minLocal + (nSize - minLocal) % (pPage->pBt->usableSize - 4); + testcase( nSize==pPage->maxLocal ); + testcase( nSize==(u32)pPage->maxLocal+1 ); + if( nSize>pPage->maxLocal ){ + nSize = minLocal; + } + nSize += 4 + (u16)(pIter - pCell); + } + assert( nSize==debuginfo.nSize || CORRUPT_DB ); + return (u16)nSize; +} #ifdef SQLITE_DEBUG @@ -1880,6 +1926,7 @@ static int decodeFlags(MemPage *pPage, int flagByte){ pPage->intKey = 1; if( pPage->leaf ){ pPage->intKeyLeaf = 1; + pPage->xCellSize = cellSizePtrTableLeaf; pPage->xParseCell = btreeParseCellPtr; }else{ pPage->intKeyLeaf = 0; @@ -9310,7 +9357,7 @@ int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){ bPreserve = (flags & BTREE_SAVEPOSITION)!=0; if( bPreserve ){ if( !pPage->leaf - || (pPage->nFree+cellSizePtr(pPage,pCell)+2)>(int)(pBt->usableSize*2/3) + || (pPage->nFree+pPage->xCellSize(pPage,pCell)+2)>(int)(pBt->usableSize*2/3) || pPage->nCell==1 /* See dbfuzz001.test for a test case */ ){ /* A b-tree rebalance will be required after deleting this entry. From fc4fe5a83776eed1013cee2c57db9dfad685d983 Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 24 Feb 2022 01:08:53 +0000 Subject: [PATCH 06/75] Update the version number of version 3.39.0 for the next development cycle. FossilOrigin-Name: 9542e9bebbd25b20228fa2366b76d55845a40f12fdc4bbd077d1cb48e32b8cf2 --- VERSION | 2 +- configure | 18 +++++++++--------- manifest | 14 +++++++------- manifest.uuid | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/VERSION b/VERSION index 4f7d6a223d..4a8c3b9681 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.38.0 +3.39.0 diff --git a/configure b/configure index abb182d5eb..c5d122423d 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for sqlite 3.38.0. +# Generated by GNU Autoconf 2.69 for sqlite 3.39.0. # # # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. @@ -726,8 +726,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='sqlite' PACKAGE_TARNAME='sqlite' -PACKAGE_VERSION='3.38.0' -PACKAGE_STRING='sqlite 3.38.0' +PACKAGE_VERSION='3.39.0' +PACKAGE_STRING='sqlite 3.39.0' PACKAGE_BUGREPORT='' PACKAGE_URL='' @@ -1468,7 +1468,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures sqlite 3.38.0 to adapt to many kinds of systems. +\`configure' configures sqlite 3.39.0 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1533,7 +1533,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of sqlite 3.38.0:";; + short | recursive ) echo "Configuration of sqlite 3.39.0:";; esac cat <<\_ACEOF @@ -1661,7 +1661,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -sqlite configure 3.38.0 +sqlite configure 3.39.0 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -2080,7 +2080,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by sqlite $as_me 3.38.0, which was +It was created by sqlite $as_me 3.39.0, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -12390,7 +12390,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by sqlite $as_me 3.38.0, which was +This file was extended by sqlite $as_me 3.39.0, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -12456,7 +12456,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -sqlite config.status 3.38.0 +sqlite config.status 3.39.0 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" diff --git a/manifest b/manifest index 3c1e65c5d2..e3e9f526e5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sa\snew\ssubclass\sfor\sMemPage.xCellSize\sspecifically\sfor\sthe\scase\sof\sa\sleaf\npage\sin\sa\sB+Tree,\sthat\sis\soptimized\sfor\sthat\scases.\s\sThis\sgains\sa\shalf\smillion\ncycles\sor\smore\sat\sthe\scost\sof\sless\sthan\s200\sbytes\sof\scode\sspace. -D 2022-02-23T22:56:10.399 +C Update\sthe\sversion\snumber\sof\sversion\s3.39.0\sfor\sthe\snext\sdevelopment\scycle. +D 2022-02-24T01:08:53.800 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -7,7 +7,7 @@ F Makefile.in b210ad2733317f1a4353085dfb9d385ceec30b0e6a61d20a5accabecac6b1949 F Makefile.linux-gcc f609543700659711fbd230eced1f01353117621dccae7b9fb70daa64236c5241 F Makefile.msc b28a8a7a977e7312f6859f560348e1eb110c21bd6cf9fab0d16537c0a514eef3 F README.md 2dd87a5c1d108b224921f3dd47dea567973f706e1f6959386282a626f459a70c -F VERSION 392c2f83569705069415a5d98b1c138ec8fe8a56a663a0d94cea019e806537b2 +F VERSION fa8e7d2d1cc962f9e14c6d410387cf75860ee139462763fda887c1be4261f824 F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50 F art/sqlite370.eps aa97a671332b432a54e1d74ff5e8775be34200c2 F art/sqlite370.ico af56c1d00fee7cd4753e8631ed60703ed0fc6e90 @@ -34,7 +34,7 @@ F autoconf/tea/win/rules.vc c511f222b80064096b705dbeb97060ee1d6b6d63 F config.guess 883205ddf25b46f10c181818bf42c09da9888884af96f79e1719264345053bd6 F config.h.in 6376abec766e9a0785178b1823b5a587e9f1ccbc F config.sub c2d0260f17f3e4bc0b6808fccf1b291cb5e9126c14fc5890efc77b9fd0175559 -F configure a2877fe63cc821af0df41abe70f1f7c4e97cb7e23a42e0a1402e8a2f55a88aa2 x +F configure 00378d14cca0ce02fa9eca28fd494789c2eda7d10d86003a5f9a42f34b0af418 x F configure.ac 3ef6eeff4387585bfcab76b0c3f6e15a0618587bb90245dd5d44e4378141bb35 F contrib/sqlitecon.tcl 210a913ad63f9f991070821e599d600bd913e0ad F doc/F2FS.txt c1d4a0ae9711cfe0e1d8b019d154f1c29e0d3abfe820787ba1e9ed7691160fcd @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 41061f29969dc546c2702f7f412127070a4dd54593827692df93a83c939dfb61 -R 0695953d4b2e50c110a18d3aed9c37a6 +P 7ad829224adbec5d74ff9e5ab040eb2ad3e17fe45da7a2cf0cca770a0731401a +R bb2ca2b22fef0360a3282231ca50752e U drh -Z dd86536eafbb7b97b20458522e864263 +Z 21720323eb2a9807a637b350c35e01d5 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 56a9ce0972..9df7be6c20 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7ad829224adbec5d74ff9e5ab040eb2ad3e17fe45da7a2cf0cca770a0731401a \ No newline at end of file +9542e9bebbd25b20228fa2366b76d55845a40f12fdc4bbd077d1cb48e32b8cf2 \ No newline at end of file From cdc59c82ad43f741274d8ca20203b1195c8a62ac Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 24 Feb 2022 01:41:14 +0000 Subject: [PATCH 07/75] Fix an assert() so that it is still valid following OOM with the latest enhancements. FossilOrigin-Name: ecf832f71fbaee36ee10f6da5bde19a8af9f90adbba06e8c5706d18b768bae1f --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/btree.c | 4 +++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index e3e9f526e5..8a2a1734ba 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Update\sthe\sversion\snumber\sof\sversion\s3.39.0\sfor\sthe\snext\sdevelopment\scycle. -D 2022-02-24T01:08:53.800 +C Fix\san\sassert()\sso\sthat\sit\sis\sstill\svalid\sfollowing\sOOM\swith\sthe\slatest\nenhancements. +D 2022-02-24T01:41:14.942 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -492,7 +492,7 @@ F src/auth.c f4fa91b6a90bbc8e0d0f738aa284551739c9543a367071f55574681e0f24f8cf F src/backup.c a2891172438e385fdbe97c11c9745676bec54f518d4447090af97189fd8e52d7 F src/bitvec.c 7c849aac407230278445cb069bebc5f89bf2ddd87c5ed9459b070a9175707b3d F src/btmutex.c 8acc2f464ee76324bf13310df5692a262b801808984c1b79defb2503bbafadb6 -F src/btree.c 50a8f846a1cad4e903aa31afe94df6ec329ac0cafba12977dcb7fc8b076a57d0 +F src/btree.c 11dfaa11397d415fe760ed96d447a1d0cd50db8bd1ee11a91c81a97e364f648c F src/btree.h 74d64b8f28cfa4a894d14d4ed64fa432cd697b98b61708d4351482ae15913e22 F src/btreeInt.h 7282a6e77775f93a6eb78d3a41dab372a01a4ec1d93d3b4728d191d15fda42e2 F src/build.c 9891c2160886cf7e344d7e8f1f7177f9612916c7c67ffeacd64cb34a92d387a8 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 7ad829224adbec5d74ff9e5ab040eb2ad3e17fe45da7a2cf0cca770a0731401a -R bb2ca2b22fef0360a3282231ca50752e +P 9542e9bebbd25b20228fa2366b76d55845a40f12fdc4bbd077d1cb48e32b8cf2 +R 83fc7b1d5ad52a1020e03f9e6b22b358 U drh -Z 21720323eb2a9807a637b350c35e01d5 +Z 0b7f17dc3bbf2617bd43295134016fde # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 9df7be6c20..d8d9052175 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9542e9bebbd25b20228fa2366b76d55845a40f12fdc4bbd077d1cb48e32b8cf2 \ No newline at end of file +ecf832f71fbaee36ee10f6da5bde19a8af9f90adbba06e8c5706d18b768bae1f \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 25bf8eaf9b..288a141ec6 100644 --- a/src/btree.c +++ b/src/btree.c @@ -2303,7 +2303,9 @@ getAndInitPage_error1: pCur->pPage = pCur->apPage[pCur->iPage]; } testcase( pgno==0 ); - assert( pgno!=0 || rc==SQLITE_CORRUPT ); + assert( pgno!=0 || rc==SQLITE_CORRUPT + || rc==SQLITE_IOERR_NOMEM + || rc==SQLITE_NOMEM ); return rc; } From b2d594a19b66c482329f6eb7a2b5ac4c28e2da30 Mon Sep 17 00:00:00 2001 From: larrybr Date: Thu, 24 Feb 2022 11:09:08 +0000 Subject: [PATCH 08/75] Spell fix, no code change FossilOrigin-Name: f2597fae3c2b8f77f98a3ba9420b309f649b4008f9530d3cfaeeba1e2bf5d8a3 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/sqlite.h.in | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 8a2a1734ba..cdaffb3a86 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\san\sassert()\sso\sthat\sit\sis\sstill\svalid\sfollowing\sOOM\swith\sthe\slatest\nenhancements. -D 2022-02-24T01:41:14.942 +C Spell\sfix,\sno\scode\schange +D 2022-02-24T11:09:08.525 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -554,7 +554,7 @@ F src/resolve.c ea935b87d6fb36c78b70cdc7b28561dc8f33f2ef37048389549c7b5ef9b0ba5e F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92 F src/select.c 3baa9dd8cf240654773c7974e2bcce398ac9dd24419c36684156963defe43b35 F src/shell.c.in 14cdfba32c73cb06169e50cd448632c28359f2bab2a0f803dc4a7f46dfc5b6fa -F src/sqlite.h.in e30cedf008d9c51511f4027a3739b727a588da553424748b48d2393f85dbde41 +F src/sqlite.h.in e82ac380b307659d0892f502b742f825504e78729f4edaadce946003b9c00816 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h a95cb9ed106e3d39e2118e4dcc15a14faec3fa50d0093425083d340d9dfd96e6 F src/sqliteInt.h f8814239fb1f95056555e2d7fa475750e64681cac4221fb03610d1fde0b79d53 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 9542e9bebbd25b20228fa2366b76d55845a40f12fdc4bbd077d1cb48e32b8cf2 -R 83fc7b1d5ad52a1020e03f9e6b22b358 -U drh -Z 0b7f17dc3bbf2617bd43295134016fde +P ecf832f71fbaee36ee10f6da5bde19a8af9f90adbba06e8c5706d18b768bae1f +R 9a1c1f565cb49075ff57da0847a15219 +U larrybr +Z 2e93185395e97365671553cf23deb2d5 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d8d9052175..667a1935ff 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ecf832f71fbaee36ee10f6da5bde19a8af9f90adbba06e8c5706d18b768bae1f \ No newline at end of file +f2597fae3c2b8f77f98a3ba9420b309f649b4008f9530d3cfaeeba1e2bf5d8a3 \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index bc1db4609f..97ffcd88cc 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -9767,7 +9767,7 @@ int sqlite3_vtab_in_next(sqlite3_value *pVal, sqlite3_value **ppOut); ** ^When xBestIndex returns, the sqlite3_value object returned by ** sqlite3_vtab_rhs_value() is automatically deallocated. ** -** The "_rhs_" in the name of this routine is an appreviation for +** The "_rhs_" in the name of this routine is an abbreviation for ** "Right-Hand Side". */ int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value **ppVal); From a7c9dd546b96db946d8d3219da96d19c4c1ed2f2 Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 24 Feb 2022 14:44:23 +0000 Subject: [PATCH 09/75] Change the OP_Next and OP_Prev opcodes so that they invoke sqlite3BtreeNext() and sqlite3BtreePrevious() directly rather than through a function pointer, for improved performance and a decrease in code size. FossilOrigin-Name: 9d13cbbef3cf64f281d3e100f23f1b2ed6e8d65920c7517a84e1e4f964ceff2e --- manifest | 20 ++++++++++---------- manifest.uuid | 2 +- src/vdbe.c | 37 +++++++++++++++++-------------------- src/vdbe.h | 3 +-- src/vdbeaux.c | 24 ++---------------------- tool/mkopcodeh.tcl | 3 --- 6 files changed, 31 insertions(+), 58 deletions(-) diff --git a/manifest b/manifest index cdaffb3a86..37e367f783 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Spell\sfix,\sno\scode\schange -D 2022-02-24T11:09:08.525 +C Change\sthe\sOP_Next\sand\sOP_Prev\sopcodes\sso\sthat\sthey\sinvoke\nsqlite3BtreeNext()\sand\ssqlite3BtreePrevious()\sdirectly\srather\sthan\sthrough\na\sfunction\spointer,\sfor\simproved\sperformance\sand\sa\sdecrease\sin\scode\ssize. +D 2022-02-24T14:44:23.869 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -624,11 +624,11 @@ F src/upsert.c 8789047a8f0a601ea42fa0256d1ba3190c13746b6ba940fe2d25643a7e991937 F src/utf.c ee39565f0843775cc2c81135751ddd93eceb91a673ea2c57f61c76f288b041a0 F src/util.c 602fe229f32a96ceccae4f40824129669582096f7c355f53dbac156c9fecef23 F src/vacuum.c 6c38ddc52f0619865c91dae9c441d4d48bf3040d7dc1bc5b22da1e45547ed0b3 -F src/vdbe.c e179d2d6551c6cc3dda7f6f233f9fe3d3c8da2f9bfc46eaabb4b54dc4337d3cf -F src/vdbe.h 25dabb25c7e157b84e59260cfb5b466c3ac103ede9f36f4db371332c47601abe +F src/vdbe.c 5ff8a23c52b38a25f5b8ae398c0a787aff6fdf49e60e675915614022862a4a0a +F src/vdbe.h 40b26aa28d9af2ebb5a444416079688f7a9c584a7e4084164fd720f9a6bebcd2 F src/vdbeInt.h b45599a2b59f1ce042512ab6786b0b82a8cf3002f6b0fa60b4834e2cd3ac61d8 F src/vdbeapi.c 8863ffb5a7bac42fe9a68aaa3526ee29fc18fb02a9b27188b756de41e33856e9 -F src/vdbeaux.c 0d7659fe8cb38ce86092b9bc5131c99a834a04eb78745e54acb77d79d7af2fb5 +F src/vdbeaux.c 7c45a49f51d903488a8189b698adc4a61a3884bc176b6a86b1fd6d5d79f408f5 F src/vdbeblob.c 5e61ce31aca17db8fb60395407457a8c1c7fb471dde405e0cd675974611dcfcd F src/vdbemem.c 7737f0b1c480a32b057849c804d2f21d5389649bb8be80f77ad75df700adc9a1 F src/vdbesort.c 43756031ca7430f7aec3ef904824a7883c4ede783e51f280d99b9b65c0796e35 @@ -1875,7 +1875,7 @@ F tool/mkctimec.tcl 3147e9dfc4ad774e94f80084789ebaada9da9b6e66ddab16438cfc07999b F tool/mkkeywordhash.c 35bfc41adacc4aa6ef6fca7fd0c63e0ec0534b78daf4d0cfdebe398216bbffc3 F tool/mkmsvcmin.tcl 6ecab9fe22c2c8de4d82d4c46797bda3d2deac8e763885f5a38d0c44a895ab33 F tool/mkopcodec.tcl 33d20791e191df43209b77d37f0ff0904620b28465cca6990cf8d60da61a07ef -F tool/mkopcodeh.tcl 130b88697da6ec5b89b41844d955d08fb62c2552e889dec8c7bcecb28d8f50bd +F tool/mkopcodeh.tcl 5dab48c49a25452257494e9601702ab63adaba6bd54a9b382615fa52661c8f8c F tool/mkopts.tcl 680f785fdb09729fd9ac50632413da4eadbdf9071535e3f26d03795828ab07fa F tool/mkpragmatab.tcl bd07bd59d45d0f3448e123d6937e9811195f9908a51e09d774609883055bfd3d F tool/mkshellc.tcl df5d249617f9cc94d5c48eb0401673eb3f31f383ecbc54e8a13ca3dd97e89450 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P ecf832f71fbaee36ee10f6da5bde19a8af9f90adbba06e8c5706d18b768bae1f -R 9a1c1f565cb49075ff57da0847a15219 -U larrybr -Z 2e93185395e97365671553cf23deb2d5 +P f2597fae3c2b8f77f98a3ba9420b309f649b4008f9530d3cfaeeba1e2bf5d8a3 +R c4f84c0b82c6a47f3e7bc22716270649 +U drh +Z 3e76345e3d38fad9e71118178b08dd0f # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 667a1935ff..b93321a07f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f2597fae3c2b8f77f98a3ba9420b309f649b4008f9530d3cfaeeba1e2bf5d8a3 \ No newline at end of file +9d13cbbef3cf64f281d3e100f23f1b2ed6e8d65920c7517a84e1e4f964ceff2e \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index 83cf382213..19e9156030 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -5888,7 +5888,7 @@ case OP_Rewind: { /* jump */ break; } -/* Opcode: Next P1 P2 P3 P4 P5 +/* Opcode: Next P1 P2 P3 * P5 ** ** Advance cursor P1 so that it points to the next key/data pair in its ** table or index. If there are no more key/value pairs then fall through @@ -5907,15 +5907,12 @@ case OP_Rewind: { /* jump */ ** omitted if that index had been unique. P3 is usually 0. P3 is ** always either 0 or 1. ** -** P4 is always of type P4_ADVANCE. The function pointer points to -** sqlite3BtreeNext(). -** ** If P5 is positive and the jump is taken, then event counter ** number P5-1 in the prepared statement is incremented. ** ** See also: Prev */ -/* Opcode: Prev P1 P2 P3 P4 P5 +/* Opcode: Prev P1 P2 P3 * P5 ** ** Back up cursor P1 so that it points to the previous key/data pair in its ** table or index. If there is no previous key/value pairs then fall through @@ -5935,9 +5932,6 @@ case OP_Rewind: { /* jump */ ** omitted if that index had been unique. P3 is usually 0. P3 is ** always either 0 or 1. ** -** P4 is always of type P4_ADVANCE. The function pointer points to -** sqlite3BtreePrevious(). -** ** If P5 is positive and the jump is taken, then event counter ** number P5-1 in the prepared statement is incremented. */ @@ -5955,7 +5949,20 @@ case OP_SorterNext: { /* jump */ assert( isSorter(pC) ); rc = sqlite3VdbeSorterNext(db, pC); goto next_tail; + case OP_Prev: /* jump */ + assert( pOp->p1>=0 && pOp->p1nCursor ); + assert( pOp->p5aCounter) ); + pC = p->apCsr[pOp->p1]; + assert( pC!=0 ); + assert( pC->deferredMoveto==0 ); + assert( pC->eCurType==CURTYPE_BTREE ); + assert( pC->seekOp==OP_SeekLT || pC->seekOp==OP_SeekLE + || pC->seekOp==OP_Last || pC->seekOp==OP_IfNoHope + || pC->seekOp==OP_NullRow); + rc = sqlite3BtreePrevious(pC->uc.pCursor, pOp->p3); + goto next_tail; + case OP_Next: /* jump */ assert( pOp->p1>=0 && pOp->p1nCursor ); assert( pOp->p5aCounter) ); @@ -5963,22 +5970,12 @@ case OP_Next: /* jump */ assert( pC!=0 ); assert( pC->deferredMoveto==0 ); assert( pC->eCurType==CURTYPE_BTREE ); - assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext ); - assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious ); - - /* The Next opcode is only used after SeekGT, SeekGE, Rewind, and Found. - ** The Prev opcode is only used after SeekLT, SeekLE, and Last. */ - assert( pOp->opcode!=OP_Next - || pC->seekOp==OP_SeekGT || pC->seekOp==OP_SeekGE + assert( pC->seekOp==OP_SeekGT || pC->seekOp==OP_SeekGE || pC->seekOp==OP_Rewind || pC->seekOp==OP_Found || pC->seekOp==OP_NullRow|| pC->seekOp==OP_SeekRowid || pC->seekOp==OP_IfNoHope); - assert( pOp->opcode!=OP_Prev - || pC->seekOp==OP_SeekLT || pC->seekOp==OP_SeekLE - || pC->seekOp==OP_Last || pC->seekOp==OP_IfNoHope - || pC->seekOp==OP_NullRow); + rc = sqlite3BtreeNext(pC->uc.pCursor, pOp->p3); - rc = pOp->p4.xAdvance(pC->uc.pCursor, pOp->p3); next_tail: pC->cacheStatus = CACHE_STALE; VdbeBranchTaken(rc==SQLITE_OK,2); diff --git a/src/vdbe.h b/src/vdbe.h index 3257ff68a1..d917ebf268 100644 --- a/src/vdbe.h +++ b/src/vdbe.h @@ -63,7 +63,6 @@ struct VdbeOp { #ifdef SQLITE_ENABLE_CURSOR_HINTS Expr *pExpr; /* Used when p4type is P4_EXPR */ #endif - int (*xAdvance)(BtCursor *, int); } p4; #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS char *zComment; /* Comment to improve readability */ @@ -114,7 +113,7 @@ typedef struct VdbeOpList VdbeOpList; #define P4_COLLSEQ (-2) /* P4 is a pointer to a CollSeq structure */ #define P4_INT32 (-3) /* P4 is a 32-bit signed integer */ #define P4_SUBPROGRAM (-4) /* P4 is a pointer to a SubProgram structure */ -#define P4_ADVANCE (-5) /* P4 is a pointer to BtreeNext() or BtreePrev() */ +/* (-5) // Available for reuse. Was P4_ADVANCE */ #define P4_TABLE (-6) /* P4 is a pointer to a Table structure */ /* Above do not own any resources. Must free those below */ #define P4_FREE_IF_LE (-7) diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 0f3d0eb877..1add1ca335 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -782,7 +782,7 @@ void sqlite3VdbeAssertAbortable(Vdbe *p){ ** (3) Update the Vdbe.readOnly and Vdbe.bIsReader flags to accurately ** indicate what the prepared statement actually does. ** -** (4) Initialize the p4.xAdvance pointer on opcodes that use it. +** (4) (discontinued) ** ** (5) Reclaim the memory allocated for storing labels. ** @@ -828,25 +828,6 @@ static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){ p->bIsReader = 1; break; } - case OP_Next: - case OP_SorterNext: { - pOp->p4.xAdvance = sqlite3BtreeNext; - pOp->p4type = P4_ADVANCE; - /* The code generator never codes any of these opcodes as a jump - ** to a label. They are always coded as a jump backwards to a - ** known address */ - assert( pOp->p2>=0 ); - break; - } - case OP_Prev: { - pOp->p4.xAdvance = sqlite3BtreePrevious; - pOp->p4type = P4_ADVANCE; - /* The code generator never codes any of these opcodes as a jump - ** to a label. They are always coded as a jump backwards to a - ** known address */ - assert( pOp->p2>=0 ); - break; - } #ifndef SQLITE_OMIT_VIRTUALTABLE case OP_VUpdate: { if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2; @@ -1727,8 +1708,7 @@ char *sqlite3VdbeDisplayP4(sqlite3 *db, Op *pOp){ zP4 = "program"; break; } - case P4_DYNBLOB: - case P4_ADVANCE: { + case P4_DYNBLOB: { break; } case P4_TABLE: { diff --git a/tool/mkopcodeh.tcl b/tool/mkopcodeh.tcl index d4f3c4f13b..57c6920111 100644 --- a/tool/mkopcodeh.tcl +++ b/tool/mkopcodeh.tcl @@ -158,9 +158,6 @@ set rp2v_ops { OP_JournalMode OP_VUpdate OP_VFilter - OP_Next - OP_SorterNext - OP_Prev } # Assign the smallest values to opcodes that are processed by resolveP2Values() From c45924ebc231eb70525633ec1c7f6998c4268e7b Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 25 Feb 2022 01:10:57 +0000 Subject: [PATCH 10/75] Remove unused P4 types on the Opcode object. Saves a few bytes of code space and simplifies the code. FossilOrigin-Name: aca538435939e6146f9a42e72e3a65030bbc5f646a0bbc7684e43688a0339888 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/analyze.c | 2 +- src/vdbe.h | 26 ++++++++++++-------------- src/vdbeaux.c | 4 ---- 5 files changed, 22 insertions(+), 28 deletions(-) diff --git a/manifest b/manifest index 37e367f783..0024fd5be2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\sthe\sOP_Next\sand\sOP_Prev\sopcodes\sso\sthat\sthey\sinvoke\nsqlite3BtreeNext()\sand\ssqlite3BtreePrevious()\sdirectly\srather\sthan\sthrough\na\sfunction\spointer,\sfor\simproved\sperformance\sand\sa\sdecrease\sin\scode\ssize. -D 2022-02-24T14:44:23.869 +C Remove\sunused\sP4\stypes\son\sthe\sOpcode\sobject.\s\sSaves\sa\sfew\sbytes\sof\scode\nspace\sand\ssimplifies\sthe\scode. +D 2022-02-25T01:10:57.145 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -486,7 +486,7 @@ F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786 F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a F src/alter.c e31cae888bc3077e34f9a82c6b4a96e4e44d37861eeb6472d68a378f1e8e46ba -F src/analyze.c 7518b99e07c5494111fe3bd867f28f804b6c5c1ad0703ec3d116de9bab3fa516 +F src/analyze.c 3a119baeb03053c154029877454d41bb8fd79d4d1eb583392f2289b3554a75bc F src/attach.c f26d400f3ffe2cdca01406bca70e5f58c5488bf165b4fc37c228136dfcf1b583 F src/auth.c f4fa91b6a90bbc8e0d0f738aa284551739c9543a367071f55574681e0f24f8cf F src/backup.c a2891172438e385fdbe97c11c9745676bec54f518d4447090af97189fd8e52d7 @@ -625,10 +625,10 @@ F src/utf.c ee39565f0843775cc2c81135751ddd93eceb91a673ea2c57f61c76f288b041a0 F src/util.c 602fe229f32a96ceccae4f40824129669582096f7c355f53dbac156c9fecef23 F src/vacuum.c 6c38ddc52f0619865c91dae9c441d4d48bf3040d7dc1bc5b22da1e45547ed0b3 F src/vdbe.c 5ff8a23c52b38a25f5b8ae398c0a787aff6fdf49e60e675915614022862a4a0a -F src/vdbe.h 40b26aa28d9af2ebb5a444416079688f7a9c584a7e4084164fd720f9a6bebcd2 +F src/vdbe.h a1d0e3b934e835e73edd146f2e7c4eadb711b5c9875c18159a57483fd78e550e F src/vdbeInt.h b45599a2b59f1ce042512ab6786b0b82a8cf3002f6b0fa60b4834e2cd3ac61d8 F src/vdbeapi.c 8863ffb5a7bac42fe9a68aaa3526ee29fc18fb02a9b27188b756de41e33856e9 -F src/vdbeaux.c 7c45a49f51d903488a8189b698adc4a61a3884bc176b6a86b1fd6d5d79f408f5 +F src/vdbeaux.c 3aa7ec0f53156760e9b42557122c61f90efddba5d9d173d076b3b8826b1b23bb F src/vdbeblob.c 5e61ce31aca17db8fb60395407457a8c1c7fb471dde405e0cd675974611dcfcd F src/vdbemem.c 7737f0b1c480a32b057849c804d2f21d5389649bb8be80f77ad75df700adc9a1 F src/vdbesort.c 43756031ca7430f7aec3ef904824a7883c4ede783e51f280d99b9b65c0796e35 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P f2597fae3c2b8f77f98a3ba9420b309f649b4008f9530d3cfaeeba1e2bf5d8a3 -R c4f84c0b82c6a47f3e7bc22716270649 +P 9d13cbbef3cf64f281d3e100f23f1b2ed6e8d65920c7517a84e1e4f964ceff2e +R 2e2e520a1c1c7c20c92c398ea415795b U drh -Z 3e76345e3d38fad9e71118178b08dd0f +Z 977c1663b04e9296fbb3fb3dc96b6b1a # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index b93321a07f..bae34e001c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9d13cbbef3cf64f281d3e100f23f1b2ed6e8d65920c7517a84e1e4f964ceff2e \ No newline at end of file +aca538435939e6146f9a42e72e3a65030bbc5f646a0bbc7684e43688a0339888 \ No newline at end of file diff --git a/src/analyze.c b/src/analyze.c index 5bbd34f9a2..e8699653f7 100644 --- a/src/analyze.c +++ b/src/analyze.c @@ -1023,7 +1023,7 @@ static void analyzeOneTable( memcpy(pStat1->zName, "sqlite_stat1", 13); pStat1->nCol = 3; pStat1->iPKey = -1; - sqlite3VdbeAddOp4(pParse->pVdbe, OP_Noop, 0, 0, 0,(char*)pStat1,P4_DYNBLOB); + sqlite3VdbeAddOp4(pParse->pVdbe, OP_Noop, 0, 0, 0,(char*)pStat1,P4_DYNAMIC); } #endif diff --git a/src/vdbe.h b/src/vdbe.h index d917ebf268..fb383e3ed2 100644 --- a/src/vdbe.h +++ b/src/vdbe.h @@ -113,21 +113,19 @@ typedef struct VdbeOpList VdbeOpList; #define P4_COLLSEQ (-2) /* P4 is a pointer to a CollSeq structure */ #define P4_INT32 (-3) /* P4 is a 32-bit signed integer */ #define P4_SUBPROGRAM (-4) /* P4 is a pointer to a SubProgram structure */ -/* (-5) // Available for reuse. Was P4_ADVANCE */ -#define P4_TABLE (-6) /* P4 is a pointer to a Table structure */ +#define P4_TABLE (-5) /* P4 is a pointer to a Table structure */ /* Above do not own any resources. Must free those below */ -#define P4_FREE_IF_LE (-7) -#define P4_DYNAMIC (-7) /* Pointer to memory from sqliteMalloc() */ -#define P4_FUNCDEF (-8) /* P4 is a pointer to a FuncDef structure */ -#define P4_KEYINFO (-9) /* P4 is a pointer to a KeyInfo structure */ -#define P4_EXPR (-10) /* P4 is a pointer to an Expr tree */ -#define P4_MEM (-11) /* P4 is a pointer to a Mem* structure */ -#define P4_VTAB (-12) /* P4 is a pointer to an sqlite3_vtab structure */ -#define P4_REAL (-13) /* P4 is a 64-bit floating point value */ -#define P4_INT64 (-14) /* P4 is a 64-bit signed integer */ -#define P4_INTARRAY (-15) /* P4 is a vector of 32-bit integers */ -#define P4_FUNCCTX (-16) /* P4 is a pointer to an sqlite3_context object */ -#define P4_DYNBLOB (-17) /* Pointer to memory from sqliteMalloc() */ +#define P4_FREE_IF_LE (-6) +#define P4_DYNAMIC (-6) /* Pointer to memory from sqliteMalloc() */ +#define P4_FUNCDEF (-7) /* P4 is a pointer to a FuncDef structure */ +#define P4_KEYINFO (-8) /* P4 is a pointer to a KeyInfo structure */ +#define P4_EXPR (-9) /* P4 is a pointer to an Expr tree */ +#define P4_MEM (-10) /* P4 is a pointer to a Mem* structure */ +#define P4_VTAB (-11) /* P4 is a pointer to an sqlite3_vtab structure */ +#define P4_REAL (-12) /* P4 is a 64-bit floating point value */ +#define P4_INT64 (-13) /* P4 is a 64-bit signed integer */ +#define P4_INTARRAY (-14) /* P4 is a vector of 32-bit integers */ +#define P4_FUNCCTX (-15) /* P4 is a pointer to an sqlite3_context object */ /* Error message codes for OP_Halt */ #define P5_ConstraintNotNull 1 diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 1add1ca335..bcfe63130f 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -1111,7 +1111,6 @@ static void freeP4(sqlite3 *db, int p4type, void *p4){ case P4_REAL: case P4_INT64: case P4_DYNAMIC: - case P4_DYNBLOB: case P4_INTARRAY: { sqlite3DbFree(db, p4); break; @@ -1708,9 +1707,6 @@ char *sqlite3VdbeDisplayP4(sqlite3 *db, Op *pOp){ zP4 = "program"; break; } - case P4_DYNBLOB: { - break; - } case P4_TABLE: { zP4 = pOp->p4.pTab->zName; break; From 9606a134329894715b8e3eef8536ba0907070ec9 Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 25 Feb 2022 01:23:17 +0000 Subject: [PATCH 11/75] Invoking SQLITE_TESTCTRL_INTERNAL_FUNCTIONS causes the flags field of the PRAGMA function_list to show all bits, including internal-use-only bits, rather than just the bits that are part of the API. FossilOrigin-Name: ad1be34828726bfef0dbc0ce16090400cf3530e7b5077849af96774d7428387b --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/pragma.c | 15 ++++++++------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index 0024fd5be2..4423f92fcb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\sunused\sP4\stypes\son\sthe\sOpcode\sobject.\s\sSaves\sa\sfew\sbytes\sof\scode\nspace\sand\ssimplifies\sthe\scode. -D 2022-02-25T01:10:57.145 +C Invoking\sSQLITE_TESTCTRL_INTERNAL_FUNCTIONS\scauses\sthe\sflags\sfield\sof\sthe\nPRAGMA\sfunction_list\sto\sshow\sall\sbits,\sincluding\sinternal-use-only\sbits,\nrather\sthan\sjust\sthe\sbits\sthat\sare\spart\sof\sthe\sAPI. +D 2022-02-25T01:23:17.074 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -545,7 +545,7 @@ F src/parse.y 0f02b27cdaa334441463153fff3ceb780fea006ab53ffd6ef566d4468f93e924 F src/pcache.c 084e638432c610f95aea72b8509f0845d2791293f39d1b82f0c0a7e089c3bb6b F src/pcache.h 4f87acd914cef5016fae3030343540d75f5b85a1877eed1a2a19b9f284248586 F src/pcache1.c 54881292a9a5db202b2c0ac541c5e3ef9a5e8c4f1c1383adb2601d5499a60e65 -F src/pragma.c 7c024d690a3dc93f61830f11f900e4af2357f31d081b0c79099ca5e28919cba7 +F src/pragma.c a7323cd175587afa0b82c213b9bba5789fe9ea67f9e5d66e35df00742a923bcc F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c a187dade741c1f09ae118fcbbf0302511807bfc0355880927d7152eb75b8260d F src/printf.c 05d8dfd2018bc4fc3ddb8b37eb97ccef7abf985643fa1caebdcf2916ca90fa32 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 9d13cbbef3cf64f281d3e100f23f1b2ed6e8d65920c7517a84e1e4f964ceff2e -R 2e2e520a1c1c7c20c92c398ea415795b +P aca538435939e6146f9a42e72e3a65030bbc5f646a0bbc7684e43688a0339888 +R 40203a3ea03c20c36dd71deecf295b46 U drh -Z 977c1663b04e9296fbb3fb3dc96b6b1a +Z 5ccd33ee4f07f795e380e5ae421f88d6 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index bae34e001c..be1af898bb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -aca538435939e6146f9a42e72e3a65030bbc5f646a0bbc7684e43688a0339888 \ No newline at end of file +ad1be34828726bfef0dbc0ce16090400cf3530e7b5077849af96774d7428387b \ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index b13de54942..0e87524dd5 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -307,15 +307,16 @@ static void pragmaFunclistLine( int isBuiltin, /* True if this is a built-in function */ int showInternFuncs /* True if showing internal functions */ ){ + u32 mask = + SQLITE_DETERMINISTIC | + SQLITE_DIRECTONLY | + SQLITE_SUBTYPE | + SQLITE_INNOCUOUS | + SQLITE_FUNC_INTERNAL + ; + if( showInternFuncs ) mask = -1; for(; p; p=p->pNext){ const char *zType; - static const u32 mask = - SQLITE_DETERMINISTIC | - SQLITE_DIRECTONLY | - SQLITE_SUBTYPE | - SQLITE_INNOCUOUS | - SQLITE_FUNC_INTERNAL - ; static const char *azEnc[] = { 0, "utf8", "utf16le", "utf16be" }; assert( SQLITE_FUNC_ENCMASK==0x3 ); From d1f0a86c12b61263c96e04f47a7c957fbc968d9d Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 25 Feb 2022 11:30:29 +0000 Subject: [PATCH 12/75] Fix unimportant typos in comment text. FossilOrigin-Name: 393460132994d6ca133e52af57374e43a2795a9e7fc7781bd9dea752a2b52c6a --- ext/misc/shathree.c | 2 +- manifest | 14 +++++++------- manifest.uuid | 2 +- src/select.c | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ext/misc/shathree.c b/ext/misc/shathree.c index 1f100986ea..f80dd855da 100644 --- a/ext/misc/shathree.c +++ b/ext/misc/shathree.c @@ -19,7 +19,7 @@ ** The sha3(X) function computes the SHA3 hash of the input X, or NULL if ** X is NULL. ** -** The sha3_query(Y) function evalutes all queries in the SQL statements of Y +** The sha3_query(Y) function evaluates all queries in the SQL statements of Y ** and returns a hash of their results. ** ** The SIZE argument is optional. If omitted, the SHA3-256 hash algorithm diff --git a/manifest b/manifest index 4423f92fcb..d5960c30c2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Invoking\sSQLITE_TESTCTRL_INTERNAL_FUNCTIONS\scauses\sthe\sflags\sfield\sof\sthe\nPRAGMA\sfunction_list\sto\sshow\sall\sbits,\sincluding\sinternal-use-only\sbits,\nrather\sthan\sjust\sthe\sbits\sthat\sare\spart\sof\sthe\sAPI. -D 2022-02-25T01:23:17.074 +C Fix\sunimportant\stypos\sin\scomment\stext. +D 2022-02-25T11:30:29.835 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -323,7 +323,7 @@ F ext/misc/rot13.c 51ac5f51e9d5fd811db58a9c23c628ad5f333c173f1fc53c8491a3603d385 F ext/misc/scrub.c 2a44b0d44c69584c0580ad2553f6290a307a49df4668941d2812135bfb96a946 F ext/misc/series.c 8d79354f2c3d46b95ee21272a07cf0bcabb58d1f2b06d9e7b8a31dca1dacb3e5 F ext/misc/sha1.c 4011aef176616872b2a0d5bccf0ecfb1f7ce3fe5c3d107f3a8e949d8e1e3f08d -F ext/misc/shathree.c 9b6fce315bf8b37bd72786086d1f0974701f651e83022a93244e0e8f56f98a45 +F ext/misc/shathree.c 7b17615869a495659f1569ada1d8d3d21b4a24614f2746d93cc87ef7c0b6b36d F ext/misc/showauth.c 732578f0fe4ce42d577e1c86dc89dd14a006ab52 F ext/misc/spellfix.c 94df9bbfa514a563c1484f684a2df3d128a2f7209a84ca3ca100c68a0163e29f F ext/misc/sqlar.c 0ace5d3c10fe736dc584bf1159a36b8e2e60fab309d310cd8a0eecd9036621b6 @@ -552,7 +552,7 @@ F src/printf.c 05d8dfd2018bc4fc3ddb8b37eb97ccef7abf985643fa1caebdcf2916ca90fa32 F src/random.c 097dc8b31b8fba5a9aca1697aeb9fd82078ec91be734c16bffda620ced7ab83c F src/resolve.c ea935b87d6fb36c78b70cdc7b28561dc8f33f2ef37048389549c7b5ef9b0ba5e F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92 -F src/select.c 3baa9dd8cf240654773c7974e2bcce398ac9dd24419c36684156963defe43b35 +F src/select.c 4890a3cfee0bc60ff231c3a44db37968859ab0be156983dbcc0c096109832cdd F src/shell.c.in 14cdfba32c73cb06169e50cd448632c28359f2bab2a0f803dc4a7f46dfc5b6fa F src/sqlite.h.in e82ac380b307659d0892f502b742f825504e78729f4edaadce946003b9c00816 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P aca538435939e6146f9a42e72e3a65030bbc5f646a0bbc7684e43688a0339888 -R 40203a3ea03c20c36dd71deecf295b46 +P ad1be34828726bfef0dbc0ce16090400cf3530e7b5077849af96774d7428387b +R a4beb76483336f72fca390718a058877 U drh -Z 5ccd33ee4f07f795e380e5ae421f88d6 +Z e5f1864550275862aa2798467c9b0f60 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index be1af898bb..7d6b60bd57 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ad1be34828726bfef0dbc0ce16090400cf3530e7b5077849af96774d7428387b \ No newline at end of file +393460132994d6ca133e52af57374e43a2795a9e7fc7781bd9dea752a2b52c6a \ No newline at end of file diff --git a/src/select.c b/src/select.c index 6719d47471..0c5ce55715 100644 --- a/src/select.c +++ b/src/select.c @@ -2623,7 +2623,7 @@ static int multiSelectOrderBy( ** The "LIMIT of exactly 1" case of condition (1) comes about when a VALUES ** clause occurs within scalar expression (ex: "SELECT (VALUES(1),(2),(3))"). ** The sqlite3CodeSubselect will have added the LIMIT 1 clause in tht case. -** Since the limit is exactly 1, we only need to evalutes the left-most VALUES. +** Since the limit is exactly 1, we only need to evaluate the left-most VALUES. */ static int multiSelectValues( Parse *pParse, /* Parsing context */ From 7fd6a7761f32f454f1707639f3f69371d2272b74 Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 25 Feb 2022 13:29:56 +0000 Subject: [PATCH 13/75] Improved comment on the codeDeferredSeek() routine. No code changes. FossilOrigin-Name: 54f49f65ac943263a1622b1efe519c8a61f30f23694fd4fec89ad2bf0e17b473 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/wherecode.c | 20 ++++++++++++++------ 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index d5960c30c2..e6c22fe855 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sunimportant\stypos\sin\scomment\stext. -D 2022-02-25T11:30:29.835 +C Improved\scomment\son\sthe\scodeDeferredSeek()\sroutine.\sNo\scode\schanges. +D 2022-02-25T13:29:56.636 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -641,7 +641,7 @@ F src/wal.h c3aa7825bfa2fe0d85bef2db94655f99870a285778baa36307c0a16da32b226a F src/walker.c f890a3298418d7cba3b69b8803594fdc484ea241206a8dfa99db6dd36f8cbb3b F src/where.c 0d75d7514764726409ea945520fe9fb515e7d9ae52a5a3c0a136142cfaa19087 F src/whereInt.h 15d2975c3b4c193c78c26674400a840da8647fe1777ae3b026e2d15937b38a03 -F src/wherecode.c 6150f51c0368be941fad90a736ce37cc1e2a719876750a3183a516ed256a4cbb +F src/wherecode.c d34d3980f35e504a558f788ad9ac4bc6876b119409d597e7e234a4564a94c6ab F src/whereexpr.c 2a71f5491798460c9590317329234d332d9eb1717cba4f3403122189a75c465e F src/window.c dfaec4abc6012cbc18e4a202ca3a5d5a0efcc4011d86a06d882ddaab8aedee4d F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P ad1be34828726bfef0dbc0ce16090400cf3530e7b5077849af96774d7428387b -R a4beb76483336f72fca390718a058877 +P 393460132994d6ca133e52af57374e43a2795a9e7fc7781bd9dea752a2b52c6a +R 9d513bd798b81de21bb7dd572470a8e8 U drh -Z e5f1864550275862aa2798467c9b0f60 +Z bd0ff582d66826c917840ae517528eb1 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 7d6b60bd57..0e6e71b15e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -393460132994d6ca133e52af57374e43a2795a9e7fc7781bd9dea752a2b52c6a \ No newline at end of file +54f49f65ac943263a1622b1efe519c8a61f30f23694fd4fec89ad2bf0e17b473 \ No newline at end of file diff --git a/src/wherecode.c b/src/wherecode.c index 79504159a6..ab3b8b18e1 100644 --- a/src/wherecode.c +++ b/src/wherecode.c @@ -1118,13 +1118,21 @@ static void codeCursorHint( ** ** OP_DeferredSeek $iCur $iRowid ** +** Which causes a seek on $iCur to the row with rowid $iRowid. +** ** However, if the scan currently being coded is a branch of an OR-loop and -** the statement currently being coded is a SELECT, then P3 of OP_DeferredSeek -** is set to iIdxCur and P4 is set to point to an array of integers -** containing one entry for each column of the table cursor iCur is open -** on. For each table column, if the column is the i'th column of the -** index, then the corresponding array entry is set to (i+1). If the column -** does not appear in the index at all, the array entry is set to 0. +** the statement currently being coded is a SELECT, then additional information +** is added that might allow OP_Column to omit the seek and instead do its +** lookup on the index, thus avoiding an expensive seek operation. To +** enable this optimization, the P3 of OP_DeferredSeek is set to iIdxCur +** and P4 is set to an array of integers containing one entry for each column +** in the table. For each table column, if the column is the i'th +** column of the index, then the corresponding array entry is set to (i+1). +** If the column does not appear in the index at all, the array entry is set +** to 0. The OP_Column opcode can check this array to see if the column it +** wants is in the index and if it is, it will substitute the index cursor +** and column number and continue with those new values, rather than seeking +** the table cursor. */ static void codeDeferredSeek( WhereInfo *pWInfo, /* Where clause context */ From a10be3da203225ab799785cd207414e0f93652d7 Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 25 Feb 2022 18:51:09 +0000 Subject: [PATCH 14/75] Fix the OP_NullRow documentation so that it accurately describes what it actually does for a pseudo-cursor. FossilOrigin-Name: 4e269902094e8f9d852e5fc852e473167048fdeb9034f1fb1436f6df205de926 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbe.c | 4 ++++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index e6c22fe855..42a39fbdc4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improved\scomment\son\sthe\scodeDeferredSeek()\sroutine.\sNo\scode\schanges. -D 2022-02-25T13:29:56.636 +C Fix\sthe\sOP_NullRow\sdocumentation\sso\sthat\sit\saccurately\sdescribes\swhat\sit\nactually\sdoes\sfor\sa\spseudo-cursor. +D 2022-02-25T18:51:09.169 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -624,7 +624,7 @@ F src/upsert.c 8789047a8f0a601ea42fa0256d1ba3190c13746b6ba940fe2d25643a7e991937 F src/utf.c ee39565f0843775cc2c81135751ddd93eceb91a673ea2c57f61c76f288b041a0 F src/util.c 602fe229f32a96ceccae4f40824129669582096f7c355f53dbac156c9fecef23 F src/vacuum.c 6c38ddc52f0619865c91dae9c441d4d48bf3040d7dc1bc5b22da1e45547ed0b3 -F src/vdbe.c 5ff8a23c52b38a25f5b8ae398c0a787aff6fdf49e60e675915614022862a4a0a +F src/vdbe.c 5299556464a6a947611334db56adbf20d2b345c1cff7d74f666008c349f0410c F src/vdbe.h a1d0e3b934e835e73edd146f2e7c4eadb711b5c9875c18159a57483fd78e550e F src/vdbeInt.h b45599a2b59f1ce042512ab6786b0b82a8cf3002f6b0fa60b4834e2cd3ac61d8 F src/vdbeapi.c 8863ffb5a7bac42fe9a68aaa3526ee29fc18fb02a9b27188b756de41e33856e9 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 393460132994d6ca133e52af57374e43a2795a9e7fc7781bd9dea752a2b52c6a -R 9d513bd798b81de21bb7dd572470a8e8 +P 54f49f65ac943263a1622b1efe519c8a61f30f23694fd4fec89ad2bf0e17b473 +R 84b7b86c0cda7b37ea1827afa5aef02e U drh -Z bd0ff582d66826c917840ae517528eb1 +Z ad486a9d2be85a263d9516418548523a # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 0e6e71b15e..05dec89be9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -54f49f65ac943263a1622b1efe519c8a61f30f23694fd4fec89ad2bf0e17b473 \ No newline at end of file +4e269902094e8f9d852e5fc852e473167048fdeb9034f1fb1436f6df205de926 \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index 19e9156030..f6c350a9b5 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -5709,6 +5709,10 @@ case OP_Rowid: { /* out2 */ ** Move the cursor P1 to a null row. Any OP_Column operations ** that occur while the cursor is on the null row will always ** write a NULL. +** +** Or, if P1 is a Pseudo-Cursor (a cursor opened using OP_OpenPseudo) +** just reset the cache for that cursor. This causes the row of +** content held by the pseudo-cursor to be reparsed. */ case OP_NullRow: { VdbeCursor *pC; From fc56950337825789486227a2f4ce8655d670b420 Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 25 Feb 2022 20:11:59 +0000 Subject: [PATCH 15/75] Revise the initialization processing for OP_Column to make it about 1.8 million cycles faster. FossilOrigin-Name: 3b7259ebd5b9b1f75577521c4d0d96f5503d302a513b20a0b17dbe8c3823dd33 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/vdbe.c | 40 +++++++++++++++++++++++++++++----------- src/vdbeInt.h | 2 +- src/vdbeaux.c | 36 ++---------------------------------- 5 files changed, 41 insertions(+), 55 deletions(-) diff --git a/manifest b/manifest index 42a39fbdc4..892f8fb779 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\sOP_NullRow\sdocumentation\sso\sthat\sit\saccurately\sdescribes\swhat\sit\nactually\sdoes\sfor\sa\spseudo-cursor. -D 2022-02-25T18:51:09.169 +C Revise\sthe\sinitialization\sprocessing\sfor\sOP_Column\sto\smake\sit\sabout\n1.8\smillion\scycles\sfaster. +D 2022-02-25T20:11:59.160 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -624,11 +624,11 @@ F src/upsert.c 8789047a8f0a601ea42fa0256d1ba3190c13746b6ba940fe2d25643a7e991937 F src/utf.c ee39565f0843775cc2c81135751ddd93eceb91a673ea2c57f61c76f288b041a0 F src/util.c 602fe229f32a96ceccae4f40824129669582096f7c355f53dbac156c9fecef23 F src/vacuum.c 6c38ddc52f0619865c91dae9c441d4d48bf3040d7dc1bc5b22da1e45547ed0b3 -F src/vdbe.c 5299556464a6a947611334db56adbf20d2b345c1cff7d74f666008c349f0410c +F src/vdbe.c e3947ae70531c7e26fdca3da379bcb1aaad349dc1daad9841a11dd78f40e4705 F src/vdbe.h a1d0e3b934e835e73edd146f2e7c4eadb711b5c9875c18159a57483fd78e550e -F src/vdbeInt.h b45599a2b59f1ce042512ab6786b0b82a8cf3002f6b0fa60b4834e2cd3ac61d8 +F src/vdbeInt.h de2348c1643c1ac5bf0932452cbb708f52f52d8b4e29b667abdcfd4bacbf6aa6 F src/vdbeapi.c 8863ffb5a7bac42fe9a68aaa3526ee29fc18fb02a9b27188b756de41e33856e9 -F src/vdbeaux.c 3aa7ec0f53156760e9b42557122c61f90efddba5d9d173d076b3b8826b1b23bb +F src/vdbeaux.c 1dc2bdd377baf4e3602e02ca33d241944f04bda2e724526437018f143f9e75f3 F src/vdbeblob.c 5e61ce31aca17db8fb60395407457a8c1c7fb471dde405e0cd675974611dcfcd F src/vdbemem.c 7737f0b1c480a32b057849c804d2f21d5389649bb8be80f77ad75df700adc9a1 F src/vdbesort.c 43756031ca7430f7aec3ef904824a7883c4ede783e51f280d99b9b65c0796e35 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 54f49f65ac943263a1622b1efe519c8a61f30f23694fd4fec89ad2bf0e17b473 -R 84b7b86c0cda7b37ea1827afa5aef02e +P 4e269902094e8f9d852e5fc852e473167048fdeb9034f1fb1436f6df205de926 +R 8636bb1bb599a232ab53a80eb27f1dd2 U drh -Z ad486a9d2be85a263d9516418548523a +Z 2c3c6e68626da40fc12f58f70cf79dcd # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 05dec89be9..45a49d23f0 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4e269902094e8f9d852e5fc852e473167048fdeb9034f1fb1436f6df205de926 \ No newline at end of file +3b7259ebd5b9b1f75577521c4d0d96f5503d302a513b20a0b17dbe8c3823dd33 \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index f6c350a9b5..d1e54b8f9e 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -2659,7 +2659,7 @@ case OP_Offset: { /* out3 */ case OP_Column: { u32 p2; /* column number to retrieve */ VdbeCursor *pC; /* The VDBE cursor */ - BtCursor *pCrsr; /* The BTree cursor */ + BtCursor *pCrsr; /* The B-Tree cursor corresponding to pC */ u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */ int len; /* The length of the serialized data for the column */ int i; /* Loop counter */ @@ -2673,19 +2673,11 @@ case OP_Column: { Mem *pReg; /* PseudoTable input register */ assert( pOp->p1>=0 && pOp->p1nCursor ); + assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) ); pC = p->apCsr[pOp->p1]; - assert( pC!=0 ); p2 = (u32)pOp->p2; - /* If the cursor cache is stale (meaning it is not currently point at - ** the correct row) then bring it up-to-date by doing the necessary - ** B-Tree seek. */ - rc = sqlite3VdbeCursorMoveto(&pC, &p2); - if( rc ) goto abort_due_to_error; - - assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) ); - pDest = &aMem[pOp->p3]; - memAboutToChange(p, pDest); +op_column_restart: assert( pC!=0 ); assert( p2<(u32)pC->nField ); aOffset = pC->aOffset; @@ -2706,11 +2698,28 @@ case OP_Column: { pC->payloadSize = pC->szRow = pReg->n; pC->aRow = (u8*)pReg->z; }else{ + pDest = &aMem[pOp->p3]; + memAboutToChange(p, pDest); sqlite3VdbeMemSetNull(pDest); goto op_column_out; } }else{ pCrsr = pC->uc.pCursor; + if( pC->deferredMoveto ){ + u32 iMap; + assert( !pC->isEphemeral ); + if( pC->ub.aAltMap && (iMap = pC->ub.aAltMap[1+p2])>0 ){ + pC = pC->pAltCursor; + p2 = iMap - 1; + goto op_column_restart; + } + rc = sqlite3VdbeFinishMoveto(pC); + if( rc ) goto abort_due_to_error; + }else if( sqlite3BtreeCursorHasMoved(pCrsr) ){ + rc = sqlite3VdbeHandleMovedCursor(pC); + if( rc ) goto abort_due_to_error; + goto op_column_restart; + } assert( pC->eCurType==CURTYPE_BTREE ); assert( pCrsr ); assert( sqlite3BtreeCursorIsValid(pCrsr) ); @@ -2766,6 +2775,10 @@ case OP_Column: { testcase( aOffset[0]==0 ); goto op_column_read_header; } + }else if( sqlite3BtreeCursorHasMoved(pC->uc.pCursor) ){ + rc = sqlite3VdbeHandleMovedCursor(pC); + if( rc ) goto abort_due_to_error; + goto op_column_restart; } /* Make sure at least the first p2+1 entries of the header have been @@ -2834,6 +2847,8 @@ case OP_Column: { ** columns. So the result will be either the default value or a NULL. */ if( pC->nHdrParsed<=p2 ){ + pDest = &aMem[pOp->p3]; + memAboutToChange(p, pDest); if( pOp->p4type==P4_MEM ){ sqlite3VdbeMemShallowCopy(pDest, pOp->p4.pMem, MEM_Static); }else{ @@ -2851,6 +2866,8 @@ case OP_Column: { */ assert( p2nHdrParsed ); assert( rc==SQLITE_OK ); + pDest = &aMem[pOp->p3]; + memAboutToChange(p, pDest); assert( sqlite3VdbeCheckMemInvariants(pDest) ); if( VdbeMemDynamic(pDest) ){ sqlite3VdbeMemSetNull(pDest); @@ -6197,6 +6214,7 @@ case OP_IdxRowid: { /* out2 */ pTabCur->nullRow = 0; pTabCur->movetoTarget = rowid; pTabCur->deferredMoveto = 1; + pTabCur->cacheStatus = CACHE_STALE; assert( pOp->p4type==P4_INTARRAY || pOp->p4.ai==0 ); assert( !pTabCur->isEphemeral ); pTabCur->ub.aAltMap = pOp->p4.ai; diff --git a/src/vdbeInt.h b/src/vdbeInt.h index f02b37c6a2..cc5fd604d5 100644 --- a/src/vdbeInt.h +++ b/src/vdbeInt.h @@ -506,8 +506,8 @@ struct ValueList { void sqlite3VdbeError(Vdbe*, const char *, ...); void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*); void sqliteVdbePopStack(Vdbe*,int); +int SQLITE_NOINLINE sqlite3VdbeHandleMovedCursor(VdbeCursor *p); int SQLITE_NOINLINE sqlite3VdbeFinishMoveto(VdbeCursor*); -int sqlite3VdbeCursorMoveto(VdbeCursor**, u32*); int sqlite3VdbeCursorRestore(VdbeCursor*); u32 sqlite3VdbeSerialTypeLen(u32); u8 sqlite3VdbeOneByteSerialTypeLen(u8); diff --git a/src/vdbeaux.c b/src/vdbeaux.c index bcfe63130f..35044127ac 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -3505,7 +3505,7 @@ int SQLITE_NOINLINE sqlite3VdbeFinishMoveto(VdbeCursor *p){ ** is supposed to be pointing. If the row was deleted out from under the ** cursor, set the cursor to point to a NULL row. */ -static int SQLITE_NOINLINE handleMovedCursor(VdbeCursor *p){ +int SQLITE_NOINLINE sqlite3VdbeHandleMovedCursor(VdbeCursor *p){ int isDifferentRow, rc; assert( p->eCurType==CURTYPE_BTREE ); assert( p->uc.pCursor!=0 ); @@ -3523,39 +3523,7 @@ static int SQLITE_NOINLINE handleMovedCursor(VdbeCursor *p){ int sqlite3VdbeCursorRestore(VdbeCursor *p){ assert( p->eCurType==CURTYPE_BTREE ); if( sqlite3BtreeCursorHasMoved(p->uc.pCursor) ){ - return handleMovedCursor(p); - } - return SQLITE_OK; -} - -/* -** Make sure the cursor p is ready to read or write the row to which it -** was last positioned. Return an error code if an OOM fault or I/O error -** prevents us from positioning the cursor to its correct position. -** -** If a MoveTo operation is pending on the given cursor, then do that -** MoveTo now. If no move is pending, check to see if the row has been -** deleted out from under the cursor and if it has, mark the row as -** a NULL row. -** -** If the cursor is already pointing to the correct row and that row has -** not been deleted out from under the cursor, then this routine is a no-op. -*/ -int sqlite3VdbeCursorMoveto(VdbeCursor **pp, u32 *piCol){ - VdbeCursor *p = *pp; - assert( p->eCurType==CURTYPE_BTREE || p->eCurType==CURTYPE_PSEUDO ); - if( p->deferredMoveto ){ - u32 iMap; - assert( !p->isEphemeral ); - if( p->ub.aAltMap && (iMap = p->ub.aAltMap[1+*piCol])>0 && !p->nullRow ){ - *pp = p->pAltCursor; - *piCol = iMap - 1; - return SQLITE_OK; - } - return sqlite3VdbeFinishMoveto(p); - } - if( sqlite3BtreeCursorHasMoved(p->uc.pCursor) ){ - return handleMovedCursor(p); + return sqlite3VdbeHandleMovedCursor(p); } return SQLITE_OK; } From 9090df6f739dec4fb1663a4c76561b4491144256 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 26 Feb 2022 14:39:08 +0000 Subject: [PATCH 16/75] Allow the OP_Column opcode to read rows that are larger than SQLITE_LIMIT_LENGTH as long as the specific field being read out is less than or equal to SQLITE_LIMIT_LENGTH. FossilOrigin-Name: 1bf4848995ab094ad84ef4aa1563bce641d5acf7335fb4630c892b16cf7d7edd --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbe.c | 6 ++---- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 892f8fb779..14b7b855ce 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Revise\sthe\sinitialization\sprocessing\sfor\sOP_Column\sto\smake\sit\sabout\n1.8\smillion\scycles\sfaster. -D 2022-02-25T20:11:59.160 +C Allow\sthe\sOP_Column\sopcode\sto\sread\srows\sthat\sare\slarger\sthan\nSQLITE_LIMIT_LENGTH\sas\slong\sas\sthe\sspecific\sfield\sbeing\sread\sout\sis\nless\sthan\sor\sequal\sto\sSQLITE_LIMIT_LENGTH. +D 2022-02-26T14:39:08.859 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -624,7 +624,7 @@ F src/upsert.c 8789047a8f0a601ea42fa0256d1ba3190c13746b6ba940fe2d25643a7e991937 F src/utf.c ee39565f0843775cc2c81135751ddd93eceb91a673ea2c57f61c76f288b041a0 F src/util.c 602fe229f32a96ceccae4f40824129669582096f7c355f53dbac156c9fecef23 F src/vacuum.c 6c38ddc52f0619865c91dae9c441d4d48bf3040d7dc1bc5b22da1e45547ed0b3 -F src/vdbe.c e3947ae70531c7e26fdca3da379bcb1aaad349dc1daad9841a11dd78f40e4705 +F src/vdbe.c 2dd9dc73c6e99db958550d1b66ea35046ff3d95ee2c752f41cf90a73ca742d25 F src/vdbe.h a1d0e3b934e835e73edd146f2e7c4eadb711b5c9875c18159a57483fd78e550e F src/vdbeInt.h de2348c1643c1ac5bf0932452cbb708f52f52d8b4e29b667abdcfd4bacbf6aa6 F src/vdbeapi.c 8863ffb5a7bac42fe9a68aaa3526ee29fc18fb02a9b27188b756de41e33856e9 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 4e269902094e8f9d852e5fc852e473167048fdeb9034f1fb1436f6df205de926 -R 8636bb1bb599a232ab53a80eb27f1dd2 +P 3b7259ebd5b9b1f75577521c4d0d96f5503d302a513b20a0b17dbe8c3823dd33 +R a170b2aecc18c2441545989ed3dec05a U drh -Z 2c3c6e68626da40fc12f58f70cf79dcd +Z 8d66f3f471c1337d94ff51594a5973cc # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 45a49d23f0..cfe6a25611 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3b7259ebd5b9b1f75577521c4d0d96f5503d302a513b20a0b17dbe8c3823dd33 \ No newline at end of file +1bf4848995ab094ad84ef4aa1563bce641d5acf7335fb4630c892b16cf7d7edd \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index d1e54b8f9e..4a31555795 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -2727,15 +2727,11 @@ op_column_restart: pC->aRow = sqlite3BtreePayloadFetch(pCrsr, &pC->szRow); assert( pC->szRow<=pC->payloadSize ); assert( pC->szRow<=65536 ); /* Maximum page size is 64KiB */ - if( pC->payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){ - goto too_big; - } } pC->cacheStatus = p->cacheCtr; pC->iHdrOffset = getVarint32(pC->aRow, aOffset[0]); pC->nHdrParsed = 0; - if( pC->szRowaRow does not have to hold the entire row, but it does at least ** need to cover the header of the record. If pC->aRow does not contain @@ -2888,6 +2884,7 @@ op_column_restart: pDest->n = len = (t-12)/2; pDest->enc = encoding; if( pDest->szMalloc < len+2 ){ + if( len>db->aLimit[SQLITE_LIMIT_LENGTH] ) goto too_big; pDest->flags = MEM_Null; if( sqlite3VdbeMemGrow(pDest, len+2, 0) ) goto no_mem; }else{ @@ -2920,6 +2917,7 @@ op_column_restart: */ sqlite3VdbeSerialGet((u8*)sqlite3CtypeMap, t, pDest); }else{ + if( len>db->aLimit[SQLITE_LIMIT_LENGTH] ) goto too_big; rc = sqlite3VdbeMemFromBtree(pC->uc.pCursor, aOffset[p2], len, pDest); if( rc!=SQLITE_OK ) goto abort_due_to_error; sqlite3VdbeSerialGet((const u8*)pDest->z, t, pDest); From a0318fd7b4fbedbce74f133fb0f84ff4a19ea075 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 26 Feb 2022 23:01:25 +0000 Subject: [PATCH 17/75] Remove an unnecessary local variable for a small performance increase and size reduction. FossilOrigin-Name: 9bda611f0d182a62ac1b68610313143c2e28868c16c7d4362a8f5945c27dd88e --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbe.c | 4 +--- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 14b7b855ce..bbf330528d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Allow\sthe\sOP_Column\sopcode\sto\sread\srows\sthat\sare\slarger\sthan\nSQLITE_LIMIT_LENGTH\sas\slong\sas\sthe\sspecific\sfield\sbeing\sread\sout\sis\nless\sthan\sor\sequal\sto\sSQLITE_LIMIT_LENGTH. -D 2022-02-26T14:39:08.859 +C Remove\san\sunnecessary\slocal\svariable\sfor\sa\ssmall\sperformance\sincrease\sand\ssize\nreduction. +D 2022-02-26T23:01:25.800 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -624,7 +624,7 @@ F src/upsert.c 8789047a8f0a601ea42fa0256d1ba3190c13746b6ba940fe2d25643a7e991937 F src/utf.c ee39565f0843775cc2c81135751ddd93eceb91a673ea2c57f61c76f288b041a0 F src/util.c 602fe229f32a96ceccae4f40824129669582096f7c355f53dbac156c9fecef23 F src/vacuum.c 6c38ddc52f0619865c91dae9c441d4d48bf3040d7dc1bc5b22da1e45547ed0b3 -F src/vdbe.c 2dd9dc73c6e99db958550d1b66ea35046ff3d95ee2c752f41cf90a73ca742d25 +F src/vdbe.c 4b969ebe6b61f87a90aebf817bc6ebda5075fe56987591091a9bf22556262484 F src/vdbe.h a1d0e3b934e835e73edd146f2e7c4eadb711b5c9875c18159a57483fd78e550e F src/vdbeInt.h de2348c1643c1ac5bf0932452cbb708f52f52d8b4e29b667abdcfd4bacbf6aa6 F src/vdbeapi.c 8863ffb5a7bac42fe9a68aaa3526ee29fc18fb02a9b27188b756de41e33856e9 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 3b7259ebd5b9b1f75577521c4d0d96f5503d302a513b20a0b17dbe8c3823dd33 -R a170b2aecc18c2441545989ed3dec05a +P 1bf4848995ab094ad84ef4aa1563bce641d5acf7335fb4630c892b16cf7d7edd +R 6ea0329386e044b14d5ca6833590b961 U drh -Z 8d66f3f471c1337d94ff51594a5973cc +Z 0c7c29fba439ea1710add27e6f563edc # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index cfe6a25611..c989e71c09 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1bf4848995ab094ad84ef4aa1563bce641d5acf7335fb4630c892b16cf7d7edd \ No newline at end of file +9bda611f0d182a62ac1b68610313143c2e28868c16c7d4362a8f5945c27dd88e \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index 4a31555795..82ea6cf6bd 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -3130,7 +3130,6 @@ case OP_MakeRecord: { Mem *pLast; /* Last field of the record */ int nField; /* Number of fields in the record */ char *zAffinity; /* The affinity string for the record */ - int file_format; /* File format to use for encoding */ u32 len; /* Length of a field */ u8 *zHdr; /* Where to write next byte of the header */ u8 *zPayload; /* Where to write next byte of the payload */ @@ -3159,7 +3158,6 @@ case OP_MakeRecord: { pData0 = &aMem[nField]; nField = pOp->p2; pLast = &pData0[nField-1]; - file_format = p->minWriteFileFormat; /* Identify the output register */ assert( pOp->p3p1 || pOp->p3>=pOp->p1+pOp->p2 ); @@ -3261,7 +3259,7 @@ case OP_MakeRecord: { testcase( uu==2147483647 ); testcase( uu==2147483648LL ); testcase( uu==140737488355327LL ); testcase( uu==140737488355328LL ); if( uu<=127 ){ - if( (i&1)==i && file_format>=4 ){ + if( (i&1)==i && p->minWriteFileFormat>=4 ){ pRec->uTemp = 8+(u32)uu; }else{ nData++; From a1e951fa48050ac346e49cb74a923f6309fedf80 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sun, 27 Feb 2022 18:54:33 +0000 Subject: [PATCH 18/75] Bypass a single branch in vdbeRecordCompareString() in the common case, for a performance increase of over 600K CPU cycles. FossilOrigin-Name: 36f0f07e505dfb38c61d3b4d5b947013c8793e6796fe690e53864479b9276abb --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbeaux.c | 12 ++++++++---- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index bbf330528d..3b121c810a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\san\sunnecessary\slocal\svariable\sfor\sa\ssmall\sperformance\sincrease\sand\ssize\nreduction. -D 2022-02-26T23:01:25.800 +C Bypass\sa\ssingle\sbranch\sin\svdbeRecordCompareString()\sin\sthe\scommon\scase,\sfor\na\sperformance\sincrease\sof\sover\s600K\sCPU\scycles. +D 2022-02-27T18:54:33.505 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -628,7 +628,7 @@ F src/vdbe.c 4b969ebe6b61f87a90aebf817bc6ebda5075fe56987591091a9bf22556262484 F src/vdbe.h a1d0e3b934e835e73edd146f2e7c4eadb711b5c9875c18159a57483fd78e550e F src/vdbeInt.h de2348c1643c1ac5bf0932452cbb708f52f52d8b4e29b667abdcfd4bacbf6aa6 F src/vdbeapi.c 8863ffb5a7bac42fe9a68aaa3526ee29fc18fb02a9b27188b756de41e33856e9 -F src/vdbeaux.c 1dc2bdd377baf4e3602e02ca33d241944f04bda2e724526437018f143f9e75f3 +F src/vdbeaux.c 855d86f29143177253c554344362a78ba30feaa221554e17e0cd2b144658f077 F src/vdbeblob.c 5e61ce31aca17db8fb60395407457a8c1c7fb471dde405e0cd675974611dcfcd F src/vdbemem.c 7737f0b1c480a32b057849c804d2f21d5389649bb8be80f77ad75df700adc9a1 F src/vdbesort.c 43756031ca7430f7aec3ef904824a7883c4ede783e51f280d99b9b65c0796e35 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 1bf4848995ab094ad84ef4aa1563bce641d5acf7335fb4630c892b16cf7d7edd -R 6ea0329386e044b14d5ca6833590b961 +P 9bda611f0d182a62ac1b68610313143c2e28868c16c7d4362a8f5945c27dd88e +R 76aeac53a072a4a75391246dfc2d8423 U drh -Z 0c7c29fba439ea1710add27e6f563edc +Z 87e616c52c5100e606e896a97c48322f # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index c989e71c09..35e6c33ef5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9bda611f0d182a62ac1b68610313143c2e28868c16c7d4362a8f5945c27dd88e \ No newline at end of file +36f0f07e505dfb38c61d3b4d5b947013c8793e6796fe690e53864479b9276abb \ No newline at end of file diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 35044127ac..be9cebd51d 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -4746,11 +4746,15 @@ static int vdbeRecordCompareString( assert( pPKey2->aMem[0].flags & MEM_Str ); vdbeAssertFieldCountWithinLimits(nKey1, pKey1, pPKey2->pKeyInfo); - serial_type = (u8)(aKey1[1]); - if( serial_type >= 0x80 ){ - sqlite3GetVarint32(&aKey1[1], (u32*)&serial_type); - } + serial_type = (signed char)(aKey1[1]); + +vrcs_restart: if( serial_type<12 ){ + if( serial_type<0 ){ + sqlite3GetVarint32(&aKey1[1], (u32*)&serial_type); + if( serial_type>=12 ) goto vrcs_restart; + assert( CORRUPT_DB ); + } res = pPKey2->r1; /* (pKey1/nKey1) is a number or a null */ }else if( !(serial_type & 0x01) ){ res = pPKey2->r2; /* (pKey1/nKey1) is a blob */ From f357cafaf50290fe2264ea87312d38dddc89befd Mon Sep 17 00:00:00 2001 From: drh <> Date: Sun, 27 Feb 2022 21:10:49 +0000 Subject: [PATCH 19/75] Cache values of UnpackedRecord.aMem[0] into new fields of UnpackedRecord. This avoids extra indirections and saves about 750K cycles. FossilOrigin-Name: 7cf2d1f0396362aae7b93da75c2036d52ba86acba1cc90abca560bcf0314a22f --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/sqliteInt.h | 5 +++++ src/vdbeaux.c | 14 ++++++++++---- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index 3b121c810a..ca25a7d23f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Bypass\sa\ssingle\sbranch\sin\svdbeRecordCompareString()\sin\sthe\scommon\scase,\sfor\na\sperformance\sincrease\sof\sover\s600K\sCPU\scycles. -D 2022-02-27T18:54:33.505 +C Cache\svalues\sof\sUnpackedRecord.aMem[0]\sinto\snew\sfields\sof\sUnpackedRecord.\nThis\savoids\sextra\sindirections\sand\ssaves\sabout\s750K\scycles. +D 2022-02-27T21:10:49.020 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -557,7 +557,7 @@ F src/shell.c.in 14cdfba32c73cb06169e50cd448632c28359f2bab2a0f803dc4a7f46dfc5b6f F src/sqlite.h.in e82ac380b307659d0892f502b742f825504e78729f4edaadce946003b9c00816 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h a95cb9ed106e3d39e2118e4dcc15a14faec3fa50d0093425083d340d9dfd96e6 -F src/sqliteInt.h f8814239fb1f95056555e2d7fa475750e64681cac4221fb03610d1fde0b79d53 +F src/sqliteInt.h 4a8b7d685781df55ce546b6c72bdbd72bb23ca93f59b6d70d81ed6df22607d75 F src/sqliteLimit.h d7323ffea5208c6af2734574bae933ca8ed2ab728083caa117c9738581a31657 F src/status.c 4b8bc2a6905163a38b739854a35b826c737333fab5b1f8e03fa7eb9a4799c4c1 F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 @@ -628,7 +628,7 @@ F src/vdbe.c 4b969ebe6b61f87a90aebf817bc6ebda5075fe56987591091a9bf22556262484 F src/vdbe.h a1d0e3b934e835e73edd146f2e7c4eadb711b5c9875c18159a57483fd78e550e F src/vdbeInt.h de2348c1643c1ac5bf0932452cbb708f52f52d8b4e29b667abdcfd4bacbf6aa6 F src/vdbeapi.c 8863ffb5a7bac42fe9a68aaa3526ee29fc18fb02a9b27188b756de41e33856e9 -F src/vdbeaux.c 855d86f29143177253c554344362a78ba30feaa221554e17e0cd2b144658f077 +F src/vdbeaux.c fd3a8624f9d100aed25d93b3f3d33becba4a81a5e34ffb20935bae608263eeb6 F src/vdbeblob.c 5e61ce31aca17db8fb60395407457a8c1c7fb471dde405e0cd675974611dcfcd F src/vdbemem.c 7737f0b1c480a32b057849c804d2f21d5389649bb8be80f77ad75df700adc9a1 F src/vdbesort.c 43756031ca7430f7aec3ef904824a7883c4ede783e51f280d99b9b65c0796e35 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 9bda611f0d182a62ac1b68610313143c2e28868c16c7d4362a8f5945c27dd88e -R 76aeac53a072a4a75391246dfc2d8423 +P 36f0f07e505dfb38c61d3b4d5b947013c8793e6796fe690e53864479b9276abb +R 210a5a709d1400d775b9fe8a84643106 U drh -Z 87e616c52c5100e606e896a97c48322f +Z 7b50e756ba7763330519aa8c81aced5b # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 35e6c33ef5..0531823e2d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -36f0f07e505dfb38c61d3b4d5b947013c8793e6796fe690e53864479b9276abb \ No newline at end of file +7cf2d1f0396362aae7b93da75c2036d52ba86acba1cc90abca560bcf0314a22f \ No newline at end of file diff --git a/src/sqliteInt.h b/src/sqliteInt.h index c8dbec2f15..5e6b67c84d 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -2517,6 +2517,11 @@ struct KeyInfo { struct UnpackedRecord { KeyInfo *pKeyInfo; /* Collation and sort-order information */ Mem *aMem; /* Values */ + union { + char *z; /* Cache of aMem[0].z for vdbeRecordCompareString() */ + i64 i; /* Cache of aMem[0].u.i for vdbeRecordCompareInt() */ + } u; + int n; /* Cache of aMem[0].n used by vdbeRecordCompareString() */ u16 nField; /* Number of entries in apMem[] */ i8 default_rc; /* Comparison result if keys are equal */ u8 errCode; /* Error detected by xRecordCompare (CORRUPT or NOMEM) */ diff --git a/src/vdbeaux.c b/src/vdbeaux.c index be9cebd51d..650225d307 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -4710,7 +4710,8 @@ static int vdbeRecordCompareInt( return sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2); } - v = pPKey2->aMem[0].u.i; + assert( pPKey2->u.i == pPKey2->aMem[0].u.i ); + v = pPKey2->u.i; if( v>lhs ){ res = pPKey2->r1; }else if( vaMem[0].flags & MEM_Str ); + assert( pPKey2->aMem[0].n == pPKey2->n ); + assert( pPKey2->aMem[0].z == pPKey2->u.z ); vdbeAssertFieldCountWithinLimits(nKey1, pKey1, pPKey2->pKeyInfo); serial_type = (signed char)(aKey1[1]); @@ -4768,15 +4771,15 @@ vrcs_restart: pPKey2->errCode = (u8)SQLITE_CORRUPT_BKPT; return 0; /* Corruption */ } - nCmp = MIN( pPKey2->aMem[0].n, nStr ); - res = memcmp(&aKey1[szHdr], pPKey2->aMem[0].z, nCmp); + nCmp = MIN( pPKey2->n, nStr ); + res = memcmp(&aKey1[szHdr], pPKey2->u.z, nCmp); if( res>0 ){ res = pPKey2->r2; }else if( res<0 ){ res = pPKey2->r1; }else{ - res = nStr - pPKey2->aMem[0].n; + res = nStr - pPKey2->n; if( res==0 ){ if( pPKey2->nField>1 ){ res = sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1); @@ -4831,6 +4834,7 @@ RecordCompare sqlite3VdbeFindCompare(UnpackedRecord *p){ p->r2 = 1; } if( (flags & MEM_Int) ){ + p->u.i = p->aMem[0].u.i; return vdbeRecordCompareInt; } testcase( flags & MEM_Real ); @@ -4840,6 +4844,8 @@ RecordCompare sqlite3VdbeFindCompare(UnpackedRecord *p){ && p->pKeyInfo->aColl[0]==0 ){ assert( flags & MEM_Str ); + p->u.z = p->aMem[0].z; + p->n = p->aMem[0].n; return vdbeRecordCompareString; } } From b3d981c3b740755dba418024da2a8de1d825ed92 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 28 Feb 2022 02:35:48 +0000 Subject: [PATCH 20/75] Avoid unnecessary deinitialization of the Mem.flags field. FossilOrigin-Name: bb520293d8c11518ba153b986662f081ebfd781d38eb624c509605fa9148f6e9 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbeaux.c | 3 ++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index ca25a7d23f..f855faf0cf 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Cache\svalues\sof\sUnpackedRecord.aMem[0]\sinto\snew\sfields\sof\sUnpackedRecord.\nThis\savoids\sextra\sindirections\sand\ssaves\sabout\s750K\scycles. -D 2022-02-27T21:10:49.020 +C Avoid\sunnecessary\sdeinitialization\sof\sthe\sMem.flags\sfield. +D 2022-02-28T02:35:48.040 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -628,7 +628,7 @@ F src/vdbe.c 4b969ebe6b61f87a90aebf817bc6ebda5075fe56987591091a9bf22556262484 F src/vdbe.h a1d0e3b934e835e73edd146f2e7c4eadb711b5c9875c18159a57483fd78e550e F src/vdbeInt.h de2348c1643c1ac5bf0932452cbb708f52f52d8b4e29b667abdcfd4bacbf6aa6 F src/vdbeapi.c 8863ffb5a7bac42fe9a68aaa3526ee29fc18fb02a9b27188b756de41e33856e9 -F src/vdbeaux.c fd3a8624f9d100aed25d93b3f3d33becba4a81a5e34ffb20935bae608263eeb6 +F src/vdbeaux.c 342a59d99d57185b972fe40b8a9e4bb7d8d52ee8ce327159992ffb3efe55e1ab F src/vdbeblob.c 5e61ce31aca17db8fb60395407457a8c1c7fb471dde405e0cd675974611dcfcd F src/vdbemem.c 7737f0b1c480a32b057849c804d2f21d5389649bb8be80f77ad75df700adc9a1 F src/vdbesort.c 43756031ca7430f7aec3ef904824a7883c4ede783e51f280d99b9b65c0796e35 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 36f0f07e505dfb38c61d3b4d5b947013c8793e6796fe690e53864479b9276abb -R 210a5a709d1400d775b9fe8a84643106 +P 7cf2d1f0396362aae7b93da75c2036d52ba86acba1cc90abca560bcf0314a22f +R 4d4dfe83297801d5193fce44bd4e8a2e U drh -Z 7b50e756ba7763330519aa8c81aced5b +Z 9485415c0ffb00de37ffcb9d694e10b9 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 0531823e2d..0689e20b8f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7cf2d1f0396362aae7b93da75c2036d52ba86acba1cc90abca560bcf0314a22f \ No newline at end of file +bb520293d8c11518ba153b986662f081ebfd781d38eb624c509605fa9148f6e9 \ No newline at end of file diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 650225d307..dea71a3c96 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -1889,8 +1889,9 @@ static void releaseMemArray(Mem *p, int N){ sqlite3DbFreeNN(db, p->zMalloc); p->szMalloc = 0; } - +#ifdef SQLITE_DEBUG p->flags = MEM_Undefined; +#endif }while( (++p) Date: Mon, 28 Feb 2022 03:25:13 +0000 Subject: [PATCH 21/75] An optimization to initMemArray() saves almost 500K cycles. But it seems a little dodgy. I want to think about this more before merging to trunk. Perhaps there is a cleaner way to accomplish the same. FossilOrigin-Name: 7fefd8676110a53e6c98a697e2dbf820740fe602a1e83b6caa8d099c41a15d80 --- manifest | 19 +++++++++++-------- manifest.uuid | 2 +- src/vdbeInt.h | 14 +++++++++----- src/vdbeapi.c | 10 ++++++---- src/vdbeaux.c | 30 ++++++++++++++++++++++++------ 5 files changed, 51 insertions(+), 24 deletions(-) diff --git a/manifest b/manifest index f855faf0cf..d712c505fd 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Avoid\sunnecessary\sdeinitialization\sof\sthe\sMem.flags\sfield. -D 2022-02-28T02:35:48.040 +C An\soptimization\sto\sinitMemArray()\ssaves\salmost\s500K\scycles.\s\sBut\sit\sseems\sa\nlittle\sdodgy.\s\sI\swant\sto\sthink\sabout\sthis\smore\sbefore\smerging\sto\strunk.\nPerhaps\sthere\sis\sa\scleaner\sway\sto\saccomplish\sthe\ssame. +D 2022-02-28T03:25:13.694 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -626,9 +626,9 @@ F src/util.c 602fe229f32a96ceccae4f40824129669582096f7c355f53dbac156c9fecef23 F src/vacuum.c 6c38ddc52f0619865c91dae9c441d4d48bf3040d7dc1bc5b22da1e45547ed0b3 F src/vdbe.c 4b969ebe6b61f87a90aebf817bc6ebda5075fe56987591091a9bf22556262484 F src/vdbe.h a1d0e3b934e835e73edd146f2e7c4eadb711b5c9875c18159a57483fd78e550e -F src/vdbeInt.h de2348c1643c1ac5bf0932452cbb708f52f52d8b4e29b667abdcfd4bacbf6aa6 -F src/vdbeapi.c 8863ffb5a7bac42fe9a68aaa3526ee29fc18fb02a9b27188b756de41e33856e9 -F src/vdbeaux.c 342a59d99d57185b972fe40b8a9e4bb7d8d52ee8ce327159992ffb3efe55e1ab +F src/vdbeInt.h 1336e8e23cec21df0dd83d61d0981e3ce72dd19923e9792182066affa2adbf73 +F src/vdbeapi.c 9daec6f3382a150f1da47fc74f2b3aa5b1790bd9dff322539887d25f18054ca9 +F src/vdbeaux.c e5dfd98fe562475d6519af81667b99d237f4999c4709be219d1084ea1fb0af1f F src/vdbeblob.c 5e61ce31aca17db8fb60395407457a8c1c7fb471dde405e0cd675974611dcfcd F src/vdbemem.c 7737f0b1c480a32b057849c804d2f21d5389649bb8be80f77ad75df700adc9a1 F src/vdbesort.c 43756031ca7430f7aec3ef904824a7883c4ede783e51f280d99b9b65c0796e35 @@ -1944,8 +1944,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 7cf2d1f0396362aae7b93da75c2036d52ba86acba1cc90abca560bcf0314a22f -R 4d4dfe83297801d5193fce44bd4e8a2e +P bb520293d8c11518ba153b986662f081ebfd781d38eb624c509605fa9148f6e9 +R f523ab929bd4578ff1ab123801eb9b63 +T *branch * optimize-init-mem +T *sym-optimize-init-mem * +T -sym-trunk * U drh -Z 9485415c0ffb00de37ffcb9d694e10b9 +Z 9ff8d5adc5911dd21d68c30eb1e14ee4 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 0689e20b8f..d40615c913 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -bb520293d8c11518ba153b986662f081ebfd781d38eb624c509605fa9148f6e9 \ No newline at end of file +7fefd8676110a53e6c98a697e2dbf820740fe602a1e83b6caa8d099c41a15d80 \ No newline at end of file diff --git a/src/vdbeInt.h b/src/vdbeInt.h index cc5fd604d5..dc284fb0bb 100644 --- a/src/vdbeInt.h +++ b/src/vdbeInt.h @@ -199,6 +199,10 @@ struct VdbeFrame { ** Internally, the vdbe manipulates nearly all SQL values as Mem ** structures. Each Mem struct may cache multiple representations (string, ** integer etc.) of the same value. +** +** Code uses offsetof() on this object. Order of the fields is important. +** Search for tag-20220228a to find all places that need to change when the +** field order changes. */ struct sqlite3_value { union MemValue { @@ -208,16 +212,16 @@ struct sqlite3_value { const char *zPType; /* Pointer type when MEM_Term|MEM_Subtype|MEM_Null */ FuncDef *pDef; /* Used only when flags==MEM_Agg */ } u; + char *z; /* String or BLOB value */ + int n; /* Number of characters in string value, excluding '\0' */ u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */ u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */ u8 eSubtype; /* Subtype for this value */ - int n; /* Number of characters in string value, excluding '\0' */ - char *z; /* String or BLOB value */ /* ShallowCopy only needs to copy the information above */ - char *zMalloc; /* Space to hold MEM_Str or MEM_Blob if szMalloc>0 */ + sqlite3 *db; /* The associated database connection */ int szMalloc; /* Size of the zMalloc allocation */ u32 uTemp; /* Transient storage for serial_type in OP_MakeRecord */ - sqlite3 *db; /* The associated database connection */ + char *zMalloc; /* Space to hold MEM_Str or MEM_Blob if szMalloc>0 */ void (*xDel)(void*);/* Destructor for Mem.z - only valid if MEM_Dyn */ #ifdef SQLITE_DEBUG Mem *pScopyFrom; /* This Mem is a shallow copy of pScopyFrom */ @@ -229,7 +233,7 @@ struct sqlite3_value { ** Size of struct Mem not including the Mem.zMalloc member or anything that ** follows. */ -#define MEMCELLSIZE offsetof(Mem,zMalloc) +#define MEMCELLSIZE offsetof(Mem,db) /* One or more of the following flags are set to indicate the validOK ** representations of the value stored in the Mem struct. diff --git a/src/vdbeapi.c b/src/vdbeapi.c index 6939813a27..69f3d7b120 100644 --- a/src/vdbeapi.c +++ b/src/vdbeapi.c @@ -1087,6 +1087,8 @@ int sqlite3_data_count(sqlite3_stmt *pStmt){ /* ** Return a pointer to static memory containing an SQL NULL value. +** +** Must be revised if column order for Mem changes. tag-20220228a. */ static const Mem *columnNullValue(void){ /* Even though the Mem structure contains an element @@ -1104,15 +1106,15 @@ static const Mem *columnNullValue(void){ #endif = { /* .u = */ {0}, + /* .z = */ (char*)0, + /* .n = */ (int)0, /* .flags = */ (u16)MEM_Null, /* .enc = */ (u8)0, /* .eSubtype = */ (u8)0, - /* .n = */ (int)0, - /* .z = */ (char*)0, - /* .zMalloc = */ (char*)0, + /* .db = */ (sqlite3*)0, /* .szMalloc = */ (int)0, /* .uTemp = */ (u32)0, - /* .db = */ (sqlite3*)0, + /* .zMalloc = */ (char*)0, /* .xDel = */ (void(*)(void*))0, #ifdef SQLITE_DEBUG /* .pScopyFrom = */ (Mem*)0, diff --git a/src/vdbeaux.c b/src/vdbeaux.c index dea71a3c96..0d91124c9d 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -1838,16 +1838,34 @@ void sqlite3VdbePrintOp(FILE *pOut, int pc, VdbeOp *pOp){ /* ** Initialize an array of N Mem element. +** +** This is a high-runner, so it is optimized by taking advantage of the +** order of the fields in a Mem object and using memcpy() rather than +** individually setting each field. For each Mem, we need to set: +** +** Mem.flags = flags +** Mem.db = db +** Mem.szMalloc = 0 +** +** All other fields of Mem can safely remain uninitialized for now. They +** will be initialized before use. The fields that are initialized by this +** routine are grouped together so that they can be set using memcpy(). +** +** tag-20220228a */ static void initMemArray(Mem *p, int N, sqlite3 *db, u16 flags){ - while( (N--)>0 ){ - p->db = db; - p->flags = flags; - p->szMalloc = 0; + if( N>0 ){ + Mem x; + x.flags = flags; + x.db = db; + x.szMalloc = 0; + do{ + memcpy(&p->flags, &x.flags, offsetof(Mem,uTemp)-offsetof(Mem,flags)); #ifdef SQLITE_DEBUG - p->pScopyFrom = 0; + p->pScopyFrom = 0; #endif - p++; + p++; + }while( (--N)>0 ); } } From 4296357c90fa9c67ef2ce6e5e68d8ec1b3e1b40e Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 28 Feb 2022 12:08:09 +0000 Subject: [PATCH 22/75] The performance increase in the previous check-in of this branch was due to the revised loop in initMemArray() and reordering fields of Mem - not the call the memcpy(). Changing the code to avoid memcpy() results in an even better gain, and code that is far less dodgy. FossilOrigin-Name: d74aa979530d4236f5900d2ef998b27065d352d7c18bcd822e5c8f1041a1a81c --- manifest | 19 ++++++++----------- manifest.uuid | 2 +- src/vdbeInt.h | 4 ---- src/vdbeapi.c | 2 -- src/vdbeaux.c | 20 ++++++++------------ 5 files changed, 17 insertions(+), 30 deletions(-) diff --git a/manifest b/manifest index d712c505fd..a4673e8d7e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C An\soptimization\sto\sinitMemArray()\ssaves\salmost\s500K\scycles.\s\sBut\sit\sseems\sa\nlittle\sdodgy.\s\sI\swant\sto\sthink\sabout\sthis\smore\sbefore\smerging\sto\strunk.\nPerhaps\sthere\sis\sa\scleaner\sway\sto\saccomplish\sthe\ssame. -D 2022-02-28T03:25:13.694 +C The\sperformance\sincrease\sin\sthe\sprevious\scheck-in\sof\sthis\sbranch\swas\sdue\sto\nthe\srevised\sloop\sin\sinitMemArray()\sand\sreordering\sfields\sof\sMem\s-\snot\sthe\ncall\sthe\smemcpy().\s\sChanging\sthe\scode\sto\savoid\smemcpy()\sresults\sin\san\seven\nbetter\sgain,\sand\scode\sthat\sis\sfar\sless\sdodgy. +D 2022-02-28T12:08:09.462 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -626,9 +626,9 @@ F src/util.c 602fe229f32a96ceccae4f40824129669582096f7c355f53dbac156c9fecef23 F src/vacuum.c 6c38ddc52f0619865c91dae9c441d4d48bf3040d7dc1bc5b22da1e45547ed0b3 F src/vdbe.c 4b969ebe6b61f87a90aebf817bc6ebda5075fe56987591091a9bf22556262484 F src/vdbe.h a1d0e3b934e835e73edd146f2e7c4eadb711b5c9875c18159a57483fd78e550e -F src/vdbeInt.h 1336e8e23cec21df0dd83d61d0981e3ce72dd19923e9792182066affa2adbf73 -F src/vdbeapi.c 9daec6f3382a150f1da47fc74f2b3aa5b1790bd9dff322539887d25f18054ca9 -F src/vdbeaux.c e5dfd98fe562475d6519af81667b99d237f4999c4709be219d1084ea1fb0af1f +F src/vdbeInt.h 2ff02995d153d30d362c99d27248b8a3bf825617a8e0d4d8d1e0231eca3bc4f7 +F src/vdbeapi.c 1c80efbe51118bbecc7279023e75d18edcfa4b3dc441287e1718ee70ad594f58 +F src/vdbeaux.c 0f3ce77dabb1f897cc7d3812ed162ec5d31d2298d1aa41b606f8048a742c4b9e F src/vdbeblob.c 5e61ce31aca17db8fb60395407457a8c1c7fb471dde405e0cd675974611dcfcd F src/vdbemem.c 7737f0b1c480a32b057849c804d2f21d5389649bb8be80f77ad75df700adc9a1 F src/vdbesort.c 43756031ca7430f7aec3ef904824a7883c4ede783e51f280d99b9b65c0796e35 @@ -1944,11 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P bb520293d8c11518ba153b986662f081ebfd781d38eb624c509605fa9148f6e9 -R f523ab929bd4578ff1ab123801eb9b63 -T *branch * optimize-init-mem -T *sym-optimize-init-mem * -T -sym-trunk * +P 7fefd8676110a53e6c98a697e2dbf820740fe602a1e83b6caa8d099c41a15d80 +R 0cbe8ba68087a6c2d38d406f08a0fa0f U drh -Z 9ff8d5adc5911dd21d68c30eb1e14ee4 +Z d7015a158f91cecfa6d5c894c1220cae # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d40615c913..7529ec2db4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7fefd8676110a53e6c98a697e2dbf820740fe602a1e83b6caa8d099c41a15d80 \ No newline at end of file +d74aa979530d4236f5900d2ef998b27065d352d7c18bcd822e5c8f1041a1a81c \ No newline at end of file diff --git a/src/vdbeInt.h b/src/vdbeInt.h index dc284fb0bb..657c6f8cf6 100644 --- a/src/vdbeInt.h +++ b/src/vdbeInt.h @@ -199,10 +199,6 @@ struct VdbeFrame { ** Internally, the vdbe manipulates nearly all SQL values as Mem ** structures. Each Mem struct may cache multiple representations (string, ** integer etc.) of the same value. -** -** Code uses offsetof() on this object. Order of the fields is important. -** Search for tag-20220228a to find all places that need to change when the -** field order changes. */ struct sqlite3_value { union MemValue { diff --git a/src/vdbeapi.c b/src/vdbeapi.c index 69f3d7b120..83f7b0fd65 100644 --- a/src/vdbeapi.c +++ b/src/vdbeapi.c @@ -1087,8 +1087,6 @@ int sqlite3_data_count(sqlite3_stmt *pStmt){ /* ** Return a pointer to static memory containing an SQL NULL value. -** -** Must be revised if column order for Mem changes. tag-20220228a. */ static const Mem *columnNullValue(void){ /* Even though the Mem structure contains an element diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 0d91124c9d..54332caa37 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -1839,28 +1839,24 @@ void sqlite3VdbePrintOp(FILE *pOut, int pc, VdbeOp *pOp){ /* ** Initialize an array of N Mem element. ** -** This is a high-runner, so it is optimized by taking advantage of the -** order of the fields in a Mem object and using memcpy() rather than -** individually setting each field. For each Mem, we need to set: +** This is a high-runner, so only those fields that really do need to +** be initialized are set. The Mem structure is organized so that +** the fields that get initialized are nearby and hopefully on the same +** cache line. ** ** Mem.flags = flags ** Mem.db = db ** Mem.szMalloc = 0 ** ** All other fields of Mem can safely remain uninitialized for now. They -** will be initialized before use. The fields that are initialized by this -** routine are grouped together so that they can be set using memcpy(). -** -** tag-20220228a +** will be initialized before use. */ static void initMemArray(Mem *p, int N, sqlite3 *db, u16 flags){ if( N>0 ){ - Mem x; - x.flags = flags; - x.db = db; - x.szMalloc = 0; do{ - memcpy(&p->flags, &x.flags, offsetof(Mem,uTemp)-offsetof(Mem,flags)); + p->flags = flags; + p->db = db; + p->szMalloc = 0; #ifdef SQLITE_DEBUG p->pScopyFrom = 0; #endif From 74a12dd6fd1cd358d1cd264132096d1302ddcad0 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 28 Feb 2022 13:38:28 +0000 Subject: [PATCH 23/75] Expand the comment on the definition of the Mem object to better explain the meanings of the various flag bits. FossilOrigin-Name: f2f0426035d4e0334be000a3eb62bbd7d61fdab7c2ef9ba13cfdf6482396dd13 --- manifest | 13 ++++++------- manifest.uuid | 2 +- src/vdbeInt.h | 37 ++++++++++++++++++++++++++++++++++++- 3 files changed, 43 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 280478ad3f..cf4cae4a5a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Performance\soptimization\sin\sinitMemArray()\ssaves\sabout\s750K\scycles\swith\sonly\na\s4-byte\sincrease\sin\scode\ssize. -D 2022-02-28T12:16:51.464 +C Expand\sthe\scomment\son\sthe\sdefinition\sof\sthe\sMem\sobject\sto\sbetter\sexplain\sthe\nmeanings\sof\sthe\svarious\sflag\sbits. +D 2022-02-28T13:38:28.184 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -626,7 +626,7 @@ F src/util.c 602fe229f32a96ceccae4f40824129669582096f7c355f53dbac156c9fecef23 F src/vacuum.c 6c38ddc52f0619865c91dae9c441d4d48bf3040d7dc1bc5b22da1e45547ed0b3 F src/vdbe.c 4b969ebe6b61f87a90aebf817bc6ebda5075fe56987591091a9bf22556262484 F src/vdbe.h a1d0e3b934e835e73edd146f2e7c4eadb711b5c9875c18159a57483fd78e550e -F src/vdbeInt.h 2ff02995d153d30d362c99d27248b8a3bf825617a8e0d4d8d1e0231eca3bc4f7 +F src/vdbeInt.h d23573156379d0666dc3f04f0305ea50385ecaf7c788413a530a2523dbaf2c54 F src/vdbeapi.c 1c80efbe51118bbecc7279023e75d18edcfa4b3dc441287e1718ee70ad594f58 F src/vdbeaux.c 0f3ce77dabb1f897cc7d3812ed162ec5d31d2298d1aa41b606f8048a742c4b9e F src/vdbeblob.c 5e61ce31aca17db8fb60395407457a8c1c7fb471dde405e0cd675974611dcfcd @@ -1944,9 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P bb520293d8c11518ba153b986662f081ebfd781d38eb624c509605fa9148f6e9 d74aa979530d4236f5900d2ef998b27065d352d7c18bcd822e5c8f1041a1a81c -R 0cbe8ba68087a6c2d38d406f08a0fa0f -T +closed d74aa979530d4236f5900d2ef998b27065d352d7c18bcd822e5c8f1041a1a81c +P c3e9cd5e7430be0653a96a2097a695447549980e08cc8bd8d8097a50c954908e +R 1afa8d37576887b173d9bf5fb651f41d U drh -Z 9bc2a643cc2decfa66e7a766c34e11ae +Z dd0779de4c53c5ff450355df311fc955 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 26a86980c5..158dfc4444 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c3e9cd5e7430be0653a96a2097a695447549980e08cc8bd8d8097a50c954908e \ No newline at end of file +f2f0426035d4e0334be000a3eb62bbd7d61fdab7c2ef9ba13cfdf6482396dd13 \ No newline at end of file diff --git a/src/vdbeInt.h b/src/vdbeInt.h index 657c6f8cf6..26a7bc0def 100644 --- a/src/vdbeInt.h +++ b/src/vdbeInt.h @@ -231,9 +231,44 @@ struct sqlite3_value { */ #define MEMCELLSIZE offsetof(Mem,db) -/* One or more of the following flags are set to indicate the validOK +/* One or more of the following flags are set to indicate the ** representations of the value stored in the Mem struct. ** +** * MEM_Null An SQL NULL value +** +** * MEM_Null|MEM_Zero An SQL NULL with the virtual table +** UPDATE no-change flag set +** +** * MEM_Null|MEM_Term| An SQL NULL, but also contains a +** MEM_Subtype pointer accessible using +** sqlite3_value_pointer(). +** +** * MEM_Null|MEM_Cleared Special SQL NULL that compares non-equal +** to other NULLs even using the IS operator. +** +** * MEM_Str A string, stored in Mem.z with +** length Mem.n. Zero-terminated if +** MEM_Term is set. This flag is +** incompatible with MEM_Blob and +** MEM_Null, but can appear with MEM_Int, +** MEM_Real, and MEM_IntReal. +** +** * MEM_Blob A blob, stored in Mem.z length Mem.n. +** Incompatible with MEM_Str, MEM_Null, +** MEM_Int, MEM_Real, and MEM_IntReal. +** +** * MEM_Blob|MEM_Zero A blob in Mem.z of length Mem.n plus +** MEM.u.i extra 0x00 bytes at the end. +** +** * MEM_Int Integer stored in Mem.u.i. +** +** * MEM_Real Real stored in Mem.u.r. +** +** * MEM_IntReal Real stored as an integer in Mem.u.i. +** +** * MEM_Undefined An undefined and/or uninitialized value. +** Trying to use an Undefined value is an error. +** ** If the MEM_Null flag is set, then the value is an SQL NULL value. ** For a pointer type created using sqlite3_bind_pointer() or ** sqlite3_result_pointer() the MEM_Term and MEM_Subtype flags are also set. From 8552b10c45578bb8e7f37ab5c44416e8f1ed7f35 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 28 Feb 2022 14:26:33 +0000 Subject: [PATCH 24/75] Reorganize the bits in Mem.flags. Free up one bit for reuse. FossilOrigin-Name: fe454291d959c299d6608dfc165c9e05fb53e431b0fc7aed1cb4a557cd61d8ab --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbeInt.h | 46 ++++++++++++++++++++++------------------------ 3 files changed, 29 insertions(+), 31 deletions(-) diff --git a/manifest b/manifest index cf4cae4a5a..c214ca0a37 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Expand\sthe\scomment\son\sthe\sdefinition\sof\sthe\sMem\sobject\sto\sbetter\sexplain\sthe\nmeanings\sof\sthe\svarious\sflag\sbits. -D 2022-02-28T13:38:28.184 +C Reorganize\sthe\sbits\sin\sMem.flags.\s\sFree\sup\sone\sbit\sfor\sreuse. +D 2022-02-28T14:26:33.757 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -626,7 +626,7 @@ F src/util.c 602fe229f32a96ceccae4f40824129669582096f7c355f53dbac156c9fecef23 F src/vacuum.c 6c38ddc52f0619865c91dae9c441d4d48bf3040d7dc1bc5b22da1e45547ed0b3 F src/vdbe.c 4b969ebe6b61f87a90aebf817bc6ebda5075fe56987591091a9bf22556262484 F src/vdbe.h a1d0e3b934e835e73edd146f2e7c4eadb711b5c9875c18159a57483fd78e550e -F src/vdbeInt.h d23573156379d0666dc3f04f0305ea50385ecaf7c788413a530a2523dbaf2c54 +F src/vdbeInt.h 958066f0448930dac697a7d1fc345d1b5fd1bb2d93685860967b94c901a7b244 F src/vdbeapi.c 1c80efbe51118bbecc7279023e75d18edcfa4b3dc441287e1718ee70ad594f58 F src/vdbeaux.c 0f3ce77dabb1f897cc7d3812ed162ec5d31d2298d1aa41b606f8048a742c4b9e F src/vdbeblob.c 5e61ce31aca17db8fb60395407457a8c1c7fb471dde405e0cd675974611dcfcd @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P c3e9cd5e7430be0653a96a2097a695447549980e08cc8bd8d8097a50c954908e -R 1afa8d37576887b173d9bf5fb651f41d +P f2f0426035d4e0334be000a3eb62bbd7d61fdab7c2ef9ba13cfdf6482396dd13 +R 212742c08d61f97ea8c5e2c9e09ba4bf U drh -Z dd0779de4c53c5ff450355df311fc955 +Z 643db4bc2b127b89002f367b4377945f # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 158dfc4444..c52afd36d2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f2f0426035d4e0334be000a3eb62bbd7d61fdab7c2ef9ba13cfdf6482396dd13 \ No newline at end of file +fe454291d959c299d6608dfc165c9e05fb53e431b0fc7aed1cb4a557cd61d8ab \ No newline at end of file diff --git a/src/vdbeInt.h b/src/vdbeInt.h index 26a7bc0def..8ef2795551 100644 --- a/src/vdbeInt.h +++ b/src/vdbeInt.h @@ -266,9 +266,6 @@ struct sqlite3_value { ** ** * MEM_IntReal Real stored as an integer in Mem.u.i. ** -** * MEM_Undefined An undefined and/or uninitialized value. -** Trying to use an Undefined value is an error. -** ** If the MEM_Null flag is set, then the value is an SQL NULL value. ** For a pointer type created using sqlite3_bind_pointer() or ** sqlite3_result_pointer() the MEM_Term and MEM_Subtype flags are also set. @@ -279,6 +276,7 @@ struct sqlite3_value { ** set, then the string is nul terminated. The MEM_Int and MEM_Real ** flags may coexist with the MEM_Str flag. */ +#define MEM_Undefined 0x0000 /* Value is undefined */ #define MEM_Null 0x0001 /* Value is NULL (or a pointer) */ #define MEM_Str 0x0002 /* Value is a string */ #define MEM_Int 0x0004 /* Value is an integer */ @@ -286,28 +284,24 @@ struct sqlite3_value { #define MEM_Blob 0x0010 /* Value is a BLOB */ #define MEM_IntReal 0x0020 /* MEM_Int that stringifies like MEM_Real */ #define MEM_AffMask 0x003f /* Mask of affinity bits */ -#define MEM_FromBind 0x0040 /* Value originates from sqlite3_bind() */ -#define MEM_Undefined 0x0080 /* Value is undefined */ -#define MEM_Cleared 0x0100 /* NULL set by OP_Null, not from data */ -#define MEM_TypeMask 0xc1bf /* Mask of type bits */ - -/* Whenever Mem contains a valid string or blob representation, one of -** the following flags must be set to determine the memory management -** policy for Mem.z. The MEM_Term flag tells us whether or not the -** string is \000 or \u0000 terminated +/* Extra bits that modify the meanings of the core datatypes above */ +#define MEM_FromBind 0x0040 /* Value originates from sqlite3_bind() */ + /* 0x0080 // Available */ +#define MEM_Cleared 0x0100 /* NULL set by OP_Null, not from data */ #define MEM_Term 0x0200 /* String in Mem.z is zero terminated */ -#define MEM_Dyn 0x0400 /* Need to call Mem.xDel() on Mem.z */ -#define MEM_Static 0x0800 /* Mem.z points to a static string */ -#define MEM_Ephem 0x1000 /* Mem.z points to an ephemeral string */ -#define MEM_Agg 0x2000 /* Mem.z points to an agg function context */ -#define MEM_Zero 0x4000 /* Mem.i contains count of 0s appended to blob */ -#define MEM_Subtype 0x8000 /* Mem.eSubtype is valid */ -#ifdef SQLITE_OMIT_INCRBLOB - #undef MEM_Zero - #define MEM_Zero 0x0000 -#endif +#define MEM_Zero 0x0400 /* Mem.i contains count of 0s appended to blob */ +#define MEM_Subtype 0x0800 /* Mem.eSubtype is valid */ +#define MEM_TypeMask 0x0dbf /* Mask of type bits */ + +/* Bits that determine the storage for Mem.z for a string or blob or +** aggregate accumulator. +*/ +#define MEM_Dyn 0x1000 /* Need to call Mem.xDel() on Mem.z */ +#define MEM_Static 0x2000 /* Mem.z points to a static string */ +#define MEM_Ephem 0x4000 /* Mem.z points to an ephemeral string */ +#define MEM_Agg 0x8000 /* Mem.z points to an agg function context */ /* Return TRUE if Mem X contains dynamically allocated content - anything ** that needs to be deallocated to avoid a leak. @@ -329,11 +323,15 @@ struct sqlite3_value { && (X)->n==0 && (X)->u.nZero==0) /* -** Return true if a memory cell is not marked as invalid. This macro +** Return true if a memory cell has been initialized and is valid. ** is for use inside assert() statements only. +** +** A Memory cell is initialized if at least one of the +** MEM_Null, MEM_Str, MEM_Int, MEM_Real, MEM_Blob, or MEM_IntReal bits +** is set. It is "undefined" if all those bits are zero. */ #ifdef SQLITE_DEBUG -#define memIsValid(M) ((M)->flags & MEM_Undefined)==0 +#define memIsValid(M) ((M)->flags & MEM_AffMask)!=0 #endif /* From 935c37229ca9f9a02ab076756ba4e95dcb4c44d7 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 28 Feb 2022 16:44:58 +0000 Subject: [PATCH 25/75] Fix the Xfer-optimization on the INSERT statement so that it is omitted if there is a RETURNING clause, since that optimization is not able to deal with RETURNING. See [forum:/forumpost/595e132f71|forum thread 595e132f71] for details. FossilOrigin-Name: 1d3760a517b8bd2a6be82d2d5788945f49397cdc539fe28fd23e2c0c62a1dbe2 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/insert.c | 13 ++++++------- test/insert4.test | 8 +++++++- test/returning1.test | 14 ++++++++++++++ 5 files changed, 36 insertions(+), 17 deletions(-) diff --git a/manifest b/manifest index c214ca0a37..c13f3872f4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Reorganize\sthe\sbits\sin\sMem.flags.\s\sFree\sup\sone\sbit\sfor\sreuse. -D 2022-02-28T14:26:33.757 +C Fix\sthe\sXfer-optimization\son\sthe\sINSERT\sstatement\sso\sthat\sit\sis\somitted\sif\nthere\sis\sa\sRETURNING\sclause,\ssince\sthat\soptimization\sis\snot\sable\sto\sdeal\nwith\sRETURNING.\s\sSee\s[forum:/forumpost/595e132f71|forum\sthread\s595e132f71]\nfor\sdetails. +D 2022-02-28T16:44:58.607 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -512,7 +512,7 @@ F src/hash.c 8d7dda241d0ebdafb6ffdeda3149a412d7df75102cecfc1021c98d6219823b19 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h cb1d7e3e1ed94b7aa6fde95ae2c2daccc3df826be26fc9ed7fd90d1750ae6144 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 -F src/insert.c 1eea44389de3768ac98588c1410171cd53e7c6ad1af74049983dcbac82093de0 +F src/insert.c 9fbf8704562fe17e442c16b7f60d3d91101ea69fc45c2bce96ee6cb982e86d2f F src/json.c 225b00422112ecd7094a555f3ace16b25d7d5894062b823269ed03899907c2a2 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c aa919a6a7884f8b34d7b791841b24d14b1b0ab43f45b3940f4851043b2855c0c @@ -1121,7 +1121,7 @@ F test/init.test 15c823093fdabbf7b531fe22cf037134d09587a7 F test/insert.test 4e3f0de67aac3c5be1f4aaedbcea11638f1b5cdc9a3115be14d19aa9db7623c6 F test/insert2.test 4d14b8f1b810a41995f6286b64a6943215d52208 F test/insert3.test 1b7db95a03ad9c5013fdf7d6722b6cd66ee55e30 -F test/insert4.test 59cb99521be01a5aefc9be8e8b5a51ee7f3944781d4d7f6201b9f774fcd51662 +F test/insert4.test 2bf81535a990c969665d66db51fcf76c23499b39893b5109f413d1de4ad34cd3 F test/insert5.test 394f96728d1258f406fe5f5aeb0aaf29487c39a6 F test/insertfault.test ac63d14ea3b49c573673a572f4014b9117383a03e497c58f308b5c776e4a7f74 F test/instr.test 107df2b9b74a4b59315916b575590a08f2a714de0754abe541f10a0971d0a2a4 @@ -1316,7 +1316,7 @@ F test/reindex.test cd9d6021729910ece82267b4f5e1b5ac2911a7566c43b43c176a6a4732e2 F test/releasetest_data.tcl 11ba48a21ed1c808147b0e77c6e93d204577f4327ffe6d7c3b34cd3c01eac3a2 F test/resetdb.test 8062cf10a09d8c048f8de7711e94571c38b38168db0e5877ba7561789e5eeb2b F test/resolver01.test f4022acafda7f4d40eca94dbf16bc5fc4ac30ceb -F test/returning1.test ee0b115162b17f59fe486767899596b1e8290bcd845db05d7d1d9e6c2dad1b8b +F test/returning1.test c43b8370a351f77aec6d71f4a2cde59b849369ed1933261a2c2c69e23e34ff5e F test/returningfault.test ae4c4b5e8745813287a359d9ccdb9d5c883c2e68afb18fb0767937d5de5692a4 F test/rollback.test 06680159bc6746d0f26276e339e3ae2f951c64812468308838e0a3362d911eaa F test/rollback2.test 3f3a4e20401825017df7e7671e9f31b6de5fae5620c2b9b49917f52f8c160a8f @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P f2f0426035d4e0334be000a3eb62bbd7d61fdab7c2ef9ba13cfdf6482396dd13 -R 212742c08d61f97ea8c5e2c9e09ba4bf +P fe454291d959c299d6608dfc165c9e05fb53e431b0fc7aed1cb4a557cd61d8ab +R e9028d6c34b8a78e7f17a977b6a22df9 U drh -Z 643db4bc2b127b89002f367b4377945f +Z ccd7a3ce5bbeae9f70687f9b0ffdfb00 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index c52afd36d2..a8c037e4c9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fe454291d959c299d6608dfc165c9e05fb53e431b0fc7aed1cb4a557cd61d8ab \ No newline at end of file +1d3760a517b8bd2a6be82d2d5788945f49397cdc539fe28fd23e2c0c62a1dbe2 \ No newline at end of file diff --git a/src/insert.c b/src/insert.c index fd3590cb30..de01be3ba1 100644 --- a/src/insert.c +++ b/src/insert.c @@ -795,7 +795,11 @@ void sqlite3Insert( ** ** This is the 2nd template. */ - if( pColumn==0 && xferOptimization(pParse, pTab, pSelect, onError, iDb) ){ + if( pColumn==0 + && pSelect!=0 + && pTrigger==0 + && xferOptimization(pParse, pTab, pSelect, onError, iDb) + ){ assert( !pTrigger ); assert( pList==0 ); goto insert_end; @@ -2766,18 +2770,13 @@ static int xferOptimization( int destHasUniqueIdx = 0; /* True if pDest has a UNIQUE index */ int regData, regRowid; /* Registers holding data and rowid */ - if( pSelect==0 ){ - return 0; /* Must be of the form INSERT INTO ... SELECT ... */ - } + assert( pSelect!=0 ); if( pParse->pWith || pSelect->pWith ){ /* Do not attempt to process this query if there are an WITH clauses ** attached to it. Proceeding may generate a false "no such table: xxx" ** error if pSelect reads from a CTE named "xxx". */ return 0; } - if( sqlite3TriggerList(pParse, pDest) ){ - return 0; /* tab1 must not have triggers */ - } #ifndef SQLITE_OMIT_VIRTUALTABLE if( IsVirtual(pDest) ){ return 0; /* tab1 must not be a virtual table */ diff --git a/test/insert4.test b/test/insert4.test index 3eca60a84d..8bd65a006f 100644 --- a/test/insert4.test +++ b/test/insert4.test @@ -11,7 +11,6 @@ # This file implements regression tests for SQLite library. The # focus of this file is testing the INSERT transfer optimization. # -# $Id: insert4.test,v 1.10 2008/01/21 16:22:46 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -598,6 +597,13 @@ do_test 10.3 { set sqlite3_xferopt_count } {1} +do_test 10.4 { + execsql { PRAGMA integrity_check } + set sqlite3_xferopt_count 0 + execsql { INSERT INTO x SELECT * FROM t8 RETURNING * } + set sqlite3_xferopt_count +} {0} + #------------------------------------------------------------------------- # xfer transfer between tables where the source has an empty partial index. # diff --git a/test/returning1.test b/test/returning1.test index 2b97b42348..fb058a6438 100644 --- a/test/returning1.test +++ b/test/returning1.test @@ -362,4 +362,18 @@ do_execsql_test 15.2 { DELETE FROM t1 RETURNING x, affinity(x); } {6.0 real} +# 2022-02-28 Forum post https://sqlite.org/forum/forumpost/595e132f71 +# RETURNING with the xfer optimization +# +reset_db +do_execsql_test 16.0 { + CREATE TABLE t1(a,b,c); + INSERT INTO t1 VALUES(1,2,3),('a','b','c'); + CREATE TEMP TABLE t2(x,y,z); + INSERT INTO t2 SELECT * FROM t1 RETURNING *; +} {1 2 3 a b c} +do_execsql_test 16.1 { + SELECT * FROM t2; +} {1 2 3 a b c} + finish_test From 90368c5dcb8a66f98e513f828e2a01bfd72e1c26 Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 1 Mar 2022 14:13:32 +0000 Subject: [PATCH 26/75] Increase the max_page_count on ROLLBACK, if necessary, so that it is sufficient to cover the entire database. Fix for the problem identified by [forum:/forumpost/3b9e894312|forum post 3b9e894312]. FossilOrigin-Name: 12c012162ce110a7a7fbbe853f422e23cb4ae10b45237727328c8f3315b70842 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/pager.c | 3 +++ test/pager1.test | 28 ++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index c13f3872f4..3700f7da5f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\sXfer-optimization\son\sthe\sINSERT\sstatement\sso\sthat\sit\sis\somitted\sif\nthere\sis\sa\sRETURNING\sclause,\ssince\sthat\soptimization\sis\snot\sable\sto\sdeal\nwith\sRETURNING.\s\sSee\s[forum:/forumpost/595e132f71|forum\sthread\s595e132f71]\nfor\sdetails. -D 2022-02-28T16:44:58.607 +C Increase\sthe\smax_page_count\son\sROLLBACK,\sif\snecessary,\sso\sthat\sit\sis\ssufficient\nto\scover\sthe\sentire\sdatabase.\s\sFix\sfor\sthe\sproblem\sidentified\sby\n[forum:/forumpost/3b9e894312|forum\spost\s3b9e894312]. +D 2022-03-01T14:13:32.451 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -539,7 +539,7 @@ F src/os_setup.h 0dbaea40a7d36bf311613d31342e0b99e2536586 F src/os_unix.c f5ad51cfd024116db8531feab9efd831c2621436dca1464e4ff1e8af9bf3252e F src/os_win.c 77d39873836f1831a9b0b91894fec45ab0e9ca8e067dc8c549e1d1eca1566fe9 F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a -F src/pager.c 90a3721b4ab007a835c751a441c1b1fc68bfe68d99dd298f28d91cc163730194 +F src/pager.c 1c415888b3658513c26a79b6a61989ca6463d3770102e6c24372fd7235022b02 F src/pager.h f82e9844166e1585f5786837ddc7709966138ced17f568c16af7ccf946c2baa3 F src/parse.y 0f02b27cdaa334441463153fff3ceb780fea006ab53ffd6ef566d4468f93e924 F src/pcache.c 084e638432c610f95aea72b8509f0845d2791293f39d1b82f0c0a7e089c3bb6b @@ -1272,7 +1272,7 @@ F test/oserror.test 1fc9746b83d778e70d115049747ba19c7fba154afce7cc165b09feb6ca6a F test/ossfuzz.c 9636dad2092a05a32110df0ca06713038dd0c43dd89a77dabe4b8b0d71096715 F test/ossshell.c f125c5bd16e537a2549aa579b328dd1c59905e7ab1338dfc210e755bb7b69f17 F test/ovfl.test 199c482696defceacee8c8e0e0ef36da62726b2f -F test/pager1.test 8cb45ccbdb3ba423fc8158701c8f010a1d104336b8f14ef14bbfbadf14bad700 +F test/pager1.test ffd885cdc98b986c9f746496508c0c4810ed0eaade3575ddf53c222e85880552 F test/pager2.test 67b8f40ae98112bcdba1f2b2d03ea83266418c71 F test/pager3.test 4e9a83d6ca0838d7c602c9eb93d1357562d9059c1e02ffb138a8271020838370 F test/pager4.test a122e9e6925d5b23b31e3dfef8c6a44bbf19590e @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P fe454291d959c299d6608dfc165c9e05fb53e431b0fc7aed1cb4a557cd61d8ab -R e9028d6c34b8a78e7f17a977b6a22df9 +P 1d3760a517b8bd2a6be82d2d5788945f49397cdc539fe28fd23e2c0c62a1dbe2 +R a263a674387992906dd7cdc654c455fb U drh -Z ccd7a3ce5bbeae9f70687f9b0ffdfb00 +Z 752cae2129a5da5a149754dd50e2175d # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index a8c037e4c9..f413b15bd8 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1d3760a517b8bd2a6be82d2d5788945f49397cdc539fe28fd23e2c0c62a1dbe2 \ No newline at end of file +12c012162ce110a7a7fbbe853f422e23cb4ae10b45237727328c8f3315b70842 \ No newline at end of file diff --git a/src/pager.c b/src/pager.c index c1866cac11..33ed31d7ad 100644 --- a/src/pager.c +++ b/src/pager.c @@ -2845,6 +2845,9 @@ static int pager_playback(Pager *pPager, int isHot){ goto end_playback; } pPager->dbSize = mxPg; + if( pPager->mxPgnomxPgno = mxPg; + } } /* Copy original pages out of the journal and back into the diff --git a/test/pager1.test b/test/pager1.test index ff7d3e4061..79598e2a70 100644 --- a/test/pager1.test +++ b/test/pager1.test @@ -2925,4 +2925,32 @@ do_test 43.3 { sqlite3_db_status db CACHE_MISS 0 } {0 1 0} +# 2022-03-01 Forum post https://sqlite.org/forum/forumpost/3b9e894312 +# Ensure that max_page_count gets adjusted upward, if needed, on a +# ROLLBACK. +# +db close +sqlite3 db :memory: +do_execsql_test 44.1 { + PRAGMA page_size=4096; + PRAGMA auto_vacuum=FULL; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b ANY); + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<50) + INSERT INTO t1(a,b) SELECT x, zeroblob(1000) FROM c; + CREATE TABLE t2 AS SELECT * FROM t1; + PRAGMA page_count; +} {31} +do_execsql_test 44.2 { + BEGIN; + DROP TABLE t2; + PRAGMA incremental_vacuum=50; + PRAGMA page_count; + PRAGMA max_page_count=2; +} {16 16} +do_execsql_test 44.3 { + ROLLBACK; + PRAGMA page_count; + PRAGMA max_page_count; +} {31 31} + finish_test From e7fae604a0e86308ab60affa07ceb3b3834e2bab Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 1 Mar 2022 15:48:16 +0000 Subject: [PATCH 27/75] Fix slightly-incorrect assert() statements. [forum:/forumpost/f1e83b77b5ff37db|Forum post f1e83b77b5ff37db] FossilOrigin-Name: 3c9f5c9defd7d36684132ae4ade9db2e2148dad4bd91bfe9374620ecafc35348 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/btree.c | 2 +- src/pcache.c | 3 ++- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 3700f7da5f..b1024b6817 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Increase\sthe\smax_page_count\son\sROLLBACK,\sif\snecessary,\sso\sthat\sit\sis\ssufficient\nto\scover\sthe\sentire\sdatabase.\s\sFix\sfor\sthe\sproblem\sidentified\sby\n[forum:/forumpost/3b9e894312|forum\spost\s3b9e894312]. -D 2022-03-01T14:13:32.451 +C Fix\sslightly-incorrect\sassert()\sstatements.\n[forum:/forumpost/f1e83b77b5ff37db|Forum\spost\sf1e83b77b5ff37db] +D 2022-03-01T15:48:16.615 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -492,7 +492,7 @@ F src/auth.c f4fa91b6a90bbc8e0d0f738aa284551739c9543a367071f55574681e0f24f8cf F src/backup.c a2891172438e385fdbe97c11c9745676bec54f518d4447090af97189fd8e52d7 F src/bitvec.c 7c849aac407230278445cb069bebc5f89bf2ddd87c5ed9459b070a9175707b3d F src/btmutex.c 8acc2f464ee76324bf13310df5692a262b801808984c1b79defb2503bbafadb6 -F src/btree.c 11dfaa11397d415fe760ed96d447a1d0cd50db8bd1ee11a91c81a97e364f648c +F src/btree.c e9b7ca07afe4005dcd047b49181c960528e56a0a67797ec4c09a65a15cf7cfa4 F src/btree.h 74d64b8f28cfa4a894d14d4ed64fa432cd697b98b61708d4351482ae15913e22 F src/btreeInt.h 7282a6e77775f93a6eb78d3a41dab372a01a4ec1d93d3b4728d191d15fda42e2 F src/build.c 9891c2160886cf7e344d7e8f1f7177f9612916c7c67ffeacd64cb34a92d387a8 @@ -542,7 +542,7 @@ F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a F src/pager.c 1c415888b3658513c26a79b6a61989ca6463d3770102e6c24372fd7235022b02 F src/pager.h f82e9844166e1585f5786837ddc7709966138ced17f568c16af7ccf946c2baa3 F src/parse.y 0f02b27cdaa334441463153fff3ceb780fea006ab53ffd6ef566d4468f93e924 -F src/pcache.c 084e638432c610f95aea72b8509f0845d2791293f39d1b82f0c0a7e089c3bb6b +F src/pcache.c 0aab73936341fad83d107cf62c6a7bc2d2d5fb9aaec8c3ce61e19fc18e4560fc F src/pcache.h 4f87acd914cef5016fae3030343540d75f5b85a1877eed1a2a19b9f284248586 F src/pcache1.c 54881292a9a5db202b2c0ac541c5e3ef9a5e8c4f1c1383adb2601d5499a60e65 F src/pragma.c a7323cd175587afa0b82c213b9bba5789fe9ea67f9e5d66e35df00742a923bcc @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 1d3760a517b8bd2a6be82d2d5788945f49397cdc539fe28fd23e2c0c62a1dbe2 -R a263a674387992906dd7cdc654c455fb +P 12c012162ce110a7a7fbbe853f422e23cb4ae10b45237727328c8f3315b70842 +R 0ec794fb0f5ba9deb5bc4890e9cda4ec U drh -Z 752cae2129a5da5a149754dd50e2175d +Z 0cf3035e6ec855c63a0dc18af5169a25 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index f413b15bd8..af1a9cc6ca 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -12c012162ce110a7a7fbbe853f422e23cb4ae10b45237727328c8f3315b70842 \ No newline at end of file +3c9f5c9defd7d36684132ae4ade9db2e2148dad4bd91bfe9374620ecafc35348 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 288a141ec6..08ea6f29c8 100644 --- a/src/btree.c +++ b/src/btree.c @@ -9041,7 +9041,7 @@ int sqlite3BtreeInsert( assert( pPage->intKey || pX->nKey>=0 || (flags & BTREE_PREFORMAT) ); assert( pPage->leaf || !pPage->intKey ); if( pPage->nFree<0 ){ - if( NEVER(pCur->eState>CURSOR_INVALID) ){ + if( pCur->eState>CURSOR_INVALID ){ rc = SQLITE_CORRUPT_BKPT; }else{ rc = btreeComputeFreeSpace(pPage); diff --git a/src/pcache.c b/src/pcache.c index 14d1e7cde0..76cc4bb7a9 100644 --- a/src/pcache.c +++ b/src/pcache.c @@ -551,7 +551,8 @@ void sqlite3PcacheDrop(PgHdr *p){ ** make it so. */ void sqlite3PcacheMakeDirty(PgHdr *p){ - assert( p->nRef>0 ); + assert( p->nRef>0 || p->pCache->bPurgeable==0 ); + testcase( p->nRef==0 ); assert( sqlite3PcachePageSanity(p) ); if( p->flags & (PGHDR_CLEAN|PGHDR_DONT_WRITE) ){ /*OPTIMIZATION-IF-FALSE*/ p->flags &= ~PGHDR_DONT_WRITE; From 3703429cdb955dedb52378338f37494910730425 Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 1 Mar 2022 16:22:54 +0000 Subject: [PATCH 28/75] Fix two assert() statements in btree.c which were not true in the case of a corrupt database file. [forum:/forumpost/14819f2063|Forum post 14819f2063]. FossilOrigin-Name: 3b36ed79d82fae47a08a7d27f4fcefb7978fdf0e7f8c0f4a82f59501f201b32b --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/btree.c | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index b1024b6817..a085c17a7e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sslightly-incorrect\sassert()\sstatements.\n[forum:/forumpost/f1e83b77b5ff37db|Forum\spost\sf1e83b77b5ff37db] -D 2022-03-01T15:48:16.615 +C Fix\stwo\sassert()\sstatements\sin\sbtree.c\swhich\swere\snot\strue\sin\sthe\scase\sof\na\scorrupt\sdatabase\sfile.\n[forum:/forumpost/14819f2063|Forum\spost\s14819f2063]. +D 2022-03-01T16:22:54.591 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -492,7 +492,7 @@ F src/auth.c f4fa91b6a90bbc8e0d0f738aa284551739c9543a367071f55574681e0f24f8cf F src/backup.c a2891172438e385fdbe97c11c9745676bec54f518d4447090af97189fd8e52d7 F src/bitvec.c 7c849aac407230278445cb069bebc5f89bf2ddd87c5ed9459b070a9175707b3d F src/btmutex.c 8acc2f464ee76324bf13310df5692a262b801808984c1b79defb2503bbafadb6 -F src/btree.c e9b7ca07afe4005dcd047b49181c960528e56a0a67797ec4c09a65a15cf7cfa4 +F src/btree.c 7ca88aa5572d21cbcb76b59f8264a1fbe14ed705af45e3cc0e7d4d8eb1a7e393 F src/btree.h 74d64b8f28cfa4a894d14d4ed64fa432cd697b98b61708d4351482ae15913e22 F src/btreeInt.h 7282a6e77775f93a6eb78d3a41dab372a01a4ec1d93d3b4728d191d15fda42e2 F src/build.c 9891c2160886cf7e344d7e8f1f7177f9612916c7c67ffeacd64cb34a92d387a8 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 12c012162ce110a7a7fbbe853f422e23cb4ae10b45237727328c8f3315b70842 -R 0ec794fb0f5ba9deb5bc4890e9cda4ec +P 3c9f5c9defd7d36684132ae4ade9db2e2148dad4bd91bfe9374620ecafc35348 +R d7be88b69a61c70ed08f890c1f637015 U drh -Z 0cf3035e6ec855c63a0dc18af5169a25 +Z 0293e7f5122586d466d085516d14c5f5 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index af1a9cc6ca..789a849565 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3c9f5c9defd7d36684132ae4ade9db2e2148dad4bd91bfe9374620ecafc35348 \ No newline at end of file +3b36ed79d82fae47a08a7d27f4fcefb7978fdf0e7f8c0f4a82f59501f201b32b \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 08ea6f29c8..f26e1753f9 100644 --- a/src/btree.c +++ b/src/btree.c @@ -2142,7 +2142,7 @@ static void zeroPage(MemPage *pPage, int flags){ u8 hdr = pPage->hdrOffset; u16 first; - assert( sqlite3PagerPagenumber(pPage->pDbPage)==pPage->pgno ); + assert( sqlite3PagerPagenumber(pPage->pDbPage)==pPage->pgno || CORRUPT_DB ); assert( sqlite3PagerGetExtra(pPage->pDbPage) == (void*)pPage ); assert( sqlite3PagerGetData(pPage->pDbPage) == data ); assert( sqlite3PagerIswriteable(pPage->pDbPage) ); @@ -2284,7 +2284,7 @@ static int getAndInitPage( goto getAndInitPage_error2; } } - assert( (*ppPage)->pgno==pgno ); + assert( (*ppPage)->pgno==pgno || CORRUPT_DB ); assert( (*ppPage)->aData==sqlite3PagerGetData(pDbPage) ); /* If obtaining a child page for a cursor, we must verify that the page is From 3b4cb719c054a6052555a6ebf55038eb052e909b Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 1 Mar 2022 19:19:20 +0000 Subject: [PATCH 29/75] Fix a minor typo in a comment. FossilOrigin-Name: 86ba06aa4c55d3aefe030b19b2b5c08baf46bbb2218b04ac1228ab76682a929b --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/btree.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index a085c17a7e..a705549b4b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\stwo\sassert()\sstatements\sin\sbtree.c\swhich\swere\snot\strue\sin\sthe\scase\sof\na\scorrupt\sdatabase\sfile.\n[forum:/forumpost/14819f2063|Forum\spost\s14819f2063]. -D 2022-03-01T16:22:54.591 +C Fix\sa\sminor\stypo\sin\sa\scomment. +D 2022-03-01T19:19:20.084 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -492,7 +492,7 @@ F src/auth.c f4fa91b6a90bbc8e0d0f738aa284551739c9543a367071f55574681e0f24f8cf F src/backup.c a2891172438e385fdbe97c11c9745676bec54f518d4447090af97189fd8e52d7 F src/bitvec.c 7c849aac407230278445cb069bebc5f89bf2ddd87c5ed9459b070a9175707b3d F src/btmutex.c 8acc2f464ee76324bf13310df5692a262b801808984c1b79defb2503bbafadb6 -F src/btree.c 7ca88aa5572d21cbcb76b59f8264a1fbe14ed705af45e3cc0e7d4d8eb1a7e393 +F src/btree.c 7e9400d1582136ca86af9bbb07f8f3e933b284e969cda516bdc755285d137eb2 F src/btree.h 74d64b8f28cfa4a894d14d4ed64fa432cd697b98b61708d4351482ae15913e22 F src/btreeInt.h 7282a6e77775f93a6eb78d3a41dab372a01a4ec1d93d3b4728d191d15fda42e2 F src/build.c 9891c2160886cf7e344d7e8f1f7177f9612916c7c67ffeacd64cb34a92d387a8 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 3c9f5c9defd7d36684132ae4ade9db2e2148dad4bd91bfe9374620ecafc35348 -R d7be88b69a61c70ed08f890c1f637015 +P 3b36ed79d82fae47a08a7d27f4fcefb7978fdf0e7f8c0f4a82f59501f201b32b +R 672415af5b93cf666a13cbb4e5190cf0 U drh -Z 0293e7f5122586d466d085516d14c5f5 +Z f44c78af05c98bc038cc5e60cffa1d77 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 789a849565..4a625fe341 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3b36ed79d82fae47a08a7d27f4fcefb7978fdf0e7f8c0f4a82f59501f201b32b \ No newline at end of file +86ba06aa4c55d3aefe030b19b2b5c08baf46bbb2218b04ac1228ab76682a929b \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index f26e1753f9..fdf259766f 100644 --- a/src/btree.c +++ b/src/btree.c @@ -1457,7 +1457,7 @@ static u16 cellSize(MemPage *pPage, int iCell){ #ifndef SQLITE_OMIT_AUTOVACUUM /* ** The cell pCell is currently part of page pSrc but will ultimately be part -** of pPage. (pSrc and pPager are often the same.) If pCell contains a +** of pPage. (pSrc and pPage are often the same.) If pCell contains a ** pointer to an overflow page, insert an entry into the pointer-map for ** the overflow page that will be valid after pCell has been moved to pPage. */ From a055abb8c4189f5867852a8f67ec6b454eb7e058 Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 1 Mar 2022 20:15:04 +0000 Subject: [PATCH 30/75] The MemPage.aDataEnd field should point to the end of the data buffer for the page, not just the end of the usable portion of that buffer. The purpose aDataEnd is to detect cells that overflow the page, and that won't work on a page with reserved bytes and a cell that starts in the reserved region, unless the boundary is at the very end of the page. Chromium issue 1276294. FossilOrigin-Name: f839c0bc8388a31f6db5081906b66b9e129855ba27a13cf13bd995b083f7386e --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/btree.c | 4 ++-- src/btreeInt.h | 4 +++- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index a705549b4b..cb0879e53d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sminor\stypo\sin\sa\scomment. -D 2022-03-01T19:19:20.084 +C The\sMemPage.aDataEnd\sfield\sshould\spoint\sto\sthe\send\sof\sthe\sdata\sbuffer\sfor\nthe\spage,\snot\sjust\sthe\send\sof\sthe\susable\sportion\sof\sthat\sbuffer.\s\sThe\spurpose\naDataEnd\sis\sto\sdetect\scells\sthat\soverflow\sthe\spage,\sand\sthat\swon't\swork\son\sa\npage\swith\sreserved\sbytes\sand\sa\scell\sthat\sstarts\sin\sthe\sreserved\sregion,\sunless\nthe\sboundary\sis\sat\sthe\svery\send\sof\sthe\spage.\sChromium\sissue\s1276294. +D 2022-03-01T20:15:04.332 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -492,9 +492,9 @@ F src/auth.c f4fa91b6a90bbc8e0d0f738aa284551739c9543a367071f55574681e0f24f8cf F src/backup.c a2891172438e385fdbe97c11c9745676bec54f518d4447090af97189fd8e52d7 F src/bitvec.c 7c849aac407230278445cb069bebc5f89bf2ddd87c5ed9459b070a9175707b3d F src/btmutex.c 8acc2f464ee76324bf13310df5692a262b801808984c1b79defb2503bbafadb6 -F src/btree.c 7e9400d1582136ca86af9bbb07f8f3e933b284e969cda516bdc755285d137eb2 +F src/btree.c 752fc154c07e03fd77a5426f6d625aa5aeeacd0054e0d5be9a89dd217d8b7f02 F src/btree.h 74d64b8f28cfa4a894d14d4ed64fa432cd697b98b61708d4351482ae15913e22 -F src/btreeInt.h 7282a6e77775f93a6eb78d3a41dab372a01a4ec1d93d3b4728d191d15fda42e2 +F src/btreeInt.h 1ca477727c5f420a8321208dc5b14d93cb46cec8f941bc49318feb0e00bc961f F src/build.c 9891c2160886cf7e344d7e8f1f7177f9612916c7c67ffeacd64cb34a92d387a8 F src/callback.c 4c19af69835787bfe790ac560f3071a824eb629f34e41f97b52ce5235c77de1c F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 3b36ed79d82fae47a08a7d27f4fcefb7978fdf0e7f8c0f4a82f59501f201b32b -R 672415af5b93cf666a13cbb4e5190cf0 +P 86ba06aa4c55d3aefe030b19b2b5c08baf46bbb2218b04ac1228ab76682a929b +R 759bdd2426153bccb0e084e1cc68e2b8 U drh -Z f44c78af05c98bc038cc5e60cffa1d77 +Z c62f0605f7573e50ae4553081294f184 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 4a625fe341..f5f5a33e67 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -86ba06aa4c55d3aefe030b19b2b5c08baf46bbb2218b04ac1228ab76682a929b \ No newline at end of file +f839c0bc8388a31f6db5081906b66b9e129855ba27a13cf13bd995b083f7386e \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index fdf259766f..fb35bbbc5f 100644 --- a/src/btree.c +++ b/src/btree.c @@ -2107,7 +2107,7 @@ static int btreeInitPage(MemPage *pPage){ pPage->nOverflow = 0; pPage->cellOffset = pPage->hdrOffset + 8 + pPage->childPtrSize; pPage->aCellIdx = data + pPage->childPtrSize + 8; - pPage->aDataEnd = pPage->aData + pBt->usableSize; + pPage->aDataEnd = pPage->aData + pBt->pageSize; pPage->aDataOfst = pPage->aData + pPage->childPtrSize; /* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the ** number of cells on the page. */ @@ -2158,7 +2158,7 @@ static void zeroPage(MemPage *pPage, int flags){ pPage->nFree = (u16)(pBt->usableSize - first); decodeFlags(pPage, flags); pPage->cellOffset = first; - pPage->aDataEnd = &data[pBt->usableSize]; + pPage->aDataEnd = &data[pBt->pageSize]; pPage->aCellIdx = &data[first]; pPage->aDataOfst = &data[pPage->childPtrSize]; pPage->nOverflow = 0; diff --git a/src/btreeInt.h b/src/btreeInt.h index e038f313e2..3b0572e954 100644 --- a/src/btreeInt.h +++ b/src/btreeInt.h @@ -293,7 +293,9 @@ struct MemPage { u8 *apOvfl[4]; /* Pointers to the body of overflow cells */ BtShared *pBt; /* Pointer to BtShared that this page is part of */ u8 *aData; /* Pointer to disk image of the page data */ - u8 *aDataEnd; /* One byte past the end of usable data */ + u8 *aDataEnd; /* One byte past the end of the entire page - not just + ** the usable space, the entire page. Used to prevent + ** corruption-induced of buffer overflow. */ u8 *aCellIdx; /* The cell index area */ u8 *aDataOfst; /* Same as aData for leaves. aData+4 for interior */ DbPage *pDbPage; /* Pager page handle */ From 86af59830f24976286920f410f3e95b38721d87b Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 2 Mar 2022 00:50:06 +0000 Subject: [PATCH 31/75] The performance optimizations at [bb520293d8c11518] is not quite right, so it has to be backed out. FossilOrigin-Name: 15f73b121cacf77ada02bfe434f9caa1175ac482d007156cfb0864e4221490d1 --- manifest | 13 +++++++------ manifest.uuid | 2 +- src/vdbeaux.c | 3 +-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index cb0879e53d..19005ed6e2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C The\sMemPage.aDataEnd\sfield\sshould\spoint\sto\sthe\send\sof\sthe\sdata\sbuffer\sfor\nthe\spage,\snot\sjust\sthe\send\sof\sthe\susable\sportion\sof\sthat\sbuffer.\s\sThe\spurpose\naDataEnd\sis\sto\sdetect\scells\sthat\soverflow\sthe\spage,\sand\sthat\swon't\swork\son\sa\npage\swith\sreserved\sbytes\sand\sa\scell\sthat\sstarts\sin\sthe\sreserved\sregion,\sunless\nthe\sboundary\sis\sat\sthe\svery\send\sof\sthe\spage.\sChromium\sissue\s1276294. -D 2022-03-01T20:15:04.332 +C The\sperformance\soptimizations\sat\s[bb520293d8c11518]\sis\snot\squite\sright,\nso\sit\shas\sto\sbe\sbacked\sout. +D 2022-03-02T00:50:06.086 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -628,7 +628,7 @@ F src/vdbe.c 4b969ebe6b61f87a90aebf817bc6ebda5075fe56987591091a9bf22556262484 F src/vdbe.h a1d0e3b934e835e73edd146f2e7c4eadb711b5c9875c18159a57483fd78e550e F src/vdbeInt.h 958066f0448930dac697a7d1fc345d1b5fd1bb2d93685860967b94c901a7b244 F src/vdbeapi.c 1c80efbe51118bbecc7279023e75d18edcfa4b3dc441287e1718ee70ad594f58 -F src/vdbeaux.c 0f3ce77dabb1f897cc7d3812ed162ec5d31d2298d1aa41b606f8048a742c4b9e +F src/vdbeaux.c ab8c90419e78021b70b3a76a02b6f6dcc8f80d4208f065e916066968909020bf F src/vdbeblob.c 5e61ce31aca17db8fb60395407457a8c1c7fb471dde405e0cd675974611dcfcd F src/vdbemem.c 7737f0b1c480a32b057849c804d2f21d5389649bb8be80f77ad75df700adc9a1 F src/vdbesort.c 43756031ca7430f7aec3ef904824a7883c4ede783e51f280d99b9b65c0796e35 @@ -1944,8 +1944,9 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 86ba06aa4c55d3aefe030b19b2b5c08baf46bbb2218b04ac1228ab76682a929b -R 759bdd2426153bccb0e084e1cc68e2b8 +P f839c0bc8388a31f6db5081906b66b9e129855ba27a13cf13bd995b083f7386e +Q -bb520293d8c11518ba153b986662f081ebfd781d38eb624c509605fa9148f6e9 +R 76d16a1a1f4506ffb5d6a4d86b768e8a U drh -Z c62f0605f7573e50ae4553081294f184 +Z b009d278911c3d1765c2302d54175b80 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index f5f5a33e67..377701bdbb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f839c0bc8388a31f6db5081906b66b9e129855ba27a13cf13bd995b083f7386e \ No newline at end of file +15f73b121cacf77ada02bfe434f9caa1175ac482d007156cfb0864e4221490d1 \ No newline at end of file diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 54332caa37..b12094410a 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -1903,9 +1903,8 @@ static void releaseMemArray(Mem *p, int N){ sqlite3DbFreeNN(db, p->zMalloc); p->szMalloc = 0; } -#ifdef SQLITE_DEBUG + p->flags = MEM_Undefined; -#endif }while( (++p) Date: Wed, 2 Mar 2022 01:02:16 +0000 Subject: [PATCH 32/75] Fix a harmless compiler warning. FossilOrigin-Name: 6497997aa80419688890ed5dbbb7d6acc26bf3732305ff4a728cba1fe4d1626b --- manifest | 13 ++++++------- manifest.uuid | 2 +- src/pragma.c | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 19005ed6e2..1925c433f7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C The\sperformance\soptimizations\sat\s[bb520293d8c11518]\sis\snot\squite\sright,\nso\sit\shas\sto\sbe\sbacked\sout. -D 2022-03-02T00:50:06.086 +C Fix\sa\sharmless\scompiler\swarning. +D 2022-03-02T01:02:16.787 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -545,7 +545,7 @@ F src/parse.y 0f02b27cdaa334441463153fff3ceb780fea006ab53ffd6ef566d4468f93e924 F src/pcache.c 0aab73936341fad83d107cf62c6a7bc2d2d5fb9aaec8c3ce61e19fc18e4560fc F src/pcache.h 4f87acd914cef5016fae3030343540d75f5b85a1877eed1a2a19b9f284248586 F src/pcache1.c 54881292a9a5db202b2c0ac541c5e3ef9a5e8c4f1c1383adb2601d5499a60e65 -F src/pragma.c a7323cd175587afa0b82c213b9bba5789fe9ea67f9e5d66e35df00742a923bcc +F src/pragma.c 9047ffb003d9434810ee81d7b1722d0093821622eb3217c962c3407bad949ce2 F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c a187dade741c1f09ae118fcbbf0302511807bfc0355880927d7152eb75b8260d F src/printf.c 05d8dfd2018bc4fc3ddb8b37eb97ccef7abf985643fa1caebdcf2916ca90fa32 @@ -1944,9 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P f839c0bc8388a31f6db5081906b66b9e129855ba27a13cf13bd995b083f7386e -Q -bb520293d8c11518ba153b986662f081ebfd781d38eb624c509605fa9148f6e9 -R 76d16a1a1f4506ffb5d6a4d86b768e8a +P 15f73b121cacf77ada02bfe434f9caa1175ac482d007156cfb0864e4221490d1 +R 92cb4b3e8b72c08af06d80ae9f960ec3 U drh -Z b009d278911c3d1765c2302d54175b80 +Z f78232375c28b78519d89054564af79f # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 377701bdbb..d12eabcabf 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -15f73b121cacf77ada02bfe434f9caa1175ac482d007156cfb0864e4221490d1 \ No newline at end of file +6497997aa80419688890ed5dbbb7d6acc26bf3732305ff4a728cba1fe4d1626b \ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index 0e87524dd5..a95b9ee3d1 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -314,7 +314,7 @@ static void pragmaFunclistLine( SQLITE_INNOCUOUS | SQLITE_FUNC_INTERNAL ; - if( showInternFuncs ) mask = -1; + if( showInternFuncs ) mask = 0xffffffff; for(; p; p=p->pNext){ const char *zType; static const char *azEnc[] = { 0, "utf8", "utf16le", "utf16be" }; From e3994f2975287b459692d8a347f3f33fffa08bda Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 2 Mar 2022 11:39:11 +0000 Subject: [PATCH 33/75] The optimization at [ece326db50201937] is not quite right, so back it out for now. FossilOrigin-Name: b218a4b9fe44ffc5cb8d2a2491a5aad217d37b26ccc6b04caf8f28b71bcfe809 --- manifest | 13 +++++++------ manifest.uuid | 2 +- src/pager.c | 7 ++++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 1925c433f7..c33545bdf8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sharmless\scompiler\swarning. -D 2022-03-02T01:02:16.787 +C The\soptimization\sat\s[ece326db50201937]\sis\snot\squite\sright,\sso\sback\sit\sout\nfor\snow. +D 2022-03-02T11:39:11.573 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -539,7 +539,7 @@ F src/os_setup.h 0dbaea40a7d36bf311613d31342e0b99e2536586 F src/os_unix.c f5ad51cfd024116db8531feab9efd831c2621436dca1464e4ff1e8af9bf3252e F src/os_win.c 77d39873836f1831a9b0b91894fec45ab0e9ca8e067dc8c549e1d1eca1566fe9 F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a -F src/pager.c 1c415888b3658513c26a79b6a61989ca6463d3770102e6c24372fd7235022b02 +F src/pager.c 42120492784fc9bcd9082b5c9b5e329b7318c357f9f3574a1bbfcf7418910356 F src/pager.h f82e9844166e1585f5786837ddc7709966138ced17f568c16af7ccf946c2baa3 F src/parse.y 0f02b27cdaa334441463153fff3ceb780fea006ab53ffd6ef566d4468f93e924 F src/pcache.c 0aab73936341fad83d107cf62c6a7bc2d2d5fb9aaec8c3ce61e19fc18e4560fc @@ -1944,8 +1944,9 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 15f73b121cacf77ada02bfe434f9caa1175ac482d007156cfb0864e4221490d1 -R 92cb4b3e8b72c08af06d80ae9f960ec3 +P 6497997aa80419688890ed5dbbb7d6acc26bf3732305ff4a728cba1fe4d1626b +Q -ece326db50201937eb688809df39edc7fb97413b4614d2e2e783418192f7b02a +R 6e3d2a70dcfbb60b44acaa137825df92 U drh -Z f78232375c28b78519d89054564af79f +Z 2c1c2df4762c35de9490f72bfde9d5c8 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d12eabcabf..8f223b6ba7 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6497997aa80419688890ed5dbbb7d6acc26bf3732305ff4a728cba1fe4d1626b \ No newline at end of file +b218a4b9fe44ffc5cb8d2a2491a5aad217d37b26ccc6b04caf8f28b71bcfe809 \ No newline at end of file diff --git a/src/pager.c b/src/pager.c index 33ed31d7ad..b6a0cdfca8 100644 --- a/src/pager.c +++ b/src/pager.c @@ -5494,6 +5494,7 @@ static int getPageNormal( assert( assert_pager_state(pPager) ); assert( pPager->hasHeldSharedLock==1 ); + if( pgno==0 ) return SQLITE_CORRUPT_BKPT; pBase = sqlite3PcacheFetch(pPager->pPCache, pgno, 3); if( pBase==0 ){ pPg = 0; @@ -5521,10 +5522,10 @@ static int getPageNormal( /* The pager cache has created a new page. Its content needs to ** be initialized. But first some error checks: ** - ** (1) Never try to fetch the locking page - ** (2) Never try to fetch page 0, which does not exist + ** (*) obsolete. Was: maximum page number is 2^31 + ** (2) Never try to fetch the locking page */ - if( pgno==PAGER_SJ_PGNO(pPager) || pgno==0 ){ + if( pgno==PAGER_SJ_PGNO(pPager) ){ rc = SQLITE_CORRUPT_BKPT; goto pager_acquire_err; } From 5308d3931eba2b006fceb2956d6d4718a6fa7065 Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 2 Mar 2022 13:45:22 +0000 Subject: [PATCH 34/75] Reinstate the releaseMemArray() performance optimization of [bb520293d8c11518] with corrections. FossilOrigin-Name: 1291080d118c678072289a2e57a56b73657e9256ae47eafa7853716c8d47392f --- manifest | 13 ++++++------- manifest.uuid | 2 +- src/vdbeaux.c | 16 +++++++++++++--- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index c33545bdf8..8b54b28a11 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C The\soptimization\sat\s[ece326db50201937]\sis\snot\squite\sright,\sso\sback\sit\sout\nfor\snow. -D 2022-03-02T11:39:11.573 +C Reinstate\sthe\sreleaseMemArray()\sperformance\soptimization\sof\n[bb520293d8c11518]\swith\scorrections. +D 2022-03-02T13:45:22.786 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -628,7 +628,7 @@ F src/vdbe.c 4b969ebe6b61f87a90aebf817bc6ebda5075fe56987591091a9bf22556262484 F src/vdbe.h a1d0e3b934e835e73edd146f2e7c4eadb711b5c9875c18159a57483fd78e550e F src/vdbeInt.h 958066f0448930dac697a7d1fc345d1b5fd1bb2d93685860967b94c901a7b244 F src/vdbeapi.c 1c80efbe51118bbecc7279023e75d18edcfa4b3dc441287e1718ee70ad594f58 -F src/vdbeaux.c ab8c90419e78021b70b3a76a02b6f6dcc8f80d4208f065e916066968909020bf +F src/vdbeaux.c 219aef2bb6dc46f6ede76de18e7c388c30bd359ec094e178c362e1b412c56213 F src/vdbeblob.c 5e61ce31aca17db8fb60395407457a8c1c7fb471dde405e0cd675974611dcfcd F src/vdbemem.c 7737f0b1c480a32b057849c804d2f21d5389649bb8be80f77ad75df700adc9a1 F src/vdbesort.c 43756031ca7430f7aec3ef904824a7883c4ede783e51f280d99b9b65c0796e35 @@ -1944,9 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 6497997aa80419688890ed5dbbb7d6acc26bf3732305ff4a728cba1fe4d1626b -Q -ece326db50201937eb688809df39edc7fb97413b4614d2e2e783418192f7b02a -R 6e3d2a70dcfbb60b44acaa137825df92 +P b218a4b9fe44ffc5cb8d2a2491a5aad217d37b26ccc6b04caf8f28b71bcfe809 +R 5f0e4af1c896fc134e4b58b7139e0944 U drh -Z 2c1c2df4762c35de9490f72bfde9d5c8 +Z 49bdd6bb7b5e60b4733d0aedae5472b4 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 8f223b6ba7..5b5f56c2b5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b218a4b9fe44ffc5cb8d2a2491a5aad217d37b26ccc6b04caf8f28b71bcfe809 \ No newline at end of file +1291080d118c678072289a2e57a56b73657e9256ae47eafa7853716c8d47392f \ No newline at end of file diff --git a/src/vdbeaux.c b/src/vdbeaux.c index b12094410a..3a110dd28f 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -1866,7 +1866,12 @@ static void initMemArray(Mem *p, int N, sqlite3 *db, u16 flags){ } /* -** Release an array of N Mem elements +** Release auxiliary memory held in an array of N Mem elements. +** +** After this routine returns, all Mem elements in the array will still +** be valid. Those Mem elements that were not holding auxiliary resources +** will be unchanged. Mem elements which had something freed will be +** set to MEM_Undefined. */ static void releaseMemArray(Mem *p, int N){ if( p && N ){ @@ -1899,12 +1904,17 @@ static void releaseMemArray(Mem *p, int N){ if( p->flags&(MEM_Agg|MEM_Dyn) ){ testcase( (p->flags & MEM_Dyn)!=0 && p->xDel==sqlite3VdbeFrameMemDel ); sqlite3VdbeMemRelease(p); + p->flags = MEM_Undefined; }else if( p->szMalloc ){ sqlite3DbFreeNN(db, p->zMalloc); p->szMalloc = 0; + p->flags = MEM_Undefined; } - - p->flags = MEM_Undefined; +#ifdef SQLITE_DEBUG + else{ + p->flags = MEM_Undefined; + } +#endif }while( (++p) Date: Wed, 2 Mar 2022 17:50:59 +0000 Subject: [PATCH 35/75] Faster version of sqlite3VdbeMemRelease(). FossilOrigin-Name: 86c5fa2f301e4bdb538099f654b70b6ba0e214778cba2c53c53844e5d7ca129f --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- src/vdbe.c | 2 +- src/vdbeInt.h | 1 + src/vdbeaux.c | 12 ++++++------ src/vdbemem.c | 8 ++++++++ 6 files changed, 26 insertions(+), 17 deletions(-) diff --git a/manifest b/manifest index 8b54b28a11..31f2d21b13 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Reinstate\sthe\sreleaseMemArray()\sperformance\soptimization\sof\n[bb520293d8c11518]\swith\scorrections. -D 2022-03-02T13:45:22.786 +C Faster\sversion\sof\ssqlite3VdbeMemRelease(). +D 2022-03-02T17:50:59.164 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -624,13 +624,13 @@ F src/upsert.c 8789047a8f0a601ea42fa0256d1ba3190c13746b6ba940fe2d25643a7e991937 F src/utf.c ee39565f0843775cc2c81135751ddd93eceb91a673ea2c57f61c76f288b041a0 F src/util.c 602fe229f32a96ceccae4f40824129669582096f7c355f53dbac156c9fecef23 F src/vacuum.c 6c38ddc52f0619865c91dae9c441d4d48bf3040d7dc1bc5b22da1e45547ed0b3 -F src/vdbe.c 4b969ebe6b61f87a90aebf817bc6ebda5075fe56987591091a9bf22556262484 +F src/vdbe.c d2cf2ef62b51aedab4d9df4b9980f70f95c7ab294ff6e56478067630b7c5c5eb F src/vdbe.h a1d0e3b934e835e73edd146f2e7c4eadb711b5c9875c18159a57483fd78e550e -F src/vdbeInt.h 958066f0448930dac697a7d1fc345d1b5fd1bb2d93685860967b94c901a7b244 +F src/vdbeInt.h 8dd91427155a38ec06e9ecbde07e33f21bc02e101625191e7613f883e379a363 F src/vdbeapi.c 1c80efbe51118bbecc7279023e75d18edcfa4b3dc441287e1718ee70ad594f58 -F src/vdbeaux.c 219aef2bb6dc46f6ede76de18e7c388c30bd359ec094e178c362e1b412c56213 +F src/vdbeaux.c 280383a4c7fc567e30266cf72bb5031c252bc4cbc1a80d4e1461d77c4bd01547 F src/vdbeblob.c 5e61ce31aca17db8fb60395407457a8c1c7fb471dde405e0cd675974611dcfcd -F src/vdbemem.c 7737f0b1c480a32b057849c804d2f21d5389649bb8be80f77ad75df700adc9a1 +F src/vdbemem.c ff564b58f49a9e982414c8ecde99e416eff939e7cbb0333aa976610430fd8038 F src/vdbesort.c 43756031ca7430f7aec3ef904824a7883c4ede783e51f280d99b9b65c0796e35 F src/vdbetrace.c fe0bc29ebd4e02c8bc5c1945f1d2e6be5927ec12c06d89b03ef2a4def34bf823 F src/vdbevtab.c f99b275366c5fc5e2d99f734729880994ab9500bdafde7fae3b02d562b9d323c @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P b218a4b9fe44ffc5cb8d2a2491a5aad217d37b26ccc6b04caf8f28b71bcfe809 -R 5f0e4af1c896fc134e4b58b7139e0944 +P 1291080d118c678072289a2e57a56b73657e9256ae47eafa7853716c8d47392f +R 6a54efa5d5625f9f9ec36bf19fa8fdf3 U drh -Z 49bdd6bb7b5e60b4733d0aedae5472b4 +Z 145582c8165744c10655e15250277f3e # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 5b5f56c2b5..5bbd428d13 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1291080d118c678072289a2e57a56b73657e9256ae47eafa7853716c8d47392f \ No newline at end of file +86c5fa2f301e4bdb538099f654b70b6ba0e214778cba2c53c53844e5d7ca129f \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index 82ea6cf6bd..e0668ea9aa 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -6345,7 +6345,7 @@ case OP_IdxGE: { /* jump */ rc = sqlite3VdbeMemFromBtreeZeroOffset(pCur, (u32)nCellKey, &m); if( rc ) goto abort_due_to_error; res = sqlite3VdbeRecordCompareWithSkip(m.n, m.z, &r, 0); - sqlite3VdbeMemRelease(&m); + sqlite3VdbeMemReleaseMalloc(&m); } /* End of inlined sqlite3VdbeIdxKeyCompare() */ diff --git a/src/vdbeInt.h b/src/vdbeInt.h index 8ef2795551..45720b6a55 100644 --- a/src/vdbeInt.h +++ b/src/vdbeInt.h @@ -602,6 +602,7 @@ int sqlite3VdbeMemCast(Mem*,u8,u8); int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,Mem*); int sqlite3VdbeMemFromBtreeZeroOffset(BtCursor*,u32,Mem*); void sqlite3VdbeMemRelease(Mem *p); +void sqlite3VdbeMemReleaseMalloc(Mem*p); int sqlite3VdbeMemFinalize(Mem*, FuncDef*); #ifndef SQLITE_OMIT_WINDOWFUNC int sqlite3VdbeMemAggValue(Mem*, Mem*, FuncDef*); diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 3a110dd28f..f5aa1f0fd2 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -4209,8 +4209,8 @@ static int vdbeCompareMemString( }else{ rc = pColl->xCmp(pColl->pUser, c1.n, v1, c2.n, v2); } - sqlite3VdbeMemRelease(&c1); - sqlite3VdbeMemRelease(&c2); + sqlite3VdbeMemReleaseMalloc(&c1); + sqlite3VdbeMemReleaseMalloc(&c2); return rc; } } @@ -4942,14 +4942,14 @@ int sqlite3VdbeIdxRowid(sqlite3 *db, BtCursor *pCur, i64 *rowid){ /* Fetch the integer off the end of the index record */ sqlite3VdbeSerialGet((u8*)&m.z[m.n-lenRowid], typeRowid, &v); *rowid = v.u.i; - sqlite3VdbeMemRelease(&m); + sqlite3VdbeMemReleaseMalloc(&m); return SQLITE_OK; /* Jump here if database corruption is detected after m has been ** allocated. Free the m object and return SQLITE_CORRUPT. */ idx_rowid_corruption: testcase( m.szMalloc!=0 ); - sqlite3VdbeMemRelease(&m); + sqlite3VdbeMemReleaseMalloc(&m); return SQLITE_CORRUPT_BKPT; } @@ -4991,7 +4991,7 @@ int sqlite3VdbeIdxKeyCompare( return rc; } *res = sqlite3VdbeRecordCompareWithSkip(m.n, m.z, pUnpacked, 0); - sqlite3VdbeMemRelease(&m); + sqlite3VdbeMemReleaseMalloc(&m); return SQLITE_OK; } @@ -5158,7 +5158,7 @@ static void vdbeFreeUnpacked(sqlite3 *db, int nField, UnpackedRecord *p){ int i; for(i=0; iaMem[i]; - if( pMem->zMalloc ) sqlite3VdbeMemRelease(pMem); + if( pMem->zMalloc ) sqlite3VdbeMemReleaseMalloc(pMem); } sqlite3DbFreeNN(db, p); } diff --git a/src/vdbemem.c b/src/vdbemem.c index e840f6586c..1795bb7d76 100644 --- a/src/vdbemem.c +++ b/src/vdbemem.c @@ -555,6 +555,14 @@ void sqlite3VdbeMemRelease(Mem *p){ } } +/* Like sqlite3VdbeMemRelease() but faster for cases where we +** know in advance that the Mem is not MEM_Dyn or MEM_Agg. +*/ +void sqlite3VdbeMemReleaseMalloc(Mem *p){ + assert( !VdbeMemDynamic(p) ); + if( p->szMalloc ) vdbeMemClear(p); +} + /* ** Convert a 64-bit IEEE double into a 64-bit signed integer. ** If the double is out of range of a 64-bit signed integer then From 56945695914d9cd980f71c020f9dee4e85957364 Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 2 Mar 2022 21:04:10 +0000 Subject: [PATCH 36/75] Bloom filter pull-down optimization is incompatible with Skip-Scan. Make sure the query planner does not try to to both. [forum:/info/50a1bbe08ce4c29c|Forum post 50a1bbe08ce4c29c]. FossilOrigin-Name: ad3ffa1a75a5a032ebb64d8e014ee0a85c5e44b732e4b11bd67f31a59e729b94 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/wherecode.c | 2 ++ test/join5.test | 19 +++++++++++++++++++ 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 31f2d21b13..d18322769a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Faster\sversion\sof\ssqlite3VdbeMemRelease(). -D 2022-03-02T17:50:59.164 +C Bloom\sfilter\spull-down\soptimization\sis\sincompatible\swith\sSkip-Scan.\nMake\ssure\sthe\squery\splanner\sdoes\snot\stry\sto\sto\sboth.\n[forum:/info/50a1bbe08ce4c29c|Forum\spost\s50a1bbe08ce4c29c]. +D 2022-03-02T21:04:10.291 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -641,7 +641,7 @@ F src/wal.h c3aa7825bfa2fe0d85bef2db94655f99870a285778baa36307c0a16da32b226a F src/walker.c f890a3298418d7cba3b69b8803594fdc484ea241206a8dfa99db6dd36f8cbb3b F src/where.c 0d75d7514764726409ea945520fe9fb515e7d9ae52a5a3c0a136142cfaa19087 F src/whereInt.h 15d2975c3b4c193c78c26674400a840da8647fe1777ae3b026e2d15937b38a03 -F src/wherecode.c d34d3980f35e504a558f788ad9ac4bc6876b119409d597e7e234a4564a94c6ab +F src/wherecode.c 273893ebc8622737e0ea631138278bbc8138e3dc4d2e193ce2678a6baa21016f F src/whereexpr.c 2a71f5491798460c9590317329234d332d9eb1717cba4f3403122189a75c465e F src/window.c dfaec4abc6012cbc18e4a202ca3a5d5a0efcc4011d86a06d882ddaab8aedee4d F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 @@ -1143,7 +1143,7 @@ F test/join.test 25cf0ac11c3b81fedfd166f9062166bdb39dea92f5a7c16cacbf6dc1f7f6702 F test/join2.test 9bdc615841b91c97a16d68bad9508aea11fa0c6b34e5689847bcc4dac70e4990 F test/join3.test 6f0c774ff1ba0489e6c88a3e77b9d3528fb4fda0 F test/join4.test 1a352e4e267114444c29266ce79e941af5885916 -F test/join5.test 37864d567928652cab79a7872ebde74b3c67a1feb0366d98bb3bc7832885f388 +F test/join5.test 3d51c4ae5f1f373a03164ca3c88d438f64bed7a2c01cf69810e2ca3d0e9071c8 F test/join6.test f809c025fa253f9e150c0e9afd4cef8813257bceeb6f46e04041228c9403cc2c F test/journal1.test c7b768041b7f494471531e17abc2f4f5ebf9e5096984f43ed17c4eb80ba34497 F test/journal2.test 9dac6b4ba0ca79c3b21446bbae993a462c2397c4 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 1291080d118c678072289a2e57a56b73657e9256ae47eafa7853716c8d47392f -R 6a54efa5d5625f9f9ec36bf19fa8fdf3 +P 86c5fa2f301e4bdb538099f654b70b6ba0e214778cba2c53c53844e5d7ca129f +R ce130c74174cec9891d61458e25bf794 U drh -Z 145582c8165744c10655e15250277f3e +Z d775ec6037256eae49bb0d3cd795e9f6 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 5bbd428d13..570bbc16d5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -86c5fa2f301e4bdb538099f654b70b6ba0e214778cba2c53c53844e5d7ca129f \ No newline at end of file +ad3ffa1a75a5a032ebb64d8e014ee0a85c5e44b732e4b11bd67f31a59e729b94 \ No newline at end of file diff --git a/src/wherecode.c b/src/wherecode.c index ab3b8b18e1..2149129179 100644 --- a/src/wherecode.c +++ b/src/wherecode.c @@ -792,6 +792,7 @@ static int codeAllEqualityTerms( VdbeCoverageIf(v, bRev!=0); VdbeComment((v, "begin skip-scan on %s", pIdx->zName)); j = sqlite3VdbeAddOp0(v, OP_Goto); + assert( pLevel->addrSkip==0 ); pLevel->addrSkip = sqlite3VdbeAddOp4Int(v, (bRev?OP_SeekLT:OP_SeekGT), iIdxCur, 0, regBase, nSkip); VdbeCoverageIf(v, bRev==0); @@ -1397,6 +1398,7 @@ static SQLITE_NOINLINE void filterPullDown( WhereLevel *pLevel = &pWInfo->a[iLevel]; WhereLoop *pLoop = pLevel->pWLoop; if( pLevel->regFilter==0 ) continue; + if( pLevel->pWLoop->nSkip ) continue; /* ,--- Because sqlite3ConstructBloomFilter() has will not have set ** vvvvv--' pLevel->regFilter if this were true. */ if( NEVER(pLoop->prereq & notReady) ) continue; diff --git a/test/join5.test b/test/join5.test index e3f997737b..518fab7a92 100644 --- a/test/join5.test +++ b/test/join5.test @@ -342,4 +342,23 @@ do_execsql_test 9.1 { SELECT a FROM (SELECT a FROM t1 NATURAL LEFT JOIN t1) NATURAL LEFT JOIN t1 WHERE (rowid,1)<=(5,0); } {1} +# 2022-03-02 https://sqlite.org/forum/info/50a1bbe08ce4c29c +# Bloom-filter pulldown is incompatible with skip-scan. +# +reset_db +do_execsql_test 10.1 { + CREATE TABLE t1(x INT); + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<20) + INSERT INTO t1(x) SELECT 0 FROM c; + CREATE INDEX t1x1 ON t1(x BETWEEN 0 AND 10, x); + ANALYZE; + DELETE FROM t1; + INSERT INTO t1 VALUES(0),(0); + CREATE VIEW v1 AS SELECT * FROM t1 NATURAL JOIN t1 WHERE (x BETWEEN 0 AND 10) OR true; + CREATE VIEW v2 AS SELECT * FROM v1 NATURAL JOIN v1; + CREATE VIEW v3 AS SELECT * FROM v2, v1 USING (x) GROUP BY x; + SELECT x FROM v3; +} {0} + + finish_test From 1902516d16d24506a7ae8ce3ac776bbad78c539e Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 3 Mar 2022 15:00:44 +0000 Subject: [PATCH 37/75] Add the new OP_BeginSubrtn opcode (which is really an alias for OP_Integer) and make other changes so that the span of a subroutine that implements a subquery is more readily apparent in bytecode listings. FossilOrigin-Name: b8226748709de37cfc86414714c20567254e5b320b380e767c322dba69a79d49 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/expr.c | 18 +++++++++++------- src/vdbe.c | 17 ++++++++++++++++- 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/manifest b/manifest index d18322769a..9ff7ab746e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Bloom\sfilter\spull-down\soptimization\sis\sincompatible\swith\sSkip-Scan.\nMake\ssure\sthe\squery\splanner\sdoes\snot\stry\sto\sto\sboth.\n[forum:/info/50a1bbe08ce4c29c|Forum\spost\s50a1bbe08ce4c29c]. -D 2022-03-02T21:04:10.291 +C Add\sthe\snew\sOP_BeginSubrtn\sopcode\s(which\sis\sreally\san\salias\sfor\sOP_Integer)\nand\smake\sother\schanges\sso\sthat\sthe\sspan\sof\sa\ssubroutine\sthat\simplements\na\ssubquery\sis\smore\sreadily\sapparent\sin\sbytecode\slistings. +D 2022-03-03T15:00:44.258 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -503,7 +503,7 @@ F src/date.c 1abbd739ae1d3fc8e0aaff995f57332af10d0b332728e4d3f241c494515495f0 F src/dbpage.c 8a01e865bf8bc6d7b1844b4314443a6436c07c3efe1d488ed89e81719047833a F src/dbstat.c 861e08690fcb0f2ee1165eff0060ea8d4f3e2ea10f80dab7d32ad70443a6ff2d F src/delete.c b5f1716b4d723db48254ee0f896e362cd029e865e05414139ea7f539f3884e1d -F src/expr.c b90a029105a93a93a0ed5e5f8c5eaed8f19043a3b62e4c4d235a4611d9ada178 +F src/expr.c 3cdb00b6c15f815c94836e7b4474b675155d1279e64804f6ab5816188a9b05b6 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c 06e4ac33031b02dde7130c12e79cddf4dc5cfa72b23d8e63a3c26878fc9c1d3c F src/func.c f801c6bc8b30afea51817d86a6c46259d3cca180c612cfa0a30b18d661e9c8df @@ -624,7 +624,7 @@ F src/upsert.c 8789047a8f0a601ea42fa0256d1ba3190c13746b6ba940fe2d25643a7e991937 F src/utf.c ee39565f0843775cc2c81135751ddd93eceb91a673ea2c57f61c76f288b041a0 F src/util.c 602fe229f32a96ceccae4f40824129669582096f7c355f53dbac156c9fecef23 F src/vacuum.c 6c38ddc52f0619865c91dae9c441d4d48bf3040d7dc1bc5b22da1e45547ed0b3 -F src/vdbe.c d2cf2ef62b51aedab4d9df4b9980f70f95c7ab294ff6e56478067630b7c5c5eb +F src/vdbe.c 62282c976aedf02603368d8d20d33cb7c8c214a34538f39da028d3e0c2aa6e16 F src/vdbe.h a1d0e3b934e835e73edd146f2e7c4eadb711b5c9875c18159a57483fd78e550e F src/vdbeInt.h 8dd91427155a38ec06e9ecbde07e33f21bc02e101625191e7613f883e379a363 F src/vdbeapi.c 1c80efbe51118bbecc7279023e75d18edcfa4b3dc441287e1718ee70ad594f58 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 86c5fa2f301e4bdb538099f654b70b6ba0e214778cba2c53c53844e5d7ca129f -R ce130c74174cec9891d61458e25bf794 +P ad3ffa1a75a5a032ebb64d8e014ee0a85c5e44b732e4b11bd67f31a59e729b94 +R cf617415d744f05eb16874e90dfd5f1d U drh -Z d775ec6037256eae49bb0d3cd795e9f6 +Z c1aa9fa8cb20b2f538a49ebe46b0f2e7 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 570bbc16d5..04cf7d651f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ad3ffa1a75a5a032ebb64d8e014ee0a85c5e44b732e4b11bd67f31a59e729b94 \ No newline at end of file +b8226748709de37cfc86414714c20567254e5b320b380e767c322dba69a79d49 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 271f06bc6a..79889bdd75 100644 --- a/src/expr.c +++ b/src/expr.c @@ -3040,8 +3040,7 @@ void sqlite3CodeRhsOfIN( assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) ); pExpr->y.sub.regReturn = ++pParse->nMem; pExpr->y.sub.iAddr = - sqlite3VdbeAddOp2(v, OP_Integer, 0, pExpr->y.sub.regReturn) + 1; - VdbeComment((v, "return address")); + sqlite3VdbeAddOp2(v, OP_BeginSubrtn, 0, pExpr->y.sub.regReturn) + 1; addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v); } @@ -3143,6 +3142,7 @@ void sqlite3CodeRhsOfIN( ** expression we need to rerun this code each time. */ if( addrOnce && !sqlite3ExprIsConstant(pE2) ){ + sqlite3VdbeChangeToNoop(v, addrOnce-1); sqlite3VdbeChangeToNoop(v, addrOnce); ExprClearProperty(pExpr, EP_Subrtn); addrOnce = 0; @@ -3163,7 +3163,10 @@ void sqlite3CodeRhsOfIN( sqlite3VdbeJumpHere(v, addrOnce); /* Subroutine return */ assert( ExprUseYSub(pExpr) ); - sqlite3VdbeAddOp1(v, OP_Return, pExpr->y.sub.regReturn); + assert( sqlite3VdbeGetOp(v,pExpr->y.sub.iAddr-1)->opcode==OP_BeginSubrtn + || pParse->nErr ); + sqlite3VdbeAddOp3(v, OP_Return, pExpr->y.sub.regReturn, 0, + pExpr->y.sub.iAddr-1); sqlite3VdbeChangeP1(v, pExpr->y.sub.iAddr-1, sqlite3VdbeCurrentAddr(v)-1); sqlite3ClearTempRegCache(pParse); } @@ -3218,9 +3221,7 @@ int sqlite3CodeSubselect(Parse *pParse, Expr *pExpr){ ExprSetProperty(pExpr, EP_Subrtn); pExpr->y.sub.regReturn = ++pParse->nMem; pExpr->y.sub.iAddr = - sqlite3VdbeAddOp2(v, OP_Integer, 0, pExpr->y.sub.regReturn) + 1; - VdbeComment((v, "return address")); - + sqlite3VdbeAddOp2(v, OP_BeginSubrtn, 0, pExpr->y.sub.regReturn) + 1; /* The evaluation of the EXISTS/SELECT must be repeated every time it ** is encountered if any of the following is true: @@ -3293,7 +3294,10 @@ int sqlite3CodeSubselect(Parse *pParse, Expr *pExpr){ /* Subroutine return */ assert( ExprUseYSub(pExpr) ); - sqlite3VdbeAddOp1(v, OP_Return, pExpr->y.sub.regReturn); + assert( sqlite3VdbeGetOp(v,pExpr->y.sub.iAddr-1)->opcode==OP_BeginSubrtn + || pParse->nErr ); + sqlite3VdbeAddOp3(v, OP_Return, pExpr->y.sub.regReturn, 0, + pExpr->y.sub.iAddr-1); sqlite3VdbeChangeP1(v, pExpr->y.sub.iAddr-1, sqlite3VdbeCurrentAddr(v)-1); sqlite3ClearTempRegCache(pParse); return rReg; diff --git a/src/vdbe.c b/src/vdbe.c index e0668ea9aa..554c9afb54 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -991,10 +991,14 @@ jump_to_p2: break; } -/* Opcode: Return P1 * * * * +/* Opcode: Return P1 * P3 * * ** ** Jump to the next instruction after the address in register P1. After ** the jump, register P1 becomes undefined. +** +** P3 is not used by the byte-code engine. However, the code generator +** sets P3 to address of the associated OP_BeginSubrtn opcode, if there is +** one. */ case OP_Return: { /* in1 */ pIn1 = &aMem[pOp->p1]; @@ -1182,11 +1186,22 @@ case OP_Halt: { goto vdbe_return; } +/* Opcode: BeginSubrtn P1 P2 * * * +** Synopsis: r[P2]=P1 +** +** Mark the beginning of a subroutine by loading the integer value P1 +** into register r[P2]. The P2 register is used to store the return +** address of the subroutine call. +** +** This opcode is identical to OP_Integer. It has a different name +** only to make the byte code easier to read and verify. +*/ /* Opcode: Integer P1 P2 * * * ** Synopsis: r[P2]=P1 ** ** The 32-bit integer value P1 is written into register P2. */ +case OP_BeginSubrtn: case OP_Integer: { /* out2 */ pOut = out2Prerelease(p, pOp); pOut->u.i = pOp->p1; From c9bcc5aab787e65ef1593d5b0943ad7b4bf4645b Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 3 Mar 2022 15:59:22 +0000 Subject: [PATCH 38/75] Fix for the problem identified in [forum:/forumpost/0cd8e058bf|forum post 0cd8e058bf]: When evaluating an multi-index OR, do not push down auxiliary WHERE clause terms that involve subqueries into the OR-subqueries. Otherwise, the covering-index optimizer might convert table-references into index-references for the particular OR index that is active for the branch in which the subquery subroutine is coded, and those index-references will not work if the subquery subroutine is invoked from a different OR branch that uses a different index. FossilOrigin-Name: 61a1c6dbd089979cbeb8b0c0c5ee1ab1abcb466be1d21a3a851be73c27e67a6c --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/wherecode.c | 12 ++++++++++-- test/where7.test | 24 ++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 9ff7ab746e..adb0b21a69 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\snew\sOP_BeginSubrtn\sopcode\s(which\sis\sreally\san\salias\sfor\sOP_Integer)\nand\smake\sother\schanges\sso\sthat\sthe\sspan\sof\sa\ssubroutine\sthat\simplements\na\ssubquery\sis\smore\sreadily\sapparent\sin\sbytecode\slistings. -D 2022-03-03T15:00:44.258 +C Fix\sfor\sthe\sproblem\sidentified\sin\s\n[forum:/forumpost/0cd8e058bf|forum\spost\s0cd8e058bf]:\nWhen\sevaluating\san\smulti-index\sOR,\sdo\snot\spush\sdown\sauxiliary\sWHERE\sclause\nterms\sthat\sinvolve\ssubqueries\sinto\sthe\sOR-subqueries.\s\sOtherwise,\sthe\ncovering-index\soptimizer\smight\sconvert\stable-references\sinto\sindex-references\nfor\sthe\sparticular\sOR\sindex\sthat\sis\sactive\sfor\sthe\sbranch\sin\swhich\sthe\nsubquery\ssubroutine\sis\scoded,\sand\sthose\sindex-references\nwill\snot\swork\sif\sthe\ssubquery\ssubroutine\sis\sinvoked\sfrom\sa\sdifferent\sOR\sbranch\nthat\suses\sa\sdifferent\sindex. +D 2022-03-03T15:59:22.986 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -641,7 +641,7 @@ F src/wal.h c3aa7825bfa2fe0d85bef2db94655f99870a285778baa36307c0a16da32b226a F src/walker.c f890a3298418d7cba3b69b8803594fdc484ea241206a8dfa99db6dd36f8cbb3b F src/where.c 0d75d7514764726409ea945520fe9fb515e7d9ae52a5a3c0a136142cfaa19087 F src/whereInt.h 15d2975c3b4c193c78c26674400a840da8647fe1777ae3b026e2d15937b38a03 -F src/wherecode.c 273893ebc8622737e0ea631138278bbc8138e3dc4d2e193ce2678a6baa21016f +F src/wherecode.c 5559cf12b4d3f6d123f70f9097a88fa879921785e9b69815a8901b89d63a87bf F src/whereexpr.c 2a71f5491798460c9590317329234d332d9eb1717cba4f3403122189a75c465e F src/window.c dfaec4abc6012cbc18e4a202ca3a5d5a0efcc4011d86a06d882ddaab8aedee4d F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 @@ -1774,7 +1774,7 @@ F test/where3.test 5b4ffc0ac2ea0fe92f02b1244b7531522fe4d7bccf6fa8741d54e82c10e67 F test/where4.test 4a371bfcc607f41d233701bdec33ac2972908ba8 F test/where5.test fdf66f96d29a064b63eb543e28da4dfdccd81ad2 F test/where6.test 5da5a98cec820d488e82708301b96cb8c18a258b -F test/where7.test ab41d53ce8f2a6919ea3d5b13cd1153c1375a8e3ddaa129b81781f9033981383 +F test/where7.test 1c1bf436bf31b913d4764a2b62ac6e98b9681e5c7ae2b562605592a56b7e946b F test/where8.test 461ca40265ed996a6305da99bb024b0e41602bb586acf544c08f95922358e49f F test/where9.test 1ffb75edc50a8faa6e7bd77f8221d783febb00b44b0bdb32fb48cec6e38eca95 F test/whereA.test 9d1077b117f1b68d5f739d94f36956c36cf995eb87bb19b77b2e81af020edd20 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P ad3ffa1a75a5a032ebb64d8e014ee0a85c5e44b732e4b11bd67f31a59e729b94 -R cf617415d744f05eb16874e90dfd5f1d +P b8226748709de37cfc86414714c20567254e5b320b380e767c322dba69a79d49 +R 43ae22005686caeeb8b845d41ecc6632 U drh -Z c1aa9fa8cb20b2f538a49ebe46b0f2e7 +Z 98e64c0fcadb781d4eb26d18c4816857 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 04cf7d651f..614b58bcfa 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b8226748709de37cfc86414714c20567254e5b320b380e767c322dba69a79d49 \ No newline at end of file +61a1c6dbd089979cbeb8b0c0c5ee1ab1abcb466be1d21a3a851be73c27e67a6c \ No newline at end of file diff --git a/src/wherecode.c b/src/wherecode.c index 2149129179..ff82ffc1a5 100644 --- a/src/wherecode.c +++ b/src/wherecode.c @@ -2345,6 +2345,14 @@ Bitmask sqlite3WhereCodeOneLoopStart( ** the initialization of the right-hand operand of the vector comparison ** might not occur, or might occur only in an OR branch that is not ** taken. dbsqlfuzz 80a9fade844b4fb43564efc972bcb2c68270f5d1. + ** + ** 2022-03-03: Do not push down expressions that involve subqueries. + ** The subquery might get coded as a subroutine. Any table-references + ** in the subquery might be resolved to index-references for the index on + ** the OR branch in which the subroutine is coded. But if the subroutine + ** is invoked from a different OR branch that uses a different index, such + ** index-references will not work. tag-20220303a + ** https://sqlite.org/forum/forumpost/36937b197273d403 */ if( pWC->nTerm>1 ){ int iTerm; @@ -2357,8 +2365,8 @@ Bitmask sqlite3WhereCodeOneLoopStart( if( (pWC->a[iTerm].wtFlags & (TERM_VIRTUAL|TERM_CODED|TERM_SLICE))!=0 ){ continue; } - if( (pWC->a[iTerm].eOperator & WO_ALL)==0 ) continue; - testcase( pWC->a[iTerm].wtFlags & TERM_ORINFO ); + if( (pWC->a[iTerm].eOperator & WO_SINGLE)==0 ) continue; + if( ExprHasProperty(pExpr, EP_Subquery) ) continue; /* tag-20220303a */ pExpr = sqlite3ExprDup(db, pExpr, 0); pAndExpr = sqlite3ExprAnd(pParse, pAndExpr, pExpr); } diff --git a/test/where7.test b/test/where7.test index 830530634f..f76e8aba8b 100644 --- a/test/where7.test +++ b/test/where7.test @@ -23361,4 +23361,28 @@ do_eqp_test where7-3.2 { `--USE TEMP B-TREE FOR ORDER BY } +# 2022-03-03 https://sqlite.org/forum/forumpost/36937b197273d403 +# +# In the multi-index OR, if there is an auxiliary WHERE clause term +# that includes a subquery and that subquery is pushed down into the +# OR-clause subqueries, WHERE subquery might get coded as a subroutine. +# In that case, the covering-index optimizer will attempt to change +# table-references into index-references. But it will do so for the +# index of the OR branch in which the subquery is coded. If the +# subquery subroutine is called from a different OR branch, the +# index might be different and the index-reference will no longer +# work. tag-20220303a +# +reset_db +do_execsql_test 4.1 { + CREATE TABLE t0(w); + INSERT INTO t0(w) VALUES(1); + CREATE TABLE t1(x INT, y INT PRIMARY KEY, z); + INSERT INTO t1 VALUES(0,111,222); + CREATE INDEX t1zxy ON t1(z,x,y); + SELECT y FROM t1 + WHERE (z=222 OR y=111) + AND (false OR EXISTS(SELECT 1 FROM t0 WHERE t1.y)); +} {111} + finish_test From 4f122717808b6977ef541f04e4519f5af392118f Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 3 Mar 2022 16:48:35 +0000 Subject: [PATCH 39/75] Make sure the xParseCell and xCellSize methods of the MemPage object are initialized consistently even if the page is detected as being corrupt. dbsqlfuzz fd21f341f3b4f582401d2feb2a1c0c4cc2c26caa. FossilOrigin-Name: 725a06434b886c96bb816340ef236530672a4593f0ceb3230ce69c8367beb997 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/btree.c | 6 +++++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index adb0b21a69..2961d421fe 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sfor\sthe\sproblem\sidentified\sin\s\n[forum:/forumpost/0cd8e058bf|forum\spost\s0cd8e058bf]:\nWhen\sevaluating\san\smulti-index\sOR,\sdo\snot\spush\sdown\sauxiliary\sWHERE\sclause\nterms\sthat\sinvolve\ssubqueries\sinto\sthe\sOR-subqueries.\s\sOtherwise,\sthe\ncovering-index\soptimizer\smight\sconvert\stable-references\sinto\sindex-references\nfor\sthe\sparticular\sOR\sindex\sthat\sis\sactive\sfor\sthe\sbranch\sin\swhich\sthe\nsubquery\ssubroutine\sis\scoded,\sand\sthose\sindex-references\nwill\snot\swork\sif\sthe\ssubquery\ssubroutine\sis\sinvoked\sfrom\sa\sdifferent\sOR\sbranch\nthat\suses\sa\sdifferent\sindex. -D 2022-03-03T15:59:22.986 +C Make\ssure\sthe\sxParseCell\sand\sxCellSize\smethods\sof\sthe\sMemPage\sobject\sare\ninitialized\sconsistently\seven\sif\sthe\spage\sis\sdetected\sas\sbeing\scorrupt.\ndbsqlfuzz\sfd21f341f3b4f582401d2feb2a1c0c4cc2c26caa. +D 2022-03-03T16:48:35.284 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -492,7 +492,7 @@ F src/auth.c f4fa91b6a90bbc8e0d0f738aa284551739c9543a367071f55574681e0f24f8cf F src/backup.c a2891172438e385fdbe97c11c9745676bec54f518d4447090af97189fd8e52d7 F src/bitvec.c 7c849aac407230278445cb069bebc5f89bf2ddd87c5ed9459b070a9175707b3d F src/btmutex.c 8acc2f464ee76324bf13310df5692a262b801808984c1b79defb2503bbafadb6 -F src/btree.c 752fc154c07e03fd77a5426f6d625aa5aeeacd0054e0d5be9a89dd217d8b7f02 +F src/btree.c 9a5112589dc9491781bfd4e1b30d79bdab7e7ea3fc37a505e7ca5cc82f01c09a F src/btree.h 74d64b8f28cfa4a894d14d4ed64fa432cd697b98b61708d4351482ae15913e22 F src/btreeInt.h 1ca477727c5f420a8321208dc5b14d93cb46cec8f941bc49318feb0e00bc961f F src/build.c 9891c2160886cf7e344d7e8f1f7177f9612916c7c67ffeacd64cb34a92d387a8 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P b8226748709de37cfc86414714c20567254e5b320b380e767c322dba69a79d49 -R 43ae22005686caeeb8b845d41ecc6632 +P 61a1c6dbd089979cbeb8b0c0c5ee1ab1abcb466be1d21a3a851be73c27e67a6c +R e394f5d71fcf3ab03b849ac8d2f2e010 U drh -Z 98e64c0fcadb781d4eb26d18c4816857 +Z 6957f162062fe17752cd0dc465054be9 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 614b58bcfa..f3b06b1630 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -61a1c6dbd089979cbeb8b0c0c5ee1ab1abcb466be1d21a3a851be73c27e67a6c \ No newline at end of file +725a06434b886c96bb816340ef236530672a4593f0ceb3230ce69c8367beb997 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index fb35bbbc5f..8ba0c4e97f 100644 --- a/src/btree.c +++ b/src/btree.c @@ -1914,7 +1914,6 @@ static int decodeFlags(MemPage *pPage, int flagByte){ pPage->leaf = (u8)(flagByte>>3); assert( PTF_LEAF == 1<<3 ); flagByte &= ~PTF_LEAF; pPage->childPtrSize = 4-4*pPage->leaf; - pPage->xCellSize = cellSizePtr; pBt = pPage->pBt; if( flagByte==(PTF_LEAFDATA | PTF_INTKEY) ){ /* EVIDENCE-OF: R-07291-35328 A value of 5 (0x05) means the page is an @@ -1944,12 +1943,17 @@ static int decodeFlags(MemPage *pPage, int flagByte){ assert( (PTF_ZERODATA|PTF_LEAF)==10 ); pPage->intKey = 0; pPage->intKeyLeaf = 0; + pPage->xCellSize = cellSizePtr; pPage->xParseCell = btreeParseCellPtrIndex; pPage->maxLocal = pBt->maxLocal; pPage->minLocal = pBt->minLocal; }else{ /* EVIDENCE-OF: R-47608-56469 Any other value for the b-tree page type is ** an error. */ + pPage->intKey = 0; + pPage->intKeyLeaf = 0; + pPage->xCellSize = cellSizePtr; + pPage->xParseCell = btreeParseCellPtrIndex; return SQLITE_CORRUPT_PAGE(pPage); } pPage->max1bytePayload = pBt->max1bytePayload; From 07559b2716a69bccee5ae823489ba4963d8db052 Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 3 Mar 2022 19:40:21 +0000 Subject: [PATCH 40/75] Restore the ability to push-down OR subterms of the WHERE clause when processing a multi-index OR. FossilOrigin-Name: d71fb6fdc32d2fce73059b6ab86d7d7bbc812c637469755dd45b6794aadc3a80 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/wherecode.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 2961d421fe..8705c1f52f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\ssure\sthe\sxParseCell\sand\sxCellSize\smethods\sof\sthe\sMemPage\sobject\sare\ninitialized\sconsistently\seven\sif\sthe\spage\sis\sdetected\sas\sbeing\scorrupt.\ndbsqlfuzz\sfd21f341f3b4f582401d2feb2a1c0c4cc2c26caa. -D 2022-03-03T16:48:35.284 +C Restore\sthe\sability\sto\spush-down\sOR\ssubterms\sof\sthe\sWHERE\sclause\swhen\nprocessing\sa\smulti-index\sOR. +D 2022-03-03T19:40:21.148 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -641,7 +641,7 @@ F src/wal.h c3aa7825bfa2fe0d85bef2db94655f99870a285778baa36307c0a16da32b226a F src/walker.c f890a3298418d7cba3b69b8803594fdc484ea241206a8dfa99db6dd36f8cbb3b F src/where.c 0d75d7514764726409ea945520fe9fb515e7d9ae52a5a3c0a136142cfaa19087 F src/whereInt.h 15d2975c3b4c193c78c26674400a840da8647fe1777ae3b026e2d15937b38a03 -F src/wherecode.c 5559cf12b4d3f6d123f70f9097a88fa879921785e9b69815a8901b89d63a87bf +F src/wherecode.c e0f6be39a0938008a20f1b1a528225f2364c459e88603799c417247a4ea3836c F src/whereexpr.c 2a71f5491798460c9590317329234d332d9eb1717cba4f3403122189a75c465e F src/window.c dfaec4abc6012cbc18e4a202ca3a5d5a0efcc4011d86a06d882ddaab8aedee4d F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 61a1c6dbd089979cbeb8b0c0c5ee1ab1abcb466be1d21a3a851be73c27e67a6c -R e394f5d71fcf3ab03b849ac8d2f2e010 +P 725a06434b886c96bb816340ef236530672a4593f0ceb3230ce69c8367beb997 +R 4b254954a632dbd7b6a27be8beffe3fb U drh -Z 6957f162062fe17752cd0dc465054be9 +Z 721c2ad23ec3a940469fd54f5a97ae6c # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index f3b06b1630..f321fa2422 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -725a06434b886c96bb816340ef236530672a4593f0ceb3230ce69c8367beb997 \ No newline at end of file +d71fb6fdc32d2fce73059b6ab86d7d7bbc812c637469755dd45b6794aadc3a80 \ No newline at end of file diff --git a/src/wherecode.c b/src/wherecode.c index ff82ffc1a5..d1f0635e7a 100644 --- a/src/wherecode.c +++ b/src/wherecode.c @@ -2365,7 +2365,7 @@ Bitmask sqlite3WhereCodeOneLoopStart( if( (pWC->a[iTerm].wtFlags & (TERM_VIRTUAL|TERM_CODED|TERM_SLICE))!=0 ){ continue; } - if( (pWC->a[iTerm].eOperator & WO_SINGLE)==0 ) continue; + if( (pWC->a[iTerm].eOperator & WO_ALL)==0 ) continue; if( ExprHasProperty(pExpr, EP_Subquery) ) continue; /* tag-20220303a */ pExpr = sqlite3ExprDup(db, pExpr, 0); pAndExpr = sqlite3ExprAnd(pParse, pAndExpr, pExpr); From 6f9d68817cddd4491a225403e8aa9125ee199fe5 Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 4 Mar 2022 16:28:24 +0000 Subject: [PATCH 41/75] When setting an sqlite3_value object to a pointer value, make sure any prior memory allocations associated with that object have been cleared first. dbsqlfuzz 33f842d1a09afaad5f078c3e1162a54b78e5f2ab. FossilOrigin-Name: 31e1bde4b20bec4242b4101adad29bfa85648ea703d6e8c5c75e8c49b54a3a0f --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbemem.c | 1 + 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 8705c1f52f..d67961edef 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Restore\sthe\sability\sto\spush-down\sOR\ssubterms\sof\sthe\sWHERE\sclause\swhen\nprocessing\sa\smulti-index\sOR. -D 2022-03-03T19:40:21.148 +C When\ssetting\san\ssqlite3_value\sobject\sto\sa\spointer\svalue,\smake\ssure\sany\sprior\nmemory\sallocations\sassociated\swith\sthat\sobject\shave\sbeen\scleared\sfirst.\ndbsqlfuzz\s33f842d1a09afaad5f078c3e1162a54b78e5f2ab. +D 2022-03-04T16:28:24.220 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -630,7 +630,7 @@ F src/vdbeInt.h 8dd91427155a38ec06e9ecbde07e33f21bc02e101625191e7613f883e379a363 F src/vdbeapi.c 1c80efbe51118bbecc7279023e75d18edcfa4b3dc441287e1718ee70ad594f58 F src/vdbeaux.c 280383a4c7fc567e30266cf72bb5031c252bc4cbc1a80d4e1461d77c4bd01547 F src/vdbeblob.c 5e61ce31aca17db8fb60395407457a8c1c7fb471dde405e0cd675974611dcfcd -F src/vdbemem.c ff564b58f49a9e982414c8ecde99e416eff939e7cbb0333aa976610430fd8038 +F src/vdbemem.c 57fceb4ed6aac960e9517c963dc0668189e8b7c8e6216d257030a2f5e9a583df F src/vdbesort.c 43756031ca7430f7aec3ef904824a7883c4ede783e51f280d99b9b65c0796e35 F src/vdbetrace.c fe0bc29ebd4e02c8bc5c1945f1d2e6be5927ec12c06d89b03ef2a4def34bf823 F src/vdbevtab.c f99b275366c5fc5e2d99f734729880994ab9500bdafde7fae3b02d562b9d323c @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 725a06434b886c96bb816340ef236530672a4593f0ceb3230ce69c8367beb997 -R 4b254954a632dbd7b6a27be8beffe3fb +P d71fb6fdc32d2fce73059b6ab86d7d7bbc812c637469755dd45b6794aadc3a80 +R 65843abfd17a21a032904c45a4211684 U drh -Z 721c2ad23ec3a940469fd54f5a97ae6c +Z 30a89616aec618962c425515c30f7a87 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index f321fa2422..70d5b1929a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d71fb6fdc32d2fce73059b6ab86d7d7bbc812c637469755dd45b6794aadc3a80 \ No newline at end of file +31e1bde4b20bec4242b4101adad29bfa85648ea703d6e8c5c75e8c49b54a3a0f \ No newline at end of file diff --git a/src/vdbemem.c b/src/vdbemem.c index 1795bb7d76..516a06b71e 100644 --- a/src/vdbemem.c +++ b/src/vdbemem.c @@ -924,6 +924,7 @@ void sqlite3VdbeMemSetPointer( void (*xDestructor)(void*) ){ assert( pMem->flags==MEM_Null ); + vdbeMemClear(pMem); pMem->u.zPType = zPType ? zPType : ""; pMem->z = pPtr; pMem->flags = MEM_Null|MEM_Dyn|MEM_Subtype|MEM_Term; From ff55da360d32879036881a7024cc12bbcb7b7779 Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 4 Mar 2022 20:54:09 +0000 Subject: [PATCH 42/75] Do try to evaluate the Bloom filter on a LEFT JOIN early, as doing so essentially converts it into an INNER JOIN. See [forum:/forumpost/544af7eee2|forum thread 544af7eee2]. FossilOrigin-Name: d46d0e67c96bd49add4f71194496804a31209f2027a2e48eaf36dde26c1ca7df --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/where.c | 3 +++ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index d67961edef..42daecdade 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\ssetting\san\ssqlite3_value\sobject\sto\sa\spointer\svalue,\smake\ssure\sany\sprior\nmemory\sallocations\sassociated\swith\sthat\sobject\shave\sbeen\scleared\sfirst.\ndbsqlfuzz\s33f842d1a09afaad5f078c3e1162a54b78e5f2ab. -D 2022-03-04T16:28:24.220 +C Do\stry\sto\sevaluate\sthe\sBloom\sfilter\son\sa\sLEFT\sJOIN\searly,\sas\sdoing\sso\nessentially\sconverts\sit\sinto\san\sINNER\sJOIN.\s\sSee\n[forum:/forumpost/544af7eee2|forum\sthread\s544af7eee2]. +D 2022-03-04T20:54:09.487 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -639,7 +639,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c b9df133a705093da8977da5eb202eaadb844839f1c7297c08d33471f5491843d F src/wal.h c3aa7825bfa2fe0d85bef2db94655f99870a285778baa36307c0a16da32b226a F src/walker.c f890a3298418d7cba3b69b8803594fdc484ea241206a8dfa99db6dd36f8cbb3b -F src/where.c 0d75d7514764726409ea945520fe9fb515e7d9ae52a5a3c0a136142cfaa19087 +F src/where.c 1471be86b34b8ce328c6c68d7e2ee667c7f801ddf83ff179bc5936700cf43aa7 F src/whereInt.h 15d2975c3b4c193c78c26674400a840da8647fe1777ae3b026e2d15937b38a03 F src/wherecode.c e0f6be39a0938008a20f1b1a528225f2364c459e88603799c417247a4ea3836c F src/whereexpr.c 2a71f5491798460c9590317329234d332d9eb1717cba4f3403122189a75c465e @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P d71fb6fdc32d2fce73059b6ab86d7d7bbc812c637469755dd45b6794aadc3a80 -R 65843abfd17a21a032904c45a4211684 +P 31e1bde4b20bec4242b4101adad29bfa85648ea703d6e8c5c75e8c49b54a3a0f +R ad552847ccd96e978367f3230e28420d U drh -Z 30a89616aec618962c425515c30f7a87 +Z ad96c30e3eedda5fc4e20235f373b88a # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 70d5b1929a..3417925d68 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -31e1bde4b20bec4242b4101adad29bfa85648ea703d6e8c5c75e8c49b54a3a0f \ No newline at end of file +d46d0e67c96bd49add4f71194496804a31209f2027a2e48eaf36dde26c1ca7df \ No newline at end of file diff --git a/src/where.c b/src/where.c index c1a2f0595e..ddec44723f 100644 --- a/src/where.c +++ b/src/where.c @@ -1078,7 +1078,10 @@ static SQLITE_NOINLINE void sqlite3ConstructBloomFilter( pLoop->wsFlags &= ~WHERE_BLOOMFILTER; if( OptimizationDisabled(pParse->db, SQLITE_BloomPulldown) ) break; while( ++iLevel < pWInfo->nLevel ){ + const SrcItem *pTabItem; pLevel = &pWInfo->a[iLevel]; + pTabItem = &pWInfo->pTabList->a[pLevel->iFrom]; + if( pTabItem->fg.jointype & JT_LEFT ) continue; pLoop = pLevel->pWLoop; if( NEVER(pLoop==0) ) continue; if( pLoop->prereq & notReady ) continue; From 768ab1f2969938b01475bea3e77d20f41db69a3c Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 5 Mar 2022 11:57:28 +0000 Subject: [PATCH 43/75] Update obsolete text in the ICU README.txt file talking about SQLite's robustness (or lack thereof) in the face of corrupt database files. FossilOrigin-Name: dc88fc62f096bcf4df91406f565197f335333388121f860ba4424d9c881b0117 --- ext/icu/README.txt | 14 ++++---------- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/ext/icu/README.txt b/ext/icu/README.txt index be443f54ef..c3c35a2c6f 100644 --- a/ext/icu/README.txt +++ b/ext/icu/README.txt @@ -153,18 +153,12 @@ SQLite. Documentation follows. the ICU extension LIKE operator is 50000, defined in source file "icu.c". - 3.3 Collation Sequence Security Issue + 3.3 Collation Sequence Security Internally, SQLite assumes that indices stored in database files are sorted according to the collation sequence indicated by the SQL schema. Changing the definition of a collation sequence after an index has been built is therefore equivalent to database - corruption. The SQLite library is not very well tested under - these conditions, and may contain potential buffer overruns - or other programming errors that could be exploited by a malicious - programmer. - - If the ICU extension is used in an environment where potentially - malicious users may execute arbitrary SQL (i.e. gears), they - should be prevented from invoking the icu_load_collation() function, - possibly using the authorisation callback. + corruption. The SQLite library is well tested for robustness in + the fact of database corruption. Database corruption may well + lead to incorrect answers, but should not cause memory errors. diff --git a/manifest b/manifest index 42daecdade..11d72ac22a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Do\stry\sto\sevaluate\sthe\sBloom\sfilter\son\sa\sLEFT\sJOIN\searly,\sas\sdoing\sso\nessentially\sconverts\sit\sinto\san\sINNER\sJOIN.\s\sSee\n[forum:/forumpost/544af7eee2|forum\sthread\s544af7eee2]. -D 2022-03-04T20:54:09.487 +C Update\sobsolete\stext\sin\sthe\sICU\sREADME.txt\sfile\stalking\sabout\sSQLite's\nrobustness\s(or\slack\sthereof)\sin\sthe\sface\sof\scorrupt\sdatabase\sfiles. +D 2022-03-05T11:57:28.075 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -237,7 +237,7 @@ F ext/fts5/tool/fts5txt2db.tcl c0d43c8590656f8240e622b00957b3a0facc49482411a9fdc F ext/fts5/tool/loadfts5.tcl 95b03429ee6b138645703c6ca192c3ac96eaf093 F ext/fts5/tool/mkfts5c.tcl 3eba8e9bee4221ed165f3304b51b2a74a705f4ec5df3d044573a2be539534af8 F ext/fts5/tool/showfts5.tcl d54da0e067306663e2d5d523965ca487698e722c -F ext/icu/README.txt 1c48ffaf7f255bd73d00a35f68f6de357c2a6594f16cb00506a151be23694706 +F ext/icu/README.txt 7ab7ced8ae78e3a645b57e78570ff589d4c672b71370f5aa9e1cd7024f400fc9 F ext/icu/icu.c 91c021c7e3e8bbba286960810fa303295c622e323567b2e6def4ce58e4466e60 F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a32075a8 F ext/lsm1/Makefile a553b728bba6c11201b795188c5708915cc4290f02b7df6ba7e8c4c943fd5cd9 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 31e1bde4b20bec4242b4101adad29bfa85648ea703d6e8c5c75e8c49b54a3a0f -R ad552847ccd96e978367f3230e28420d +P d46d0e67c96bd49add4f71194496804a31209f2027a2e48eaf36dde26c1ca7df +R 632afad4f960b20a23d678e1a540eb43 U drh -Z ad96c30e3eedda5fc4e20235f373b88a +Z 317b33796bdbec5f162d2e98c6d11372 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 3417925d68..e38302ceb3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d46d0e67c96bd49add4f71194496804a31209f2027a2e48eaf36dde26c1ca7df \ No newline at end of file +dc88fc62f096bcf4df91406f565197f335333388121f860ba4424d9c881b0117 \ No newline at end of file From a275e7669692532ce118d057d79d6a234422f9aa Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 5 Mar 2022 14:44:12 +0000 Subject: [PATCH 44/75] Fix the sqlite_offset() function so that it gives the correct answer even if the argument is a virtual column in an index-only query. Test cases in TH3. FossilOrigin-Name: 6029514b08b88e3fb3c0163813af38358490a6b6070b90f69975a324481394e5 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbe.c | 9 ++++++++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 11d72ac22a..3d2f6909bc 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Update\sobsolete\stext\sin\sthe\sICU\sREADME.txt\sfile\stalking\sabout\sSQLite's\nrobustness\s(or\slack\sthereof)\sin\sthe\sface\sof\scorrupt\sdatabase\sfiles. -D 2022-03-05T11:57:28.075 +C Fix\sthe\ssqlite_offset()\sfunction\sso\sthat\sit\sgives\sthe\scorrect\sanswer\seven\nif\sthe\sargument\sis\sa\svirtual\scolumn\sin\san\sindex-only\squery.\s\sTest\scases\nin\sTH3. +D 2022-03-05T14:44:12.351 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -624,7 +624,7 @@ F src/upsert.c 8789047a8f0a601ea42fa0256d1ba3190c13746b6ba940fe2d25643a7e991937 F src/utf.c ee39565f0843775cc2c81135751ddd93eceb91a673ea2c57f61c76f288b041a0 F src/util.c 602fe229f32a96ceccae4f40824129669582096f7c355f53dbac156c9fecef23 F src/vacuum.c 6c38ddc52f0619865c91dae9c441d4d48bf3040d7dc1bc5b22da1e45547ed0b3 -F src/vdbe.c 62282c976aedf02603368d8d20d33cb7c8c214a34538f39da028d3e0c2aa6e16 +F src/vdbe.c 2ea24e2b9064064ebdcce697b8f0717a8a53d66ca7292e4a3c838f4dd0b21c89 F src/vdbe.h a1d0e3b934e835e73edd146f2e7c4eadb711b5c9875c18159a57483fd78e550e F src/vdbeInt.h 8dd91427155a38ec06e9ecbde07e33f21bc02e101625191e7613f883e379a363 F src/vdbeapi.c 1c80efbe51118bbecc7279023e75d18edcfa4b3dc441287e1718ee70ad594f58 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P d46d0e67c96bd49add4f71194496804a31209f2027a2e48eaf36dde26c1ca7df -R 632afad4f960b20a23d678e1a540eb43 +P dc88fc62f096bcf4df91406f565197f335333388121f860ba4424d9c881b0117 +R 2806557a3f81ede52f2013929b744554 U drh -Z 317b33796bdbec5f162d2e98c6d11372 +Z b59d89faf70fb0b5b277341b5f59b059 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index e38302ceb3..60d2989007 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -dc88fc62f096bcf4df91406f565197f335333388121f860ba4424d9c881b0117 \ No newline at end of file +6029514b08b88e3fb3c0163813af38358490a6b6070b90f69975a324481394e5 \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index 554c9afb54..e0c1b47cd9 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -2641,8 +2641,15 @@ case OP_Offset: { /* out3 */ VdbeCursor *pC; /* The VDBE cursor */ assert( pOp->p1>=0 && pOp->p1nCursor ); pC = p->apCsr[pOp->p1]; + if( pC->deferredMoveto ){ + rc = sqlite3VdbeFinishMoveto(pC); + if( rc ) goto abort_due_to_error; + } pOut = &p->aMem[pOp->p3]; - if( NEVER(pC==0) || pC->eCurType!=CURTYPE_BTREE ){ + if( NEVER(pC==0) + || pC->eCurType!=CURTYPE_BTREE + || NEVER(sqlite3BtreeEof(pC->uc.pCursor)) + ){ sqlite3VdbeMemSetNull(pOut); }else{ sqlite3VdbeMemSetInt64(pOut, sqlite3BtreeOffset(pC->uc.pCursor)); From 8f32d92786dc542a7550ca4142fd78f9d0d8a194 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 5 Mar 2022 19:36:29 +0000 Subject: [PATCH 45/75] Further improvements to the sqlite_offset() function. FossilOrigin-Name: 4230e2f5e068f2151fa33be25bb06123d41273dbe497a5ebc7173f8d7f81d160 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbe.c | 19 ++++++++++--------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/manifest b/manifest index 3d2f6909bc..d4520ccadb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\ssqlite_offset()\sfunction\sso\sthat\sit\sgives\sthe\scorrect\sanswer\seven\nif\sthe\sargument\sis\sa\svirtual\scolumn\sin\san\sindex-only\squery.\s\sTest\scases\nin\sTH3. -D 2022-03-05T14:44:12.351 +C Further\simprovements\sto\sthe\ssqlite_offset()\sfunction. +D 2022-03-05T19:36:29.116 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -624,7 +624,7 @@ F src/upsert.c 8789047a8f0a601ea42fa0256d1ba3190c13746b6ba940fe2d25643a7e991937 F src/utf.c ee39565f0843775cc2c81135751ddd93eceb91a673ea2c57f61c76f288b041a0 F src/util.c 602fe229f32a96ceccae4f40824129669582096f7c355f53dbac156c9fecef23 F src/vacuum.c 6c38ddc52f0619865c91dae9c441d4d48bf3040d7dc1bc5b22da1e45547ed0b3 -F src/vdbe.c 2ea24e2b9064064ebdcce697b8f0717a8a53d66ca7292e4a3c838f4dd0b21c89 +F src/vdbe.c 17ac5ed082a7f6832af3eb6c72b9a74049867c9a8c80b3c1e40faa017960941d F src/vdbe.h a1d0e3b934e835e73edd146f2e7c4eadb711b5c9875c18159a57483fd78e550e F src/vdbeInt.h 8dd91427155a38ec06e9ecbde07e33f21bc02e101625191e7613f883e379a363 F src/vdbeapi.c 1c80efbe51118bbecc7279023e75d18edcfa4b3dc441287e1718ee70ad594f58 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P dc88fc62f096bcf4df91406f565197f335333388121f860ba4424d9c881b0117 -R 2806557a3f81ede52f2013929b744554 +P 6029514b08b88e3fb3c0163813af38358490a6b6070b90f69975a324481394e5 +R f0549687576d457bd9294e013f1fc17c U drh -Z b59d89faf70fb0b5b277341b5f59b059 +Z bfd7cd8391b1ab153c29141b066fa590 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 60d2989007..d030798693 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6029514b08b88e3fb3c0163813af38358490a6b6070b90f69975a324481394e5 \ No newline at end of file +4230e2f5e068f2151fa33be25bb06123d41273dbe497a5ebc7173f8d7f81d160 \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index e0c1b47cd9..e79ffe54fd 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -2641,18 +2641,19 @@ case OP_Offset: { /* out3 */ VdbeCursor *pC; /* The VDBE cursor */ assert( pOp->p1>=0 && pOp->p1nCursor ); pC = p->apCsr[pOp->p1]; - if( pC->deferredMoveto ){ - rc = sqlite3VdbeFinishMoveto(pC); - if( rc ) goto abort_due_to_error; - } pOut = &p->aMem[pOp->p3]; - if( NEVER(pC==0) - || pC->eCurType!=CURTYPE_BTREE - || NEVER(sqlite3BtreeEof(pC->uc.pCursor)) - ){ + if( pC==0 || pC->eCurType!=CURTYPE_BTREE ){ sqlite3VdbeMemSetNull(pOut); }else{ - sqlite3VdbeMemSetInt64(pOut, sqlite3BtreeOffset(pC->uc.pCursor)); + if( pC->deferredMoveto ){ + rc = sqlite3VdbeFinishMoveto(pC); + if( rc ) goto abort_due_to_error; + } + if( NEVER(sqlite3BtreeEof(pC->uc.pCursor)) ){ + sqlite3VdbeMemSetNull(pOut); + }else{ + sqlite3VdbeMemSetInt64(pOut, sqlite3BtreeOffset(pC->uc.pCursor)); + } } break; } From ea840117af0ec45f50a840a20001587deda31ece Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 5 Mar 2022 20:12:53 +0000 Subject: [PATCH 46/75] Fix the 'localtime' modifier in date/time functions so that it preserves fractional seconds. [forum:/forumpost/2ffbaa2c3fd7fb82|Forum post 2ffbaa2c3fd7fb82]. FossilOrigin-Name: 1c875b0764ab00e95c92f0ee329659e88041763e125c2891201d80f68c41f717 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/date.c | 2 +- test/date.test | 5 ++++- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index d4520ccadb..4e1a2d6053 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Further\simprovements\sto\sthe\ssqlite_offset()\sfunction. -D 2022-03-05T19:36:29.116 +C Fix\sthe\s'localtime'\smodifier\sin\sdate/time\sfunctions\sso\sthat\sit\spreserves\nfractional\sseconds.\n[forum:/forumpost/2ffbaa2c3fd7fb82|Forum\spost\s2ffbaa2c3fd7fb82]. +D 2022-03-05T20:12:53.990 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -499,7 +499,7 @@ F src/build.c 9891c2160886cf7e344d7e8f1f7177f9612916c7c67ffeacd64cb34a92d387a8 F src/callback.c 4c19af69835787bfe790ac560f3071a824eb629f34e41f97b52ce5235c77de1c F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e F src/ctime.c 2cce39df1a13e05b7633e6d21b651f21492471f991dd7b323a4ee4e7b7f0b7f1 -F src/date.c 1abbd739ae1d3fc8e0aaff995f57332af10d0b332728e4d3f241c494515495f0 +F src/date.c 15082566229d4b1e5f24fdb490bf9bcc68824b911d70e3573ef075a1b9e2d26f F src/dbpage.c 8a01e865bf8bc6d7b1844b4314443a6436c07c3efe1d488ed89e81719047833a F src/dbstat.c 861e08690fcb0f2ee1165eff0060ea8d4f3e2ea10f80dab7d32ad70443a6ff2d F src/delete.c b5f1716b4d723db48254ee0f896e362cd029e865e05414139ea7f539f3884e1d @@ -837,7 +837,7 @@ F test/ctime.test 340f362f41f92972bbd71f44e10569a5cc694062b692231bd08aa6fe6c1c47 F test/cursorhint.test 0175e4404181ace3ceca8b114eb0a98eae600d565aa4e2705abbe6614c7fe201 F test/cursorhint2.test 6f3aa9cb19e7418967a10ec6905209bcbb5968054da855fc36c8beee9ae9c42f F test/dataversion1.test 6e5e86ac681f0782e766ebcb56c019ae001522d114e0e111e5ebf68ccf2a7bb8 -F test/date.test 50d5b1eeec57041c000d2be5e9ab995026ded4255507f0206c81c1ca3b34b840 +F test/date.test 118e04db8c8b4efeb885542b4918c7b869a34c460a6bebbfe927dfd75706b80d F test/date2.test 7e12ec14aaf4d5e6294b4ba140445b0eca06ea50062a9c3a69c4ee13d0b6f8b1 F test/date3.test a1b77abf05c6772fe5ca2337cac1398892f2a41e62bce7e6be0f4a08a0e64ae5 F test/dbdata.test 042f49acff3438f940eeba5868d3af080ae64ddf26ae78f80c92bec3ca7d8603 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 6029514b08b88e3fb3c0163813af38358490a6b6070b90f69975a324481394e5 -R f0549687576d457bd9294e013f1fc17c +P 4230e2f5e068f2151fa33be25bb06123d41273dbe497a5ebc7173f8d7f81d160 +R a3891cb2acaa3a2b99d86e17fa16100e U drh -Z bfd7cd8391b1ab153c29141b066fa590 +Z 5cc749784ef515382e391fd2e88fc594 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d030798693..4601230080 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4230e2f5e068f2151fa33be25bb06123d41273dbe497a5ebc7173f8d7f81d160 \ No newline at end of file +1c875b0764ab00e95c92f0ee329659e88041763e125c2891201d80f68c41f717 \ No newline at end of file diff --git a/src/date.c b/src/date.c index b96ebc05d2..6e2ba202b7 100644 --- a/src/date.c +++ b/src/date.c @@ -602,7 +602,7 @@ static int toLocaltime( p->D = sLocal.tm_mday; p->h = sLocal.tm_hour; p->m = sLocal.tm_min; - p->s = sLocal.tm_sec; + p->s = sLocal.tm_sec + (p->iJD%1000)*0.001; p->validYMD = 1; p->validHMS = 1; p->validJD = 0; diff --git a/test/date.test b/test/date.test index a9a34065c1..62233ad8f6 100644 --- a/test/date.test +++ b/test/date.test @@ -539,6 +539,9 @@ datetest 17.5 {datetime(2457828,'start of year')} {2017-01-01 00:00:00} datetest 17.6 {datetime(37,'start of year')} NULL datetest 17.7 {datetime(38,'start of year')} {-4712-01-01 00:00:00} - +# 2022-03-04 https://sqlite.org/forum/forumpost/2ffbaa2c3fd7fb82 +# The 'localtime' modifier should preserve fractional seconds. +# +datetest 18.1 {strftime('%f',1.234,'unixepoch','localtime')} {01.234} finish_test From dc9513601e0d82a4b2e93e94fb80ec69f02326e5 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 5 Mar 2022 23:52:05 +0000 Subject: [PATCH 47/75] Remove a NEVER() associated with sqlite_offset()> FossilOrigin-Name: e29dffcdba6f68af5cb76ca250e06a42183d9db92b60a16b2337b0d43c68bf2e --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbe.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 4e1a2d6053..de82fdee97 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\s'localtime'\smodifier\sin\sdate/time\sfunctions\sso\sthat\sit\spreserves\nfractional\sseconds.\n[forum:/forumpost/2ffbaa2c3fd7fb82|Forum\spost\s2ffbaa2c3fd7fb82]. -D 2022-03-05T20:12:53.990 +C Remove\sa\sNEVER()\sassociated\swith\ssqlite_offset()> +D 2022-03-05T23:52:05.495 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -624,7 +624,7 @@ F src/upsert.c 8789047a8f0a601ea42fa0256d1ba3190c13746b6ba940fe2d25643a7e991937 F src/utf.c ee39565f0843775cc2c81135751ddd93eceb91a673ea2c57f61c76f288b041a0 F src/util.c 602fe229f32a96ceccae4f40824129669582096f7c355f53dbac156c9fecef23 F src/vacuum.c 6c38ddc52f0619865c91dae9c441d4d48bf3040d7dc1bc5b22da1e45547ed0b3 -F src/vdbe.c 17ac5ed082a7f6832af3eb6c72b9a74049867c9a8c80b3c1e40faa017960941d +F src/vdbe.c b1830c6daf744473a732257652b6431ac18032f508a3e30ff3a1466fe5978559 F src/vdbe.h a1d0e3b934e835e73edd146f2e7c4eadb711b5c9875c18159a57483fd78e550e F src/vdbeInt.h 8dd91427155a38ec06e9ecbde07e33f21bc02e101625191e7613f883e379a363 F src/vdbeapi.c 1c80efbe51118bbecc7279023e75d18edcfa4b3dc441287e1718ee70ad594f58 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 4230e2f5e068f2151fa33be25bb06123d41273dbe497a5ebc7173f8d7f81d160 -R a3891cb2acaa3a2b99d86e17fa16100e +P 1c875b0764ab00e95c92f0ee329659e88041763e125c2891201d80f68c41f717 +R eddd65823035f6d87a8d953cb436e877 U drh -Z 5cc749784ef515382e391fd2e88fc594 +Z 2f62ada0831e290d77c07589d7cf603f # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 4601230080..a2682f8205 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1c875b0764ab00e95c92f0ee329659e88041763e125c2891201d80f68c41f717 \ No newline at end of file +e29dffcdba6f68af5cb76ca250e06a42183d9db92b60a16b2337b0d43c68bf2e \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index e79ffe54fd..cf6137ab0a 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -2649,7 +2649,7 @@ case OP_Offset: { /* out3 */ rc = sqlite3VdbeFinishMoveto(pC); if( rc ) goto abort_due_to_error; } - if( NEVER(sqlite3BtreeEof(pC->uc.pCursor)) ){ + if( sqlite3BtreeEof(pC->uc.pCursor) ){ sqlite3VdbeMemSetNull(pOut); }else{ sqlite3VdbeMemSetInt64(pOut, sqlite3BtreeOffset(pC->uc.pCursor)); From 97a985e0c5c3257bbed7423ab81a9123d18079ca Mon Sep 17 00:00:00 2001 From: drh <> Date: Sun, 6 Mar 2022 11:43:06 +0000 Subject: [PATCH 48/75] The sqlite_offset() function should be non-deterministic. dbsqlfuzz 3df8230bb940870db87ffca2c0fc759c1e7fa356. FossilOrigin-Name: e1a185e60afd32d3b25278dee42049920759ccd8fe709161007f5daa4a048693 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/func.c | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index de82fdee97..c055120748 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\sa\sNEVER()\sassociated\swith\ssqlite_offset()> -D 2022-03-05T23:52:05.495 +C The\ssqlite_offset()\sfunction\sshould\sbe\snon-deterministic.\ndbsqlfuzz\s3df8230bb940870db87ffca2c0fc759c1e7fa356. +D 2022-03-06T11:43:06.649 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -506,7 +506,7 @@ F src/delete.c b5f1716b4d723db48254ee0f896e362cd029e865e05414139ea7f539f3884e1d F src/expr.c 3cdb00b6c15f815c94836e7b4474b675155d1279e64804f6ab5816188a9b05b6 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c 06e4ac33031b02dde7130c12e79cddf4dc5cfa72b23d8e63a3c26878fc9c1d3c -F src/func.c f801c6bc8b30afea51817d86a6c46259d3cca180c612cfa0a30b18d661e9c8df +F src/func.c a3407a6fbb0d4088d8d502e46f0ace63e0aeae7467ae23a9ca9815bbf9239761 F src/global.c a3daa18a1696aadd94f18d37cbbdebf0bbdb827b8397a534f021cd56c15cd0f9 F src/hash.c 8d7dda241d0ebdafb6ffdeda3149a412d7df75102cecfc1021c98d6219823b19 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 1c875b0764ab00e95c92f0ee329659e88041763e125c2891201d80f68c41f717 -R eddd65823035f6d87a8d953cb436e877 +P e29dffcdba6f68af5cb76ca250e06a42183d9db92b60a16b2337b0d43c68bf2e +R e44b1e991497d101f7d60ecf2d42efc6 U drh -Z 2f62ada0831e290d77c07589d7cf603f +Z 5e3aad0d7656a38b0b65e677bfc05be9 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index a2682f8205..20437b1396 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e29dffcdba6f68af5cb76ca250e06a42183d9db92b60a16b2337b0d43c68bf2e \ No newline at end of file +e1a185e60afd32d3b25278dee42049920759ccd8fe709161007f5daa4a048693 \ No newline at end of file diff --git a/src/func.c b/src/func.c index c15f5c73e7..7ccb5118e8 100644 --- a/src/func.c +++ b/src/func.c @@ -2241,8 +2241,8 @@ void sqlite3RegisterBuiltinFunctions(void){ INLINE_FUNC(likelihood, 2, INLINEFUNC_unlikely, SQLITE_FUNC_UNLIKELY), INLINE_FUNC(likely, 1, INLINEFUNC_unlikely, SQLITE_FUNC_UNLIKELY), #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC - FUNCTION2(sqlite_offset, 1, 0, 0, noopFunc, SQLITE_FUNC_OFFSET| - SQLITE_FUNC_TYPEOF), + {1, SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_FUNC_OFFSET|SQLITE_FUNC_TYPEOF, + 0, 0, noopFunc, 0, 0, 0, "sqlite_offset", {0} }, #endif FUNCTION(ltrim, 1, 1, 0, trimFunc ), FUNCTION(ltrim, 2, 1, 0, trimFunc ), From eab1064f045a249a4801d8329a4fbf09d47a4b0a Mon Sep 17 00:00:00 2001 From: drh <> Date: Sun, 6 Mar 2022 20:22:24 +0000 Subject: [PATCH 49/75] Fix obsolete but harmless comments in btree. No changes to code. FossilOrigin-Name: 4838b888e431f794b8a5ee65e797b3bf0616c03261de4e1fc9499287eb3e1265 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/btree.c | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index c055120748..5916def05f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C The\ssqlite_offset()\sfunction\sshould\sbe\snon-deterministic.\ndbsqlfuzz\s3df8230bb940870db87ffca2c0fc759c1e7fa356. -D 2022-03-06T11:43:06.649 +C Fix\sobsolete\sbut\sharmless\scomments\sin\sbtree.\s\sNo\schanges\sto\scode. +D 2022-03-06T20:22:24.862 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -492,7 +492,7 @@ F src/auth.c f4fa91b6a90bbc8e0d0f738aa284551739c9543a367071f55574681e0f24f8cf F src/backup.c a2891172438e385fdbe97c11c9745676bec54f518d4447090af97189fd8e52d7 F src/bitvec.c 7c849aac407230278445cb069bebc5f89bf2ddd87c5ed9459b070a9175707b3d F src/btmutex.c 8acc2f464ee76324bf13310df5692a262b801808984c1b79defb2503bbafadb6 -F src/btree.c 9a5112589dc9491781bfd4e1b30d79bdab7e7ea3fc37a505e7ca5cc82f01c09a +F src/btree.c 3a925b8542eb7f2a00c1919d6dbcd252b1d2781fbc43228b33dcc03fe6cd772a F src/btree.h 74d64b8f28cfa4a894d14d4ed64fa432cd697b98b61708d4351482ae15913e22 F src/btreeInt.h 1ca477727c5f420a8321208dc5b14d93cb46cec8f941bc49318feb0e00bc961f F src/build.c 9891c2160886cf7e344d7e8f1f7177f9612916c7c67ffeacd64cb34a92d387a8 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P e29dffcdba6f68af5cb76ca250e06a42183d9db92b60a16b2337b0d43c68bf2e -R e44b1e991497d101f7d60ecf2d42efc6 +P e1a185e60afd32d3b25278dee42049920759ccd8fe709161007f5daa4a048693 +R 3b376b7bd2b0a7789dc2fc49263ee5af U drh -Z 5e3aad0d7656a38b0b65e677bfc05be9 +Z 746f08a842d71959509f58033103e467 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 20437b1396..8116d99ea5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e1a185e60afd32d3b25278dee42049920759ccd8fe709161007f5daa4a048693 \ No newline at end of file +4838b888e431f794b8a5ee65e797b3bf0616c03261de4e1fc9499287eb3e1265 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 8ba0c4e97f..ea31738c7d 100644 --- a/src/btree.c +++ b/src/btree.c @@ -807,7 +807,7 @@ void sqlite3BtreeClearCursor(BtCursor *pCur){ /* ** In this version of BtreeMoveto, pKey is a packed index record ** such as is generated by the OP_MakeRecord opcode. Unpack the -** record and then call BtreeMovetoUnpacked() to do the work. +** record and then call sqlite3BtreeIndexMoveto() to do the work. */ static int btreeMoveto( BtCursor *pCur, /* Cursor open on the btree to be searched */ @@ -8875,7 +8875,7 @@ static int btreeOverwriteCell(BtCursor *pCur, const BtreePayload *pX){ ** pX.pData,nData,nZero fields must be zero. ** ** If the seekResult parameter is non-zero, then a successful call to -** MovetoUnpacked() to seek cursor pCur to (pKey,nKey) has already +** sqlite3BtreeIndexMoveto() to seek cursor pCur to (pKey,nKey) has already ** been performed. In other words, if seekResult!=0 then the cursor ** is currently pointing to a cell that will be adjacent to the cell ** to be inserted. If seekResult<0 then pCur points to a cell that is @@ -8893,7 +8893,7 @@ int sqlite3BtreeInsert( BtCursor *pCur, /* Insert data into the table of this cursor */ const BtreePayload *pX, /* Content of the row to be inserted */ int flags, /* True if this is likely an append */ - int seekResult /* Result of prior MovetoUnpacked() call */ + int seekResult /* Result of prior IndexMoveto() call */ ){ int rc; int loc = seekResult; /* -1: before desired location +1: after */ From 53e1186da9e6c971ab3301f4f46bbdcb8db81d04 Mon Sep 17 00:00:00 2001 From: larrybr Date: Sun, 6 Mar 2022 23:41:21 +0000 Subject: [PATCH 50/75] For CLI .import, revert to importing into temp or main when given table is found there and no -schema option used. And plug an obscure leak. FossilOrigin-Name: bf9d1278846dce9255f9a11ddfc5dfac1acea2eadcb20816a19d59f7bccaec0f --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/shell.c.in | 45 +++++++++++++++++++++++---------------------- test/shell5.test | 16 +++++++++++++++- 4 files changed, 47 insertions(+), 32 deletions(-) diff --git a/manifest b/manifest index 5916def05f..8702de82a3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sobsolete\sbut\sharmless\scomments\sin\sbtree.\s\sNo\schanges\sto\scode. -D 2022-03-06T20:22:24.862 +C For\sCLI\s.import,\srevert\sto\simporting\sinto\stemp\sor\smain\swhen\sgiven\stable\sis\sfound\sthere\sand\sno\s-schema\soption\sused.\sAnd\splug\san\sobscure\sleak. +D 2022-03-06T23:41:21.849 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -553,7 +553,7 @@ F src/random.c 097dc8b31b8fba5a9aca1697aeb9fd82078ec91be734c16bffda620ced7ab83c F src/resolve.c ea935b87d6fb36c78b70cdc7b28561dc8f33f2ef37048389549c7b5ef9b0ba5e F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92 F src/select.c 4890a3cfee0bc60ff231c3a44db37968859ab0be156983dbcc0c096109832cdd -F src/shell.c.in 14cdfba32c73cb06169e50cd448632c28359f2bab2a0f803dc4a7f46dfc5b6fa +F src/shell.c.in 3b4cfb17b0683831b3b42f92f411c311a8757d4e6fac7a1524258a29bbfbadbf F src/sqlite.h.in e82ac380b307659d0892f502b742f825504e78729f4edaadce946003b9c00816 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h a95cb9ed106e3d39e2118e4dcc15a14faec3fa50d0093425083d340d9dfd96e6 @@ -1392,7 +1392,7 @@ F test/shell1.test b224e0793c5f48aa3749e65d8c64b93a30731bd206f2e41e6c5f1bee1bdb1 F test/shell2.test 89e4b2db062d52baed75022227b462d085cff495809de1699652779d8e0257d6 F test/shell3.test a50628ab1d78d90889d9d3f32fb2c084ee15674771e96afe954aaa0accd1de3c F test/shell4.test 8f6c0fce4abed19a8a7f7262517149812a04caa905d01bdc8f5e92573504b759 -F test/shell5.test 2b521446f55146c9aafccd0946bdb44ae288b0d25bd48f722e041974fdeeb04a +F test/shell5.test 0a9920d81fae28c45cd5dbd1deb809487a23c5f4b422a49f9d31c85f926d4a9c F test/shell6.test 1ceb51b2678c472ba6cf1e5da96679ce8347889fe2c3bf93a0e0fa73f00b00d3 F test/shell7.test 115132f66d0463417f408562cc2cf534f6bbc6d83a6d50f0072a9eb171bae97f F test/shell8.test 388471d16e4de767333107e30653983f186232c0e863f4490bb230419e830aae @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P e1a185e60afd32d3b25278dee42049920759ccd8fe709161007f5daa4a048693 -R 3b376b7bd2b0a7789dc2fc49263ee5af -U drh -Z 746f08a842d71959509f58033103e467 +P 4838b888e431f794b8a5ee65e797b3bf0616c03261de4e1fc9499287eb3e1265 +R 48c484e9a49cdc0f439e995f4d0daf72 +U larrybr +Z b5862c83f76331b7720ff8f2e107fcd4 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 8116d99ea5..dc324d3a48 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4838b888e431f794b8a5ee65e797b3bf0616c03261de4e1fc9499287eb3e1265 \ No newline at end of file +bf9d1278846dce9255f9a11ddfc5dfac1acea2eadcb20816a19d59f7bccaec0f \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index 354c9a849b..90445c9cf4 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -8827,7 +8827,7 @@ static int do_meta_command(char *zLine, ShellState *p){ if( c=='i' && strncmp(azArg[0], "import", n)==0 ){ char *zTable = 0; /* Insert data into this table */ - char *zSchema = "main"; /* within this schema */ + char *zSchema = 0; /* within this schema (may default to "main") */ char *zFile = 0; /* Name of file to extra content from */ sqlite3_stmt *pStmt = NULL; /* A statement */ int nCol; /* Number of columns in the table */ @@ -8963,7 +8963,6 @@ static int do_meta_command(char *zLine, ShellState *p){ import_cleanup(&sCtx); goto meta_command_exit; } - /* Below, resources must be freed before exit. */ if( eVerbose>=2 || (eVerbose>=1 && useOutputMode) ){ char zSep[2]; zSep[1] = 0; @@ -8975,11 +8974,17 @@ static int do_meta_command(char *zLine, ShellState *p){ output_c_string(p->out, zSep); utf8_printf(p->out, "\n"); } + /* Below, resources must be freed before exit. */ while( (nSkip--)>0 ){ while( xRead(&sCtx) && sCtx.cTerm==sCtx.cColSep ){} } - zSql = sqlite3_mprintf("SELECT * FROM \"%w\".\"%w\"", zSchema, zTable); - if( zSql==0 ){ + if( zSchema!=0 ){ + zSchema = sqlite3_mprintf("\"%w\".\"%w\"", zSchema, zTable); + }else{ + zSchema = sqlite3_mprintf("\"%w\"", zTable); + } + zSql = sqlite3_mprintf("SELECT * FROM %s", zSchema); + if( zSql==0 || zSchema==0 ){ import_cleanup(&sCtx); shell_out_of_memory(); } @@ -8987,8 +8992,7 @@ static int do_meta_command(char *zLine, ShellState *p){ rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); import_append_char(&sCtx, 0); /* To ensure sCtx.z is allocated */ if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(p->db))==0 ){ - char *zCreate = sqlite3_mprintf("CREATE TABLE \"%w\".\"%w\"", - zSchema, zTable); + char *zCreate = sqlite3_mprintf("CREATE TABLE %s", zSchema); sqlite3 *dbCols = 0; char *zRenames = 0; char *zColDefs; @@ -9005,9 +9009,12 @@ static int do_meta_command(char *zLine, ShellState *p){ } assert(dbCols==0); if( zColDefs==0 ){ - sqlite3_free(zCreate); - import_cleanup(&sCtx); utf8_printf(stderr,"%s: empty file\n", sCtx.zFile); + import_fail: + sqlite3_free(zCreate); + sqlite3_free(zSql); + sqlite3_free(zSchema); + import_cleanup(&sCtx); rc = 1; goto meta_command_exit; } @@ -9018,22 +9025,18 @@ static int do_meta_command(char *zLine, ShellState *p){ rc = sqlite3_exec(p->db, zCreate, 0, 0, 0); if( rc ){ utf8_printf(stderr, "%s failed:\n%s\n", zCreate, sqlite3_errmsg(p->db)); - sqlite3_free(zCreate); - import_cleanup(&sCtx); - rc = 1; - goto meta_command_exit; + goto import_fail; } sqlite3_free(zCreate); + zCreate = 0; rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); } - sqlite3_free(zSql); if( rc ){ if (pStmt) sqlite3_finalize(pStmt); utf8_printf(stderr,"Error: %s\n", sqlite3_errmsg(p->db)); - import_cleanup(&sCtx); - rc = 1; - goto meta_command_exit; + goto import_fail; } + sqlite3_free(zSql); nCol = sqlite3_column_count(pStmt); sqlite3_finalize(pStmt); pStmt = 0; @@ -9043,8 +9046,7 @@ static int do_meta_command(char *zLine, ShellState *p){ import_cleanup(&sCtx); shell_out_of_memory(); } - sqlite3_snprintf(nByte+20, zSql, "INSERT INTO \"%w\".\"%w\" VALUES(?", - zSchema, zTable); + sqlite3_snprintf(nByte+20, zSql, "INSERT INTO %s VALUES(?", zSchema); j = strlen30(zSql); for(i=1; iout, "Insert using: %s\n", zSql); } rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); - sqlite3_free(zSql); if( rc ){ utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db)); if (pStmt) sqlite3_finalize(pStmt); - import_cleanup(&sCtx); - rc = 1; - goto meta_command_exit; + goto import_fail; } + sqlite3_free(zSql); + sqlite3_free(zSchema); needCommit = sqlite3_get_autocommit(p->db); if( needCommit ) sqlite3_exec(p->db, "BEGIN", 0, 0, 0); do{ diff --git a/test/shell5.test b/test/shell5.test index 2237e685d5..d63a0a20d3 100644 --- a/test/shell5.test +++ b/test/shell5.test @@ -262,7 +262,7 @@ do_test shell5-1.7.1 { SELECT COUNT(*) FROM t3;}] } [list 0 $rows] -# Inport from a pipe. (Unix only, as it requires "awk") +# Import from a pipe. (Unix only, as it requires "awk") if {$tcl_platform(platform)=="unix"} { do_test shell5-1.8 { forcedelete test.db @@ -476,6 +476,20 @@ CREATE TABLE t8(a, b, c); db eval { SELECT * FROM t8 } } {1 2 3} +do_test shell5-4.4 { + forcedelete shell5.csv + set fd [open shell5.csv w] + puts $fd "1,2,3" + close $fd + catchcmd test.db [string trim { +.mode csv +CREATE TEMP TABLE t8(a, b, c); +.import shell5.csv t8 +.nullvalue # +SELECT * FROM temp.t8 + }] +} {0 1,2,3} + #---------------------------------------------------------------------------- # Tests for the shell automatic column rename. # From 41f46703b84b12c3d67e053687a9967aa8048cb9 Mon Sep 17 00:00:00 2001 From: larrybr Date: Mon, 7 Mar 2022 00:14:52 +0000 Subject: [PATCH 51/75] Disentangle variable use in last checkin FossilOrigin-Name: 4c3a02600f10926da1f88ddbd457bb1486e6e02dee366b5cfc89e498a10daa6f --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/shell.c.in | 17 +++++++++-------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/manifest b/manifest index 8702de82a3..1a7976cec9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C For\sCLI\s.import,\srevert\sto\simporting\sinto\stemp\sor\smain\swhen\sgiven\stable\sis\sfound\sthere\sand\sno\s-schema\soption\sused.\sAnd\splug\san\sobscure\sleak. -D 2022-03-06T23:41:21.849 +C Disentangle\svariable\suse\sin\slast\scheckin +D 2022-03-07T00:14:52.499 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -553,7 +553,7 @@ F src/random.c 097dc8b31b8fba5a9aca1697aeb9fd82078ec91be734c16bffda620ced7ab83c F src/resolve.c ea935b87d6fb36c78b70cdc7b28561dc8f33f2ef37048389549c7b5ef9b0ba5e F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92 F src/select.c 4890a3cfee0bc60ff231c3a44db37968859ab0be156983dbcc0c096109832cdd -F src/shell.c.in 3b4cfb17b0683831b3b42f92f411c311a8757d4e6fac7a1524258a29bbfbadbf +F src/shell.c.in 0a9c4b9226143365c8aea42eb9a62e055e9fffffc5e4559da5c9dadc0bedaa25 F src/sqlite.h.in e82ac380b307659d0892f502b742f825504e78729f4edaadce946003b9c00816 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h a95cb9ed106e3d39e2118e4dcc15a14faec3fa50d0093425083d340d9dfd96e6 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 4838b888e431f794b8a5ee65e797b3bf0616c03261de4e1fc9499287eb3e1265 -R 48c484e9a49cdc0f439e995f4d0daf72 +P bf9d1278846dce9255f9a11ddfc5dfac1acea2eadcb20816a19d59f7bccaec0f +R 496fa8a876df6daf353669fc02e2fc4c U larrybr -Z b5862c83f76331b7720ff8f2e107fcd4 +Z 013bf70ae42a0fa3c911efc40e5d2bba # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index dc324d3a48..209490bd9e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -bf9d1278846dce9255f9a11ddfc5dfac1acea2eadcb20816a19d59f7bccaec0f \ No newline at end of file +4c3a02600f10926da1f88ddbd457bb1486e6e02dee366b5cfc89e498a10daa6f \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index 90445c9cf4..b0f3b02dc4 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -8836,6 +8836,7 @@ static int do_meta_command(char *zLine, ShellState *p){ int needCommit; /* True to COMMIT or ROLLBACK at end */ int nSep; /* Number of bytes in p->colSeparator[] */ char *zSql; /* An SQL statement */ + char *zFullTabName; /* Table name with schema if applicable */ ImportCtx sCtx; /* Reader context */ char *(SQLITE_CDECL *xRead)(ImportCtx*); /* Func to read one value */ int eVerbose = 0; /* Larger for more console output */ @@ -8979,12 +8980,12 @@ static int do_meta_command(char *zLine, ShellState *p){ while( xRead(&sCtx) && sCtx.cTerm==sCtx.cColSep ){} } if( zSchema!=0 ){ - zSchema = sqlite3_mprintf("\"%w\".\"%w\"", zSchema, zTable); + zFullTabName = sqlite3_mprintf("\"%w\".\"%w\"", zSchema, zTable); }else{ - zSchema = sqlite3_mprintf("\"%w\"", zTable); + zFullTabName = sqlite3_mprintf("\"%w\"", zTable); } - zSql = sqlite3_mprintf("SELECT * FROM %s", zSchema); - if( zSql==0 || zSchema==0 ){ + zSql = sqlite3_mprintf("SELECT * FROM %s", zFullTabName); + if( zSql==0 || zFullTabName==0 ){ import_cleanup(&sCtx); shell_out_of_memory(); } @@ -8992,7 +8993,7 @@ static int do_meta_command(char *zLine, ShellState *p){ rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); import_append_char(&sCtx, 0); /* To ensure sCtx.z is allocated */ if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(p->db))==0 ){ - char *zCreate = sqlite3_mprintf("CREATE TABLE %s", zSchema); + char *zCreate = sqlite3_mprintf("CREATE TABLE %s", zFullTabName); sqlite3 *dbCols = 0; char *zRenames = 0; char *zColDefs; @@ -9013,7 +9014,7 @@ static int do_meta_command(char *zLine, ShellState *p){ import_fail: sqlite3_free(zCreate); sqlite3_free(zSql); - sqlite3_free(zSchema); + sqlite3_free(zFullTabName); import_cleanup(&sCtx); rc = 1; goto meta_command_exit; @@ -9046,7 +9047,7 @@ static int do_meta_command(char *zLine, ShellState *p){ import_cleanup(&sCtx); shell_out_of_memory(); } - sqlite3_snprintf(nByte+20, zSql, "INSERT INTO %s VALUES(?", zSchema); + sqlite3_snprintf(nByte+20, zSql, "INSERT INTO %s VALUES(?", zFullTabName); j = strlen30(zSql); for(i=1; idb); if( needCommit ) sqlite3_exec(p->db, "BEGIN", 0, 0, 0); do{ From c5a55db75d92aeefbbf368c72f6df2aab180aea4 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 7 Mar 2022 01:29:36 +0000 Subject: [PATCH 52/75] Optimizations to sqlite3BtreeIndexMoveto() avoid unnecessary comparisons if the cursor is already near the end of the table and is not moving far. This case is more common that you would expect. The optimization saves almost 4 million CPU cycles. FossilOrigin-Name: 0057bbb508e7662b0da19e981c07ef10236cb616bda952745de3aa2d1c286289 --- manifest | 14 +++---- manifest.uuid | 2 +- src/btree.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 106 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 1a7976cec9..bca29d167e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Disentangle\svariable\suse\sin\slast\scheckin -D 2022-03-07T00:14:52.499 +C Optimizations\sto\ssqlite3BtreeIndexMoveto()\savoid\sunnecessary\scomparisons\sif\nthe\scursor\sis\salready\snear\sthe\send\sof\sthe\stable\sand\sis\snot\smoving\sfar.\s\sThis\ncase\sis\smore\scommon\sthat\syou\swould\sexpect.\s\sThe\soptimization\ssaves\salmost\n4\smillion\sCPU\scycles. +D 2022-03-07T01:29:36.578 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -492,7 +492,7 @@ F src/auth.c f4fa91b6a90bbc8e0d0f738aa284551739c9543a367071f55574681e0f24f8cf F src/backup.c a2891172438e385fdbe97c11c9745676bec54f518d4447090af97189fd8e52d7 F src/bitvec.c 7c849aac407230278445cb069bebc5f89bf2ddd87c5ed9459b070a9175707b3d F src/btmutex.c 8acc2f464ee76324bf13310df5692a262b801808984c1b79defb2503bbafadb6 -F src/btree.c 3a925b8542eb7f2a00c1919d6dbcd252b1d2781fbc43228b33dcc03fe6cd772a +F src/btree.c dff405cefec5a5573ca9254a6fdefcadf64fa884b575cc15cd4bb23c13b35516 F src/btree.h 74d64b8f28cfa4a894d14d4ed64fa432cd697b98b61708d4351482ae15913e22 F src/btreeInt.h 1ca477727c5f420a8321208dc5b14d93cb46cec8f941bc49318feb0e00bc961f F src/build.c 9891c2160886cf7e344d7e8f1f7177f9612916c7c67ffeacd64cb34a92d387a8 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P bf9d1278846dce9255f9a11ddfc5dfac1acea2eadcb20816a19d59f7bccaec0f -R 496fa8a876df6daf353669fc02e2fc4c -U larrybr -Z 013bf70ae42a0fa3c911efc40e5d2bba +P 4c3a02600f10926da1f88ddbd457bb1486e6e02dee366b5cfc89e498a10daa6f +R d2948dadaedd31df84454fee7cf7f673 +U drh +Z 0ebffd417ef0adafd19b87cdd03ffdc7 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 209490bd9e..5424375871 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4c3a02600f10926da1f88ddbd457bb1486e6e02dee366b5cfc89e498a10daa6f \ No newline at end of file +0057bbb508e7662b0da19e981c07ef10236cb616bda952745de3aa2d1c286289 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index ea31738c7d..0acfad38c0 100644 --- a/src/btree.c +++ b/src/btree.c @@ -5698,6 +5698,69 @@ moveto_table_finish: return rc; } +/* +** Compare the "idx"-th cell on the page the cursor pCur is currently +** pointing to to pIdxKey using xRecordCompare. Return negative or +** zero if the cell is less than or equal pIdxKey. Return positive +** if unknown. +** +** Return value negative: Cell at pCur[idx] less than pIdxKey +** +** Return value is zero: Cell at pCur[idx] equals pIdxKey +** +** Return value positive: Nothing is known about the relationship +** of the cell at pCur[idx] and pIdxKey. +** +** This routine is part of an optimization. It is always safe to return +** a positive value as that will cause the optimization to be skipped. +*/ +static int indexCellCompare( + BtCursor *pCur, + int idx, + UnpackedRecord *pIdxKey, + RecordCompare xRecordCompare +){ + MemPage *pPage = pCur->pPage; + int c; + int nCell; /* Size of the pCell cell in bytes */ + u8 *pCell = findCellPastPtr(pPage, idx); + + nCell = pCell[0]; + if( nCell<=pPage->max1bytePayload ){ + /* This branch runs if the record-size field of the cell is a + ** single byte varint and the record fits entirely on the main + ** b-tree page. */ + testcase( pCell+nCell+1==pPage->aDataEnd ); + c = xRecordCompare(nCell, (void*)&pCell[1], pIdxKey); + }else if( !(pCell[1] & 0x80) + && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal + ){ + /* The record-size field is a 2 byte varint and the record + ** fits entirely on the main b-tree page. */ + testcase( pCell+nCell+2==pPage->aDataEnd ); + c = xRecordCompare(nCell, (void*)&pCell[2], pIdxKey); + }else{ + /* If the record extends into overflow pages, do not attempt + ** the optimization. */ + c = 99; + } + return c; +} + +/* +** Return true (non-zero) if pCur is current pointing to the last +** page of a table. +*/ +static int cursorOnLastPage(BtCursor *pCur){ + int i; + assert( pCur->eState==CURSOR_VALID ); + for(i=0; iiPage; i++){ + MemPage *pPage = pCur->apPage[i]; + if( pCur->aiIdx[i]nCell ) return 0; + } + return 1; +} + /* Move the cursor so that it points to an entry in an index table ** near the key pIdxKey. Return a success code. ** @@ -5748,6 +5811,36 @@ int sqlite3BtreeIndexMoveto( || pIdxKey->default_rc==-1 ); + + /* Check to see if we can skip a lot of work. Two cases: + ** + ** (1) If the cursor is already pointing to the very last cell + ** in the table and the pIdxKey search key is greater than or + ** equal to that last cell, then no movement is required. + ** + ** (2) If the cursor is on the last page of the table and the first + ** cell on that last page is less than or equal to the pIdxKey + ** search key, then we can start the search on the current page + ** without needing to go back to root. + */ + if( pCur->eState==CURSOR_VALID + && pCur->pPage->leaf + && cursorOnLastPage(pCur) + ){ + int c; + if( pCur->ix==pCur->pPage->nCell-1 + && (c = indexCellCompare(pCur, pCur->ix, pIdxKey, xRecordCompare))<=0 + ){ + *pRes = c; + return SQLITE_OK; /* Cursor already pointing at the correct spot */ + } + if( pCur->iPage>0 + && (c = indexCellCompare(pCur, 0, pIdxKey, xRecordCompare))<=0 + ){ + goto bypass_moveto_root; /* Start search on the current page */ + } + } + rc = moveToRoot(pCur); if( rc ){ if( rc==SQLITE_EMPTY ){ @@ -5757,12 +5850,14 @@ int sqlite3BtreeIndexMoveto( } return rc; } + +bypass_moveto_root: assert( pCur->pPage ); assert( pCur->pPage->isInit ); assert( pCur->eState==CURSOR_VALID ); assert( pCur->pPage->nCell > 0 ); - assert( pCur->iPage==0 || pCur->apPage[0]->intKey==pCur->curIntKey ); - assert( pCur->curIntKey || pIdxKey ); + assert( pCur->curIntKey==0 ); + assert( pIdxKey!=0 ); for(;;){ int lwr, upr, idx, c; Pgno chldPg; @@ -5776,7 +5871,7 @@ int sqlite3BtreeIndexMoveto( ** be the right kind (index or table) of b-tree page. Otherwise ** a moveToChild() or moveToRoot() call would have detected corruption. */ assert( pPage->nCell>0 ); - assert( pPage->intKey==(pIdxKey==0) ); + assert( pPage->intKey==0 ); lwr = 0; upr = pPage->nCell-1; idx = upr>>1; /* idx = (lwr+upr)/2; */ From 6d6ea42a25ce8d0f31bc1ff10be0c0767607b8fa Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 7 Mar 2022 14:51:29 +0000 Subject: [PATCH 53/75] Fix the code generated for vector IN operator constraints on virtual tables so that they work even if the "omit" field in the sqlite3_index_info object is off. This has apparently never worked correctly before. Presumably, nobody has ever before written a virtual table that can use vector IN operator constraints and that relies on bytecode to double-check the constraints. Test cases in TH3. Problem discovered by dbsqlfuzz cab8e26194a40147627094f3c6849c0a7b1e0310. FossilOrigin-Name: 21b656572d066b640ff5774205a4f0db13e1b08a35d0fd484da9130e759b0c26 --- manifest | 12 ++++----- manifest.uuid | 2 +- src/wherecode.c | 67 ++++++++++++++++++++++++++----------------------- 3 files changed, 42 insertions(+), 39 deletions(-) diff --git a/manifest b/manifest index bca29d167e..c8bcb4a680 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Optimizations\sto\ssqlite3BtreeIndexMoveto()\savoid\sunnecessary\scomparisons\sif\nthe\scursor\sis\salready\snear\sthe\send\sof\sthe\stable\sand\sis\snot\smoving\sfar.\s\sThis\ncase\sis\smore\scommon\sthat\syou\swould\sexpect.\s\sThe\soptimization\ssaves\salmost\n4\smillion\sCPU\scycles. -D 2022-03-07T01:29:36.578 +C Fix\sthe\scode\sgenerated\sfor\svector\sIN\soperator\sconstraints\son\svirtual\stables\nso\sthat\sthey\swork\seven\sif\sthe\s"omit"\sfield\sin\sthe\ssqlite3_index_info\sobject\nis\soff.\s\sThis\shas\sapparently\snever\sworked\scorrectly\sbefore.\s\sPresumably,\snobody\nhas\sever\sbefore\swritten\sa\svirtual\stable\sthat\scan\suse\svector\sIN\soperator\nconstraints\sand\sthat\srelies\son\sbytecode\sto\sdouble-check\sthe\sconstraints.\nTest\scases\sin\sTH3.\s\sProblem\sdiscovered\sby\ndbsqlfuzz\scab8e26194a40147627094f3c6849c0a7b1e0310. +D 2022-03-07T14:51:29.714 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -641,7 +641,7 @@ F src/wal.h c3aa7825bfa2fe0d85bef2db94655f99870a285778baa36307c0a16da32b226a F src/walker.c f890a3298418d7cba3b69b8803594fdc484ea241206a8dfa99db6dd36f8cbb3b F src/where.c 1471be86b34b8ce328c6c68d7e2ee667c7f801ddf83ff179bc5936700cf43aa7 F src/whereInt.h 15d2975c3b4c193c78c26674400a840da8647fe1777ae3b026e2d15937b38a03 -F src/wherecode.c e0f6be39a0938008a20f1b1a528225f2364c459e88603799c417247a4ea3836c +F src/wherecode.c 555f598a9ddad81761f084710fdb4f8733fe31bc14cd6b19f8ca4274a7eaa04c F src/whereexpr.c 2a71f5491798460c9590317329234d332d9eb1717cba4f3403122189a75c465e F src/window.c dfaec4abc6012cbc18e4a202ca3a5d5a0efcc4011d86a06d882ddaab8aedee4d F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 4c3a02600f10926da1f88ddbd457bb1486e6e02dee366b5cfc89e498a10daa6f -R d2948dadaedd31df84454fee7cf7f673 +P 0057bbb508e7662b0da19e981c07ef10236cb616bda952745de3aa2d1c286289 +R 6a4ed095521aa4ba12dc4960a634c639 U drh -Z 0ebffd417ef0adafd19b87cdd03ffdc7 +Z 1e4d19ee992d5d61115bab33a2b8aaba # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 5424375871..4ca5a31a2a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0057bbb508e7662b0da19e981c07ef10236cb616bda952745de3aa2d1c286289 \ No newline at end of file +21b656572d066b640ff5774205a4f0db13e1b08a35d0fd484da9130e759b0c26 \ No newline at end of file diff --git a/src/wherecode.c b/src/wherecode.c index d1f0635e7a..ce0279a8f6 100644 --- a/src/wherecode.c +++ b/src/wherecode.c @@ -1533,7 +1533,6 @@ Bitmask sqlite3WhereCodeOneLoopStart( int iReg; /* P3 Value for OP_VFilter */ int addrNotFound; int nConstraint = pLoop->nLTerm; - int iIn; /* Counter for IN constraints */ iReg = sqlite3GetTempRange(pParse, nConstraint+2); addrNotFound = pLevel->addrBrk; @@ -1579,50 +1578,54 @@ Bitmask sqlite3WhereCodeOneLoopStart( pLevel->op = pWInfo->eOnePass ? OP_Noop : OP_VNext; pLevel->p2 = sqlite3VdbeCurrentAddr(v); assert( (pLoop->wsFlags & WHERE_MULTI_OR)==0 ); - if( pLoop->wsFlags & WHERE_IN_ABLE ){ - iIn = pLevel->u.in.nIn; - }else{ - iIn = 0; - } - for(j=nConstraint-1; j>=0; j--){ - int bIn; /* True to generate byte code to loop over RHS IN values */ + + for(j=0; jaLTerm[j]; - if( (pTerm->eOperator & WO_IN)!=0 - && (SMASKBIT32(j) & pLoop->u.vtab.mHandleIn)==0 - ){ - bIn = 1; - }else{ - bIn = 0; - } - if( bIn ) iIn--; if( j<16 && (pLoop->u.vtab.omitMask>>j)&1 ){ disableTerm(pLevel, pTerm); - }else if( bIn && sqlite3ExprVectorSize(pTerm->pExpr->pLeft)==1 ){ + continue; + } + if( (pTerm->eOperator & WO_IN)!=0 + && (SMASKBIT32(j) & pLoop->u.vtab.mHandleIn)==0 + && !db->mallocFailed + ){ Expr *pCompare; /* The comparison operator */ Expr *pRight; /* RHS of the comparison */ VdbeOp *pOp; /* Opcode to access the value of the IN constraint */ + int iIn; /* IN loop corresponding to the j-th constraint */ /* Reload the constraint value into reg[iReg+j+2]. The same value ** was loaded into the same register prior to the OP_VFilter, but ** the xFilter implementation might have changed the datatype or - ** encoding of the value in the register, so it *must* be reloaded. */ - assert( pLevel->u.in.aInLoop!=0 || db->mallocFailed ); - if( !db->mallocFailed ){ - assert( iIn>=0 && iInu.in.nIn ); + ** encoding of the value in the register, so it *must* be reloaded. + */ + for(iIn=0; ALWAYS(iInu.in.nIn); iIn++){ pOp = sqlite3VdbeGetOp(v, pLevel->u.in.aInLoop[iIn].addrInTop); - assert( pOp->opcode==OP_Column || pOp->opcode==OP_Rowid ); - assert( pOp->opcode!=OP_Column || pOp->p3==iReg+j+2 ); - assert( pOp->opcode!=OP_Rowid || pOp->p2==iReg+j+2 ); - testcase( pOp->opcode==OP_Rowid ); - sqlite3VdbeAddOp3(v, pOp->opcode, pOp->p1, pOp->p2, pOp->p3); + if( (pOp->opcode==OP_Column && pOp->p3==iReg+j+2) + || (pOp->opcode==OP_Rowid && pOp->p2==iReg+j+2) + ){ + testcase( pOp->opcode==OP_Rowid ); + sqlite3VdbeAddOp3(v, pOp->opcode, pOp->p1, pOp->p2, pOp->p3); + break; + } } /* Generate code that will continue to the next row if - ** the IN constraint is not satisfied */ + ** the IN constraint is not satisfied + */ pCompare = sqlite3PExpr(pParse, TK_EQ, 0, 0); - assert( pCompare!=0 || db->mallocFailed ); - if( pCompare ){ - pCompare->pLeft = pTerm->pExpr->pLeft; + if( !db->mallocFailed ){ + int iFld = pTerm->u.x.iField; + Expr *pLeft = pTerm->pExpr->pLeft; + assert( pLeft!=0 ); + if( iFld>0 ){ + assert( pLeft->op==TK_VECTOR ); + assert( ExprUseXList(pLeft) ); + assert( iFld<=pLeft->x.pList->nExpr ); + pCompare->pLeft = pLeft->x.pList->a[iFld-1].pExpr; + }else{ + pCompare->pLeft = pLeft; + } pCompare->pRight = pRight = sqlite3Expr(db, TK_REGISTER, 0); if( pRight ){ pRight->iTable = iReg+j+2; @@ -1631,11 +1634,11 @@ Bitmask sqlite3WhereCodeOneLoopStart( ); } pCompare->pLeft = 0; - sqlite3ExprDelete(db, pCompare); } + sqlite3ExprDelete(db, pCompare); } } - assert( iIn==0 || db->mallocFailed ); + /* These registers need to be preserved in case there is an IN operator ** loop. So we could deallocate the registers here (and potentially ** reuse them later) if (pLoop->wsFlags & WHERE_IN_ABLE)==0. But it seems From 4c460bbffdd0e51fad6b1ff61a6e15ecc795a748 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 7 Mar 2022 16:22:31 +0000 Subject: [PATCH 54/75] Do not allocate new Trigger objects in the parser following a syntax error, to avoid violating invariants associated with Expr nodes. See [forum:/forumpost/2024e94071ef1531|forum thread 2024e94071ef1531] for more information. FossilOrigin-Name: 5e0ed49b3d739d292f5df3e498449ae8f4357cbb83394181fb34f98ed8372707 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/trigger.c | 1 + test/trigger1.test | 11 +++++++++++ 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index c8bcb4a680..0dcaefc452 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\scode\sgenerated\sfor\svector\sIN\soperator\sconstraints\son\svirtual\stables\nso\sthat\sthey\swork\seven\sif\sthe\s"omit"\sfield\sin\sthe\ssqlite3_index_info\sobject\nis\soff.\s\sThis\shas\sapparently\snever\sworked\scorrectly\sbefore.\s\sPresumably,\snobody\nhas\sever\sbefore\swritten\sa\svirtual\stable\sthat\scan\suse\svector\sIN\soperator\nconstraints\sand\sthat\srelies\son\sbytecode\sto\sdouble-check\sthe\sconstraints.\nTest\scases\sin\sTH3.\s\sProblem\sdiscovered\sby\ndbsqlfuzz\scab8e26194a40147627094f3c6849c0a7b1e0310. -D 2022-03-07T14:51:29.714 +C Do\snot\sallocate\snew\sTrigger\sobjects\sin\sthe\sparser\sfollowing\sa\ssyntax\serror,\nto\savoid\sviolating\sinvariants\sassociated\swith\sExpr\snodes.\s\sSee\n[forum:/forumpost/2024e94071ef1531|forum\sthread\s2024e94071ef1531]\sfor\smore\ninformation. +D 2022-03-07T16:22:31.035 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -618,7 +618,7 @@ F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/threads.c 4ae07fa022a3dc7c5beb373cf744a85d3c5c6c3c F src/tokenize.c 6661a9fa660ecbd3ac0df1acd2ec788b3a8122b4316022bcdaf476ea6754a8de F src/treeview.c a84b57d15e46007d8b1ae249344b3f0b7f3c62def908b98baaa54935a57c8476 -F src/trigger.c 19fc6fe696a2409b04496df1ff044e6a942dad6ed3b6e897b1c9093b88cc2c62 +F src/trigger.c 5fc3cde35cc4de510be68bb2db4dcff0ce0e1625f43e28a0920be9a6f010cd3f F src/update.c f875b0d59da5c3055a0b2ac20560e1650229c6787e78de5e9836267b5cbb8359 F src/upsert.c 8789047a8f0a601ea42fa0256d1ba3190c13746b6ba940fe2d25643a7e991937 F src/utf.c ee39565f0843775cc2c81135751ddd93eceb91a673ea2c57f61c76f288b041a0 @@ -1640,7 +1640,7 @@ F test/trans.test 45f6f9ab6f66a7b5744f1caac06b558f95da62501916906cf55586a896f9f4 F test/trans2.test 62bd045bfc7a1c14c5ba83ba64d21ade31583f76 F test/trans3.test 91a100e5412b488e22a655fe423a14c26403ab94 F test/transitive1.test f8ee983600b33d167da1885657f064aec404e1c0d0bc8765fdf163f4c749237a -F test/trigger1.test d30cd09ae8ac365a088f09daba583cc5c0b8fc7d4e1d70809d0b4be3bf6ae2ab +F test/trigger1.test 02cc64dc98278816c1c1ed8e472e18db8edbad88f37018bf46223e9614831963 F test/trigger2.test 6e35bd7321c49e63d540aee980eb95dec63e1d1caca175224101045bcc80871f F test/trigger3.test aa640bb2bbb03edd5ff69c055117ea088f121945 F test/trigger4.test 74700b76ebf3947b2f7a92405141eb2cf2a5d359 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 0057bbb508e7662b0da19e981c07ef10236cb616bda952745de3aa2d1c286289 -R 6a4ed095521aa4ba12dc4960a634c639 +P 21b656572d066b640ff5774205a4f0db13e1b08a35d0fd484da9130e759b0c26 +R 28d58384364b7a2f3c7b557082919a43 U drh -Z 1e4d19ee992d5d61115bab33a2b8aaba +Z 79d608a0bfa4ae7a72b8e52e1aaf2711 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 4ca5a31a2a..89467f2511 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -21b656572d066b640ff5774205a4f0db13e1b08a35d0fd484da9130e759b0c26 \ No newline at end of file +5e0ed49b3d739d292f5df3e498449ae8f4357cbb83394181fb34f98ed8372707 \ No newline at end of file diff --git a/src/trigger.c b/src/trigger.c index 8f096a05c6..5df6b0c0bc 100644 --- a/src/trigger.c +++ b/src/trigger.c @@ -446,6 +446,7 @@ static TriggerStep *triggerStepAllocate( sqlite3 *db = pParse->db; TriggerStep *pTriggerStep; + if( pParse->nErr ) return 0; pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep) + pName->n + 1); if( pTriggerStep ){ char *z = (char*)&pTriggerStep[1]; diff --git a/test/trigger1.test b/test/trigger1.test index 456e983381..6de121fa9c 100644 --- a/test/trigger1.test +++ b/test/trigger1.test @@ -827,4 +827,15 @@ do_execsql_test trigger1-22.10 { SELECT a, CASE WHEN typeof(b)='text' THEN quote(b) ELSE '' END, '|' FROM t1; } {1 | 2 'X' | 3 'Z' |} +# 2022-03-06 https://sqlite.org/forum/forumpost/2024e94071 +# Harmless assertion fault following a syntax error. +# +reset_db +do_catchsql_test trigger1-23.1 { + CREATE TABLE t1(a INT); + CREATE TRIGGER r1 AFTER INSERT ON t1 BEGIN + INSERT INTO t1 SELECT e_master LIMIT 1,#1; + END; +} {1 {near "#1": syntax error}} + finish_test From 42bb09c41289e9ed4196643c97f9fb458826503c Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 7 Mar 2022 17:19:40 +0000 Subject: [PATCH 55/75] In the stay-on-last-page optimization for sqlite3BtreeIndexMoveto() (check-in [0057bbb508e7662b] about 16 hours ago), be sure to clear the BTCF_ValidOvfl flag, since the overflow cache is invalidated by the search on the last page. OSSFuzz issue 45329. FossilOrigin-Name: 0021bebc162e001b788786703ce634e7b8fcd3976f7047a5956e82140791e765 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/btree.c | 1 + test/btree01.test | 21 +++++++++++++++++++++ 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 0dcaefc452..4d2ba895f9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Do\snot\sallocate\snew\sTrigger\sobjects\sin\sthe\sparser\sfollowing\sa\ssyntax\serror,\nto\savoid\sviolating\sinvariants\sassociated\swith\sExpr\snodes.\s\sSee\n[forum:/forumpost/2024e94071ef1531|forum\sthread\s2024e94071ef1531]\sfor\smore\ninformation. -D 2022-03-07T16:22:31.035 +C In\sthe\sstay-on-last-page\soptimization\s\sfor\ssqlite3BtreeIndexMoveto()\n(check-in\s[0057bbb508e7662b]\sabout\s16\shours\sago),\sbe\ssure\nto\sclear\sthe\sBTCF_ValidOvfl\sflag,\ssince\sthe\soverflow\scache\sis\sinvalidated\nby\sthe\ssearch\son\sthe\slast\spage.\s\sOSSFuzz\sissue\s45329. +D 2022-03-07T17:19:40.649 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -492,7 +492,7 @@ F src/auth.c f4fa91b6a90bbc8e0d0f738aa284551739c9543a367071f55574681e0f24f8cf F src/backup.c a2891172438e385fdbe97c11c9745676bec54f518d4447090af97189fd8e52d7 F src/bitvec.c 7c849aac407230278445cb069bebc5f89bf2ddd87c5ed9459b070a9175707b3d F src/btmutex.c 8acc2f464ee76324bf13310df5692a262b801808984c1b79defb2503bbafadb6 -F src/btree.c dff405cefec5a5573ca9254a6fdefcadf64fa884b575cc15cd4bb23c13b35516 +F src/btree.c 8abb72f4b4cd362eca177332da67c6f7e55dbfb1f0cb4c1df153a90e6ee2027d F src/btree.h 74d64b8f28cfa4a894d14d4ed64fa432cd697b98b61708d4351482ae15913e22 F src/btreeInt.h 1ca477727c5f420a8321208dc5b14d93cb46cec8f941bc49318feb0e00bc961f F src/build.c 9891c2160886cf7e344d7e8f1f7177f9612916c7c67ffeacd64cb34a92d387a8 @@ -751,7 +751,7 @@ F test/boundary3.tcl 23361e108a125dca9c4080c2feb884fe54d69243 F test/boundary3.test 56ef82096b4329aca2be74fa1e2b0f762ea0eb45 F test/boundary4.tcl 0bb4b1a94f4fc5ae59b79b9a2b7a140c405e2983 F test/boundary4.test 89e02fa66397b8a325d5eb102b5806f961f8ec4b -F test/btree01.test e08b3613540145b353f20c81cb18ead54ff12e0f +F test/btree01.test 8e1ba2f857608ad8fbf9fcc11f33b15b083711162f9566b0a21fb573f2008593 F test/btree02.test 7555a5440453d900410160a52554fe6478af4faf53098f7235f1f443d5a1d6cc F test/btreefault.test c2bcb542685eea44621275cfedbd8a13f65201e3 F test/busy.test 510dc6daaad18bcbbc085bcc6217d6dc418def5e73f72ce1475eea0cb7834727 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 21b656572d066b640ff5774205a4f0db13e1b08a35d0fd484da9130e759b0c26 -R 28d58384364b7a2f3c7b557082919a43 +P 5e0ed49b3d739d292f5df3e498449ae8f4357cbb83394181fb34f98ed8372707 +R f716eefd212005e4b7e38ae3bd823c39 U drh -Z 79d608a0bfa4ae7a72b8e52e1aaf2711 +Z e8342be86d82f1f58876f0baf6aae742 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 89467f2511..9f01f7ac66 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5e0ed49b3d739d292f5df3e498449ae8f4357cbb83394181fb34f98ed8372707 \ No newline at end of file +0021bebc162e001b788786703ce634e7b8fcd3976f7047a5956e82140791e765 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 0acfad38c0..d6aec1af3f 100644 --- a/src/btree.c +++ b/src/btree.c @@ -5837,6 +5837,7 @@ int sqlite3BtreeIndexMoveto( if( pCur->iPage>0 && (c = indexCellCompare(pCur, 0, pIdxKey, xRecordCompare))<=0 ){ + pCur->curFlags &= ~BTCF_ValidOvfl; goto bypass_moveto_root; /* Start search on the current page */ } } diff --git a/test/btree01.test b/test/btree01.test index 25f2c6897b..9c309760d5 100644 --- a/test/btree01.test +++ b/test/btree01.test @@ -129,4 +129,25 @@ for {set i 1} {$i<=31} {incr i} { } {ok} } +# 2022-03-06 OSSFuzz issue 45329 +# An assertion fault due to the failure to clear a flag in an optimization +# committed last night. +# +# When the stay-on-last page optimization of sqlite3BtreeIndexMoveto() is +# invoked, it needs to clear the BTCF_ValidOvfl flag. +# +db close +sqlite3 db :memory: +do_execsql_test btree01-2.1 { + PRAGMA page_size=1024; + CREATE TABLE t1(a INT PRIMARY KEY, b BLOB, c INT) WITHOUT ROWID; + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<100) + INSERT INTO t1(a,b,c) SELECT x*2, zeroblob(100), x FROM c; + UPDATE t1 SET b=zeroblob(1000) WHERE a=198; + CREATE TABLE t2(x INTEGER PRIMARY KEY, y INT); + INSERT INTO t2(y) VALUES(198),(187),(100); + SELECT y, c FROM t2 LEFT JOIN t1 ON y=a ORDER BY x; +} {198 99 187 {} 100 50} + + finish_test From ec9b622fbf47ec01765cab43df087dfdc4c7720a Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 7 Mar 2022 18:32:08 +0000 Subject: [PATCH 56/75] Disable an assert in moveToRoot() when the database is corrupt. [forum:/forumpost/e9a176b7bd|Forum post e9a176b7bd]. FossilOrigin-Name: ae464a18d74bf44fc95bc335e75e6a57dc974f6d6a3d603133594039fb589af2 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/btree.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 4d2ba895f9..e58b19eca1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C In\sthe\sstay-on-last-page\soptimization\s\sfor\ssqlite3BtreeIndexMoveto()\n(check-in\s[0057bbb508e7662b]\sabout\s16\shours\sago),\sbe\ssure\nto\sclear\sthe\sBTCF_ValidOvfl\sflag,\ssince\sthe\soverflow\scache\sis\sinvalidated\nby\sthe\ssearch\son\sthe\slast\spage.\s\sOSSFuzz\sissue\s45329. -D 2022-03-07T17:19:40.649 +C Disable\san\sassert\sin\smoveToRoot()\swhen\sthe\sdatabase\sis\scorrupt.\n[forum:/forumpost/e9a176b7bd|Forum\spost\se9a176b7bd]. +D 2022-03-07T18:32:08.024 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -492,7 +492,7 @@ F src/auth.c f4fa91b6a90bbc8e0d0f738aa284551739c9543a367071f55574681e0f24f8cf F src/backup.c a2891172438e385fdbe97c11c9745676bec54f518d4447090af97189fd8e52d7 F src/bitvec.c 7c849aac407230278445cb069bebc5f89bf2ddd87c5ed9459b070a9175707b3d F src/btmutex.c 8acc2f464ee76324bf13310df5692a262b801808984c1b79defb2503bbafadb6 -F src/btree.c 8abb72f4b4cd362eca177332da67c6f7e55dbfb1f0cb4c1df153a90e6ee2027d +F src/btree.c 1b45f4520b73804ebeb508c0af62859a2637a2488767838f745920f48d97aee8 F src/btree.h 74d64b8f28cfa4a894d14d4ed64fa432cd697b98b61708d4351482ae15913e22 F src/btreeInt.h 1ca477727c5f420a8321208dc5b14d93cb46cec8f941bc49318feb0e00bc961f F src/build.c 9891c2160886cf7e344d7e8f1f7177f9612916c7c67ffeacd64cb34a92d387a8 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 5e0ed49b3d739d292f5df3e498449ae8f4357cbb83394181fb34f98ed8372707 -R f716eefd212005e4b7e38ae3bd823c39 +P 0021bebc162e001b788786703ce634e7b8fcd3976f7047a5956e82140791e765 +R e0b86902d16238577f96cc645b162d8b U drh -Z e8342be86d82f1f58876f0baf6aae742 +Z 57da721f31e60b784724ed26b1739204 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 9f01f7ac66..d7124a64f5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0021bebc162e001b788786703ce634e7b8fcd3976f7047a5956e82140791e765 \ No newline at end of file +ae464a18d74bf44fc95bc335e75e6a57dc974f6d6a3d603133594039fb589af2 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index d6aec1af3f..95170a1513 100644 --- a/src/btree.c +++ b/src/btree.c @@ -5377,7 +5377,7 @@ static int moveToRoot(BtCursor *pCur){ pCur->curIntKey = pCur->pPage->intKey; } pRoot = pCur->pPage; - assert( pRoot->pgno==pCur->pgnoRoot ); + assert( pRoot->pgno==pCur->pgnoRoot || CORRUPT_DB ); /* If pCur->pKeyInfo is not NULL, then the caller that opened this cursor ** expected to open it on an index b-tree. Otherwise, if pKeyInfo is From e684ac6f12a0106dc75d7e319e5e08471c0eb163 Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 8 Mar 2022 13:59:46 +0000 Subject: [PATCH 57/75] Fix compiler warnings. FossilOrigin-Name: 5e30c6ea707f9d381127e8b2bb59e0b39bc00997da2c14d32a0e302d0121203b --- ext/misc/zipfile.c | 4 ++++ manifest | 26 +++++++++++++------------- manifest.uuid | 2 +- src/btree.c | 2 +- src/dbpage.c | 2 +- src/global.c | 3 +++ src/json.c | 2 +- src/shell.c.in | 3 ++- src/treeview.c | 4 ++-- src/vdbeaux.c | 2 +- 10 files changed, 29 insertions(+), 21 deletions(-) diff --git a/ext/misc/zipfile.c b/ext/misc/zipfile.c index db2aa78cc7..d3259fbf41 100644 --- a/ext/misc/zipfile.c +++ b/ext/misc/zipfile.c @@ -2170,6 +2170,10 @@ static int zipfileRegister(sqlite3 *db){ zipfileRollback, /* xRollback */ zipfileFindFunction, /* xFindMethod */ 0, /* xRename */ + 0, /* xSavepoint */ + 0, /* xRelease */ + 0, /* xRollback */ + 0 /* xShadowName */ }; int rc = sqlite3_create_module(db, "zipfile" , &zipfileModule, 0); diff --git a/manifest b/manifest index e58b19eca1..644ca00073 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Disable\san\sassert\sin\smoveToRoot()\swhen\sthe\sdatabase\sis\scorrupt.\n[forum:/forumpost/e9a176b7bd|Forum\spost\se9a176b7bd]. -D 2022-03-07T18:32:08.024 +C Fix\scompiler\swarnings. +D 2022-03-08T13:59:46.057 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -339,7 +339,7 @@ F ext/misc/vfsstat.c 474d08efc697b8eba300082cb1eb74a5f0f3df31ed257db1cb07e72ab0e F ext/misc/vtablog.c 5538acd0c8ddaae372331bee11608d76973436b77d6a91e8635cfc9432fba5ae F ext/misc/vtshim.c 1976e6dd68dd0d64508c91a6dfab8e75f8aaf6cd F ext/misc/wholenumber.c a838d1bea913c514ff316c69695efbb49ea3b8cb37d22afc57f73b6b010b4546 -F ext/misc/zipfile.c 238ccb990ed45a74e24d0fbb449d7752a568c2b7c1d5b255d451f11703ced592 +F ext/misc/zipfile.c c4e2d12b3544a380ce171a143dc2fdfe2fc76ae424ed4cf43ba4f74c6d0db444 F ext/misc/zorder.c b0ff58fa643afa1d846786d51ea8d5c4b6b35aa0254ab5a82617db92f3adda64 F ext/rbu/rbu.c 801450b24eaf14440d8fd20385aacc751d5c9d6123398df41b1b5aa804bf4ce8 F ext/rbu/rbu1.test c62904bd9526dcdc3496a21199aaf14ae191bbadbf67f076bf16be6b3f2115c2 @@ -492,7 +492,7 @@ F src/auth.c f4fa91b6a90bbc8e0d0f738aa284551739c9543a367071f55574681e0f24f8cf F src/backup.c a2891172438e385fdbe97c11c9745676bec54f518d4447090af97189fd8e52d7 F src/bitvec.c 7c849aac407230278445cb069bebc5f89bf2ddd87c5ed9459b070a9175707b3d F src/btmutex.c 8acc2f464ee76324bf13310df5692a262b801808984c1b79defb2503bbafadb6 -F src/btree.c 1b45f4520b73804ebeb508c0af62859a2637a2488767838f745920f48d97aee8 +F src/btree.c f00f7323b3e7d2bf5192055b4a325a5b813686d424b59815e725690d2c215451 F src/btree.h 74d64b8f28cfa4a894d14d4ed64fa432cd697b98b61708d4351482ae15913e22 F src/btreeInt.h 1ca477727c5f420a8321208dc5b14d93cb46cec8f941bc49318feb0e00bc961f F src/build.c 9891c2160886cf7e344d7e8f1f7177f9612916c7c67ffeacd64cb34a92d387a8 @@ -500,20 +500,20 @@ F src/callback.c 4c19af69835787bfe790ac560f3071a824eb629f34e41f97b52ce5235c77de1 F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e F src/ctime.c 2cce39df1a13e05b7633e6d21b651f21492471f991dd7b323a4ee4e7b7f0b7f1 F src/date.c 15082566229d4b1e5f24fdb490bf9bcc68824b911d70e3573ef075a1b9e2d26f -F src/dbpage.c 8a01e865bf8bc6d7b1844b4314443a6436c07c3efe1d488ed89e81719047833a +F src/dbpage.c 74cf60d209adbf00a5687fb777fd66c450e7008dcf9e97f446b543c13fe841c4 F src/dbstat.c 861e08690fcb0f2ee1165eff0060ea8d4f3e2ea10f80dab7d32ad70443a6ff2d F src/delete.c b5f1716b4d723db48254ee0f896e362cd029e865e05414139ea7f539f3884e1d F src/expr.c 3cdb00b6c15f815c94836e7b4474b675155d1279e64804f6ab5816188a9b05b6 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c 06e4ac33031b02dde7130c12e79cddf4dc5cfa72b23d8e63a3c26878fc9c1d3c F src/func.c a3407a6fbb0d4088d8d502e46f0ace63e0aeae7467ae23a9ca9815bbf9239761 -F src/global.c a3daa18a1696aadd94f18d37cbbdebf0bbdb827b8397a534f021cd56c15cd0f9 +F src/global.c 75deb064a71e1db60c8972a660a84f4e6d805c8f0463299a18e30ea527f4a650 F src/hash.c 8d7dda241d0ebdafb6ffdeda3149a412d7df75102cecfc1021c98d6219823b19 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h cb1d7e3e1ed94b7aa6fde95ae2c2daccc3df826be26fc9ed7fd90d1750ae6144 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/insert.c 9fbf8704562fe17e442c16b7f60d3d91101ea69fc45c2bce96ee6cb982e86d2f -F src/json.c 225b00422112ecd7094a555f3ace16b25d7d5894062b823269ed03899907c2a2 +F src/json.c 24fcd7f5f9080b04b89722c343010d390f85e55b2ab560046cb567c9dd640f62 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c aa919a6a7884f8b34d7b791841b24d14b1b0ab43f45b3940f4851043b2855c0c F src/main.c 0840cee6984034c7e73cc747a1562c7eaed4673694bf20b00980aaa0672c0405 @@ -553,7 +553,7 @@ F src/random.c 097dc8b31b8fba5a9aca1697aeb9fd82078ec91be734c16bffda620ced7ab83c F src/resolve.c ea935b87d6fb36c78b70cdc7b28561dc8f33f2ef37048389549c7b5ef9b0ba5e F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92 F src/select.c 4890a3cfee0bc60ff231c3a44db37968859ab0be156983dbcc0c096109832cdd -F src/shell.c.in 0a9c4b9226143365c8aea42eb9a62e055e9fffffc5e4559da5c9dadc0bedaa25 +F src/shell.c.in 69d1e59da4881f096ab47fbd3e6d99794f3e4a43f41fd9e4d2e845c9b8d20fd5 F src/sqlite.h.in e82ac380b307659d0892f502b742f825504e78729f4edaadce946003b9c00816 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h a95cb9ed106e3d39e2118e4dcc15a14faec3fa50d0093425083d340d9dfd96e6 @@ -617,7 +617,7 @@ F src/test_window.c cdae419fdcea5bad6dcd9368c685abdad6deb59e9fc8b84b153de513d394 F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/threads.c 4ae07fa022a3dc7c5beb373cf744a85d3c5c6c3c F src/tokenize.c 6661a9fa660ecbd3ac0df1acd2ec788b3a8122b4316022bcdaf476ea6754a8de -F src/treeview.c a84b57d15e46007d8b1ae249344b3f0b7f3c62def908b98baaa54935a57c8476 +F src/treeview.c 90e133ebe903572ce0e30e866fa76efba3effcf487c9f5ce457870f315f297ea F src/trigger.c 5fc3cde35cc4de510be68bb2db4dcff0ce0e1625f43e28a0920be9a6f010cd3f F src/update.c f875b0d59da5c3055a0b2ac20560e1650229c6787e78de5e9836267b5cbb8359 F src/upsert.c 8789047a8f0a601ea42fa0256d1ba3190c13746b6ba940fe2d25643a7e991937 @@ -628,7 +628,7 @@ F src/vdbe.c b1830c6daf744473a732257652b6431ac18032f508a3e30ff3a1466fe5978559 F src/vdbe.h a1d0e3b934e835e73edd146f2e7c4eadb711b5c9875c18159a57483fd78e550e F src/vdbeInt.h 8dd91427155a38ec06e9ecbde07e33f21bc02e101625191e7613f883e379a363 F src/vdbeapi.c 1c80efbe51118bbecc7279023e75d18edcfa4b3dc441287e1718ee70ad594f58 -F src/vdbeaux.c 280383a4c7fc567e30266cf72bb5031c252bc4cbc1a80d4e1461d77c4bd01547 +F src/vdbeaux.c 2870683ec4a50276a32ebbe32300732dbfc47c3207662bd767c8d612620a9d78 F src/vdbeblob.c 5e61ce31aca17db8fb60395407457a8c1c7fb471dde405e0cd675974611dcfcd F src/vdbemem.c 57fceb4ed6aac960e9517c963dc0668189e8b7c8e6216d257030a2f5e9a583df F src/vdbesort.c 43756031ca7430f7aec3ef904824a7883c4ede783e51f280d99b9b65c0796e35 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 0021bebc162e001b788786703ce634e7b8fcd3976f7047a5956e82140791e765 -R e0b86902d16238577f96cc645b162d8b +P ae464a18d74bf44fc95bc335e75e6a57dc974f6d6a3d603133594039fb589af2 +R 0305e4ee75e40dc455311f12a8983540 U drh -Z 57da721f31e60b784724ed26b1739204 +Z 4d6c360fc29e12f82d08e8ad6a34a2b7 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d7124a64f5..2abefe58b0 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ae464a18d74bf44fc95bc335e75e6a57dc974f6d6a3d603133594039fb589af2 \ No newline at end of file +5e30c6ea707f9d381127e8b2bb59e0b39bc00997da2c14d32a0e302d0121203b \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 95170a1513..e23fcd7187 100644 --- a/src/btree.c +++ b/src/btree.c @@ -214,7 +214,7 @@ static int hasSharedCacheTableLock( int bSeen = 0; for(p=sqliteHashFirst(&pSchema->idxHash); p; p=sqliteHashNext(p)){ Index *pIdx = (Index *)sqliteHashData(p); - if( pIdx->tnum==(int)iRoot ){ + if( pIdx->tnum==iRoot ){ if( bSeen ){ /* Two or more indexes share the same root page. There must ** be imposter tables. So just return true. The assert is not diff --git a/src/dbpage.c b/src/dbpage.c index c4f0b539ef..c74e811926 100644 --- a/src/dbpage.c +++ b/src/dbpage.c @@ -333,7 +333,7 @@ static int dbpageUpdate( goto update_fail; } pBt = pTab->db->aDb[iDb].pBt; - if( pgno<1 || pBt==0 || pgno>(int)sqlite3BtreeLastPage(pBt) ){ + if( pgno<1 || pBt==0 || pgno>sqlite3BtreeLastPage(pBt) ){ zErr = "bad page number"; goto update_fail; } diff --git a/src/global.c b/src/global.c index 6ad3bb4654..c77d0cc201 100644 --- a/src/global.c +++ b/src/global.c @@ -290,6 +290,9 @@ SQLITE_WSD struct Sqlite3Config sqlite3Config = { 0x7ffffffe, /* iOnceResetThreshold */ SQLITE_DEFAULT_SORTERREF_SIZE, /* szSorterRef */ 0, /* iPrngSeed */ +#ifdef SQLITE_DEBUG + {0,0,0,0,0,0} /* aTune */ +#endif }; /* diff --git a/src/json.c b/src/json.c index ab1d32d6a5..243afd5dd4 100644 --- a/src/json.c +++ b/src/json.c @@ -1625,7 +1625,7 @@ static JsonNode *jsonMergePatch( if( pPatch->eType!=JSON_OBJECT ){ return pPatch; } - assert( iTarget>=0 && iTargetnNode ); + assert( iTargetnNode ); pTarget = &pParse->aNode[iTarget]; assert( (pPatch->jnFlags & JNODE_APPEND)==0 ); if( pTarget->eType!=JSON_OBJECT ){ diff --git a/src/shell.c.in b/src/shell.c.in index b0f3b02dc4..45cbb436e0 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -8842,6 +8842,7 @@ static int do_meta_command(char *zLine, ShellState *p){ int eVerbose = 0; /* Larger for more console output */ int nSkip = 0; /* Initial lines to skip */ int useOutputMode = 1; /* Use output mode to determine separators */ + char *zCreate = 0; /* CREATE TABLE statement text */ failIfSafeMode(p, "cannot run .import in safe mode"); memset(&sCtx, 0, sizeof(sCtx)); @@ -8993,10 +8994,10 @@ static int do_meta_command(char *zLine, ShellState *p){ rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); import_append_char(&sCtx, 0); /* To ensure sCtx.z is allocated */ if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(p->db))==0 ){ - char *zCreate = sqlite3_mprintf("CREATE TABLE %s", zFullTabName); sqlite3 *dbCols = 0; char *zRenames = 0; char *zColDefs; + zCreate = sqlite3_mprintf("CREATE TABLE %s", zFullTabName); while( xRead(&sCtx) ){ zAutoColumn(sCtx.z, &dbCols, 0); if( sCtx.cTerm!=sCtx.cColSep ) break; diff --git a/src/treeview.c b/src/treeview.c index 86f06e8323..16124fe677 100644 --- a/src/treeview.c +++ b/src/treeview.c @@ -33,7 +33,7 @@ static TreeView *sqlite3TreeViewPush(TreeView *p, u8 moreToFollow){ p->iLevel++; } assert( moreToFollow==0 || moreToFollow==1 ); - if( p->iLevelbLine) ) p->bLine[p->iLevel] = moreToFollow; + if( p->iLevel<(int)sizeof(p->bLine) ) p->bLine[p->iLevel] = moreToFollow; return p; } @@ -57,7 +57,7 @@ static void sqlite3TreeViewLine(TreeView *p, const char *zFormat, ...){ char zBuf[500]; sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0); if( p ){ - for(i=0; iiLevel && ibLine)-1; i++){ + for(i=0; iiLevel && i<(int)sizeof(p->bLine)-1; i++){ sqlite3_str_append(&acc, p->bLine[i] ? "| " : " ", 4); } sqlite3_str_append(&acc, p->bLine[i] ? "|-- " : "'-- ", 4); diff --git a/src/vdbeaux.c b/src/vdbeaux.c index f5aa1f0fd2..aea932125c 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -180,7 +180,7 @@ static int growOpArray(Vdbe *v, int nOp){ return SQLITE_NOMEM; } - assert( nOp<=(1024/sizeof(Op)) ); + assert( nOp<=(int)(1024/sizeof(Op)) ); assert( nNew>=(v->nOpAlloc+nOp) ); pNew = sqlite3DbRealloc(p->db, v->aOp, nNew*sizeof(Op)); if( pNew ){ From 32135d7e0a4e63a357237a2bd9507d49138fa357 Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 8 Mar 2022 15:49:17 +0000 Subject: [PATCH 58/75] Fix a minor typo in a comment. FossilOrigin-Name: cf61419f8816377f40ea032e1e3fb8b765ff7eb5b3a5ece8f7b59acffc5d3f05 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/btreeInt.h | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 644ca00073..0da165e6f9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\scompiler\swarnings. -D 2022-03-08T13:59:46.057 +C Fix\sa\sminor\stypo\sin\sa\scomment. +D 2022-03-08T15:49:17.727 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -494,7 +494,7 @@ F src/bitvec.c 7c849aac407230278445cb069bebc5f89bf2ddd87c5ed9459b070a9175707b3d F src/btmutex.c 8acc2f464ee76324bf13310df5692a262b801808984c1b79defb2503bbafadb6 F src/btree.c f00f7323b3e7d2bf5192055b4a325a5b813686d424b59815e725690d2c215451 F src/btree.h 74d64b8f28cfa4a894d14d4ed64fa432cd697b98b61708d4351482ae15913e22 -F src/btreeInt.h 1ca477727c5f420a8321208dc5b14d93cb46cec8f941bc49318feb0e00bc961f +F src/btreeInt.h 8ce1332edd89dfd2461d561ac10a0ab5601c8e06200cb5230596c3caaf54482e F src/build.c 9891c2160886cf7e344d7e8f1f7177f9612916c7c67ffeacd64cb34a92d387a8 F src/callback.c 4c19af69835787bfe790ac560f3071a824eb629f34e41f97b52ce5235c77de1c F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P ae464a18d74bf44fc95bc335e75e6a57dc974f6d6a3d603133594039fb589af2 -R 0305e4ee75e40dc455311f12a8983540 +P 5e30c6ea707f9d381127e8b2bb59e0b39bc00997da2c14d32a0e302d0121203b +R dd5da23e574023e92e905ca7b95262f2 U drh -Z 4d6c360fc29e12f82d08e8ad6a34a2b7 +Z b1ecbf8808dd4301db6e0ee5abe242f9 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 2abefe58b0..f58af3d910 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5e30c6ea707f9d381127e8b2bb59e0b39bc00997da2c14d32a0e302d0121203b \ No newline at end of file +cf61419f8816377f40ea032e1e3fb8b765ff7eb5b3a5ece8f7b59acffc5d3f05 \ No newline at end of file diff --git a/src/btreeInt.h b/src/btreeInt.h index 3b0572e954..1f45553dc9 100644 --- a/src/btreeInt.h +++ b/src/btreeInt.h @@ -295,7 +295,7 @@ struct MemPage { u8 *aData; /* Pointer to disk image of the page data */ u8 *aDataEnd; /* One byte past the end of the entire page - not just ** the usable space, the entire page. Used to prevent - ** corruption-induced of buffer overflow. */ + ** corruption-induced buffer overflow. */ u8 *aCellIdx; /* The cell index area */ u8 *aDataOfst; /* Same as aData for leaves. aData+4 for interior */ DbPage *pDbPage; /* Pager page handle */ From 577f0a1e454e7b5027ca1621c4501253457164bb Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 9 Mar 2022 12:20:40 +0000 Subject: [PATCH 59/75] Improve the defenses against bad pathnames input into the findCreateFileMode() function of os_unix.c in order to quiet static-analyzer warnings. There are no demonstrated problems in the prior code, but this change makes the code easier to prove correct and more robust against future changes. FossilOrigin-Name: a9cda38997a692e25d2fe994a9a3fb9472c00ba04323c82e706fdb1112d4244e --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/os_unix.c | 25 ++++++++++++++----------- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/manifest b/manifest index 0da165e6f9..46f9512989 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sminor\stypo\sin\sa\scomment. -D 2022-03-08T15:49:17.727 +C Improve\sthe\sdefenses\sagainst\sbad\spathnames\sinput\sinto\sthe\sfindCreateFileMode()\nfunction\sof\sos_unix.c\sin\sorder\sto\squiet\sstatic-analyzer\swarnings.\s\sThere\nare\sno\sdemonstrated\sproblems\sin\sthe\sprior\scode,\sbut\sthis\schange\smakes\sthe\scode\neasier\sto\sprove\scorrect\sand\smore\srobust\sagainst\sfuture\schanges. +D 2022-03-09T12:20:40.382 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -536,7 +536,7 @@ F src/os.c b1c4f2d485961e9a5b6b648c36687d25047c252222e9660b7cc25a6e1ea436ab F src/os.h 26890f540b475598cd9881dcc68931377b8d429d3ea3e2eeb64470cde64199f8 F src/os_common.h b2f4707a603e36811d9b1a13278bffd757857b85 F src/os_setup.h 0dbaea40a7d36bf311613d31342e0b99e2536586 -F src/os_unix.c f5ad51cfd024116db8531feab9efd831c2621436dca1464e4ff1e8af9bf3252e +F src/os_unix.c f0dc85d439ece53120c4071c98876758ec24e6f713b67af3711af033c897091e F src/os_win.c 77d39873836f1831a9b0b91894fec45ab0e9ca8e067dc8c549e1d1eca1566fe9 F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a F src/pager.c 42120492784fc9bcd9082b5c9b5e329b7318c357f9f3574a1bbfcf7418910356 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 5e30c6ea707f9d381127e8b2bb59e0b39bc00997da2c14d32a0e302d0121203b -R dd5da23e574023e92e905ca7b95262f2 +P cf61419f8816377f40ea032e1e3fb8b765ff7eb5b3a5ece8f7b59acffc5d3f05 +R 4636c384f511b3ce8faf4df959f18ada U drh -Z b1ecbf8808dd4301db6e0ee5abe242f9 +Z d8f9c4f94a9d430581376bee45736088 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index f58af3d910..a3f62c76e7 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -cf61419f8816377f40ea032e1e3fb8b765ff7eb5b3a5ece8f7b59acffc5d3f05 \ No newline at end of file +a9cda38997a692e25d2fe994a9a3fb9472c00ba04323c82e706fdb1112d4244e \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index cd619f5c04..f4e5421469 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -6011,20 +6011,23 @@ static int findCreateFileMode( ** ** where NN is a decimal number. The NN naming schemes are ** used by the test_multiplex.c module. + ** + ** In normal operation, the journal file name will always contain + ** a '-' character. However in 8+3 filename mode, or if a corrupt + ** rollback journal specifies a super-journal with a goofy name, then + ** the '-' might be missing or the '-' might be the first character in + ** the filename. In that case, just return SQLITE_OK with *pMode==0. */ - nDb = sqlite3Strlen30(zPath) - 1; - while( zPath[nDb]!='-' ){ - /* In normal operation, the journal file name will always contain - ** a '-' character. However in 8+3 filename mode, or if a corrupt - ** rollback journal specifies a super-journal with a goofy name, then - ** the '-' might be missing. */ - if( nDb==0 || zPath[nDb]=='.' ) return SQLITE_OK; + nDb = sqlite3Strlen30(zPath) - 1; + while( nDb>0 && zPath[nDb]!='.' ){ + if( zPath[nDb]=='-' ){ + memcpy(zDb, zPath, nDb); + zDb[nDb] = '\0'; + rc = getFileMode(zDb, pMode, pUid, pGid); + break; + } nDb--; } - memcpy(zDb, zPath, nDb); - zDb[nDb] = '\0'; - - rc = getFileMode(zDb, pMode, pUid, pGid); }else if( flags & SQLITE_OPEN_DELETEONCLOSE ){ *pMode = 0600; }else if( flags & SQLITE_OPEN_URI ){ From b528a5a04e262131936bf5d90005d7bca35e2cac Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 9 Mar 2022 13:22:53 +0000 Subject: [PATCH 60/75] Do not use va_arg() as an l-value, because [forum:/forumpost/45e39c1311|AIX does not allow that], from what we are told. FossilOrigin-Name: 46d1a6de620f26fef9d0e2de6e9ea032790016441e4e6228a2f8cb30e20c9a51 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/main.c | 10 ++++++---- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 46f9512989..f6196db066 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improve\sthe\sdefenses\sagainst\sbad\spathnames\sinput\sinto\sthe\sfindCreateFileMode()\nfunction\sof\sos_unix.c\sin\sorder\sto\squiet\sstatic-analyzer\swarnings.\s\sThere\nare\sno\sdemonstrated\sproblems\sin\sthe\sprior\scode,\sbut\sthis\schange\smakes\sthe\scode\neasier\sto\sprove\scorrect\sand\smore\srobust\sagainst\sfuture\schanges. -D 2022-03-09T12:20:40.382 +C Do\snot\suse\sva_arg()\sas\san\sl-value,\sbecause\n[forum:/forumpost/45e39c1311|AIX\sdoes\snot\sallow\sthat],\sfrom\swhat\swe\sare\ntold. +D 2022-03-09T13:22:53.442 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -516,7 +516,7 @@ F src/insert.c 9fbf8704562fe17e442c16b7f60d3d91101ea69fc45c2bce96ee6cb982e86d2f F src/json.c 24fcd7f5f9080b04b89722c343010d390f85e55b2ab560046cb567c9dd640f62 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c aa919a6a7884f8b34d7b791841b24d14b1b0ab43f45b3940f4851043b2855c0c -F src/main.c 0840cee6984034c7e73cc747a1562c7eaed4673694bf20b00980aaa0672c0405 +F src/main.c 89dfd569b4fbcab65281b3c6d636b887b2cb23cbaa16f8c6b67062862144c927 F src/malloc.c fec841aa0a0400a6f7d20706178a5d8e8219a6bf562b6fe712c17f6c26813266 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c c12a42539b1ba105e3707d0e628ad70e611040d8f5e38cf942cee30c867083de @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P cf61419f8816377f40ea032e1e3fb8b765ff7eb5b3a5ece8f7b59acffc5d3f05 -R 4636c384f511b3ce8faf4df959f18ada +P a9cda38997a692e25d2fe994a9a3fb9472c00ba04323c82e706fdb1112d4244e +R 64b1de8af9978ba381b4e1a3e1bb2e50 U drh -Z d8f9c4f94a9d430581376bee45736088 +Z 86421268c2e3304c272a8e4b33f694ad # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index a3f62c76e7..60ec156405 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a9cda38997a692e25d2fe994a9a3fb9472c00ba04323c82e706fdb1112d4244e \ No newline at end of file +46d1a6de620f26fef9d0e2de6e9ea032790016441e4e6228a2f8cb30e20c9a51 \ No newline at end of file diff --git a/src/main.c b/src/main.c index 8747f07b56..4aac64da3e 100644 --- a/src/main.c +++ b/src/main.c @@ -4387,10 +4387,12 @@ int sqlite3_test_control(int op, ...){ case SQLITE_TESTCTRL_LOGEST: { double rIn = va_arg(ap, double); LogEst rLogEst = sqlite3LogEstFromDouble(rIn); - u64 iInt = sqlite3LogEstToInt(rLogEst); - va_arg(ap, int*)[0] = rLogEst; - va_arg(ap, u64*)[0] = iInt; - va_arg(ap, int*)[0] = sqlite3LogEst(iInt); + int *pI1 = va_arg(ap,int*); + u64 *pU64 = va_arg(ap,u64*); + int *pI2 = va_arg(ap,int*); + *pI1 = rLogEst; + *pU64 = sqlite3LogEstToInt(rLogEst); + *pI2 = sqlite3LogEst(*pU64); break; } From 46dc631a3273373be86400bbd8e9696262b55b27 Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 9 Mar 2022 14:22:28 +0000 Subject: [PATCH 61/75] Fix the sqlite_dbpage virtual table so that it starts a write transaction on all attached schemas. FossilOrigin-Name: 642a0b4752743216271e4f855a465515ef7f6a985f280251e18d67e3d5fb694b --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/dbpage.c | 1 + src/sqliteInt.h | 5 +++++ src/where.c | 17 ++++++++++++++++- 5 files changed, 31 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index f6196db066..5b9e73c6da 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Do\snot\suse\sva_arg()\sas\san\sl-value,\sbecause\n[forum:/forumpost/45e39c1311|AIX\sdoes\snot\sallow\sthat],\sfrom\swhat\swe\sare\ntold. -D 2022-03-09T13:22:53.442 +C Fix\sthe\ssqlite_dbpage\svirtual\stable\sso\sthat\sit\sstarts\sa\swrite\stransaction\non\sall\sattached\sschemas. +D 2022-03-09T14:22:28.517 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -500,7 +500,7 @@ F src/callback.c 4c19af69835787bfe790ac560f3071a824eb629f34e41f97b52ce5235c77de1 F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e F src/ctime.c 2cce39df1a13e05b7633e6d21b651f21492471f991dd7b323a4ee4e7b7f0b7f1 F src/date.c 15082566229d4b1e5f24fdb490bf9bcc68824b911d70e3573ef075a1b9e2d26f -F src/dbpage.c 74cf60d209adbf00a5687fb777fd66c450e7008dcf9e97f446b543c13fe841c4 +F src/dbpage.c a70be9a4879ac5392673a1050d526a72b8b2f9938df7049f65348566a2637db3 F src/dbstat.c 861e08690fcb0f2ee1165eff0060ea8d4f3e2ea10f80dab7d32ad70443a6ff2d F src/delete.c b5f1716b4d723db48254ee0f896e362cd029e865e05414139ea7f539f3884e1d F src/expr.c 3cdb00b6c15f815c94836e7b4474b675155d1279e64804f6ab5816188a9b05b6 @@ -557,7 +557,7 @@ F src/shell.c.in 69d1e59da4881f096ab47fbd3e6d99794f3e4a43f41fd9e4d2e845c9b8d20fd F src/sqlite.h.in e82ac380b307659d0892f502b742f825504e78729f4edaadce946003b9c00816 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h a95cb9ed106e3d39e2118e4dcc15a14faec3fa50d0093425083d340d9dfd96e6 -F src/sqliteInt.h 4a8b7d685781df55ce546b6c72bdbd72bb23ca93f59b6d70d81ed6df22607d75 +F src/sqliteInt.h a98a9cfc7e717b98f30e72545695f1ad92354fdf16df8510e80f48cf98c4adbe F src/sqliteLimit.h d7323ffea5208c6af2734574bae933ca8ed2ab728083caa117c9738581a31657 F src/status.c 4b8bc2a6905163a38b739854a35b826c737333fab5b1f8e03fa7eb9a4799c4c1 F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 @@ -639,7 +639,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c b9df133a705093da8977da5eb202eaadb844839f1c7297c08d33471f5491843d F src/wal.h c3aa7825bfa2fe0d85bef2db94655f99870a285778baa36307c0a16da32b226a F src/walker.c f890a3298418d7cba3b69b8803594fdc484ea241206a8dfa99db6dd36f8cbb3b -F src/where.c 1471be86b34b8ce328c6c68d7e2ee667c7f801ddf83ff179bc5936700cf43aa7 +F src/where.c 5c5a380bfb13a6964a7ab4d3780f9b4fd2b40457f4bfd2b85224d326f4a3bae1 F src/whereInt.h 15d2975c3b4c193c78c26674400a840da8647fe1777ae3b026e2d15937b38a03 F src/wherecode.c 555f598a9ddad81761f084710fdb4f8733fe31bc14cd6b19f8ca4274a7eaa04c F src/whereexpr.c 2a71f5491798460c9590317329234d332d9eb1717cba4f3403122189a75c465e @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P a9cda38997a692e25d2fe994a9a3fb9472c00ba04323c82e706fdb1112d4244e -R 64b1de8af9978ba381b4e1a3e1bb2e50 +P 46d1a6de620f26fef9d0e2de6e9ea032790016441e4e6228a2f8cb30e20c9a51 +R 3cf9d0a8d2242fdc47ea70af0c922c52 U drh -Z 86421268c2e3304c272a8e4b33f694ad +Z 3ca5a3fb65527e732bd1765ba8c8c948 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 60ec156405..e04ec1134b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -46d1a6de620f26fef9d0e2de6e9ea032790016441e4e6228a2f8cb30e20c9a51 \ No newline at end of file +642a0b4752743216271e4f855a465515ef7f6a985f280251e18d67e3d5fb694b \ No newline at end of file diff --git a/src/dbpage.c b/src/dbpage.c index c74e811926..8a997e2def 100644 --- a/src/dbpage.c +++ b/src/dbpage.c @@ -156,6 +156,7 @@ static int dbpageBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){ ){ pIdxInfo->orderByConsumed = 1; } + sqlite3VtabWriteAll(pIdxInfo); return SQLITE_OK; } diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 5e6b67c84d..a4015430d5 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -5106,7 +5106,12 @@ int sqlite3VtabCallCreate(sqlite3*, int, const char *, char **); int sqlite3VtabCallConnect(Parse*, Table*); int sqlite3VtabCallDestroy(sqlite3*, int, const char *); int sqlite3VtabBegin(sqlite3 *, VTable *); + FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*); +#if (defined(SQLITE_ENABLE_DBPAGE_VTAB) || defined(SQLITE_TEST)) \ + && !defined(SQLITE_OMIT_VIRTUALTABLE) + void sqlite3VtabWriteAll(sqlite3_index_info*); +#endif sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context*); int sqlite3VdbeParameterIndex(Vdbe*, const char*, int); int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt *); diff --git a/src/where.c b/src/where.c index ddec44723f..9ce65c42b2 100644 --- a/src/where.c +++ b/src/where.c @@ -3764,7 +3764,6 @@ int sqlite3_vtab_rhs_value( return rc; } - /* ** Return true if ORDER BY clause may be handled as DISTINCT. */ @@ -3776,6 +3775,22 @@ int sqlite3_vtab_distinct(sqlite3_index_info *pIdxInfo){ return pHidden->eDistinct; } +#if (defined(SQLITE_ENABLE_DBPAGE_VTAB) || defined(SQLITE_TEST)) \ + && !defined(SQLITE_OMIT_VIRTUALTABLE) +/* +** Cause the prepared statement that is associated with a call to +** xBestIndex to open write transactions on all attached schemas. +** This is used by the (built-in) sqlite_dbpage virtual table. +*/ +void sqlite3VtabWriteAll(sqlite3_index_info *pIdxInfo){ + HiddenIndexInfo *pHidden = (HiddenIndexInfo*)&pIdxInfo[1]; + Parse *pParse = pHidden->pParse; + Parse *pTopLevel = sqlite3ParseToplevel(pParse); + pTopLevel->cookieMask = + pTopLevel->writeMask = (((u64)1) << pParse->db->nDb) - 1; +} +#endif + /* ** Add all WhereLoop objects for a table of the join identified by ** pBuilder->pNew->iTab. That table is guaranteed to be a virtual table. From 6563d0c11a59e2487c8b05fc0ea9a4517b27afbc Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 9 Mar 2022 18:29:19 +0000 Subject: [PATCH 62/75] Further refinements to the sqlite_offset() fix from [6029514b08b88e3f]. FossilOrigin-Name: 6f838305e2c848a43b210bd1b7b962fb9e3c41de34de778675e6578fcd99f397 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/where.c | 4 ++++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 5b9e73c6da..ea1836c448 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\ssqlite_dbpage\svirtual\stable\sso\sthat\sit\sstarts\sa\swrite\stransaction\non\sall\sattached\sschemas. -D 2022-03-09T14:22:28.517 +C Further\srefinements\sto\sthe\ssqlite_offset()\sfix\sfrom\s[6029514b08b88e3f]. +D 2022-03-09T18:29:19.102 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -639,7 +639,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c b9df133a705093da8977da5eb202eaadb844839f1c7297c08d33471f5491843d F src/wal.h c3aa7825bfa2fe0d85bef2db94655f99870a285778baa36307c0a16da32b226a F src/walker.c f890a3298418d7cba3b69b8803594fdc484ea241206a8dfa99db6dd36f8cbb3b -F src/where.c 5c5a380bfb13a6964a7ab4d3780f9b4fd2b40457f4bfd2b85224d326f4a3bae1 +F src/where.c b6f15969cadadd050cb9e43e77af76c7b073fd0247c486f0364427b56336f0c2 F src/whereInt.h 15d2975c3b4c193c78c26674400a840da8647fe1777ae3b026e2d15937b38a03 F src/wherecode.c 555f598a9ddad81761f084710fdb4f8733fe31bc14cd6b19f8ca4274a7eaa04c F src/whereexpr.c 2a71f5491798460c9590317329234d332d9eb1717cba4f3403122189a75c465e @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 46d1a6de620f26fef9d0e2de6e9ea032790016441e4e6228a2f8cb30e20c9a51 -R 3cf9d0a8d2242fdc47ea70af0c922c52 +P 642a0b4752743216271e4f855a465515ef7f6a985f280251e18d67e3d5fb694b +R e003996df7c18cb8469e22c2bd0a359b U drh -Z 3ca5a3fb65527e732bd1765ba8c8c948 +Z b55793a1f68bedfa10993b4fd3b3fa4f # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index e04ec1134b..0643f7a01b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -642a0b4752743216271e4f855a465515ef7f6a985f280251e18d67e3d5fb694b \ No newline at end of file +6f838305e2c848a43b210bd1b7b962fb9e3c41de34de778675e6578fcd99f397 \ No newline at end of file diff --git a/src/where.c b/src/where.c index 9ce65c42b2..6705c4d36b 100644 --- a/src/where.c +++ b/src/where.c @@ -6150,6 +6150,10 @@ void sqlite3WhereEnd(WhereInfo *pWInfo){ Index *pPk = sqlite3PrimaryKeyIndex(pTab); x = pPk->aiColumn[x]; assert( x>=0 ); +#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC + }else if( pOp->opcode==OP_Offset ){ + /* Do not need to translate the column number */ +#endif }else{ testcase( x!=sqlite3StorageColumnToTable(pTab,x) ); x = sqlite3StorageColumnToTable(pTab,x); From 6a51e70c5fb683a1f9c390da5ff7fe5eeaf99676 Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 10 Mar 2022 01:10:28 +0000 Subject: [PATCH 63/75] Check-in [642a0b4752743216] fixing sqlite_dbpage is not exactly correct. This patch should fix it. FossilOrigin-Name: 6ba36714ca5e5457bc424273129f2814b62b7fae38926aa6eeeeec81020d7f70 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/where.c | 6 +++--- test/dbpage.test | 6 ++++++ 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index ea1836c448..92bc7c81de 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Further\srefinements\sto\sthe\ssqlite_offset()\sfix\sfrom\s[6029514b08b88e3f]. -D 2022-03-09T18:29:19.102 +C Check-in\s[642a0b4752743216]\sfixing\ssqlite_dbpage\sis\snot\sexactly\scorrect.\nThis\spatch\sshould\sfix\sit. +D 2022-03-10T01:10:28.743 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -639,7 +639,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c b9df133a705093da8977da5eb202eaadb844839f1c7297c08d33471f5491843d F src/wal.h c3aa7825bfa2fe0d85bef2db94655f99870a285778baa36307c0a16da32b226a F src/walker.c f890a3298418d7cba3b69b8803594fdc484ea241206a8dfa99db6dd36f8cbb3b -F src/where.c b6f15969cadadd050cb9e43e77af76c7b073fd0247c486f0364427b56336f0c2 +F src/where.c baec5c64db111227b6c7f07f65d91706a51d9f8c72d3f3ec7e65c39450b592d0 F src/whereInt.h 15d2975c3b4c193c78c26674400a840da8647fe1777ae3b026e2d15937b38a03 F src/wherecode.c 555f598a9ddad81761f084710fdb4f8733fe31bc14cd6b19f8ca4274a7eaa04c F src/whereexpr.c 2a71f5491798460c9590317329234d332d9eb1717cba4f3403122189a75c465e @@ -845,7 +845,7 @@ F test/dbfuzz.c 73047c920d6210e5912c87cdffd9a1c281d4252e F test/dbfuzz001.test 55e1a3504f8dea84155e09912fe3b1c3ad77e0b1a938ec42ca03b8e51b321e30 F test/dbfuzz2-seed1.db e6225c6f3d7b63f9c5b6867146a5f329d997ab105bee64644dc2b3a2f2aebaee F test/dbfuzz2.c 4b3c12de4d98b1b2d908ab03d217d4619e47c8b23d5e67f8a6f2b1bdee7cae23 -F test/dbpage.test 650234ba683b9d82b899c6c51439819787e7609f17a0cc40e0080a7b6443bc38 +F test/dbpage.test fce29035c7566fd7835ec0f19422cb4b9c6944ce0e1b936ff8452443f92e887d F test/dbstatus.test 4a4221a883025ffd39696b3d1b3910b928fb097d77e671351acb35f3aed42759 F test/dbstatus2.test f5fe0afed3fa45e57cfa70d1147606c20d2ba23feac78e9a172f2fe8ab5b78ef F test/decimal.test fcf403fd5585f47342234e153c4a4338cd737b8e0884ac66fc484df47dbcf1a7 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 642a0b4752743216271e4f855a465515ef7f6a985f280251e18d67e3d5fb694b -R e003996df7c18cb8469e22c2bd0a359b +P 6f838305e2c848a43b210bd1b7b962fb9e3c41de34de778675e6578fcd99f397 +R 1c08757aded2a038b243d63f31083a42 U drh -Z b55793a1f68bedfa10993b4fd3b3fa4f +Z 02f19376b233605a19102be65ce52f53 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 0643f7a01b..c3bc62682b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6f838305e2c848a43b210bd1b7b962fb9e3c41de34de778675e6578fcd99f397 \ No newline at end of file +6ba36714ca5e5457bc424273129f2814b62b7fae38926aa6eeeeec81020d7f70 \ No newline at end of file diff --git a/src/where.c b/src/where.c index 6705c4d36b..ca4ce3d805 100644 --- a/src/where.c +++ b/src/where.c @@ -3785,9 +3785,9 @@ int sqlite3_vtab_distinct(sqlite3_index_info *pIdxInfo){ void sqlite3VtabWriteAll(sqlite3_index_info *pIdxInfo){ HiddenIndexInfo *pHidden = (HiddenIndexInfo*)&pIdxInfo[1]; Parse *pParse = pHidden->pParse; - Parse *pTopLevel = sqlite3ParseToplevel(pParse); - pTopLevel->cookieMask = - pTopLevel->writeMask = (((u64)1) << pParse->db->nDb) - 1; + int nDb = pParse->db->nDb; + int i; + for(i=0; i Date: Thu, 10 Mar 2022 02:23:43 +0000 Subject: [PATCH 64/75] Mention that sqlite3_column_text16() returns have native endianness FossilOrigin-Name: 25b7f88fcb2bb1908abde109c1167c462efbb156b4a8a8f94d36202bd93ea433 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/sqlite.h.in | 6 +++++- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 92bc7c81de..535fa436f2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Check-in\s[642a0b4752743216]\sfixing\ssqlite_dbpage\sis\snot\sexactly\scorrect.\nThis\spatch\sshould\sfix\sit. -D 2022-03-10T01:10:28.743 +C Mention\sthat\ssqlite3_column_text16()\sreturns\shave\snative\sendianness +D 2022-03-10T02:23:43.705 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -554,7 +554,7 @@ F src/resolve.c ea935b87d6fb36c78b70cdc7b28561dc8f33f2ef37048389549c7b5ef9b0ba5e F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92 F src/select.c 4890a3cfee0bc60ff231c3a44db37968859ab0be156983dbcc0c096109832cdd F src/shell.c.in 69d1e59da4881f096ab47fbd3e6d99794f3e4a43f41fd9e4d2e845c9b8d20fd5 -F src/sqlite.h.in e82ac380b307659d0892f502b742f825504e78729f4edaadce946003b9c00816 +F src/sqlite.h.in a9517f548afe7507bf6c50bfe4eae96eafb4fcce71d980f0b915b8a71916dae5 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h a95cb9ed106e3d39e2118e4dcc15a14faec3fa50d0093425083d340d9dfd96e6 F src/sqliteInt.h a98a9cfc7e717b98f30e72545695f1ad92354fdf16df8510e80f48cf98c4adbe @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 6f838305e2c848a43b210bd1b7b962fb9e3c41de34de778675e6578fcd99f397 -R 1c08757aded2a038b243d63f31083a42 -U drh -Z 02f19376b233605a19102be65ce52f53 +P 6ba36714ca5e5457bc424273129f2814b62b7fae38926aa6eeeeec81020d7f70 +R 2a08b42c1d235daa1c1ecabbd9423a51 +U larrybr +Z c7702290f0be1e7531fdca6dcb5d7c26 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index c3bc62682b..1c9e53916c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6ba36714ca5e5457bc424273129f2814b62b7fae38926aa6eeeeec81020d7f70 \ No newline at end of file +25b7f88fcb2bb1908abde109c1167c462efbb156b4a8a8f94d36202bd93ea433 \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 97ffcd88cc..c82c0971ef 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -4979,6 +4979,10 @@ int sqlite3_data_count(sqlite3_stmt *pStmt); ** even empty strings, are always zero-terminated. ^The return ** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer. ** +** ^Strings returned by sqlite3_column_text16() always have the endianness +** which is native to the platform, regardless of the text encoding set +** for the database. +** ** Warning: ^The object returned by [sqlite3_column_value()] is an ** [unprotected sqlite3_value] object. In a multithreaded environment, ** an unprotected sqlite3_value object may only be used safely with @@ -4992,7 +4996,7 @@ int sqlite3_data_count(sqlite3_stmt *pStmt); ** [application-defined SQL functions] or [virtual tables], not within ** top-level application code. ** -** The these routines may attempt to convert the datatype of the result. +** These routines may attempt to convert the datatype of the result. ** ^For example, if the internal representation is FLOAT and a text result ** is requested, [sqlite3_snprintf()] is used internally to perform the ** conversion automatically. ^(The following table details the conversions From 7931f0a3d834067b77298eccd17b99f0c07982db Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 10 Mar 2022 11:48:16 +0000 Subject: [PATCH 65/75] Only run atof1.test on x86_64 machines. FossilOrigin-Name: 4173819cd285a1c133645eda27b9f6dc5a2247eaa0c834bdc60058ef3109b102 --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/atof1.test | 4 ++++ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 535fa436f2..2ad5218d57 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Mention\sthat\ssqlite3_column_text16()\sreturns\shave\snative\sendianness -D 2022-03-10T02:23:43.705 +C Only\srun\satof1.test\son\sx86_64\smachines. +D 2022-03-10T11:48:16.021 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -690,7 +690,7 @@ F test/async2.test c0a9bd20816d7d6a2ceca7b8c03d3d69c28ffb8b F test/async3.test d73a062002376d7edc1fe3edff493edbec1fc2f7 F test/async4.test 1787e3952128aa10238bf39945126de7ca23685a F test/async5.test 383ab533fdb9f7ad228cc99ee66e1acb34cc0dc0 -F test/atof1.test 10049623e77006691c4c2978c1dc8a3f75276377a53417811aa85bda7493f963 +F test/atof1.test 1f24a6f16e44892848298bd8e488159d4a60cf47be003d32747a136103c9bbac F test/atomic.test 065a453dde33c77ff586d91ccaa6ed419829d492dbb1a5694b8a09f3f9d7d061 F test/atomic2.test b6863b4aa552543874f80b42fb3063f1c8c2e3d8e56b6562f00a3cc347b5c1da F test/atrc.c c388fac43dbba05c804432a7135ae688b32e8f25818e9994ffba4b64cf60c27c @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 6ba36714ca5e5457bc424273129f2814b62b7fae38926aa6eeeeec81020d7f70 -R 2a08b42c1d235daa1c1ecabbd9423a51 -U larrybr -Z c7702290f0be1e7531fdca6dcb5d7c26 +P 25b7f88fcb2bb1908abde109c1167c462efbb156b4a8a8f94d36202bd93ea433 +R aa1dfd2d13b644293181fbe4bafecf94 +U drh +Z 5c827774c79c6c3a7cb870a82b6e2f6a # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 1c9e53916c..fd1c0cff54 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -25b7f88fcb2bb1908abde109c1167c462efbb156b4a8a8f94d36202bd93ea433 \ No newline at end of file +4173819cd285a1c133645eda27b9f6dc5a2247eaa0c834bdc60058ef3109b102 \ No newline at end of file diff --git a/test/atof1.test b/test/atof1.test index 0505fb2268..5959c5d5b9 100644 --- a/test/atof1.test +++ b/test/atof1.test @@ -19,6 +19,10 @@ if {$::longdouble_size<=8} { finish_test return } +if {$::tcl_platform(machine)!="x86_64"} { + finish_test + return +} expr srand(1) for {set i 1} {$i<20000} {incr i} { From 105dcaa5033e416d73eb68c1932a63efaa34a34f Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 10 Mar 2022 16:01:14 +0000 Subject: [PATCH 66/75] Refactor Window.pFunc into Window.pWFunc to disambiguate from other uses of the variable or field named "pFunc". FossilOrigin-Name: d9475ebcde169272ad7b1d3a82b2326df55dafc68217bfecd9fcd1f2b89efbd9 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/sqliteInt.h | 2 +- src/treeview.c | 2 +- src/window.c | 24 ++++++++++++------------ 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/manifest b/manifest index 2ad5218d57..380759d93a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Only\srun\satof1.test\son\sx86_64\smachines. -D 2022-03-10T11:48:16.021 +C Refactor\sWindow.pFunc\sinto\sWindow.pWFunc\sto\sdisambiguate\sfrom\sother\suses\sof\nthe\svariable\sor\sfield\snamed\s"pFunc". +D 2022-03-10T16:01:14.573 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -557,7 +557,7 @@ F src/shell.c.in 69d1e59da4881f096ab47fbd3e6d99794f3e4a43f41fd9e4d2e845c9b8d20fd F src/sqlite.h.in a9517f548afe7507bf6c50bfe4eae96eafb4fcce71d980f0b915b8a71916dae5 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h a95cb9ed106e3d39e2118e4dcc15a14faec3fa50d0093425083d340d9dfd96e6 -F src/sqliteInt.h a98a9cfc7e717b98f30e72545695f1ad92354fdf16df8510e80f48cf98c4adbe +F src/sqliteInt.h 7ab4575383df08f356ac2d60cee07da5d6c3c20488b5ca4d79f41664b0f93f0b F src/sqliteLimit.h d7323ffea5208c6af2734574bae933ca8ed2ab728083caa117c9738581a31657 F src/status.c 4b8bc2a6905163a38b739854a35b826c737333fab5b1f8e03fa7eb9a4799c4c1 F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 @@ -617,7 +617,7 @@ F src/test_window.c cdae419fdcea5bad6dcd9368c685abdad6deb59e9fc8b84b153de513d394 F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/threads.c 4ae07fa022a3dc7c5beb373cf744a85d3c5c6c3c F src/tokenize.c 6661a9fa660ecbd3ac0df1acd2ec788b3a8122b4316022bcdaf476ea6754a8de -F src/treeview.c 90e133ebe903572ce0e30e866fa76efba3effcf487c9f5ce457870f315f297ea +F src/treeview.c 3fac35b0835998f34bc940cb07282c5c485caa1645135435fca07ba828c48463 F src/trigger.c 5fc3cde35cc4de510be68bb2db4dcff0ce0e1625f43e28a0920be9a6f010cd3f F src/update.c f875b0d59da5c3055a0b2ac20560e1650229c6787e78de5e9836267b5cbb8359 F src/upsert.c 8789047a8f0a601ea42fa0256d1ba3190c13746b6ba940fe2d25643a7e991937 @@ -643,7 +643,7 @@ F src/where.c baec5c64db111227b6c7f07f65d91706a51d9f8c72d3f3ec7e65c39450b592d0 F src/whereInt.h 15d2975c3b4c193c78c26674400a840da8647fe1777ae3b026e2d15937b38a03 F src/wherecode.c 555f598a9ddad81761f084710fdb4f8733fe31bc14cd6b19f8ca4274a7eaa04c F src/whereexpr.c 2a71f5491798460c9590317329234d332d9eb1717cba4f3403122189a75c465e -F src/window.c dfaec4abc6012cbc18e4a202ca3a5d5a0efcc4011d86a06d882ddaab8aedee4d +F src/window.c ce1b413b2e7320c20e709e9cec11d1589c7cb671718961e15162e14723389135 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/affinity2.test ce1aafc86e110685b324e9a763eab4f2a73f737842ec3b687bd965867de90627 F test/affinity3.test eecb0dabee4b7765a8465439d5e99429279ffba23ca74a7eae270a452799f9e7 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 25b7f88fcb2bb1908abde109c1167c462efbb156b4a8a8f94d36202bd93ea433 -R aa1dfd2d13b644293181fbe4bafecf94 +P 4173819cd285a1c133645eda27b9f6dc5a2247eaa0c834bdc60058ef3109b102 +R 0dcc25c67d9010afc551373ff27626de U drh -Z 5c827774c79c6c3a7cb870a82b6e2f6a +Z 8d13225c9c60b1f2df116002c6ed2308 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index fd1c0cff54..004dd22cbb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4173819cd285a1c133645eda27b9f6dc5a2247eaa0c834bdc60058ef3109b102 \ No newline at end of file +d9475ebcde169272ad7b1d3a82b2326df55dafc68217bfecd9fcd1f2b89efbd9 \ No newline at end of file diff --git a/src/sqliteInt.h b/src/sqliteInt.h index a4015430d5..90a7b6d6a4 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -4146,7 +4146,7 @@ struct Window { Window **ppThis; /* Pointer to this object in Select.pWin list */ Window *pNextWin; /* Next window function belonging to this SELECT */ Expr *pFilter; /* The FILTER expression */ - FuncDef *pFunc; /* The function */ + FuncDef *pWFunc; /* The function */ int iEphCsr; /* Partition buffer or Peer buffer */ int regAccum; /* Accumulator */ int regResult; /* Interim result */ diff --git a/src/treeview.c b/src/treeview.c index 16124fe677..b547c96c57 100644 --- a/src/treeview.c +++ b/src/treeview.c @@ -387,7 +387,7 @@ void sqlite3TreeViewWindow(TreeView *pView, const Window *pWin, u8 more){ void sqlite3TreeViewWinFunc(TreeView *pView, const Window *pWin, u8 more){ pView = sqlite3TreeViewPush(pView, more); sqlite3TreeViewLine(pView, "WINFUNC %s(%d)", - pWin->pFunc->zName, pWin->pFunc->nArg); + pWin->pWFunc->zName, pWin->pWFunc->nArg); sqlite3TreeViewWindow(pView, pWin, 0); sqlite3TreeViewPop(pView); } diff --git a/src/window.c b/src/window.c index 2b2e856ec9..a03ea0d656 100644 --- a/src/window.c +++ b/src/window.c @@ -724,7 +724,7 @@ void sqlite3WindowUpdate( } } } - pWin->pFunc = pFunc; + pWin->pWFunc = pFunc; } /* @@ -1033,7 +1033,7 @@ int sqlite3WindowRewrite(Parse *pParse, Select *p){ ExprList *pArgs; assert( ExprUseXList(pWin->pOwner) ); pArgs = pWin->pOwner->x.pList; - if( pWin->pFunc->funcFlags & SQLITE_FUNC_SUBTYPE ){ + if( pWin->pWFunc->funcFlags & SQLITE_FUNC_SUBTYPE ){ selectWindowRewriteEList(pParse, pMWin, pSrc, pArgs, pTab, &pSublist); pWin->iArgCol = (pSublist ? pSublist->nExpr : 0); pWin->bExprArgs = 1; @@ -1415,7 +1415,7 @@ void sqlite3WindowCodeInit(Parse *pParse, Select *pSelect){ } for(pWin=pMWin; pWin; pWin=pWin->pNextWin){ - FuncDef *p = pWin->pFunc; + FuncDef *p = pWin->pWFunc; if( (p->funcFlags & SQLITE_FUNC_MINMAX) && pWin->eStart!=TK_UNBOUNDED ){ /* The inline versions of min() and max() require a single ephemeral ** table and 3 registers. The registers are used as follows: @@ -1432,7 +1432,7 @@ void sqlite3WindowCodeInit(Parse *pParse, Select *pSelect){ pWin->csrApp = pParse->nTab++; pWin->regApp = pParse->nMem+1; pParse->nMem += 3; - if( pKeyInfo && pWin->pFunc->zName[1]=='i' ){ + if( pKeyInfo && pWin->pWFunc->zName[1]=='i' ){ assert( pKeyInfo->aSortFlags[0]==0 ); pKeyInfo->aSortFlags[0] = KEYINFO_ORDER_DESC; } @@ -1655,7 +1655,7 @@ static void windowAggStep( Vdbe *v = sqlite3GetVdbe(pParse); Window *pWin; for(pWin=pMWin; pWin; pWin=pWin->pNextWin){ - FuncDef *pFunc = pWin->pFunc; + FuncDef *pFunc = pWin->pWFunc; int regArg; int nArg = pWin->bExprArgs ? 0 : windowArgCount(pWin); int i; @@ -1769,7 +1769,7 @@ static void windowAggFinal(WindowCodeArg *p, int bFin){ for(pWin=pMWin; pWin; pWin=pWin->pNextWin){ if( pMWin->regStartRowid==0 - && (pWin->pFunc->funcFlags & SQLITE_FUNC_MINMAX) + && (pWin->pWFunc->funcFlags & SQLITE_FUNC_MINMAX) && (pWin->eStart!=TK_UNBOUNDED) ){ sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult); @@ -1783,12 +1783,12 @@ static void windowAggFinal(WindowCodeArg *p, int bFin){ int nArg = windowArgCount(pWin); if( bFin ){ sqlite3VdbeAddOp2(v, OP_AggFinal, pWin->regAccum, nArg); - sqlite3VdbeAppendP4(v, pWin->pFunc, P4_FUNCDEF); + sqlite3VdbeAppendP4(v, pWin->pWFunc, P4_FUNCDEF); sqlite3VdbeAddOp2(v, OP_Copy, pWin->regAccum, pWin->regResult); sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regAccum); }else{ sqlite3VdbeAddOp3(v, OP_AggValue,pWin->regAccum,nArg,pWin->regResult); - sqlite3VdbeAppendP4(v, pWin->pFunc, P4_FUNCDEF); + sqlite3VdbeAppendP4(v, pWin->pWFunc, P4_FUNCDEF); } } } @@ -1917,7 +1917,7 @@ static void windowReturnOneRow(WindowCodeArg *p){ Window *pWin; for(pWin=pMWin; pWin; pWin=pWin->pNextWin){ - FuncDef *pFunc = pWin->pFunc; + FuncDef *pFunc = pWin->pWFunc; assert( ExprUseXList(pWin->pOwner) ); if( pFunc->zName==nth_valueName || pFunc->zName==first_valueName @@ -1989,7 +1989,7 @@ static int windowInitAccum(Parse *pParse, Window *pMWin){ int nArg = 0; Window *pWin; for(pWin=pMWin; pWin; pWin=pWin->pNextWin){ - FuncDef *pFunc = pWin->pFunc; + FuncDef *pFunc = pWin->pWFunc; assert( pWin->regAccum ); sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regAccum); nArg = MAX(nArg, windowArgCount(pWin)); @@ -2019,7 +2019,7 @@ static int windowCacheFrame(Window *pMWin){ Window *pWin; if( pMWin->regStartRowid ) return 1; for(pWin=pMWin; pWin; pWin=pWin->pNextWin){ - FuncDef *pFunc = pWin->pFunc; + FuncDef *pFunc = pWin->pWFunc; if( (pFunc->zName==nth_valueName) || (pFunc->zName==first_valueName) || (pFunc->zName==leadName) @@ -2377,7 +2377,7 @@ Window *sqlite3WindowDup(sqlite3 *db, Expr *pOwner, Window *p){ pNew->zName = sqlite3DbStrDup(db, p->zName); pNew->zBase = sqlite3DbStrDup(db, p->zBase); pNew->pFilter = sqlite3ExprDup(db, p->pFilter, 0); - pNew->pFunc = p->pFunc; + pNew->pWFunc = p->pWFunc; pNew->pPartition = sqlite3ExprListDup(db, p->pPartition, 0); pNew->pOrderBy = sqlite3ExprListDup(db, p->pOrderBy, 0); pNew->eFrmType = p->eFrmType; From 5e121a50b3455589332e419a9ed0e2f07c16394a Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 10 Mar 2022 16:26:00 +0000 Subject: [PATCH 67/75] Prevent a NULL-pointer dereference when trying to parse a illegal schema entry that contains a window function while doing a RENAME COLUMN. [forum:/forumpost/ec2a2e0deb|Forum post ec2a2e0deb]. FossilOrigin-Name: 58de3c2b1a773a71b2d6a5d9a4dc0f839185d78d64519e7d267ad133b9830120 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/window.c | 7 ++++++- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 380759d93a..dae3d43f71 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Refactor\sWindow.pFunc\sinto\sWindow.pWFunc\sto\sdisambiguate\sfrom\sother\suses\sof\nthe\svariable\sor\sfield\snamed\s"pFunc". -D 2022-03-10T16:01:14.573 +C Prevent\sa\sNULL-pointer\sdereference\swhen\strying\sto\sparse\sa\sillegal\nschema\sentry\sthat\scontains\sa\swindow\sfunction\swhile\sdoing\sa\sRENAME\sCOLUMN.\n[forum:/forumpost/ec2a2e0deb|Forum\spost\sec2a2e0deb]. +D 2022-03-10T16:26:00.147 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -643,7 +643,7 @@ F src/where.c baec5c64db111227b6c7f07f65d91706a51d9f8c72d3f3ec7e65c39450b592d0 F src/whereInt.h 15d2975c3b4c193c78c26674400a840da8647fe1777ae3b026e2d15937b38a03 F src/wherecode.c 555f598a9ddad81761f084710fdb4f8733fe31bc14cd6b19f8ca4274a7eaa04c F src/whereexpr.c 2a71f5491798460c9590317329234d332d9eb1717cba4f3403122189a75c465e -F src/window.c ce1b413b2e7320c20e709e9cec11d1589c7cb671718961e15162e14723389135 +F src/window.c 457434edca750340462c84f2747381dfd15e3295e834821a18e48bde6d40da5f F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/affinity2.test ce1aafc86e110685b324e9a763eab4f2a73f737842ec3b687bd965867de90627 F test/affinity3.test eecb0dabee4b7765a8465439d5e99429279ffba23ca74a7eae270a452799f9e7 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 4173819cd285a1c133645eda27b9f6dc5a2247eaa0c834bdc60058ef3109b102 -R 0dcc25c67d9010afc551373ff27626de +P d9475ebcde169272ad7b1d3a82b2326df55dafc68217bfecd9fcd1f2b89efbd9 +R 19ed8acfffced0dc406eb65b6efd6f1c U drh -Z 8d13225c9c60b1f2df116002c6ed2308 +Z b78965c8e1d3b4bd978415cc04bb99fe # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 004dd22cbb..994eeee954 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d9475ebcde169272ad7b1d3a82b2326df55dafc68217bfecd9fcd1f2b89efbd9 \ No newline at end of file +58de3c2b1a773a71b2d6a5d9a4dc0f839185d78d64519e7d267ad133b9830120 \ No newline at end of file diff --git a/src/window.c b/src/window.c index a03ea0d656..ca543f145d 100644 --- a/src/window.c +++ b/src/window.c @@ -957,7 +957,11 @@ static int disallowAggregatesInOrderByCb(Walker *pWalker, Expr *pExpr){ */ int sqlite3WindowRewrite(Parse *pParse, Select *p){ int rc = SQLITE_OK; - if( p->pWin && p->pPrior==0 && ALWAYS((p->selFlags & SF_WinRewrite)==0) ){ + if( p->pWin + && p->pPrior==0 + && ALWAYS((p->selFlags & SF_WinRewrite)==0) + && !IN_RENAME_OBJECT + ){ Vdbe *v = sqlite3GetVdbe(pParse); sqlite3 *db = pParse->db; Select *pSub = 0; /* The subquery */ @@ -1032,6 +1036,7 @@ int sqlite3WindowRewrite(Parse *pParse, Select *p){ for(pWin=pMWin; pWin; pWin=pWin->pNextWin){ ExprList *pArgs; assert( ExprUseXList(pWin->pOwner) ); + assert( pWin->pWFunc!=0 ); pArgs = pWin->pOwner->x.pList; if( pWin->pWFunc->funcFlags & SQLITE_FUNC_SUBTYPE ){ selectWindowRewriteEList(pParse, pMWin, pSrc, pArgs, pTab, &pSublist); From 551b6502361b282012f99b73c4c58f946573d0ea Mon Sep 17 00:00:00 2001 From: larrybr Date: Thu, 10 Mar 2022 19:44:04 +0000 Subject: [PATCH 68/75] Amend sqlite3_column_*() doc table. (no code change) FossilOrigin-Name: 1f473099776249f774a285fa117316636e00c3ff030ba0f22ed5bd05641c1bc9 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/sqlite.h.in | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index dae3d43f71..3b0acbb3bc 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Prevent\sa\sNULL-pointer\sdereference\swhen\strying\sto\sparse\sa\sillegal\nschema\sentry\sthat\scontains\sa\swindow\sfunction\swhile\sdoing\sa\sRENAME\sCOLUMN.\n[forum:/forumpost/ec2a2e0deb|Forum\spost\sec2a2e0deb]. -D 2022-03-10T16:26:00.147 +C Amend\ssqlite3_column_*()\sdoc\stable.\s(no\scode\schange) +D 2022-03-10T19:44:04.358 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -554,7 +554,7 @@ F src/resolve.c ea935b87d6fb36c78b70cdc7b28561dc8f33f2ef37048389549c7b5ef9b0ba5e F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92 F src/select.c 4890a3cfee0bc60ff231c3a44db37968859ab0be156983dbcc0c096109832cdd F src/shell.c.in 69d1e59da4881f096ab47fbd3e6d99794f3e4a43f41fd9e4d2e845c9b8d20fd5 -F src/sqlite.h.in a9517f548afe7507bf6c50bfe4eae96eafb4fcce71d980f0b915b8a71916dae5 +F src/sqlite.h.in b93deee892f1bc4030e5c8712df9e21d786a1bf8e921ab8dc987eaf1e44c676f F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h a95cb9ed106e3d39e2118e4dcc15a14faec3fa50d0093425083d340d9dfd96e6 F src/sqliteInt.h 7ab4575383df08f356ac2d60cee07da5d6c3c20488b5ca4d79f41664b0f93f0b @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P d9475ebcde169272ad7b1d3a82b2326df55dafc68217bfecd9fcd1f2b89efbd9 -R 19ed8acfffced0dc406eb65b6efd6f1c -U drh -Z b78965c8e1d3b4bd978415cc04bb99fe +P 58de3c2b1a773a71b2d6a5d9a4dc0f839185d78d64519e7d267ad133b9830120 +R 453123152676a643644021462da06059 +U larrybr +Z 7a65559d2f8fe7a81c1e2aa9ebb98f60 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 994eeee954..9a44bf7cda 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -58de3c2b1a773a71b2d6a5d9a4dc0f839185d78d64519e7d267ad133b9830120 \ No newline at end of file +1f473099776249f774a285fa117316636e00c3ff030ba0f22ed5bd05641c1bc9 \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index c82c0971ef..6062f79c22 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -5021,7 +5021,7 @@ int sqlite3_data_count(sqlite3_stmt *pStmt); ** TEXT BLOB No change ** BLOB INTEGER [CAST] to INTEGER ** BLOB FLOAT [CAST] to REAL -** BLOB TEXT Add a zero terminator if needed +** BLOB TEXT [CAST] to TEXT, ensure zero terminator ** ** )^ ** From fde3043200acc528b43dcb5f7108ec3bf6ab0a26 Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 10 Mar 2022 21:04:49 +0000 Subject: [PATCH 69/75] Stronger defenses against corrupt schemas in the ALTER TABLE logic. FossilOrigin-Name: 13fbde28173332522a7ad307c1aad2b83c9aa1fe737583afa2b29f6da4de6370 --- manifest | 20 ++++++++++---------- manifest.uuid | 2 +- src/alter.c | 16 +++++++++------- src/build.c | 5 +++++ src/window.c | 2 +- test/alterqf.test | 6 ++---- 6 files changed, 28 insertions(+), 23 deletions(-) diff --git a/manifest b/manifest index 3b0acbb3bc..03eed7959c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Amend\ssqlite3_column_*()\sdoc\stable.\s(no\scode\schange) -D 2022-03-10T19:44:04.358 +C Stronger\sdefenses\sagainst\scorrupt\sschemas\sin\sthe\sALTER\sTABLE\slogic. +D 2022-03-10T21:04:49.750 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -485,7 +485,7 @@ F spec.template 86a4a43b99ebb3e75e6b9a735d5fd293a24e90ca F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786 F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a -F src/alter.c e31cae888bc3077e34f9a82c6b4a96e4e44d37861eeb6472d68a378f1e8e46ba +F src/alter.c 006325f8844c65d885b3ba469b4c08d9dd0cd3e9ec481d5bcff621f224cb2302 F src/analyze.c 3a119baeb03053c154029877454d41bb8fd79d4d1eb583392f2289b3554a75bc F src/attach.c f26d400f3ffe2cdca01406bca70e5f58c5488bf165b4fc37c228136dfcf1b583 F src/auth.c f4fa91b6a90bbc8e0d0f738aa284551739c9543a367071f55574681e0f24f8cf @@ -495,7 +495,7 @@ F src/btmutex.c 8acc2f464ee76324bf13310df5692a262b801808984c1b79defb2503bbafadb6 F src/btree.c f00f7323b3e7d2bf5192055b4a325a5b813686d424b59815e725690d2c215451 F src/btree.h 74d64b8f28cfa4a894d14d4ed64fa432cd697b98b61708d4351482ae15913e22 F src/btreeInt.h 8ce1332edd89dfd2461d561ac10a0ab5601c8e06200cb5230596c3caaf54482e -F src/build.c 9891c2160886cf7e344d7e8f1f7177f9612916c7c67ffeacd64cb34a92d387a8 +F src/build.c a0cc68fe8172c0a31b54576f9c6c0fe6f7c82b1b5e1387afdd6a5a13132bc131 F src/callback.c 4c19af69835787bfe790ac560f3071a824eb629f34e41f97b52ce5235c77de1c F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e F src/ctime.c 2cce39df1a13e05b7633e6d21b651f21492471f991dd7b323a4ee4e7b7f0b7f1 @@ -643,7 +643,7 @@ F src/where.c baec5c64db111227b6c7f07f65d91706a51d9f8c72d3f3ec7e65c39450b592d0 F src/whereInt.h 15d2975c3b4c193c78c26674400a840da8647fe1777ae3b026e2d15937b38a03 F src/wherecode.c 555f598a9ddad81761f084710fdb4f8733fe31bc14cd6b19f8ca4274a7eaa04c F src/whereexpr.c 2a71f5491798460c9590317329234d332d9eb1717cba4f3403122189a75c465e -F src/window.c 457434edca750340462c84f2747381dfd15e3295e834821a18e48bde6d40da5f +F src/window.c 42a71595263dbd8ef8248218e4fc7d4b5ddccece52146ad48e079342d93f6f8f F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/affinity2.test ce1aafc86e110685b324e9a763eab4f2a73f737842ec3b687bd965867de90627 F test/affinity3.test eecb0dabee4b7765a8465439d5e99429279ffba23ca74a7eae270a452799f9e7 @@ -666,7 +666,7 @@ F test/alterlegacy.test f38c6d06cda39e1f7b955bbce57f2e3ef5b7cb566d3d1234502093e2 F test/altermalloc.test 167a47de41b5c638f5f5c6efb59784002b196fff70f98d9b4ed3cd74a3fb80c9 F test/altermalloc2.test 17fb3724c4b004c469c27dc4ef181608aa644555fbd3f3236767584f73747c81 F test/altermalloc3.test 55e606edf4b0acfbbd851ddfe93cfdddfae43d103644dcfd6008ae4ab3c44adf -F test/alterqf.test 3008318ba9e16b4ac0b5f83cf7683caa4b0a3154aafe3b4099838a250d4ba74a +F test/alterqf.test ff6c6f881485c29ed699b8ef4774864ca1b0c01a6c08f5cdd624a008e4b40fca F test/altertab.test 7273b8506eab46342be016af78028df49f3bd99037412f997a8f1011b37a6912 F test/altertab2.test 62597b6fd08feaba1b6bfe7d31dac6117c67e06dc9ce9c478a3abe75b5926de0 F test/altertab3.test 5929f522fd6fd708396ad9f317d4af9ff1a93e460df85bb1d54d4499eeb94960 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 58de3c2b1a773a71b2d6a5d9a4dc0f839185d78d64519e7d267ad133b9830120 -R 453123152676a643644021462da06059 -U larrybr -Z 7a65559d2f8fe7a81c1e2aa9ebb98f60 +P 1f473099776249f774a285fa117316636e00c3ff030ba0f22ed5bd05641c1bc9 +R 2ae2925ec91f5619d1a35088b1bcfad0 +U drh +Z e232808c8eb653b66c1790d6c0687a0f # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 9a44bf7cda..27eff9f1b6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1f473099776249f774a285fa117316636e00c3ff030ba0f22ed5bd05641c1bc9 \ No newline at end of file +13fbde28173332522a7ad307c1aad2b83c9aa1fe737583afa2b29f6da4de6370 \ No newline at end of file diff --git a/src/alter.c b/src/alter.c index 59b3bf0303..1ec74cdcc7 100644 --- a/src/alter.c +++ b/src/alter.c @@ -1131,19 +1131,21 @@ static int renameParseSql( ){ int rc; - db->init.iDb = bTemp ? 1 : sqlite3FindDbName(db, zDb); - - /* Parse the SQL statement passed as the first argument. If no error - ** occurs and the parse does not result in a new table, index or - ** trigger object, the database must be corrupt. */ sqlite3ParseObjectInit(p, db); + if( zSql==0 ){ + return SQLITE_NOMEM; + } + if( sqlite3StrNICmp(zSql,"CREATE ",7)!=0 ){ + return SQLITE_CORRUPT_BKPT; + } + db->init.iDb = bTemp ? 1 : sqlite3FindDbName(db, zDb); p->eParseMode = PARSE_MODE_RENAME; p->db = db; p->nQueryLoop = 1; - rc = zSql ? sqlite3RunParser(p, zSql) : SQLITE_NOMEM; + rc = sqlite3RunParser(p, zSql); if( db->mallocFailed ) rc = SQLITE_NOMEM; if( rc==SQLITE_OK - && p->pNewTable==0 && p->pNewIndex==0 && p->pNewTrigger==0 + && NEVER(p->pNewTable==0 && p->pNewIndex==0 && p->pNewTrigger==0) ){ rc = SQLITE_CORRUPT_BKPT; } diff --git a/src/build.c b/src/build.c index 58b0710660..f7614af625 100644 --- a/src/build.c +++ b/src/build.c @@ -2826,6 +2826,11 @@ void sqlite3EndTable( int addrInsLoop; /* Top of the loop for inserting rows */ Table *pSelTab; /* A table that describes the SELECT results */ + if( IN_SPECIAL_PARSE ){ + pParse->rc = SQLITE_ERROR; + pParse->nErr++; + return; + } regYield = ++pParse->nMem; regRec = ++pParse->nMem; regRowid = ++pParse->nMem; diff --git a/src/window.c b/src/window.c index ca543f145d..d0ef81ae59 100644 --- a/src/window.c +++ b/src/window.c @@ -960,7 +960,7 @@ int sqlite3WindowRewrite(Parse *pParse, Select *p){ if( p->pWin && p->pPrior==0 && ALWAYS((p->selFlags & SF_WinRewrite)==0) - && !IN_RENAME_OBJECT + && ALWAYS(!IN_RENAME_OBJECT) ){ Vdbe *v = sqlite3GetVdbe(pParse); sqlite3 *db = pParse->db; diff --git a/test/alterqf.test b/test/alterqf.test index 400c4b6e79..423a9fa865 100644 --- a/test/alterqf.test +++ b/test/alterqf.test @@ -63,8 +63,7 @@ foreach {tn before after} { 10 {CREATE TABLE t2(abc, xyz CHECK (xyz != "123"))} {CREATE TABLE t2(abc, xyz CHECK (xyz != '123'))} - 11 { - CREATE TRIGGER ott AFTER UPDATE ON t1 BEGIN + 11 {CREATE TRIGGER ott AFTER UPDATE ON t1 BEGIN SELECT max("str", new."a") FROM t1 WHERE group_concat("b", ",") OVER (ORDER BY c||"str"); UPDATE t1 SET c= b + "str"; @@ -72,8 +71,7 @@ foreach {tn before after} { SELECT 1 FROM t1 AS o WHERE o."a" = "o.a" AND t1.b IN("t1.b") ); END; - } { - CREATE TRIGGER ott AFTER UPDATE ON t1 BEGIN + } {CREATE TRIGGER ott AFTER UPDATE ON t1 BEGIN SELECT max('str', new."a") FROM t1 WHERE group_concat("b", ',') OVER (ORDER BY c||'str'); UPDATE t1 SET c= b + 'str'; From 463edb627592fc258c1129a6a58d680cdf2a4d5c Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 10 Mar 2022 22:54:32 +0000 Subject: [PATCH 70/75] In the sqlite3BtreeIndexMoveto() last-page optimization, make sure to return SQLITE_CORRUPT if corruption is detected. FossilOrigin-Name: 4ef19ba9b5cbda435c0bb9f2faddf8f7fac5d51399ff69bd049571c2ca3d9357 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/btree.c | 1 + 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 03eed7959c..f629b390d9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Stronger\sdefenses\sagainst\scorrupt\sschemas\sin\sthe\sALTER\sTABLE\slogic. -D 2022-03-10T21:04:49.750 +C In\sthe\ssqlite3BtreeIndexMoveto()\slast-page\soptimization,\smake\ssure\sto\sreturn\nSQLITE_CORRUPT\sif\scorruption\sis\sdetected. +D 2022-03-10T22:54:32.736 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -492,7 +492,7 @@ F src/auth.c f4fa91b6a90bbc8e0d0f738aa284551739c9543a367071f55574681e0f24f8cf F src/backup.c a2891172438e385fdbe97c11c9745676bec54f518d4447090af97189fd8e52d7 F src/bitvec.c 7c849aac407230278445cb069bebc5f89bf2ddd87c5ed9459b070a9175707b3d F src/btmutex.c 8acc2f464ee76324bf13310df5692a262b801808984c1b79defb2503bbafadb6 -F src/btree.c f00f7323b3e7d2bf5192055b4a325a5b813686d424b59815e725690d2c215451 +F src/btree.c ed074030972b8445ac7020ef4928e2e2ec090bfe3b2169f4674dcd225d101a99 F src/btree.h 74d64b8f28cfa4a894d14d4ed64fa432cd697b98b61708d4351482ae15913e22 F src/btreeInt.h 8ce1332edd89dfd2461d561ac10a0ab5601c8e06200cb5230596c3caaf54482e F src/build.c a0cc68fe8172c0a31b54576f9c6c0fe6f7c82b1b5e1387afdd6a5a13132bc131 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 1f473099776249f774a285fa117316636e00c3ff030ba0f22ed5bd05641c1bc9 -R 2ae2925ec91f5619d1a35088b1bcfad0 +P 13fbde28173332522a7ad307c1aad2b83c9aa1fe737583afa2b29f6da4de6370 +R 5ddd7ed25326819447879d6db7c533a0 U drh -Z e232808c8eb653b66c1790d6c0687a0f +Z 65cf82e71fed144bd34f9030a2054257 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 27eff9f1b6..d1fa0807bc 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -13fbde28173332522a7ad307c1aad2b83c9aa1fe737583afa2b29f6da4de6370 \ No newline at end of file +4ef19ba9b5cbda435c0bb9f2faddf8f7fac5d51399ff69bd049571c2ca3d9357 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index e23fcd7187..262ffae2aa 100644 --- a/src/btree.c +++ b/src/btree.c @@ -5832,6 +5832,7 @@ int sqlite3BtreeIndexMoveto( && (c = indexCellCompare(pCur, pCur->ix, pIdxKey, xRecordCompare))<=0 ){ *pRes = c; + if( pIdxKey->errCode ) return SQLITE_CORRUPT_BKPT; return SQLITE_OK; /* Cursor already pointing at the correct spot */ } if( pCur->iPage>0 From 3946561a7fef3f249f9f2fe82b82951ae6373fb0 Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 10 Mar 2022 23:37:58 +0000 Subject: [PATCH 71/75] Another corruption detection case in the sqlite3BtreeIndexMoveto() last page optimization. FossilOrigin-Name: 531e6ad0389c6c820bb8c64db5049fb6b0bffd30bd394fd8ee7412959b1752e2 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/btree.c | 1 + 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index f629b390d9..fb6cbf47e4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C In\sthe\ssqlite3BtreeIndexMoveto()\slast-page\soptimization,\smake\ssure\sto\sreturn\nSQLITE_CORRUPT\sif\scorruption\sis\sdetected. -D 2022-03-10T22:54:32.736 +C Another\scorruption\sdetection\scase\sin\sthe\ssqlite3BtreeIndexMoveto()\nlast\spage\soptimization. +D 2022-03-10T23:37:58.562 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -492,7 +492,7 @@ F src/auth.c f4fa91b6a90bbc8e0d0f738aa284551739c9543a367071f55574681e0f24f8cf F src/backup.c a2891172438e385fdbe97c11c9745676bec54f518d4447090af97189fd8e52d7 F src/bitvec.c 7c849aac407230278445cb069bebc5f89bf2ddd87c5ed9459b070a9175707b3d F src/btmutex.c 8acc2f464ee76324bf13310df5692a262b801808984c1b79defb2503bbafadb6 -F src/btree.c ed074030972b8445ac7020ef4928e2e2ec090bfe3b2169f4674dcd225d101a99 +F src/btree.c 961ae88f10541fa0cb6fb0cffedfbdfb7183041b66d99c57544b7e9fc1214f8f F src/btree.h 74d64b8f28cfa4a894d14d4ed64fa432cd697b98b61708d4351482ae15913e22 F src/btreeInt.h 8ce1332edd89dfd2461d561ac10a0ab5601c8e06200cb5230596c3caaf54482e F src/build.c a0cc68fe8172c0a31b54576f9c6c0fe6f7c82b1b5e1387afdd6a5a13132bc131 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 13fbde28173332522a7ad307c1aad2b83c9aa1fe737583afa2b29f6da4de6370 -R 5ddd7ed25326819447879d6db7c533a0 +P 4ef19ba9b5cbda435c0bb9f2faddf8f7fac5d51399ff69bd049571c2ca3d9357 +R 9eddff8d6613df9db13f90a975151eff U drh -Z 65cf82e71fed144bd34f9030a2054257 +Z 14dbf23053f6e391019ac64193a5c1f0 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d1fa0807bc..c30bb8df66 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4ef19ba9b5cbda435c0bb9f2faddf8f7fac5d51399ff69bd049571c2ca3d9357 \ No newline at end of file +531e6ad0389c6c820bb8c64db5049fb6b0bffd30bd394fd8ee7412959b1752e2 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 262ffae2aa..a41778761a 100644 --- a/src/btree.c +++ b/src/btree.c @@ -5839,6 +5839,7 @@ int sqlite3BtreeIndexMoveto( && (c = indexCellCompare(pCur, 0, pIdxKey, xRecordCompare))<=0 ){ pCur->curFlags &= ~BTCF_ValidOvfl; + if( pIdxKey->errCode ){ *pRes = 0; return SQLITE_CORRUPT_BKPT; } goto bypass_moveto_root; /* Start search on the current page */ } } From 7ef4d75bd2933bc56e8e0729af02827f7b53ceb3 Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 11 Mar 2022 12:02:18 +0000 Subject: [PATCH 72/75] Fix a case in fts5 where a corrupt database could cause a crash. FossilOrigin-Name: 5e95df261cce275adb5b2226e9584f4c389bb0d53c3b4feafd5a14be8d02ce63 --- ext/fts5/fts5_main.c | 2 +- ext/fts5/test/fts5corrupt3.test | 154 ++++++++++++++++++++++++++++++++ manifest | 16 ++-- manifest.uuid | 2 +- 4 files changed, 164 insertions(+), 10 deletions(-) diff --git a/ext/fts5/fts5_main.c b/ext/fts5/fts5_main.c index fd3a9066b7..9a8b2fadb4 100644 --- a/ext/fts5/fts5_main.c +++ b/ext/fts5/fts5_main.c @@ -804,7 +804,7 @@ static int fts5SorterNext(Fts5Cursor *pCsr){ rc = sqlite3_step(pSorter->pStmt); if( rc==SQLITE_DONE ){ rc = SQLITE_OK; - CsrFlagSet(pCsr, FTS5CSR_EOF); + CsrFlagSet(pCsr, FTS5CSR_EOF|FTS5CSR_REQUIRE_CONTENT); }else if( rc==SQLITE_ROW ){ const u8 *a; const u8 *aBlob; diff --git a/ext/fts5/test/fts5corrupt3.test b/ext/fts5/test/fts5corrupt3.test index adfaa6d85b..f9a95665c4 100644 --- a/ext/fts5/test/fts5corrupt3.test +++ b/ext/fts5/test/fts5corrupt3.test @@ -15366,6 +15366,160 @@ do_catchsql_test 79.2 { INSERT INTO t1(t1) SELECT 'merge' FROM t2; } {1 {query aborted}} +#------------------------------------------------------------------------- +reset_db +do_test 80.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +.open --hexdb +| size 40960 pagesize 4096 filename crash-f928a9c1ec68dd.db +| page 1 offset 0 +| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. +| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 0a .....@ ........ +| 32: 00 00 00 00 00 00 00 00 00 00 00 0d 00 00 00 04 ................ +| 96: 00 00 00 00 0d 00 00 00 0d 0b 6e 00 0f a3 0f 4c ..........n....L +| 112: 0e e1 0e 81 0e 24 0d cc 0d 72 0d 1b 0c b0 0c 50 .....$...r.....P +| 128: 0b f8 0b b3 0b 6e 00 00 00 00 00 00 00 00 00 00 .....n.......... +| 2912: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 43 0d ..............C. +| 2928: 06 17 11 11 08 75 74 61 62 6c 65 74 34 74 34 43 .....utablet4t4C +| 2944: 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 REATE VIRTUAL TA +| 2960: 42 4c 45 20 74 34 20 55 53 49 4e 47 20 66 74 73 BLE t4 USING fts +| 2976: 35 76 6f 63 61 62 28 27 74 32 27 2c 20 27 72 6f 5vocab('t2', 'ro +| 2992: 77 27 29 43 0c 06 17 11 11 08 75 74 61 62 6c 65 w')C......utable +| 3008: 74 33 74 33 43 52 45 41 54 45 20 56 49 52 54 55 t3t3CREATE VIRTU +| 3024: 41 4c 20 54 41 42 4c 45 20 74 33 20 55 53 49 4e AL TABLE t3 USIN +| 3040: 47 20 66 74 73 35 76 6f 63 61 62 28 27 74 31 27 G fts5vocab('t1' +| 3056: 2c 20 27 72 6f 77 27 29 56 0b 06 17 1f 1f 01 7d , 'row')V....... +| 3072: 74 61 62 6c 65 74 32 5f 63 6f 6e 66 69 67 74 32 tablet2_configt2 +| 3088: 5f 63 6f 6e 66 69 67 0a 43 52 45 41 54 45 20 54 _config.CREATE T +| 3104: 41 42 4c 45 20 27 74 32 5f 63 6f 6e 66 69 67 27 ABLE 't2_config' +| 3120: 28 6b 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 (k PRIMARY KEY, +| 3136: 76 29 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 v) WITHOUT ROWID +| 3152: 5e 0a 07 17 21 21 01 81 07 74 61 62 6c 65 74 32 ^...!!...tablet2 +| 3168: 5f 63 6f 6e 74 65 6e 74 74 32 5f 63 6f 6e 74 65 _contentt2_conte +| 3184: 6e 74 09 43 52 45 41 54 45 20 54 41 42 4c 45 20 nt.CREATE TABLE +| 3200: 27 74 32 5f 63 6f 6e 74 65 6e 74 27 28 69 64 20 't2_content'(id +| 3216: 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 INTEGER PRIMARY +| 3232: 4b 45 59 2c 20 63 30 2c 20 63 31 2c 20 63 32 29 KEY, c0, c1, c2) +| 3248: 69 09 07 17 19 19 01 81 2d 74 61 62 6c 65 74 32 i.......-tablet2 +| 3264: 5f 69 64 78 74 32 5f 69 64 78 08 43 52 45 41 54 _idxt2_idx.CREAT +| 3280: 45 20 54 41 42 4c 45 20 27 74 32 5f 69 64 78 27 E TABLE 't2_idx' +| 3296: 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20 70 67 (segid, term, pg +| 3312: 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45 59 28 no, PRIMARY KEY( +| 3328: 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20 57 49 segid, term)) WI +| 3344: 54 48 4f 55 54 20 52 4f 57 49 44 55 08 07 17 1b THOUT ROWIDU.... +| 3360: 1b 01 81 01 74 61 62 6c 65 74 32 5f 64 61 74 61 ....tablet2_data +| 3376: 74 32 5f 64 61 74 61 07 43 52 45 41 54 45 20 54 t2_data.CREATE T +| 3392: 41 42 4c 45 20 27 74 32 5f 64 61 74 61 27 28 69 ABLE 't2_data'(i +| 3408: 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 d INTEGER PRIMAR +| 3424: 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f Y KEY, block BLO +| 3440: 42 29 58 07 07 17 11 11 08 81 1d 74 61 62 6c 65 B)X........table +| 3456: 74 32 74 32 43 52 45 41 54 45 20 56 49 52 54 55 t2t2CREATE VIRTU +| 3472: 41 4c 20 54 41 42 4c 45 20 74 32 20 55 53 49 4e AL TABLE t2 USIN +| 3488: 47 20 66 74 73 35 28 27 61 27 2c 5b 62 5d 2c 22 G fts5('a',[b],. +| 3504: 63 22 2c 64 65 74 61 69 6c 3d 6e 6f 6e 65 2c 63 c.,detail=none,c +| 3520: 6f 6c 75 6d 6e 73 69 7a 65 3d 30 29 56 06 06 17 olumnsize=0)V... +| 3536: 1f 1f 01 7d 74 61 62 6c 65 74 31 5f 63 6f 6e 66 ....tablet1_conf +| 3552: 69 67 74 31 5f 63 6f 6e 66 69 67 06 43 52 45 41 igt1_config.CREA +| 3568: 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f 6e TE TABLE 't1_con +| 3584: 66 69 67 27 28 6b 20 50 52 49 4d 41 52 59 20 4b fig'(k PRIMARY K +| 3600: 45 59 2c 20 76 29 20 57 49 54 48 4f 55 54 20 52 EY, v) WITHOUT R +| 3616: 4f 57 49 44 5b 05 07 17 21 21 01 81 01 74 61 62 OWID[...!!...tab +| 3632: 6c 65 74 31 5f 64 6f 63 73 69 7a 65 74 31 5f 64 let1_docsizet1_d +| 3648: 6f 63 73 69 7a 65 05 43 52 45 41 54 45 20 54 41 ocsize.CREATE TA +| 3664: 42 4c 45 20 27 74 31 5f 64 6f 63 73 69 7a 65 27 BLE 't1_docsize' +| 3680: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d (id INTEGER PRIM +| 3696: 41 52 59 20 4b 45 59 2c 20 73 7a 20 42 4c 4f 42 ARY KEY, sz BLOB +| 3712: 29 5e 04 07 17 21 21 01 81 07 74 61 62 6c 65 74 )^...!!...tablet +| 3728: 31 5f 63 6f 6e 74 65 6e 74 74 31 5f 63 6f 6e 74 1_contentt1_cont +| 3744: 65 6e 74 04 43 52 45 41 54 45 20 54 41 42 4c 45 ent.CREATE TABLE +| 3760: 20 27 74 31 5f 63 6f 6e 74 65 6e 74 27 28 69 64 't1_content'(id +| 3776: 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 INTEGER PRIMARY +| 3792: 20 4b 45 59 2c 20 63 30 2c 20 63 31 2c 20 63 32 KEY, c0, c1, c2 +| 3808: 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65 74 )i.......-tablet +| 3824: 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45 41 1_idxt1_idx.CREA +| 3840: 54 45 20 54 41 42 4c 45 20 27 74 31 5f 69 64 78 TE TABLE 't1_idx +| 3856: 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20 70 '(segid, term, p +| 3872: 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45 59 gno, PRIMARY KEY +| 3888: 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20 57 (segid, term)) W +| 3904: 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07 17 ITHOUT ROWIDU... +| 3920: 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61 74 .....tablet1_dat +| 3936: 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45 20 at1_data.CREATE +| 3952: 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27 28 TABLE 't1_data'( +| 3968: 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 id INTEGER PRIMA +| 3984: 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42 4c RY KEY, block BL +| 4000: 4f 42 29 5b 01 07 17 11 11 08 81 23 74 61 62 6c OB)[.......#tabl +| 4016: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54 et1t1CREATE VIRT +| 4032: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49 UAL TABLE t1 USI +| 4048: 4e 47 20 66 74 73 35 28 61 2c 62 20 75 6e 69 6e NG fts5(a,b unin +| 4064: 64 65 78 65 64 2c 63 2c 74 6f 6b 65 6e 69 7a 65 dexed,c,tokenize +| 4080: 3d 22 70 6f 72 74 65 72 20 61 73 63 69 69 22 29 =.porter ascii.) +| page 2 offset 4096 +| 0: 0d 0f 68 00 05 0f 13 00 0f e6 0f 13 0f a8 0f 7c ..h............| +| 16: 0f 2a 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .*.............. +| 3856: 00 00 00 15 0a 03 00 30 00 00 00 00 01 03 03 00 .......0........ +| 3872: 03 01 01 01 02 01 01 03 01 01 37 8c 80 80 80 80 ..........7..... +| 3888: 01 03 00 74 00 00 00 2e 02 30 61 03 02 02 01 01 ...t.....0a..... +| 3904: 62 03 02 03 01 01 63 03 02 04 01 01 67 03 06 01 b.....c.....g... +| 3920: 02 02 01 01 68 03 06 01 02 03 01 01 69 03 06 01 ....h.......i... +| 3936: 02 04 04 06 06 06 08 08 0f ef 00 14 2a 00 00 00 ............*... +| 3952: 00 01 02 02 00 02 01 01 01 02 01 01 25 88 80 80 ............%... +| 3968: 80 80 01 03 00 50 00 00 00 1f 02 30 67 02 08 02 .....P.....0g... +| 3984: 01 02 02 01 01 68 02 08 03 01 02 03 01 01 69 02 .....h........i. +| 4000: 08 04 01 02 04 04 09 09 37 84 80 80 80 80 01 03 ........7....... +| 4016: 00 74 00 00 00 2e 02 30 61 01 02 02 01 01 62 01 .t.....0a.....b. +| 4032: 02 03 01 01 63 01 02 04 01 01 67 01 06 01 02 02 ....c.....g..... +| 4048: 01 01 68 01 06 01 02 03 01 01 69 01 06 01 02 04 ..h.......i..... +| 4064: 04 06 06 06 08 08 07 01 03 00 14 03 09 00 09 00 ................ +| 4080: 00 00 11 24 00 00 00 00 01 01 01 00 01 01 01 01 ...$............ +| page 3 offset 8192 +| 0: 0a 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 ................ +| 4064: 00 00 00 00 00 00 00 00 00 00 00 00 06 04 01 0c ................ +| 4080: 01 03 02 06 04 01 0c 01 02 02 05 04 09 0c 01 02 ................ +| page 4 offset 12288 +| 0: 0d 00 00 00 03 0f be 00 0f ea 0f d4 0f be 00 00 ................ +| 4016: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 14 03 ................ +| 4032: 05 00 17 17 17 61 20 62 20 63 67 20 68 20 69 67 .....a b cg h ig +| 4048: 20 68 20 69 14 02 05 00 17 17 17 67 20 68 20 69 h i.......g h i +| 4064: 61 20 62 20 63 67 20 68 20 69 14 01 05 00 17 17 a b cg h i...... +| 4080: 17 61 20 62 20 63 64 20 65 20 66 67 20 68 20 69 .a b cd e fg h i +| page 5 offset 16384 +| 0: 0d 00 00 00 03 0f e8 00 0f f8 0f f0 0f e8 00 00 ................ +| 4064: 00 00 00 00 00 00 00 00 06 03 03 00 12 03 00 03 ................ +| 4080: 06 02 03 00 12 03 00 03 06 01 03 00 12 03 00 03 ................ +| page 6 offset 20480 +| 0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 01 00 00 00 ................ +| 4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04 ........version. +| page 7 offset 24576 +| 0: 0d 00 00 00 03 0f 9e 00 0f e6 0f ef 00 00 00 00 ................ +| 3984: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 84 ..............A. +| 4000: 80 80 80 80 01 04 00 81 06 00 00 00 34 02 30 61 ............4.0a +| 4016: 01 01 01 01 01 62 01 01 01 01 01 63 01 01 01 01 .....b.....c.... +| 4032: 01 64 01 01 01 65 01 01 01 66 01 01 01 67 01 01 .d...e...f...g.. +| 4048: 01 01 01 68 01 01 01 01 01 69 01 01 01 04 06 06 ...h.....i...... +| 4064: 06 04 04 04 06 06 07 01 03 00 14 03 09 09 09 0f ................ +| 4080: 0a 03 00 24 00 00 00 00 01 01 01 00 01 01 01 01 ...$............ +| page 8 offset 28672 +| 0: 0a 00 00 00 01 0f fa 00 00 00 00 00 00 00 00 00 ................ +| 4080: 00 00 00 00 00 00 00 00 00 00 05 04 09 0c 01 12 ................ +| page 9 offset 32768 +| 0: 0d 00 00 00 03 0f be 00 0f ea 0f d4 0f be 00 00 ................ +| 4016: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 14 03 ................ +| 4032: 05 00 17 17 17 61 20 62 20 63 67 20 68 20 69 67 .....a b cg h ig +| 4048: 20 68 20 69 14 02 05 00 17 17 17 67 20 68 20 69 h i.......g h i +| 4064: 61 20 62 20 63 67 20 68 20 69 14 01 05 00 17 17 a b cg h i...... +| 4080: 17 61 20 62 20 63 64 20 65 20 66 67 20 68 20 69 .a b cd e fg h i +| page 10 offset 36864 +| 0: 0a 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 ................ +| 4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 00 00 00 00 ........vers.... +| end crash-f928a9c1ec68dd.db +}]} {} + +do_catchsql_test 80.1 { +SELECT snippet(rowid, -1, '.', '..', '[', '(]'),snippet(rowid, -1, '.', '.', '', '(]'), highlight(t1, 29, 1 , '') FROM t1('g+ h') WHERE rank MATCH 'bm25(1.0, 10)' ORDER BY NOT (SELECT 1 FROM t1('g+ æ') WHERE rank MATCH 'bm25(1.0, 10)' ORDER BY rank); +} {1 {database disk image is malformed}} + + sqlite3_fts5_may_be_corrupt 0 finish_test diff --git a/manifest b/manifest index fb6cbf47e4..ecda399fcd 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Another\scorruption\sdetection\scase\sin\sthe\ssqlite3BtreeIndexMoveto()\nlast\spage\soptimization. -D 2022-03-10T23:37:58.562 +C Fix\sa\scase\sin\sfts5\swhere\sa\scorrupt\sdatabase\scould\scause\sa\scrash. +D 2022-03-11T12:02:18.299 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -120,7 +120,7 @@ F ext/fts5/fts5_config.c 501e7d3566bc92766b0e11c0109a7c5a6146bc41144195459af5422 F ext/fts5/fts5_expr.c fcd0770d53028c2b53a15d0f53bf6d0e01b1bf3dd97630b9fedf0801f03aa3ec F ext/fts5/fts5_hash.c d4fb70940359f2120ccd1de7ffe64cc3efe65de9e8995b822cd536ff64c96982 F ext/fts5/fts5_index.c fdfbc8a62827ec1d1b6f207a1e59c1c4986c3ce245592b5128ffe738867cfcd1 -F ext/fts5/fts5_main.c 7c6092a53e6802962fa07b0fad3e61cb077b6c98b74b727d8d44ac2cf63bd914 +F ext/fts5/fts5_main.c 6078ae86d3b813753a4f1201054550aff21a3f660e97b30f200d2b1472874151 F ext/fts5/fts5_storage.c 76c6085239eb44424004c022e9da17a5ecd5aaec859fba90ad47d3b08f4c8082 F ext/fts5/fts5_tcl.c b1445cbe69908c411df8084a10b2485500ac70a9c747cdc8cda175a3da59d8ae F ext/fts5/fts5_test_mi.c 08c11ec968148d4cb4119d96d819f8c1f329812c568bac3684f5464be177d3ee @@ -160,7 +160,7 @@ F ext/fts5/test/fts5connect.test 08030168fc96fc278fa81f28654fb7e90566f33aff269c0 F ext/fts5/test/fts5content.test 213506436fb2c87567b8e31f6d43ab30aab99354cec74ed679f22aad0cdbf283 F ext/fts5/test/fts5corrupt.test 77ae6f41a7eba10620efb921cf7dbe218b0ef232b04519deb43581cb17a57ebe F ext/fts5/test/fts5corrupt2.test 7453752ba12ce91690c469a6449d412561cc604b1dec994e16ab132952e7805f -F ext/fts5/test/fts5corrupt3.test 0e473620582a53ac61f468f364db8a151c1e18d2a879b16439d172c12c4c9828 +F ext/fts5/test/fts5corrupt3.test 7da9895dafa404efd20728f66ff4b94399788bdc042c36fe2689801bba2ccd78 F ext/fts5/test/fts5corrupt4.test f4c08e2182a48d8b70975fd869ee5391855c06d8a0ff87b6a2529e7c5a88a1d3 F ext/fts5/test/fts5corrupt5.test 550d0884c14424f9acad051a741f1dd99ec9342277d938e91ff3daf9123d1209 F ext/fts5/test/fts5corrupt6.test bf8eeae07825b088b9665d9d8e4accbd8dc9bf3cb85b6c64cf6c9e18ccc420a4 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 4ef19ba9b5cbda435c0bb9f2faddf8f7fac5d51399ff69bd049571c2ca3d9357 -R 9eddff8d6613df9db13f90a975151eff -U drh -Z 14dbf23053f6e391019ac64193a5c1f0 +P 531e6ad0389c6c820bb8c64db5049fb6b0bffd30bd394fd8ee7412959b1752e2 +R b26ba835a81a27a8d4e88d89ca2bec5f +U dan +Z 72823c7752498ddb91913ba2db429eed # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index c30bb8df66..ea9149f6cc 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -531e6ad0389c6c820bb8c64db5049fb6b0bffd30bd394fd8ee7412959b1752e2 \ No newline at end of file +5e95df261cce275adb5b2226e9584f4c389bb0d53c3b4feafd5a14be8d02ce63 \ No newline at end of file From 605137aae612a2b5bde0620eda7b976af7ba2112 Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 11 Mar 2022 14:20:06 +0000 Subject: [PATCH 73/75] Fix a harmless compiler warning and restore performance in the sqlite3BtreeIndexMoveto() last-page optimization. FossilOrigin-Name: 8b032293b384c3728c27b0658ee634c028c0d231d067de8b747d2e9e4ae704a7 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/btree.c | 7 ++++--- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index ecda399fcd..083d0d7bc0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\scase\sin\sfts5\swhere\sa\scorrupt\sdatabase\scould\scause\sa\scrash. -D 2022-03-11T12:02:18.299 +C Fix\sa\sharmless\scompiler\swarning\sand\srestore\sperformance\sin\sthe\nsqlite3BtreeIndexMoveto()\slast-page\soptimization. +D 2022-03-11T14:20:06.914 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -492,7 +492,7 @@ F src/auth.c f4fa91b6a90bbc8e0d0f738aa284551739c9543a367071f55574681e0f24f8cf F src/backup.c a2891172438e385fdbe97c11c9745676bec54f518d4447090af97189fd8e52d7 F src/bitvec.c 7c849aac407230278445cb069bebc5f89bf2ddd87c5ed9459b070a9175707b3d F src/btmutex.c 8acc2f464ee76324bf13310df5692a262b801808984c1b79defb2503bbafadb6 -F src/btree.c 961ae88f10541fa0cb6fb0cffedfbdfb7183041b66d99c57544b7e9fc1214f8f +F src/btree.c ddc3cec12a39675e10066c008aac7925b26c74f78c46b849b2416ca45701a313 F src/btree.h 74d64b8f28cfa4a894d14d4ed64fa432cd697b98b61708d4351482ae15913e22 F src/btreeInt.h 8ce1332edd89dfd2461d561ac10a0ab5601c8e06200cb5230596c3caaf54482e F src/build.c a0cc68fe8172c0a31b54576f9c6c0fe6f7c82b1b5e1387afdd6a5a13132bc131 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 531e6ad0389c6c820bb8c64db5049fb6b0bffd30bd394fd8ee7412959b1752e2 -R b26ba835a81a27a8d4e88d89ca2bec5f -U dan -Z 72823c7752498ddb91913ba2db429eed +P 5e95df261cce275adb5b2226e9584f4c389bb0d53c3b4feafd5a14be8d02ce63 +R 5ab1a745e3278dea812b08524563aa85 +U drh +Z e7eed47d8c0d1a5c83108e7c1f88ee07 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index ea9149f6cc..a825781807 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5e95df261cce275adb5b2226e9584f4c389bb0d53c3b4feafd5a14be8d02ce63 \ No newline at end of file +8b032293b384c3728c27b0658ee634c028c0d231d067de8b747d2e9e4ae704a7 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index a41778761a..2e87707072 100644 --- a/src/btree.c +++ b/src/btree.c @@ -5830,18 +5830,19 @@ int sqlite3BtreeIndexMoveto( int c; if( pCur->ix==pCur->pPage->nCell-1 && (c = indexCellCompare(pCur, pCur->ix, pIdxKey, xRecordCompare))<=0 + && pIdxKey->errCode==SQLITE_OK ){ *pRes = c; - if( pIdxKey->errCode ) return SQLITE_CORRUPT_BKPT; return SQLITE_OK; /* Cursor already pointing at the correct spot */ } if( pCur->iPage>0 - && (c = indexCellCompare(pCur, 0, pIdxKey, xRecordCompare))<=0 + && indexCellCompare(pCur, 0, pIdxKey, xRecordCompare)<=0 + && pIdxKey->errCode==SQLITE_OK ){ pCur->curFlags &= ~BTCF_ValidOvfl; - if( pIdxKey->errCode ){ *pRes = 0; return SQLITE_CORRUPT_BKPT; } goto bypass_moveto_root; /* Start search on the current page */ } + pIdxKey->errCode = SQLITE_OK; } rc = moveToRoot(pCur); From 27e456458e7bcae3c77979b3c53f690a2fb7d8b7 Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 11 Mar 2022 15:16:50 +0000 Subject: [PATCH 74/75] Fix a harmless compiler warning. FossilOrigin-Name: 5d739aff96c47146dba72fd76fed62d4e43ded09b32246fdde13d5467f713135 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/sqliteInt.h | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 083d0d7bc0..6305afd2c4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sharmless\scompiler\swarning\sand\srestore\sperformance\sin\sthe\nsqlite3BtreeIndexMoveto()\slast-page\soptimization. -D 2022-03-11T14:20:06.914 +C Fix\sa\sharmless\scompiler\swarning. +D 2022-03-11T15:16:50.449 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -557,7 +557,7 @@ F src/shell.c.in 69d1e59da4881f096ab47fbd3e6d99794f3e4a43f41fd9e4d2e845c9b8d20fd F src/sqlite.h.in b93deee892f1bc4030e5c8712df9e21d786a1bf8e921ab8dc987eaf1e44c676f F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h a95cb9ed106e3d39e2118e4dcc15a14faec3fa50d0093425083d340d9dfd96e6 -F src/sqliteInt.h 7ab4575383df08f356ac2d60cee07da5d6c3c20488b5ca4d79f41664b0f93f0b +F src/sqliteInt.h 2ce7d868630ccd70ffd4b15d46b59ccf7daf89198993b62ed6e4a165d3511280 F src/sqliteLimit.h d7323ffea5208c6af2734574bae933ca8ed2ab728083caa117c9738581a31657 F src/status.c 4b8bc2a6905163a38b739854a35b826c737333fab5b1f8e03fa7eb9a4799c4c1 F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 5e95df261cce275adb5b2226e9584f4c389bb0d53c3b4feafd5a14be8d02ce63 -R 5ab1a745e3278dea812b08524563aa85 +P 8b032293b384c3728c27b0658ee634c028c0d231d067de8b747d2e9e4ae704a7 +R ffc0ccb4d1ca145963d18f87b727b980 U drh -Z e7eed47d8c0d1a5c83108e7c1f88ee07 +Z 8ce388e37bd47e2c9feee08884bf9baa # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index a825781807..5e9ebf06da 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8b032293b384c3728c27b0658ee634c028c0d231d067de8b747d2e9e4ae704a7 \ No newline at end of file +5d739aff96c47146dba72fd76fed62d4e43ded09b32246fdde13d5467f713135 \ No newline at end of file diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 90a7b6d6a4..0f4077aae8 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1103,7 +1103,7 @@ struct BusyHandler { ** pointer will work here as long as it is distinct from SQLITE_STATIC ** and SQLITE_TRANSIENT. */ -#define SQLITE_DYNAMIC ((sqlite3_destructor_type)sqlite3OomFault) +#define SQLITE_DYNAMIC ((sqlite3_destructor_type)sqlite3OomClear) /* ** When SQLITE_OMIT_WSD is defined, it means that the target platform does From 5a1f761218a1fdb581262685902680db2c222b5b Mon Sep 17 00:00:00 2001 From: drh <> Date: Fri, 11 Mar 2022 15:42:05 +0000 Subject: [PATCH 75/75] Add a comment linking a part of the UPDATE constraint checking code to one of the corresponding TH3 test cases. FossilOrigin-Name: 0606e8e93edb5de4d154f377dbf91f15295d25ca9013c0f1612ae6d63a0139ea --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/insert.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 6305afd2c4..32242ebdcf 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sharmless\scompiler\swarning. -D 2022-03-11T15:16:50.449 +C Add\sa\scomment\slinking\sa\spart\sof\sthe\sUPDATE\sconstraint\schecking\scode\sto\none\sof\sthe\scorresponding\sTH3\stest\scases. +D 2022-03-11T15:42:05.493 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -512,7 +512,7 @@ F src/hash.c 8d7dda241d0ebdafb6ffdeda3149a412d7df75102cecfc1021c98d6219823b19 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h cb1d7e3e1ed94b7aa6fde95ae2c2daccc3df826be26fc9ed7fd90d1750ae6144 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 -F src/insert.c 9fbf8704562fe17e442c16b7f60d3d91101ea69fc45c2bce96ee6cb982e86d2f +F src/insert.c d9fd15b2bd030cb9bd3119b301dbdb2912f16fff76c6e3797296cfd1500faaf4 F src/json.c 24fcd7f5f9080b04b89722c343010d390f85e55b2ab560046cb567c9dd640f62 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c aa919a6a7884f8b34d7b791841b24d14b1b0ab43f45b3940f4851043b2855c0c @@ -1944,8 +1944,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 8b032293b384c3728c27b0658ee634c028c0d231d067de8b747d2e9e4ae704a7 -R ffc0ccb4d1ca145963d18f87b727b980 +P 5d739aff96c47146dba72fd76fed62d4e43ded09b32246fdde13d5467f713135 +R fe298d8fac60be400e4a8c74276154d9 U drh -Z 8ce388e37bd47e2c9feee08884bf9baa +Z 318438bd874dd4bc6c146383b35f409b # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 5e9ebf06da..5a00a628e2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5d739aff96c47146dba72fd76fed62d4e43ded09b32246fdde13d5467f713135 \ No newline at end of file +0606e8e93edb5de4d154f377dbf91f15295d25ca9013c0f1612ae6d63a0139ea \ No newline at end of file diff --git a/src/insert.c b/src/insert.c index de01be3ba1..9b4f0b2201 100644 --- a/src/insert.c +++ b/src/insert.c @@ -2282,7 +2282,7 @@ void sqlite3GenerateConstraintChecks( if( isUpdate ){ /* If currently processing the PRIMARY KEY of a WITHOUT ROWID ** table, only conflict if the new PRIMARY KEY values are actually - ** different from the old. + ** different from the old. See TH3 withoutrowid04.test. ** ** For a UNIQUE index, only conflict if the PRIMARY KEY values ** of the matched index row are different from the original PRIMARY