Xray
1h 6h 24h 48h 3d 5d 7d 14d 30d ‹
Last 1 hour▾
Ends now. Anything up to this cluster's 30-day retention.
Start and end times
Cancel
Interpreted in UTC (change it at the right of this bar). Earliest available: 2026-10-19 15:17:33.
› →|
updated 1d ago
Sample data. This database was generated by scripts/seed_dev_db.py — every service, deploy, person and figure on this page is synthetic. Names are sample.*@seed.invalid and image tags are prefixed SEED-. Nothing here happened.
← query trends

Query shape trend

plan 826C56EA · read · last 1h

Query
match (task:Task)-[:BELONGS_TO]->(inbox:Inbox)-[:MANAGED_BY]->(Organization) 
where (Organization.alias = $scopeOrgAlias or (Organization.alias = $scopeCroOrgAlias and NOT EXISTS { 
MATCH (task)-[:BELONGS_TO]-(:Inbox{type:?})-[:MANAGED_BY]-(:Site)-[:SITE_TO_ORGANIZATION]->(o:Organization) 
WHERE o.alias <> $scopeOrgAlias } and coalesce(task.category, ?) <> $scopeTrainingCategory)) 
match (task)-[:BELONGS_TO]->(SInbox:Inbox{type:?})-[:MANAGED_BY]->(Study:Study{name:$scopeStudyName})-[:STUDY_TO_ORG]->(Organization) 
where (Organization.alias = $scopeOrgAlias or (Organization.alias = $scopeCroOrgAlias and NOT EXISTS { 
MATCH (task)-[:BELONGS_TO]-(:Inbox{type:?})-[:MANAGED_BY]-(:Site)-[:SITE_TO_ORGANIZATION]->(o:Organization) 
WHERE o.alias <> $scopeOrgAlias } and coalesce(task.category, ?) <> $scopeTrainingCategory)) and task.category in $lists.scopeCategories and task.state in $lists.scopeStates 
with task 
match (task)-[:WITH_CONTEXT]->() 
where task.state <> ? 
optional match (task)-[:BELONGS_TO]-(SInbox:Inbox{type:?})-[:MANAGED_BY]-(UserStudy:Study)-[:STUDY_TO_ORG]-(Organization) 
where (Organization.alias = $scopeOrgAlias or (Organization.alias = $scopeCroOrgAlias and NOT EXISTS { 
MATCH (task)-[:BELONGS_TO]-(:Inbox{type:?})-[:MANAGED_BY]-(:Site)-[:SITE_TO_ORGANIZATION]->(o:Organization) 
WHERE o.alias <> $scopeOrgAlias } and coalesce(task.category, ?) <> $scopeTrainingCategory)) 
with task, SInbox, UserStudy 
where (SInbox IS NULL) OR (SInbox IS NOT NULL AND exists((:User{email:$scopeUserEmail})-[:FOR_USER]-(:Actor)-[:STUDY_TO_ACTOR]-(UserStudy))) 
with distinct task as t 
call apoc.do.case([ t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext IN [?, ?, ?], ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ? ], ?, {t: t}) 
yield value 
return value, {inbox: {InboxStudy: head([(t)-[:BELONGS_TO]->(:Inbox{type:?})-[:MANAGED_BY]->(ist:Study) | ist])}} as inboxStudy 
order by t.category 
limit $pageLimit

Optimizer suggestions — proposals from claude-opus-5-5, 1d ago; suggests only, a human applies

index Index Study.name so the plan can start from the scoped study
The issue`(Study:Study{name:$scopeStudyName})` in the second MATCH is the most selective predicate in the statement. Without a lookup index on Study.name, the planner has to start from a Task label scan, or from Organization. It then expands every task through BELONGS_TO/MANAGED_BY and runs the OR/NOT EXISTS predicate on each one before the study filter removes most rows. That fits the 1850 ms p95 against a 402 ms average: tenants with many tasks get a much larger scan.
The fixCreate a range index on :Study(name). The planner can then use NodeIndexSeek on Study, expand STUDY_TO_ORG to Organization and MANAGED_BY back to the Inbox, and reach only that study's tasks. Pair it with the Organization.alias index if EXPLAIN still picks the Organization side. If study names are unique, a uniqueness constraint gives the same lookup and also protects the data.
Add this index
CREATE INDEX study_name IF NOT EXISTS FOR (s:Study) ON (s.name)
Expected: Probably cuts db hits by roughly the ratio of all tasks to tasks in one study. The slow p95 case may drop from about 1.8 s to tens of ms, but this is not verified. With only 3 runs in 7 days the total saving is small; the main benefit is shorter waits for the people running it. · Evidence: PROFILE before and after. Look for NodeIndexSeek on Study(name) near the leaf of the plan, replacing NodeByLabelScan(Task) or NodeByLabelScan(Organization), and a lower db-hit total. Check the p95 over the next week.
index Index Organization.alias for the $scopeOrgAlias / $scopeCroOrgAlias predicates
The issueThree WHERE clauses filter `Organization.alias = $scopeOrgAlias OR Organization.alias = $scopeCroOrgAlias`, and the NOT EXISTS subqueries filter `o.alias <> $scopeOrgAlias`. With no index on Organization.alias, the OR has to be checked row by row after expansion. The planner also cannot use a two-seek union on Organization as an alternative starting point.
The fixAdd a range index on :Organization(alias). The planner can then seek both aliases directly and expand inward. The index is cheap to keep, and it probably helps other tusker queries that scope by org alias. If alias is a natural key, use a uniqueness constraint instead.
Add this index
CREATE INDEX organization_alias IF NOT EXISTS FOR (o:Organization) ON (o.alias)
Expected: Makes Organization a cheap anchor of two seeks, and gives the planner a cheap way to rule out non-matching organizations. The gain is smaller than the Study index if study names are more selective. · Evidence: EXPLAIN showing NodeIndexSeek, or a Union of seeks, on Organization(alias). Compare db hits with and without the index.
rewrite Drop the duplicate scope predicate, anchor on Study, and apply LIMIT before apoc.do.case
The issue1) The second MATCH reuses the same `task` and `Organization` variables, so its WHERE repeats the whole OR/NOT EXISTS check that the first MATCH already applied. The NOT EXISTS subquery therefore runs twice per row for no reason. 2) `ORDER BY t.category LIMIT $pageLimit` comes after `CALL apoc.do.case(...)`, so the 26-branch case procedure and the head() pattern comprehension run for every matching task, not just one page. apoc.do.case also runs its branch in a write-capable inner transaction, which costs more than evaluating a CASE.
The fixMerge the two MATCH clauses into one path that starts from the study. Keep the scope predicate once and leave the category/state filters as they are. Sort and limit on t.category before the procedure call. apoc.do.case returns exactly one row per input, so limiting first gives the same rows. If the branch queries are read-only, also consider switching to apoc.case (read mode). That change is not applied below because the branch bodies are not visible.
Proposed rewrite — current query in red −, proposed in green +
- match (task:Task)-[:BELONGS_TO]->(inbox:Inbox)-[:MANAGED_BY]->(Organization) where (Organization.alias = $scopeOrgAlias or (Organization.alias = $scopeCroOrgAlias and NOT EXISTS { MATCH (task)-[:BELONGS_TO]-(:Inbox{type:?})-[:MANAGED_BY]-(:Site)-[:SITE_TO_ORGANIZATION]->(o:Organization) WHERE o.alias <> $scopeOrgAlias } and coalesce(task.category, ?) <> $scopeTrainingCategory)) match (task)-[:BELONGS_TO]->(SInbox:Inbox{type:?})-[:MANAGED_BY]->(Study:Study{name:$scopeStudyName})-[:STUDY_TO_ORG]->(Organization) where (Organization.alias = $scopeOrgAlias or (Organization.alias = $scopeCroOrgAlias and NOT EXISTS { MATCH (task)-[:BELONGS_TO]-(:Inbox{type:?})-[:MANAGED_BY]-(:Site)-[:SITE_TO_ORGANIZATION]->(o:Organization) WHERE o.alias <> $scopeOrgAlias } and coalesce(task.category, ?) <> $scopeTrainingCategory)) and task.category in $lists.scopeCategories and task.state in $lists.scopeStates with task match (task)-[:WITH_CONTEXT]->() where task.state <> ? optional match (task)-[:BELONGS_TO]-(SInbox:Inbox{type:?})-[:MANAGED_BY]-(UserStudy:Study)-[:STUDY_TO_ORG]-(Organization) where (Organization.alias = $scopeOrgAlias or (Organization.alias = $scopeCroOrgAlias and NOT EXISTS { MATCH (task)-[:BELONGS_TO]-(:Inbox{type:?})-[:MANAGED_BY]-(:Site)-[:SITE_TO_ORGANIZATION]->(o:Organization) WHERE o.alias <> $scopeOrgAlias } and coalesce(task.category, ?) <> $scopeTrainingCategory)) with task, SInbox, UserStudy where (SInbox IS NULL) OR (SInbox IS NOT NULL AND exists((:User{email:$scopeUserEmail})-[:FOR_USER]-(:Actor)-[:STUDY_TO_ACTOR]-(UserStudy))) with distinct task as t call apoc.do.case([ t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext IN [?, ?, ?], ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ? ], ?, {t: t}) yield value return value, {inbox: {InboxStudy: head([(t)-[:BELONGS_TO]->(:Inbox{type:?})-[:MANAGED_BY]->(ist:Study) | ist])}} as inboxStudy order by t.category limit $pageLimit
+ match (Study:Study{name:$scopeStudyName})-[:STUDY_TO_ORG]->(Organization), (task:Task)-[:BELONGS_TO]->(SInbox:Inbox{type:?})-[:MANAGED_BY]->(Study), (task)-[:BELONGS_TO]->(inbox:Inbox)-[:MANAGED_BY]->(Organization) where task.category in $lists.scopeCategories and task.state in $lists.scopeStates and (Organization.alias = $scopeOrgAlias or (Organization.alias = $scopeCroOrgAlias and NOT EXISTS { MATCH (task)-[:BELONGS_TO]-(:Inbox{type:?})-[:MANAGED_BY]-(:Site)-[:SITE_TO_ORGANIZATION]->(o:Organization) WHERE o.alias <> $scopeOrgAlias } and coalesce(task.category, ?) <> $scopeTrainingCategory)) with task match (task)-[:WITH_CONTEXT]->() where task.state <> ? optional match (task)-[:BELONGS_TO]-(SInbox:Inbox{type:?})-[:MANAGED_BY]-(UserStudy:Study)-[:STUDY_TO_ORG]-(Organization) where (Organization.alias = $scopeOrgAlias or (Organization.alias = $scopeCroOrgAlias and NOT EXISTS { MATCH (task)-[:BELONGS_TO]-(:Inbox{type:?})-[:MANAGED_BY]-(:Site)-[:SITE_TO_ORGANIZATION]->(o:Organization) WHERE o.alias <> $scopeOrgAlias } and coalesce(task.category, ?) <> $scopeTrainingCategory)) with task, SInbox, UserStudy where (SInbox IS NULL) OR (SInbox IS NOT NULL AND exists((:User{email:$scopeUserEmail})-[:FOR_USER]-(:Actor)-[:STUDY_TO_ACTOR]-(UserStudy))) with distinct task as t order by t.category limit $pageLimit call apoc.do.case([ t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext IN [?, ?, ?], ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ?, t.relationshipContext = ?, ? ], ?, {t: t}) yield value return value, {inbox: {InboxStudy: head([(t)-[:BELONGS_TO]->(:Inbox{type:?})-[:MANAGED_BY]->(ist:Study) | ist])}} as inboxStudy order by t.category
Expected: Removes one NOT EXISTS evaluation per candidate row. The apoc call and the pattern comprehension then run at most $pageLimit times instead of once per matching task. For large tenants this probably saves an amount roughly proportional to (matches − pageLimit) × the cost per case call. · Evidence: PROFILE both versions with the same parameters. Check that results are identical, including order when categories tie; add a secondary sort key such as elementId(t) if ties matter. Then compare the rows feeding ProcedureCall and the total db hits.

Status: proposed · all suggestions

No rollups for this shape in the window.