Re: grouping (was: if or template?)

Subject: Re: grouping (was: if or template?)
From: "Steve Muench" <smuench@xxxxxxxxxxxxx>
Date: Mon, 8 May 2000 10:24:28 -0700
| A FAQ: use something like
| <xsl:for-each select="//tracker-id[not(.=preceding::tracker-id)]">
| 
| This is the traditional solution; Steve Muench has just told me about a
| brilliant alternative using keys:
| 
| <xsl:key name="tid" use="tracker-id" select="."/>
| 
| <xsl:for-each
| select="//tracker-id[generate-id(.)=generate-id(key('tid',.)[1])]">
| 
| I hope Steve will forgive me for announcing this discovery before he does,
| I'm quite excited by it because it gives much better performance.
+------

I stumbled on this idea this weekend as I was writing the 
last chapter of my book on Oracle and XML for O'Reilly. 
I was writing up some information comparing the
pros and cons of using SQL's GROUP BY and ORDER BY capability
with grouping/sorting techniques available in XSLT 1.0,
trying to help people see the tradeoffs. I started thinking, 
"How does a database make grouping and sorting fast?" 
Well, it does that by creating indexes.

Then it dawned on me that creating an XSLT key like:

    <xsl:key name="tid" use="tracker-id" select="."/>

was conceptually similar to the SQL DDL statement:

    CREATE INDEX tid ON currentDocument( tracker-id );

Namely, it asks the system to "waste" a little storage
to keep track of some extra data structures to make 
access to this *specific* piece of information -- which
presumably is happening frequently for a given task --
much faster.

The speed difference between this approach and the
traditional "scan-my-preceding" strategy is very 
measurable. I see from 4 to 13 *times* performance
improvement for grouping using Saxon, Xalan, and OracleXSL
by adopting this strategy. I was not able to test it
out with XT or MSXSL3 with current versions, but when
these support key, I'd suspect similar results.

Maybe there are further refinements that the folks on the
list will discover as they try to experiment with this
key-enhanced grouping idea...

______________________________________________________________
Steve Muench, Lead XML Evangelist & Consulting Product Manager
Business Components for Java & XSQL Servlet Development Teams
Oracle Rep to the W3C XSL Working Group


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread