Bom, eu criei os indíces aqui, pensando nas várias possibilidades
(okey, é só um teste mesmo, vamos criar índices a vontade!)
CREATE INDEX idx_nomemunic
ON tab_municipios
(nomemunic);
CREATE INDEX idx_nomemunic_upper_to_ascii
ON tab_municipios
(upper(to_ascii(nomemunic)));
CREATE INDEX idx_nomemuniclower
ON tab_municipios
(lower(nomemunic));
CREATE INDEX idx_nomemuniclower_to_ascii
ON tab_municipios
(lower(to_ascii(nomemunic)));
CREATE INDEX idx_nomemunicupper
ON tab_municipios
(upper(nomemunic));
Agora, as queries :)
EXPLAIN SELECT *
FROM tab_municipios
WHERE lower(to_ascii(nomemunic,'LATIN1')) = lower(to_ascii('sÃo
PaULo','LATIN1'))
RESULTADO:
"Seq Scan on tab_municipios (cost=0.00..198.37 rows=28 width=142)"
" Filter: (lower(to_ascii((nomemunic)::text, 'LATIN1'::name)) = 'sao
paulo'::text)"
_____
agora, com UPPER:
EXPLAIN SELECT *
FROM tab_municipios
WHERE upper(to_ascii(nomemunic,'LATIN1')) = upper(to_ascii('sÃo
PaULo','LATIN1'))
RESULTADO:
"Seq Scan on tab_municipios (cost=0.00..198.37 rows=28 width=142)"
" Filter: (upper(to_ascii((nomemunic)::text, 'LATIN1'::name)) = 'SAO
PAULO'::text)"
Ele executa, mas não usa os indíces. E agora?
[]'s
- Walter
_______________________________________________
Grupo de Usuários do PostgreSQL no Brasil
http://www.postgresql.org.br