Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help With Indexing Question

1 view
Skip to first unread message

don....@gmail.com

unread,
Jul 26, 2006, 2:04:27 PM7/26/06
to
I'm trying to tune my tables a bit and have been running EXPLAIN on
some of my queries with the hope of creating some indexes that will
help.

I have the following sample tables:

EMPLOYEE
employee_id
first_name
last_name

INDEX on PRIMARY

TIMESHEET
timesheet_id
employee_id
hours

INDEX on PRIMARY
INDEX on employee_id name FKEY_EmpID

I want to run a query with a sub select to get all the hours for each
employee.

I have the following

SELECT t.hours, e.first_name, e.last_name
FROM timesheet t, employee e
WHERE t.employee_id in
(
SELECT employee_id FROM employee
)
AND t.employee_id = e.employee_id
GROUP BY t.employee_id

When I run explain on this, I get...

ID: 1
Select_Type: PRIMARY
table: t
type: ALL
possible_keys: FKEY_EmpID (what I named it)
key: <NULL>
key_len: <NULL>
rows: 126592
Extra: Using where; Using temporary; Using filesort


ID: 1
Select_Type: PRIMARY
table: e
type: eq_ref
possible_keys: PRIMARY
key: PRIMARY
key_len: 4
rows: 1
Extra: Using where;


ID: 2
Select_Type: DEPENDENT SUBQUERY
table: employee
type: unique_subquery
possible_keys: PRIMARY
key: PRIMARY
key_len: 4
rows: 1
Extra: Using index


I'm trying to not have it scan the full timesheet table. Is there
something simple I'm missing?

TIA,
Don

0 new messages