ObjectIdGetDatum() missing from SearchSysCache*() callers

Lists: pgsql-hackers
From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: ObjectIdGetDatum() missing from SearchSysCache*() callers
Date: 2023-07-17 11:10:34
Message-ID: [email protected]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi all,

While scanning the code, I have noticed that a couple of code paths
that do syscache lookups are passing down directly Oids rather than
Datums. I think that we'd better be consistent here, even if there is
no actual bug.

I have noticed 11 callers of SearchSysCache*() that pass down
an Oid instead of a Datum.

Thoughts or comments?
--
Michael

Attachment Content-Type Size
syscache-datums.patch text/x-diff 5.4 KB

From: Aleksander Alekseev <aleksander(at)timescale(dot)com>
To: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>
Subject: Re: ObjectIdGetDatum() missing from SearchSysCache*() callers
Date: 2023-07-17 12:36:45
Message-ID: CAJ7c6TPfDV_19KB5MkDaUVYhOv_Hk19UzezATYfDm6Nrr063fw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi,

> I have noticed 11 callers of SearchSysCache*() that pass down
> an Oid instead of a Datum.

Good catch.

> I think that we'd better be consistent here, even if there is
> no actual bug.
>

+1

--
Best regards,
Aleksander Alekseev


From: Zhang Mingli <zmlpostgres(at)gmail(dot)com>
To: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Michael Paquier <michael(at)paquier(dot)xyz>
Subject: Re: ObjectIdGetDatum() missing from SearchSysCache*() callers
Date: 2023-07-17 13:09:01
Message-ID: 0a6ee217-6958-4f13-9af8-61904f677f09@Spark
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi

Regards,
Zhang Mingli
On Jul 17, 2023 at 19:10 +0800, Michael Paquier <michael(at)paquier(dot)xyz>, wrote:
> Hi all,
>
> While scanning the code, I have noticed that a couple of code paths
> that do syscache lookups are passing down directly Oids rather than
> Datums. I think that we'd better be consistent here, even if there is
> no actual bug.
>
> I have noticed 11 callers of SearchSysCache*() that pass down
> an Oid instead of a Datum.
>
> Thoughts or comments?
> --
> Michael
LGTM, and there are two functions missed, in sequence_options

 pgstuple = SearchSysCache1(SEQRELID, relid);

Shall we fix that too?


From: Zhang Mingli <zmlpostgres(at)gmail(dot)com>
To: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Michael Paquier <michael(at)paquier(dot)xyz>
Subject: Re: ObjectIdGetDatum() missing from SearchSysCache*() callers
Date: 2023-07-17 13:11:22
Message-ID: 50061d8e-e3fc-42bf-9162-59d72ba57a84@Spark
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi,

Regards,
Zhang Mingli
On Jul 17, 2023 at 21:09 +0800, Zhang Mingli <zmlpostgres(at)gmail(dot)com>, wrote:
> sequence_options
And inside pg_sequence_parameters:
pgstuple = SearchSysCache1(SEQRELID, relid);


From: Aleksander Alekseev <aleksander(at)timescale(dot)com>
To: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, Zhang Mingli <zmlpostgres(at)gmail(dot)com>
Subject: Re: ObjectIdGetDatum() missing from SearchSysCache*() callers
Date: 2023-07-17 14:33:42
Message-ID: CAJ7c6TMU7L3nQQSebUJJ6G2fp4E9o3kVnkRjmaOi3wG6Jxb8KA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi,

> And inside pg_sequence_parameters:
> pgstuple = SearchSysCache1(SEQRELID, relid);

Found another one in partcache.c:

```
/* Get pg_class.relpartbound */
tuple = SearchSysCache1(RELOID, RelationGetRelid(rel));
```

I can't be 100% sure but it looks like that's all of them. PFA the
updated patch v2.

--
Best regards,
Aleksander Alekseev

Attachment Content-Type Size
v2-0001-Pass-Datum-to-SearchSysCache-instead-of-Oid.patch application/octet-stream 7.8 KB

From: Aleksander Alekseev <aleksander(at)timescale(dot)com>
To: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, Zhang Mingli <zmlpostgres(at)gmail(dot)com>
Subject: Re: ObjectIdGetDatum() missing from SearchSysCache*() callers
Date: 2023-07-17 14:38:41
Message-ID: CAJ7c6TPaRHE2Jt=F2nbUQungA=1tbR4NCWjyWqXrbdiJHEANCQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi,

> > And inside pg_sequence_parameters:
> > pgstuple = SearchSysCache1(SEQRELID, relid);
>
> Found another one in partcache.c:
>
> ```
> /* Get pg_class.relpartbound */
> tuple = SearchSysCache1(RELOID, RelationGetRelid(rel));
> ```
>
> I can't be 100% sure but it looks like that's all of them. PFA the
> updated patch v2.

Added a CF entry, just in case:
https://commitfest.postgresql.org/44/4448/

--
Best regards,
Aleksander Alekseev


From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Aleksander Alekseev <aleksander(at)timescale(dot)com>
Cc: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Zhang Mingli <zmlpostgres(at)gmail(dot)com>
Subject: Re: ObjectIdGetDatum() missing from SearchSysCache*() callers
Date: 2023-07-17 22:27:02
Message-ID: [email protected]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Jul 17, 2023 at 05:33:42PM +0300, Aleksander Alekseev wrote:
> I can't be 100% sure but it looks like that's all of them. PFA the
> updated patch v2.

Thanks. Yes, this stuff is easy to miss. I was just grepping for a
few patterns and missed these two.
--
Michael


From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Aleksander Alekseev <aleksander(at)timescale(dot)com>
Cc: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Zhang Mingli <zmlpostgres(at)gmail(dot)com>
Subject: Re: ObjectIdGetDatum() missing from SearchSysCache*() callers
Date: 2023-07-20 06:28:19
Message-ID: ZLjUA54A/[email protected]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Jul 18, 2023 at 07:27:02AM +0900, Michael Paquier wrote:
> On Mon, Jul 17, 2023 at 05:33:42PM +0300, Aleksander Alekseev wrote:
> > I can't be 100% sure but it looks like that's all of them. PFA the
> > updated patch v2.
>
> Thanks. Yes, this stuff is easy to miss. I was just grepping for a
> few patterns and missed these two.

Spotted a few more of these things after a second lookup.

One for subscriptions:
src/backend/commands/alter.c:
if (SearchSysCacheExists2(SUBSCRIPTIONNAME, MyDatabaseId,

And two for transforms:
src/backend/utils/cache/lsyscache.c:
tup = SearchSysCache2(TRFTYPELANG, typid, langid);
src/backend/utils/cache/lsyscache.c:
tup = SearchSysCache2(TRFTYPELANG, typid, langid);

And applied the whole. Thanks for looking and spot more of these
inconsistencies!
--
Michael