pgsql: Don't leak a signalfd when using latches in the postmaster.

2022-12-22 Thread Thomas Munro
Don't leak a signalfd when using latches in the postmaster. At the time of commit 6a2a70a02 we didn't use latch infrastructure in the postmaster. We're planning to start doing that, so we'd better make sure that the signalfd inherited from a postmaster is not duplicated and then leaked in the

pgsql: Allow parent's WaitEventSets to be freed after fork().

2022-12-22 Thread Thomas Munro
Allow parent's WaitEventSets to be freed after fork(). An epoll fd belonging to the parent should be closed in the child. A kqueue fd is automatically closed by fork(), but we should still adjust our counter. For poll and Windows systems, nothing special is required. On all systems we free the

pgsql: Add WL_SOCKET_ACCEPT event to WaitEventSet API.

2022-12-22 Thread Thomas Munro
Add WL_SOCKET_ACCEPT event to WaitEventSet API. To be able to handle incoming connections on a server socket with the WaitEventSet API, we'll need a new kind of event to indicate that the the socket is ready to accept a connection. On Unix, it's just the same as WL_SOCKET_READABLE, but on

pgsql: Update upgrade_adapt.sql to handle tables using aclitem as data

2022-12-22 Thread Michael Paquier
Update upgrade_adapt.sql to handle tables using aclitem as data type The regression test suite includes a table called "tab_core_types" that has one attribute based on the type "aclitem". Keeping this attribute as-is causes hard failures when running pg_upgrade with an origin on ~15. This

pgsql: Fix some incorrectness in upgrade_adapt.sql on query for WITH OI

2022-12-22 Thread Michael Paquier
Fix some incorrectness in upgrade_adapt.sql on query for WITH OIDS The query used to disable WITH OIDS in all the relations making use of it was checking for materialized views, but this is not a supported operation. On the contrary, this needs to be done on foreign tables. While on it, use

pgsql: Fix some incorrectness in upgrade_adapt.sql on query for WITH OI

2022-12-22 Thread Michael Paquier
Fix some incorrectness in upgrade_adapt.sql on query for WITH OIDS The query used to disable WITH OIDS in all the relations making use of it was checking for materialized views, but this is not a supported operation. On the contrary, this needs to be done on foreign tables. While on it, use

pgsql: Fix some incorrectness in upgrade_adapt.sql on query for WITH OI

2022-12-22 Thread Michael Paquier
Fix some incorrectness in upgrade_adapt.sql on query for WITH OIDS The query used to disable WITH OIDS in all the relations making use of it was checking for materialized views, but this is not a supported operation. On the contrary, this needs to be done on foreign tables. While on it, use

pgsql: Fix some incorrectness in upgrade_adapt.sql on query for WITH OI

2022-12-22 Thread Michael Paquier
Fix some incorrectness in upgrade_adapt.sql on query for WITH OIDS The query used to disable WITH OIDS in all the relations making use of it was checking for materialized views, but this is not a supported operation. On the contrary, this needs to be done on foreign tables. While on it, use

pgsql: Fix some incorrectness in upgrade_adapt.sql on query for WITH OI

2022-12-22 Thread Michael Paquier
Fix some incorrectness in upgrade_adapt.sql on query for WITH OIDS The query used to disable WITH OIDS in all the relations making use of it was checking for materialized views, but this is not a supported operation. On the contrary, this needs to be done on foreign tables. While on it, use

Re: pgsql: Remove dead code

2022-12-22 Thread Michael Paquier
On Thu, Dec 22, 2022 at 09:30:41AM -0600, Justin Pryzby wrote: > This caused me to notice various wrong-looking elog()s. Nice catch. These have been wrong for quite some time, so I have done something down to v11 while passing by.. -- Michael signature.asc Description: PGP signature

pgsql: Fix come incorrect elog() messages in aclchk.c

2022-12-22 Thread Michael Paquier
Fix come incorrect elog() messages in aclchk.c Three error strings used with cache lookup failures were referring to incorrect object types for ACL checks: - Schemas - Types - Foreign Servers There errors should never be triggered, but if they do incorrect information would be reported. Author:

pgsql: Fix come incorrect elog() messages in aclchk.c

2022-12-22 Thread Michael Paquier
Fix come incorrect elog() messages in aclchk.c Three error strings used with cache lookup failures were referring to incorrect object types for ACL checks: - Schemas - Types - Foreign Servers There errors should never be triggered, but if they do incorrect information would be reported. Author:

pgsql: Fix come incorrect elog() messages in aclchk.c

2022-12-22 Thread Michael Paquier
Fix come incorrect elog() messages in aclchk.c Three error strings used with cache lookup failures were referring to incorrect object types for ACL checks: - Schemas - Types - Foreign Servers There errors should never be triggered, but if they do incorrect information would be reported. Author:

pgsql: Fix come incorrect elog() messages in aclchk.c

2022-12-22 Thread Michael Paquier
Fix come incorrect elog() messages in aclchk.c Three error strings used with cache lookup failures were referring to incorrect object types for ACL checks: - Schemas - Types - Foreign Servers There errors should never be triggered, but if they do incorrect information would be reported. Author:

pgsql: Fix come incorrect elog() messages in aclchk.c

2022-12-22 Thread Michael Paquier
Fix come incorrect elog() messages in aclchk.c Three error strings used with cache lookup failures were referring to incorrect object types for ACL checks: - Schemas - Types - Foreign Servers There errors should never be triggered, but if they do incorrect information would be reported. Author:

pgsql: Fix come incorrect elog() messages in aclchk.c

2022-12-22 Thread Michael Paquier
Fix come incorrect elog() messages in aclchk.c Three error strings used with cache lookup failures were referring to incorrect object types for ACL checks: - Schemas - Types - Foreign Servers There errors should never be triggered, but if they do incorrect information would be reported. Author:

pgsql: Rename pg_dissect_walfile_name() to pg_split_walfile_name()

2022-12-22 Thread Michael Paquier
Rename pg_dissect_walfile_name() to pg_split_walfile_name() The former name was discussed as being confusing, so use "split", as per a suggestion from Magnus Hagander. While on it, one of the output arguments is renamed from "segno" to "segment_number", as per a suggestion from Kyotaro

pgsql: Allow window functions to adjust their frameOptions

2022-12-22 Thread David Rowley
Allow window functions to adjust their frameOptions WindowFuncs such as row_number() don't care if it's called with ROWS UNBOUNDED PRECEDING AND CURRENT ROW or with RANGE UNBOUNDED PRECEDING AND CURRENT ROW. The latter is less efficient as the RANGE option requires that the executor check for

pgsql: Improve notation of cacheinfo table in syscache.c.

2022-12-22 Thread Thomas Munro
Improve notation of cacheinfo table in syscache.c. Use C99 designated initializer syntax for the array elements, instead of writing the enumerator name and position in a comment. Replace nkeys and key with a local variadic macro, for a shorter notation. Reviewed-by: Tom Lane Reviewed-by: Peter

pgsql: Use scanned_pages to decide when to failsafe check.

2022-12-22 Thread Peter Geoghegan
Use scanned_pages to decide when to failsafe check. Perform a failsafe check every time VACUUM's first heap scan scans a further FAILSAFE_EVERY_PAGES pages, rather than using an approach based on the number of physical blocks that our current blkno is from the blkno at the time of the previous

pgsql: Refactor how VACUUM passes around its XID cutoffs.

2022-12-22 Thread Peter Geoghegan
Refactor how VACUUM passes around its XID cutoffs. Use a dedicated struct for the XID/MXID cutoffs used by VACUUM, such as FreezeLimit and OldestXmin. This state is initialized in vacuum.c, and then passed around by code from vacuumlazy.c to heapam.c freezing related routines. The new

pgsql: Avoid O(N^2) cost when pulling up lots of UNION ALL subqueries.

2022-12-22 Thread Tom Lane
Avoid O(N^2) cost when pulling up lots of UNION ALL subqueries. perform_pullup_replace_vars() knows how to scan the whole parent query tree when we are replacing Vars during a subquery flattening operation. However, for the specific case of flattening a UNION ALL leaf query, that's mostly wasted

pgsql: Add some recursion and looping defenses in prepjointree.c.

2022-12-22 Thread Tom Lane
Add some recursion and looping defenses in prepjointree.c. Andrey Lepikhov demonstrated a case where we spend an unreasonable amount of time in pull_up_subqueries(). Not only is that recursing with no explicit check for stack overrun, but the code seems not interruptable by control-C. Let's

pgsql: Add some recursion and looping defenses in prepjointree.c.

2022-12-22 Thread Tom Lane
Add some recursion and looping defenses in prepjointree.c. Andrey Lepikhov demonstrated a case where we spend an unreasonable amount of time in pull_up_subqueries(). Not only is that recursing with no explicit check for stack overrun, but the code seems not interruptable by control-C. Let's

pgsql: Add some recursion and looping defenses in prepjointree.c.

2022-12-22 Thread Tom Lane
Add some recursion and looping defenses in prepjointree.c. Andrey Lepikhov demonstrated a case where we spend an unreasonable amount of time in pull_up_subqueries(). Not only is that recursing with no explicit check for stack overrun, but the code seems not interruptable by control-C. Let's

pgsql: Add some recursion and looping defenses in prepjointree.c.

2022-12-22 Thread Tom Lane
Add some recursion and looping defenses in prepjointree.c. Andrey Lepikhov demonstrated a case where we spend an unreasonable amount of time in pull_up_subqueries(). Not only is that recursing with no explicit check for stack overrun, but the code seems not interruptable by control-C. Let's

pgsql: Add some recursion and looping defenses in prepjointree.c.

2022-12-22 Thread Tom Lane
Add some recursion and looping defenses in prepjointree.c. Andrey Lepikhov demonstrated a case where we spend an unreasonable amount of time in pull_up_subqueries(). Not only is that recursing with no explicit check for stack overrun, but the code seems not interruptable by control-C. Let's

pgsql: Add some recursion and looping defenses in prepjointree.c.

2022-12-22 Thread Tom Lane
Add some recursion and looping defenses in prepjointree.c. Andrey Lepikhov demonstrated a case where we spend an unreasonable amount of time in pull_up_subqueries(). Not only is that recursing with no explicit check for stack overrun, but the code seems not interruptable by control-C. Let's

Re: pgsql: Remove dead code

2022-12-22 Thread Justin Pryzby
On Thu, Dec 22, 2022 at 07:21:50AM +, Peter Eisentraut wrote: > Remove dead code > > The second appearance of NamespaceRelationId in this if-else chain is > in error and can be removed. This caused me to notice various wrong-looking elog()s. diff --git a/src/backend/catalog/aclchk.c