Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9688939

Browse files
committed
Implement isolation levels read uncommitted and repeatable read as acting
like the next higher one.
1 parent 144a2ec commit 9688939

File tree

15 files changed

+156
-69
lines changed

15 files changed

+156
-69
lines changed

doc/src/sgml/mvcc.sgml

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/mvcc.sgml,v 2.40 2003/11/04 09:55:38 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/mvcc.sgml,v 2.41 2003/11/06 22:08:14 petere Exp $
33
-->
44

55
<chapter id="mvcc">
@@ -206,8 +206,25 @@ $Header: /cvsroot/pgsql/doc/src/sgml/mvcc.sgml,v 2.40 2003/11/04 09:55:38 petere
206206
</table>
207207

208208
<para>
209-
<productname>PostgreSQL</productname>
210-
offers the Read Committed and Serializable isolation levels.
209+
In <productname>PostgreSQL</productname>, you can use all four
210+
possible transaction isolation levels. Internally, there are only
211+
two distinct isolation levels, which correspond to the levels Read
212+
Committed and Serializable. When you select the level Read
213+
Uncommitted you really get Read Committed, and when you select
214+
Repeatable Read you really get Serializable, so the actual
215+
isolation level may be stricter than what you select. This is
216+
permitted by the SQL standard: the four isolation levels only
217+
define which phenomena must not happen, they do not define which
218+
phenomena must happen. The reason that PostgreSQL only provides
219+
two isolation levels is that this is the only sensible way to map
220+
the isolation levels to the multiversion concurrency control
221+
architecture. The behavior of the available isolation levels is
222+
detailed in the following subsections.
223+
</para>
224+
225+
<para>
226+
To set the transaction isolation level of a transaction, use the
227+
command <xref linkend="sql-set-transaction">.
211228
</para>
212229

213230
<sect2 id="xact-read-committed">

doc/src/sgml/ref/set_transaction.sgml

+17-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/ref/set_transaction.sgml,v 1.17 2003/09/11 21:42:20 momjian Exp $ -->
1+
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/ref/set_transaction.sgml,v 1.18 2003/11/06 22:08:14 petere Exp $ -->
22
<refentry id="SQL-SET-TRANSACTION">
33
<refmeta>
44
<refentrytitle id="SQL-SET-TRANSACTION-TITLE">SET TRANSACTION</refentrytitle>
@@ -17,9 +17,12 @@
1717
<refsynopsisdiv>
1818
<synopsis>
1919
SET TRANSACTION
20-
[ ISOLATION LEVEL { READ COMMITTED | SERIALIZABLE } ] [ READ WRITE | READ ONLY ]
20+
[ ISOLATION LEVEL { READ UNCOMMITTED | READ COMMITTED | REPEATABLE READ | SERIALIZABLE } ]
21+
[ READ WRITE | READ ONLY ]
22+
2123
SET SESSION CHARACTERISTICS AS TRANSACTION
22-
[ ISOLATION LEVEL { READ COMMITTED | SERIALIZABLE } ] [ READ WRITE | READ ONLY ]
24+
[ ISOLATION LEVEL { READ UNCOMMITTED | READ COMMITTED | REPEATABLE READ | SERIALIZABLE } ]
25+
[ READ WRITE | READ ONLY ]
2326
</synopsis>
2427
</refsynopsisdiv>
2528

@@ -76,8 +79,11 @@ SET SESSION CHARACTERISTICS AS TRANSACTION
7679
</varlistentry>
7780
</variablelist>
7881

79-
The transaction isolation level cannot be set after the first query
80-
or data-modification statement (<command>SELECT</command>,
82+
The level <literal>READ UNCOMMITTED</literal> is mapped to
83+
<literal>READ COMMITTED</literal>, the level <literal>REPEATABLE
84+
READ</literal> is mapped to <literal>SERIALIZABLE</literal>, The
85+
transaction isolation level cannot be set after the first query or
86+
data-modification statement (<command>SELECT</command>,
8187
<command>INSERT</command>, <command>DELETE</command>,
8288
<command>UPDATE</command>, <command>FETCH</command>,
8389
<command>COPY</command>) of a transaction has been executed. See
@@ -122,13 +128,12 @@ SET default_transaction_isolation = '<replaceable>value</replaceable>'
122128
<para>
123129
Both commands are defined in the <acronym>SQL</acronym> standard.
124130
<literal>SERIALIZABLE</literal> is the default transaction
125-
isolation level in the standard; in <productname>PostgreSQL</productname> the default is
126-
ordinarily <literal>READ COMMITTED</literal>, but you can change it as
127-
described above. <productname>PostgreSQL</productname> does not
128-
provide the isolation levels <literal>READ UNCOMMITTED</literal>
129-
and <literal>REPEATABLE READ</literal>. Because of multiversion
130-
concurrency control, the <literal>SERIALIZABLE</literal> level is
131-
not truly serializable. See <xref linkend="mvcc"> for details.
131+
isolation level in the standard; in
132+
<productname>PostgreSQL</productname> the default is ordinarily
133+
<literal>READ COMMITTED</literal>, but you can change it as
134+
described above. Because of multiversion concurrency control, the
135+
<literal>SERIALIZABLE</literal> level is not truly
136+
serializable. See <xref linkend="mvcc"> for details.
132137
</para>
133138

134139
<para>

doc/src/sgml/ref/start_transaction.sgml

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/start_transaction.sgml,v 1.7 2003/09/09 18:28:53 tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/start_transaction.sgml,v 1.8 2003/11/06 22:08:14 petere Exp $
33
PostgreSQL documentation
44
-->
55

@@ -20,7 +20,9 @@ PostgreSQL documentation
2020

2121
<refsynopsisdiv>
2222
<synopsis>
23-
START TRANSACTION [ ISOLATION LEVEL { READ COMMITTED | SERIALIZABLE } ] [ READ WRITE | READ ONLY ]
23+
START TRANSACTION
24+
[ ISOLATION LEVEL { READ UNCOMMITTED | READ COMMITTED | REPEATABLE READ | SERIALIZABLE } ]
25+
[ READ WRITE | READ ONLY ]
2426
</synopsis>
2527
</refsynopsisdiv>
2628

doc/src/sgml/runtime.sgml

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.216 2003/11/04 09:55:38 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.217 2003/11/06 22:08:14 petere Exp $
33
-->
44

55
<Chapter Id="runtime">
@@ -2043,10 +2043,12 @@ SET ENABLE_SEQSCAN TO OFF;
20432043
<term><varname>default_transaction_isolation</varname> (<type>string</type>)</term>
20442044
<listitem>
20452045
<para>
2046-
Each SQL transaction has an isolation level, which can be either
2047-
<quote>read committed</quote> or <quote>serializable</quote>.
2048-
This parameter controls the default isolation level of each new
2049-
transaction. The default is <quote>read committed</quote>.
2046+
Each SQL transaction has an isolation level, which can be
2047+
either <quote>read uncommitted</quote>, <quote>read
2048+
committed</quote>, <quote>repeatable read</quote>, or
2049+
<quote>serializable</quote>. This parameter controls the
2050+
default isolation level of each new transaction. The default
2051+
is <quote>read committed</quote>.
20502052
</para>
20512053

20522054
<para>

src/backend/catalog/sql_features.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,10 @@ F051 Basic date and time 07 LOCALTIME YES
156156
F051 Basic date and time 08 LOCALTIMESTAMP YES
157157
F052 Intervals and datetime arithmetic YES
158158
F081 UNION and EXCEPT in views YES
159-
F111 Isolation levels other than SERIALIZABLE NO
160-
F111 Isolation levels other than SERIALIZABLE 01 READ UNCOMMITTED isolation level NO
159+
F111 Isolation levels other than SERIALIZABLE YES
160+
F111 Isolation levels other than SERIALIZABLE 01 READ UNCOMMITTED isolation level YES behaves like READ COMMITTED
161161
F111 Isolation levels other than SERIALIZABLE 02 READ COMMITTED isolation level YES
162-
F111 Isolation levels other than SERIALIZABLE 03 REPEATABLE READ isolation level NO
162+
F111 Isolation levels other than SERIALIZABLE 03 REPEATABLE READ isolation level YES behaves like SERIALIZABLE
163163
F121 Basic diagnostics management NO
164164
F121 Basic diagnostics management 01 GET DIAGNOSTICS statement NO
165165
F121 Basic diagnostics management 02 SET TRANSACTION statement: DIAGNOSTICS SIZE clause NO

src/backend/commands/trigger.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.159 2003/10/02 06:34:03 petere Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.160 2003/11/06 22:08:14 petere Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -1576,7 +1576,7 @@ ltrmark:;
15761576

15771577
case HeapTupleUpdated:
15781578
ReleaseBuffer(buffer);
1579-
if (XactIsoLevel == XACT_SERIALIZABLE)
1579+
if (IsXactIsoLevelSerializable)
15801580
ereport(ERROR,
15811581
(errcode(ERRCODE_T_R_SERIALIZATION_FAILURE),
15821582
errmsg("could not serialize access due to concurrent update")));

src/backend/commands/variable.c

+24-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.88 2003/09/25 06:57:59 petere Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.89 2003/11/06 22:08:14 petere Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -640,11 +640,21 @@ assign_XactIsoLevel(const char *value, bool doit, bool interactive)
640640
if (doit)
641641
XactIsoLevel = XACT_SERIALIZABLE;
642642
}
643+
else if (strcmp(value, "repeatable read") == 0)
644+
{
645+
if (doit)
646+
XactIsoLevel = XACT_REPEATABLE_READ;
647+
}
643648
else if (strcmp(value, "read committed") == 0)
644649
{
645650
if (doit)
646651
XactIsoLevel = XACT_READ_COMMITTED;
647652
}
653+
else if (strcmp(value, "read uncommitted") == 0)
654+
{
655+
if (doit)
656+
XactIsoLevel = XACT_READ_UNCOMMITTED;
657+
}
648658
else if (strcmp(value, "default") == 0)
649659
{
650660
if (doit)
@@ -659,10 +669,19 @@ assign_XactIsoLevel(const char *value, bool doit, bool interactive)
659669
const char *
660670
show_XactIsoLevel(void)
661671
{
662-
if (XactIsoLevel == XACT_SERIALIZABLE)
663-
return "serializable";
664-
else
665-
return "read committed";
672+
switch (XactIsoLevel)
673+
{
674+
case XACT_READ_UNCOMMITTED:
675+
return "read uncommitted";
676+
case XACT_READ_COMMITTED:
677+
return "read committed";
678+
case XACT_REPEATABLE_READ:
679+
return "repeatable read";
680+
case XACT_SERIALIZABLE:
681+
return "serializable";
682+
default:
683+
return "bogus";
684+
}
666685
}
667686

668687

src/backend/executor/execMain.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*
2727
*
2828
* IDENTIFICATION
29-
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.220 2003/10/01 21:30:52 tgl Exp $
29+
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.221 2003/11/06 22:08:14 petere Exp $
3030
*
3131
*-------------------------------------------------------------------------
3232
*/
@@ -1139,7 +1139,7 @@ lnext: ;
11391139
break;
11401140

11411141
case HeapTupleUpdated:
1142-
if (XactIsoLevel == XACT_SERIALIZABLE)
1142+
if (IsXactIsoLevelSerializable)
11431143
ereport(ERROR,
11441144
(errcode(ERRCODE_T_R_SERIALIZATION_FAILURE),
11451145
errmsg("could not serialize access due to concurrent update")));
@@ -1440,7 +1440,7 @@ ldelete:;
14401440
break;
14411441

14421442
case HeapTupleUpdated:
1443-
if (XactIsoLevel == XACT_SERIALIZABLE)
1443+
if (IsXactIsoLevelSerializable)
14441444
ereport(ERROR,
14451445
(errcode(ERRCODE_T_R_SERIALIZATION_FAILURE),
14461446
errmsg("could not serialize access due to concurrent update")));
@@ -1576,7 +1576,7 @@ lreplace:;
15761576
break;
15771577

15781578
case HeapTupleUpdated:
1579-
if (XactIsoLevel == XACT_SERIALIZABLE)
1579+
if (IsXactIsoLevelSerializable)
15801580
ereport(ERROR,
15811581
(errcode(ERRCODE_T_R_SERIALIZATION_FAILURE),
15821582
errmsg("could not serialize access due to concurrent update")));

src/backend/parser/gram.y

+9-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.436 2003/10/02 06:34:04 petere Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.437 2003/11/06 22:08:14 petere Exp $
1515
*
1616
* HISTORY
1717
* AUTHOR DATE MAJOR EVENT
@@ -342,7 +342,7 @@ static void doNegateFloat(Value *v);
342342

343343
DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
344344
DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS
345-
DESC DISTINCT DO DOMAIN_P DOUBLE_P DROP
345+
DESC DISTINCT DO DOMAIN_P DOUBLE_P DROP
346346

347347
EACH ELSE ENCODING ENCRYPTED END_P ESCAPE EXCEPT EXCLUDING
348348
EXCLUSIVE EXECUTE EXISTS EXPLAIN EXTERNAL EXTRACT
@@ -380,7 +380,7 @@ static void doNegateFloat(Value *v);
380380
PRECISION PRESERVE PREPARE PRIMARY
381381
PRIOR PRIVILEGES PROCEDURAL PROCEDURE
382382

383-
READ REAL RECHECK REFERENCES REINDEX RELATIVE_P RENAME REPLACE
383+
READ REAL RECHECK REFERENCES REINDEX RELATIVE_P RENAME REPEATABLE REPLACE
384384
RESET RESTART RESTRICT RETURNS REVOKE RIGHT ROLLBACK ROW ROWS
385385
RULE
386386

@@ -393,7 +393,7 @@ static void doNegateFloat(Value *v);
393393
TO TOAST TRAILING TRANSACTION TREAT TRIGGER TRIM TRUE_P
394394
TRUNCATE TRUSTED TYPE_P
395395

396-
UNENCRYPTED UNION UNIQUE UNKNOWN UNLISTEN UNTIL
396+
UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN UNLISTEN UNTIL
397397
UPDATE USAGE USER USING
398398

399399
VACUUM VALID VALIDATOR VALUES VARCHAR VARYING
@@ -922,7 +922,9 @@ var_value: opt_boolean
922922
{ $$ = makeAConst($1); }
923923
;
924924

925-
iso_level: READ COMMITTED { $$ = "read committed"; }
925+
iso_level: READ UNCOMMITTED { $$ = "read uncommitted"; }
926+
| READ COMMITTED { $$ = "read committed"; }
927+
| REPEATABLE READ { $$ = "repeatable read"; }
926928
| SERIALIZABLE { $$ = "serializable"; }
927929
;
928930

@@ -7407,6 +7409,7 @@ unreserved_keyword:
74077409
| REINDEX
74087410
| RELATIVE_P
74097411
| RENAME
7412+
| REPEATABLE
74107413
| REPLACE
74117414
| RESET
74127415
| RESTART
@@ -7445,6 +7448,7 @@ unreserved_keyword:
74457448
| TRUNCATE
74467449
| TRUSTED
74477450
| TYPE_P
7451+
| UNCOMMITTED
74487452
| UNENCRYPTED
74497453
| UNKNOWN
74507454
| UNLISTEN

src/backend/parser/keywords.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.141 2003/08/04 02:40:01 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.142 2003/11/06 22:08:15 petere Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -251,6 +251,7 @@ static const ScanKeyword ScanKeywords[] = {
251251
{"reindex", REINDEX},
252252
{"relative", RELATIVE_P},
253253
{"rename", RENAME},
254+
{"repeatable", REPEATABLE},
254255
{"replace", REPLACE},
255256
{"reset", RESET},
256257
{"restart", RESTART},
@@ -307,6 +308,7 @@ static const ScanKeyword ScanKeywords[] = {
307308
{"truncate", TRUNCATE},
308309
{"trusted", TRUSTED},
309310
{"type", TYPE_P},
311+
{"uncommitted", UNCOMMITTED},
310312
{"unencrypted", UNENCRYPTED},
311313
{"union", UNION},
312314
{"unique", UNIQUE},

src/backend/utils/adt/ri_triggers.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*
1818
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
1919
*
20-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ri_triggers.c,v 1.63 2003/10/31 03:58:20 wieck Exp $
20+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ri_triggers.c,v 1.64 2003/11/06 22:08:15 petere Exp $
2121
*
2222
* ----------
2323
*/
@@ -3073,7 +3073,7 @@ ri_PerformCheck(RI_QueryKey *qkey, void *qplan,
30733073
* rows under current snapshot that wouldn't be visible per the
30743074
* transaction snapshot).
30753075
*/
3076-
if (XactIsoLevel == XACT_SERIALIZABLE)
3076+
if (IsXactIsoLevelSerializable)
30773077
{
30783078
useCurrentSnapshot = detectNewRows;
30793079
}

0 commit comments

Comments
 (0)