x

Definition of SARGable

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

more ▼

asked Oct 09, 2009 at 02:49 PM in Default

Steve Jones - Editor gravatar image

Steve Jones - Editor ♦♦
5.1k 77 79 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, 2009 at 08:55 AM

Grant Fritchey gravatar image

Grant Fritchey ♦♦
98.1k 19 21 74

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, 2009 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, 2009 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, 2009 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.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

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

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x343
x127
x107
x2

asked: Oct 09, 2009 at 02:49 PM

Seen: 4155 times

Last Updated: Oct 15, 2009 at 05:53 AM