Re: Should we skip foreign key checks in binary upgrade mode?

From: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
To: David Rowley <dgrowleyml(at)gmail(dot)com>
Cc: PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Should we skip foreign key checks in binary upgrade mode?
Date: 2026-11-27 09:02:27
Message-ID: fa4b2513-3fd1-4f88-8dda-25a30868ca25@iki.fi
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 26/11/2026 03:43, David Rowley wrote:
> On Thu, 26 Nov 2026 at 03:02, Heikki Linnakangas <hlinnaka(at)iki(dot)fi> wrote:
>> 35% sounds nice..
>>
>> I'm hesitant to add special cases like this for pg_upgrade, though.
>> Could you could optimize validateForeignKeyConstraint() for the case of
>> an empty table, whether it's part of pg_upgrade or not? That would also
>> help plain pg_dump/restore.
>>
>> For example, you could first do a quick check to see if the table is
>> completely empty, before starting up the SPI query. Something like the
>> attached quick prototype. (I first tried calling
>> table_relation_estimate_size(), but that returns a dummy, constant
>> estimate rather than 0 for an empty table that hasn't been vacuumed yet.)
>
> Good thinking. That avoids the possibly controversial part of what I
> was proposing.
>
> I think we need to keep the comment about avoiding the SPI query,
> otherwise someone might look at your change and wonder why it's not
> the way it was previously. Also, is it worth forming the patch so it
> leaves the tight loop untouched? Something like the attached, but
> maybe it might be worth doing it your way and use unlikely() to make
> the compiler put the extra code out of line of the loop and just have
> the extra cmp/jmp within the loop?

The table_rescan() seems a bit ugly to me, I'd rather restructure the
loop slightly to avoid that. Maybe turn it from "while
(table_scan_getnextslot())" into "do {} while(table_scan_getnextslot())"

The comments could use some copy-editing. It mentions "pg_dump
--schema-only" explicitly, but I think it's even more generally true
that the table is likely to be empty. And the comment about temporal FKs
seems misplaced now, that should still be above the "if (!hasperiod)" check.

- Heikki

In response to

Browse pgsql-hackers by date

  From Date Subject
Previous Message Andrey Borodin 2026-11-27 08:55:37 Re: CYCLE over calculates windows functions