Skip to content

Commit 0a99fcb

Browse files
committed
Merge branch 'master' of github.com:postgrespro/pg_pathman
2 parents 4227a98 + c7a8abf commit 0a99fcb

File tree

6 files changed

+53
-16
lines changed

6 files changed

+53
-16
lines changed

Diff for: expected/pg_pathman.out

+1-1
Original file line numberDiff line numberDiff line change
@@ -1690,7 +1690,7 @@ INSERT INTO messages SELECT g, md5(g::text) FROM generate_series(1, 10) as g;
16901690
INSERT INTO replies SELECT g, g, md5(g::text) FROM generate_series(1, 10) as g;
16911691
SELECT create_range_partitions('messages', 'id', 1, 100, 2);
16921692
WARNING: Foreign key 'replies_message_id_fkey' references to the relation 'messages'
1693-
ERROR: Relation 'messages' is referenced from other relations
1693+
ERROR: Relation "messages" is referenced from other relations
16941694
ALTER TABLE replies DROP CONSTRAINT replies_message_id_fkey;
16951695
SELECT create_range_partitions('messages', 'id', 1, 100, 2);
16961696
NOTICE: sequence "messages_seq" does not exist, skipping

Diff for: init.sql

+2-2
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ BEGIN
341341
END LOOP;
342342

343343
IF is_referenced THEN
344-
RAISE EXCEPTION 'Relation ''%'' is referenced from other relations', p_relation;
344+
RAISE EXCEPTION 'Relation "%" is referenced from other relations', p_relation;
345345
END IF;
346346

347347
RETURN TRUE;
@@ -515,7 +515,7 @@ BEGIN
515515
DELETE FROM @[email protected]_config_params WHERE partrel = parent_relid;
516516

517517
IF conf_num_del = 0 THEN
518-
RAISE EXCEPTION 'table % has no partitions', parent_relid::text;
518+
RAISE EXCEPTION 'Relation "%" has no partitions', parent_relid::text;
519519
END IF;
520520

521521
FOR v_rec IN (SELECT inhrelid::regclass::text AS tbl

Diff for: src/hooks.c

+9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "runtimeappend.h"
1515
#include "runtime_merge_append.h"
1616
#include "utils.h"
17+
#include "xact_handling.h"
1718

1819
#include "miscadmin.h"
1920
#include "optimizer/cost.h"
@@ -451,6 +452,14 @@ pathman_post_parse_analysis_hook(ParseState *pstate, Query *query)
451452
if (post_parse_analyze_hook_next)
452453
post_parse_analyze_hook_next(pstate, query);
453454

455+
/* We shouldn't do anything on BEGIN or SET ISOLATION LEVEL stmts */
456+
if (query->commandType == CMD_UTILITY &&
457+
(xact_is_transaction_stmt(query->utilityStmt) ||
458+
xact_is_set_transaction_stmt(query->utilityStmt)))
459+
{
460+
return;
461+
}
462+
454463
/* Finish delayed invalidation jobs */
455464
if (IsPathmanReady())
456465
finish_delayed_invalidation();

Diff for: src/pathman_workers.c

-12
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "pathman_workers.h"
1919
#include "relation_info.h"
2020
#include "utils.h"
21-
#include "xact_handling.h"
2221

2322
#include "access/htup_details.h"
2423
#include "access/xact.h"
@@ -360,17 +359,6 @@ bgw_main_spawn_partitions(Datum main_arg)
360359
DebugPrintDatum(value, args->value_type), MyProcPid);
361360
#endif
362361

363-
/* Check again if there's a conflicting lock */
364-
if (xact_bgw_conflicting_lock_exists(args->partitioned_table))
365-
{
366-
elog(LOG, "%s: there's a conflicting lock on relation \"%s\"",
367-
spawn_partitions_bgw,
368-
get_rel_name_or_relid(args->partitioned_table));
369-
370-
dsm_detach(segment);
371-
return; /* exit quickly */
372-
}
373-
374362
/* Create partitions and save the Oid of the last one */
375363
args->result = create_partitions_internal(args->partitioned_table,
376364
value, /* unpacked Datum */

Diff for: src/xact_handling.c

+37-1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,42 @@ xact_is_level_read_committed(void)
109109
return false;
110110
}
111111

112+
/*
113+
* Check if 'stmt' is BEGIN\ROLLBACK etc transaction statement.
114+
*/
115+
bool
116+
xact_is_transaction_stmt(Node *stmt)
117+
{
118+
if (!stmt)
119+
return false;
120+
121+
if (IsA(stmt, TransactionStmt))
122+
return true;
123+
124+
return false;
125+
}
126+
127+
/*
128+
* Check if 'stmt' is SET TRANSACTION statement.
129+
*/
130+
bool
131+
xact_is_set_transaction_stmt(Node *stmt)
132+
{
133+
if (!stmt)
134+
return false;
135+
136+
if (IsA(stmt, VariableSetStmt))
137+
{
138+
VariableSetStmt *var_set_stmt = (VariableSetStmt *) stmt;
139+
140+
/* special case for SET TRANSACTION ... */
141+
if (var_set_stmt->kind == VAR_SET_MULTI)
142+
return true;
143+
}
144+
145+
return false;
146+
}
147+
112148
/*
113149
* Do we hold the specified lock?
114150
*/
@@ -132,7 +168,7 @@ do_we_hold_the_lock(Oid relid, LOCKMODE lockmode)
132168
return false;
133169

134170
default:
135-
return false; /* should not happen */
171+
return false;
136172
}
137173
}
138174

Diff for: src/xact_handling.h

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
#include "pathman.h"
1515

16+
#include "postgres.h"
17+
1618

1719
/*
1820
* Transaction locks.
@@ -28,5 +30,7 @@ void xact_unlock_rel_exclusive(Oid relid);
2830
*/
2931
bool xact_bgw_conflicting_lock_exists(Oid relid);
3032
bool xact_is_level_read_committed(void);
33+
bool xact_is_transaction_stmt(Node *stmt);
34+
bool xact_is_set_transaction_stmt(Node *stmt);
3135

3236
#endif

0 commit comments

Comments
 (0)