SearchSearch   

Simple MySQL Index

 
   Webmaster Forums (Home) -> MySQL RSS
Next:  mysqldump select query  
Author Message
McMurphy

External


Since: Jun 29, 2007
Posts: 1



(Msg. 1) Posted: Fri Jun 29, 2007 3:59 am
Post subject: Simple MySQL Index
Archived from groups: mailing>database>mysql (more info?)

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...
Back to top
lark

External


Since: May 07, 2007
Posts: 17



(Msg. 2) Posted: Thu Jul 05, 2007 1:50 pm
Post subject: Re: Simple MySQL Index
Archived from groups: per prev. post (more info?)

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!!!
Back to top
Display posts from previous:   
       Webmaster Forums (Home) -> MySQL
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum