on 2009 Nov 27 4:43 PM
I just tried a simple exclusion query of the form
select * from T1 where C1 not in (select C2 from T2)
where C1 is a varchar column.
That works very fast if C1 and C2 are both varchar types.
It runs horrible slow when C1 is a nvarchar type and C2 is not.
It runs fast again when C1 is explicetely casted as in
select * from T1 where cast(C1 as varchar) not in (select C2 from T2)
Is this kind of implicit string conversion between varchar and nvarchar an exclusion for a "sargable" predicate?
(I'm not dealing with this particular case, just asking if this is a general rule of thumb: To cast any search predicate when using IN expressions and the like?)
I'm running SA 11.0.1.2331.
Request clarification before answering.
The short answer is yes.
To ensure safety in doing comparison operations, SQL Anywhere must in many cases avoid using an index for value lookups if the domain of the lookup value is not identical to the domain of the indexed column.
There is a whitepaper that explains this in detail for all other data types (since the paper was written for Vrsion 9, it contains nothing about CHAR - NCHAR comparisons.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
75 | |
30 | |
9 | |
8 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.