From ef7beb15967e3bf3f7e844a284efd04d624d385c Mon Sep 17 00:00:00 2001 From: alesapin Date: Wed, 20 Feb 2019 12:22:13 +0300 Subject: [PATCH] Fix bug with long http insert queries processing --- dbms/src/Interpreters/executeQuery.cpp | 8 +++++++- .../0_stateless/00908_long_http_insert.reference | 1 + .../queries/0_stateless/00908_long_http_insert.sh | 11 +++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 dbms/tests/queries/0_stateless/00908_long_http_insert.reference create mode 100755 dbms/tests/queries/0_stateless/00908_long_http_insert.sh diff --git a/dbms/src/Interpreters/executeQuery.cpp b/dbms/src/Interpreters/executeQuery.cpp index 4a7defb5b63..a5856fb6173 100644 --- a/dbms/src/Interpreters/executeQuery.cpp +++ b/dbms/src/Interpreters/executeQuery.cpp @@ -462,12 +462,16 @@ void executeQuery( size_t max_query_size = context.getSettingsRef().max_query_size; + bool may_have_tail; if (istr.buffer().end() - istr.position() > static_cast(max_query_size)) { /// If remaining buffer space in 'istr' is enough to parse query up to 'max_query_size' bytes, then parse inplace. begin = istr.position(); end = istr.buffer().end(); istr.position() += end - begin; + /// Actually we don't know will query has additional data or not. + /// But we can't check istr.eof(), because begin and end pointers will became invalid + may_have_tail = true; } else { @@ -479,12 +483,14 @@ void executeQuery( begin = parse_buf.data(); end = begin + parse_buf.size(); + /// Can check stream for eof, because we have copied data + may_have_tail = !istr.eof(); } ASTPtr ast; BlockIO streams; - std::tie(ast, streams) = executeQueryImpl(begin, end, context, false, QueryProcessingStage::Complete, !istr.eof()); + std::tie(ast, streams) = executeQueryImpl(begin, end, context, false, QueryProcessingStage::Complete, may_have_tail); try { diff --git a/dbms/tests/queries/0_stateless/00908_long_http_insert.reference b/dbms/tests/queries/0_stateless/00908_long_http_insert.reference new file mode 100644 index 00000000000..749fce669df --- /dev/null +++ b/dbms/tests/queries/0_stateless/00908_long_http_insert.reference @@ -0,0 +1 @@ +1000000 diff --git a/dbms/tests/queries/0_stateless/00908_long_http_insert.sh b/dbms/tests/queries/0_stateless/00908_long_http_insert.sh new file mode 100755 index 00000000000..5acc70cfe0d --- /dev/null +++ b/dbms/tests/queries/0_stateless/00908_long_http_insert.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +set -e + +CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +. $CURDIR/../shell_config.sh + +echo 'DROP TABLE IF EXISTS test.table_for_insert' | ${CLICKHOUSE_CURL} -sSg ${CLICKHOUSE_URL} -d @- +echo 'CREATE TABLE test.table_for_insert (a UInt8, b UInt8) ENGINE = Memory' | ${CLICKHOUSE_CURL} -sSg ${CLICKHOUSE_URL} -d @- +echo "INSERT INTO test.table_for_insert VALUES `printf '%*s' "1000000" | sed 's/ /(1, 2)/g'`" | ${CLICKHOUSE_CURL} -sSg ${CLICKHOUSE_URL} -d @- +echo 'SELECT count(*) FROM test.table_for_insert' | ${CLICKHOUSE_CURL} -sSg ${CLICKHOUSE_URL} -d @- +echo 'DROP TABLE IF EXISTS test.table_for_insert' | ${CLICKHOUSE_CURL} -sSg ${CLICKHOUSE_URL} -d @-