Skip to content

MDEV-10426 ANY_VALUE function#5151

Open
jaeheonshim wants to merge 16 commits into
MariaDB:mainfrom
jaeheonshim:MDEV-10426-any-value
Open

MDEV-10426 ANY_VALUE function#5151
jaeheonshim wants to merge 16 commits into
MariaDB:mainfrom
jaeheonshim:MDEV-10426-any-value

Conversation

@jaeheonshim

Copy link
Copy Markdown

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 Outdated
@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.
SELECT charset(ANY_VALUE(a)), collation(ANY_VALUE(a)) FROM t;
SELECT coercibility(ANY_VALUE(a)), coercibility(ANY_VALUE('x')) FROM t;

DROP TABLE t;

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.

This all seems fine so far.
Bonus points, consider this

create table t1 (a int, b int, index(a));
insert into t1 values (1, 1), (1, 2), (2, 3);
select a, any_value(b) from t1 group by a;

does the row t1(a,b) = (1,2) need to read by the engine/handler?
Is it?
There is already similar code in the server (see loosescan here)
https://mariadb.com/docs/server/ha-and-performance/optimization-and-tuning/query-optimizer/minmax-optimization
Note: i don't actually expect you to implement this, but do write up something.

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.

Also, as you've added a token to the parser, you've changed the 'digest hashes' in a perfschema test. You'll need to record/update those too.

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.

Also also, there is a single line in a commit with whitespace before a newline, remove that whitespace.
Add some tests without ONLY_FULL_GROUP_BY sql_mode, and demonstrate how to use it as a window function.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Updated the digest hashes, fixed whitespace, and added the additional test cases. I will report back with short circuit possibilities for any_value

@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
@jaeheonshim

Copy link
Copy Markdown
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 from 8cc1af6 to 7a00a0c Compare June 30, 2026 04:51
@jaeheonshim jaeheonshim force-pushed the MDEV-10426-any-value branch from 7a00a0c to e87743f Compare July 1, 2026 01:21
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.

5 participants