How to optimize the query in a remote bank using Clientdataset?

Asked

Viewed 749 times

1

I’m using a Clientdataset for consultation in a remote database, the table has more than 100 thousand records and this getting very slow, the SQL I am using is:

select (coalesce (cast(A.con_baixa as date),current_date) - cast(A.con_vencto as date) )Diastraso,
        A.CLI_CODIGO, A.CON_DOCUMENTO, A.CON_PARCELA, A.CON_DOC_ORIGEM,cast(A.CON_LANCTO as date) CON_LANCTO,
        cast(A.CON_VENCTO as date)CON_VENCTO, A.CON_VALOR, A.PLA_CODIGO, A.CON_TIPO, A.CON_PREVISAO,  A.CON_ESPECIE,
        cast(A.CON_BAIXA as date)CON_BAIXA,A.CON_PAGO, (A.CON_JUROS + A.CON_MULTA) CON_JUROSMULTA, A.CON_SITUACAO,
        A.BANCO, A.AGENCIA, A.CONTA, A.CONTA_R, A.CHEQUE, A.EMITENTE, A.CIDADE, A.CLI_REPASSE_CODIGO, A.CLI_REPASSE_NOME,
        A.CON_VL_BRUTO, A.CON_ID, A.BOL_CONTA, A.BOL_NOSSONUMERO, A.BOL_LINHADIGITAVEL, A.BOL_LOTE, A.NOSSONUMERO,
        A.CON_HISTORICO, A.IDORDEMSERVICO, A.ECF_NUMERO,  A.STATUSCONTA, A.CON_FPAGTOID, A.CONTRATOLOC, A.CON_DESCONTO,
        A.CON_OUTROS, A.IDLOTE, A.IDPAI, A.MOVORIGEM, A.IDCARTAO, A.CON_DATA, A.IDBORDERO, A.CCUSTOID, A.IDDESCONTO,
        A.IDLOJA,B.cli_nome, C.PLA_DESCRICAO, D.DESCRICAO CENTROCUSTO, E.FDESCRICAO, NomeFantasia
from contas A
left join CLIENTES B on (B.cli_codigo = A.cli_codigo)
left join PLANOCONTAS C on A.PLA_CODIGO = C.PLA_CODIGO
left join CCUSTO D on A.CCUSTOID = D.CCUSTOID
left join FPAGTO E on A.CON_FPAGTOID = E.FPAGTOID
inner join Loja F on F.IdLoja = A.IdLoja
where  (A.CON_LANCTO >='03/05/2013 00:00:00' and A.CON_LANCTO <= '03/24/2015 23:59:59' )
        and A.CON_TIPO = 'R' and A.IdLoja in (1) and A.STATUSCONTA <> 'AGRUPAMENTO'
        order by A.IdLoja, A.CON_LANCTO
  • Come on ? which DBMS? Tables have index ? Statistics are up to date ? Query Execution Plan was made ?

  • What is the need to load all records?

  • I am using Firebird, there is no information, statistics are not updated and no plan was made, I am new and do not know how it works...

  • http://www.firebirdsql.org/manual/isql-set.html#isql-set-plan

  • Related: http://answall.com/questions/54034/comormelhorar o-performanco-consulta-do-clientdataset-muitos-registros

3 answers

1

Were you able to identify if the slow is the execution of the query or the loading in the dataset ? how many records are returning in the query, as I understand it, probably the problem is that many records are being returned, and as we know the clientdataset puts them all in memory.

Create indexes for some fields can help a lot, but it is no use to go out creating a lot of indexes, this can harm performance. It is necessary to analyze the consultation plan to evaluate the best indexes to be created.

0

0

If there is no index you are doing full scan table and that is the reason for the delay. Create indexes for each field in Join and Where and run the query again

  • The fields that are in the joins are primary key, already have an index created for each of them and even so is slow

  • And the Where fields ? These also need indexes

  • I had not seen the Order by, those if not have, have to have indexes too

  • i created for everyone from Where and order by, yet it remains the same thing s;

  • Well now that your bank is full of indexes and the blame can not be imposed on it, the problem is the amount of records brought at once to the client, makes the suggestion of Gypsy Morrison Mendez who posted a response limiting the amount of records brought at a time

Browser other questions tagged

You are not signed in. Login or sign up in order to post.