On 26/11/2026 03:43, David Rowley wrote:
On Thu, 26 Nov 2026 at 03:02, Heikki Linnakangas <[email protected]> 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



Reply via email to