ClickHouse/tests/queries/0_stateless/01646_rewrite_sum_if.sql

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

42 lines
2.2 KiB
MySQL
Raw Normal View History

SET optimize_rewrite_sum_if_to_count_if = 0;
SELECT sumIf(1, number % 2 > 2) FROM numbers(100);
SELECT sumIf(1 as one_expr, number % 2 > 2 as cond_expr), sum(cond_expr), one_expr FROM numbers(100);
SELECT countIf(number % 2 > 2) FROM numbers(100);
SELECT sumIf(1, number % 2 == 0) FROM numbers(100);
SELECT sumIf(1 as one_expr, number % 2 == 0 as cond_expr), sum(cond_expr), one_expr FROM numbers(100);
SELECT countIf(number % 2 == 0) FROM numbers(100);
SELECT sum(if(number % 2 == 0, 1, 0)) FROM numbers(100);
SELECT sum(if(number % 2 == 0 as cond_expr, 1 as one_expr, 0 as zero_expr) as if_expr), sum(cond_expr), sum(if_expr), one_expr, zero_expr FROM numbers(100);
SELECT countIf(number % 2 == 0) FROM numbers(100);
SELECT sum(if(number % 2 == 0, 0, 1)) FROM numbers(100);
SELECT sum(if(number % 2 == 0 as cond_expr, 0 as zero_expr, 1 as one_expr) as if_expr), sum(cond_expr), sum(if_expr), one_expr, zero_expr FROM numbers(100);
SELECT countIf(number % 2 != 0) FROM numbers(100);
SET optimize_rewrite_sum_if_to_count_if = 1;
SELECT sumIf(1, number % 2 > 2) FROM numbers(100);
SELECT sumIf(1 as one_expr, number % 2 > 2 as cond_expr), sum(cond_expr), one_expr FROM numbers(100);
SELECT countIf(number % 2 > 2) FROM numbers(100);
SELECT sumIf(1, number % 2 == 0) FROM numbers(100);
SELECT sumIf(1 as one_expr, number % 2 == 0 as cond_expr), sum(cond_expr), one_expr FROM numbers(100);
SELECT countIf(number % 2 == 0) FROM numbers(100);
SELECT sum(if(number % 2 == 0, 1, 0)) FROM numbers(100);
SELECT sum(if(number % 2 == 0 as cond_expr, 1 as one_expr, 0 as zero_expr) as if_expr), sum(cond_expr), sum(if_expr), one_expr, zero_expr FROM numbers(100);
SELECT countIf(number % 2 == 0) FROM numbers(100);
SELECT sum(if(number % 2 == 0, 0, 1)) FROM numbers(100);
SELECT sum(if(number % 2 == 0 as cond_expr, 0 as zero_expr, 1 as one_expr) as if_expr), sum(cond_expr), sum(if_expr), one_expr, zero_expr FROM numbers(100);
SELECT countIf(number % 2 != 0) FROM numbers(100);
2022-12-30 07:43:54 +00:00
2024-07-12 12:49:26 +00:00
set enable_analyzer = true;
2023-01-29 11:48:46 +00:00
EXPLAIN QUERY TREE run_passes=1 SELECT sumIf(123, number % 2 == 0) FROM numbers(100);
EXPLAIN QUERY TREE run_passes=1 SELECT sum(if(number % 2 == 0, 123, 0)) FROM numbers(100);
2024-04-25 19:14:40 +00:00
EXPLAIN QUERY TREE run_passes=1 SELECT sum(if(number % 2 == 0, 0, 123)) FROM numbers(100);