Details
-
Bug
-
Status: Confirmed (View Workflow)
-
Major
-
Resolution: Unresolved
-
11.8, 12.3, 13.1, 12.3.3
-
MariaDB 12.3.3-MariaDB-ubu2404 on Linux x86_64
Description
MariaDB 12.3.3 returns no row when it substitutes a VARCHAR expression with an indexed generated column that is shorter than the expression result. The same predicate returns row 1 when the index substitution is disabled.
Reproducer
Run the following SQL in one session:
CREATE DATABASE vcol_test; |
USE vcol_test; |
SET SESSION sql_mode=''; |
|
|
CREATE TABLE t1 ( |
id INT PRIMARY KEY, |
a VARCHAR(10) CHARACTER SET latin1 COLLATE latin1_bin, |
v VARCHAR(3) CHARACTER SET latin1 COLLATE latin1_bin |
AS (CONCAT(a,'')), |
KEY v_idx(v) |
) ENGINE=InnoDB;
|
|
|
INSERT INTO t1(id,a) VALUES (1,'abcd'),(2,'abc'),(3,'xyz'); |
SHOW WARNINGS;
|
SELECT id,a,v FROM t1 ORDER BY id; |
|
|
SELECT 'baseline' AS check_name, |
COALESCE(GROUP_CONCAT(id ORDER BY id),'EMPTY') AS ids |
FROM t1 IGNORE INDEX(v_idx) |
WHERE CONCAT(a,'')='abcd'; |
|
|
SELECT 'optimized' AS check_name, |
COALESCE(GROUP_CONCAT(id ORDER BY id),'EMPTY') AS ids |
FROM t1 |
WHERE CONCAT(a,'')='abcd'; |
|
|
EXPLAIN EXTENDED
|
SELECT id FROM t1 WHERE CONCAT(a,'')='abcd'; |
SHOW WARNINGS;
|
|
|
DROP DATABASE vcol_test; |
The empty SQL mode permits the generated value to be truncated and produces the expected warning. It does not alter the source value in a.
Recorded result
Level Code Message
|
Warning 1265 Data truncated for column 'v' at row 1
|
|
|
id a v
|
1 abcd abc
|
2 abc abc
|
3 xyz xyz
|
|
|
check_name ids
|
baseline 1
|
|
|
check_name ids
|
optimized EMPTY
|
EXPLAIN EXTENDED used v_idx, and SHOW WARNINGS showed that the predicate had been rewritten from CONCAT(a,'')='abcd' to v='abcd'.
Expected behavior
Both queries have the same predicate and should return row 1. The stored source value is still abcd, so using the narrower generated value abc for the comparison must not change the result set. Either the substitution should preserve the predicate's semantics or it should not be applied when the generated column is narrower.
This occurs when a WHERE expression is substituted with an indexed generated column whose VARCHAR length is narrower than the source expression.
Attachments
Issue Links
- is caused by
-
MDEV-35616 Add basic optimizer support for virtual columns
-
- Closed
-