Overview
When a UQL query is submitted to Ultipa, it first undergoes parsing to validate its syntax. Once parsed, the query is passed through an optimization phase where Ultipa evaluates potential execution strategies based on the current state of the database.
Ultipa’s query optimizer selects the most efficient execution plan by considering factors like data distribution, indexing, and potential bottlenecks. This execution plan outlines the optimal sequence of operations, minimizing resource consumption and improving query performance.
Lifecycle of a UQL query
Explaining Execution Plans
To view the execution plan of a UQL query without running it, use the EXPLAIN
prefix. This generates a detailed view of the operator tree that outlines each step in the query’s process to retrieve the desired result.
The execution plan of the following query contains operators NodeSearch
, Template
, Aggregate
, Exchange
, Aggregate
and With
:
explain
n({@movie} as m).e().n({@country.name == "US"}) as p
group by m.genre
return m.genre, count(m)
Return(ROOT){expr:[m.genre,count(m)] row_type:m.genre:ANY<?>,count(m):UINT64}
-> With{exprs:[count(m),m],row_type:count(m):UINT64,m:ANY}
-> Aggregate{key:[m.genre],agg:[sum(#agg_25_0) as count(m),anyValue(#agg_25_1) as m],phase:GLOBAL_MERGE,row_type:m.genre:STRING,count(m):UINT64,m:NODE{genre:STRING}}
-> Exchange{distribution:distribution_type:ANY,filter:(is_schema,m,movie,5,NODE),partition_ids:[1,2,3],gap_type:APPLY_ALGO}
-> Aggregate{key:[m.genre],agg:[count(m) as #agg_25_0,anyValue(m) as #agg_25_1],phase:PARTIAL,row_type:m.genre:STRING,#agg_25_0:UINT64,#agg_25_1:NODE{genre:STRING}}
-> Template::PARTIAL{row_type:p:PATH{{}{}},m:NODE{genre:STRING},alias:p,shortest:0,no_circle:0,turbo:0,using_temp_value:0,count_row:0,limit:18446744073709551615,deduplicate:1,path:node{direction:IN_OUT,step_num:(1,1),f:m as m},edge{direction:IN_OUT,step_num:(1,1),f:{(ANY) as #hidden_3}},node{direction:IN_OUT,step_num:(1,1),f:{(eq,#hidden_4.country(NODE4).name,US) as #hidden_4}}}
-> NodeSearch{alias:m,row_type:m:NODE{genre:STRING},access_method:{condition:@movie,index_name:schema,query_type:SK_SCHEMA_SCAN}}
The EXPLAIN
feature helps in analyzing the performance implications of a query by revealing the structure and sequence of operations. This preview is essential for optimizing queries, as it allows for adjustments to achieve greater efficiency before executing the full query.