[MCOL-4786] Query with IN and BETWEEN with overlapping literal ranges prefers IN ranges if IN goes last in the query Created: 2021-06-30  Updated: 2021-07-12  Resolved: 2021-07-12

Status: Closed
Project: MariaDB ColumnStore
Component/s: ExeMgr, MDB Plugin, PrimProc
Affects Version/s: 5.6.1
Fix Version/s: 6.1.1

Type: Bug Priority: Major
Reporter: Roman Assignee: Daniel Lee (Inactive)
Resolution: Fixed Votes: 0
Labels: None

Sprint: 2021-9

 Description   

Consider the example:

CREATE TABLE `bd_dwhs_private_ex_pub_services_ins` (
  `age` int(11) DEFAULT NULL,
) ENGINE=Columnstore DEFAULT CHARSET=latin1;
 
insert into bd_dwhs_private_ex_pub_services_ins select * from seq_1_to_120;
 
CREATE OR REPLACE VIEW `dwhs_ins_call_detail_vw` AS select age, case when `bd_dwhs_private_ex_pub_services_ins`.`age` between 16 and 24 then '16-24' when `bd_dwhs_private_ex_pub_services_ins`.`age` between 25 and 34 then '25-34' when `bd_dwhs_private_ex_pub_services_ins`.`age` between 35 and 44 then '35-44' when `bd_dwhs_private_ex_pub_services_ins`.`age` between 45 and 54 then '45-54' when `bd_dwhs_private_ex_pub_services_ins`.`age` between 55 and 64 then '55-64' when `bd_dwhs_private_ex_pub_services_ins`.`age` between 65 and 74 then '65-74' when `bd_dwhs_private_ex_pub_services_ins`.`age` >= 75 then '75+' end AS `age_group` from `bd_dwhs_private_ex_pub_services_ins`;
 
select age_group,age,count(*) from dwhs_ins_call_detail_vw where age between 16 and 34 and age_group IN ('35-44') group by age_group,age order by age_group,age;

The query returns records with age > 34 but it mustn't.
CSEP analyze has no filter for BETWEEN predicate if BETWEEN goes in front of IN.



 Comments   
Comment by Daniel Lee (Inactive) [ 2021-07-09 ]

Build verified: 6.1.1 (#2754)

Reproduced the issue in 5.6.1-1 and verified the fix in 6.1.1

Comment by Gagan Goel (Inactive) [ 2021-07-12 ]

The patch broke test001 test: working_tpch1/misc/MCOL-1234.sql. I am re-opening the issue.

Comment by Denis Khalikov [ 2021-07-12 ]

last patch is not fixed it.

Comment by Denis Khalikov [ 2021-07-12 ]

Ok, the previous fix fixes situation almost in all cases and also case added to description, but when we have "between filter" equal to one of the filter inside the "case control flow" CS merges it, lucky I added a test cases exactly like this.

For example.
This query works:

select age_group,age,count(*) from dwhs_ins_call_detail_vw where age between 16 and 34 and age_group IN ('35-44') group by age_group,age order by age_group,age;

This query does not:

select age_group,age,count(*) from dwhs_ins_call_detail_vw where age between 16 and 24 and age_group IN ('35-44') group by age_group,age order by age_group,age;

Comment by Daniel Lee (Inactive) [ 2021-07-12 ]

Build verified: 6.1.1 (#2787)

Generated at Thu Feb 08 02:52:59 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.