-C Fix\sthe\sxfer\soptimization\sfor\sgenerated\scolumns,\sso\sthat\sVACUUM\sworks\sagain.
-D 2019-10-17T16:16:34.306
+C Some\s(but\snot\sall)\sINSERT\sand\sUPDATE\sstatements\snow\swork\sfor\sSTORED\scolumns.
+D 2019-10-17T17:54:05.733
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
F src/btree.c a8a9c2ce62bdf54c8cf9795143d7cb10b7473a1230a0572f702d061ffcceefe5
F src/btree.h f27a33c49280209a93385e218306c4ee5f46ba8d7649d2f81a7166b282232484
F src/btreeInt.h 91806f01fd1145a9a86ba3042f25c38d8faf6002701bf5e780742cf88bcff437
-F src/build.c 6cb40a36b3ec6a4b2dc36e0bd53e42ad448700c48b419569eae711cde4b175d3
+F src/build.c efbcb2e78a578bca138ea2d8a4b3ec44a6fef2630a1b79fb5ed619abd08068e5
F src/callback.c 25dda5e1c2334a367b94a64077b1d06b2553369f616261ca6783c48bcb6bda73
F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e
F src/ctime.c 1b0724e66f95f33b160b1af85caaf9cceb325d22abf39bd24df4f54a73982251
F src/hash.h 9d56a9079d523b648774c1784b74b89bd93fac7b365210157482e4319a468f38
F src/hwtime.h 747c1bbe9df21a92e9c50f3bbec1de841dc5e5da
F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71
-F src/insert.c 608b6d99b95f95a657b0fd13048ca002dfa8f1c212771c56bca510f1776f583d
+F src/insert.c 2402847e031cb9b1e95a776481706a38833339be1142e8bdc78fd59e65d7c87c
F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
F src/loadext.c 4ddc65ae13c0d93db0ceedc8b14a28c8c260513448b0eb8c5a2ac375e3b6a85d
F src/main.c 3e01f6a1c96643381b5f9d79e4ff7f2520bc5712197746fb0852283e78cccf66
F src/pcache.c 385ff064bca69789d199a98e2169445dc16e4291fa807babd61d4890c3b34177
F src/pcache.h 4f87acd914cef5016fae3030343540d75f5b85a1877eed1a2a19b9f284248586
F src/pcache1.c 62714cbd1b7299a6e6a27a587b66b4fd3a836a84e1181e7f96f5c34a50917848
-F src/pragma.c 61abcb6d9f80d06ed3b0d0843a7cef32e96a569a27b94ebfd764dc6c1ce1cd1d
+F src/pragma.c c04340e810dd5d6d094f7fffa9278e9183ffd052f91b2dc20f83aea471f8756a
F src/pragma.h 40962d65b645bb3f08c1f4c456effd01c6e7f073f68ea25177e0c95e181cff75
F src/prepare.c 6049beb71385f017af6fc320d2c75a4e50b75e280c54232442b785fbb83df057
F src/printf.c 9be6945837c839ba57837b4bc3af349eba630920fa5532aa518816defe42a7d4
F src/sqlite.h.in 5725a6b20190a1e8d662077a1c1c8ea889ad7be90dd803f914c2de226f5fe6ab
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
F src/sqlite3ext.h cef696ce3293242c67b2339763608427bf72ee66f1f3a05389ac2a7b46001c31
-F src/sqliteInt.h ecade7aec917068cbbc96505eed645419e07799d91052926d418dd256d60b72d
+F src/sqliteInt.h 8af46452e819f6304cc39922eb9f2153a53da44dcedae78cd59ae08e7ca7b164
F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b
F src/status.c 46e7aec11f79dad50965a5ca5fa9de009f7d6bde08be2156f1538a0a296d4d0e
F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34
F src/tokenize.c d3615f0cbe4db5949503bf5916f3cd4fa5de855d5b4ef560f3b6dd5629423a1e
F src/treeview.c fddeb413159c3eeeaea3f496172f121cf3695606c461dc4e6dcee51417952df5
F src/trigger.c 845ccc08f60716c58aa28fe6470385c18ef8c4e1d88c93dcf449bc13d464eb2e
-F src/update.c ef3e261b43cc417e4d7e59ccf4fdae1b86d9bc1879d83820253e4a2105a63278
+F src/update.c a66b56e5024541d2dd6794d0800b14f7a2cc968f6a1fdf84df2cb44048b35058
F src/upsert.c 710c91bb13e3c3fed5b6fe17cb13e09560bdd003ad8b8c51e6b16c80cfc48b10
F src/utf.c 2f0fac345c7660d5c5bd3df9e9d8d33d4c27f366bcfb09e07443064d751a0507
F src/util.c 10d910e04a4f3842042485e0df01a484f57f912c10b60b3a09ccddd5019bd138
F src/vdbemem.c d8e10d1773806105e62094c4ede0a4684f46caaf07667a45e6d461e94306b530
F src/vdbesort.c a3be032cc3fee0e3af31773af4a7a6f931b7230a34f53282ccf1d9a2a72343be
F src/vdbetrace.c fa3bf238002f0bbbdfb66cc8afb0cea284ff9f148d6439bc1f6f2b4c3b7143f0
-F src/vtab.c 27998d5d738069f2cee981620a1f224558494ce06799d14dcb5e6f34b4cdcdd1
+F src/vtab.c 108f79166d4a232a8bfb9d46e2fbec191f83a87fe97f7b93fc4de976c3fa3434
F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9
F src/wal.c bbd6838bd79c0a32144d482fb0b6a9d2d1a252fb3b16d5005ec30f2f80413b0d
F src/wal.h 606292549f5a7be50b6227bd685fa76e3a4affad71bb8ac5ce4cb5c79f6a176a
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P c21959d4eb5d742a097a98e1874c0bf132dc962a97a65be1ab22d6ca3cf2b261
-R 6aa9977527f4824498ace24e1ab11d24
+P 8f67b89b04622c1509dc102a83be7a80057dc791625804fc2c294089c98b97e4
+R f8d479928377499694b42044f6469958
U drh
-Z 5abd38c0a3e4636bc9783adf5f0cb09c
+Z aaf8a72afb67fb32144fc0364d09d870
-8f67b89b04622c1509dc102a83be7a80057dc791625804fc2c294089c98b97e4
\ No newline at end of file
+fe7517bf4d360597576ab9aba29627d7926d23f2bbbfb3e7bf4d32761617574c
\ No newline at end of file
goto generated_error;
}
}
- pTab->nVCol++;
+ if( eType==COLFLAG_VIRTUAL ) pTab->nVCol++;
pCol->colFlags |= eType;
+ assert( TF_HasVirtual==COLFLAG_VIRTUAL );
+ assert( TF_HasStored==COLFLAG_STORED );
+ pTab->tabFlags |= eType;
pCol->pDflt = sqlite3ExprDup(pParse->db, pExpr, 0);
goto generated_done;
}
#endif /* !defined(SQLITE_OMIT_CHECK) */
#ifndef SQLITE_OMIT_GENERATED_COLUMNS
- if( p->nVCol ){
+ if( p->tabFlags & (TF_HasVirtual|TF_HasStored) ){
int ii;
for(ii=0; ii<p->nCol; ii++){
if( (p->aCol[ii].colFlags & (COLFLAG_STORED|COLFLAG_VIRTUAL))!=0 ){
return 0;
}
+#ifndef SQLITE_OMIT_GENERATED_COLUMNS
+/*
+** All regular columns for table pTab have been puts into registers
+** starting with iRegStore. The registers that correspond to STORED
+** columns have not been initialized. This routine goes back and computes
+** the values for STORED columns based on the previously computed normal
+** columns.
+*/
+void sqlite3ComputeStoredColumns(
+ Parse *pParse, /* Parsing context */
+ int iRegStore, /* Register holding the first column */
+ Table *pTab /* The table */
+){
+ int i;
+ pParse->iSelfTab = -iRegStore;
+ for(i=0; i<pTab->nCol; i++, iRegStore++){
+ u32 colFlags = pTab->aCol[i].colFlags;
+ if( (colFlags & COLFLAG_VIRTUAL)!=0 ){
+ /* Virtual columns are no stored */
+ iRegStore--;
+ }else if( (colFlags & COLFLAG_STORED)!=0 ){
+ /* Stored columns are handled on the second pass */
+ sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, iRegStore);
+ }
+ }
+ pParse->iSelfTab = 0;
+}
+#endif /* SQLITE_OMIT_GENERATED_COLUMNS */
+
+
#ifndef SQLITE_OMIT_AUTOINCREMENT
/*
** Locate or create an AutoincInfo structure associated with table pTab
/* Virtual columns are no stored */
iRegStore--;
continue;
- }else if( (colFlags & COLFLAG_STORED)!=0 || pColumn==0 ){
- /* Stored columns get the default value. Also hidden columns
- ** that are not explicitly named in the INSERT */
+ }else if( (colFlags & COLFLAG_STORED)!=0 ){
+ /* Stored columns are handled on the second pass */
+ continue;
+ }else if( pColumn==0 ){
+ /* Hidden columns that are not explicitly named in the INSERT */
sqlite3ExprCodeFactorable(pParse, pTab->aCol[i].pDflt, iRegStore);
continue;
}
}
}
+#ifndef SQLITE_OMIT_GENERATED_COLUMNS
+ /* Compute the new value for STORED columns after all other
+ ** columns have already been computed */
+ if( pTab->tabFlags & TF_HasStored ){
+ sqlite3ComputeStoredColumns(pParse, regRowid+1, pTab);
+ }
+#endif
+
/* Generate code to check constraints and generate index keys and
** do the insertion.
*/
}
if( pCol->colFlags & COLFLAG_VIRTUAL ){
isHidden = 2; /* GENERATED ALWAYS AS ... VIRTUAL */
- }else if( pCol->colFlags & COLFLAG_VIRTUAL ){
+ }else if( pCol->colFlags & COLFLAG_STORED ){
isHidden = 3; /* GENERATED ALWAYS AS ... STORED */
- }else{
+ }else{ assert( pCol->colFlags & COLFLAG_HIDDEN );
isHidden = 1; /* HIDDEN */
}
}
** followed by non-hidden columns. Example: "CREATE VIRTUAL TABLE x USING
** vtab1(a HIDDEN, b);". Since "b" is a non-hidden column but "a" is hidden,
** the TF_OOOHidden attribute would apply in this case. Such tables require
-** special handling during INSERT processing.
+** special handling during INSERT processing. The "OOO" means "Out Of Order".
+**
+** Constraints:
+**
+** TF_HasVirtual == COLFLAG_Virtual
+** TF_HasStored == COLFLAG_Stored
*/
#define TF_Readonly 0x0001 /* Read-only system table */
#define TF_Ephemeral 0x0002 /* An ephemeral table */
#define TF_HasPrimaryKey 0x0004 /* Table has a primary key */
#define TF_Autoincrement 0x0008 /* Integer primary key is autoincrement */
#define TF_HasStat1 0x0010 /* nRowLogEst set from sqlite_stat1 */
-#define TF_WithoutRowid 0x0020 /* No rowid. PRIMARY KEY is the key */
-#define TF_NoVisibleRowid 0x0040 /* No user-visible "rowid" column */
-#define TF_OOOHidden 0x0080 /* Out-of-Order hidden columns */
+#define TF_HasVirtual 0x0020 /* Has one or more VIRTUAL columns */
+#define TF_HasStored 0x0040 /* Has one or more STORED columns */
+#define TF_WithoutRowid 0x0080 /* No rowid. PRIMARY KEY is the key */
#define TF_StatsUsed 0x0100 /* Query planner decisions affected by
** Index.aiRowLogEst[] values */
-#define TF_HasNotNull 0x0200 /* Contains NOT NULL constraints */
-#define TF_Shadow 0x0400 /* True for a shadow table */
+#define TF_NoVisibleRowid 0x0200 /* No user-visible "rowid" column */
+#define TF_OOOHidden 0x0400 /* Out-of-Order hidden columns */
+#define TF_HasNotNull 0x0800 /* Contains NOT NULL constraints */
+#define TF_Shadow 0x1000 /* True for a shadow table */
/*
** Test to see whether or not a table is a virtual table. This is
# define sqlite3AutoincrementEnd(X)
#endif
void sqlite3Insert(Parse*, SrcList*, Select*, IdList*, int, Upsert*);
+#ifndef SQLITE_OMIT_GENERATED_COLUMNS
+ void sqlite3ComputeStoredColumns(Parse*, int, Table*);
+#endif
void *sqlite3ArrayAllocate(sqlite3*,void*,int,int*,int*);
IdList *sqlite3IdListAppend(Parse*, IdList*, Token*);
int sqlite3IdListIndex(IdList*,const char*);
for(i=0, k=regNew; i<pTab->nCol; i++, k++){
if( i==pTab->iPKey ){
sqlite3VdbeAddOp2(v, OP_Null, 0, k);
- }else if( (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)!=0 ){
- k--;
+ }else if( (pTab->aCol[i].colFlags & COLFLAG_GENERATED)!=0 ){
+ if( pTab->aCol[i].colFlags & COLFLAG_VIRTUAL ) k--;
}else{
j = aXRef[i];
if( j>=0 ){
}
}
}
+#ifndef SQLITE_OMIT_GENERATED_COLUMNS
+ if( pTab->tabFlags & TF_HasStored ){
+ sqlite3ComputeStoredColumns(pParse, regNew, pTab);
+ }
+#endif
/* Fire any BEFORE UPDATE triggers. This happens before constraints are
** verified. One could argue that this is wrong.
** for an example.
*/
for(i=0, k=regNew; i<pTab->nCol; i++, k++){
- if( pTab->aCol[i].colFlags & COLFLAG_VIRTUAL ){
- k--;
+ if( pTab->aCol[i].colFlags & COLFLAG_GENERATED ){
+ if( pTab->aCol[i].colFlags & COLFLAG_VIRTUAL ) k--;
}else if( aXRef[i]<0 && i!=pTab->iPKey ){
sqlite3ExprCodeGetColumnOfTable(pParse, pTab, iDataCur, i, k);
}
}
+#ifndef SQLITE_OMIT_GENERATED_COLUMNS
+ if( pTab->tabFlags & TF_HasStored ){
+ sqlite3ComputeStoredColumns(pParse, regNew, pTab);
+ }
+#endif
}
if( !isView ){
rc = SQLITE_ERROR;
}else{
int iCol;
- u8 oooHidden = 0;
+ u16 oooHidden = 0;
/* If everything went according to plan, link the new VTable structure
** into the linked list headed by pTab->pVTable. Then loop through the
** columns of the table to see if any of them contain the token "hidden".