Notifications
Clear all

Top Claude Code skills for optimizing SQL database queries?

3 Posts
4 Users
0 Reactions
78 Views
0
Topic starter

What specific Claude Code prompts or skills are actually best for optimizing messy SQL queries? Im super stoked to try this out on my side project for a bakery downtown but the database is a total disaster left over from the 2000s. I saw some people online saying Claude is great at explaining execution plans and suggesting indexes but then I read a thread where someone said it hallucinates complex JOIN logic on old schemas. I need to get this inventory system running smooth by Friday or the owner is gonna be annoyed lol. Should I just feed it the schema or are there specific skills I should be looking into for the best performance boost?


3 Answers
11

Just catching up on this thread and to add to the point above: honestly, you gotta be super careful with those old schemas. Claude can definitely hallucinate a JOIN that doesnt exist if your naming conventions from the 2000s are weird. My quick tip is to always ask it to generate the EXPLAIN ANALYZE version of the query before you commit to any changes. Use that to compare the execution cost before and after. I usually keep DBeaver Community Edition 24.1 open to run the plans myself because trusting the AI blindly with an old legacy DB is a recipe for a Friday night disaster lol. It works decent for index suggestions tho. Just keep the prompts focused on one specific bottleneck at a time instead of trying to fix the whole inventory system in one go.


11

> I need to get this inventory system running smooth by Friday or the owner is gonna be annoyed lol. Totally get that pressure, been there many times. Quick question though... what flavor of SQL are you actually running? If it is something super legacy like Microsoft SQL Server 2008 R2 or an old MySQL build, Claude might suggest modern syntax that just wont fly on your server. I have been really satisfied with asking it to perform query decomposition. Basically, you tell Claude to break the giant, messy query into smaller CTEs or temp tables first. It makes the logic way easier for the AI to grasp without hallucinating weird relationships. Honestly, it works well because it also helps you spot where the 2000s-era logic is failing. I usually keep JetBrains DataGrip 2024.1 SQL IDE open to verify the execution paths it suggests. It is a bit more manual but saves a ton of money on tokens by avoiding long, failed debugging loops since you are sending smaller chunks of code.


2

> Should I just feed it the schema Feed the full DDL to Anthropic Claude 3.5 Sonnet LLM 200k Context first. I once optimized a messy 2000s inventory DB that way and the index suggestions were actually decent.


Share: