1#include "duckdb/function/pragma/pragma_functions.hpp"
2
3#include "duckdb/common/enums/output_type.hpp"
4#include "duckdb/common/operator/cast_operators.hpp"
5#include "duckdb/main/client_context.hpp"
6#include "duckdb/main/database.hpp"
7#include "duckdb/main/query_profiler.hpp"
8#include "duckdb/parallel/task_scheduler.hpp"
9#include "duckdb/planner/expression_binder.hpp"
10#include "duckdb/storage/buffer_manager.hpp"
11#include "duckdb/storage/storage_manager.hpp"
12#include "duckdb/function/function_set.hpp"
13
14#include <cctype>
15
16namespace duckdb {
17
18static void PragmaEnableProfilingStatement(ClientContext &context, const FunctionParameters &parameters) {
19 auto &config = ClientConfig::GetConfig(context);
20 config.enable_profiler = true;
21 config.emit_profiler_output = true;
22}
23
24void RegisterEnableProfiling(BuiltinFunctions &set) {
25 PragmaFunctionSet functions("");
26 functions.AddFunction(function: PragmaFunction::PragmaStatement(name: string(), function: PragmaEnableProfilingStatement));
27
28 set.AddFunction(name: "enable_profile", functions);
29 set.AddFunction(name: "enable_profiling", functions);
30}
31
32static void PragmaDisableProfiling(ClientContext &context, const FunctionParameters &parameters) {
33 auto &config = ClientConfig::GetConfig(context);
34 config.enable_profiler = false;
35}
36
37static void PragmaEnableProgressBar(ClientContext &context, const FunctionParameters &parameters) {
38 ClientConfig::GetConfig(context).enable_progress_bar = true;
39}
40
41static void PragmaDisableProgressBar(ClientContext &context, const FunctionParameters &parameters) {
42 ClientConfig::GetConfig(context).enable_progress_bar = false;
43}
44
45static void PragmaEnablePrintProgressBar(ClientContext &context, const FunctionParameters &parameters) {
46 ClientConfig::GetConfig(context).print_progress_bar = true;
47}
48
49static void PragmaDisablePrintProgressBar(ClientContext &context, const FunctionParameters &parameters) {
50 ClientConfig::GetConfig(context).print_progress_bar = false;
51}
52
53static void PragmaEnableVerification(ClientContext &context, const FunctionParameters &parameters) {
54 ClientConfig::GetConfig(context).query_verification_enabled = true;
55 ClientConfig::GetConfig(context).verify_serializer = true;
56}
57
58static void PragmaDisableVerification(ClientContext &context, const FunctionParameters &parameters) {
59 ClientConfig::GetConfig(context).query_verification_enabled = false;
60 ClientConfig::GetConfig(context).verify_serializer = false;
61}
62
63static void PragmaVerifySerializer(ClientContext &context, const FunctionParameters &parameters) {
64 ClientConfig::GetConfig(context).verify_serializer = true;
65}
66
67static void PragmaDisableVerifySerializer(ClientContext &context, const FunctionParameters &parameters) {
68 ClientConfig::GetConfig(context).verify_serializer = false;
69}
70
71static void PragmaEnableExternalVerification(ClientContext &context, const FunctionParameters &parameters) {
72 ClientConfig::GetConfig(context).verify_external = true;
73}
74
75static void PragmaDisableExternalVerification(ClientContext &context, const FunctionParameters &parameters) {
76 ClientConfig::GetConfig(context).verify_external = false;
77}
78
79static void PragmaEnableForceParallelism(ClientContext &context, const FunctionParameters &parameters) {
80 ClientConfig::GetConfig(context).verify_parallelism = true;
81}
82
83static void PragmaEnableForceIndexJoin(ClientContext &context, const FunctionParameters &parameters) {
84 ClientConfig::GetConfig(context).force_index_join = true;
85}
86
87static void PragmaForceCheckpoint(ClientContext &context, const FunctionParameters &parameters) {
88 DBConfig::GetConfig(context).options.force_checkpoint = true;
89}
90
91static void PragmaDisableForceParallelism(ClientContext &context, const FunctionParameters &parameters) {
92 ClientConfig::GetConfig(context).verify_parallelism = false;
93}
94
95static void PragmaEnableObjectCache(ClientContext &context, const FunctionParameters &parameters) {
96 DBConfig::GetConfig(context).options.object_cache_enable = true;
97}
98
99static void PragmaDisableObjectCache(ClientContext &context, const FunctionParameters &parameters) {
100 DBConfig::GetConfig(context).options.object_cache_enable = false;
101}
102
103static void PragmaEnableCheckpointOnShutdown(ClientContext &context, const FunctionParameters &parameters) {
104 DBConfig::GetConfig(context).options.checkpoint_on_shutdown = true;
105}
106
107static void PragmaDisableCheckpointOnShutdown(ClientContext &context, const FunctionParameters &parameters) {
108 DBConfig::GetConfig(context).options.checkpoint_on_shutdown = false;
109}
110
111static void PragmaEnableOptimizer(ClientContext &context, const FunctionParameters &parameters) {
112 ClientConfig::GetConfig(context).enable_optimizer = true;
113}
114
115static void PragmaDisableOptimizer(ClientContext &context, const FunctionParameters &parameters) {
116 ClientConfig::GetConfig(context).enable_optimizer = false;
117}
118
119void PragmaFunctions::RegisterFunction(BuiltinFunctions &set) {
120 RegisterEnableProfiling(set);
121
122 set.AddFunction(function: PragmaFunction::PragmaStatement(name: "disable_profile", function: PragmaDisableProfiling));
123 set.AddFunction(function: PragmaFunction::PragmaStatement(name: "disable_profiling", function: PragmaDisableProfiling));
124
125 set.AddFunction(function: PragmaFunction::PragmaStatement(name: "enable_verification", function: PragmaEnableVerification));
126 set.AddFunction(function: PragmaFunction::PragmaStatement(name: "disable_verification", function: PragmaDisableVerification));
127
128 set.AddFunction(function: PragmaFunction::PragmaStatement(name: "verify_external", function: PragmaEnableExternalVerification));
129 set.AddFunction(function: PragmaFunction::PragmaStatement(name: "disable_verify_external", function: PragmaDisableExternalVerification));
130
131 set.AddFunction(function: PragmaFunction::PragmaStatement(name: "verify_serializer", function: PragmaVerifySerializer));
132 set.AddFunction(function: PragmaFunction::PragmaStatement(name: "disable_verify_serializer", function: PragmaDisableVerifySerializer));
133
134 set.AddFunction(function: PragmaFunction::PragmaStatement(name: "verify_parallelism", function: PragmaEnableForceParallelism));
135 set.AddFunction(function: PragmaFunction::PragmaStatement(name: "disable_verify_parallelism", function: PragmaDisableForceParallelism));
136
137 set.AddFunction(function: PragmaFunction::PragmaStatement(name: "enable_object_cache", function: PragmaEnableObjectCache));
138 set.AddFunction(function: PragmaFunction::PragmaStatement(name: "disable_object_cache", function: PragmaDisableObjectCache));
139
140 set.AddFunction(function: PragmaFunction::PragmaStatement(name: "enable_optimizer", function: PragmaEnableOptimizer));
141 set.AddFunction(function: PragmaFunction::PragmaStatement(name: "disable_optimizer", function: PragmaDisableOptimizer));
142
143 set.AddFunction(function: PragmaFunction::PragmaStatement(name: "force_index_join", function: PragmaEnableForceIndexJoin));
144 set.AddFunction(function: PragmaFunction::PragmaStatement(name: "force_checkpoint", function: PragmaForceCheckpoint));
145
146 set.AddFunction(function: PragmaFunction::PragmaStatement(name: "enable_progress_bar", function: PragmaEnableProgressBar));
147 set.AddFunction(function: PragmaFunction::PragmaStatement(name: "disable_progress_bar", function: PragmaDisableProgressBar));
148
149 set.AddFunction(function: PragmaFunction::PragmaStatement(name: "enable_print_progress_bar", function: PragmaEnablePrintProgressBar));
150 set.AddFunction(function: PragmaFunction::PragmaStatement(name: "disable_print_progress_bar", function: PragmaDisablePrintProgressBar));
151
152 set.AddFunction(function: PragmaFunction::PragmaStatement(name: "enable_checkpoint_on_shutdown", function: PragmaEnableCheckpointOnShutdown));
153 set.AddFunction(
154 function: PragmaFunction::PragmaStatement(name: "disable_checkpoint_on_shutdown", function: PragmaDisableCheckpointOnShutdown));
155}
156
157} // namespace duckdb
158