Skip to content

MDEV-41989 : Fix duplicate key error code on cross-partition update - #6049

Open
girihimanshu540-prog wants to merge 2 commits into
MariaDB:mainfrom
girihimanshu540-prog:fix-mdev-41989
Open

girihimanshu540-prog wants to merge 2 commits into
MariaDB:mainfrom
girihimanshu540-prog:fix-mdev-41989

Conversation

@girihimanshu540-prog

@girihimanshu540-prog girihimanshu540-prog commented Nov 1, 2026 •

Copy link
Copy Markdown

#Jira: https://mariadb.org
Fixes: MDEV-41989

Description

Fixes a duplicate key handling regression where a cross-partition row update incorrectly returns ERROR 1022 (Can't write; duplicate key in table) instead of the expected ERROR 1062 (Duplicate entry...).

Fix

Introduced a variable saved_last_part to preserve the initial m_last_part context prior to updating the bulk insert partition state. If ha_update_row() encounters a failure within the cross-partition routine, the initial state is restored to ensure the error subsystem correctly references the expected table handler, properly returning ER_DUP_ENTRY.

@CLAassistant

CLAassistant commented Nov 1, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@gkodinov gkodinov added the External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements. label Nov 2, 2026
@gkodinov gkodinov self-assigned this Nov 2, 2026

@gkodinov gkodinov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution! This is a preliminary review.

Couple of things to fix:

  1. Please keep just one commit: fwiw, github can do merges with rebase. Please use that
  2. Please add a commit message to your commit
  3. We fix errors in the lowest affected version. In this case I'd suggest 11.4 since this is just a readability improvement and not something so critical that it'd warrant a fix in 10.11 (IMHO).
  4. the issues mentioned below: buildbot must be clean.

Comment thread sql/ha_partition.cc
}


uint32 saved_last_part= m_last_part;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this to the top of the function to fix the following compile error:

/home/buildbot/aarch64-debian-12/build/sql/ha_partition.cc: In member function ‘virtual int ha_partition::update_row(const uchar*, const uchar*)’:
/home/buildbot/aarch64-debian-12/build/sql/ha_partition.cc:4759:1: error: jump to label ‘exit’
 4759 | exit:
      | ^~~~
/home/buildbot/aarch64-debian-12/build/sql/ha_partition.cc:4716:10: note:   from here
 4716 |     goto exit;
      |          ^~~~
/home/buildbot/aarch64-debian-12/build/sql/ha_partition.cc:4719:10: note:   crosses initialization of ‘uint32 saved_last_part’
 4719 |   uint32 saved_last_part= m_last_part;
      |          ^~~~~~~~~~~~~~~
/home/buildbot/aarch64-debian-12/build/sql/ha_partition.cc:4759:1: error: jump to label ‘exit’
 4759 | exit:
      | ^~~~
/home/buildbot/aarch64-debian-12/build/sql/ha_partition.cc:4712:10: note:   from here
 4712 |     goto exit;
      |          ^~~~
/home/buildbot/aarch64-debian-12/build/sql/ha_partition.cc:4719:10: note:   crosses initialization of ‘uint32 saved_last_part’
 4719 |   uint32 saved_last_part= m_last_part;
      |          ^~~~~~~~~~~~~~~
make[2]: *** [sql/CMakeFiles/partition.dir/build.make:76: sql/CMakeFiles/partition.dir/ha_partition.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:11024: sql/CMakeFiles/partition.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....

@@ -0,0 +1,5 @@
CREATE TABLE t1 (id INT PRIMARY KEY, a INT) ENGINE=MyISAM PARTITION BY HASH (id) PARTITIONS 2;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this test into the relevant partitioning suite and pick a file to put it in that's testing similar things.
Or keep it in a separate file, but prefix it with

--echo # 
--echo # MDEV-41989: Fix duplicate key error code on cross-partition update - #6049
--echo #

And suffix it with

--echo End of 11.4 tests

Also, make sure to use the following at the top (as the rest of the part suite files do):

# The server must support partitioning.
--source include/have_partition.inc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements.

Development

Successfully merging this pull request may close these issues.

3 participants