Property Index Rule
Rule name: property_index (on by default, sixth in the pipeline, right after
Source Filter Pushdown).
What it rewrites
It records on a v()/e() start step which
property index the step reads instead of its label buckets,
and, for a condition the index answers exactly, drops that condition's
re-check. .profile() shows the choice on the start step:
v().has_label("person").has("title", "CEO") → v(labels: ["person"]).has("title", "CEO") [index: vertex person.title, exact]
v().has_label("person").has("age", P.gt(30)) → v(labels: ["person"]) [index: vertex person.age]
has("age", P.gt(30))
e().has_label("knows").has("weight", P.lt(0.5)) → e(labels: ["knows"]) [index: edge knows.weight]
has("weight", P.lt(0.5))
v().has_label("person") → v(labels: ["person"]).has("name", __.to_lower().is(P.eq("ada")))
.has("name", __.to_lower().is("ada")) [index: vertex person.name to_lower, exact]
v().has("name", "josh") → v().has("name", "josh") [index: vertex name, any label, exact]
v().has("name", "josh").count() → v().has("name", "josh").count() [index: vertex name, any label, exact] [count from index]
v().has("_owners", __.unfold().is("o1")) → v().has("_owners", __.unfold().is(P.eq("o1"))) [index: vertex _owners each, any label, exact]
v().has("_owners", __.unfold().is(P.gt("o1"))) → v() [index: vertex _owners each, any label]
has("_owners", __.unfold().is(P.gt("o1")))
v().has_label("doc") → v(labels: ["doc"]) [index: vertex doc.tags each to_lower]
.has("tags", __.unfold().to_lower().is(P.gte("x"))) has("tags", __.unfold().to_lower().is(P.gte("x")))
It looks at
- the
has(key, value)conditions Source Filter Pushdown folded into the start step (scalar values), and - the
has(key, P)steps in the run of pure filters (has,has_label,has_id,has_key,has_not) right after it, withP.eq,P.within,P.gt/gte/lt/lte,P.between,P.insideorP.outside, and - the
has(key, __.to_lower().is(P))steps in that run (TinkerPop'shas(key, traversal)with exactly that child,Pas above), which only an index with the transformto_loweron the key covers. Its slices areP's constants as given (the child compares the lowered value with them); it is covered only while that index has skipped no value (skipped0), because the child'sto_lower()fails on a non-string value and the scan must report that error. Anullconstant is not covered (to_lower()passes anullthrough, the index holds none). - the
has(key, __.unfold().is(P))steps in that run, covered by an index with the transformeach(one entry per list element) whatever it skipped (a nested list, a map's entries or a vector thatunfold()emits never equals or ranges with a scalar), andhas(key, __.unfold().to_lower().is(P))by["each", "to_lower"]while it skipped nothing. Any otherhas(key, traversal)ends the run of pure filters.
A condition on the whole value (a folded has(key, value), a has(key, P)) with no index of no
transform on the key is covered by an each index as a SUPERSET: lists holding the value are
candidates and the re-check of the whole value drops them; such an access is never exact.
A condition is covered when every label folded into the start step has an index on its key (of
the condition's transform: none for has(key, ..), to_lower for the lowered form), or when a
label-less index on the key exists: a
start step without labels can only read a label-less index; one with labels compares the sum
of its per-label estimates with the label-less index's estimate, the lower wins (a tie keeps the
per-label indexes), and with the label-less index it checks each candidate's labels. Of the
covered conditions the rule picks the most selective by the indexes' statistics (an equality: about
entries / distinct_values elements per index and value; a range: half the entries). A
unique index is read like any other index
(its statistics give an equality about one element; one that is not served, its data holding
repeated values, is never read).
Exact accesses
An access is exact (user decision 2026-11-08) when the index answers the condition it reads exactly, so no re-check could drop a candidate:
- every slice is a point (an equality, or each operand of
P.within) of a string, boolean, uuid or temporal value: a number slice spansint64andfloat64(a superset), andnulland ranges keep their re-check; - the index has no transform (a condition on the whole value), or
eachreadinghas(key, __.unfold().is(..))(an element is in the postings of each of its values once; the start step deduplicates several slices), orto_lower/["each", "to_lower"]readinghas(key, __.to_lower().is(..))/has(key, __.unfold().to_lower().is(..))(read only while the index skipped nothing, so in a reading queryto_lower()cannot fail and the lowered keys answer the condition; anullconstant is never served); not aneachindex read as a superset; - the query does not write at any level (no mutating step, in a child traversal neither: a write could change what the index holds while the plan reads it);
- the storage claims
StorageCapabilities::exact_property_index_lookups(the built-in graph, its read-only views and the wrappers that forward it do; a custom storage's lookups otherwise count as supersets).
Then the re-check of that one condition is dropped: a folded has(key, value) is no longer
checked on the candidates (the start step still shows it), a has step leaves the plan and the
start step shows it after its folded conditions, and the index marker reads , exact. Every other
condition is still checked, and so are the labels of a label-less index's candidates under a
start with labels. When nothing else is left (one slice, no other folded condition, and a
label-less index under a start without labels or the index of the start's single label) the
access is also countable, and Count Pushdown may fuse a following count()
into the start step, which the storage then answers from the index
(GraphStorage::count_by_property_index) without visiting the elements: .profile() shows
[count from index]. Should the storage not serve the index after all, the start step scans and
checks the answered condition itself, as the index keys it.
.profile() shows what happened at run time, not only what was planned: when the storage
declines a lookup (it lists the index but answers no candidates for it), the marker reads
, declined, scanned inside the brackets, and when it does not count a countable slice from the
index, [count from index declined] (the candidates were counted instead):
v(labels: ["person"]).has("name", "marko").count() [index: vertex person.name, exact, declined, scanned] [count from index declined]
The fact is recorded once per execution of the start step, never per element.
Why
The start step then reads only the elements whose value lies in the slices of the index, instead
of every element of its labels. The conditions it does not answer exactly are not removed: the
start step still checks its other folded conditions on each candidate and their has(key, P)
steps stay in the plan, so the result equals the scan's (only the order of the elements may
differ). An exact condition is not checked twice: the index is maintained exactly on every write
and rollback, it is trusted, and a wrong entry would show in the result instead of being hidden
by a re-check (the randomized differential tests compare every exact shape with the scan).
When it does not fire
- No index is declared (the rule then costs nothing), or one of the folded labels has none on the key and no label-less index covers it. Only indexes the storage serves count: an index of a type this version does not know (written by a newer version) is kept in the catalog but never read.
- The start step has no folded label (
v().has("title", "CEO")) and no label-less index covers the key, has ids folded (v("1").has_label(..): the ids are cheaper), or a fusedcount()/group_count(). - The condition is not served:
P.neq,P.without, text predicates, composites, a list or map value, a jpath key,NaN; ahas(key, traversal)whose child is not exactlyto_lower().is(P),unfold().is(P)orunfold().to_lower().is(P); a lowered form while its index skipped a non-string value.
g.with("optimizer.disabled", ["property_index"]) turns it off for one query, for example to
compare the plan with the label scan.