I downloaded an IBGE xml file with data from states, cities, municipalities and districts. I made the split for 4 tables and made their relationships.
My question is:
- Is this relationship right?
- Can you still improve using MySQL?
I made a view to make the data search with the query displayed more practical.
- Does this query improve or is it already good?
- And when I put a
order by nome_estado, nome_cidade, nome_municipio, nome_distrito
, with the data I have (a total of 10302) this query changes from 0.006s (a mean) to 0.356s (tbm a mean), this because of the order by. Can you improve this sort order?
Follow the query itself:
select e.id as estado_id, e.nome as nome_estado,
c.id as cidade_id, c.nome as nome_cidade,
m.id as municipio_id, m.nome as nome_municipio,
d.id as distrito_id, d.nome as nome_distrito
from distrito d
join municipio m ON m.id = d.municipio_id
join cidade c ON c.id = m.cidade_id
join estado e ON e.id = c.estado_id