mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-22 22:11:29 +08:00
Improve GUC handling
This PR improves GUC handling to be more inline with the Postgres GUC system.
This commit is contained in:
parent
c7bb9c04a8
commit
4638688e5b
3
Makefile
3
Makefile
@ -37,7 +37,8 @@ SRCS = \
|
|||||||
src/insert_chunk_state.c \
|
src/insert_chunk_state.c \
|
||||||
src/insert_statement_state.c \
|
src/insert_statement_state.c \
|
||||||
src/ddl_utils.c \
|
src/ddl_utils.c \
|
||||||
src/agg_bookend.c
|
src/agg_bookend.c \
|
||||||
|
src/guc.c
|
||||||
|
|
||||||
OBJS = $(SRCS:.c=.o)
|
OBJS = $(SRCS:.c=.o)
|
||||||
DEPS = $(SRCS:.c=.d)
|
DEPS = $(SRCS:.c=.d)
|
||||||
|
60
src/guc.c
Normal file
60
src/guc.c
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
#include <postgres.h>
|
||||||
|
#include <utils/guc.h>
|
||||||
|
|
||||||
|
#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)
|
||||||
|
{
|
||||||
|
}
|
12
src/guc.h
Normal file
12
src/guc.h
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#ifndef TIMESCALEDB_GUC_H
|
||||||
|
#define TIMESCALEDB_GUC_H
|
||||||
|
#include <postgres.h>
|
||||||
|
|
||||||
|
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 */
|
33
src/init.c
33
src/init.c
@ -6,6 +6,7 @@
|
|||||||
#include <utils/guc.h>
|
#include <utils/guc.h>
|
||||||
|
|
||||||
#include "executor.h"
|
#include "executor.h"
|
||||||
|
#include "guc.h"
|
||||||
|
|
||||||
#define MIN_SUPPORTED_VERSION_STR "9.6"
|
#define MIN_SUPPORTED_VERSION_STR "9.6"
|
||||||
#define MIN_SUPPORTED_VERSION_NUM 90600
|
#define MIN_SUPPORTED_VERSION_NUM 90600
|
||||||
@ -41,22 +42,22 @@ _PG_init(void)
|
|||||||
{
|
{
|
||||||
if (!process_shared_preload_libraries_in_progress)
|
if (!process_shared_preload_libraries_in_progress)
|
||||||
{
|
{
|
||||||
|
|
||||||
char *force_load = GetConfigOptionByName("timescaledb.allow_install_without_preload", NULL, true);
|
if (!guc_allow_install_without_preload)
|
||||||
if (force_load == NULL || strlen(force_load) != 2 || strncmp(force_load, "on", 2) != 0) {
|
{
|
||||||
char *config_file = GetConfigOptionByName("config_file", NULL, false);
|
char *config_file = GetConfigOptionByName("config_file", NULL, false);
|
||||||
|
|
||||||
ereport(ERROR, (errmsg("The timescaledb library is not preloaded"),
|
ereport(ERROR,
|
||||||
errhint(
|
(errmsg("The timescaledb library is not preloaded"),
|
||||||
"Please preload the timescaledb library via shared_preload_libraries.\n\n"
|
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"
|
"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"
|
"and adding 'timescaledb' to the list in the shared_preload_libraries config.\n"
|
||||||
" # Modify postgresql.conf:\n"
|
" # Modify postgresql.conf:\n shared_preload_libraries = 'timescaledb'\n\n"
|
||||||
" shared_preload_libraries = 'timescaledb'\n\n"
|
"Another way to do this, if not preloading other libraries, is with the command:\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"
|
||||||
" 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"
|
"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)));
|
" SET timescaledb.allow_install_without_preload = 'on';", config_file)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -67,6 +68,7 @@ _PG_init(void)
|
|||||||
_planner_init();
|
_planner_init();
|
||||||
_executor_init();
|
_executor_init();
|
||||||
_process_utility_init();
|
_process_utility_init();
|
||||||
|
_guc_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -76,6 +78,7 @@ _PG_fini(void)
|
|||||||
* Order of items should be strict reverse order of _PG_init. Please
|
* Order of items should be strict reverse order of _PG_init. Please
|
||||||
* document any exceptions.
|
* document any exceptions.
|
||||||
*/
|
*/
|
||||||
|
_guc_fini();
|
||||||
_process_utility_fini();
|
_process_utility_fini();
|
||||||
_executor_fini();
|
_executor_fini();
|
||||||
_planner_fini();
|
_planner_fini();
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include "partitioning.h"
|
#include "partitioning.h"
|
||||||
#include "extension.h"
|
#include "extension.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "guc.h"
|
||||||
|
|
||||||
void _planner_init(void);
|
void _planner_init(void);
|
||||||
void _planner_fini(void);
|
void _planner_fini(void);
|
||||||
@ -347,10 +348,6 @@ timescaledb_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
|
|||||||
if (extension_is_loaded())
|
if (extension_is_loaded())
|
||||||
{
|
{
|
||||||
ChangeTableNameCtx context;
|
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 */
|
/* replace call to main table with call to the replica table */
|
||||||
context.hcache = hypertable_cache_pin();
|
context.hcache = hypertable_cache_pin();
|
||||||
@ -369,11 +366,6 @@ timescaledb_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
|
|||||||
|
|
||||||
cache_release(context.hcache);
|
cache_release(context.hcache);
|
||||||
|
|
||||||
if (printParse != NULL && strcmp(printParse, "true") == 0)
|
|
||||||
{
|
|
||||||
pprint(parse);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
if (prev_planner_hook != NULL)
|
if (prev_planner_hook != NULL)
|
||||||
{
|
{
|
||||||
@ -394,8 +386,8 @@ timescaledb_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
|
|||||||
static inline bool
|
static inline bool
|
||||||
should_optimize_query()
|
should_optimize_query()
|
||||||
{
|
{
|
||||||
return !util_config_default_off("timescaledb.disable_optimizations") &&
|
return !guc_disable_optimizations &&
|
||||||
(util_config_default_off("timescaledb.optimize_plain_tables") || (global_planner_ctx != NULL && global_planner_ctx->has_hypertables));
|
(guc_optimize_non_hypertables || (global_planner_ctx != NULL && global_planner_ctx->has_hypertables));
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void sort_transform_optimization(PlannerInfo *root, RelOptInfo *rel);
|
extern void sort_transform_optimization(PlannerInfo *root, RelOptInfo *rel);
|
||||||
|
10
src/utils.c
10
src/utils.c
@ -353,13 +353,3 @@ timestamptz_bucket(PG_FUNCTION_ARGS)
|
|||||||
}
|
}
|
||||||
PG_RETURN_TIMESTAMPTZ(result);
|
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;
|
|
||||||
}
|
|
||||||
|
@ -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 FmgrInfo *create_fmgr(char *schema, char *function_name, int num_args);
|
||||||
extern RangeVar *makeRangeVarFromRelid(Oid relid);
|
extern RangeVar *makeRangeVarFromRelid(Oid relid);
|
||||||
extern int int_cmp(const void *a, const void *b);
|
extern int int_cmp(const void *a, const void *b);
|
||||||
extern bool util_config_default_off(const char *name);
|
|
||||||
|
|
||||||
#define DATUM_GET(values, attno) \
|
#define DATUM_GET(values, attno) \
|
||||||
values[attno-1]
|
values[attno-1]
|
||||||
|
@ -468,7 +468,7 @@ LIMIT 2;
|
|||||||
|
|
||||||
--can turn on plain table optimizations
|
--can turn on plain table optimizations
|
||||||
BEGIN;
|
BEGIN;
|
||||||
SET LOCAL timescaledb.optimize_plain_tables= 'on';
|
SET LOCAL timescaledb.optimize_non_hypertables = 'on';
|
||||||
EXPLAIN (costs off)
|
EXPLAIN (costs off)
|
||||||
SELECT date_trunc('minute', time) t, avg(series_0), min(series_1), avg(series_2)
|
SELECT date_trunc('minute', time) t, avg(series_0), min(series_1), avg(series_2)
|
||||||
FROM plain_table
|
FROM plain_table
|
||||||
|
@ -439,7 +439,7 @@ LIMIT 2;
|
|||||||
|
|
||||||
--can turn on plain table optimizations
|
--can turn on plain table optimizations
|
||||||
BEGIN;
|
BEGIN;
|
||||||
SET LOCAL timescaledb.optimize_plain_tables= 'on';
|
SET LOCAL timescaledb.optimize_non_hypertables = 'on';
|
||||||
EXPLAIN (costs off)
|
EXPLAIN (costs off)
|
||||||
SELECT date_trunc('minute', time) t, avg(series_0), min(series_1), avg(series_2)
|
SELECT date_trunc('minute', time) t, avg(series_0), min(series_1), avg(series_2)
|
||||||
FROM plain_table
|
FROM plain_table
|
||||||
|
@ -148,7 +148,7 @@ LIMIT 2;
|
|||||||
|
|
||||||
--can turn on plain table optimizations
|
--can turn on plain table optimizations
|
||||||
BEGIN;
|
BEGIN;
|
||||||
SET LOCAL timescaledb.optimize_plain_tables= 'on';
|
SET LOCAL timescaledb.optimize_non_hypertables = 'on';
|
||||||
EXPLAIN (costs off)
|
EXPLAIN (costs off)
|
||||||
SELECT date_trunc('minute', time) t, avg(series_0), min(series_1), avg(series_2)
|
SELECT date_trunc('minute', time) t, avg(series_0), min(series_1), avg(series_2)
|
||||||
FROM plain_table
|
FROM plain_table
|
||||||
|
Loading…
x
Reference in New Issue
Block a user