Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kZItM-0004UM-K1 for pgsql-hackers@arkaria.postgresql.org; Sun, 01 Nov 2020 19:19:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kZItL-0000c7-7x for pgsql-hackers@arkaria.postgresql.org; Sun, 01 Nov 2020 19:19:51 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kZItL-0000c0-1B for pgsql-hackers@lists.postgresql.org; Sun, 01 Nov 2020 19:19:51 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kZItG-0002xZ-Tc for pgsql-hackers@lists.postgresql.org; Sun, 01 Nov 2020 19:19:50 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 0A1JJiTQ472275 for ; Sun, 1 Nov 2020 14:19:44 -0500 From: Tom Lane To: pgsql-hackers@lists.postgresql.org Subject: Getting Gen_fmgrtab.pl to generate macros for all pg_proc entries MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <472235.1604258319.0@sss.pgh.pa.us> Date: Sun, 01 Nov 2020 14:19:44 -0500 Message-ID: <472274.1604258384@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <472235.1604258319.1@sss.pgh.pa.us> Over in [1] I noted a need for fmgroids.h macros for pg_proc entries that overload a particular C function. The F_XXX macros seem to be designed on the assumption that the only thing they're needed for is to call the function, so you don't really care which SQL alias you use to get there. That's unhelpful though when you are concerned with the SQL-level function more than the C function. I seem to recall that we've run into this before, but up to now have been able to work around it. A narrow solution would be to revert the policy we just established (in commit 36b931214) against allowing oid_symbol entries in pg_proc.dat, and just manually label such entries when we need to refer to them in the C code. I don't especially care for that though, for the reasons cited in 36b931214 --- it'll lead to a lot of random variation in how people refer to pg_proc entries, rather than having a uniform convention. I experimented with generating the fmgroids.h macros by using, not the prosrc field, but the concatenation of the proname and proargtypes fields. That's guaranteed unique within pg_proc, but it would have resulted in several hundred required changes in our source tree, because of common references to F_OIDEQ and suchlike. But I discovered that we could alter the rule to be "append proargtypes only if proname is not unique", and that eliminates the pain almost completely: only two existing code references need to change. As an additional benefit, we can generate macros for all the bootstrap pg_proc entries, not only ones that are for C functions; that fixes another issue noted in [1]. Hence, I propose the attached. Any objections? regards, tom lane [1] https://www.postgresql.org/message-id/298489.1604188643%40sss.pgh.pa.us ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="revise-fmgroids.h-generation-rule.patch"; charset="us-ascii" Content-ID: <472235.1604258319.2@sss.pgh.pa.us> Content-Description: revise-fmgroids.h-generation-rule.patch Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/optimizer/util/clauses.c b/src/backend/optimizer/= util/clauses.c index e7d814651b..85ef873caa 100644 --- a/src/backend/optimizer/util/clauses.c +++ b/src/backend/optimizer/util/clauses.c @@ -779,7 +779,7 @@ contain_volatile_functions_not_nextval(Node *clause) static bool contain_volatile_functions_not_nextval_checker(Oid func_id, void *context= ) { - return (func_id !=3D F_NEXTVAL_OID && + return (func_id !=3D F_NEXTVAL && func_volatile(func_id) =3D=3D PROVOLATILE_VOLATILE); } = diff --git a/src/backend/utils/Gen_fmgrtab.pl b/src/backend/utils/Gen_fmgr= tab.pl index b7c7b4c8fa..a3f7307263 100644 --- a/src/backend/utils/Gen_fmgrtab.pl +++ b/src/backend/utils/Gen_fmgrtab.pl @@ -64,22 +64,26 @@ foreach my $datfile (@ARGV) = # Collect certain fields from pg_proc.dat. my @fmgr =3D (); +my %proname_counts; = foreach my $row (@{ $catalog_data{pg_proc} }) { my %bki_values =3D %$row; = - # Select out just the rows for internal-language procedures. - next if $bki_values{prolang} ne 'internal'; - push @fmgr, { oid =3D> $bki_values{oid}, + name =3D> $bki_values{proname}, + args =3D> $bki_values{proargtypes}, strict =3D> $bki_values{proisstrict}, retset =3D> $bki_values{proretset}, nargs =3D> $bki_values{pronargs}, + lang =3D> $bki_values{prolang}, prosrc =3D> $bki_values{prosrc}, }; + + # Count so that we can detect overloaded pronames. + $proname_counts{ $bki_values{proname} }++; } = # Emit headers for both files @@ -122,13 +126,10 @@ print $ofh <{oid} <=3D> $b->{oid} } @fmgr) { - next if $seenit{ $s->{prosrc} }; - $seenit{ $s->{prosrc} } =3D 1; - print $ofh "#define F_" . uc $s->{prosrc} . " $s->{oid}\n"; - print $pfh "extern Datum $s->{prosrc}(PG_FUNCTION_ARGS);\n"; + my $sqlname =3D $s->{name}; + $sqlname .=3D "_" . $s->{args} if ($proname_counts{ $s->{name} } > 1); + $sqlname =3D~ tr/ /_/; + print $ofh "#define F_" . uc $sqlname . " $s->{oid}\n"; + # We want only one extern per internal-language function + if ($s->{lang} eq 'internal' && !$seenit{ $s->{prosrc} }) + { + $seenit{ $s->{prosrc} } =3D 1; + print $pfh "extern Datum $s->{prosrc}(PG_FUNCTION_ARGS);\n"; + } } = # Create the fmgr_builtins table, collect data for fmgr_builtin_oid_index @@ -206,22 +213,16 @@ my $last_builtin_oid =3D 0; my $fmgr_count =3D 0; foreach my $s (sort { $a->{oid} <=3D> $b->{oid} } @fmgr) { + next if $s->{lang} ne 'internal'; + + print $tfh ",\n" if ($fmgr_count > 0); print $tfh " { $s->{oid}, $s->{nargs}, $bmap{$s->{strict}}, $bmap{$s->{retset}},= \"$s->{prosrc}\", $s->{prosrc} }"; = $fmgr_builtin_oid_index[ $s->{oid} ] =3D $fmgr_count++; $last_builtin_oid =3D $s->{oid}; - - if ($fmgr_count <=3D $#fmgr) - { - print $tfh ",\n"; - } - else - { - print $tfh "\n"; - } } -print $tfh "};\n"; +print $tfh "\n};\n"; = printf $tfh qq| const int fmgr_nbuiltins =3D (sizeof(fmgr_builtins) / sizeof(FmgrBuiltin)= ); diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/rul= eutils.c index 6c656586e8..7446193252 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -10144,7 +10144,7 @@ get_from_clause_item(Node *jtnode, Query *query, d= eparse_context *context) RangeTblFunction *rtfunc =3D (RangeTblFunction *) lfirst(lc); = if (!IsA(rtfunc->funcexpr, FuncExpr) || - ((FuncExpr *) rtfunc->funcexpr)->funcid !=3D F_ARRAY_UNNEST || + ((FuncExpr *) rtfunc->funcexpr)->funcid !=3D F_UNNEST_ANYARRAY || rtfunc->funccolnames !=3D NIL) { all_unnest =3D false; ------- =_aaaaaaaaaa0--