]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Ignore CHECK constraints when
authordrh <>
Tue, 9 Apr 2024 14:08:39 +0000 (14:08 +0000)
committerdrh <>
Tue, 9 Apr 2024 14:08:39 +0000 (14:08 +0000)
qualifying the xfer optimization while running VACUUM.

FossilOrigin-Name: 944d1b6eb346a9b3c32bce3457f8a62013ee5d6b538fa19243036cd2924678d4

manifest
manifest.uuid
src/insert.c
test/vacuum-into.test

index 219883b6f55cfa6145f3509ada04de1131465cfb..d1cb8d5dcb842d430b53de48881699395218f6c7 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Check-in\sa9657c87c53c1922\sis\swrong:\sthe\sIndexedExpr.bMaybeNullRow\sflag\sis\nrequired\sfor\svirtual\scolumns\sif\sthey\sare\spart\sof\san\souter\sjoin.\s\sAdd\sa\ntest\scase\sto\sprove\sit.
-D 2024-04-05T14:13:43.998
+C Ignore\sCHECK\sconstraints\swhen\nqualifying\sthe\sxfer\soptimization\swhile\srunning\sVACUUM.
+D 2024-04-09T14:08:39.797
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -684,7 +684,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 b2045aafc52f0475dc5d723d11cc0aaa9e1d233a28031b08c8174a3e407ed50c
 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
 F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36
@@ -1878,7 +1878,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
@@ -2144,9 +2144,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 d38cfa6067ccd450c4fac183765c05ff247ecb49ccf172a68ef9d381577df84f
-Q +4484ec6d26b31305e31de89bdbae26344d8083a7e7de20861430d31737d9979c
-R 8554e23db7a373e229e42ced9c16a035
+P 083b0f7e771838e5f02744c245e8dbd7bef4fc998df59466ba65c531c7162d99
+Q +a6e26e778812c8409fca77183e24d3b70189c4d02fce10c7e74cd4ccc8c8ea97
+R f264450f7cca472796cdd7c597afe939
 U drh
-Z 3cbdd21853a35d8d9b49c29bfbf22c21
+Z 915f7b0fa0754bf87832059126685eef
 # Remove this line to create a well-formed Fossil manifest.
index 00b4f5ee54e8b1ea10a4685d74b43dd766b713d1..07add73704a3ea9385a40b74a15c49c630ed914d 100644 (file)
@@ -1 +1 @@
-083b0f7e771838e5f02744c245e8dbd7bef4fc998df59466ba65c531c7162d99
\ No newline at end of file
+944d1b6eb346a9b3c32bce3457f8a62013ee5d6b538fa19243036cd2924678d4
\ No newline at end of file
index 095298b90ce37c2fdb9ce2dcc7b82b79ff1bb734..c2c2f7cc02adf14f1e78da081775c2729de8d3e7 100644 (file)
@@ -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
index 698d65f5406baed4ef690ca9c98da7c54dc24290..d559b7fb398f86aee952af1b58b8a3fc73abb207 100644 (file)
@@ -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}