On Fri, 2007-09-07 at 14:00 +0100, Simon Riggs wrote:
> Short patch
--
Simon Riggs
2ndQuadrant http://www.2ndQuadrant.com
Index: doc/src/sgml/ref/set_transaction.sgml
===================================================================
RCS file: /projects/cvsroot/pgsql/doc/src/sgml/ref/set_transaction.sgml,v
retrieving revision 1.25
diff -c -r1.25 set_transaction.sgml
*** doc/src/sgml/ref/set_transaction.sgml 16 Sep 2006 00:30:20 -0000 1.25
--- doc/src/sgml/ref/set_transaction.sgml 7 Sep 2007 12:49:05 -0000
***************
*** 31,42 ****
<para>
The <command>SET TRANSACTION</command> command sets the
! characteristics of the current transaction. It has no effect on any
! subsequent transactions. <command>SET SESSION
! CHARACTERISTICS</command> sets the default transaction
! characteristics for subsequent transactions of a session. These
! defaults can be overridden by <command>SET TRANSACTION</command>
! for an individual transaction.
</para>
<para>
--- 31,43 ----
<para>
The <command>SET TRANSACTION</command> command sets the
! characteristics of the current or next transaction. If the command
! executed from within a transaction block it will set the current
! transaction, otherwise the specified characteristics will apply to
! the next transaction. <command>SET SESSION CHARACTERISTICS</command>
! sets the default transaction characteristics for subsequent
! transactions of a session. These defaults can be overridden by
! <command>SET TRANSACTION</command> for an individual transaction.
</para>
<para>
***************
*** 112,120 ****
<para>
If <command>SET TRANSACTION</command> is executed without a prior
! <command>START TRANSACTION</command> or <command>BEGIN</command>,
! it will appear to have no effect, since the transaction will immediately
! end.
</para>
<para>
--- 113,125 ----
<para>
If <command>SET TRANSACTION</command> is executed without a prior
! <command>START TRANSACTION</command> or <command>BEGIN</command>,
! then the next transaction (only) on this session will acquire the
! specified transaction characteristics. Those characteristics may
! be overridden if any conflicting options exist on the
! <command>START TRANSACTION</command> or <command>BEGIN</command>, if
! one is issued for the next transaction. This is new behaviour in
! Release 8.3 to conform with the SQL standard.
</para>
<para>
Index: src/backend/access/transam/xact.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/access/transam/xact.c,v
retrieving revision 1.248
diff -c -r1.248 xact.c
*** src/backend/access/transam/xact.c 5 Sep 2007 18:10:47 -0000 1.248
--- src/backend/access/transam/xact.c 7 Sep 2007 12:49:09 -0000
***************
*** 52,60 ****
--- 52,62 ----
*/
int DefaultXactIsoLevel = XACT_READ_COMMITTED;
int XactIsoLevel;
+ int nextXactIsoLevel = XACT_ISOLATION_NOT_SET;
bool DefaultXactReadOnly = false;
bool XactReadOnly;
+ bool nextXactReadOnly = false;
bool XactSyncCommit = true;
***************
*** 1388,1395 ****
* Make sure we've freed any old snapshot, and reset xact state variables
*/
FreeXactSnapshot();
! XactIsoLevel = DefaultXactIsoLevel;
! XactReadOnly = DefaultXactReadOnly;
forceSyncCommit = false;
/*
--- 1390,1412 ----
* Make sure we've freed any old snapshot, and reset xact state variables
*/
FreeXactSnapshot();
!
! if (nextXactIsoLevel != XACT_ISOLATION_NOT_SET)
! {
! XactIsoLevel = nextXactIsoLevel;
! nextXactIsoLevel = XACT_ISOLATION_NOT_SET;
! }
! else
! XactIsoLevel = DefaultXactIsoLevel;
!
! if (nextXactReadOnly)
! {
! XactReadOnly = true;
! nextXactReadOnly = false;
! }
! else
! XactReadOnly = DefaultXactReadOnly;
!
forceSyncCommit = false;
/*
Index: src/backend/commands/variable.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/commands/variable.c,v
retrieving revision 1.121
diff -c -r1.121 variable.c
*** src/backend/commands/variable.c 4 Aug 2007 01:26:53 -0000 1.121
--- src/backend/commands/variable.c 7 Sep 2007 12:49:10 -0000
***************
*** 604,609 ****
--- 604,618 ----
else
return NULL;
+ /*
+ * If we are setting isolation level and we are not in a transaction block
+ * then set the level for the next transaction, as per SQL standard.
+ * We allow the mode to be set for the current transaction, since this
+ * is historic behaviour and harmless.
+ */
+ if (!IsTransactionBlock())
+ nextXactIsoLevel = XactIsoLevel;
+
return value;
}
Index: src/backend/utils/misc/guc.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/utils/misc/guc.c,v
retrieving revision 1.416
diff -c -r1.416 guc.c
*** src/backend/utils/misc/guc.c 3 Sep 2007 18:46:30 -0000 1.416
--- src/backend/utils/misc/guc.c 7 Sep 2007 12:49:17 -0000
***************
*** 6894,6899 ****
--- 6894,6909 ----
else if (source != PGC_S_OVERRIDE)
return false;
}
+
+ /*
+ * If we are setting READ ONLY mode and we are not in a transaction block
+ * then set the mode for the next transaction, as per SQL standard.
+ * We also allow the setting of the mode for the current transaction.
+ * This is historic behaviour and is harmless.
+ */
+ if (!IsTransactionBlock() && source == PGC_S_SESSION)
+ nextXactReadOnly = newval;
+
return true;
}
Index: src/include/access/xact.h
===================================================================
RCS file: /projects/cvsroot/pgsql/src/include/access/xact.h,v
retrieving revision 1.89
diff -c -r1.89 xact.h
*** src/include/access/xact.h 5 Sep 2007 18:10:48 -0000 1.89
--- src/include/access/xact.h 7 Sep 2007 12:49:18 -0000
***************
*** 23,28 ****
--- 23,29 ----
/*
* Xact isolation levels
*/
+ #define XACT_ISOLATION_NOT_SET -1
#define XACT_READ_UNCOMMITTED 0
#define XACT_READ_COMMITTED 1
#define XACT_REPEATABLE_READ 2
***************
*** 30,35 ****
--- 31,37 ----
extern int DefaultXactIsoLevel;
extern int XactIsoLevel;
+ extern int nextXactIsoLevel;
/*
* We only implement two isolation levels internally. This macro should
***************
*** 40,45 ****
--- 42,48 ----
/* Xact read-only state */
extern bool DefaultXactReadOnly;
extern bool XactReadOnly;
+ extern bool nextXactReadOnly;
/* Asynchronous commits */
extern bool XactSyncCommit;
---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster