pgsql: Use a hash table to de-duplicate column names in ruleutils.c.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Use a hash table to de-duplicate column names in ruleutils.c.
Date: 2024-09-10 20:49:13
Message-ID: E1so7nV-000UaJ-8F@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Use a hash table to de-duplicate column names in ruleutils.c.

Commit 8004953b5 added a hash table to avoid O(N^2) cost in choosing
unique relation aliases while deparsing a view or rule. It did
nothing about the similar O(N^2) (maybe worse) costs of choosing
unique column aliases within each RTE. However, that's now
demonstrably a bottleneck when deparsing CHECK constraints for wide
tables, so let's use a similar hash table to handle those.

The extra cost of setting up the hash table will not be repaid unless
the table has many columns. I've set this up so that we use the brute
force method if there are less than 32 columns. The exact cutoff is
not too critical, but this value seems good because it results in both
code paths getting exercised by existing regression-test cases.

Patch by me; thanks to David Rowley for review.

Discussion: https://postgr.es/m/2885468.1722291250@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/52c707483ce4d0161127e4958d981d1b5655865e

Modified Files
--------------
src/backend/utils/adt/ruleutils.c | 188 +++++++++++++++++++++++++++++++++-----
1 file changed, 165 insertions(+), 23 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Noah Misch 2024-09-10 22:24:31 pgsql: Optimize pg_visibility with read streams.
Previous Message Tom Lane 2024-09-10 20:20:39 pgsql: Fix some whitespace issues in XMLSERIALIZE(... INDENT).