Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
112148: sql: add cluster version for udfs with mutations r=rharding6373 a=rharding6373

sql: move udf mutations privileges logic tests to their own file
    
Epic: None
    
Release note: None

sql: add cluster version for udfs with mutations

This PR gates the UDFs containing mutations feature.

Epic: CRDB-25388
Informs: cockroachdb#105365

Release note: None

Co-authored-by: rharding6373 <[email protected]>
  • Loading branch information
craig[bot] and rharding6373 committed Oct 12, 2023
2 parents d399485 + 2cbc02e commit 619aa6e
Show file tree
Hide file tree
Showing 22 changed files with 283 additions and 129 deletions.
2 changes: 1 addition & 1 deletion docs/generated/settings/settings-for-tenants.txt
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,4 @@ trace.snapshot.rate duration 0s if non-zero, interval at which background trace
trace.span_registry.enabled boolean true if set, ongoing traces can be seen at https://<ui>/#/debug/tracez application
trace.zipkin.collector string the address of a Zipkin instance to receive traces, as <host>:<port>. If no port is specified, 9411 will be used. application
ui.display_timezone enumeration etc/utc the timezone used to format timestamps in the ui [etc/utc = 0, america/new_york = 1] application
version version 1000023.1-36 set the active cluster version in the format '<major>.<minor>' application
version version 1000023.1-38 set the active cluster version in the format '<major>.<minor>' application
2 changes: 1 addition & 1 deletion docs/generated/settings/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,6 @@
<tr><td><div id="setting-trace-span-registry-enabled" class="anchored"><code>trace.span_registry.enabled</code></div></td><td>boolean</td><td><code>true</code></td><td>if set, ongoing traces can be seen at https://&lt;ui&gt;/#/debug/tracez</td><td>Serverless/Dedicated/Self-Hosted</td></tr>
<tr><td><div id="setting-trace-zipkin-collector" class="anchored"><code>trace.zipkin.collector</code></div></td><td>string</td><td><code></code></td><td>the address of a Zipkin instance to receive traces, as &lt;host&gt;:&lt;port&gt;. If no port is specified, 9411 will be used.</td><td>Serverless/Dedicated/Self-Hosted</td></tr>
<tr><td><div id="setting-ui-display-timezone" class="anchored"><code>ui.display_timezone</code></div></td><td>enumeration</td><td><code>etc/utc</code></td><td>the timezone used to format timestamps in the ui [etc/utc = 0, america/new_york = 1]</td><td>Serverless/Dedicated/Self-Hosted</td></tr>
<tr><td><div id="setting-version" class="anchored"><code>version</code></div></td><td>version</td><td><code>1000023.1-36</code></td><td>set the active cluster version in the format &#39;&lt;major&gt;.&lt;minor&gt;&#39;</td><td>Serverless/Dedicated/Self-Hosted</td></tr>
<tr><td><div id="setting-version" class="anchored"><code>version</code></div></td><td>version</td><td><code>1000023.1-38</code></td><td>set the active cluster version in the format &#39;&lt;major&gt;.&lt;minor&gt;&#39;</td><td>Serverless/Dedicated/Self-Hosted</td></tr>
</tbody>
</table>
7 changes: 7 additions & 0 deletions pkg/ccl/logictestccl/tests/3node-tenant/generated_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions pkg/clusterversion/cockroach_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,9 @@ const (
// PLpgSQL language.
V23_2_PLpgSQL

// V23_2_UDFMutations is the version where UDFs with mutations are enabled.
V23_2_UDFMutations

// *************************************************
// Step (1) Add new versions here.
// Do not add new versions to a patch release.
Expand Down Expand Up @@ -874,6 +877,10 @@ var rawVersionsSingleton = keyedVersions{
Key: V23_2_PLpgSQL,
Version: roachpb.Version{Major: 23, Minor: 1, Internal: 36},
},
{
Key: V23_2_UDFMutations,
Version: roachpb.Version{Major: 23, Minor: 1, Internal: 38},
},

// *************************************************
// Step (2): Add new versions here.
Expand Down
108 changes: 108 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/mixed_version_udf_mutations
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# LogicTest: cockroach-go-testserver-upgrade-to-master

query T nodeidx=0
SELECT crdb_internal.node_executable_version()
----
23.1

query T nodeidx=1
SELECT crdb_internal.node_executable_version()
----
23.1

query T nodeidx=2
SELECT crdb_internal.node_executable_version()
----
23.1

# ----------------------------------------------------------------------
# Test UDFs with mutations with all nodes running old binaries.
# ----------------------------------------------------------------------

statement ok
CREATE TABLE t (a INT PRIMARY KEY, b INT DEFAULT 0);

statement error pgcode 0A000 pq: unimplemented: INSERT usage inside a function definition
CREATE FUNCTION f_insert() RETURNS VOID AS $$
INSERT INTO t VALUES (1,1);
$$ LANGUAGE SQL;

statement error pgcode 0A000 pq: unimplemented: DELETE usage inside a function definition
CREATE FUNCTION f_delete() RETURNS VOID AS $$
DELETE FROM t WHERE a = 1;
$$ LANGUAGE SQL;

statement error pgcode 0A000 pq: unimplemented: UPDATE usage inside a function definition
CREATE FUNCTION f_update() RETURNS VOID AS $$
UPDATE t SET b = 1 WHERE a = 1;
$$ LANGUAGE SQL;

# ----------------------------------------------------------------------
# Test UDFs with mutations with only the gateway running 23.2.
# ----------------------------------------------------------------------

upgrade 0

user root nodeidx=0

statement error pgcode 0A000 pq: unimplemented: INSERT usage inside a function definition is not supported until version 23.2
CREATE FUNCTION f_insert() RETURNS VOID AS $$
INSERT INTO t VALUES (1,1);
$$ LANGUAGE SQL;

statement error pgcode 0A000 pq: unimplemented: DELETE usage inside a function definition is not supported until version 23.2
CREATE FUNCTION f_delete() RETURNS VOID AS $$
DELETE FROM t WHERE a = 1;
$$ LANGUAGE SQL;

statement error pgcode 0A000 pq: unimplemented: UPDATE usage inside a function definition is not supported until version 23.2
CREATE FUNCTION f_update() RETURNS VOID AS $$
UPDATE t SET b = 1 WHERE a = 1;
$$ LANGUAGE SQL;

user root nodeidx=1

# These statements should fail.

statement error pgcode 0A000 pq: unimplemented: INSERT usage inside a function definition
CREATE FUNCTION f_insert() RETURNS VOID AS $$
INSERT INTO t VALUES (1,1);
$$ LANGUAGE SQL;

statement error pgcode 0A000 pq: unimplemented: DELETE usage inside a function definition
CREATE FUNCTION f_delete() RETURNS VOID AS $$
DELETE FROM t WHERE a = 1;
$$ LANGUAGE SQL;

statement error pgcode 0A000 pq: unimplemented: UPDATE usage inside a function definition
CREATE FUNCTION f_update() RETURNS VOID AS $$
UPDATE t SET b = 1 WHERE a = 1;
$$ LANGUAGE SQL;

# ----------------------------------------------------------------------
# Upgrade all nodes and test that creating UDFs with mutations succeeds.
# ----------------------------------------------------------------------

upgrade 1

upgrade 2

query B retry
SELECT crdb_internal.is_at_least_version('23.1-38')
----
true

statement ok
CREATE FUNCTION f_insert() RETURNS VOID AS $$
INSERT INTO t VALUES (1,1);
$$ LANGUAGE SQL;

statement ok
CREATE FUNCTION f_delete() RETURNS VOID AS $$
DELETE FROM t WHERE a = 1;
$$ LANGUAGE SQL;

statement ok
CREATE FUNCTION f_update() RETURNS VOID AS $$
UPDATE t SET b = 1 WHERE a = 1;
$$ LANGUAGE SQL;
2 changes: 2 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/udf_delete
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# LogicTest: !local-mixed-22.2-23.1

statement ok
CREATE TABLE kv (
k INT PRIMARY KEY,
Expand Down
2 changes: 2 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/udf_fk
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# LogicTest: !local-mixed-22.2-23.1

# Disable fast path for some test runs.
let $enable_insert_fast_path
SELECT random() < 0.5
Expand Down
2 changes: 2 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/udf_insert
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# LogicTest: !local-mixed-22.2-23.1

statement ok
CREATE TABLE t (a INT PRIMARY KEY, b INT DEFAULT 0);

Expand Down
90 changes: 0 additions & 90 deletions pkg/sql/logictest/testdata/logic_test/udf_privileges
Original file line number Diff line number Diff line change
Expand Up @@ -805,93 +805,3 @@ SET ROLE root

subtest end

subtest mutations

statement ok
CREATE TABLE t (a INT, b INT);
CREATE FUNCTION f_insert() RETURNS VOID LANGUAGE SQL AS $$ INSERT INTO t VALUES (1,2); $$;
CREATE FUNCTION f_select() RETURNS INT LANGUAGE SQL AS $$ SELECT b FROM t WHERE a = 1; $$;
CREATE FUNCTION f_update() RETURNS VOID LANGUAGE SQL AS $$ UPDATE t SET b = 3 WHERE a = 1; $$;
CREATE FUNCTION f_delete() RETURNS VOID LANGUAGE SQL AS $$ DELETE FROM t WHERE a = 1; $$;
CREATE USER test_user;

statement ok
SET ROLE test_user

statement error pq: user test_user does not have INSERT privilege on relation t
select f_insert();

statement error pq: user test_user does not have SELECT privilege on relation t
select f_select();

statement error pq: user test_user does not have UPDATE privilege on relation t
select f_update();

statement error pq: user test_user does not have DELETE privilege on relation t
select f_delete();

statement ok
SET ROLE root

statement ok
GRANT SELECT, INSERT, DELETE, UPDATE ON t TO test_user;

statement ok
SET ROLE test_user


statement ok
SELECT f_insert();

query I
SELECT f_select();
----
2

statement ok
SELECT f_update();

query II
SELECT * FROM t;
----
1 3

statement ok
SELECT f_delete();

query II
SELECT * FROM t;
----

statement ok
SET ROLE root

statement ok
REVOKE SELECT, INSERT, DELETE, UPDATE ON t FROM test_user;

statement ok
SET ROLE test_user

statement error pq: user test_user does not have SELECT privilege on relation t
select f_select();

statement error pq: user test_user does not have INSERT privilege on relation t
select f_insert();

statement error pq: user test_user does not have UPDATE privilege on relation t
select f_update();

statement error pq: user test_user does not have DELETE privilege on relation t
select f_delete();

statement ok
SET ROLE root

statement ok
DROP FUNCTION f_insert;
DROP FUNCTION f_select;
DROP FUNCTION f_update;
DROP FUNCTION f_delete;
DROP USER test_user;

subtest end
92 changes: 92 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/udf_privileges_mutations
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# LogicTest: !local-mixed-22.2-23.1

subtest privileges_mutations

statement ok
CREATE TABLE t (a INT, b INT);
CREATE FUNCTION f_insert() RETURNS VOID LANGUAGE SQL AS $$ INSERT INTO t VALUES (1,2); $$;
CREATE FUNCTION f_select() RETURNS INT LANGUAGE SQL AS $$ SELECT b FROM t WHERE a = 1; $$;
CREATE FUNCTION f_update() RETURNS VOID LANGUAGE SQL AS $$ UPDATE t SET b = 3 WHERE a = 1; $$;
CREATE FUNCTION f_delete() RETURNS VOID LANGUAGE SQL AS $$ DELETE FROM t WHERE a = 1; $$;
CREATE USER test_user;

statement ok
SET ROLE test_user

statement error pq: user test_user does not have INSERT privilege on relation t
select f_insert();

statement error pq: user test_user does not have SELECT privilege on relation t
select f_select();

statement error pq: user test_user does not have UPDATE privilege on relation t
select f_update();

statement error pq: user test_user does not have DELETE privilege on relation t
select f_delete();

statement ok
SET ROLE root

statement ok
GRANT SELECT, INSERT, DELETE, UPDATE ON t TO test_user;

statement ok
SET ROLE test_user


statement ok
SELECT f_insert();

query I
SELECT f_select();
----
2

statement ok
SELECT f_update();

query II
SELECT * FROM t;
----
1 3

statement ok
SELECT f_delete();

query II
SELECT * FROM t;
----

statement ok
SET ROLE root

statement ok
REVOKE SELECT, INSERT, DELETE, UPDATE ON t FROM test_user;

statement ok
SET ROLE test_user

statement error pq: user test_user does not have SELECT privilege on relation t
select f_select();

statement error pq: user test_user does not have INSERT privilege on relation t
select f_insert();

statement error pq: user test_user does not have UPDATE privilege on relation t
select f_update();

statement error pq: user test_user does not have DELETE privilege on relation t
select f_delete();

statement ok
SET ROLE root

statement ok
DROP FUNCTION f_insert;
DROP FUNCTION f_select;
DROP FUNCTION f_update;
DROP FUNCTION f_delete;
DROP USER test_user;

subtest end
2 changes: 2 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/udf_update
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# LogicTest: !local-mixed-22.2-23.1

statement ok
CREATE TABLE t (a INT PRIMARY KEY, b INT);

Expand Down
2 changes: 2 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/udf_upsert
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# LogicTest: !local-mixed-22.2-23.1

subtest on_conflict_do_nothing

statement ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ go_test(
"//pkg/sql/logictest:testdata", # keep
],
exec_properties = {"Pool": "large"},
shard_count = 16,
shard_count = 17,
tags = [
"cpu:2",
],
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 619aa6e

Please sign in to comment.