Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
backend ruleP1universalStack: sql
sqlperformancejoinsdatabase
Apply filtering conditions in the JOIN ON clause rather than joining then discarding rows
When a join should only match rows meeting a condition, put that condition in the JOIN ON clause instead of joining everything and filtering afterwards, which is wasteful.
PR: hegnar-investor-ws · org-mining-2026-06Created: Jun 17, 2026
Bad example
Old codesql
| 1 | JOIN tickers t ON th.ticker_id = t.id |
| 2 | WHERE t.millistream_id IS NOT NULL -- joins rows we then throw away |
Explanation (EN)
Objašnjenje (HR)
Good example
New codesql
| 1 | JOIN tickers t ON th.ticker_id = t.id AND t.millistream_id IS NOT NULL |
Explanation (EN)
Objašnjenje (HR)