Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
111330: plpgsql: implement CLOSE statements r=DrewKimball a=DrewKimball

#### plpgsql: add builtin function for closing cursors

This patch adds the `crdb_internal.plpgsql_close` builtin, which closes
the cursor with the given name. It returns a `34000` error if there is
no cursor with the given name. A following commit will use this to
implement the PLpgSQL CLOSE statement.

Informs #109709

Release note: None

#### plpgsql: implement CLOSE statements

This patch implements the PLpgSQL CLOSE statement, which allows a
PLpgSQL routine to close a cursor with the name specified by a cursor
variable. Closing the cursor is handled by the internal builtin function
`crdb_internal.plpgsql_close`.

Informs #109709

Release note (sql change): Added support for the PLpgSQL CLOSE statement.

111597: sql: add support for SHOW CREATE PROCEDURE r=mgartner a=mgartner

#### sql/tree: rename ShowCreateFunction to ShowCreateRoutine

Release note: None

#### sql/logictest: move create_function_statements tests to crdb_internal

Release note: None

#### sql: add crdb_internal.show_procedure_statements

This commit adds the `crdb_internal.show_procedure_statements` table. It
is very similar to the `show_function_statements` table, but it shows
procedures instead of user-defined functions.

Release note: None

#### sql: add SHOW CREATE PROCEDURE

This commit adds support for the `SHOW CREATE PROCEDURE` statement.

Epic: CRDB-25388

Release note: None


111617: storage: reduce MVCCValueMerger allocations r=jbowens a=jbowens

These commits address the first four items of #106567.

```
               │   old.txt    │               new.txt               │
               │    sec/op    │    sec/op     vs base               │
ServerQuery-10   1.484m ± ∞ ¹   1.180m ± ∞ ¹  -20.49% (p=0.008 n=5)
¹ need >= 6 samples for confidence interval at level 0.95

               │    old.txt    │               new.txt               │
               │     B/op      │     B/op       vs base              │
ServerQuery-10   1.581Mi ± ∞ ¹   1.434Mi ± ∞ ¹  -9.27% (p=0.008 n=5)
¹ need >= 6 samples for confidence interval at level 0.95

               │   old.txt    │               new.txt               │
               │  allocs/op   │  allocs/op    vs base               │
ServerQuery-10   18.55k ± ∞ ¹   15.98k ± ∞ ¹  -13.89% (p=0.008 n=5)
```



111759: backupccl,delegate: change SHOW SCHEDULES columns for schedule options r=msbutler a=adityamaru

For 23.2 we added two columns to `SHOW SCHEDULES` that surfaces the values for the schedule options corresponding to `on_previous_running` and `on_execution_failure`. These column names were previously named `on_wait` and `on_error` since those were the internal proto names. It makes more sense to align these with the publically documented option names.

Epic: none
Release note (sql change): `SHOW SCHEDULES` has two columns that surface the schedule options. These columns have been renamed to align with the documented option names namely `on_previous_running` and `on_execution_failure`.

111771: .gitignore: ignore `embedded.go` files that are no longer generated r=rail a=rickystewart

Epic: none
Release note: None

Co-authored-by: Drew Kimball <[email protected]>
Co-authored-by: Marcus Gartner <[email protected]>
Co-authored-by: Jackson Owens <[email protected]>
Co-authored-by: adityamaru <[email protected]>
Co-authored-by: Ricky Stewart <[email protected]>
  • Loading branch information
6 people committed Oct 4, 2023
6 parents 2da2993 + d2070e5 + 47157fd + 057e992 + a62f127 + d975845 commit fd181dd
Show file tree
Hide file tree
Showing 56 changed files with 1,633 additions and 1,012 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ build/Railroad.jar
# Generated code.
*.pb.go
*.pb.gw.go
pkg/roachprod/vm/aws/embedded.go
pkg/security/securitytest/embedded.go
pkg/ccl/kvccl/kvtenantccl/upgradeinterlockccl/generated_test.go
pkg/ccl/backupccl/data_driven_generated_test.go
pkg/ccl/backupccl/restore_memory_monitoring_generated_test.go
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ alter backup schedule $fullID set schedule option on_previous_running = 'start';
----

query-sql
select on_error, on_wait
select on_execution_failure, on_previous_running
from [show schedules for backup]
where id in ($fullID, $incID)
order by backup_type asc;
Expand All @@ -57,7 +57,7 @@ alter backup schedule $fullID set schedule option on_previous_running = 'skip';
----

query-sql
select on_error, on_wait
select on_execution_failure, on_previous_running
from [show schedules for backup]
where id in ($fullID, $incID)
order by backup_type asc;
Expand All @@ -70,7 +70,7 @@ alter backup schedule $fullID set schedule option on_previous_running = 'wait';
----

query-sql
select on_error, on_wait
select on_execution_failure, on_previous_running
from [show schedules for backup]
where id in ($fullID, $incID)
order by backup_type asc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ crdb_internal cluster_transaction_statistics table node NULL NULL
crdb_internal cluster_transactions table node NULL NULL
crdb_internal cluster_txn_execution_insights table node NULL NULL
crdb_internal create_function_statements table node NULL NULL
crdb_internal create_procedure_statements table node NULL NULL
crdb_internal create_schema_statements table node NULL NULL
crdb_internal create_statements table node NULL NULL
crdb_internal create_type_statements table node NULL NULL
Expand Down
1 change: 1 addition & 0 deletions pkg/cli/testdata/zip/partial1
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ debug zip --concurrency=1 --cpu-profile-duration=0s /dev/null
[cluster] requesting data for debug/settings... received response... writing JSON output: debug/settings.json... done
[cluster] requesting data for debug/reports/problemranges... received response... writing JSON output: debug/reports/problemranges.json... done
[cluster] retrieving SQL data for "".crdb_internal.create_function_statements... writing output: debug/crdb_internal.create_function_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_procedure_statements... writing output: debug/crdb_internal.create_procedure_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_schema_statements... writing output: debug/crdb_internal.create_schema_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_statements... writing output: debug/crdb_internal.create_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_type_statements... writing output: debug/crdb_internal.create_type_statements.txt... done
Expand Down
1 change: 1 addition & 0 deletions pkg/cli/testdata/zip/partial1_excluded
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ debug zip /dev/null --concurrency=1 --exclude-nodes=2 --cpu-profile-duration=0
[cluster] requesting data for debug/settings... received response... writing JSON output: debug/settings.json... done
[cluster] requesting data for debug/reports/problemranges... received response... writing JSON output: debug/reports/problemranges.json... done
[cluster] retrieving SQL data for "".crdb_internal.create_function_statements... writing output: debug/crdb_internal.create_function_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_procedure_statements... writing output: debug/crdb_internal.create_procedure_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_schema_statements... writing output: debug/crdb_internal.create_schema_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_statements... writing output: debug/crdb_internal.create_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_type_statements... writing output: debug/crdb_internal.create_type_statements.txt... done
Expand Down
1 change: 1 addition & 0 deletions pkg/cli/testdata/zip/partial2
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ debug zip --concurrency=1 --cpu-profile-duration=0 /dev/null
[cluster] requesting data for debug/settings... received response... writing JSON output: debug/settings.json... done
[cluster] requesting data for debug/reports/problemranges... received response... writing JSON output: debug/reports/problemranges.json... done
[cluster] retrieving SQL data for "".crdb_internal.create_function_statements... writing output: debug/crdb_internal.create_function_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_procedure_statements... writing output: debug/crdb_internal.create_procedure_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_schema_statements... writing output: debug/crdb_internal.create_schema_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_statements... writing output: debug/crdb_internal.create_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_type_statements... writing output: debug/crdb_internal.create_type_statements.txt... done
Expand Down
1 change: 1 addition & 0 deletions pkg/cli/testdata/zip/testzip
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ debug zip --concurrency=1 --cpu-profile-duration=1s /dev/null
[cluster] requesting data for debug/settings... received response... writing JSON output: debug/settings.json... done
[cluster] requesting data for debug/reports/problemranges... received response... writing JSON output: debug/reports/problemranges.json... done
[cluster] retrieving SQL data for "".crdb_internal.create_function_statements... writing output: debug/crdb_internal.create_function_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_procedure_statements... writing output: debug/crdb_internal.create_procedure_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_schema_statements... writing output: debug/crdb_internal.create_schema_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_statements... writing output: debug/crdb_internal.create_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_type_statements... writing output: debug/crdb_internal.create_type_statements.txt... done
Expand Down
3 changes: 3 additions & 0 deletions pkg/cli/testdata/zip/testzip_concurrent
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ zip
[cluster] retrieving SQL data for "".crdb_internal.create_function_statements...
[cluster] retrieving SQL data for "".crdb_internal.create_function_statements: done
[cluster] retrieving SQL data for "".crdb_internal.create_function_statements: writing output: debug/crdb_internal.create_function_statements.txt...
[cluster] retrieving SQL data for "".crdb_internal.create_procedure_statements...
[cluster] retrieving SQL data for "".crdb_internal.create_procedure_statements: done
[cluster] retrieving SQL data for "".crdb_internal.create_procedure_statements: writing output: debug/crdb_internal.create_procedure_statements.txt...
[cluster] retrieving SQL data for "".crdb_internal.create_schema_statements...
[cluster] retrieving SQL data for "".crdb_internal.create_schema_statements: done
[cluster] retrieving SQL data for "".crdb_internal.create_schema_statements: writing output: debug/crdb_internal.create_schema_statements.txt...
Expand Down
1 change: 1 addition & 0 deletions pkg/cli/testdata/zip/testzip_exclude_goroutine_stacks
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ debug zip --concurrency=1 --cpu-profile-duration=1s --include-goroutine-stacks=f
[cluster] requesting data for debug/settings... received response... writing JSON output: debug/settings.json... done
[cluster] requesting data for debug/reports/problemranges... received response... writing JSON output: debug/reports/problemranges.json... done
[cluster] retrieving SQL data for "".crdb_internal.create_function_statements... writing output: debug/crdb_internal.create_function_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_procedure_statements... writing output: debug/crdb_internal.create_procedure_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_schema_statements... writing output: debug/crdb_internal.create_schema_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_statements... writing output: debug/crdb_internal.create_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_type_statements... writing output: debug/crdb_internal.create_type_statements.txt... done
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ debug zip --concurrency=1 --cpu-profile-duration=1s /dev/null
[cluster] requesting data for debug/reports/problemranges: last request failed: rpc error: ...
[cluster] requesting data for debug/reports/problemranges: creating error output: debug/reports/problemranges.json.err.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_function_statements... writing output: debug/crdb_internal.create_function_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_procedure_statements... writing output: debug/crdb_internal.create_procedure_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_schema_statements... writing output: debug/crdb_internal.create_schema_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_statements... writing output: debug/crdb_internal.create_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_type_statements... writing output: debug/crdb_internal.create_type_statements.txt... done
Expand Down
1 change: 1 addition & 0 deletions pkg/cli/testdata/zip/testzip_include_goroutine_stacks
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ debug zip --concurrency=1 --cpu-profile-duration=1s /dev/null
[cluster] requesting data for debug/settings... received response... writing JSON output: debug/settings.json... done
[cluster] requesting data for debug/reports/problemranges... received response... writing JSON output: debug/reports/problemranges.json... done
[cluster] retrieving SQL data for "".crdb_internal.create_function_statements... writing output: debug/crdb_internal.create_function_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_procedure_statements... writing output: debug/crdb_internal.create_procedure_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_schema_statements... writing output: debug/crdb_internal.create_schema_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_statements... writing output: debug/crdb_internal.create_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_type_statements... writing output: debug/crdb_internal.create_type_statements.txt... done
Expand Down
1 change: 1 addition & 0 deletions pkg/cli/testdata/zip/testzip_include_range_info
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ debug zip --concurrency=1 --cpu-profile-duration=1s --include-range-info /dev/nu
[cluster] requesting data for debug/settings... received response... writing JSON output: debug/settings.json... done
[cluster] requesting data for debug/reports/problemranges... received response... writing JSON output: debug/reports/problemranges.json... done
[cluster] retrieving SQL data for "".crdb_internal.create_function_statements... writing output: debug/crdb_internal.create_function_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_procedure_statements... writing output: debug/crdb_internal.create_procedure_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_schema_statements... writing output: debug/crdb_internal.create_schema_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_statements... writing output: debug/crdb_internal.create_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_type_statements... writing output: debug/crdb_internal.create_type_statements.txt... done
Expand Down
2 changes: 2 additions & 0 deletions pkg/cli/testdata/zip/testzip_shared_process_virtualization
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ debug zip --concurrency=1 --cpu-profile-duration=1s /dev/null
[cluster] requesting data for debug/settings... received response... writing JSON output: debug/settings.json... done
[cluster] requesting data for debug/reports/problemranges... received response... writing JSON output: debug/reports/problemranges.json... done
[cluster] retrieving SQL data for "".crdb_internal.create_function_statements... writing output: debug/crdb_internal.create_function_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_procedure_statements... writing output: debug/crdb_internal.create_procedure_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_schema_statements... writing output: debug/crdb_internal.create_schema_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_statements... writing output: debug/crdb_internal.create_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_type_statements... writing output: debug/crdb_internal.create_type_statements.txt... done
Expand Down Expand Up @@ -134,6 +135,7 @@ debug zip --concurrency=1 --cpu-profile-duration=1s /dev/null
[cluster] requesting data for debug/cluster/test-tenant/reports/problemranges: last request failed: rpc error: ...
[cluster] requesting data for debug/cluster/test-tenant/reports/problemranges: creating error output: debug/cluster/test-tenant/reports/problemranges.json.err.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_function_statements... writing output: debug/cluster/test-tenant/crdb_internal.create_function_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_procedure_statements... writing output: debug/cluster/test-tenant/crdb_internal.create_procedure_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_schema_statements... writing output: debug/cluster/test-tenant/crdb_internal.create_schema_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_statements... writing output: debug/cluster/test-tenant/crdb_internal.create_statements.txt... done
[cluster] retrieving SQL data for "".crdb_internal.create_type_statements... writing output: debug/cluster/test-tenant/crdb_internal.create_type_statements.txt... done
Expand Down
10 changes: 10 additions & 0 deletions pkg/cli/zip_table_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,16 @@ var zipInternalTablesPerCluster = DebugZipTableRegistry{
"crdb_internal.hide_sql_constants(create_statement) as create_statement",
},
},
`"".crdb_internal.create_procedure_statements`: {
nonSensitiveCols: NonSensitiveColumns{
"database_id",
"database_name",
"schema_id",
"procedure_id",
"procedure_name",
"crdb_internal.hide_sql_constants(create_statement) as create_statement",
},
},
// The synthetic SQL CREATE statements for all tables.
// Note the "". to collect across all databases.
`"".crdb_internal.create_schema_statements`: {
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/alter_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ func toSchemaOverloadSignature(fnDesc *funcdesc.Mutable) descpb.SchemaDescriptor
ArgTypes: make([]*types.T, len(fnDesc.GetParams())),
ReturnType: fnDesc.ReturnType.Type,
ReturnSet: fnDesc.ReturnType.ReturnSet,
IsProcedure: fnDesc.IsProcedure,
IsProcedure: fnDesc.IsProcedure(),
}
for i := range fnDesc.Params {
ret.ArgTypes[i] = fnDesc.Params[i].Type
Expand Down
9 changes: 7 additions & 2 deletions pkg/sql/catalog/descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -974,9 +974,14 @@ type FunctionDescriptor interface {
// GetLanguage returns the language of this function.
GetLanguage() catpb.Function_Language

// ToCreateExpr converts a function descriptor back to a CREATE FUNCTION
// statement. This is mainly used for formatting, e.g. SHOW CREATE FUNCTION.
// ToCreateExpr converts a function descriptor back to a CREATE FUNCTION or
// CREATE PROCEDURE statement. This is mainly used for formatting, e.g.,
// SHOW CREATE FUNCTION and SHOW CREATE PROCEDURE.
ToCreateExpr() (*tree.CreateRoutine, error)

// IsProcedure returns true if the descriptor represents a procedure. It
// returns false if the descriptor represents a user-defined function.
IsProcedure() bool
}

// FilterDroppedDescriptor returns an error if the descriptor state is DROP.
Expand Down
12 changes: 9 additions & 3 deletions pkg/sql/catalog/funcdesc/func_desc.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ func (desc *immutable) GetObjectType() privilege.ObjectType {

// GetObjectTypeString implements the Object interface.
func (desc *immutable) GetObjectTypeString() string {
if desc.IsProcedure {
if desc.IsProcedure() {
return "procedure"
}
return "function"
Expand All @@ -699,7 +699,7 @@ func (desc *immutable) GetLanguage() catpb.Function_Language {

func (desc *immutable) ToOverload() (ret *tree.Overload, err error) {
routineType := tree.UDFRoutine
if desc.IsProcedure {
if desc.IsProcedure() {
routineType = tree.ProcedureRoutine
}
ret = &tree.Overload{
Expand Down Expand Up @@ -773,7 +773,8 @@ func (desc *immutable) calledOnNullInput() (bool, error) {
// ToCreateExpr implements the FunctionDescriptor interface.
func (desc *immutable) ToCreateExpr() (ret *tree.CreateRoutine, err error) {
ret = &tree.CreateRoutine{
Name: tree.MakeRoutineNameFromPrefix(tree.ObjectNamePrefix{}, tree.Name(desc.Name)),
Name: tree.MakeRoutineNameFromPrefix(tree.ObjectNamePrefix{}, tree.Name(desc.Name)),
IsProcedure: desc.IsProcedure(),
ReturnType: tree.RoutineReturnType{
Type: desc.ReturnType.Type,
SetOf: desc.ReturnType.ReturnSet,
Expand Down Expand Up @@ -804,6 +805,11 @@ func (desc *immutable) ToCreateExpr() (ret *tree.CreateRoutine, err error) {
return ret, nil
}

// IsProcedure implements the FunctionDescriptor interface.
func (desc *immutable) IsProcedure() bool {
return desc.FunctionDescriptor.IsProcedure
}

func (desc *immutable) getCreateExprLang() tree.RoutineLanguage {
switch desc.Lang {
case catpb.Function_SQL:
Expand Down
Loading

0 comments on commit fd181dd

Please sign in to comment.