MySQL Forums
Forum List  »  InnoDB

Indexing optimisation
Posted by: Julien B
Date: September 04, 2008 04:44AM

Hello

I have a table that contains thoses fields:

CREATE TABLE `test` (
`id_p` int(10) unsigned NOT NULL,
`id_s` int(10) unsigned default NULL,
`typ` enum('a','b') NOT NULL,
KEY `test_FKIndex1` (`id_s`),
KEY `test` (`id_p`),
KEY `index_test_1` (`typ`,`id_p`,`id_s`),
KEY `index_test_2` (`typ`,`id_p`),
CONSTRAINT `test_ibfk_1` FOREIGN KEY (`id_s`) REFERENCES `table_s` (`id_s`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `test_ibfk_2` FOREIGN KEY (`id_p`) REFERENCES `table_p` (`id_p`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1

when i am doing this query:

select count(*) from test where id_p=<something> and typ=<something>

mysql does not look at index_test_2 index. (i saw it with the explain function).
If i force index_test_2 index with "use index(...)" syntax, it gives me the same row results in explain command.
It seems to be that mysql do not want to look at index_test_2 index.
Can someone explain me why ?

Is it beacuse i have 50% records with typ="a" and 50% with typ="b" ?

Thanks

Julien

Options: ReplyQuote


Subject
Views
Written By
Posted
Indexing optimisation
2664
September 04, 2008 04:44AM
1617
September 04, 2008 09:42AM
1670
September 05, 2008 12:18AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.