From: drh Date: Thu, 10 Dec 2020 12:49:26 +0000 (+0000) Subject: The DO UPDATE code generator searches for the correct ON CONFLICT clause to X-Git-Tag: version-3.35.0~183^2~8 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=91f2717f22e5a7c3feab8224a16416677ad28e47;p=thirdparty%2Fsqlite.git The DO UPDATE code generator searches for the correct ON CONFLICT clause to use. FossilOrigin-Name: a47e35ee2d901baaa37e7229d190f934e1b0bd3510147cd4a2a49c4a1411416a --- diff --git a/manifest b/manifest index 7766814266..abce3073d7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C For\supsert,\sthe\sconstraint\scheck\scode\sgenerator\suses\sa\scopy\sof\sthe\sindex\slist\nfor\sthe\starget\stable,\swhich\scan\spotentially\sbe\sreordered. -D 2020-12-09T20:30:47.480 +C The\sDO\sUPDATE\scode\sgenerator\ssearches\sfor\sthe\scorrect\sON\sCONFLICT\sclause\sto\nuse. +D 2020-12-10T12:49:26.425 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -545,7 +545,7 @@ F src/shell.c.in e9f674ee4ec6c345679e8a5b16c869c6c59eb1540dd98ac69e4736ecddce009 F src/sqlite.h.in 0e2b4259e49a0eda54d9118eb18a04fcd60e0727a2fd2c81aade0bf57520e706 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 61b38c073d5e1e96a3d45271b257aef27d0d13da2bea5347692ae579475cd95e -F src/sqliteInt.h f01f37844eed0fab3e1fa8efe72cc327cf8e2ac121688ec94199d610978ecb09 +F src/sqliteInt.h 0e042bd76044617ae919a294778ceacdb00a405d60de1b94c8ee4d2b81829bdb F src/sqliteLimit.h d7323ffea5208c6af2734574bae933ca8ed2ab728083caa117c9738581a31657 F src/status.c 4b8bc2a6905163a38b739854a35b826c737333fab5b1f8e03fa7eb9a4799c4c1 F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 @@ -608,7 +608,7 @@ F src/tokenize.c 01dba3023659dc6f6b1e054c14b35a0074bd35de10466b99454d33278191d97 F src/treeview.c 4b92992176fb2caefbe06ba5bd06e0e0ebcde3d5564758da672631f17aa51cda F src/trigger.c 515e79206d40d1d4149129318582e79a6e9db590a7b74e226fdb5b2a6c7e1b10 F src/update.c 9f126204a6acb96bbe47391ae48e0fc579105d8e76a6d9c4fab3271367476580 -F src/upsert.c 803c383d493546c71580e9e532d6c7f87fc337316a2ffc202ba1812158dfa8fb +F src/upsert.c 49170532578f2f30984b35e2c1e2f308b089c6814edf384d32158a53b25fc930 F src/utf.c ee39565f0843775cc2c81135751ddd93eceb91a673ea2c57f61c76f288b041a0 F src/util.c c0c7977de7ef9b8cb10f6c85f2d0557889a658f817b0455909a49179ba4c8002 F src/vacuum.c 492422c1463c076473bae1858799c7a0a5fe87a133d1223239447c422cd26286 @@ -1888,10 +1888,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 8ccb8d1d55fa5aaf625c30f0e7c10aa403d79b5574dbdfa3fd0271a4e546f7e3 -R cb21a770762087a569cd96190733ebe7 -T *branch * generalized-upsert-ex1 -T *sym-generalized-upsert-ex1 * -T -sym-generalized-upsert * +P 3194c00c2c6a32bdfd5acc9fda5b38ae131d20cd3b7aea8512a41b2e76808f6a +R 8dc7164868d12444f67e9c3abe760e73 U drh -Z d9a35c3fa2c53151f722f0a994f8bfdd +Z 978ca06206ec1f9d5cc426705017394f diff --git a/manifest.uuid b/manifest.uuid index ce7066ad55..88e882cea1 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3194c00c2c6a32bdfd5acc9fda5b38ae131d20cd3b7aea8512a41b2e76808f6a \ No newline at end of file +a47e35ee2d901baaa37e7229d190f934e1b0bd3510147cd4a2a49c4a1411416a \ No newline at end of file diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 8661f9058c..23df9cc710 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -3086,11 +3086,12 @@ struct Upsert { ** information from the INSERT processing down into the UPDATE processing ** while generating code. The fields below are owned by the INSERT ** statement and will be freed by INSERT processing. */ - Index *pUpsertIdx; /* Constraint that pUpsertTarget identifies */ + Index *pUpsertIdx; /* UNIQUE constraint specified by pUpsertTarget */ SrcList *pUpsertSrc; /* Table to be updated */ int regData; /* First register holding array of VALUES */ int iDataCur; /* Index of the data cursor */ int iIdxCur; /* Index of the first index cursor */ + int addrGenericUpdate; /* Address of routine for generic DO UPDATE */ }; /* diff --git a/src/upsert.c b/src/upsert.c index 0f1f6d8a32..63b9144419 100644 --- a/src/upsert.c +++ b/src/upsert.c @@ -229,11 +229,27 @@ void sqlite3UpsertDoUpdate( SrcList *pSrc; /* FROM clause for the UPDATE */ int iDataCur; int i; + Upsert *pTop = pUpsert; assert( v!=0 ); assert( pUpsert!=0 ); - VdbeNoopComment((v, "Begin DO UPDATE of UPSERT")); iDataCur = pUpsert->iDataCur; + while( + pUpsert->pUpsertTarget!=0 + && (pUpsert->pUpsertIdx==0 ? pIdx!=0 : + pUpsert->pUpsertIdx->zName!=pIdx->zName) + ){ + assert( pUpsert->pNextUpsert!=0 ); + pUpsert = pUpsert->pNextUpsert; + } + if( pUpsert->addrGenericUpdate>0 ){ + sqlite3VdbeAddOp2(v, OP_Goto, 0, pUpsert->addrGenericUpdate); + return; + } + VdbeNoopComment((v, "Begin DO UPDATE of UPSERT")); + if( pUpsert->pUpsertTarget==0 ){ + pUpsert->addrGenericUpdate = sqlite3VdbeCurrentAddr(v); + } if( pIdx && iCur!=iDataCur ){ if( HasRowid(pTab) ){ int regRowid = sqlite3GetTempReg(pParse); @@ -263,13 +279,13 @@ void sqlite3UpsertDoUpdate( sqlite3VdbeJumpHere(v, i); } } - /* pUpsert does not own pUpsertSrc - the outer INSERT statement does. So - ** we have to make a copy before passing it down into sqlite3Update() */ - pSrc = sqlite3SrcListDup(db, pUpsert->pUpsertSrc, 0); + /* pUpsert does not own pTop->pUpsertSrc - the outer INSERT statement does. + ** So we have to make a copy before passing it down into sqlite3Update() */ + pSrc = sqlite3SrcListDup(db, pTop->pUpsertSrc, 0); /* excluded.* columns of type REAL need to be converted to a hard real */ for(i=0; inCol; i++){ if( pTab->aCol[i].affinity==SQLITE_AFF_REAL ){ - sqlite3VdbeAddOp1(v, OP_RealAffinity, pUpsert->regData+i); + sqlite3VdbeAddOp1(v, OP_RealAffinity, pTop->regData+i); } } sqlite3Update(pParse, pSrc, pUpsert->pUpsertSet,