Bug #121068 NO_BACKSLASH_ESCAPES + UNION + escaped apostrophe raises error

Submitted: 7 Aug 22:26 Modified: 10 Aug 5:21
Reporter: Junwen An Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S3 (Non-critical)
Version:8.0.46, 8.4.11, 9.7.2 OS:Ubuntu
Assigned to: CPU Architecture:ARM

[7 Aug 22:26] Junwen An
Description:
Please see the repro below. It seems this query pattern causes inconsistent behavior with strings like o'brien.

How to repeat:
-- ========== FAIL ==========
SET sql_mode = 'NO_BACKSLASH_ESCAPES';
SELECT * FROM (SELECT 'x' AS c UNION ALL SELECT 'y') AS t
WHERE c = 'o''brien';
-- ERROR 1064 near 'brien')'

-- ========== OK: drop NO_BACKSLASH_ESCAPES ==========
SET sql_mode = '';
SELECT * FROM (SELECT 'x' AS c UNION ALL SELECT 'y') AS t
WHERE c = 'o''brien';
-- empty result (correct)

-- ========== OK: drop UNION ==========
SET sql_mode = 'NO_BACKSLASH_ESCAPES';
SELECT * FROM (SELECT 'x' AS c) AS t
WHERE c = 'o''brien';
-- empty result (correct)

-- ========== OK: literal alone under the same mode ==========
SET sql_mode = 'NO_BACKSLASH_ESCAPES';
SELECT 'o''brien' AS v, LENGTH('o''brien') AS n;
-- v = o'brien, n = 7

Suggested fix:
The UNION rewrite under NO_BACKSLASH_ESCAPES corrupts 'o''brien' into something like 'o'brien' (string ends early)?
[10 Aug 5:20] Chaithra Marsur Gopala Reddy
Hi Junwen An,

Thank you for the test case. Verified as described.

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

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