Bug #99634 | partition pruning not working with sub query | ||
---|---|---|---|
Submitted: | 19 May 2020 19:24 | Modified: | 21 May 2020 18:50 |
Reporter: | Sivanarayana Chekuri | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server | Severity: | S2 (Serious) |
Version: | 8.0.19 | OS: | Any |
Assigned to: | CPU Architecture: | Any | |
Tags: | partitioning, SUB QUERY |
[19 May 2020 19:24]
Sivanarayana Chekuri
[19 May 2020 20:13]
MySQL Verification Team
Please provide the complete test case not just the description, the SQL script to create table, insert data, query, real result and expected result. Thanks in advance.
[21 May 2020 6:57]
Sivanarayana Chekuri
Thanks Miguel Solorzano for the response Following are the steps to reproduce this issue.... -- create party_id and wfid mapping table CREATE TABLE s3apiappl.partition_mapping_table ( PARTY_ID VARCHAR(32), wfid VARCHAR(64) ); -- sample data for party_id and wfid table. insert into s3apiappl.partition_mapping_table values ('100','wfid1'); insert into s3apiappl.partition_mapping_table values ('100','wfid2'); insert into s3apiappl.partition_mapping_table values ('100','wfid3'); insert into s3apiappl.partition_mapping_table values ('200','wfid4'); insert into s3apiappl.partition_mapping_table values ('200','wfid5'); insert into s3apiappl.partition_mapping_table values ('200','wfid6'); insert into s3apiappl.partition_mapping_table values ('300','wfid7'); insert into s3apiappl.partition_mapping_table values ('300','wfid8'); commit; -- create transaction table which will have diff inventory's for each wfid. CREATE TABLE s3apiappl.list_partition_test ( PARTY_ID VARCHAR(32), wfid VARCHAR(64), inv VARCHAR(8) ) PARTITION BY LIST COLUMNS( wfid) ( PARTITION pWfid_1 VALUES IN( 'wfid1'), PARTITION pWfid_2 VALUES IN( 'wfid2'), PARTITION pWfid_3 VALUES IN( 'wfid3'), PARTITION pWfid_4 VALUES IN( 'wfid4'), PARTITION pWfid_5 VALUES IN( 'wfid5'), PARTITION pWfid_6 VALUES IN( 'wfid6'), PARTITION pWfid_7 VALUES IN( 'wfid7'), PARTITION pWfid_8 VALUES IN( 'wfid8') ); -- create sample data set insert into s3apiappl.list_partition_test values ('100','wfid1','inv1'); insert into s3apiappl.list_partition_test values ('100','wfid1','inv2'); insert into s3apiappl.list_partition_test values ('100','wfid1','inv3'); insert into s3apiappl.list_partition_test values ('100','wfid1','inv4'); insert into s3apiappl.list_partition_test values ('100','wfid2','inv1'); insert into s3apiappl.list_partition_test values ('100','wfid3','inv1'); insert into s3apiappl.list_partition_test values ('200','wfid4','inv1'); insert into s3apiappl.list_partition_test values ('200','wfid5','inv1'); insert into s3apiappl.list_partition_test values ('200','wfid6','inv1'); insert into s3apiappl.list_partition_test values ('300','wfid7','inv1'); insert into s3apiappl.list_partition_test values ('300','wfid8','inv1'); commit; -- Sub query, which is not working partition pruning., doing ALL Partition scan. select * from s3apiappl.list_partition_test where wfid in (select wfid from s3apiappl.partition_mapping_table where party_id = 100); -- showing All partition scan. It should limit to only 3 partitions(pWfid_1,pWfid_2,pWfid_3) scan. explain select * from s3apiappl.list_partition_test where wfid in (select wfid from s3apiappl.partition_mapping_table where party_id = 100); -- Tried with joing two tables, instead sub query. Joing also showing all partition scan. explain select * from s3apiappl.list_partition_test a, s3apiappl.partition_mapping_table b where a.party_id = b.party_id and a.wfid = b.wfid and b.party_id = 100;
[21 May 2020 12:45]
MySQL Verification Team
Hi Mr. Chekuri, Thank you for your bug report. However, I do not think that this is a bug. There are several reasons of why pruning would not work, of which I will mention only a couple of those. Since you do not have any suitable index, how can pruning function ??? Next, if even you have all suitable indices, pruning would not function, because for the number of rows smaller than one or two hundreds, it is MUCH faster to scan them all, instead of doing index search or pruning. This is all explained in our Reference Manual, chapter on Optimisation. Not a bug.
[21 May 2020 18:50]
Sivanarayana Chekuri
Actual table will have more than One billion records. Since i can't add all the data here, i given sample data. I tried with adding index on both the tables and Analyze the table, still it's not showing partition pruning. This problem i can see with only sub query's and joining with other tables. If i use partition key in where clause and passing exact values as comma separated, it's working fine. ex.. select * from s3apiappl.list_partition_test where wfid in ('wfid1','wfid2','wfid3','wfid4') and party_id = 100; -- working fine. issue with only getting wfid in subquery or joining with other table. ex... select * from s3apiappl.list_partition_test where wfid in (select wfid from s3apiappl.partition_mapping_table where party_id = 100); or select * from s3apiappl.list_partition_test a, s3apiappl.partition_mapping_table b where a.party_id = b.party_id and a.wfid = b.wfid and b.party_id = 100;
[22 May 2020 12:05]
MySQL Verification Team
Our analysis still stands, regarding index. Also, there are queries that can't use indices, like for some tables in outer joins, semi joins or in dependent nested queries. This is all described in our Reference Manual.