Re: Towards easier AMs: Cleaning up inappropriate use of name "relkind"

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Mark Dilger <mark(dot)dilger(at)enterprisedb(dot)com>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Towards easier AMs: Cleaning up inappropriate use of name "relkind"
Date: 2020-07-11 19:32:55
Message-ID: 2446657.1594495975@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Mark Dilger <mark(dot)dilger(at)enterprisedb(dot)com> writes:
> On Jul 10, 2020, at 11:00 PM, Michael Paquier <michael(at)paquier(dot)xyz> wrote:
>> I am not really a fan of this patch. I could see a benefit in
>> switching to an enum so as for places where we use a switch/case
>> without a default we would be warned if a new relkind gets added or if
>> a value is not covered, but then we should not really need
>> RELKIND_NULL, no?

> There are code paths where relkind is sometimes '\0' under normal, non-exceptional conditions. This happens in

> allpaths.c: set_append_rel_size
> rewriteHandler.c: view_query_is_auto_updatable
> lockcmds.c: LockViewRecurse_walker
> pg_depend.c: getOwnedSequences_internal

> Doesn't this justify having RELKIND_NULL in the enum?

I'd say no. I think including an intentionally invalid value in such
an enum is horrid, mainly because it will force a lot of places to cover
that value when they shouldn't (or else draw "enum value not handled in
switch" warnings). The confusion factor about whether it maybe *is*
a valid value is not to be discounted, either.

If we can't readily get rid of the use of '\0' in these code paths,
maybe trying to convert to an enum isn't going to be a win after all.

> Getting the compiler to warn when a new relkind is added to the
> enumeration but not handled in a switch is difficult.

We already have a project policy about how to do that.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2020-07-11 19:59:12 Re: output columns of \dAo and \dAp
Previous Message Soumyadeep Chakraborty 2020-07-11 19:25:08 Re: Does TupleQueueReaderNext() really need to copy its result?