[MDEV-26729] Optimizer does wrong cast from number to string Created: 2021-09-30  Updated: 2021-10-14  Resolved: 2021-10-14

Status: Closed
Project: MariaDB Server
Component/s: Optimizer
Affects Version/s: 10.4.13, 10.6.3
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Oli Sennhauser Assignee: Sergei Golubchik
Resolution: Duplicate Votes: 0
Labels: cast, int, optimizer, string
Environment:

Linux n.a.


Attachments: File sales_flat_order_dump.sql.gz    
Issue Links:
Duplicate
is duplicated by MDEV-18089 optimizer is wrong Closed

 Description   

Optimizer does a wrong cast from column string to number instead of constant number to string:

source sales_flat_order_dump.sql
analyze table sales_flat_order;
 
explain  
SELECT `main_table`.* FROM `sales_flat_order` AS `main_table` WHERE (`increment_id` >= 238900 AND `increment_id` <= 238907)
;
+------+-------------+------------+------+-----------------------------------+------+---------+------+--------+-------------+
| id   | select_type | table      | type | possible_keys                     | key  | key_len | ref  | rows   | Extra       |
+------+-------------+------------+------+-----------------------------------+------+---------+------+--------+-------------+
|    1 | SIMPLE      | main_table | ALL  | UNQ_SALES_FLAT_ORDER_INCREMENT_ID | NULL | NULL    | NULL | 260559 | Using where |
+------+-------------+------------+------+-----------------------------------+------+---------+------+--------+-------------+

Execution time:
3 rows in set (1.467 sec)

explain  
SELECT `main_table`.* FROM `sales_flat_order` AS `main_table` WHERE (`increment_id` >= '238900' AND `increment_id` <= '238907')
;
+------+-------------+------------+-------+-----------------------------------+-----------------------------------+---------+------+------+-----------------------+
| id   | select_type | table      | type  | possible_keys                     | key                               | key_len | ref  | rows | Extra                 |
+------+-------------+------------+-------+-----------------------------------+-----------------------------------+---------+------+------+-----------------------+
|    1 | SIMPLE      | main_table | range | UNQ_SALES_FLAT_ORDER_INCREMENT_ID | UNQ_SALES_FLAT_ORDER_INCREMENT_ID | 153     | NULL | 3    | Using index condition |
+------+-------------+------------+-------+-----------------------------------+-----------------------------------+---------+------+------+-----------------------+

Execution time:
3 rows in set (0.002 sec)

This is reproducible at will. See example attached.



 Comments   
Comment by Sergei Golubchik [ 2021-10-14 ]

see, for example, this comment

Generated at Thu Feb 08 09:47:30 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.