473,395 Members | 2,467 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,395 software developers and data experts.

similar queries, big difference

Can someone explain why there is such a big performance difference in these
two queries? Note: I have a multicolumn index on ltid and inuse.

mysql> UPDATE leads SET inuse='0' WHERE inuse!='0' and ltid='8' and
inuse<'1098298863';
Query OK, 0 rows affected (46.35 sec)
Rows matched: 0 Changed: 0 Warnings: 0

mysql> UPDATE leads SET inuse='0' WHERE inuse='1' and ltid='8' and
inuse<'1098298863';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0 Changed: 0 Warnings: 0

The one that tests by ='1' is almost instant, while the one that tests !='0'
takes 40 seconds! Is this just something strange, or is there some principle
that I am missing?

I just noticed that using "WHERE inuse>'0' " also is instanteous.

Thanks!!
Shane

Jul 20 '05 #1
1 1532
Shane Niebergall wrote:
The one that tests by ='1' is almost instant, while the one that tests !='0'
takes 40 seconds! Is this just something strange, or is there some principle
that I am missing? WHERE inuse!='0' and ltid='8' and inuse<'1098298863';


The guess I can come up with is that != creates two intervals, while =
and > create one interval. That is, one interval is from -inf to 0
(non-inclusive), and the other interval is from 0 to 1098298863
(non-inclusive).

Whereas if you use inuse=1, it only needs to do one interval. In the
case of using inuse=1, the other condition on inuse can be factored out,
since it is always true if the first condition is true, and irrelevant
(because of the AND) if the first condition is false.

I'm not knowledgeable enough to know why two intervals would cause such
a dramatic performance difference over one interval. This is just my
best guess.

There's a bunch of technical detail on the MySQL site about how range
conditions are optimized into intervals, so the optimizer can make the
most efficient pass through an index.

http://dev.mysql.com/doc/mysql/en/Ra...ngle-part.html

Regards,
Bill K.
Jul 20 '05 #2

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

Similar topics

8
by: Mike N. | last post by:
Hello: I am new to T-SQL programing, and relativly new to SQL statements in general, although I have a good understanding of database theory. I'm a little confused as to the fundamental...
3
by: Metal Dave | last post by:
Hi all, Currently our product has a setup that stores information about transactions in a transaction table. Additionally, certain transactions pertain to specific people, and extra information...
3
by: NeilAnderson | last post by:
I'm a fairly new user of access & I've never had any training, so I'm wondering if I'm doing the right thing here, or if it matter at all. I'm building a database for room booking purposes and I'm...
5
by: Megan | last post by:
Hi everybody- I'm helping a friend with a music database. She has an old one and is creating a new one. She wants to compare records and fields in the old database with records and fields in the...
1
by: Aaron | last post by:
Hello fellow programmers, I am trying to run an append/update query from code, a command button on a form initiates the queries. the format i am using is; ...
7
by: Zlatko Matić | last post by:
Let's assume that we have a database on some SQL server (let it be MS SQL Server) and that we want to execute some parameterized query as a pass.through query. How can we pass parameters to the...
2
by: CSN | last post by:
Is there much difference between using subqueries and separating out them into separate queries? __________________________________ Do you Yahoo!? Yahoo! SiteBuilder - Free web site building...
1
by: loosecannon_1 | last post by:
Hello everyone, I am hoping someone can help me with this problem. I will say up front that I am not a SQL Server DBA, I am a developer. I have an application that sends about 25 simultaneous...
5
by: marshmallowww | last post by:
I have an Access 2000 mde application which uses ADO and pass through queries to communicate with SQL Server 7, 2000 or 2005. Some of my customers, especially those with SQL Server 2005, have had...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.