Y’all Are Getting Good Free AI Advice from PasteThePlan.

AI, PasteThePlan.com
9 Comments

PasteThePlan has a new AI Suggestions tab, and it’s been really fun to watch the query plans come in and the advice go out. Here are some examples:

  • Date “tables” – when I looked at the query, I glossed over the real problem. I thought arc_Calendar was a real date table, but AI figured out that it’s actually generated on the fly with spt_values, something that blows my mind at what an incredibly bad idea that is. It never crossed my mind that someone would even consider doing this in production, and AI tells them what to do instead.
  • This is fine – someone asked for advice on a select from a 1-row temp table. AI said get outta here with that nonsense.
  • One-table delete – but due to foreign keys, it’s actually touching multiple tables. The AI advice explains what’s going on and how to make it go faster, plus boils it down to “if you only do one thing” – I love that! I love prioritized advice.
  • Reporting process – a kitchen-sink style query that at first glance should probably be rewritten to dynamic SQL, but they’ve already solved that to some extent by slapping an option recompile hint on it. The AI advice catches a scalar UDF causing problems, suggests a rewrite using a technique the company’s already using on another column, and suggests a slight rewrite to push filtering earlier. Again, I love its recap here, all for free, in less than 30 seconds.
  • Lengthy paged dynamic SQL – ugh, even just glancing at this makes me look at the clock to think about how long it would take me to analyze. In seconds, AI reasoned over this monster to suggest indexes that would help the paging, plus raises some eyebrows at a weird not-exists-not-exists design.
  • Meaningful function rewrites – advice to quickly and easily change non-sargable functions into index seeks, and remove a correlated subquery.

Advice I’m not as wild about, and I’m thinking about how to tune the AI prompt in order to improve it:

  • 16,000 row export with no WHERE clause – my first reaction here is to say, “Whoa now, we don’t tune for 16,000-row XML export queries.” However, when it comes to tuning the prompt to deliver better advice, I think we need to push the user harder to copy/paste in actual execution plans that include timing information, and then evaluate whether we should bother making changes, or whether the query’s performing good enough based on the wild output we’re asking for. This Power BI query is a similar example – whenever I see scientific notation for the estimated number of rows, I wanna stop tuning there and go get the actual plan.
  • Covering indexes galore – this is just one example, but my first iteration on my AI prompt didn’t discourage covering indexes, and AI seems to really wanna suggest ’em. I need to refine the prompt to suggest starting indexes with just the keys, and then only add includes for covering if the query’s still not fast enough after the initial indexes. There also seems to be a hesitance to recommend clustered indexes on heaps, even reporting heaps that were just created for the purpose of the query we’re looking at.
  • Lose the cursor – I’m surprised at how often I’ve seen folks paste cursor plans in. I do love the advice – it’s always “hey lose the cursor” – but I think we could do better. I’d like to be able to proactively rewrite stuff for folks, but realistically, a web page isn’t the best UI for that, and it will probably need a better, slower model with a >30 second timeout. We need to tell people, “Here’s a link to a set of commands that will rewrite the query for you” – whether that’s Claude Code, ChatGPT Codex, the plain chat interface for those tools, or something else.

And some queries & advice are just making me think. For example, in this multi-step reporting query, the AI seemed to find a lot of advice, but to understand if the advice is any good, I kinda want a followup status report from the user. Did they implement any of these fixes? Which ones? What kinds of differences did they see? We probably need a feedback loop of some kind to help iterate over the AI prompt.

I’m not delusional enough to think PasteThePlan.com is the right long-term solution for getting plan advice! We only have about 50 people using it each weekday. However, if that helps 50 people per day avoid posting questions to forums, and get instant answers that solve their problems for free and make users happier, then I’m very happy with that result. I couldn’t possibly answer 50 peoples’ query questions per day for free in my spare time!

Previous Post
My Wish List for SQL Server Performance Features
Next Post
[Video] Office Hours: Q&A on the Mountaintop

9 Comments. Leave new

  • Jac Thiessen
    March 25, 2026 4:44 pm

    I loved your email today about the AI advice. I appreciate the insights AI gives after pasting the prompt. I am also not convinced about covering indexes as a top solution. One aspect that I think is also worth mentioning is that I include the comment “Optimize for MSSQL 2016” or whichever version is in production and it gives better advice for older versions of SQL. You will often get different results for SQL2016 and SQL2019 in particular. It may be helpful to actually include that in the PasteThePlan AI prompt.

    Reply
    • 2016 will be out of support in less than 6 months. I wouldn’t recommend anyone spend time tuning on that. If you’re still on 2016 and performance is important to you, you should focus your work on moving to a supported version with more tuning capabilities. (That’s what I tell clients, at least.)

      Reply
      • I’ve needed to get queries tuned up on 2016 just to provide better visibility of individual query performance in 2016 and reduce noise for baselines to compare to for the eventual upgrade. Lots of queries getting 25% grants continuously blowing the cache. But I was working on that 2 years ago…

        Reply
  • ‘If you only do one thing’ — that’s the kind of advice that actually gets implemented. The fact that it reasoned over that dynamic SQL monster in seconds and came back with something actionable says a lot about where this is heading.

    Understanding whether the AI advice is any good is the real question — I like that feedback loop. It would at least reflect if the AI is legitimately any good, or just becoming more confident.

    Fifty people a day getting instant advice they’d otherwise wait days for on a forum is not a small thing. Appreciate you making it available, Brent.

    Reply
    • Our pleasure! Richie and I have already started sketching out what the feedback loop should look like, and designing the ability to ask for a second opinion inform a deeper thinking model. I’m excited for that.

      Reply
  • Just posting to say that while I don’t use pastetheplan.com every day or even week, when I did need to use it, it was super helpful. Thanks for maintaining and even improving it, guys! I’m looking forward to trying the new AI functionality.

    Reply
  • I’m wondering about violating corporate security if I post a plan involving one of my work queries. Has anyone else dealt with the issue?

    Reply
    • If you have questions about your company’s security policies, the best place to ask them would be to your company’s security team, not a blog comment section.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.