[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

return only latest version of an item

A. Steven Anderson steve at asanderson.com
Thu May 14 17:06:57 PDT 2009


  return only latest version of an item
Thanks for the quick replies.

To answer Ken's question, I'm looking for time efficiency (i.e. quickest
results returned) vs. space (i.e. RAM) efficiency.

Pavel, you were correct in your interpretation of my request; I'm looking to
return the set of items with the greatest version number within the same id.

Unfortunately though, I tried your suggestion but only returned one item
which was had the greatest version of all items.

As far as implementation, I'm querying eXist-db 1.2.5.

Any other suggestions?

Steve

On Thu, May 14, 2009 at 2:41 PM, Pavel Minaev <http://x-query.com/mailman/listinfo/talk> wrote:

> On Thu, May 14, 2009 at 11:23 AM, G. Ken Holman
> <http://x-query.com/mailman/listinfo/talk> wrote:
> > At 2009-05-14 14:18 -0400, A. Steven Anderson wrote:
> >>
> >> I've got a pretty complex xquery that returns only the latest version of
> >> all items in a collection, but I know there has got to be a more
> efficient
> >> way to do it.
> >> ...
> >> What would be the most efficient way to do this?
> >
> > By which criteria are you trying to measure efficiency?
> >
> > Below is an example using max()
> >
> > I hope this helps.
> >
> > . . . . . . . . Ken
> >
> > t:\ftemp>type steven.xml
> > <items>
> >   <item>
> >      <id>1</id>
> >      <name>item # 1</name>
> >      <version>1</version>
> >   </item>
> >   <item>
> >      <id>1</id>
> >      <name>item # 1</name>
> >      <version>2</version>
> >   </item>
> >   <item>
> >      <id>1</id>
> >      <name>item # 1</name>
> >      <version>3</version>
> >   </item>
> >   <item>
> >      <id>2</id>
> >      <name>item # 2</name>
> >      <version>1</version>
> >   </item>
> >   <item>
> >      <id>2</id>
> >      <name>item # 2</name>
> >      <version>2</version>
> >   </item>
> >   <item>
> >      <id>3</id>
> >      <name>item # 3</name>
> >      <version>1</version>
> >   </item>
> > </items>
> >
> > t:\ftemp>type steven.xq
> > /items/item[version=max(/items/item/version)]
>
> That doesn't work as intended - it gets all items with version number
> equal to the highest version number for all items. What is needed (if
> I understood the original request correctly) is to only compare
> versions within group of items with the same id. Something like this:
>
>  for $item in /items/item
>  where $item/version = max(/items/item[id = $item/id]/version)
>  return $item
>
> It's hard to tell the performance impact of this, since it's heavily
> implementation-dependant. Though I'd expect grouping operations (like
> xsl:for-each-group) to be easier to optimize, if they were there.
>
> _______________________________________________
> http://x-query.com/mailman/listinfo/talk
> http://x-query.com/mailman/listinfo/talk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://x-query.com/pipermail/talk/attachments/20090514/1c10d88f/attachment.htm


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.