メインコンテンツまでスキップ
メインコンテンツまでスキップ

内部関数

この章で説明されている関数を使用して、クエリプロファイリングのために ELF および DWARF を内部確認できます。

注記

これらの関数は遅く、安全性に関する考慮事項があります。

内部関数の適切な動作のために:

  • clickhouse-common-static-dbg パッケージをインストールしてください。

  • allow_introspection_functions 設定を 1 に設定してください。

    セキュリティ上の理由から、内部確認関数はデフォルトで無効になっています。

ClickHouse はプロファイラーレポートを trace_log システムテーブルに保存します。テーブルとプロファイラーが正しく構成されていることを確認してください。

demangle

導入バージョン: v20.1

シンボルを C++ 関数名に変換します。 シンボルは通常、関数 addressToSymbol によって返されます。

構文

demangle(symbol)

引数

  • symbol — オブジェクトファイルからのシンボル。 String

戻り値

C++ 関数の名前を返すか、シンボルが無効な場合は空の文字列を返します。 String

trace_log システムテーブルから最初の文字列を選択する

SELECT * FROM system.trace_log LIMIT 1 \G;
-- The `trace` field contains the stack trace at the moment of sampling.
Row 1:
──────
event_date:    2019-11-20
event_time:    2019-11-20 16:57:59
revision:      54429
timer_type:    Real
thread_number: 48
query_id:      724028bf-f550-45aa-910d-2af6212b94ac
trace:         [94138803686098,94138815010911,94138815096522,94138815101224,94138815102091,94138814222988,94138806823642,94138814457211,94138806823642,94138814457211,94138806823642,94138806795179,94138806796144,94138753770094,94138753771646,94138753760572,94138852407232,140399185266395,140399178045583]

単一アドレスの関数名を取得する

SET allow_introspection_functions=1;
SELECT demangle(addressToSymbol(94138803686098)) \G;
Row 1:
──────
demangle(addressToSymbol(94138803686098)): DB::IAggregateFunctionHelper<DB::AggregateFunctionSum<unsigned long, unsigned long, DB::AggregateFunctionSumData<unsigned long> > >::addBatchSinglePlace(unsigned long, char*, DB::IColumn const**, DB::Arena*) const

スタックトレース全体に関数を適用する

SET allow_introspection_functions=1;

-- The arrayMap function allows to process each individual element of the trace array by the demangle function.
-- The result of this processing is shown in the trace_functions column of output.

SELECT
    arrayStringConcat(arrayMap(x -> demangle(addressToSymbol(x)), trace), '\n') AS trace_functions
FROM system.trace_log
LIMIT 1
\G
Row 1:
──────
trace_functions: DB::IAggregateFunctionHelper<DB::AggregateFunctionSum<unsigned long, unsigned long, DB::AggregateFunctionSumData<unsigned long> > >::addBatchSinglePlace(unsigned long, char*, DB::IColumn const**, DB::Arena*) const
DB::Aggregator::executeWithoutKeyImpl(char*&, unsigned long, DB::Aggregator::AggregateFunctionInstruction*, DB::Arena*) const
DB::Aggregator::executeOnBlock(std::vector<COW<DB::IColumn>::immutable_ptr<DB::IColumn>, std::allocator<COW<DB::IColumn>::immutable_ptr<DB::IColumn> > >, unsigned long, DB::AggregatedDataVariants&, std::vector<DB::IColumn const*, std::allocator<DB::IColumn const*> >&, std::vector<std::vector<DB::IColumn const*, std::allocator<DB::IColumn const*> >, std::allocator<std::vector<DB::IColumn const*, std::allocator<DB::IColumn const*> > > >&, bool&)
DB::Aggregator::executeOnBlock(DB::Block const&, DB::AggregatedDataVariants&, std::vector<DB::IColumn const*, std::allocator<DB::IColumn const*> >&, std::vector<std::vector<DB::IColumn const*, std::allocator<DB::IColumn const*> >, std::allocator<std::vector<DB::IColumn const*, std::allocator<DB::IColumn const*> > > >&, bool&)
DB::Aggregator::execute(std::shared_ptr<DB::IBlockInputStream> const&, DB::AggregatedDataVariants&)
DB::AggregatingBlockInputStream::readImpl()
DB::IBlockInputStream::read()
DB::ExpressionBlockInputStream::readImpl()
DB::IBlockInputStream::read()
DB::ExpressionBlockInputStream::readImpl()
DB::IBlockInputStream::read()
DB::AsynchronousBlockInputStream::calculate()
std::_Function_handler<void (), DB::AsynchronousBlockInputStream::next()::{lambda()#1}>::_M_invoke(std::_Any_data const&)
ThreadPoolImpl<ThreadFromGlobalPool>::worker(std::_List_iterator<ThreadFromGlobalPool>)
ThreadFromGlobalPool::ThreadFromGlobalPool<ThreadPoolImpl<ThreadFromGlobalPool>::scheduleImpl<void>(std::function<void ()>, int, std::optional<unsigned long>)::{lambda()#3}>(ThreadPoolImpl<ThreadFromGlobalPool>::scheduleImpl<void>(std::function<void ()>, int, std::optional<unsigned long>)::{lambda()#3}&&)::{lambda()#1}::operator()() const
ThreadPoolImpl<std::thread>::worker(std::_List_iterator<std::thread>)
execute_native_thread_routine
start_thread
clone

isMergeTreePartCoveredBy

導入バージョン: v25.6

最初の引数の部分が、2 番目の引数の部分でカバーされているかどうかを確認する関数です。

構文

isMergeTreePartCoveredBy(nested_part, covering_part)

引数

  • nested_part — 期待されるネストされた部分の名前。 String
  • covering_part — 期待されるカバリング部分の名前。 String

戻り値

カバーされている場合は 1、そうでない場合は 0 を返します。 UInt8

基本的な例

WITH 'all_12_25_7_4' AS lhs, 'all_7_100_10_20' AS rhs
SELECT isMergeTreePartCoveredBy(rhs, lhs), isMergeTreePartCoveredBy(lhs, rhs);
┌─isMergeTreePartCoveredBy(rhs, lhs)─┬─isMergeTreePartCoveredBy(lhs, rhs)─┐
│                                  0 │                                  1 │
└────────────────────────────────────┴────────────────────────────────────┘

logTrace

導入バージョン: v20.12

Block に対してサーバーログにトレースログメッセージを出力します。

構文

logTrace(message)

引数

  • message — サーバーログに出力されるメッセージ。 const String

戻り値

常に 0 を返します。 UInt8

基本的な例

SELECT logTrace('logTrace message');
┌─logTrace('logTrace message')─┐
│                            0 │
└──────────────────────────────┘

mergeTreePartInfo

導入バージョン: v25.6

MergeTree 部分名から有用な値を取り出すのを助ける関数です。

構文

mergeTreePartInfo(part_name)

引数

  • part_name — アンパックする部分の名前。 String

戻り値

partition_idmin_blockmax_blocklevelmutation のサブカラムを持つタプルを返します。 Tuple

基本的な例

WITH mergeTreePartInfo('all_12_25_7_4') AS info
SELECT info.partition_id, info.min_block, info.max_block, info.level, info.mutation;
┌─info.partition_id─┬─info.min_block─┬─info.max_block─┬─info.level─┬─info.mutation─┐
│ all               │             12 │             25 │          7 │             4 │
└───────────────────┴────────────────┴────────────────┴────────────┴───────────────┘

tid

導入バージョン: v20.12

現在の Block が処理されているスレッドの ID を返します。

構文

tid()

引数

  • なし。 戻り値

現在のスレッド ID を返します。 UInt64

使用例

SELECT tid();
┌─tid()─┐
│  3878 │
└───────┘