Re: Cleaning up array_in()

jian he <jian.universality@gmail.com>

From: jian he <jian.universality@gmail.com>
To: Alexander Lakhin <exclusion@gmail.com>
Cc: Heikki Linnakangas <hlinnaka@iki.fi>, Tom Lane <tgl@sss.pgh.pa.us>, Nikhil Benesch <nikhil.benesch@gmail.com>, Nathan Bossart <nathandbossart@gmail.com>, pgsql-hackers@lists.postgresql.org
Date: 2023-09-12T08:45:29Z
Lists: pgsql-hackers

Attachments

On Mon, Sep 11, 2023 at 8:00 PM Alexander Lakhin <exclusion@gmail.com> wrote:
>
> I can confirm that all those anomalies are fixed now.
> But new version brings a warning when compiled with gcc:
> arrayfuncs.c:659:9: warning: variable 'prev_tok' is uninitialized when used here [-Wuninitialized]
>                                  if (prev_tok == ATOK_DELIM || nest_level == 0)
>                                      ^~~~~~~~
> arrayfuncs.c:628:3: note: variable 'prev_tok' is declared here
>                  ArrayToken      prev_tok;
>                  ^
> 1 warning generated.
>
> Also it looks like an updated comment needs fixing/improving:
>   /* No array dimensions, so first literal character should be oepn curl-braces */
> (should be an opening brace?)
>

fixed these 2 issues.
--query
SELECT ('{ ' || string_agg(chr((ascii('B') + round(random() * 25)) ::
integer),', ') || ' }')::text[]
FROM generate_series(1,1e6) \watch i=0.1 c=1

After applying the patch, the above query runs slightly faster.

Commits

  1. Don't specify number of dimensions in cases where we don't know it.

  2. Improve readability and error detection of array_in().

  3. Add trailing commas to enum definitions