← Back to Pull requests

MDEV-10436 non-deterministic vcol does not force rbr #6208

Open
unknown opened this pull request with 281 lines diff across 3 files
View on GitHub
unknown unknown commented on Nov 24, 2026 10:12 UTC
Author

Description

In MIXED binlog format, statements reading a table with a
non-deterministic virtual column (e.g. RAND()) were logged in
statement format, so a slave recomputes the column and may end up
with different data. RAND() written directly in a statement is
already marked unsafe at parse time, but virtual column expressions
are parsed separately and never marked the statement unsafe.

Fix: collect the flags of all virtual columns into a new
TABLE_SHARE::vcol_flags in parse_vcol_defs(), and in
THD::decide_logging_format() mark the statement unsafe
(BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION) when a table with a
VCOL_NON_DETERMINISTIC or VCOL_SESSION_FUNC virtual column is read,
or is the target of UPDATE/DELETE.

Design notes

  • Follows Sergei's 2017 review of the earlier patch: a uint vcol_flags

  • (OR of vcol_info->flags) stored once in TABLE_SHARE and checked per
    table in decide_logging_format(), instead of iterating fields per
    statement.
  • Per table rather than per column, since read_set is not populated yet

  • when decide_logging_format() runs from lock_tables(). This may
    over-approximate (e.g. INSERT ... SELECT a FROM t2 not reading the
    vcol), which only costs binlog size.
  • Only VIRTUAL columns: STORED ones are computed once at insert, so

  • reading them is deterministic.
  • Uses VCOL_NON_DETERMINISTIC | VCOL_SESSION_FUNC but not TIME_FUNC,

  • matching the existing non_determinstic_insert check; time functions
    are safe as TIMESTAMP is replicated.
  • Reuses BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION (same reason as RAND()

  • used directly) to avoid adding a new error message in a GA branch.

    How can this PR be tested?

    Added to binlog.binlog_unsafe: four statements reading a RAND() vcol
    now produce the unsafe warning in STATEMENT mode, three that don't read
    it (or read only a NOW() vcol) do not, and in MIXED mode the
    INSERT ... SELECT is logged as Write_rows. Also ran the binlog, vcol and
    rpl suites locally; rpl.rpl_parallel_sbm,
    binlog.binlog_expire_logs_seconds and
    binlog.binlog_show_binlog_events_invalid_offset_silent failed under
    parallel load and look timing-related/unrelated, but I have not
    confirmed them against an unpatched build.

    Licensing

    I am contributing this under the 3-clause BSD license.

    Diff: 281 lines (+210 / -71) across 3 files Reviewer: gkodinov Review duration: 9844m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.40) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 281 lines diff across 3 files
    0.40
    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
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.338
    Real PR Conversation Timeline
    1 comments
    "Review active on #6208"
    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: 39.7% (MEDIUM) · Higher = larger blast radius
    39.7%
    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: 21.1% · Safe to merge
    21.1%
    Repository