]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add comments for the new code on this branch.
authordan <Dan Kennedy>
Tue, 5 Mar 2024 20:33:48 +0000 (20:33 +0000)
committerdan <Dan Kennedy>
Tue, 5 Mar 2024 20:33:48 +0000 (20:33 +0000)
FossilOrigin-Name: 551caba93bc1ab0c57451bc3f0cd29d16a9d577874d22d5083ac53fe09a5e60a

manifest
manifest.uuid
src/insert.c
src/sqliteInt.h
test/values.test

index d1d51da4b250a2dfc9b70306a8923984af0b9cc6..26f57faf0f65d50327f6432aa62ccd5613ee2e21 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Merge\strunk\schanges\sinto\sthis\sbranch.
-D 2024-03-05T18:03:28.571
+C Add\scomments\sfor\sthe\snew\scode\son\sthis\sbranch.
+D 2024-03-05T20:33:48.969
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -709,7 +709,7 @@ F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220
 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51
 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6
 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71
-F src/insert.c 455bd07274de3e58974ccbf755ac6fb8ca47db00ee3c36f7173028c5fab29b11
+F src/insert.c d1cf81c7668c59307c7b4e1dc95a0374b4cc5333f1cc2fe181d21c7bed90e188
 F src/json.c 9337dac9d9d4c77461db55fd3e06e4d006f4283cb1da2b3a9b1f8d750701583e
 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
 F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36
@@ -755,7 +755,7 @@ F src/shell.c.in 78bbd861cd0128aed67c0136561572ebcf11649be6cea86bee8491576d5958d
 F src/sqlite.h.in 19a2db3995a699bd7f6dfb423856242bfceb7ec849a93c91d241d19fc28d9f0f
 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54
-F src/sqliteInt.h 616591f3bc242446caba3160f7c1ebca4817f06cea2ed6a5da5b988203834c09
+F src/sqliteInt.h 4059c20ebd3fd2772846f451a0946902c900451f6ba91ce20f568bf9ae7da9eb
 F src/sqliteLimit.h 6878ab64bdeb8c24a1d762d45635e34b96da21132179023338c93f820eee6728
 F src/status.c cb11f8589a6912af2da3bb1ec509a94dd8ef27df4d4c1a97e0bcf2309ece972b
 F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1
@@ -1920,7 +1920,7 @@ F test/vacuum4.test 7ea76b769fffeb41f925303b04cbcf5a5bbeabe55e4c60ae754ff24eeeb7
 F test/vacuum5.test 263b144d537e92ad8e9ca8a73cc6e1583f41cfd0dda9432b87f7806174a2f48c
 F test/vacuum6.test b137b04bf3392d3f5c3b8fda0ce85a6775a70ca112f6559f74ff52dc9ce042fd
 F test/vacuummem.test 4b30f5b95a9ff86e9d5c20741e50a898b2dc10b0962a3211571eb165357003fb
-F test/values.test 94f74c64ba6649de423d49c471eaebb6300ccd754213b170f82b10bbd1a143d2
+F test/values.test 81e0863873b6ec9db79c332d17812c31368130cc401a647c6d1d0e5fc3a27fe4
 F test/varint.test bbce22cda8fc4d135bcc2b589574be8410614e62
 F test/veryquick.test 57ab846bacf7b90cf4e9a672721ea5c5b669b661
 F test/view.test d4c4281e1679245829db35597817282f60dc513fc39cc5439078f009bd118487
@@ -2177,8 +2177,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 4784a92e567013632ea833d8747bc304ae39aaa9c2dff66198cda53797ec3ab7 8290646792bc5411112b0c01dc5ac0837743056a7679725ee2edefef2e10d146
-R ed3feaa2ba2f3d55860d55573371a912
+P a003fffafdb532de4ff3876a81e73dbccbdf83debecd83a2a9ae2d449bf02adc
+R 55010f332167e59d2e243052f3e4e866
 U dan
-Z 7b3184a27c83c890e77e2b23a3919d24
+Z 749255c97ae7f51a891e46cc76606f6a
 # Remove this line to create a well-formed Fossil manifest.
index c28564c2657527c11f0558ca7053349141b19acb..75cab7c1a6083d77a205dcc03a863f4889222b8e 100644 (file)
@@ -1 +1 @@
-a003fffafdb532de4ff3876a81e73dbccbdf83debecd83a2a9ae2d449bf02adc
\ No newline at end of file
+551caba93bc1ab0c57451bc3f0cd29d16a9d577874d22d5083ac53fe09a5e60a
\ No newline at end of file
index b5f9b4950d96976dfde4b28b5e80168008b08eea..779d8ab60f629609db240f6589d24f369467c2f0 100644 (file)
@@ -577,47 +577,21 @@ void sqlite3AutoincrementEnd(Parse *pParse){
 # define autoIncStep(A,B,C)
 #endif /* SQLITE_OMIT_AUTOINCREMENT */
 
-static int isConstantRow(ExprList *pRow){
-  int ii;
-  for(ii=0; ii<pRow->nExpr; ii++){
-    if( !sqlite3ExprIsConstantOrFunction(pRow->a[ii].pExpr, 0) ) return 0;
-  }
-  return 1;
-}
-
-void sqlite3MultiValuesStart(Parse *pParse, Select *pSel){
-  Vdbe *v = sqlite3GetVdbe(pParse);
-  MultiValues *pVal = 0;
-
-  assert( pParse->pValues==0 );
-  assert( pParse->zValuesToken!=0 );
-  if( isConstantRow(pSel->pEList) ){
-    pVal = (MultiValues*)sqlite3DbMallocZero(pParse->db, sizeof(*pVal));
-    pVal->pSelect = pSel;
-    pVal->regYield = ++pParse->nMem;
-    pVal->addrTop = sqlite3VdbeCurrentAddr(v) + 1;
-    sqlite3VdbeAddOp3(v, OP_InitCoroutine, pVal->regYield, 0, pVal->addrTop);
-    sqlite3SelectDestInit(&pVal->dest, SRT_Coroutine, pVal->regYield);
-    sqlite3Select(pParse, pSel, &pVal->dest);
-    pParse->pValues = pVal;
-    pSel->selFlags = pSel->selFlags & (~SF_Values);
-    sqlite3ParserAddCleanup(pParse, sqlite3DbFree, pVal);
-  }
-}
-
-static void insertEndCoroutine(Vdbe *v, int regYield, int addrTop){
-  sqlite3VdbeEndCoroutine(v, regYield);
-  sqlite3VdbeJumpHere(v, addrTop - 1);
-}
-
 Select *sqlite3InsertMultiValues(Parse *pParse, Select *pLeft, ExprList *pRow){
   MultiValues *pVal = pParse->pValues;
   Select *pRight;
 
+  /* Allocate a new Select structure for the next row of the VALUES clause.
+  ** There are then three options: (a) the co-routine has already been 
+  ** started - in this case code the next row of the co-routine and then
+  ** delete the new Select, (b) the co-routine has not been started - in
+  ** this case link the new Select to the old using a TK_ALL operator, or
+  ** (c) an OOM has occured.  */
   pRight = sqlite3SelectNew(pParse,pRow, 0,0,0,0,0, SF_Values|SF_MultiValue, 0);
   pLeft->selFlags &= ~SF_MultiValue;
   if( pRight ){
     if( pVal && pVal->pSelect==pLeft ){
+      /* Option (a) above */
       int explain = pParse->explain;
       pParse->explain = 255;
       sqlite3Select(pParse, pRight, &pVal->dest);
@@ -625,13 +599,18 @@ Select *sqlite3InsertMultiValues(Parse *pParse, Select *pLeft, ExprList *pRow){
       sqlite3SelectDelete(pParse->db, pRight);
       pRight = pLeft;
     }else{
+      /* Option (b) above */
       pRight->op = TK_ALL;
       pRight->pPrior = pLeft;
     }
   }else{
+    /* Option (c) above - an OOM */
     pRight = pLeft;
   }
 
+  /* If the co-routine has not already been started, but more than
+  ** SQLITE_LIMIT_COMPOUND_SELECT select statements have been create during
+  ** this parse, check if the co-routine should be started now. */
   if( pVal==0 && pParse->zValuesToken 
    && (pParse->nSelect > pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT])
   ){
@@ -642,6 +621,7 @@ Select *sqlite3InsertMultiValues(Parse *pParse, Select *pLeft, ExprList *pRow){
     if( nSelect>pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT] 
      && (p->selFlags & SF_InsertValues)
     ){
+      /* Start coding the co-routine */
       Vdbe *v = sqlite3GetVdbe(pParse);
       pVal = (MultiValues*)sqlite3DbMallocZero(pParse->db, sizeof(*pVal));
       if( v && pVal ){
@@ -659,8 +639,8 @@ Select *sqlite3InsertMultiValues(Parse *pParse, Select *pLeft, ExprList *pRow){
           Select *pNext = p->pNext;
           int explain = pParse->explain;
           p->selFlags = p->selFlags & (~SF_Values);
-          pParse->explain = 255;
           p->pPrior = 0;
+          pParse->explain = 255;
           sqlite3Select(pParse, p, &pVal->dest);
           pParse->explain = explain;
           if( p!=pRight ) sqlite3SelectDelete(pParse->db, p);
index 2c96daf126fe190ac703eea7e27e91312f356acf..820162c1035fe8f0e83b9ddd6b9f4314b5796158 100644 (file)
@@ -4487,14 +4487,33 @@ struct Window {
                           ** due to the SQLITE_SUBTYPE flag */
 };
 
+/*
+** A single instance of this object is used when parsing "INSERT INTO ... 
+** VALUES" statements when the VALUES clause contains a large number of
+** rows - more than the configured SQLITE_LIMIT_COMPOUND_SELECT limit.
+**
+** An INSERT with a multi-row VALUES clause begins by coding a co-routine
+** to access each row of the VALUES clause. Usually, this doesn't happen
+** until after the entire statement has been parsed. Since each row of the
+** VALUES clause is stored in-memory as a separate Select statement, the
+** parse tree for very large VALUES clauses might consume significant 
+** amounts of memory.
+**
+** In order to avoid this in extreme cases, once a VALUES clause that is
+** part of an INSERT statement grows to larger than
+** SQLITE_LIMIT_COMPOUND_SELECT rows, the co-routine is coded incrementally,
+** while parsing the remainder of the VALUES clause. An instance of this
+** object is stored in Parse.pValues while this is ongoing.
+*/
 struct MultiValues {
-  Select *pSelect;
-  SelectDest dest;
-  int addrTop;
-  int regYield;
-  int bEnd;               /* EndCoroutine already coded */
+  Select *pSelect;        /* The VALUES(...) Select object */
+  SelectDest dest;        /* Destination object for the co-routine */
+  int addrTop;            /* Address of top of co-routine */
+  int regYield;           /* Register used for co-routine */
 };
 
+Select *sqlite3InsertMultiValues(Parse*, Select*, ExprList*);
+
 #ifndef SQLITE_OMIT_WINDOWFUNC
 void sqlite3WindowDelete(sqlite3*, Window*);
 void sqlite3WindowUnlinkFromSelect(Window*);
@@ -5781,7 +5800,4 @@ sqlite3_uint64 sqlite3Hwtime(void);
 # define IS_STMT_SCANSTATUS(db) 0
 #endif
 
-Select *sqlite3InsertMultiValues(Parse*, Select*, ExprList*);
-void sqlite3MultiValuesStart(Parse*, Select*);
-
 #endif /* SQLITEINT_H */
index 7c024943a269944f781024e595f2739416a6776c..a8880acac80fe2f3123c2a5e2f9dc8c087cb13e9 100644 (file)
@@ -86,6 +86,11 @@ do_execsql_test 1.2.6 {
   6 6 6
 }
 
+#-------------------------------------------------------------------------
+# different number of columns error.
+# SQLITE_LIMIT_COMPOUND_SELECT set to 0.
+#
+
 
 
 finish_test