postgres query performance [closed]
-
13-03-2021 - |
Frage
I can't find a good way to rewrite this query or improve the performance:
query:
update company_holding c
set issuer_stim_buy_quarter = sq.estim_quarter_buy
from (select h.company_id
,h.issuer_cusip
,var_quarter as quarter
,min(h.quarter) as estim_quarter_buy
from company_holding h
where h.quarter <= var_quarter
and h.issuer_tot_share > 0
group by h.company_id, quarter, h.issuer_cusip
) sq
where c.company_id = sq.company_id
and c.issuer_cusip = sq.issuer_cusip
and c.quarter = sq.quarter
company_holding
is a partitioned table.
This is the explain analyze: https://explain.depesz.com/s/5rjU
Lösung
Most of the time is spent aggregating and sorting the data.
I don't know how the tables are partitioned, but if the partitioning key is part of the join condition or the aggregate can be calculated partition by partition, you might benefit by setting enable_partitionwise_aggregate
and enable_partitionwise_join
to on
.
There is not much more I can say with that little information.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit dba.stackexchange