Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nooblose committed May 25, 2024
1 parent afa684a commit 68f40f8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
16 changes: 12 additions & 4 deletions src/Interpreters/executeQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ namespace ErrorCodes
extern const int LOGICAL_ERROR;
extern const int NOT_IMPLEMENTED;
extern const int QUERY_WAS_CANCELLED;
extern const int INCORRECT_DATA;
extern const int SYNTAX_ERROR;
extern const int SUPPORT_IS_DISABLED;
extern const int INCORRECT_QUERY;
Expand Down Expand Up @@ -966,7 +965,7 @@ executeQueryImpl(QueryData & query_data, ContextMutablePtr context, QueryFlags f
{
if (can_use_query_cache && settings.enable_reads_from_query_cache)
{
QueryCache::Key key(ast, context->getUserID(), context->getCurrentRoles());
QueryCache::Key key(ast, context->getCurrentDatabase(), context->getUserID(), context->getCurrentRoles());
QueryCache::Reader reader = query_cache->createReader(key);
if (reader.hasCacheEntryForKey())
{
Expand Down Expand Up @@ -1088,7 +1087,7 @@ executeQueryImpl(QueryData & query_data, ContextMutablePtr context, QueryFlags f
&& (!ast_contains_system_tables || system_table_handling == QueryCacheSystemTableHandling::Save))
{
QueryCache::Key key(
ast, res.pipeline.getHeader(),
ast, context->getCurrentDatabase(), res.pipeline.getHeader(),
context->getUserID(), context->getCurrentRoles(),
settings.query_cache_share_between_users,
std::chrono::system_clock::now() + std::chrono::seconds(settings.query_cache_ttl),
Expand Down Expand Up @@ -1259,7 +1258,16 @@ QueryData::QueryData(ReadBuffer & istr, ContextMutablePtr context, QueryFlags fl
const char * begin;
const char * end;

istr.nextIfAtEnd();
try
{
istr.nextIfAtEnd();
}
catch (...)
{
/// If buffer contains invalid data and we failed to decompress, we still want to have some information about the query in the log.
logQuery("<cannot parse>", context, /* internal = */ false, QueryProcessingStage::Complete);
throw;
}

const auto max_query_size = getMaxQuerySize(context, flags);

Expand Down
1 change: 0 additions & 1 deletion src/Interpreters/executeQuery.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include "Parsers/IAST_fwd.h"
#include <Core/QueryProcessingStage.h>
#include <Formats/FormatSettings.h>
#include <Interpreters/Context_fwd.h>
Expand Down
12 changes: 7 additions & 5 deletions src/Server/HTTPHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <Server/IServer.h>
#include <Common/logger_useful.h>
#include <Common/SettingsChanges.h>
#include <Common/StringUtils/StringUtils.h>
#include <Common/StringUtils.h>
#include <Common/scope_guard_safe.h>
#include <Common/setThreadName.h>
#include <Common/typeid_cast.h>
Expand All @@ -39,6 +39,8 @@
#include <base/scope_guard.h>
#include <Server/HTTP/HTTPResponse.h>

#include "config.h"

#include <Parsers/ASTFunction.h>
#include <Parsers/ASTSelectQuery.h>
#include <Parsers/ASTSelectWithUnionQuery.h>
Expand Down Expand Up @@ -786,11 +788,11 @@ void HTTPHandler::processQuery(
/// The data can also be compressed using incompatible internal algorithm. This is indicated by
/// 'decompress' query parameter.
std::unique_ptr<ReadBuffer> in_post_maybe_compressed;
bool in_post_compressed = false;
bool is_in_post_compressed = false;
if (params.getParsed<bool>("decompress", false))
{
in_post_maybe_compressed = std::make_unique<CompressedReadBuffer>(*in_post);
in_post_compressed = true;
is_in_post_compressed = true;
}
else
in_post_maybe_compressed = std::move(in_post);
Expand Down Expand Up @@ -890,7 +892,7 @@ void HTTPHandler::processQuery(

/// If 'http_native_compression_disable_checksumming_on_decompress' setting is turned on,
/// checksums of client data compressed with internal algorithm are not checked.
if (in_post_compressed && settings.http_native_compression_disable_checksumming_on_decompress)
if (is_in_post_compressed && settings.http_native_compression_disable_checksumming_on_decompress)
static_cast<CompressedReadBuffer &>(*in_post_maybe_compressed).disableChecksumming();

/// Add CORS header if 'add_http_cors_header' setting is turned on send * in Access-Control-Allow-Origin
Expand Down Expand Up @@ -1177,7 +1179,7 @@ void HTTPHandler::handleRequest(HTTPServerRequest & request, HTTPServerResponse
client_trace_context,
context->getSettingsRef(),
context->getOpenTelemetrySpanLog());
thread_trace_context->root_span.kind = OpenTelemetry::SERVER;
thread_trace_context->root_span.kind = OpenTelemetry::SpanKind::SERVER;
thread_trace_context->root_span.addAttribute("clickhouse.uri", request.getURI());

response.setContentType("text/plain; charset=UTF-8");
Expand Down
2 changes: 1 addition & 1 deletion src/Server/HTTPHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class HTTPHandler : public HTTPRequestHandler

class DynamicQueryHandler : public HTTPHandler
{
protected:
private:
std::string param_name;
public:
explicit DynamicQueryHandler(IServer & server_, const std::string & param_name_ = "query", const std::optional<String>& content_type_override_ = std::nullopt);
Expand Down

0 comments on commit 68f40f8

Please sign in to comment.