diff --git a/Makefile b/Makefile index d5699ab75..3f957757c 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,8 @@ SRCS = \ src/insert_chunk_state.c \ src/insert_statement_state.c \ src/ddl_utils.c \ - src/agg_bookend.c + src/agg_bookend.c \ + src/guc.c OBJS = $(SRCS:.c=.o) DEPS = $(SRCS:.c=.d) diff --git a/src/guc.c b/src/guc.c new file mode 100644 index 000000000..74e7b0f9a --- /dev/null +++ b/src/guc.c @@ -0,0 +1,60 @@ +#include +#include + +#include "guc.h" + +bool guc_disable_optimizations = false; +bool guc_optimize_non_hypertables = false; +bool guc_allow_install_without_preload = false; +bool guc_restoring = false; + + +void +_guc_init(void) +{ + /* Main database to connect to. */ + DefineCustomBoolVariable("timescaledb.disable_optimizations", "Disable all timescale query optimizations", + NULL, + &guc_disable_optimizations, + false, + PGC_USERSET, + 0, + NULL, + NULL, + NULL); + DefineCustomBoolVariable("timescaledb.optimize_non_hypertables", "Apply timescale query optimization to plain tables", + "Apply timescale query optimization to plain tables in addition to hypertables", + &guc_optimize_non_hypertables, + false, + PGC_USERSET, + 0, + NULL, + NULL, + NULL); + + DefineCustomBoolVariable("timescaledb.allow_install_without_preload", "Allow installing timescaledb without preloading the library (DANGEROUS)", + NULL, + &guc_allow_install_without_preload, + false, + PGC_USERSET, + 0, + NULL, + NULL, + NULL); + + DefineCustomBoolVariable("timescaledb.restoring", "Install timescale in restoring mode", + "Used for running pg_restore", + &guc_restoring, + false, + PGC_SUSET, + 0, + NULL, + NULL, + NULL); + +} + +void +_guc_fini(void) +{ +} diff --git a/src/guc.h b/src/guc.h new file mode 100644 index 000000000..956437da4 --- /dev/null +++ b/src/guc.h @@ -0,0 +1,12 @@ +#ifndef TIMESCALEDB_GUC_H +#define TIMESCALEDB_GUC_H +#include + +extern bool guc_disable_optimizations; +extern bool guc_optimize_non_hypertables; +extern bool guc_allow_install_without_preload; + +void _guc_init(void); +void _guc_fini(void); + +#endif /* TIMESCALEDB_GUC_H */ diff --git a/src/init.c b/src/init.c index 632a53ba2..d7b86097e 100644 --- a/src/init.c +++ b/src/init.c @@ -6,6 +6,7 @@ #include #include "executor.h" +#include "guc.h" #define MIN_SUPPORTED_VERSION_STR "9.6" #define MIN_SUPPORTED_VERSION_NUM 90600 @@ -41,22 +42,22 @@ _PG_init(void) { if (!process_shared_preload_libraries_in_progress) { - - char *force_load = GetConfigOptionByName("timescaledb.allow_install_without_preload", NULL, true); - if (force_load == NULL || strlen(force_load) != 2 || strncmp(force_load, "on", 2) != 0) { + + if (!guc_allow_install_without_preload) + { char *config_file = GetConfigOptionByName("config_file", NULL, false); - - ereport(ERROR, (errmsg("The timescaledb library is not preloaded"), - errhint( -"Please preload the timescaledb library via shared_preload_libraries.\n\n" -"This can be done by editing the config file at: %1$s\n" -"and adding 'timescaledb' to the list in the shared_preload_libraries config.\n" -" # Modify postgresql.conf:\n" -" shared_preload_libraries = 'timescaledb'\n\n" -"Another way to do this, if not preloading other libraries, is with the command:\n" -" echo \"shared_preload_libraries = 'timescaledb'\" >> %1$s \n\n" -"If you REALLY know what you are doing and would like to load the library without preloading, you can disable this check with: \n" -" SET timescaledb.allow_install_without_preload = 'on';", config_file))); + + ereport(ERROR, + (errmsg("The timescaledb library is not preloaded"), + errhint("Please preload the timescaledb library via shared_preload_libraries.\n\n" + "This can be done by editing the config file at: %1$s\n" + "and adding 'timescaledb' to the list in the shared_preload_libraries config.\n" + " # Modify postgresql.conf:\n shared_preload_libraries = 'timescaledb'\n\n" + "Another way to do this, if not preloading other libraries, is with the command:\n" + " echo \"shared_preload_libraries = 'timescaledb'\" >> %1$s \n\n" + "(Will require a database restart.)\n\n" + "If you REALLY know what you are doing and would like to load the library without preloading, you can disable this check with: \n" + " SET timescaledb.allow_install_without_preload = 'on';", config_file))); return; } } @@ -67,6 +68,7 @@ _PG_init(void) _planner_init(); _executor_init(); _process_utility_init(); + _guc_init(); } void @@ -76,6 +78,7 @@ _PG_fini(void) * Order of items should be strict reverse order of _PG_init. Please * document any exceptions. */ + _guc_fini(); _process_utility_fini(); _executor_fini(); _planner_fini(); diff --git a/src/planner.c b/src/planner.c index aa07e8a06..127759776 100644 --- a/src/planner.c +++ b/src/planner.c @@ -20,6 +20,7 @@ #include "partitioning.h" #include "extension.h" #include "utils.h" +#include "guc.h" void _planner_init(void); void _planner_fini(void); @@ -347,10 +348,6 @@ timescaledb_planner(Query *parse, int cursorOptions, ParamListInfo boundParams) if (extension_is_loaded()) { ChangeTableNameCtx context; - char *printParse = GetConfigOptionByName("io.print_parse", NULL, true); - - /* set to false to not print all internal actions */ - SetConfigOption("io.print_parse", "false", PGC_USERSET, PGC_S_SESSION); /* replace call to main table with call to the replica table */ context.hcache = hypertable_cache_pin(); @@ -369,11 +366,6 @@ timescaledb_planner(Query *parse, int cursorOptions, ParamListInfo boundParams) cache_release(context.hcache); - if (printParse != NULL && strcmp(printParse, "true") == 0) - { - pprint(parse); - } - } if (prev_planner_hook != NULL) { @@ -394,8 +386,8 @@ timescaledb_planner(Query *parse, int cursorOptions, ParamListInfo boundParams) static inline bool should_optimize_query() { - return !util_config_default_off("timescaledb.disable_optimizations") && - (util_config_default_off("timescaledb.optimize_plain_tables") || (global_planner_ctx != NULL && global_planner_ctx->has_hypertables)); + return !guc_disable_optimizations && + (guc_optimize_non_hypertables || (global_planner_ctx != NULL && global_planner_ctx->has_hypertables)); } extern void sort_transform_optimization(PlannerInfo *root, RelOptInfo *rel); diff --git a/src/utils.c b/src/utils.c index 425a702ed..5713677b3 100644 --- a/src/utils.c +++ b/src/utils.c @@ -353,13 +353,3 @@ timestamptz_bucket(PG_FUNCTION_ARGS) } PG_RETURN_TIMESTAMPTZ(result); } - -inline bool -util_config_default_off(const char *name) -{ - const char *result = GetConfigOption(name, true, true); - - if (result != NULL && strlen(result) == 2 && strncmp(result, "on", 2) == 0) - return true; - return false; -} diff --git a/src/utils.h b/src/utils.h index 749d86538..bed471b0f 100644 --- a/src/utils.h +++ b/src/utils.h @@ -36,7 +36,6 @@ extern char *internal_time_to_column_literal_sql(int64 internal_time, Oid type); extern FmgrInfo *create_fmgr(char *schema, char *function_name, int num_args); extern RangeVar *makeRangeVarFromRelid(Oid relid); extern int int_cmp(const void *a, const void *b); -extern bool util_config_default_off(const char *name); #define DATUM_GET(values, attno) \ values[attno-1] diff --git a/test/expected/sql_query_results_optimized.out b/test/expected/sql_query_results_optimized.out index f62c92488..19e7c5732 100644 --- a/test/expected/sql_query_results_optimized.out +++ b/test/expected/sql_query_results_optimized.out @@ -468,7 +468,7 @@ LIMIT 2; --can turn on plain table optimizations BEGIN; - SET LOCAL timescaledb.optimize_plain_tables= 'on'; + SET LOCAL timescaledb.optimize_non_hypertables = 'on'; EXPLAIN (costs off) SELECT date_trunc('minute', time) t, avg(series_0), min(series_1), avg(series_2) FROM plain_table diff --git a/test/expected/sql_query_results_unoptimized.out b/test/expected/sql_query_results_unoptimized.out index 9e6b155d3..726f717d2 100644 --- a/test/expected/sql_query_results_unoptimized.out +++ b/test/expected/sql_query_results_unoptimized.out @@ -439,7 +439,7 @@ LIMIT 2; --can turn on plain table optimizations BEGIN; - SET LOCAL timescaledb.optimize_plain_tables= 'on'; + SET LOCAL timescaledb.optimize_non_hypertables = 'on'; EXPLAIN (costs off) SELECT date_trunc('minute', time) t, avg(series_0), min(series_1), avg(series_2) FROM plain_table diff --git a/test/sql/include/sql_query_results.sql b/test/sql/include/sql_query_results.sql index 70264537f..30c9ec4a5 100644 --- a/test/sql/include/sql_query_results.sql +++ b/test/sql/include/sql_query_results.sql @@ -148,7 +148,7 @@ LIMIT 2; --can turn on plain table optimizations BEGIN; - SET LOCAL timescaledb.optimize_plain_tables= 'on'; + SET LOCAL timescaledb.optimize_non_hypertables = 'on'; EXPLAIN (costs off) SELECT date_trunc('minute', time) t, avg(series_0), min(series_1), avg(series_2) FROM plain_table