[ 
https://issues.apache.org/jira/browse/JENA-638?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Andy Seaborne updated JENA-638:
-------------------------------

    Description: 
There is a new opportunity for transformation of slice/order to a TopN 
execution.

Currently, {{OrderByDistinctApplication}} is done after TopN.

If {{OrderByDistinctApplication}} is done before TopN optimization, then the 
algebra may have the form slice/order/distinct/project which is can be executed 
as a TopN query. This form does not appear in algebra expressions directly from 
queries; the modifier order is slice/distinct/project/order which, in general, 
is not safe for TopN execution.

However, {{OrderByDistinctApplication}} picks out a condition for it's own 
optimization, that leaves the resultant algebra as further transformable to 
TopN.

Currently:

{noformat}
SELECT DISTINCT  ?z
WHERE
  { ?s ?p ?z }
ORDER BY ?z
LIMIT   5
{noformat}
Compiled to algebra:
{noformat}
(slice _ 5
  (distinct
    (project (?z)
      (order (?z)
        (bgp (triple ?s ?p ?z))))))
{noformat}
After optimization: TopN did not apply:
{noformat}
(slice _ 5
  (order (?z)
    (distinct
      (project (?z)
        (bgp (triple ?s ?p ?z))))))
{noformat}
but this is possible:
{noformat}
(top (5 ?z)
  (distinct
    (project (?z)
      (bgp (triple ?s ?p ?z)))))
{noformat}


  was:
There is a new opportunity for transformation of slice/order to a TopN 
execution.

Currently, {{OrderByDistinctApplication{{ is done after TopN.

If {{OrderByDistinctApplication}} is done before TopN optimization, then the 
algebra may have the form slice/order/distinct/project which is can be executed 
as a TopN query. This form does not appear in algebra expressions directly from 
queries; the modifier order is slice/distinct/project/order which, in general, 
is not safe for TopN execution.

However, {{OrderByDistinctApplication}} picks out a condition for it's own 
optimization, that leaves the resultant algebra as further transformable to 
TopN.

Currently:

{noformat}
SELECT DISTINCT  ?z
WHERE
  { ?s ?p ?z }
ORDER BY ?z
LIMIT   5
{noformat}
Compiled to algebra:
{noformat}
(slice _ 5
  (distinct
    (project (?z)
      (order (?z)
        (bgp (triple ?s ?p ?z))))))
{noformat}
After optimization: TopN did not apply:
{noformat}
(slice _ 5
  (order (?z)
    (distinct
      (project (?z)
        (bgp (triple ?s ?p ?z))))))
{noformat}
but this is possible:
{noformat}
(top (5 ?z)
  (distinct
    (project (?z)
      (bgp (triple ?s ?p ?z)))))
{noformat}



> Optimization OrderByDistinctApplication can enable better TopN optimization.
> ----------------------------------------------------------------------------
>
>                 Key: JENA-638
>                 URL: https://issues.apache.org/jira/browse/JENA-638
>             Project: Apache Jena
>          Issue Type: Improvement
>          Components: ARQ, Optimizer
>    Affects Versions: Jena 2.11.1
>            Reporter: Andy Seaborne
>            Assignee: Andy Seaborne
>
> There is a new opportunity for transformation of slice/order to a TopN 
> execution.
> Currently, {{OrderByDistinctApplication}} is done after TopN.
> If {{OrderByDistinctApplication}} is done before TopN optimization, then the 
> algebra may have the form slice/order/distinct/project which is can be 
> executed as a TopN query. This form does not appear in algebra expressions 
> directly from queries; the modifier order is slice/distinct/project/order 
> which, in general, is not safe for TopN execution.
> However, {{OrderByDistinctApplication}} picks out a condition for it's own 
> optimization, that leaves the resultant algebra as further transformable to 
> TopN.
> Currently:
> {noformat}
> SELECT DISTINCT  ?z
> WHERE
>   { ?s ?p ?z }
> ORDER BY ?z
> LIMIT   5
> {noformat}
> Compiled to algebra:
> {noformat}
> (slice _ 5
>   (distinct
>     (project (?z)
>       (order (?z)
>         (bgp (triple ?s ?p ?z))))))
> {noformat}
> After optimization: TopN did not apply:
> {noformat}
> (slice _ 5
>   (order (?z)
>     (distinct
>       (project (?z)
>         (bgp (triple ?s ?p ?z))))))
> {noformat}
> but this is possible:
> {noformat}
> (top (5 ?z)
>   (distinct
>     (project (?z)
>       (bgp (triple ?s ?p ?z)))))
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)

Reply via email to