[xquery-talk] return only latest version of an item

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


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 <int19h at gmail.com> wrote:

> On Thu, May 14, 2009 at 11:23 AM, G. Ken Holman
> <gkholman at cranesoftwrights.com> 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.
>
> _______________________________________________
> talk at x-query.com
> 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


More information about the talk mailing list