Re: [PATCHES] SET TRANSACTION conformance to SQL:2003

2007-09-14 Thread Bruce Momjian

This has been saved for the 8.4 release:

http://momjian.postgresql.org/cgi-bin/pgpatches_hold

---

Simon Riggs wrote:
 Short patch to implement SQL standard behaviour of the SET TRANSACTION
 command. According to their publically accessible docs, I note that
 MySQL and Ingres correctly implement this behaviour, SQLServer does this
 also (and more), while Oracle and DB2 do so since they use implicit
 transaction blocks.
 
 Docs page updated.
 
 Manual tests OK. There isn't a test suite for SET TRANSACTION, so I
 haven't created one just for this. Behaviour is shown below; the SET
 command sets the session characteristics of the *next* transaction, when
 executed outside of a transaction block.
 
 postgres=# show transaction_read_only;
  transaction_read_only 
 ---
  off
 (1 row)
 
 postgres=# set transaction read only;
 SET
 postgres=# begin;
 BEGIN
 postgres=# show transaction_read_only;
  transaction_read_only 
 ---
  on
 (1 row)
 
 postgres=# commit;
 COMMIT
 
 
 -- 
   Simon Riggs
   2ndQuadrant  http://www.2ndQuadrant.com
 
 
 ---(end of broadcast)---
 TIP 3: Have you checked our extensive FAQ?
 
http://www.postgresql.org/docs/faq

-- 
  Bruce Momjian  [EMAIL PROTECTED]  http://momjian.us
  EnterpriseDB   http://www.enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +

---(end of broadcast)---
TIP 4: Have you searched our list archives?

   http://archives.postgresql.org


Re: [PATCHES] SET TRANSACTION conformance to SQL:2003

2007-09-07 Thread Simon Riggs
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 -	1.25
--- doc/src/sgml/ref/set_transaction.sgml	7 Sep 2007 12:49:05 -
***
*** 31,42 
  
para
 The commandSET TRANSACTION/command command sets the
!characteristics of the current transaction. It has no effect on any
!subsequent transactions.  commandSET SESSION
!CHARACTERISTICS/command sets the default transaction
!characteristics for subsequent transactions of a session.  These
!defaults can be overridden by commandSET TRANSACTION/command
!for an individual transaction.
/para
  
para
--- 31,43 
  
para
 The commandSET 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.  commandSET SESSION CHARACTERISTICS/command 
!sets the default transaction characteristics for subsequent 
!transactions of a session.  These defaults can be overridden by 
!commandSET TRANSACTION/command for an individual transaction.
/para
  
para
***
*** 112,120 
  
para
 If commandSET TRANSACTION/command is executed without a prior
!commandSTART TRANSACTION/command or  commandBEGIN/command,
!it will appear to have no effect, since the transaction will immediately
!end.
/para
  
para
--- 113,125 
  
para
 If commandSET TRANSACTION/command is executed without a prior
!commandSTART TRANSACTION/command or commandBEGIN/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 
!commandSTART TRANSACTION/command or commandBEGIN/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 -	1.248
--- src/backend/access/transam/xact.c	7 Sep 2007 12:49:09 -
***
*** 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 -	1.121
--- src/backend/commands/variable.c	7 Sep 2007 12:49:10 -
***
*** 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 -	1.416
---