The attached patch implements START TRANSACTION, per SQL99. The
functionality of the command is basically identical to that of BEGIN; it just accepts a few extra options (only one of which PostgreSQL currently implements), and is standards-compliant. The patch includes a simple regression test and documentation. [ Regression tests removed, per Peter.] Neil Conway
This commit is contained in:
parent
fecc04f95a
commit
19e0e35bcd
10 changed files with 74 additions and 49 deletions
|
@ -1,5 +1,5 @@
|
||||||
<!--
|
<!--
|
||||||
$Header: /cvsroot/pgsql/doc/src/sgml/ref/allfiles.sgml,v 1.43 2002/07/29 22:14:10 tgl Exp $
|
$Header: /cvsroot/pgsql/doc/src/sgml/ref/allfiles.sgml,v 1.44 2002/08/04 04:31:44 momjian Exp $
|
||||||
PostgreSQL documentation
|
PostgreSQL documentation
|
||||||
Complete list of usable sgml source files in this directory.
|
Complete list of usable sgml source files in this directory.
|
||||||
-->
|
-->
|
||||||
|
@ -113,6 +113,7 @@ Complete list of usable sgml source files in this directory.
|
||||||
<!entity setSessionAuth system "set_session_auth.sgml">
|
<!entity setSessionAuth system "set_session_auth.sgml">
|
||||||
<!entity setTransaction system "set_transaction.sgml">
|
<!entity setTransaction system "set_transaction.sgml">
|
||||||
<!entity show system "show.sgml">
|
<!entity show system "show.sgml">
|
||||||
|
<!entity startTransaction system "start_transaction.sgml">
|
||||||
<!entity truncate system "truncate.sgml">
|
<!entity truncate system "truncate.sgml">
|
||||||
<!entity unlisten system "unlisten.sgml">
|
<!entity unlisten system "unlisten.sgml">
|
||||||
<!entity update system "update.sgml">
|
<!entity update system "update.sgml">
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<!--
|
<!--
|
||||||
$Header: /cvsroot/pgsql/doc/src/sgml/ref/begin.sgml,v 1.17 2002/04/21 19:02:39 thomas Exp $
|
$Header: /cvsroot/pgsql/doc/src/sgml/ref/begin.sgml,v 1.18 2002/08/04 04:31:44 momjian Exp $
|
||||||
PostgreSQL documentation
|
PostgreSQL documentation
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/ref/set_transaction.sgml,v 1.8 2002/01/20 22:19:57 petere Exp $ -->
|
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/ref/set_transaction.sgml,v 1.9 2002/08/04 04:31:44 momjian Exp $ -->
|
||||||
<refentry id="SQL-SET-TRANSACTION">
|
<refentry id="SQL-SET-TRANSACTION">
|
||||||
<docinfo>
|
<docinfo>
|
||||||
<date>2000-11-24</date>
|
<date>2000-11-24</date>
|
||||||
|
@ -97,11 +97,11 @@ SET default_transaction_isolation = '<replaceable>value</replaceable>'
|
||||||
<title>SQL92, SQL99</title>
|
<title>SQL92, SQL99</title>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
SERIALIZABLE is the default level in <acronym>SQL</acronym>.
|
<option>SERIALIZABLE</option> is the default level in
|
||||||
<productname>PostgreSQL</productname> does not provide the
|
<acronym>SQL</acronym>. <productname>PostgreSQL</productname> does
|
||||||
isolation levels <option>READ UNCOMMITTED</option>
|
not provide the isolation levels <option>READ UNCOMMITTED</option>
|
||||||
and <option>REPEATABLE READ</option>. Because
|
and <option>REPEATABLE READ</option>. Because of multiversion
|
||||||
of multiversion concurrency control, the serializable level is not
|
concurrency control, the <option>SERIALIZABLE</option> level is not
|
||||||
truly serializable. See the <citetitle>User's Guide</citetitle> for
|
truly serializable. See the <citetitle>User's Guide</citetitle> for
|
||||||
details.
|
details.
|
||||||
</para>
|
</para>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<!-- reference.sgml
|
<!-- reference.sgml
|
||||||
$Header: /cvsroot/pgsql/doc/src/sgml/reference.sgml,v 1.32 2002/07/29 22:14:10 tgl Exp $
|
$Header: /cvsroot/pgsql/doc/src/sgml/reference.sgml,v 1.33 2002/08/04 04:31:44 momjian Exp $
|
||||||
|
|
||||||
PostgreSQL Reference Manual
|
PostgreSQL Reference Manual
|
||||||
-->
|
-->
|
||||||
|
@ -122,6 +122,7 @@ PostgreSQL Reference Manual
|
||||||
&setSessionAuth;
|
&setSessionAuth;
|
||||||
&setTransaction;
|
&setTransaction;
|
||||||
&show;
|
&show;
|
||||||
|
&startTransaction;
|
||||||
&truncate;
|
&truncate;
|
||||||
&unlisten;
|
&unlisten;
|
||||||
&update;
|
&update;
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.198 2002/07/29 22:14:10 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.199 2002/08/04 04:31:44 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -2226,6 +2226,7 @@ _copyTransactionStmt(TransactionStmt *from)
|
||||||
TransactionStmt *newnode = makeNode(TransactionStmt);
|
TransactionStmt *newnode = makeNode(TransactionStmt);
|
||||||
|
|
||||||
newnode->command = from->command;
|
newnode->command = from->command;
|
||||||
|
Node_Copy(from, newnode, options);
|
||||||
|
|
||||||
return newnode;
|
return newnode;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.145 2002/07/29 22:14:10 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.146 2002/08/04 04:31:44 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -1055,6 +1055,8 @@ _equalTransactionStmt(TransactionStmt *a, TransactionStmt *b)
|
||||||
{
|
{
|
||||||
if (a->command != b->command)
|
if (a->command != b->command)
|
||||||
return false;
|
return false;
|
||||||
|
if (!equal(a->options, b->options))
|
||||||
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.352 2002/07/31 17:19:51 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.353 2002/08/04 04:31:44 momjian Exp $
|
||||||
*
|
*
|
||||||
* HISTORY
|
* HISTORY
|
||||||
* AUTHOR DATE MAJOR EVENT
|
* AUTHOR DATE MAJOR EVENT
|
||||||
|
@ -195,7 +195,7 @@ static void doNegateFloat(Value *v);
|
||||||
|
|
||||||
%type <str> opt_id, all_Op, MathOp, opt_name, SpecialRuleRelation
|
%type <str> opt_id, all_Op, MathOp, opt_name, SpecialRuleRelation
|
||||||
|
|
||||||
%type <str> opt_level, opt_encoding
|
%type <str> iso_level, opt_encoding
|
||||||
%type <node> grantee
|
%type <node> grantee
|
||||||
%type <list> grantee_list
|
%type <list> grantee_list
|
||||||
%type <ival> privilege
|
%type <ival> privilege
|
||||||
|
@ -218,7 +218,7 @@ static void doNegateFloat(Value *v);
|
||||||
target_list, update_target_list, insert_column_list,
|
target_list, update_target_list, insert_column_list,
|
||||||
insert_target_list, def_list, opt_indirection,
|
insert_target_list, def_list, opt_indirection,
|
||||||
group_clause, TriggerFuncArgs, select_limit,
|
group_clause, TriggerFuncArgs, select_limit,
|
||||||
opt_select_limit, opclass_item_list
|
opt_select_limit, opclass_item_list, trans_options
|
||||||
|
|
||||||
%type <range> into_clause, OptTempTableName
|
%type <range> into_clause, OptTempTableName
|
||||||
|
|
||||||
|
@ -847,14 +847,14 @@ set_rest: ColId TO var_list_or_default
|
||||||
n->args = makeList1($3);
|
n->args = makeList1($3);
|
||||||
$$ = n;
|
$$ = n;
|
||||||
}
|
}
|
||||||
| TRANSACTION ISOLATION LEVEL opt_level opt_mode
|
| TRANSACTION ISOLATION LEVEL iso_level opt_mode
|
||||||
{
|
{
|
||||||
VariableSetStmt *n = makeNode(VariableSetStmt);
|
VariableSetStmt *n = makeNode(VariableSetStmt);
|
||||||
n->name = "TRANSACTION ISOLATION LEVEL";
|
n->name = "TRANSACTION ISOLATION LEVEL";
|
||||||
n->args = makeList1(makeStringConst($4, NULL));
|
n->args = makeList1(makeStringConst($4, NULL));
|
||||||
$$ = n;
|
$$ = n;
|
||||||
}
|
}
|
||||||
| SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL opt_level
|
| SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL iso_level
|
||||||
{
|
{
|
||||||
VariableSetStmt *n = makeNode(VariableSetStmt);
|
VariableSetStmt *n = makeNode(VariableSetStmt);
|
||||||
n->name = "default_transaction_isolation";
|
n->name = "default_transaction_isolation";
|
||||||
|
@ -902,7 +902,7 @@ var_value: opt_boolean
|
||||||
{ $$ = makeAConst($1); }
|
{ $$ = makeAConst($1); }
|
||||||
;
|
;
|
||||||
|
|
||||||
opt_level: READ COMMITTED { $$ = "read committed"; }
|
iso_level: READ COMMITTED { $$ = "read committed"; }
|
||||||
| SERIALIZABLE { $$ = "serializable"; }
|
| SERIALIZABLE { $$ = "serializable"; }
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -3445,44 +3445,49 @@ TransactionStmt:
|
||||||
{
|
{
|
||||||
TransactionStmt *n = makeNode(TransactionStmt);
|
TransactionStmt *n = makeNode(TransactionStmt);
|
||||||
n->command = ROLLBACK;
|
n->command = ROLLBACK;
|
||||||
|
n->options = NIL;
|
||||||
$$ = (Node *)n;
|
$$ = (Node *)n;
|
||||||
}
|
}
|
||||||
| BEGIN_TRANS opt_trans
|
| BEGIN_TRANS opt_trans
|
||||||
{
|
{
|
||||||
TransactionStmt *n = makeNode(TransactionStmt);
|
TransactionStmt *n = makeNode(TransactionStmt);
|
||||||
n->command = BEGIN_TRANS;
|
n->command = BEGIN_TRANS;
|
||||||
|
n->options = NIL;
|
||||||
|
$$ = (Node *)n;
|
||||||
|
}
|
||||||
|
| START TRANSACTION trans_options
|
||||||
|
{
|
||||||
|
TransactionStmt *n = makeNode(TransactionStmt);
|
||||||
|
n->command = START;
|
||||||
|
n->options = $3;
|
||||||
$$ = (Node *)n;
|
$$ = (Node *)n;
|
||||||
}
|
}
|
||||||
| COMMIT opt_trans
|
| COMMIT opt_trans
|
||||||
{
|
{
|
||||||
TransactionStmt *n = makeNode(TransactionStmt);
|
TransactionStmt *n = makeNode(TransactionStmt);
|
||||||
n->command = COMMIT;
|
n->command = COMMIT;
|
||||||
$$ = (Node *)n;
|
n->options = NIL;
|
||||||
}
|
|
||||||
| COMMIT opt_trans opt_chain
|
|
||||||
{
|
|
||||||
TransactionStmt *n = makeNode(TransactionStmt);
|
|
||||||
n->command = COMMIT;
|
|
||||||
$$ = (Node *)n;
|
$$ = (Node *)n;
|
||||||
}
|
}
|
||||||
| END_TRANS opt_trans
|
| END_TRANS opt_trans
|
||||||
{
|
{
|
||||||
TransactionStmt *n = makeNode(TransactionStmt);
|
TransactionStmt *n = makeNode(TransactionStmt);
|
||||||
n->command = COMMIT;
|
n->command = COMMIT;
|
||||||
|
n->options = NIL;
|
||||||
$$ = (Node *)n;
|
$$ = (Node *)n;
|
||||||
}
|
}
|
||||||
| ROLLBACK opt_trans
|
| ROLLBACK opt_trans
|
||||||
{
|
{
|
||||||
TransactionStmt *n = makeNode(TransactionStmt);
|
TransactionStmt *n = makeNode(TransactionStmt);
|
||||||
n->command = ROLLBACK;
|
n->command = ROLLBACK;
|
||||||
|
n->options = NIL;
|
||||||
$$ = (Node *)n;
|
$$ = (Node *)n;
|
||||||
}
|
}
|
||||||
| ROLLBACK opt_trans opt_chain
|
;
|
||||||
{
|
|
||||||
TransactionStmt *n = makeNode(TransactionStmt);
|
trans_options: ISOLATION LEVEL iso_level
|
||||||
n->command = ROLLBACK;
|
{ $$ = makeList1(makeStringConst($3, NULL)); }
|
||||||
$$ = (Node *)n;
|
| /* EMPTY */ { $$ = NIL; }
|
||||||
}
|
|
||||||
;
|
;
|
||||||
|
|
||||||
opt_trans: WORK {}
|
opt_trans: WORK {}
|
||||||
|
@ -3490,22 +3495,10 @@ opt_trans: WORK {}
|
||||||
| /*EMPTY*/ {}
|
| /*EMPTY*/ {}
|
||||||
;
|
;
|
||||||
|
|
||||||
opt_chain: AND NO CHAIN {}
|
|
||||||
| AND CHAIN
|
|
||||||
{
|
|
||||||
/* SQL99 asks that conforming dbs reject AND CHAIN
|
|
||||||
* if they don't support it. So we can't just ignore it.
|
|
||||||
* - thomas 2000-08-06
|
|
||||||
*/
|
|
||||||
elog(ERROR, "COMMIT/AND CHAIN not yet supported");
|
|
||||||
}
|
|
||||||
;
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
*
|
*
|
||||||
* QUERY:
|
* QUERY:
|
||||||
* define view <viewname> '('target-list ')' [where <quals> ]
|
* create view <viewname> '('target-list ')' AS <query>
|
||||||
*
|
*
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.276 2002/07/30 16:55:45 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.277 2002/08/04 04:31:44 momjian Exp $
|
||||||
*
|
*
|
||||||
* NOTES
|
* NOTES
|
||||||
* this is the "main" module of the postgres backend and
|
* this is the "main" module of the postgres backend and
|
||||||
|
@ -1693,7 +1693,7 @@ PostgresMain(int argc, char *argv[], const char *username)
|
||||||
if (!IsUnderPostmaster)
|
if (!IsUnderPostmaster)
|
||||||
{
|
{
|
||||||
puts("\nPOSTGRES backend interactive interface ");
|
puts("\nPOSTGRES backend interactive interface ");
|
||||||
puts("$Revision: 1.276 $ $Date: 2002/07/30 16:55:45 $\n");
|
puts("$Revision: 1.277 $ $Date: 2002/08/04 04:31:44 $\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -2160,6 +2160,10 @@ CreateCommandTag(Node *parsetree)
|
||||||
tag = "BEGIN";
|
tag = "BEGIN";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case START:
|
||||||
|
tag = "START TRANSACTION";
|
||||||
|
break;
|
||||||
|
|
||||||
case COMMIT:
|
case COMMIT:
|
||||||
tag = "COMMIT";
|
tag = "COMMIT";
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.167 2002/07/30 16:55:45 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.168 2002/08/04 04:31:44 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -205,6 +205,28 @@ ProcessUtility(Node *parsetree,
|
||||||
BeginTransactionBlock();
|
BeginTransactionBlock();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* START TRANSACTION, as defined by SQL99: Identical to BEGIN,
|
||||||
|
* except that it takes a few additional options.
|
||||||
|
*/
|
||||||
|
case START:
|
||||||
|
{
|
||||||
|
BeginTransactionBlock();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Currently, the only option that can be set is
|
||||||
|
* the transaction isolation level by START
|
||||||
|
* TRANSACTION.
|
||||||
|
*/
|
||||||
|
if (stmt->options)
|
||||||
|
{
|
||||||
|
SetPGVariable("TRANSACTION ISOLATION LEVEL",
|
||||||
|
stmt->options,
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case COMMIT:
|
case COMMIT:
|
||||||
EndTransactionBlock();
|
EndTransactionBlock();
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Id: parsenodes.h,v 1.196 2002/07/30 16:55:45 momjian Exp $
|
* $Id: parsenodes.h,v 1.197 2002/08/04 04:31:44 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -1387,13 +1387,14 @@ typedef struct UnlistenStmt
|
||||||
} UnlistenStmt;
|
} UnlistenStmt;
|
||||||
|
|
||||||
/* ----------------------
|
/* ----------------------
|
||||||
* {Begin|Abort|End} Transaction Statement
|
* {Begin|Commit|Rollback} Transaction Statement
|
||||||
* ----------------------
|
* ----------------------
|
||||||
*/
|
*/
|
||||||
typedef struct TransactionStmt
|
typedef struct TransactionStmt
|
||||||
{
|
{
|
||||||
NodeTag type;
|
NodeTag type;
|
||||||
int command; /* BEGIN|END|ABORT */
|
int command; /* BEGIN_TRANS|START|COMMIT|ROLLBACK */
|
||||||
|
List *options;
|
||||||
} TransactionStmt;
|
} TransactionStmt;
|
||||||
|
|
||||||
/* ----------------------
|
/* ----------------------
|
||||||
|
|
Loading…
Reference in a new issue