Commit 2ac1787
committed
Restructure get_similar_neurons with CALL subqueries
Reviewer flagged a cartesian-product risk in the previous version:
chained OPTIONAL MATCHes for (xref, site), (channel, ri, templ),
(technique), and (typ) compounded into N × M × K rows per n2 before
RETURN DISTINCT collapsed them. On densely-typed or multi-aligned
neurons this is wasteful, and `type` was being aggregated within the
(channel, technique) grouping rather than once per n2.
Refactored each optional branch into a CALL subquery scoped to n2:
CALL { WITH n2
OPTIONAL MATCH (n2)-[:INSTANCEOF]->(typ:Class)
RETURN apoc.text.join([l IN collect(...) WHERE ...], '|') AS type }
CALL { WITH n2
OPTIONAL MATCH (n2)-[rx:database_cross_reference]->(site:Site)
WHERE site.is_data_source
WITH rx, site LIMIT 1
RETURN rx, site }
CALL { WITH n2
OPTIONAL MATCH (n2)<-[:depicts]-(channel)-[ri:in_register_with]->...
OPTIONAL MATCH (channel)-[:is_specified_output_of]->(technique:Class)
WITH ri, templ, technique LIMIT 1
RETURN ri, templ, technique }
`type` aggregates internally (always 1 row, no LIMIT needed).
Cross-ref and alignment pick a single representative — matches what
the v2 row needs and what prod's `apoc.cypher.run('... LIMIT 5'/'10')`
pattern already does inside the XMI.
`WITH DISTINCT r, n2` upfront drops the c1/c2 cartesian from the
INSTANCEOF anchors. RETURN no longer needs DISTINCT — the row key is
guaranteed unique by construction.1 parent 66b8dc3 commit 2ac1787
1 file changed
Lines changed: 30 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2463 | 2463 | | |
2464 | 2464 | | |
2465 | 2465 | | |
2466 | | - | |
| 2466 | + | |
| 2467 | + | |
| 2468 | + | |
| 2469 | + | |
| 2470 | + | |
| 2471 | + | |
| 2472 | + | |
| 2473 | + | |
| 2474 | + | |
2467 | 2475 | | |
2468 | | - | |
2469 | | - | |
2470 | | - | |
2471 | | - | |
2472 | | - | |
2473 | | - | |
2474 | | - | |
2475 | | - | |
2476 | | - | |
2477 | | - | |
2478 | | - | |
| 2476 | + | |
| 2477 | + | |
| 2478 | + | |
| 2479 | + | |
| 2480 | + | |
| 2481 | + | |
| 2482 | + | |
| 2483 | + | |
| 2484 | + | |
| 2485 | + | |
| 2486 | + | |
| 2487 | + | |
| 2488 | + | |
| 2489 | + | |
| 2490 | + | |
| 2491 | + | |
| 2492 | + | |
| 2493 | + | |
| 2494 | + | |
| 2495 | + | |
| 2496 | + | |
2479 | 2497 | | |
2480 | 2498 | | |
2481 | 2499 | | |
| |||
0 commit comments