database performance - SQL Server: Why is SELECT on case insensitive column faster than on case sensitive? -
i use sql server 2016 express , java application jdbc driver version 4.2.
my database has collation of latin1_general_ci_as (case insensitive). table has column of type varchar(128) not null. there unique index on column.
my test scenario follows:
after inserting 150000 strings of 48 characters length 200 selects of randomly chosen, existing strings. measure total execution time of queries.
then drop index, alter table change columns collation latin1_general_cs_as (case sensitive) , create unique index again.
then 200 selects take in total more time.
in both cases (ci , cs) execution plans simple , identical (search using index).
the query execution time not depends on case sensitivity. collation cs grows faster if strings have identical prefixes. here results (execution time in seconds):
+----+---------+------------------+-------------------+-------------------+ | + rnd(48) + const(3)+rnd(45) + const(10)+rnd(38) + const(20)+rnd(28) + +----+---------+------------------+-------------------+-------------------+ | ci + 6 + 6 + 7 + 9 + | cs + 10 + 20 + 45 + 78 + +----+---------+------------------+-------------------+-------------------+ the longer identical prefix of random strings more time case sensitive queries take.
- why search on case insensitive column faster on case sensitive column?
- what reason identical prefix behavior?
Comments
Post a Comment