If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Why tb1.Name=tb2.Name does not use index on Name

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-04-08, 10:24
cy163 cy163 is offline
Registered User
 
Join Date: Apr 2007
Posts: 127
Why tb1.Name=tb2.Name does not use index on Name

Hello ALL,

I did the following query. the EXPLAIN result showed 'NULL' in the 'key' colume, meaning that NONE of indexes have been used. However, indexes have been created on Name fields for both tb1 and tb2. I wonder why MySQL does not use the indexes to speed up the query. Is there any way to make the query faster?

Code:
EXPLAIN SELECT
         tb1.Name
FROM
         tb1, tb2
WHERE
         tb1.Name = tb2.Name;
Reply With Quote
  #2 (permalink)  
Old 11-04-08, 10:48
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
  • It would help if you gave the SQL you used to create both tables. You can use the command show create table tb1.
  • How many records in both tables?
  • How long does the query take at the moment?
  • Can you show the output of your explain command?
  • Have you ever considered giving proper names to your tables?
Reply With Quote
  #3 (permalink)  
Old 11-05-08, 11:43
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
I'll make a guess then :-
assuming that your indexes are correct then the normal reason for the optimiser to decide not to use the indexes is simply because the amount of data in the tables is so small that it's not worth the effort of downloading the index pages when it might as well just download the main data pages directly. This would be quite normal behaviour.

Last edited by mike_bike_kite; 11-05-08 at 11:53.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On