-2
I have a database that has about 3 teras and I’m having problems optimizing some querys.
In this example I have 3 tables: Automaker, Car and model.
And I have this query that takes about 30m, all joins are indexed and the query was made going from the smallest table to the largest, the options that are white to 'ZZZ' are filters that the user can do in the query so I can not change them
Any hint of something that might be wrong or another way to make a query.
Select * from Montadora m
INNER JOIN Carro c
on c.codMontadora = m.codigo
and c.pais between ' ' AND 'ZZZZZ'
and c.estado between ' ' AND 'ZZZZZ'
INNER JOIN Modelo o
on o.codMontadora = c.codMontadora
and o.pais = c.pais
and o.estado = c.estado
and o.versao between ' ' AND 'ZZZZZ'
and o.cor between ' ' AND 'ZZZZZ'
and o.motor between ' ' AND 'ZZZZZ'
where
m.codigo = 'GM'
Why put selection criteria in the join condition? It would not be better to merge and then apply the selection criteria or even, if the conditions imply a substantial reduction in the number of records, make a subselect applying the selection criteria and use the result in the join?
– anonimo
Could page this by placing a limit on select.
– Mateus Ferrando
if you put a
EXPLAIN
before select you can analyze where the bottleneck is.– fernandosavio