Page 1 of 1

ADS Índice Composto ( SOLUCIONADO )

Posted: Mon Jun 06, 2016 4:52 pm
by MGA
Amigos,

referente:
INDEX ON str(filial,2)+str(cliente,6) to ...

Exemplo:

Utilizando ADS - Funciona perfeitamente :)
nContaRegistros := 0
clientes->( dbsetorder(1), dbseek( str(nFilial,2)+str(nCliente,6) ) )
do while clientes->filial = nFilial .and. clientes->codigo = nCliente .and. clientes->(!eof())
nContaRegistros ++
clientes->(dbskip())
enddo
? nContaRegistros // total 423 :)

-----------------------------------------------------------------------

Utilizando ADS - Não funciona :(
nContaRegistros := 0
clientes->( dbsetorder(1), dbseek( str(nFilial,2) ) )
do while clientes->filial = nFilial .and. clientes->(!eof())
nContaRegistros ++
clientes->(dbskip())
enddo
? nContaRegistros // total 5 :(

O ADS só permite trabalhar com índice composto integral ???
Existe alguma saída para isso?

obrigado

Re: ADS Índice Composto

Posted: Mon Jun 06, 2016 6:22 pm
by karinha
No caso do ADS, não seria:

Code: Select all

CREATE INDEX ??
 

Re: ADS Índice Composto

Posted: Tue Jun 07, 2016 4:20 pm
by fgondi
Falta en el Dbseek un ".T."

Code: Select all

Utilizando ADS - Não funciona :( 
nContaRegistros := 0
clientes->( dbsetorder(1), dbseek( str(nFilial,2), .T. ) )
do while clientes->filial = nFilial .and. clientes->(!eof())
nContaRegistros ++
clientes->(dbskip())
enddo
? nContaRegistros // total 5  :( 

Re: ADS Índice Composto

Posted: Tue Jun 07, 2016 7:32 pm
by MGA
Obrigado a todos,

segue a solução:

http://devzone.advantagedatabase.com/dz ... 31204-1609

Title:
Slow Performance, Unexpected Sort Order, Incorrect SQL Results After Converting From DBF to ADT Tables
Problem Description:
With DBF format tables creating a multi-segmented index is done with the plus ( + ) operator. A multi-segmented index expression would look like this: Field1 + Field2 + Field3. If this type of index expression is used in an ADT table there are potential performance issues, as well as a possibility for unexpected sort order results.

In version 6.x the performance issue is a result of the Advantage Server incorrectly using the multi-segmented index which contains the plus operator. In version 7.0 the Advantage Server was changed such that indexes with the plus operator were ignored. In either case performance is adversely affected.

The incorrect sort order problem is due to the fact that if one field in a multi-segmented index is NULL, the entire index key will evaluate to null. The null key can also cause problems for queries as the index would be used to to optimize a search.
Solution:
The solution to these problems is to change the operator used to create the multi-segmented index from the plus ( + ) operator to the semicolon ( ; ) operator. Using the semicolon operator will avoid all the problems mentioned above.