removing unnecessary get_att*() lsyscache functions

Started by Peter Eisentrautalmost 8 years ago6 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

won't retrysuccessCI history

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t39527
psql -h localhost -U postgres

Built from patchset v3 (message #3), July 28, 2026 at 05:08 AM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t39527_3 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t39527_3 && git checkout t39527_3

Patchset v3 (message #3) is on t39527_3

Jump to latest
#1Peter Eisentraut
peter_e@gmx.net

I noticed that get_attidentity() isn't really necessary because the
information can be obtained from an existing tuple descriptor in each case.

Also, get_atttypmod() hasn't been used since 2004.

I propose the attached patches to remove these two functions.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

0001-Remove-get_attidentity.patchtext/plain; charset=UTF-8; name=0001-Remove-get_attidentity.patch; x-mac-creator=0; x-mac-type=0Download+4-37
0002-Remove-get_atttypmod.patchtext/plain; charset=UTF-8; name=0002-Remove-get_atttypmod.patch; x-mac-creator=0; x-mac-type=0Download+1-30
#2Michael Paquier
michael@paquier.xyz
In reply to: Peter Eisentraut (#1)
Re: removing unnecessary get_att*() lsyscache functions

On Thu, Oct 18, 2018 at 09:57:00PM +0200, Peter Eisentraut wrote:

I noticed that get_attidentity() isn't really necessary because the
information can be obtained from an existing tuple descriptor in each
case.

This one is also recent, so it looks fine to remove it.

Also, get_atttypmod() hasn't been used since 2004.

github is not actually reporting areas where this is used.

I propose the attached patches to remove these two functions.

-     if (get_attidentity(RelationGetRelid(rel), attnum))
+     if (TupleDescAttr(RelationGetDescr(rel), attnum - 1)->attidentity)

I find this style heavy, saving Form_pg_attribute into a different
variable would be more readable in my opinion..
--
Michael

#3Peter Eisentraut
peter_e@gmx.net
In reply to: Michael Paquier (#2)
Re: removing unnecessary get_att*() lsyscache functions

On 19/10/2018 16:00, Michael Paquier wrote:

-     if (get_attidentity(RelationGetRelid(rel), attnum))
+     if (TupleDescAttr(RelationGetDescr(rel), attnum - 1)->attidentity)

I find this style heavy, saving Form_pg_attribute into a different
variable would be more readable in my opinion..

OK, slightly reworked version attached.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

t39527_3
v2-0001-Remove-get_atttypmod.patchtext/plain; charset=UTF-8; name=v2-0001-Remove-get_atttypmod.patch; x-mac-creator=0; x-mac-type=0Download+1-30
v2-0002-Remove-get_attidentity.patchtext/plain; charset=UTF-8; name=v2-0002-Remove-get_attidentity.patch; x-mac-creator=0; x-mac-type=0Download+11-41
#4Michael Paquier
michael@paquier.xyz
In reply to: Peter Eisentraut (#3)
Re: removing unnecessary get_att*() lsyscache functions

On Mon, Oct 22, 2018 at 07:12:28PM +0200, Peter Eisentraut wrote:

OK, slightly reworked version attached.

+ attTup = (Form_pg_attribute) GETSTRUCT(tuple);
attnum = ((Form_pg_attribute) GETSTRUCT(tuple))->attnum;

No need to call twice GETSTRUCT here.. The rest looks fine.
--
Michael

#5Andres Freund
andres@anarazel.de
In reply to: Michael Paquier (#4)
Re: removing unnecessary get_att*() lsyscache functions

Hi,

On 2018-10-23 09:11:17 +0900, Michael Paquier wrote:

On Mon, Oct 22, 2018 at 07:12:28PM +0200, Peter Eisentraut wrote:

OK, slightly reworked version attached.

+ attTup = (Form_pg_attribute) GETSTRUCT(tuple);
attnum = ((Form_pg_attribute) GETSTRUCT(tuple))->attnum;

No need to call twice GETSTRUCT here.. The rest looks fine.

Just about every optimize compiler can optimize that away, it's just a
bit of pointer magic. Obviously we don't want to repeat longer lines
superfluously, but twice isn't that bad...

Greetings,

Andres Freund

#6Peter Eisentraut
peter_e@gmx.net
In reply to: Michael Paquier (#4)
Re: removing unnecessary get_att*() lsyscache functions

On 23/10/2018 02:11, Michael Paquier wrote:

On Mon, Oct 22, 2018 at 07:12:28PM +0200, Peter Eisentraut wrote:

OK, slightly reworked version attached.

+ attTup = (Form_pg_attribute) GETSTRUCT(tuple);
attnum = ((Form_pg_attribute) GETSTRUCT(tuple))->attnum;

No need to call twice GETSTRUCT here.. The rest looks fine.

Fixed that, and committed, thanks.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services