Hello Christian, Thanks for the response. I should have been more descriptive. I am not having issues just wanted to make sure I was using the best approach. I notice that I could accomplish the task two ways: subseqence(somequery, 0, 10)(somequery)[(1 to 10)]
My specific query was really insignificant. Basically I just wanted to ensure I was writing queries in a way where once all predicates are achieved the execution is terminated. On a side note. What would take a query a long time to compile? I'm seeing 60 second compilations coupled with 52ms execution times. Its really not an issues since this type of query would only be executed on 'schema' changes, but I was just curious if you had a comment on this from a BaseX perspective. - James
From: christian.gruen@gmail.com Date: Tue, 21 May 2013 23:24:20 +0200 Subject: Re: [basex-talk] Quick question regarding subsequences To: james.jw@hotmail.com CC: basex-talk@mailman.uni-konstanz.de
Hi James,
regarding your specific query, I’m afraid it’s probably too nested in order to simply say how it’s gonna be evaluated, so I would suggest to simply run the query, see what happens and check out the optimization steps int the query info. In general, I can confirm that the evaluation of a filter expression with a positional predicate will be stopped as soon as all results in the specified range have been returned. The following query demonstrates this behavior (it would run quite a while if the iteration were not interrupted):
(1 to 100000000000000000)[position() = 1 to 10]
Next, you may get better results if you move expressions out of a predicate if they may need to be evaluated multiple times:
let $key := $entityMetadata/property[@key = 'true']/@name return ($context//* [name() = $type] [data((*|@*)[name() = $key]) = $entityId] )[1]
In the given case, it might be unnecessary, as you want to stop evaluation after the first hit anyway.
I agree that each XQuery implementation may find different strategies to evaluate this query – and I’d like to add that it‘s often not possible to say what a specific implementation does, as optimization strategies change over time, and may also be dependent on the input data, available index structures, etc. For example, if multiple predicates are specified, we are trying to find and evaluate the cheapest predicate earlier than others, and this estimation also depends on the database statistics.
In a nutshell: you will often succeed in speeding up your queries by rewriting them. On the other hand, it’s sometimes impossible to say in advance if a query will be evaluated faster than another.
Hope this helps, Christian ___________________________
On Tue, May 21, 2013 at 9:42 PM, James Wright james.jw@hotmail.com wrote:
Hey,
In the BaseX implementation this query:
($context//*[name() = $type and data((*|@*)[name() = $entityMetadata/property[@key = 'true']/@name]) = $entityId])[1]
Will the query execute completely and then a 'subset' of 1 will be extracted, or will it only execute until it find the '1st' item that matches the query? Maybe this is a general XQuery question but I figured it was implementation specific.
- James
BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk