Skip to content

*: add aggregate function sum_int #66085

Merged
ti-chi-bot[bot] merged 9 commits intopingcap:feature/release-8.5-materialized-viewfrom
windtalker:feature/materialized_view
Feb 14, 2026
Merged

*: add aggregate function sum_int #66085
ti-chi-bot[bot] merged 9 commits intopingcap:feature/release-8.5-materialized-viewfrom
windtalker:feature/materialized_view

Conversation

@windtalker
Copy link
Contributor

@windtalker windtalker commented Feb 5, 2026

What problem does this PR solve?

Issue Number: ref #66124

Problem Summary:

What changed and how does it work?

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

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

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Feb 5, 2026
@tiprow
Copy link

tiprow bot commented Feb 5, 2026

Hi @windtalker. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@codecov
Copy link

codecov bot commented Feb 5, 2026

Codecov Report

❌ Patch coverage is 50.25253% with 197 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (feature/release-8.5-materialized-view@b476f8f). Learn more about missing BASE report.

Additional details and impacted files
@@                            Coverage Diff                             @@
##             feature/release-8.5-materialized-view     #66085   +/-   ##
==========================================================================
  Coverage                                         ?   57.2771%           
==========================================================================
  Files                                            ?       1787           
  Lines                                            ?     639677           
  Branches                                         ?          0           
==========================================================================
  Hits                                             ?     366389           
  Misses                                           ?     248704           
  Partials                                         ?      24584           
Flag Coverage Δ
integration 37.4038% <0.7575%> (?)
unit 72.7943% <50.2525%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 52.9278% <0.0000%> (?)
parser ∅ <0.0000%> (?)
br 52.7576% <0.0000%> (?)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds a new aggregate function sum_int to TiDB. The new function is designed to sum integer values and return an integer result (TypeLonglong), as opposed to the regular sum function which returns decimal or double results for integer inputs.

Changes:

  • Added parser support for the SUM_INT SQL function
  • Implemented core aggregation logic for signed and unsigned integers with distinct support
  • Added executor-level implementation with sliding window support and spill/serialization capabilities
  • Updated aggregation descriptors and metadata to include sum_int in relevant operations
  • Explicitly disabled push-down to storage engines for this function
  • Added unit and integration tests

Reviewed changes

Copilot reviewed 15 out of 16 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
pkg/parser/parser.y Added grammar rule for SUM_INT function
pkg/parser/misc.go Added token mapping for SUM_INT keyword
pkg/parser/ast/functions.go Added constant for AggFuncSumInt
pkg/expression/aggregation/sum_int.go Core aggregation logic implementation
pkg/expression/aggregation/descriptor.go Updated to handle sum_int in aggregation operations
pkg/expression/aggregation/base_func.go Added type inference and validation for sum_int
pkg/expression/aggregation/aggregation.go Added sum_int to helper functions and disabled push-down
pkg/expression/aggregation/BUILD.bazel Added sum_int.go to build configuration
pkg/executor/aggfuncs/func_sum_int.go Executor implementation with sliding window and spill support
pkg/executor/aggfuncs/builder.go Added builder function for sum_int
pkg/executor/aggfuncs/BUILD.bazel Added func_sum_int.go to build configuration
pkg/executor/aggfuncs/spill_serialize_helper.go Added serialization for sum_int partial results
pkg/executor/aggfuncs/spill_deserialize_helper.go Added deserialization for sum_int partial results
pkg/executor/aggfuncs/func_sum_test.go Added unit tests for sum_int
pkg/executor/test/aggregate/aggregate_test.go Added integration test for sum_int

@@ -0,0 +1,88 @@
// Copyright 2017 PingCAP, Inc.
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

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

The copyright year should be 2025 for this new file, not 2017. This appears to have been copied from an existing file template without updating the year.

Copilot uses AI. Check for mistakes.
@windtalker windtalker force-pushed the feature/materialized_view branch 2 times, most recently from 3c71d2f to 4cfcf7d Compare February 12, 2026 12:01
Comment on lines +155 to +184
for i := uint64(0); i < shiftEnd; i++ {
input, isNull, err := e.args[0].EvalInt(sctx, getRow(lastEnd+i))
if err != nil {
return err
}
if isNull {
continue
}
sum, err := types.AddInt64(p.val, input)
if err != nil {
return err
}
p.val = sum
p.notNullRowCount++
}
for i := uint64(0); i < shiftStart; i++ {
input, isNull, err := e.args[0].EvalInt(sctx, getRow(lastStart+i))
if err != nil {
return err
}
if isNull {
continue
}
sum, err := types.SubInt64(p.val, input)
if err != nil {
return err
}
p.val = sum
p.notNullRowCount--
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's better to move the sub before the add to avoid the overflow issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I've update the code to sub fist

Comment on lines +335 to +364
for i := uint64(0); i < shiftEnd; i++ {
input, isNull, err := e.args[0].EvalInt(sctx, getRow(lastEnd+i))
if err != nil {
return err
}
if isNull {
continue
}
sum, err := types.AddUint64(p.val, uint64(input))
if err != nil {
return err
}
p.val = sum
p.notNullRowCount++
}
for i := uint64(0); i < shiftStart; i++ {
input, isNull, err := e.args[0].EvalInt(sctx, getRow(lastStart+i))
if err != nil {
return err
}
if isNull {
continue
}
sum, err := types.SubUint64(p.val, uint64(input))
if err != nil {
return err
}
p.val = sum
p.notNullRowCount--
}
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

@ti-chi-bot
Copy link

ti-chi-bot bot commented Feb 12, 2026

@gengliqi: adding LGTM is restricted to approvers and reviewers in OWNERS files.

Details

In response to this:

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Signed-off-by: xufei <xufeixw@mail.ustc.edu.cn>
Signed-off-by: xufei <xufeixw@mail.ustc.edu.cn>
Signed-off-by: xufei <xufeixw@mail.ustc.edu.cn>
Signed-off-by: xufei <xufeixw@mail.ustc.edu.cn>
Signed-off-by: xufei <xufeixw@mail.ustc.edu.cn>
Signed-off-by: xufei <xufeixw@mail.ustc.edu.cn>
Signed-off-by: xufei <xufeixw@mail.ustc.edu.cn>
Signed-off-by: xufei <xufeixw@mail.ustc.edu.cn>
@windtalker windtalker force-pushed the feature/materialized_view branch from 4cfcf7d to 222a32d Compare February 13, 2026 06:48
@ti-chi-bot ti-chi-bot bot added the sig/planner SIG: Planner label Feb 13, 2026
@windtalker
Copy link
Contributor Author

/test build

@windtalker
Copy link
Contributor Author

/test unit-test

@windtalker
Copy link
Contributor Author

/test check-dev

@windtalker
Copy link
Contributor Author

/test check-dev2

@tiprow
Copy link

tiprow bot commented Feb 13, 2026

@windtalker: PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test.

Details

In response to this:

/test build

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@tiprow
Copy link

tiprow bot commented Feb 13, 2026

@windtalker: PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test.

Details

In response to this:

/test unit-test

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@tiprow
Copy link

tiprow bot commented Feb 13, 2026

@windtalker: PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test.

Details

In response to this:

/test check-dev

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@tiprow
Copy link

tiprow bot commented Feb 13, 2026

@windtalker: PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test.

Details

In response to this:

/test check-dev2

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Signed-off-by: xufei <xufeixw@mail.ustc.edu.cn>
@hawkingrei
Copy link
Member

/ok-to-test

@ti-chi-bot ti-chi-bot bot added the ok-to-test Indicates a PR is ready to be tested. label Feb 13, 2026
Copy link
Contributor

@xzhangxian1008 xzhangxian1008 left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Feb 14, 2026
@windtalker
Copy link
Contributor Author

/test fast_test_tiprow_for_release

@ti-chi-bot
Copy link

ti-chi-bot bot commented Feb 14, 2026

@windtalker: The specified target(s) for /test were not found.
The following commands are available to trigger required jobs:

/test build
/test check-dev
/test check-dev2
/test mysql-test
/test pull-br-integration-test
/test pull-unit-test-ddlv1
/test unit-test

The following commands are available to trigger optional jobs:

/test pull-common-test
/test pull-e2e-test
/test pull-integration-common-test
/test pull-integration-copr-test
/test pull-integration-ddl-test
/test pull-integration-e2e-test
/test pull-integration-jdbc-test
/test pull-integration-mysql-test
/test pull-integration-nodejs-test
/test pull-integration-python-orm-test
/test pull-integration-tidb-tools-test
/test pull-lightning-integration-test
/test pull-mysql-client-test
/test pull-sqllogic-test

Use /test all to run the following jobs that were automatically triggered:

pingcap/tidb/release-8.5/pull_build
pingcap/tidb/release-8.5/pull_check
pingcap/tidb/release-8.5/pull_check2
pingcap/tidb/release-8.5/pull_mysql_test
pingcap/tidb/release-8.5/pull_unit_test
Details

In response to this:

/test fast_test_tiprow_for_release

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@ti-chi-bot
Copy link

ti-chi-bot bot commented Feb 14, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: gengliqi, wshwsh12, xzhangxian1008
Once this PR has been reviewed and has the lgtm label, please assign tangenta, wddevries, yudongusa, zanmato1984 for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

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

Details 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 Feb 14, 2026
@ti-chi-bot
Copy link

ti-chi-bot bot commented Feb 14, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-02-14 05:17:45.84054979 +0000 UTC m=+72833.586943815: ☑️ agreed by xzhangxian1008.
  • 2026-02-14 05:58:07.538497523 +0000 UTC m=+75255.284891554: ☑️ agreed by wshwsh12.

@gengliqi
Copy link
Contributor

/retest

@tiprow
Copy link

tiprow bot commented Feb 14, 2026

@windtalker: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
fast_test_tiprow_for_release 00e198d link true /test fast_test_tiprow_for_release

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@ti-chi-bot ti-chi-bot bot merged commit 6ac0a2f into pingcap:feature/release-8.5-materialized-view Feb 14, 2026
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm ok-to-test Indicates a PR is ready to be tested. release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants