ClickHouse/tests/queries/0_stateless/01281_group_by_limit_memory_tracking.sh
2020-05-27 14:09:12 +03:00

36 lines
961 B
Bash
Executable File

#!/usr/bin/env bash
# Regression for MemoryTracker that had been incorrectly accounted
# (it was reseted before deallocation)
#
# For this will be used:
# - two-level group by
# - max_memory_usage_for_user
# - one users' query in background (to avoid reseting max_memory_usage_for_user)
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
. $CURDIR/../shell_config.sh
set -o pipefail
function execute_null()
{
${CLICKHOUSE_CLIENT} --format Null -n "$@"
}
function execute_group_by()
{
local opts=(
--max_memory_usage_for_user=$((150<<20))
--max_threads=2
)
execute_null "${opts[@]}" <<<'SELECT uniq(number) FROM numbers_mt(toUInt64(1e6)) GROUP BY number % 5e5'
}
# This is needed to keep at least one running query for user for the time of test.
execute_null <<<'SELECT sleep(3)' &
execute_group_by
# if memory accounting will be incorrect, the second query will be failed with MEMORY_LIMIT_EXCEEDED
execute_group_by
wait