Ricardo Acras
Ricardo Acras

Reputation: 36244

Understanding the execution plan of a query

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.

Upvotes: 1

Views: 2934

Answers (2)

Douglas Tosi
Douglas Tosi

Reputation: 2350

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

Upvotes: 0

Andrej Kirejeŭ
Andrej Kirejeŭ

Reputation: 5481

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.

Upvotes: 4

Related Questions