From 912837f1bba0e389edb655e9b2748368efd77c66 Mon Sep 17 00:00:00 2001 From: RekGRpth Date: Sun, 26 Nov 2023 12:09:53 +0500 Subject: [PATCH] optimize --- conf.c | 1 - spi.c | 9 --------- task.c | 2 -- work.c | 1 - 4 files changed, 13 deletions(-) diff --git a/conf.c b/conf.c index 484c417..aef2484 100644 --- a/conf.c +++ b/conf.c @@ -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"); diff --git a/spi.c b/spi.c index ba938bb..f81e8c5 100644 --- a/spi.c +++ b/spi.c @@ -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; } @@ -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; } @@ -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; } @@ -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); } @@ -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); } @@ -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); } @@ -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); } diff --git a/task.c b/task.c index c17bb45..297b767 100644 --- a/task.c +++ b/task.c @@ -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(); @@ -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); diff --git a/work.c b/work.c index f7cbfd6..e447e11 100644 --- a/work.c +++ b/work.c @@ -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);