Skip to content

MDEV-41877 Partition function error still writes the row on MyISAM - #6243

Open
FarihaIS wants to merge 1 commit into
MariaDB:10.11from
FarihaIS:mdev-41877
Open

FarihaIS wants to merge 1 commit into
MariaDB:10.11from
FarihaIS:mdev-41877

Conversation

@FarihaIS

Copy link
Copy Markdown
Contributor

Description

An integer overflow in a partition function, for example HASH (-a) with a = -9223372036854775808, raises ER_DATA_OUT_OF_RANGE but does not set null_value. part_val_int() checked thd->is_error() only when null_value was set, so it returned 0 as a valid value. The row went to the partition for 0 and the statement ended with the error already in the diagnostics area. MyISAM kept the row, or the new value on UPDATE. On a debug build my_ok() hit the assertion !is_set() || (m_status == DA_OK_BULK && is_bulk_op()) in Diagnostics_area::set_ok_status().

Check thd->is_error() in part_val_int() regardless of null_value, so the row is not written. In ha_partition::is_fatal_error(), do not treat HA_ERR_NO_PARTITION_FOUND as ignorable when an error is already set, so INSERT IGNORE fails instead of skipping the row and sending OK. In ha_partition::print_error(), do not add "Table has no partition for value" on top of the existing error.

Add a test to main.partition.

Release Notes

N/A

How can this PR be tested?

Execute main.partition in mysql-test-run, with and without --ps-protocol.

This commit adds a test to main.partition that runs INSERT, multi-row INSERT, INSERT IGNORE, REPLACE and UPDATE on MyISAM tables whose partition function overflows.

  • It covers HASH, RANGE and LIST partitioning and subpartitions.
  • It checks that each statement fails with ER_DATA_OUT_OF_RANGE, that no row or new value is stored, and that SHOW WARNINGS lists only that error.

Before the fix

On a debug build, running main.partition fails as below:

main.partition                           [ fail ]
        Test ended at 2026-11-26 18:01:41

CURRENT_TEST: main.partition
mysqltest: At line 3168: query 'INSERT INTO t1 VALUES (-9223372036854775808)' failed with wrong errno <Unknown> (2013): 'Lost connection to server during query', instead of ER_DATA_OUT_OF_RANGE (1690)...

mariadbd: sql/sql_error.cc:344: void Diagnostics_area::set_ok_status(ulonglong, ulonglong, const char*): Assertion `!is_set() || (m_status == DA_OK_BULK && is_bulk_op())' failed.

#8  Diagnostics_area::set_ok_status (affected_rows=1, last_insert_id=0, message=0x0) at sql/sql_error.cc:344
#9  my_ok (affected_rows_arg=1, id=0, message=0x0) at sql/sql_class.h:6036
#10 mysql_insert (..., duplic=DUP_ERROR, ignore=false, result=0x0) at sql/sql_insert.cc:1428
#11 mysql_execute_command (is_called_from_prepared_stmt=false) at sql/sql_parse.cc:4664
#12 mysql_parse (rawbuf="INSERT INTO t1 VALUES (-9223372036854775808)", ...) at sql/sql_parse.cc:8219

After the fix

Running main.partition succeeds:

main.partition                           [ pass ]   2813

With --ps-protocol:

main.partition                           [ pass ]   4102

Basing the PR against the correct MariaDB version

  • This is a bug fix, and the PR is based against the earliest maintained branch on which the bug can be reproduced: 10.11.

Copyright

All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc.

An integer overflow in a partition function, for example HASH (-a) with
a = -9223372036854775808, raises ER_DATA_OUT_OF_RANGE but does not set
null_value. part_val_int() checked thd->is_error() only when null_value
was set, so it returned 0 as a valid value. The row went to the
partition for 0 and the statement ended with the error already in the
diagnostics area. MyISAM kept the row, or the new value on UPDATE. On a
debug build my_ok() hit the assertion `!is_set() || (m_status ==
DA_OK_BULK && is_bulk_op())` in Diagnostics_area::set_ok_status().

Check thd->is_error() in part_val_int() regardless of null_value, so the
row is not written. In ha_partition::is_fatal_error(), do not treat
HA_ERR_NO_PARTITION_FOUND as ignorable when an error is already set, so
INSERT IGNORE fails instead of skipping the row and sending OK. In
ha_partition::print_error(), do not add "Table has no partition for
value" on top of the existing error.

Add a test to main.partition.

All new code of the whole pull request, including one or several files
that are either new files or modified ones, are contributed under the
BSD-new license. I am contributing on behalf of my employer Amazon Web
Services, Inc.

Assisted-by: Claude:claude-opus-5.5
@FarihaIS
FarihaIS marked this pull request as ready for review November 26, 2026 20:40
@gkodinov gkodinov added the External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements. label Nov 27, 2026
@gkodinov gkodinov self-assigned this Nov 27, 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.

LGTM. Please stand by for the final review.

@gkodinov

Copy link
Copy Markdown
Member

FYI: According to our development cycle we work on bugs In the following periods 15 Mar-30 Apr, 15 Jun-30 Jul, 15 Sep-30 Oct and 15 Dec-31 Jan. So, please, expect to get a review somewhere between these two dates and the goal is to have your PR merged before the second date

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