Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support repeatable read and serializable isolation level #1695

Merged
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
24b2488
fix: add support to handle reapeatable read isolation level as snapshot
Aug 8, 2023
7f9fb25
fix: update error message for SET repeatable read in test output files
Aug 8, 2023
fbde49d
fix: test out error message for set isolation level
Aug 8, 2023
d110850
fix: handle serializable isolation level as snapshot isolation level …
Aug 10, 2023
1df807a
test: add test cases for concurrent update/delete
Aug 11, 2023
8cc852d
test: add JDBC tests for setting isolation levels
Aug 11, 2023
33ba846
test: add jdbc test for setting guc on database/session level
Aug 14, 2023
a987487
fix: remove some concurrent isolation tests
Aug 14, 2023
0e9e058
Empty-Commit
Aug 15, 2023
4e58f32
fix: change apping for serializable level
Aug 17, 2023
086796f
Empty commit
tanscorpio7 Aug 17, 2023
f7fddc5
refactor: change guc name
tanscorpio7 Aug 21, 2023
e9a3d93
refactor: change error message
tanscorpio7 Aug 21, 2023
b14a5d7
refactor: change description for guc
tanscorpio7 Aug 21, 2023
5d637ad
fix: separate gucs for isolation levels
tanscorpio7 Aug 22, 2023
142e467
fix: add test for phantomn read in repeatable read
tanscorpio7 Aug 22, 2023
6fd9432
fix: fix python tests for serializable
tanscorpio7 Aug 23, 2023
0d9107c
refactor
tanscorpio7 Aug 24, 2023
4757a79
empty commit to add signoff in PR
tanscorpio7 Aug 25, 2023
8fb83d2
fix: add dotnet test for isolation levels
tanscorpio7 Aug 28, 2023
106a5cd
Merge branch 'BABEL_3_X_DEV' into BABEL_4146
tanscorpio7 Oct 19, 2023
c18a168
refactor guc names
tanscorpio7 Oct 19, 2023
789236c
update guc name in tests
tanscorpio7 Oct 19, 2023
57f84b9
retrigger tests
tanscorpio7 Oct 19, 2023
52a5023
retrigger tests
tanscorpio7 Oct 19, 2023
9a1360d
remove 4145 from parallel worker
tanscorpio7 Oct 19, 2023
77f1fac
add isolation gucs to sp_babelfish_configure
tanscorpio7 Oct 19, 2023
f6c8f07
add sp_configurations_view to upgrade script
tanscorpio7 Oct 20, 2023
d351911
indentation
tanscorpio7 Oct 21, 2023
70cba7a
indentation
tanscorpio7 Oct 21, 2023
0f34fe6
use enum GUC & refactor guc name and err msg
tanscorpio7 Oct 23, 2023
c387ad7
refactor
tanscorpio7 Oct 25, 2023
ce3e97c
refactor
tanscorpio7 Oct 25, 2023
48356da
fix typo
tanscorpio7 Oct 25, 2023
809c958
Merge branch 'BABEL_3_X_DEV' into BABEL_4146
tanscorpio7 Oct 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion contrib/babelfishpg_tsql/sql/sys_procedures.sql
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ CREATE VIEW sys.babelfish_configurations_view as
FROM pg_catalog.pg_settings
WHERE name collate "C" like 'babelfishpg_tsql.explain_%' OR
name collate "C" like 'babelfishpg_tsql.escape_hatch_%' OR
name collate "C" = 'babelfishpg_tsql.enable_pg_hint';
name collate "C" = 'babelfishpg_tsql.enable_pg_hint' OR
name collate "C" like 'babelfishpg_tsql.isolation_level_%';
GRANT SELECT on sys.babelfish_configurations_view TO PUBLIC;

CREATE OR REPLACE PROCEDURE sys.sp_babelfish_configure(IN "@option_name" varchar(128), IN "@option_value" varchar(128), IN "@option_scope" varchar(128))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1341,6 +1341,14 @@ DROP PROCEDURE sys.babelfish_update_user_catalog_for_guest_schema();
-- Please have this be one of the last statements executed in this upgrade script.
DROP PROCEDURE sys.babelfish_drop_deprecated_object(varchar, varchar, varchar);

CREATE OR REPLACE VIEW sys.babelfish_configurations_view as
SELECT *
FROM pg_catalog.pg_settings
WHERE name collate "C" like 'babelfishpg_tsql.explain_%' OR
name collate "C" like 'babelfishpg_tsql.escape_hatch_%' OR
name collate "C" = 'babelfishpg_tsql.enable_pg_hint' OR
name collate "C" like 'babelfishpg_tsql.isolation_level_%';
GRANT SELECT on sys.babelfish_configurations_view TO PUBLIC;

-- Reset search_path to not affect any subsequent scripts
SELECT set_config('search_path', trim(leading 'sys, ' from current_setting('search_path')), false);
29 changes: 23 additions & 6 deletions contrib/babelfishpg_tsql/src/backend_parser/gram-tsql-rule.y
Original file line number Diff line number Diff line change
Expand Up @@ -4338,11 +4338,20 @@ tsql_IsolationLevelStr:
}
| REPEATABLE READ
{
TSQLInstrumentation(INSTR_UNSUPPORTED_TSQL_ISOLATION_LEVEL_REPEATABLE_READ);
ereport(ERROR,
if (pltsql_isolation_level_repeatable_read)
{
TSQLInstrumentation(INSTR_TSQL_ISOLATION_LEVEL_REPEATABLE_READ);
$$ = "repeatable read";
}
else
{
TSQLInstrumentation(INSTR_UNSUPPORTED_TSQL_ISOLATION_LEVEL_REPEATABLE_READ);
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("REPEATABLE READ isolation level is not supported"),
errmsg("REPEATABLE READis not currently supported in Babelfish. Please use ‘babelfishpg_tsql.isolation_level_ repeatable_read’ to get PG repeatable read."),
tanscorpio7 marked this conversation as resolved.
Show resolved Hide resolved
parser_errposition(@1)));
}

}
| SNAPSHOT
{
Expand All @@ -4351,11 +4360,19 @@ tsql_IsolationLevelStr:
}
| SERIALIZABLE
{
TSQLInstrumentation(INSTR_UNSUPPORTED_TSQL_ISOLATION_LEVEL_SERIALIZABLE);
ereport(ERROR,
if (pltsql_isolation_level_serializable)
{
TSQLInstrumentation(INSTR_TSQL_ISOLATION_LEVEL_SERIALIZABLE);
$$ = "serializable";
}
else
{
TSQLInstrumentation(INSTR_UNSUPPORTED_TSQL_ISOLATION_LEVEL_SERIALIZABLE);
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("SERIALIZABLE isolation level is not supported"),
errmsg("SERIALIZABLEis not currently supported in Babelfish. Please use ‘babelfishpg_tsql.isolation_level_serializable’ to get PG serializable."),
tanscorpio7 marked this conversation as resolved.
Show resolved Hide resolved
parser_errposition(@1)));
}
}
;

Expand Down
33 changes: 31 additions & 2 deletions contrib/babelfishpg_tsql/src/guc.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,12 @@ bool pltsql_showplan_xml = false;
bool pltsql_fmtonly = false;
bool pltsql_enable_tsql_information_schema = true;
bool pltsql_no_browsetable = false;
bool pltsql_enable_create_alter_view_from_pg = false;

char *pltsql_host_destribution = NULL;
char *pltsql_host_release = NULL;
char *pltsql_host_service_pack_level = NULL;

bool pltsql_enable_create_alter_view_from_pg = false;
tanscorpio7 marked this conversation as resolved.
Show resolved Hide resolved

static const struct config_enum_entry explain_format_options[] = {
{"text", EXPLAIN_FORMAT_TEXT, false},
{"xml", EXPLAIN_FORMAT_XML, false},
Expand Down Expand Up @@ -128,6 +127,12 @@ static const struct config_enum_entry escape_hatch_options[] = {
{NULL, EH_NULL, false},
};

static const struct config_enum_entry bbf_isolation_options[] = {
{"off", ISOLATION_OFF, false},
{"pg_isolation", PG_ISOLATION, false},
{NULL, ISOLATION_OFF, false},
};

static bool
check_ansi_null_dflt_on(bool *newval, void **extra, GucSource source)
{
Expand Down Expand Up @@ -1207,6 +1212,8 @@ int escape_hatch_rowversion = EH_STRICT;
int escape_hatch_showplan_all = EH_STRICT;
int escape_hatch_checkpoint = EH_IGNORE;
int escape_hatch_set_transaction_isolation_level = EH_STRICT;
int pltsql_isolation_level_repeatable_read = ISOLATION_OFF;
int pltsql_isolation_level_serializable = ISOLATION_OFF;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this it is off, both are 2 tabs & 1 space


void
define_escape_hatch_variables(void)
Expand Down Expand Up @@ -1557,6 +1564,28 @@ define_escape_hatch_variables(void)
PGC_USERSET,
GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE | GUC_DISALLOW_IN_AUTO_FILE,
NULL, NULL, NULL);

/* REPEATABLE READ MAPPING */
DefineCustomEnumVariable("babelfishpg_tsql.isolation_level_repeatable_read",
gettext_noop("Select mapping for isolation level reapeatable read"),
NULL,
&pltsql_isolation_level_repeatable_read,
ISOLATION_OFF,
bbf_isolation_options,
PGC_USERSET,
GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE | GUC_DISALLOW_IN_AUTO_FILE,
NULL, NULL, NULL);

/* SERIALIZABLE MAPPING */
DefineCustomEnumVariable("babelfishpg_tsql.isolation_level_serializable",
gettext_noop("Select mapping for isolation level serializable"),
NULL,
&pltsql_isolation_level_serializable,
ISOLATION_OFF,
bbf_isolation_options,
PGC_USERSET,
GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE | GUC_DISALLOW_IN_AUTO_FILE,
NULL, NULL, NULL);
}

void
Expand Down
7 changes: 7 additions & 0 deletions contrib/babelfishpg_tsql/src/guc.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@ typedef enum EscapeHatchOption
EH_STRICT, EH_IGNORE, EH_NULL
} EscapeHatchOption;

typedef enum IsolationOptions
{
ISOLATION_OFF, PG_ISOLATION
} IsolationOptions;

extern bool pltsql_fmtonly;
extern bool pltsql_enable_create_alter_view_from_pg;
extern bool pltsql_enable_linked_servers;
extern bool pltsql_allow_windows_login;
extern char *pltsql_psql_logical_babelfish_db_name;
extern int pltsql_isolation_level_repeatable_read;
extern int pltsql_isolation_level_serializable;

extern void define_custom_variables(void);
extern void pltsql_validate_set_config_function(char *name, char *value);
Expand Down
2 changes: 2 additions & 0 deletions contrib/babelfishpg_tsql/src/pltsql_instr.h
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,10 @@ typedef enum PgTsqlInstrMetricType

INSTR_TSQL_ISOLATION_LEVEL_READ_UNCOMMITTED,
INSTR_TSQL_ISOLATION_LEVEL_READ_COMMITTED,
INSTR_TSQL_ISOLATION_LEVEL_REPEATABLE_READ,
INSTR_UNSUPPORTED_TSQL_ISOLATION_LEVEL_REPEATABLE_READ,
INSTR_TSQL_ISOLATION_LEVEL_SNAPSHOT,
INSTR_TSQL_ISOLATION_LEVEL_SERIALIZABLE,
INSTR_UNSUPPORTED_TSQL_ISOLATION_LEVEL_SERIALIZABLE,

INSTR_UNSUPPORTED_TSQL_SELECT_COL_ALIAS,
Expand Down
93 changes: 91 additions & 2 deletions test/JDBC/expected/BABEL-3214.out
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
GO
~~ERROR (Code: 33557097)~~

~~ERROR (Message: REPEATABLE READ isolation level is not supported)~~
~~ERROR (Message: REPEATABLE READis not currently supported in Babelfish. Please use ‘babelfishpg_tsql.isolation_level_ repeatable_read’ to get PG repeatable read.)~~

SELECT CAST(current_setting('transaction_isolation') AS VARCHAR);
SELECT transaction_isolation_level from sys.dm_exec_sessions WHERE session_id = @@SPID;
Expand All @@ -65,7 +65,7 @@ SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
GO
~~ERROR (Code: 33557097)~~

~~ERROR (Message: SERIALIZABLE isolation level is not supported)~~
~~ERROR (Message: SERIALIZABLEis not currently supported in Babelfish. Please use ‘babelfishpg_tsql.isolation_level_serializable’ to get PG serializable.)~~

SELECT CAST(current_setting('transaction_isolation') AS VARCHAR);
SELECT transaction_isolation_level from sys.dm_exec_sessions WHERE session_id = @@SPID;
Expand Down Expand Up @@ -98,3 +98,92 @@ smallint
5
~~END~~


SELECT set_config('babelfishpg_tsql.isolation_level_repeatable_read','pg_isolation',false);
SELECT set_config('babelfishpg_tsql.isolation_level_serializable','pg_isolation',false);
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
SELECT CAST(current_setting('transaction_isolation') AS VARCHAR);
SELECT transaction_isolation_level from sys.dm_exec_sessions WHERE session_id = @@SPID;
GO
~~START~~
text
pg_isolation
~~END~~

~~START~~
text
pg_isolation
~~END~~

~~START~~
varchar
read uncommitted
~~END~~

~~START~~
smallint
1
~~END~~


SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
SELECT CAST(current_setting('transaction_isolation') AS VARCHAR);
SELECT transaction_isolation_level from sys.dm_exec_sessions WHERE session_id = @@SPID;
GO
~~START~~
varchar
read committed
~~END~~

~~START~~
smallint
2
~~END~~


SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
GO
SELECT CAST(current_setting('transaction_isolation') AS VARCHAR);
SELECT transaction_isolation_level from sys.dm_exec_sessions WHERE session_id = @@SPID;
GO
~~START~~
varchar
repeatable read
~~END~~

~~START~~
smallint
5
~~END~~


SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
GO
SELECT CAST(current_setting('transaction_isolation') AS VARCHAR);
SELECT transaction_isolation_level from sys.dm_exec_sessions WHERE session_id = @@SPID;
GO
~~START~~
varchar
serializable
~~END~~

~~START~~
smallint
4
~~END~~


SET TRANSACTION ISOLATION LEVEL SNAPSHOT;
SELECT CAST(current_setting('transaction_isolation') AS VARCHAR);
SELECT transaction_isolation_level from sys.dm_exec_sessions WHERE session_id = @@SPID;
GO
~~START~~
varchar
repeatable read
~~END~~

~~START~~
smallint
5
~~END~~

6 changes: 6 additions & 0 deletions test/JDBC/expected/BABEL-UNSUPPORTED.out
Original file line number Diff line number Diff line change
Expand Up @@ -2035,6 +2035,8 @@ babelfishpg_tsql.explain_summary#!#on#!#Include summary information (e.g., total
babelfishpg_tsql.explain_timing#!#on#!#Include actual startup time and time spent in each node in the output
babelfishpg_tsql.explain_verbose#!#off#!#Display additional information regarding the plan
babelfishpg_tsql.explain_wal#!#off#!#Include information on WAL record generation
babelfishpg_tsql.isolation_level_repeatable_read#!#off#!#Select mapping for isolation level reapeatable read
babelfishpg_tsql.isolation_level_serializable#!#off#!#Select mapping for isolation level serializable
~~END~~


Expand Down Expand Up @@ -2101,6 +2103,8 @@ babelfishpg_tsql.explain_summary#!#on#!#Include summary information (e.g., total
babelfishpg_tsql.explain_timing#!#on#!#Include actual startup time and time spent in each node in the output
babelfishpg_tsql.explain_verbose#!#off#!#Display additional information regarding the plan
babelfishpg_tsql.explain_wal#!#off#!#Include information on WAL record generation
babelfishpg_tsql.isolation_level_repeatable_read#!#off#!#Select mapping for isolation level reapeatable read
babelfishpg_tsql.isolation_level_serializable#!#off#!#Select mapping for isolation level serializable
~~END~~


Expand Down Expand Up @@ -2148,6 +2152,8 @@ babelfishpg_tsql.explain_summary#!#on#!#Include summary information (e.g., total
babelfishpg_tsql.explain_timing#!#on#!#Include actual startup time and time spent in each node in the output
babelfishpg_tsql.explain_verbose#!#off#!#Display additional information regarding the plan
babelfishpg_tsql.explain_wal#!#off#!#Include information on WAL record generation
babelfishpg_tsql.isolation_level_repeatable_read#!#off#!#Select mapping for isolation level reapeatable read
babelfishpg_tsql.isolation_level_serializable#!#off#!#Select mapping for isolation level serializable
~~END~~


Expand Down
Loading
Loading