From 84f6dea4501627590727c23535779165869c9b52 Mon Sep 17 00:00:00 2001 From: Hanefi Onaldi Date: Thu, 9 Sep 2021 18:47:25 +0300 Subject: [PATCH 1/5] Use correct flags for creating hash tables in PG14 --- topn.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/topn.c b/topn.c index d20c61a..5161471 100644 --- a/topn.c +++ b/topn.c @@ -719,14 +719,20 @@ CreateTopnAggState(void) { int32 hashTableSize = 0; HASHCTL hashInfo; + int flags = HASH_ELEM | HASH_CONTEXT; hashTableSize = (NumberOfCounters / 0.75) + 1; memset(&hashInfo, 0, sizeof(hashInfo)); hashInfo.keysize = MAX_KEYSIZE; hashInfo.entrysize = sizeof(FrequentTopnItem); hashInfo.hcxt = CurrentMemoryContext; + +#if PG_VERSION_NUM >= 140000 + flags |= HASH_STRINGS; +#endif + return (TopnAggState *) hash_create("Item Frequency Map", hashTableSize, &hashInfo, - HASH_ELEM | HASH_CONTEXT); + flags); } From 74c47fd01ecb6ae34b868eb4b6beb9196e5218a8 Mon Sep 17 00:00:00 2001 From: Hanefi Onaldi Date: Thu, 9 Sep 2021 18:47:43 +0300 Subject: [PATCH 2/5] Introduce PG14 specific test results --- expected/customer_reviews_query.out | 12 ++- expected/customer_reviews_query_0.out | 12 ++- expected/customer_reviews_query_1.out | 105 ++++++++++++++++++++++++++ sql/customer_reviews_query.sql | 3 +- 4 files changed, 125 insertions(+), 7 deletions(-) create mode 100644 expected/customer_reviews_query_1.out diff --git a/expected/customer_reviews_query.out b/expected/customer_reviews_query.out index 3500a34..734b740 100644 --- a/expected/customer_reviews_query.out +++ b/expected/customer_reviews_query.out @@ -1,10 +1,16 @@ SHOW server_version \gset -SELECT substring(:'server_version', '\d+')::int >= 13; +SELECT substring(:'server_version', '\d+')::int = 14; ?column? ---------- t (1 row) +SELECT substring(:'server_version', '\d+')::int = 13; + ?column? +---------- + f +(1 row) + -- Create table to insert summaries. create table popular_products ( @@ -47,9 +53,9 @@ order by 2 DESC, 1; 0671014730 | 572 0743527550 | 572 0375700757 | 555 - 0871136791 | 553 + 0871136791 | 555 0679460691 | 551 - 0375402926 | 548 + 0375402926 | 550 0613221583 | 536 0812550293 | 536 1575110458 | 536 diff --git a/expected/customer_reviews_query_0.out b/expected/customer_reviews_query_0.out index 206b21f..123f465 100644 --- a/expected/customer_reviews_query_0.out +++ b/expected/customer_reviews_query_0.out @@ -1,10 +1,16 @@ SHOW server_version \gset -SELECT substring(:'server_version', '\d+')::int >= 13; +SELECT substring(:'server_version', '\d+')::int = 14; ?column? ---------- f (1 row) +SELECT substring(:'server_version', '\d+')::int = 13; + ?column? +---------- + t +(1 row) + -- Create table to insert summaries. create table popular_products ( @@ -47,9 +53,9 @@ order by 2 DESC, 1; 0671014730 | 572 0743527550 | 572 0375700757 | 555 - 0871136791 | 555 + 0871136791 | 553 0679460691 | 551 - 0375402926 | 550 + 0375402926 | 548 0613221583 | 536 0812550293 | 536 1575110458 | 536 diff --git a/expected/customer_reviews_query_1.out b/expected/customer_reviews_query_1.out new file mode 100644 index 0000000..29bb832 --- /dev/null +++ b/expected/customer_reviews_query_1.out @@ -0,0 +1,105 @@ +SHOW server_version \gset +SELECT substring(:'server_version', '\d+')::int = 14; + ?column? +---------- + f +(1 row) + +SELECT substring(:'server_version', '\d+')::int = 13; + ?column? +---------- + f +(1 row) + +-- Create table to insert summaries. +create table popular_products +( + review_summary jsonb, + year double precision, + month double precision +); +set topn.number_of_counters to 1000; +-- Create different summaries by grouping the reviews according to their year and month. +insert into + popular_products(review_summary, year, month ) +select + topn_add_agg(product_id), + extract(year from review_date) as year, + extract(month from review_date) as month +from + customer_reviews +group by + year, + month; +-- Create another table for the merged results. +create table + overall_result(merged_summary jsonb); +-- Let's merge the summaries for the overall result and check top-20 items. +insert into + overall_result(merged_summary) +select + topn_union_agg(review_summary) +from + popular_products; +select + (topn(merged_summary, 20)).* +from + overall_result +order by 2 DESC, 1; + item | frequency +------------+----------- + 0671003755 | 576 + 0613033205 | 575 + 0671014730 | 572 + 0743527550 | 572 + 0375700757 | 555 + 0871136791 | 555 + 0679460691 | 551 + 0375402926 | 550 + 0613221583 | 536 + 0812550293 | 536 + 1575110458 | 536 + 1590073983 | 536 + 1590073991 | 536 + 0375402675 | 524 + 0375403477 | 524 + 0375703241 | 524 + 0399143904 | 524 + 0425170349 | 524 + 0613222407 | 524 + 0765342294 | 510 +(20 rows) + +-- Test window functions +CREATE TABLE daily_populars +( + date DATE, + agg_data JSONB +); +INSERT INTO daily_populars + SELECT + date_trunc('day', review_date), + topn_add_agg(product_id) + FROM + customer_reviews + GROUP BY + 1; +SELECT + date, + topn_union_agg(agg_data) OVER seven_days +FROM + daily_populars +WINDOW + seven_days AS (ORDER BY date ASC ROWS 6 PRECEDING) +ORDER BY + 1 +LIMIT 5; + date | topn_union_agg +------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + 12-30-1970 | {"1551802538": 1, "1551803542": 1} + 06-19-1995 | {"0898624932": 1, "1551802538": 1, "1551803542": 1} + 06-23-1995 | {"0521469112": 1, "0898624932": 1, "1551802538": 1, "1551803542": 1} + 07-14-1995 | {"0521469112": 1, "0679722955": 1, "0898624932": 1, "1551802538": 1, "1551803542": 1} + 07-18-1995 | {"0195069056": 1, "0471114251": 1, "0517887290": 1, "0521469112": 1, "0679722955": 1, "0898624932": 1, "0962344788": 1, "1551802538": 1, "1551803542": 1, "1574531093": 1} +(5 rows) + diff --git a/sql/customer_reviews_query.sql b/sql/customer_reviews_query.sql index 5c11749..5c65778 100644 --- a/sql/customer_reviews_query.sql +++ b/sql/customer_reviews_query.sql @@ -1,5 +1,6 @@ SHOW server_version \gset -SELECT substring(:'server_version', '\d+')::int >= 13; +SELECT substring(:'server_version', '\d+')::int = 14; +SELECT substring(:'server_version', '\d+')::int = 13; -- Create table to insert summaries. create table popular_products From 22eea54ea2a61f3ac5bbda6892c94e8c1672a572 Mon Sep 17 00:00:00 2001 From: Hanefi Onaldi Date: Thu, 9 Sep 2021 18:51:05 +0300 Subject: [PATCH 3/5] Fix gitignore rules for migration scripts --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 26fd77a..e85fe53 100644 --- a/.gitignore +++ b/.gitignore @@ -36,7 +36,8 @@ copy_data.out # Generated migration scripts -topn--?.?.?.sql +topn--*.sql +!update/topn--*.sql # Sample data customer_reviews_????.csv From d595958f576b487e49d044836912b54394fae3c1 Mon Sep 17 00:00:00 2001 From: Hanefi Onaldi Date: Thu, 9 Sep 2021 18:53:03 +0300 Subject: [PATCH 4/5] Bump to 2.4.0 --- CHANGELOG.md | 4 ++++ Makefile | 4 +++- topn.control | 2 +- update/topn--2.3.1--2.4.0.sql | 3 +++ 4 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 update/topn--2.3.1--2.4.0.sql diff --git a/CHANGELOG.md b/CHANGELOG.md index c548235..c053de0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### topn v2.4.0 (September 09, 2021) ### + +* Adds PostgreSQL 14 support + ### topn v2.3.1 (November 27, 2020) ### * Adds PostgreSQL 13 support diff --git a/Makefile b/Makefile index c1ad386..5333d96 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ MODULES = topn EXTENSION = topn -EXTVERSIONS = 2.0.0 2.1.0 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 +EXTVERSIONS = 2.0.0 2.1.0 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 2.4.0 DATA = $(wildcard $(EXTENSION)--*--*.sql) DATA_built = $(foreach v,$(EXTVERSIONS),$(EXTENSION)--$(v).sql) PG_CONFIG ?= pg_config @@ -32,6 +32,8 @@ $(EXTENSION)--2.3.0.sql: $(EXTENSION)--2.2.2.sql $(EXTENSION)--2.2.2--2.3.0.sql cat $^ > $@ $(EXTENSION)--2.3.1.sql: $(EXTENSION)--2.3.0.sql $(EXTENSION)--2.3.0--2.3.1.sql cat $^ > $@ +$(EXTENSION)--2.4.0.sql: $(EXTENSION)--2.3.1.sql $(EXTENSION)--2.3.1--2.4.0.sql + cat $^ > $@ EXTRA_CLEAN += topn--*.sql -r $(RPM_BUILD_ROOT) diff --git a/topn.control b/topn.control index 0996985..b0e456e 100644 --- a/topn.control +++ b/topn.control @@ -1,4 +1,4 @@ # topn extension comment = 'type for top-n JSONB' -default_version = '2.3.1' +default_version = '2.4.0' module_pathname = '$libdir/topn' diff --git a/update/topn--2.3.1--2.4.0.sql b/update/topn--2.3.1--2.4.0.sql new file mode 100644 index 0000000..09d2077 --- /dev/null +++ b/update/topn--2.3.1--2.4.0.sql @@ -0,0 +1,3 @@ +/* topn--2.3.1--2.4.0 */ + +/* bump version to 2.4.0 */ From 4bb5cea1800d8f559f0ce9ecdbb679ec43d03943 Mon Sep 17 00:00:00 2001 From: Hanefi Onaldi Date: Thu, 9 Sep 2021 18:54:50 +0300 Subject: [PATCH 5/5] Add PG14 to CI configs --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 16ed6f5..635448e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,7 @@ matrix: - env: PGVERSION=11 - env: PGVERSION=12 - env: PGVERSION=13 + - env: PGVERSION=14 before_install: - bash test_data_provider - git clone -b v0.7.13 --depth 1 https://github.com/citusdata/tools.git