Repository navigation
Conversation
DerZc
force-pushed
the
fix-mdev-39194
branch
from
September 21, 2026 06:03
5f94299 to
3634ec3
Compare
gkodinov
requested changes
Sep 23, 2026
gkodinov
left a comment
Member
There was a problem hiding this comment.
Thank you for your contribution! This is a preliminary review.
To get to the final review:
- squash the two commits into one
- make sure there's no failing tests in the build bot runs.
SUM(DISTINCT b'1100') returns 9 instead of 12 because the hybrid hex/bit literal handler inherits the default DOUBLE temporary field. The literal's byte length becomes the DOUBLE(M,0) display width, which clips the numeric value when it is stored. Override make_num_distinct_aggregator_field for Type_handler_hex_hybrid to use an unsigned integer temporary field. Keep argument-based field selection for other types so DISTINCT retains the input expression's precision and scale, including for AVG of decimal expressions. Extend main.sum_distinct with bit and hex literals, byte boundaries, the unsigned 64-bit boundary, duplicate inputs, AVG, COUNT, and a decimal AVG control. Keep existing decimal result expectations intact. Bug report: https://jira.mariadb.org/browse/MDEV-39194
DerZc
force-pushed
the
fix-mdev-39194
branch
from
September 23, 2026 14:49
217c4e3 to
fde7f12
Compare
gkodinov
approved these changes
Sep 24, 2026
gkodinov
left a comment
Member
There was a problem hiding this comment.
Thanks! LGTM. Please stand by for the final review.
raghunandanbhat
requested changes
Sep 30, 2026
raghunandanbhat
left a comment
Contributor
There was a problem hiding this comment.
thanks @DerZc for the fix. comments inline.
Please re-write commit message in this format-
MDEV-xxxx: <Titile>
Problem: < Short description of the issue >
Fix: <Short description of your fix>
| Hex and bit literals have unsigned integer values in numeric aggregates. | ||
| Their max_length is a byte count, not a DOUBLE(M,0) display width. | ||
| */ | ||
| return type_handler_ulonglong.make_num_distinct_aggregator_field(mem_root, |
Contributor
There was a problem hiding this comment.
I wouldn't use the hard-coded type_handler_ulonglong here.
Any specific reason why we can't just return a new Field_longlong() from this function? (making sure it is always unsigned, ofc). for ex:
Field *
Type_handler_hex_hybrid::make_num_distinct_aggregator_field(
MEM_ROOT *mem_root, const Item *item) const
{
/*
Hex and bit literals have unsigned integer values in numeric aggregates.
Their max_length is a byte count, not a DOUBLE(M,0) display width.
*/
return new (mem_root)
Field_longlong(NULL, item->max_length,
(uchar *) (item->maybe_null() ? "" : 0),
item->maybe_null() ? 1 : 0, Field::NONE,
&item->name, 0, true /* unsigned */);
}| COUNT(DISTINCT b'1100') AS bit_count FROM t1; | ||
| # DISTINCT inputs keep the argument's decimal scale, not AVG's result scale. | ||
| SELECT AVG(DISTINCT b / a) AS decimal_average FROM t1; | ||
| DROP TABLE t1; |
Contributor
There was a problem hiding this comment.
please add end of test marker here
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SUM(DISTINCT b'1100')returns 9 instead of 12. Bit and hybrid hex literals inherit the default numeric DISTINCT temporary field, which uses their byte length as aDOUBLE(M,0)display width and clips the stored value.Bug report: https://jira.mariadb.org/browse/MDEV-39194
Changes
Type_handler_hex_hybrid::make_num_distinct_aggregator_fieldto use unsigned integer storage for numeric DISTINCT aggregation of bit and hybrid hex literals.AVG(DISTINCT b / a)inmain.distinct_notembeddedcontinues to return0.61110000.main.sum_distinctregression with zero, byte boundaries, hybrid hex literals, the unsigned 64-bit boundary, duplicate inputs,AVG,COUNT, and the decimal precision control.Validation
Built against
11.4atd10e5d726799b1cd57cc866f40aad68c720803dawith GCC 13 in Release mode.main.sum_distinctregression fails on the unchanged base and passes with this fix.main.distinct_notembeddedfailure locally:0.61111111instead of0.61110000. This matches all eight failed Buildbot configurations and AppVeyor; the corrected implementation passes without changing that test's expected output.main.sum_distinct,main.distinct_notembedded,main.distinct,main.func_group,main.group_by,main.select,main.type_bit,main.type_bit_innodb,main.type_decimal,main.type_float, andmain.type_hex_hybrid.main.sum_distinctandmain.distinct_notembeddedalso passed with--ps-protocoland with--view-protocol, for 15 successful test executions overall.git diff --checkpassed.The full regression suite and Windows builds were not run locally.