EXCHANGE/CONVERT ... WITHOUT VALIDATION are supposed to bypass the check that each row belongs to the partition in question. However as a side-effect it also allows to bypass unique constraints, and it seems there is no good way to repair it. REPAIR TABLE, REPAIR PARTITION, REBUILD PARTITION don't help. REPAIR TABLE upon the failed attempt points at the duplicate key value suggesting to handle it manually, but since it only shows one violation at a time and there can be thousands or millions such records after unfortunate alter without validation, it is not really a feasible way to recover. Dump/reload which CHECK suggests also doesn't work as it simply tries to re-insert duplicate records into the table.
Note: REBUILD PARTITION fails with different errors on a release build and with an assertion failure on debug builds (similar to MDEV-20498), which is why it is commented in the test case below.
--source include/have_partition.inc
createtable t1 (a intunique) partition by range(a) (
partition p0 values less than (100),
partition p1 values less than (maxvalue)
);
insertinto t1 values (1),(2),(3);
createtable t (a intunique);
insertinto t values (1),(3);
altertable t1 exchange partition p1 withtable t without validation;
checktable t1 extended;
repair table t1;
altertable t1 repair partition p1;
#altertable t1 rebuild partition p1;
checktable t1 extended;
select * from t1;
# Cleanup
droptableif exists t1, t;
11.4 5462b61b0c3ae59d3996018d7da34220460baf46
altertable t1 exchange partition p1 withtable t without validation;
checktable t1 extended;
Table Op Msg_type Msg_text
test.t1 check error Found a misplaced row
test.t1 check error Partition p1 returned error
test.t1 check error Upgrade required. Please do "REPAIR TABLE `t1`"or dump/reload to fix it!
repair table t1;
Table Op Msg_type Msg_text
test.t1 repair error Failed tomove/insert a row from part 1 into part 0:
Duplicate key found, please updateordelete the record:
a:1
test.t1 repair error Partition p1 returned error
test.t1 repair error Corrupt
altertable t1 repair partition p1;
Table Op Msg_type Msg_text
test.t1 repair error Failed tomove/insert a row from part 1 into part 0:
Duplicate key found, please updateordelete the record:
a:1
test.t1 repair error Partition p1 returned error
test.t1 repair error Corrupt
checktable t1 extended;
Table Op Msg_type Msg_text
test.t1 check error Found a misplaced row
test.t1 check error Partition p1 returned error
test.t1 check error Upgrade required. Please do "REPAIR TABLE `t1`"or dump/reload to fix it!
select * from t1;
a
1
1
2
3
3
MySQL 8.2 doesn't look any better, except for maybe the assertion failure.
Attachments
Issue Links
is caused by
MDEV-22164WITHOUT VALIDATION for EXCHANGE PARTITION/CONVERT IN
I didn't make it a "blocker" for MDEV-22164 feature, as I'm not sure whether anything can be done about it. MySQL behaves in the same way, but it's unclear whether it's the expected outcome or an omission, at least MySQL manual doesn't say anything about it (and usually, if it were a known effect, it would have).
Elena Stepanova
added a comment - I didn't make it a "blocker" for MDEV-22164 feature, as I'm not sure whether anything can be done about it. MySQL behaves in the same way, but it's unclear whether it's the expected outcome or an omission, at least MySQL manual doesn't say anything about it (and usually, if it were a known effect, it would have).
sure, there is a way to repair the table. something like
deletefrom t1 where a in (select a from t1 groupby a havingcount(a) > 1)
but let's say REPAIR TABLE should be able to repair the table too
Sergei Golubchik
added a comment - - edited sure, there is a way to repair the table. something like
delete from t1 where a in ( select a from t1 group by a having count (a) > 1)
but let's say REPAIR TABLE should be able to repair the table too
sure, there is a way to repair the table. something like
deletefrom t1 where a in (select a from t1 groupby a havingcount(a) > 1)
Sure, when I said "no way to repair", I meant a meaningful way with a predictable result and preferably with minimal data loss. Otherwise there are other ways – one can truncate the table, or drop the newly added partition, etc.
For the above query and its likes, as the table is broken, the behavior is undefined. It may delete all rows with these keys (not just duplicates), or, if one's more lucky, it may delete the old good records and preserve the new not-so-good ones. With the data from the description, for InnoDB it does the former and for MyISAM the latter, but I suppose it can depend on many factors.
Elena Stepanova
added a comment - - edited
sure, there is a way to repair the table. something like
delete from t1 where a in ( select a from t1 group by a having count (a) > 1)
Sure, when I said "no way to repair", I meant a meaningful way with a predictable result and preferably with minimal data loss. Otherwise there are other ways – one can truncate the table, or drop the newly added partition, etc.
For the above query and its likes, as the table is broken, the behavior is undefined. It may delete all rows with these keys (not just duplicates), or, if one's more lucky, it may delete the old good records and preserve the new not-so-good ones. With the data from the description, for InnoDB it does the former and for MyISAM the latter, but I suppose it can depend on many factors.
It seems there is a more or less universal (although not immediately obvious) way to fix a variety of problems with such tables, including the one describe in this ticket: ALTER IGNORE TABLE ... FORCE, ALGORITHM=COPY.
The table gets rebuilt and misplaced rows are moved around, while IGNORE ensures that the operation doesn't fail on duplicate keys, and duplicate entries are removed instead.
Algorithm is important for InnoDB, as otherwise it's inplace and doesn't do much.
insertinto t1 values (1),(2),(3);
createtable t (a intunique);
insertinto t values (1),(3);
altertable t1 exchange partition p1 withtable t without validation;
checktable t1 extended;
Table Op Msg_type Msg_text
test.t1 check error Found a misplaced row
test.t1 check error Partition p1 returned error
test.t1 check error Upgrade required. Please do "REPAIR TABLE `t1`"or dump/reload to fix it!
alterignoretable t1 force, algorithm=copy;
checktable t1 extended;
Table Op Msg_type Msg_text
test.t1 check status OK
select * from t1;
a
1
2
3
select * from t1 partition (p0);
a
1
2
3
select * from t1 partition (p1);
a
Elena Stepanova
added a comment - - edited It seems there is a more or less universal (although not immediately obvious) way to fix a variety of problems with such tables, including the one describe in this ticket: ALTER IGNORE TABLE ... FORCE, ALGORITHM=COPY .
The table gets rebuilt and misplaced rows are moved around, while IGNORE ensures that the operation doesn't fail on duplicate keys, and duplicate entries are removed instead.
Algorithm is important for InnoDB, as otherwise it's inplace and doesn't do much.
insert into t1 values (1),(2),(3);
create table t (a int unique );
insert into t values (1),(3);
alter table t1 exchange partition p1 with table t without validation;
check table t1 extended;
Table Op Msg_type Msg_text
test.t1 check error Found a misplaced row
test.t1 check error Partition p1 returned error
test.t1 check error Upgrade required. Please do "REPAIR TABLE `t1`" or dump/reload to fix it!
alter ignore table t1 force , algorithm=copy;
check table t1 extended;
Table Op Msg_type Msg_text
test.t1 check status OK
select * from t1;
a
1
2
3
select * from t1 partition (p0);
a
1
2
3
select * from t1 partition (p1);
a
People
Alexey Botchkov
Elena Stepanova
Votes:
0Vote for this issue
Watchers:
4Start watching this issue
Dates
Created:
Updated:
Git Integration
Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.
{"report":{"fcp":983.5,"ttfb":232.90000009536743,"pageVisibility":"visible","entityId":127083,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"7f59121f-adda-4aa9-bdbb-492da4a23f0f","navigationType":0,"readyForUser":1059,"redirectCount":0,"resourceLoadedEnd":1058,"resourceLoadedStart":312.2999999523163,"resourceTiming":[{"duration":50.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":312.2999999523163,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":312.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":362.7999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":50.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/2bf333562ca6724060a9d5f1535471f6/_/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","startTime":312.59999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":312.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":363.09999990463257,"responseStart":0,"secureConnectionStart":0},{"duration":121.69999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":312.90000009536743,"connectEnd":312.90000009536743,"connectStart":312.90000009536743,"domainLookupEnd":312.90000009536743,"domainLookupStart":312.90000009536743,"fetchStart":312.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":312.90000009536743,"responseEnd":434.59999990463257,"responseStart":434.59999990463257,"secureConnectionStart":312.90000009536743},{"duration":198.40000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/2bf333562ca6724060a9d5f1535471f6/_/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","startTime":313,"connectEnd":313,"connectStart":313,"domainLookupEnd":313,"domainLookupStart":313,"fetchStart":313,"redirectEnd":0,"redirectStart":0,"requestStart":313,"responseEnd":511.40000009536743,"responseStart":511.40000009536743,"secureConnectionStart":313},{"duration":202.59999990463257,"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":313.2000000476837,"connectEnd":313.2000000476837,"connectStart":313.2000000476837,"domainLookupEnd":313.2000000476837,"domainLookupStart":313.2000000476837,"fetchStart":313.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":313.2000000476837,"responseEnd":515.7999999523163,"responseStart":515.7999999523163,"secureConnectionStart":313.2000000476837},{"duration":203,"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":313.40000009536743,"connectEnd":313.40000009536743,"connectStart":313.40000009536743,"domainLookupEnd":313.40000009536743,"domainLookupStart":313.40000009536743,"fetchStart":313.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":313.40000009536743,"responseEnd":516.4000000953674,"responseStart":516.4000000953674,"secureConnectionStart":313.40000009536743},{"duration":203.20000004768372,"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":313.59999990463257,"connectEnd":313.59999990463257,"connectStart":313.59999990463257,"domainLookupEnd":313.59999990463257,"domainLookupStart":313.59999990463257,"fetchStart":313.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":313.59999990463257,"responseEnd":516.7999999523163,"responseStart":516.7999999523163,"secureConnectionStart":313.59999990463257},{"duration":290,"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":313.7999999523163,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":313.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":603.7999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":203.89999985694885,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":313.90000009536743,"connectEnd":313.90000009536743,"connectStart":313.90000009536743,"domainLookupEnd":313.90000009536743,"domainLookupStart":313.90000009536743,"fetchStart":313.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":313.90000009536743,"responseEnd":517.7999999523163,"responseStart":517.7999999523163,"secureConnectionStart":313.90000009536743},{"duration":290.2000000476837,"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":314,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":314,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":604.2000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":204.20000004768372,"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":314.2000000476837,"connectEnd":314.2000000476837,"connectStart":314.2000000476837,"domainLookupEnd":314.2000000476837,"domainLookupStart":314.2000000476837,"fetchStart":314.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":314.2000000476837,"responseEnd":518.4000000953674,"responseStart":518.4000000953674,"secureConnectionStart":314.2000000476837},{"duration":724.8999998569489,"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":315.2000000476837,"connectEnd":315.2000000476837,"connectStart":315.2000000476837,"domainLookupEnd":315.2000000476837,"domainLookupStart":315.2000000476837,"fetchStart":315.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":315.2000000476837,"responseEnd":1040.0999999046326,"responseStart":1040.0999999046326,"secureConnectionStart":315.2000000476837},{"duration":694.4000000953674,"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":363.59999990463257,"connectEnd":363.59999990463257,"connectStart":363.59999990463257,"domainLookupEnd":363.59999990463257,"domainLookupStart":363.59999990463257,"fetchStart":363.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":363.59999990463257,"responseEnd":1058,"responseStart":1058,"secureConnectionStart":363.59999990463257},{"duration":423,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":618.5,"connectEnd":618.5,"connectStart":618.5,"domainLookupEnd":618.5,"domainLookupStart":618.5,"fetchStart":618.5,"redirectEnd":0,"redirectStart":0,"requestStart":618.5,"responseEnd":1041.5,"responseStart":1041.5,"secureConnectionStart":618.5},{"duration":259.5,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":935.5999999046326,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":935.5999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1195.0999999046326,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":43,"responseStart":233,"responseEnd":362,"domLoading":271,"domInteractive":1224,"domContentLoadedEventStart":1224,"domContentLoadedEventEnd":1283,"domComplete":1528,"loadEventStart":1528,"loadEventEnd":1529,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1204},{"name":"bigPipe.sidebar-id.end","time":1204.7000000476837},{"name":"bigPipe.activity-panel-pipe-id.start","time":1204.9000000953674},{"name":"bigPipe.activity-panel-pipe-id.end","time":1207.7000000476837},{"name":"activityTabFullyLoaded","time":1296.2000000476837}],"measures":[],"correlationId":"aba6d821c7d019","effectiveType":"4g","downlink":9.5,"rtt":0,"serverDuration":113,"dbReadsTimeInMs":14,"dbConnsTimeInMs":22,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
I didn't make it a "blocker" for
MDEV-22164feature, as I'm not sure whether anything can be done about it. MySQL behaves in the same way, but it's unclear whether it's the expected outcome or an omission, at least MySQL manual doesn't say anything about it (and usually, if it were a known effect, it would have).