473,796 Members | 2,737 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Used EXPLAIN, have indexes - query still surprisingly slow

I have the following query that takes anywhere from 1 to 3 seconds
to run. I would expect it to run in less than 1/2 a second (and
I really need it to do so). I've added the appropriate indices
and tried EXPLAIN and ANALYZE; but, I'm not getting anywhere.

SELECT message.id
FROM message, message_thread
WHERE message.id = message_thread. message_id
AND message_thread. thread_id = SOME_CONSTANT_N UMBER

where SOME_CONSTANT_N UMBER is an integer literal, like 16400 (and no,
I'm not putting quotes around the number).

Here are the two tables involved:

message table
------------------------------------------------------------------
Field Type NULL Key Default Extra
------------------------------------------------------------------
id int(11) PRI NULL auto_increment
msgtype_id int(11) MUL NULL
content blob YES
precedence varchar(255) YES
message_thread table
------------------------------------------------------------------
Field Type NULL Key Default Extra
------------------------------------------------------------------
id int(11) PRI NULL auto_increment
message_id int(11) MUL -1
thread_id int(11) MUL -1
contact varchar(255) YES

The message table has 1,117,213 records and the
message_thread table has 2,563,893 records. At most, each query
will return 200 records.

Here is the output of the explain function (turned sideways):

---------------------------------------------------------------
table : message_thread message
---------------------------------------------------------------
type : ref eq_ref
---------------------------------------------------------------
possible_keys : thread_id, PRIMARY
message_id
---------------------------------------------------------------
key : thread_id PRIMARY
---------------------------------------------------------------
key_len : 4 4
---------------------------------------------------------------
ref : const message_thread. message_index
---------------------------------------------------------------
rows : 200 1
---------------------------------------------------------------
Extra : Using where Using index
---------------------------------------------------------------
This is running on a 2.2 GHz Pentium 4, NTFS File system,
MS Windows 2000, MySQL 4.0.18. Each table is an InnoDB type.

I've tried a combined thread_id/message_id index in the message_thread
table; but, that did not seem to help at all.

Any help would be appreciated.
Jul 20 '05 #1
0 1080

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

Similar topics

6
14679
by: Christian | last post by:
HI, I have a function that is used to constrain a query: Select COl1, Col2 From MyTable WHERE col1 = ... AND col2 = ... And MyFunction(col1) = ... My problem is that MyFunction is executed as many times that there are
0
1808
by: Jacob Larsen | last post by:
We can get a slow query log with log-long-format and even a summarized version with mysqldumpslow. But why don't we have a script that can parse the slow query log and produce sql statements that will create the missing indexes in the MySQL database tables? If someone already have this script, I'm interested. If not, let's create it. I'd be happy to give it a try. What say you?
3
2026
by: Mark Harrison | last post by:
I have indexed two columns in a table. Can somebody explain to me why the first query below uses an Index Scan while the second uses a Seq Scan? Many TIA! Mark planb=# \d abcs Table "public.abcs"
5
3323
by: radhika | last post by:
ENVIRONMENT: DB2 OS/390 V6 Peoplesoft v8 I have a strange situation: I have a table called TABLEA and it has indexes Ind1 Ind2 Ind3
1
1458
by: Waldo Nell | last post by:
Hi, I have a *huge* problem. I have a table with indexes on but the moment I have an OR in my SELECT query it seems to not use the appropriate index. oasis=> \d purchases Table "public.purchases" Column | Type | Modifiers
6
1644
by: Dan Pelleg | last post by:
I'm trying to access a table with about 120M rows. It's a vertical version of a table with 360 or so columns. The new columns are: original item col, original item row, and the value. I created an index: CREATE INDEX idx on table (col, row) however, selects are still very slow. It seems it still needs a sequential scan:
1
1342
by: pootlecat | last post by:
Hello everyone, I have a fair sized table now (1,955,041 rows) and it currently has two indexes: PRIMARY is the ID number and Keywords is a FULLTEXT index of the Keywords column (Text). +----------------------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------------------+------------------+------+-----+---------+----------------+
22
1779
by: Zamdrist | last post by:
I am tasked with maintaining a large database still on SQL Server 7.0. Performance is an issue not surprisingly and I've targeted two rather large tables to see what I can do with the indexes. The 2 tables are described as follows: MatterConflicts: Fields: MatterConflicts varchar(16), Matters varchar(16), HitMatters varchar(16), IsInclude varchar(1) Index: MatterConflicts
3
4595
by: skaushik | last post by:
Hi all, I ran an explain plan for a sql query which has some bind variables used in it. The plan shows that index is being used but the execution takes a very long time. Also, in another query the use of bind variables totally discards the usage of indexes and the explain plan also does not show the use of indexes. Any idea how the optimizer behaves when using bind variables? It would be great if someone can help me out in making sure...
0
9535
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10200
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10021
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9061
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7558
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5453
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4127
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2931
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.