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

Method comQuery

src/Server/MySQLHandler.cpp:480–578  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

478}
479
480void MySQLHandler::comQuery(ReadBuffer & payload, bool binary_protocol)
481{
482 String query = String(payload.position(), payload.buffer().end());
483
484 // This is a workaround in order to support adding ClickHouse to MySQL using federated server.
485 // As Clickhouse doesn't support these statements, we just send OK packet in response.
486 if (isFederatedServerSetupSetCommand(query))
487 {
488 packet_endpoint->sendPacket(OKPacket(0x00, client_capabilities, 0, 0, 0));
489 }
490 else
491 {
492 String replacement_query;
493 bool should_replace = false;
494 bool with_output = false;
495
496 // Queries replacements
497 for (auto const & [query_to_replace, replacement_fn] : queries_replacements)
498 {
499 if (checkShouldReplaceQuery(query, query_to_replace))
500 {
501 should_replace = true;
502 replacement_query = replacement_fn(query);
503 break;
504 }
505 }
506
507 // Settings replacements
508 if (!should_replace)
509 {
510 for (auto const & [mysql_setting, clickhouse_setting] : settings_replacements)
511 {
512 const auto replacement_query_opt = setSettingReplacementQuery(query, mysql_setting, clickhouse_setting);
513 if (replacement_query_opt.has_value())
514 {
515 should_replace = true;
516 replacement_query = replacement_query_opt.value();
517 break;
518 }
519 }
520 }
521
522 auto query_context = session->makeQueryContext();
523 query_context->setCurrentQueryId(fmt::format("mysql:{}:{}", connection_id, toString(UUIDHelpers::generateV4())));
524
525 /// --- Workaround for Bug 56173.
526 auto settings = query_context->getSettingsCopy();
527 if (!settings[Setting::allow_experimental_analyzer])
528 {
529 settings[Setting::prefer_column_name_to_alias] = true;
530 query_context->setSettings(settings);
531 }
532
533 /// Update timeouts
534 socket().setReceiveTimeout(settings[Setting::receive_timeout]);
535 socket().setSendTimeout(settings[Setting::send_timeout]);
536
537 QueryScope query_scope = QueryScope::create(query_context);

Callers

nothing calls this directly

Calls 15

OKPacketClass · 0.85
checkShouldReplaceQueryFunction · 0.85
generateV4Function · 0.85
sendPacketMethod · 0.80
setCurrentQueryIdMethod · 0.80
getSettingsCopyMethod · 0.80
getProgressCallbackMethod · 0.80
StringClass · 0.50
formatFunction · 0.50
toStringFunction · 0.50

Tested by

no test coverage detected