MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / addBuildTextIndexesStep

Method addBuildTextIndexesStep

src/Storages/MergeTree/MergeTask.cpp:2802–2876  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2800}
2801
2802void MergeTask::addBuildTextIndexesStep(QueryPlan & plan, const IMergeTreeDataPart & data_part, const GlobalRuntimeContextPtr & global_ctx)
2803{
2804 if (global_ctx->text_indexes_to_merge.empty())
2805 return;
2806
2807 auto original_header = plan.getCurrentHeader();
2808 auto read_column_names = original_header->getNameSet();
2809
2810 IndicesDescription description_to_build;
2811 std::vector<MergeTreeIndexPtr> indexes_to_build;
2812 const auto storage_columns = global_ctx->storage_columns.getNameSet();
2813 const auto virtual_columns = global_ctx->virtual_columns.getNameSet();
2814
2815 for (const auto & index : global_ctx->text_indexes_to_merge)
2816 {
2817 auto required_columns = index.expression->getRequiredColumns();
2818
2819 bool read_any_required_column = std::ranges::any_of(required_columns, [&](const auto & column_name)
2820 {
2821 return read_column_names.contains(getColumnNameInStorage(column_name, storage_columns, virtual_columns));
2822 });
2823
2824 if (!read_any_required_column)
2825 continue;
2826
2827 auto index_ptr = MergeTreeIndexFactory::instance().get(global_ctx->metadata_snapshot, index, *global_ctx->data_settings);
2828
2829 /// Rebuild index if merge may reduce rows because we cannot adjust parts offsets in that case.
2830 /// Build index if it is not materialized in the data part.
2831 if (global_ctx->merge_may_reduce_rows || !index_ptr->getDeserializedFormat(data_part.checksums, index_ptr->getFileName(), &data_part.getDataPartStorage()))
2832 {
2833 description_to_build.push_back(index);
2834 indexes_to_build.push_back(std::move(index_ptr));
2835 }
2836 }
2837
2838 if (indexes_to_build.empty())
2839 return;
2840
2841 if (!global_ctx->temporary_text_index_storage)
2842 {
2843 auto new_part_path = global_ctx->new_data_part->getDataPartStorage().getRelativePath();
2844 global_ctx->temporary_text_index_storage = createTemporaryTextIndexStorage(global_ctx->disk, new_part_path);
2845 }
2846
2847 addSkipIndexesExpressionSteps(plan, description_to_build, global_ctx);
2848
2849 MergeTreeWriterSettings writer_settings(
2850 global_ctx->data->getContext()->getSettingsRef(),
2851 global_ctx->context->getWriteSettings(),
2852 global_ctx->data->getSettings(),
2853 global_ctx->new_data_part,
2854 global_ctx->new_data_part->index_granularity_info.mark_type.adaptive,
2855 /*rewrite_primary_key=*/ false,
2856 /*save_marks_in_cache=*/ false,
2857 /*save_primary_index_in_memory=*/ false,
2858 /*blocks_are_granules_size=*/ false);
2859

Callers

nothing calls this directly

Calls 15

getColumnNameInStorageFunction · 0.85
getDataPartStorageMethod · 0.80
getRelativePathMethod · 0.80
getWriteSettingsMethod · 0.80
getFileExtensionMethod · 0.80
emptyMethod · 0.45
getNameSetMethod · 0.45
getRequiredColumnsMethod · 0.45
containsMethod · 0.45
getMethod · 0.45
getDeserializedFormatMethod · 0.45

Tested by

no test coverage detected