Bug #121032 `REGEXP` backslash character-class in a WHERE over a UNION ALL derived table drops all matching rows

Submitted: 30 Jul 0:14 Modified: 31 Jul 10:39
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.10, 9.7.1, 26.7 OS:Ubuntu
Assigned to: CPU Architecture:ARM

[30 Jul 0:14] Junwen An
Description:
Under `NO_BACKSLASH_ESCAPES`, a `REGEXP` predicate whose pattern uses a backslash character-class escape (`\w \d \s \W \S \D`) returns wrong (missing) row when the filtered relation is a `UNION ALL` derived table (or a view built on one). 

The same predicate over the base table, or over a plain (non-`UNION`) derived table, matches correctly.

How to repeat:
## Environment

- **Version:** `VERSION()` = `26.7.0-debug` (MySQL `main`, commit `@06a5c1c9`, assertions on)
- **`sql_mode`:** must include `NO_BACKSLASH_ESCAPES` (see note below)
- **`character_set_connection`:** `utf8mb4`
- **`collation_connection`:** `utf8mb4_0900_bin`

Minimal repro

```sql
SET SESSION sql_mode = 'NO_BACKSLASH_ESCAPES';

CREATE TABLE t (name VARCHAR(255));
INSERT INTO t VALUES ('a');

-- Expected 1 row, actual 1 row (correct):
SELECT name FROM t WHERE name REGEXP '\w';

-- Expected 1 row, actual 0 rows (WRONG):
SELECT name FROM (SELECT * FROM t UNION ALL SELECT * FROM t WHERE 0) x WHERE name REGEXP '\w';
```
[31 Jul 10:39] 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.054 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.