I am mainly confused about the execution plan of three tables, this is the execution plan of query as below(note: t1d,t2d,t3d are distributed table):
select xxx
from t1d t1d
left join
(select * from t2d where xxx group by xxx) t2d
using A
left join
(select * from t3d where xxx group by xxx) t3d
using A
where t1d.xxx
group by t1d.xxx
SETTINGS distributed_product_mode='local'
┌─explain───────────────────────────────────────────────────────────────────────────────────────────┐
│ Expression (Projection) │
│ CreatingSets (Create sets before main query execution) │
│ Expression (Before ORDER BY) │
│ Join (JOIN) │
│ Expression ((Before JOIN + Projection)) │
│ SettingQuotaAndLimits (Set limits and quota after reading from storage) │
│ Union │
│ Expression ((Convert block structure for query from local replica + )) │
│ CreatingSets (Create sets before main query execution) │
│ Expression (Before ORDER BY) │
│ AddingDelayedSource (Add non-joined rows after JOIN) │
│ Join (JOIN) │
│ Expression (Before JOIN) │
│ SettingQuotaAndLimits (Set limits and quota after reading from storage) │
│ ReadFromPreparedSource (Read from NullSource) │
│ CreatingSet (Create set for JOIN) │
│ Expression ((Projection + Before ORDER BY)) │
│ Aggregating │
│ Expression (Before GROUP BY) │
│ SettingQuotaAndLimits (Set limits and quota after reading from storage) │
│ ReadFromStorage (MergeTree) │
│ ReadFromPreparedSource (Read from remote replica) │
│ CreatingSet (Create set for JOIN) │
│ Expression (Projection) │
│ SettingQuotaAndLimits (Set limits and quota after reading from storage) │
│ Union │
│ Expression ((Convert block structure for query from local replica + Before ORDER BY)) │
│ SettingQuotaAndLimits (Set limits and quota after reading from storage) │
│ ReadFromStorage (MergeTree) │
│ ReadFromPreparedSource (Read from remote replica) │
From my understanding, I think the step as below:
t1_local and t2_local do local join on each shard as your reply, and I use explain syntax to find that t2d is written to t2_local, it is true, I am clear about this.
Initiator host combines the results from all shard of local join
each shard do query "select * from t3_local where xxx group by xxx" and combines on the initiator(maybe this is synchronized with step1)
Initiator do join between result of step2 and result of step3.
and my question is that: I hope on each shard can do local join like
select xxx
from t1_local
left join (select xxx from t2_local)
using A
left join (select xxx from t3_local)
using A
and then the initiator combines results from all shards. I think this is faster than above. But actually the execution plan can't show it.


