Database Indexing Prompts
AI prompts for database indexing from the LearnWithHasan AI Coding Building Blocks (Performance).
Find and Fix a Slow Query with an Index
Start here. The fastest path from "my page is slow" to "it's fast now" From the Database Indexing AI Coding Building Block.
My [app / Django app / Rails app / Node app] has a page that loads slowly: [describe the page, e.g. "the orders list filtered by customer" or "the search results page"]. The table has [number] rows and growing. Find the slow query, explain why it's slow, and add a database index to fix it. After adding the index: - Show me the before and after query speed difference - Explain what the index does in plain English - Tell me if I need to run a migration or any extra step My stack: [your language and framework here, e.g. Python + Django, Ruby on Rails, Node + PostgreSQL] I'm learning, so explain each part simply.
Set Up Django Debug Toolbar to Find Slow Queries
For proactively finding performance problems before they get bad From the Database Indexing AI Coding Building Block.
I want to find slow database queries in my Django app before users complain. Set up Django Debug Toolbar so I can: - See every SQL query each page runs - See how long each query takes - Spot queries doing full table scans (sequential scans) - Identify which queries would benefit from an index Walk me through the installation, settings, and what to look for once it's running. My Django version: [your version, e.g. Django 4.2] I'm learning, so explain each part simply.
Audit My Database for Missing Indexes
For a full health check on an app that's been running a while From the Database Indexing AI Coding Building Block.
My [app] has grown and I want to make sure I'm not missing important database indexes. Review my models/schema and: - List every column that appears in WHERE, ORDER BY, or JOIN clauses - Identify which of those columns are missing indexes - Recommend composite (multi-column) indexes for queries that filter on multiple fields at once - Flag any indexes I already have that might be unnecessary or redundant - Prioritize the fixes by biggest performance impact My stack: [your language and framework here] Here are my models/schema: [paste your models or schema file] I'm learning, so explain each part simply.