Skip to content
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

Vectorized grouping by multiple column #7754

Merged
merged 22 commits into from
Mar 11, 2025
Merged

Conversation

akuzm
Copy link
Member

@akuzm akuzm commented Feb 19, 2025

Paste the values together and use the umash hash of the resulting value for grouping, like we do for the text keys.

Up to 150% improvement on some tsbench queries.

Paste the values together and use the umash hash of the resulting value
for grouping, like we do for the text keys.
Copy link

codecov bot commented Feb 19, 2025

Codecov Report

Attention: Patch coverage is 89.44954% with 23 lines in your changes missing coverage. Please review.

Project coverage is 81.94%. Comparing base (59f50f2) to head (ead7c30).
Report is 832 commits behind head on main.

Files with missing lines Patch % Lines
...odes/vector_agg/hashing/hash_strategy_serialized.c 88.70% 2 Missing and 19 partials ⚠️
tsl/src/nodes/vector_agg/grouping_policy_hash.c 90.90% 0 Missing and 1 partial ⚠️
...rc/nodes/vector_agg/hashing/batch_hashing_params.h 83.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7754      +/-   ##
==========================================
+ Coverage   80.06%   81.94%   +1.88%     
==========================================
  Files         190      249      +59     
  Lines       37181    45975    +8794     
  Branches     9450    11516    +2066     
==========================================
+ Hits        29770    37676    +7906     
- Misses       2997     3770     +773     
- Partials     4414     4529     +115     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@akuzm akuzm mentioned this pull request Feb 19, 2025
11 tasks
@akuzm akuzm marked this pull request as ready for review February 28, 2025 10:15
@@ -225,7 +227,7 @@ add_one_range(GroupingPolicyHash *policy, TupleTableSlot *vector_slot, const int
* Remember which aggregation states have already existed, and which we
* have to initialize. State index zero is invalid.
*/
const uint32 last_initialized_key_index = policy->last_used_key_index;
const uint32 last_initialized_key_index = policy->hashing.last_used_key_index;
Copy link
Member Author

Choose a reason for hiding this comment

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

Did some mechanical refactoring to move more hashing-related data into the hashing strategy struct.

@akuzm akuzm modified the milestone: v2.19.0 Mar 4, 2025
@dbeck dbeck self-requested a review March 10, 2025 15:11
Copy link
Contributor

@dbeck dbeck left a comment

Choose a reason for hiding this comment

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

Can you please add a test case specifically for NULLs. A table with two integer columns would do, and two tuples with (1, NULL) and (NULL, 1) ?


if (column_values->decompression_type == DT_Scalar)
{
if (!*column_values->output_isnull)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure about this. Are we hashing the two tuples of (NULL, "A") and ("A", NULL) to the same hash code?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, there's a null bitmap at the beginning, which will be different. I think if we can deserialize the key unambiguously, it means we don't confuse such cases.

Copy link
Member Author

Choose a reason for hiding this comment

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

The deserialization code is in serialized_emit_key.

Copy link
Member Author

Choose a reason for hiding this comment

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

We had some tests with nulls but I also added one like you asked, for clarity.

{
const bool is_valid = !*column_values->output_isnull;
byte_bitmap_set_row_validity(serialized_key_validity_bitmap, column_index, is_valid);
if (is_valid)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question about hashing NULLs here. I'm not sure if it is valid to just ignore NULLs

Copy link
Contributor

@dbeck dbeck left a comment

Choose a reason for hiding this comment

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

I downloaded the code and I tested, NULLs are not an issue

@akuzm akuzm enabled auto-merge (squash) March 11, 2025 09:44
The continuous aggregate incremental refresh test accidentally used the
now() function which makes it fail. Replace it with fixed dates.
@akuzm akuzm disabled auto-merge March 11, 2025 10:29
@akuzm akuzm enabled auto-merge (squash) March 11, 2025 10:31
@akuzm akuzm merged commit 89a7fb0 into timescale:main Mar 11, 2025
48 checks passed
@akuzm akuzm deleted the hash-serialized branch March 11, 2025 22:52
@akuzm akuzm added the force-auto-backport Automatically backport this PR or fix of this issue, even if it's not marked as "bug" label Mar 12, 2025
@timescale-automation
Copy link
Member

Automated backport to 2.19.x not done: backport failed.

The PR touches a workflow file '.github/workflows/windows-build-and-test.yaml' and cannot be backported automatically

Job log

@timescale-automation timescale-automation added the auto-backport-not-done Automated backport of this PR has failed non-retriably (e.g. conflicts) label Mar 12, 2025
akuzm added a commit to akuzm/timescaledb that referenced this pull request Mar 12, 2025
Paste the values together and use the umash hash of the resulting value
for grouping, like we do for the text keys.
@akuzm akuzm mentioned this pull request Mar 12, 2025
akuzm added a commit that referenced this pull request Mar 17, 2025
Paste the values together and use the umash hash of the resulting value
for grouping, like we do for the text keys.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport-not-done Automated backport of this PR has failed non-retriably (e.g. conflicts) backported-2.19.x force-auto-backport Automatically backport this PR or fix of this issue, even if it's not marked as "bug"
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants