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

Merged
merged 3 commits into from
Dec 18, 2019

Conversation

tiancaiamao
Copy link
Contributor

@tiancaiamao tiancaiamao commented Dec 17, 2019

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)

@tiancaiamao
Copy link
Contributor Author

PTAL @jackysp @lysu

@codecov
Copy link

codecov bot commented Dec 17, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@f356c6c). Click here to learn what that means.
The diff coverage is 100%.

@@             Coverage Diff             @@
##             master     #14099   +/-   ##
===========================================
  Coverage          ?   80.1587%           
===========================================
  Files             ?        483           
  Lines             ?     121489           
  Branches          ?          0           
===========================================
  Hits              ?      97384           
  Misses            ?      16345           
  Partials          ?       7760

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

jackysp commented Dec 18, 2019

/merge

@sre-bot sre-bot added the status/can-merge Indicates a PR has been approved by a committer. label Dec 18, 2019
@sre-bot
Copy link
Contributor

sre-bot commented Dec 18, 2019

/run-all-tests

@sre-bot
Copy link
Contributor

sre-bot commented Dec 18, 2019

cherry pick to release-3.0 in PR #14107

XiaTianliang pushed a commit to XiaTianliang/tidb that referenced this pull request Dec 21, 2019
@tiancaiamao tiancaiamao deleted the locate-err-msg branch December 23, 2019 02:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/can-merge Indicates a PR has been approved by a committer. status/LGT1 Indicates that a PR has LGTM 1. type/compatibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants