Lets say I have two tables in a database:
user:
---------------
| name | id |
|-------|-----|
| foo | 1 |
| bar | 2 |
---------------
comments:
------------------
| comment | id |
|-----------------|
| comment 1 | 1 |
| comment 2 | 1 |
| comment 3 | 1 |
| comment 4 | 1 |
| comment 5 | 1 |
| comment 1 | 2 |
------------------
Lets says I want to pull up all comments made by foo
so my query will be
SELECT c.comment from comments c, user u WHERE u.name='foo' and c.id = u.id
will the above query do a FULL table scan on comments table to get comments made by user foo
or is there a better query to optimize this and avoid a full table lookup ? Should I create index for these tables ?
Aucun commentaire:
Enregistrer un commentaire