Re: Remove redundant assignment of a variable in function AlterPublicationTables - Mailing list pgsql-hackers

From Michael Paquier
Subject Re: Remove redundant assignment of a variable in function AlterPublicationTables
Date
Msg-id aKZkJaqzKStuoQK0@paquier.xyz
Whole thread Raw
In response to Re: Remove redundant assignment of a variable in function AlterPublicationTables  (Chao Li <li.evan.chao@gmail.com>)
Responses Re: Remove redundant assignment of a variable in function AlterPublicationTables
Re: Remove redundant assignment of a variable in function AlterPublicationTables
List pgsql-hackers
On Wed, Aug 20, 2025 at 05:18:53PM +0800, Chao Li wrote:
> If we look into the subsequent functions, yes, “isnull” will always
> be assigned. But how about if someone incidentally changed a
> subsequent function and moved an assignment?
> I think giving an initial value is a good habit without much
> performance burden.

It does not matter to leave the code as is.  We have a bunch of these
depending on how people feel on the day when they implement something.

Compilers are smart enough to optimize such things away when they don't
matter, usually.  Some compiler versions and flags can also be very
picky with initializations not done, missing that sometimes a variable
is actually set in all the relevant code paths.  Warnings can show
depending on the complexity of the branches used, as well.
--
Michael

Attachment

pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: pg_get_sequence_data Shows Non-NULL last_value for Freshly Created Sequence
Next
From: Chao Li
Date:
Subject: Re: Remove redundant assignment of a variable in function AlterPublicationTables