MDEV-40672: Pluggable Aggregate Function - #5522
Draft
drrtuy wants to merge 1 commit into
Draft
Conversation
drrtuy
force-pushed
the
pluggable_aggregate_funcs
branch
from
August 10, 2026 20:32
5acea19 to
df0b051
Compare
drrtuy
force-pushed
the
pluggable_aggregate_funcs
branch
from
August 14, 2026 20:43
df0b051 to
66d0210
Compare
There was a problem hiding this comment.
Pull request overview
Adds pluggable aggregate functions to MariaDB’s standard aggregation and window-function infrastructure.
Changes:
- Introduces
Item_sum_pluginwith plugin lifetime and data-type handling. - Adds parser,
DISTINCT, and window-function support. - Adds test aggregates and MTR coverage.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
sql/sql_yacc.yy |
Parses and constructs plugin aggregates. |
sql/sql_window.cc |
Handles plugin window aggregates. |
sql/sql_schema.h |
Exposes plugin references during lookup. |
sql/sql_schema.cc |
Implements plugin-aware schema lookup. |
sql/item_sum.h |
Defines plugin aggregate interfaces. |
sql/item_sum.cc |
Implements lifecycle and DISTINCT replay. |
sql/item_create.h |
Adds aggregate builder marker. |
sql/item_create.cc |
Retains plugins during item creation. |
plugin/func_test/plugin.cc |
Adds test aggregate plugins. |
plugin/func_test/mysql-test/func_test/function_plugin.test |
Adds primary functional tests. |
plugin/func_test/mysql-test/func_test/function_plugin.result |
Records primary test results. |
plugin/func_test/mysql-test/func_test/function_plugin_negative.test |
Adds failure-path tests. |
plugin/func_test/mysql-test/func_test/function_plugin_negative.result |
Records negative test results. |
plugin/func_test/mysql-test/func_test/function_plugin_extra.test |
Adds extended lifecycle/type tests. |
plugin/func_test/mysql-test/func_test/function_plugin_extra.result |
Records extended test results. |
include/mysql/plugin_function.h |
Documents the aggregate plugin contract. |
include/mysql/plugin_function.h.pp |
Updates the preprocessed API header. |
Suppressed comments (3)
sql/sql_yacc.yy:11375
- The descriptor contract is only checked when the returned object already casts to
Item_sum. An aggregate-marked builder that accidentally returns a scalar skips this block and is accepted even though its arguments were parsed as an aggregate; conversely, a scalar-marked builder returningItem_sum_pluginis accepted as an aggregate. Validate the builder's declared aggregate kind against the returned item (when non-null), and require every aggregate descriptor to returnItem_sum_plugin.
Item_sum *sum_item= item ? dynamic_cast<Item_sum *>(item) : NULL;
if (function_plugin && sum_item)
sql/item_sum.cc:582
- This null check does not make the allocation recoverable: ordinary throwing
newnever returns null (and typically terminates in no-exception builds), so allocation failure cannot reach the caller'sER_OUT_OF_RESOURCESpath. Use a non-throwing allocation here.
m_plugin_lifetime=
new Item_sum_plugin_lifetime(static_cast<plugin_ref>(plugin));
return !m_plugin_lifetime;
sql/item_sum.cc:905
- Routing plugin aggregates through this DISTINCT branch leaves their
add()failures unhandled for the common in-memorytreereplay path.unique_walk_function()discards the boolean returned byitem_sum->add(), andendup()also ignorestree->walk()'s status, so a plugin that reports an allocation or evaluation failure can continue replaying and return a partial result. Propagate the callback failure and stop/fail the walk, as the new on-disk replay loop already does.
if (item_sum->sum_func() == Item_sum::COUNT_FUNC ||
item_sum->sum_func() == Item_sum::COUNT_DISTINCT_FUNC ||
item_sum->sum_func() == Item_sum::PLUGIN_SUM_FUNC)
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+11261
to
+11263
| Create_func *native_builder= Schema::find_implied(thd)-> | ||
| find_native_function_builder(thd, sysname); | ||
| aggregate= dynamic_cast<Create_aggregate_func *>(native_builder) != NULL; |
Contributor
Author
There was a problem hiding this comment.
Known issue. Similar situation is filed as MDEV-20842.
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.
Add pluggable aggregate function support
What
Implement MDEV-40672 by extending function plugins to provide aggregate functions through the standard
Item_sumlifecycle. Support grouped aggregation,DISTINCT, window functions, native and pluggable data types, and safe plugin lifetime management.Key changes
Plugin_functiondescriptors to distinguish scalar and aggregate functions.Item_sum_pluginas the base class for plugin-provided aggregates.DISTINCTargument replay and pluggable result types such as UUID.How to test
Run:
/git/BuildOf_mdb-13/mysql-test/mtr function_plugin function_plugin_extraBoth tests pass.