Subject SV: [firebird-support] Re: Slow query with like '%xxx%' clause - PROBLEM SOLVED!
Author Svein Erling Tysvær
>CREATE VIEW LISTA_CLIENTES_PESQUISA (IDCLIENTES, PESQUISA)
>AS
>
>select c.IDCLIENTES,cp.DESCRICAO||p.NOME||c.IDCLIENTES||c.CLIENTE||c.MORADA||
>c.CP||c.LOCALIDADE||c.PAIS||c.TELEFONE||c.FAX||c.EMAIL||c.PER_DESCONTO||
>c.CONTRIBUINTE||c.COD_CLIENTE_FAT
>FROM CLIENTES c
i>nner join PAISES p on p.CODIGO_ISO_3166_1=c.PAIS
>inner join COND_PAGAMENTO cp on
>cp.IDCOND_PAGAMENTO=c.CONDICOES_PAGAMENTO
>order by c.CLIENTE;

>Then the slow query is replaced with this:
>
>select first 20 IDCLIENTES from LISTA_CLIENTES_PESQUISA where PESQUISA like '%crist%'

Great to learn that Fabiano helped you out! I just downloaded your database, but knowing that your issue is solved, I don't have to open it.

In addition to Philips suggestion to add COALESCE, may I suggest that you add one additional character between each field? E.g.

select c.IDCLIENTES,coalesce(cp.DESCRICAO,'')||'|'||coalesce(p.NOME,'')||'|''||...

The reason for this addition is that your original search will return a record where DESCRICAO = 'Frederic' and NOME = 'Risto' (which would result in FredericRisto..., which contains cRist). Add a | between each field and you get Frederic|Risto, which doesn't contain crist.

Set