Tagged Variants grid search box optimisation: a search takes about 12 s with 200k tags

Open
#2,885 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
52/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
postgresql, python

Research direction

Start with snpdb/views/datatable_view.py and variantopedia/grids.py, then inspect how DatatableConfig.power_search builds filters for VariantTagsColumns. Compare the current search plan with the proposed key lookup for annotations, coordinates, and related tables, including tags lifted from other builds. Measure the full search and count path on the 200k-tag dataset; done means searches approach the unsearched grid cost while preserving the documented matching behavior.

Written by the indexing model from the issue text.

Description

🤖 Written by Claude

On Variants → Tagged Variants, searching in the Tags grid's Search box takes about 12 s on a database with 200k tags (vg-test2, GRCh37, lab user). The grid's other actions take about 5 s once #2878 / PR #2879 lands. A search for "GATA2", which matches 5 tags, takes 12.1 s on the PR.

What the search box matches

The text is matched case-insensitively as "contains" against every searchable column, ORed together:

  • Variant (coordinate string), Gene, g.HGVS (hidden)
  • Tag, Analysis id and name, Sample name, Patient identity, username and full name
  • Tag ID, Variant ID and the created date, each cast to text

snpdb/views/datatable_view.py:DatatableConfig.power_search does this for every grid. The Tags grid is variantopedia/grids.py:VariantTagsColumns.

Where the time goes

Each search runs the filter twice, once for the count and once for the page, at about 6 s each. Variant and Gene are computed for each tag through the build's variant, annotation and gene joins, so Postgres computes them for every tag before it can filter.

Each column searched on its own (2.8 s of each figure is the grid with no search):

Column Time
Gene 5.1 s
Variant 3.5 s
g.HGVS 2.7 s
Patient 2.1 s
Each of the rest under 1 s
All together, as the grid does it 6.2 s

Matching the same text against the annotation's gene symbol directly, for tagged variants only, takes 0.09 s.

Proposed approach

Resolve the search text to keys first, then filter tags on indexed columns:

  1. Gene symbol and g.HGVS: match against the build's annotation partition for tagged variants, going through the tag's allele as well as its variant. The grid also shows tags lifted over from other builds: the direct SQL above found 4 tags where the grid finds 5.
  2. Coordinate: when the text parses as a coordinate (VariantCoordinate), look the variant up directly.
  3. Tag, user, analysis, sample, patient: match in their own small tables.
  4. Filter: keep tags whose variant, allele or foreign keys are in those sets.

Numbers as text

The ID and created-date columns match by casting to text. Typing 12 matches every tag whose ID, variant ID or created date contains "12". Those columns could match only when the text is a whole number, and then by equality.

Expected outcome

A search should take close to the grid's unsearched cost (about 3 s after #2878), not 12 s. Not yet built or measured end to end.

Dominant language
Python
Stars
31
Forks
4
Avg merge
4h 52m
Merged PRs (30d)
183

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from SACGF/variantgrid

All issues in SACGF/variantgrid

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.