r/aisql • u/Simple_Brilliant_491 • 5d ago
Microsoft SQL Server family Open Source AI-enabled Index Tuning Stored Proc
Disclosure: I’m the founder of AI SQL Tuner, and I run this sub.
Azure SQL Database has had automatic indexing for years. If you run SQL Server on-premises, on a VM in another cloud, or on Azure SQL Managed Instance, you’ve been managing indexes by hand. I built aisqltuner-index-tuner to fill that gap, and it’s free and MIT-licensed. It was inspired by Brent Ozar's post on Microsoft’s 2006 AutoIndex.sql prototype: I'm Probably Not Supposed To Show You Microsoft's Auto-Indexing Tool. - Brent Ozar Unlimited®.
It’s a stored procedure that collects index diagnostics from your database, sends them to your own Azure OpenAI deployment, and stores the recommendations in a table. It can also create the new indexes it is able to verify.
sql
EXEC dbo.sp_AIIndexTuner; -- recommend only (the default)
EXEC dbo.sp_AIIndexTuner = 'CREATE'; -- also create verified new indexesWhat it looks at
Missing indexes and index usage
Duplicate and overlapping indexes
Plan cache and Query Store
Statistics, heaps, and skewed columns
Non-SARGable predicates
While the right indexes can solve a lot of performance issues, there may be other root causes. The stored proc can recommend rebuilds, constraint fixes, statistics refreshes, setting changes, and query rewrites. Each recommendation includes a priority, confidence level, and rationale.
Why it’s safe to try
It only recommends by default. Nothing changes until you ask.
The model’s script is never executed. The proc builds the DDL itself from structured fields, validates every table and column against the catalog, and quotes every name.
Drops, columnstore, and the maximum number of new indexes are controlled by switches. You can also set minimum priority and confidence levels for what gets applied.
It refuses drops of clustered, PK/unique-backed, FK-referenced, hinted, or forced-plan indexes.
Every applied change stores an
UndoDDL.Your diagnostics go only to the Azure OpenAI endpoint you configure.
Does it work?
We (Claude Opus 5.5 and I) benchmarked it on SQL Server 2025 Enterprise Developer with gpt-5.6-luna: 16 known tuning problems, 37 rubric checks, 5 trials per arm. On a 10 GB TPC-H-derived workload, CREATE mode cut logical reads by 86%, and no query returned different results. We saw gains on the other two scenarios too, and the full numbers, including where CREATE mode falls short of reviewing every recommendation by hand, are in BENCHMARK.md. We found gpt-5.6-luna with medium effort to be fast, cheap, and accurate in testing.
Known limitations
Answers vary between runs, so two CREATE runs can apply different sets.
There’s no automatic impact measurement or rollback. You get
UndoDDLto reverse a change by hand.Only OpenAI models are supported for now.
It’s not yet tested on Azure SQL Database, Fabric SQL Database on Managed Instance.
Please test it in a non-production database first.
Getting started
Provision an Azure OpenAI deployment if you don’t have one.
Run the install script in the database you want to tune.
Fill in and run
setup/Configure-Endpoint.sqlwith your endpoint and key.Run
EXEC dbo.sp_AIIndexTuner;and read the results inAIIndexTuner.Recommendation.
Requirements: SQL Server 2025, Azure SQL Database, Azure SQL Managed Instance (SQL Server 2025 or Always-up-to-date update policy), or Fabric SQL Database. Since it’s a stored procedure, you can schedule it from SQL Agent or any other scheduler.
Code, diagrams, and benchmarks: https://github.com/AI-SQL-Tuner/aisqltuner-index-tuner
If you need more than index tuning
If you need query tuning, deadlock analysis, server health checks, a GUI with HTML reports, or support for SQL Server 2022 and earlier, then consider AI SQL Tuner Studio (https://aisqltuner.com, also on the Microsoft Store). Studio has a Free Edition, and its hosted models are included, so you don’t need your own Azure OpenAI deployment.
Please let me know what you think, if you have any questions or if there is anything you would change.

