March 31, 2014 at 12:12 am
Dear All
Have a table with 15 million rows. And Almost 15 columns. I am using following query. which is very slow. This table is having cluster index
select top 100
from TABLE
where COLUMN1 like '%xxx%'
OR Column2 like '%xxx%'
.
.
.
OR Column12 like '%xxx%'
Is there a better way to get the same result.
March 31, 2014 at 12:33 am
The % at the start means your search needs to read every row and look for a match. If you really need that kind of search you should look into using a full text index.
There is also a bug related with LIKE Statement. you can look to that as well.
http://support.microsoft.com/kb/2847467
Hope it helps.
March 31, 2014 at 1:05 am
Partitions would be helpful.Then you could also restrict conditions in where clause
March 31, 2014 at 2:21 am
create full text index fro all the 15 columns?
March 31, 2014 at 2:22 am
sorry did not understand about partitionong
March 31, 2014 at 2:27 am
Partitioning is unlikely to help at all.
Unless you can add some SARGable predicates (predicates where SQL can use indexes to reduce the rows it has to read), there's probably not much that can be done. LIKE with a leading wildcard requires SQL to read every row, so that query will read every row of the table.
Full text may or may not help. Try it out and see.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
March 31, 2014 at 5:33 am
Partitioning is not primarily a performance tuning mechanism. It is primarily a data management mechanism. There are cases where you can get performance improvements, but you need to remember that it's not designed to do that. It's designed to help with large scale data management.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
March 31, 2014 at 7:00 am
As an aside, it seems odd that you are searching so many of those columns. Can you show us what the data looks like?
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
March 31, 2014 at 10:07 am
gsaini 95591 (3/31/2014)
Partitions would be helpful.Then you could also restrict conditions in where clause
We're talking about a leading wildcard in 12 different columns. As the others have suggested, parititioning wouldn't help that at all.
--Jeff Moden
Change is inevitable... Change for the better is not.
March 31, 2014 at 12:36 pm
Krishna1 (3/31/2014)
create full text index fro all the 15 columns?
Sounds like a good option, have used this in similar situations before with good results.
April 2, 2014 at 12:59 am
Dear All
Thanks for your replies. I created full text index but when see the execution plan it does not show the full text index but shows cluster index.
And the query is still slow.
Regards
Krishna
April 2, 2014 at 3:38 am
You have to change your code to use the full text index. It's not like a regular index where the optimizer just picks it up. You need to read up on this. Here's an introduction.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply