diff --git a/contrib/babelfishpg_tsql/src/pl_exec.c b/contrib/babelfishpg_tsql/src/pl_exec.c index 7a1bcc2897..77ede5f702 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) { /* @@ -5056,11 +5062,10 @@ 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) { - 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