From: drh <> Date: Tue, 9 Apr 2024 14:07:37 +0000 (+0000) Subject: Ignoring CHECK constraints when qualifying the xfer optimization while X-Git-Tag: version-3.45.3~7 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ae454277a8545f7e2645fada1c096ac3073247ae;p=thirdparty%2Fsqlite.git Ignoring CHECK constraints when qualifying the xfer optimization while running VACUUM. FossilOrigin-Name: bb6f9908098baa84b9c3b6f747ec8df6a5cf55c790ba1f172085f16394d684f2 --- diff --git a/manifest b/manifest index 2d3755d95b..4b69f46731 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sobscure\sissues\sassociated\swith\sSQLITE_ALLOW_ROWID_IN_VIEW\sand\nindexes\son\svirtual\scolumns\sin\sa\sRIGHT\sJOIN. -D 2024-04-05T14:06:21.164 +C Ignoring\sCHECK\sconstraints\swhen\squalifying\sthe\sxfer\soptimization\swhile\nrunning\sVACUUM. +D 2024-04-09T14:07:37.621 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -697,7 +697,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 eb33ea46dcab93e90f112fced343aaf41f59cbd2e951d5066f1f9302be1c2f34 +F src/insert.c 7d318f638431af858b5ebd5d2c17d6dacd0adf114dbbfbe23f3033c3c043c7f0 F src/json.c 29a42bc92c2384653b8b5e5ad26bdee4e2334544c7cfb78ceb4a3ca81d674686 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 @@ -1896,7 +1896,7 @@ F test/uri.test c1abaaaa28e9422d61e5f3f9cbc8ef993ec49fe802f581520731708561d49384 F test/uri2.test 9d3ba7a53ee167572d53a298ee4a5d38ec4a8fb7 F test/userauth01.test e740a2697a7b40d7c5003a7d7edaee16acd349a9 F test/utf16align.test 9fde0bb5d3a821594aa68c6829ab9c5453a084384137ebb9f6153e2d678039da -F test/vacuum-into.test 35dc6f79b563f91c61822f61797363e97fed1bf28f1f722688b98d43f1980d76 +F test/vacuum-into.test 77845cee98770c416dae9b0da6bb3229753861f2da65c11b4f9715d081712d8a F test/vacuum.test ce91c39f7f91a4273bf620efad21086b5aa6ef1d F test/vacuum2.test 9fd45ce6ce29f5614c249e03938d3567c06a9e772d4f155949f8eafe2d8af520 F test/vacuum3.test d9d9a04ee58c485b94694fd4f68cffaba49c32234fdefe1ac1a622c5e17d4ce3 @@ -2160,10 +2160,9 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P db31d178d65de663fb4df69c48600686ffd9684d3081ae10e0d6885cdf5adaa5 -Q +4484ec6d26b31305e31de89bdbae26344d8083a7e7de20861430d31737d9979c -Q +c7896e88850669e18e89d44c4169d4f4a5d4b904bea6ccb2ac64f93b6d348a42 -R 746ec7f9c7e41c191c2755b120a0d32d +P 4b3a253fc750c30ba01cff2a8a3ca2e1fd19973372d0e4249ae9468593905f62 +Q +a6e26e778812c8409fca77183e24d3b70189c4d02fce10c7e74cd4ccc8c8ea97 +R 3ff73ea80ac053de37c23bca7774f17c U drh -Z 9f273803eda37df508dfe4c192782de1 +Z 908529c4802edbbcc220568e8f9f9477 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 6c23246138..3fb6ee1c0b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4b3a253fc750c30ba01cff2a8a3ca2e1fd19973372d0e4249ae9468593905f62 \ No newline at end of file +bb6f9908098baa84b9c3b6f747ec8df6a5cf55c790ba1f172085f16394d684f2 \ No newline at end of file diff --git a/src/insert.c b/src/insert.c index 095298b90c..c2c2f7cc02 100644 --- a/src/insert.c +++ b/src/insert.c @@ -2978,7 +2978,10 @@ static int xferOptimization( } } #ifndef SQLITE_OMIT_CHECK - if( pDest->pCheck && sqlite3ExprListCompare(pSrc->pCheck,pDest->pCheck,-1) ){ + if( pDest->pCheck + && (db->mDbFlags & DBFLAG_Vacuum)==0 + && sqlite3ExprListCompare(pSrc->pCheck,pDest->pCheck,-1) + ){ return 0; /* Tables have different CHECK constraints. Ticket #2252 */ } #endif diff --git a/test/vacuum-into.test b/test/vacuum-into.test index 698d65f540..d559b7fb39 100644 --- a/test/vacuum-into.test +++ b/test/vacuum-into.test @@ -26,13 +26,36 @@ ifcapable {!vacuum} { forcedelete out.db do_execsql_test vacuum-into-100 { - CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + CREATE TABLE t1( + a INTEGER PRIMARY KEY, + b ANY, + c INT AS (b+1), --- See "2024-04-09" block + CHECK( typeof(b)!='integer' OR b>a-5 ) --- comment below + ); WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<100) INSERT INTO t1(a,b) SELECT x, randomblob(600) FROM c; CREATE INDEX t1b ON t1(b); DELETE FROM t1 WHERE a%2; SELECT count(*), sum(a), sum(length(b)) FROM t1; } {50 2550 30000} + +# Update 2024-04-09 for forum post eec177d68fe7fa2c. +# +# VACUUM INTO is sensitive to tables holding both generated columns +# and CHECK constraints. +# +# CHECK constraints are ignored for read-only databases in order to save +# memory (see check-in 34ddf02d3d21151b on 2014-05-21). But the xfer +# optimization normally only works if CHECK constraints match between the +# source and destination tables. So the xfer optimization was not +# working for VACUUM INTO when the source was a read-only database and the +# table held CHECK constraints. But if the table has generated columns, +# then the xfer optimization is required or else VACUUM will raise an +# error. +# +# Fix this by ignoring CHECK constraints when determining whether or not +# the xfer optimization can run while doing VACUUM. + do_execsql_test vacuum-into-110 { VACUUM main INTO 'out.db'; } {} @@ -88,11 +111,21 @@ do_catchsql_test vacuum-into-420 { # The ability to VACUUM INTO a read-only database db close +if {$tcl_platform(platform)=="windows"} { + file attributes test.db -readonly 1 +} else { + file attributes test.db -permissions 292 ;# 292 == 0444 +} sqlite3 db test.db -readonly 1 forcedelete test.db2 do_execsql_test vacuum-into-500 { VACUUM INTO 'test.db2'; } +if {$tcl_platform(platform)=="windows"} { + file attributes test.db -readonly 0 +} else { + file attributes test.db -permissions 420 ;# 420 = 0644 +} sqlite3 db2 test.db2 do_test vacuum-into-510 { db2 eval {SELECT name FROM sqlite_master ORDER BY 1}