docs/rules/ is the documentation source of truth for the ClickAdvisor rule
catalog.
The runtime code in clickadvisor/rules/ and the rule cards in
docs/rules/cards/ are intentionally separate:
- documentation cards capture scope, assumptions, validation status, and future proof notes
- runtime classes implement executable behavior
- catalog validation ensures metadata consistency before implementation lands
Rule tiers follow the contract defined in ADR-003 and specified in
docs/rules/TIERS.md.
1A: formal equivalence from relational algebra1B: formal equivalence with ClickHouse-specific invariants1C: formal equivalence with statically verifiable preconditions2: cost-based recommendationdetector: non-rewrite diagnostic signal3: speculative advisory recommendation that requires verificationenv: environment or deployment adjustment rule
The tier is not presentation-only metadata. It governs proof expectations, automatic application policy, and validation requirements.
Tier 2 cards represent cost-based recommendations. They are expected to carry
strong evidence from plans, metadata, or storage context, but they are not
formal equivalence claims. Typical examples include design suggestions for
ordering keys, projections, join strategy, and storage-layout adjustments.
These rules should:
- explain the cost signal they depend on
- avoid theorem-like equivalence language
- describe expected impact conservatively
Tier detector cards represent diagnostic findings that identify a likely
problem shape without necessarily prescribing a single canonical rewrite. They
are useful when the primary value is surfacing risk, waste, or anti-patterns
rather than transforming SQL directly.
These rules should:
- describe the signal being detected
- keep recommendations lightweight unless backed by a separate rule
- avoid pretending they are formal rewrite rules
Tier env cards represent environment-aware findings and adjustments. They do
not rewrite SQL directly; instead they adapt guidance according to hardware,
settings, caching, concurrency, storage, or cluster topology.
These rules should:
- document the environment scope clearly
- separate deployment advice from query-semantic advice
- preserve the distinction between operator tuning and SQL rewrites
SCHEMA.yaml: JSON Schema for rule card structureTEMPLATE.md: authoring template and section guidanceTIERS.md: detailed tier definitions and criteriacards/: YAML rule cards, one file per rule
- Copy the structure from
TEMPLATE.md. - Create a new YAML card in
docs/rules/cards/. - Fill metadata conservatively. Leave unknown proof details as TODOs rather than inventing them.
- Validate the catalog before opening a PR.
- Add runtime implementation later in
clickadvisor/rules/only after the card is sufficiently validated.
Run the catalog validator locally:
python scripts/rules/validate_catalog.pyThe validator checks:
- schema compliance
- duplicate rule IDs
- cross-field constraints such as
tier=1Awithopt_in=true - proof/risk requirements for more mature statuses
- Do not fabricate proofs or semantic guarantees.
- If a proof is not yet reviewed, keep the rule in
proposed. - Prefer explicit placeholders over vague prose.
- Use references to connect cards to ADRs, docs, and benchmark cases.