Offering: openGaussDev

More detail: fix bug

Match-id-0fb0e3fd71fd43bedfaef338789265f221e045f6
This commit is contained in:
openGaussDev 2022-03-03 10:12:24 +08:00 committed by yanghao
parent 621d5004a6
commit 9e59584896
2 changed files with 34 additions and 3 deletions

View File

@ -5916,6 +5916,9 @@ static int exec_stmt_dynexecute(PLpgSQL_execstate* estate, PLpgSQL_stmt_dynexecu
bool savedisAllowCommitRollback = false;
bool needResetErrMsg = false;
needResetErrMsg = stp_disable_xact_and_set_err_msg(&savedisAllowCommitRollback, STP_XACT_USED_AS_EXPR);
#else
/* Saves the status of whether to send commandId. */
bool saveSetSendCommandId = IsSendCommandId();
#endif
/*
* First we evaluate the string expression after the EXECUTE keyword. Its
@ -6010,6 +6013,8 @@ static int exec_stmt_dynexecute(PLpgSQL_execstate* estate, PLpgSQL_stmt_dynexecu
FormatCallStack* plcallstack = t_thrd.log_cxt.call_stack;
#ifndef ENABLE_MULTIPLE_NODES
estate_cursor_set(plcallstack);
#else
SetSendCommandId(saveSetSendCommandId);
#endif
if (plcallstack != NULL) {
t_thrd.log_cxt.call_stack = plcallstack->prev;
@ -6020,6 +6025,10 @@ static int exec_stmt_dynexecute(PLpgSQL_execstate* estate, PLpgSQL_stmt_dynexecu
}
PG_END_TRY();
#ifdef ENABLE_MULTIPLE_NODES
SetSendCommandId(saveSetSendCommandId);
#endif
/*
* This is used for nested STP. If the transaction Id changed,
* then need to create new econtext for the TopTransaction.
@ -6501,7 +6510,10 @@ static int exec_stmt_open(PLpgSQL_execstate* estate, PLpgSQL_stmt_open* stmt)
errmsg("cursor \"%s\" already in use in OPEN statement.", curname)));
}
}
#ifdef ENABLE_MULTIPLE_NODES
/* In distributed mode, the commandId is sent when a cursor is opened. */
SetSendCommandId(true);
#endif
/* ----------
* Process the OPEN according to it's type.
* ----------

View File

@ -748,6 +748,8 @@ Datum plpgsql_call_handler(PG_FUNCTION_ARGS)
u_sess->opt_cxt.is_stream = true;
u_sess->opt_cxt.is_stream_support = true;
}
/* Saves the status of whether to send commandId. */
bool saveSetSendCommandId = IsSendCommandId();
#else
int outerDop = u_sess->opt_cxt.query_dop;
u_sess->opt_cxt.query_dop = 1;
@ -824,6 +826,7 @@ Datum plpgsql_call_handler(PG_FUNCTION_ARGS)
PLpgSQL_compile_context* save_compile_context = u_sess->plsql_cxt.curr_compile_context;
int save_compile_list_length = list_length(u_sess->plsql_cxt.compile_context_list);
int save_compile_status = u_sess->plsql_cxt.compile_status;
PG_TRY();
{
/*
@ -876,7 +879,6 @@ Datum plpgsql_call_handler(PG_FUNCTION_ARGS)
estate_cursor_set(plcallstack);
#endif
if (plcallstack != NULL) {
t_thrd.log_cxt.call_stack = plcallstack->prev;
}
@ -973,7 +975,9 @@ Datum plpgsql_call_handler(PG_FUNCTION_ARGS)
if (u_sess->SPI_cxt._connected == 0) {
t_thrd.utils_cxt.STPSavedResourceOwner = NULL;
}
#ifdef ENABLE_MULTIPLE_NODES
SetSendCommandId(saveSetSendCommandId);
#endif
/* ErrorData could be allocted in SPI's MemoryContext, copy it. */
oldContext = MemoryContextSwitchTo(oldContext);
ErrorData *edata = CopyErrorData();
@ -995,6 +999,10 @@ Datum plpgsql_call_handler(PG_FUNCTION_ARGS)
if (u_sess->SPI_cxt._connected == 0) {
t_thrd.utils_cxt.STPSavedResourceOwner = NULL;
}
#ifdef ENABLE_MULTIPLE_NODES
SetSendCommandId(saveSetSendCommandId);
#endif
/*
* Disconnect from SPI manager
*/
@ -1042,8 +1050,12 @@ Datum plpgsql_inline_handler(PG_FUNCTION_ARGS)
#ifndef ENABLE_MULTIPLE_NODES
int outerDop = u_sess->opt_cxt.query_dop;
u_sess->opt_cxt.query_dop = 1;
#else
/* Saves the status of whether to send commandId. */
bool saveSetSendCommandId = IsSendCommandId();
#endif
_PG_init();
AssertEreport(IsA(codeblock, InlineCodeBlock), MOD_PLSQL, "Inline code block is required.");
@ -1138,11 +1150,18 @@ Datum plpgsql_inline_handler(PG_FUNCTION_ARGS)
clearCompileContextList(save_compile_list_length);
/* AutonomousSession Disconnecting and releasing resources */
DestoryAutonomousSession(true);
#ifdef ENABLE_MULTIPLE_NODES
SetSendCommandId(saveSetSendCommandId);
#endif
PG_RE_THROW();
}
PG_END_TRY();
#ifdef ENABLE_MULTIPLE_NODES
SetSendCommandId(saveSetSendCommandId);
#endif
/* Disconnecting and releasing resources */
DestoryAutonomousSession(false);