-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
MDEV-24943: Implement FILTER clause support for aggregate functions #4439
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
base: main
Are you sure you want to change the base?
Conversation
9f3c0ff to
cb7d38d
Compare
|
Thank for taking the effort to work on this. Indeed, the LIMIT clause is a part of (at least) SQL 2011 and, as such, is a very good feature to have. However, the diff seems very incomplete. Can you please make sure that you:
Please re-submit when you have the above. |
|
I don't see how the diff is incomplete. It applies fine. It compiles fine. It passes tests on buildbot, not every builder, but it passes on many builders, this doesn't look like a non-working diff. |
|
Hi @KhaledR57 , I'm experimenting with the changes and I see a difference between what should otherwise be equivalent statements. What was once written using However, on MariaDB, the Why is this the case? |
|
If we store the sequence engine result to an InnoDB-backed table and run the FILTER query against that instead we get the correct result: |
Aggregates lacked the SQL-standard FILTER clause, forcing CASE-based workarounds that reduced readability across (sum, avg, count, …). This update introduces the ability to specify a FILTER clause for aggregate functions, allowing for more granular control over which rows are included in the aggregation. Also, improves standards compliance and makes queries clearer and more readable. The FILTER(WHERE ...) condition may contain any expression allowed in regular WHERE clauses, except subqueries, window functions, and outer references.
cb7d38d to
aaea60a
Compare
|
Hi @DaveGosselin-MariaDB , Sorry for the delayed response! The issue was with the sequence storage engine's I've added a if (item->type() != Item::SUM_FUNC_ITEM ||
(((Item_sum*) item)->sum_func() != Item_sum::SUM_FUNC &&
((Item_sum*) item)->sum_func() != Item_sum::COUNT_FUNC) ||
((Item_sum*) item)->has_filter()) // NEW CHECK
return 0; // Fall back to normal aggregationStoring the sequence data to an InnoDB table gave the correct result because InnoDB goes through the standard I'll add sequence-specific tests in the next commit after I finish the stored aggregates (almost done with those). |
Description
Aggregates lacked the SQL-standard
FILTERclause, forcing CASE-based workarounds that reduced readability.This update introduces the ability to specify a
FILTERclause for aggregate functions, allowing for more granular control over which rows are included in the aggregation. Also, improves standards compliance and makes queries clearer and more readable.The
<condition>may contain any expression allowed in regularWHEREclauses, except subqueries, window functions, and outer references.Example:
How can this PR be tested?
Running the Test Suite
Validating CASE vs FILTER Equivalence
Use the
compare.pyscript to verify CASE and FILTER produce identical results:Expected Result File Format:
The script expects result files with this structure:
The script identifies test headers (
# Test N: Description), CASE/FILTER markers (# 1. CASE version/# 2. FILTER version), and compares the data rows that follow each marker.Basing the PR against the correct MariaDB version
mainbranch.PR quality check