[PATCH v1] eliminate duplicate code in table.c

Started by Junwang Zhaoalmost 4 years ago18 messageshackers
Jump to latest
#1Junwang Zhao
zhjwpku@gmail.com

There are some duplicate code in table.c, add a static inline function
to eliminate the duplicates.

--
Regards
Junwang Zhao

Attachments:

0001-eliminate-duplicate-code-in-table.c.patchapplication/octet-stream; name=0001-eliminate-duplicate-code-in-table.c.patchDownload+28-47
#2Amit Kapila
amit.kapila16@gmail.com
In reply to: Junwang Zhao (#1)
Re: [PATCH v1] eliminate duplicate code in table.c

On Thu, Jul 21, 2022 at 1:56 PM Junwang Zhao <zhjwpku@gmail.com> wrote:

There are some duplicate code in table.c, add a static inline function
to eliminate the duplicates.

Can we name function as validate_object_type, or check_object_type?

Otherwise, the patch looks fine to me. Let's see if others have
something to say.

--
With Regards,
Amit Kapila.

#3Aleksander Alekseev
aleksander@timescale.com
In reply to: Amit Kapila (#2)
Re: [PATCH v1] eliminate duplicate code in table.c

Hi hackers,

There are some duplicate code in table.c, add a static inline function
to eliminate the duplicates.

Can we name function as validate_object_type, or check_object_type?

Otherwise, the patch looks fine to me. Let's see if others have
something to say.

LGTM

--
Best regards,
Aleksander Alekseev

Attachments:

v2-0001-Eliminate-duplicate-code-in-table.c.patchapplication/octet-stream; name=v2-0001-Eliminate-duplicate-code-in-table.c.patchDownload+28-47
#4Amit Kapila
amit.kapila16@gmail.com
In reply to: Aleksander Alekseev (#3)
Re: [PATCH v1] eliminate duplicate code in table.c

On Thu, Jul 21, 2022 at 5:09 PM Aleksander Alekseev
<aleksander@timescale.com> wrote:

There are some duplicate code in table.c, add a static inline function
to eliminate the duplicates.

Can we name function as validate_object_type, or check_object_type?

Otherwise, the patch looks fine to me. Let's see if others have
something to say.

LGTM

@@ -161,10 +121,32 @@ table_openrv_extended(const RangeVar *relation,
LOCKMODE lockmode,
*
* Note that it is often sensible to hold a lock beyond relation_close;
* in that case, the lock is released automatically at xact end.
- * ----------------
+ * ----------------
*/
void
table_close(Relation relation, LOCKMODE lockmode)

I don't think this change should be part of this patch. Do you see a
reason for doing this?

--
With Regards,
Amit Kapila.

#5Aleksander Alekseev
aleksander@timescale.com
In reply to: Amit Kapila (#4)
Re: [PATCH v1] eliminate duplicate code in table.c

Hi Amit,

I don't think this change should be part of this patch. Do you see a
reason for doing this?

My bad. I thought this was done by pgindent.

--
Best regards,
Aleksander Alekseev

Attachments:

v3-0001-Eliminate-duplicate-code-in-table.c.patchapplication/octet-stream; name=v3-0001-Eliminate-duplicate-code-in-table.c.patchDownload+27-45
#6Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Junwang Zhao (#1)
Re: [PATCH v1] eliminate duplicate code in table.c

On 2022-Jul-21, Junwang Zhao wrote:

There are some duplicate code in table.c, add a static inline function
to eliminate the duplicates.

Hmm, but see commit 2ed532ee8c47 about this kind of check. Perhaps we
should change these error messages to conform to the same message style.

--
Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/
"I love the Postgres community. It's all about doing things _properly_. :-)"
(David Garamond)

#7Aleksander Alekseev
aleksander@timescale.com
In reply to: Alvaro Herrera (#6)
Re: [PATCH v1] eliminate duplicate code in table.c

Hi Alvaro,

Hmm, but see commit 2ed532ee8c47 about this kind of check. Perhaps we
should change these error messages to conform to the same message style.

Good point! Done.

--
Best regards,
Aleksander Alekseev

Attachments:

v4-0001-Eliminate-duplicate-code-in-table.c.patchapplication/octet-stream; name=v4-0001-Eliminate-duplicate-code-in-table.c.patchDownload+26-48
#8Amit Kapila
amit.kapila16@gmail.com
In reply to: Aleksander Alekseev (#7)
Re: [PATCH v1] eliminate duplicate code in table.c

On Thu, Jul 21, 2022 at 6:12 PM Aleksander Alekseev
<aleksander@timescale.com> wrote:

Hi Alvaro,

Hmm, but see commit 2ed532ee8c47 about this kind of check. Perhaps we
should change these error messages to conform to the same message style.

Good point! Done.

Yeah, that's better. On again thinking about the function name, I
wonder if validate_relation_type() suits here as there is no generic
object being passed?

--
With Regards,
Amit Kapila.

#9Aleksander Alekseev
aleksander@timescale.com
In reply to: Amit Kapila (#8)
Re: [PATCH v1] eliminate duplicate code in table.c

Hi Amit,

Yeah, that's better. On again thinking about the function name, I
wonder if validate_relation_type() suits here as there is no generic
object being passed?

Yep, validate_relation_type() sounds better.

--
Best regards,
Aleksander Alekseev

Attachments:

v5-0001-Eliminate-duplicate-code-in-table.c.patchapplication/octet-stream; name=v5-0001-Eliminate-duplicate-code-in-table.c.patchDownload+26-48
#10Aleksander Alekseev
aleksander@timescale.com
In reply to: Aleksander Alekseev (#9)
Re: [PATCH v1] eliminate duplicate code in table.c

Hi Amit,

Yep, validate_relation_type() sounds better.

Or maybe validate_relation_kind() after all?

--
Best regards,
Aleksander Alekseev

#11Junwang Zhao
zhjwpku@gmail.com
In reply to: Aleksander Alekseev (#10)
Re: [PATCH v1] eliminate duplicate code in table.c

yeah, IMHO validate_relation_kind() is better ;)

On Thu, Jul 21, 2022 at 10:21 PM Aleksander Alekseev
<aleksander@timescale.com> wrote:

Hi Amit,

Yep, validate_relation_type() sounds better.

Or maybe validate_relation_kind() after all?

--
Best regards,
Aleksander Alekseev

--
Regards
Junwang Zhao

#12Junwang Zhao
zhjwpku@gmail.com
In reply to: Aleksander Alekseev (#9)
Re: [PATCH v1] eliminate duplicate code in table.c

btw, there are some typos in Patch v5, %s/ralation/relation/g

On Thu, Jul 21, 2022 at 10:05 PM Aleksander Alekseev
<aleksander@timescale.com> wrote:

Hi Amit,

Yeah, that's better. On again thinking about the function name, I
wonder if validate_relation_type() suits here as there is no generic
object being passed?

Yep, validate_relation_type() sounds better.

--
Best regards,
Aleksander Alekseev

--
Regards
Junwang Zhao

#13Aleksander Alekseev
aleksander@timescale.com
In reply to: Junwang Zhao (#12)
Re: [PATCH v1] eliminate duplicate code in table.c

Hi Junwang,

btw, there are some typos in Patch v5, %s/ralation/relation/g

D'oh!

yeah, IMHO validate_relation_kind() is better ;)

Cool. Here is the corrected patch. Thanks!

--
Best regards,
Aleksander Alekseev

Attachments:

v6-0001-Eliminate-duplicate-code-in-table.c.patchapplication/octet-stream; name=v6-0001-Eliminate-duplicate-code-in-table.c.patchDownload+26-48
#14Junwang Zhao
zhjwpku@gmail.com
In reply to: Aleksander Alekseev (#13)
Re: [PATCH v1] eliminate duplicate code in table.c

LGTM

On Thu, Jul 21, 2022 at 11:52 PM Aleksander Alekseev
<aleksander@timescale.com> wrote:

Hi Junwang,

btw, there are some typos in Patch v5, %s/ralation/relation/g

D'oh!

yeah, IMHO validate_relation_kind() is better ;)

Cool. Here is the corrected patch. Thanks!

--
Best regards,
Aleksander Alekseev

--
Regards
Junwang Zhao

#15Kyotaro Horiguchi
horikyota.ntt@gmail.com
In reply to: Junwang Zhao (#14)
Re: [PATCH v1] eliminate duplicate code in table.c

Hi.

+ errmsg("cannot operate on relation \"%s\"",

Other callers of errdetail_relkind_not_supported() describing
operations concretely. In that sense we I think should say "cannot
open relation \"%s\"" here.

regards.

--
Kyotaro Horiguchi
NTT Open Source Software Center

#16Amit Kapila
amit.kapila16@gmail.com
In reply to: Kyotaro Horiguchi (#15)
Re: [PATCH v1] eliminate duplicate code in table.c

On Fri, Jul 22, 2022 at 7:39 AM Kyotaro Horiguchi
<horikyota.ntt@gmail.com> wrote:

+ errmsg("cannot operate on relation \"%s\"",

Other callers of errdetail_relkind_not_supported() describing
operations concretely. In that sense we I think should say "cannot
open relation \"%s\"" here.

Sounds reasonable to me. This will give more precise information to the user.

--
With Regards,
Amit Kapila.

#17Junwang Zhao
zhjwpku@gmail.com
In reply to: Amit Kapila (#16)
Re: [PATCH v1] eliminate duplicate code in table.c

Here is the patch v7. Thanks!

On Fri, Jul 22, 2022 at 1:15 PM Amit Kapila <amit.kapila16@gmail.com> wrote:

On Fri, Jul 22, 2022 at 7:39 AM Kyotaro Horiguchi
<horikyota.ntt@gmail.com> wrote:

+ errmsg("cannot operate on relation \"%s\"",

Other callers of errdetail_relkind_not_supported() describing
operations concretely. In that sense we I think should say "cannot
open relation \"%s\"" here.

Sounds reasonable to me. This will give more precise information to the user.

--
With Regards,
Amit Kapila.

--
Regards
Junwang Zhao

Attachments:

v7-0001-Eliminate-duplicate-code-in-table.c.patchapplication/octet-stream; name=v7-0001-Eliminate-duplicate-code-in-table.c.patchDownload+26-48
#18Amit Kapila
amit.kapila16@gmail.com
In reply to: Junwang Zhao (#17)
Re: [PATCH v1] eliminate duplicate code in table.c

On Fri, Jul 22, 2022 at 1:37 PM Junwang Zhao <zhjwpku@gmail.com> wrote:

Here is the patch v7. Thanks!

LGTM. I'll push this sometime early next week unless there are more
suggestions/comments.

--
With Regards,
Amit Kapila.