1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
|
-- ----------------------------------------------------------------
-- Regression tests for disabling hash aggregation
-- ----------------------------------------------------------------
-- Since we get different results for 3 different PG version sets, add following
-- queries to specify version of the output easier.
SHOW server_version_num \gset
SELECT :'server_version_num' >= 90600 as version_above_nine_five;
SELECT :'server_version_num' >= 90500 AND :'server_version_num' < 90600 as version_nine_five;
SELECT :'server_version_num' >= 90400 AND :'server_version_num' < 90500 as version_nine_four;
SELECT hll_set_output_version(1);
CREATE TABLE tt1(id int, col_1 int, sd hll);
INSERT INTO tt1 values(1,1, hll_empty());
INSERT INTO tt1 values(1,2, hll_empty());
UPDATE tt1 SET sd = hll_add(sd, hll_hash_integer(111)) WHERE id = 1 and col_1 = 1;
UPDATE tt1 SET sd = hll_add(sd, hll_hash_integer(222)) WHERE id = 1 and col_1 = 2;
INSERT INTO tt1 values(2,1, hll_empty());
INSERT INTO tt1 values(2,2, hll_empty());
UPDATE tt1 SET sd = hll_add(sd, hll_hash_integer(333)) WHERE id = 2 and col_1 = 1;
UPDATE tt1 SET sd = hll_add(sd, hll_hash_integer(444)) WHERE id = 2 and col_1 = 2;
-- Test with hll_union_agg
SET hll.force_groupagg to OFF;
EXPLAIN(COSTS OFF)
SELECT
id, hll_union_agg(sd)
FROM
tt1
GROUP BY(id);
SET hll.force_groupagg to ON;
EXPLAIN(COSTS OFF)
SELECT
id, hll_union_agg(sd)
FROM
tt1
GROUP BY(id);
-- Test with operator over aggregate
SET hll.force_groupagg to OFF;
EXPLAIN(COSTS OFF)
SELECT
id, hll_union_agg(sd) || hll_union_agg(sd)
FROM
tt1
GROUP BY(id);
SET hll.force_groupagg to ON;
EXPLAIN(COSTS OFF)
SELECT
id, hll_union_agg(sd) || hll_union_agg(sd)
FROM
tt1
GROUP BY(id);
-- Test with function over aggregate
SET hll.force_groupagg to OFF;
EXPLAIN(COSTS OFF)
SELECT
id, hll_cardinality(hll_union_agg(sd))
FROM
tt1
GROUP BY(id);
SET hll.force_groupagg to ON;
EXPLAIN(COSTS OFF)
SELECT
id, hll_cardinality(hll_union_agg(sd))
FROM
tt1
GROUP BY(id);
-- Test with having clause
SET hll.force_groupagg to OFF;
EXPLAIN(COSTS OFF)
SELECT
id, hll_cardinality(hll_union_agg(sd))
FROM
tt1
GROUP BY(id)
HAVING hll_cardinality(hll_union_agg(sd)) > 1;
SET hll.force_groupagg to ON;
EXPLAIN(COSTS OFF)
SELECT
id, hll_cardinality(hll_union_agg(sd))
FROM
tt1
GROUP BY(id)
HAVING hll_cardinality(hll_union_agg(sd)) > 1;
-- Test hll_add_agg, first set work_mem to 256MB in order to use hash aggregate
-- before forcing group aggregate
SET work_mem TO '256MB';
CREATE TABLE add_test_table(c1 bigint, c2 bigint);
INSERT INTO add_test_table SELECT g, g FROM generate_series(1, 1000) AS g;
-- Test with different hll_add_agg signatures
SET hll.force_groupagg TO OFF;
EXPLAIN(COSTS OFF)
SELECT
c1, hll_add_agg(hll_hash_bigint(c2))
FROM
add_test_table
GROUP BY 1;
SET hll.force_groupagg TO ON;
EXPLAIN(COSTS OFF)
SELECT
c1, hll_add_agg(hll_hash_bigint(c2))
FROM
add_test_table
GROUP BY 1;
SET hll.force_groupagg TO OFF;
EXPLAIN(COSTS OFF)
SELECT
c1, hll_add_agg(hll_hash_bigint(c2), 10)
FROM
add_test_table
GROUP BY 1;
SET hll.force_groupagg TO ON;
EXPLAIN(COSTS OFF)
SELECT
c1, hll_add_agg(hll_hash_bigint(c2), 10)
FROM
add_test_table
GROUP BY 1;
SET hll.force_groupagg TO OFF;
EXPLAIN(COSTS OFF)
SELECT
c1, hll_add_agg(hll_hash_bigint(c2), 10, 4)
FROM
add_test_table
GROUP BY 1;
SET hll.force_groupagg TO ON;
EXPLAIN(COSTS OFF)
SELECT
c1, hll_add_agg(hll_hash_bigint(c2), 10, 4)
FROM
add_test_table
GROUP BY 1;
SET hll.force_groupagg TO OFF;
EXPLAIN(COSTS OFF)
SELECT
c1, hll_add_agg(hll_hash_bigint(c2), 10, 4, 512)
FROM
add_test_table
GROUP BY 1;
SET hll.force_groupagg TO ON;
EXPLAIN(COSTS OFF)
SELECT
c1, hll_add_agg(hll_hash_bigint(c2), 10, 4, 512)
FROM
add_test_table
GROUP BY 1;
SET hll.force_groupagg TO OFF;
EXPLAIN(COSTS OFF)
SELECT
c1, hll_add_agg(hll_hash_bigint(c2), 10, 4, 512, 0)
FROM
add_test_table
GROUP BY 1;
SET hll.force_groupagg TO ON;
EXPLAIN(COSTS OFF)
SELECT
c1, hll_add_agg(hll_hash_bigint(c2), 10, 4, 512, 0)
FROM
add_test_table
GROUP BY 1;
RESET work_mem;
DROP TABLE tt1;
DROP TABLE add_test_table;
|