← Back to Pull requests

MDEV-40861 Table-rebuilding DDL on a not-up-to-date temp table resets the binlog state #6291

Open
unknown opened this pull request with 383 lines diff across 4 files
View on GitHub
unknown unknown commented on Dec 01, 2026 08:17 UTC
Author

  • The Jira issue number for this PR is: MDEV-40861
  • Also fixes MDEV-38770.

    Description

    Since MDEV-36099, a temporary table whose CREATE was logged, but some of whose changes were not, is marked as not up to date (table_creation_was_logged= 2), because the slave's copy is stale. mysql_alter_table() ignored this when an ALTER (or OPTIMIZE) rebuilt the table:

  • The ALTER was logged and applied to the slave's stale copy, where it can fail, for example ADD PRIMARY KEY with a duplicate key error (MDEV-38770).

  • The rebuilt table was marked as up to date, so later statements that read it were logged as statements and computed from the stale copy on the slave, silently giving different data (MDEV-40861).
  • Fix. When the table is not up to date and the statement is logged, log DROP TEMPORARY TABLE IF EXISTS for the old table instead of the ALTER, and leave the new table as not logged. The slave drops its stale copy, and statements that read the table are logged in row format. When the statement is not logged (OPTIMIZE, sql_log_bin=0), the table keeps its state. Tables that are up to date are not affected.

    Not changed: in a session with binlog_format=ROW, an ALTER of a logged temporary table still leaves the slave's copy open. This also happens for tables that are up to date.

    Release Notes

    Fixed replication of ALTER TABLE and OPTIMIZE TABLE on a temporary table that is not up to date in the binary log, with binlog_format=STATEMENT, or MIXED when create_tmp_table_binlog_formats includes MIXED. The slave could stop with an error, or silently get different data.

    How can this PR be tested?

    New test rpl.rpl_temp_table_alter. It covers an up-to-date table (the ALTER is logged as before), a not-up-to-date table with ALTER ... FORCE, the MDEV-38770 case, ALTER ... ADD COLUMN, RENAME, and OPTIMIZE. Without the fix, it fails at the first diff_tables, and the MDEV-38770 case stops the slave with error 1062. With the fix, it passes, also with --ps-protocol, --cursor-protocol and parallel replication. The test case from MDEV-40861 passes too.

    Full default test run: 5 tests fail (main.opt_trace_store_ddls, main.sp-security, sys_vars.path_basic, unit.pfs_instr-oom, unit.waiting_threads). All 5 fail the same way on this macOS machine without this change.

    Basing the PR against the correct MariaDB version


  • This is a new feature or a refactoring, and the PR is based against the main branch.

  • This is a bug fix, and the PR is based against the earliest maintained branch in which the bug can be reproduced.
  • The code comes from MDEV-36099 (first in 12.0.1), so 12.3 is the earliest maintained branch with the bug.

    PR quality check


  • I checked the CODING_STANDARDS.md file and my PR conforms to this where appropriate.

  • For any trivial modifications to the PR, I am ok with the reviewer making the changes themselves.
  • This contribution is made under the MariaDB Contributor Agreement (MCA).

    Diff: 383 lines (+287 / -96) across 4 files Reviewer: gkodinov Review duration: 907m
    All Vouch review confidence checks passed
    Residual risk 0.23 = Change Risk (0.43) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 383 lines diff across 4 files
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.356
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #6291"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 43.0% (MEDIUM) · Higher = larger blast radius
    43.0%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 22.9% · Safe to merge
    22.9%
    Repository