Skip to content

Commit fb4c5d2

Browse files
committed
Code cleanup for assign_XactIsoLevel.
The new coding avoids a spurious debug message when a transaction that has changed the isolation level has been rolled back. It also allows the property to be freely changed to the current value within a subtransaction. Kevin Grittner, with one small change by me.
1 parent cb38ab6 commit fb4c5d2

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

src/backend/commands/variable.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -546,27 +546,27 @@ show_log_timezone(void)
546546
/*
547547
* SET TRANSACTION ISOLATION LEVEL
548548
*/
549-
550549
const char *
551550
assign_XactIsoLevel(const char *value, bool doit, GucSource source)
552551
{
553-
if (FirstSnapshotSet)
552+
/* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
553+
if (source != PGC_S_OVERRIDE)
554554
{
555-
ereport(GUC_complaint_elevel(source),
556-
(errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
557-
errmsg("SET TRANSACTION ISOLATION LEVEL must be called before any query")));
558-
/* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
559-
if (source != PGC_S_OVERRIDE)
555+
if (FirstSnapshotSet)
556+
{
557+
ereport(GUC_complaint_elevel(source),
558+
(errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
559+
errmsg("SET TRANSACTION ISOLATION LEVEL must be called before any query")));
560560
return NULL;
561-
}
562-
else if (IsSubTransaction())
563-
{
564-
ereport(GUC_complaint_elevel(source),
565-
(errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
566-
errmsg("SET TRANSACTION ISOLATION LEVEL must not be called in a subtransaction")));
567-
/* source == PGC_S_OVERRIDE means do it anyway, eg at xact abort */
568-
if (source != PGC_S_OVERRIDE)
561+
}
562+
/* We ignore a subtransaction setting it to the existing value. */
563+
if (IsSubTransaction() && strcmp(value, XactIsoLevel_string) != 0)
564+
{
565+
ereport(GUC_complaint_elevel(source),
566+
(errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
567+
errmsg("SET TRANSACTION ISOLATION LEVEL must not be called in a subtransaction")));
569568
return NULL;
569+
}
570570
}
571571

572572
if (strcmp(value, "serializable") == 0)

src/backend/utils/misc/guc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,6 @@ static int server_version_num;
425425
static char *timezone_string;
426426
static char *log_timezone_string;
427427
static char *timezone_abbreviations_string;
428-
static char *XactIsoLevel_string;
429428
static char *custom_variable_classes;
430429
static int max_function_args;
431430
static int max_index_keys;
@@ -440,6 +439,7 @@ static int effective_io_concurrency;
440439
/* should be static, but commands/variable.c needs to get at these */
441440
char *role_string;
442441
char *session_authorization_string;
442+
char *XactIsoLevel_string;
443443

444444

445445
/*

src/include/utils/guc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ extern char *ConfigFileName;
201201
extern char *HbaFileName;
202202
extern char *IdentFileName;
203203
extern char *external_pid_file;
204+
extern char *XactIsoLevel_string;
204205

205206
extern char *application_name;
206207

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy