Best Reindexing Routine

This forum is meant for questions and discussions about the X# language and tools
hilberg.it
Posts: 74
Joined: Sun Sep 20, 2020 7:25 am
Location: Germany

Best Reindexing Routine

Post by hilberg.it »

Hi,
I am quite new in the community. While I am porting an app from VO to X# and accessing the files at first through DBFCDX and VO and later with X# and finally with AXDBFCDX, I've noticed that I need to rebuild the indexes at some points. What might be the best routine to rebuild all indexes? Right now I am removing all CDX files from the disk and rebuilding it from scratch. Would DbReindex be just as good? How would a decent routine look like?

Maybe someone wants to share his/her routine or experience?

And last but not least, I am trying to figure out how reindexing could look like with ADS. I don't have access to the CDX files through the API. So there is probably another way.

Thank you very much.
User avatar
robert
Posts: 4225
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Best Reindexing Routine

Post by robert »

Moritz,
What the DbReindex code does exactly depends entirely on what the developer has chosen.
For the X# driver for example we are saving the index expressions and conditions, then we erase the file and recreate it.
It is very well possible that ADS does the same. But you can't be sure.
If you want to delete the CDX with ADS (especially when the file is on a remote machine), then the best approach is to delete each of the tags in the Cdx (with OrdDestroy). I know from experience that ADS will delete the CDX file when the last tag in it is deleted. After that you can recreate the tags one by one.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
hilberg.it
Posts: 74
Joined: Sun Sep 20, 2020 7:25 am
Location: Germany

Best Reindexing Routine

Post by hilberg.it »

Hi,
I am trying my DBFCDX code on AXDBFCDX and having a hard time on reindexing and (re)creating DBF files. Right now my code to recreate the index files looks something like this:

Code: Select all

oServer:createOrder(cTagName, cFile, cKey, bKey, lUnique)
It throws an Unknown Error on AXDBFCDX. Also my routine to recreate DBF files checks if a file is existing. This will also not work on a remote server connection.

Is anyone from the community willing to share some pieces of code, on how to achieve reindexing, recreation of files on remote ADS? (If reindexing is possible through Advantage Data architect that would be also fine for now.)

Already a big thank you to you!
User avatar
wriedmann
Posts: 3644
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Best Reindexing Routine

Post by wriedmann »

Hi Moritz,
I'm using dictionary based file and order creating routines in both VO and X#.
I never use a packing routine as a problem there could damage the data, but I recreate the dbf table, copy all data and then do a rename.
For the reindexing routine I delete the CDX file and recreate all orders:

Code: Select all

    FOR nCounter := 1 UPTO ALen( _aOrders )
        oOrder      := _aOrders[nCounter]
        if Empty( oOrder:ForCondition )
	        oServer:SetOrderCondition( ,,,,{||ReIndexAppExec()},500,,,,,oOrder:Descending )
        ELSE
            cbCondition     := &("{||" + oOrder:ForCondition + "}")
            oServer:SetOrderCondition( oOrder:ForCondition, cbCondition,,,{||ReindexAppExec()},500,,,,,oOrder:Descending )
        endif
        cbExpression    := &("{||" + oOrder:IndexExpr + "}")
        if oServer:CreateOrder( oOrder:TagName,cFileName,oOrder:IndexExpr,cbExpression,false ) == false
            ErrBox( oWindow, "Fehler beim Erstellen des Orders  " + oOrder:TagName + "/" + self:Name )
			lSuccess	:= false
        endif
    NEXT
HTH
Wolfgang
P.S. this code is at least 20 years old, but it works in many different applications
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
hilberg.it
Posts: 74
Joined: Sun Sep 20, 2020 7:25 am
Location: Germany

Best Reindexing Routine

Post by hilberg.it »

Thanks Wolfgang! Appreciate it.
Does this routine even work on a remote ADS Server? Because my call to 'CreateOrder' always returns false on the remote server, but seems to work on the local server. Is the call to 'ReIndexAppExec' something custom from your side or from VO/X#? And finally how would you delete CDX files on remote server? I could not find OrdDestroy call that Robert mentioned.
Thanks
User avatar
wriedmann
Posts: 3644
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Best Reindexing Routine

Post by wriedmann »

Hi Moritz,
this code works on both local and remote ADS server and on both local and remote DBFCDX.
I'm using it regularly in VO, and the few times I've used it in X# it worked too, but I would have to recheck (had it working using the old SAP RDD).
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
wriedmann
Posts: 3644
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Best Reindexing Routine

Post by wriedmann »

Hi Moritz,
I should read the entire message <g>.

Code: Select all

function ReindexAppExec()
	ApplicationExec( EXECWHILEEVENT )
	return true
And to delete the index I use the FErase() function (I have write access to the DBF folder, otherwise it would not work).
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
g.bunzel@domonet.de
Posts: 97
Joined: Tue Mar 01, 2016 11:50 am
Location: Germany

Best Reindexing Routine

Post by g.bunzel@domonet.de »

...one note from me:

With a small extension, you can show a progress bar during creating that index:
IF Empty( oOrder:ForCondition )
oServer:SetOrderCondition( ,,,,{||ReIndexAppExec( oServer:OrderInfo(1805) )},500,,,,,oOrder:Descending )
ELSE
...

Function ReindexAppExec(nIndexbar)
// nIndexbar = 0-100 %
ApplicationExec( EXECWHILEEVENT )
RETURN TRUE

I use this eval-block to show a progress bar:
cbEval := { || oDlg:UpdateIndex (oServer:OrderInfo(1805)) }

From the ADS helpfile:
The cbEval code block passed to the DBServer:SetOrderCondition method will not be evaluated for every record the server processes. Instead, it will be evaluated about every two seconds while the index order is created.


HTH

Gerhard Bunzel
hilberg.it
Posts: 74
Joined: Sun Sep 20, 2020 7:25 am
Location: Germany

Best Reindexing Routine

Post by hilberg.it »

Thanks for your input! :)
hilberg.it
Posts: 74
Joined: Sun Sep 20, 2020 7:25 am
Location: Germany

Best Reindexing Routine

Post by hilberg.it »

Out of curiosity: If I reindex my files with VO or X# using DBFCDX RDD it takes about 15 min for all files. But if I reindex wit X# and AXDBFCDX RDD it is done after 1-2 min!! It seems to work though. Now I am curios why there is such a big difference in time. Does anyone know why? Thanks!
Post Reply