Click here to get back home

Simple MySQL Index

 HomeNewsGroups | Search | About
 mailing.database.mysql    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Simple MySQL Index McMurphy 06-28-2007
Posted by McMurphy on June 28, 2007, 11:59 pm
Please log in for more thread options
I have a single table which I would like to search on a unique column
varchar(15) that may have some nulls. Employee social club member no,
some employees have a number and others don't. Those that do have a number
will all have a unique number.

I had added an index using:
ALTER TABLE employees ADD INDEX(emp_socialclubno);

However when I run:
mysql> explain select employeeid from employees where
emp_socialclubno=103833988;
+----+-------------+------------+------+---------------+------+---------+------+--------+-------------+
| id | select_type | table | type | possible_keys | key | key_len |
ref | rows | Extra |
+----+-------------+------------+------+---------------+------+---------+------+--------+-------------+
| 1 | SIMPLE | properties | ALL | emp_socialclubno | NULL | NULL |
NULL | 170361 | Using where |
+----+-------------+------------+------+---------------+------+---------+------+--------+-------------+
1 row in set (0.00 sec)

So this indicates that even though the emp_socialclubno column has an index
it is not being used when this column is searched ?

Is this right or am I missing something ?

Thanks in advance...

Posted by lark on July 5, 2007, 9:50 am
Please log in for more thread options
McMurphy wrote:
> I have a single table which I would like to search on a unique column
> varchar(15) that may have some nulls. Employee social club member no,
> some employees have a number and others don't. Those that do have a number
> will all have a unique number.
>
> I had added an index using:
> ALTER TABLE employees ADD INDEX(emp_socialclubno);
>
> However when I run:
> mysql> explain select employeeid from employees where
> emp_socialclubno=103833988;
>
+----+-------------+------------+------+---------------+------+---------+------+--------+-------------+
> | id | select_type | table | type | possible_keys | key | key_len |
> ref | rows | Extra |
>
+----+-------------+------------+------+---------------+------+---------+------+--------+-------------+
> | 1 | SIMPLE | properties | ALL | emp_socialclubno | NULL | NULL |
> NULL | 170361 | Using where |
>
+----+-------------+------------+------+---------------+------+---------+------+--------+-------------+
> 1 row in set (0.00 sec)
>
> So this indicates that even though the emp_socialclubno column has an index
> it is not being used when this column is searched ?
>
> Is this right or am I missing something ?
>
> Thanks in advance...


looks like your query is for table employees but the explain is run on
properties. these are two different tables!!!

Similar ThreadsPosted
Full text index before or after non-clustered index December 20, 2006, 7:26 am
Simple MySQL Search from MySQL beginner June 27, 2006, 6:51 am
Index's in MySQL - Multiple index warning from PHPMyAdmin - please help. July 6, 2005, 4:37 pm
PLEASE HELP FOR SIMPLE QUERY!!! January 24, 2006, 12:21 pm
A simple thing! January 30, 2006, 6:25 pm
Having problem with simple "NOT IN" query August 20, 2005, 8:40 am
This is a reall simple SQL question January 24, 2006, 1:01 pm
Cant get my mind around this simple query May 29, 2006, 5:00 pm
Maybe simple - group by / having restriction - but then show all results. March 15, 2006, 7:48 pm
Which index to hit first? November 30, 2005, 3:36 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap