Connecting Tech Pros Worldwide Help | Site Map

Simple MySQL Index

  #1  
Old June 29th, 2007, 05:05 AM
McMurphy
Guest
 
Posts: n/a
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:
mysqlexplain 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...
  #2  
Old July 5th, 2007, 02:55 PM
lark
Guest
 
Posts: n/a

re: Simple MySQL Index


McMurphy wrote:
Quote:
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:
mysqlexplain 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!!!
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Wed Development - Dynamically Generated News Index infidel02@lycos.com answers 7 December 21st, 2005 01:15 AM
Glitch in php or count() in mysql? Schraalhans Keukenmeester answers 7 October 24th, 2005 04:05 AM
MySQL not using index Boo answers 5 July 23rd, 2005 08:03 AM
oracle - mysql comparison jonathan answers 133 July 20th, 2005 01:20 AM