SPARQL query hints
You can use query hints to specify optimization and evaluation strategies for a particular SPARQL query in Amazon Neptune.
Query hints are expressed using additional triple patterns that are embedded in the SPARQL query with the following parts:
scope
hint
value
scope – Determines the part of the query that the query hint applies to, such as a certain group in the query or the full query.
hint – Identifies the type of the hint to apply.
value – Determines the behavior of the system aspect under consideration.
The query hints and scopes are exposed as predefined terms in the Amazon Neptune
namespace http://aws.amazon.com/neptune/vocab/v01/QueryHints#
. The examples in this
section include the namespace as a hint
prefix that is defined and
included in the query:
PREFIX hint: <http://aws.amazon.com/neptune/vocab/v01/QueryHints#>
For example, the following shows how to include a joinOrder
hint in a
SELECT
query:
PREFIX hint: <http://aws.amazon.com/neptune/vocab/v01/QueryHints#> SELECT
...
{ hint:Query hint:joinOrder "Ordered" ....
}
The preceding query instructs the Neptune engine to evaluate joins in the query in the given order and disables any automatic reordering.
Consider the following when using query hints:
You can combine different query hints in a single query. For example, you can use the
bottomUp
query hint to annotate a subquery for bottom-up evaluation and ajoinOrder
query hint to fix the join order inside the subquery.You can use the same query hint multiple times, in different non-overlapping scopes.
Query hints are hints. Although the query engine generally aims to consider given query hints, it might also ignore them.
Query hints are semantics preserving. Adding a query hint does not change the output of the query (except for the potential result order when no ordering guarantees are given—that is, when the result order is not explicitly enforced by using ORDER BY).
The following sections provide more information about the available query hints and their usage in Neptune.
Topics
Scope of SPARQL query hints in Neptune
The following table shows the available scopes, associated hints, and descriptions for
SPARQL query hints in Amazon Neptune. The hint
prefix in these entries represents
the Neptune namespace for hints:
PREFIX hint: <http://aws.amazon.com/neptune/vocab/v01/QueryHints#>
Scope | Supported Hint | Description |
---|---|---|
hint:Query |
The query hint applies to the whole query. | |
hint:Query |
The time-out value applies to the entire query. | |
hint:Query |
Type promotion is disabled for the entire query. | |
hint:Query |
The query ID value applies to the entire query. | |
hint:Query |
Use of the DFE is enabled (or disabled) for the entire query. | |
hint:Group |
The query hint applies to the top-level elements in the specified group, but not to nested elements (such as subqueries) or parent elements. | |
hint:SubQuery |
The hint is specified and applied to a nested SELECT subquery. The subquery is evaluated independently, without considering solutions computed before the subquery. |