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

overwrite addBatchSinglePlace and addBatchSinglePlaceNotNull in AggregateFunctionCountNotNullUnary #9563

Conversation

windtalker
Copy link
Contributor

@windtalker windtalker commented Oct 29, 2024

What problem does this PR solve?

Issue Number: ref #9146

Problem Summary:

What is changed and how it works?

AggregateFunctionCountNotNullUnary does not overwrite addBatchSinglePlace and addBatchSinglePlaceNotNull, so the code path will be

void addBatchSinglePlace(
size_t start_offset,
size_t batch_size,
AggregateDataPtr place,
const IColumn ** columns,
Arena * arena,
ssize_t if_argument_pos = -1) const override
{
if (if_argument_pos >= 0)
{
const auto & flags = assert_cast<const ColumnUInt8 &>(*columns[if_argument_pos]).getData();
for (size_t i = start_offset; i < start_offset + batch_size; ++i)
{
if (flags[i])
static_cast<const Derived *>(this)->add(place, columns, i, arena);
}
}
else
{
for (size_t i = start_offset; i < start_offset + batch_size; ++i)
static_cast<const Derived *>(this)->add(place, columns, i, arena);
}
}

In fact, AggregateFunctionCountNotNullUnary can be optimized by count the element number in batch like AggregateFunctionCount by overwrite addBatchSinglePlace and addBatchSinglePlaceNotNull


Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

None

@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-linked-issue release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed do-not-merge/needs-linked-issue labels Oct 29, 2024
@windtalker
Copy link
Contributor Author

/test pull-unit-test

Signed-off-by: xufei <xufeixw@mail.ustc.edu.cn>
@windtalker windtalker force-pushed the add_missing_overwrite_function_in_agg_count branch from b836940 to 86c0dc5 Compare October 29, 2024 03:15
Copy link
Contributor

@yibin87 yibin87 left a comment

Choose a reason for hiding this comment

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

What're the differences between these two functions? Only the way that the nullmap is passed?

@windtalker
Copy link
Contributor Author

What're the differences between these two functions? Only the way that the nullmap is passed?

addBatchSinglePlace is the public function that will be called from Aggregator directly, addBatchSinglePlaceNotNull is kind of a protect function that usually be called inside AggregateFunctionXXX.

Comment on lines 143 to 152
if (if_argument_pos >= 0)
{
const auto & flags = assert_cast<const ColumnUInt8 &>(*columns[if_argument_pos]).getData();
data(place).count
+= countBytesInFilterWithNull(flags, nc.getNullMapData().data(), start_offset, batch_size);
}
else
{
data(place).count += batch_size - countBytesInFilter(nc.getNullMapData().data(), start_offset, batch_size);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

How about calling addBatchSinglePlaceNotNull here directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea.

Signed-off-by: xufei <xufeixw@mail.ustc.edu.cn>
@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Oct 29, 2024
Copy link
Contributor

@yibin87 yibin87 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

ti-chi-bot bot commented Oct 30, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gengliqi, yibin87

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Oct 30, 2024
Copy link
Contributor

ti-chi-bot bot commented Oct 30, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-10-29 16:09:26.231694667 +0000 UTC m=+366079.070850213: ☑️ agreed by gengliqi.
  • 2024-10-30 01:11:32.528145168 +0000 UTC m=+398605.367300709: ☑️ agreed by yibin87.

@ti-chi-bot ti-chi-bot bot merged commit 43a0a69 into pingcap:master Oct 30, 2024
5 checks passed
@windtalker windtalker deleted the add_missing_overwrite_function_in_agg_count branch December 6, 2024 00:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants