aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/misc/guc.c
diff options
context:
space:
mode:
authorJeff Davis <jdavis@postgresql.org>2023-08-10 12:43:53 -0700
committerJeff Davis <jdavis@postgresql.org>2023-08-10 12:43:53 -0700
commit5765cfe18c595b5d8a7df3a62d253f60a00718ce (patch)
tree10c9845c3c3b5ba873800a008b574f091d65dc98 /src/backend/utils/misc/guc.c
parentbee263b0878cacec5e3d888ab666000edc3219de (diff)
downloadpostgresql-5765cfe18c595b5d8a7df3a62d253f60a00718ce.tar.gz
postgresql-5765cfe18c595b5d8a7df3a62d253f60a00718ce.zip
Transform proconfig for faster execution.
Store function config settings in lists to avoid the need to parse and allocate for each function execution. Speedup is modest but significant. Additionally, this change also seems cleaner and supports some other performance improvements under discussion. Discussion: https://postgr.es/m/04c8592dbd694e4114a3ed87139a7a04e4363030.camel@j-davis.com Reviewed-by: Nathan Bossart
Diffstat (limited to 'src/backend/utils/misc/guc.c')
-rw-r--r--src/backend/utils/misc/guc.c45
1 files changed, 38 insertions, 7 deletions
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index 5308896c87f..3449470953a 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -6215,14 +6215,12 @@ ParseLongOption(const char *string, char **name, char **value)
/*
- * Handle options fetched from pg_db_role_setting.setconfig,
- * pg_proc.proconfig, etc. Caller must specify proper context/source/action.
- *
- * The array parameter must be an array of TEXT (it must not be NULL).
+ * Transform array of GUC settings into lists of names and values. The lists
+ * are faster to process in cases where the settings must be applied
+ * repeatedly (e.g. for each function invocation).
*/
void
-ProcessGUCArray(ArrayType *array,
- GucContext context, GucSource source, GucAction action)
+TransformGUCArray(ArrayType *array, List **names, List **values)
{
int i;
@@ -6231,6 +6229,8 @@ ProcessGUCArray(ArrayType *array,
Assert(ARR_NDIM(array) == 1);
Assert(ARR_LBOUND(array)[0] == 1);
+ *names = NIL;
+ *values = NIL;
for (i = 1; i <= ARR_DIMS(array)[0]; i++)
{
Datum d;
@@ -6262,14 +6262,45 @@ ProcessGUCArray(ArrayType *array,
continue;
}
+ *names = lappend(*names, name);
+ *values = lappend(*values, value);
+
+ pfree(s);
+ }
+}
+
+
+/*
+ * Handle options fetched from pg_db_role_setting.setconfig,
+ * pg_proc.proconfig, etc. Caller must specify proper context/source/action.
+ *
+ * The array parameter must be an array of TEXT (it must not be NULL).
+ */
+void
+ProcessGUCArray(ArrayType *array,
+ GucContext context, GucSource source, GucAction action)
+{
+ List *gucNames;
+ List *gucValues;
+ ListCell *lc1;
+ ListCell *lc2;
+
+ TransformGUCArray(array, &gucNames, &gucValues);
+ forboth(lc1, gucNames, lc2, gucValues)
+ {
+ char *name = lfirst(lc1);
+ char *value = lfirst(lc2);
+
(void) set_config_option(name, value,
context, source,
action, true, 0, false);
pfree(name);
pfree(value);
- pfree(s);
}
+
+ list_free(gucNames);
+ list_free(gucValues);
}