You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Zen 98052 <z9...@outlook.com> on 2016/06/03 17:28:48 UTC
optimize a query
Hi,
Is there a way to rewrite this Sparql query to run more efficiently?
SELECT ?s
WHERE
{
?s <http://foo/bar> ?o1, ?o2 .
?o2 <http://foo/id> "some id" .
FILTER (?o1 != ?o2) .
}
It seems to me this can be optimized, I am still trying to figure it out.
Thanks,
Z
Re: optimize a query
Posted by Zen 98052 <z9...@outlook.com>.
Thanks Andy for the pointer!
I turned off that flag, and it got pushed to BGPs as expected.
Before that, I also tried rewrite the query, and I got same behavior like turning off that flag.
The re-written query is:
SELECT ?s
WHERE
{
?o2 <http://foo/id> "some id" .
?s <http://foo/bar> ?o2 .
?s <http://foo/bar> ?o1 .
FILTER (?o1 != ?o2) .
}
Thanks,
Z
________________________________
From: Andy Seaborne <an...@apache.org>
Sent: Friday, June 3, 2016 6:03:02 PM
To: users@jena.apache.org
Subject: Re: optimize a query
On 03/06/16 18:28, Zen 98052 wrote:
> Hi,
>
> Is there a way to rewrite this Sparql query to run more efficiently?
>
>
> SELECT ?s
>
> WHERE
>
> {
>
> ?s <http://foo/bar> ?o1, ?o2 .
>
> ?o2 <http://foo/id> "some id" .
>
> FILTER (?o1 != ?o2) .
> }
>
>
> It seems to me this can be optimized, I am still trying to figure it out.
Yes - by the filter placement transform TransformFilterPlacement
There is no need to wait for ?o2 <http://foo/id> "some id" .
The filter can be executed after ?s <http://foo/bar> ?o1, ?o2 . as both
?o1 and ?o2 are bound.
BGPs are left alone if
context.isTrueOrUndef(ARQ.optFilterPlacementBGP) ;
See Optimize.rewrite
TDB turns it off by setting that context values on each dataset:
dsg.getContext().set(ARQ.optFilterPlacementBGP, false) ;
(then does it itself in "NodeId" space, not in "Node")
You can experiment using the command line tools:
arq.qparse --print=opt --query=YourQuery.rq
Andy
>
>
>
> Thanks,
>
> Z
>
Re: optimize a query
Posted by Andy Seaborne <an...@apache.org>.
On 03/06/16 18:28, Zen 98052 wrote:
> Hi,
>
> Is there a way to rewrite this Sparql query to run more efficiently?
>
>
> SELECT ?s
>
> WHERE
>
> {
>
> ?s <http://foo/bar> ?o1, ?o2 .
>
> ?o2 <http://foo/id> "some id" .
>
> FILTER (?o1 != ?o2) .
> }
>
>
> It seems to me this can be optimized, I am still trying to figure it out.
Yes - by the filter placement transform TransformFilterPlacement
There is no need to wait for ?o2 <http://foo/id> "some id" .
The filter can be executed after ?s <http://foo/bar> ?o1, ?o2 . as both
?o1 and ?o2 are bound.
BGPs are left alone if
context.isTrueOrUndef(ARQ.optFilterPlacementBGP) ;
See Optimize.rewrite
TDB turns it off by setting that context values on each dataset:
dsg.getContext().set(ARQ.optFilterPlacementBGP, false) ;
(then does it itself in "NodeId" space, not in "Node")
You can experiment using the command line tools:
arq.qparse --print=opt --query=YourQuery.rq
Andy
>
>
>
> Thanks,
>
> Z
>
Re: optimize a query
Posted by Zen 98052 <z9...@outlook.com>.
I also notice a weirdness this BGP pattern ?o2 <http://foo/id> "some id" is somehow not passed by Jena, hence it never got optimized [:(]
The prime suspect is the FILTER line, which if I remove it, or change it to FILTER (?o1 = ?o2) (note this is just for experimental purpose since it's not making sense), then I can see pattern ?o2 <http://foo/id> "some id" is being passed now. Weird..
________________________________
From: Zen 98052 <z9...@outlook.com>
Sent: Friday, June 3, 2016 1:28:48 PM
To: users@jena.apache.org
Subject: optimize a query
Hi,
Is there a way to rewrite this Sparql query to run more efficiently?
SELECT ?s
WHERE
{
?s <http://foo/bar> ?o1, ?o2 .
?o2 <http://foo/id> "some id" .
FILTER (?o1 != ?o2) .
}
It seems to me this can be optimized, I am still trying to figure it out.
Thanks,
Z