I got a suspicion that there might be something wrong with DROP PRIMARY KEY, ADD PRIMARY KEY with ROW_FORMAT=REDUNDANT tables.
The reason for this is the call in row_log_table_low_redundant():
old_pk_size = rec_get_converted_size_temp(
|
new_index, old_pk->fields, old_pk->n_fields,
|
ventry, &old_pk_extra_size);
|
The logic is duplicated differently in row_log_table_low(), where ventry is replaced with NULL:
old_pk_size = rec_get_converted_size_temp(
|
new_index, old_pk->fields, old_pk->n_fields,
|
NULL, &old_pk_extra_size);
|
This turns out to be a bigger issue. I can repeat corruption and a crash with a small modification to an existing test:
diff --git a/mysql-test/suite/innodb/t/innodb-table-online.test b/mysql-test/suite/innodb/t/innodb-table-online.test
|
index a1977fa06a4..3ed206d0f44 100644
|
--- a/mysql-test/suite/innodb/t/innodb-table-online.test
|
+++ b/mysql-test/suite/innodb/t/innodb-table-online.test
|
@@ -241,6 +241,12 @@ reap;
|
# when the above error was noticed.
|
eval $innodb_metrics_select;
|
|
+SET @saved_max = @@GLOBAL.innodb_online_alter_log_max_size;
|
+SET GLOBAL innodb_online_alter_log_max_size = 131072;
|
+ALTER TABLE t1 ROW_FORMAT=REDUNDANT;
|
+ALTER TABLE t1 ADD COLUMN v1 INT AS (c1) VIRTUAL, LOCK=NONE;
|
+#ALTER TABLE t1 ADD INDEX(v1), LOCK=NONE;
|
+
|
# Accumulate and apply some modification log.
|
SET DEBUG_SYNC = 'row_log_table_apply1_before SIGNAL rebuilt3 WAIT_FOR dml3_done';
|
--error ER_MULTIPLE_PRI_KEY
|
@@ -258,7 +264,7 @@ SET DEBUG_SYNC = 'now WAIT_FOR rebuilt3';
|
# Generate some log (delete-mark, delete-unmark, insert etc.)
|
eval $innodb_metrics_select;
|
BEGIN;
|
-INSERT INTO t1 SELECT 320 + c1, c2, c3 FROM t1 WHERE c1 > 240;
|
+INSERT INTO t1 (c1,c2,c3) SELECT 320 + c1, c2, c3 FROM t1 WHERE c1 > 240;
|
DELETE FROM t1 WHERE c1 > 320;
|
ROLLBACK;
|
BEGIN;
|
@@ -273,8 +279,11 @@ SET DEBUG_SYNC = 'now SIGNAL dml3_done';
|
connection con1;
|
reap;
|
eval $innodb_metrics_select;
|
+SET GLOBAL innodb_online_alter_log_max_size = @saved_max;
|
+
|
SELECT COUNT(c22f) FROM t1;
|
CHECK TABLE t1;
|
+ALTER TABLE t1 DROP COLUMN v1;
|
|
# Create a column prefix index.
|
--error ER_DUP_ENTRY
|
I did request this kind of tests when I reviewed WL#8149 while I was employed at Oracle.
In the above patch, there are a couple of ‘parameters’:
- the ROW_FORMAT of the table (ROW_FORMAT=REDUNDANT is logged differently)
- whether an index exists on the virtual column
Actually, virtual columns should not matter at all for the logging of table-rebuilding ALTER TABLE operations. No matter if the columns are indexed, all that we need the values of the PRIMARY KEY and the base columns.
Creating secondary indexes is a different matter. There currently exist unnecessary limitations around that (for example, adding a virtual column and adding an index is not supported in a single ALTER TABLE statement).
{"report":{"fcp":898.5,"ttfb":282.7999999523163,"pageVisibility":"visible","entityId":63121,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":32,"apdex":0.5,"journeyId":"9eb11d01-72f1-4f47-93c1-8184af2d349d","navigationType":0,"readyForUser":1003.3999998569489,"redirectCount":0,"resourceLoadedEnd":1054.2999999523163,"resourceLoadedStart":293,"resourceTiming":[{"duration":58.89999985694885,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":293,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":293,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":351.89999985694885,"responseStart":0,"secureConnectionStart":0},{"duration":59.09999990463257,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/css/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":293.2999999523163,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":293.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":352.39999985694885,"responseStart":0,"secureConnectionStart":0},{"duration":70.79999995231628,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":293.5,"connectEnd":293.5,"connectStart":293.5,"domainLookupEnd":293.5,"domainLookupStart":293.5,"fetchStart":293.5,"redirectEnd":0,"redirectStart":0,"requestStart":293.5,"responseEnd":364.2999999523163,"responseStart":364.2999999523163,"secureConnectionStart":293.5},{"duration":123,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/js/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true&whisper-enabled=true","startTime":293.69999980926514,"connectEnd":293.69999980926514,"connectStart":293.69999980926514,"domainLookupEnd":293.69999980926514,"domainLookupStart":293.69999980926514,"fetchStart":293.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":293.69999980926514,"responseEnd":416.69999980926514,"responseStart":416.69999980926514,"secureConnectionStart":293.69999980926514},{"duration":126.29999995231628,"initiatorType":"script","name":"https://jira.mariadb.org/s/a9324d6758d385eb45c462685ad88f1d-CDN/lu2cib/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":293.89999985694885,"connectEnd":293.89999985694885,"connectStart":293.89999985694885,"domainLookupEnd":293.89999985694885,"domainLookupStart":293.89999985694885,"fetchStart":293.89999985694885,"redirectEnd":0,"redirectStart":0,"requestStart":293.89999985694885,"responseEnd":420.19999980926514,"responseStart":420.19999980926514,"secureConnectionStart":293.89999985694885},{"duration":126.69999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":294,"connectEnd":294,"connectStart":294,"domainLookupEnd":294,"domainLookupStart":294,"fetchStart":294,"redirectEnd":0,"redirectStart":0,"requestStart":294,"responseEnd":420.69999980926514,"responseStart":420.69999980926514,"secureConnectionStart":294},{"duration":127,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":294.2999999523163,"connectEnd":294.2999999523163,"connectStart":294.2999999523163,"domainLookupEnd":294.2999999523163,"domainLookupStart":294.2999999523163,"fetchStart":294.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":294.2999999523163,"responseEnd":421.2999999523163,"responseStart":421.2999999523163,"secureConnectionStart":294.2999999523163},{"duration":211.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2cib/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":294.39999985694885,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":294.39999985694885,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":505.89999985694885,"responseStart":0,"secureConnectionStart":0},{"duration":127.09999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":294.59999990463257,"connectEnd":294.59999990463257,"connectStart":294.59999990463257,"domainLookupEnd":294.59999990463257,"domainLookupStart":294.59999990463257,"fetchStart":294.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":294.59999990463257,"responseEnd":421.69999980926514,"responseStart":421.59999990463257,"secureConnectionStart":294.59999990463257},{"duration":211.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/css/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.css?jira.create.linked.issue=true","startTime":294.69999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":294.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":506.19999980926514,"responseStart":0,"secureConnectionStart":0},{"duration":127.29999995231628,"initiatorType":"script","name":"https://jira.mariadb.org/s/5d5e8fe91fbc506585e83ea3b62ccc4b-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/js/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.js?jira.create.linked.issue=true&locale=en","startTime":294.89999985694885,"connectEnd":294.89999985694885,"connectStart":294.89999985694885,"domainLookupEnd":294.89999985694885,"domainLookupStart":294.89999985694885,"fetchStart":294.89999985694885,"redirectEnd":0,"redirectStart":0,"requestStart":294.89999985694885,"responseEnd":422.19999980926514,"responseStart":422.19999980926514,"secureConnectionStart":294.89999985694885},{"duration":389.89999985694885,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":296.2999999523163,"connectEnd":296.2999999523163,"connectStart":296.2999999523163,"domainLookupEnd":296.2999999523163,"domainLookupStart":296.2999999523163,"fetchStart":296.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":296.2999999523163,"responseEnd":686.1999998092651,"responseStart":686.1999998092651,"secureConnectionStart":296.2999999523163},{"duration":701.9000000953674,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":300.59999990463257,"connectEnd":300.59999990463257,"connectStart":300.59999990463257,"domainLookupEnd":300.59999990463257,"domainLookupStart":300.59999990463257,"fetchStart":300.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":300.59999990463257,"responseEnd":1002.5,"responseStart":1002.5,"secureConnectionStart":300.59999990463257},{"duration":169.29999995231628,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":517.8999998569489,"connectEnd":517.8999998569489,"connectStart":517.8999998569489,"domainLookupEnd":517.8999998569489,"domainLookupStart":517.8999998569489,"fetchStart":517.8999998569489,"redirectEnd":0,"redirectStart":0,"requestStart":517.8999998569489,"responseEnd":687.1999998092651,"responseStart":687.0999999046326,"secureConnectionStart":517.8999998569489},{"duration":262.10000014305115,"initiatorType":"link","name":"https://jira.mariadb.org/s/d5715adaadd168a9002b108b2b039b50-CDN/lu2cib/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/css/jira.project.sidebar,-_super,-project.issue.navigator,-jira.general,-jira.browse.project,-jira.view.issue,-jira.global,-atl.general,-com.atlassian.jira.projects.sidebar.init/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":792.1999998092651,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":792.1999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1054.2999999523163,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":104,"responseStart":283,"responseEnd":298,"domLoading":290,"domInteractive":1087,"domContentLoadedEventStart":1087,"domContentLoadedEventEnd":1144,"domComplete":1960,"loadEventStart":1960,"loadEventEnd":1961,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1067.5999999046326},{"name":"bigPipe.sidebar-id.end","time":1068.2999999523163},{"name":"bigPipe.activity-panel-pipe-id.start","time":1068.3999998569489},{"name":"bigPipe.activity-panel-pipe-id.end","time":1070.1999998092651},{"name":"activityTabFullyLoaded","time":1168.5}],"measures":[],"correlationId":"69e5abd125f09f","effectiveType":"4g","downlink":9.1,"rtt":0,"serverDuration":110,"dbReadsTimeInMs":19,"dbConnsTimeInMs":29,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Thinking deeper, this may need more effort to fix properly.
It is true that the values of virtual columns are redundant information for a table-rebuilding online ALTER when no indexes on virtual columns exist. And in this case, we should not expect a crash like this:
mysqld: /mariadb/10.2/storage/innobase/trx/trx0rec.cc:2426: void trx_undo_read_v_cols(const dict_table_t *, const byte *, const dtuple_t *, bool, const ulint *): Assertion `ptr == end_ptr' failed.
But, if there exist indexed virtual columns after the ALTER TABLE, the values of those columns must be available to row_log_table_apply(), either by evaluating the virtual column values (which could collide with
MDEV-11371compressed columns; seeMDEV-13359) or by retrieving the values from the online_log. Currently, if the ADD INDEX in the above test patch is enabled, the test will fail in a more graceful way:CURRENT_TEST: innodb.innodb-table-online
mysqltest: At line 280: query 'reap' failed: 1712: Index PRIMARY is corrupted
I remember another problematic scenario in MySQL 5.7 that was filed as an Oracle internal bug and probably remains open. It was something like ALTER TABLE…ADD INDEX(virtual_column) concurrently with an UPDATE that would affect the value of the virtual_column. Because the column was not indexed at the time when the UPDATE was logged, a garbage value of virtual_column would have been provided to row_log_online_op().