postgres_fdw: Useless if-test in GetConnection()

Started by Etsuro Fujitaabout 3 years ago6 messageshackers
Jump to latest
#1Etsuro Fujita
fujita.etsuro@lab.ntt.co.jp

Hi,

While working on something else, I noticed that the “if (entry->conn
== NULL)” test after doing disconnect_pg_server() when re-establishing
a given connection in GetConnection() is pointless, because the former
function ensures that entry->conn is NULL. So I removed the if-test.
Attached is a patch for that. I think we could instead add an
assertion, but I did not, because we already have it in
make_new_connection().

This would be harmless, so I am planning to apply the patch to HEAD only.

Best regards,
Etsuro Fujita

Attachments:

remove-useless-if-test.patchapplication/octet-stream; name=remove-useless-if-test.patchDownload+1-2
#2Richard Guo
guofenglinux@gmail.com
In reply to: Etsuro Fujita (#1)
Re: postgres_fdw: Useless if-test in GetConnection()

On Wed, Mar 15, 2023 at 6:18 PM Etsuro Fujita <etsuro.fujita@gmail.com>
wrote:

While working on something else, I noticed that the “if (entry->conn
== NULL)” test after doing disconnect_pg_server() when re-establishing
a given connection in GetConnection() is pointless, because the former
function ensures that entry->conn is NULL. So I removed the if-test.
Attached is a patch for that. I think we could instead add an
assertion, but I did not, because we already have it in
make_new_connection().

+1. Good catch.

Thanks
Richard

#3Daniel Gustafsson
daniel@yesql.se
In reply to: Etsuro Fujita (#1)
Re: postgres_fdw: Useless if-test in GetConnection()

On 15 Mar 2023, at 11:18, Etsuro Fujita <etsuro.fujita@gmail.com> wrote:

While working on something else, I noticed that the “if (entry->conn
== NULL)” test after doing disconnect_pg_server() when re-establishing
a given connection in GetConnection() is pointless, because the former
function ensures that entry->conn is NULL. So I removed the if-test.
Attached is a patch for that.

LGTM, nice catch.

I think we could instead add an assertion, but I did not, because we already
have it in make_new_connection().

Agreed, the assertion in make_new_connection is enough (and is needed there).

--
Daniel Gustafsson

#4Etsuro Fujita
fujita.etsuro@lab.ntt.co.jp
In reply to: Richard Guo (#2)
Re: postgres_fdw: Useless if-test in GetConnection()

On Wed, Mar 15, 2023 at 7:40 PM Richard Guo <guofenglinux@gmail.com> wrote:

On Wed, Mar 15, 2023 at 6:18 PM Etsuro Fujita <etsuro.fujita@gmail.com> wrote:

While working on something else, I noticed that the “if (entry->conn
== NULL)” test after doing disconnect_pg_server() when re-establishing
a given connection in GetConnection() is pointless, because the former
function ensures that entry->conn is NULL. So I removed the if-test.
Attached is a patch for that. I think we could instead add an
assertion, but I did not, because we already have it in
make_new_connection().

+1. Good catch.

Cool! Thanks for looking!

Best regards,
Etsuro Fujita

#5Etsuro Fujita
fujita.etsuro@lab.ntt.co.jp
In reply to: Daniel Gustafsson (#3)
Re: postgres_fdw: Useless if-test in GetConnection()

On Wed, Mar 15, 2023 at 7:58 PM Daniel Gustafsson <daniel@yesql.se> wrote:

On 15 Mar 2023, at 11:18, Etsuro Fujita <etsuro.fujita@gmail.com> wrote:
While working on something else, I noticed that the “if (entry->conn
== NULL)” test after doing disconnect_pg_server() when re-establishing
a given connection in GetConnection() is pointless, because the former
function ensures that entry->conn is NULL. So I removed the if-test.
Attached is a patch for that.

LGTM, nice catch.

I think we could instead add an assertion, but I did not, because we already
have it in make_new_connection().

Agreed, the assertion in make_new_connection is enough (and is needed there).

Great! Thanks for looking!

Best regards,
Etsuro Fujita

#6Etsuro Fujita
fujita.etsuro@lab.ntt.co.jp
In reply to: Etsuro Fujita (#1)
Re: postgres_fdw: Useless if-test in GetConnection()

On Wed, Mar 15, 2023 at 7:18 PM Etsuro Fujita <etsuro.fujita@gmail.com> wrote:

This would be harmless, so I am planning to apply the patch to HEAD only.

I forgot to mention that this was added in v14. Done that way.

Best regards,
Etsuro Fujita