← Back to Pull requests

MDEV-40089 Preserve unsigned cached integers in real comparisons #5769

Open
DerZc opened this pull request with 15 lines diff across 3 files
View on GitHub
DerZc DerZc commented on Sep 28, 2026 06:05 UTC
Author

Item_cache_int::val_real() interprets stored unsigned bits as a signed integer before converting to DOUBLE. Values above LLONG_MAX become negative, so a BETWEEN predicate using a cached ~TRUE bound can wrongly discard rows.

Use unsigned_flag to convert unsigned cached values through ulonglong before converting to DOUBLE.

Regression coverage

Add one query to main.func_bit with a bitwise complement and a VARCHAR column. Two rows prevent constant-table optimization from bypassing the cache. Both should satisfy IS FALSE because zero is below the unsigned lower bound; ORDER BY makes the result deterministic.

The five-line test needs no InnoDB prerequisite, SET, database creation, manual prepared statements or duplicate queries. Existing test prerequisites remain unchanged, and MTR supplies prepared-statement and view protocol coverage.

Validation

On current 11.4 at f49e838d367f2154b3edb43effa99ff9eb0d8602:

  • The unmodified server fails main.func_bit only on the new query, returning no rows instead of 0 and 1.

  • The patched Release build succeeds.

  • Normal protocol: main.func_bit, main.select, main.type_bit, main.type_bit_innodb, main.type_decimal and main.type_float pass.

  • Prepared-statement protocol: main.func_bit passes.

  • View protocol: main.func_bit passes.

  • Expected rows are independently derived from unsigned 64-bit complement arithmetic and numeric comparison.

  • The full database regression suite was not run.
  • Bug report: https://jira.mariadb.org/browse/MDEV-40089

    Diff: 15 lines (+14 / -1) across 3 files Reviewer: gkodinov Review duration: 23788m
    All Vouch review confidence checks passed
    Residual risk 0.02 = Change Risk (0.23) × (1 − Review Confidence (0.90)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.23 · 15 lines diff across 3 files
    0.23
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.91 · 3 substantive comment(s)
    0.91
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    89%
    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.166
    Real PR Conversation Timeline
    6 items
    gkodinov gkodinov commented on code on Sep 28, 2026 11:04 UTC
    Code Review
    mysql-test/main/func_bit.test:1
    @@ -1,3 +1,4 @@
    +--source include/have_innodb.inc

    this might have side effects on the pre-existing tests. if you need something like that add a new test file.

    gkodinov gkodinov commented on code on Sep 28, 2026 11:04 UTC
    Code Review
    mysql-test/main/func_bit.test:1
    @@ -95,3 +96,65 @@ SELECT BIT_COUNT(-9223372036854775808e0) AS c1;
     --echo #
     --echo # End of 10.5 tests
     --echo #
    +
    +--echo #
    +--echo # Start of 11.4 tests
    +--echo #
    +--echo # MDEV-40089 Wrong result for BETWEEN predicate involving bitwise negation and implicit type conversion
    +--echo #
    +SET @save_optimizer_switch=@@optimizer_switch;

    no redundant SET or CREATE DATABASE statements please.
    avoid anything that is not essential to the regression test at hand.

    gkodinov gkodinov commented on code on Sep 28, 2026 11:05 UTC
    Code Review
    mysql-test/main/func_bit.test:1
    @@ -95,3 +96,65 @@ SELECT BIT_COUNT(-9223372036854775808e0) AS c1;
     --echo #
     --echo # End of 10.5 tests
     --echo #
    +
    +--echo #
    +--echo # Start of 11.4 tests
    +--echo #
    +--echo # MDEV-40089 Wrong result for BETWEEN predicate involving bitwise negation and implicit type conversion
    +--echo #
    +SET @save_optimizer_switch=@@optimizer_switch;
    +SET @save_sql_mode=@@sql_mode;
    +SET @save_default_storage_engine=@@default_storage_engine;
    +SET @save_character_set_client=@@character_set_client;
    +SET @save_character_set_results=@@character_set_results;
    +SET @save_character_set_connection=@@character_set_connection;
    +SET @save_collation_connection=@@collation_connection;
    +CREATE DATABASE bug_40089 CHARACTER SET utf8mb4 COLLATE utf8mb4_uca1400_ai_ci;
    +USE bug_40089;
    +SET sql_mode=DEFAULT;
    +SET optimizer_switch=DEFAULT;
    +SET default_storage_engine=InnoDB;
    +SET NAMES utf8mb4 COLLATE utf8mb4_general_ci;
    +CREATE TABLE t0 (c1 VARCHAR(54));
    +INSERT INTO t0 VALUES ('jnbF3LETSTP');
    +--sorted_result
    +SELECT c1 FROM t0 WHERE ('' BETWEEN (~TRUE) AND c1) IS FALSE;
    +PREPARE regression_stmt FROM 'SELECT c1 FROM t0 WHERE ('''' BETWEEN (~TRUE) AND c1) IS FALSE;';
    +--sorted_result
    +EXECUTE regression_stmt;

    remove all the redundant queries that do not contribute to code coverage please. in this particular case mtr runs tests with view and prepared statements protocols.

    gkodinov gkodinov requested changes on Sep 28, 2026 11:07 UTC
    Changes Requested Reviewer

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

    One general note on the commit message: please do not summarize the changes done.

    Good commit messages usually follow the following pattern:

    1. what was wrong exactly
    2. how it was fixed
    3. how was the fix tested.

    gkodinov gkodinov approved these changes on Sep 29, 2026 10:14 UTC
    Approved Reviewer

    LGTM. Thanks! Please stand by for the final review.

    Reviewers
    Assignees
    DerZc DerZc
    Labels
    risk: low confidence: 89.9% 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: 22.5% (LOW) · Higher = larger blast radius
    22.5%
    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: 89.9% · Lower = rushed or shallow review
    89.9%
    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: 2.3% · Safe to merge
    2.3%
    Repository