IndexHintTrait
The index a model hands the optimizer for the loop its list-family queries share.
The optimizer chooses an index from estimates, and an estimate can be wrong in
the one direction that costs : a list narrowed on a very selective value and
ordered on another field may be read through the index of the order, every
document of the collection walked to keep a handful, where the index of the
narrowing value would have read that handful alone. The EXPLAIN says which
index a query takes โ see wiki/en/db/explain-and-profiling.md.
AQL::INDEX_HINT => 'byOwnerDue' , // a name, or a list of names in order of preference
AQL::FORCE_INDEX_HINT => true , // optional : an error rather than another index
becomes, on the loop of the list :
FOR doc IN @@collection OPTIONS {"forceIndexHint":true,"indexHint":"byOwnerDue"}
and, on the loop of its count, facet counts and bounds :
FOR doc IN @@collection OPTIONS {"indexHint":"byOwnerDue"}
๐ The list, the count, the facet counts and the bounds receive the same index, because they share their loop (FilteredScopeTrait) : a list and its count read the same set, and the count is served by the same index.
๐จ But the list alone FORCES it. An index may serve the list for its SORT
alone โ [ due ] for ยซ the tasks of one owner, by due date ยป โ, and the count,
the facet counts and the bounds sort nothing : forced on them, such an index is
one they cannot use, and the server refuses the query (ยซ could not use index hint
to serve query ยป, measured live). They receive the hint as a preference, which
the optimizer takes whenever the index serves their filter.
๐จ Not on a search. When an active ?search= iterates the View, the loop runs
over the View, which knows no indexHint : the option is left out there.
โ ๏ธ forceIndexHint makes the query fail when the index is missing, or cannot
serve it. Declare the index in AQL::INDEXES before forcing it. Without
forceIndexHint, an index the optimizer cannot use is a preference it ignores.
Nothing declared โ the default โ leaves every query exactly as it was.
Tags
Table of Contents
Properties
- $forceIndexHint : bool|null
- Whether the {@see $indexHint} is mandatory. `null` leaves the server's default (`false`).
- $indexHint : string|array<int, string>|null
- The index the loop is handed : a name, or a list of names in order of preference. `null` โ the default โ hands none.
Methods
- initializeIndexHint() : $this
- Initialize the index handed to the optimizer, and whether it is mandatory.
- indexHintOptions() : array<string, mixed>|null
- The options of the loop over the collection, or null when no index is handed.
Properties
$forceIndexHint
Whether the {@see $indexHint} is mandatory. `null` leaves the server's default (`false`).
public
bool|null
$forceIndexHint
= null
$indexHint
The index the loop is handed : a name, or a list of names in order of preference. `null` โ the default โ hands none.
public
string|array<int, string>|null
$indexHint
= null
Methods
initializeIndexHint()
Initialize the index handed to the optimizer, and whether it is mandatory.
public
initializeIndexHint([array<string|int, mixed> $init = [] ]) : $this
Parameters
- $init : array<string|int, mixed> = []
-
Reads
AQL::INDEX_HINTandAQL::FORCE_INDEX_HINT.
Return values
$thisindexHintOptions()
The options of the loop over the collection, or null when no index is handed.
protected
indexHintOptions([bool $forcible = true ]) : array<string, mixed>|null
โ ๏ธ forceIndexHint alone, without an index to force, hands nothing.
Parameters
- $forcible : bool = true
-
Whether this loop may carry
forceIndexHintโ the list's does, the loops that sort nothing do not.