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 | |
16 | namespace duckdb { |
17 | |
18 | static void PragmaEnableProfilingStatement(ClientContext &context, const FunctionParameters ¶meters) { |
19 | auto &config = ClientConfig::GetConfig(context); |
20 | config.enable_profiler = true; |
21 | config.emit_profiler_output = true; |
22 | } |
23 | |
24 | void 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 | |
32 | static void PragmaDisableProfiling(ClientContext &context, const FunctionParameters ¶meters) { |
33 | auto &config = ClientConfig::GetConfig(context); |
34 | config.enable_profiler = false; |
35 | } |
36 | |
37 | static void PragmaEnableProgressBar(ClientContext &context, const FunctionParameters ¶meters) { |
38 | ClientConfig::GetConfig(context).enable_progress_bar = true; |
39 | } |
40 | |
41 | static void PragmaDisableProgressBar(ClientContext &context, const FunctionParameters ¶meters) { |
42 | ClientConfig::GetConfig(context).enable_progress_bar = false; |
43 | } |
44 | |
45 | static void PragmaEnablePrintProgressBar(ClientContext &context, const FunctionParameters ¶meters) { |
46 | ClientConfig::GetConfig(context).print_progress_bar = true; |
47 | } |
48 | |
49 | static void PragmaDisablePrintProgressBar(ClientContext &context, const FunctionParameters ¶meters) { |
50 | ClientConfig::GetConfig(context).print_progress_bar = false; |
51 | } |
52 | |
53 | static void PragmaEnableVerification(ClientContext &context, const FunctionParameters ¶meters) { |
54 | ClientConfig::GetConfig(context).query_verification_enabled = true; |
55 | ClientConfig::GetConfig(context).verify_serializer = true; |
56 | } |
57 | |
58 | static void PragmaDisableVerification(ClientContext &context, const FunctionParameters ¶meters) { |
59 | ClientConfig::GetConfig(context).query_verification_enabled = false; |
60 | ClientConfig::GetConfig(context).verify_serializer = false; |
61 | } |
62 | |
63 | static void PragmaVerifySerializer(ClientContext &context, const FunctionParameters ¶meters) { |
64 | ClientConfig::GetConfig(context).verify_serializer = true; |
65 | } |
66 | |
67 | static void PragmaDisableVerifySerializer(ClientContext &context, const FunctionParameters ¶meters) { |
68 | ClientConfig::GetConfig(context).verify_serializer = false; |
69 | } |
70 | |
71 | static void PragmaEnableExternalVerification(ClientContext &context, const FunctionParameters ¶meters) { |
72 | ClientConfig::GetConfig(context).verify_external = true; |
73 | } |
74 | |
75 | static void PragmaDisableExternalVerification(ClientContext &context, const FunctionParameters ¶meters) { |
76 | ClientConfig::GetConfig(context).verify_external = false; |
77 | } |
78 | |
79 | static void PragmaEnableForceParallelism(ClientContext &context, const FunctionParameters ¶meters) { |
80 | ClientConfig::GetConfig(context).verify_parallelism = true; |
81 | } |
82 | |
83 | static void PragmaEnableForceIndexJoin(ClientContext &context, const FunctionParameters ¶meters) { |
84 | ClientConfig::GetConfig(context).force_index_join = true; |
85 | } |
86 | |
87 | static void PragmaForceCheckpoint(ClientContext &context, const FunctionParameters ¶meters) { |
88 | DBConfig::GetConfig(context).options.force_checkpoint = true; |
89 | } |
90 | |
91 | static void PragmaDisableForceParallelism(ClientContext &context, const FunctionParameters ¶meters) { |
92 | ClientConfig::GetConfig(context).verify_parallelism = false; |
93 | } |
94 | |
95 | static void PragmaEnableObjectCache(ClientContext &context, const FunctionParameters ¶meters) { |
96 | DBConfig::GetConfig(context).options.object_cache_enable = true; |
97 | } |
98 | |
99 | static void PragmaDisableObjectCache(ClientContext &context, const FunctionParameters ¶meters) { |
100 | DBConfig::GetConfig(context).options.object_cache_enable = false; |
101 | } |
102 | |
103 | static void PragmaEnableCheckpointOnShutdown(ClientContext &context, const FunctionParameters ¶meters) { |
104 | DBConfig::GetConfig(context).options.checkpoint_on_shutdown = true; |
105 | } |
106 | |
107 | static void PragmaDisableCheckpointOnShutdown(ClientContext &context, const FunctionParameters ¶meters) { |
108 | DBConfig::GetConfig(context).options.checkpoint_on_shutdown = false; |
109 | } |
110 | |
111 | static void PragmaEnableOptimizer(ClientContext &context, const FunctionParameters ¶meters) { |
112 | ClientConfig::GetConfig(context).enable_optimizer = true; |
113 | } |
114 | |
115 | static void PragmaDisableOptimizer(ClientContext &context, const FunctionParameters ¶meters) { |
116 | ClientConfig::GetConfig(context).enable_optimizer = false; |
117 | } |
118 | |
119 | void 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 | |