Performance and the capital of Albania
Tuesday, 6 March 2012 · 4 messages · last reply 9 Mar 2012
AB
Andy Bunce6 Mar 2012 17:17 #
Using the factbook.xml database and a recent 7.1.2 beta, I am hitting some performance problems. To debug I have been trying some expressions in the GUI window. The goal is given a country id, get the capital. The examples use Albania ="f0_136"
let $id:="f0_136"
let $cap:=//country[@id=$id]/@capital
return //city[@id=$cap]
------result------------
<city id="f0_1461" country="f0_136" longitude="10.7" latitude="46.2">
<name>Tirane</name>
<population year="87">192000</population>
</city>
*Time: 0.7ms *
Very nice. Sadly my code is not doing it like this! ( the xpath is being
generated from some data description xml I have created)If I try in the GUI some Xpath variations they produce wildly different execution times
let $id:="f0_136"
return //city[@id=(//country[@id=$id]/@capital)]
*26144ms*
let $id:="f0_136"
return //city[@id=//country[@id=$id]/@capital]
*25157ms*
let $id:="f0_136"
return (//city)[@id=(//country[@id=$id]/@capital)]
*550ms*
let $id:="f0_136"
return (//city)[@id=((//country)[@id=$id]/@capital)]
*6087ms*I was expecting all these to perform about the same. They all produce the same result.
/Andy
CG
Christian Grün9 Mar 2012 13:12 #
Hi Andy,
it looks as if all expressions are optimized and evaluated in a little bit different way. No doubt this will be handled sooner or later (but it may take some time).
Thanks,
Christian
Quoted text · Andy Bunce · 48 lines
On Tue, Mar 6, 2012 at 5:17 PM, Andy Bunce <bunce.andy at gmail.com> wrote: > Using the factbook.xml database and a recent 7.1.2 beta, I am hitting some > performance problems. To debug I have been trying some expressions in the > GUI window. The goal is given a country id, get the capital. The examples > use Albania ="f0_136" > > let $id:="f0_136" > let $cap:=//country[@id=$id]/@capital > return //city[@id=$cap] > ------result------------ > <city id="f0_1461" country="f0_136" longitude="10.7" latitude="46.2"> > <name>Tirane</name> > <population year="87">192000</population> > </city> > Time: 0.7ms > Very nice. Sadly my code is not doing it like this! ( the xpath is being > generated from some data description xml I have created) > > If I try in the GUI some Xpath variations they produce wildly different > execution times > > let $id:="f0_136" > return //city[@id=(//country[@id=$id]/@capital)] > 26144ms > > let $id:="f0_136" > return //city[@id=//country[@id=$id]/@capital] > 25157ms > > let $id:="f0_136" > return (//city)[@id=(//country[@id=$id]/@capital)] > 550ms > > let $id:="f0_136" > return (//city)[@id=((//country)[@id=$id]/@capital)] > 6087ms > > I was expecting all these to perform about the same. They all produce the > same result. > > /Andy > > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >
AB
Andy Bunce9 Mar 2012 14:15 #
Ok, What a difference parenthesis or two can make :-).
Any guidance about what approaches are likely to give the best results with the current schema. Maybe breakout and assign sub expressions where possible?
/Andy
On Fri, Mar 9, 2012 at 12:12 PM, Christian Grün
<christian.gruen at gmail.com>wrote:
Quoted text · Christian Grün · 60 lines
> Hi Andy, > > it looks as if all expressions are optimized and evaluated in a little > bit different way. No doubt this will be handled sooner or later (but > it may take some time). > > Thanks, > Christian > ___________________________ > > On Tue, Mar 6, 2012 at 5:17 PM, Andy Bunce <bunce.andy at gmail.com> wrote: > > Using the factbook.xml database and a recent 7.1.2 beta, I am hitting > some > > performance problems. To debug I have been trying some expressions in the > > GUI window. The goal is given a country id, get the capital. The examples > > use Albania ="f0_136" > > > > let $id:="f0_136" > > let $cap:=//country[@id=$id]/@capital > > return //city[@id=$cap] > > ------result------------ > > <city id="f0_1461" country="f0_136" longitude="10.7" latitude="46.2"> > > <name>Tirane</name> > > <population year="87">192000</population> > > </city> > > Time: 0.7ms > > Very nice. Sadly my code is not doing it like this! ( the xpath is being > > generated from some data description xml I have created) > > > > If I try in the GUI some Xpath variations they produce wildly different > > execution times > > > > let $id:="f0_136" > > return //city[@id=(//country[@id=$id]/@capital)] > > 26144ms > > > > let $id:="f0_136" > > return //city[@id=//country[@id=$id]/@capital] > > 25157ms > > > > let $id:="f0_136" > > return (//city)[@id=(//country[@id=$id]/@capital)] > > 550ms > > > > let $id:="f0_136" > > return (//city)[@id=((//country)[@id=$id]/@capital)] > > 6087ms > > > > I was expecting all these to perform about the same. They all produce the > > same result. > > > > /Andy > > > > > > _______________________________________________ > > BaseX-Talk mailing list > > BaseX-Talk at mailman.uni-konstanz.de > > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk > > >
CG
Christian Grün9 Mar 2012 14:23 #
Quoted text · Andy Bunce · 4 lines
> Ok, What a difference parenthesis or two can make :-). > Any guidance about what approaches are likely to give the best results with > the current schema. Maybe breakout and assign sub expressions where > possible?
Right; in general, nested predicates are more difficult to rewrite, as the number of potential optimizations increases. Expressions can also be put in global variables if you want them to be evaluated once at compile time. Next, if you start at the root node, or prefix expressions with doc() or db:open(), this further increases the chance for triggering optimizations.
Hope this helps,
Christian
Quoted text · Christian Grün · 67 lines
> On Fri, Mar 9, 2012 at 12:12 PM, Christian Grün <christian.gruen at gmail.com> > wrote: >> >> Hi Andy, >> >> it looks as if all expressions are optimized and evaluated in a little >> bit different way. No doubt this will be handled sooner or later (but >> it may take some time). >> >> Thanks, >> Christian >> ___________________________ >> >> On Tue, Mar 6, 2012 at 5:17 PM, Andy Bunce <bunce.andy at gmail.com> wrote: >> > Using the factbook.xml database and a recent 7.1.2 beta, I am hitting >> > some >> > performance problems. To debug I have been trying some expressions in >> > the >> > GUI window. The goal is given a country id, get the capital. The >> > examples >> > use Albania ="f0_136" >> > >> > let $id:="f0_136" >> > let $cap:=//country[@id=$id]/@capital >> > return //city[@id=$cap] >> > ------result------------ >> > <city id="f0_1461" country="f0_136" longitude="10.7" latitude="46.2"> >> > <name>Tirane</name> >> > <population year="87">192000</population> >> > </city> >> > Time: 0.7ms >> > Very nice. Sadly my code is not doing it like this! ( the xpath is being >> > generated from some data description xml I have created) >> > >> > If I try in the GUI some Xpath variations they produce wildly different >> > execution times >> > >> > let $id:="f0_136" >> > return //city[@id=(//country[@id=$id]/@capital)] >> > 26144ms >> > >> > let $id:="f0_136" >> > return //city[@id=//country[@id=$id]/@capital] >> > 25157ms >> > >> > let $id:="f0_136" >> > return (//city)[@id=(//country[@id=$id]/@capital)] >> > 550ms >> > >> > let $id:="f0_136" >> > return (//city)[@id=((//country)[@id=$id]/@capital)] >> > 6087ms >> > >> > I was expecting all these to perform about the same. They all produce >> > the >> > same result. >> > >> > /Andy >> > >> > >> > _______________________________________________ >> > BaseX-Talk mailing list >> > BaseX-Talk at mailman.uni-konstanz.de >> > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >> > > >
Written for BaseX 7.1. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery