Bug #120992 Inconsistent comparison behavior between CHARSET() string expression vs CTAS materialized column against hex literal (0x

Submitted: 23 Jul 13:06 Modified: 3 Aug 6:53
Reporter: Xiaoyuan Xie Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S2 (Serious)
Version:8.0.46, 8.4.10, 9.7.1 OS:Ubuntu
Assigned to: CPU Architecture:Any

[23 Jul 13:06] Xiaoyuan Xie
Description:
A query result divergence occurs when comparing a dynamic CHARSET() expression with a hex literal (0x51), compared to evaluating the same hex literal comparison against a materialized VARCHAR column derived via CREATE TABLE ... AS SELECT (CTAS).

Specifically:

Dynamic expression evaluation: SELECT 1 WHERE CHARSET(0) > 0x51 evaluates 'binary' vs 0x51 as TRUE and returns 1 row.

Materialized table evaluation: CREATE TABLE t1 AS SELECT CHARSET(0) AS c; materializes column c with value 'binary'. Executing SELECT 1 FROM t1 WHERE c > 0x51 evaluates to FALSE and returns Empty set.

How to repeat:
DROP DATABASE IF EXISTS test;
CREATE DATABASE test;
USE test;

-- Step 1: Create materialized table t1 via CTAS storing CHARSET(0)
CREATE TABLE t1 AS SELECT CHARSET(0) AS c;

-- Query 1: Dynamic function comparison against hex literal (without FROM table)
SELECT 1 WHERE CHARSET(0) > 0x51;
-- Returns: 1 row

-- Query 2: Materialized column comparison against hex literal
SELECT 1 FROM t1 WHERE c > 0x51;
-- Returns: Empty set
[3 Aug 6:53] Chaithra Marsur Gopala Reddy
Hi Xiaoyuan Xie,

Thank you for the test case. Verified as described.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.049 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.