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

table/tables: fix an error message when table has no partition for value (#14099) #14107

Merged
merged 2 commits into from
Dec 18, 2019

Conversation

sre-bot
Copy link
Contributor

@sre-bot sre-bot commented Dec 18, 2019

cherry-pick #14099 to release-3.0


What problem does this PR solve?

mysql> CREATE TABLE t_month_data_monitor (
    ->         id int(20) NOT NULL AUTO_INCREMENT,
    ->         data_date date NOT NULL,
    ->         PRIMARY KEY (id, data_date)
    -> ) PARTITION BY RANGE COLUMNS(data_date) (
    ->         PARTITION p20190401 VALUES LESS THAN ('2019-04-02'),
    ->         PARTITION p20190402 VALUES LESS THAN ('2019-04-03')
    -> )
    -> ;
Query OK, 0 rows affected (0.00 sec)

mysql> INSERT INTO t_month_data_monitor VALUES (4, '2019-04-04');
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 1 column 7 near ""

The error should be

mysql> INSERT INTO t_month_data_monitor VALUES (4, '2019-08-04');
ERROR 1526 (HY000): Table has no partition for value from column_list

What is changed and how it works?

We evaluate the argument value for table has no partition for value %s, and that step failed with en error. That error is returned mistakenly as the final error message:

[parser:1064]You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 1 column 7 near "" 
github.com/pingcap/errors.AddStack
	/media/genius/OS/project/pkg/mod/github.com/pingcap/[email protected]/errors.go:174
github.com/pingcap/parser/terror.(*Error).GenWithStackByArgs
	/media/genius/OS/project/pkg/mod/github.com/pingcap/[email protected]/terror/terror.go:238
github.com/pingcap/tidb/util.SyntaxError
	/media/genius/OS/project/src/github.com/pingcap/tidb/util/misc.go:124
github.com/pingcap/tidb/expression.ParseSimpleExprWithTableInfo
	/media/genius/OS/project/src/github.com/pingcap/tidb/expression/simple_rewriter.go:49
github.com/pingcap/tidb/table/tables.(*partitionedTable).locateRangePartition
	/media/genius/OS/project/src/github.com/pingcap/tidb/table/tables/partition.go:296
github.com/pingcap/tidb/table/tables.(*partitionedTable).locatePartition
	/media/genius/OS/project/src/github.com/pingcap/tidb/table/tables/partition.go:261
github.com/pingcap/tidb/table/tables.(*partitionedTable).AddRecord
	/media/genius/OS/project/src/github.com/pingcap/tidb/table/tables/partition.go:348
github.com/pingcap/tidb/executor.(*InsertValues).addRecord
	/media/genius/OS/project/src/github.com/pingcap/tidb/executor/insert_common.go:786
github.com/pingcap/tidb/executor.(*InsertExec).exec
	/media/genius/OS/project/src/github.com/pingcap/tidb/executor/insert.go:79
github.com/pingcap/tidb/executor.(*InsertValues).insertRows
	/media/genius/OS/project/src/github.com/pingcap/tidb/executor/insert_common.go:223
github.com/pingcap/tidb/executor.(*InsertExec).Next
	/media/genius/OS/project/src/github.com/pingcap/tidb/executor/insert.go:242
github.com/pingcap/tidb/executor.Next
	/media/genius/OS/project/src/github.com/pingcap/tidb/executor/executor.go:192
github.com/pingcap/tidb/executor.(*ExecStmt).handleNoDelayExecutor
	/media/genius/OS/project/src/github.com/pingcap/tidb/executor/adapter.go:431
github.com/pingcap/tidb/executor.(*ExecStmt).Exec
	/media/genius/OS/project/src/github.com/pingcap/tidb/executor/adapter.go:295
github.com/pingcap/tidb/session.runStmt
	/media/genius/OS/project/src/github.com/pingcap/tidb/session/tidb.go:249
github.com/pingcap/tidb/session.(*session).executeStatement

Extract value from pi.Expr as possible as we can, but don't use it when an error happens.

Check List

Tests

  • Unit test
  • Manual test (add detailed scripts or steps below)

@sre-bot
Copy link
Contributor Author

sre-bot commented Dec 18, 2019

/run-all-tests

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/LGT1 Indicates that a PR has LGTM 1. label Dec 18, 2019
Copy link
Contributor

@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/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Dec 18, 2019
@ngaut ngaut merged commit 1866f27 into pingcap:release-3.0 Dec 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/LGT2 Indicates that a PR has LGTM 2. type/compatibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants