Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: populate information_schema.routines and parameters #105944

Merged
merged 5 commits into from Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/generated/sql/functions.md
Expand Up @@ -3587,6 +3587,8 @@ table. Returns an error if validation fails.</p>
</span></td><td>Immutable</td></tr>
<tr><td><a name="information_schema._pg_numeric_scale"></a><code>information_schema._pg_numeric_scale(typid: oid, typmod: int4) &rarr; <a href="int.html">int</a></code></td><td><span class="funcdesc"><p>Returns the scale of the given type with type modifier</p>
</span></td><td>Immutable</td></tr>
<tr><td><a name="nameconcatoid"></a><code>nameconcatoid(name: <a href="string.html">string</a>, oid: oid) &rarr; name</code></td><td><span class="funcdesc"><p>Used in the information_schema to produce specific_name columns, which are supposed to be unique per schema. The result is the same as ($1::text || ‘_’ || $2::text)::name except that, if it would not fit in 63 characters, we make it do so by truncating the name input (not the oid).</p>
</span></td><td>Immutable</td></tr>
<tr><td><a name="obj_description"></a><code>obj_description(object_oid: oid) &rarr; <a href="string.html">string</a></code></td><td><span class="funcdesc"><p>Returns the comment for a database object specified by its OID alone. This is deprecated since there is no guarantee that OIDs are unique across different system catalogs; therefore, the wrong comment might be returned.</p>
</span></td><td>Stable</td></tr>
<tr><td><a name="obj_description"></a><code>obj_description(object_oid: oid, catalog_name: <a href="string.html">string</a>) &rarr; <a href="string.html">string</a></code></td><td><span class="funcdesc"><p>Returns the comment for a database object specified by its OID and the name of the containing system catalog. For example, obj_description(123456, ‘pg_class’) would retrieve the comment for the table with OID 123456.</p>
Expand All @@ -3601,6 +3603,8 @@ table. Returns an error if validation fails.</p>
</span></td><td>Immutable</td></tr>
<tr><td><a name="pg_function_is_visible"></a><code>pg_function_is_visible(oid: oid) &rarr; <a href="bool.html">bool</a></code></td><td><span class="funcdesc"><p>Returns whether the function with the given OID belongs to one of the schemas on the search path.</p>
</span></td><td>Stable</td></tr>
<tr><td><a name="pg_get_function_arg_default"></a><code>pg_get_function_arg_default(func_oid: oid, arg_num: int4) &rarr; <a href="string.html">string</a></code></td><td><span class="funcdesc"><p>Get textual representation of a function argument’s default value. The second argument of this function is the argument number among all arguments (i.e. proallargtypes, <em>not</em> proargtypes), starting with 1, because that’s how information_schema.sql uses it. Currently, this always returns NULL, since CockroachDB does not support default values.</p>
</span></td><td>Stable</td></tr>
<tr><td><a name="pg_get_function_arguments"></a><code>pg_get_function_arguments(func_oid: oid) &rarr; <a href="string.html">string</a></code></td><td><span class="funcdesc"><p>Returns the argument list (with defaults) necessary to identify a function, in the form it would need to appear in within CREATE FUNCTION.</p>
</span></td><td>Stable</td></tr>
<tr><td><a name="pg_get_function_identity_arguments"></a><code>pg_get_function_identity_arguments(func_oid: oid) &rarr; <a href="string.html">string</a></code></td><td><span class="funcdesc"><p>Returns the argument list (without defaults) necessary to identify a function, in the form it would need to appear in within ALTER FUNCTION, for instance.</p>
Expand Down
4 changes: 2 additions & 2 deletions pkg/cli/clisqlshell/testdata/describe
Expand Up @@ -585,13 +585,13 @@ https://www.postgresql.org/docs/9.5/view-pg-indexes.html"
pg_catalog,pg_inherits,table,admin,NULL,permanent,prefix,"table inheritance hierarchy (empty - feature does not exist)
https://www.postgresql.org/docs/9.5/catalog-pg-inherits.html"
pg_catalog,pg_init_privs,table,admin,NULL,permanent,prefix,pg_init_privs was created for compatibility and is currently unimplemented
pg_catalog,pg_language,table,admin,NULL,permanent,prefix,"available languages (empty - feature does not exist)
pg_catalog,pg_language,table,admin,NULL,permanent,prefix,"available languages
https://www.postgresql.org/docs/9.5/catalog-pg-language.html"
pg_catalog,pg_largeobject,table,admin,NULL,permanent,prefix,pg_largeobject was created for compatibility and is currently unimplemented
pg_catalog,pg_largeobject_metadata,table,admin,NULL,permanent,prefix,pg_largeobject_metadata was created for compatibility and is currently unimplemented
pg_catalog,pg_locks,table,admin,NULL,permanent,prefix,"locks held by active processes (empty - feature does not exist)
https://www.postgresql.org/docs/9.6/view-pg-locks.html"
pg_catalog,pg_matviews,table,admin,NULL,permanent,prefix,"available materialized views (empty - feature does not exist)
pg_catalog,pg_matviews,table,admin,NULL,permanent,prefix,"available materialized views
https://www.postgresql.org/docs/9.6/view-pg-matviews.html"
pg_catalog,pg_namespace,table,admin,NULL,permanent,prefix,"available namespaces
https://www.postgresql.org/docs/9.5/catalog-pg-namespace.html"
Expand Down
133 changes: 122 additions & 11 deletions pkg/sql/information_schema.go
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/catalog"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkeys"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/catenumpb"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/colinfo"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/nstree"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/schemadesc"
Expand Down Expand Up @@ -856,14 +857,44 @@ https://www.postgresql.org/docs/9.5/infoschema-key-column-usage.html`,

// Postgres: https://www.postgresql.org/docs/9.6/static/infoschema-parameters.html
// MySQL: https://dev.mysql.com/doc/refman/5.7/en/parameters-table.html
var informationSchemaParametersTable = virtualSchemaTable{
comment: `built-in function parameters (empty - introspection not yet supported)
var informationSchemaParametersTable = virtualSchemaView{
comment: `function parameters
https://www.postgresql.org/docs/9.5/infoschema-parameters.html`,
schema: vtable.InformationSchemaParameters,
populate: func(ctx context.Context, p *planner, dbContext catalog.DatabaseDescriptor, addRow func(...tree.Datum) error) error {
return nil
resultColumns: colinfo.ResultColumns{
{Name: "specific_catalog", Typ: types.String},
{Name: "specific_schema", Typ: types.String},
{Name: "specific_name", Typ: types.String},
{Name: "ordinal_position", Typ: types.Int},
{Name: "parameter_mode", Typ: types.String},
{Name: "is_result", Typ: types.String},
{Name: "as_locator", Typ: types.String},
{Name: "parameter_name", Typ: types.String},
{Name: "data_type", Typ: types.String},
{Name: "character_maximum_length", Typ: types.Int},
{Name: "character_octet_length", Typ: types.Int},
{Name: "character_set_catalog", Typ: types.String},
{Name: "character_set_schema", Typ: types.String},
{Name: "character_set_name", Typ: types.String},
{Name: "collation_catalog", Typ: types.String},
{Name: "collation_schema", Typ: types.String},
{Name: "collation_name", Typ: types.String},
{Name: "numeric_precision", Typ: types.Int},
{Name: "numeric_precision_radix", Typ: types.Int},
{Name: "numeric_scale", Typ: types.Int},
{Name: "datetime_precision", Typ: types.Int},
{Name: "interval_type", Typ: types.String},
{Name: "interval_precision", Typ: types.Int},
{Name: "udt_catalog", Typ: types.String},
{Name: "udt_schema", Typ: types.String},
{Name: "udt_name", Typ: types.String},
{Name: "scope_catalog", Typ: types.String},
{Name: "scope_schema", Typ: types.String},
{Name: "scope_name", Typ: types.String},
{Name: "maximum_cardinality", Typ: types.Int},
{Name: "dtd_identifier", Typ: types.String},
{Name: "parameter_default", Typ: types.String},
},
unimplemented: true,
}

var (
Expand Down Expand Up @@ -964,14 +995,94 @@ https://www.postgresql.org/docs/9.5/infoschema-role-table-grants.html`,
}

// MySQL: https://dev.mysql.com/doc/mysql-infoschema-excerpt/5.7/en/routines-table.html
var informationSchemaRoutineTable = virtualSchemaTable{
comment: `built-in functions (empty - introspection not yet supported)
https://www.postgresql.org/docs/9.5/infoschema-routines.html`,
var informationSchemaRoutineTable = virtualSchemaView{
comment: `built-in functions and user-defined functions
https://www.postgresql.org/docs/15/infoschema-routines.html`,
schema: vtable.InformationSchemaRoutines,
populate: func(ctx context.Context, p *planner, dbContext catalog.DatabaseDescriptor, addRow func(...tree.Datum) error) error {
return nil
resultColumns: colinfo.ResultColumns{
{Name: "specific_catalog", Typ: types.String},
{Name: "specific_schema", Typ: types.String},
{Name: "specific_name", Typ: types.String},
{Name: "routine_catalog", Typ: types.String},
{Name: "routine_schema", Typ: types.String},
{Name: "routine_name", Typ: types.String},
{Name: "routine_type", Typ: types.String},
{Name: "module_catalog", Typ: types.String},
{Name: "module_schema", Typ: types.String},
{Name: "module_name", Typ: types.String},
{Name: "udt_catalog", Typ: types.String},
{Name: "udt_schema", Typ: types.String},
{Name: "udt_name", Typ: types.String},
{Name: "data_type", Typ: types.String},
{Name: "character_maximum_length", Typ: types.Int},
{Name: "character_octet_length", Typ: types.Int},
{Name: "character_set_catalog", Typ: types.String},
{Name: "character_set_schema", Typ: types.String},
{Name: "character_set_name", Typ: types.String},
{Name: "collation_catalog", Typ: types.String},
{Name: "collation_schema", Typ: types.String},
{Name: "collation_name", Typ: types.String},
{Name: "numeric_precision", Typ: types.Int},
{Name: "numeric_precision_radix", Typ: types.Int},
{Name: "numeric_scale", Typ: types.Int},
{Name: "datetime_precision", Typ: types.Int},
{Name: "interval_type", Typ: types.String},
{Name: "interval_precision", Typ: types.Int},
{Name: "type_udt_catalog", Typ: types.String},
{Name: "type_udt_schema", Typ: types.String},
{Name: "type_udt_name", Typ: types.String},
{Name: "scope_catalog", Typ: types.String},
{Name: "scope_schema", Typ: types.String},
{Name: "scope_name", Typ: types.String},
{Name: "maximum_cardinality", Typ: types.Int},
{Name: "dtd_identifier", Typ: types.String},
{Name: "routine_body", Typ: types.String},
{Name: "routine_definition", Typ: types.String},
{Name: "external_name", Typ: types.String},
{Name: "external_language", Typ: types.String},
{Name: "parameter_style", Typ: types.String},
{Name: "is_deterministic", Typ: types.String},
{Name: "sql_data_access", Typ: types.String},
{Name: "is_null_call", Typ: types.String},
{Name: "sql_path", Typ: types.String},
{Name: "schema_level_routine", Typ: types.String},
{Name: "max_dynamic_result_sets", Typ: types.Int},
{Name: "is_user_defined_cast", Typ: types.String},
{Name: "is_implicitly_invocable", Typ: types.String},
{Name: "security_type", Typ: types.String},
{Name: "to_sql_specific_catalog", Typ: types.String},
{Name: "to_sql_specific_schema", Typ: types.String},
{Name: "to_sql_specific_name", Typ: types.String},
{Name: "as_locator", Typ: types.String},
{Name: "created", Typ: types.TimestampTZ},
{Name: "last_altered", Typ: types.TimestampTZ},
{Name: "new_savepoint_level", Typ: types.String},
{Name: "is_udt_dependent", Typ: types.String},
{Name: "result_cast_from_data_type", Typ: types.String},
{Name: "result_cast_as_locator", Typ: types.String},
{Name: "result_cast_char_max_length", Typ: types.Int},
{Name: "result_cast_char_octet_length", Typ: types.Int},
{Name: "result_cast_char_set_catalog", Typ: types.String},
{Name: "result_cast_char_set_schema", Typ: types.String},
{Name: "result_cast_char_set_name", Typ: types.String},
{Name: "result_cast_collation_catalog", Typ: types.String},
{Name: "result_cast_collation_schema", Typ: types.String},
{Name: "result_cast_collation_name", Typ: types.String},
{Name: "result_cast_numeric_precision", Typ: types.Int},
{Name: "result_cast_numeric_precision_radix", Typ: types.Int},
{Name: "result_cast_numeric_scale", Typ: types.Int},
{Name: "result_cast_datetime_precision", Typ: types.Int},
{Name: "result_cast_interval_type", Typ: types.String},
{Name: "result_cast_interval_precision", Typ: types.Int},
{Name: "result_cast_type_udt_catalog", Typ: types.String},
{Name: "result_cast_type_udt_schema", Typ: types.String},
{Name: "result_cast_type_udt_name", Typ: types.String},
{Name: "result_cast_scope_catalog", Typ: types.String},
{Name: "result_cast_scope_schema", Typ: types.String},
{Name: "result_cast_scope_name", Typ: types.String},
{Name: "result_cast_maximum_cardinality", Typ: types.Int},
{Name: "result_cast_dtd_identifier", Typ: types.String},
},
unimplemented: true,
}

// MySQL: https://dev.mysql.com/doc/refman/5.7/en/schemata-table.html
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/logictest/testdata/logic_test/crdb_internal
Expand Up @@ -202,7 +202,7 @@ pg_index false
pg_indexes false
pg_inherits true
pg_init_privs true
pg_language true
pg_language false
pg_largeobject true
pg_largeobject_metadata true
pg_locks true
Expand Down