Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Like operator - Query performance issue Expand / Collapse
Author
Message
Posted Monday, March 31, 2014 12:12 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Sunday, April 27, 2014 7:55 PM
Points: 218, Visits: 556
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.
Post #1556336
Posted Monday, March 31, 2014 12:33 AM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Today @ 4:13 AM
Points: 747, Visits: 1,315
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.
Post #1556340
Posted Monday, March 31, 2014 1:05 AM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Friday, September 12, 2014 4:12 AM
Points: 416, Visits: 140
Partitions would be helpful.Then you could also restrict conditions in where clause
Post #1556351
Posted Monday, March 31, 2014 2:21 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Sunday, April 27, 2014 7:55 PM
Points: 218, Visits: 556
create full text index fro all the 15 columns?
Post #1556378
Posted Monday, March 31, 2014 2:22 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Sunday, April 27, 2014 7:55 PM
Points: 218, Visits: 556
sorry did not understand about partitionong
Post #1556379
Posted Monday, March 31, 2014 2:27 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 9:33 AM
Points: 43,026, Visits: 36,190
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 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1556380
Posted Monday, March 31, 2014 5:33 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Today @ 7:18 AM
Points: 15,737, Visits: 28,143
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
The Scary DBA
Author of: SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #1556427
Posted Monday, March 31, 2014 7:00 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Friday, September 12, 2014 9:43 AM
Points: 7,284, Visits: 13,824
As an aside, it seems odd that you are searching so many of those columns. Can you show us what the data looks like?

“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

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
Exploring Recursive CTEs by Example Dwain Camps
Post #1556449
Posted Monday, March 31, 2014 10:07 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 5:42 AM
Points: 37,099, Visits: 31,649
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
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1556570
Posted Monday, March 31, 2014 12:36 PM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 8:26 AM
Points: 1,975, Visits: 5,141
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.
Post #1556644
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse