---
title: "Building PlanetScale with Insights Agent"
description: "PlanetScale ran its Insights Agent, which finds costly queries via Query Insights and opens fix PRs, against its own Rails API on MySQL."
url: "https://swe.quest/articles/building-planetscale-with-insights-agent-b70b35e12242702e"
canonical: "https://planetscale.com/blog/building-planetscale-with-insights-agent"
source: "PlanetScale"
published: "2026-11-19"
difficulty: "medium"
kind: "Case study"
reading_minutes: 5
tags: ["mysql","performance","ai-agents","ruby","databases"]
---

# Building PlanetScale with Insights Agent

A post on [PlanetScale](https://swe.quest/sources/planetscale.md), published 2026-11-19, 5 min read, Case study. Original: [https://planetscale.com/blog/building-planetscale-with-insights-agent](https://planetscale.com/blog/building-planetscale-with-insights-agent)

## Summary

PlanetScale ran its Insights Agent, which finds costly queries via Query Insights and opens fix PRs, against its own Rails API on MySQL. Reordering a Flipper feature-flag check cut 28.7M daily lookups to 8.3M, saving about 6.5 hours of database time per day. An agent-added index made a billing query slower because a normalized IN list hid 645 values and most calls returned zero rows. Filtering in Ruby instead cut database time about 14x, and the agent now checks rows read/returned per call and SQL size. A composite index on (ready, failed\_at, created\_at) brought a reconciliation job's queries from seconds to milliseconds.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [MySQL](https://swe.quest/tags/mysql.md) (Data & databases)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [AI agents](https://swe.quest/tags/ai-agents.md) (AI & ML)
- [Ruby](https://swe.quest/tags/ruby.md) (Languages)
- [Databases](https://swe.quest/tags/databases.md) (Data & databases)

## Prerequisites

- MySQL composite indexes ([easy posts on MySQL](https://swe.quest/tags/mysql.md?difficulty=easy))
- Rails ActiveRecord ([easy posts on Ruby](https://swe.quest/tags/ruby.md?difficulty=easy))
- query execution plans

## Keywords

PlanetScale, Insights Agent, Query Insights, Flipper, MySQL, Rails

## Related posts

- [How we improved availability through iterative simplification](https://swe.quest/articles/how-we-improved-availability-through-iterative-simplification-1aa63e0def5687e6.md): GitHub Engineering · 2024-07-23 · Medium · 6 min read · Performance engineering, MySQL, Ruby, Observability, Deployment
  GitHub cut timeouts in its Rails monolith with small, measured changes found through Datadog metrics, Splunk logs and custom MySQL slow-query monitors.
- [Timeseries indexing at scale](https://swe.quest/articles/timeseries-indexing-at-scale-cbd6b9bd5fe12d35.md): Datadog Engineering · 2024-06-28 · Medium · 20 min read · Storage engines, Search, Databases, Observability, Scaling
  Datadog replaced its timeseries index, which auto-generated materialized indexes from a log of slow queries, with an inverted index that unconditionally indexes every metric;tag pair, much like search engines map words to documents.
- [Finding performance wins in our own traces with a coding agent](https://swe.quest/articles/finding-performance-wins-in-our-own-traces-with-a-coding-agent-884170e809905d07.md): Sentry · 2026-11-03 · Medium · 6 min read · Performance engineering, PostgreSQL, AI for coding, Observability, Python
  Pairing a coding agent with the Sentry MCP over Sentry's own production traces surfaced dozens of small backend fixes that together removed hundreds of millions of queries a week.
- [Operate with confidence: check production with your coding agent](https://swe.quest/articles/operate-with-confidence-check-production-with-your-coding-agent-2d12eed022759488.md): Supabase · 2026-10-20 · Medium · 4 min read · AI agents, Observability, PostgreSQL, Developer tools
  Supabase now ships Agent prompts that let a coding agent (Claude, Codex, Cursor) check a production project on a schedule for error spikes, security findings, slow queries and resource growth, reporting only new or worsening issues with the measured value, threshold and a next step.
- [What's new in ClickStack - May 2026](https://swe.quest/articles/what-s-new-in-clickstack-may-2026-9dca7663001ee0ca.md): ClickHouse · 2026-06-23 · Easy · 12 min read · Observability, Analytics & OLAP, AI agents
  ClickStack's May 2026 update focuses on making dashboards useful during investigations.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
