

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# `queryTimeout` SPARQL 查詢提示
<a name="sparql-query-hints-queryTimeout"></a>

`queryTimeout` 查詢提示指定的逾時比資料庫參數群組中設定的 `neptune_query_timeout` 值短。

如果查詢因為此提示而終止，則會擲出 `TimeLimitExceededException`，並帶有 `Operation terminated (deadline exceeded)` 訊息。

## `queryTimeout` SPARQL 提示語法
<a name="sparql-query-hints-queryTimeout-syntax"></a>

```
PREFIX hint: <http://aws.amazon.com/neptune/vocab/v01/QueryHints#>
SELECT ... WHERE {
    hint:Query hint:queryTimeout 10 .
    # OR
    hint:Query hint:queryTimeout "10" .
    # OR
    hint:Query hint:queryTimeout "10"^^xsd:integer .
 ...
}
```

逾時值以毫秒表示。

逾時值必須小於資料庫參數群組中設定的 `neptune_query_timeout` 值。否則，會擲出 `MalformedQueryException` 例外狀況，並帶有 `Malformed query: Query hint 'queryTimeout' must be less than neptune_query_timeout DB Parameter Group` 訊息。

`queryTimeout` 查詢提示應該在主要查詢的 `WHERE` 子句中指定，或在其中一個子查詢的 `WHERE` 子句中指定，如下例所示。

它必須在所有查詢/子查詢和 SPARQL Updates 區段 (例如 INSERT 和 DELETE) 上設定一次。否則，會擲出 `MalformedQueryException` 例外狀況，並帶有 `Malformed query: Query hint 'queryTimeout' must be set only once` 訊息。

**可用範圍**

`queryTimeout` 提示可同時套用至 SPARQL 查詢和更新。
+ 在 SPARQL 查詢中，它可以出現在主要查詢或子查詢的 WHERE 子句中。
+ 在 SPARQL 更新中，可以在 INSERT、DELETE 或 WHERE 子句中設定。如果有多個更新子句，則只能在其中一個設定。

如需更多查詢提示範圍的詳細資訊，請參閱 [Neptune 中的 SPARQL 查詢提示範圍](sparql-query-hints.md#sparql-query-hints-scope)。

## `queryTimeout` SPARQL 提示範例
<a name="sparql-query-hints-queryTimeout-example"></a>

下例在 `UPDATE` 查詢的主要 `WHERE` 子句中使用 `hint:queryTimeout`：

```
PREFIX hint: <http://aws.amazon.com/neptune/vocab/v01/QueryHints#>
INSERT {
    ?s ?p ?o
} WHERE {
    hint:Query hint:queryTimeout 100 .
    ?s ?p ?o .
}
```

在此，`hint:queryTimeout` 位在子查詢的 `WHERE` 子句中：

```
PREFIX hint: <http://aws.amazon.com/neptune/vocab/v01/QueryHints#>
SELECT * {
   ?s ?p ?o .
   {
      SELECT ?s WHERE {
         hint:Query hint:queryTimeout 100 .
         ?s ?p1 ?o1 .
      }
   }
}
```