ClickHouse/tests/queries/0_stateless/01624_soft_constraints.sh

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

97 lines
3.8 KiB
Bash
Raw Normal View History

2021-05-03 19:08:26 +00:00
#!/usr/bin/env bash
set -e
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh
. "$CURDIR"/../shell_config.sh
2021-05-04 19:18:37 +00:00
SETTINGS="SET convert_query_to_cnf = 1; SET optimize_using_constraints = 1; SET optimize_move_to_prewhere = 1; SET optimize_substitute_columns = 1; SET optimize_append_index = 1"
2021-05-03 19:08:26 +00:00
$CLICKHOUSE_CLIENT -n --query="
2021-05-04 18:43:58 +00:00
$SETTINGS;
2021-05-04 19:31:32 +00:00
DROP TABLE IF EXISTS hypothesis_test_test;
DROP TABLE IF EXISTS hypothesis_test_test2;
DROP TABLE IF EXISTS hypothesis_test_test3;
2021-05-04 10:47:23 +00:00
2021-05-04 19:31:32 +00:00
CREATE TABLE hypothesis_test_test (
2021-05-03 19:08:26 +00:00
i UInt64,
a UInt64,
b UInt64,
c Float64,
INDEX t (a < b) TYPE hypothesis GRANULARITY 1,
INDEX t2 (b <= c) TYPE hypothesis GRANULARITY 1
) ENGINE = MergeTree() ORDER BY i SETTINGS index_granularity=1;
"
2021-05-04 18:43:58 +00:00
$CLICKHOUSE_CLIENT -n --query="$SETTINGS;
2021-05-04 19:31:32 +00:00
INSERT INTO hypothesis_test_test VALUES (0, 1, 2, 2), (1, 2, 1, 2), (2, 2, 2, 1), (3, 1, 2, 3)"
2021-05-03 19:08:26 +00:00
2021-05-04 19:31:32 +00:00
$CLICKHOUSE_CLIENT -n --query="$SETTINGS; SELECT count() FROM hypothesis_test_test WHERE b > a FORMAT JSON" | grep "rows_read" # 4
2021-05-04 10:47:23 +00:00
2021-05-04 19:31:32 +00:00
$CLICKHOUSE_CLIENT -n --query="$SETTINGS; SELECT count() FROM hypothesis_test_test WHERE b <= a FORMAT JSON" | grep "rows_read"
2021-05-04 10:47:23 +00:00
2021-05-04 19:31:32 +00:00
$CLICKHOUSE_CLIENT -n --query="$SETTINGS; SELECT count() FROM hypothesis_test_test WHERE b >= a FORMAT JSON" | grep "rows_read" # 4
2021-05-04 10:47:23 +00:00
2021-05-04 19:31:32 +00:00
$CLICKHOUSE_CLIENT -n --query="$SETTINGS; SELECT count() FROM hypothesis_test_test WHERE b = a FORMAT JSON" | grep "rows_read"
2021-05-04 10:47:23 +00:00
2021-05-04 19:31:32 +00:00
$CLICKHOUSE_CLIENT -n --query="$SETTINGS; SELECT count() FROM hypothesis_test_test WHERE c < a FORMAT JSON" | grep "rows_read"
2021-05-04 10:47:23 +00:00
2021-05-04 19:31:32 +00:00
$CLICKHOUSE_CLIENT -n --query="$SETTINGS; SELECT count() FROM hypothesis_test_test WHERE c = a FORMAT JSON" | grep "rows_read"
2021-05-04 10:47:23 +00:00
2021-05-04 19:31:32 +00:00
$CLICKHOUSE_CLIENT -n --query="$SETTINGS; SELECT count() FROM hypothesis_test_test WHERE c > a FORMAT JSON" | grep "rows_read" # 4
2021-05-04 10:47:23 +00:00
2021-05-04 19:31:32 +00:00
$CLICKHOUSE_CLIENT -n --query="$SETTINGS; SELECT count() FROM hypothesis_test_test WHERE c < a FORMAT JSON" | grep "rows_read"
2021-05-04 10:47:23 +00:00
$CLICKHOUSE_CLIENT -n --query="
2021-05-04 18:43:58 +00:00
$SETTINGS;
2021-05-04 19:31:32 +00:00
CREATE TABLE hypothesis_test_test2 (
2021-05-04 10:47:23 +00:00
i UInt64,
a UInt64,
b UInt64,
INDEX t (a != b) TYPE hypothesis GRANULARITY 1
) ENGINE = MergeTree() ORDER BY i SETTINGS index_granularity=1;
"
2021-05-04 18:43:58 +00:00
$CLICKHOUSE_CLIENT -n --query="$SETTINGS;
2021-05-04 19:31:32 +00:00
INSERT INTO hypothesis_test_test2 VALUES (0, 1, 2), (1, 2, 1), (2, 2, 2), (3, 1, 0)"
2021-05-04 10:47:23 +00:00
2021-05-04 19:31:32 +00:00
$CLICKHOUSE_CLIENT -n --query="$SETTINGS; SELECT count() FROM hypothesis_test_test2 WHERE a < b FORMAT JSON" | grep "rows_read" # 4
2021-05-04 10:47:23 +00:00
2021-05-04 19:31:32 +00:00
$CLICKHOUSE_CLIENT -n --query="$SETTINGS; SELECT count() FROM hypothesis_test_test2 WHERE a <= b FORMAT JSON" | grep "rows_read" # 4
2021-05-04 10:47:23 +00:00
2021-05-04 19:31:32 +00:00
$CLICKHOUSE_CLIENT -n --query="$SETTINGS; SELECT count() FROM hypothesis_test_test2 WHERE a = b FORMAT JSON" | grep "rows_read" # 1
2021-05-04 10:47:23 +00:00
2021-05-04 19:31:32 +00:00
$CLICKHOUSE_CLIENT -n --query="$SETTINGS; SELECT count() FROM hypothesis_test_test2 WHERE a != b FORMAT JSON" | grep "rows_read" # 4
2021-05-03 19:08:26 +00:00
2021-05-04 10:47:23 +00:00
$CLICKHOUSE_CLIENT -n --query="
2021-05-04 18:43:58 +00:00
$SETTINGS;
2021-05-04 19:31:32 +00:00
CREATE TABLE hypothesis_test_test3 (
2021-05-04 10:47:23 +00:00
i UInt64,
a UInt64,
b UInt64,
INDEX t (a = b) TYPE hypothesis GRANULARITY 1
) ENGINE = MergeTree() ORDER BY i SETTINGS index_granularity=1;
"
2021-05-04 18:43:58 +00:00
$CLICKHOUSE_CLIENT -n --query="
$SETTINGS;
2021-05-04 19:31:32 +00:00
INSERT INTO hypothesis_test_test3 VALUES (0, 1, 2), (1, 2, 1), (2, 2, 2), (3, 1, 0)"
2021-05-03 19:08:26 +00:00
2021-05-04 19:31:32 +00:00
$CLICKHOUSE_CLIENT -n --query="$SETTINGS;SELECT count() FROM hypothesis_test_test3 WHERE a < b FORMAT JSON" | grep "rows_read" # 3
2021-05-03 19:08:26 +00:00
2021-05-04 19:31:32 +00:00
$CLICKHOUSE_CLIENT -n --query="$SETTINGS;SELECT count() FROM hypothesis_test_test3 WHERE a <= b FORMAT JSON" | grep "rows_read" # 4
2021-05-03 19:08:26 +00:00
2021-05-04 19:31:32 +00:00
$CLICKHOUSE_CLIENT -n --query="$SETTINGS;SELECT count() FROM hypothesis_test_test3 WHERE a = b FORMAT JSON" | grep "rows_read" # 4
2021-05-03 19:08:26 +00:00
2021-05-04 19:31:32 +00:00
$CLICKHOUSE_CLIENT -n --query="$SETTINGS;SELECT count() FROM hypothesis_test_test3 WHERE a != b FORMAT JSON" | grep "rows_read" # 3
2021-05-03 19:08:26 +00:00
$CLICKHOUSE_CLIENT -n --query="
2021-05-04 18:43:58 +00:00
$SETTINGS;
2021-05-04 19:31:32 +00:00
DROP TABLE hypothesis_test_test;
DROP TABLE hypothesis_test_test2;
DROP TABLE hypothesis_test_test3;"