Remove redundant if-else in EXPLAIN by using ExplainPropertyText

Started by Ilia Evdokimovover 1 year ago3 messageshackers
Jump to latest
#1Ilia Evdokimov
ilya.evdokimov@tantorlabs.com

Hi hackers,

Thanks to David [0]/messages/by-id/CAApHDvpq2gOt3gnzkd4Ud=wrT7YRGrF3zb29jgWzDsYEhETrOA@mail.gmail.com, we found that the if and else branches contained
equivalent code. Since ExplainPropertyText already handles non-text
formats, the extra condition is unnecessary.

I reviewed other files related to EXPLAIN where similar patterns might
exist, but this was the only instance I found.

I’m attaching a patch with the fix. If anyone spots a similar case
elsewhere, please let me know.

[0]: /messages/by-id/CAApHDvpq2gOt3gnzkd4Ud=wrT7YRGrF3zb29jgWzDsYEhETrOA@mail.gmail.com
/messages/by-id/CAApHDvpq2gOt3gnzkd4Ud=wrT7YRGrF3zb29jgWzDsYEhETrOA@mail.gmail.com

--
Best regards,
Ilia Evdokimov,
Tantor Labs LLC.

Attachments:

v1-0001-Remove-redundant-if-else-in-EXPLAIN.patchtext/x-patch; charset=UTF-8; name=v1-0001-Remove-redundant-if-else-in-EXPLAIN.patchDownload+3-13
#2David Rowley
dgrowleyml@gmail.com
In reply to: Ilia Evdokimov (#1)
Re: Remove redundant if-else in EXPLAIN by using ExplainPropertyText

On Fri, 21 Mar 2025 at 09:24, Ilia Evdokimov
<ilya.evdokimov@tantorlabs.com> wrote:

Thanks to David [0], we found that the if and else branches contained
equivalent code. Since ExplainPropertyText already handles non-text
formats, the extra condition is unnecessary.

I reviewed other files related to EXPLAIN where similar patterns might
exist, but this was the only instance I found.

I looked at; git grep -E "appendStringInfo.*\\n" --
src/backend/commands/explain.c and all those results are appending
multiple options. No single option ones.

The patch looks good to me and seems worth applying to master. I feel
this should be fixed to avoid misleading future patches that add new
properties to Memoize into copying the same pattern.

David

#3David Rowley
dgrowleyml@gmail.com
In reply to: David Rowley (#2)
Re: Remove redundant if-else in EXPLAIN by using ExplainPropertyText

On Fri, 21 Mar 2025 at 10:12, David Rowley <dgrowleyml@gmail.com> wrote:

The patch looks good to me and seems worth applying to master.

Ok. Pushed.

David