evitaDB - Fast e-commerce database
logo
page-background

Behavioral ordering containers

Special behavioural order constraint containers are used to define a order constraint scope.

In Scope

argument:enum(LIVE|ARCHIVED)

mandatory enum argument representing the scope to which the order constraints in the second and subsequent arguments are applied

orderConstraint:any+

one or more mandatory order conditions, combined by a logical link, used to order entities only in a specific scope

The inScope (
) order container is used to restrict order conditions so that they only apply to a specific scope.

The evitaDB query engine is strict about indexes and does not allow you to order or sort on data (attributes, references, etc.) for which no index has been prepared in advance (it tries to avoid situations where a full scan would degrade query performance). Scopes, on the other hand, allows us to get rid of unnecessary indexes when we know we will not need them (archived data is not expected to be queried as extensively as live data) and free up some resources for more important tasks.

The scope order constraint allows us to query entities in both scopes at once, which would be impossible if we couldn't tell which order constraint to apply to which scope. The inScope container is designed to handle this situation.
It's obvious that the inScope container is not necessary if we are only querying entities in one scope. However, if you do use it in this case, it must match the scope of the query. If you use the inScope container with the LIVE scope, but the query is executed in the ARCHIVED scope, the engine will return an error.
For example, in our demo dataset we have only a few attributes indexed in the archive - namely url and code and a few others. No attribute has a sort index in the archive scope. So if we were to select a few entities from both scopes and try to sort them by name, we'd get an error. However, if we use the inScope container, we can sort the entities by name in the live scope and let the archived entities sort by the order in the input query.
The result contains two live entities ordered by the code attribute. The other entities come from the ARCHIVED scope, which contains no sort index, and are ordered by their primary keys.
Similar inScope containers are available for filter constraints and requirements constraints with the same purpose and meaning.

Author: Ing. Jan Novotný

Date updated: 29.11.2024

Documentation Source