Skip to content

sql: enum introspection improvements#57197

Merged
craig[bot] merged 2 commits intocockroachdb:masterfrom
arulajmani:enum-introspection
Dec 1, 2020
Merged

sql: enum introspection improvements#57197
craig[bot] merged 2 commits intocockroachdb:masterfrom
arulajmani:enum-introspection

Conversation

@arulajmani
Copy link
Copy Markdown
Collaborator

See individual commit messages for details.

Previously, `SHOW ENUMS` was restricted to all schemas in the current
database. Other analogous `SHOW` commands, such as `SHOW TABLES`, can
optionally take a schema_name or a db_name.schema_name and only show
objects under that hierarchy. This patch brings this functionality to
the `SHOW ENUMS` statement as well.

Closes cockroachdb#57196

Release note (sql change): `SHOW ENUMS` is now extended to take an
optional "FROM" clause. The user can specify either the schema name
or both the db name and schema name separated by a '.'. If a hierarchy
is specified so, the statement returns ENUMS falling in that hierarchy
rather than all of the enums in the current database.
@arulajmani arulajmani requested review from a team and otan November 27, 2020 22:47
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
Contributor

@otan otan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 7 of 7 files at r1, 3 of 3 files at r2.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @arulajmani)


pkg/sql/pg_catalog.go, line 1303 at r2 (raw file):

		return forEachTypeDesc(ctx, p, dbContext, func(_ *dbdesc.Immutable, _ string, typDesc *typedesc.Immutable) error {
			// We only want to iterate over ENUM types and multi-region enums.
			if typDesc.Kind != descpb.TypeDescriptor_ENUM &&

nit: nicer as a switch statement:

switch typDesc.Kind {
    case ENUM,
             MULTIREGION_ENUM:
          return nil
}

pkg/sql/delegate/show_enums.go, line 63 at r1 (raw file):

WHERE types.typtype = 'e' %[2]s
ORDER BY (nsp.nspname, types.typname)
`, &name.CatalogName, schemaClause)

should this be lex.EscapeSQLString(name.CatalogName) ?

After this patch, multi-region enums can be introspected using the
`pg_catalog.pg_enum` virtual table. As a consequence, they can also
be viewed by issuing the `SHOW ENUMS` query or one of its variants.
Unlike user defined enums, multi-region enums don't show `CREATE`
statements, as they are constructed implicitly.

Closes cockroachdb#57087

Release note (sql change): The multi-region enum, created implicitly
for all multiregion databases, can be introspected using the
`pg_catalog.pg_enum` table. It is also displayed in `SHOW ENUMS`.
@blathers-crl blathers-crl bot requested a review from otan November 30, 2020 16:21
Copy link
Copy Markdown
Collaborator Author

@arulajmani arulajmani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RFAL

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @otan)


pkg/sql/pg_catalog.go, line 1303 at r2 (raw file):

Previously, otan (Oliver Tan) wrote…

nit: nicer as a switch statement:

switch typDesc.Kind {
    case ENUM,
             MULTIREGION_ENUM:
          return nil
}

Done


pkg/sql/delegate/show_enums.go, line 63 at r1 (raw file):

Previously, otan (Oliver Tan) wrote…

should this be lex.EscapeSQLString(name.CatalogName) ?

Naa. We're using this to construct a FQN of the pg_enum table, which won't work if we put quotes around the db name.

Copy link
Copy Markdown
Member

@jordanlewis jordanlewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @otan)


pkg/sql/delegate/show_enums.go, line 63 at r1 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Naa. We're using this to construct a FQN of the pg_enum table, which won't work if we put quotes around the db name.

Try this out:

CREATE DATABASE "I am tricksy";
SHOW ENUMS FROM "I am tricksy";

@otan
Copy link
Copy Markdown
Contributor

otan commented Nov 30, 2020


pkg/sql/delegate/show_enums.go, line 63 at r1 (raw file):

Previously, jordanlewis (Jordan Lewis) wrote…

Try this out:

CREATE DATABASE "I am tricksy";
SHOW ENUMS FROM "I am tricksy";

yeah and use EncodeRestrictedSQLIdent in that case.

Copy link
Copy Markdown
Collaborator Author

@arulajmani arulajmani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @otan)


pkg/sql/delegate/show_enums.go, line 63 at r1 (raw file):

Previously, otan (Oliver Tan) wrote…

yeah and use EncodeRestrictedSQLIdent in that case.

Talked w @otan offline -- the case above works because the x.Name.String() escapes correctly, so we don't need anything special here.

Copy link
Copy Markdown
Contributor

@otan otan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r3.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @otan)

@arulajmani
Copy link
Copy Markdown
Collaborator Author

TFTR!

bors r=otan

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Dec 1, 2020

Build failed:

@arulajmani
Copy link
Copy Markdown
Collaborator Author

bors r=otan

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Dec 1, 2020

Build succeeded:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants