Compare commits

...

2 Commits

Author SHA1 Message Date
Amit Langote
178ee1d858 Prevent duplicate RTEPermissionInfo for plain-inheritance parents
Currently, expand_single_inheritance_child() doesn't reset
perminfoindex in a plain-inheritance parent's child RTE, because
prior to 387f9ed0a0, the executor would use the first child RTE to
locate the parent's RTEPermissionInfo.  That in turn causes
add_rte_to_flat_rtable() to create an extra RTEPermissionInfo
belonging to the parent's child RTE with the same content as the one
belonging to the parent's original ("root") RTE.

In 387f9ed0a0, we changed things so that the executor can now use the
parent's "root" RTE for locating its RTEPermissionInfo instead of the
child RTE, so the latter's perminfoindex need not be set anymore, so
make it so.

Reported-by: Tom Lane
Discussion: https://postgr.es/m/839708.1698174464@sss.pgh.pa.us
Backpatch-through: 16
2023-10-26 11:53:41 +09:00
Tom Lane
d76606f077 Doc: remove misleading info about ecpg's CONNECT/DISCONNECT DEFAULT.
As far as I can see, ecpg has no notion of a "default" open
connection.  You can do "CONNECT TO DEFAULT" but that just specifies
letting libpq use all its default connection parameters --- the
resulting connection is not special subsequently.  In particular,
SET CONNECTION = DEFAULT and DISCONNECT DEFAULT simply act on a
connection named DEFAULT, if you've made one; they do not have
special lookup rules.  But the documentation of these commands
makes it look like they do.

Simplest fix, I think, is just to remove the paras suggesting that
DEFAULT is special here.

Also, SET CONNECTION *does* have one special lookup rule, which
is that it recognizes CURRENT as an alias for the currently selected
connection.  SET CONNECTION = CURRENT is a no-op, so it's pretty
useless, but nonetheless it does something different from selecting
a connection by name; so we'd better document it.

Per report from Sylvain Frandaz.  Back-patch to all supported
versions.

Discussion: https://postgr.es/m/169824721149.1769274.1553568436817652238@wrigleys.postgresql.org
2023-10-25 17:34:47 -04:00
2 changed files with 5 additions and 28 deletions

View File

@ -412,12 +412,6 @@ EXEC SQL DISCONNECT <optional><replaceable>connection</replaceable></optional>;
</simpara>
</listitem>
<listitem>
<simpara>
<literal>DEFAULT</literal>
</simpara>
</listitem>
<listitem>
<simpara>
<literal>CURRENT</literal>
@ -7128,7 +7122,6 @@ EXEC SQL DEALLOCATE DESCRIPTOR mydesc;
<synopsis>
DISCONNECT <replaceable class="parameter">connection_name</replaceable>
DISCONNECT [ CURRENT ]
DISCONNECT DEFAULT
DISCONNECT ALL
</synopsis>
</refsynopsisdiv>
@ -7169,15 +7162,6 @@ DISCONNECT ALL
</listitem>
</varlistentry>
<varlistentry id="ecpg-sql-disconnect-default">
<term><literal>DEFAULT</literal></term>
<listitem>
<para>
Close the default connection.
</para>
</listitem>
</varlistentry>
<varlistentry id="ecpg-sql-disconnect-all">
<term><literal>ALL</literal></term>
<listitem>
@ -7196,13 +7180,11 @@ DISCONNECT ALL
int
main(void)
{
EXEC SQL CONNECT TO testdb AS DEFAULT USER testuser;
EXEC SQL CONNECT TO testdb AS con1 USER testuser;
EXEC SQL CONNECT TO testdb AS con2 USER testuser;
EXEC SQL CONNECT TO testdb AS con3 USER testuser;
EXEC SQL DISCONNECT CURRENT; /* close con3 */
EXEC SQL DISCONNECT DEFAULT; /* close DEFAULT */
EXEC SQL DISCONNECT ALL; /* close con2 and con1 */
return 0;
@ -7770,11 +7752,11 @@ SET CONNECTION [ TO | = ] <replaceable class="parameter">connection_name</replac
</listitem>
</varlistentry>
<varlistentry id="ecpg-sql-set-connection-default">
<term><literal>DEFAULT</literal></term>
<varlistentry id="ecpg-sql-set-connection-current">
<term><literal>CURRENT</literal></term>
<listitem>
<para>
Set the connection to the default connection.
Set the connection to the current connection (thus, nothing happens).
</para>
</listitem>
</varlistentry>

View File

@ -494,13 +494,8 @@ expand_single_inheritance_child(PlannerInfo *root, RangeTblEntry *parentrte,
childrte->inh = false;
childrte->securityQuals = NIL;
/*
* No permission checking for the child RTE unless it's the parent
* relation in its child role, which only applies to traditional
* inheritance.
*/
if (childOID != parentOID)
childrte->perminfoindex = 0;
/* No permission checking for child RTEs. */
childrte->perminfoindex = 0;
/* Link not-yet-fully-filled child RTE into data structures */
parse->rtable = lappend(parse->rtable, childrte);