aboutsummaryrefslogtreecommitdiff
path: root/src/insert.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2017-01-25 14:58:27 +0000
committerdrh <drh@noemail.net>2017-01-25 14:58:27 +0000
commit585ce1923c7c45bd0bf4da4ad957b6421785d1f0 (patch)
treec0d25427ded534238ea457702daf233c4728759b /src/insert.c
parent7888d14caa853827e60bac132ffcb0c6b25036c8 (diff)
downloadsqlite-585ce1923c7c45bd0bf4da4ad957b6421785d1f0.tar.gz
sqlite-585ce1923c7c45bd0bf4da4ad957b6421785d1f0.zip
Experimental enhancement to automatically trim NULL values from the end of
records, for a reduced disk footprint. This change also involves increasing the P5 operand from 8 to 16 bits. FossilOrigin-Name: 118ded403b95050b74ae2b03919c43d614094a32
Diffstat (limited to 'src/insert.c')
-rw-r--r--src/insert.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/insert.c b/src/insert.c
index 93c22ae3f..5bb8ba2ff 100644
--- a/src/insert.c
+++ b/src/insert.c
@@ -1669,6 +1669,23 @@ void sqlite3GenerateConstraintChecks(
}
/*
+** 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);
+}
+
+/*
** This routine generates code to finish the INSERT or UPDATE operation
** that was started by a prior call to sqlite3GenerateConstraintChecks.
** A consecutive range of registers starting at regNewData contains the
@@ -1727,6 +1744,7 @@ void sqlite3CompleteInsertion(
regData = regNewData + 1;
regRec = sqlite3GetTempReg(pParse);
sqlite3VdbeAddOp3(v, OP_MakeRecord, regData, pTab->nCol, regRec);
+ sqlite3SetMakeRecordP5(v, pTab);
if( !bAffinityDone ){
sqlite3TableAffinity(v, pTab, 0);
sqlite3ExprCacheAffinityChange(pParse, regData, pTab->nCol);