Overview
Indexing, or property indexing, is a technique used in Ultipa to speed up query performance by creating indexes on specific properties of nodes and edges. This allows the database to quickly locate and retrieve data based on indexed properties. Indexes are particularly beneficial for large datasets, as they optimize the filtering of specific property values without needing to scan the entire graph.
Index Types
Ultipa supports single index on one property and composite index which involve multiple properties from a schema.
Showing Indexes
To retrieve information about indexes in the current graphset:
// Shows all indexes
show().index()
// Shows all node indexes
show().node_index()
// Shows all edge indexes
show().edge_index()
The information about indexes is organized into tables _nodeIndex
and _edgeIndex
. Each table includes fields that provide essential details about each index:
Field |
Description |
---|---|
id |
The id of the index. |
name |
The name assigned to the index. |
properties |
The properties involved in the index. |
schema |
The schema of the properties involved in the index. |
status |
The current state of the index, which can be DONE or CREATING . |
Creating Indexes
You can create one or more indexes using a single create()
statement. Each index is specified by chaining a node_index()
or edge_index()
method. Note that each property can only have one single index. The index creation runs as a job, you may run show().job(<id?>)
afterward to verify the success of the creation.
System properties in Ultipa are inherently optimized for query performance and have built-in efficiencies. However, they do not support additional indexing.
create()
.node_index(@<schema>.<property>(<length?>), "<indexName>")
.edge_index(@<schema>.<property>(<length?>), "<indexName>")
.node_index(@<schema>(<property1>(<length1?>), <property2>(<length2?>), ...), "<indexName>")
.edge_index(@<schema>(<property1>(<length1?>), <property2>(<length2?>), ...), "<indexName>")
...
Method | Param | Description |
---|---|---|
node_index() or edge_index() |
@<schema>.<property>(<length?>) or @<schema>(<property1>(<length1?>), <property2>(<length2?>),...) |
For a single index, specifies the property and its schema using @<schema>.<property> .For a composite index, lists multiple properties within a schema using @<schema>(<property1>, <property2>,...) .In both index types, if the property type is string or text , you must specify the maximum string length[1] in search to enable the index. This prevents performance degradation that can occur when indexing long text fields. |
<indexName> |
The name of the index. Names must be unique among nodes and among edges, but a node index and an edge index may share the same name. |
[1] The length of one Chinese character is 3.
To create single index balance
for node property @card.balance
:
create().node_index(@card.balance, "balance")
To create single index cName
for edge property @card.name
(string
type), restricting the maximum search string length as 10
:
create().edge_index(@card.name(10), "cName")
To create composite index transAmountNotes
for properties amount
and notes
(text
type, restricting the maximum search string length as 10
) for @transfer
edges:
create().edge_index(@transfer(amount, notes(10)), "transAmountNotes")
To create multiple indexes:
create()
.node_index(@card.balance, "balance")
.edge_index(@transfer(amount, notes(10)), "transAmountNotes")
Dropping Indexes
You can drop one or more indexes using a single drop()
statement. Each index is specified by chaining a node_index()
or edge_index()
method. Dropping an index does not affect the actual property values stored in shards. However, deleting a property will automatically remove its associated indexes.
To drop the node index balance
:
drop().node_index("balance")
To drop the edge index transAmountNotes
:
drop().edge_index("transAmountNotes")
To drop multiple indexes:
drop().node_index("balance").edge_index("transAmountNotes")
Using Indexes
Indexes are automatically applied when the corresponding properties are used in query filters, without the need for explicit declarations.
Leftmost Prefix Rule
The order of properties in a composite index matters — queries that match the leftmost properties of the index (i.e., the first property or the first few properties in the defined order) will benefit from the index.
For example:
create().node_index(@user(name(10),age), 'name_age')
find().nodes({@user.name == "Kavi" && @user.age > 20})
uses the index.find().nodes({@user.name == "Kavi"})
uses the index.find().nodes({@user.age > 20})
doesn't use the index.find().nodes({@user.name == "Kavi" && @user.age > 20 && @user.grade == 7})
uses the index, meanwhile it contains the filtering for the@user.grade
property which lacks an index.
String Length Limitation
For indexes with string
or text
properties, ensure the filter string length does not exceed the defined limit.
For example:
create().edge_index(@user.name(8), "Username")
The query below won't utilize the Username
index as the specified string exceeds the 8-character limit:
find().nodes({@user.name == "Aventurine"}) as n return n