Skip to content

Commit

Permalink
Merge pull request ClickHouse#58872 from ClickHouse/revert-58835-supp…
Browse files Browse the repository at this point in the history
…ort-net-write-read-settings

Revert "Add support for MySQL `net_write_timeout` and `net_read_timeout` settings"
  • Loading branch information
tavplubix committed Jan 16, 2024
2 parents 74973c1 + 661500a commit 27fc822
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 70 deletions.
42 changes: 13 additions & 29 deletions src/Server/MySQLHandler.cpp
Expand Up @@ -64,7 +64,7 @@ static const size_t SSL_REQUEST_PAYLOAD_SIZE = 32;
static String selectEmptyReplacementQuery(const String & query);
static String showTableStatusReplacementQuery(const String & query);
static String killConnectionIdReplacementQuery(const String & query);
static std::optional<String> setSettingReplacementQuery(const String & query, const String & mysql_setting, const String & native_setting);
static String selectLimitReplacementQuery(const String & query);

MySQLHandler::MySQLHandler(
IServer & server_,
Expand All @@ -86,12 +86,10 @@ MySQLHandler::MySQLHandler(
if (ssl_enabled)
server_capabilities |= CLIENT_SSL;

queries_replacements.emplace("KILL QUERY", killConnectionIdReplacementQuery);
queries_replacements.emplace("SHOW TABLE STATUS LIKE", showTableStatusReplacementQuery);
queries_replacements.emplace("SHOW VARIABLES", selectEmptyReplacementQuery);
settings_replacements.emplace("SQL_SELECT_LIMIT", "limit");
settings_replacements.emplace("NET_WRITE_TIMEOUT", "send_timeout");
settings_replacements.emplace("NET_READ_TIMEOUT", "receive_timeout");
replacements.emplace("KILL QUERY", killConnectionIdReplacementQuery);
replacements.emplace("SHOW TABLE STATUS LIKE", showTableStatusReplacementQuery);
replacements.emplace("SHOW VARIABLES", selectEmptyReplacementQuery);
replacements.emplace("SET SQL_SELECT_LIMIT", selectLimitReplacementQuery);
}

void MySQLHandler::run()
Expand Down Expand Up @@ -340,30 +338,16 @@ void MySQLHandler::comQuery(ReadBuffer & payload, bool binary_protocol)
bool should_replace = false;
bool with_output = false;

// Queries replacements
for (auto const & [query_to_replace, replacement_fn] : queries_replacements)
for (auto const & x : replacements)
{
if (0 == strncasecmp(query_to_replace.c_str(), query.c_str(), query_to_replace.size()))
if (0 == strncasecmp(x.first.c_str(), query.c_str(), x.first.size()))
{
should_replace = true;
replacement_query = replacement_fn(query);
replacement_query = x.second(query);
break;
}
}

// Settings replacements
if (!should_replace)
for (auto const & [mysql_setting, native_setting] : settings_replacements)
{
const auto replacement_query_opt = setSettingReplacementQuery(query, mysql_setting, native_setting);
if (replacement_query_opt.has_value())
{
should_replace = true;
replacement_query = replacement_query_opt.value();
break;
}
}

ReadBufferFromString replacement(replacement_query);

auto query_context = session->makeQueryContext();
Expand Down Expand Up @@ -601,12 +585,12 @@ static String showTableStatusReplacementQuery(const String & query)
return query;
}

static std::optional<String> setSettingReplacementQuery(const String & query, const String & mysql_setting, const String & native_setting)
static String selectLimitReplacementQuery(const String & query)
{
const String prefix = "SET " + mysql_setting;
if (0 == strncasecmp(prefix.c_str(), query.c_str(), prefix.size()))
return "SET " + native_setting + String(query.data() + prefix.length());
return std::nullopt;
const String prefix = "SET SQL_SELECT_LIMIT";
if (query.starts_with(prefix))
return "SET limit" + std::string(query.data() + prefix.length());
return query;
}

/// Replace "KILL QUERY [connection_id]" into "KILL QUERY WHERE query_id LIKE 'mysql:[connection_id]:xxx'".
Expand Down
9 changes: 3 additions & 6 deletions src/Server/MySQLHandler.h
Expand Up @@ -92,12 +92,9 @@ class MySQLHandler : public Poco::Net::TCPServerConnection
MySQLProtocol::PacketEndpointPtr packet_endpoint;
std::unique_ptr<Session> session;

using QueryReplacementFn = std::function<String(const String & query)>;
using QueriesReplacements = std::unordered_map<std::string, QueryReplacementFn>;
QueriesReplacements queries_replacements;

using SettingsReplacements = std::unordered_map<std::string, std::string>;
SettingsReplacements settings_replacements;
using ReplacementFn = std::function<String(const String & query)>;
using Replacements = std::unordered_map<std::string, ReplacementFn>;
Replacements replacements;

std::mutex prepared_statements_mutex;
UInt32 current_prepared_statement_id TSA_GUARDED_BY(prepared_statements_mutex) = 0;
Expand Down
14 changes: 0 additions & 14 deletions tests/queries/0_stateless/02967_mysql_settings_override.reference

This file was deleted.

21 changes: 0 additions & 21 deletions tests/queries/0_stateless/02967_mysql_settings_override.sh

This file was deleted.

0 comments on commit 27fc822

Please sign in to comment.