Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c93393d
Add remote procedure execution via TDS protocol with RPC out validati…
Nov 25, 2025
e5c200b
Address critical security and correctness issues in remote procedure …
Dec 10, 2025
2ce4ece
Enhanced remote procedure execution with ANTLR SELECT-only validation…
Dec 13, 2025
1963aa5
Fixed test failures and procedures.c and set GUC on for github actions
Dec 15, 2025
d67147b
Address code review comments:
Dec 16, 2025
bea0871
Add nested stored procedure support with improved error handling and …
Dec 16, 2025
8df5612
added upgrade tests and fixed tests
Dec 18, 2025
14385e2
updated tests output
Dec 18, 2025
58dc7ce
set github action create extension permission to catalog and fixed diff
Dec 18, 2025
398f07b
fixed whitespaces
Dec 19, 2025
cf8d2f7
Address all blocking reviewer comments and improve code quality for the
Feb 27, 2026
17b2f9e
Map PG error 22P02 to SQL Server error 245 and add RPC error tests. F…
Mar 14, 2026
bd1f891
Fix CI failures: revert 22P02 error mapping, fix upgrade schedule nam…
Mar 16, 2026
ced2eee
Fix CI failures: remove sybdb.h macro pollution from ANTLR parser and…
Mar 17, 2026
ebe442d
fix failing checks
Mar 18, 2026
a70cc73
fix
Mar 18, 2026
745cf43
fix single_db tests
Mar 18, 2026
4d5ec2c
Fix single-db CI failure and add transaction behavior tests
Mar 19, 2026
8136178
Block transaction control statements in remote procedure validation
Mar 19, 2026
359f235
Implement T-SQL compatible RPC error handling for linked server RPC
Mar 20, 2026
a078042
Fix CI failures: update expected outputs for RPC error handling changes
Mar 21, 2026
c92b6c7
Fix version upgrade CI: update expected output for new error codes 72…
Mar 22, 2026
d992bf8
Re-trigger CI
Mar 23, 2026
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
4 changes: 4 additions & 0 deletions contrib/babelfishpg_tds/error_mapping.txt
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,7 @@ XX000 ERRCODE_INTERNAL_ERROR "The table-valued parameter \"%s\" must be declared
42P01 ERRCODE_UNDEFINED_TABLE "FOR JSON AUTO requires at least one table for generating JSON objects. Use FOR JSON PATH or add a FROM clause with a table name." SQL_ERROR_13600 16
42P01 ERRCODE_FEATURE_NOT_SUPPORTED "sub-select and values for json auto are not currently supported." SQL_ERROR_13600 16

HV004 ERRCODE_FDW_UNABLE_TO_CREATE_EXECUTION "Could not execute statement on remote server '%s'." SQL_ERROR_7215 16 "Could not execute statement on remote server"
HV000 ERRCODE_FDW_ERROR "Server '%s' is not configured for RPC OUT." SQL_ERROR_7412 16 "is not configured for RPC OUT"
HV000 ERRCODE_FDW_ERROR "Could not find server '%s' in sys.servers." SQL_ERROR_7202 11 "Could not find server"

3 changes: 2 additions & 1 deletion contrib/babelfishpg_tsql/sql/linked_servers_tsql.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
CREATE TABLE sys.babelfish_server_options (
servername sys.SYSNAME NOT NULL PRIMARY KEY COLLATE "C",
query_timeout INT,
connect_timeout INT
connect_timeout INT,
rpc_out BOOLEAN DEFAULT FALSE
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  1. We can't change that directly, should use the upgrade script to alter the table add new columns
  2. Also in this script, we should also use alter table after create table.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We can modify this. This will only be run on a fresh provisioning of Babelfish database. This is not the upgrade script. The ALTER statement should be part of the upgrade script.

);
GRANT SELECT ON sys.babelfish_server_options TO PUBLIC;

Expand Down
2 changes: 1 addition & 1 deletion contrib/babelfishpg_tsql/sql/sys_views.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3528,7 +3528,7 @@ SELECT
CAST(s.query_timeout as int) AS query_timeout,
CAST(1 as sys.bit) AS is_linked,
CAST(0 as sys.bit) AS is_remote_login_enabled,
CAST(0 as sys.bit) AS is_rpc_out_enabled,
CAST(COALESCE(s.rpc_out, false) as sys.bit) AS is_rpc_out_enabled,
CAST(1 as sys.bit) AS is_data_access_enabled,
CAST(0 as sys.bit) AS is_collation_compatible,
CAST(1 as sys.bit) AS uses_remote_collation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,54 @@ BEGIN
END;
$$
LANGUAGE plpgsql IMMUTABLE STRICT;
-- Add rpc_out column to babelfish_server_options for remote procedure execution feature
ALTER TABLE sys.babelfish_server_options ADD COLUMN IF NOT EXISTS rpc_out BOOLEAN DEFAULT FALSE;

-- Recreate sys.servers view to include rpc_out column
CREATE OR REPLACE VIEW sys.servers
AS
SELECT
CAST(f.oid as int) AS server_id,
CAST(f.srvname as sys.sysname) AS name,
CAST('' as sys.sysname) AS product,
CAST('tds_fdw' as sys.sysname) AS provider,
CAST((select PG_CATALOG.string_agg(
case
when option like 'servername=%%' then substring(option, 12)
else NULL
end, ',')
from unnest(f.srvoptions) as option) as sys.nvarchar(4000)) AS data_source,
CAST(NULL as sys.nvarchar(4000)) AS location,
CAST(NULL as sys.nvarchar(4000)) AS provider_string,
CAST((select PG_CATALOG.string_agg(
case
when option like 'database=%%' then substring(option, 10)
else NULL
end, ',')
from unnest(f.srvoptions) as option) as sys.sysname) AS catalog,
CAST(s.connect_timeout as int) AS connect_timeout,
CAST(s.query_timeout as int) AS query_timeout,
CAST(1 as sys.bit) AS is_linked,
CAST(0 as sys.bit) AS is_remote_login_enabled,
CAST(COALESCE(s.rpc_out, false) as sys.bit) AS is_rpc_out_enabled,
CAST(1 as sys.bit) AS is_data_access_enabled,
CAST(0 as sys.bit) AS is_collation_compatible,
CAST(1 as sys.bit) AS uses_remote_collation,
CAST(NULL as sys.sysname) AS collation_name,
CAST(0 as sys.bit) AS lazy_schema_validation,
CAST(0 as sys.bit) AS is_system,
CAST(0 as sys.bit) AS is_publisher,
CAST(0 as sys.bit) AS is_subscriber,
CAST(0 as sys.bit) AS is_distributor,
CAST(0 as sys.bit) AS is_nonsql_subscriber,
CAST(1 as sys.bit) AS is_remote_proc_transaction_promotion_enabled,
CAST(NULL as sys.datetime) AS modify_date,
CAST(0 as sys.bit) AS is_rda_server
FROM pg_foreign_server AS f
LEFT JOIN pg_foreign_data_wrapper AS w ON f.srvfdw = w.oid
LEFT JOIN sys.babelfish_server_options AS s on f.srvname = s.servername
WHERE w.fdwname = 'tds_fdw';
GRANT SELECT ON sys.servers TO PUBLIC;

-- Drops the temporary procedure used by the upgrade script.
-- Please have this be one of the last statements executed in this upgrade script.
Expand Down
42 changes: 39 additions & 3 deletions contrib/babelfishpg_tsql/src/catalog.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@ initTsqlSyscache()
bool
IsPLtsqlExtendedCatalog(Oid relationId)
{
/* Skip during Babelfish restore */
if (!babelfish_dump_restore && (relationId == sysdatabases_oid ||
/* Skip during Babelfish restore or extension creation/upgrade */
if (!babelfish_dump_restore && !creating_extension && (relationId == sysdatabases_oid ||
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why we need this change ?

relationId == bbf_function_ext_oid || relationId == namespace_ext_oid ||
relationId == bbf_authid_login_ext_oid || relationId == bbf_authid_user_ext_oid ||
relationId == bbf_view_def_oid || relationId == bbf_servers_def_oid ||
Expand Down Expand Up @@ -1423,6 +1423,42 @@ get_timeout_from_server_name(char *servername, int attnum)
return timeout;
}

bool
get_rpc_out_option(char *servername)
{
Relation bbf_servers_def_rel;
HeapTuple tuple;
ScanKeyData key;
TableScanDesc scan;
bool rpc_out_enabled = false; /* Default to disabled */

bbf_servers_def_rel = table_open(get_bbf_servers_def_oid(),
AccessShareLock);

ScanKeyInit(&key,
Anum_bbf_servers_def_servername,
BTEqualStrategyNumber, F_TEXTEQ,
CStringGetTextDatum(servername));

scan = table_beginscan_catalog(bbf_servers_def_rel, 1, &key);

tuple = heap_getnext(scan, ForwardScanDirection);
if (HeapTupleIsValid(tuple))
{
bool isNull;
rpc_out_enabled = DatumGetBool(heap_getattr(tuple,
Anum_bbf_servers_def_rpc_out,
RelationGetDescr(bbf_servers_def_rel),
&isNull));
if (isNull)
rpc_out_enabled = false; /* Default if NULL */
}

table_endscan(scan);
table_close(bbf_servers_def_rel, AccessShareLock);
return rpc_out_enabled;
}

void
clean_up_bbf_server_def()
{
Expand Down Expand Up @@ -6490,4 +6526,4 @@ bbf_check_member_has_direct_priv_to_grant_role(Oid member, Oid role)

ReleaseSysCacheList(memlist);
return false;
}
}
5 changes: 4 additions & 1 deletion contrib/babelfishpg_tsql/src/catalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,15 @@ typedef FormData_bbf_view_def * Form_bbf_view_def;
#define Anum_bbf_servers_def_servername 1
#define Anum_bbf_servers_def_query_timeout 2
#define Anum_bbf_servers_def_connect_timeout 3
#define BBF_SERVERS_DEF_NUM_COLS 3
#define Anum_bbf_servers_def_rpc_out 4
#define BBF_SERVERS_DEF_NUM_COLS 4
extern Oid bbf_servers_def_oid;
extern Oid bbf_servers_def_idx_oid;

extern Oid get_bbf_servers_def_oid(void);
extern Oid get_bbf_servers_def_idx_oid(void);
extern int get_timeout_from_server_name(char *servername, int attnum);
extern bool get_rpc_out_option(char *servername);
extern int get_server_id_from_server_name(char *servername);
extern void clean_up_bbf_server_def(void);

Expand All @@ -258,6 +260,7 @@ typedef struct FormData_bbf_servers_def
text servername;
int32 query_timeout;
int32 connect_timeout;
bool rpc_out;
} FormData_bbf_servers_def;

typedef FormData_bbf_servers_def *Form_bbf_servers_def;
Expand Down
10 changes: 10 additions & 0 deletions contrib/babelfishpg_tsql/src/guc.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ char *pltsql_language = NULL;
char *pltsql_psql_logical_babelfish_db_name = NULL;
int pltsql_lock_timeout = -1;
bool pltsql_enable_linked_servers = true;
bool pltsql_enable_remote_proc_exec = true;
bool pltsql_enable_ownership_chaining = true;
bool pltsql_allow_windows_login = true;
bool pltsql_allow_fulltext_parser = false;
Expand Down Expand Up @@ -1257,6 +1258,15 @@ define_custom_variables(void)
GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_AUTO_FILE,
NULL, NULL, NULL);

DefineCustomBoolVariable("babelfishpg_tsql.enable_remote_proc_exec",
gettext_noop("Enables remote procedure execution via four-part names (EXEC server.db.schema.proc)"),
NULL,
&pltsql_enable_remote_proc_exec,
true,
PGC_SUSET,
GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_AUTO_FILE,
NULL, NULL, NULL);

/* GUC to enable/disable the ownership chaining feature, by default enabled */
DefineCustomBoolVariable("babelfishpg_tsql.enable_ownership_chaining",
gettext_noop("Enables ownership chaining"),
Expand Down
1 change: 1 addition & 0 deletions contrib/babelfishpg_tsql/src/guc.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ extern bool pltsql_fmtonly;
extern bool pltsql_enable_create_alter_view_from_pg;
extern bool pltsql_enable_alter_owner_from_pg;
extern bool pltsql_enable_linked_servers;
extern bool pltsql_enable_remote_proc_exec;
extern bool pltsql_enable_ownership_chaining;
extern bool pltsql_allow_windows_login;
extern bool pltsql_allow_fulltext_parser;
Expand Down
Loading
Loading