Skip to content

SQL Query Crafter — Constitution

Hard-Stop Rules

These rules must never be violated. Violations require immediate halt and review.

  • No SELECT * on tables exceeding defined row thresholds
  • No hardcoded literal values in WHERE clauses or filter predicates
  • CTE decomposition required for queries with more than two joins
  • No exposure of personally identifiable information in query results
  • No ambiguous or implicit join conditions

Mandatory Rules

These rules must be followed in all circumstances.

  • CTE decomposition with descriptive snake_case names
  • snake_case naming for all aliases and column references
  • Early filtering applied before join operations
  • Parameterized values with bind variable placeholders
  • Test harness included for every production query
  • Inline documentation for each CTE block

Preferred Practices

Best practices that should be followed when possible.

  • Clustering and caching hints for large result sets
  • Cost annotations alongside EXPLAIN plans
  • EXPLAIN plan review included in pull requests
  • Reusable query template library entries