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

Function tryKeyValueJoin

src/Interpreters/ExpressionAnalyzer.cpp:1209–1251  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1207}
1208
1209std::shared_ptr<DirectKeyValueJoin> tryKeyValueJoin(std::shared_ptr<TableJoin> analyzed_join, const Block & right_sample_block)
1210{
1211 auto storage = analyzed_join->getStorageKeyValue();
1212 if (!storage)
1213 return nullptr;
1214
1215 bool allowed_inner = isInner(analyzed_join->kind()) && analyzed_join->strictness() == JoinStrictness::All;
1216 bool allowed_left = isLeft(analyzed_join->kind()) && (analyzed_join->strictness() == JoinStrictness::Any ||
1217 analyzed_join->strictness() == JoinStrictness::All ||
1218 analyzed_join->strictness() == JoinStrictness::Semi ||
1219 analyzed_join->strictness() == JoinStrictness::Anti);
1220 if (!allowed_inner && !allowed_left)
1221 {
1222 LOG_TRACE(getLogger(), "Can't use direct join: {} {} is not supported",
1223 analyzed_join->kind(), analyzed_join->strictness());
1224 return nullptr;
1225 }
1226
1227 const auto & clauses = analyzed_join->getClauses();
1228 bool only_one_key = clauses.size() == 1 &&
1229 clauses[0].key_names_left.size() == 1 &&
1230 clauses[0].key_names_right.size() == 1 &&
1231 !clauses[0].on_filter_condition_left &&
1232 !clauses[0].on_filter_condition_right;
1233
1234 if (!only_one_key)
1235 {
1236 LOG_TRACE(getLogger(), "Can't use direct join: only one key is supported");
1237 return nullptr;
1238 }
1239
1240 String key_name = clauses[0].key_names_right[0];
1241 String original_key_name = analyzed_join->getOriginalName(key_name);
1242 const auto & storage_primary_key = storage->getPrimaryKey();
1243 if (storage_primary_key.size() != 1 || storage_primary_key[0] != original_key_name)
1244 {
1245 LOG_TRACE(getLogger(), "Can't use direct join: join key '{}' doesn't match to storage key ({})",
1246 original_key_name, fmt::join(storage_primary_key, ", "));
1247 return nullptr;
1248 }
1249
1250 return std::make_shared<DirectKeyValueJoin>(analyzed_join, right_sample_block, storage);
1251}
1252
1253JoinPtr SelectQueryExpressionAnalyzer::makeJoin(
1254 const ASTTablesInSelectQueryElement & join_element,

Callers 1

tryCreateJoinFunction · 0.85

Calls 9

isInnerFunction · 0.85
isLeftFunction · 0.85
getStorageKeyValueMethod · 0.80
kindMethod · 0.80
strictnessMethod · 0.80
getOriginalNameMethod · 0.80
getLoggerFunction · 0.70
sizeMethod · 0.45
getPrimaryKeyMethod · 0.45

Tested by

no test coverage detected