On Sun, 30 Nov 2003 02:51:07 +0100, Matthias Braun <mat_braun@web.de>
wrote:[color=blue]
>
>I am using MySQL 4.1.0-alpha. Only one index is used for that query,
>but the index is a multi-column index, see also[/color]
I know about multi-colum indexes. I was basically just saying that
you need to use a multi-column index. You could not just create three
seperate single-field indexes and have mysql use them all on the same
query.
But I did mis-read your original posted query.
Lets see, it does:
select ... from table1 where col2=x
So you would need an index on table1.col2 by itself.
And it does
select max(col2) from table1 where table1.col1=table2.col1
and table1.col3=table2.col3
So you'd need an index on table1.col1+table1.col3 and
table2.col1+table2.col3
I am GUESSING that mysql would be able to use two different
indexes, since they really are seperate queries. I haven't played
with sub-selects much in mysql, so I'm not sure what the optimizer
will do. And in fact, the optimizer might not do a great job yet.
Chuck Gadd
http://www.csd.net/~cgadd/aqua