xpath expressions vs xquery select

Sunday, 31 January 2010 · 4 messages · last reply 1 Feb 2010
CG
Christian Grünin reply to Travis Webb, 31 Jan 2010, 23:5731 Jan 2010 23:16 #
Dear Travis, it always depends on the XQuery implementation, and its optimizer, which query variant will be evaluated more efficiently. In BaseX, your two example queries...
  for $x in doc('test')/* where $x/node="value" return $x
  for $x in doc('test')/*[node="value"] return $x
...will both be simplified/rewritten to this query: doc('test')/*[node="value"] The "Query Info" panel in BaseX will give you more insight on how your queries are compiled and optimized. Hope this helps, Christian
Quoted text · Travis Webb · 12 lines
On Sun, Jan 31, 2010 at 10:57 PM, Travis Webb <tjwebb at vt.edu> wrote: > I'm trying to figure out which is more efficient (xpath or xquery select), > so if someone has knowledge on this I'd appreciate any input. This may or > may not be specific to the implementation of BaseX. > For example, the following queries return the same thing, but which one is > faster? Does basex treat them the same way? 1 uses xquery select, 2 uses > xpath > 1. for $x in doc('test')/* where $x/node="value" return $x > OR > 2. for $x in doc('test')/*[node="value"] return $x > Thanks. > -tjw
___________________________ Christian Gruen Universitaet Konstanz Department of Computer & Information Science D-78457 Konstanz, Germany Tel: +49 (0)7531/88-4449, Fax: +49 (0)7531/88-3577 http://www.inf.uni-konstanz.de/~gruen
TW
Travis Webb31 Jan 2010 23:57 #
I'm trying to figure out which is more efficient (xpath or xquery select), so if someone has knowledge on this I'd appreciate any input. This may or may not be specific to the implementation of BaseX. For example, the following queries return the same thing, but which one is faster? Does basex treat them the same way? 1 uses xquery select, 2 uses xpath 1. for $x in doc('test')/* where $x/node="value" return $x OR 2. for $x in doc('test')/*[node="value"] return $x Thanks. -tjw
CG
Christian Grünin reply to Travis Webb, 1 Feb 2010, 01:181 Feb 2010 00:36 #
Quoted text · Travis Webb · 5 lines
> Thanks for the response. In the API, It looks like I can make use of > precompiled queries; is this so? If so, and I precompile the query, will it > still be optimized at runtime, or will it be executed exactly as it is > written? > -tjw
You probably refer to prepared queries? This processing mode basically allows to bind different variable values to the same query and execute it several times. The actual query compilation is very fast, so there was no real need of precompiling it yet. – Christian
Quoted text · Christian Grün · 49 lines
> On Sun, Jan 31, 2010 at 5:16 PM, Christian Grün <christian.gruen at gmail.com> > wrote: >> >> Dear Travis, >> >> it always depends on the XQuery implementation, and its optimizer, >> which query variant will be evaluated more efficiently. In BaseX, your >> two example queries... >> >> for $x in doc('test')/* where $x/node="value" return $x >> for $x in doc('test')/*[node="value"] return $x >> >> ...will both be simplified/rewritten to this query: >> >> doc('test')/*[node="value"] >> >> The "Query Info" panel in BaseX will give you more insight on how your >> queries are compiled and optimized. >> >> Hope this helps, >> Christian >> >> >> On Sun, Jan 31, 2010 at 10:57 PM, Travis Webb <tjwebb at vt.edu> wrote: >> > I'm trying to figure out which is more efficient (xpath or xquery >> > select), >> > so if someone has knowledge on this I'd appreciate any input. This may >> > or >> > may not be specific to the implementation of BaseX. >> > For example, the following queries return the same thing, but which one >> > is >> > faster? Does basex treat them the same way? 1 uses xquery select, 2 uses >> > xpath >> > 1. for $x in doc('test')/* where $x/node="value" return $x >> > OR >> > 2. for $x in doc('test')/*[node="value"] return $x >> > Thanks. >> > -tjw >> >> ___________________________ >> >> Christian Gruen >> Universitaet Konstanz >> Department of Computer & Information Science >> D-78457 Konstanz, Germany >> Tel: +49 (0)7531/88-4449, Fax: +49 (0)7531/88-3577 >> http://www.inf.uni-konstanz.de/~gruen > >
TW
Travis Webbin reply to Christian Grün, 31 Jan 2010, 23:161 Feb 2010 01:18 #
Thanks for the response. In the API, It looks like I can make use of precompiled queries; is this so? If so, and I precompile the query, will it still be optimized at runtime, or will it be executed exactly as it is written? -tjw On Sun, Jan 31, 2010 at 5:16 PM, Christian Grün <christian.gruen at gmail.com>wrote:
Quoted text · Christian Grün · 44 lines
> Dear Travis, > > it always depends on the XQuery implementation, and its optimizer, > which query variant will be evaluated more efficiently. In BaseX, your > two example queries... > > for $x in doc('test')/* where $x/node="value" return $x > for $x in doc('test')/*[node="value"] return $x > > ...will both be simplified/rewritten to this query: > > doc('test')/*[node="value"] > > The "Query Info" panel in BaseX will give you more insight on how your > queries are compiled and optimized. > > Hope this helps, > Christian > > > On Sun, Jan 31, 2010 at 10:57 PM, Travis Webb <tjwebb at vt.edu> wrote: > > I'm trying to figure out which is more efficient (xpath or xquery > select), > > so if someone has knowledge on this I'd appreciate any input. This may or > > may not be specific to the implementation of BaseX. > > For example, the following queries return the same thing, but which one > is > > faster? Does basex treat them the same way? 1 uses xquery select, 2 uses > > xpath > > 1. for $x in doc('test')/* where $x/node="value" return $x > > OR > > 2. for $x in doc('test')/*[node="value"] return $x > > Thanks. > > -tjw > > ___________________________ > > Christian Gruen > Universitaet Konstanz > Department of Computer & Information Science > D-78457 Konstanz, Germany > Tel: +49 (0)7531/88-4449, Fax: +49 (0)7531/88-3577 > http://www.inf.uni-konstanz.de/~gruen >

⚡Generated with XQuery