3 ms·
not a good idea, constaints are one thing and joins are another thing. plus I can join on conditions other than =. the problem that author is trying to solve c
by slt2021 5y ago
not a good idea, constaints are one thing and joins are another thing.
plus I can join on conditions other than =.
the problem that author is trying to solve can be easily solved by a view:
1. Declare a view with all necessary JOINs once
2. select from view only what you need, aggregate what you want
3. Optimizer will throw out unnecessary stuff and optimize query while all JOIN logic will be declared only once and will be hidden inside the view
plus each DBMS has its own flavor of SQL and will have its own query optimizer nuances when dealing with joins, especially nested via CTEs/views/lateral queries,etc.
- Sesse__ 5y agoYour #3 is very optimistic. You can't just remove a join (be it inner, left, or really any other type) just because you didn't refer to any fields from one of the sides, and it's even harder when aggregation is in the mix. There are cases where you can without influencing the result, but they are special-case optimizations and not universally supported across databases.