-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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 to_base64 function. #7266
Conversation
Hi contributor, thanks for your PR. This patch needs to be approved by someone of admins. They should reply with "/ok-to-test" to accept this PR for running test automatically. |
expression/builtin_string.go
Outdated
@@ -3044,6 +3055,10 @@ func (b *builtinToBase64Sig) evalString(row chunk.Row) (d string, isNull bool, e | |||
return "", isNull, errors.Trace(err) | |||
} | |||
|
|||
if b.tp.Flen*mysql.MaxBytesOfCharacter > int(b.maxAllowedPacket) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not correct to use Flen
to decide whether the result of ToBase64
exceeds max_allowed_packet
, I think we can learn from MySQL:
String *Item_func_to_base64::val_str_ascii(String *str) {
String *res = args[0]->val_str(str);
bool too_long = false;
uint64 length;
if (!res || res->length() > (uint)base64_encode_max_arg_length() ||
(too_long =
((length = base64_needed_encoded_length((uint64)res->length())) >
current_thd->variables.max_allowed_packet)) ||
tmp_value.alloc((uint)length)) {
null_value = 1; // NULL input, too long input, or OOM.
if (too_long) {
push_warning_printf(
current_thd, Sql_condition::SL_WARNING,
ER_WARN_ALLOWED_PACKET_OVERFLOWED,
ER_THD(current_thd, ER_WARN_ALLOWED_PACKET_OVERFLOWED), func_name(),
current_thd->variables.max_allowed_packet);
}
return 0;
}
base64_encode(res->ptr(), (int)res->length(), (char *)tmp_value.ptr());
DBUG_ASSERT(length > 0);
tmp_value.length((uint)length - 1); // Without trailing '\0'
null_value = 0;
return &tmp_value;
}
The above code is taken from: https://github.com/mysql/mysql-server/blob/5.7/sql/item_strfunc.cc#L690
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, thanks, I will correct it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, @supernan1994 any update?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry!!! I had a bussiness trip and was back yesterday, I will take a look at it tonight and tomorrow night @zz-jason
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😄 take your time, it's just a just a friendly Ping
…xceeds max_allowed_packet
expression/builtin_string_test.go
Outdated
input := chunk.NewChunkWithCapacity(colTypes, 1) | ||
input.AppendString(0, test.args) | ||
res, isNull, err := toBase64.evalString(input.GetRow(0)) | ||
if test.getErr { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all the added test.getErr
is false
, maybe this check can be replaced with: c.Assert(err, IsNil)
expression/builtin_string_test.go
Outdated
c.Assert(res, Equals, test.expect) | ||
} | ||
warnings := s.ctx.GetSessionVars().StmtCtx.GetWarnings() | ||
c.Assert(len(warnings), Equals, warningCount) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warningCount
is always zero, seems the test of max_allowed_packets
is not working
expression/builtin_string_test.go
Outdated
c.Assert(err, IsNil) | ||
if test.isNil { | ||
c.Assert(isNull, IsTrue) | ||
warningCount += 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warningCount
will add 1 when to_base64
result is nil
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we reset the warning appended to s.ctx.GetSessionVars().StmtCtx
and check the exactly warning count and warning content in each test case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
It seems travis ci failed because of temporary network problem
|
@supernan1994 re-triggered |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 2 files at r2, 1 of 1 files at r4.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @supernan1994 and @zz-jason)
/run-all-tests |
2 similar comments
/run-all-tests |
/run-all-tests |
/run-all-tests |
@XuHuaiyu PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
@supernan1994 It would be nice if you can cherry-pick this PR to the |
@zz-jason OK! |
pingcap#7266) (cherry picked from commit 016006f)
What have you changed? (mandatory)
Return NULL and a warning when the result of to_base64 exceeds max_allowed_packetbs.
Before this PR:
After this PR:
This PR calculates length of to_base64 result by function
base64NeededEncodedLength
before executing core of to_base64 logic, and compares length with global variablemax_allowed_packet
.unit tests are added for covering three circumstances:
=
What is the type of the changes? (mandatory)
How has this PR been tested? (mandatory)
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
Please note:
Refer to a related PR or issue link (optional)
to #7153
Benchmark result if necessary (optional)
Add a few positive/negative examples (optional)