[MDEV-31946] Optimizer handle UCASE(varchar_col)=... does not work for UPDATE/DELETE Created: 2023-08-18  Updated: 2023-08-24  Resolved: 2023-08-24

Status: Closed
Project: MariaDB Server
Component/s: Optimizer
Affects Version/s: 11.3
Fix Version/s: 11.3.0

Type: Bug Priority: Major
Reporter: Lena Startseva Assignee: Sergei Petrunia
Resolution: Duplicate Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-31496 Make optimizer handle UCASE(varchar_c... Closed

 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'"
    }
  }
}



 Comments   
Comment by Sergei Petrunia [ 2023-08-21 ]

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.

Comment by Lena Startseva [ 2023-08-23 ]

Ok to push

Comment by Sergei Petrunia [ 2023-08-24 ]

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

Generated at Thu Feb 08 10:27:39 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.