A New Microsoft Patent Has AI Speed Up Database Code, Then Checks Its Work
Microsoft's patent lets an AI rewrite slow database code, then refuses to use the rewrite until a formal check shows it always gives the same answer as the original.
What Microsoft's AI query rewriter actually does
A company analyst types a database question late on a Friday. Buried inside it is a small custom program, written in Python, that cleans up some text before the database can answer. The database crawls through it, and the report comes back slowly.
Microsoft's patent application describes a tool that hands that custom program to a large language model (the AI technology behind chatbots) and asks it to rewrite the logic in plain database language, which databases run much faster. The risk is obvious: an AI can get things subtly wrong, and wrong numbers in a report are worse than slow ones.
So the system checks the AI's work before trusting it. If the check passes, the faster version goes in. If it fails, the original runs as usual, so you never get a different answer, only, at best, a quicker one.
… translating, using a large language model (LLM), the UDF into a translated SQL query; compiling the translated SQL query into a logical plan; generating verification conditions for the logical plan; translating the UDF into an intermediate verification language; …
Translation: An artificial intelligence translates custom code into database language, then breaks it down to check its own work.
How Microsoft proves the AI's rewrite matches
The input is a parent query: a normal database request (written in SQL, the standard language for asking databases questions) that calls a user-defined function, or UDF. A UDF is a custom piece of code, often in Python, that the database runs row by row. The filing says these can run orders of magnitude slower than the same job done in native SQL.
The system works in a series of steps:
- An LLM translates the UDF into SQL. The filing describes prompts tailored to each type of UDF, plus details such as table layouts and data types.
- The translated SQL is compiled into a logical plan, a step-by-step map of operations like split, filter and join.
- That plan becomes verification conditions: a chain of stand-in functions (called uninterpreted functions) that describe what each SQL operation does.
- Separately, the original UDF is converted into Boogie, a language built for proving that code behaves correctly.
A verifier then matches the two sides and checks that, for any possible input, they produce the same result. The Python-to-Boogie conversion uses a set of rewrite rules that preserve meaning, so they can be applied in any order. If the system can't tell what type a variable is, the check counts as failed.
The present disclosure relates to systems and methods for translating a structured query language (SQL) with a user-defined function (UDF) into a translated SQL query using a machine learning model.
Translation: Microsoft patented a system that uses machine learning to rewrite custom database code into standard SQL.
Why faster database queries matter to Microsoft
For anyone who runs reports on big company data, this points to faster answers without a human rewriting code by hand. The filing also says the approach cuts out-of-memory errors. Microsoft sells cloud databases and data tools, so shaving time off common queries is worth real money to its customers and to its own servers.
The patent office has approved this application, and once Microsoft pays the final fee it should be issued as a granted patent. The design also lets Microsoft add support for new functions by registering them in a shared repository, without changing the rest of the tool.
That makes this Microsoft's 27th filing we've tracked in our AI guardrails race since July, adding to work like fact-checking before summarizing and an AI-built answer key.
The trade here is clear: you spend extra time and computing power proving each rewrite, and in return you never have to trust the AI's word. That is a good bargain for databases, where one wrong number in a quarterly report can cost far more than a slow query.
The weak spot is coverage. The check only passes if the system can map every piece of the original code to something it understands, and a single ambiguous variable type makes it fail. Messy real-world code will fail often, and each failure means falling back to the slow original, so the speedup shows up only on the code the checker can handle.
Still, falling back safely is a sensible choice. The system gives up some speed on hard cases to keep every answer correct, and that is the right order of priorities for data people rely on.
Get our take in your Top Stories
Liked this breakdown? Add Patentlyze as a preferred source on Google, and our plain-English take shows up more often in your Top Stories the next time Microsoft patent news breaks.
There are more where this came from
We read every patent application Big Tech publishes and send you the ones worth knowing. Plain English, free, every week.
The drawings
4 drawing sheets from US 2026/0339938 A1 · click any drawing to enlarge
Want this weekly breakdown for a company we don't cover? Patentlyze Pro →
Be the first to weigh in