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 a bug that adding range partition meets error when value is negative #11407

Merged
merged 4 commits into from
Aug 1, 2019

Conversation

tiancaiamao
Copy link
Contributor

What problem does this PR solve?

CREATE TABLE `tt5` (
  `c3` bigint(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
PARTITION BY RANGE ( `c3` ) (
  PARTITION p0 VALUES LESS THAN (-3),
  PARTITION p1 VALUES LESS THAN (-2)
);

ALTER TABLE `tt5` add partition ( partition p2 values less than (-1) );
(1054, u"Unknown column '' in 'partition function'")  # Succeed in MySQL, fail in TiDB.

and also this one:

ALTER TABLE `tt5` add partition ( partition p2 values less than (6 - 1) );

What is changed and how it works?

In this line https://github.com/pingcap/tidb/compare/master...tiancaiamao:fix-add-range-partition?expand=1#diff-edfa54cbe2fdb418f0a77bd0ec4a56f2L3395, we check the expression to be an integer.
However, expr.GetType() returns unspecified type and the error is throw out.

After removing that, I meet another error, here https://github.com/pingcap/tidb/compare/master...tiancaiamao:fix-add-range-partition?expand=1#diff-edfa54cbe2fdb418f0a77bd0ec4a56f2L2145

checkAddPartitionValue this function also asserts the partition less than value to be a simple integer,
so I replace it with another one.

Check List

Tests

  • Unit test

Related changes

  • Need to cherry-pick to the release branch

@tiancaiamao
Copy link
Contributor Author

PTAL @crazycs520 @zimulala @winkyao

@codecov
Copy link

codecov bot commented Jul 25, 2019

Codecov Report

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

@@             Coverage Diff             @@
##             master     #11407   +/-   ##
===========================================
  Coverage   81.2765%   81.2765%           
===========================================
  Files           426        426           
  Lines         92184      92184           
===========================================
  Hits          74924      74924           
  Misses        11905      11905           
  Partials       5355       5355

@tiancaiamao
Copy link
Contributor Author

PTAL @crazycs520 @zimulala @winkyao

for ith, def := range spec.PartDefinitions {
if err := def.Clause.Validate(part.Type, len(part.Columns)); err != nil {
return nil, errors.Trace(err)
}
// For RANGE partition only VALUES LESS THAN should be possible.
clause := def.Clause.(*ast.PartitionDefinitionClauseLessThan)
for _, expr := range clause.Exprs {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why just remove it? Could we refine the checking?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As you see, there are no test cases break and I'm adding new test cases, so it's fine to remove it.

Copy link
Contributor

@winkyao winkyao 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
Member

@jackysp jackysp left a comment

Choose a reason for hiding this comment

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

LGTM

@jackysp jackysp added the status/LGT2 Indicates that a PR has LGTM 2. label Jul 30, 2019
@tiancaiamao
Copy link
Contributor Author

/run-all-tests

@tiancaiamao tiancaiamao added status/all tests passed status/can-merge Indicates a PR has been approved by a committer. labels Aug 1, 2019
@sre-bot
Copy link
Contributor

sre-bot commented Aug 1, 2019

/run-all-tests

Copy link
Collaborator

@lysu lysu left a comment

Choose a reason for hiding this comment

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

LGTM

@lysu lysu added status/can-merge Indicates a PR has been approved by a committer. and removed status/can-merge Indicates a PR has been approved by a committer. labels Aug 1, 2019
@sre-bot
Copy link
Contributor

sre-bot commented Aug 1, 2019

/run-all-tests

@sre-bot sre-bot merged commit 10e8498 into pingcap:master Aug 1, 2019
@sre-bot
Copy link
Contributor

sre-bot commented Aug 1, 2019

cherry pick to release-3.0 failed

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/LGT2 Indicates that a PR has LGTM 2. type/bug-fix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants