1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[SQL] DISTINCT ON needing Bitmap Heap Scan

Discussão em 'Outras Linguagens' iniciado por Stack, Novembro 10, 2024 às 00:02.

  1. Stack

    Stack Membro Participativo

    I have a query like:

    SELECT
    DISTINCT ON (services.group_id)
    services.service_id,
    ...
    FROM services
    WHERE services.group_id IN ('67240181b97477f054f9b1bc', '67240181b97477f054f9b1be')


    I have an index on group_id

    Why does Postgres need to do an extra heap scan? I just want any 1st match with a matching group_id. Notice it should alr have the correct records from the Bitmap Index Scan which already checks for matching group_id

    Unique (cost=609.73..611.66 rows=50 width=240) (actual time=0.353..0.385 rows=2 loops=1)
    -> Sort (cost=609.73..610.70 rows=386 width=240) (actual time=0.353..0.364 rows=386 loops=1)
    Sort Key: group_id
    Sort Method: quicksort Memory: 133kB
    -> Bitmap Heap Scan on services (cost=11.56..593.15 rows=386 width=240) (actual time=0.030..0.180 rows=386 loops=1)
    Recheck Cond: ((group_id)::text = ANY ('{67240181b97477f054f9b1bc,67240181b97477f054f9b1be}'::text[]))
    Heap Blocks: exact=39
    -> Bitmap Index Scan on ix_services_group_id (cost=0.00..11.46 rows=386 width=0) (actual time=0.019..0.020 rows=386 loops=1)
    Index Cond: ((group_id)::text = ANY ('{67240181b97477f054f9b1bc,67240181b97477f054f9b1be}'::text[]))
    Planning Time: 0.505 ms
    Execution Time: 0.434 ms

    Continue reading...

Compartilhe esta Página