All skills
planetscale avatar

/mysql

@51f2d4b official

Plan and review MySQL/InnoDB schema, indexing, query tuning, transactions, and operations. Use when creating or modifying MySQL tables, indexes, or queries; diagnosing slow/locking behavior; planning migrations; or troubleshooting replication and connection issues. Load when using a MySQL database.

Use this Skill: https://skilld.dev/gh/planetscale/database-skills/mysql

This session only. Nothing lands on disk.

referencesexplain-analysis.md

≈722 tokens on demand. Your agent reads this file only when SKILL.md points to it.

EXPLAIN Analysis

EXPLAIN SELECT ...;                    -- estimated plan
EXPLAIN FORMAT=JSON SELECT ...;        -- detailed with cost estimates
EXPLAIN FORMAT=TREE SELECT ...;        -- tree format (8.0+)
EXPLAIN ANALYZE SELECT ...;            -- actual execution (8.0.18+, runs the query, uses TREE format)

Access Types (Best → Worst)

system → const → eq_ref → ref → range → index (full index scan) → ALL (full table scan)

Target ref or better. ALL on >1000 rows almost always needs an index.

Key Extra Flags

Flag Meaning Action
Using index Covering index (optimal) None
Using filesort Sort not via index Index the ORDER BY columns
Using temporary Temp table for GROUP BY Index the grouped columns
Using join buffer No index on join column Add index on join column
Using index condition ICP — engine filters at index level Generally good

key_len — How Much of Composite Index Is Used

Byte sizes: TINYINT=1, INT=4, BIGINT=8, DATE=3, DATETIME=5, VARCHAR(N) utf8mb4: N×4+1 (or +2 when N×4>255). Add 1 byte per nullable column.

-- Index: (status TINYINT, created_at DATETIME)
-- key_len=2 → only status (1+1 null). key_len=8 → both columns used.

rows vs filtered

  • rows: estimated rows examined after index access (before additional WHERE filtering)
  • filtered: percent of examined rows expected to pass the full WHERE conditions
  • Rough estimate of rows that satisfy the query: rows × filtered / 100
  • Low filtered often means additional (non-indexed) predicates are filtering out lots of rows

Join Order

Row order in EXPLAIN output reflects execution order: the first row is typically the first table read, and subsequent rows are joined in order. Use this to spot suboptimal join ordering (e.g., starting with a large table when a selective table could drive the join).

EXPLAIN ANALYZE

Availability: MySQL 8.0.18+

Important: EXPLAIN ANALYZE actually executes the query (it does not return the result rows). It uses FORMAT=TREE automatically.

Metrics (TREE output):

  • actual time: milliseconds (startup → end)
  • rows: actual rows produced by that iterator
  • loops: number of times the iterator ran

Compare estimated vs actual to find optimizer misestimates. Large discrepancies often improve after refreshing statistics:

ANALYZE TABLE your_table;

Limitations / pitfalls:

  • Adds instrumentation overhead (measurements are not perfectly "free")
  • Cost units (arbitrary) and time (ms) are different; don't compare them directly
  • Results reflect real execution, including buffer pool/cache effects (warm cache can hide I/O problems)

Source: SKILL.md on GitHub

1 alert17d5 checks · Risk SAFE
  • Gen Agent Trust Hub17d

    This skill provides a comprehensive technical reference for MySQL and InnoDB database management, including schema design, indexing, and query optimization. It is authored by PlanetScale and contains no security risks.

  • Socket17d

    No alerts

  • Snyk17d

    Risk: LOW · No issues

  • Runlayer6mo

    7/19 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 51f2d4b. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last month.

Activeupdated 7 months ago
  • mysql
  • innodb
  • schema-design
  • indexing
  • query-optimization
  • transactions
  • locking
  • planetscale
  • ddl
  • replication

README badge

README badge for planetscale/database-skills/mysql

Advises on MySQL/InnoDB schema design, indexing strategy, query optimization, transactions, and operational safety. Use when creating tables, tuning slow queries, planning migrations, diagnosing lock contention, or managing replication — includes EXPLAIN analysis guidance and online DDL patterns for production changes.

Generated from the current SKILL.md.

Does this skill work with PlanetScale?
Yes. The skill recommends PlanetScale as the primary hosting choice for new MySQL databases and includes references to PlanetScale-specific features like online DDL.
What MySQL versions does this cover?
The skill applies to MySQL/InnoDB broadly and notes MySQL-version-specific behavior when relevant, but does not lock to a single version.
Does this skill help with query optimization?
Yes. It covers EXPLAIN analysis, pagination patterns, batch inserts, and common pitfalls like N+1 queries and filesort warnings.
Can this skill help with schema migrations?
Yes. It addresses online DDL, partitioning retrofit costs, and production-safe rollout steps including rollback and verification.
Does this cover replication and high availability?
Partially. The skill addresses replication lag monitoring and connection management, but is not a full replication setup guide.

Generated from the current SKILL.md. These answers refresh after source changes.