Skip to content

"All" pathway semantics behave as "any": HAVING compares a per-gene group count to a total row count #228

Description

@jbrestel

In Model/lib/wdk/model/questions/queries/pathwayQueries.xml, the any_or_all_pathway "all" branch does not implement "all". It is a no-op in at least one search and probably close to one in the others.

The defect

Take PathwaysByGeneList:

GROUP BY tp.pathway_source_id, tp.pathway_source, tp.gene_source_id, tp.ec_number_gene, tp.ec_number_pathway
HAVING (
  ('$$any_or_all_pathway$$' = 'any')
  OR (count(*) <= (SELECT count (*)
                   FROM apidbtuning.TranscriptPathway tp , dsGene ds
                   WHERE tp.gene_source_id = ds.gene
                  )
  ))

The GROUP BY includes tp.gene_source_id, so each group is one gene in one pathway with one EC pair — count(*) per group is typically 1. The subquery counts every pathway-gene row for the entire input list. So the comparison is roughly 1 <= (large number), which is true for every group. The all branch filters nothing.

For "pathways containing all of these genes", the comparison needs to be at the pathway level — something like count(distinct gene_source_id) = <number of input genes> after grouping by pathway alone, not per gene.

Evidence

EXPLAIN ANALYZE of PathwaysByGeneList against genomicsdb_071n, 5-gene input (PF3D7_0103700, PF3D7_0109500, PF3D7_0109850, PF3D7_0110600, PF3D7_0202900), pathways_source=1, exclude_incomplete_ec=0, exact_match_only=0:

mode rows out
any 3687
all 3687

Identical. With any the planner constant-folds ('any' = 'any') and drops the subquery entirely; with all it evaluates it as an InitPlan and every group still passes.

Affected sites

Query Line (approx) Comparison
PathwaysByGeneList ~234 count(*) <= — never filters
PathwaysByGeneIds ~414 count(*) = — same grouping problem, also grouped per gene
PathwaysByCompounds ~307 count(*) = — same shape, worth checking against compound grouping

The <= in PathwaysByGeneList is the most clearly wrong; the = variants may filter something, but not the intended thing, since the group is still per-gene.

Why this wasn't caught

It fails open. "All" silently returns the "any" result set, which is a superset containing the correct answer — so results look plausible and nothing errors. Only a count comparison between the two modes reveals it.

Not in scope of #227

Noticed while fixing the gene-alias resolution in these same queries (#227), and deliberately left untouched there — it is pre-existing and needs a semantics decision, not a mechanical fix. Someone should confirm what "all" is meant to mean in the UI before rewriting the grouping.

🤖 Generated with Claude Code

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions