Amazon Neptune
User Guide (API Version 2017-11-29)

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 additional triple patterns in the Amazon Neptune namespace http://aws.amazon.com/neptune/vocab/v01/QueryHints#.

Note

The examples in this section include the namespace as a 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 a joinOrder 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 for convenience.

  • 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.