Skip to content

Commit ef72caa

Browse files
committed
reorder some steps in pathman_post_parse_analysis_hook() (issue #118)
1 parent 79147b0 commit ef72caa

File tree

3 files changed

+51
-35
lines changed

3 files changed

+51
-35
lines changed

src/hooks.c

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -632,39 +632,51 @@ pathman_post_parse_analysis_hook(ParseState *pstate, Query *query)
632632
if (post_parse_analyze_hook_next)
633633
post_parse_analyze_hook_next(pstate, query);
634634

635-
/* Hooks can be disabled */
635+
/* See cook_partitioning_expression() */
636636
if (!pathman_hooks_enabled)
637637
return;
638638

639-
/* Finish delayed invalidation jobs */
640-
if (IsPathmanReady())
641-
finish_delayed_invalidation();
639+
/* We shouldn't proceed on: ... */
640+
if (query->commandType == CMD_UTILITY)
641+
{
642+
/* ... BEGIN */
643+
if (xact_is_transaction_stmt(query->utilityStmt))
644+
return;
642645

643-
/*
644-
* We shouldn't proceed on:
645-
* BEGIN
646-
* SET [TRANSACTION]
647-
*/
648-
if (query->commandType == CMD_UTILITY &&
649-
(xact_is_transaction_stmt(query->utilityStmt) ||
650-
xact_is_set_stmt(query->utilityStmt)))
651-
return;
646+
/* ... SET pg_pathman.enable */
647+
if (xact_is_set_stmt(query->utilityStmt, PATHMAN_ENABLE))
648+
{
649+
/* Accept all events in case it's "enable = OFF" */
650+
if (IsPathmanReady())
651+
finish_delayed_invalidation();
652652

653-
/*
654-
* We should also disable pg_pathman on:
655-
* ALTER EXTENSION pg_pathman
656-
*/
657-
if (query->commandType == CMD_UTILITY &&
658-
xact_is_alter_pathman_stmt(query->utilityStmt))
659-
{
660-
/* Disable pg_pathman to perform a painless update */
661-
(void) set_config_option(PATHMAN_ENABLE, "off",
662-
PGC_SUSET, PGC_S_SESSION,
663-
GUC_ACTION_SAVE, true, 0, false);
653+
return;
654+
}
664655

665-
return;
656+
/* ... SET [TRANSACTION] */
657+
if (xact_is_set_stmt(query->utilityStmt, NULL))
658+
return;
659+
660+
/* ... ALTER EXTENSION pg_pathman */
661+
if (xact_is_alter_pathman_stmt(query->utilityStmt))
662+
{
663+
/* Leave no delayed events before ALTER EXTENSION */
664+
if (IsPathmanReady())
665+
finish_delayed_invalidation();
666+
667+
/* Disable pg_pathman to perform a painless update */
668+
(void) set_config_option(PATHMAN_ENABLE, "off",
669+
PGC_SUSET, PGC_S_SESSION,
670+
GUC_ACTION_SAVE, true, 0, false);
671+
672+
return;
673+
}
666674
}
667675

676+
/* Finish all delayed invalidation jobs */
677+
if (IsPathmanReady())
678+
finish_delayed_invalidation();
679+
668680
/* Load config if pg_pathman exists & it's still necessary */
669681
if (IsPathmanEnabled() &&
670682
!IsPathmanInitialized() &&
@@ -746,7 +758,7 @@ pathman_relcache_hook(Datum arg, Oid relid)
746758
{
747759
Oid parent_relid;
748760

749-
/* Hooks can be disabled */
761+
/* See cook_partitioning_expression() */
750762
if (!pathman_hooks_enabled)
751763
return;
752764

src/include/xact_handling.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ 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_stmt(Node *stmt);
31+
bool xact_is_set_stmt(Node *stmt, const char *name);
3232
bool xact_is_alter_pathman_stmt(Node *stmt);
3333
bool xact_object_is_visible(TransactionId obj_xmin);
3434

src/xact_handling.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ xact_is_level_read_committed(void)
9696
}
9797

9898
/*
99-
* Check if 'stmt' is BEGIN\ROLLBACK etc transaction statement.
99+
* Check if 'stmt' is BEGIN/ROLLBACK/etc [TRANSACTION] statement.
100100
*/
101101
bool
102102
xact_is_transaction_stmt(Node *stmt)
@@ -111,18 +111,21 @@ xact_is_transaction_stmt(Node *stmt)
111111
}
112112

113113
/*
114-
* Check if 'stmt' is SET [TRANSACTION] statement.
114+
* Check if 'stmt' is SET ('name' | [TRANSACTION]) statement.
115115
*/
116116
bool
117-
xact_is_set_stmt(Node *stmt)
117+
xact_is_set_stmt(Node *stmt, const char *name)
118118
{
119119
/* Check that SET TRANSACTION is implemented via VariableSetStmt */
120120
Assert(VAR_SET_MULTI > 0);
121121

122122
if (!stmt)
123123
return false;
124124

125-
if (IsA(stmt, VariableSetStmt))
125+
if (!IsA(stmt, VariableSetStmt))
126+
return false;
127+
128+
if (!name || pg_strcasecmp(name, ((VariableSetStmt *) stmt)->name) == 0)
126129
return true;
127130

128131
return false;
@@ -137,16 +140,17 @@ xact_is_alter_pathman_stmt(Node *stmt)
137140
if (!stmt)
138141
return false;
139142

140-
if (IsA(stmt, AlterExtensionStmt) &&
141-
0 == strcmp(((AlterExtensionStmt *) stmt)->extname,
142-
"pg_pathman"))
143+
if (!IsA(stmt, AlterExtensionStmt))
144+
return false;
145+
146+
if (pg_strcasecmp(((AlterExtensionStmt *) stmt)->extname, "pg_pathman") == 0)
143147
return true;
144148

145149
return false;
146150
}
147151

148152
/*
149-
* Check if object is visible in newer transactions.
153+
* Check if object is visible to newer transactions.
150154
*/
151155
bool
152156
xact_object_is_visible(TransactionId obj_xmin)

0 commit comments

Comments
 (0)