I have a database that has about 3 teras and I'm having trouble optimizing some querys.
In this example I have 3 tables: Assembler, Car and model.
And I have this query that takes about 30m, all the inner 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 query so I can not change them
Any hint of something that may 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'