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

*: fix "create or replace view" infoschema is inconsistent #14832

Merged
merged 3 commits into from
Feb 20, 2020

Conversation

zimulala
Copy link
Contributor

What problem does this PR solve?

create table t(a int, b int);
create view v as select * from t;
create or replace view v  as select * from t2;
create table t1(a int, b int, c int);
create or replace view v  as select * from t1;
select count(*) from information_schema.views where table_name ='v';

Before this PR

+---------------+--------------+------------+-------------------------------------------------------------------------+--------------+--------------+----------------+---------------+----------------------+----------------------+
| TABLE_CATALOG | TABLE_SCHEMA | TABLE_NAME | VIEW_DEFINITION                                                         | CHECK_OPTION | IS_UPDATABLE | DEFINER        | SECURITY_TYPE | CHARACTER_SET_CLIENT | COLLATION_CONNECTION |
+---------------+--------------+------------+-------------------------------------------------------------------------+--------------+--------------+----------------+---------------+----------------------+----------------------+
| def           | test         | v          | SELECT `test`.`t`.`a`,`test`.`t`.`b` FROM `test`.`t`                    | CASCADED     | NO           | root@127.0.0.1 | DEFINER       | utf8                 | utf8_general_ci      |
| def           | test         | v          | SELECT `test`.`t1`.`a`,`test`.`t1`.`b`,`test`.`t1`.`c` FROM `test`.`t1` | CASCADED     | NO           | root@127.0.0.1 | DEFINER       | utf8                 | utf8_general_ci      |
+---------------+--------------+------------+-------------------------------------------------------------------------+--------------+--------------+----------------+---------------+----------------------+----------------------+

After this PR

+---------------+--------------+------------+-------------------------------------------------------------------------+--------------+--------------+----------------+---------------+----------------------+----------------------+
| TABLE_CATALOG | TABLE_SCHEMA | TABLE_NAME | VIEW_DEFINITION                                                         | CHECK_OPTION | IS_UPDATABLE | DEFINER        | SECURITY_TYPE | CHARACTER_SET_CLIENT | COLLATION_CONNECTION |
+---------------+--------------+------------+-------------------------------------------------------------------------+--------------+--------------+----------------+---------------+----------------------+----------------------+
| def           | test         | v          | SELECT `test`.`t1`.`a`,`test`.`t1`.`b`,`test`.`t1`.`c` FROM `test`.`t1` | CASCADED     | NO           | root@127.0.0.1 | DEFINER       | utf8                 | utf8_general_ci      |
+---------------+--------------+------------+-------------------------------------------------------------------------+--------------+--------------+----------------+---------------+----------------------+----------------------+

What is changed and how it works?

Check List

Tests

  • Unit test

Related changes

  • Need to cherry-pick to the release branch

Release note

  • Fix "create or replace view" infoschema is inconsistent.

ddl/ddl_worker.go Outdated Show resolved Hide resolved
@zimulala
Copy link
Contributor Author

PTAL @XuHuaiyu

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.

lgtm

@zimulala zimulala added the status/LGT1 Indicates that a PR has LGTM 1. label Feb 19, 2020
// it has two table IDs and should be handled differently.
if oldTbInfoID > 0 && orReplace {
diff.OldTableID = oldTbInfoID
}
Copy link
Contributor

Choose a reason for hiding this comment

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

else the diff.OldTableID is 0? Do we need to handle this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If diff.OldTableID is 0, it's the invalid table ID. It would not do anything in ApplyDiff.

Copy link
Contributor

@crazycs520 crazycs520 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@AilinKid AilinKid left a comment

Choose a reason for hiding this comment

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

LGTM

@zimulala zimulala added status/LGT3 The PR has already had 3 LGTM. status/can-merge Indicates a PR has been approved by a committer. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Feb 20, 2020
@sre-bot
Copy link
Contributor

sre-bot commented Feb 20, 2020

/run-all-tests

@sre-bot
Copy link
Contributor

sre-bot commented Feb 20, 2020

cherry pick to release-3.0 in PR #14867

@zimulala zimulala deleted the create-view-replace branch February 20, 2020 07:13
@you06 you06 added the sig/sql-infra SIG: SQL Infra label Mar 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/sql-infra SIG: SQL Infra status/can-merge Indicates a PR has been approved by a committer. status/LGT3 The PR has already had 3 LGTM. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants