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

Add create view support #8001

Closed
wants to merge 3 commits into from

Conversation

AndrewDi
Copy link
Contributor

@AndrewDi AndrewDi commented Oct 23, 2018

What problem does this PR solve?

Implement view support, support following grammar:

  1. create or replace view as SelectStmt ...
  2. drop table ...
  3. show full tables
  4. show create table viewname
  5. select from view

issue ref #7974
Part of the code reference from #4874

What is changed and how it works?

Use tableinfo to store view select statement

Check List

Tests

  • Unit test

Code changes

  • Has interface methods change
    Add CreateView interface to ddl/ddl.go
  • Has persistent data change

Side effects

Related changes


This change is Reviewable

@sre-bot
Copy link
Contributor

sre-bot commented Oct 23, 2018

Hi contributor, thanks for your PR.

This patch needs to be approved by someone of admins. They should reply with "/ok-to-test" to accept this PR for running test automatically.

@zz-jason zz-jason added contribution This PR is from a community contributor. sig/planner SIG: Planner labels Oct 23, 2018
@ngaut
Copy link
Member

ngaut commented Oct 23, 2018

Well done.

@AndrewDi AndrewDi force-pushed the add_create_view_support branch from 449889c to 503e0d7 Compare October 23, 2018 08:59
@AndrewDi
Copy link
Contributor Author

Do some commit clean...

@AndrewDi AndrewDi force-pushed the add_create_view_support branch 3 times, most recently from ed49dea to e52330f Compare October 23, 2018 13:28
@AndrewDi AndrewDi force-pushed the add_create_view_support branch from e52330f to 8ad8f80 Compare October 23, 2018 13:41
@XuHuaiyu XuHuaiyu added the require-LGT3 Indicates that the PR requires three LGTM. label Oct 24, 2018
@XuHuaiyu
Copy link
Contributor

@AndrewDi will file a proposal for the details of supporting View these days.

ddl/ddl.go Outdated
@@ -19,6 +19,7 @@ package ddl

import (
"fmt"
"github.com/pingcap/tidb/expression"
Copy link
Member

Choose a reason for hiding this comment

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

please reorg the import packages.

@AndrewDi
Copy link
Contributor Author

I will implement this feature with independent PRs.

@AndrewDi AndrewDi closed this Nov 28, 2018
@morgo
Copy link
Contributor

morgo commented Dec 3, 2018

How is the SQL mode handled with views - I assume it is dependent on the session executing the view?

(The MySQL compatible behavior is to capture the SQL mode when the view is created.)

@XuHuaiyu
Copy link
Contributor

XuHuaiyu commented Dec 3, 2018

@morgo
Yes, we need to take SQL_MODE into consideration.

A minor case of view in MySQL, it seems that everything is frozen after CREATE_VIEW:

mysql> create view v as select "a" from t;
Query OK, 0 rows affected (0.03 sec)

mysql> select "a" from t;
+---+
| a |
+---+
| a |
+---+
1 row in set (0.00 sec)

mysql> select * from v;
+---+
| a |
+---+
| a |
+---+
1 row in set (0.00 sec)

mysql> set @@sql_mode='ANSI_QUOTES';                                                Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> select "a" from t
    -> ;
+------+
| a    |
+------+
| NULL |
+------+
1 row in set (0.00 sec)

mysql> select * from v;
+---+
| a |
+---+
| a |
+---+
1 row in set (0.00 sec)

@XuHuaiyu
Copy link
Contributor

XuHuaiyu commented Dec 3, 2018

@morgo
We decided to implement the most basic features of view in TiDB,
as the task with P1 priority mentioned in this proposal #8416.

SQL_MODE in view may be listed as a P2 or P3 priority task.

@AndrewDi AndrewDi deleted the add_create_view_support branch December 21, 2018 13:35
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. require-LGT3 Indicates that the PR requires three LGTM. sig/planner SIG: Planner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants