Hi Morris,

>> The idea of the isLast() interface will be a good thing if the 
>> overhead for caching is small enough.
If it'd be defined as a seperate interface (as I understand this is what
you're suggesting), then implementations of only "double-fetch" critical
iterators can implement this - which will make changes minimal. For the rest
of DTMIterator's is-last can be implemented as "position() =(!=) last()".
I currently don't see any cases when cache of more than one "node" will be
necessary. Consider sql extension lib in streaming mode: to return value for
isLast() method you need to just call ResultSet.next() once. So this would
look like (approx):

isLast() {
  if (!m_nextFetched) {
    m_nextFetched = true;
    m_hasMore = resultSet.next(); 
    // current record is already cached in the streaming node
  }
  return m_hasMore;
}

nextNode() {
  if (!m_nextFetched) {
    // current implementation
  } else {
    m_nextFetched = false;
    // implementation similar to current, but w/o extra ResultSet.next();
  }
}

Since, the idea seems to be good, I'll go ahead and make changes necessary
for this functionality and post them here.

Thanks,
Dimitry

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Friday, February 21, 2003 11:12
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: Re: position() = last() optimization feature request


The idea of the isLast() interface will be a good thing if the overhead for
caching is small enough.

By the way, I will also look at the optimizations for  "node[last()]"  in
my XSLTC_DTM performance improvement work. This is better to be done on the
DTM side. My current idea is to have the DTMAxisIterator support a
getLastNode() interface. This is a separate issue from isLast. I will
suggest you to look at the isLast issue first.

Regards,

Morris Kwan
XSLT Development
IBM Toronto Lab
Tel: (905)413-3729
Email: [EMAIL PROTECTED]



 

                      "Voytenko,

                      Dimitry"                 To:
[EMAIL PROTECTED]                                                    
                      <dvoytenko@sector        cc:

                      data.com>                Subject:  position() = last()
optimization feature request                            
 

                      02/20/2003 09:42

                      PM

                      Please respond to

                      xalan-dev

 

 




Hi,

Please take a look at the attached letter and response from W3C about
is-last optimization. It looks like this could be advantageous for many
queries (especially for sql extension in streaming mode). XPath expressions
(sub-expressions) of view:
             position() ? last(), where "?" is =, !=, <, >, etc,

can be easily optimized (org.apache.xpath.compiler.Compiler class) into the
call to the internal "is-last()" function.
Simpliest (or caching) iterators can implement this call just as "position
()
? last()". And more complicated implementations would require (in the worst
case) caching of only one (next) node. So this can really save resources
for
many queries.

I could post changes that need to be done in Compiler class (they'd be
pretty simple). But this would make sense only if DTMManager (and all other
iterator interfaces) would have isLast() method, which already requires
changes to the interfaces.
>From the iteration standpoint java.util.Iterator and Enumeration interfaces
all have hasNext() method (just as examples).

Please, send your comments if this looks interesting.

In addition, similar optimization could be done for queries "node[last()]"
as call to internal "get-last()" method, and probably some others.

Thanks,
Dimitry


_____________________________________________________
Sector Data, LLC, is not affiliated with Sector, Inc., or SIAC
 <<RE: Iteration functionality request for XPath 2.0>>

----- Message from "Kay, Michael" <[EMAIL PROTECTED]> on Fri, 20
Sep 2002 02:30:54 -0800 -----
 

      To: "Voytenko, Dimitry" <[EMAIL PROTECTED]>,
"'[EMAIL PROTECTED]'"              
          <[EMAIL PROTECTED]>

 

 Subject: RE: Iteration functionality request for XPath 2.0

 


> ....
> Sometimes it's very important to know if current node is the
> last one in the node-set. There're two basic ways to do it in
> XPath 1.0:
> **** FIRST APPROACH: using "position" and "last":
>            <xsl:if test="position() = last()">
>                        ....
>            </xsl:if>
>
> Drawbacks:
>            If node-set implementation is iterative, i.e. new node
> is fetched only when for-each instruction goes to a new cycle
> and whole list of nodes is not cached in node-set object,
> then the first call to last() function will go through all
> nodes to find out their quantity. This will repeat the
> node-set fetch procedure twice or will lead to the caching of
> the nodes list.....

> In my point of view, this could be easily solved by extending
> list of node-set/context functions with one more function,
> something like "is-last" (another function "is-first" could
> also be added for symmetry, eventhough it'd be redundant).
> This function would return boolean true if current node is
> the last node in the node-set.

Saxon has an internal function like your is-last(), and its optimizer
rewrites the predicate [position()=last()] as [is-last()], for all the
reasons you mention.

I don't see a good reason why is-last() should be made available as a
user-visible function, when this construct is very easy for optimizers to
handle internally.
Michael Kay




_____________________________________________________
Sector Data, LLC, is not affiliated with Sector, Inc., or SIAC

Reply via email to