Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0b77eba

Browse files
Alexander Kuzmenkovkelvich
Alexander Kuzmenkov
authored andcommitted
Handle multistatement DDL correctly. https://jira.postgrespro.ru/browse/PGPRO-1598
1 parent 185bd09 commit 0b77eba

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

multimaster.c

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5138,18 +5138,24 @@ AdjustCreateSequence(List *options)
51385138
}
51395139

51405140
static void MtmProcessUtility(PlannedStmt *pstmt,
5141-
const char *queryString, ProcessUtilityContext context,
5142-
ParamListInfo params,
5143-
QueryEnvironment *queryEnv,
5144-
DestReceiver *dest, char *completionTag)
5141+
const char *queryString, ProcessUtilityContext context,
5142+
ParamListInfo params,
5143+
QueryEnvironment *queryEnv,
5144+
DestReceiver *dest, char *completionTag)
51455145
{
51465146
bool skipCommand = false;
51475147
bool executed = false;
51485148
bool prevMyXactAccessedTempRel;
51495149
Node *parsetree = pstmt->utilityStmt;
5150+
int stmt_start = pstmt->stmt_location > 0 ? pstmt->stmt_location : 0;
5151+
int stmt_len = pstmt->stmt_len > 0 ? pstmt->stmt_len : strlen(queryString + stmt_start);
5152+
char *stmt_string = palloc(stmt_len + 1);
5153+
5154+
strncpy(stmt_string, queryString + stmt_start, stmt_len);
5155+
stmt_string[stmt_len] = 0;
51505156

5151-
MTM_LOG2("%d: Process utility statement tag=%d, context=%d, issubtrans=%d, creating_extension=%d, query=%s",
5152-
MyProcPid, nodeTag(parsetree), context, IsSubTransaction(), creating_extension, queryString);
5157+
MTM_LOG2("%d: Process utility statement tag=%d, context=%d, issubtrans=%d, creating_extension=%d, statement=%s",
5158+
MyProcPid, nodeTag(parsetree), context, IsSubTransaction(), creating_extension, stmt_string);
51535159
switch (nodeTag(parsetree))
51545160
{
51555161
case T_TransactionStmt:
@@ -5230,7 +5236,7 @@ static void MtmProcessUtility(PlannedStmt *pstmt,
52305236
else
52315237
{
52325238
skipCommand = true;
5233-
MtmProcessDDLCommand(queryString, false);
5239+
MtmProcessDDLCommand(stmt_string, false);
52345240
}
52355241
}
52365242
break;
@@ -5242,7 +5248,7 @@ static void MtmProcessUtility(PlannedStmt *pstmt,
52425248
if (!MtmVolksWagenMode)
52435249
{
52445250
if (context == PROCESS_UTILITY_TOPLEVEL) {
5245-
MtmProcessDDLCommand(queryString, false);
5251+
MtmProcessDDLCommand(stmt_string, false);
52465252
MtmTx.isDistributed = false;
52475253
} else if (MtmApplyContext != NULL) {
52485254
MemoryContext oldContext = MemoryContextSwitchTo(MtmApplyContext);
@@ -5335,7 +5341,7 @@ static void MtmProcessUtility(PlannedStmt *pstmt,
53355341
if (!IsTransactionBlock())
53365342
{
53375343
skipCommand = true;
5338-
MtmGucSet(stmt, queryString);
5344+
MtmGucSet(stmt, stmt_string);
53395345
}
53405346
}
53415347
break;
@@ -5346,7 +5352,7 @@ static void MtmProcessUtility(PlannedStmt *pstmt,
53465352
if (indexStmt->concurrent)
53475353
{
53485354
if (context == PROCESS_UTILITY_TOPLEVEL) {
5349-
MtmProcessDDLCommand(queryString, false);
5355+
MtmProcessDDLCommand(stmt_string, false);
53505356
MtmTx.isDistributed = false;
53515357
skipCommand = true;
53525358
/*
@@ -5378,7 +5384,7 @@ static void MtmProcessUtility(PlannedStmt *pstmt,
53785384
if (stmt->removeType == OBJECT_INDEX && stmt->concurrent)
53795385
{
53805386
if (context == PROCESS_UTILITY_TOPLEVEL) {
5381-
MtmProcessDDLCommand(queryString, false);
5387+
MtmProcessDDLCommand(stmt_string, false);
53825388
MtmTx.isDistributed = false;
53835389
skipCommand = true;
53845390
} else if (MtmApplyContext != NULL) {
@@ -5448,12 +5454,14 @@ static void MtmProcessUtility(PlannedStmt *pstmt,
54485454

54495455
if (!skipCommand && !MtmTx.isReplicated && !MtmDDLStatement)
54505456
{
5451-
MTM_LOG3("Process DDL statement '%s', MtmTx.isReplicated=%d, MtmIsLogicalReceiver=%d", queryString, MtmTx.isReplicated, MtmIsLogicalReceiver);
5452-
MtmProcessDDLCommand(queryString, true);
5457+
MTM_LOG3("Process DDL statement '%s', MtmTx.isReplicated=%d, "
5458+
"MtmIsLogicalReceiver=%d", stmt_string, MtmTx.isReplicated,
5459+
MtmIsLogicalReceiver);
5460+
MtmProcessDDLCommand(stmt_string, true);
54535461
executed = true;
5454-
MtmDDLStatement = queryString;
5462+
MtmDDLStatement = stmt_string;
54555463
}
5456-
else MTM_LOG3("Skip utility statement '%s': skip=%d, insideDDL=%d", queryString, skipCommand, MtmDDLStatement != NULL);
5464+
else MTM_LOG3("Skip utility statement '%s': skip=%d, insideDDL=%d", stmt_string, skipCommand, MtmDDLStatement != NULL);
54575465

54585466
prevMyXactAccessedTempRel = MyXactFlags & XACT_FLAGS_ACCESSEDTEMPREL;
54595467

@@ -5491,7 +5499,7 @@ static void MtmProcessUtility(PlannedStmt *pstmt,
54915499
}
54925500
if (MyXactFlags & XACT_FLAGS_ACCESSEDTEMPREL)
54935501
{
5494-
MTM_LOG1("Xact accessed temp table, stopping replication of statement '%s'", queryString);
5502+
MTM_LOG1("Xact accessed temp table, stopping replication of statement '%s'", stmt_string);
54955503
MtmTx.isDistributed = false; /* Skip */
54965504
MtmTx.snapshot = INVALID_CSN;
54975505
}

0 commit comments

Comments
 (0)