8000 add documentation for query timeout (#219) · arangodb/docs@247c8a9 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Dec 13, 2023. It is now read-only.

Commit 247c8a9

Browse files
ObiWahnSimran-B
authored andcommitted
add documentation for query timeout (#219)
1 parent 9f91f03 commit 247c8a9

File tree

2 files changed

+52
-11
lines changed

2 files changed

+52
-11
lines changed

3.6/aql/invocation-with-arangosh.md

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
layout: default
3-
description: Within the ArangoDB shell, the _query and _createStatement methods of thedb object can be used to execute AQL queries
3+
description: Within the ArangoDB shell, the _query and _createStatement methods of the db object can be used to execute AQL queries
44
---
55
Executing queries from Arangosh
66
===============================
@@ -16,6 +16,7 @@ One can execute queries with the *_query* method of the *db* object.
1616
This will run the specified query in the context of the currently
1717
selected database and return the query results in a cursor. The results of the cursor
1818
can be printed using its *toArray* method:
19+
1920
{% arangoshexample examplevar="examplevar" script="script" result="result" %}
2021
@startDocuBlockInline 01_workWithAQL_all
2122
@EXAMPLE_ARANGOSH_OUTPUT{01_workWithAQL_all}
@@ -27,10 +28,12 @@ can be printed using its *toArray* method:
2728
@endDocuBlock 01_workWithAQL_all
2829
{% endarangoshexample %}
2930
{% include arangoshexample.html id=examplevar script=script result=result %}
31+
3032
### db._query Bind parameters
3133

3234
To pass bind parameters into a query, they can be specified as second argument to the
3335
*_query* method:
36+
3437
{% arangoshexample examplevar="examplevar" script="script" result="result" %}
3538
@startDocuBlockInline 02_workWithAQL_bindValues
3639
@EXAMPLE_ARANGOSH_OUTPUT{02_workWithAQL_bindValues}
@@ -43,6 +46,7 @@ To pass bind parameters into a query, they can be specified as second argument t
4346
@endDocuBlock 02_workWithAQL_bindValues
4447
{% endarangoshexample %}
4548
{% include arangoshexample.html id=examplevar script=script result=result %}
49+
4650
### ES6 template strings
4751

4852
It is also possible to use ES6 template strings for generating AQL queries. There is
@@ -59,6 +63,7 @@ aql`FOR c IN mycollection FILTER c._key == ${key} RETURN c._key`;
5963
}
6064
}
6165
```
66+
6267
{% arangoshexample examplevar="examplevar" script="script" result="result" %}
6368
@startDocuBlockInline 02_workWithAQL_aqlQuery
6469
@EXAMPLE_ARANGOSH_OUTPUT{02_workWithAQL_aqlQuery}
@@ -70,8 +75,10 @@ aql`FOR c IN mycollection FILTER c._key == ${key} RETURN c._key`;
7075
@endDocuBlock 02_workWithAQL_aqlQuery
7176
{% endarangoshexample %}
7277
{% include arangoshexample.html id=examplevar script=script result=result %}
73-
Arbitrary JavaScript expressions can be used in queries that are generated with the
78+
79+
Arbitrary JavaScript expressions can be used in queries that are generated with the
7480
*aql* template string generator. Collection objects are handled automatically:
81+
7582
{% arangoshexample examplevar="examplevar" script="script" result="result" %}
7683
@startDocuBlockInline 02_workWithAQL_aqlCollectionQuery
7784
@EXAMPLE_ARANGOSH_OUTPUT{02_workWithAQL_aqlCollectionQuery}
@@ -82,13 +89,15 @@ Arbitrary JavaScript expressions can be used in queries that are generated with
8289
@endDocuBlock 02_workWithAQL_aqlCollectionQuery
8390
{% endarangoshexample %}
8491
{% include arangoshexample.html id=examplevar script=script result=result %}
92+
8593
Note: data-modification AQL queries normally do not return a result (unless the AQL query
8694
contains an extra *RETURN* statement). When not using a *RETURN* statement in the query, the
8795
*toArray* method will return an empty array.
8896

8997
### Statistics and extra Information
90-
98+
9199
It is always possible to retrieve statistics for a query with the *getExtra* method:
100+
92101
{% arangoshexample examplevar="examplevar" script="script" result="result" %}
93102
@startDocuBlockInline 03_workWithAQL_getExtra
94103
@EXAMPLE_ARANGOSH_OUTPUT{03_workWithAQL_getExtra}
@@ -100,6 +109,7 @@ It is always possible to retrieve statistics for a query with the *getExtra* met
100109
@endDocuBlock 03_workWithAQL_getExtra
101110
{% endarangoshexample %}
102111
{% include arangoshexample.html id=examplevar script=script result=result %}
112+
103113
The meaning of the statistics values is described in [Execution statistics](execution-and-performance-query-statistics.html).
104114
You also will find warnings in here; If you're designing queries on the shell be sure to also look at it.
105115

@@ -111,6 +121,7 @@ allowed to use. When a single AQL query reaches the specified limit value,
111121
the query will be aborted with a *resource limit exceeded* exception. In a
112122
cluster, the memory accounting is done per shard, so the limit value is
113123
effectively a memory limit per query per shard.
124+
114125
{% arangoshexample examplevar="examplevar" script="script" result="result" %}
115126
@startDocuBlockInline 02_workWithAQL_memoryLimit
116127
@EXAMPLE_ARANGOSH_OUTPUT{02_workWithAQL_memoryLimit}
@@ -122,6 +133,7 @@ effectively a memory limit per query per shard.
122133
@endDocuBlock 02_workWithAQL_memoryLimit
123134
{% endarangoshexample %}
124135
{% include arangoshexample.html id=examplevar script=script result=result %}
136+
125137
If no memory limit is specified, then the server default value (controlled by
126138
startup option *--query.memory-limit* will be used for restricting the maximum amount
127139
of memory the query can use. A memory limit value of *0* means that the maximum
@@ -170,6 +182,9 @@ There are further options that can be passed in the *options* attribute of the *
170182
after the query is finished.
171183
The default value is *false*
172184

185+
- *timeout*: The query has to be executed within the given timeout or it will be killed.
186+
The value is specified in seconds. The default value is *0.0* (no timeout).
187+
173188
The following additional attributes can be passed to queries in the RocksDB storage engine:
174189

175190
- *maxTransactionSize*: transaction size limit in bytes
@@ -196,6 +211,7 @@ The *_query* method is a shorthand for creating an ArangoStatement object,
196211
executing it and iterating over the resulting cursor. If more control over the
197212
result set iteration is needed, it is recommended to first create an
198213
ArangoStatement object as follows:
214+
199215
{% arangoshexample examplevar="examplevar" script="script" result="result" %}
200216
@startDocuBlockInline 04_workWithAQL_statements1
201217
@EXAMPLE_ARANGOSH_OUTPUT{04_workWithAQL_statements1}
@@ -205,7 +221,9 @@ ArangoStatement object as follows:
205221
@endDocuBlock 04_workWithAQL_statements1
206222
{% endarangoshexample %}
207223
{% include arangoshexample.html id=examplevar script=script result=result %}
224+
208225
To execute the query, use the *execute* method of the statement:
226+
209227
{% arangoshexample examplevar="examplevar" script="script" result="result" %}
210228
@startDocuBlockInline 05_workWithAQL_statements2
211229
@EXAMPLE_ARANGOSH_OUTPUT{05_workWithAQL_statements2}
@@ -215,12 +233,14 @@ To execute the query, use the *execute* method of the statement:
215233
@endDocuBlock 05_workWithAQL_statements2
216234
{% endarangoshexample %}
217235
{% include arangoshexample.html id=examplevar script=script result=result %}
236+
218237
### Cursors
219238

220239
Once the query executed the query results are available in a cursor.
221240
The cursor can return all its results at once using the *toArray* method.
222241
This is a short-cut that you can use if you want to access the full result
223242
set without iterating over it yourself.
243+
224244
{% arangoshexample examplevar="examplevar" script="script" result="result" %}
225245
@startDocuBlockInline 05_workWithAQL_statements3
226246
@EXAMPLE_ARANGOSH_OUTPUT{05_workWithAQL_statements3}
@@ -232,7 +252,6 @@ set without iterating over it yourself.
232252
{% endarangoshexample %}
233253
{% include arangoshexample.html id=examplevar script=script result=result %}
234254

235-
236255
Cursors can also be used to iterate over the result set document-by-document.
237256
To do so, use the *hasNext* and *next* methods of the cursor:
238257
{% arangoshexample examplevar="examplevar" script="script" result="result" %}
@@ -245,17 +264,19 @@ To do so, use the *hasNext* and *next* methods of the cursor:
245264
@endDocuBlock 05_workWithAQL_statements4
246265
{% endarangoshexample %}
247266
{% include arangoshexample.html id=examplevar script=script result=result %}
267+
248268
Please note that you can iterate over the results of a cursor only once, and that
249269
the cursor will be empty when you have fully iterated over it. To iterate over
250270
the results again, the query needs to be re-executed.
251-
271+
252272
Additionally, the iteration can be done in a forward-only fashion. There is no
253273
backwards iteration or random access to elements in a cursor.
254274

255275
### ArangoStatement parameters binding
256276

257277
To execute an AQL query using bind parameters, you need to create a statement first
258278
and then bind the parameters to it before execution:
279+
259280
{% arangoshexample examplevar="examplevar" script="script" result="result" %}
260281
@startDocuBlockInline 05_workWithAQL_statements5
261282
@EXAMPLE_ARANGOSH_OUTPUT{05_workWithAQL_statements5}
@@ -268,8 +289,10 @@ and then bind the parameters to it before execution:
268289
@endDocuBlock 05_workWithAQL_statements5
269290
{% endarangoshexample %}
270291
{% include arangoshexample.html id=examplevar script=script result=result %}
292+
271293
The cursor results can then be dumped or iterated over as usual, e.g.:
272-
{% arangoshexample examplevar="examplevar" script="script" result="result" %}
294+
295+
{% arangoshexample examplevar="examplevar" script="script" result="result" %}
273296
@startDocuBlockInline 05_workWithAQL_statements6
274297
@EXAMPLE_ARANGOSH_OUTPUT{05_workWithAQL_statements6}
275298
~var stmt = db._createStatement( { "query": "FOR i IN [ @one, @two ] RETURN i * 2" } );
@@ -281,7 +304,9 @@ The cursor results can then be dumped or iterated over as usual, e.g.:
281304
@endDocuBlock 05_workWithAQL_statements6
282305
{% endarangoshexample %}
283306
{% include arangoshexample.html id=examplevar script=script result=result %}
284-
or
307+
308+
or
309+
285310
{% arangoshexample examplevar="examplevar" script="script" result="result" %}
286311
@startDocuBlockInline 05_workWithAQL_statements7
287312
@EXAMPLE_ARANGOSH_OUTPUT{05_workWithAQL_statements7}
@@ -294,9 +319,11 @@ or
294319
@endDocuBlock 05_workWithAQL_statements7
295320
{% endarangoshexample %}
296321
{% include arangoshexample.html id=examplevar script=script result=result %}
322+
297323
Please note that bind parameters can also be passed into the *_createStatement* method directly,
298324
making it a bit more convenient:
299-
{% arangoshexample examplevar="examplevar" script="script" result="result" %}
325+
326+
{% arangoshexample examplevar="examplevar" script="script" result="result" %}
300327
@startDocuBlockInline 05_workWithAQL_statements8
301328
@EXAMPLE_ARANGOSH_OUTPUT{05_workWithAQL_statements8}
302329
|stmt = db._createStatement( {
@@ -310,11 +337,13 @@ making it a bit more convenient:
310337
@endDocuBlock 05_workWithAQL_statements8
311338
{% endarangoshexample %}
312339
{% include arangoshexample.html id=examplevar script=script result=result %}
340+
313341
### Counting with a cursor
314-
342+
315343
Cursors also optionally provide the total number of results. By default, they do not.
316344
To make the server return the total number of results, you may set the *count* attribute to
317345
*true* when creating a statement:
346+
318347
{% arangoshexample examplevar="examplevar" script="script" result="result" %}
319348
@startDocuBlockInline 05_workWithAQL_statements9
320349
@EXAMPLE_ARANGOSH_OUTPUT{05_workWithAQL_statements9}
@@ -325,8 +354,10 @@ To make the server return the total number of results, you may set the *count* a
325354
@endDocuBlock 05_workWithAQL_statements9
326355
{% endarangoshexample %}
327356
{% include arangoshexample.html id=examplevar script=script result=result %}
357+
328358
After executing this query, you can use the *count* method of the cursor to get the
329359
number of total results from the result set:
360+
330361
{% arangoshexample examplevar="examplevar" script="script" result="result" %}
331362
@startDocuBlockInline 05_workWithAQL_statements10
332363
@EXAMPLE_ARANGOSH_OUTPUT{05_workWithAQL_statements10}
@@ -337,6 +368,7 @@ number of total results from the result set:
337368
@endDocuBlock 05_workWithAQL_statements10
338369
{% endarangoshexample %}
339370
{% include arangoshexample.html id=examplevar script=script result=result %}
371+
340372
Please note that the *count* method returns nothing if you did not specify the *count*
341373
attribute when creating the query.
342374

@@ -354,13 +386,13 @@ This may change in the future. Future versions of ArangoDB may create result set
354386
on the server-side and may be able to apply optimizations if a result set is not fully fetched by
355387
a client.
356388

357-
358389
### Using cursors to obtain additional information on internal timings
359390

360391
Cursors can also optionally provide statistics of the internal execution phases. By default, they do not.
361392
To get to know how long parsing, optimization, instantiation and execution took,
362393
make the server return that by setting the *profile* attribute to
363394
*true* when creating a statement:
395+
364396
{% arangoshexample examplevar="examplevar" script="script" result="result" %}
365397
@startDocuBlockInline 06_workWithAQL_statements11
366398
@EXAMPLE_ARANGOSH_OUTPUT{06_workWithAQL_statements11}
@@ -371,8 +403,10 @@ make the server return that by setting the *profile* attribute to
371403
@endDocuBlock 06_workWithAQL_statements11
372404
{% endarangoshexample %}
373405
{% include arangoshexample.html id=examplevar script=script result=result %}
406+
374407
After executing this query, you can use the *getExtra()* method of the cursor to get the
375408
produced statistics:
409+
376410
{% arangoshexample examplevar="examplevar" script="script" result="result" %}
377411
@startDocuBlockInline 06_workWithAQL_statements12
378412
@EXAMPLE_ARANGOSH_OUTPUT{06_workWithAQL_statements12}
@@ -383,11 +417,13 @@ produced statistics:
383417
@endDocuBlock 06_workWithAQL_statements12
384418
{% endarangoshexample %}
385419
{% include arangoshexample.html id=examplevar script=script result=result %}
420+
386421
Query validation
387422
----------------
388423

389424
The *_parse* method of the *db* object can be used to parse and validate a
390425
query syntactically, without actually executing it.
426+
391427
{% arangoshexample examplevar="examplevar" script="script" result="result" %}
392428
@startDocuBlockInline 06_workWithAQL_statements13
393429
@EXAMPLE_ARANGOSH_OUTPUT{06_workWithAQL_statements13}

3.6/release-notes-new-features36.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,12 @@ into a set of equal-distance buckets.
226226

227227
### Miscellaneous AQL changes
228228

229-
ArangoDB 3.6 provides a new AQL function `GEO_AREA` for area calculations.
229+
ArangoDB 3.6 provides the following new AQL functionality:
230+
231+
- a function `GEO_AREA()` for [area calculations](aql/functions-geo.html#geo_area)
232+
- a [query option](aql/invocation-with-arangosh.html#setting-options) `timeout`
233+
to restrict the execution to a given time in seconds. Also see
234+
[HTTP API](http/aql-query-cursor-accessing-cursors.html#create-cursor).
230235

231236
HTTP API
232237
--------

0 commit comments

Comments
 (0)
0