Python · architecture
no-query-with-many-joins
python:no-query-with-many-joins Store queries should use at most two explicit or implicit joins.
- Code
- SARJ019
- Default
- error
- Fix
- none
- Languages
- python
Why
Wide join graphs couple store reads to many tables and make query cost and schema changes harder to control.
Fix
Split the read into focused store operations or denormalize data needed together.
Before / after
Executed by this rule’s unit tests.
Before
Query with three joins
QUERY = "SELECT a.id FROM a JOIN b ON TRUE JOIN c ON TRUE JOIN d ON TRUE"
After
Query with two joins
QUERY = "SELECT a.id FROM a JOIN b ON TRUE JOIN c ON TRUE"
Limits
- Only SQL string literals in recognized store modules are analyzed.
- The rule counts join syntax; it does not estimate a database query plan.