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 ruleP0universalStack: sql
correctnessqueriesfilteringboolean-logic
Combine alternative-match filters with OR, not AND
When several filters represent alternative ways a record can match (e.g. country/region/sub-region), group them with OR inside one clause and AND that group with the rest, or valid cross-matches return nothing.
PR: vinify-backend · org-mining-2026-06Created: Jun 17, 2026
Bad example
Old codesql
| 1 | WHERE country_id = :country |
| 2 | AND region_id = :region |
| 3 | AND sub_region_id = :subRegion -- empty for valid cross-origins |
Explanation (EN)
Objašnjenje (HR)
Good example
New codesql
| 1 | WHERE ( |
| 2 | country_id = :country |
| 3 | OR region_id = :region |
| 4 | OR sub_region_id = :subRegion |
| 5 | ) |
| 6 | AND other_filter = :x |
Explanation (EN)
Objašnjenje (HR)