agentleFS
febshhyfebshhy/mimir-codex/.agents/skills/advanced-sql/SKILL.md

advanced-sql

Skill0 starsChanged 4 days agoMITArchived repositoryView on GitHub

Design, review, debug, test and optimize SQL queries, analytical schemas, semantic models, SQL pipelines, SQL-based statistics, ML feature queries and governed SQL/AI workloads. Use for joins, CTEs, window or recursive queries, query plans and dialect selection. Complement data-dimensional-modeling for business grain and database-design for physical indexing/engines. Do not require a warehouse migration or use every advanced feature.

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Method: Start with the actual engine/version, target question and relevant tables.

    line 10
  2. Very specific:

    Express clearly: prefer the simplest readable set-based query.

    line 18
  3. Very specific:

    Avoid treating SELECT *, indexes, partitioning, caching, materialized views, OBT and streaming as universal optimizations.

    line 30

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Advanced SQL — semantic correctness → measured query efficiency

Authority: The SQL representation and execution of an approved question, data contract or transformation. $requirements owns business rules; $data-dimensional-modeling owns analytic fact/metric meanings; $database-design owns engine and persistent physical-design choices; $data-statistics owns statistical inference; $data-decision-science owns ML decision validity; $data-lifecycle/$data-operations own running pipelines. Do not silently redefine these contracts to speed up a query.

Method: Start with the actual engine/version, target question and relevant tables. Use only relevant references: query semantics, model selection, execution plans and dialects, SQL pipelines and semantic layers, SQL in science, AI and emerging syntax. See book-derived concept map.

The eight-step SQL review (scale to the task)

  1. Question and consumer: state output and why it matters; distinguish a descriptive query, operational transformation, prediction dataset and write.
  2. Inputs and grain: identify source authority, row meaning, unique keys, cardinalities, source version, null/duplicate policy, and event/effective/ingest time. Record what is unknown.
  3. Model fit: choose existing normalized, star, snowflake, wide, lakehouse or semantic/graph representation by actual read/write patterns and change needs. Do not remodel when a query suffices.
  4. Relational correctness: map each join's multiplicity, filtering stage, grouping level, aggregation and null semantics. Guard against silent row multiplication and denominator changes.
  5. Express clearly: prefer the simplest readable set-based query. Use CTEs to structure reasoning, windows for row-relative calculations, recursion for bounded traversals, and subqueries/EXISTS for membership. CTEs do not automatically materialize or speed up queries.
  6. Validate results: compare with small known-answer fixtures or an independent query; exercise 0/1/many matches, NULLs, ties, duplicate or late events and time boundaries. Check both row grain and aggregate reconciliation.
  7. Measure before tuning: inspect real plan and runtime/cost/bytes at representative parameters and volume. Change one mechanism at a time; recheck output equivalence and concurrent/load behavior. Mark unmeasured claims unknown.
  8. Operationalize conditionally: for shared SQL models add ownership, lineage, permissions, freshness, incremental/backfill semantics, tests, monitoring and compatible releases. For one-off analysis, keep a reproducible query and assumptions; no mandatory orchestration.

Critical guards

  • A correct SQL syntax or schema is not proof of correct business meaning. Know one row represents what, especially before JOIN, COUNT, DISTINCT, AVG, ratios and windows.
  • LEFT JOIN can become an effective inner join when right-side filters are placed in WHERE; an INNER JOIN can multiply facts. Test both risks.
  • ROW_NUMBER() and top-N need a deterministic total order to resolve ties. Window ORDER BY and window frame (ROWS/RANGE/GROUPS) are distinct; do not assume a cumulative frame expresses a whole partition.
  • SQL uses three-valued logic: NULL is not an ordinary value. Be careful with NOT IN when the subquery contains NULL; prefer NOT EXISTS for anti-membership when appropriate. COUNT(*) differs from COUNT(col).
  • Casts, overflow, decimal precision, timestamps/timezones, implicit coercion, division by zero, collation, isolation and dialect behavior need explicit treatment when relevant.
  • Avoid treating SELECT *, indexes, partitioning, caching, materialized views, OBT and streaming as universal optimizations. Protect correctness, authorization and maintainability first.
  • A model feature must be available at decision cutoff; event time alone does not establish availability. A successful SQL training query is not evidence of model validity or causal impact.
  • SQL-triggered generative AI may disclose governed content to an external service. Require permission, cost ceiling, grounding, output evaluation, and vendor/version-specific confirmation before enabling it.

Focused output contract

Consumer / question / intended output:
SQL engine + version + dialect constraints (known/unknown):
Input sources / owners / row grain / cardinality / time semantics:
Query/model choice, alternative and reason:
SQL + expected result shape and key invariants:
Small known-answer test + adversarial edge cases:
Observed plan, runtime and cost | Not measured:
Permissions / lineage / freshness / replay / rollback if operational:
Known | Assumed | Unknown | decision pending:

Scope and provenance: This method synthesizes Advanced SQL: Implementing Modern Data Solutions and ML Applications by Rui Machado, Hélder Russa and Pedro Esmeriz (O'Reilly, 2026), using the public publisher table of contents and chapter previews, then adds explicitly identified Mimir engineering checks. The book's full text is not included in this repository. These are original, practical instructions, not verbatim book examples and not a claim of exhaustive full-text coverage.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.