Skip to content

MDEV-38839 Assertion (thd->state_flags & Open_tables_state::BACKUPS_A… - #5027

Merged
mariadb-PranavTiwari merged 2 commits into
12.3from
12.3-MDEV-38839
Oct 11, 2026
Merged

mariadb-PranavTiwari merged 2 commits into
12.3from
12.3-MDEV-38839

Conversation

@mariadb-PranavTiwari

@mariadb-PranavTiwari mariadb-PranavTiwari commented May 1, 2026 •

Copy link
Copy Markdown
Contributor

fixes MDEV-38839

Problem:

CREATE TABLE ... SELECT ... FOR UPDATE involving a MyISAM temporary table can trigger an assertion in close_thread_tables() when binary logging is enabled in MIXED mode.

Cause:

MyISAM temporary tables do not support row-level locking, so FOR UPDATE acquires a write lock even for read-only access. This causes the table to be incorrectly classified as a write operation, preventing binlog_truncate_trx_cache() from running and ultimately triggering an assertion.

Fix:

Update decide_logging_format() to check tbl->updating and distinguish actual writes from read-only access. For read-only access to temporary non-transactional tables, mark the statement as STMT_READS_TEMP_NON_TRANS_TABLE instead of treating it as a write. This prevents incorrect write classification and avoids the assertion failure.

@mariadb-PranavTiwari
mariadb-PranavTiwari marked this pull request as draft May 1, 2026 03:29
@mariadb-PranavTiwari
mariadb-PranavTiwari force-pushed the 12.3-MDEV-38839 branch 4 times, most recently from 58ff35c to afea455 Compare May 3, 2026 01:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes binlog table-access classification for CREATE TABLE ... SELECT when the source is a temporary table, aiming to avoid incorrectly treating read-only temp-table access as a write and thereby prevent MIXED-mode binlog cache state from getting stuck and triggering the reported assertion.

Changes:

  • Add a dedicated stmt_writes_to_non_trans_temp_table() helper and use it when marking non-transactional temp-table modifications in binlog write paths.
  • Adjust THD::decide_logging_format() so CREATE TABLE ... SELECT can classify temporary source-table access as reads instead of writes.
  • Add an MTR regression test covering several temp-table engine combinations around CREATE TABLE ... SELECT ... FOR UPDATE.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
sql/sql_lex.h Adds a helper to distinguish non-transactional temp-table writes from general access.
sql/sql_class.cc Changes table-access flag assignment during logging-format analysis for CREATE TABLE.
sql/log.cc Narrows the condition that marks a non-transactional temp table as modified in transactional cache paths.
mysql-test/main/binlog_mdev38839.test Adds a regression test for the reported assertion scenario.
mysql-test/main/binlog_mdev38839.result Records the expected output for the new regression test.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread sql/sql_class.cc Outdated
Comment thread mysql-test/main/binlog_mdev38839.test Outdated
@mariadb-PranavTiwari
mariadb-PranavTiwari marked this pull request as ready for review May 4, 2026 08:58
Comment thread mysql-test/main/binlog_mdev38839.test Outdated
Comment thread sql/sql_class.cc Outdated
Comment thread sql/sql_class.cc Outdated
Comment thread sql/sql_class.cc
Comment thread mysql-test/main/binlog_mdev38839.test Outdated
Comment thread sql/sql_class.cc
Comment thread sql/sql_class.cc Outdated
@mariadb-PranavTiwari
mariadb-PranavTiwari force-pushed the 12.3-MDEV-38839 branch 3 times, most recently from 2393bb5 to f3b5b86 Compare May 7, 2026 05:57
Comment thread mysql-test/main/binlog_mdev38839.test Outdated
Comment thread mysql-test/main/binlog_mdev38839.test Outdated
Comment thread sql/sql_class.cc Outdated
@mariadb-PranavTiwari
mariadb-PranavTiwari force-pushed the 12.3-MDEV-38839 branch 2 times, most recently from 76b8145 to fa8cf40 Compare May 7, 2026 10:35
@mariadb-PranavTiwari
mariadb-PranavTiwari marked this pull request as draft May 8, 2026 11:29
@CLAassistant

CLAassistant commented Jul 6, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@midenok
midenok force-pushed the 12.3-MDEV-38839 branch from 7d154bc to 4c1db76 Compare July 6, 2026 12:50

@midenok midenok left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, except couple of minor notes and unexpected --disable_warnings directive. Please pay attention that I have pushed new comment for the table_list->updating flag to this branch.

Comment thread sql/sql_lex.cc Outdated
Comment thread mysql-test/suite/rpl/t/rpl_mysql_upgrade.test Outdated
Comment thread mysql-test/suite/binlog/t/binlog_bug38839.test Outdated
Comment thread sql/sql_lex.cc
@mariadb-PranavTiwari

Copy link
Copy Markdown
Contributor Author

LGTM, except couple of minor notes and unexpected --disable_warnings directive. Please pay attention that I have pushed new comment for the table_list->updating flag to this branch.

Incorporated code review comments.

midenok and others added 2 commits October 10, 2026 18:04
…_AVAIL) || !thd->has_pending_row_events()` failed in close_thread_tables on CREATE TABLE

Problem:
CREATE TABLE ... SELECT ... FOR UPDATE involving a MyISAM temporary table can trigger an assertion in close_thread_tables() when binary logging is enabled in MIXED mode.

Cause:
MyISAM temporary tables do not support row-level locking, so SELECT ... FOR UPDATE acquires a write lock even when the access is read-only. This causes the table to be incorrectly classified as a write operation, preventing binlog_truncate_trx_cache() from running and eventually triggering the assertion.

Fix:
Update decide_logging_format() to use tbl->updating to distinguish actual table modifications from read-only accesses. For read-only access to temporary non-transactional tables, mark the statement as STMT_READS_TEMP_NON_TRANS_TABLE instead of treating it as a write operation. This prevents incorrect write classification and avoids the assertion failure.
@mariadb-PranavTiwari
mariadb-PranavTiwari merged commit 5e1d303 into 12.3 Oct 11, 2026
19 checks passed
@dr-m
dr-m deleted the 12.3-MDEV-38839 branch October 13, 2026 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

5 participants