Repository navigation
perf(entities): a scoped name search or detail reads only the entities it asks for (#6330) - #6410
Merged
Merged
Conversation
…s it asks for (#6330) Under a tag filter, the entity list recomputed mention counts for every visible entity in the bank before applying the name search (twice: total and page), and the detail view did the same to keep one entity. The shared visible-mentions query now takes the entity ids a read wants. While they have at most FEW_POSTINGS (5000) postings it reads only their mentions, finding inheriting observations with one GIN && probe on source_memory_ids instead of unnesting every visible observation. Past the cap it runs the unchanged query, because walking from postings loses badly on a broad search. The visibility rule stays in one place for list, detail and graph. 300k memories, 20k entities, one tag scope, median of 5, main vs fix: search one name 585 -> 58 ms, prefix of 100 names 659 -> 76 ms, detail of a small entity 68 -> 4 ms; broad searches and entities past the cap unchanged. Same rows and counts in every case.
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.
Fixes #6330. Thanks to @harshitgupta31415 for finding this and measuring it.
Problem
With a tag filter on, searching entities by name counted mentions for every entity visible in the scope, then kept only the ones whose name matched. It did that twice (once for the total, once for the page). Opening one entity's detail page did the same and kept one row.
Fix
The shared "visible mentions" query (used by list, detail and graph) now accepts the entities a read wants:
&&lookup onsource_memory_ids, instead of unnesting every visible observation.A one-time check picks the branch, so only one of them runs. The visibility rules stay in one place.
Not taken from the issue's patch: it copied the visibility SQL into a second query (drift risk between list, detail and graph), only handled exactly one match with ≤ 64 mentions, and was Postgres only.
Numbers
300k memories (150k observations), 20k entities, one tag scope, median of 5, main and fix alternated on the same database:
Same rows and counts in every case.
Tests
test_observations_lend_their_sources_entities_under_a_filternow runs name search and detail through both branches (normal cap, and cap forced to 0). Its observation's two sources both name the same entity, so it also checks duplicates are removed. It fails if the narrowed branch returns nothing.oracle-testslabel added for the Oracle path.