Bug #110579 Right join query with BETWEEN wrong result

Submitted: 31 Mar 2023 15:10 Modified: 31 Mar 2023 16:49
Reporter: Pedro Ferreira Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S3 (Non-critical)
Version:8.0.32, 5.7.41 OS:Ubuntu (22.04)
Assigned to: CPU Architecture:x86 (x86_64)
Tags: between, RIGHT JOIN

[31 Mar 2023 15:10] Pedro Ferreira
Description:
Run these statements:

CREATE TABLE t85 (c0 INT,c4 TEXT);
INSERT INTO t85 VALUES (69,'5'),(-22,'3'),(-24,'8'),(73,'a');
CREATE TABLE t100 (c0 INT);

Then these queries:

SELECT 1 FROM t100 RIGHT JOIN t85 USING (c0);
SELECT 1 FROM t100 RIGHT JOIN t85 USING (c0) WHERE t85.c4 NOT BETWEEN -50 AND field(t85.c0, t100.c0);
SELECT 1 FROM t100 RIGHT JOIN t85 USING (c0) WHERE NOT (t85.c4 NOT BETWEEN -50 AND field(t85.c0, t100.c0));
SELECT 1 FROM t100 RIGHT JOIN t85 USING (c0) WHERE (t85.c4 NOT BETWEEN -50 AND field(t85.c0, t100.c0)) IS NULL;

The cardinality of the 3 bottom queries must match the upper one (true, false, and NULL). The top SELECT query returns 4 lines, the true query 3, and the others none. By looking more carefully, the query:

SELECT 1 FROM t100 RIGHT JOIN t85 USING (c0) WHERE NOT (t85.c4 NOT BETWEEN -50 AND field(t85.c0, t100.c0));

has a wrong result because the tuple (73,'a') should match in this case: the NOT cancel each other, field(t85.c0, t100.c0) evaluates to 0 and 'a' BETWEEN -50 AND 0 evaluates to 1.

The compilation parameters are the same as issue 108148:

-DWITH_DEBUG=1 -DWITH_ASAN=ON -DWITH_UBSAN=ON and boost library version 1.77

How to repeat:
Run the queries above.
[31 Mar 2023 16:49] MySQL Verification Team
Hello Pedro Ferreira,

Thank you for the report and feedback.

regards,
Umesh

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.