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

information_schema: Fill information_schema.key_column_usage #2721

Merged
merged 4 commits into from
May 12, 2017

Conversation

shenli
Copy link
Member

@shenli shenli commented Feb 23, 2017

Add content for key-column-usage table.
@zimulala @tiancaiamao @XuHuaiyu PTAL

@shenli shenli force-pushed the shenli/key-column-usage branch from 8ff23ab to 3fd6374 Compare May 8, 2017 05:46
@shenli shenli changed the title [DNM] information_schema: Fill information_schema.key_column_usage information_schema: Fill information_schema.key_column_usage May 8, 2017
for _, table := range schema.Tables {
rs := keyColumnUsageInTable(schema, table)
for _, r := range rs {
rows = append(rows, r)
Copy link
Member

Choose a reason for hiding this comment

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

rows = append(rows, rs...)

@@ -847,6 +848,103 @@ func dataForTableConstraints(schemas []*model.DBInfo) [][]types.Datum {
return rows
}

func dataForKeyColumnUsage(schemas []*model.DBInfo) [][]types.Datum {
rows := [][]types.Datum{}
Copy link
Member

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,
Copy link
Contributor

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 ?

Copy link
Member Author

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.

@shenli
Copy link
Member Author

shenli commented May 12, 2017

@tiancaiamao @hanfei1991 PTAL

@tiancaiamao
Copy link
Contributor

LGTM

@tiancaiamao tiancaiamao added the status/LGT1 Indicates that a PR has LGTM 1. label May 12, 2017
@@ -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.
Copy link
Contributor

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)) ?

@zimulala
Copy link
Contributor

LGTM

@shenli shenli merged commit 9f08180 into master May 12, 2017
@shenli shenli deleted the shenli/key-column-usage branch May 12, 2017 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/LGT1 Indicates that a PR has LGTM 1.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants