Positional predicate optimization
Good morning,
I wondered if there is room for optimization during the compilation of the following query:
let $oneBillion := 1000000000 for $x at $p in (1 to $oneBillion ) where $p = 1 return $x
I would have expected this to be compiled into something like
for $x in (1 to $oneBillion)[1] return $x
Or simply
(1 to $oneBillion)[1]
Judging only from the execution times of the original query versus the optimized ones, it seems the sequence of 1 to one billion is entirely generated, which seems suboptimal in this case.
Kind regards, Daniël Knippers
Good evening Daniël,
I have introduced the suggested optimization, considering some more cases like $p = (1 to 10), $p >= 1 and $p <= 3 etc. I would be pleased if you could check out the latest snapshot and do some testing.
Christian
Quoted text · Daniël Knippers · 26 lines
On Thu, Aug 14, 2014 at 9:11 AM, Daniël Knippers <dknippers at gmail.com> wrote: > Good morning, > > I wondered if there is room for optimization during the compilation of the > following query: > > let $oneBillion := 1000000000 > for $x at $p in (1 to > $oneBillion > ) where $p = 1 return $x > > I would have expected this to be compiled into something like > > for $x in (1 to $oneBillion)[1] return $x > > Or simply > > > (1 to $oneBillion)[1] > > Judging only from the execution times of the original query versus the > optimized ones, it seems the sequence of 1 to one billion is entirely > generated, which seems suboptimal in this case. > > Kind regards, > Daniël Knippers
Hi Christian,
Thank you for your quick response and implementation. Very impressive. I will try to run some tests soon, if I find anything strange I will let you know.
Daniël
Quoted text · Christian Grün · 42 lines
On Thu, Aug 14, 2014 at 8:36 PM, Christian Grün <christian.gruen at gmail.com> wrote: > Good evening Daniël, > > I have introduced the suggested optimization, considering some more > cases like $p = (1 to 10), $p >= 1 and $p <= 3 etc. I would be pleased > if you could check out the latest snapshot and do some testing. > > Christian > > [1] http://files.basex.org/releases/latest/ > > > On Thu, Aug 14, 2014 at 9:11 AM, Daniël Knippers <dknippers at gmail.com> > wrote: > > Good morning, > > > > I wondered if there is room for optimization during the compilation of > the > > following query: > > > > let $oneBillion := 1000000000 > > for $x at $p in (1 to > > $oneBillion > > ) where $p = 1 return $x > > > > I would have expected this to be compiled into something like > > > > for $x in (1 to $oneBillion)[1] return $x > > > > Or simply > > > > > > (1 to $oneBillion)[1] > > > > Judging only from the execution times of the original query versus the > > optimized ones, it seems the sequence of 1 to one billion is entirely > > generated, which seems suboptimal in this case. > > > > Kind regards, > > Daniël Knippers >
Written for BaseX 7.9. BaseX may have changed since: please check the current documentation.