1
I have a database with 9551011 lines. It contains addresses from all over the country.
When I make an appointment for a certain place, and that address exists in the bank, I can get a return within two seconds. The problem is that this database is used in an application where one has to upload a file with multiple addresses, and many of these addresses do not exist in the database. When an address does not exist, it takes TOO LONG in that search... Is there any way to improve it? I’ve tried it with some classic forms of performance in the Postgresql world like Vacuum, for example. But I haven’t 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
, longitude_fim
.
- Index in column name.
It is possible to make the bank not slow to give the answer when no record is found?
Example of a query performed 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
It is possible, but only knowing the problem in detail to help. Usually the solution is to create index. http://answall.com/q/35088/101, http://answall.com/q/32052/101 and http://answall.com/q/55118/101
– Maniero
@Naldson Chagas: It depends a lot on the query you are running in the database. You could post some example ?
– Lacobus
Guys, I got a significant improvement by adding index in three more columns (name, city, state). @Lacobus: I will post an example of a query.
– Naldson