473,486 Members | 2,277 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Slow results with simple, well-indexed query


I'm struggling with speed issues on some queries that
I would have expected to be relatively fast. Perhaps
even more frustratingly, when I've tried to break
these down into their components, they still execute
very slowly. I've looked over all the relevant suggestions
for optimization and so forth, and there's nothing I can
tell that I'm missing.

An example of a query is to get all the words (the cg.cw
field) in a particular alphabetical range that have been
added in some timespan (the sref.cd field). The cg table
has about 3M rows, and the sref table about 70,000; the
intervening tables are all indexed on the relevant id
fields:

-----
mysql> SELECT cg.cw FROM cg,q,cit,sref
-> WHERE cg.q_id = q.id AND q.cit_id = cit.id AND cit.sref_id = sref.id
-> AND cg.cw BETWEEN 't' AND 'tzzz'
-> AND sref.cd > DATE_SUB(CURDATE(), INTERVAL 6 MONTH)
-> ORDER BY cg.cw
-> LIMIT 1000,10;
+---------------+
| cw |
+---------------+
| teeny-pop |
| teeter |
| teetery |
| teeth-grating |
| Teflon |
| teflon |
| teflon |
| teflon |
| teflubenzuron |
| Tejano |
+---------------+
10 rows in set (7.30 sec)
-----

That's just too slow; yet an EXPLAIN doesn't make things easy for
me to see what's wrong:

-----
mysql> EXPLAIN SELECT cg.cw FROM cg,q,cit,sref
-> WHERE cg.q_id = q.id AND q.cit_id = cit.id AND cit.sref_id = sref.id
-> AND cg.cw BETWEEN 't' AND 'tzzz'
-> AND sref.cd > DATE_SUB(CURDATE(), INTERVAL 6 MONTH)
-> ORDER BY cg.cw
-> LIMIT 1000,10\G
*************************** 1. row ***************************
table: cg
type: range
possible_keys: q_id,cw
key: cw
key_len: 26
ref: NULL
rows: 170982
Extra: Using where; Using filesort
*************************** 2. row ***************************
table: q
type: eq_ref
possible_keys: PRIMARY,cit_id
key: PRIMARY
key_len: 4
ref: cg.q_id
rows: 1
Extra:
*************************** 3. row ***************************
table: cit
type: eq_ref
possible_keys: PRIMARY,sref_id
key: PRIMARY
key_len: 4
ref: q.cit_id
rows: 1
Extra:
*************************** 4. row ***************************
table: sref
type: eq_ref
possible_keys: PRIMARY,cd
key: PRIMARY
key_len: 4
ref: cit.sref_id
rows: 1
Extra: Using where
4 rows in set (0.00 sec)
-----

Executing just the search on the word table, with no joins to the
table with the dates, is still slow:

-----
mysql> SELECT cw
-> FROM cg
-> WHERE cw BETWEEN 's' AND 'szzz'
-> ORDER BY cw
-> LIMIT 3000,5;
+---------------------+
| cw |
+---------------------+
| sacrifice hit |
| sacrifice play |
| sacrifice the earth |
| sacrifice throw |
| sacrifice to |
+---------------------+
5 rows in set (5.80 sec)
-----

and has a similar EXPLAIN:

-----
mysql> EXPLAIN SELECT cw FROM cg WHERE cw BETWEEN 's' AND 'szzz' ORDER BY cw LIMIT 3000,5\G
*************************** 1. row ***************************
table: cg
type: range
possible_keys: cw
key: cw
key_len: 26
ref: NULL
rows: 318244
Extra: Using where; Using filesort
1 row in set (0.00 sec)
-----

Of course cw is indexed. Is there anything I can to do improve queries of this
nature? There are more complicated queries from this database, but the big
slowdown always seems to be when one of the possibilities (e.g. all words
in 'S') is large; the other limitations don't improve things.

Thanks.

Jesse Sheidlower

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/my***********...ie.nctu.edu.tw

Jul 19 '05 #1
0 1903

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

Similar topics

9
3436
by: j askey | last post by:
I have a strange bandwidth issue that I have finally tracked down to something fairly specific if anyone has any ideas... Setup: Win2003 Server, PHP 4.3.4, IIS6.0, ISAPI Network: DSL line with...
16
2556
by: Jason | last post by:
Hey, I'm an experience programmer but new to Python. I'm doing a simple implementation of a field morphing techinique due to Beier and Neely (1992) and I have the simple case working in Python...
12
2613
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...
12
3643
by: Albert Grennock | last post by:
Hi, Hope this is the right forum to ask in. Anyway in IE I go to this site and I click on computing on the left hand menu and it takes from about 6 to 15 seconds to open the submenu. I then...
8
2865
by: Neil | last post by:
I have a very puzzling situation with a database. It's an Access 2000 mdb with a SQL 7 back end, with forms bound using ODBC linked tables. At our remote location (accessed via a T1 line) the time...
2
2804
by: Rocky A | last post by:
This is my first posting so please be gentle I've been writing access programs for only about a year and may have bit off more than I can chew but....... I've written an operations program for...
6
8557
by: B B | last post by:
Okay, here is what's happening: I have a reasonably fast laptop (1.4 GHz Mobile M, so comparable to 2.5GHz P4) doing .net development. Running Windows XP pro, SP2 IIS is installed and running...
13
3427
by: eighthman11 | last post by:
using Access 2003 and sql server version 8.0 Hey everyone. Created a text box where the user types in an Inventory number and it takes them to that inventory number on the contimuous form. The...
1
4895
by: ianwr | last post by:
Hi, I wondered in anyone can help with the following problem that i'm experiencing, i'll try to provide as much info as possible and any suggestions would be appreciated. I have just started...
2
3203
by: killy971 | last post by:
I have been testing different libraries to process XSL transformations on large XML files. The fact is that I read a document from Intel, stating their library (XSLT accelerator) was more twice...
0
7105
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7132
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,...
1
6846
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7341
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5439
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,...
0
4564
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3076
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
600
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
266
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.