forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
22 changed files
with
283 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
pkg/sql/logictest/testdata/logic_test/mixed_version_udf_mutations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
pkg/sql/logictest/testdata/logic_test/udf_privileges_mutations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
pkg/sql/logictest/tests/cockroach-go-testserver-upgrade-to-master/generated_test.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.