Skip to content

Commit 10be049

Browse files
author
Rucha Kulkarni
committed
Merge remote-tracking branch 'upstream/BABEL_5_X_DEV' into jira-babel-ssms-perf-5x
2 parents 88a8e73 + 9387495 commit 10be049

39 files changed

Lines changed: 3978 additions & 646 deletions

contrib/babelfishpg_tsql/runtime/functions.c

Lines changed: 754 additions & 474 deletions
Large diffs are not rendered by default.

contrib/babelfishpg_tsql/sql/sys_functions.sql

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4455,35 +4455,15 @@ CREATE OR REPLACE FUNCTION objectproperty(
44554455
)
44564456
RETURNS INT AS
44574457
'babelfishpg_tsql', 'objectproperty_internal'
4458-
LANGUAGE C STABLE;
4458+
LANGUAGE C STABLE STRICT;
44594459

44604460
CREATE OR REPLACE FUNCTION OBJECTPROPERTYEX(
44614461
id INT,
44624462
property SYS.VARCHAR
44634463
)
4464-
RETURNS SYS.SQL_VARIANT
4465-
AS $$
4466-
BEGIN
4467-
property := PG_CATALOG.RTRIM(LOWER(COALESCE(property, '')));
4468-
4469-
IF NOT EXISTS(SELECT ao.object_id FROM sys.all_objects ao WHERE object_id = id)
4470-
THEN
4471-
RETURN NULL;
4472-
END IF;
4473-
4474-
IF property = 'basetype' COLLATE "C" -- BaseType
4475-
THEN
4476-
RETURN (SELECT CAST(ao.type AS SYS.SQL_VARIANT)
4477-
FROM sys.all_objects ao
4478-
WHERE ao.object_id = id
4479-
LIMIT 1
4480-
);
4481-
END IF;
4482-
4483-
RETURN CAST(OBJECTPROPERTY(id, property) AS SYS.SQL_VARIANT);
4484-
END
4485-
$$
4486-
LANGUAGE plpgsql STABLE;
4464+
RETURNS SYS.SQL_VARIANT AS
4465+
'babelfishpg_tsql', 'objectpropertyex_internal'
4466+
LANGUAGE C STABLE STRICT;
44874467

44884468
CREATE OR REPLACE FUNCTION sys.sid_binary(IN login sys.nvarchar)
44894469
RETURNS SYS.VARBINARY

contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--5.6.0--5.7.0.sql

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,22 @@ CREATE OR REPLACE AGGREGATE sys.tsql_select_for_xml_text_agg(
421421
FINALFUNC = tsql_query_to_xml_text_ffunc
422422
);
423423

424+
CREATE OR REPLACE FUNCTION objectproperty(
425+
id INT,
426+
property SYS.VARCHAR
427+
)
428+
RETURNS INT AS
429+
'babelfishpg_tsql', 'objectproperty_internal'
430+
LANGUAGE C STABLE STRICT;
431+
432+
CREATE OR REPLACE FUNCTION OBJECTPROPERTYEX(
433+
id INT,
434+
property SYS.VARCHAR
435+
)
436+
RETURNS SYS.SQL_VARIANT AS
437+
'babelfishpg_tsql', 'objectpropertyex_internal'
438+
LANGUAGE C STABLE STRICT;
439+
424440
-- Drops the temporary procedure used by the upgrade script.
425441
-- Please have this be one of the last statements executed in this upgrade script.
426442
DROP PROCEDURE sys.babelfish_drop_deprecated_object(varchar, varchar, varchar, varchar);

contrib/babelfishpg_tsql/src/pltsql_utils.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1797,7 +1797,7 @@ tsql_get_constraint_nsp_oid(Oid object_id, Oid user_id)
17971797
*/
17981798
if (OidIsValid(con->conrelid))
17991799
{
1800-
if (pg_class_aclcheck(con->conrelid, user_id, ACL_SELECT) == ACLCHECK_OK)
1800+
if (pg_class_aclcheck(con->conrelid, user_id, ACL_SELECT | ACL_INSERT | ACL_UPDATE | ACL_DELETE | ACL_REFERENCES) == ACLCHECK_OK)
18011801
namespace_oid = con->connamespace;
18021802
}
18031803
}

test/JDBC/expected/objectproperty-vu-verify.out

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,7 @@ SELECT OBJECTPROPERTY(OBJECT_ID('objectproperty_vu_prepare_IsTrigger_trigger', '
11291129
GO
11301130
~~START~~
11311131
int
1132-
<NULL>
1132+
1
11331133
~~END~~
11341134

11351135

@@ -1151,6 +1151,25 @@ int
11511151
~~END~~
11521152

11531153

1154+
-- =============== Trigger properties ===============
1155+
-- ExecIsAnsiNullsOn on trigger
1156+
SELECT OBJECTPROPERTY(OBJECT_ID('objectproperty_vu_prepare_IsTrigger_trigger', 'TR'), 'ExecIsAnsiNullsOn')
1157+
GO
1158+
~~START~~
1159+
int
1160+
1
1161+
~~END~~
1162+
1163+
1164+
-- ExecIsQuotedIdentOn on trigger
1165+
SELECT OBJECTPROPERTY(OBJECT_ID('objectproperty_vu_prepare_IsTrigger_trigger', 'TR'), 'ExecIsQuotedIdentOn')
1166+
GO
1167+
~~START~~
1168+
int
1169+
1
1170+
~~END~~
1171+
1172+
11541173
-- tsql user=objectproperty_login_1 password=12345678
11551174
-- user does not have permission on the object (should return NULL)
11561175
SELECT OBJECTPROPERTY(OBJECT_ID('IsTrigger_trigger', 'TR'), 'IsTrigger')

test/JDBC/expected/objectproperty.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,7 @@ SELECT OBJECTPROPERTY(OBJECT_ID('IsTrigger_trigger', 'TR'), 'IsTrigger')
15671567
GO
15681568
~~START~~
15691569
int
1570-
<NULL>
1570+
1
15711571
~~END~~
15721572

15731573

@@ -3202,7 +3202,7 @@ SELECT OBJECTPROPERTY(OBJECT_ID('IsTrigger_trigger', 'TR'), 'IsTrigger')
32023202
GO
32033203
~~START~~
32043204
int
3205-
<NULL>
3205+
1
32063206
~~END~~
32073207

32083208

Lines changed: 84 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,78 @@
1-
DROP TABLE objectpropertyex_ownerid_schema.objectpropertyex_ownerid_table
1+
-- =============== ACL tests ===============
2+
DROP USER objectpropertyex_test_user
23
GO
34

4-
DROP SCHEMA objectpropertyex_ownerid_schema
5+
DROP LOGIN objectpropertyex_test_login
6+
GO
7+
8+
-- =============== Cross-database scoping ===============
9+
DROP DATABASE objectpropertyex_otherdb
10+
GO
11+
12+
13+
-- =============== Properties test objects ===============
14+
DROP INDEX objectpropertyex_idx ON objectpropertyex_indexed_table
15+
GO
16+
17+
DROP TABLE objectpropertyex_indexed_table
18+
GO
19+
20+
DROP TABLE objectpropertyex_noindex_table
21+
GO
22+
23+
DROP TABLE objectpropertyex_default_table
24+
GO
25+
26+
DROP TABLE objectpropertyex_notshipped_table
27+
GO
28+
29+
DROP FUNCTION objectpropertyex_schemabound_fn
30+
GO
31+
32+
DROP FUNCTION objectpropertyex_noschemabound_fn
33+
GO
34+
35+
36+
-- =============== IsSchemaBound - schema-bound view ===============
37+
DROP VIEW objectpropertyex_schemabound_view
38+
GO
39+
40+
41+
-- =============== BaseType - additional object types ===============
42+
DROP FUNCTION objectpropertyex_tvf
43+
GO
44+
45+
DROP FUNCTION objectpropertyex_itvf
46+
GO
47+
48+
DROP SEQUENCE objectpropertyex_test_seq
49+
GO
50+
51+
DROP TABLE objectpropertyex_fk_table
52+
GO
53+
54+
DROP TABLE objectpropertyex_constraint_table
55+
GO
56+
57+
DROP TRIGGER objectpropertyex_test_trigger
58+
GO
59+
60+
DROP TABLE objectpropertyex_trigger_table
61+
GO
62+
63+
64+
-- =============== Special Input Cases ===============
65+
DROP TABLE objectpropertyex_specialinput_table
566
GO
667

768

869
-- =============== BaseType ===============
9-
-- Cleanup
1070
DROP TABLE objectpropertyex_basetype_table
1171
GO
1272

73+
DROP TYPE objectpropertyex_basetype_tt
74+
GO
75+
1376
DROP VIEW objectpropertyex_basetype_view
1477
GO
1578

@@ -20,7 +83,22 @@ DROP PROC objectpropertyex_basetype_proc
2083
GO
2184

2285

23-
-- =============== Special Input Cases ===============
24-
-- Cleanup
25-
DROP TABLE objectpropertyex_specialinput_table
86+
-- =============== OwnerId ===============
87+
DROP TABLE objectpropertyex_ownerid_schema.objectpropertyex_ownerid_table
88+
GO
89+
90+
DROP SCHEMA objectpropertyex_ownerid_schema
91+
GO
92+
93+
-- =============== Permission edge cases ===============
94+
DROP TABLE objectpropertyex_oid_helper
95+
GO
96+
97+
DROP TABLE objectpropertyex_perm_table
98+
GO
99+
100+
DROP USER objectpropertyex_perm_user
101+
GO
102+
103+
DROP LOGIN objectpropertyex_perm_login
26104
GO

test/JDBC/expected/objectpropertyex-before-16_5-or-15_9-vu-prepare.out

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ GO
1010
CREATE TABLE objectpropertyex_basetype_table(a int)
1111
GO
1212

13+
CREATE TYPE objectpropertyex_basetype_tt AS TABLE(a int)
14+
GO
15+
1316
CREATE VIEW objectpropertyex_basetype_view AS
1417
SELECT 1
1518
GO
@@ -32,3 +35,123 @@ GO
3235
-- Setup
3336
CREATE TABLE objectpropertyex_specialinput_table(a int)
3437
GO
38+
39+
40+
-- =============== BaseType - additional object types ===============
41+
-- Trigger
42+
CREATE TABLE objectpropertyex_trigger_table(a int)
43+
GO
44+
45+
CREATE TRIGGER objectpropertyex_test_trigger ON objectpropertyex_trigger_table
46+
AFTER INSERT AS
47+
BEGIN
48+
SELECT 1
49+
END
50+
GO
51+
52+
-- Constraints: PK, FK, CHECK, DEFAULT
53+
CREATE TABLE objectpropertyex_constraint_table(
54+
a int,
55+
b int DEFAULT 42,
56+
c int CHECK (c > 0),
57+
CONSTRAINT objectpropertyex_pk PRIMARY KEY (a)
58+
)
59+
GO
60+
61+
CREATE TABLE objectpropertyex_fk_table(
62+
x int,
63+
CONSTRAINT objectpropertyex_fk FOREIGN KEY (x) REFERENCES objectpropertyex_constraint_table(a)
64+
)
65+
GO
66+
67+
-- Sequence
68+
CREATE SEQUENCE objectpropertyex_test_seq START WITH 1
69+
GO
70+
71+
-- Inline table-valued function
72+
CREATE FUNCTION objectpropertyex_itvf()
73+
RETURNS TABLE
74+
AS
75+
RETURN (SELECT 1 AS col1)
76+
GO
77+
78+
-- Multi-statement table-valued function
79+
CREATE FUNCTION objectpropertyex_tvf()
80+
RETURNS @result TABLE (col1 int)
81+
AS
82+
BEGIN
83+
INSERT @result VALUES (1)
84+
RETURN
85+
END
86+
GO
87+
88+
89+
-- =============== Properties test objects ===============
90+
-- IsSchemaBound
91+
CREATE FUNCTION objectpropertyex_schemabound_fn()
92+
RETURNS int
93+
WITH SCHEMABINDING
94+
BEGIN
95+
RETURN 1
96+
END
97+
GO
98+
99+
CREATE FUNCTION objectpropertyex_noschemabound_fn()
100+
RETURNS int
101+
BEGIN
102+
RETURN 1
103+
END
104+
GO
105+
106+
-- IsIndexed
107+
CREATE TABLE objectpropertyex_indexed_table(a int)
108+
GO
109+
110+
CREATE INDEX objectpropertyex_idx ON objectpropertyex_indexed_table(a)
111+
GO
112+
113+
CREATE TABLE objectpropertyex_noindex_table(a int)
114+
GO
115+
116+
-- IsDefaultCnst
117+
CREATE TABLE objectpropertyex_default_table(a int DEFAULT 10)
118+
GO
119+
120+
-- IsMSShipped
121+
CREATE TABLE objectpropertyex_notshipped_table(a int)
122+
GO
123+
124+
125+
-- =============== IsSchemaBound - schema-bound view ===============
126+
CREATE VIEW objectpropertyex_schemabound_view
127+
WITH SCHEMABINDING
128+
AS
129+
SELECT 1 AS col1
130+
GO
131+
132+
-- =============== Cross-database scoping ===============
133+
CREATE DATABASE objectpropertyex_otherdb
134+
GO
135+
136+
USE objectpropertyex_otherdb
137+
GO
138+
139+
CREATE TABLE objectpropertyex_otherdb_table(a int)
140+
GO
141+
142+
USE master
143+
GO
144+
145+
-- =============== Permission edge cases (OID helper) ===============
146+
CREATE TABLE objectpropertyex_perm_table(a int)
147+
GO
148+
149+
CREATE TRIGGER objectpropertyex_perm_trigger ON objectpropertyex_perm_table INSTEAD OF INSERT
150+
AS
151+
BEGIN
152+
SELECT * FROM objectpropertyex_perm_table
153+
END
154+
GO
155+
-- Store OIDs so restricted users can bypass OBJECT_ID() limitation
156+
CREATE TABLE objectpropertyex_oid_helper(name varchar(100), oid_val int)
157+
GO

0 commit comments

Comments
 (0)