Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-31946

Optimizer handle UCASE(varchar_col)=... does not work for UPDATE/DELETE

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Duplicate
    • 11.3(EOL)
    • 11.3.0
    • Optimizer
    • None

    Description

      Expected that UPDATE/DELETE will be used "index_condition": "t3.b = 'ABC'" as SELECT when " optimizer_switch='sargable_casefold=on'", but they still use "attached_condition": "ucase(t3.b) = 'ABC'"
      Testcase:

      set
        @tmp_switch_sarg_casefold=@@optimizer_switch,
        optimizer_switch='sargable_casefold=on';
       
      create table t3 (
        a varchar(32),
        b varchar(32),
        key(a),
        key(b)
      ) collate utf8mb3_general_ci;
      insert into t3 values ('abc','ABC'), ('xyz','XYZ'), ('123','abc'), ('456','xyz');
       
      explain format=json
      select* from t3 where upper(b)='ABC';
      select* from t3 where upper(b)='ABC';
       
      explain format=json
      update t3 set a='00' where upper(b)='ABC';
      update t3 set a='00' where upper(b)='ABC';
       
      select a from t3;
       
       
      explain format=json
      delete from t3 where upper(b)='ABC';
      delete from t3 where upper(b)='ABC';
       
      drop table t3;
       
      set optimizer_switch=@tmp_switch_sarg_casefold;
      

      Actual value:

      select* from t3 where upper(b)='ABC';
      EXPLAIN
      {
        "query_block": {
          "select_id": 1,
          "table": {
            "table_name": "t3",
            "access_type": "ref",
            "possible_keys": ["b"],
            "key": "b",
            "key_length": "99",
            "used_key_parts": ["b"],
            "ref": ["const"],
            "rows": 2,
            "filtered": 100,
            "index_condition": "t3.b = 'ABC'"
          }
        }
      }
       
       
      update t3 set a='00' where upper(b)='ABC';
      EXPLAIN
      {
        "query_block": {
          "select_id": 1,
          "table": {
            "update": 1,
            "table_name": "t3",
            "access_type": "ALL",
            "rows": 4,
            "attached_condition": "ucase(t3.b) = 'ABC'"
          }
        }
      }
       
      delete from t3 where upper(b)='ABC';
      EXPLAIN
      {
        "query_block": {
          "select_id": 1,
          "table": {
            "delete": 1,
            "table_name": "t3",
            "access_type": "ALL",
            "rows": 4,
            "attached_condition": "ucase(t3.b) = 'ABC'"
          }
        }
      }
      

      Attachments

        Issue Links

          Activity

            Fix pushed into bb-10.6-MDEV-31496 tree:

            commit b1b7cfe19e6a4218a8e4e0b40417f697a747545c (HEAD -> bb-10.6-MDEV-31496, origin/bb-10.6-MDEV-31496)
            Author: Sergei Petrunia <sergey@mariadb.com>
            Date:   Mon Aug 21 11:15:13 2023 +0300
             
                MDEV-31946: UCASE(varchar_col)=... not handled for UPDATE/DELETE
                
                Add the rewrite for UPDATE/DELETE.
            

            psergei Sergei Petrunia added a comment - Fix pushed into bb-10.6- MDEV-31496 tree: commit b1b7cfe19e6a4218a8e4e0b40417f697a747545c (HEAD -> bb-10.6-MDEV-31496, origin/bb-10.6-MDEV-31496) Author: Sergei Petrunia <sergey@mariadb.com> Date: Mon Aug 21 11:15:13 2023 +0300   MDEV-31946: UCASE(varchar_col)=... not handled for UPDATE/DELETE Add the rewrite for UPDATE/DELETE.

            Ok to push

            lstartseva Lena Startseva added a comment - Ok to push

            The fix for this is now a part of fix for MDEV-31496.

            psergei Sergei Petrunia added a comment - The fix for this is now a part of fix for MDEV-31496 .

            People

              psergei Sergei Petrunia
              lstartseva Lena Startseva
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.