Skip to content

Commit

Permalink
optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
RekGRpth committed Nov 26, 2023
1 parent be5103f commit 912837f
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 13 deletions.
1 change: 0 additions & 1 deletion conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ void conf_main(Datum arg) {
on_shmem_exit(conf_shmem_exit, (Datum)NULL);
BackgroundWorkerUnblockSignals();
BackgroundWorkerInitializeConnectionMy("postgres", NULL);
MemoryContextSwitchTo(TopMemoryContext);
set_config_option_my("application_name", "pg_conf", PGC_USERSET, PGC_S_SESSION, GUC_ACTION_SET, true, ERROR);
pgstat_report_appname("pg_conf");
set_ps_display_my("main");
Expand Down
9 changes: 0 additions & 9 deletions spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ Portal SPI_cursor_open_my(const char *src, SPIPlanPtr plan, Datum *values, const
SPI_freetuptable(SPI_tuptable);
check_log_statement_my(STMT_BIND, src, plan->nargs, plan->argtypes, values, nulls, false);
if (!(portal = SPI_cursor_open(NULL, plan, values, nulls, false))) ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("SPI_cursor_open failed"), errdetail("%s", SPI_result_code_string(SPI_result))));
MemoryContextSwitchTo(TopMemoryContext);
check_log_duration_my(STMT_BIND, src, plan->nargs, plan->argtypes, values, nulls);
return portal;
}
Expand All @@ -98,7 +97,6 @@ Portal SPI_cursor_open_with_args_my(const char *src, int nargs, Oid *argtypes, D
SPI_freetuptable(SPI_tuptable);
check_log_statement_my(STMT_BIND, src, nargs, argtypes, values, nulls, false);
if (!(portal = SPI_cursor_open_with_args(NULL, src, nargs, argtypes, values, nulls, false, 0))) ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("SPI_cursor_open_with_args failed"), errdetail("%s", SPI_result_code_string(SPI_result)), errcontext("%s", src)));
MemoryContextSwitchTo(TopMemoryContext);
check_log_duration_my(STMT_BIND, src, nargs, argtypes, values, nulls);
return portal;
}
Expand All @@ -109,7 +107,6 @@ SPIPlanPtr SPI_prepare_my(const char *src, int nargs, Oid *argtypes) {
check_log_statement_my(STMT_PARSE, src, 0, NULL, NULL, NULL, false);
if (!(plan = SPI_prepare(src, nargs, argtypes))) ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("SPI_prepare failed"), errdetail("%s", SPI_result_code_string(SPI_result)), errcontext("%s", src)));
if ((rc = SPI_keepplan(plan))) ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("SPI_keepplan failed"), errdetail("%s", SPI_result_code_string(rc)), errcontext("%s", src)));
MemoryContextSwitchTo(TopMemoryContext);
check_log_duration_my(STMT_PARSE, src, 0, NULL, NULL, NULL);
return plan;
}
Expand All @@ -123,20 +120,17 @@ void SPI_connect_my(const char *src) {
if ((rc = SPI_connect()) != SPI_OK_CONNECT) ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("SPI_connect failed"), errdetail("%s", SPI_result_code_string(rc)), errcontext("%s", src)));
PushActiveSnapshot(GetTransactionSnapshot());
StatementTimeout > 0 ? enable_timeout_after(STATEMENT_TIMEOUT, StatementTimeout) : disable_timeout(STATEMENT_TIMEOUT, false);
MemoryContextSwitchTo(TopMemoryContext);
}

void SPI_cursor_close_my(Portal portal) {
SPI_freetuptable(SPI_tuptable);
SPI_cursor_close(portal);
MemoryContextSwitchTo(TopMemoryContext);
}

void SPI_cursor_fetch_my(const char *src, Portal portal, bool forward, long count) {
check_log_statement_my(STMT_FETCH, src, 0, NULL, NULL, NULL, true);
SPI_freetuptable(SPI_tuptable);
SPI_cursor_fetch(portal, forward, count);
MemoryContextSwitchTo(TopMemoryContext);
check_log_duration_my(STMT_FETCH, src, 0, NULL, NULL, NULL);
}

Expand All @@ -145,7 +139,6 @@ void SPI_execute_plan_my(const char *src, SPIPlanPtr plan, Datum *values, const
SPI_freetuptable(SPI_tuptable);
check_log_statement_my(STMT_EXECUTE, src, plan->nargs, plan->argtypes, values, nulls, true);
if ((rc = SPI_execute_plan(plan, values, nulls, false, 0)) != res) ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("SPI_execute_plan failed"), errdetail("%s while expecting %s", SPI_result_code_string(rc), SPI_result_code_string(res))));
MemoryContextSwitchTo(TopMemoryContext);
check_log_duration_my(STMT_EXECUTE, src, plan->nargs, plan->argtypes, values, nulls);
}

Expand All @@ -154,7 +147,6 @@ void SPI_execute_with_args_my(const char *src, int nargs, Oid *argtypes, Datum *
SPI_freetuptable(SPI_tuptable);
check_log_statement_my(STMT_STATEMENT, src, nargs, argtypes, values, nulls, true);
if ((rc = SPI_execute_with_args(src, nargs, argtypes, values, nulls, false, 0)) != res) ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("SPI_execute_with_args failed"), errdetail("%s while expecting %s", SPI_result_code_string(rc), SPI_result_code_string(res)), errcontext("%s", src)));
MemoryContextSwitchTo(TopMemoryContext);
check_log_duration_my(STMT_STATEMENT, src, nargs, argtypes, values, nulls);
}

Expand All @@ -171,5 +163,4 @@ void SPI_finish_my(void) {
pgstat_report_stat(false);
debug_query_string = NULL;
pgstat_report_activity(STATE_IDLE, NULL);
MemoryContextSwitchTo(TopMemoryContext);
}
2 changes: 0 additions & 2 deletions task.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ static void task_catch(void) {
#if PG_VERSION_NUM >= 110000
jit_reset_after_error();
#endif
MemoryContextSwitchTo(TopMemoryContext);
FlushErrorState();
xact_started = false;
RESUME_INTERRUPTS();
Expand Down Expand Up @@ -387,7 +386,6 @@ void task_main(Datum arg) {
work.table = quote_identifier(work.shared->table);
work.user = quote_identifier(work.shared->user);
BackgroundWorkerInitializeConnectionMy(work.shared->data, work.shared->user);
MemoryContextSwitchTo(TopMemoryContext);
application_name = MyBgworkerEntry->bgw_name + strlen(work.shared->user) + 1 + strlen(work.shared->data) + 1;
set_config_option_my("application_name", application_name, PGC_USERSET, PGC_S_SESSION, GUC_ACTION_SET, true, ERROR);
pgstat_report_appname(application_name);
Expand Down
1 change: 0 additions & 1 deletion work.c
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,6 @@ void work_main(Datum arg) {
work.table = quote_identifier(work.shared->table);
work.user = quote_identifier(work.shared->user);
BackgroundWorkerInitializeConnectionMy(work.shared->data, work.shared->user);
MemoryContextSwitchTo(TopMemoryContext);
application_name = MyBgworkerEntry->bgw_name + strlen(work.shared->user) + 1 + strlen(work.shared->data) + 1;
set_config_option_my("application_name", application_name, PGC_USERSET, PGC_S_SESSION, GUC_ACTION_SET, true, ERROR);
pgstat_report_appname(application_name);
Expand Down

0 comments on commit 912837f

Please sign in to comment.