The indexes are the primary way of tuning your query speed but bear in mind that mysql can only use 1 index-per-table-per-query.. your single column indexes do help some.
try an EXPLAIN to see what I mean: EXPLAIN SELECT ... This will show you how mysql is approaching the query. From your query, figure which attributes you are selecting on and then create an index on them with the smallest cardinality (the one with the fewest distinct values) going first. if I have a table with FIRSTNAME, LASTNAME, CITY, GENDER and I am searching on all LASTNAME and GENDER, I would create an index on (LASTNAME,GENDER) rather than (GENDER, LASTNAME) because the earlier terms should narrow the search as much as possible. - michael On 8/14/07, Hugo Ferreira da Silva <[EMAIL PROTECTED]> wrote: > hum... I get it. > But in my query, I look in 3 tables > > FROM > > mensagens m, > mensagenspara mp, > usuarios u, > usuarios up > > WHERE > > m.codmensagem = mp.codmensagem > AND u.codusaurio = m.codusuario > AND up.codusuario = mp.codusuario > > m.codmensagem, u.codusaurio and up.codusuario are primary keys > mp.codusuario, m.codusuario and mp.codmensagem are indexes. > > I'm joining the usuario's table twice to get the name of who is sending and > who is receiving. > > I thought that creating indexes for the others columns will optimize the > results, because I'm using them in where clause. > > Do you know some way to turn the response time of this query faster? > -- - michael dykman - [EMAIL PROTECTED] - All models are wrong. Some models are useful. -- - michael dykman - [EMAIL PROTECTED] - All models are wrong. Some models are useful. -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]