Xray
daily rollups 1h 6h 24h 48h 3d 5d 7d 14d 30d ‹
Last 7 days▾
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 12:57:22.
› →|
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 54CFB8E7 · write · last 7d

Query
MATCH (:Organization {tildaid: $org_id})<-[:WORK_ORDER_TO_ORGANIZATION]-(w:WorkOrder) 
WHERE w.delpending = false AND (w.tildaid = $work_order_id OR w.work_order_id = $work_order_id) AND (w.study_id IN $accessible_study_ids OR coalesce(w.study_id, ?) = ?) AND EXISTS { 
MATCH (w)-[:WORK_ORDER_TO_ACTIVITY]->(m:WorkOrderActivity) 
WHERE m.activity_type IN $email_types AND (m.activity_type <> ? OR coalesce(m.status, ?) IN [?, ?]) AND (m.activity_type <> ? OR coalesce(m.status, ?) IN [?]) AND coalesce(m.ignoreType, ?) <> ? } 
MATCH (w)-[:WORK_ORDER_TO_ACTIVITY]->(a:WorkOrderActivity) 
WHERE a.activity_type IN $email_types AND (a.activity_type <> ? OR coalesce(a.status, ?) IN [?, ?]) AND (a.activity_type <> ? OR coalesce(a.status, ?) IN [?]) AND coalesce(a.ignoreType, ?) <> ? 
WITH w, count(a) AS email_count, max(coalesce(a.timestamp, a.createdat)) AS last_email_at_ms, min(coalesce(a.timestamp, a.createdat)) AS first_email_at_ms, sum(CASE WHEN a.activity_type = ? AND a.status = ? THEN ? ELSE ? END) AS draft_count 
WITH w, email_count, last_email_at_ms, first_email_at_ms, draft_count 
ORDER BY last_email_at_ms DESC, w.tildaid DESC 
SKIP $
skip 
LIMIT $
limit // The newest email in the thread — what the list pane previews. Its body is // truncated here, not in Python: that is the point of a summaries-only page. 
CALL (w) { 
MATCH (w)-[:WORK_ORDER_TO_ACTIVITY]->(le:WorkOrderActivity) 
WHERE le.activity_type IN $email_types AND (le.activity_type <> ? OR coalesce(le.status, ?) IN [?, ?]) AND (le.activity_type <> ? OR coalesce(le.status, ?) IN [?]) AND coalesce(le.ignoreType, ?) <> ? 
RETURN le 
ORDER BY coalesce(le.timestamp, le.createdat) DESC, le.tildaid DESC 
LIMIT ? } // Every From address in the thread, in chronological order. Deduped in Python, 
where // preserving first-seen order is one 
call; Cypher has no ordered 
set without APOC. 
CALL (w) { 
MATCH (w)-[:WORK_ORDER_TO_ACTIVITY]->(pa:WorkOrderActivity) 
WHERE pa.activity_type IN $email_types AND (pa.activity_type <> ? OR coalesce(pa.status, ?) IN [?, ?]) AND (pa.activity_type <> ? OR coalesce(pa.status, ?) IN [?]) AND coalesce(pa.ignoreType, ?) <> ? 
WITH pa 
ORDER BY coalesce(pa.timestamp, pa.createdat) ASC, pa.tildaid ASC 
RETURN collect(CASE WHEN pa.activity_type = ? THEN coalesce(pa.sender, ?) ELSE coalesce(pa.from_ai_teammate_email, ?) END) AS from_addresses } 
OPTIONAL MATCH (w)-[:WORK_ORDER_TO_STUDY]->(study:Study) 
OPTIONAL MATCH (w)-[:WORK_ORDER_TO_SITE]->(site:Site) 
RETURN w, email_count, last_email_at_ms, first_email_at_ms, draft_count, from_addresses, study.name AS study_name, site.name AS site_name, // The site NUMBER lives on the study?U_REPLY???U_REPLY???[]?[]??null??']), ?, $snippet_chars) AS last_snippet 
ORDER BY last_email_at_ms DESC, w.tildaid DESC

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

index Index WorkOrder.work_order_id so the thread lookup can start from the work order instead of the org
The issueThe query starts with `MATCH (:Organization {tildaid: $org_id})<-[:WORK_ORDER_TO_ORGANIZATION]-(w:WorkOrder)` and then applies `(w.tildaid = $work_order_id OR w.work_order_id = $work_order_id)` as a filter. The OR across two properties can only use index seeks (a union of two seeks) if both properties are indexed. If `work_order_id` has no index, the planner has to fan out from the org to every one of its WorkOrders and test each one, even though the predicate identifies one thread. That fan-out matches the 900 ms p95 against a 248 ms average: big orgs pay much more.
The fixAdd a range index on WorkOrder.work_order_id. Also make sure WorkOrder.tildaid has a uniqueness constraint or index (it is probably the node key). With both in place, the planner can seek on each side of the OR, de-duplicate the results, and check the single ORGANIZATION relationship from there. It no longer has to expand the whole org.
Add this index
CREATE INDEX workorder_work_order_id IF NOT EXISTS FOR (w:WorkOrder) ON (w.work_order_id)
Expected: With both indexes, rows into the first filter should drop from the org's WorkOrder count to about 1. That could take the p95 from hundreds of ms to tens of ms for large orgs. The total saving is small, though, because this shape ran only 4 times in 7 days. · Evidence: Run `SHOW INDEXES` to see whether WorkOrder(tildaid) and WorkOrder(work_order_id) are covered. Then PROFILE the query before and after the change: look for NodeIndexSeek on WorkOrder (two seeks under a Union/Distinct) in place of an Expand(All) from Organization, with rows/db hits at the top of the plan near 1. Then compare p95 over the next week.
rewrite Drop the redundant EXISTS and read the activities once instead of four times
The issueThe same filtered set `(w)-[:WORK_ORDER_TO_ACTIVITY]->(:WorkOrderActivity)` with the same five predicates is read four times: once in the `EXISTS { ... }` block, once in the aggregating MATCH, once in the `CALL (w)` block for the latest email (`le`), and once in the `CALL (w)` block for `from_addresses`, which also sorts. The EXISTS adds nothing, because the MATCH right after it already drops any w with no matching activity. Each of the two CALL blocks reads the thread again and sorts it, so a long email thread is scanned and sorted several times.
The fixRemove the EXISTS block. Match the activities once, sort them by (coalesce(timestamp, createdat), tildaid) ascending, and collect them in that order while computing count/max/min/sum in the same aggregation. After pagination, the latest email is `acts[-1]`. Ascending order with the last element gives the same result as the original DESC LIMIT 1, including how nulls sort. `from_addresses` is a list comprehension over the already-ordered list. The tail of the statement (study/site OPTIONAL MATCHes and the last_snippet expression on `le`) is copied exactly as given; that part of the original is garbled, so check that it still refers to `le`.
Proposed rewrite — current query in red −, proposed in green +
- MATCH (:Organization {tildaid: $org_id})<-[:WORK_ORDER_TO_ORGANIZATION]-(w:WorkOrder) WHERE w.delpending = false AND (w.tildaid = $work_order_id OR w.work_order_id = $work_order_id) AND (w.study_id IN $accessible_study_ids OR coalesce(w.study_id, ?) = ?) AND EXISTS { MATCH (w)-[:WORK_ORDER_TO_ACTIVITY]->(m:WorkOrderActivity) WHERE m.activity_type IN $email_types AND (m.activity_type <> ? OR coalesce(m.status, ?) IN [?, ?]) AND (m.activity_type <> ? OR coalesce(m.status, ?) IN [?]) AND coalesce(m.ignoreType, ?) <> ? } MATCH (w)-[:WORK_ORDER_TO_ACTIVITY]->(a:WorkOrderActivity) WHERE a.activity_type IN $email_types AND (a.activity_type <> ? OR coalesce(a.status, ?) IN [?, ?]) AND (a.activity_type <> ? OR coalesce(a.status, ?) IN [?]) AND coalesce(a.ignoreType, ?) <> ? WITH w, count(a) AS email_count, max(coalesce(a.timestamp, a.createdat)) AS last_email_at_ms, min(coalesce(a.timestamp, a.createdat)) AS first_email_at_ms, sum(CASE WHEN a.activity_type = ? AND a.status = ? THEN ? ELSE ? END) AS draft_count WITH w, email_count, last_email_at_ms, first_email_at_ms, draft_count ORDER BY last_email_at_ms DESC, w.tildaid DESC SKIP $skip LIMIT $limit // The newest email in the thread — what the list pane previews. Its body is // truncated here, not in Python: that is the point of a summaries-only page. CALL (w) { MATCH (w)-[:WORK_ORDER_TO_ACTIVITY]->(le:WorkOrderActivity) WHERE le.activity_type IN $email_types AND (le.activity_type <> ? OR coalesce(le.status, ?) IN [?, ?]) AND (le.activity_type <> ? OR coalesce(le.status, ?) IN [?]) AND coalesce(le.ignoreType, ?) <> ? RETURN le ORDER BY coalesce(le.timestamp, le.createdat) DESC, le.tildaid DESC LIMIT ? } // Every From address in the thread, in chronological order. Deduped in Python, where // preserving first-seen order is one call; Cypher has no ordered set without APOC. CALL (w) { MATCH (w)-[:WORK_ORDER_TO_ACTIVITY]->(pa:WorkOrderActivity) WHERE pa.activity_type IN $email_types AND (pa.activity_type <> ? OR coalesce(pa.status, ?) IN [?, ?]) AND (pa.activity_type <> ? OR coalesce(pa.status, ?) IN [?]) AND coalesce(pa.ignoreType, ?) <> ? WITH pa ORDER BY coalesce(pa.timestamp, pa.createdat) ASC, pa.tildaid ASC RETURN collect(CASE WHEN pa.activity_type = ? THEN coalesce(pa.sender, ?) ELSE coalesce(pa.from_ai_teammate_email, ?) END) AS from_addresses } OPTIONAL MATCH (w)-[:WORK_ORDER_TO_STUDY]->(study:Study) OPTIONAL MATCH (w)-[:WORK_ORDER_TO_SITE]->(site:Site) RETURN w, email_count, last_email_at_ms, first_email_at_ms, draft_count, from_addresses, study.name AS study_name, site.name AS site_name, // The site NUMBER lives on the study?U_REPLY???U_REPLY???[]?[]??null??']), ?, $snippet_chars) AS last_snippet ORDER BY last_email_at_ms DESC, w.tildaid DESC
+ MATCH (:Organization {tildaid: $org_id})<-[:WORK_ORDER_TO_ORGANIZATION]-(w:WorkOrder) WHERE w.delpending = false AND (w.tildaid = $work_order_id OR w.work_order_id = $work_order_id) AND (w.study_id IN $accessible_study_ids OR coalesce(w.study_id, ?) = ?) MATCH (w)-[:WORK_ORDER_TO_ACTIVITY]->(a:WorkOrderActivity) WHERE a.activity_type IN $email_types AND (a.activity_type <> ? OR coalesce(a.status, ?) IN [?, ?]) AND (a.activity_type <> ? OR coalesce(a.status, ?) IN [?]) AND coalesce(a.ignoreType, ?) <> ? WITH w, a ORDER BY coalesce(a.timestamp, a.createdat) ASC, a.tildaid ASC WITH w, collect(a) AS acts, count(a) AS email_count, max(coalesce(a.timestamp, a.createdat)) AS last_email_at_ms, min(coalesce(a.timestamp, a.createdat)) AS first_email_at_ms, sum(CASE WHEN a.activity_type = ? AND a.status = ? THEN ? ELSE ? END) AS draft_count ORDER BY last_email_at_ms DESC, w.tildaid DESC SKIP $skip LIMIT $limit WITH w, email_count, last_email_at_ms, first_email_at_ms, draft_count, acts[-1] AS le, [pa IN acts | CASE WHEN pa.activity_type = ? THEN coalesce(pa.sender, ?) ELSE coalesce(pa.from_ai_teammate_email, ?) END] AS from_addresses OPTIONAL MATCH (w)-[:WORK_ORDER_TO_STUDY]->(study:Study) OPTIONAL MATCH (w)-[:WORK_ORDER_TO_SITE]->(site:Site) RETURN w, email_count, last_email_at_ms, first_email_at_ms, draft_count, from_addresses, study.name AS study_name, site.name AS site_name, // The site NUMBER lives on the study?U_REPLY???U_REPLY???[]?[]??null??']), ?, $snippet_chars) AS last_snippet ORDER BY last_email_at_ms DESC, w.tildaid DESC
Expected: Activity expansions per work order should fall from 4 to 1, with one sort instead of two. Db hits on the activity side should drop by roughly 3–4×, which matters most for long threads. · Evidence: PROFILE the old and new statements on the same long thread. Compare total db hits and the number of Expand(All) operators on WORK_ORDER_TO_ACTIVITY (4 before, 1 after). Diff the returned rows to confirm email_count, draft_count, the last_snippet source and the from_addresses order are identical.
index Make sure WorkOrder.tildaid is backed by a uniqueness constraint
The issueThe other half of `w.tildaid = $work_order_id OR w.work_order_id = $work_order_id` also needs an index. Otherwise the OR cannot become an index union and the plan goes back to expanding from Organization, even after work_order_id is indexed. tildaid looks like the WorkOrder key, so it should be unique.
The fixIf `SHOW CONSTRAINTS` does not list a uniqueness constraint on WorkOrder.tildaid, create one. It provides the backing index for the seek and also guarantees one node per key.
Add this index
CREATE CONSTRAINT workorder_tildaid_unique IF NOT EXISTS FOR (w:WorkOrder) REQUIRE w.tildaid IS UNIQUE
Expected: Together with the work_order_id index, the WorkOrder lookup becomes two seeks returning at most a couple of rows. If the constraint already exists, nothing changes. · Evidence: Check `SHOW CONSTRAINTS` before creating it. In PROFILE, look for NodeUniqueIndexSeek or NodeIndexSeek on WorkOrder(tildaid) next to the work_order_id seek.

Status: proposed · all suggestions

No rollups for this shape in the window.