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: qualify table name for COMMENT ON INDEX, COLUMN event logs #58472

Merged
merged 1 commit into from
Jan 6, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions pkg/sql/comment_on_column.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,16 @@ func (n *commentOnColumnNode) startExec(params runParams) error {
if n.n.Comment != nil {
comment = *n.n.Comment
}

tn, err := params.p.getQualifiedTableName(params.ctx, n.tableDesc)
if err != nil {
return err
}

return params.p.logEvent(params.ctx,
n.tableDesc.ID,
&eventpb.CommentOnColumn{
// TODO(knz): This table name is improperly qualified.
// See: https://github.com/cockroachdb/cockroach/issues/57740
TableName: n.tableDesc.Name,
TableName: tn.String(),
ColumnName: string(n.n.ColumnItem.ColumnName),
Comment: comment,
NullComment: n.n.Comment == nil,
Expand Down
10 changes: 7 additions & 3 deletions pkg/sql/comment_on_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,16 @@ func (n *commentOnIndexNode) startExec(params runParams) error {
if n.n.Comment != nil {
comment = *n.n.Comment
}

tn, err := params.p.getQualifiedTableName(params.ctx, n.tableDesc)
if err != nil {
return err
}

return params.p.logEvent(params.ctx,
n.tableDesc.ID,
&eventpb.CommentOnIndex{
// TODO(knz): This table name is improperly qualified.
// See: https://github.com/cockroachdb/cockroach/issues/57740
TableName: n.tableDesc.Name,
TableName: tn.String(),
IndexName: string(n.n.Index.Index),
Comment: comment,
NullComment: n.n.Comment == nil,
Expand Down
40 changes: 40 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/event_log
Original file line number Diff line number Diff line change
Expand Up @@ -909,3 +909,43 @@ ORDER BY "timestamp", info
----
1 drop_type {"EventType": "drop_type", "Statement": "DROP TYPE defaultdb.public.eventlog_renamed", "TypeName": "defaultdb.public.eventlog_renamed", "User": "root"}
1 drop_type {"EventType": "drop_type", "Statement": "DROP TYPE defaultdb.public.eventlog_renamed", "TypeName": "defaultdb.public._eventlog_renamed", "User": "root"}


# Test the event logs generated by COMMENT ON ... commands.
subtest eventlog_comments

statement ok
CREATE TABLE a (id INT PRIMARY KEY, b INT NOT NULL)

statement ok
COMMENT ON COLUMN a.id IS 'This is a column.'

query IT
SELECT "reportingID", info::JSONB - 'Timestamp' - 'DescriptorID'
FROM system.eventlog
WHERE "eventType" = 'comment_on_column'
----
1 {"ColumnName": "id", "Comment": "This is a column.", "EventType": "comment_on_column", "Statement": "COMMENT ON COLUMN a.id IS 'This is a column.'", "TableName": "defaultdb.public.a", "User": "root"}

statement ok
CREATE INDEX b_index ON a (b)

statement ok
COMMENT ON INDEX b_index IS 'This is an index.'

query IT
SELECT "reportingID", info::JSONB - 'Timestamp' - 'DescriptorID'
FROM system.eventlog
WHERE "eventType" = 'comment_on_index'
----
1 {"Comment": "This is an index.", "EventType": "comment_on_index", "IndexName": "b_index", "Statement": "COMMENT ON INDEX \"\".\"\".b_index IS 'This is an index.'", "TableName": "defaultdb.public.a", "User": "root"}

statement ok
COMMENT ON TABLE a IS 'This is a table.'

query IT
SELECT "reportingID", info::JSONB - 'Timestamp' - 'DescriptorID'
FROM system.eventlog
WHERE "eventType" = 'comment_on_table'
----
1 {"Comment": "This is a table.", "EventType": "comment_on_table", "Statement": "COMMENT ON TABLE defaultdb.public.a IS 'This is a table.'", "TableName": "defaultdb.public.a", "User": "root"}