From: dan Date: Thu, 7 Mar 2024 15:44:50 +0000 (+0000) Subject: Add further tests for the code on this branch. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ca1a5f8c36f25cdd0fc8cf4dd480998dbe58caaa;p=thirdparty%2Fsqlite.git Add further tests for the code on this branch. FossilOrigin-Name: 5d8065e80144ba3e762c353a9f06fd5e4aea2d0125c4e365a3d6394f8e09a13c --- diff --git a/manifest b/manifest index e3dc735b9e..74635c72ea 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Avoid\smaking\stoo\smany\scalls\sto\ssqlite3Select/sqlite3WhereBegin()\swhen\sprocessing\slarge\sVALUES\sclauses. -D 2024-03-06T20:34:59.358 +C Add\sfurther\stests\sfor\sthe\scode\son\sthis\sbranch. +D 2024-03-07T15:44:50.470 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 515295695e6cf86136c7e85b1a2014d00bb9b8b098b96f7338f017dcad5b20d5 +F src/insert.c 0b90d3d515c94cf7ac3c545db94001f8868db095f2e0ba12457498bb72efa2b5 F src/json.c 9337dac9d9d4c77461db55fd3e06e4d006f4283cb1da2b3a9b1f8d750701583e F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 @@ -739,7 +739,7 @@ F src/os_win.c 6ff43bac175bd9ed79e7c0f96840b139f2f51d01689a638fd05128becf94908a F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a F src/pager.c ff60e98138d2499082ac6230f01ac508aba545315debccfca2fd6042f5f10fcd F src/pager.h 4b1140d691860de0be1347474c51fee07d5420bd7f802d38cbab8ea4ab9f538a -F src/parse.y 9b9923ee2c2de30bddd4120fc096007c2bfb2c63194d18e140d365cae8be9812 +F src/parse.y 56a0ddc81574d433e1403246c1cd897584499792cf5a76008c1193fbb709776c F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00 @@ -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 4059c20ebd3fd2772846f451a0946902c900451f6ba91ce20f568bf9ae7da9eb +F src/sqliteInt.h c59487cb4b80d72b7f9ba72db1dd8eb8c1b5d7413aa344baf8d1ffcd5e6a7ccf F src/sqliteLimit.h 6878ab64bdeb8c24a1d762d45635e34b96da21132179023338c93f820eee6728 F src/status.c cb11f8589a6912af2da3bb1ec509a94dd8ef27df4d4c1a97e0bcf2309ece972b F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 @@ -1920,7 +1920,8 @@ F test/vacuum4.test 7ea76b769fffeb41f925303b04cbcf5a5bbeabe55e4c60ae754ff24eeeb7 F test/vacuum5.test 263b144d537e92ad8e9ca8a73cc6e1583f41cfd0dda9432b87f7806174a2f48c F test/vacuum6.test b137b04bf3392d3f5c3b8fda0ce85a6775a70ca112f6559f74ff52dc9ce042fd F test/vacuummem.test 4b30f5b95a9ff86e9d5c20741e50a898b2dc10b0962a3211571eb165357003fb -F test/values.test 4d72de229975e6569f4ae996433ad6f3f818eaf0768593faf561d2faa422c0bd +F test/values.test 402810384b43afc7b3fdf7b93970debe519ab9fdafdbeb89521df09246639014 +F test/valuesfault.test 2ef23ed965e3bd08e268cdc38a0d11653390ddbbe1e8e2e98d16f55edd30f6e8 F test/varint.test bbce22cda8fc4d135bcc2b589574be8410614e62 F test/veryquick.test 57ab846bacf7b90cf4e9a672721ea5c5b669b661 F test/view.test d4c4281e1679245829db35597817282f60dc513fc39cc5439078f009bd118487 @@ -2177,8 +2178,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 f5074b29d96e8e642e597ce855d2481220628f6892110b9699e27c3806084f5d -R 622ec394e32f40c2646817ddc80e7ba5 +P 356158c1928ddcdc50c3635d677d3d20ab020184c8d91d61df103801a365eb83 +R 0684bc69b27f58b6341be0bbcbd6625d U dan -Z 2d14187c1480c54766681609db97193f +Z cdacbf657eabe45b96b6d5353a8a6009 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 28e157873d..415afd224f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -356158c1928ddcdc50c3635d677d3d20ab020184c8d91d61df103801a365eb83 \ No newline at end of file +5d8065e80144ba3e762c353a9f06fd5e4aea2d0125c4e365a3d6394f8e09a13c \ No newline at end of file diff --git a/src/insert.c b/src/insert.c index 31fbd74cbf..b92c006f36 100644 --- a/src/insert.c +++ b/src/insert.c @@ -577,13 +577,32 @@ void sqlite3AutoincrementEnd(Parse *pParse){ # define autoIncStep(A,B,C) #endif /* SQLITE_OMIT_AUTOINCREMENT */ +/* +** The Select object passed as the second argument is a component of +** a multi-row VALUES(...) clause that is part of an INSERT statement. +** The entire VALUES clause will be coded as a co-routine. Each component +** is coded by loading the N values returned by the select into an array +** of registers at pParse->pValues->dest.iSdst followed by an OP_Yield +** instruction (using register pParse->pValues->regYield). +** +** This function generates the co-routine code for the select passed as +** the second argument. If argument bDel is true then the Select object +** is deleted before returning. +*/ static void multiValuesSelect(Parse *pParse, Select *p, int bDel){ MultiValues *pVal = pParse->pValues; sqlite3SelectPrep(pParse, p, 0); if( bDel && p->pWin==0 ){ + /* Code this row directly. This is prefered as calling sqlite3Select() + ** too many times for a single Parse context leads to excessing realloc() + ** calls. */ sqlite3ExprCodeExprList(pParse, p->pEList, pVal->dest.iSdst, 0, 0); sqlite3VdbeAddOp1(pParse->pVdbe, OP_Yield, pVal->regYield); }else{ + /* Call the full sqlite3Select() function for this row. This is required + ** to handle any window functions, or if bDel is false - in this last + ** case this is because this call to sqlite3Select() is required to + ** fulling initialize pVal->dest. */ sqlite3Select(pParse, p, &pVal->dest); } if( bDel ){ @@ -591,7 +610,24 @@ static void multiValuesSelect(Parse *pParse, Select *p, int bDel){ } } -Select *sqlite3InsertMultiValues(Parse *pParse, Select *pLeft, ExprList *pRow){ +/* +** This function is called by the parser to process the second and subsequent +** rows of a multi-row VALUES(...) clause. Argument pLeft is the previous +** row of the clause, pRow contains the expressions for the new row. +** +** Usually, this function allocates a new Select object using pRow as its +** select-list, links it to pLeft via a TK_ALL operator and returns the +** new object. The SF_MultiValue flag is cleared on pLeft and set on +** the returned object. +** +** However, if (a) the VALUES clause is part of an INSERT statement and +** (b) it now has more rows than the configured SQLITE_LIMIT_COMPOUND_SELECT +** limit, then it is already known that each row of the VALUES clause will +** be coded as part of a co-routine that returns all such rows. In this +** case the co-routine may be coded incrementally by this routine. This is +** done to save memory while parsing the large VALUES clause. +*/ +Select *sqlite3MultiValues(Parse *pParse, Select *pLeft, ExprList *pRow){ MultiValues *pVal = pParse->pValues; Select *pRight; diff --git a/src/parse.y b/src/parse.y index 6d010d24ac..1feeae646f 100644 --- a/src/parse.y +++ b/src/parse.y @@ -631,7 +631,7 @@ values(A) ::= VALUES(T) LP nexprlist(X) RP. { A = sqlite3SelectNew(pParse,X,0,0,0,0,0,f,0); } values(A) ::= values(A) COMMA LP nexprlist(Y) RP. { - A = sqlite3InsertMultiValues(pParse,A,Y); + A = sqlite3MultiValues(pParse,A,Y); } // The "distinct" nonterminal is true (1) if the DISTINCT keyword is diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 820162c103..a3fb4c4dfe 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -4512,7 +4512,7 @@ struct MultiValues { int regYield; /* Register used for co-routine */ }; -Select *sqlite3InsertMultiValues(Parse*, Select*, ExprList*); +Select *sqlite3MultiValues(Parse*, Select*, ExprList*); #ifndef SQLITE_OMIT_WINDOWFUNC void sqlite3WindowDelete(sqlite3*, Window*); diff --git a/test/values.test b/test/values.test index 323c5f8c38..6fe66d088f 100644 --- a/test/values.test +++ b/test/values.test @@ -182,9 +182,50 @@ foreach {tn iLimit} {1 0 2 2} { do_execsql_test 3.$tn.1.2 { SELECT * FROM y1; } {1 2 3 4 1 6 1 7} +} +#------------------------------------------------------------------------- +reset_db + +do_execsql_test 4.0 { + CREATE TABLE x1(a PRIMARY KEY, b) WITHOUT ROWID; } +foreach {tn iLimit} {1 0 2 3} { + sqlite3_limit db SQLITE_LIMIT_COMPOUND_SELECT $iLimit + + do_execsql_test 4.1.1 { + DELETE FROM x1; + INSERT INTO x1 VALUES + (1, 1), + (2, (SELECT * FROM (VALUES('a'), ('b'), ('c'), ('d')) )) + } + do_execsql_test 4.1.2 { + SELECT * FROM x1 + } {1 1 2 a} + + do_execsql_test 4.2.1 { + DELETE FROM x1; + INSERT INTO x1 VALUES + (1, 1), + (2, 2), + (3, 3), + (4, 4), + (5, (SELECT * FROM (VALUES('a'), ('b'), ('c'), ('d')) )) + } + do_execsql_test 4.2.2 { + SELECT * FROM x1 + } {1 1 2 2 3 3 4 4 5 a} + + do_execsql_test 4.3.1 { + DELETE FROM x1; + INSERT INTO x1 VALUES + (1, (SELECT * FROM (VALUES('a'), ('b'), ('c'), ('d'), ('e')) )) + } + do_execsql_test 4.3.2 { + SELECT * FROM x1 + } {1 a} +} finish_test diff --git a/test/valuesfault.test b/test/valuesfault.test new file mode 100644 index 0000000000..bc5dddfb0e --- /dev/null +++ b/test/valuesfault.test @@ -0,0 +1,37 @@ +# 2024 March 3 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix valuesfault +source $testdir/malloc_common.tcl + + +do_execsql_test 1.0 { + CREATE TABLE x1(a, b, c); +} +faultsim_save_and_close + +do_faultsim_test 1 -prep { + faultsim_restore_and_reopen + sqlite3_limit db SQLITE_LIMIT_COMPOUND_SELECT 2 +} -body { + execsql { + INSERT INTO x1 VALUES(1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4); + } +} -test { + faultsim_test_result {0 {}} +} + + +finish_test