Skip to content

Commit

Permalink
sql: qualify table name for alter_table_owner event log
Browse files Browse the repository at this point in the history
Fixes #57960.

Previously, event logs were not capturing the qualified table names
for ALTER TABLE OWNER commands.
This PR changes the event logs to use the qualified table name.
Tests were fixed to reflect these changes.

Release note (bug fix): qualify table name for alter_table_owner event log
  • Loading branch information
the-ericwang35 committed Jan 6, 2021
1 parent 9fa3e82 commit 81e0172
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
9 changes: 6 additions & 3 deletions pkg/sql/alter_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -1290,12 +1290,15 @@ func (p *planner) checkCanAlterTableAndSetNewOwner(
privs := desc.GetPrivileges()
privs.SetOwner(newOwner)

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

return p.logEvent(ctx,
desc.ID,
&eventpb.AlterTableOwner{
// TODO(knz): Properly qualify this.
// See: https://github.com/cockroachdb/cockroach/issues/57960
TableName: desc.Name,
TableName: tn.String(),
Owner: newOwner.Normalized(),
})
}
8 changes: 4 additions & 4 deletions pkg/sql/logictest/testdata/logic_test/event_log
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ ORDER BY "timestamp", info
----
1 alter_database_owner {"DatabaseName": "atest", "EventType": "alter_database_owner", "Owner": "u", "Statement": "ALTER DATABASE atest OWNER TO u", "User": "root"}
1 alter_schema_owner {"EventType": "alter_schema_owner", "Owner": "u", "SchemaName": "sc", "Statement": "ALTER SCHEMA atest.sc OWNER TO u", "User": "root"}
1 alter_table_owner {"EventType": "alter_table_owner", "Owner": "u", "Statement": "ALTER TABLE atest.sc.t OWNER TO u", "TableName": "t", "User": "root"}
1 alter_table_owner {"EventType": "alter_table_owner", "Owner": "u", "Statement": "ALTER TABLE atest.sc.t OWNER TO u", "TableName": "atest.sc.t", "User": "root"}
1 alter_type_owner {"EventType": "alter_type_owner", "Owner": "u", "Statement": "ALTER TYPE atest.sc.ty OWNER TO u", "TypeName": "ty", "User": "root"}
1 alter_type_owner {"EventType": "alter_type_owner", "Owner": "u", "Statement": "ALTER TYPE atest.sc.ty OWNER TO u", "TypeName": "_ty", "User": "root"}

Expand Down Expand Up @@ -841,9 +841,9 @@ ORDER BY "timestamp", info
----
1 alter_database_owner {"DatabaseName": "atest", "EventType": "alter_database_owner", "Owner": "v", "Statement": "REASSIGN OWNED BY testuser TO v", "User": "root"}
1 alter_schema_owner {"EventType": "alter_schema_owner", "Owner": "v", "SchemaName": "sc", "Statement": "REASSIGN OWNED BY testuser TO v", "User": "root"}
1 alter_table_owner {"EventType": "alter_table_owner", "Owner": "v", "Statement": "REASSIGN OWNED BY testuser TO v", "TableName": "t", "User": "root"}
1 alter_table_owner {"EventType": "alter_table_owner", "Owner": "v", "Statement": "REASSIGN OWNED BY testuser TO v", "TableName": "v", "User": "root"}
1 alter_table_owner {"EventType": "alter_table_owner", "Owner": "v", "Statement": "REASSIGN OWNED BY testuser TO v", "TableName": "s", "User": "root"}
1 alter_table_owner {"EventType": "alter_table_owner", "Owner": "v", "Statement": "REASSIGN OWNED BY testuser TO v", "TableName": "atest.sc.t", "User": "root"}
1 alter_table_owner {"EventType": "alter_table_owner", "Owner": "v", "Statement": "REASSIGN OWNED BY testuser TO v", "TableName": "atest.sc.v", "User": "root"}
1 alter_table_owner {"EventType": "alter_table_owner", "Owner": "v", "Statement": "REASSIGN OWNED BY testuser TO v", "TableName": "atest.sc.s", "User": "root"}
1 alter_type_owner {"EventType": "alter_type_owner", "Owner": "v", "Statement": "REASSIGN OWNED BY testuser TO v", "TypeName": "ty", "User": "root"}
1 alter_type_owner {"EventType": "alter_type_owner", "Owner": "v", "Statement": "REASSIGN OWNED BY testuser TO v", "TypeName": "_ty", "User": "root"}

Expand Down

0 comments on commit 81e0172

Please sign in to comment.