x
login about faq Site discussion (meta-askssc)

Definition of SARGable

What does SARGable mean? I see this posted in forums.

more ▼

asked Oct 09 '09 at 02:49 PM in Default

Steve Jones - Editor gravatar image

Steve Jones - Editor ♦♦
5.1k 74 78 82

(comments are locked)
10|1200 characters needed characters left

2 answers: sort voted first

I've read the article on Wikipedia before. I don't think it's entirely accurate. What does the use of a covering index have to do with SARGable?

Anyway, it's a measure of whether or not the query can use an index. Specifically, whether or not predicates in WHERE clauses and JOIN clauses will prevent the use of an index. There are operators that are SARGable and ones that are not. SARGable operations would include =,>,<, BETWEEN, and some LIKE conditions. Non-SARGable operations would include <>,!=,NOT IN, OR, other LIKE conditions.

The use of a function on a column can render the query Non-SARGable as well.

more ▼

answered Oct 10 '09 at 08:55 AM

Grant Fritchey gravatar image

Grant Fritchey ♦♦
64.9k 13 20 66

Can I ask where the != operator not being SARGable comes from? If I have two queries reading a table by it's clustered index using = or !=, the plans show as equivalent for me...

Oct 10 '09 at 11:00 AM Matt Whitfield ♦♦

I believe the issue of != comes from the optimizer not using an index when it was included. This was the behavior for years, so every query with a != caused a scan. Regardless of logic, if it doesn't get the optimizer to use an index, then it isn't SARG-able.

Oct 12 '09 at 10:52 AM Steve Jones - Editor ♦♦
(comments are locked)
10|1200 characters needed characters left

According to Wikipedia:

In relational databases, a condition (or predicate) in a query is said to be sargable if the DBMS engine can take advantage of an index to speed up the execution of the query (using index seeks, not covering indexes). The term is derived from a contraction of Search ARGument Able.

more ▼

answered Oct 09 '09 at 03:51 PM

Ben Adderson gravatar image

Ben Adderson ♦♦
361 5 7 8

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x275
x114
x107
x2

asked: Oct 09 '09 at 02:49 PM

Seen: 3148 times

Last Updated: Oct 15 '09 at 05:53 AM

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.