by alexisread · 1y ago · 0 comments
This applies the filter before the join, compared with:
Select from mytable1 join mytable2 on... Where...
Which relies on the query plan to resolve the correct application of where, and hope it puts the where before the join.
This becomes more important in the cloud, where Iceberg tables cannot be benchmarked in the same way as single-cluster relational DBs.
Filter pushdown ("correct application of where, and hope it puts the where before the join") is table stakes for a query planner and has been for decades.
And no, Iceberg tables are not special in any way here. Iceberg tables contain data statistics, just like the ones described in the article to make the optimizer choose the right query plan.
On the other hand, if you are hand coding the query, you are hand coding whether you use SQL, Linq, or anything else. And a strength of SQL is a robust ecosystem of documentation, tools, employment candidates, and consultants.
databases are complicated beasts and tens of thousands if not more working years of the smartest people have been working on them since the 70s
Yes, but they've also set themselves a much harder problem. Instead of "find the proper execution for this particular query, armed with all the knowledge of the database you have" they have the problem of "find the proper execution for all possible queries, using only information that's encoded in DB statistics."
So it's no surprise that it's quite easy to find places the optimizer does silly things. To take one instance that bit me recently: or clauses representing different tables cannot be optimized well at all in postgres (https://www.cybertec-postgresql.com/en/avoid-or-for-better-p...).
I'd still rather have optimizers than not--the optimizer does well most of the time, and my current work has far too many queries to hand-optimize. But you do end up seeing a lot of poorly optimized queries.
select ...
from table1
left join mytable2 on ...
where ..
If you move contents of where clause to the join/on clause, you will change meaning of the query.If someone has a complex query or complex performance, they could do either subselects
select ...
from ( select ... from table1 where ... ) as table1_filtered
inner join mytable2 on ...
or CTEs with table1_filtered as ( select ... from table1 where ... )
select ...
from table1_filtered
inner join mytable2 on ...so I don't get it