-
Notifications
You must be signed in to change notification settings - Fork 117
Add support for disabling hash aggregate with hll #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
sudo: required | ||
dist: trusty | ||
language: c | ||
env: | ||
global: | ||
- PG_PRELOAD=hll | ||
matrix: | ||
fast_finish: true | ||
include: | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,326 @@ | ||
-- ---------------------------------------------------------------- | ||
-- 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 \gset | ||
SELECT substring(:'server_version', '\d+\.\d+')::float > 9.5 as version_above_nine_five; | ||
version_above_nine_five | ||
------------------------- | ||
t | ||
(1 row) | ||
|
||
SELECT substring(:'server_version', '\d+\.\d+')::float = 9.5 as versiong_nine_five; | ||
versiong_nine_five | ||
-------------------- | ||
f | ||
(1 row) | ||
|
||
SELECT substring(:'server_version', '\d+\.\d+')::float = 9.4 as versiong_nine_four; | ||
versiong_nine_four | ||
-------------------- | ||
f | ||
(1 row) | ||
|
||
SELECT hll_set_output_version(1); | ||
hll_set_output_version | ||
------------------------ | ||
1 | ||
(1 row) | ||
|
||
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); | ||
QUERY PLAN | ||
----------------------- | ||
HashAggregate | ||
Group Key: id | ||
-> Seq Scan on tt1 | ||
(3 rows) | ||
|
||
SET hll.force_groupagg to ON; | ||
EXPLAIN(COSTS OFF) | ||
SELECT | ||
id, hll_union_agg(sd) | ||
FROM | ||
tt1 | ||
GROUP BY(id); | ||
QUERY PLAN | ||
----------------------------- | ||
GroupAggregate | ||
Group Key: id | ||
-> Sort | ||
Sort Key: id | ||
-> Seq Scan on tt1 | ||
(5 rows) | ||
|
||
-- 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); | ||
QUERY PLAN | ||
----------------------- | ||
HashAggregate | ||
Group Key: id | ||
-> Seq Scan on tt1 | ||
(3 rows) | ||
|
||
SET hll.force_groupagg to ON; | ||
EXPLAIN(COSTS OFF) | ||
SELECT | ||
id, hll_union_agg(sd) || hll_union_agg(sd) | ||
FROM | ||
tt1 | ||
GROUP BY(id); | ||
QUERY PLAN | ||
----------------------------- | ||
GroupAggregate | ||
Group Key: id | ||
-> Sort | ||
Sort Key: id | ||
-> Seq Scan on tt1 | ||
(5 rows) | ||
|
||
-- 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); | ||
QUERY PLAN | ||
----------------------- | ||
HashAggregate | ||
Group Key: id | ||
-> Seq Scan on tt1 | ||
(3 rows) | ||
|
||
SET hll.force_groupagg to ON; | ||
EXPLAIN(COSTS OFF) | ||
SELECT | ||
id, hll_cardinality(hll_union_agg(sd)) | ||
FROM | ||
tt1 | ||
GROUP BY(id); | ||
QUERY PLAN | ||
----------------------------- | ||
GroupAggregate | ||
Group Key: id | ||
-> Sort | ||
Sort Key: id | ||
-> Seq Scan on tt1 | ||
(5 rows) | ||
|
||
-- 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; | ||
QUERY PLAN | ||
------------------------------------------------------------------------ | ||
HashAggregate | ||
Group Key: id | ||
Filter: (hll_cardinality(hll_union_agg(sd)) > '1'::double precision) | ||
-> Seq Scan on tt1 | ||
(4 rows) | ||
|
||
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; | ||
QUERY PLAN | ||
------------------------------------------------------------------------ | ||
GroupAggregate | ||
Group Key: id | ||
Filter: (hll_cardinality(hll_union_agg(sd)) > '1'::double precision) | ||
-> Sort | ||
Sort Key: id | ||
-> Seq Scan on tt1 | ||
(6 rows) | ||
|
||
-- 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; | ||
QUERY PLAN | ||
---------------------------------- | ||
HashAggregate | ||
Group Key: c1 | ||
-> Seq Scan on add_test_table | ||
(3 rows) | ||
|
||
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; | ||
QUERY PLAN | ||
---------------------------------------- | ||
GroupAggregate | ||
Group Key: c1 | ||
-> Sort | ||
Sort Key: c1 | ||
-> Seq Scan on add_test_table | ||
(5 rows) | ||
|
||
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; | ||
QUERY PLAN | ||
---------------------------------- | ||
HashAggregate | ||
Group Key: c1 | ||
-> Seq Scan on add_test_table | ||
(3 rows) | ||
|
||
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; | ||
QUERY PLAN | ||
---------------------------------------- | ||
GroupAggregate | ||
Group Key: c1 | ||
-> Sort | ||
Sort Key: c1 | ||
-> Seq Scan on add_test_table | ||
(5 rows) | ||
|
||
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; | ||
QUERY PLAN | ||
---------------------------------- | ||
HashAggregate | ||
Group Key: c1 | ||
-> Seq Scan on add_test_table | ||
(3 rows) | ||
|
||
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; | ||
QUERY PLAN | ||
---------------------------------------- | ||
GroupAggregate | ||
Group Key: c1 | ||
-> Sort | ||
Sort Key: c1 | ||
-> Seq Scan on add_test_table | ||
(5 rows) | ||
|
||
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; | ||
QUERY PLAN | ||
---------------------------------- | ||
HashAggregate | ||
Group Key: c1 | ||
-> Seq Scan on add_test_table | ||
(3 rows) | ||
|
||
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; | ||
QUERY PLAN | ||
---------------------------------------- | ||
GroupAggregate | ||
Group Key: c1 | ||
-> Sort | ||
Sort Key: c1 | ||
-> Seq Scan on add_test_table | ||
(5 rows) | ||
|
||
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; | ||
QUERY PLAN | ||
---------------------------------- | ||
HashAggregate | ||
Group Key: c1 | ||
-> Seq Scan on add_test_table | ||
(3 rows) | ||
|
||
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; | ||
QUERY PLAN | ||
---------------------------------------- | ||
GroupAggregate | ||
Group Key: c1 | ||
-> Sort | ||
Sort Key: c1 | ||
-> Seq Scan on add_test_table | ||
(5 rows) | ||
|
||
RESET work_mem; | ||
DROP TABLE tt1; | ||
DROP TABLE add_test_table; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all disable hash_agg expectations look the same. it would be better if we put some sort of PG version information that caused us to make this differentiation