Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> comp.databases.theory -> Re: Nearest Common Ancestor Report (XDb1's $1000 Challenge)

Re: Nearest Common Ancestor Report (XDb1's $1000 Challenge)

From: Hugo Kornelis <hugo_at_pe_NO_rFact.in_SPAM_fo>
Date: Tue, 25 May 2004 00:48:07 +0200
Message-ID: <mts4b09m5olm07v0b9ppienrdk8au4md6c@4ax.com>


Hi Neo,

I promised a second post - here it is.

When I was testing my algorith against larger amounts of data, I noticed that it was bugged. The algorithm to determine all ancestors of each thing may sometimes try to insert the same thing/ancestor combination with two different path lengths. I had to use a GROUP BY and a MIN(..) to solve this.

I didn't like the performance hit I took (up to 14.3 ms avg) - still better than the 16 ms that XDb1 needs on this same machine but I figured I could do better.

I changed my model to use integer columns with the IDENTITY property (SQL Server's name for autoincrementing artificial ID) as primary keys. This improved the performance of my report generation; the average execution time is now down to 11.0 ms. Note that my report still shows the names of the things in the hierarchies, not the ID's. (SQL and output are down below).

Incidentally, this quicker implementation is also better equipped to adapt to many of the changes you suggested after your original post. You want different things to share the same name? Easy - just remove the unique constraint on thingName and you're done. You want things without name? Remove thingName from the things table, create a new table thingNames with columns thing (primary key / foreign key to things) and thingName.
You want things with multiple names? As above, but primary key on thingNames table should span both columns.

All this doesn't matter for the challenge you set, as these were all requirements that you brought into the equation at a later time. What does matter is my improved model, that you'll find below. The average execution time is 11.0 ms (as you can see from the output). This is based on an execution on my desktop system (1.3 GHz Athlon, 256 MB RAM, 2 harddisks at 40 GB / 7200 rpm each) with several open applications. XDb1 takes 16 ms for generating the report on the same machine with the same applications still active.

(Start of SQL for improved model)

(Output after running the above script)

Initialization done - starting actual test

started                  ended                    elapsed (10 executions) 

------------------------ ------------------------ -----------------------
2004-05-25 00:37:03.780 2004-05-25 00:37:03.890 00:00:00:110

ThingX ThingY CmnAnc Dist
-------------------- -------------------- -------------------- -----------

army                 fido                 army                 2
army                 john                 army                 1
army                 laptop1              army                 2
army                 luke                 god                  3
army                 mary                 army                 1
army                 trinity              god                  2
fido                 laptop1              john                 2
fido                 laptop1              mary                 2
god                  army                 god                  1
god                  fido                 god                  3
god                  john                 god                  2
god                  laptop1              god                  3
god                  luke                 god                  2
god                  mary                 god                  2
god                  trinity              god                  1
john                 fido                 john                 1
john                 laptop1              john                 1
john                 luke                 god                  4
john                 mary                 army                 2
luke                 fido                 luke                 1
luke                 laptop1              trinity              3
mary                 fido                 mary                 1
mary                 laptop1              mary                 1
mary                 luke                 trinity              2
trinity              fido                 trinity              2
trinity              john                 god                  3
trinity              laptop1              trinity              2
trinity              luke                 trinity              1
trinity              mary                 trinity              1


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

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address) Received on Mon May 24 2004 - 17:48:07 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US