Re: Functionally dependent columns in SELECT DISTINCT

Поиск
Список
Период
Сортировка
От shammat@gmx.net
Тема Re: Functionally dependent columns in SELECT DISTINCT
Дата
Msg-id 88e52d11-6185-473d-9eb2-673b62cb2426@gmx.net
обсуждение исходный текст
Ответ на Functionally dependent columns in SELECT DISTINCT  (Willow Chargin <postgresql@wchargin.com>)
Ответы Re: Functionally dependent columns in SELECT DISTINCT
Список pgsql-general
Willow Chargin schrieb am 13.09.2024 um 07:20:
> Hello! Postgres lets us omit columns from a GROUP BY clause if they are
> functionally dependent on a grouped key, which is a nice quality-of-life
> feature. I'm wondering if a similar relaxation could be permitted for
> the SELECT DISTINCT list?
>
> I have a query where I want to find the most recent few items from a
> table that match some complex condition, where the condition involves
> joining other tables. Here's an example, with two approaches:


What about using DISTINCT ON () ?
    SELECT DISTINCT ON (items.id) items.*
    FROM items
      JOIN parts ON items.id = parts.item_id
    WHERE part_id % 3 = 0
    ORDER BY items.id,items.create_time DESC
    LIMIT 5;

This gives me this plan: https://explain.depesz.com/s/QHr6 on 16.2  (Windows, i7-1260P)








В списке pgsql-general по дате отправления: