Hi team,
I am encountering an issue with query pushdown when using dynamic date conditions. My use case involves executing queries on a dynamic date condition, and I’ve observed that the query pushdown is not happening as expected. This is leading to performance issues when working with big data sets.
When I use a hardcoded date condition, the date filter is applied within the JDBC step, resulting in efficient query execution. However, when I use a dynamic date condition, a separate filter step is executed in Dremio, which affects performance. The query plan shows that the initial query is executed without any date filter, and the filter step is applied afterward within Dremio.
Below are the queries I am working with:
Query with hardcoded date condition:
select Cust_Sub_Id AS cust_sub_id,Msisdn as msisdn,Line_Type as line_type,OG_Bundle_Call_Revenue from “EDA Customer 360”.EDA.“Voice_Seg_Fct” where Event_Date between TO_DATE(‘2024-05-01’) and TO_DATE(‘2024-05-31’)
Query with dynamic date condition:
select Cust_Sub_Id AS cust_sub_id,Msisdn as msisdn,Line_Type as line_type,OG_Bundle_Call_Revenue from “EDA Customer 360”.EDA.“Voice_Seg_Fct” where Event_Date >= TO_DATE(DATE_ADD(DATE_SUB(LAST_DAY(now()), CAST(2 AS INTERVAL MONTH)),1) ,‘YYYY-MM-DD’,0) and Event_Date <= LAST_DAY(DATE_SUB(now(), CAST(1 AS INTERVAL MONTH)))
In the query plan for the dynamic date condition, the filter step is executed separately within Dremio, resulting in reduced performance.
Query Plan with hardcoded date condition:
Jdbc(sql=[SELECT
Cust_Sub_Id
AScust_sub_id
,Msisdn
ASmsisdn
,Line_Type
ASline_type
,OG_Bundle_Call_Revenue
FROM (SELECTVoice_Seg_Fct
.Msisdn
,Voice_Seg_Fct
.Cust_Sub_Id
,Voice_Seg_Fct
.Event_Date
,Voice_Seg_Fct
.OG_Bundle_Call_Revenue
,Voice_Seg_Fct
.Line_Type
FROMEDA
.Voice_Seg_Fct
) ASVoice_Seg_Fct
WHEREEvent_Date
>= CAST(‘2024-05-01’ AS DATE) ANDEvent_Date
<= CAST(‘2024-05-31’ AS DATE)]) : rowType = RecordType(BIGINT cust_sub_id, VARCHAR(65536) msisdn, VARCHAR(65536) line_type, DECIMAL(16, 4) OG_Bundle_Call_Revenue): rowcount = 1.0, cumulative cost = {3.0 rows, 52.0 cpu, 50.0 io, 50.0 network, 0.0 memory}, id = 157631
Query Plan with dynamic date condition:
00-06 SelectionVectorRemover : rowType = RecordType(VARCHAR(65536) Msisdn, BIGINT Cust_Sub_Id, DATE Event_Date, DECIMAL(16, 4) OG_Bundle_Call_Revenue, VARCHAR(65536) Line_Type): rowcount = 1.0, cumulative cost = {4.0 rows, 63.00005 cpu, 50.0 io, 50.0 network, 0.0 memory}, id = 158099
00-07 Filter(condition=[AND(>=($2, TO_DATE(DATE_ADD(DATE_SUB(LAST_DAY(2024-06-07 06:49:15.001:TIMESTAMP(3)), 2:INTERVAL MONTH), 1), ‘YYYY-MM-DD’:VARCHAR(10), 0)), <=($2, 2024-05-31))]) : rowType = RecordType(VARCHAR(65536) Msisdn, BIGINT Cust_Sub_Id, DATE Event_Date, DECIMAL(16, 4) OG_Bundle_Call_Revenue, VARCHAR(65536) Line_Type): rowcount = 1.0, cumulative cost = {3.0 rows, 62.00005 cpu, 50.0 io, 50.0 network, 0.0 memory}, id = 158098
00-08 Project(Msisdn=[$0], Cust_Sub_Id=[$1], Event_Date=[$2], OG_Bundle_Call_Revenue=[$3], Line_Type=[$4]) : rowType = RecordType(VARCHAR(65536) Msisdn, BIGINT Cust_Sub_Id, DATE Event_Date, DECIMAL(16, 4) OG_Bundle_Call_Revenue, VARCHAR(65536) Line_Type): rowcount = 1.0, cumulative cost = {2.0 rows, 50.00005 cpu, 50.0 io, 50.0 network, 0.0 memory}, id = 158097
00-09 Jdbc(sql=[SELECTVoice_Seg_Fct
.Msisdn
,Voice_Seg_Fct
.Cust_Sub_Id
,Voice_Seg_Fct
.Event_Date
,Voice_Seg_Fct
.OG_Bundle_Call_Revenue
,Voice_Seg_Fct
.Line_Type
FROMEDA
.Voice_Seg_Fct
]) : rowType = RecordType(VARCHAR(65536) Msisdn, BIGINT Cust_Sub_Id, DATE Event_Date, DECIMAL(16, 4) OG_Bundle_Call_Revenue, VARCHAR(65536) Line_Type): rowcount = 1.0, cumulative cost = {1.0 rows, 50.0 cpu, 50.0 io, 50.0 network, 0.0 memory}, id = 157959
Dremio version : 24
Note : I am executing the above queries in SingleStore and have connected to SingleStore using the MySQL connector.
Is there a way to ensure that the date filter is applied within the JDBC step for dynamic date conditions, similar to the hardcoded date condition? Any insights or recommendations to improve the query pushdown for dynamic conditions would be greatly appreciated.
Please find the profile query for the above queries attached below.
Query with Harded Date.zip (19.3 KB)
Query with Dynamic Date.zip (20.5 KB)
Thank you!