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: add the not expression check when creating a partition table #21497

Merged
merged 21 commits into from
Dec 24, 2020

Conversation

Reminiscent
Copy link
Contributor

What problem does this PR solve?

Issue Number: close #17808

Problem Summary:
When TiDB uses HASH(not c) as the partition condition, it will convert not c to UnaryOperationExpr instead of FuncCallExpr to check whether the expression is valid.

What is changed and how it works?

What's Changed:
When we use checkPartitionExprArgs for checking whether the expression is valid. , we add UnaryOperationExpr into consideration. And if the operand is not, we will report an error.

Before this PR:

mysql> CREATE TABLE t1(c0 INT) PARTITION BY HASH((NOT c0)) PARTITIONS 2;
Query OK, 0 rows affected (0.00 sec)

After this PR:

mysql> CREATE TABLE t1(c0 INT) PARTITION BY HASH((NOT c0)) PARTITIONS 2;
ERROR 1564 (HY000): This partition function is not allowed

How it Works:

Tests

  • Unit test
  • Integration test

Release note

  • add the not expression check when creating a partition table

@Reminiscent
Copy link
Contributor Author

/label type/bug-fix, sig/ddl

@ti-srebot ti-srebot added sig/sql-infra SIG: SQL Infra type/bugfix This PR fixes a bug. labels Dec 4, 2020
@Reminiscent
Copy link
Contributor Author

/cc @wjhuang2016

@Reminiscent
Copy link
Contributor Author

/cc @tiancaiamao

ddl/partition.go Outdated Show resolved Hide resolved
@ichn-hu ichn-hu mentioned this pull request Dec 4, 2020
ddl/db_partition_test.go Outdated Show resolved Hide resolved
@Reminiscent Reminiscent requested a review from a team as a code owner December 18, 2020 07:24
@Reminiscent Reminiscent requested review from SunRunAway and removed request for a team December 18, 2020 07:24
@xiongjiwei
Copy link
Contributor

xiongjiwei commented Dec 18, 2020

a white-list of allowed expression of partition table will be much easier to compatible with MySQL because MySQL uses white-list too. we will always not sure whether we miss some expressions check if we use a black-list.

@wjhuang2016
Copy link
Member

/run-all-tests

@Reminiscent
Copy link
Contributor Author

/run-check_dev

ddl/partition.go Outdated
ast.DateDiff: {}, ast.Floor: {}, ast.Mod: {},
}
if _, ok := allowedFuncMap[expr.FnName.L]; ok {
case *ast.FuncCastExpr, *ast.CaseExpr, *ast.SubqueryExpr, *ast.WindowFuncExpr, *ast.RowExpr, *ast.DefaultExpr, *ast.ValuesExpr,
Copy link
Contributor

Choose a reason for hiding this comment

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

we should explicitly list the expr which is allowed in partition expression. Although there are many expr, only a few of them are allowed.

@Reminiscent
Copy link
Contributor Author

/run-all-tests

@Reminiscent
Copy link
Contributor Author

/run-all-tests

@xiongjiwei
Copy link
Contributor

/run-e2e-tests

Copy link
Member

@wjhuang2016 wjhuang2016 left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-srebot ti-srebot added the status/LGT1 Indicates that a PR has LGTM 1. label Dec 24, 2020
Copy link
Contributor

@xiongjiwei xiongjiwei left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-srebot
Copy link
Contributor

@xiongjiwei, Thanks for your review. The bot only counts LGTMs from Reviewers and higher roles, but you're still welcome to leave your comments. See the corresponding SIG page for more information. Related SIG: execution(slack).

@ti-srebot ti-srebot removed the status/LGT1 Indicates that a PR has LGTM 1. label Dec 24, 2020
@ti-srebot ti-srebot added the status/LGT2 Indicates that a PR has LGTM 2. label Dec 24, 2020
@XuHuaiyu
Copy link
Contributor

/merge

@ti-srebot
Copy link
Contributor

Your auto merge job has been accepted, waiting for:

  • 21953

@ti-srebot ti-srebot added the status/can-merge Indicates a PR has been approved by a committer. label Dec 24, 2020
@ti-srebot
Copy link
Contributor

/run-all-tests

@ti-srebot
Copy link
Contributor

@Reminiscent merge failed.

@Reminiscent
Copy link
Contributor Author

/run-e2e-tests

@XuHuaiyu XuHuaiyu merged commit db31b29 into pingcap:master Dec 24, 2020
Tjianke pushed a commit to Tjianke/tidb that referenced this pull request Dec 25, 2020
@Reminiscent Reminiscent deleted the issue17808 branch August 5, 2021 01:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/expression 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/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

P1-[4.0 bug hunting]-[SQL Plan Management]-Server panic for NATURAL LEFT JOIN on partitioned table
5 participants