|
51 | 51 | #include "runtime/runtime_profile.h" |
52 | 52 | #include "runtime/runtime_state.h" |
53 | 53 | #include "service/backend_options.h" |
54 | | -#include "storage/cache/schema_cache.h" |
55 | 54 | #include "storage/id_manager.h" |
56 | 55 | #include "storage/index/inverted/inverted_index_profile.h" |
57 | 56 | #include "storage/iterator/block_reader.h" |
@@ -164,68 +163,24 @@ Status OlapScanner::prepare() { |
164 | 163 | // value (e.g. select a from t where a .. and b ... limit 1), |
165 | 164 | // it will be very slow when reading data in segment iterator |
166 | 165 | _tablet_reader->set_batch_size(_state->batch_size()); |
167 | | - TabletSchemaSPtr cached_schema; |
168 | | - std::string schema_key; |
169 | 166 | { |
170 | 167 | TOlapScanNode& olap_scan_node = local_state->olap_scan_node(); |
171 | 168 |
|
172 | | - const auto check_can_use_cache = [&]() { |
173 | | - if (!(olap_scan_node.__isset.schema_version && olap_scan_node.__isset.columns_desc && |
174 | | - !olap_scan_node.columns_desc.empty() && |
175 | | - olap_scan_node.columns_desc[0].col_unique_id >= 0 && // Why check first column? |
176 | | - tablet->tablet_schema()->num_variant_columns() == 0 && |
177 | | - tablet->tablet_schema()->num_virtual_columns() == 0)) { |
178 | | - return false; |
| 169 | + // Each scanner builds its own TabletSchema to avoid concurrent modification. |
| 170 | + tablet_schema = std::make_shared<TabletSchema>(); |
| 171 | + tablet_schema->copy_from(*tablet->tablet_schema()); |
| 172 | + if (olap_scan_node.__isset.columns_desc && !olap_scan_node.columns_desc.empty() && |
| 173 | + olap_scan_node.columns_desc[0].col_unique_id >= 0) { |
| 174 | + tablet_schema->clear_columns(); |
| 175 | + for (const auto& column_desc : olap_scan_node.columns_desc) { |
| 176 | + tablet_schema->append_column(TabletColumn(column_desc)); |
179 | 177 | } |
180 | | - |
181 | | - // If `delete_predicates` is not empty, will merge the columns in delete predicate into current tablet schema |
182 | | - if (!_tablet_reader_params.delete_predicates.empty()) { |
183 | | - return false; |
| 178 | + if (olap_scan_node.__isset.schema_version) { |
| 179 | + tablet_schema->set_schema_version(olap_scan_node.schema_version); |
184 | 180 | } |
185 | | - |
186 | | - const bool has_pruned_column = |
187 | | - std::ranges::any_of(_output_tuple_desc->slots(), [](const auto& slot) { |
188 | | - if ((slot->type()->get_primitive_type() == PrimitiveType::TYPE_STRUCT || |
189 | | - slot->type()->get_primitive_type() == PrimitiveType::TYPE_MAP || |
190 | | - slot->type()->get_primitive_type() == PrimitiveType::TYPE_ARRAY) && |
191 | | - !slot->all_access_paths().empty()) { |
192 | | - return true; |
193 | | - } |
194 | | - return false; |
195 | | - }); |
196 | | - return !has_pruned_column; |
197 | | - }(); |
198 | | - |
199 | | - if (check_can_use_cache) { |
200 | | - schema_key = |
201 | | - SchemaCache::get_schema_key(tablet->tablet_id(), olap_scan_node.columns_desc, |
202 | | - olap_scan_node.schema_version); |
203 | | - cached_schema = SchemaCache::instance()->get_schema(schema_key); |
204 | 181 | } |
205 | | - if (cached_schema && cached_schema->num_virtual_columns() == 0) { |
206 | | - tablet_schema = cached_schema; |
207 | | - } else { |
208 | | - // If schema is not cached or cached schema has virtual columns, |
209 | | - // we need to create a new TabletSchema. |
210 | | - tablet_schema = std::make_shared<TabletSchema>(); |
211 | | - tablet_schema->copy_from(*tablet->tablet_schema()); |
212 | | - if (olap_scan_node.__isset.columns_desc && !olap_scan_node.columns_desc.empty() && |
213 | | - olap_scan_node.columns_desc[0].col_unique_id >= 0) { |
214 | | - // Originally scanner get TabletSchema from tablet object in BE. |
215 | | - // To support lightweight schema change for adding / dropping columns, |
216 | | - // tabletschema is bounded to rowset and tablet's schema maybe outdated, |
217 | | - // so we have to use schema from a query plan witch FE puts it in query plans. |
218 | | - tablet_schema->clear_columns(); |
219 | | - for (const auto& column_desc : olap_scan_node.columns_desc) { |
220 | | - tablet_schema->append_column(TabletColumn(column_desc)); |
221 | | - } |
222 | | - if (olap_scan_node.__isset.schema_version) { |
223 | | - tablet_schema->set_schema_version(olap_scan_node.schema_version); |
224 | | - } |
225 | | - } |
226 | | - if (olap_scan_node.__isset.indexes_desc) { |
227 | | - tablet_schema->update_indexes_from_thrift(olap_scan_node.indexes_desc); |
228 | | - } |
| 182 | + if (olap_scan_node.__isset.indexes_desc) { |
| 183 | + tablet_schema->update_indexes_from_thrift(olap_scan_node.indexes_desc); |
229 | 184 | } |
230 | 185 |
|
231 | 186 | if (_tablet_reader_params.rs_splits.empty()) { |
@@ -283,12 +238,6 @@ Status OlapScanner::prepare() { |
283 | 238 | read_columns_to_string(tablet_schema, _return_columns)); |
284 | 239 | } |
285 | 240 |
|
286 | | - // Add newly created tablet schema to schema cache if it does not have virtual columns. |
287 | | - if (cached_schema == nullptr && !schema_key.empty() && |
288 | | - tablet_schema->num_virtual_columns() == 0 && !tablet_schema->has_pruned_columns()) { |
289 | | - SchemaCache::instance()->insert_schema(schema_key, tablet_schema); |
290 | | - } |
291 | | - |
292 | 241 | if (_tablet_reader_params.score_runtime) { |
293 | 242 | SCOPED_TIMER(local_state->_statistics_collect_timer); |
294 | 243 | _tablet_reader_params.collection_statistics = std::make_shared<CollectionStatistics>(); |
|
0 commit comments