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

executor: support "show columns from" for view #8863

Merged
merged 5 commits into from
Jan 5, 2019

Conversation

AndrewDi
Copy link
Contributor

@AndrewDi AndrewDi commented Dec 28, 2018

What problem does this PR solve?

Modify DESCRIBE TABLE to describe view columns

What is changed and how it works?

ref proposal Proposal: Implement View

Check List

Tests

  • Unit test

Code changes

  • Has exported function/method change
    Export function func (b *PlanBuilder) BuildDataSourceFromView(dbName model.CIStr, tableInfo *model.TableInfo)

Side effects
none


This change is Reviewable

@AndrewDi AndrewDi mentioned this pull request Dec 28, 2018
19 tasks
@zz-jason zz-jason added contribution This PR is from a community contributor. sig/execution SIG execution labels Dec 29, 2018
@AndrewDi
Copy link
Contributor Author

AndrewDi commented Jan 2, 2019

@XuHuaiyu @winkyao PTAL

Copy link
Contributor

@XuHuaiyu XuHuaiyu left a comment

Choose a reason for hiding this comment

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

Any test for this?

@AndrewDi
Copy link
Contributor Author

AndrewDi commented Jan 3, 2019

@XuHuaiyu show_test.go do not contain any DESCRIBE TBALE test, so I didn't add test either.

@XuHuaiyu
Copy link
Contributor

XuHuaiyu commented Jan 3, 2019

We'd better add some test cases for it.

Copy link
Contributor

@alivxxx alivxxx left a comment

Choose a reason for hiding this comment

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

LGTM

@alivxxx alivxxx added the status/LGT1 Indicates that a PR has LGTM 1. label Jan 3, 2019
@AndrewDi
Copy link
Contributor Author

AndrewDi commented Jan 4, 2019

/run-all-tests

@AndrewDi
Copy link
Contributor Author

AndrewDi commented Jan 4, 2019

@XuHuaiyu PTAL

@codecov-io
Copy link

codecov-io commented Jan 4, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@081a2c5). Click here to learn what that means.
The diff coverage is 83.33%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #8863   +/-   ##
=========================================
  Coverage          ?   67.54%           
=========================================
  Files             ?      363           
  Lines             ?    75111           
  Branches          ?        0           
=========================================
  Hits              ?    50731           
  Misses            ?    19907           
  Partials          ?     4473
Impacted Files Coverage Δ
planner/core/logical_plan_builder.go 74.02% <100%> (ø)
executor/show.go 41.47% <80%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 081a2c5...7abbb96. Read the comment docs.

for _, col := range cols {
viewColumn := viewSchema.FindColumnByName(col.Name.L)
if viewColumn != nil {
col.FieldType = *viewColumn.GetType()
Copy link
Member

Choose a reason for hiding this comment

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

We can't get the column type from the columns returned by tb.Cols()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, view's column tableinfo only store column name, so we need to extract sql's schema.column to get column type.

Copy link
Member

Choose a reason for hiding this comment

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

Can we fill the column type info when this table info is generated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think so, because undertable's column type and column length can be change.

Copy link
Member

Choose a reason for hiding this comment

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

MySQL(root@localhost:test) > create table t(a bigint, b bigint);
Query OK, 0 rows affected (0.04 sec)

MySQL(root@localhost:test) > create view v as select * from t;
Query OK, 0 rows affected (0.07 sec)

MySQL(root@localhost:test) > show columns from v;
+-------+------------+------+-----+---------+-------+
| Field | Type       | Null | Key | Default | Extra |
+-------+------------+------+-----+---------+-------+
| a     | bigint(20) | YES  |     | NULL    |       |
| b     | bigint(20) | YES  |     | NULL    |       |
+-------+------------+------+-----+---------+-------+
2 rows in set (0.01 sec)

MySQL(root@localhost:test) > drop table t;
Query OK, 0 rows affected (0.03 sec)

MySQL(root@localhost:test) > create table t(a double, b double, c double);
Query OK, 0 rows affected (0.07 sec)

MySQL(root@localhost:test) > show columns from v;
+-------+--------+------+-----+---------+-------+
| Field | Type   | Null | Key | Default | Extra |
+-------+--------+------+-----+---------+-------+
| a     | double | YES  |     | NULL    |       |
| b     | double | YES  |     | NULL    |       |
+-------+--------+------+-----+---------+-------+
2 rows in set (0.01 sec)

Got it. Confirmed in MySQL.

Copy link
Member

Choose a reason for hiding this comment

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

@AndrewDi Could you add a comment to specify why we need to build logical plan on the view to get the column types?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@AndrewDi AndrewDi force-pushed the view/describe_table branch from 2e8077a to 7abbb96 Compare January 5, 2019 12:58
Copy link
Member

@zz-jason zz-jason left a comment

Choose a reason for hiding this comment

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

LGTM

@zz-jason
Copy link
Member

zz-jason commented Jan 5, 2019

/run-all-tests

@zz-jason zz-jason added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jan 5, 2019
@zz-jason zz-jason changed the title planner,executor: alter describe table to support view executor: support "show columns from" for view Jan 5, 2019
@zz-jason zz-jason merged commit 78a51a4 into pingcap:master Jan 5, 2019
@AndrewDi AndrewDi deleted the view/describe_table branch January 15, 2019 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution This PR is from a community contributor. sig/execution SIG execution status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants