diff --git a/pkg/sql/comment_on_column.go b/pkg/sql/comment_on_column.go index db32a86225e7..9a891c60943d 100644 --- a/pkg/sql/comment_on_column.go +++ b/pkg/sql/comment_on_column.go @@ -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, diff --git a/pkg/sql/comment_on_index.go b/pkg/sql/comment_on_index.go index 93e7e4134ff5..d61ea4abe77a 100644 --- a/pkg/sql/comment_on_index.go +++ b/pkg/sql/comment_on_index.go @@ -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, diff --git a/pkg/sql/logictest/testdata/logic_test/event_log b/pkg/sql/logictest/testdata/logic_test/event_log index fc81daa64ed2..6d2b3befd651 100644 --- a/pkg/sql/logictest/testdata/logic_test/event_log +++ b/pkg/sql/logictest/testdata/logic_test/event_log @@ -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"}