views:

80

answers:

2

I have this SQL:

SELECT
  *
FROM
  Requisicao r
  join convenio c on c.idconvenio = r.idconvenio
  join empresa e on e.idempresa = c.idempresa

When I execute it I get this plan of execution:

PLAN JOIN (C NATURAL,E INDEX (INTEG_160),R INDEX (INTEG_318))

What means that Convenio's index was not used (every table has its indexes)

I would like to understand it a little better so I can improve some performance issues I'm having with this system.

Thanks.

+3  A: 

What seems wrong for you? Because you don't have any conditions (WHERE clause) server will read one table naturally, i.e. from the very first row to the last one. Taking into consideration index's selectivity served decided that it would be better to read from c and to join records from e and r.

Andrei K.
A: 

I agree with Andrei. If convenio.idconvenio has low selectivity, the plan is fine.

Douglas Tosi