[MDEV-32343] Pushdown from HAVING into WHERE does not remove conditions from HAVING Created: 2023-10-03  Updated: 2023-10-06  Resolved: 2023-10-04

Status: Closed
Project: MariaDB Server
Component/s: Optimizer
Affects Version/s: 10.4, 10.5, 10.6
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Oleg Smirnov Assignee: Unassigned
Resolution: Not a Bug Votes: 0
Labels: None

Issue Links:
Relates

 Description   

This test case is taken from having_cond_pushdown.test from the main suite.

CREATE TABLE t1(a INT, b INT, c INT);
CREATE TABLE t2(x INT, y INT);
 
INSERT INTO t1 VALUES (1,14,3), (2,13,2), (1,22,1), (3,13,4), (3,14,2);
INSERT INTO t2 VALUES (2,13),(5,22),(3,14),(1,22);
 
EXPLAIN FORMAT=JSON SELECT t1.a,MAX(t1.b),MIN(t1.c)
FROM t1
GROUP BY t1.a
HAVING ((t1.a>2) AND (MAX(t1.b)>13)) OR ((t1.a<3) AND (MIN(t1.c)>1));

In the output we can see

"attached_condition": "t1.a > 2 or t1.a < 3"

which means those conjuncts have been pushed to the WHERE part, but at the same time

"having_condition": "t1.a > 2 and max(t1.b) > 13 or t1.a < 3 and min(t1.c) > 1"

which means they haven't been removed from the HAVING part.



 Comments   
Comment by Oleg Smirnov [ 2023-10-04 ]

There is a misunderstanding of the pushdown logic. Actually OR conditions must not be removed from HAVING despite being pushed to WHERE.

Generated at Thu Feb 08 10:30:37 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.