-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
information_schema: Fill information_schema.key_column_usage #2721
Conversation
8ff23ab
to
3fd6374
Compare
infoschema/tables.go
Outdated
for _, table := range schema.Tables { | ||
rs := keyColumnUsageInTable(schema, table) | ||
for _, r := range rs { | ||
rows = append(rows, r) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rows = append(rows, rs...)
infoschema/tables.go
Outdated
@@ -847,6 +848,103 @@ func dataForTableConstraints(schemas []*model.DBInfo) [][]types.Datum { | |||
return rows | |||
} | |||
|
|||
func dataForKeyColumnUsage(schemas []*model.DBInfo) [][]types.Datum { | |||
rows := [][]types.Datum{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
init the cap
schema.Name.O, // TABLE_SCHEMA | ||
table.Name.O, // TABLE_NAME | ||
col.Name.O, // COLUMN_NAME | ||
i+1, // ORDINAL_POSITION, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why it's i+1
here, but line 877 is i
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 877 should be 1.
The value of ORDINAL_POSITION is the column's position within the constraint, not the column's position within the table. Column positions are numbered beginning with 1.
So for PkAsHandle, it should always be 1.
@tiancaiamao @hanfei1991 PTAL |
LGTM |
infoschema/tables.go
Outdated
@@ -847,6 +848,101 @@ func dataForTableConstraints(schemas []*model.DBInfo) [][]types.Datum { | |||
return rows | |||
} | |||
|
|||
func dataForKeyColumnUsage(schemas []*model.DBInfo) [][]types.Datum { | |||
rows := make([][]types.Datum, len(schemas)) // The capacity is not accurate, but it is not a big problem. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-> make([][]types.Datum, 0, len(schemas))
?
LGTM |
Add content for key-column-usage table.
@zimulala @tiancaiamao @XuHuaiyu PTAL