Skip to content

Commit

Permalink
sql,clusterversion: add a cluster version for procedures
Browse files Browse the repository at this point in the history
Release note: None
  • Loading branch information
mgartner committed Oct 7, 2023
1 parent 6a89db6 commit 6c60444
Show file tree
Hide file tree
Showing 16 changed files with 174 additions and 101 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 @@ -317,4 +317,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-32 set the active cluster version in the format '<major>.<minor>' application
version version 1000023.1-34 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 @@ -269,6 +269,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-32</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-34</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>
8 changes: 7 additions & 1 deletion pkg/clusterversion/cockroach_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,9 @@ const (
// {statement|transaction}_execution_insights system tables.
V23_2_AddSystemExecInsightsTable

// V23_2_Procedures is the version where procedures are enabled.
V23_2_Procedures

// *************************************************
// Step (1) Add new versions here.
// Do not add new versions to a patch release.
Expand Down Expand Up @@ -855,11 +858,14 @@ var rawVersionsSingleton = keyedVersions{
Key: V23_2_MVCCStatisticsTable,
Version: roachpb.Version{Major: 23, Minor: 1, Internal: 30},
},

{
Key: V23_2_AddSystemExecInsightsTable,
Version: roachpb.Version{Major: 23, Minor: 1, Internal: 32},
},
{
Key: V23_2_Procedures,
Version: roachpb.Version{Major: 23, Minor: 1, Internal: 34},
},

// *************************************************
// Step (2): Add new versions here.
Expand Down
149 changes: 81 additions & 68 deletions pkg/sql/logictest/testdata/logic_test/crdb_internal
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,7 @@ CREATE FUNCTION f(STRING, b INT) RETURNS STRING STRICT IMMUTABLE LEAKPROOF LANGU

# Add a procedure to ensure that it doesn't show up in the
# create_function_statements table.
skipif config local-mixed-22.2-23.1
statement ok
CREATE PROCEDURE f(BOOL) LANGUAGE SQL AS $$ SELECT 1 $$;

Expand All @@ -1467,93 +1468,96 @@ CREATE SCHEMA sc;
statement
CREATE FUNCTION sc.f2(STRING) RETURNS STRING LANGUAGE SQL AS $$ SELECT 'hello' $$;

query ITITITT
SELECT database_id, database_name, schema_id, schema_name, function_id, function_name, create_statement
query TTTT
SELECT database_name, schema_name, function_name, create_statement
FROM crdb_internal.create_function_statements
WHERE function_name IN ('f', 'f2')
ORDER BY function_id;
----
104 test 105 public 129 f CREATE FUNCTION public.f(IN INT8)
RETURNS INT8
VOLATILE
NOT LEAKPROOF
CALLED ON NULL INPUT
LANGUAGE SQL
AS $$
SELECT 1;
$$
104 test 105 public 130 f CREATE FUNCTION public.f(IN STRING, IN b INT8)
RETURNS STRING
IMMUTABLE
LEAKPROOF
STRICT
LANGUAGE SQL
AS $$
SELECT 'hello';
$$
104 test 132 sc 133 f2 CREATE FUNCTION sc.f2(IN STRING)
RETURNS STRING
VOLATILE
NOT LEAKPROOF
CALLED ON NULL INPUT
LANGUAGE SQL
AS $$
SELECT 'hello';
$$
test public f CREATE FUNCTION public.f(IN INT8)
RETURNS INT8
VOLATILE
NOT LEAKPROOF
CALLED ON NULL INPUT
LANGUAGE SQL
AS $$
SELECT 1;
$$
test public f CREATE FUNCTION public.f(IN STRING, IN b INT8)
RETURNS STRING
IMMUTABLE
LEAKPROOF
STRICT
LANGUAGE SQL
AS $$
SELECT 'hello';
$$
test sc f2 CREATE FUNCTION sc.f2(IN STRING)
RETURNS STRING
VOLATILE
NOT LEAKPROOF
CALLED ON NULL INPUT
LANGUAGE SQL
AS $$
SELECT 'hello';
$$

statement ok
CREATE DATABASE test_cross_db;
USE test_cross_db;
CREATE FUNCTION f_cross_db() RETURNS INT LANGUAGE SQL AS $$ SELECT 1 $$;
USE test;

query ITITITT
SELECT database_id, database_name, schema_id, schema_name, function_id, function_name, create_statement
query TTTT
SELECT database_name, schema_name, function_name, create_statement
FROM "".crdb_internal.create_function_statements
WHERE function_name IN ('f', 'f2', 'f_cross_db')
ORDER BY function_id;
----
104 test 105 public 129 f CREATE FUNCTION public.f(IN INT8)
RETURNS INT8
VOLATILE
NOT LEAKPROOF
CALLED ON NULL INPUT
LANGUAGE SQL
AS $$
SELECT 1;
$$
104 test 105 public 130 f CREATE FUNCTION public.f(IN STRING, IN b INT8)
RETURNS STRING
IMMUTABLE
LEAKPROOF
STRICT
LANGUAGE SQL
AS $$
SELECT 'hello';
$$
104 test 132 sc 133 f2 CREATE FUNCTION sc.f2(IN STRING)
RETURNS STRING
VOLATILE
NOT LEAKPROOF
CALLED ON NULL INPUT
LANGUAGE SQL
AS $$
SELECT 'hello';
$$
134 test_cross_db 135 public 136 f_cross_db CREATE FUNCTION public.f_cross_db()
RETURNS INT8
VOLATILE
NOT LEAKPROOF
CALLED ON NULL INPUT
LANGUAGE SQL
AS $$
SELECT 1;
$$
test public f CREATE FUNCTION public.f(IN INT8)
RETURNS INT8
VOLATILE
NOT LEAKPROOF
CALLED ON NULL INPUT
LANGUAGE SQL
AS $$
SELECT 1;
$$
test public f CREATE FUNCTION public.f(IN STRING, IN b INT8)
RETURNS STRING
IMMUTABLE
LEAKPROOF
STRICT
LANGUAGE SQL
AS $$
SELECT 'hello';
$$
test sc f2 CREATE FUNCTION sc.f2(IN STRING)
RETURNS STRING
VOLATILE
NOT LEAKPROOF
CALLED ON NULL INPUT
LANGUAGE SQL
AS $$
SELECT 'hello';
$$
test_cross_db public f_cross_db CREATE FUNCTION public.f_cross_db()
RETURNS INT8
VOLATILE
NOT LEAKPROOF
CALLED ON NULL INPUT
LANGUAGE SQL
AS $$
SELECT 1;
$$

skipif config local-mixed-22.2-23.1
statement ok
DROP PROCEDURE f(BOOL);

statement ok
DROP FUNCTION f(INT);
DROP FUNCTION f(STRING, INT);
DROP PROCEDURE f(BOOL);
DROP FUNCTION sc.f2(STRING);
DROP SCHEMA sc;
USE test_cross_db;
Expand All @@ -1566,23 +1570,29 @@ subtest end

subtest create_procedure_statements

skipif config local-mixed-22.2-23.1
statement ok
CREATE PROCEDURE p(INT) LANGUAGE SQL AS $$ SELECT 1 $$;

skipif config local-mixed-22.2-23.1
statement ok
CREATE PROCEDURE p(STRING, b INT) LANGUAGE SQL AS $$ SELECT 'hello' $$;

# Add a function to ensure that it doesn't show up in the
# create_procedure_statements table.
skipif config local-mixed-22.2-23.1
statement ok
CREATE FUNCTION p(BOOL) RETURNS INT LANGUAGE SQL AS $$ SELECT 1 $$;

skipif config local-mixed-22.2-23.1
statement ok
CREATE SCHEMA sc;

skipif config local-mixed-22.2-23.1
statement
CREATE PROCEDURE sc.p2(STRING) LANGUAGE SQL AS $$ SELECT 'hello' $$;

skipif config local-mixed-22.2-23.1
query ITITITT
SELECT database_id, database_name, schema_id, schema_name, procedure_id, procedure_name, create_statement
FROM crdb_internal.create_procedure_statements
Expand All @@ -1605,12 +1615,14 @@ ORDER BY procedure_id;
SELECT 'hello';
$$

skipif config local-mixed-22.2-23.1
statement ok
CREATE DATABASE test_cross_db;
USE test_cross_db;
CREATE PROCEDURE p_cross_db() LANGUAGE SQL AS $$ SELECT 1 $$;
USE test;

skipif config local-mixed-22.2-23.1
query ITITITT
SELECT database_id, database_name, schema_id, schema_name, procedure_id, procedure_name, create_statement
FROM "".crdb_internal.create_procedure_statements
Expand Down Expand Up @@ -1638,6 +1650,7 @@ ORDER BY procedure_id;
SELECT 1;
$$

skipif config local-mixed-22.2-23.1
statement ok
DROP PROCEDURE p(INT);
DROP PROCEDURE p(STRING, INT);
Expand Down
2 changes: 2 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/drop_procedure
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# LogicTest: !local-mixed-22.2-23.1

statement ok
CREATE PROCEDURE p_test_drop() LANGUAGE SQL AS 'SELECT 1'

Expand Down
49 changes: 49 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/mixed_version_procedure
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# LogicTest: cockroach-go-testserver-upgrade-to-master

# Verify that all nodes are running the previous version.

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

upgrade 0

user root nodeidx=0

# Creating a procedure should fail with an unimplemented error.
statement error unimplemented: procedures are not yet supported
CREATE PROCEDURE p() LANGUAGE SQL AS 'SELECT 1'

user root nodeidx=1

# These statements should fail with a parsing error.
statement error at or near "procedure": syntax error
CREATE PROCEDURE p() LANGUAGE SQL AS 'SELECT 1'

# Upgrade all nodes.

upgrade 1

upgrade 2

# Makes sure the upgrade job has finished, and the cluster version gate is
# passed.
query B retry
SELECT crdb_internal.is_at_least_version('23.1-32')
----
true

# Creating a procedure should now be possible.
statement ok
CREATE PROCEDURE p() LANGUAGE SQL AS 'SELECT 1'
2 changes: 2 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/procedure
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# LogicTest: !local-mixed-22.2-23.1

statement ok
CREATE PROCEDURE p() LANGUAGE SQL AS 'SELECT 1'

Expand Down
2 changes: 2 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/procedure_plpgsql
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 (
k INT PRIMARY KEY,
Expand Down
2 changes: 2 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/procedure_privileges
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# LogicTest: !local-mixed-22.2-23.1

subtest grant_revoke

statement ok
Expand Down
6 changes: 6 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/show_create
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,11 @@ CREATE FUNCTION r1() RETURNS INT LANGUAGE SQL AS 'SELECT 1'
statement ok
CREATE FUNCTION r1(i INT) RETURNS INT LANGUAGE SQL AS 'SELECT 1'

skipif config local-mixed-22.2-23.1
statement ok
CREATE PROCEDURE r1(s STRING) LANGUAGE SQL AS 'SELECT 1'

skipif config local-mixed-22.2-23.1
statement ok
CREATE PROCEDURE r1(s STRING, i INT) LANGUAGE SQL AS 'SELECT 1'

Expand All @@ -233,6 +235,7 @@ r1 CREATE FUNCTION public.r1(IN i INT8)
SELECT 1;
$$

skipif config local-mixed-22.2-23.1
query TT
SELECT * FROM [SHOW CREATE PROCEDURE r1] ORDER BY 2
----
Expand All @@ -253,12 +256,14 @@ CREATE SCHEMA sc
statement ok
CREATE FUNCTION sc.r2() RETURNS INT LANGUAGE SQL AS 'SELECT 1'

skipif config local-mixed-22.2-23.1
statement ok
CREATE PROCEDURE sc.r2(s STRING) LANGUAGE SQL AS 'SELECT 1'

statement error pgcode 42883 pq: unknown function: r2()
SHOW CREATE FUNCTION r2;

skipif config local-mixed-22.2-23.1
statement error pgcode 42883 pq: unknown procedure: r2()
SHOW CREATE PROCEDURE r2;

Expand All @@ -278,6 +283,7 @@ r2 CREATE FUNCTION sc.r2()
SELECT 1;
$$

skipif config local-mixed-22.2-23.1
query TT
SHOW CREATE PROCEDURE r2
----
Expand Down
7 changes: 6 additions & 1 deletion pkg/sql/logictest/testdata/logic_test/udf_privileges
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,13 @@ CREATE SCHEMA sc_test_show_grants;
SET search_path = sc_test_show_grants;
CREATE FUNCTION f_test_show_grants(INT) RETURNS INT LANGUAGE SQL AS $$ SELECT 1 $$;
CREATE FUNCTION f_test_show_grants(INT, string, OID) RETURNS INT LANGUAGE SQL AS $$ SELECT 1 $$;
CREATE PROCEDURE test_priv_p() LANGUAGE SQL AS $$ SELECT 1 $$;
CREATE USER u_test_show_grants;

skipif config local-mixed-22.2-23.1
statement ok
CREATE PROCEDURE test_priv_p() LANGUAGE SQL AS $$ SELECT 1 $$;

statement ok
GRANT EXECUTE ON FUNCTION f_test_show_grants(INT), f_test_show_grants(INT, string, OID) TO u_test_show_grants;

statement error pgcode 42725 pq: function name "f_test_show_grants" is not unique
Expand Down
Loading

0 comments on commit 6c60444

Please sign in to comment.