473,386 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Slow select on sql 2000 with like '%value'

Hello.

I test some query on sql server 2000 (sp2 on OS windows 2000) and i
want to know why a simple query like this :
select * from Table Where Column like '%value'
is more slow on 2000 than on sql 7.

And this case arrive only if the % character is in the begin.
If you test this :
select * from Table Where Column like 'v%alue'
then it's more fast on 2000.

I look the execution plan, there is a difference but this difference
is the same in all the case i test (for the two query i write in this
message for example).

I don't understand why and so, if someone have an explanation, and
perhaps a solution ...

Excuse my poor english language.
And thanks for time people spend to answer me.
Jul 20 '05 #1
2 9227

"Benoit Le Goff" <be***@caramail.com> wrote in message
news:b4**************************@posting.google.c om...
Hello.

I test some query on sql server 2000 (sp2 on OS windows 2000) and i
want to know why a simple query like this :
select * from Table Where Column like '%value'
is more slow on 2000 than on sql 7.

And this case arrive only if the % character is in the begin.
If you test this :
select * from Table Where Column like 'v%alue'
then it's more fast on 2000.

I look the execution plan, there is a difference but this difference
is the same in all the case i test (for the two query i write in this
message for example).

I don't understand why and so, if someone have an explanation, and
perhaps a solution ...

Excuse my poor english language.
And thanks for time people spend to answer me.


I don't know why you're seeing a performance difference between SQL7 and
SQL2000, but a query like "select * from Table Where Column like '%value'"
will often be slow. This is because you're looking for a match at the end of
the column value, so an index can't be used. On the other hand, with the
query "select * from Table Where Column like 'v%alue'", SQL Server could use
a suitable index to examine only rows where the string starts with 'v'.

Simon
Jul 20 '05 #2
Benoit Le Goff (be***@caramail.com) writes:
I test some query on sql server 2000 (sp2 on OS windows 2000) and i
want to know why a simple query like this :
select * from Table Where Column like '%value'
is more slow on 2000 than on sql 7.

And this case arrive only if the % character is in the begin.
If you test this :
select * from Table Where Column like 'v%alue'
then it's more fast on 2000.

I look the execution plan, there is a difference but this difference
is the same in all the case i test (for the two query i write in this
message for example).


I can't really say why the query is slower on SQL2000 than on SQL7, but
it could be that you have more data on SQL 2000, or that the table is
very fragmented. You could run DBCC DBREINDEX on the table, and see what
effect it has.

The expression LIKE '%value' is likely to be slow, because if there is
an index on the column, SQL Server can not search it, because the
matching values could be anywhere in the index. So the normal thing for
SQL Server to do would be to scan the table. Which is why you can suffer
from fragmentation.
--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: M Wells | last post by:
Hi All, I have a table that currently contains approx. 8 million records. I'm running a SELECT query against this table that in some circumstances is either very quick (ie results returned in...
6
by: pragile | last post by:
I have a stored procedure that has some problems with slow performance. The procedure has 2 parameters @firstname varchar(100) @lastname varchar(100) These parameters can have values like a%,...
12
by: Neil | last post by:
I previously posted re. this, but thought I'd try again with a summary of facts. I have an Access 2000 MDB with a SQL Server 7 back end. There is a view that is linked to the database via ODBC...
5
by: Kurt Bauer | last post by:
I have an ASP group calendar application which pulls calendar data from Exchange via webdav into an XML string. I then loop the XML nodes to populate a collection of appointments. Finally I use...
4
by: sherkozmo | last post by:
SQL2000 - AccessXP I built an adp file with a stored procedure from SQL as follows: SELECT * FROM Z_mis_sjk_job_code_access WHERE job_code=@JobCode UNION ALL SELECT * FROM...
11
by: nico | last post by:
Hello I have write this program that retrieve all directory and subdirectory recursively of a given directory given in parameter. For each directory, the script find all user permission for the...
19
by: jimatqsi | last post by:
I'm using Access 2000 (and also 2003 with same result) in a Windows XP Professional environment on a peer-to-peer network. Files in this system are relatively small. There are about 1,200 rows in the...
29
by: wizofaus | last post by:
I previously posted about a problem where it seemed that changing the case of the word "BY" in a SELECT query was causing it to run much much faster. Now I've hit the same thing again, where...
7
by: Peter Nurse | last post by:
Two (almost) identical SQL Server databases (DB1 backed up and restored to DB2 yesterday). DB2.dbo.GetSchPaymentsTD took 1.5 seconds (!) to execute DB1.dbo.GetSchPaymentsTD took less than a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.