From: drh Date: Wed, 25 Jan 2017 20:55:11 +0000 (+0000) Subject: Trim NULL values off the end of records when the SQLITE_ENABLE_TRIM_NULLS X-Git-Tag: version-3.17.0~77 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d447dced96050d3a5cc77a53eea8473612df18a9;p=thirdparty%2Fsqlite.git Trim NULL values off the end of records when the SQLITE_ENABLE_TRIM_NULLS compile-time option is used. Increase the size of the P5 operand to 16 bits. Fix a problem with short records in the sessions extension. FossilOrigin-Name: 4801bd59a01dcc11a3eb9e776e7599b36f162d2a --- d447dced96050d3a5cc77a53eea8473612df18a9 diff --cc manifest index edea9fbb44,e160f9e3f6..b6cd8613f4 --- a/manifest +++ b/manifest @@@ -1,5 -1,5 +1,5 @@@ - C Ensure\sthat\ssqlite3_blob_reopen()\scorrectly\shandles\sshort\srows.\s\nFix\sfor\sticket\s[e6e962d6b0f06f46e]. - D 2017-01-25T14:38:19.847 -C Fix\sanother\spre-update\shook\sissue,\sthis\stime\sin\ssqlite3preupdate_old(). -D 2017-01-25T18:53:27.729 ++C Trim\sNULL\svalues\soff\sthe\send\sof\srecords\swhen\sthe\sSQLITE_ENABLE_TRIM_NULLS\ncompile-time\soption\sis\sused.\s\sIncrease\sthe\ssize\sof\sthe\sP5\soperand\sto\s16\sbits.\nFix\sa\sproblem\swith\sshort\srecords\sin\sthe\ssessions\sextension. ++D 2017-01-25T20:55:11.502 F Makefile.in 5f415e7867296d678fed2e6779aea10c1318b4bc F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc b8ca53350ae545e3562403d5da2a69cec79308da @@@ -352,7 -352,7 +352,7 @@@ F src/hash.c 63d0ee752a3b92d4695b2b1f52 F src/hash.h ab34c5c54a9e9de2e790b24349ba5aab3dbb4fd4 F src/hwtime.h 747c1bbe9df21a92e9c50f3bbec1de841dc5e5da F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 - F src/insert.c 05e47e2de7b712a3a4148cd469e5f60873f5ef13 -F src/insert.c 07ccec2c1fb32dd2c5fbfd63426e98dc2a79a0fa ++F src/insert.c 8183e1778ec42d26732bec8c98aeffa8af13038f F src/legacy.c 75d3023be8f0d2b99d60f905090341a03358c58e F src/loadext.c a68d8d1d14cf7488bb29dc5311cb1ce9a4404258 F src/main.c e207b81542d13b9f13d61e78ca441f9781f055b0 @@@ -395,7 -395,7 +395,7 @@@ F src/shell.c 59de9acab4423a536277653f2 F src/sqlite.h.in 1971ab9709e010d52a02a1a6276d5a2f9b947476 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 8648034aa702469afb553231677306cc6492a1ae - F src/sqliteInt.h 525c061ae9aafc8d4720a018d82f0936d9eee5ab -F src/sqliteInt.h dc587b0727c2bc888d78d200d891620080567691 ++F src/sqliteInt.h 341ce9e5b0397771fa6bd9dadb8ef4cbbd6224d0 F src/sqliteLimit.h c0373387c287c8d0932510b5547ecde31b5da247 F src/status.c a9e66593dfb28a9e746cba7153f84d49c1ddc4b1 F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34 @@@ -457,11 -457,11 +457,11 @@@ F src/update.c b356b29d04c71f33c779f2cb F src/utf.c 699001c79f28e48e9bcdf8a463da029ea660540c F src/util.c a88b0466fddf445ce752226d4698ca3faada620a F src/vacuum.c 33c174b28886b2faf26e503b5a49a1c01a9b1c16 - F src/vdbe.c c7add5978cb84ae3a7bcb16f8b56cb3bbdf04b7e - F src/vdbe.h b0866e4191f096f1c987a84b042c3599bdf5423b -F src/vdbe.c b1f2448184fa58c66fc94591004b1258964ef9da ++F src/vdbe.c 1fa3e8f3ee1cdfc56d9559bca9ca2c84e4a398be + F src/vdbe.h 59998ffd71d7caa8886bc78dafaf8caeccd4c13c F src/vdbeInt.h 281cb70332dc8b593b8c7afe776f3a2ba7d4255e - F src/vdbeapi.c d6ebaa465f070eb1af8ba4e7b34583ece87bdd24 - F src/vdbeaux.c 35c9a9908174e5a26c96d15e1f98214814a39147 + F src/vdbeapi.c 7a65f10684982daecfce50f557f2632b7f20b198 + F src/vdbeaux.c 7c19b78999faae833e1be66dfa4e3deaf334d739 F src/vdbeblob.c 2b3d1ad915dbe5dc92c48759dc18fa8c697e78e5 F src/vdbemem.c 3b5a9a5b375458d3e12a50ae1aaa41eeec2175fd F src/vdbesort.c eda25cb2d1727efca6f7862fea32b8aa33c0face @@@ -1547,8 -1547,7 +1547,8 @@@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a9 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 - P 0803390c152141c9ab4e7a28406b2a5d72a5c2fa 57d8dad35c2a9ab635e954dce7f3986ae1ca8ed2 - R d15a5cee6a51c7118a4d78b7d0cbd2de - T +closed 57d8dad35c2a9ab635e954dce7f3986ae1ca8ed2 -P f66614dc78e32d2d369518200b3322cd97990ffe -R b9395615953abce115528c9bb805cca4 -U dan -Z c5b3bc3bd2550d6ddb6d6d5566bf3773 ++P 8cd1a4451cce1fe28f462800e2be1dee1735c0d0 c7651d21bfdfd9b8cf04b26e0264bc58c03d247f ++R 97e00d1e041d69da0e0a6af8a75ee1a0 ++T +closed c7651d21bfdfd9b8cf04b26e0264bc58c03d247f +U drh - Z f9af43b146da8d8246d0b97014ae0d3a ++Z 857c1b54405ac0784389a22078eb728f diff --cc manifest.uuid index d15e64c7de,5de3845661..854e8f8a47 --- a/manifest.uuid +++ b/manifest.uuid @@@ -1,1 -1,1 +1,1 @@@ - 8cd1a4451cce1fe28f462800e2be1dee1735c0d0 -c7651d21bfdfd9b8cf04b26e0264bc58c03d247f ++4801bd59a01dcc11a3eb9e776e7599b36f162d2a diff --cc src/insert.c index 93c22ae3f5,5bb8ba2ff9..5370ef77ed --- a/src/insert.c +++ b/src/insert.c @@@ -1668,6 -1668,23 +1668,25 @@@ void sqlite3GenerateConstraintChecks VdbeModuleComment((v, "END: GenCnstCks(%d)", seenReplace)); } ++#ifdef SQLITE_ENABLE_NULL_TRIM + /* + ** Change the P5 operand on the last opcode (which should be an OP_MakeRecord) + ** to be the number of columns in table pTab that must not be NULL-trimmed. + ** + ** Or if no columns of pTab may be NULL-trimmed, leave P5 at zero. + */ + void sqlite3SetMakeRecordP5(Vdbe *v, Table *pTab){ + u16 i; + + /* Records with omitted columns are only allowed for schema format + ** version 2 and later (SQLite version 3.1.4, 2005-02-20). */ + if( pTab->pSchema->file_format<2 ) return; + + for(i=pTab->nCol; i>1 && pTab->aCol[i-1].pDflt==0; i--){} + sqlite3VdbeChangeP5(v, i); + } ++#endif + /* ** This routine generates code to finish the INSERT or UPDATE operation ** that was started by a prior call to sqlite3GenerateConstraintChecks. diff --cc src/sqliteInt.h index 6344cac5f1,ceae4dcb1f..7ea8748b73 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@@ -3790,6 -3790,7 +3790,11 @@@ int sqlite3GenerateIndexKey(Parse*, Ind void sqlite3ResolvePartIdxLabel(Parse*,int); void sqlite3GenerateConstraintChecks(Parse*,Table*,int*,int,int,int,int, u8,u8,int,int*,int*); -void sqlite3SetMakeRecordP5(Vdbe*,Table*); ++#ifdef SQLITE_ENABLE_NULL_TRIM ++ void sqlite3SetMakeRecordP5(Vdbe*,Table*); ++#else ++# define sqlite3SetMakeRecordP5(A,B) ++#endif void sqlite3CompleteInsertion(Parse*,Table*,int,int,int,int*,int,int,int); int sqlite3OpenTableAndIndices(Parse*, Table*, int, u8, int, u8*, int*, int*); void sqlite3BeginWriteOperation(Parse*, int, int); diff --cc src/vdbe.c index cbb7867512,88010a9a6f..6838acccd5 --- a/src/vdbe.c +++ b/src/vdbe.c @@@ -2777,6 -2777,18 +2777,20 @@@ case OP_MakeRecord: }while( zAffinity[0] ); } ++#ifdef SQLITE_ENABLE_NULL_TRIM + /* NULLs can be safely trimmed from the end of the record, as long as + ** as the schema format is 2 or more and none of the omitted columns + ** have a non-NULL default value. Also, the record must be left with + ** at least one field. If P5>0 then it will be one more than the + ** index of the right-most column with a non-NULL default value */ + if( pOp->p5 ){ + while( (pLast->flags & MEM_Null)!=0 && nField>pOp->p5 ){ + pLast--; + nField--; + } + } ++#endif + /* Loop through the elements that will make up the record to figure ** out how much space is required for the new record. */