This is an automated email from the ASF dual-hosted git repository. maxyang pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit 6784abd9f389c429c1cba35522ffa3651c8a3845 Author: Adam Lee <[email protected]> AuthorDate: Wed Nov 23 14:52:46 2022 +0800 Fix the test extension to execute SQL code inside of a Portal (#14515) This extension fails with a later version of PostgreSQL, which we will merge. commit 41c6a5bec25e720d98bd60d77dd5c2939189ed3c Author: Tom Lane <[email protected]> Date: Fri May 21 14:03:53 2021 -0400 Restore the portal-level snapshot after procedure COMMIT/ROLLBACK. And quote the release note: > Some extensions may attempt to execute SQL code outside of any Portal. > They are responsible for ensuring that an outer snapshot exists before > doing so. Previously, not providing a snapshot might work or it might > not; now it will consistently fail with “cannot execute SQL without an > outer snapshot or portal”. --- .../extension/extended_protocol_commit_test_fdw.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/test/fdw/extension/extended_protocol_commit_test_fdw.c b/src/test/fdw/extension/extended_protocol_commit_test_fdw.c index 67053c660d..7940a05190 100644 --- a/src/test/fdw/extension/extended_protocol_commit_test_fdw.c +++ b/src/test/fdw/extension/extended_protocol_commit_test_fdw.c @@ -16,7 +16,7 @@ #include "optimizer/pathnode.h" #include "optimizer/planmain.h" #include "optimizer/restrictinfo.h" -#include "utils/snapmgr.h" +#include "tcop/pquery.h" #ifdef PG_MODULE_MAGIC PG_MODULE_MAGIC; @@ -34,11 +34,16 @@ test_execute_spi_expression(const char *query) { int r; - if (SPI_connect() != SPI_OK_CONNECT) - elog(ERROR, "Failed to connect to SPI"); + /* Set up the global portal */ + Portal saveActivePortal = ActivePortal; + + ActivePortal = CreateNewPortal(); + PG_TRY(); { - PushActiveSnapshot(GetTransactionSnapshot()); + if (SPI_connect() != SPI_OK_CONNECT) + elog(ERROR, "Failed to connect to SPI"); + r = SPI_execute(query, false, 0); if (r < 0) elog(ERROR, "Failed to execute '%s' via SPI: %s [%d]", query, SPI_result_code_string(r), r); @@ -46,10 +51,18 @@ test_execute_spi_expression(const char *query) PG_CATCH(); { SPI_finish(); + + /* Restore the global portal */ + ActivePortal = saveActivePortal; + PG_RE_THROW(); } PG_END_TRY(); + SPI_finish(); + + /* Restore the global portal */ + ActivePortal = saveActivePortal; } static void --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
