Skip to content

Commit 53e7c77

Browse files
committed
refactoring, do not emit update-related ERROR on SET & ALTER EXTENSION pg_pathman (issue #95)
1 parent c856cd1 commit 53e7c77

File tree

9 files changed

+78
-36
lines changed

9 files changed

+78
-36
lines changed

src/hooks.c

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -613,16 +613,35 @@ pathman_post_parse_analysis_hook(ParseState *pstate, Query *query)
613613
if (!pathman_hooks_enabled)
614614
return;
615615

616-
/* We shouldn't do anything on BEGIN or SET ISOLATION LEVEL stmts */
617-
if (query->commandType == CMD_UTILITY &&
618-
(xact_is_transaction_stmt(query->utilityStmt) ||
619-
xact_is_set_transaction_stmt(query->utilityStmt)))
620-
return;
621-
622616
/* Finish delayed invalidation jobs */
623617
if (IsPathmanReady())
624618
finish_delayed_invalidation();
625619

620+
/*
621+
* We shouldn't proceed on:
622+
* BEGIN
623+
* SET [TRANSACTION]
624+
*/
625+
if (query->commandType == CMD_UTILITY &&
626+
(xact_is_transaction_stmt(query->utilityStmt) ||
627+
xact_is_set_stmt(query->utilityStmt)))
628+
return;
629+
630+
/*
631+
* We should also disable pg_pathman on:
632+
* ALTER EXTENSION pg_pathman
633+
*/
634+
if (query->commandType == CMD_UTILITY &&
635+
xact_is_alter_pathman_stmt(query->utilityStmt))
636+
{
637+
/* Disable pg_pathman to perform a painless update */
638+
(void) set_config_option(PATHMAN_ENABLE, "off",
639+
PGC_SUSET, PGC_S_SESSION,
640+
GUC_ACTION_SAVE, true, 0, false);
641+
642+
return;
643+
}
644+
626645
/* Load config if pg_pathman exists & it's still necessary */
627646
if (IsPathmanEnabled() &&
628647
!IsPathmanInitialized() &&

src/include/init.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,14 @@ simpify_mcxt_name(MemoryContext mcxt)
143143

144144

145145
/* Default column values for PATHMAN_CONFIG_PARAMS */
146-
#define DEFAULT_ENABLE_PARENT false
147-
#define DEFAULT_AUTO true
148-
#define DEFAULT_INIT_CALLBACK InvalidOid
149-
#define DEFAULT_SPAWN_USING_BGW false
146+
#define DEFAULT_PATHMAN_ENABLE_PARENT false
147+
#define DEFAULT_PATHMAN_AUTO true
148+
#define DEFAULT_PATHMAN_INIT_CALLBACK InvalidOid
149+
#define DEFAULT_PATHMAN_SPAWN_USING_BGW false
150150

151151
/* Other default values (for GUCs etc) */
152-
#define DEFAULT_PATHMAN_ENABLE true
153-
#define DEFAULT_OVERRIDE_COPY true
152+
#define DEFAULT_PATHMAN_ENABLE true
153+
#define DEFAULT_PATHMAN_OVERRIDE_COPY true
154154

155155

156156
/* Lowest version of Pl/PgSQL frontend compatible with internals (0xAA_BB_CC) */

src/include/pathman.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@
4040
#endif
4141

4242

43+
/*
44+
* Main GUC variables.
45+
*/
46+
#define PATHMAN_ENABLE "pg_pathman.enable"
47+
#define PATHMAN_ENABLE_AUTO_PARTITION "pg_pathman.enable_auto_partition"
48+
#define PATHMAN_OVERRIDE_COPY "pg_pathman.override_copy"
49+
50+
4351
/*
4452
* Definitions for the "pathman_config" table.
4553
*/

src/include/xact_handling.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ LockAcquireResult xact_lock_rel(Oid relid, LOCKMODE lockmode, bool nowait);
2828
bool xact_bgw_conflicting_lock_exists(Oid relid);
2929
bool xact_is_level_read_committed(void);
3030
bool xact_is_transaction_stmt(Node *stmt);
31-
bool xact_is_set_transaction_stmt(Node *stmt);
31+
bool xact_is_set_stmt(Node *stmt);
32+
bool xact_is_alter_pathman_stmt(Node *stmt);
3233
bool xact_object_is_visible(TransactionId obj_xmin);
3334

3435
void prevent_data_modification_internal(Oid relid);

src/init.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ void
150150
init_main_pathman_toggles(void)
151151
{
152152
/* Main toggle, load_config() will enable it */
153-
DefineCustomBoolVariable("pg_pathman.enable",
154-
"Enables pg_pathman's optimizations during the planner stage",
153+
DefineCustomBoolVariable(PATHMAN_ENABLE,
154+
"Enables pg_pathman's optimizations during planning stage",
155155
NULL,
156156
&pathman_init_state.pg_pathman_enable,
157157
DEFAULT_PATHMAN_ENABLE,
@@ -162,23 +162,23 @@ init_main_pathman_toggles(void)
162162
NULL);
163163

164164
/* Global toggle for automatic partition creation */
165-
DefineCustomBoolVariable("pg_pathman.enable_auto_partition",
165+
DefineCustomBoolVariable(PATHMAN_ENABLE_AUTO_PARTITION,
166166
"Enables automatic partition creation",
167167
NULL,
168168
&pathman_init_state.auto_partition,
169-
DEFAULT_AUTO,
169+
DEFAULT_PATHMAN_AUTO,
170170
PGC_SUSET,
171171
0,
172172
NULL,
173173
NULL,
174174
NULL);
175175

176176
/* Global toggle for COPY stmt handling */
177-
DefineCustomBoolVariable("pg_pathman.override_copy",
177+
DefineCustomBoolVariable(PATHMAN_OVERRIDE_COPY,
178178
"Override COPY statement handling",
179179
NULL,
180180
&pathman_init_state.override_copy,
181-
DEFAULT_OVERRIDE_COPY,
181+
DEFAULT_PATHMAN_OVERRIDE_COPY,
182182
PGC_SUSET,
183183
0,
184184
NULL,

src/partition_creation.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ create_single_range_partition_internal(Oid parent_relid,
134134

135135
/* Cook args for init_callback */
136136
MakeInitCallbackRangeParams(&callback_params,
137-
DEFAULT_INIT_CALLBACK,
137+
DEFAULT_PATHMAN_INIT_CALLBACK,
138138
parent_relid, partition_relid,
139139
*start_value, *end_value, value_type);
140140

@@ -193,7 +193,7 @@ create_single_hash_partition_internal(Oid parent_relid,
193193

194194
/* Cook args for init_callback */
195195
MakeInitCallbackHashParams(&callback_params,
196-
DEFAULT_INIT_CALLBACK,
196+
DEFAULT_PATHMAN_INIT_CALLBACK,
197197
parent_relid, partition_relid);
198198

199199
/* Add constraint & execute init_callback */
@@ -263,8 +263,8 @@ create_partitions_for_value(Oid relid, Datum value, Oid value_type)
263263
if (pathman_config_contains_relation(relid, NULL, NULL, &rel_xmin, NULL))
264264
{
265265
/* Take default values */
266-
bool spawn_using_bgw = DEFAULT_SPAWN_USING_BGW,
267-
enable_auto = DEFAULT_AUTO;
266+
bool spawn_using_bgw = DEFAULT_PATHMAN_SPAWN_USING_BGW,
267+
enable_auto = DEFAULT_PATHMAN_AUTO;
268268

269269
/* Values to be extracted from PATHMAN_CONFIG_PARAMS */
270270
Datum values[Natts_pathman_config_params];
@@ -835,7 +835,7 @@ create_table_using_stmt(CreateStmt *create_stmt, Oid relowner)
835835
guc_level = NewGUCNestLevel();
836836

837837
/* ... and set client_min_messages = warning */
838-
(void) set_config_option("client_min_messages", "WARNING",
838+
(void) set_config_option(CppAsString(client_min_messages), "WARNING",
839839
PGC_USERSET, PGC_S_SESSION,
840840
GUC_ACTION_SAVE, true, 0, false);
841841

@@ -1683,7 +1683,7 @@ validate_part_callback(Oid procid, bool emit_error)
16831683
Form_pg_proc functup;
16841684
bool is_ok = true;
16851685

1686-
if (procid == DEFAULT_INIT_CALLBACK)
1686+
if (procid == DEFAULT_PATHMAN_INIT_CALLBACK)
16871687
return true;
16881688

16891689
tp = SearchSysCache1(PROCOID, ObjectIdGetDatum(procid));

src/pg_pathman.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ _PG_init(void)
232232

233233
/* Assign pg_pathman's initial state */
234234
temp_init_state.pg_pathman_enable = DEFAULT_PATHMAN_ENABLE;
235-
temp_init_state.auto_partition = DEFAULT_AUTO;
236-
temp_init_state.override_copy = DEFAULT_OVERRIDE_COPY;
235+
temp_init_state.auto_partition = DEFAULT_PATHMAN_AUTO;
236+
temp_init_state.override_copy = DEFAULT_PATHMAN_OVERRIDE_COPY;
237237
temp_init_state.initialization_needed = true; /* ofc it's needed! */
238238

239239
/* Apply initial state */

src/relation_info.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ refresh_pathman_relation_info(Oid relid,
302302
/* Else set default values if they cannot be found */
303303
else
304304
{
305-
prel->enable_parent = DEFAULT_ENABLE_PARENT;
305+
prel->enable_parent = DEFAULT_PATHMAN_ENABLE_PARENT;
306306
}
307307

308308
/* We've successfully built a cache entry */

src/xact_handling.c

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,22 +111,36 @@ xact_is_transaction_stmt(Node *stmt)
111111
}
112112

113113
/*
114-
* Check if 'stmt' is SET TRANSACTION statement.
114+
* Check if 'stmt' is SET [TRANSACTION] statement.
115115
*/
116116
bool
117-
xact_is_set_transaction_stmt(Node *stmt)
117+
xact_is_set_stmt(Node *stmt)
118118
{
119+
/* Check that SET TRANSACTION is implemented via VariableSetStmt */
120+
Assert(VAR_SET_MULTI > 0);
121+
119122
if (!stmt)
120123
return false;
121124

122125
if (IsA(stmt, VariableSetStmt))
123-
{
124-
VariableSetStmt *var_set_stmt = (VariableSetStmt *) stmt;
126+
return true;
125127

126-
/* special case for SET TRANSACTION ... */
127-
if (var_set_stmt->kind == VAR_SET_MULTI)
128-
return true;
129-
}
128+
return false;
129+
}
130+
131+
/*
132+
* Check if 'stmt' is ALTER EXTENSION pg_pathman.
133+
*/
134+
bool
135+
xact_is_alter_pathman_stmt(Node *stmt)
136+
{
137+
if (!stmt)
138+
return false;
139+
140+
if (IsA(stmt, AlterExtensionStmt) &&
141+
0 == strcmp(((AlterExtensionStmt *) stmt)->extname,
142+
"pg_pathman"))
143+
return true;
130144

131145
return false;
132146
}

0 commit comments

Comments
 (0)