Skip to content

MDEV-10426 ANY_VALUE function - #5151

Merged
grooverdan merged 4 commits into
MariaDB:mainfrom
jaeheonshim:MDEV-10426-any-value
Nov 5, 2026
Merged

grooverdan merged 4 commits into
MariaDB:mainfrom
jaeheonshim:MDEV-10426-any-value

Conversation

@jaeheonshim

Copy link
Copy Markdown
Contributor

MDEV-10426: Add support for the MySQL ANY_VALUE() function (SQL:2023 feature T626).

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements the ANY_VALUE() function by adding it to the client commands, defining the Item_func_any_value class (inheriting from Item_func_coalesce), and registering it in the function registry. Feedback on the changes points out a critical issue: because Item_func_any_value inherits from Item_func_coalesce, it will still trigger ONLY_FULL_GROUP_BY errors unless check_cols_in_group_by() is overridden to return false directly.

Comment thread sql/item_cmpfunc.h Resolved
@vuvova vuvova added the GSoC label Jun 1, 2026
@gkodinov gkodinov added the External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements. label Jun 1, 2026
@jaeheonshim
jaeheonshim force-pushed the MDEV-10426-any-value branch from c6f6e73 to 9525ad3 Compare June 15, 2026 03:32
kjarir added a commit to kjarir/server that referenced this pull request Jun 22, 2026
Per Daniel Black's reference to PR MariaDB#5151 (copy_or_same() fix for
ANY_VALUE), investigated whether the same gap exists for our
BIT_AND/BIT_OR/BIT_XOR binary mode aggregates.

Finding: no bug exists. Item_sum_or/Item_sum_and/Item_sum_xor
already have correct copy_or_same() implementations that clone
via the Item_sum_bit copy constructor, which properly deep-copies
m_str_value and m_binary_bit_counters for each rollup level's
independent accumulator.

Verified WITH ROLLUP produces mathematically correct results for
binary mode BIT_OR/BIT_AND/BIT_XOR (manually cross-checked byte
by byte against expected values). Added Section 16 as permanent
regression coverage for this previously-untested combination.
Comment thread mysql-test/main/any_value.test Resolved
@jaeheonshim
jaeheonshim marked this pull request as ready for review June 25, 2026 02:00
@jaeheonshim
jaeheonshim force-pushed the MDEV-10426-any-value branch from 86dfc73 to 7660557 Compare June 25, 2026 02:57

@gkodinov gkodinov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for working on this. This is a preliminary review.

Please:

  • squash your commits into one per feature. I guess one in your case?
  • I'd also consider resolving the conflicts with the upstream branch sooner than later.

Comment thread mysql-test/main/any_value.test Resolved
@jaeheonshim

Copy link
Copy Markdown
Contributor Author

squash your commits into one per feature. I guess one in your case?

Is it okay if I save this step until the very end? In the case that I need to make further modifications during the review process, it would be helpful for me to retain the commit history

@jaeheonshim
jaeheonshim force-pushed the MDEV-10426-any-value branch 3 times, most recently from e87743f to cf74df9 Compare July 2, 2026 04:01

@gkodinov gkodinov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your test file fails on embedded. It looks like a test stability issue to me. Please rectify.

@jaeheonshim

Copy link
Copy Markdown
Contributor Author

@gkodinov The test should be fixed now. I discovered that the output of ANY_VALUE as a window function is not guaranteed across multiple executions of the same test due to the way that rows are ordered within the temp table. The test has been stabilized by modifying the table used by the window function assertion to ensure that for each group, there exists only one unique value in the any_value column.

@gkodinov gkodinov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM as far as the preliminary review goes. Please work with your assigned reviewer on the final review.
One small thing: please consider squashing the commits to a reasonable minimum. One maybe? Could be done prior to merging too, as long as it's being done.

@gkodinov

Copy link
Copy Markdown
Member

FYI: According to our development cycle all testing of features must be completed before 30 Apr, 30 Jul, 30 Nov and 31 Jan (approximate release dates). You might get comments from the tester before that date or your feature will be approved as is and merged. But it'll all likely happen closer to the release date, not right now.

@sanja-byelkin

Copy link
Copy Markdown
Member

Just note: the work should not in such form in main tree pushed, commits should be reworked to present them not historically but functionally, most probably just one commit.

Comment thread mysql-test/main/group_by.test Resolved
@grooverdan
grooverdan force-pushed the MDEV-10426-any-value branch 5 times, most recently from 1da8edd to 6e878ad Compare November 5, 2026 03:04
@CLAassistant

CLAassistant commented Nov 5, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@mariadb-RexJohnston mariadb-RexJohnston left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good

jaeheonshim and others added 4 commits November 6, 2026 08:52
Implement the ANY_VALUE function that, in a GROUP BY expression, returns
any one of the rows as a result. This meets the aggregation requirements
of sql_mode=ONLY_FULL_GROUP_BY.

Completed as part of Google Summer of Code 2026.

Corrected as part of testing:
* MDEV-41138 Ensure ANY_VALUE not fully reserved
* MDEV-41200 ANY_VALUE not marked BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION
* MDEV-41202 ONLY_FULL_GROUP_BY silently bypassed for outer-correlated fields inside aggregate
* MDEV-41400 Server is crashing in base_list::push_back/List<Item_field>::push_back
Item_sum_any_value::update_field can no-longer be a no-op
and if there is a filter, we delegate this to the parent class
to record the value of the aggregation otherwise it will have
null value if the first value in the any_value(g) group results
if it didn't mean the filter criteria.

Review: Rex Johnston
Like MIN and MAX, ANY_VALUE can take a value from an
index and will return the first non-NULL value.
…e_field

When an early execution takes the Item_sum_any_value::add function the
has_value gets set. If the execution plan changes for the second
execution the update_field resulting in the has_value debug assertion
being hit.

Added a Item_sum_any_value::reset_field() to reset the has_value back
to false so this test case is covered.

Thanks Alice Sherepa for the well found test case and Rex Johnston for
review.
@grooverdan
grooverdan force-pushed the MDEV-10426-any-value branch from 6e878ad to ef9d496 Compare November 5, 2026 21:55
@grooverdan
grooverdan enabled auto-merge (rebase) November 5, 2026 22:03
@grooverdan
grooverdan merged commit 37af117 into MariaDB:main Nov 5, 2026
16 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements. GSoC

Development

Successfully merging this pull request may close these issues.

7 participants