MDEV-38752: Wrong result upon GROUP BY on a table with indexed virtual column after INSERT IGNORE#4759
MDEV-38752: Wrong result upon GROUP BY on a table with indexed virtual column after INSERT IGNORE#4759kjarir wants to merge 1 commit intoMariaDB:12.3from
Conversation
aa9523d to
1002ee1
Compare
gkodinov
left a comment
There was a problem hiding this comment.
Thank you for your contribution! This is a preliminary review.
Please rebase to 12.3: this is a bug fix and it needs to cover all affected versions
| CREATE TABLE t1 (a INT PRIMARY KEY, va TINYINT AS (a), KEY(va)); | ||
| INSERT IGNORE INTO t1 (a) VALUES (100),(150),(200); | ||
| --echo # Should return 3 rows (fix: substitution disallowed) | ||
| SELECT a, va, COUNT(*) FROM t1 GROUP BY a; |
There was a problem hiding this comment.
Please increase verbosity so that the note about vcol impossible substitution is actually printed. Or do an EXPLAIN: it should do it too.
| SELECT a, va, COUNT(*) FROM t2 GROUP BY a; | ||
| DROP TABLE t2; | ||
|
|
||
| --echo # Case 3: Unsafe narrowing for VARCHAR |
There was a problem hiding this comment.
Add a test for different decimals as well please.
| --echo # 'apple' and 'apricot' both truncate to 'apple' in va | ||
| --echo # Should return 3 rows | ||
| SELECT a, va, COUNT(*) FROM t3 GROUP BY a; | ||
| DROP TABLE t3; |
There was a problem hiding this comment.
we customarily end tests with a print like that:
--echo End of ... tests.
There was a problem hiding this comment.
Please also make sure all of the related failing tests are re-recorded.
05fd327 to
b33ef30
Compare
|
|
21e3d7f to
7bf01fe
Compare
…l column after INSERT IGNORE
7bf01fe to
17e3155
Compare
Description
This PR fixes MDEV-38752, a regression introduced in commit
8cdee25952763a0401e4c2a4d61e92c13499bdc6.The issue was caused by the optimizer incorrectly substituting expressions in
GROUP BYorORDER BYwith indexed virtual columns that had "narrower" data types (e.g., substituting anINTexpression with aTINYINTvirtual column). After anINSERT IGNORE, data truncation in the virtual column caused distinct values from the original expression to merge into a single group in the query result.Changes
max_lengthand decimals are sufficient to cover the expression's range without truncation.Testing