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

ddl: fix creating partition table with unique prefix index #17196

Merged
merged 4 commits into from
May 14, 2020

Conversation

tiancaiamao
Copy link
Contributor

What problem does this PR solve?

create table t1 (a varchar(20), b binary, unique index (a(5))) partition by range columns (a) (
    partition p0 values less than ('aaaaa'),
    partition p1 values less than ('bbbbb'),
    partition p2 values less than ('ccccc')
);

MySQL: A UNIQUE INDEX must include all columns in the table's partitioning function
TiDB: no error

Problem Summary:

Unique prefix index can't be used on the partition table.

What is changed and how it works?

Proposal: xxx

What's Changed:

How it Works:

Add check

Related changes

  • Need to cherry-pick to the release branch

Check List

Tests

  • Unit test

Release note

  • Fix the check of create and alter table, unique prefix index must not be used on the partition table

@tiancaiamao
Copy link
Contributor Author

PTAL @crazycs520 @zimulala @XuHuaiyu

@tiancaiamao tiancaiamao added type/bugfix This PR fixes a bug. sig/sql-infra SIG: SQL Infra labels May 14, 2020
@tiancaiamao tiancaiamao added this to the v4.0.0-ga milestone May 14, 2020
ddl/partition.go Outdated
@@ -761,6 +763,15 @@ func checkPartitioningKeysConstraints(sctx sessionctx.Context, s *ast.CreateTabl
return nil
}

func hasPrefixIndexColumn(idxCols []*model.IndexColumn) bool {
for _, col := range idxCols {
if col.Length > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should check the table name too?

Below sql will execute sucessfull in Mysql but faild in This PR:

create table part12 (a varchar(20), b varchar(10), unique index (a(5),b)) partition by range columns (b) (
			partition p0 values less than ('aaaaa'),
			partition p1 values less than ('bbbbb'),
			partition p2 values less than ('ccccc'))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@codecov
Copy link

codecov bot commented May 14, 2020

Codecov Report

Merging #17196 into master will not change coverage.
The diff coverage is n/a.

@@             Coverage Diff             @@
##             master     #17196   +/-   ##
===========================================
  Coverage   80.1515%   80.1515%           
===========================================
  Files           511        511           
  Lines        140137     140137           
===========================================
  Hits         112322     112322           
  Misses        18855      18855           
  Partials       8960       8960           

@tiancaiamao tiancaiamao added the priority/release-blocker This issue blocks a release. Please solve it ASAP. label May 14, 2020
@bb7133
Copy link
Member

bb7133 commented May 14, 2020

/run-all-tests

@sre-bot
Copy link
Contributor

sre-bot commented May 14, 2020

cherry pick to release-4.0 in PR #17213

sre-bot pushed a commit to sre-bot/tidb that referenced this pull request May 14, 2020
Signed-off-by: sre-bot <sre-bot@pingcap.com>
@sre-bot
Copy link
Contributor

sre-bot commented May 14, 2020

cherry pick to release-3.0 in PR #17214

@sre-bot
Copy link
Contributor

sre-bot commented May 14, 2020

cherry pick to release-3.1 in PR #17215

jebter added a commit that referenced this pull request May 21, 2020
…17213)

Co-authored-by: tiancaiamao <tiancaiamao@gmail.com>
Co-authored-by: HuaiyuXu <391585975@qq.com>
Co-authored-by: Lynn <zimu_xia@126.com>
Co-authored-by: jebter <jebter@126.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority/release-blocker This issue blocks a release. Please solve it ASAP. sig/sql-infra SIG: SQL Infra type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants