trino
trino copied to clipboard
Use only the biggest cardinality symbol for forced exchange
Description
The exchange below group-id is not beneficial if it doesn't help partial aggregation to be more efficient. This can happen if partitions by columns that would otherwise be aggregated. To limit the impact of this, we now can only partition by single column with the highest cardinality.
----
trino:tpcds_sf1000_orc> explain analyze verbose select count(*) from store_sales group by rollup (ss_ticket_number, ss_quantity, ss_store_sk);
-- before
CPU Time: 11463.6s total, 251K rows/s, 349KB/s, 65% active
1:59 [2.88B rows, 3.82GB] [24.2M rows/s, 32.8MB/s]
-- after
CPU Time: 8521.3s total, 338K rows/s, 470KB/s, 67% active
1:43 [2.88B rows, 3.82GB] [28M rows/s, 38MB/s]
-- rule disabled
CPU Time: 7746.6s total, 372K rows/s, 517KB/s, 69% active
1:33 [2.88B rows, 3.82GB] [30.8M rows/s, 41.9MB/s]
----
explain analyze verbose
select count(ss_item_sk) FILTER (WHERE grouping_id=2) as c0,
count(ss_store_sk) FILTER (WHERE grouping_id=4) as c1
from (select grouping(ss_item_sk,ss_store_sk, ss_ticket_number) AS grouping_id, ss_item_sk, ss_store_sk, ss_ticket_number
from store_sales group by grouping sets ((ss_ticket_number, ss_item_sk), (ss_ticket_number, ss_store_sk)));
-- before
CPU Time: 6058.2s total, 475K rows/s, 1.76MB/s, 51% active
53.47 [2.88B rows, 10.4GB] [53.9M rows/s, 199MB/s]
-- after
CPU Time: 5318.7s total, 541K rows/s, 2MB/s, 65% active
43.22 [2.88B rows, 10.4GB] [66.6M rows/s, 247MB/s]
-- rule disabled
CPU Time: 4683.0s total, 615K rows/s, 2.28MB/s, 63% active
33.62 [2.88B rows, 10.4GB] [85.7M rows/s, 317MB/s]
--- tpcds q18
-- before
CPU Time: 413.5s total, 1.1M rows/s, 44.7MB/s, 25% active
6.42 [454M rows, 18.1GB] [70.8M rows/s, 2.81GB/s]
-- after
CPU Time: 400.0s total, 1.13M rows/s, 46.2MB/s, 24% active
6.46 [450M rows, 18.1GB] [69.7M rows/s, 2.8GB/s]
-- rule disabled
CPU Time: 413.3s total, 1.1M rows/s, 44.7MB/s, 29% active
5.92 [454M rows, 18.1GB] [76.6M rows/s, 3.05GB/s]
--- tpcds q22
-- before
CPU Time: 524.4s total, 355K rows/s, 2.48MB/s, 94% active
9.59 [186M rows, 1.27GB] [19.4M rows/s, 136MB/s]
-- after
CPU Time: 523.5s total, 355K rows/s, 2.48MB/s, 91% active
9.36 [186M rows, 1.27GB] [19.9M rows/s, 139MB/s]
-- rule disabled
CPU Time: 1231.1s total, 151K rows/s, 1.06MB/s, 95% active
45.43 [186M rows, 1.27GB] [4.09M rows/s, 28.6MB/s]
--- tpcds q67
-- before
CPU Time: 7792.7s total, 71.2K rows/s, 2.33MB/s, 61% active
53.23 [555M rows, 17.7GB] [10.4M rows/s, 341MB/s]
-- after
CPU Time: 7718.9s total, 71.9K rows/s, 2.35MB/s, 60% active
51.47 [555M rows, 17.7GB] [10.8M rows/s, 352MB/s]
-- rule disabled
CPU Time: 13827.4s total, 40.1K rows/s, 1.31MB/s, 64% active
1:36 [555M rows, 17.7GB] [5.8M rows/s, 190MB/s]
Additional context and related issues
Release notes
( ) This is not user-visible or is docs only, and no release notes are required. (X) Release notes are required. Please propose a release note for me. ( ) Release notes are required, with the following suggested text:
fyi @martint
I'm not sure I understand the benchmark results.
For example, according to this one, disabling the rule results in lower CPU time. Also, why is "before" different from "rule disabled"? Shouldn't both be approximately equal?
-- before
CPU Time: 6058.2s total, 475K rows/s, 1.76MB/s, 51% active
53.47 [2.88B rows, 10.4GB] [53.9M rows/s, 199MB/s]
-- after
CPU Time: 5318.7s total, 541K rows/s, 2MB/s, 65% active
43.22 [2.88B rows, 10.4GB] [66.6M rows/s, 247MB/s]
-- rule disabled
CPU Time: 4683.0s total, 615K rows/s, 2.28MB/s, 63% active
33.62 [2.88B rows, 10.4GB] [85.7M rows/s, 317MB/s]
In these ones, why are "before" and "after" the same, while rule disabled uses twice as much CPU? Shouldn't "rule disabled" be equivalent to "before"?
--- tpcds q22
-- before
CPU Time: 524.4s total, 355K rows/s, 2.48MB/s, 94% active
9.59 [186M rows, 1.27GB] [19.4M rows/s, 136MB/s]
-- after
CPU Time: 523.5s total, 355K rows/s, 2.48MB/s, 91% active
9.36 [186M rows, 1.27GB] [19.9M rows/s, 139MB/s]
-- rule disabled
CPU Time: 1231.1s total, 151K rows/s, 1.06MB/s, 95% active
45.43 [186M rows, 1.27GB] [4.09M rows/s, 28.6MB/s]
--- tpcds q67
-- before
CPU Time: 7792.7s total, 71.2K rows/s, 2.33MB/s, 61% active
53.23 [555M rows, 17.7GB] [10.4M rows/s, 341MB/s]
-- after
CPU Time: 7718.9s total, 71.9K rows/s, 2.35MB/s, 60% active
51.47 [555M rows, 17.7GB] [10.8M rows/s, 352MB/s]
-- rule disabled
CPU Time: 13827.4s total, 40.1K rows/s, 1.31MB/s, 64% active
1:36 [555M rows, 17.7GB] [5.8M rows/s, 190MB/s]
@martint the rule is on by default. before/after
is without/with the change here. rule off
is disabling the rule altogether