Re: Very newbie question

From: Олег Самойлов <splarv(at)ya(dot)ru>
To: Toomas <toomas(dot)kristin(at)gmail(dot)com>
Cc: "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Very newbie question
Date: 2023-10-23 15:45:10
Message-ID: B9F995CD-F6A1-416D-9B76-D5B96616B074@ya.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

This is not correct. An index can accelerate, for instance, max(). Here is also not WHERE or ORDER BY, but index is useful:
select max(created_at) from delivery;

> 23 окт. 2023 г., в 18:23, Toomas <toomas(dot)kristin(at)gmail(dot)com> написал(а):
>
>
> There is no reason to use index. The query has neither WHERE nor ORDER BY clause.
>
> Toomas
>
>> On 23. Oct 2023, at 18:13, Олег Самойлов <splarv(at)ya(dot)ru> wrote:
>>
>> Back pardon, but I have a very newbie question. I have a partitioned table, partitioned by primary bigint key, size of partition 10000000. I need to get the number of partition which need to archive, which has all rows are olden then 3 month. Here is query:
>>
>> SELECT id/10000000 as partition
>> FROM delivery
>> GROUP BY partition
>> HAVING max(created_at) < CURRENT_DATE - '3 month'::interval;
>>
>> The 'id/10000000 as partition' is a number of the partition, it later will be used inside the partition name.
>> The query runs long by sequence scan. Has anyone any ideas how to rewrite query so it will use any index?
>>
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ron 2023-10-23 15:50:47 Re: Very newbie question
Previous Message Олег Самойлов 2023-10-23 15:42:05 Re: Very newbie question