Skip to content

Add processor memory allocated and freed columns to processors profile log - #106263

Closed
alexandrefimov wants to merge 10 commits into
ClickHouse:masterfrom
alexandrefimov:query-doctor-70587-processor-memory
Closed

alexandrefimov wants to merge 10 commits into
ClickHouse:masterfrom
alexandrefimov:query-doctor-70587-processor-memory

Conversation

@alexandrefimov

@alexandrefimov alexandrefimov commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

Related: #70587

Changelog category (leave one):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Added memory_allocated_bytes and memory_freed_bytes to system.processors_profile_log, showing how much memory each processor allocated and freed while executing its work.

ThreadStatus keeps two monotonic counters that CurrentMemoryTracker advances on allocation and free, and ExecutionThreadContext::executeTask takes their difference around executeJob. The columns exclude processor preparation, scheduling and destruction, and memory blocked at VariableContext::Process or lower is not counted.

A single signed delta was the earlier shape of this change. It was replaced after testing on TPC-H and ClickBench showed a processor that frees what another one allocated coming out as the biggest memory releaser in the query, which reads as the opposite of what it is.


Workflow [PR]
Sync PR [sync-upstream/pr/106263]

@CLAassistant

CLAassistant commented Jun 1, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jun 5, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [82adf86]

Summary: ❌

job_name test_name status info comment
Stress test (amd_msan) FAIL
Hung check failed, possible deadlock found FAIL cidb

AI Review

Summary

This PR adds memory_allocated_bytes and memory_freed_bytes to system.processors_profile_log by snapshotting per-thread allocation counters around processor execution and wiring the values through the existing processor profile log path. I reviewed the GitHub diff, the current checkout, and the prior discussion; the previously open cross-thread async-pipeline concern is now reflected in the column descriptions, and I did not find any remaining correctness, safety, or metadata issues that warrant changes.

Final Verdict

Status: ✅ Approve

LLVM Coverage Report

Measured on commit 82adf86.

Metric Baseline Current Δ
Lines 88.80% 88.80% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 81.20% 81.20% +0.00%

Changed lines: Changed C/C++ lines covered: 66/67 (98.51%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label Jun 5, 2026
@alexandrefimov

Copy link
Copy Markdown
Contributor Author

I looked through the two failed jobs on this run and they look unrelated to this PR.

  • Stateless tests (arm_asan_ubsan, targeted) reports Failed: 0, Passed: 943, Skipped: 50; the job then hit Timeout exceeded [2805], sending SIGTERM to process group .... The server log ends with a normal shutdown / child exit code 0, and 02210_processors_profile_log passed in this job.
  • Stress test (arm_tsan) failed because the server stopped responding / could not start (Cannot execute SELECT 1 query). The CI report also links the Cannot start clickhouse-server failure to the known issue Cannot start clickhouse-server #105912.

I did not find sanitizer reports or stack traces involving the changed processor/profile-log code (IProcessor, ExecutionThreadContext, ProcessorsProfileLog, CurrentMemoryTracker, or memory_usage_delta) in these logs.

@Fgrtue Fgrtue self-assigned this Jun 8, 2026

@Fgrtue Fgrtue left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi @alexandrefimov , thank you for contribution. It seems that RFC requires a different way of tracking memory. With these deltas we track something else instead of allocated/freed memory in a processor.

@alexandrefimov

Copy link
Copy Markdown
Contributor Author

Thanks, I agree. The previous version measured the current memory before/after IProcessor::work, so it could miss allocation/free turnover inside the processor.

I updated the patch to use the RFC-style direction: ExecutionThreadContext now sets the active processor scope while IProcessor::work is running, and CurrentMemoryTracker accumulates signed allocation/free deltas for that active processor. I also added a focused gtest that checks direct alloc/free attribution and verifies that memory blocked at the query/process level is not attributed.

@alexandrefimov

Copy link
Copy Markdown
Contributor Author

Public CI is green on 5e46d23, but CH Inc sync is still red with description tests failed and no public details. I don't have access to the private sync PR/logs. Could someone rerun the failed private sync jobs or point me to any failure that requires a public-side change?

@alexandrefimov

Copy link
Copy Markdown
Contributor Author

@Fgrtue, could you please rerun failed check?)

@Fgrtue

Fgrtue commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

@alexandrefimov I checked the CI, this is some internal testing and it is not related to your changes. I will take a look at them.

@alexandrefimov

Copy link
Copy Markdown
Contributor Author

Thanks!

@clickhouse-gh

clickhouse-gh Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.90% 85.90% +0.00%
Functions 92.70% 92.70% +0.00%
Branches 78.00% 78.00% +0.00%

Changed lines: Changed C/C++ lines covered: 84/84 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh

clickhouse-gh Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Dear @Fgrtue, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@alexandrefimov

alexandrefimov commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor Author

@alexey-milovidov, the implementation now follows the RFC direction and the previous review thread is resolved. Since the previous reviewer was unassigned due to inactivity, could you please suggest another reviewer or take a look when convenient?

CI status for clarity: CH Inc sync is green, but the overall public PR CI is still red. The three primary failures appear unrelated to this change: amd_asan_ubsan failed a hung/deadlock check, amd_tsan hit an or_argument_nodes.size() > 1 assertion, and the performance shard completed its tests successfully but failed while building the report. A rerun of the failed checks should be sufficient.

@alexandrefimov

Copy link
Copy Markdown
Contributor Author

@Fgrtue, you previously confirmed that the failing CI was unrelated to this change and planned to review it, but the inactivity bot has since unassigned you. Would you be able to continue the review, or suggest another appropriate reviewer? Thanks!

@Fgrtue Fgrtue left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi @alexandrefimov, sorry for late response. Its unpleasant to say, but after internal discussion we are still in doubt about the details of implementation for memory tracking. The current infrastructure is a bit clumsy regarding the memory tracking per processor and some work is currently going on to improve it. Since the current implementation uses the only possible methods that are available, we are hesitant to add it, because it might be confusing for the users. The reason is that most of the memory is allocated during Reading, and then freed further in the pipeline. This might make most of the processors have negative memory delta, and at the same time that still won't allow to track real issues like OOM during Hash Table built in Joins.

Anyways, during the week I will take a look at the code, and try to test it on real life queries that cause high memory consumption. Then I'll discuss with the collegues if this approach of memory tracking gives more pros than cons and will be useful for our users.

Sorry again for the wait, it was a few busy months, so I did not have a proper chance to get back to this PR.

@Fgrtue Fgrtue self-assigned this Aug 3, 2026
@alexandrefimov

alexandrefimov commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the update. Your point about allocations and frees happening in different processors is fair.

If the net delta turns out to be misleading on real queries, we could record allocated and freed bytes separately. That would show allocation/free activity while each processor was running without implying that the processor owns the memory. It still would not solve retained-memory or OOM attribution.

Let’s see what the real-query tests show before changing the patch.

`master` moved the documentation from the Docusaurus tree under
`docs/en/**/*.md` to the Mintlify tree at `docs/**/*.mdx`, deleting every
file this branch edits. The edits are replayed at the new paths:

- `docs/en/operations/system-tables/processors_profile_log.md` -> `docs/reference/system-tables/processors_profile_log.mdx`
@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

Hi @Fgrtue, following up on the real-query tests you mentioned. Did they show whether the signed per-processor delta is useful, or whether allocation and freeing in different processors makes it too misleading? If the current direction is not acceptable, a short conclusion on whether to close this PR or what measurement would be meaningful would help me avoid pushing the wrong model. Thanks!

@alexandrefimov

Copy link
Copy Markdown
Contributor Author

Rather than ask a third time, let me put a plan on it.

The patch records a signed net delta per processor. Your point on Aug 3 was that allocations and frees land in different processors, which can make that misleading, and that the per-processor memory tracking infrastructure is being reworked anyway. If that is where things stand, this PR is not useful to anyone sitting open against infrastructure that is about to change.

So unless you would rather keep it, I will close it at the end of the week. The analysis stays in the thread, and I am glad to redo it against the new infrastructure once it lands — either as the signed delta or as allocated and freed recorded separately, whichever turns out to measure something real.

@clickhouse-gh

clickhouse-gh Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Dear @Fgrtue, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@abashkeev abashkeev added the comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. label Sep 4, 2026
@Fgrtue Fgrtue self-assigned this Sep 4, 2026
@Fgrtue

Fgrtue commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Hi @alexandrefimov. Sorry for the wait, I was PTO. Here are the result of the testing:

I did the testing using TPC-H scale 30 and ClickBench 100 million rows on machine with 32 cores, 61 GB RAM.
To be precise:

  • TPC-H SF30: Q02, Q03, Q05, Q21, Q22
  • ClickBench (hits, 100 M rows): Q17, Q22, Q28, Q30, Q31, Q32, Q33
  • Two hand-written queries on hits to check that the column names the right operator. Each was run twice: once fully in memory, and once with spilling to disk forced by a setting, to see whether the number for the
    operator drops when its memory really goes to disk.
    • Aggregation: SELECT WatchID, ClientIP, count() FROM hits GROUP BY WatchID, ClientIP, in memory and with max_bytes_before_external_group_by = 2 GB
    • Sort: SELECT ClientIP, WatchID, EventTime FROM hits ORDER BY ClientIP, in memory and with max_bytes_before_external_sort = 1 GB
  1. The delta column is not redundant and cannot be derived from output_bytes.

ExpressionTransform in two queries as an example:

query processor output_bytes memory delta
tpch30_q02 ExpressionTransform 326.40 GiB 2.62 MiB
cb_q28 ExpressionTransform 9.81 GiB 10.34 GiB
  1. We can track the operator that consumed a lot of memory during allocation.

SELECT WatchID, ClientIP, count() FROM hits GROUP BY WatchID, ClientIP

peak spill parts AggregatingTransform top reported allocator
max_bytes_before_external_group_by=0 12.20 GiB 0 +10.86 GiB AggregatingTransform 10.86 GiB
max_bytes_before_external_group_by=2 GB 5.03 GiB 318 −840.59 MiB SourceFromNativeStream 3.00 GiB

When spilling is turned on, the aggregation's figure collapses as it should, and the new top
consumer is the read-back path. A user comparing the two tables learns exactly the right
thing.

  1. The negative delta is ambiguous

SELECT ClientIP, WatchID, EventTime FROM hits ORDER BY ClientIP

  • t4_sort_mem: default settings, the sort runs in memory.
  • t4_sort_spill: max_bytes_before_external_sort = 1 GB, so the sort writes
    intermediate data to disk.

The third is tpch30_q02 (TPC-H Q02), which sorts under ORDER BY ... LIMIT 100. It is the
query that produced the −27 GB on MergeSortingTransform noted earlier in this review.

query peak MergingSorted MergeSorting most negative
t4_sort_mem 1.52 GiB +1.49 GiB +19.90 MiB PartialSorting −31.73 KiB
t4_sort_spill 1.16 GiB +2.79 GiB +112.32 MiB BufferingToFileSink −1.40 GiB
tpch30_q02 1.68 GiB +96.81 KiB −25.09 GiB MergeSorting −25.09 GiB

What happened in each case:

  1. Plain sort in memory. MergeSortingTransform takes 100 million rows in and puts
    100 million rows out. Inside its work it frees the input chunks and allocates output
    chunks of about the same size. The two cancel, and the delta is a small positive
    (+19.90 MiB). No large negative appears.

  2. Plain sort with spilling. BufferingToFileSink receives 1.29 GiB of sorted blocks,
    writes them to disk, and frees them. Its delta is −1.40 GiB. Here the negative number tells
    the true story: this processor really gave memory back.

  3. Sort under LIMIT (TPC-H Q02). The join upstream produces 14 GiB in only 14,155 very
    wide rows. MergeSortingTransform receives them, keeps 3,200 rows because of the LIMIT,
    and frees the rest inside its work. Its delta is −25.09 GiB (−27 GB). The memory was
    allocated by the join, not by the sort. The sort only happens to be the place where it
    is freed.

So a negative number has two possible meanings. In case 2 it means "this processor released
its own memory". In case 3 it means "this processor released memory that another processor
allocated". The single signed column cannot tell the reader which one they are looking at.

  1. Case of click bench query 28

SELECT REGEXP_REPLACE(Referer, ...) AS k, AVG(length(Referer)), COUNT(*), MIN(Referer) FROM hits WHERE Referer <> '' GROUP BY k HAVING COUNT(*) > 100000 ORDER BY l DESC LIMIT 25

Query peak: 2.58 GiB.

processor delta out_bytes in_bytes
ExpressionTransform +10.34 GiB 9.81 GiB 6.81 GiB
MergeTreeSelect +6.96 GiB 6.95 GiB 0 B
FilterTransform +1.45 GiB 6.81 GiB 7.78 GiB
…
ConvertingAggregatedToChunksWithMergingSource −1.34 GiB 850.67 MiB 0 B
AggregatingTransform −17.40 GiB 850.67 MiB 10.64 GiB

All 32 AggregatingTransform instances are negative (min −851.56 MiB, max −307.20 MiB).

The aggregation holds ~850 MiB of group states. It is reported as the single biggest memory
releaser in the query
, at 6.7 × the whole query's peak in the negative direction. It shows
this because it is where the transient strings that the regexp produced upstream go to die.

Anyone triaging an OOM in this query reads that row and concludes the aggregation is not the
problem. That is the wrong conclusion, and the table gives no way to see it.

  1. Summary: does the biggest allocator name the real owner?
query peak top allocator amount × peak most negative × peak
cb_q17 5.47 GiB AggregatingTransform 3.23 GiB 0.59 ConvertingAggToChunksWithMerging 0.01
cb_q22 207.46 MiB MergeTreeSelect 9.52 MiB 0.05 PartialSorting 0.01
cb_q28 2.58 GiB ExpressionTransform 10.34 GiB 4.00 AggregatingTransform 6.73
cb_q30 884.88 MiB AggregatingTransform 745.82 MiB 0.84 ConvertingAggToChunksWithMerging 0.81
cb_q31 1.79 GiB AggregatingTransform 1.57 GiB 0.88 ConvertingAggToChunksWithMerging 0.75
cb_q32 16.40 GiB AggregatingTransform 14.76 GiB 0.90 ConvertingAggToChunksWithMerging 0.79
cb_q33 8.30 GiB MergeTreeSelect 9.17 GiB 1.11 PartialSorting 0.52
t3_agg_mem 12.20 GiB AggregatingTransform 10.86 GiB 0.89 ConvertingAggToChunksWithMerging 0.83
t3_agg_spill 5.03 GiB SourceFromNativeStream 3.00 GiB 0.60 MergingAggregatedBucket 0.27
t4_sort_mem 1.52 GiB MergingSortedTransform 1.49 GiB 0.98 PartialSorting 0.00
t4_sort_spill 1.16 GiB MergingSortedTransform 2.79 GiB 2.41 BufferingToFileSink 1.21
tpch30_q02 1.68 GiB JoiningTransform 292.88 GiB 174.01 MergeSorting 14.91
tpch30_q03 6.88 GiB FillingRightJoinSide 4.77 GiB 0.69 ConvertingAggToChunksWithMerging 0.01
tpch30_q05 13.45 GiB JoiningTransform 148.61 GiB 11.05 SimpleSquashing 0.08
tpch30_q21 6.33 GiB FillingRightJoinSide 4.61 GiB 0.73 JoiningTransform 0.35
tpch30_q22 162.84 MiB MergeTreeSelect 195.52 MiB 1.20 SimpleSquashing 0.87

12 of 16 land in 0.05–1.2 × peak and name a sensible operator. The 4 outliers are all
churn-dominated: two large joins, one string-materialising expression, one spilling sort.

Across all 16 queries: 103 processor/query rows positive, 52 negative, 67 exactly zero. A
third of the non-zero rows carry a negative "memory usage".

@Fgrtue Fgrtue left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For the implementation, we want the smallest possible change the following approach:

  1. Two columns instead of one. Replace memory_usage_delta with memory_allocated_bytes and memory_freed_bytes (UInt64) in IProcessor, ProcessorsProfileLogInfo, the log element, the table columns and
    the docs. Users can compute the difference themselves.

  2. Two plain counters in ThreadStatus. Add two UInt64 fields next to untracked_memory that only grow. In CurrentMemoryTracker::allocImpl and CurrentMemoryTracker::free, add size to the matching field
    after the tracker call has succeeded. Keep the current rule: allocations blocked at VariableContext::Process or lower are not counted. Remove current_processor_memory_usage_delta and
    addCurrentProcessorMemoryUsageDelta. The memory tracker must not know about processors.

  3. Snapshot in executeTask. Do not change executeJob. Read the two thread counters before the existing executeJob call, and after it add the differences to the processor. Put this under the same
    profile_processors check that already guards execution_time_watch. Please revert the executeJob rewrite, the ProcessorMemoryUsageScope class, the new declaration in the header and the comment edits in
    IProcessor.h.

  4. Tests. The functional test is the main one. Keep max_untracked_memory = 0 and max_threads = 1. Check only that both columns are > 0 for a processor that must allocate, such as AggregatingTransform. Do
    not compare exact byte counts. The gtest can stay in a short form: check the two thread counters after alloc and free, and check that a MemoryTrackerBlockerInThread at Process level does not change them. No
    integration test is needed.

Replace `memory_usage_delta` in `system.processors_profile_log` with
`memory_allocated_bytes` and `memory_freed_bytes`. A signed net value hides
who owns the memory: a processor that frees what another one allocated shows
up as the biggest releaser in the query.

`ThreadStatus` now keeps two monotonic counters that `CurrentMemoryTracker`
advances on alloc and free, and `ExecutionThreadContext::executeTask` takes
their difference around `executeJob`. The memory tracker no longer knows about
processors. Memory blocked at `VariableContext::Process` or lower is still not
counted.
…ory' into query-doctor-70587-processor-memory

# Conflicts:
#	docs/en/operations/system-tables/processors_profile_log.md
#	docs/reference/system-tables/processors_profile_log.mdx
`master` moved `ExecutionThreadContext` into `src/Processors/Executors/Runtime/`
and pulled `ProcessorsProfileLogInfo` out of `IProcessor.h`, so the change is
replayed at the new locations.

The documentation edit is dropped. The column list in
`docs/reference/system-tables/processors_profile_log.mdx` sits between
`AUTOGENERATED_START` and `AUTOGENERATED_END`, and `check_autogenerated_regions`
rejects direct edits there without the `pr-autogenerated-docs` label. The column
descriptions in `ProcessorsProfileLog.cpp` are what that region is generated from.
@alexandrefimov

Copy link
Copy Markdown
Contributor Author

Done, all four points. Master is merged in, so the conflicts are gone.

Two things differ from what you described:

  • The functional test is a new file, 05136_processors_profile_log_memory_bytes.sql, rather than an addition to 02210, which measures the elapsed and wait columns. It runs with max_threads = 1 and max_untracked_memory = 0 and checks that both columns are > 0 for AggregatingTransform. Happy to move it into 02210 if you would rather have it there.

  • No documentation change. The column list in docs/reference/system-tables/processors_profile_log.mdx is between AUTOGENERATED_START and AUTOGENERATED_END, and check_autogenerated_regions in the docs job rejects edits there without the pr-autogenerated-docs label. The descriptions live in ProcessorsProfileLog.cpp, which is what that region is generated from.

A processor that runs an inner pipeline through `PullingAsyncPipelineExecutor`
allocates on a thread from the global pool, and that pipeline never reaches
`logProcessorProfile`, so none of its memory lands in any row.
@alexandrefimov

Copy link
Copy Markdown
Contributor Author

The two columns miss processors that run an inner pipeline through PullingAsyncPipelineExecutor — RecursiveCTESource, and ExecutingInnerQueryFromViewTransform under use_async_executor_for_materialized_views = 1. The counters follow the thread that runs work, that pipeline runs on a thread from the global pool, and its processors are never passed to logProcessorProfile, so its memory lands in no row: a sum over query_id is short by it, and a zero row looks like a real zero.

The limitation is now in the column descriptions in ProcessorsProfileLog.cpp, which is what that documentation region is generated from. Carrying the counters out of the async executor is the other half of what the bot suggested; I would leave that to a follow-up, but it is your call.

@clickhouse-gh

clickhouse-gh Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 82adf86f2 with master 8396165e8 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

1231 translation units recompiled, 7722 s compile time in total, 1231 of them have a recent master baseline.

Job report

@Fgrtue Fgrtue left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, I will ask another colleague to take a look in order to make sure that this won't affect other work on memory tracking.

@Fgrtue Fgrtue changed the title Add processor memory delta to processors profile log Add processor memory allocated and freed columns to processors profile log Sep 11, 2026
@alexandrefimov

Copy link
Copy Markdown
Contributor Author

LGTM, I will ask another colleague to take a look in order to make sure that this won't affect other work on memory tracking.

Thanks!

@Fgrtue
Fgrtue requested a review from azat September 16, 2026 11:03

@azat azat left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I also have concerns about introducing allocation throughput per processor, as it might add noise and confusion rather than actionable diagnostics.

Concerns/[Existing] Alternatives:

  • Knowing which processor performed an allocation is usually not enough, typically need call stacks. We already have detailed profiling options for this, such as Memory, MemorySample, JemallocSample and others, but yes not all of this is enabled by default because it is more heavy (we can add processor information into trace_log btw)
  • Processors that actually consume significant memory (e.g., JOIN, Sort, Aggregating) already expose dedicated interfaces for tracked memory usage, and #119443 will extend this coverage to disk spilling
  • Minor, but AFAICS, entries in system.processors_profile_log are written only when a query finishes successfully. Queries that fail with MEMORY_LIMIT_EXCEEDED won't be captured here anyway, while those are the most interesting.
  • Regarding the original RFC #70587, likely it will require significant work and I am not sure that it worth implementing

Maybe you can describe some examples where this can be useful, and we can discuss, does it worth it or maybe there are better alternatives or some of existing introspection can cover them

P.S. sorry for the delay and that it took so many rounds

@alexandrefimov

Copy link
Copy Markdown
Contributor Author

Thanks, fair points. I checked the third one: processors_profile_log is written only when a query finishes successfully, so the OOM case from #70587 isn't covered at all. I don't have a use case the existing tools can't handle.

Tagging trace_log entries (Memory, MemorySample, JemallocSample) with the current processor looks more useful: you get stacks and failed queries too. Would you accept a small PR for that? If yes, I'll close this one and open that instead.

@azat azat self-assigned this Sep 21, 2026
@azat

azat commented Sep 21, 2026

Copy link
Copy Markdown
Member

Would you accept a small PR for that?

To add processor to trace_log?

I am actually not sure that it will be useful either, I don't remember a case when I was needed this
Plus it won't be small actually, since you will have to convert each processor's name to enum, otherwise it won't fit into PIPE_BUF, to send between threads atomically

But what definitely make sense is to add entries for system.processor_profile_log even in case of exception (ExceptionWhileProcessing)

@alexandrefimov

Copy link
Copy Markdown
Contributor Author

Makes sense. I'll close this one and open a new PR that logs processors_profile_log entries for failed queries too. Could you review it?

@azat

azat commented Sep 21, 2026

Copy link
Copy Markdown
Member

Sure, feel free to ping me there.

huldarchen pushed a commit to huldarchen/ClickHouse that referenced this pull request Oct 5, 2026
…exception

Until now `processors_profile_log` was written only from the query finish path,
so queries ending with `ExceptionWhileProcessing` (for example
`MEMORY_LIMIT_EXCEPTION`) had no entries. `BlockIO::onException` now passes the
pipeline, which is not reset yet, to the exception callbacks, and the callback
from `executeQuery` logs its processors.

`LocalConnection` kept its executors alive during `onException`, so their
threads could still write the processors' counters. It now stops them first,
as `finishQuery` does before `onFinish`.

Related: ClickHouse#106263
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. manual approve Manual approve required to run CI pr-feature Pull request with new product feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants