From bf94b82cfc537f7e075f4442950f5371922d42f6 Mon Sep 17 00:00:00 2001 From: Zhibai Song Date: Tue, 28 Nov 2023 01:16:55 +0000 Subject: [PATCH 1/2] Fix the issue that PIVOT execution not return row affected line Previous our implement of PIVOT has a issue that it didn't return the row affected line as result, this fix has fixed the bug. Task: BABEL-284 Signed-off-by: Zhibai Song --- contrib/babelfishpg_tsql/src/pl_exec.c | 9 +++++++-- test/JDBC/expected/pivot-vu-verify.out | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/contrib/babelfishpg_tsql/src/pl_exec.c b/contrib/babelfishpg_tsql/src/pl_exec.c index 7a1bcc2897..8ede6c56c4 100644 --- a/contrib/babelfishpg_tsql/src/pl_exec.c +++ b/contrib/babelfishpg_tsql/src/pl_exec.c @@ -4693,6 +4693,12 @@ exec_stmt_execsql(PLtsql_execstate *estate, return ret; } + if (expr->plan && expr->plan->oneshot) + { + SPI_freeplan(expr->plan); + expr->plan = NULL; + } + if (expr->plan == NULL) { /* @@ -5059,8 +5065,7 @@ exec_stmt_execsql(PLtsql_execstate *estate, /* If current plan constains a pivot operator, we remove the plan */ if (is_pivot) { - SPI_freeplan(expr->plan); - expr->plan = NULL; + expr->plan->oneshot = true; } /* Expect SPI_tuptable to be NULL else complain */ diff --git a/test/JDBC/expected/pivot-vu-verify.out b/test/JDBC/expected/pivot-vu-verify.out index 1e9abd20dd..2618174b21 100644 --- a/test/JDBC/expected/pivot-vu-verify.out +++ b/test/JDBC/expected/pivot-vu-verify.out @@ -738,6 +738,8 @@ PIVOT ( ) AS pvt; SELECT TOP 10 * FROM pivot_insert_into ORDER by 1, 2; GO +~~ROW COUNT: 197~~ + ~~START~~ int#!#int#!#int#!#int#!#int#!#int#!#int 1200#!#200#!#0#!#0#!#0#!#0#!#0 From c58216ceb0f3f9be3166b2a04a976cbcadfa2adc Mon Sep 17 00:00:00 2001 From: Zhibai Song Date: Tue, 28 Nov 2023 02:30:28 +0000 Subject: [PATCH 2/2] change comment --- contrib/babelfishpg_tsql/src/pl_exec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/babelfishpg_tsql/src/pl_exec.c b/contrib/babelfishpg_tsql/src/pl_exec.c index 8ede6c56c4..77ede5f702 100644 --- a/contrib/babelfishpg_tsql/src/pl_exec.c +++ b/contrib/babelfishpg_tsql/src/pl_exec.c @@ -5062,7 +5062,7 @@ exec_stmt_execsql(PLtsql_execstate *estate, /* If query affects IDENTITY_INSERT relation then update sequence */ pltsql_update_identity_insert_sequence(expr); - /* If current plan constains a pivot operator, we remove the plan */ + /* If current plan constains a pivot operator, we set it as execute oneshot */ if (is_pivot) { expr->plan->oneshot = true;