Indexes
Last updated
Was this helpful?
Last updated
Was this helpful?
Aidbox index management is in draft stage. API will change.
Database indexes are essential for performance. In particular you will need indexes to speed up search requests.
Aidbox provides mechanisms to
manage indexes
suggest indexes
generate indexes automatically
Aidbox uses database for storage. Most of resource data is contained in column with type.
Consider simple example: active searh parameter for Patient resource.
Let's try the search query
Use to find out SQL query generated by this request
Possible response is
Corresponding SQL is
Without indexes Postgres has to check this condition for every Patient resource stored in the database.
We can create GIN index for the resource
column
Now Postgres can use this index to make search much faster.
Consider more complex example: name
search parameter for Patient
resource.
Request
Generates SQL like
You can create functional index to speed up this query:
Managing indexes manually is quite tedious and error-prone.
Consider this example
Here
box
is the Aidbox project entrypoint
repositories
is an Aidbox service
patient-repository
is an Aidbox repository. It configures resource behavior. Currently it can only add indexes and search parameters.
my-index
is index definition
Use aidbox.index.draft/sync-indexes
RPC to update indexes.
This RPC creates indexes requested by your configuration. And removes indexes not requested.
Note. Aidbox managed indexes start with aidbox_mng_idx
prefix. So your custom indexes which do not start with this prefix will not be affected.
Import aidbox.index.v1
in the example above and add :indexes
into patient-repository.
Add new symbol my-index1
with tag aidbox.index.v1/auto-index
to make index on start, based on Index Suggestion API for Patient.brthd SearchParameter.
After restart new index will be added.
After restart new index will be added:
As in previous section, actuall creation/deletion of indexes is triggered with aidbox.index.draft/sync-indexes
RPC.
Formal description of Zen Indexes:
Aidbox provides two RPCs which can suggest you indexes
Use aidbox.index/suggest-index
RPC to get index suggestion for specific search parameter
Use aidbox.index/suggest-index-query
RPC to get index suggestions based on query
Here is containment operator. It tests whether jsonb value on the right-hand side is contained in the jsonb value on the left-hand side.
However, can speed up these kind of queries.
Postgres' supports index searches for ILIKE
queries.
Aidbox provides a mechanism to manage indexes automatically using .
You can make index by your own with . However, Aidbox can be configured to make indexes for desired SearchParameters at start automatically.
Use aidbox.index.v1/index
tag with :expression
and fields: