Skip to content

*: support Local MATCH AGAINST Boolean evaluation and TiFlash pushdown | pd=release-8.5 tikv=release-8.5 tiflash=release-8.5 ticdc=release-8.5 - #71839

Merged
ti-chi-bot[bot] merged 33 commits into
pingcap:feature/release-8.5-ftsfrom
solotzg:codex/match-against-feature-8.5-fts
Oct 21, 2026
Merged

ti-chi-bot[bot] merged 33 commits into
pingcap:feature/release-8.5-ftsfrom
solotzg:codex/match-against-feature-8.5-fts

Conversation

@solotzg

@solotzg solotzg commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: ref #71397 pingcap/tiflash#11111

Provide row-wise Boolean Local MATCH and eligible TiFlash scalar pushdown without relying on TiCI or inverted-index consistency.

What changed and how does it work?

  • tidb_enable_local_match_against (default OFF) gates both TiDB and TiFlash local execution. With the gate ON, eligible TiFlash MPP Selection evaluation is available to the optimizer; unsupported pushdown is evaluated at TiDB root. OFF rejects Local MATCH. This PR does not implement native indexed FTS.
  • A matching public FULLTEXT definition is still required to select the parser. MATCH columns must equal its complete column set, in any order. All columns in one MATCH must have the same collation; mixed collations return error 1235. No inverted-index contents are read.
  • Encode the Boolean AST and analyzer configuration in Expr.val for LocalMatchAgainstBoolean = 5250. Semantic protocol version 2 is shared with TiFlash; unsupported versions are rejected. Deploy compatible TiFlash support before TiDB emits a new version, and do not silently change an existing version's meaning.
  • Support the existing required/optional/prohibited words, quoted phrases and trailing * prefixes with STANDARD/NGRAM, configured token lengths, built-in stopwords, NULL searches/documents and multiple MATCH columns. This is no-score Boolean filtering, not relevance ranking or new Boolean syntax.
  • Compare tokens using the MATCH collation and stopwords using the separately transmitted collation_server. Align BMP word classification and multibyte NGRAM scanning across Go/C++; preserve filtered phrase positions and verify necessary phrases against the unfiltered document.
  • Disable prepared and non-prepared plan cache for Local MATCH, including force-cache controls, to avoid stale analyzer settings and bound searches. Ordinary SQL caching is unchanged. Unsupported STANDARD split-prefix and legacy-collation paths remain at TiDB root.
  • Precompute owned stopword keys, prefix patterns and collation-aware dense-phrase failure tables without caching documents/results. Preserve small NGRAM bucket Compare and malformed-input behavior.
  • Product unit/regression tests are included in this PR. Real-cluster E2E, the plan checker, MySQL oracles and performance/profile/pressure tools are maintained separately, pending unified test-system integration.

Dependencies

Paired with TiFlash PR pingcap/tiflash#11111. The scalar-ID reservation pingcap/tipb#431 and feature protocol pingcap/tipb#432 are merged. Both products use the official PingCAP Tipb revision 4044aac591d778250cad3488dfd6e6f574411f1a: TiDB through module version v0.0.0-20261014084553-4044aac591d7 and TiFlash through contrib/tipb. The forked Tipb dependency is no longer required. Compatible TiFlash support must be deployed before enabling TiDB pushdown that emits this protocol.

Correctness verification (2026-10-12)

The correctness and performance results below are historical evidence from the 2026-10-12 validation runs, not a fresh rerun of the current PR heads. The latest follow-up changes have not been rerun locally; their validation is left to CI for the corresponding PR heads. Historical E2E/performance results do not establish current-head or formal release acceptance.

  • Focused Go analyzer/parser/generator and expression/planner regressions passed; fulltext unit and race tests passed. All 31 paired TiFlash Local MATCH/character-classification/DAG/block gtests passed.
  • Selected real TiUP E2E passed locally and independently on h124. Coverage includes Boolean evaluation, seeded differential checks, committed snapshots, large documents, range/plans, prepared/cache behavior, collation regressions and stopwords.
  • Native tests wait for replica AVAILABLE=1, compare complete matched results and require MATCH in mpp[tiflash] Selection without a root MATCH residual. Fallback tests compare complete row IDs and assert TiDB root evaluation. No TiCI path is used.
  • Real MySQL 8.0.44 InnoDB / Go matcher / TiDB fallback / TiFlash MPP comparisons passed at NGRAM sizes 1, 2 and 3, each with 680 searches and 40 NULL/NOT checks.
  • Separate regression checks completed 3,648 successful timed queries and 1,104 complete-result/plan verifications with no query errors or selected correctness regressions. Finite test matrices do not prove complete MySQL compatibility or full-repository correctness.

Performance verification

On the shared h124 server, a development benchmark used 20,000 × 4 KiB repeated synthetic documents, STANDARD/NGRAM, stopwords OFF/ON, five query shapes, default MPP settings and native SQL threads=1. Single-connection TiFlash MPP end-to-end P50 was 2.96–6.95× faster than TiDB fallback across the selected cases; complete matched IDs and actual plan placement were checked. This compares different scan engines and execution paths, not isolated Go/C++ matcher speed.

Separate paired regression checks observed persistent small increases for NGRAM size=2 with stopwords ON: about 0.8–1.0% for TiDB word/prefix/phrase in an independent follow-up and 1.3–2.2% for TiFlash prefix/CJK in the main measurements. Root cause is not established; do not claim zero performance regression or use other cases' improvements to cancel these observations.

These are development measurements, not an SLA or release acceptance. The host is shared, CPU frequency is not pinned, the corpus is repetitive and highly compressible, and h124 TiFlash is RELWITHDEBINFO (-O2 -g -DNDEBUG), not an official release package. Tests use official v8.5.8 PD/TiKV with locally built modified products, identified by runtime versions and binary fingerprints; TiDB identity is checked with tidb_version(). Raw logs, measurements, complete-result/plan records and detailed reports are retained outside the product repositories and are not public CI artifacts.

Remaining acceptance work

  • Historical focused product unit/regression tests and real-cluster result/plan verification
  • Historical NGRAM 1/2/3 MySQL comparisons and selected performance/regression measurements
  • Use merged official Tipb protocol dependencies in both products
  • Integrate external correctness, performance and pressure suites into the unified test system
  • Resolve or explicitly assess the observed small performance increases for release acceptance
  • Formal release-binary, resource/sanitizer, broader concurrency and replica/schema/mixed-version lifecycle acceptance

Opt-in memory pressure was skipped; ASAN/UBSAN and full token/position differential coverage remain pending. Ready for code review does not mean formal release acceptance.

Release note

Support gated row-wise Boolean Local MATCH with eligible TiFlash scalar pushdown and TiDB fallback, requiring public FULLTEXT parser metadata but not reading an inverted index.

Summary by CodeRabbit

  • New Features
    • Boolean MATCH ... AGAINST searches can run in TiFlash when supported; TiDB handles cases that cannot be pushed down.
  • Bug Fixes
    • Full-text searches better respect column and stopword collations, including NGRAM and phrase matching.
    • NULL search terms now return a non-NULL zero result.
    • Improved handling of Unicode, stopwords, prefixes, and short NGRAM tokens.

@ti-chi-bot

ti-chi-bot Bot commented Oct 9, 2026

Copy link
Copy Markdown

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@ti-chi-bot ti-chi-bot Bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Oct 9, 2026
@coderabbitai

coderabbitai Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c86b2443-1e44-418a-be47-f818239219d7
📥 Commits

Reviewing files that changed from the base of the PR and between f918794 and 6bf2b1a.

📒 Files selected for processing: 1
  • pkg/expression/matchagainst/generator/main.go
🚧 Files skipped from review as they are similar to previous changes: 1
  • pkg/expression/matchagainst/generator/main.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📝 Walkthrough

Local Boolean MATCH ... AGAINST gains collation-aware analysis and matching, a versioned query representation, and TiFlash pushdown support. Planner logic selects matching public FULLTEXT indexes and attaches metadata for eligible TiFlash evaluation. Tests cover query behavior, serialization, and planner execution paths.

Changes: Local MATCH execution

Layer / File(s) Summary
Analyzer and query matching
pkg/expression/fulltext/analyzer.go, pkg/expression/fulltext/document.go, pkg/expression/fulltext/query.go, pkg/expression/matchagainst/*, related tests
Analyzer and document processing now use collation-aware token and stopword handling. Query matching applies collation to terms, prefixes, and phrases, and adds source-text verification for filtered phrases. NGRAM scanning and token classification are updated.
Boolean-query protocol
DEPS.bzl, go.mod, pkg/expression/fulltext/local_match_against_tipb.go, related tests and BUILD.bazel
Adds a versioned TiFlash Boolean-query representation with analyzer settings. Serialization handles supported query clauses and rejects unsupported forms. Analyzer settings can be restored from the wire representation.
Expression evaluation and protobuf conversion
pkg/expression/builtin.go, pkg/expression/builtin_fts.go, pkg/expression/distsql_builtin.go, pkg/expression/expr_to_pb.go, pkg/expression/infer_pushdown.go, related tests
Separates TiDB local-evaluation metadata from TiFlash Boolean-query metadata. Protobuf conversion validates and serializes eligible Local MATCH expressions; decoding reconstructs their analyzer configuration. A NULL search evaluates to zero with a non-NULL result in local evaluation.
Planner eligibility and TiFlash pushdown
pkg/planner/core/expression_rewriter.go, pkg/planner/core/local_match_against_pushdown_test.go, pkg/planner/core/fts_index_test.go, related tests, pkg/sessionctx/variable/*
Planner logic matches requested columns to a public FULLTEXT index regardless of order, rejects duplicate columns and mixed collations, and attaches TiFlash metadata when its conditions are met. Local MATCH plan caching is disabled. Tests cover pushdown, TiDB fallback, and analyzer settings.

Priority: ⬆️ High

Estimated code review effort: 4 (Complex) | ~60 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Planner
  participant Expression as TiDB expression conversion
  participant TiFlash
  Planner->>Expression: Attach Boolean query and analyzer metadata
  Expression->>TiFlash: Serialize eligible Local MATCH scalar
  TiFlash->>TiFlash: Evaluate Boolean MATCH expression
Loading
Merge Risk: ⚪ Minimal · up to 6bf2b

This change adds a developer-side generator for a header file and does not alter default runtime behavior. No actionable merge-blocking risk was identified in the supplied context.

Security architecture risk: 🔵 Low · up to 41ea1

The feature remains off by default, and unsupported configurations retain local evaluation. No introduced security vulnerability was established. The main design risk is compatibility during upgrades or downgrades: enabling pushdown depends on compatible TiFlash support, whose behavior could not be verified here.

Retained concerns

  • Low · architecture · inferred: TiFlash compatibility is an external rollout prerequisite rather than an enforced placement invariant. With Local MATCH enabled, the inspected paths can serialize version 2 for an available replica without checking that peer’s protocol support. An older or downgraded peer may therefore fail affected queries. Planning-time fallback for unsupported configurations does not establish fallback after remote rejection. Default-OFF gating and the existing pushdown blacklist limit exposure; receiver and recovery behavior remain unverified.
Security review details

Security Blast Radius

  • inferred — Compared with the base, eligible enabled queries expose TiFlash’s Local MATCH decoder and evaluator to SQL-supplied search terms and scanned document values. The inspected planner binds these expressions to one resolved table and its replica. Maximum tenant, fleet or environment exposure cannot be established without receiver and deployment-policy evidence.

Trust Boundaries and Controls

  • observed — TiDB controls which MATCH expressions cross the execution boundary through planner eligibility, dedicated metadata and fail-closed serialization. The Go receiver restores analyzer settings from the request rather than its session and validates the semantic version. These are semantic boundary controls, not evidence of TiFlash authentication, authorization or tenant isolation.

Resilience and Maintainability Implications

  • observed — Failure containment is demonstrated locally: failed compilation does not publish partial cache state, rejected serialization returns no payload, and fallback tests inspect root evaluation for unsupported configurations. Those tests use fake replicas and do not establish recovery from rejection by a real TiFlash peer.

Hardening Proposals

  • proposed — Before enabling pushdown, verify the paired schema and TiFlash receiver recognize the dedicated signature and version 2, reject unsupported versions, and have a defined downgrade outcome. Keep Local MATCH pushdown blacklisted during incompatible upgrade or rollback states if TiDB-local execution must remain available.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 24.14% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 145 functions across 31 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title clearly identifies the main change: Local MATCH AGAINST Boolean evaluation and TiFlash pushdown. The release-branch suffix adds repository metadata but does not make the title misleading.
Description check Passed The description is detailed and covers the problem, implementation, dependencies, testing, performance, remaining acceptance work, and release note. It omits the template's explicit Check List, Side e…
Full details: Description check

Explanation

The description is detailed and covers the problem, implementation, dependencies, testing, performance, remaining acceptance work, and release note. It omits the template's explicit Check List, Side effects, and Documentation headings, but the key information is provided elsewhere.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

A rabbit reads the tokens bright,
Then checks each phrase in collation light.
Through NGRAM fields the query goes,
To TiFlash where the Boolean flows.
The rabbit hops past stopwords small,
And finds the match among them all.

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

@ti-chi-bot ti-chi-bot Bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. sig/planner SIG: Planner labels Oct 9, 2026
Require default MPP execution settings, validate decoded statement-summary envelopes, and reject cop/batchCop-only native plans. Add a collation-aware stopword differential matrix and reusable h124 cluster, SQL benchmark, process sampling, and CPU profile tools.

Verified with real TiUP clusters at token sizes 2/3 and paired single-thread server runs; benchmark tool and plan-validator unit tests pass.
@codecov

codecov Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.97063% with 149 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (feature/release-8.5-fts@54acfe3). Learn more about missing BASE report.

Additional details and impacted files
@@                     Coverage Diff                      @@
##             feature/release-8.5-fts     #71839   +/-   ##
============================================================
  Coverage                           ?   55.3315%           
============================================================
  Files                              ?       1866           
  Lines                              ?     670829           
  Branches                           ?          0           
============================================================
  Hits                               ?     371180           
  Misses                             ?     271913           
  Partials                           ?      27736           
Flag Coverage Δ
integration 38.3874% <32.2714%> (?)
unit 65.2553% <80.9706%> (?)

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

Components Coverage Δ
dumpling 55.3108% <0.0000%> (?)
parser ∅ <0.0000%> (?)
br 54.9330% <0.0000%> (?)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@solotzg solotzg changed the title *: support Local MATCH AGAINST Boolean evaluation and TiFlash pushdown | pd=release-8.5 tikv=release-8.5 tiflash=release-8.5 *: support Local MATCH AGAINST Boolean evaluation and TiFlash pushdown | pd=release-8.5 tikv=release-8.5 tiflash=release-8.5 ticdc=release-8.5 Oct 13, 2026
@ti-chi-bot

ti-chi-bot Bot commented Oct 13, 2026

Copy link
Copy Markdown

@solotzg: solotzg unauthorized: /override is restricted to Repo administrators, and the following github teams:pingcap/tidb: tidb-maintainers qa-release-merge.

Details

In response to this:

/override pull-integration-tici-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.

@solotzg

solotzg commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

/cc @AilinKid

@ti-chi-bot
ti-chi-bot Bot requested a review from AilinKid October 21, 2026 02:21
@ti-chi-bot ti-chi-bot Bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Oct 21, 2026
@AilinKid

Copy link
Copy Markdown
Contributor

/test pull-integration-tici-test

@ti-chi-bot

ti-chi-bot Bot commented Oct 21, 2026

Copy link
Copy Markdown

@solotzg: 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
pull-integration-tici-test 6bf2b1a link false /test pull-integration-tici-test

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.

@solotzg

solotzg commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

/cc @windtalker @qw4990

@ti-chi-bot
ti-chi-bot Bot requested review from qw4990 and windtalker October 21, 2026 06:09
@ti-chi-bot ti-chi-bot Bot added the lgtm label Oct 21, 2026
@ti-chi-bot

ti-chi-bot Bot commented Oct 21, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: AilinKid, qw4990
Once this PR has been reviewed and has the lgtm label, please assign terry1purcell, windtalker 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 removed the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Oct 21, 2026
@ti-chi-bot

ti-chi-bot Bot commented Oct 21, 2026

Copy link
Copy Markdown

[LGTM Timeline notifier]

Timeline:

  • 2026-10-21 02:59:35.868051853 +0000 UTC m=+159188.128138780: ☑️ agreed by AilinKid.
  • 2026-10-21 06:59:22.531855625 +0000 UTC m=+173574.791942552: ☑️ agreed by qw4990.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. 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.

4 participants