TysonLPrice
Programmer
I've been pointed to several links for here and this explanation:
This confuses me:
bwcclaimnum is a non-unique non clustered index on the claim table. Both selects seem to generate the same execution plan. Souldn't the first select be doing a table scan? I'll try and show the execution plan but I don't know how it will post:
First select:
Nested Loops
Index Seek
RID Lookup
Second select:
Nested Loops
Index Seek
RID Lookup
Regarding the other information needed to answer I don't know what is relevent. I'll try and post it if requested.
The only real difference I see is:
First select:
OBJECT[Manhattan].[dbo].[Claim].[BwcClaimNum]), SEEK[Manhattan].[dbo].[Claim].[BwcClaimNum] >= '9701301833þ' AND [Manhattan].[dbo].[Claim].[BwcClaimNum] < '9701301835'), WHERE[Manhattan].[dbo].[Claim].[BwcClaimNum] like '9701301834%') ORDERED FORWARD
Second select:
OBJECT[Manhattan].[dbo].[Claim].[BwcClaimNum]), SEEK[Manhattan].[dbo].[Claim].[BwcClaimNum]='9701301834') ORDERED FORWARD
Thanks!
Think of it this way. Suppose someone handed you a dictionary and told you to highlight (with a marker) all words that begin with 'tr'. What would you do? You would flip through the pages (very quickly) and find the first word that starts with TR. You would start highlighting them until you get to the first word that does NOT start with TR.
Now, imagine someone hands you a dictionary and says, highlight each word that contains TR. The only way to do this would be to start at the beginning and examine EVERY word. Obviously this would take a lot longer to accomplish.
By making the query sargable, it will use an existing index to identify the records faster, thus causing the entire operation to take less time. This ONLY works if there is an index.
For example, if someone hands you a 'normal' book and told you to highlight the words that start with TR, you would again have to examine every word. Again... this would take a long time to accomplish.
This confuses me:
Code:
Set SHOWPLAN_ALL On
go
select * from claim where bwcclaimnum like '9701301834%'
select * from claim where bwcclaimnum = '9701301834'
go
Set SHOWPLAN_ALL Off
bwcclaimnum is a non-unique non clustered index on the claim table. Both selects seem to generate the same execution plan. Souldn't the first select be doing a table scan? I'll try and show the execution plan but I don't know how it will post:
First select:
Nested Loops
Index Seek
RID Lookup
Second select:
Nested Loops
Index Seek
RID Lookup
Regarding the other information needed to answer I don't know what is relevent. I'll try and post it if requested.
The only real difference I see is:
First select:
OBJECT[Manhattan].[dbo].[Claim].[BwcClaimNum]), SEEK[Manhattan].[dbo].[Claim].[BwcClaimNum] >= '9701301833þ' AND [Manhattan].[dbo].[Claim].[BwcClaimNum] < '9701301835'), WHERE[Manhattan].[dbo].[Claim].[BwcClaimNum] like '9701301834%') ORDERED FORWARD
Second select:
OBJECT[Manhattan].[dbo].[Claim].[BwcClaimNum]), SEEK[Manhattan].[dbo].[Claim].[BwcClaimNum]='9701301834') ORDERED FORWARD
Thanks!