Documentation
¶
Overview ¶
Package performance provides linter rules for detecting SQL anti-patterns that cause poor query performance, full table scans, or N+1 problems.
Rules:
- L016: SELECT * (fetches all columns)
- L017: Missing WHERE on SELECT (full scan risk)
- L018: Leading wildcard LIKE (prevents index use)
- L019: NOT IN with subquery (NULL risk)
- L020: Correlated subquery in SELECT list (N+1)
- L021: OR instead of IN (multiple equality conditions)
- L022: Function on indexed column in WHERE
- L023: Implicit cross join (comma-separated tables)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FunctionOnColumnRule ¶
FunctionOnColumnRule (L022) detects function calls wrapped around column references in WHERE clauses (e.g., YEAR(created_at) = 2024). Wrapping a column in a function prevents the query planner from using indexes.
func NewFunctionOnColumnRule ¶
func NewFunctionOnColumnRule() *FunctionOnColumnRule
NewFunctionOnColumnRule creates a new L022 rule instance.
type ImplicitCrossJoinRule ¶
ImplicitCrossJoinRule (L023) flags queries that reference multiple tables in the FROM clause without explicit JOIN syntax. Comma-separated tables create an implicit cross join (Cartesian product) which is almost always unintentional and produces an explosive result set.
func NewImplicitCrossJoinRule ¶
func NewImplicitCrossJoinRule() *ImplicitCrossJoinRule
NewImplicitCrossJoinRule creates a new L023 rule instance.
type LeadingWildcardRule ¶
LeadingWildcardRule (L018) flags LIKE patterns with a leading wildcard (% or _). A leading wildcard forces a full table scan — it cannot use a B-tree index.
func NewLeadingWildcardRule ¶
func NewLeadingWildcardRule() *LeadingWildcardRule
NewLeadingWildcardRule creates a new L018 rule instance.
type MissingWhereRule ¶
MissingWhereRule (L017) flags SELECT statements with no WHERE clause and no LIMIT on queries that reference at least one table — indicating a potential full table scan.
func NewMissingWhereRule ¶
func NewMissingWhereRule() *MissingWhereRule
NewMissingWhereRule creates a new L017 rule instance.
type NotInWithNullRule ¶
NotInWithNullRule (L019) flags NOT IN (subquery) patterns. If the subquery returns any NULL value, the entire NOT IN expression evaluates to UNKNOWN (never true), silently returning zero rows — a common SQL trap.
func NewNotInWithNullRule ¶
func NewNotInWithNullRule() *NotInWithNullRule
NewNotInWithNullRule creates a new L019 rule instance.
type OrInsteadOfInRule ¶
OrInsteadOfInRule (L021) detects repeated equality conditions on the same column joined by OR (e.g., col = A OR col = B OR col = C) and suggests using IN instead. Multiple ORs on the same column can prevent index use and are harder to read.
func NewOrInsteadOfInRule ¶
func NewOrInsteadOfInRule() *OrInsteadOfInRule
NewOrInsteadOfInRule creates a new L021 rule instance.
type SelectStarRule ¶
SelectStarRule (L016) flags SELECT * usage. SELECT * fetches all columns, preventing index-only scans and over-fetching data.
func NewSelectStarRule ¶
func NewSelectStarRule() *SelectStarRule
NewSelectStarRule creates a new L016 rule instance.
type SubqueryInSelectRule ¶
SubqueryInSelectRule (L020) flags correlated subqueries in the SELECT column list. A subquery in the SELECT list is executed once per row — this is the classic N+1 problem.
func NewSubqueryInSelectRule ¶
func NewSubqueryInSelectRule() *SubqueryInSelectRule
NewSubqueryInSelectRule creates a new L020 rule instance.