Skip to content

Slow Join + Filter query #6180

@kuza55

Description

@kuza55

Hi,

The following query took several seconds to resolve on an m5.2xlarge:

SELECT instances.uid, instances.extra
FROM instances
WHERE (EXISTS (SELECT 1
FROM queries
WHERE instances.uid = queries.instance_uid AND queries.`sql` = '...' AND (EXISTS (SELECT 1
FROM query_tags
WHERE queries.uid = query_tags.query_uid AND query_tags.tag = 'primary')))) AND (EXISTS (SELECT 1
FROM query_tags, queries
WHERE queries.uid = query_tags.query_uid AND query_tags.tag = 'bird_gpt35_kg_cot'))

In particular both the pieces of query_tags filtering made this much slower than filtering based on the sql query alone, loading the relevant instance by uid, loading all the queries by uid, then loading all the tags by uid, and doing the filtering manually in python.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions