Skip to content

flash: handle TiCI estimate count RPC#10826

Merged
ti-chi-bot[bot] merged 14 commits intopingcap:feature/ftsfrom
wshwsh12:wsh/tici-estimate-count
Apr 30, 2026
Merged

flash: handle TiCI estimate count RPC#10826
ti-chi-bot[bot] merged 14 commits intopingcap:feature/ftsfrom
wshwsh12:wsh/tici-estimate-count

Conversation

@wshwsh12
Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: None

Problem Summary:

TiDB needs TiFlash to expose TiCI-side estimate count so the optimizer can use sampled TiCI fulltext cardinality instead of relying only on local planner estimates.

What is changed and how it works?

flash: handle GetEstimateTiCICount RPC for TiCI fulltext stats
  • Add FlashService handling for GetEstimateTiCICount.
  • Build TiCI estimate input from the request expression and shard/range list.
  • Return TiCI estimate count to TiDB and ignore missing shards during estimate.
  • Update kvproto to the branch containing the estimate count RPC definitions.

Check List

Tests

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

Manual test:

  • TiUP playground tag: tici-estimate-skew-20260426-2240.
  • Query: EXPLAIN SELECT COUNT(*) FROM estimate_skew WHERE MATCH(content) AGAINST ('heavyhit' IN BOOLEAN MODE);.
  • Result: TiDB used TiCI estimate 4321; exact match count was 4000; total table row count was 9400.
  • Logs confirmed TiFlash GetEstimateTiCICount done, est_count=4321 and TiCI EstimateCountResult { estimated_total_count: 4321, ... }.

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 the release-note-none Denotes a PR that doesn't merit a release note. label Apr 27, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 27, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

🗂️ Base branches to auto review (3)
  • release-8.5
  • release-7.5
  • release-8.1

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 29ae0122-e3d3-4150-b88d-6c76ed6ea289

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ti-chi-bot ti-chi-bot Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 27, 2026
Signed-off-by: wshwsh12 <793703860@qq.com>
Signed-off-by: wshwsh12 <793703860@qq.com>
Signed-off-by: wshwsh12 <793703860@qq.com>
Copy link
Copy Markdown
Contributor

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 PR adds a new TiFlash gRPC endpoint to support TiDB optimizer cardinality estimation for TiCI fulltext queries by forwarding an “estimate count” request to the TiCI search library and returning the result.

Changes:

  • Add FlashService::GetEstimateTiCICount gRPC handler and supporting request parsing / timezone handling.
  • Expose TiCIReadTaskPool::tipbToTiCIExpr for reuse when building the TiCI estimate query from tipb expressions.
  • Refactor getKeyRanges into a reusable helper in TantivyInputStream.h for building TiCI range inputs.

Reviewed changes

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

File Description
dbms/src/Storages/Tantivy/TiCIReadTaskPool.h Exposes expression conversion helper for building TiCI queries outside the task pool.
dbms/src/Storages/Tantivy/TantivyInputStream.h Moves key-range conversion into a shared helper used by both scan and estimate paths.
dbms/src/Flash/FlashService.h Declares the new GetEstimateTiCICount RPC handler.
dbms/src/Flash/FlashService.cpp Implements the new RPC: parses query/ranges/timezone, calls TiCI estimate_count, and returns the estimate.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread dbms/src/Flash/FlashService.cpp Outdated
Comment thread dbms/src/Flash/FlashService.cpp Outdated
Signed-off-by: wshwsh12 <793703860@qq.com>
Signed-off-by: wshwsh12 <793703860@qq.com>
Copy link
Copy Markdown
Contributor

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

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


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread dbms/src/Flash/FlashService.cpp Outdated
Comment thread dbms/src/Flash/FlashService.cpp Outdated
@ChangRui-Ryan
Copy link
Copy Markdown
Contributor

lgtm

Signed-off-by: wshwsh12 <793703860@qq.com>
Copy link
Copy Markdown
Contributor

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

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


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread dbms/src/Flash/FlashService.cpp Outdated
Comment thread dbms/src/Storages/Tantivy/TantivyInputStream.h Outdated
Comment thread dbms/src/Storages/Tantivy/TiCIReadTaskPool.h Outdated
Signed-off-by: wshwsh12 <793703860@qq.com>
@ti-chi-bot ti-chi-bot Bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 29, 2026
@wshwsh12 wshwsh12 requested a review from Copilot April 29, 2026 11:56
Copy link
Copy Markdown
Contributor

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

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread dbms/src/Flash/FlashService.cpp Outdated
Comment thread dbms/src/Storages/Tantivy/TiCIRequestUtils.h
Comment thread dbms/src/Storages/Tantivy/TiCIRequestUtils.h Outdated
Comment thread dbms/src/Storages/Tantivy/TiCIRequestUtils.h Outdated
Signed-off-by: wshwsh12 <793703860@qq.com>
Signed-off-by: wshwsh12 <793703860@qq.com>
Copy link
Copy Markdown
Contributor

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

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread dbms/src/Flash/FlashService.cpp Outdated
Comment on lines +986 to +987
LOG_WARNING(log, "GetEstimateTiCICount failed with unknown exception");
response->set_other_error("other exception");
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

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

catch (...) currently logs only a generic message and sets other_error to a generic string, which makes unexpected failures hard to diagnose in production. Consider calling tryLogCurrentException(log, ...) (or otherwise logging the current exception detail) and returning an other_error that at least indicates an unknown exception occurred (so the server log can be correlated).

Suggested change
LOG_WARNING(log, "GetEstimateTiCICount failed with unknown exception");
response->set_other_error("other exception");
try
{
throw;
}
catch (const std::exception & e)
{
LOG_WARNING(log, "GetEstimateTiCICount failed with unknown std exception: {}", e.what());
}
catch (...)
{
LOG_WARNING(log, "GetEstimateTiCICount failed with unknown non-std exception");
}
response->set_other_error("unknown exception");

Copilot uses AI. Check for mistakes.
namespace DB::TS
{

// Convert literal value from timezone specified in cop request to UTC in-place.
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

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

The comment says the timezone conversion happens "in-place", but convertPackedU64WithTimezone takes from_time by value and returns the converted value instead of mutating an input parameter. Please adjust the comment (or the signature) so it accurately reflects the behavior.

Suggested change
// Convert literal value from timezone specified in cop request to UTC in-place.
// Convert a literal value from the timezone specified in the cop request to UTC and return the converted value.

Copilot uses AI. Check for mistakes.
Signed-off-by: wshwsh12 <793703860@qq.com>
Copy link
Copy Markdown
Contributor

@windtalker windtalker 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 needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Apr 30, 2026
@ti-chi-bot
Copy link
Copy Markdown
Contributor

ti-chi-bot Bot commented Apr 30, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JinheLin, windtalker

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

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [JinheLin,windtalker]

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 Apr 30, 2026
@ti-chi-bot
Copy link
Copy Markdown
Contributor

ti-chi-bot Bot commented Apr 30, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-04-30 07:09:24.718207631 +0000 UTC m=+2840969.923567678: ☑️ agreed by windtalker.
  • 2026-04-30 07:15:02.398809724 +0000 UTC m=+2841307.604169781: ☑️ agreed by JinheLin.

@ti-chi-bot
Copy link
Copy Markdown
Contributor

ti-chi-bot Bot commented Apr 30, 2026

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

Test name Commit Details Required Rerun command
pull-sanitizer-asan b0f8f1e link false /test pull-sanitizer-asan
pull-sanitizer-tsan b0f8f1e link false /test pull-sanitizer-tsan

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 4d9b25a into pingcap:feature/fts Apr 30, 2026
5 of 7 checks passed
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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants