pgsql: Introduce an RTE for the grouping step

2024-09-09 Thread Richard Guo
Introduce an RTE for the grouping step If there are subqueries in the grouping expressions, each of these subqueries in the targetlist and HAVING clause is expanded into distinct SubPlan nodes. As a result, only one of these SubPlan nodes would be converted to reference to the grouping key column

pgsql: Mark expressions nullable by grouping sets

2024-09-09 Thread Richard Guo
Mark expressions nullable by grouping sets When generating window_pathkeys, distinct_pathkeys, or sort_pathkeys, we failed to realize that the grouping/ordering expressions might be nullable by grouping sets. As a result, we may incorrectly deem that the PathKeys are redundant by EquivalenceClass

pgsql: Remove emode argument from XLogFileRead() and XLogFileReadAnyTLI

2024-09-09 Thread Michael Paquier
Remove emode argument from XLogFileRead() and XLogFileReadAnyTLI() This change makes the code slightly easier to reason about, because there is actually no need to know if a specific caller of one of these routines should fail hard on a PANIC, or just let it go through with a DEBUG2. The only cal

pgsql: Add WAL usage reporting to ANALYZE VERBOSE output.

2024-09-09 Thread Masahiko Sawada
Add WAL usage reporting to ANALYZE VERBOSE output. This change adds WAL usage reporting to the output of ANALYZE VERBOSE and autoanalyze reports. It aligns the analyze output with VACUUM, providing consistency. Additionally, it aids in troubleshooting cases where WAL records are generated during a

pgsql: Consistently use PageGetExactFreeSpace() in pgstattuple.

2024-09-09 Thread Tom Lane
Consistently use PageGetExactFreeSpace() in pgstattuple. Previously this code used PageGetHeapFreeSpace on heap pages, and usually used PageGetFreeSpace on index pages (though for some reason GetHashPageStats used PageGetExactFreeSpace instead). The difference is that those functions subtract off

pgsql: Don't bother checking the result of SPI_connect[_ext] anymore.

2024-09-09 Thread Tom Lane
Don't bother checking the result of SPI_connect[_ext] anymore. SPI_connect/SPI_connect_ext have not returned any value other than SPI_OK_CONNECT since commit 1833f1a1c in v10; any errors are thrown via ereport. (The most likely failure is out-of-memory, which has always been thrown that way, so c

pgsql: Add PQfullProtocolVersion() to surface the precise protocol vers

2024-09-09 Thread Robert Haas
Add PQfullProtocolVersion() to surface the precise protocol version. The existing function PQprotocolVersion() does not include the minor version of the protocol. In preparation for pending work that will bump that number for the first time, add a new function to provide it to clients that may ca

pgsql: SQL/JSON: Avoid initializing unnecessary ON ERROR / ON EMPTY ste

2024-09-09 Thread Amit Langote
SQL/JSON: Avoid initializing unnecessary ON ERROR / ON EMPTY steps When the ON ERROR / ON EMPTY behavior is to return NULL, returning NULL directly from ExecEvalJsonExprPath() suffices. Therefore, there's no need to create separate steps to check the error/empty flag or those to evaluate the the c