Skip to content

Slow AQL query performance #1443

@wajda

Description

@wajda

The following query takes 27 sec to run on the 40k execution plans database.

WITH executionPlan, executes, depends, affects, operation, follows, readsFrom, writesTo, emits, uses, produces, schema, consistsOf, attribute, computedBy, derivesFrom, expression, takes, dataSource
LET v_plan = FIRST(FOR ep IN executionPlan FILTER ep._key == @plan_key RETURN ep)

LET e_executes =  FIRST (FOR e IN executes FILTER e._belongsTo == v_plan._id RETURN e)
LET es_depends =        (FOR e IN depends FILTER e._belongsTo == v_plan._id RETURN e)
LET e_affects =   FIRST (FOR e IN affects FILTER e._belongsTo == v_plan._id RETURN e)

LET vs_operations =     (FOR v IN operation FILTER v._belongsTo == v_plan._id RETURN v)
LET es_follows =        (FOR e IN follows FILTER e._belongsTo == v_plan._id RETURN e)
LET es_reads_from =     (FOR e IN readsFrom FILTER e._belongsTo == v_plan._id RETURN e)
LET e_writes_to = FIRST (FOR e IN writesTo FILTER e._belongsTo == v_plan._id RETURN e)
LET es_emits =          (FOR e IN emits FILTER e._belongsTo == v_plan._id RETURN e)
LET es_uses =           (FOR e IN uses FILTER e._belongsTo == v_plan._id RETURN e)
LET es_produces =       (FOR e IN produces FILTER e._belongsTo == v_plan._id RETURN e)

LET vs_sources =        (FOR ds IN 1 OUTBOUND v_plan depends, affects RETURN ds)

LET vs_schemas =        (FOR v IN schema FILTER v._belongsTo == v_plan._id RETURN v)
LET es_consists_of =    (FOR e IN consistsOf FILTER e._belongsTo == v_plan._id RETURN e)

LET vs_attributes =     (FOR v IN attribute FILTER v._belongsTo == v_plan._id RETURN v)
LET es_computed_by =    (FOR e IN computedBy FILTER e._belongsTo == v_plan._id RETURN e)
LET es_derives_from =   (FOR e IN derivesFrom FILTER e._belongsTo == v_plan._id RETURN e)

LET vs_expressions =    (FOR v IN expression FILTER v._belongsTo == v_plan._id RETURN v)
LET es_takes =          (FOR e IN takes FILTER e._belongsTo == v_plan._id RETURN e)

RETURN {
  // execution plan
  "executionPlan" : v_plan,
  "executes"      : e_executes,
  "depends"       : es_depends,
  "affects"       : e_affects,

  // operation
  "operations"    : vs_operations,
  "follows"       : es_follows,
  "readsFrom"     : es_reads_from,
  "writesTo"      : e_writes_to,
  "emits"         : es_emits,
  "uses"          : es_uses,
  "produces"      : es_produces,

  // data source
  "dataSources"   : vs_sources,

  // schema
  "schemas"       : vs_schemas,
  "consistsOf"    : es_consists_of,

  // attribute
  "attributes"    : vs_attributes,
  "computedBy"    : es_computed_by,
  "derivesFrom"   : es_derives_from,

  // expression
  "expressions"   : vs_expressions,
  "takes"         : es_takes
}

AQL EXPLAIN:

Query String (2577 chars, cacheable: true):
 WITH executionPlan, executes, depends, affects, operation, follows, readsFrom, writesTo, emits, 
 uses, produces, schema, consistsOf, attribute, computedBy, derivesFrom, expression, takes, 
 dataSource
 LET v_plan = FIRST(FOR ep IN executionPlan FILTER ep._key == @plan_key RETURN ep)
 LET e_executes =  FIRST (FOR e IN executes FILTER e._belongsTo == v_plan._id RETURN e)
 LET es_depends =        (FOR e IN depends FILTER e._belongsTo == v_plan._id RETURN e)
 LET e_affects =   FIRST (FOR e IN affects FILTER e._belongsTo == v_plan._id RETURN e)
 LET vs_operations =     (FOR v IN operation FILTER v._belongsTo == v_plan._id RETURN v)
 LET es_follows =        (FOR e IN follows FILTER e._belongsTo == v_plan._id RETURN e)
 LET es_reads_from =     (FOR e IN readsFrom FILTER e._belongsTo == v_plan._id RETURN e)
 LET e_writes_to = FIRST (FOR e IN writesTo FILTER e._belongsTo == v_plan._id RETURN e)
 LET es_emits =          (FOR e IN emits FILTER e._belongsTo == v_plan._id RETURN e)
 LET es_uses =           (FOR e IN uses...

Execution plan:
  Id   NodeType                  Site      Est.   Comment
   1   SingletonNode             COOR         1   * ROOT
 236   SubqueryStartNode         COOR         1     - LET #1 = ( /* subquery begin */
 128   ScatterNode               COOR         1       - SCATTER
 129   RemoteNode                DBS          1       - REMOTE
 124   IndexNode                 DBS          1       - FOR ep IN executionPlan   /* primary index scan, index scan + document lookup, 1 shard(s) */    
 130   RemoteNode                COOR         1         - REMOTE
 131   GatherNode                COOR         1         - GATHER   /* unsorted */
 122   LimitNode                 COOR         1         - LIMIT 0, 1
 237   SubqueryEndNode           COOR         1         - RETURN  ep ) /* subquery end */
   8   CalculationNode           COOR         1     - LET v_plan = FIRST(#1)   /* simple expression */
 234   SubqueryStartNode         COOR         1     - LET es_takes = ( /* subquery begin */
 132   ScatterNode               COOR         1       - SCATTER
 133   RemoteNode                DBS          1       - REMOTE
 127   IndexNode                 DBS        220       - FOR e IN takes   /* persistent index scan, index scan + document lookup (filter projections: `_belongsTo`), 1 shard(s) */    FILTER (e.`_belongsTo` == v_plan.`_id`)   /* early pruning */   
 134   RemoteNode                COOR       220         - REMOTE
 135   GatherNode                COOR       220         - GATHER   /* unsorted */
 235   SubqueryEndNode           COOR         1         - RETURN  e ) /* subquery end */
 232   SubqueryStartNode         COOR         1     - LET vs_expressions = ( /* subquery begin */
 136   ScatterNode               COOR         1       - SCATTER
 137   RemoteNode                DBS          1       - REMOTE
 107   EnumerateCollectionNode   DBS    8269897       - FOR v IN expression   /* full collection scan, 1 shard(s)  */   FILTER (v.`_belongsTo` == v_plan.`_id`)   /* early pruning */
 138   RemoteNode                COOR   8269897         - REMOTE
 139   GatherNode                COOR   8269897         - GATHER   /* unsorted */
 233   SubqueryEndNode           COOR         1         - RETURN  v ) /* subquery end */
 230   SubqueryStartNode         COOR         1     - LET es_derives_from = ( /* subquery begin */
 140   ScatterNode               COOR         1       - SCATTER
 141   RemoteNode                DBS          1       - REMOTE
 101   EnumerateCollectionNode   DBS    2157801       - FOR e IN derivesFrom   /* full collection scan, 1 shard(s)  */   FILTER (e.`_belongsTo` == v_plan.`_id`)   /* early pruning */
 142   RemoteNode                COOR   2157801         - REMOTE
 143   GatherNode                COOR   2157801         - GATHER   /* unsorted */
 231   SubqueryEndNode           COOR         1         - RETURN  e ) /* subquery end */
 228   SubqueryStartNode         COOR         1     - LET es_computed_by = ( /* subquery begin */
 144   ScatterNode               COOR         1       - SCATTER
 145   RemoteNode                DBS          1       - REMOTE
  95   EnumerateCollectionNode   DBS    1694680       - FOR e IN computedBy   /* full collection scan, 1 shard(s)  */   FILTER (e.`_belongsTo` == v_plan.`_id`)   /* early pruning */
 146   RemoteNode                COOR   1694680         - REMOTE
 147   GatherNode                COOR   1694680         - GATHER   /* unsorted */
 229   SubqueryEndNode           COOR         1         - RETURN  e ) /* subquery end */
 226   SubqueryStartNode         COOR         1     - LET vs_attributes = ( /* subquery begin */
 148   ScatterNode               COOR         1       - SCATTER
 149   RemoteNode                DBS          1       - REMOTE
  89   EnumerateCollectionNode   DBS    4155838       - FOR v IN attribute   /* full collection scan, 1 shard(s)  */   FILTER (v.`_belongsTo` == v_plan.`_id`)   /* early pruning */
 150   RemoteNode                COOR   4155838         - REMOTE
 151   GatherNode                COOR   4155838         - GATHER   /* unsorted */
 227   SubqueryEndNode           COOR         1         - RETURN  v ) /* subquery end */
 224   SubqueryStartNode         COOR         1     - LET es_consists_of = ( /* subquery begin */
 152   ScatterNode               COOR         1       - SCATTER
 153   RemoteNode                DBS          1       - REMOTE
  83   EnumerateCollectionNode   DBS   10834403       - FOR e IN consistsOf   /* full collection scan, 1 shard(s)  */   FILTER (e.`_belongsTo` == v_plan.`_id`)   /* early pruning */
 154   RemoteNode                COOR  10834403         - REMOTE
 155   GatherNode                COOR  10834403         - GATHER   /* unsorted */
 225   SubqueryEndNode           COOR         1         - RETURN  e ) /* subquery end */
 222   SubqueryStartNode         COOR         1     - LET vs_schemas = ( /* subquery begin */
 156   ScatterNode               COOR         1       - SCATTER
 157   RemoteNode                DBS          1       - REMOTE
  77   EnumerateCollectionNode   DBS     272810       - FOR v IN schema   /* full collection scan, 1 shard(s)  */   FILTER (v.`_belongsTo` == v_plan.`_id`)   /* early pruning */
 158   RemoteNode                COOR    272810         - REMOTE
 159   GatherNode                COOR    272810         - GATHER   /* unsorted */
 223   SubqueryEndNode           COOR         1         - RETURN  v ) /* subquery end */
 220   SubqueryStartNode         COOR         1     - LET vs_sources = ( /* subquery begin */
  73   TraversalNode             COOR         3       - FOR ds  /* vertex */ IN 1..1  /* min..maxPathDepth */ OUTBOUND v_plan /* startnode */  depends, OUTBOUND affects
 221   SubqueryEndNode           COOR         1         - RETURN  ds ) /* subquery end */
 218   SubqueryStartNode         COOR         1     - LET es_produces = ( /* subquery begin */
 160   ScatterNode               COOR         1       - SCATTER
 161   RemoteNode                DBS          1       - REMOTE
  67   EnumerateCollectionNode   DBS    4148348       - FOR e IN produces   /* full collection scan, 1 shard(s)  */   FILTER (e.`_belongsTo` == v_plan.`_id`)   /* early pruning */
 162   RemoteNode                COOR   4148348         - REMOTE
 163   GatherNode                COOR   4148348         - GATHER   /* unsorted */
 219   SubqueryEndNode           COOR         1         - RETURN  e ) /* subquery end */
 216   SubqueryStartNode         COOR         1     - LET es_uses = ( /* subquery begin */
 164   ScatterNode               COOR         1       - SCATTER
 165   RemoteNode                DBS          1       - REMOTE
  61   EnumerateCollectionNode   DBS    8602126       - FOR e IN uses   /* full collection scan, 1 shard(s)  */   FILTER (e.`_belongsTo` == v_plan.`_id`)   /* early pruning */
 166   RemoteNode                COOR   8602126         - REMOTE
 167   GatherNode                COOR   8602126         - GATHER   /* unsorted */
 217   SubqueryEndNode           COOR         1         - RETURN  e ) /* subquery end */
 214   SubqueryStartNode         COOR         1     - LET es_emits = ( /* subquery begin */
 168   ScatterNode               COOR         1       - SCATTER
 169   RemoteNode                DBS          1       - REMOTE
  55   EnumerateCollectionNode   DBS     451579       - FOR e IN emits   /* full collection scan, 1 shard(s)  */   FILTER (e.`_belongsTo` == v_plan.`_id`)   /* early pruning */
 170   RemoteNode                COOR    451579         - REMOTE
 171   GatherNode                COOR    451579         - GATHER   /* unsorted */
 215   SubqueryEndNode           COOR         1         - RETURN  e ) /* subquery end */
 212   SubqueryStartNode         COOR         1     - LET #29 = ( /* subquery begin */
 172   ScatterNode               COOR         1       - SCATTER
 173   RemoteNode                DBS          1       - REMOTE
  48   EnumerateCollectionNode   DBS      38528       - FOR e IN writesTo   /* full collection scan, 1 shard(s)  */   FILTER (e.`_belongsTo` == v_plan.`_id`)   /* early pruning */
 174   RemoteNode                COOR     38528         - REMOTE
 175   GatherNode                COOR     38528         - GATHER   /* unsorted */
 123   LimitNode                 COOR         1         - LIMIT 0, 1
 213   SubqueryEndNode           COOR         1         - RETURN  e ) /* subquery end */
 210   SubqueryStartNode         COOR         1     - LET es_reads_from = ( /* subquery begin */
 176   ScatterNode               COOR         1       - SCATTER
 177   RemoteNode                DBS          1       - REMOTE
  42   EnumerateCollectionNode   DBS     159237       - FOR e IN readsFrom   /* full collection scan, 1 shard(s)  */   FILTER (e.`_belongsTo` == v_plan.`_id`)   /* early pruning */
 178   RemoteNode                COOR    159237         - REMOTE
 179   GatherNode                COOR    159237         - GATHER   /* unsorted */
 211   SubqueryEndNode           COOR         1         - RETURN  e ) /* subquery end */
 208   SubqueryStartNode         COOR         1     - LET es_follows = ( /* subquery begin */
 180   ScatterNode               COOR         1       - SCATTER
 181   RemoteNode                DBS          1       - REMOTE
 126   IndexNode                 DBS         14       - FOR e IN follows   /* persistent index scan, index scan + document lookup (filter projections: `_belongsTo`), 1 shard(s) */    FILTER (e.`_belongsTo` == v_plan.`_id`)   /* early pruning */   
 182   RemoteNode                COOR        14         - REMOTE
 183   GatherNode                COOR        14         - GATHER   /* unsorted */
 209   SubqueryEndNode           COOR         1         - RETURN  e ) /* subquery end */
 206   SubqueryStartNode         COOR         1     - LET vs_operations = ( /* subquery begin */
 184   ScatterNode               COOR         1       - SCATTER
 185   RemoteNode                DBS          1       - REMOTE
 125   IndexNode                 DBS         16       - FOR v IN operation   /* persistent index scan, index scan + document lookup (filter projections: `_belongsTo`), 1 shard(s) */    FILTER (v.`_belongsTo` == v_plan.`_id`)   /* early pruning */   
 186   RemoteNode                COOR        16         - REMOTE
 187   GatherNode                COOR        16         - GATHER   /* unsorted */
 207   SubqueryEndNode           COOR         1         - RETURN  v ) /* subquery end */
 204   SubqueryStartNode         COOR         1     - LET #13 = ( /* subquery begin */
 188   ScatterNode               COOR         1       - SCATTER
 189   RemoteNode                DBS          1       - REMOTE
  23   EnumerateCollectionNode   DBS      38527       - FOR e IN affects   /* full collection scan, 1 shard(s)  */   FILTER (e.`_belongsTo` == v_plan.`_id`)   /* early pruning */
 190   RemoteNode                COOR     38527         - REMOTE
 191   GatherNode                COOR     38527         - GATHER   /* unsorted */
 121   LimitNode                 COOR         1         - LIMIT 0, 1
 205   SubqueryEndNode           COOR         1         - RETURN  e ) /* subquery end */
 202   SubqueryStartNode         COOR         1     - LET es_depends = ( /* subquery begin */
 192   ScatterNode               COOR         1       - SCATTER
 193   RemoteNode                DBS          1       - REMOTE
  17   EnumerateCollectionNode   DBS     159237       - FOR e IN depends   /* full collection scan, 1 shard(s)  */   FILTER (e.`_belongsTo` == v_plan.`_id`)   /* early pruning */
 194   RemoteNode                COOR    159237         - REMOTE
 195   GatherNode                COOR    159237         - GATHER   /* unsorted */
 203   SubqueryEndNode           COOR         1         - RETURN  e ) /* subquery end */
 200   SubqueryStartNode         COOR         1     - LET #5 = ( /* subquery begin */
 196   ScatterNode               COOR         1       - SCATTER
 197   RemoteNode                DBS          1       - REMOTE
  10   EnumerateCollectionNode   DBS      38527       - FOR e IN executes   /* full collection scan, 1 shard(s)  */   FILTER (e.`_belongsTo` == v_plan.`_id`)   /* early pruning */
 198   RemoteNode                COOR     38527         - REMOTE
 199   GatherNode                COOR     38527         - GATHER   /* unsorted */
 120   LimitNode                 COOR         1         - LIMIT 0, 1
 201   SubqueryEndNode           COOR         1         - RETURN  e ) /* subquery end */
 118   CalculationNode           COOR         1     - LET #114 = { "executionPlan" : v_plan, "executes" : FIRST(#5), "depends" : es_depends, "affects" : FIRST(#13), "operations" : vs_operations, "follows" : es_follows, "readsFrom" : es_reads_from, "writesTo" : FIRST(#29), "emits" : es_emits, "uses" : es_uses, "produces" : es_produces, "dataSources" : vs_sources, "schemas" : vs_schemas, "consistsOf" : es_consists_of, "attributes" : vs_attributes, "computedBy" : es_computed_by, "derivesFrom" : es_derives_from, "expressions" : vs_expressions, "takes" : es_takes }   /* simple expression */
 119   ReturnNode                COOR         1     - RETURN #114

Indexes used:
  By   Name                      Type         Collection      Unique   Sparse   Cache   Selectivity   Fields             Stored values   Ranges
 124   primary                   primary      executionPlan   true     false    false      100.00 %   [ `_key` ]         [  ]            (ep.`_key` == "98e64d0b-d046-56ad-928d-341fdd4145f2")
 127   idx_1838358837563752448   persistent   takes           false    false    false        0.45 %   [ `_belongsTo` ]   [  ]            (e.`_belongsTo` == FIRST(#1).`_id`)
  73   edge                      edge         affects         false    false    false       99.99 %   [ `_from` ]        [  ]            base OUTBOUND
  73   edge                      edge         depends         false    false    false       42.58 %   [ `_from` ]        [  ]            base OUTBOUND
 126   idx_1805908898236858372   persistent   follows         false    false    false        6.70 %   [ `_belongsTo` ]   [  ]            (e.`_belongsTo` == FIRST(#1).`_id`)
 125   idx_1805908898212741123   persistent   operation       false    false    false        6.15 %   [ `_belongsTo` ]   [  ]            (v.`_belongsTo` == FIRST(#1).`_id`)

Functions used:
 Name    Deterministic   Cacheable   Uses V8
 FIRST   true            true        false  

Traversals on graphs:
 Id  Depth  Vertex collections  Edge collections  Options                                  Filter / Prune Conditions
 73  1..1                       depends, affects  uniqueVertices: none, uniqueEdges: path                           

Optimization rules applied:
 Id   RuleName
  1   move-calculations-up
  2   remove-unnecessary-calculations
  3   optimize-subqueries
  4   move-calculations-up-2
  5   use-indexes
  6   remove-filter-covered-by-index
  7   optimize-traversals
  8   remove-unnecessary-calculations-2
  9   move-calculations-down
 10   scatter-in-cluster
 11   distribute-filtercalc-to-cluster
 12   move-filters-into-enumerate
 13   splice-subqueries

Optimization rules with highest execution times:
 RuleName                                       Duration [s]
 use-indexes                                         0.01796

57 rule(s) executed, 1 plan(s) created, peak mem [b]: 131072, exec time [s]: 0.02072

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions