Bug #120994 Inconsistent JOIN result when comparing TEXT and DECIMAL columns with and without UNIQUE index
| Submitted: | 23 Jul 14:09 | Modified: | 1 Dec 17:21 |
|---|---|---|---|
| Reporter: | Xiaoyuan Xie | Email Updates: | |
| Status: | Closed | Impact on me: | |
| Category: | MySQL Server: Optimizer | Severity: | S2 (Serious) |
| Version: | 8.0.46, 8.4.10, 9.7.1 | OS: | Ubuntu |
| Assigned to: | CPU Architecture: | Any |
[3 Aug 8:57]
Chaithra Marsur Gopala Reddy
Hi Xiaoyuan Xie, Thank you for test case. Verified as described.
[19 Oct 14:08]
OCA Admin
Contribution submitted via Github - Bug#120994: Store parsed DECIMAL values for ignored truncation (*) Contribution by PR specific confirm no longer needed
Contribution: git_patch_4660271606.txt (text/plain), 10.75 KiB.
[22 Oct 14:48]
MySQL Admin
Posted by developer: Bug status updated to 'Patch pending'
[22 Oct 20:48]
MySQL Admin
Posted by developer: Bug status updated to 'Documenting'
[1 Dec 17:21]
Edward Gilmore
Posted by developer: Added the following note to the MySQL Server 9.7.5 and 27.1.0 release notes: Indexed DECIMAL comparisons and joins could omit matching rows when strings containing trailing text were accepted with a truncation warning. For example, joining the TEXT value '0a' to DECIMAL value 0 could return a row without an index but no rows with a unique index. Our thanks to Chi Zhang for the contribution.
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.041 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.
Description: A query result divergence occurs when performing an inner join on a TEXT column and a DECIMAL column with implicit type truncation (e.g. '0a' compared with 0), depending on whether a UNIQUE index exists on the DECIMAL column. Specifically: String '0a' implicitly converts to numeric 0 during TEXT to DECIMAL comparison in MySQL. On a table without a UNIQUE index (d_raw), performing JOIN ON d_raw.t1.c = d_raw.t0.c uses full scan/hash join, correctly truncates '0a' to 0, and returns 1 row. On a table with a UNIQUE index (d), performing JOIN ON d.t1.c = d.t0.c uses index lookup on d.t0, fails to match '0a' with 0, and incorrectly returns Empty set, 1 warning. How to repeat: DROP DATABASE IF EXISTS test_idx; DROP DATABASE IF EXISTS test_raw; -- Case 1: Table with UNIQUE index CREATE DATABASE test_idx; USE test_idx; CREATE TABLE t0 (c DECIMAL UNIQUE); CREATE TABLE t1 (c TEXT); INSERT INTO t0 VALUES (0); INSERT INTO t1 VALUES ('0a'); -- Query on table with UNIQUE index SELECT 1 FROM t1 JOIN t0 ON t1.c = t0.c; -- Returns: Empty set (Incorrect index lookup behavior) -- Case 2: Table without UNIQUE index CREATE DATABASE test_raw; USE test_raw; CREATE TABLE t0 (c DECIMAL); CREATE TABLE t1 (c TEXT); INSERT INTO t0 VALUES (0); INSERT INTO t1 VALUES ('0a'); -- Query on table without index SELECT 1 FROM t1 JOIN t0 ON t1.c = t0.c; -- Returns: 1 row (Correct implicit conversion behavior)