@@ -3045,11 +3045,16 @@ MtmGenerateGid(char* gid)
30453045
30463046static bool MtmTwoPhaseCommit (MtmCurrentTrans * x )
30473047{
3048- if (MtmUtilityStmt && ! MyXactAccessedTempRel )
3048+ if (MyXactAccessedTempRel )
30493049{
3050- MtmProcessDDLCommand (MtmUtilityStmt );
3051- pfree (MtmUtilityStmt );
3052- MtmUtilityStmt = NULL ;
3050+ /*
3051+ * XXX: this tx anyway goes to subscribers later, but without
3052+ * surrounding begin/commit. Probably there is more clever way
3053+ * to do that.
3054+ */
3055+ x -> isDistributed = false;
3056+ x -> csn = NULL ;
3057+ return false;
30533058}
30543059
30553060if (!x -> isReplicated && (x -> isDistributed && x -> containsDML )) {
@@ -3122,15 +3127,15 @@ static void MtmProcessUtility(Node *parsetree, const char *queryString,
31223127case T_CreateTableSpaceStmt :
31233128case T_AlterTableSpaceOptionsStmt :
31243129case T_TruncateStmt :
3125- case T_CommentStmt :/* XXX: we could replicate these */ ;
3130+ case T_CommentStmt :
31263131case T_PrepareStmt :
31273132case T_ExecuteStmt :
31283133case T_DeallocateStmt :
31293134case T_NotifyStmt :
31303135case T_ListenStmt :
31313136case T_UnlistenStmt :
31323137case T_LoadStmt :
3133- case T_ClusterStmt :/* XXX: we could replicate these */ ;
3138+ case T_ClusterStmt :
31343139case T_VacuumStmt :
31353140case T_ExplainStmt :
31363141case T_VariableShowStmt :
@@ -3140,6 +3145,16 @@ static void MtmProcessUtility(Node *parsetree, const char *queryString,
31403145case T_ReindexStmt :
31413146skipCommand = true;
31423147break ;
3148+
3149+ /* Do not skip following unless temp object was accessed */
3150+ case T_CreateTableAsStmt :
3151+ case T_CreateStmt :
3152+ case T_ViewStmt :
3153+ case T_IndexStmt :
3154+ case T_DropStmt :
3155+ break ;
3156+
3157+ /* Save GUC context for consequent DDL execution */
31433158case T_DiscardStmt :
31443159{
31453160DiscardStmt * stmt = (DiscardStmt * )parsetree ;
@@ -3156,8 +3171,6 @@ static void MtmProcessUtility(Node *parsetree, const char *queryString,
31563171{
31573172VariableSetStmt * stmt = (VariableSetStmt * )parsetree ;
31583173
3159- // skipCommand = true;
3160-
31613174/* Prevent SET TRANSACTION from replication */
31623175if (stmt -> kind == VAR_SET_MULTI )
31633176skipCommand = true;
@@ -3169,88 +3182,8 @@ static void MtmProcessUtility(Node *parsetree, const char *queryString,
31693182}
31703183}
31713184break ;
3172- case T_CreateTableAsStmt :
3173- // {
3174- // /* Do not replicate temp tables */
3175- // CreateTableAsStmt *stmt = (CreateTableAsStmt *) parsetree;
3176- // skipCommand = stmt->into->rel->relpersistence == RELPERSISTENCE_TEMP ||
3177- // (stmt->into->rel->schemaname && strcmp(stmt->into->rel->schemaname, "pg_temp") == 0);
3178- // }
3179- break ;
3180- case T_CreateStmt :
3181- {
3182- /* Do not replicate temp tables */
3183- CreateStmt * stmt = (CreateStmt * )parsetree ;
3184- skipCommand = stmt -> relation -> relpersistence == RELPERSISTENCE_TEMP ||
3185- (stmt -> relation -> schemaname && strcmp (stmt -> relation -> schemaname ,"pg_temp" )== 0 );
3186- }
3187- break ;
3188- case T_ViewStmt :
3189- {
3190- ViewStmt * stmt = (ViewStmt * )parsetree ;
3191- Query * viewParse ;
3192-
3193- viewParse = parse_analyze ((Node * )copyObject (stmt -> query ),
3194- queryString ,NULL ,0 );
3195- skipCommand = isQueryUsingTempRelation (viewParse )||
3196- stmt -> view -> relpersistence == RELPERSISTENCE_TEMP ;
3197- // ||
3198- // (stmt->relation->schemaname && strcmp(stmt->relation->schemaname, "pg_temp") == 0);
3199- }
3200- break ;
3201- case T_IndexStmt :
3202- {
3203- Oid relid ;
3204- Relation rel ;
3205- IndexStmt * stmt = (IndexStmt * )parsetree ;
3206- bool isTopLevel = (context == PROCESS_UTILITY_TOPLEVEL );
32073185
3208- if (stmt -> concurrent )
3209- PreventTransactionChain (isTopLevel ,
3210- "CREATE INDEX CONCURRENTLY" );
3211-
3212- relid = RelnameGetRelid (stmt -> relation -> relname );
3213-
3214- if (OidIsValid (relid ))
3215- {
3216- rel = heap_open (relid ,ShareLock );
3217- skipCommand = rel -> rd_rel -> relpersistence == RELPERSISTENCE_TEMP ;
3218- heap_close (rel ,ShareLock );
3219- }
3220- }
3221- break ;
3222- case T_DropStmt :
3223- {
3224- DropStmt * stmt = (DropStmt * )parsetree ;
3225-
3226- if (stmt -> removeType == OBJECT_TABLE )
3227- {
3228- RangeVar * rv = makeRangeVarFromNameList (
3229- (List * )lfirst (list_head (stmt -> objects )));
3230- Oid relid = RelnameGetRelid (rv -> relname );
3231-
3232- if (OidIsValid (relid ))
3233- {
3234- Relation rel = heap_open (relid ,ShareLock );
3235- skipCommand = rel -> rd_rel -> relpersistence == RELPERSISTENCE_TEMP ;
3236- heap_close (rel ,ShareLock );
3237- }
3238- }
3239- else if (stmt -> removeType == OBJECT_INDEX )
3240- {
3241- RangeVar * rv = makeRangeVarFromNameList (
3242- (List * )lfirst (list_head (stmt -> objects )));
3243- Oid relid = RelnameGetRelid (rv -> relname );
3244-
3245- if (OidIsValid (relid ))
3246- {
3247- Relation irel = index_open (relid ,ShareLock );
3248- skipCommand = irel -> rd_rel -> relpersistence == RELPERSISTENCE_TEMP ;
3249- index_close (irel ,ShareLock );
3250- }
3251- }
3252- }
3253- break ;
3186+ /* Copy need some special care */
32543187case T_CopyStmt :
32553188{
32563189CopyStmt * copyStatement = (CopyStmt * )parsetree ;
@@ -3281,20 +3214,9 @@ static void MtmProcessUtility(Node *parsetree, const char *queryString,
32813214if (context == PROCESS_UTILITY_TOPLEVEL )
32823215{
32833216if (!skipCommand && !MtmTx .isReplicated ) {
3284- // if (MtmProcessDDLCommand(queryString)) {
3285- // return;
3286- // }
3287-
3288- MemoryContext oldcontext ;
3289-
3290- if (MtmUtilityStmt )
3291- pfree (MtmUtilityStmt );
3292-
3293- oldcontext = MemoryContextSwitchTo (TopMemoryContext );
3294- MtmUtilityStmt = palloc (strlen (queryString )+ 1 );
3295- MemoryContextSwitchTo (oldcontext );
3296-
3297- strncpy (MtmUtilityStmt ,queryString ,strlen (queryString )+ 1 );
3217+ if (MtmProcessDDLCommand (queryString )) {
3218+ return ;
3219+ }
32983220}
32993221}
33003222