← Back to Pull requests

MDEV-39853 Preserve rows with ignorable prefixes in UCA range scans #5771

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

A prefix index under a UCA collation can contain only ignorable characters. The prefix then sorts below a lower bound even when the complete value satisfies the predicate, so both > and >= range scans can omit valid rows.

Keep the lower range open for partial UCA keys and check the complete value against the predicate. Add two comparisons on a stored generated column using only two input rows: one equal to the bound and one beginning with the ignorable U+065B character. Their expected counts are 1 and 2.

Bug report: https://jira.mariadb.org/browse/MDEV-39853

Validation

On current 11.4 at f49e838d367f2154b3edb43effa99ff9eb0d8602:

  • The unmodified server returns 0 and 1 for the new regression instead of 1 and 2. All preceding results in main.ctype_utf8mb4 match.

  • Separate full-scan controls on the earlier 322658cd baseline confirm the expected counts on both MyISAM and InnoDB.

  • The patched Release build succeeds.

  • Native MTR passes: main.ctype_utf8mb4, main.ctype_utf8, main.select, main.view, main.range, main.range_mrr_icp, main.innodb_icp, main.myisam_icp.

  • main.ctype_utf8mb4 and main.ctype_utf8 also pass with the prepared-statement protocol.

  • The full server test suite was not run.
  • Diff: 34 lines (+32 / -2) across 3 files Reviewer: gkodinov Review duration: 23696m
    All Vouch review confidence checks passed
    Residual risk 0.03 = Change Risk (0.27) × (1 − Review Confidence (0.90)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.27 · 34 lines diff across 3 files
    0.27
    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.213
    Real PR Conversation Timeline
    6 items
    gkodinov gkodinov commented on code on Sep 28, 2026 10:43 UTC
    Code Review
    mysql-test/main/ctype_utf8mb4.test:1
    @@ -2246,3 +2246,138 @@ DROP TABLE t1;
     --echo #
     --echo # End of 10.11 tests
     --echo #
    +
    +--echo #
    +--echo # Start of 11.4 tests
    +--echo #
    +--echo # MDEV-39853 Prefix index range scan on STORED generated column incorrectly skips rows containing Unicode combining characters
    +--echo #
    +SET @save_optimizer_switch=@@optimizer_switch;

    please simplify the regression test: no SET, no CREATE DATABASE unless required.

    gkodinov gkodinov commented on code on Sep 28, 2026 10:43 UTC
    Code Review
    mysql-test/main/ctype_utf8mb4.test:1
    @@ -2246,3 +2246,138 @@ DROP TABLE t1;
     --echo #
     --echo # End of 10.11 tests
     --echo #
    +
    +--echo #
    +--echo # Start of 11.4 tests
    +--echo #
    +--echo # MDEV-39853 Prefix index range scan on STORED generated column incorrectly skips rows containing Unicode combining characters
    +--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_39853 CHARACTER SET utf8mb4 COLLATE utf8mb4_uca1400_ai_ci;
    +USE bug_39853;
    +SET sql_mode=DEFAULT;
    +SET optimizer_switch=DEFAULT;
    +SET default_storage_engine=InnoDB;
    +SET NAMES utf8mb4 COLLATE utf8mb4_general_ci;
    +SET NAMES utf8mb4;
    +CREATE TABLE t (c1 INT,c2 VARCHAR(64) NOT NULL,c3 VARCHAR(64) AS (TRIM(c2)) STORED);
    +INSERT INTO t (c1,c2) VALUES (1,'A'),(2,'-804207268'),(3,'ٛRIRS/*');
    +CREATE INDEX idx_full ON t(c3);
    +CREATE INDEX idx_prefix ON t(c3(1));
    +--sorted_result
    +SELECT COUNT(*) FROM t FORCE INDEX(idx_prefix) WHERE c3>'-804207268';
    +PREPARE regression_stmt FROM 'SELECT COUNT(*) FROM t FORCE INDEX(idx_prefix) WHERE c3>''-804207268'';';

    mtr already does that. No need for tests that do not add to test coverage.

    gkodinov gkodinov commented on code on Sep 28, 2026 10:44 UTC
    Code Review
    mysql-test/main/ctype_utf8mb4.test:1
    @@ -2246,3 +2246,138 @@ DROP TABLE t1;
     --echo #
     --echo # End of 10.11 tests
     --echo #
    +
    +--echo #
    +--echo # Start of 11.4 tests
    +--echo #
    +--echo # MDEV-39853 Prefix index range scan on STORED generated column incorrectly skips rows containing Unicode combining characters
    +--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_39853 CHARACTER SET utf8mb4 COLLATE utf8mb4_uca1400_ai_ci;
    +USE bug_39853;
    +SET sql_mode=DEFAULT;
    +SET optimizer_switch=DEFAULT;
    +SET default_storage_engine=InnoDB;
    +SET NAMES utf8mb4 COLLATE utf8mb4_general_ci;
    +SET NAMES utf8mb4;
    +CREATE TABLE t (c1 INT,c2 VARCHAR(64) NOT NULL,c3 VARCHAR(64) AS (TRIM(c2)) STORED);
    +INSERT INTO t (c1,c2) VALUES (1,'A'),(2,'-804207268'),(3,'ٛRIRS/*');
    +CREATE INDEX idx_full ON t(c3);
    +CREATE INDEX idx_prefix ON t(c3(1));
    +--sorted_result
    +SELECT COUNT(*) FROM t FORCE INDEX(idx_prefix) WHERE c3>'-804207268';
    +PREPARE regression_stmt FROM 'SELECT COUNT(*) FROM t FORCE INDEX(idx_prefix) WHERE c3>''-804207268'';';
    +--sorted_result
    +EXECUTE regression_stmt;
    +--sorted_result
    +EXECUTE regression_stmt;
    +DEALLOCATE PREPARE regression_stmt;
    +--sorted_result
    +SELECT COUNT(*) FROM t WHERE c3>'-804207268';
    +--sorted_result
    +SELECT COUNT(IF(c3>'-804207268',1,NULL)) FROM t FORCE INDEX(idx_prefix);
    +--sorted_result
    +SELECT COUNT(*) FROM t FORCE INDEX(idx_prefix) WHERE NOT NOT (c3>'-804207268');

    please remove the redundant tests here that do not contribute to test coverage.

    gkodinov gkodinov requested changes on Sep 28, 2026 10:44 UTC
    Changes Requested Reviewer

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

    gkodinov gkodinov approved these changes on Sep 29, 2026 10:08 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: 27.2% (LOW) · Higher = larger blast radius
    27.2%
    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.8% · Safe to merge
    2.8%
    Repository