Re: Dealing with SeqScans when Time-based Partitions Cut Over

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Matthew Planchard <msplanchard(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Dealing with SeqScans when Time-based Partitions Cut Over
Date: 2025-12-18 20:20:30
Message-ID: CAApHDvpH1-GfwvAEKGb1WniOFK-f66E_Ex9fD-AqotDaq=OyXQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, 19 Dec 2025 at 07:48, Matthew Planchard <msplanchard(at)gmail(dot)com> wrote:
> * Because the planner's latest knowledge of the partition was based on
> its state prior to the cutover, it assumes the partition is empty and
> creates plans that use sequential scans

If the table/partition was just created and not analyzed, the planner
shouldn't consider it empty. By default, an empty table is assumed to
have 10 pages. (Check what pg_class.relpages is set to. -1 means it's
not been analyzed, 0 would mean analyzed/vacuumed when empty)

create table a (a int primary key, b int not null);
create index on a(b);
explain select * from a where a = 1;

Index Scan using a_pkey on a (cost=0.15..8.17 rows=1 width=8)
Index Cond: (a = 1)

explain select * from a where b = 1;

Bitmap Heap Scan on a (cost=4.24..14.91 rows=11 width=8)
Recheck Cond: (b = 1)
-> Bitmap Index Scan on a_b_idx (cost=0.00..4.24 rows=11 width=0)
Index Cond: (b = 1)

Perhaps pg_partman thinks running an ANALYZE or VACUUM on the new
partitions is a good idea? Otherwise, if you're not doing this
yourself, I don't know why you're getting a Seq Scan. It might help if
you showed the problem query and schema.

David

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David Rowley 2025-12-18 20:21:41 Re: Dealing with SeqScans when Time-based Partitions Cut Over
Previous Message Matthew Planchard 2025-12-18 19:55:12 Re: Dealing with SeqScans when Time-based Partitions Cut Over