-
-
Notifications
You must be signed in to change notification settings - Fork 2k
MDEV-38752: Wrong result upon GROUP BY on a table with indexed virtual column after INSERT IGNORE #4759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 12.3
Are you sure you want to change the base?
MDEV-38752: Wrong result upon GROUP BY on a table with indexed virtual column after INSERT IGNORE #4759
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| # | ||
| # MDEV-38752: Wrong result upon GROUP BY on a table with indexed virtual column after INSERT IGNORE | ||
| # | ||
| # Case 1: Unsafe narrowing substitution (INT -> TINYINT) | ||
| CREATE TABLE t1 (a INT PRIMARY KEY, va TINYINT AS (a), KEY(va)); | ||
| INSERT IGNORE INTO t1 (a) VALUES (100),(150),(200); | ||
| Warnings: | ||
| Warning 1264 Out of range value for column 'va' at row 2 | ||
| Warning 1264 Out of range value for column 'va' at row 3 | ||
| # Should return 3 rows (fix: substitution disallowed) | ||
| # EXPLAIN should show that va index is NOT used | ||
| EXPLAIN SELECT a, va, COUNT(*) FROM t1 GROUP BY a; | ||
| id select_type table type possible_keys key key_len ref rows Extra | ||
| 1 SIMPLE t1 index NULL PRIMARY 4 NULL # Using index | ||
| Warnings: | ||
| Note 1105 Cannot substitute virtual column expression `t1`.`a` -> va due to type mismatch | ||
| SHOW WARNINGS; | ||
| Level Code Message | ||
| Note 1105 Cannot substitute virtual column expression `t1`.`a` -> va due to type mismatch | ||
| SELECT a, va, COUNT(*) FROM t1 GROUP BY a; | ||
| a va COUNT(*) | ||
| 100 100 1 | ||
| 150 127 1 | ||
| 200 127 1 | ||
| DROP TABLE t1; | ||
| # Case 2: Safe substitution (INT -> INT) | ||
| CREATE TABLE t2 (a INT PRIMARY KEY, va INT AS (a), KEY(va)); | ||
| INSERT INTO t2 (a) VALUES (100),(150),(200); | ||
| # Should return 3 rows (substitution allowed, uses va index) | ||
| # EXPLAIN should show that va index is used | ||
| EXPLAIN SELECT va, COUNT(*) FROM t2 GROUP BY a; | ||
| id select_type table type possible_keys key key_len ref rows Extra | ||
| 1 SIMPLE t2 index NULL va 5 NULL # Using index | ||
| SHOW WARNINGS; | ||
| Level Code Message | ||
| SELECT va, COUNT(*) FROM t2 GROUP BY a; | ||
| va COUNT(*) | ||
| 100 1 | ||
| 150 1 | ||
| 200 1 | ||
| DROP TABLE t2; | ||
| # Case 3: Unsafe narrowing for VARCHAR | ||
| CREATE TABLE t3 (a VARCHAR(20) PRIMARY KEY, va VARCHAR(5) AS (a), KEY(va)); | ||
| INSERT IGNORE INTO t3 (a) VALUES ('apple'),('banana'),('apricot'); | ||
| Warnings: | ||
| Warning 1265 Data truncated for column 'va' at row 2 | ||
| Warning 1265 Data truncated for column 'va' at row 3 | ||
| # 'apple' and 'apricot' both truncate to 'apple' in va | ||
| # Should return 3 rows | ||
| # EXPLAIN should show that va index is NOT used | ||
| EXPLAIN SELECT a, va, COUNT(*) FROM t3 GROUP BY a; | ||
| id select_type table type possible_keys key key_len ref rows Extra | ||
| 1 SIMPLE t3 index NULL PRIMARY 82 NULL # Using index | ||
| Warnings: | ||
| Note 1105 Cannot substitute virtual column expression `t3`.`a` -> va due to type mismatch | ||
| SHOW WARNINGS; | ||
| Level Code Message | ||
| Note 1105 Cannot substitute virtual column expression `t3`.`a` -> va due to type mismatch | ||
| SELECT a, va, COUNT(*) FROM t3 GROUP BY a; | ||
| a va COUNT(*) | ||
| apple apple 1 | ||
| apricot apric 1 | ||
| banana banan 1 | ||
| DROP TABLE t3; | ||
| # Case 4: Unsafe narrowing for DECIMAL | ||
| CREATE TABLE t4 (a DECIMAL(10,5) PRIMARY KEY, va DECIMAL(10,2) AS (a), KEY(va)); | ||
| INSERT IGNORE INTO t4 (a) VALUES (1.12345), (1.12346), (1.12999); | ||
| Warnings: | ||
| Note 1265 Data truncated for column 'va' at row 1 | ||
| Note 1265 Data truncated for column 'va' at row 2 | ||
| Note 1265 Data truncated for column 'va' at row 3 | ||
| # All three values truncate to 1.12 in va | ||
| # Should return 3 rows | ||
| # EXPLAIN should show that va index is NOT used | ||
| EXPLAIN SELECT a, va, COUNT(*) FROM t4 GROUP BY a; | ||
| id select_type table type possible_keys key key_len ref rows Extra | ||
| 1 SIMPLE t4 index NULL PRIMARY 6 NULL # Using index | ||
| Warnings: | ||
| Note 1105 Cannot substitute virtual column expression `t4`.`a` -> va due to type mismatch | ||
| SHOW WARNINGS; | ||
| Level Code Message | ||
| Note 1105 Cannot substitute virtual column expression `t4`.`a` -> va due to type mismatch | ||
| SELECT a, va, COUNT(*) FROM t4 GROUP BY a; | ||
| a va COUNT(*) | ||
| 1.12345 1.12 1 | ||
| 1.12346 1.12 1 | ||
| 1.12999 1.13 1 | ||
| DROP TABLE t4; | ||
| # End of mdev_38752 tests |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| --source include/have_innodb.inc | ||
|
|
||
| --echo # | ||
| --echo # MDEV-38752: Wrong result upon GROUP BY on a table with indexed virtual column after INSERT IGNORE | ||
| --echo # | ||
|
|
||
| --echo # Case 1: Unsafe narrowing substitution (INT -> TINYINT) | ||
| 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) | ||
| --echo # EXPLAIN should show that va index is NOT used | ||
| --replace_column 9 # | ||
| EXPLAIN SELECT a, va, COUNT(*) FROM t1 GROUP BY a; | ||
| SHOW WARNINGS; | ||
| SELECT a, va, COUNT(*) FROM t1 GROUP BY a; | ||
| DROP TABLE t1; | ||
|
|
||
| --echo # Case 2: Safe substitution (INT -> INT) | ||
| CREATE TABLE t2 (a INT PRIMARY KEY, va INT AS (a), KEY(va)); | ||
| INSERT INTO t2 (a) VALUES (100),(150),(200); | ||
| --echo # Should return 3 rows (substitution allowed, uses va index) | ||
| --echo # EXPLAIN should show that va index is used | ||
| --replace_column 9 # | ||
| EXPLAIN SELECT va, COUNT(*) FROM t2 GROUP BY a; | ||
| SHOW WARNINGS; | ||
| SELECT va, COUNT(*) FROM t2 GROUP BY a; | ||
| DROP TABLE t2; | ||
|
|
||
| --echo # Case 3: Unsafe narrowing for VARCHAR | ||
grooverdan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| CREATE TABLE t3 (a VARCHAR(20) PRIMARY KEY, va VARCHAR(5) AS (a), KEY(va)); | ||
| INSERT IGNORE INTO t3 (a) VALUES ('apple'),('banana'),('apricot'); | ||
| --echo # 'apple' and 'apricot' both truncate to 'apple' in va | ||
| --echo # Should return 3 rows | ||
| --echo # EXPLAIN should show that va index is NOT used | ||
| --replace_column 9 # | ||
| EXPLAIN SELECT a, va, COUNT(*) FROM t3 GROUP BY a; | ||
| SHOW WARNINGS; | ||
| SELECT a, va, COUNT(*) FROM t3 GROUP BY a; | ||
| DROP TABLE t3; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we customarily end tests with a print like that:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please also make sure all of the related failing tests are re-recorded.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kjarir note this is |
||
|
|
||
| --echo # Case 4: Unsafe narrowing for DECIMAL | ||
| CREATE TABLE t4 (a DECIMAL(10,5) PRIMARY KEY, va DECIMAL(10,2) AS (a), KEY(va)); | ||
| INSERT IGNORE INTO t4 (a) VALUES (1.12345), (1.12346), (1.12999); | ||
| --echo # All three values truncate to 1.12 in va | ||
| --echo # Should return 3 rows | ||
| --echo # EXPLAIN should show that va index is NOT used | ||
| --replace_column 9 # | ||
| EXPLAIN SELECT a, va, COUNT(*) FROM t4 GROUP BY a; | ||
| SHOW WARNINGS; | ||
| SELECT a, va, COUNT(*) FROM t4 GROUP BY a; | ||
| DROP TABLE t4; | ||
|
|
||
| --echo # End of mdev_38752 tests | ||
Uh oh!
There was an error while loading. Please reload this page.