Slackbot
10/17/2023, 1:12 PMJohn Kowtko
10/17/2023, 5:04 PMcast(((sum("Calc_Net_Amt(sales_master)")/(select sum(a) from (
select sum("Calc_Net_Amt(sales_master)") as a, 'dummy' as b
from sales_master_COM101
group by 2
))))*100.0 as DECIMAL ),
I don't think you need to add the cartesian product to do the grouping ... in SQL you can do aggregates without a group by, and you don't need the secondary grouping and aggregate, so just:
cast( sum("Calc_Net_Amt(sales_master)" /
(select sum("Calc_Net_Amt(sales_master)") from sales_master_COM101)
)*100.0 as DECIMAL ),
I also don't know if Druid will try to execute that subquery for each select list item, so for safety (and maybe easier reading) I suggest turning that into a CTE at the beginning of the query, e.g.:
with tmp_total as (
select sum("Calc_Net_Amt(sales_master)") as TotalAmt from sales_master_COM10
)
select ...
from sales_master_COM101 cross join tmp_total
where ...
===
On the cluster config side, I would think to increase processing threads to something higher ... the segment scans are spread across the number of processing threads ... currently each thread has to process 49/3 = 17 segments ...