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

expression: handle max_allowed_packet warnings for pad functions #7171

Merged
merged 10 commits into from Jul 31, 2018

Conversation

@zz-jason
Copy link
Member

commented Jul 27, 2018

What have you changed? (mandatory)

Return NULL and a warning when the result of lpad or rpad exceeds max_allowed_packetbs.

Before this PR, select rpad('hello', 18446744073709551617, '1'); would make tidb-server panic by runtime error: makeslice: len out of range.

After this PR:

TiDB(localhost:4000) > select rpad('hello', 18446744073709551617, '1');
+------------------------------------------+
| rpad('hello', 18446744073709551617, '1') |
+------------------------------------------+
| NULL                                     |
+------------------------------------------+
1 row in set, 2 warnings (0.00 sec)

TiDB(localhost:4000) > show warnings;
+---------+------+----------------------------------------------------------------------------+
| Level   | Code | Message                                                                    |
+---------+------+----------------------------------------------------------------------------+
| Warning | 1292 | Truncated incorrect DECIMAL value: '18446744073709551617'                  |
| Warning | 1301 | Result of rpad() was larger than max_allowed_packet (67108864) - truncated |
+---------+------+----------------------------------------------------------------------------+
2 rows in set (0.00 sec)

What is the type of the changes? (mandatory)

  • Bug fix (non-breaking change which fixes an issue)

How has this PR been tested? (mandatory)

  • unit test
  • explain test

Does this PR affect documentation (docs/docs-cn) update? (mandatory)

No

Does this PR affect tidb-ansible update? (mandatory)

No

Does this PR need to be added to the release notes? (mandatory)

Yes

release note:

Return `NULL` when the result of function `LPAD`/`RPAD` is larger than `max_allowed_packet`

Refer to a related PR or issue link (optional)

to #7153

Benchmark result if necessary (optional)

Add a few positive/negative examples (optional)

@zz-jason

This comment has been minimized.

Copy link
Member Author

commented Jul 27, 2018

/run-all-tests

@zz-jason

This comment has been minimized.

Copy link
Member Author

commented Jul 27, 2018

zz-jason added 2 commits Jul 27, 2018
@@ -1760,24 +1760,33 @@ func (c *lpadFunctionClass) getFunction(ctx sessionctx.Context, args []Expressio
bf.tp.Flen = getFlen4LpadAndRpad(bf.ctx, args[1])
SetBinFlagOrBinStr(args[0].GetType(), bf.tp)
SetBinFlagOrBinStr(args[2].GetType(), bf.tp)

valStr, _ := ctx.GetSessionVars().GetSystemVar("max_allowed_packet")

This comment has been minimized.

Copy link
@XuHuaiyu

XuHuaiyu Jul 30, 2018

Contributor

make "max_allowed_packet" a constant in sessionctx/variable/sysvar.go?

@@ -316,7 +316,7 @@ var MySQLErrName = map[uint16]string{
ErrUnknownTimeZone: "Unknown or incorrect time zone: '%-.64s'",
ErrWarnInvalidTimestamp: "Invalid TIMESTAMP value in column '%s' at row %d",
ErrInvalidCharacterString: "Invalid %s character string: '%.64s'",
ErrWarnAllowedPacketOverflowed: "Result of %s() was larger than maxAllowedPacket (%d) - truncated",
ErrWarnAllowedPacketOverflowed: "Result of %s() was larger than max_allowed_packet (%d) - truncated",

This comment has been minimized.

Copy link
@winoros

winoros Jul 30, 2018

Member

This is original warning msg in mysql?

This comment has been minimized.

Copy link
@zz-jason

zz-jason Jul 30, 2018

Author Member

Yes, this error message comes from the mysql-server code base.

zz-jason added 2 commits Jul 30, 2018
@zz-jason

This comment has been minimized.

Copy link
Member Author

commented Jul 30, 2018

@XuHuaiyu Done, PTAL

Copy link
Contributor

left a comment

LGTM

@zz-jason

This comment has been minimized.

Copy link
Member Author

commented Jul 31, 2018

/run-all-tests

Copy link
Member

left a comment

LGTM

@zz-jason zz-jason added status/LGT2 and removed status/LGT1 labels Jul 31, 2018
@zz-jason zz-jason merged commit c38f567 into pingcap:master Jul 31, 2018
4 checks passed
4 checks passed
ci/circleci Your tests passed on CircleCI!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
jenkins-ci-tidb/build Jenkins job succeeded.
Details
license/cla Contributor License Agreement is signed.
Details
@zz-jason zz-jason deleted the zz-jason:dev/maxAllowedPacket branch Jul 31, 2018
zz-jason added a commit to zz-jason/tidb that referenced this pull request Aug 2, 2018
zz-jason added a commit that referenced this pull request Aug 2, 2018
…) (#7244)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.