Skip to content

columnar: add scan details stats#10905

Open
yongman wants to merge 5 commits into
pingcap:masterfrom
yongman:scan-details
Open

columnar: add scan details stats#10905
yongman wants to merge 5 commits into
pingcap:masterfrom
yongman:scan-details

Conversation

@yongman

@yongman yongman commented Jun 18, 2026

Copy link
Copy Markdown
Member

What problem does this PR solve?

Issue Number: close #10906

Problem Summary:
There is no execute summary info in explain when query columnar.

What is changed and how it works?

Add columnar stats in explain and logs.

TiDB root@localhost:test> explain analyze select * from t;
+----------------------+---------+---------+--------------+---------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------+----------+------+
| id                   | estRows | actRows | task         | access object | execution info                                                                                                                                                                                                                                                                                                                                                                                                | operator info                             | memory   | disk |
+----------------------+---------+---------+--------------+---------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------+----------+------+
| TableReader_12       | 8204.00 | 8204    | root         | partition:all | time:63.5ms, loops:10, RU:5.38, cop_task: {num: 2, max: 0s, min: 0s, avg: 0s, p95: 0s, copr_cache_hit_ratio: 0.00}                                                                                                                                                                                                                                                                                            | MppVersion: 2, data:ExchangeSender_11     | 192.7 KB | N/A  |
| └─ExchangeSender_11  | 8204.00 | 8204    | mpp[tiflash] |               | tiflash_task:{time:52.8ms, loops:1, threads:1}                                                                                                                                                                                                                                                                                                                                                                | ExchangeType: PassThrough                 | N/A      | N/A  |
|   └─TableFullScan_10 | 8204.00 | 8204    | mpp[tiflash] | table:t       | tiflash_task:{time:44.8ms, loops:1, threads:1}, columnar_scan:{mvcc_input_rows:8204, mvcc_input_bytes:360976, mvcc_output_rows:8204, regions:1, read_tasks:1, physical_tables:3, columns:3, user_read_bytes:155876, read_block:8ms, serialize_block:0ms, init_reader:12ms, prefetch:0ms, deserialize_block:4ms, rough_check:{total:0, selected:0, skipped:0, unknown:0}, remote_segments:0, total_segments:4} | keep order:false, PartitionTableScan:true | N/A      | N/A  |
+----------------------+---------+---------+--------------+---------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------+----------+------+

3 rows in set
Time: 0.077s

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

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added end-to-end columnar scan metrics collection (MVCC rows/bytes, timing breakdowns, rough-check counters, and segment counts) exposed via the engine callback interface.
    • Execution summaries and scan trace JSON now include columnar scan context data when available.
  • Bug Fixes

    • Improved stats aggregation by ensuring reader statistics are merged during reader release/cleanup.
    • Scan trace serialization now prefers columnar context and avoids emitting incomplete traces.
  • Chores

    • Updated relevant subproject revisions and aligned workspace dependency configuration.

yongman added 2 commits June 17, 2026 14:53
Signed-off-by: yongman <yming0221@gmail.com>
Signed-off-by: yongman <yming0221@gmail.com>
@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. labels Jun 18, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign fzhedu 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 the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jun 18, 2026
@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 909b6688-8c43-4f47-86f8-dd76478630e8

📥 Commits

Reviewing files that changed from the base of the PR and between b9ac619 and 7392354.

⛔ Files ignored due to path filters (1)
  • contrib/tiflash-columnar-hub/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (1)
  • contrib/tiflash-columnar-hub/Cargo.toml
🚧 Files skipped from review as they are similar to previous changes (1)
  • contrib/tiflash-columnar-hub/Cargo.toml

📝 Walkthrough

Walkthrough

Adds end-to-end columnar scan statistics collection. A new ColumnarScanStats FFI struct and ffi_columnar_scan_stats function are defined in the Rust/C FFI layer and wired into the hub runtime. On the C++ side, ColumnarScanContext is introduced as an atomic-counter accumulator with protobuf serialization, merged into DAGContext, ExecutionSummary, and ExecutorStatisticsCollector. StorageDisaggregatedColumnar registers contexts and collects stats via the proxy FFI at reader release. Submodule references for tipb and cloud-storage-engine are also updated.

Changes

Columnar Scan Statistics End-to-End

Layer / File(s) Summary
Submodule updates and dependency changes
contrib/cloud-storage-engine, contrib/tipb, contrib/tiflash-columnar-hub/Cargo.toml, contrib/tiflash-columnar-hub/hub-runtime/Cargo.toml, contrib/tiflash-columnar-hub/hub-runtime/src/cloud_helper.rs
Updates cloud-storage-engine and tipb submodule pointers, adds chrono and url to workspace dependencies, switches url in hub-runtime to workspace-provided version, and extends SnapCtx with strict file memory quota fields (strict_file_memory_quota_wait_timeout and strict_file_memory_quota).
FFI contract: ColumnarScanStats struct and interface extension
contrib/tiflash-columnar-hub/hub-runtime/ffi/src/RaftStoreProxyFFI/ProxyFFI.h, contrib/tiflash-columnar-hub/hub-runtime/src/interfaces.rs
Defines ColumnarScanStats with uint64_t MVCC/timing/segment fields in the C header and adds fn_columnar_scan_stats to SSTReaderInterfaces. Adds Default/Copy/Clone derives to ColumnarScanStats and fn_columnar_scan_stats callback to CloudStorageEngineInterfaces in Rust.
Rust FFI implementation: stats conversion and wiring
contrib/tiflash-columnar-hub/hub-runtime/src/columnar_impls.rs, contrib/tiflash-columnar-hub/hub-runtime/src/run.rs
Implements From<ColumnarRuntimeStats> for ColumnarScanStats and exports ffi_columnar_scan_stats as an extern "C" function. Registers it into cloud_storage_engine_interfaces in build_hub_ffi_helper.
C++ ColumnarScanContext class: metrics accumulator with serialization and merge
dbms/src/Flash/Coprocessor/ColumnarScanContext_fwd.h, dbms/src/Flash/Coprocessor/ColumnarScanContext.h
Introduces forward declaration with ColumnarScanContextPtr alias. Defines ColumnarScanContext with atomic counters for MVCC/timing/segment metrics, deserialize/serialize for protobuf conversion (milliseconds ↔ nanoseconds), three merge overloads (from ColumnarScanContext, tipb::ColumnarScanContext, and ColumnarScanStats), toJson() for millisecond-scaled JSON output, and addUserReadBytes/addDeserializeBlockNs increment helpers.
DAGContext, ExecutionSummary, and statistics collector integration
dbms/src/Flash/Coprocessor/DAGContext.h, dbms/src/Flash/Coprocessor/ExecutionSummary.h, dbms/src/Flash/Coprocessor/ExecutionSummary.cpp, dbms/src/Flash/Statistics/ExecutionSummaryHelper.cpp, dbms/src/Flash/Statistics/ExecutorStatisticsCollector.cpp
Adds columnar_scan_context_map to DAGContext and columnar_scan_context to ExecutionSummary. Extends merge/init in ExecutionSummary for columnar contexts with lazy initialization. Updates ExecutorStatisticsCollector to merge from columnar_scan_context_map and ExecutionSummaryHelper to serialize columnar_scan_context when present.
StorageDisaggregatedColumnar stats registration, collection, and JSON reporting
dbms/src/Storages/StorageDisaggregatedColumnar.h, dbms/src/Storages/StorageDisaggregatedColumnar.cpp, dbms/src/Flash/Statistics/TableScanImpl.cpp
Registers ColumnarScanContext in columnar_scan_context_map at RN columnar task construction. Adds mergeReaderStats() to call fn_columnar_scan_stats via proxy FFI and merge returned stats; invokes it from releaseReader() before reader cleanup. Switches post-read accounting to columnar_scan_context_map with addUserReadBytes and addDeserializeBlockNs. Updates appendExtraJson to prefer columnar scan context for scan_details.

Sequence Diagram(s)

sequenceDiagram
  rect rgba(173, 216, 230, 0.5)
    note over StorageDisaggColumnar,ExecutionSummaryHelper: Columnar scan stats collection and reporting pipeline
  end
  participant StorageDisaggColumnar as StorageDisaggregatedColumnar
  participant RNColumnarInputStream
  participant CloudStorageProxy as Cloud Storage Proxy
  participant ColumnarScanContext
  participant ExecutorStatisticsCollector
  participant ExecutionSummaryHelper

  StorageDisaggColumnar->>ColumnarScanContext: create and register in columnar_scan_context_map
  RNColumnarInputStream->>RNColumnarInputStream: releaseReader()
  RNColumnarInputStream->>RNColumnarInputStream: mergeReaderStats()
  RNColumnarInputStream->>CloudStorageProxy: fn_columnar_scan_stats(reader)
  CloudStorageProxy-->>RNColumnarInputStream: ColumnarScanStats
  RNColumnarInputStream->>ColumnarScanContext: merge(ColumnarScanStats)
  RNColumnarInputStream->>ColumnarScanContext: addUserReadBytes / addDeserializeBlockNs
  ExecutorStatisticsCollector->>ColumnarScanContext: merge from columnar_scan_context_map
  ExecutionSummaryHelper->>ColumnarScanContext: serialize() → protobuf
  ExecutionSummaryHelper->>ExecutionSummaryHelper: emit columnar_scan_context to protobuf
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Suggested reviewers

  • JaySon-Huang
  • JinheLin
  • Lloyd-Pottiger

🐇 Hoppity-hop, the stats now flow,
From Rust FFI to C++ in a row,
Rough checks, MVCC, and segment counts too,
ColumnarScanContext— shiny and new!
Through DAGContext the metrics all merge,
A JSON report to complete the surge! 📊

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.23% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding columnar scan statistics details to execution output.
Description check ✅ Passed The description follows the template with issue reference, problem summary, changes explanation, manual testing confirmation, and release notes section.
Linked Issues check ✅ Passed All changes directly implement the enhancement in #10906: adding columnar scan statistics to explain output and logs.
Out of Scope Changes check ✅ Passed All changes are scoped to adding columnar scan statistics infrastructure and integration into execution summary pipeline.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
dbms/src/Storages/StorageDisaggregatedColumnar.cpp (1)

1385-1391: ⚡ Quick win

Log exceptions in the new broad catch path

Line 1385-1391 swallows all exceptions from releaseReader() with an empty catch (...). Please keep it non-throwing but log via tryLogCurrentException(log, "...") so cleanup/FFI failures remain diagnosable.

Suggested patch
     SCOPE_EXIT({
         try
         {
             releaseReader();
         }
         catch (...)
-        {}
+        {
+            tryLogCurrentException(log, "failed to release RNColumnarInputStream reader");
+        }
     });

As per coding guidelines, use tryLogCurrentException(log, "context") in broad catch (...) paths to avoid duplicated exception-formatting code.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@dbms/src/Storages/StorageDisaggregatedColumnar.cpp` around lines 1385 - 1391,
In the SCOPE_EXIT block containing the try-catch around the releaseReader()
call, replace the empty catch (...) {} block with a logging statement. Instead
of silently swallowing exceptions, call tryLogCurrentException(log, "context
message") to log any exceptions thrown during cleanup, ensuring that cleanup and
FFI failures remain diagnosable without duplicating exception-formatting code.

Source: Coding guidelines

dbms/src/Flash/Coprocessor/ColumnarScanContext.h (1)

30-52: ⚡ Quick win

Use project width aliases (UInt64) for counters in dbms headers.

Please align counter and API types with project conventions (UInt64) instead of raw uint64_t in this header for consistency across DB code.

As per coding guidelines: **/*.{cpp,h,hpp} should use explicit width types from dbms/src/Core/Types.h such as UInt8, UInt32, Int64, Float64, String.

Also applies to: 196-197

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@dbms/src/Flash/Coprocessor/ColumnarScanContext.h` around lines 30 - 52,
Replace all instances of `uint64_t` with the project's standard width alias
`UInt64` in the ColumnarScanContext class header file. This applies to all the
atomic counter member variables (regions, read_tasks, physical_tables, columns,
user_read_bytes, mvcc_input_rows, mvcc_input_bytes, mvcc_output_rows,
total_read_block_ns, total_serialize_block_ns, total_init_reader_ns,
total_prefetch_ns, total_deserialize_block_ns, rough_check_total_packs,
rough_check_selected_packs, rough_check_skipped_packs,
rough_check_unknown_packs, remote_segments, total_segments) and any other
counter declarations at lines 196-197. Change `std::atomic<uint64_t>` to
`std::atomic<UInt64>` to align with the project's coding conventions defined in
dbms/src/Core/Types.h.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@dbms/src/Flash/Coprocessor/ColumnarScanContext.h`:
- Around line 106-107: The merge() method performs non-atomic load-max-store
operations on physical_tables and columns atomic variables (at lines 106-107 and
129-130), creating a race condition where concurrent calls can overwrite larger
maximum values with smaller ones. Replace the direct assignment pattern with
atomic compare-and-swap loops to ensure the maximum value is always preserved
atomically. Additionally, replace all uint64_t type declarations with UInt64
from dbms/src/Core/Types.h to align with coding guidelines. Apply these changes
to both the physical_tables and columns member variables in both locations.

---

Nitpick comments:
In `@dbms/src/Flash/Coprocessor/ColumnarScanContext.h`:
- Around line 30-52: Replace all instances of `uint64_t` with the project's
standard width alias `UInt64` in the ColumnarScanContext class header file. This
applies to all the atomic counter member variables (regions, read_tasks,
physical_tables, columns, user_read_bytes, mvcc_input_rows, mvcc_input_bytes,
mvcc_output_rows, total_read_block_ns, total_serialize_block_ns,
total_init_reader_ns, total_prefetch_ns, total_deserialize_block_ns,
rough_check_total_packs, rough_check_selected_packs, rough_check_skipped_packs,
rough_check_unknown_packs, remote_segments, total_segments) and any other
counter declarations at lines 196-197. Change `std::atomic<uint64_t>` to
`std::atomic<UInt64>` to align with the project's coding conventions defined in
dbms/src/Core/Types.h.

In `@dbms/src/Storages/StorageDisaggregatedColumnar.cpp`:
- Around line 1385-1391: In the SCOPE_EXIT block containing the try-catch around
the releaseReader() call, replace the empty catch (...) {} block with a logging
statement. Instead of silently swallowing exceptions, call
tryLogCurrentException(log, "context message") to log any exceptions thrown
during cleanup, ensuring that cleanup and FFI failures remain diagnosable
without duplicating exception-formatting code.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: e3055fd7-3f3f-421a-9e4b-ad3524a4dd58

📥 Commits

Reviewing files that changed from the base of the PR and between 044990a and 4cad982.

⛔ Files ignored due to path filters (1)
  • contrib/tiflash-columnar-hub/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (19)
  • contrib/cloud-storage-engine
  • contrib/tiflash-columnar-hub/Cargo.toml
  • contrib/tiflash-columnar-hub/hub-runtime/Cargo.toml
  • contrib/tiflash-columnar-hub/hub-runtime/ffi/src/RaftStoreProxyFFI/ProxyFFI.h
  • contrib/tiflash-columnar-hub/hub-runtime/src/cloud_helper.rs
  • contrib/tiflash-columnar-hub/hub-runtime/src/columnar_impls.rs
  • contrib/tiflash-columnar-hub/hub-runtime/src/interfaces.rs
  • contrib/tiflash-columnar-hub/hub-runtime/src/run.rs
  • contrib/tipb
  • dbms/src/Flash/Coprocessor/ColumnarScanContext.h
  • dbms/src/Flash/Coprocessor/ColumnarScanContext_fwd.h
  • dbms/src/Flash/Coprocessor/DAGContext.h
  • dbms/src/Flash/Coprocessor/ExecutionSummary.cpp
  • dbms/src/Flash/Coprocessor/ExecutionSummary.h
  • dbms/src/Flash/Statistics/ExecutionSummaryHelper.cpp
  • dbms/src/Flash/Statistics/ExecutorStatisticsCollector.cpp
  • dbms/src/Flash/Statistics/TableScanImpl.cpp
  • dbms/src/Storages/StorageDisaggregatedColumnar.cpp
  • dbms/src/Storages/StorageDisaggregatedColumnar.h

Comment thread dbms/src/Flash/Coprocessor/ColumnarScanContext.h Outdated
yongman added 3 commits June 18, 2026 16:26
Signed-off-by: yongman <yming0221@gmail.com>
Signed-off-by: yongman <yming0221@gmail.com>
Signed-off-by: yongman <yming0221@gmail.com>
@ti-chi-bot

ti-chi-bot Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

@yongman: 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-integration-next-gen 7392354 link true /test pull-integration-next-gen
pull-integration-next-gen-columnar 7392354 link true /test pull-integration-next-gen-columnar
pull-sanitizer-tsan 7392354 link false /test pull-sanitizer-tsan
pull-sanitizer-asan 7392354 link false /test pull-sanitizer-asan

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.

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

Labels

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.

Lack of executor summary info for columnar

1 participant