Hotfix: apply LIMIT before CALL subqueries in dataset/transgene queries#44
Merged
Conversation
PR #43 broke THRESHOLD_MEDIUM (3 s) on AlignedDatasets / AllDatasets and THRESHOLD_SLOW (15 s) on TransgeneExpressionHere because LIMIT was appended at the end of each Cypher and applied AFTER the four (or two) CALL subqueries fired for every candidate ds/ep. One of the dataset subqueries does count(DISTINCT img) across has_source edges; the transgene one traverses a 5-hop image join inside the CALL. Move LIMIT after `WITH DISTINCT ds` (or `WITH DISTINCT ep`) and before the CALL subqueries so only the rows we keep get enriched. Drop the ORDER BY from `_dataset_return_clause` and move it next to LIMIT in each caller, since you can't ORDER BY twice in the same query. Dry-run against pdb.v4 (public read-only): AlignedDatasets LIMIT 10 -> 1.64 s AllDatasets LIMIT 20 -> 1.10 s TransgeneExpr... LIMIT 10 -> 0.51 s All under their respective thresholds.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hotfix for the perf-test failure on main after PR #43 merge: https://github.com/VirtualFlyBrain/VFBquery/actions/runs/26659171834/job/78577045325
PR #43 added CALL subqueries to
get_aligned_datasets,get_all_datasets, andget_transgene_expression_here, but LIMIT was appended at the END of the constructed query. Cypher applies LIMIT after the CALL subqueries fire, so every candidate ds/ep gets enriched through 4 (or 2) CALL subqueries before being trimmed.For AlignedDatasets that meant 86 datasets × 4 subqueries (one of which is
count(DISTINCT img)overhas_sourceedges). For AllDatasets, 130 datasets. For TransgeneExpressionHere on mushroom body, 2,340 EPs with a 5-hop thumbnail join.The fix moves LIMIT after
WITH DISTINCTand before the CALL subqueries fire, so only the kept rows are enriched. Also drops theORDER BY namefrom_dataset_return_clauseand moves it next to LIMIT in each caller (can't have two ORDER BYs).Dry-run against pdb.v4 public read-only
All comfortably under their thresholds (3 s, 3 s, 15 s).