Skip to content

Commit babdf37

Browse files
committed
Port ATX to 9.6 EE branch
1 parent 308f763 commit babdf37

File tree

43 files changed

+1140
-218
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1140
-218
lines changed

src/backend/access/transam/xact.c

Lines changed: 317 additions & 13 deletions
Large diffs are not rendered by default.

src/backend/commands/trigger.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5013,6 +5013,23 @@ AfterTriggerSaveEvent(EState *estate, ResultRelInfo *relinfo,
50135013
}
50145014
}
50155015

5016+
void *
5017+
TriggerSuspend(void)
5018+
{
5019+
AfterTriggersData *state = malloc(sizeof(AfterTriggersData));
5020+
*state = afterTriggers;
5021+
memset(&afterTriggers, 0, sizeof(afterTriggers));
5022+
AfterTriggerBeginXact();
5023+
return state;
5024+
}
5025+
5026+
void
5027+
TriggerResume(void *state)
5028+
{
5029+
afterTriggers = *(AfterTriggersData *)state;
5030+
free(state);
5031+
}
5032+
50165033
Datum
50175034
pg_trigger_depth(PG_FUNCTION_ARGS)
50185035
{

src/backend/executor/spi.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ static int _SPI_stack_depth = 0; /* allocated size of _SPI_stack */
4747
static int _SPI_connected = -1;
4848
static int _SPI_curid = -1;
4949

50+
typedef struct SuspendedSPI
51+
{
52+
_SPI_connection *_SPI_stack;
53+
_SPI_connection *_SPI_current;
54+
int _SPI_stack_depth;
55+
int _SPI_connected;
56+
int _SPI_curid;
57+
} SuspendedSPI;
58+
5059
static Portal SPI_cursor_open_internal(const char *name, SPIPlanPtr plan,
5160
ParamListInfo paramLI, bool read_only);
5261

@@ -2731,3 +2740,32 @@ _SPI_save_plan(SPIPlanPtr plan)
27312740

27322741
return newplan;
27332742
}
2743+
2744+
#define MOVELEFT(A, B, C) do { (A) = (B); } while (0)
2745+
void *
2746+
SuspendSPI(void)
2747+
{
2748+
SuspendedSPI *s = malloc(sizeof(SuspendedSPI));
2749+
2750+
MOVELEFT(s->_SPI_stack, _SPI_stack, NULL);
2751+
MOVELEFT(s->_SPI_current, _SPI_current, NULL);
2752+
MOVELEFT(s->_SPI_stack_depth, _SPI_stack_depth, 0);
2753+
MOVELEFT(s->_SPI_connected, _SPI_connected, -1);
2754+
MOVELEFT(s->_SPI_curid, _SPI_curid, -1);
2755+
2756+
return s;
2757+
}
2758+
2759+
void
2760+
ResumeSPI(void *state)
2761+
{
2762+
SuspendedSPI *s = (SuspendedSPI *)state;
2763+
2764+
_SPI_stack = s->_SPI_stack;
2765+
_SPI_current = s->_SPI_current;
2766+
_SPI_stack_depth = s->_SPI_stack_depth;
2767+
_SPI_connected = s->_SPI_connected;
2768+
_SPI_curid = s->_SPI_curid;
2769+
2770+
free(state);
2771+
}

src/backend/parser/gram.y

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
409409
%type <list> opt_interval interval_second
410410
%type <node> overlay_placing substr_from substr_for
411411

412+
%type <boolean> opt_autonomous
412413
%type <boolean> opt_instead
413414
%type <boolean> opt_unique opt_concurrently opt_verbose opt_full
414415
%type <boolean> opt_freeze opt_default opt_recheck
@@ -566,7 +567,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
566567
/* ordinary key words in alphabetical order */
567568
%token <keyword> ABORT_P ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
568569
AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY APPLICATION ARRAY AS ASC
569-
ASSERTION ASSIGNMENT ASYMMETRIC AT ATTRIBUTE AUTHORIZATION
570+
ASSERTION ASSIGNMENT ASYMMETRIC AT ATTRIBUTE AUTHORIZATION AUTONOMOUS
570571

571572
BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
572573
BOOLEAN_P BOTH BY
@@ -8697,18 +8698,28 @@ TransactionStmt:
86978698
n->options = NIL;
86988699
$$ = (Node *)n;
86998700
}
8700-
| BEGIN_P opt_transaction transaction_mode_list_or_empty
8701+
| ABORT_P AUTONOMOUS TRANSACTION
8702+
{
8703+
TransactionStmt *n = makeNode(TransactionStmt);
8704+
n->kind = TRANS_STMT_ROLLBACK;
8705+
n->autonomous = true;
8706+
n->options = NIL;
8707+
$$ = (Node *)n;
8708+
}
8709+
| BEGIN_P opt_autonomous opt_transaction transaction_mode_list_or_empty
87018710
{
87028711
TransactionStmt *n = makeNode(TransactionStmt);
87038712
n->kind = TRANS_STMT_BEGIN;
8704-
n->options = $3;
8713+
n->autonomous = $2;
8714+
n->options = $4;
87058715
$$ = (Node *)n;
87068716
}
8707-
| START TRANSACTION transaction_mode_list_or_empty
8717+
| START opt_autonomous TRANSACTION transaction_mode_list_or_empty
87088718
{
87098719
TransactionStmt *n = makeNode(TransactionStmt);
87108720
n->kind = TRANS_STMT_START;
8711-
n->options = $3;
8721+
n->autonomous = $2;
8722+
n->options = $4;
87128723
$$ = (Node *)n;
87138724
}
87148725
| COMMIT opt_transaction
@@ -8718,20 +8729,44 @@ TransactionStmt:
87188729
n->options = NIL;
87198730
$$ = (Node *)n;
87208731
}
8732+
| COMMIT AUTONOMOUS TRANSACTION
8733+
{
8734+
TransactionStmt *n = makeNode(TransactionStmt);
8735+
n->kind = TRANS_STMT_COMMIT;
8736+
n->autonomous = true;
8737+
n->options = NIL;
8738+
$$ = (Node *)n;
8739+
}
87218740
| END_P opt_transaction
87228741
{
87238742
TransactionStmt *n = makeNode(TransactionStmt);
87248743
n->kind = TRANS_STMT_COMMIT;
87258744
n->options = NIL;
87268745
$$ = (Node *)n;
87278746
}
8747+
| END_P AUTONOMOUS TRANSACTION
8748+
{
8749+
TransactionStmt *n = makeNode(TransactionStmt);
8750+
n->kind = TRANS_STMT_COMMIT;
8751+
n->autonomous = true;
8752+
n->options = NIL;
8753+
$$ = (Node *)n;
8754+
}
87288755
| ROLLBACK opt_transaction
87298756
{
87308757
TransactionStmt *n = makeNode(TransactionStmt);
87318758
n->kind = TRANS_STMT_ROLLBACK;
87328759
n->options = NIL;
87338760
$$ = (Node *)n;
87348761
}
8762+
| ROLLBACK AUTONOMOUS TRANSACTION
8763+
{
8764+
TransactionStmt *n = makeNode(TransactionStmt);
8765+
n->kind = TRANS_STMT_ROLLBACK;
8766+
n->autonomous = true;
8767+
n->options = NIL;
8768+
$$ = (Node *)n;
8769+
}
87358770
| SAVEPOINT ColId
87368771
{
87378772
TransactionStmt *n = makeNode(TransactionStmt);
@@ -8800,6 +8835,11 @@ opt_transaction: WORK {}
88008835
| /*EMPTY*/ {}
88018836
;
88028837

8838+
opt_autonomous:
8839+
AUTONOMOUS { $$ = TRUE; }
8840+
| /*EMPTY*/ { $$ = FALSE; }
8841+
;
8842+
88038843
transaction_mode_item:
88048844
ISOLATION LEVEL iso_level
88058845
{ $$ = makeDefElem("transaction_isolation",
@@ -14136,6 +14176,7 @@ col_name_keyword:
1413614176
*/
1413714177
type_func_name_keyword:
1413814178
AUTHORIZATION
14179+
| AUTONOMOUS
1413914180
| BINARY
1414014181
| COLLATION
1414114182
| CONCURRENTLY

src/backend/postmaster/pgstat.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5536,3 +5536,40 @@ pgstat_db_requested(Oid databaseid)
55365536

55375537
return false;
55385538
}
5539+
5540+
typedef struct {
5541+
PgStat_SubXactStatus *pgStatXactStack;
5542+
int pgStatXactCommit;
5543+
int pgStatXactRollback;
5544+
PgStat_Counter pgStatBlockReadTime;
5545+
PgStat_Counter pgStatBlockWriteTime;
5546+
} SuspendedPgStat;
5547+
5548+
#define MOVELEFT(A, B, C) do { (A) = (B); (B) = (C); } while (0)
5549+
void *
5550+
PgStatSuspend(void)
5551+
{
5552+
SuspendedPgStat *sus = malloc(sizeof(SuspendedPgStat));
5553+
5554+
MOVELEFT(sus->pgStatXactStack, pgStatXactStack, NULL);
5555+
MOVELEFT(sus->pgStatXactCommit, pgStatXactCommit, 0);
5556+
MOVELEFT(sus->pgStatXactRollback, pgStatXactRollback, 0);
5557+
MOVELEFT(sus->pgStatBlockReadTime, pgStatBlockReadTime, 0);
5558+
MOVELEFT(sus->pgStatBlockWriteTime, pgStatBlockWriteTime, 0);
5559+
5560+
return sus;
5561+
}
5562+
5563+
void
5564+
PgStatResume(void *src)
5565+
{
5566+
SuspendedPgStat *sus = (SuspendedPgStat *)src;
5567+
5568+
pgStatXactStack = sus->pgStatXactStack;
5569+
pgStatXactCommit = sus->pgStatXactCommit;
5570+
pgStatXactRollback = sus->pgStatXactRollback;
5571+
pgStatBlockReadTime = sus->pgStatBlockReadTime;
5572+
pgStatBlockWriteTime = sus->pgStatBlockWriteTime;
5573+
5574+
free(src);
5575+
}

0 commit comments

Comments
 (0)