SQL Server 2025 REGEXP_LIKE: When a Shiny New Function Turns an Index Seek Into a Scan
Measured on SQL Server 2025: REGEXP_LIKE turned the same 100 rows from 3 logical reads into 2,979. SARGable on paper is not a seek in practice. Test the reads.
SQL Server 2025 REGEXP_LIKE is the function teams reach for the moment a database hits compatibility level 170. Native regular expressions in T-SQL at last, and Microsoft documents anchored patterns as SARGable, which sounds like a promise: swap the LIKE for a regex, keep the index, expect the seek. A measured test published this month shows what actually happens. The same 100 rows, the same indexed column, the same rare value, and the logical reads went from 3 with LIKE to 2,979 with the anchored regex. Roughly a thousand times the work for the identical answer.
The row count never changes when you swap a predicate. Only the reads tell you what it costs, and this measurement shows why: the feature's promise, what one careful test found, why SARGable did not deliver the seek, and how to check a regex swap before it reaches production.
What the feature promises
REGEXP_LIKE shipped with SQL Server 2025 (17.x) and is also available in Azure SQL Database, Azure SQL Managed Instance and SQL database in Microsoft Fabric. On Managed Instance you need the SQL Server 2025 or Always-up-to-date update policy to get the regex functions. The function requires database compatibility level 170 or above; below that level it does not exist at all.
ALTER DATABASE CURRENT SET COMPATIBILITY_LEVEL = 170;
That makes a regex migration a compatibility-level migration too, and that deserves its own testing cycle. The syntax is not the problem. You pass in a string, a pattern and optional flags, and get a boolean back:
SELECT CustomerID, LastName FROM dbo.Customers WHERE REGEXP_LIKE(LastName, '^Smith');
The documentation is precise about which patterns can use an index. The pattern must begin with the anchor ^, and the anchored part may include simple quantifiers or character ranges such as [0-9A-Za-z]. Anything else, and the only plan available is a full scan.
That eligibility test looks easy to pass. Anchor the pattern, keep the index, move on. But the documentation describes permission to seek, not a commitment to one.
The test: a million rows and a rare surname
The sqlfingers test, published on 8 October 2026, set the trap up deliberately. One table, dbo.Customers, one million rows, a nonclustered index on LastName. Exactly 100 of the million rows start with Smith; the other 999,900 start with Acct. A rare value in a large table is the textbook case for an index seek.
The measurement is clean too. The query returns only CustomerID and LastName, and because CustomerID is the clustered key it rides along inside the nonclustered index, so the query is fully covered: no key lookups, nothing else to muddy the read count. With SET STATISTICS IO on and the actual plan captured, the baseline behaved exactly as every DBA would expect:
SET STATISTICS IO ON; SELECT CustomerID, LastName FROM dbo.Customers WHERE LastName LIKE 'Smith%';
Index Seek. Three logical reads to pull 100 rows out of a million. Then the same retrieval, expressed through the pattern the documentation calls SARGable:
SELECT CustomerID, LastName FROM dbo.Customers WHERE REGEXP_LIKE(LastName, '^Smith');
Index Scan. 2,979 logical reads for the same 100 rows.
| Predicate | Operator | Logical reads | | --- | --- | --- | | LIKE 'Smith%' | Index Seek | 3 | | REGEXP_LIKE with ^Smith | Index Scan | 2,979 |
Same result set, same index, same rare value. The anchored regex burned roughly 993 times the logical reads of the LIKE it was meant to replace. The test covers one case on one instance, and the author is careful to say it does not prove every anchored regex scans. What it does prove is that documented SARGability, on its own, does not produce an efficient plan.
SARGable means allowed, not applied
Why scan? SARGability is an eligibility rule: the pattern admits a seek. Choosing between seek and scan is still a cost decision, and cost rests on how many rows the optimiser believes it will match. Nothing in the pattern syntax forces that belief anywhere useful.
The product team's own words hint at how hard regex selectivity is to estimate. The reference page dedicates space to two query hints, ASSUME_FIXED_MIN_SELECTIVITY_FOR_REGEXP and ASSUME_FIXED_MAX_SELECTIVITY_FOR_REGEXP, which exist to adjust the default selectivity assumptions for regex predicates. Cardinality estimation feedback then applies them automatically when it spots a large gap between estimated and actual rows, and trace flag 16268 switches that automatic behaviour off on cases where you need to hold the plan steady.
Dedicated query hints for a problem are the product team admitting the problem is real. They still do not buy the seek. If the cost model does not credit it, eligibility is paperwork.
Where the regex functions earn their keep
None of this makes REGEXP_LIKE a mistake. LIKE cannot validate an email format, find three consecutive vowels, or pull a substring out of a messy reference column. The regex family can, and that is where to use it: validation through CHECK constraints, extraction and cleanup with REGEXP_SUBSTR and REGEXP_REPLACE, and genuine pattern matching with character classes and quantifiers. Where the alternative is a scan anyway, the regex adds no extra cost.
Keep the boundary sharp, though. Prefix search is what LIKE 'X%' has done with an index seek for two decades, and an anchored REGEXP_LIKE looks similar enough that a modernisation pass will happily rewrite it. The measurement says do not rewrite it until you have measured your own table and your own plan.
One correctness trap is worth flagging before any swap: regular expressions do not honour SQL collations. Matching follows the pattern and Unicode character properties rather than collation rules, so results can differ from LIKE on columns with language-specific collations. On an indexed key that is a correctness problem, not a performance one, and Microsoft says so plainly in its regular expressions overview.
Test before you trust, on your data
The procedure takes minutes, and it is the same one we apply to every promising syntax change:
- Baseline the current predicate with SET STATISTICS IO ON and SET STATISTICS TIME ON. Record logical reads, CPU and the plan shape.
- Swap the predicate and run both versions back to back. The row counts will match. Compare the reads.
- Read the actual plan, not the estimated one. Seek or scan, and estimated rows against actual rows.
- Run it on data shaped like production. Distribution decides everything here: 100 matches in a million rows is the entire reason the seek exists, and an evenly distributed dev copy will not reproduce the decision.
- If the reads explode and the pattern is a prefix match, keep LIKE. If the pattern is genuinely complex, accept the scan knowingly and size the workload for it.
- Watch the release in Query Store. If plan shape flips after the change goes live, you want it on a dashboard, not inside a support ticket.
Regex is not intrinsically slow, and this test does not claim it is. It shows that you only find out by watching the reads on your own data, and watching costs two lines of T-SQL.
The 2025 modernisation trap
Predicate eligibility is the newest way to meet an old truth: the plan you assumed is not the plan you get. Parameter sniffing plays the trick with reused plans. Implicit conversions play it with data types. Now REGEXP_LIKE plays it with documented SARGability that, on this evidence, refuses to seek. The defence is identical every time: measure first, on production-shaped data, and treat every new construct as unproven until your reads and plans say otherwise.
If SQL Server 2025 is on your roadmap and the regex functions are part of the appeal, add a predicate audit to the upgrade plan. Walking each swapped predicate with SET STATISTICS IO and an actual plan takes an afternoon, and it is a far cheaper afternoon than discovering a thousand-fold read amplification under month-end load. That discipline is exactly what our SQL Server performance tuning services put in place for estates that cannot afford a slow surprise. For the wider reading, our parameter sniffing guide covers plans that change shape for reasons the syntax will never show you, and these eight index changes cover the fixes that usually pay back fastest.
Whatever the release notes promise, the reads on your own data are the only verdict that counts.
Need Expert SQL Help?
Our SQL optimization experts are ready to help you implement these strategies and optimize your database performance.
Schedule Free Consultation