I have a database with 9551011 rows. It contains addresses from all over the country.
When I make a query for a certain place, and that address exists in the database, I get a return in a maximum of 2 seconds. The problem is that this bank is used in an application where the person has to upload a file with multiple addresses, and many of these addresses do not exist in the bank. When an address does not exist, it takes a LOT in that search ... Is there any way to improve this? I have tried with some classic performance forms in the Postgresql world like the Vacuum, for example. But I have not been successful so far.
Columns in the table: id
, gid
, nome
, num_inicio_esquerda
, num_fim_esquerda
, num_inicio_direita
, num_fim_direita
, cep_esquerda
, cep_direita
, bairro_esquerda
, bairro_direita
, nivel_detalhamento
, estado_nome
, estado_sigla
, cidade
, latitude_inicio
, latitude_fim
, longitude_inicio
.
- Index in column name.
Is it possible to make the bank not delay to give the answer when a record is not found?
Example of a query in the address table:
select
gid,
bairro_esquerda,
cep_direita,
cep_esquerda,
cidade,
estado_nome,
estado_sigla,
latitude_fim,
latitude_inicio,
longitude_fim,
longitude_inicio,
nivel_detalhamento,
nome,
num_fim_direita,
num_fim_esquerda,
num_inicio_direita,
num_inicio_esquerda
from
enderecos
where
nome like 'avenida treze de maio'
and (
estado_sigla like 'CE'
)
and (
lower(unaccent(cidade))='fortaleza'
)
and (
cast(num_inicio_esquerda as integer)<=1116
and cast(num_fim_esquerda as integer)>=1116
or cast(num_fim_esquerda as integer)<=1116
and cast(num_inicio_esquerda as integer)>=1116
or cast(num_inicio_direita as integer)<=1116
and cast(num_fim_direita as integer)>=1116
or cast(num_fim_direita as integer)<=1116
and cast(num_inicio_direita as integer)>=1116
) limit 1