Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results for sargable
Search options questions only not deleted
8 votes
1 answer
1k views

Sargable Queries

I'm a bit new to this, but my understanding of Sargable and Non-Sargable SQL is that the offending function is operating on the column and thus obstructing the index (assuming one is present) which leads …
sten's user avatar
  • 183
9 votes
1 answer
2k views

Is COALESCE sargable now?

One of my developers is arguing that COALESCE(column, default value) = default value is now sargable. Is that right? I ran the following test, and think it implies that COALESCE is non-sargable. …
Mitch's user avatar
  • 2,688
27 votes
5 answers
4k views

SARGable WHERE clause for two date columns

/*would be nice if it were sargable*/ WITH [x] AS ( SELECT * , DATEDIFF(DAY, [s].[DateCol1], [s]. … [ddif] >= 48; And of course, since we are not using constants, this code changes nothing, and is not even half SARGable. No fun. Same execution plan. …
Erik Reasonable Rates Darling's user avatar
43 votes
3 answers
23k views

What does the word "SARGable" really mean?

SQL Server users use the term "sargable". I'm wondering if there is an objective implementation-agnostic timeless definition for "sargable." … Other References What makes a SQL statement sargable? …
Evan Carroll's user avatar
  • 64.7k
1 vote
1 answer
348 views

When are ORs considered non-sargable predicates

I was wondering if I could get a further explanation on non-sargable predicates concerning the OR. … From my understanding, not all ORs fall into the category of non-sargable predicates. I just want to understand more when an OR is considered a non-sargable predicate and when it's not. …
McKade Thurgood's user avatar
0 votes
0 answers
43 views

SARGABLE predicate must be in DNF. Why?

A sargable predicate is one of the form (or which can be put into the form) "column comparison-operator value". … Why exactly does being in DNF qualify a predicate to be a SARGABLE? Do the authors mean the following? …
Arun S R's user avatar
  • 207
1 vote
1 answer
134 views

Is SARGable query the first thing to put in developers' minds?

Is SARGable query the first thing to put in developers' minds from a performance tuning perspective? … It's been a while that I work through this way, but I was just wondering if you guys have the same approach, considering Microsoft will not Make more functions SARGable. …
Danilo Braga's user avatar
  • 1,428
7 votes
1 answer
868 views

How can I make this query sargable?

As I understand it this is not sargable, so I'd like to do the reverse. (The timestamp table is much larger and efficiency is more of an issue). …
Mansfield's user avatar
  • 1,051
9 votes
3 answers
225 views

Can I do a sargable first letter match on two tables?

Is there any way to make this SARGable/run faster? I can't create columns on persons table, but I can create columns on persons2. …
lastchancexi's user avatar
63 votes
2 answers
11k views

Cast to date is sargable but is it a good idea?

Casting a datetime column to date is sargable and can use an index on the datetime column. …
Mikael Eriksson's user avatar
7 votes
4 answers
1k views

DATEADD not producing a SARGable expectation of an index seek

Initially I wrote the query using DATEDIFF, but immediately after writing and taking a peek at the execution plan, I remembered that it is not a SARGable function (along with the fact the precision levels … As you'll find on PasteThePlan for this query, it is performing an index scan as expected given that DATEDIFF is not SARGable. …
PicoDeGallo's user avatar
  • 1,574
17 votes
1 answer
973 views

When can SARGable predicates be pushed into a CTE or derived table?

( SELECT TOP 101 c.UserId, c.Text, c.Score FROM dbo.Comments AS c ORDER BY c.Score DESC ) SELECT * FROM x WHERE x.Score >= 500; The SARGable … Is there a reason that a SARGable predicate can be pushed in some scenarios and not in others? …
Erik Reasonable Rates Darling's user avatar
7 votes
1 answer
1k views

Order In WHERE Clause Matter For SARGability?

FROM MyTable WHERE IndexedColumn > 5000 AND OtherIndexedColumn = 2 Since the two columns have up to date indexes, SQL Server can make assumptions and find the values faster and both queries are SARGable … The reason that I'm asking is because I'm aware that I could use a subquery or CTE to do the first part of the SARGable filter, then of the 7 rows, look and see if each is not equal, but is the query optimizer …
user541852587's user avatar
2 votes
1 answer
96 views

How to properly create a Spatial index and write a SARGable query that leverages that Spatia...

The query appears like it should be SARGable, but I still get a clustered index scan, instead of a nonclustered index seek on the Spatial index: If I try to force the index hint, I get the classic error …
J.D.'s user avatar
  • 39.6k
4 votes
2 answers
300 views

Sargability of queries against a view with a case expression

The very definition of non-sargable. I am using this view to normalize legacy data so I can write a new application on top of it. I just want the case expression to run on output. … So here is my question: Is it possible to still have my ShipmentId output go through the case expression, but also have a sargable query when ShipmentId is used in the where clause? …
Vaccano's user avatar
  • 2,540

15 30 50 per page