-
Notifications
You must be signed in to change notification settings - Fork 0
Should explain union between 3+ queries be flattened? #4856
Comments
I'm not even sure joins should be on the same level. |
With empty dummy tables: explain select count(*) from t1 inner join t2 on t1.id=t2.id inner join t3 on t1.id=t3.id;
With a more real database: explain select *
from sales.Store
inner join sales.Customer on sales.Store.BusinessEntityID = sales.Customer.StoreID
inner join sales.SalesOrderHeader on sales.Customer.CustomerID = sales.SalesOrderHeader.CustomerID
inner join sales.SalesOrderDetail on sales.SalesOrderHeader.SalesOrderID = sales.SalesOrderDetail.SalesOrderID;
Worthy of note that join order matters in DBs. Postgres uses heuristics (GEQO) to determine a good join order. When there's a low number of paths it does an exhaustive search to find the optimal solution. |
I gave this more thought and I think the joins display is the problematic part. Besides the fact that the join tree is collapsed, the information about which joins are emulated is not shown either. Not convinced it is worth fixing though. |
For postgres
For JOINs it's reasonable that it's a tree in DBs, because performance can vary between different paths. Though if we indicate any join priority it may be misleading because the DB to which it's offloaded may decide on a different order. At least we should show the order it's done when emulated. |
This is not true in the general case. (select 1 union distinct select 2) union all select 1; is different from select 1 union distinct (select 2 union all select 1);
I don't think the JOIN performance is relevant here. OUTER JOINs are not associative. |
I didn't know we supported explain select count(*) from test union all select count(*) from test explain select count(*) from test union distinct select count(*) from test |
Yes, I think that would make sense. |
I think we shouldn't try to strictly respect associativity. The original idea of I'm not sure how emulated joins work and if we currently represent those. |
Should all unions be at the same level like joins are?
The text was updated successfully, but these errors were encountered: