diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 00000000000..3a89c17ecfb --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,30 @@ +--- +name: Bug report +about: Create a report to help us improve +title: "[Bug]" +labels: bug +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. xxx +2. xxx +3. xxx + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Environment (please complete the following information):** + - OS: [e.g. CentOS 7] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/question.md b/.github/ISSUE_TEMPLATE/question.md new file mode 100644 index 00000000000..f223c068ca0 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/question.md @@ -0,0 +1,12 @@ +--- +name: Question +about: Ask question about anything here. +title: "[Question]" +labels: question +assignees: '' + +--- + +**Describe the problem** + +... diff --git a/.github/workflows/precheck.yml b/.github/workflows/precheck.yml new file mode 100644 index 00000000000..1e7582200cd --- /dev/null +++ b/.github/workflows/precheck.yml @@ -0,0 +1,90 @@ +name: precheck + +on: + push: + branches: [ POLARDB_15_STABLE ] + paths: + - '.github/workflows/precheck.yml' + - 'config/**' + - 'contrib/**' + - 'external/**' + - 'src/**' + - 'configure*' + - 'build.sh' + pull_request: + branches: [ POLARDB_15_STABLE ] + paths: + - '.github/workflows/precheck.yml' + - 'config/**' + - 'contrib/**' + - 'external/**' + - 'src/**' + - 'configure*' + - 'build.sh' + # trigger testing manually + workflow_dispatch: + +jobs: + regression: + runs-on: ubuntu-latest + strategy: + matrix: + container_image: [ rocky8, rocky9, ubuntu22.04 ] + rules: [ precheck-main, plcheck ] + debug_mode: [ on, off ] + steps: + - name: fetch source code + uses: actions/checkout@v4 + + - name: free disk space + run: | + df -h + sudo rm -rf .git + sudo swapoff -a + sudo rm -f /swapfile + sudo rm -rf \ + /usr/share/dotnet /usr/local/lib/android /opt/ghc \ + /usr/local/share/powershell /usr/share/swift /usr/local/.ghcup \ + /usr/lib/jvm || true + sudo apt autoremove -y + sudo apt clean -y + docker rmi $(docker image ls -aq) + df -h + + - name: limit WAL size + run: | + grep -n "DEFAULT_XLOG_SEG_SIZE" src/include/pg_config_manual.h | cut -d: -f1 | xargs -I {} sed -i '{}s/.*/#define DEFAULT_XLOG_SEG_SIZE (16*1024*1024)/' src/include/pg_config_manual.h + + - name: ignore unstable cases + run: | + sed -i 's/SUBDIRS += pgvector/# &/' external/Makefile + + - name: create and start the container + run: | + docker create \ + -t \ + --name polardb_${{ matrix.container_image }} \ + -v `pwd`:/home/postgres/PolarDB-for-PostgreSQL \ + polardb/polardb_pg_devel:${{ matrix.container_image }} \ + bash && \ + docker start polardb_${{ matrix.container_image }} + + - name: change ownership of the source code + run: | + docker exec \ + polardb_${{ matrix.container_image }} \ + bash -c "cd /home/postgres/PolarDB-for-PostgreSQL && \ + sudo chown -R postgres:postgres ./" + + - name: build and run checks + run: | + docker exec \ + polardb_${{ matrix.container_image }} \ + bash -c "cd /home/postgres/PolarDB-for-PostgreSQL && \ + if [ -f /etc/bashrc ]; then source /etc/bashrc; fi && \ + ./build.sh --wr=1 --debug=${{ matrix.debug_mode }} --ec='--enable-tap-tests' && \ + make ${{ matrix.rules }} -j4" + + - name: change ownership of the source code back + run: | + sudo chown -R runner:runner `pwd` diff --git a/.github/workflows/sync-postgres.yml b/.github/workflows/sync-postgres.yml new file mode 100644 index 00000000000..d56e3132af8 --- /dev/null +++ b/.github/workflows/sync-postgres.yml @@ -0,0 +1,42 @@ +name: sync with postgres upstream + +on: + workflow_dispatch: + schedule: + - cron: "0 0 * * *" + +jobs: + repo-sync: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + - name: repo-sync-master + uses: repo-sync/github-sync@v2 + with: + source_repo: https://github.com/postgres/postgres.git + source_branch: master + destination_branch: master + github_token: ${{ secrets.GITHUB_TOKEN }} + - name: repo-sync-17 + uses: repo-sync/github-sync@v2 + with: + source_repo: https://github.com/postgres/postgres.git + source_branch: REL_17_STABLE + destination_branch: REL_17_STABLE + github_token: ${{ secrets.GITHUB_TOKEN }} + - name: repo-sync-16 + uses: repo-sync/github-sync@v2 + with: + source_repo: https://github.com/postgres/postgres.git + source_branch: REL_16_STABLE + destination_branch: REL_16_STABLE + github_token: ${{ secrets.GITHUB_TOKEN }} + - name: repo-sync-15 + uses: repo-sync/github-sync@v2 + with: + source_repo: https://github.com/postgres/postgres.git + source_branch: REL_15_STABLE + destination_branch: REL_15_STABLE + github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/GNUmakefile.in b/GNUmakefile.in index 8cb6362cdce..4d51d1a6261 100644 --- a/GNUmakefile.in +++ b/GNUmakefile.in @@ -157,7 +157,7 @@ cpluspluscheck: submake-generated-headers # POLAR # LAST_COMMIT = HEAD~1 -PROVE_FLAGS = "--timer -j4" +PROVE_FLAGS = "--timer" precheck-main: | temp-install $(MAKE) check-world EXTRA_TESTS=numeric_big PG_TEST_EXTRA='kerberos ldap ssl' USE_MODULE_DB=1 PROVE_FLAGS=$(PROVE_FLAGS) diff --git a/build.sh b/build.sh index 5e63152e0a8..561b087ef1e 100755 --- a/build.sh +++ b/build.sh @@ -81,7 +81,7 @@ function compile() { configure_flag+=" --prefix=$base_dir --with-pgport=$port ${extra_configure_flag-}" info "Begin configure, flag: $configure_flag" ./configure $configure_flag - info "Begin compile and install PolarDB" + info "Begin compile and install PolarDB, flag: $make_flag" make install-world-bin $make_flag } diff --git a/external/hll/.gitignore b/external/hll/.gitignore index 8634a9c3c36..6022a745252 100644 --- a/external/hll/.gitignore +++ b/external/hll/.gitignore @@ -2,9 +2,7 @@ /log/ /results/ /tmp_check/ -regression.out -regression.diffs binary.dat .deps/ -*.sql \ No newline at end of file +/*.sql diff --git a/external/hll/sql/add_agg.sql b/external/hll/sql/add_agg.sql new file mode 100644 index 00000000000..f27e673f934 --- /dev/null +++ b/external/hll/sql/add_agg.sql @@ -0,0 +1,75 @@ +-- ---------------------------------------------------------------- +-- Regression tests for add aggregate hashval function. +-- ---------------------------------------------------------------- + +SELECT hll_set_output_version(1); + +DROP TABLE IF EXISTS test_khvengxf; + +CREATE TABLE test_khvengxf ( + val integer +); + +insert into test_khvengxf(val) values (1), (2), (3); + +-- Check default and explicit signatures. + +select hll_print(hll_add_agg(hll_hash_integer(val))) + from test_khvengxf; + +select hll_print(hll_add_agg(hll_hash_integer(val), 10)) + from test_khvengxf; + +select hll_print(hll_add_agg(hll_hash_integer(val), 10, 4)) + from test_khvengxf; + +select hll_print(hll_add_agg(hll_hash_integer(val), 10, 4, 512)) + from test_khvengxf; + +select hll_print(hll_add_agg(hll_hash_integer(val), 10, 4, -1)) + from test_khvengxf; + +select hll_print(hll_add_agg(hll_hash_integer(val), 10, 4, 512, 0)) + from test_khvengxf; + +-- Check range checking. + +select hll_print(hll_add_agg(hll_hash_integer(val), -1)) + from test_khvengxf; + +select hll_print(hll_add_agg(hll_hash_integer(val), 32)) + from test_khvengxf; + +select hll_print(hll_add_agg(hll_hash_integer(val), 10, -1)) + from test_khvengxf; + +select hll_print(hll_add_agg(hll_hash_integer(val), 10, 8)) + from test_khvengxf; + +select hll_print(hll_add_agg(hll_hash_integer(val), 10, 4, -2)) + from test_khvengxf; + +select hll_print(hll_add_agg(hll_hash_integer(val), 10, 4, 8589934592)) + from test_khvengxf; + +select hll_print(hll_add_agg(hll_hash_integer(val), 10, 4, 512, -1)) + from test_khvengxf; + +select hll_print(hll_add_agg(hll_hash_integer(val), 10, 4, 512, 2)) + from test_khvengxf; + +-- Check that we return hll_empty on null input. + +select hll_print(hll_add_agg(NULL)); + +select hll_print(hll_add_agg(NULL, 10)); + +select hll_print(hll_add_agg(NULL, 10, 4)); + +select hll_print(hll_add_agg(NULL, 10, 4, 512)); + +select hll_print(hll_add_agg(NULL, 10, 4, -1)); + +select hll_print(hll_add_agg(NULL, 10, 4, 512, 0)); + +DROP TABLE test_khvengxf; diff --git a/external/hll/sql/agg_oob.sql b/external/hll/sql/agg_oob.sql new file mode 100644 index 00000000000..1c83158a590 --- /dev/null +++ b/external/hll/sql/agg_oob.sql @@ -0,0 +1,285 @@ +-- ---------------------------------------------------------------- +-- Aggregate Operations with Out-Of-Band Values. +-- NULL, UNDEFINED, EMPTY, EXPLICIT, SPARSE +-- (Sparse and compressed are the same internally) +-- ---------------------------------------------------------------- + +SELECT hll_set_output_version(1); + +DROP TABLE IF EXISTS test_wdflbzfx; + +CREATE TABLE test_wdflbzfx ( + recno SERIAL, + v1 hll +); + +INSERT INTO test_wdflbzfx (recno, v1) VALUES +-- NULL -- +(0, NULL), +(1, NULL), +(2, NULL), +(3, NULL), +-- UNDEFINED -- +(4, E'\\x108b7f'), +(5, E'\\x108b7f'), +(6, E'\\x108b7f'), +(7, E'\\x108b7f'), +-- EMPTY -- +(8, E'\\x118b7f'), +(9, E'\\x118b7f'), +(10, E'\\x118b7f'), +(11, E'\\x118b7f'), +-- EXPLICIT -- +(12, E'\\x128b7f1111111111111111'), +(13, E'\\x128b7f2222222222222222'), +(14, E'\\x128b7f3333333333333333'), +(15, E'\\x128b7f4444444444444444'), +-- SPARSE -- +(16, E'\\x138b7f0001'), +(17, E'\\x138b7f0022'), +(18, E'\\x138b7f0041'), +(19, E'\\x138b7f0061'); + +-- ---------------------------------------------------------------- +-- Aggregate Union +-- ---------------------------------------------------------------- + +-- No rows selected +SELECT hll_union_agg(v1) FROM test_wdflbzfx WHERE recno > 100; + +-- NULLs +SELECT hll_union_agg(v1) FROM test_wdflbzfx WHERE recno IN (0, 1, 2, 3); + +-- UNDEFINED +SELECT hll_union_agg(v1) FROM test_wdflbzfx WHERE recno IN (4, 5, 6, 7); + +-- UNDEFINED and NULL +SELECT hll_union_agg(v1) FROM test_wdflbzfx WHERE recno IN (4, 5, 6, 7) + OR recno IN (0, 1, 2, 3); + +-- EMPTY +SELECT hll_union_agg(v1) FROM test_wdflbzfx WHERE recno IN (8, 9, 10, 11); + +-- EMPTY and NULL +SELECT hll_union_agg(v1) FROM test_wdflbzfx WHERE recno IN (8, 9, 10, 11) + OR recno IN (0, 1, 2, 3); + +-- EMPTY and UNDEFINED +SELECT hll_union_agg(v1) FROM test_wdflbzfx WHERE recno IN (8, 9, 10, 11) + OR recno IN (4, 5, 6, 7); + +-- EMPTY, UNDEFINED and NULL +SELECT hll_union_agg(v1) FROM test_wdflbzfx WHERE recno IN (8, 9, 10, 11) + OR recno IN (4, 5, 6, 7) + OR recno IN (0, 1, 2, 3); + +-- EXPLICIT +SELECT hll_union_agg(v1) FROM test_wdflbzfx WHERE recno IN (12, 13, 14, 15); + +-- EXPLICIT and NULL +SELECT hll_union_agg(v1) FROM test_wdflbzfx WHERE recno IN (12, 13, 14, 15) + OR recno IN (0, 1, 2, 3); + +-- EXPLICIT and UNDEFINED +SELECT hll_union_agg(v1) FROM test_wdflbzfx WHERE recno IN (12, 13, 14, 15) + OR recno IN (4, 5, 6, 7); + +-- EXPLICIT, UNDEFINED and NULL +SELECT hll_union_agg(v1) FROM test_wdflbzfx WHERE recno IN (12, 13, 14, 15) + OR recno IN (4, 5, 6, 7) + OR recno IN (0, 1, 2, 3); + +-- EXPLICIT and EMPTY +SELECT hll_union_agg(v1) FROM test_wdflbzfx WHERE recno IN (12, 13, 14, 15) + OR recno IN (8, 9, 10, 11); + +-- EXPLICIT, EMPTY and NULL +SELECT hll_union_agg(v1) FROM test_wdflbzfx WHERE recno IN (12, 13, 14, 15) + OR recno IN (8, 9, 10, 11) + OR recno IN (0, 1, 2, 3); + +-- EXPLICIT, EMPTY and UNDEFINED +SELECT hll_union_agg(v1) FROM test_wdflbzfx WHERE recno IN (12, 13, 14, 15) + OR recno IN (8, 9, 10, 11) + OR recno IN (4, 5, 6, 7); + +-- EXPLICIT, EMPTY, UNDEFINED and NULL +SELECT hll_union_agg(v1) FROM test_wdflbzfx WHERE recno IN (12, 13, 14, 15) + OR recno IN (8, 9, 10, 11) + OR recno IN (4, 5, 6, 7) + OR recno IN (0, 1, 2, 3); + +-- Don't feel like a full sparse/explicit permuatation is adding +-- anything here ... just replace explicit w/ sparse. + +-- SPARSE +SELECT hll_union_agg(v1) FROM test_wdflbzfx WHERE recno IN (16, 17, 18, 19); + +-- SPARSE and NULL +SELECT hll_union_agg(v1) FROM test_wdflbzfx WHERE recno IN (16, 17, 18, 19) + OR recno IN (0, 1, 2, 3); + +-- SPARSE and UNDEFINED +SELECT hll_union_agg(v1) FROM test_wdflbzfx WHERE recno IN (16, 17, 18, 19) + OR recno IN (4, 5, 6, 7); + +-- SPARSE, UNDEFINED and NULL +SELECT hll_union_agg(v1) FROM test_wdflbzfx WHERE recno IN (16, 17, 18, 19) + OR recno IN (4, 5, 6, 7) + OR recno IN (0, 1, 2, 3); + +-- SPARSE and EMPTY +SELECT hll_union_agg(v1) FROM test_wdflbzfx WHERE recno IN (16, 17, 18, 19) + OR recno IN (8, 9, 10, 11); + +-- SPARSE, EMPTY and NULL +SELECT hll_union_agg(v1) FROM test_wdflbzfx WHERE recno IN (16, 17, 18, 19) + OR recno IN (8, 9, 10, 11) + OR recno IN (0, 1, 2, 3); + +-- SPARSE, EMPTY and UNDEFINED +SELECT hll_union_agg(v1) FROM test_wdflbzfx WHERE recno IN (16, 17, 18, 19) + OR recno IN (8, 9, 10, 11) + OR recno IN (4, 5, 6, 7); + +-- SPARSE, EMPTY, UNDEFINED and NULL +SELECT hll_union_agg(v1) FROM test_wdflbzfx WHERE recno IN (16, 17, 18, 19) + OR recno IN (8, 9, 10, 11) + OR recno IN (4, 5, 6, 7) + OR recno IN (0, 1, 2, 3); + +-- ---------------------------------------------------------------- +-- Aggregate Cardinality +-- ---------------------------------------------------------------- + + +-- No rows selected +SELECT ceiling(hll_cardinality(hll_union_agg(v1))) + FROM test_wdflbzfx WHERE recno > 100; + +-- NULLs +SELECT ceiling(hll_cardinality(hll_union_agg(v1))) + FROM test_wdflbzfx WHERE recno IN (0, 1, 2, 3); + +-- UNDEFINED +SELECT ceiling(hll_cardinality(hll_union_agg(v1))) + FROM test_wdflbzfx WHERE recno IN (4, 5, 6, 7); + +-- UNDEFINED and NULL +SELECT ceiling(hll_cardinality(hll_union_agg(v1))) + FROM test_wdflbzfx WHERE recno IN (4, 5, 6, 7) + OR recno IN (0, 1, 2, 3); + +-- EMPTY +SELECT ceiling(hll_cardinality(hll_union_agg(v1))) + FROM test_wdflbzfx WHERE recno IN (8, 9, 10, 11); + +-- EMPTY and NULL +SELECT ceiling(hll_cardinality(hll_union_agg(v1))) + FROM test_wdflbzfx WHERE recno IN (8, 9, 10, 11) + OR recno IN (0, 1, 2, 3); + +-- EMPTY and UNDEFINED +SELECT ceiling(hll_cardinality(hll_union_agg(v1))) + FROM test_wdflbzfx WHERE recno IN (8, 9, 10, 11) + OR recno IN (4, 5, 6, 7); + +-- EMPTY, UNDEFINED and NULL +SELECT ceiling(hll_cardinality(hll_union_agg(v1))) + FROM test_wdflbzfx WHERE recno IN (8, 9, 10, 11) + OR recno IN (4, 5, 6, 7) + OR recno IN (0, 1, 2, 3); + +-- EXPLICIT +SELECT ceiling(hll_cardinality(hll_union_agg(v1))) + FROM test_wdflbzfx WHERE recno IN (12, 13, 14, 15); + +-- EXPLICIT and NULL +SELECT ceiling(hll_cardinality(hll_union_agg(v1))) + FROM test_wdflbzfx WHERE recno IN (12, 13, 14, 15) + OR recno IN (0, 1, 2, 3); + +-- EXPLICIT and UNDEFINED +SELECT ceiling(hll_cardinality(hll_union_agg(v1))) + FROM test_wdflbzfx WHERE recno IN (12, 13, 14, 15) + OR recno IN (4, 5, 6, 7); + +-- EXPLICIT, UNDEFINED and NULL +SELECT ceiling(hll_cardinality(hll_union_agg(v1))) + FROM test_wdflbzfx WHERE recno IN (12, 13, 14, 15) + OR recno IN (4, 5, 6, 7) + OR recno IN (0, 1, 2, 3); + +-- EXPLICIT and EMPTY +SELECT ceiling(hll_cardinality(hll_union_agg(v1))) + FROM test_wdflbzfx WHERE recno IN (12, 13, 14, 15) + OR recno IN (8, 9, 10, 11); + +-- EXPLICIT, EMPTY and NULL +SELECT ceiling(hll_cardinality(hll_union_agg(v1))) + FROM test_wdflbzfx WHERE recno IN (12, 13, 14, 15) + OR recno IN (8, 9, 10, 11) + OR recno IN (0, 1, 2, 3); + +-- EXPLICIT, EMPTY and UNDEFINED +SELECT ceiling(hll_cardinality(hll_union_agg(v1))) + FROM test_wdflbzfx WHERE recno IN (12, 13, 14, 15) + OR recno IN (8, 9, 10, 11) + OR recno IN (4, 5, 6, 7); + +-- EXPLICIT, EMPTY, UNDEFINED and NULL +SELECT ceiling(hll_cardinality(hll_union_agg(v1))) + FROM test_wdflbzfx WHERE recno IN (12, 13, 14, 15) + OR recno IN (8, 9, 10, 11) + OR recno IN (4, 5, 6, 7) + OR recno IN (0, 1, 2, 3); + +-- Don't feel like a full sparse/explicit permuatation is adding +-- anything here ... just replace explicit w/ sparse. + +-- SPARSE +SELECT ceiling(hll_cardinality(hll_union_agg(v1))) + FROM test_wdflbzfx WHERE recno IN (16, 17, 18, 19); + +-- SPARSE and NULL +SELECT ceiling(hll_cardinality(hll_union_agg(v1))) + FROM test_wdflbzfx WHERE recno IN (16, 17, 18, 19) + OR recno IN (0, 1, 2, 3); + +-- SPARSE and UNDEFINED +SELECT ceiling(hll_cardinality(hll_union_agg(v1))) + FROM test_wdflbzfx WHERE recno IN (16, 17, 18, 19) + OR recno IN (4, 5, 6, 7); + +-- SPARSE, UNDEFINED and NULL +SELECT ceiling(hll_cardinality(hll_union_agg(v1))) + FROM test_wdflbzfx WHERE recno IN (16, 17, 18, 19) + OR recno IN (4, 5, 6, 7) + OR recno IN (0, 1, 2, 3); + +-- SPARSE and EMPTY +SELECT ceiling(hll_cardinality(hll_union_agg(v1))) + FROM test_wdflbzfx WHERE recno IN (16, 17, 18, 19) + OR recno IN (8, 9, 10, 11); + +-- SPARSE, EMPTY and NULL +SELECT ceiling(hll_cardinality(hll_union_agg(v1))) + FROM test_wdflbzfx WHERE recno IN (16, 17, 18, 19) + OR recno IN (8, 9, 10, 11) + OR recno IN (0, 1, 2, 3); + +-- SPARSE, EMPTY and UNDEFINED +SELECT ceiling(hll_cardinality(hll_union_agg(v1))) + FROM test_wdflbzfx WHERE recno IN (16, 17, 18, 19) + OR recno IN (8, 9, 10, 11) + OR recno IN (4, 5, 6, 7); + +-- SPARSE, EMPTY, UNDEFINED and NULL +SELECT ceiling(hll_cardinality(hll_union_agg(v1))) + FROM test_wdflbzfx WHERE recno IN (16, 17, 18, 19) + OR recno IN (8, 9, 10, 11) + OR recno IN (4, 5, 6, 7) + OR recno IN (0, 1, 2, 3); + + +DROP TABLE IF EXISTS test_wdflbzfx; diff --git a/external/hll/sql/auto_sparse.sql b/external/hll/sql/auto_sparse.sql new file mode 100644 index 00000000000..9d8dbdc9c90 --- /dev/null +++ b/external/hll/sql/auto_sparse.sql @@ -0,0 +1,141 @@ +-- ---------------------------------------------------------------- +-- Tests automatic sparse to compressed threshold assignment. +-- ---------------------------------------------------------------- + +SELECT hll_set_output_version(1); + +-- Empty + +SELECT hll_empty(5,5,-1,1); + +-- Explicit + +SELECT hll_add(hll_empty(5,5,-1,1), + hll_hash_integer(1,0)); + +SELECT hll_add( + hll_add(hll_empty(5,5,-1,1), + hll_hash_integer(2,0)), + hll_hash_integer(1,0)); + +-- Sparse + +SELECT hll_add( + hll_add( + hll_add(hll_empty(5,5,-1,1), + hll_hash_integer(3,0)), + hll_hash_integer(2,0)), + hll_hash_integer(1,0)); + + +-- Sparse, has 15 filled +SELECT hll_add( + hll_add( + hll_add( + hll_add( + hll_add( + hll_add( + hll_add( + hll_add( + hll_add( + hll_add( + hll_add( + hll_add( + hll_add( + hll_add( + hll_add( + hll_add(hll_empty(5,5,-1,1), + hll_hash_integer(17,0)), + hll_hash_integer(15,0)), + hll_hash_integer(14,0)), + hll_hash_integer(13,0)), + hll_hash_integer(12,0)), + hll_hash_integer(11,0)), + hll_hash_integer(10,0)), + hll_hash_integer(9,0)), + hll_hash_integer(8,0)), + hll_hash_integer(7,0)), + hll_hash_integer(6,0)), + hll_hash_integer(5,0)), + hll_hash_integer(4,0)), + hll_hash_integer(3,0)), + hll_hash_integer(2,0)), + hll_hash_integer(1,0)); + +-- Compressed, has 16 filled +SELECT hll_add( + hll_add( + hll_add( + hll_add( + hll_add( + hll_add( + hll_add( + hll_add( + hll_add( + hll_add( + hll_add( + hll_add( + hll_add( + hll_add( + hll_add( + hll_add( + hll_add(hll_empty(5,5,-1,1), + hll_hash_integer(20,0)), + hll_hash_integer(17,0)), + hll_hash_integer(15,0)), + hll_hash_integer(14,0)), + hll_hash_integer(13,0)), + hll_hash_integer(12,0)), + hll_hash_integer(11,0)), + hll_hash_integer(10,0)), + hll_hash_integer(9,0)), + hll_hash_integer(8,0)), + hll_hash_integer(7,0)), + hll_hash_integer(6,0)), + hll_hash_integer(5,0)), + hll_hash_integer(4,0)), + hll_hash_integer(3,0)), + hll_hash_integer(2,0)), + hll_hash_integer(1,0)); + +-- Same with fixed sparse of 128 + +SELECT hll_set_max_sparse(128); + +SELECT hll_add( + hll_add( + hll_add( + hll_add( + hll_add( + hll_add( + hll_add( + hll_add( + hll_add( + hll_add( + hll_add( + hll_add( + hll_add( + hll_add( + hll_add( + hll_add( + hll_add(hll_empty(5,5,-1,1), + hll_hash_integer(20,0)), + hll_hash_integer(17,0)), + hll_hash_integer(15,0)), + hll_hash_integer(14,0)), + hll_hash_integer(13,0)), + hll_hash_integer(12,0)), + hll_hash_integer(11,0)), + hll_hash_integer(10,0)), + hll_hash_integer(9,0)), + hll_hash_integer(8,0)), + hll_hash_integer(7,0)), + hll_hash_integer(6,0)), + hll_hash_integer(5,0)), + hll_hash_integer(4,0)), + hll_hash_integer(3,0)), + hll_hash_integer(2,0)), + hll_hash_integer(1,0)); + +-- Notice that sparse result is not shorter than the compressed +-- result. diff --git a/external/hll/sql/card_op.sql b/external/hll/sql/card_op.sql new file mode 100644 index 00000000000..995d2409a80 --- /dev/null +++ b/external/hll/sql/card_op.sql @@ -0,0 +1,25 @@ +-- ---------------------------------------------------------------- +-- Regression tests for cardinality operator. +-- ---------------------------------------------------------------- + +set extra_float_digits=0; +SELECT hll_set_output_version(1); + +SELECT #E'\\x108b49'::hll; + +SELECT #hll_empty(11,5,256,1); + +-- # gets evaluated first so || hll_union(double, bigint) fails +SELECT #hll_empty(11,5,256,1) || hll_hash_integer(1,0); + +SELECT #(hll_empty(11,5,256,1) || hll_hash_integer(1,0)); + +SELECT #E'\\x128b498895a3f5af28cafe'::hll; + +SELECT #E'\\x128b498895a3f5af28cafeda0ce907e4355b60'::hll; + +SELECT #E'\\x138b4f0061'::hll; + +SELECT #E'\\x148B480800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'::hll; + +SELECT #E'\\x148B480842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'::hll; diff --git a/external/hll/sql/cast_shape.sql b/external/hll/sql/cast_shape.sql new file mode 100644 index 00000000000..3f15e20d5c9 --- /dev/null +++ b/external/hll/sql/cast_shape.sql @@ -0,0 +1,76 @@ +-- ---------------------------------------------------------------- +-- Shape checks on casts +-- ---------------------------------------------------------------- + +SELECT hll_set_output_version(1); + +-- Empty Casts ---- + +SELECT E'\\x118b7f'::hll; + +SELECT E'\\x118b7f'::hll(11,5,-1,1); + +-- ERROR: register count does not match: source uses 2048 and dest uses 1024 +SELECT E'\\x118b7f'::hll(10,5,-1,1); + +-- ERROR: register width does not match: source uses 5 and dest uses 4 +SELECT E'\\x118b7f'::hll(11,4,-1,1); + +-- ERROR: explicit threshold does not match: source uses -1 and dest uses 64 +SELECT E'\\x118b7f'::hll(11,5,64,1); + +-- ERROR: sparse enable does not match: source uses 1 and dest uses 0 +SELECT E'\\x118b7f'::hll(11,5,-1,0); + +-- Explicit Vector Casts ---- + +SELECT E'\\x128b7f1111111111111111'::hll; + +SELECT E'\\x128b7f1111111111111111'::hll(11,5,-1,1); + +-- ERROR: register count does not match: source uses 2048 and dest uses 1024 +SELECT E'\\x128b7f1111111111111111'::hll(10,5,-1,1); + +-- ERROR: register width does not match: source uses 5 and dest uses 4 +SELECT E'\\x128b7f1111111111111111'::hll(11,4,-1,1); + +-- ERROR: explicit threshold does not match: source uses -1 and dest uses 64 +SELECT E'\\x128b7f1111111111111111'::hll(11,5,64,1); + +-- ERROR: sparse enable does not match: source uses 1 and dest uses 0 +SELECT E'\\x128b7f1111111111111111'::hll(11,5,-1,0); + +-- Sparse Vector Casts ---- + +SELECT E'\\x138b7f0001'::hll; + +SELECT E'\\x138b7f0001'::hll(11,5,-1,1); + +-- ERROR: register count does not match: source uses 2048 and dest uses 1024 +SELECT E'\\x138b7f0001'::hll(10,5,-1,1); + +-- ERROR: register width does not match: source uses 5 and dest uses 4 +SELECT E'\\x138b7f0001'::hll(11,4,-1,1); + +-- ERROR: explicit threshold does not match: source uses -1 and dest uses 64 +SELECT E'\\x138b7f0001'::hll(11,5,64,1); + +-- ERROR: sparse enable does not match: source uses 1 and dest uses 0 +SELECT E'\\x138b7f0001'::hll(11,5,-1,0); + +-- Compressed Vector Casts ---- +SELECT E'\\x148b7f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000'::hll; + +SELECT E'\\x148b7f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000'::hll(11,5,-1,1); + +-- ERROR: register count does not match: source uses 2048 and dest uses 1024 +SELECT E'\\x148b7f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000'::hll(10,5,-1,1); + +-- ERROR: register width does not match: source uses 5 and dest uses 4 +SELECT E'\\x148b7f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000'::hll(11,4,-1,1); + +-- ERROR: explicit threshold does not match: source uses -1 and dest uses 64 +SELECT E'\\x148b7f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000'::hll(11,5,64,1); + +-- ERROR: sparse enable does not match: source uses 1 and dest uses 0 +SELECT E'\\x148b7f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000'::hll(11,5,-1,0); diff --git a/external/hll/sql/copy_binary.sql b/external/hll/sql/copy_binary.sql new file mode 100644 index 00000000000..54eacab3094 --- /dev/null +++ b/external/hll/sql/copy_binary.sql @@ -0,0 +1,21 @@ +SELECT hll_set_output_version(1); + +DROP TABLE IF EXISTS test_binary; + +CREATE TABLE test_binary (id SERIAL, v1 hll); + +INSERT INTO test_binary(id,v1) VALUES (1, hll_empty() || hll_hash_text('A')); + +SELECT hll_cardinality(v1) FROM test_binary; + +\COPY test_binary TO 'binary.dat' WITH (FORMAT "binary") + +DELETE FROM test_binary; + +SELECT hll_cardinality(v1) FROM test_binary; + +\COPY test_binary FROM 'binary.dat' WITH (FORMAT "binary") + +SELECT hll_cardinality(v1) FROM test_binary; + +DROP TABLE test_binary; diff --git a/external/hll/sql/cumulative_add_cardinality_correction.sql b/external/hll/sql/cumulative_add_cardinality_correction.sql new file mode 100644 index 00000000000..1baefe6dceb --- /dev/null +++ b/external/hll/sql/cumulative_add_cardinality_correction.sql @@ -0,0 +1,54 @@ +-- ================================================================ +-- Setup the table +-- + +set extra_float_digits=0; +SELECT hll_set_output_version(1); + +-- This test relies on a non-standard fixed sparse-to-compressed +-- threshold value. +-- +SELECT hll_set_max_sparse(0); + +DROP TABLE IF EXISTS test_msgfjqhm; + +CREATE TABLE test_msgfjqhm ( + recno SERIAL, + cardinality double precision, + raw_value bigint, + union_compressed_multiset hll +); + +-- Copy the CSV data into the table +-- +\copy test_msgfjqhm (cardinality, raw_value, union_compressed_multiset) from sql/data/cumulative_add_cardinality_correction.csv with csv header + +SELECT COUNT(*) FROM test_msgfjqhm; + +-- Test incremental adding. +SELECT curr.recno, + curr.union_compressed_multiset, + hll_add(prev.union_compressed_multiset, hll_hashval(curr.raw_value)) + FROM test_msgfjqhm prev, test_msgfjqhm curr + WHERE curr.recno > 1 + AND curr.recno = prev.recno + 1 + AND curr.union_compressed_multiset != + hll_add(prev.union_compressed_multiset, hll_hashval(curr.raw_value)) + ORDER BY curr.recno; + +-- Test cardinality of incremental adds. +SELECT curr.recno, + curr.cardinality, + hll_cardinality(hll_add(prev.union_compressed_multiset, + hll_hashval(curr.raw_value))) + FROM test_msgfjqhm prev, test_msgfjqhm curr + WHERE curr.recno > 1 + AND curr.recno = prev.recno + 1 + AND round(curr.cardinality::numeric, 10) != + round(hll_cardinality(hll_add(prev.union_compressed_multiset, + hll_hashval(curr.raw_value)))::numeric, + 10) + ORDER BY curr.recno; + +DROP TABLE test_msgfjqhm; + diff --git a/external/hll/sql/cumulative_add_comprehensive_promotion.sql b/external/hll/sql/cumulative_add_comprehensive_promotion.sql new file mode 100644 index 00000000000..d14607bbe33 --- /dev/null +++ b/external/hll/sql/cumulative_add_comprehensive_promotion.sql @@ -0,0 +1,54 @@ +-- ================================================================ +-- Setup the table +-- + +set extra_float_digits=0; +SELECT hll_set_output_version(1); + +-- This test relies on a non-standard fixed sparse-to-compressed +-- threshold value. +-- +SELECT hll_set_max_sparse(512); + +DROP TABLE IF EXISTS test_ptwysrqk; + +CREATE TABLE test_ptwysrqk ( + recno SERIAL, + cardinality double precision, + raw_value bigint, + union_compressed_multiset hll +); + +-- Copy the CSV data into the table +-- +\copy test_ptwysrqk (cardinality, raw_value, union_compressed_multiset) from sql/data/cumulative_add_comprehensive_promotion.csv with csv header + +SELECT COUNT(*) FROM test_ptwysrqk; + +-- Test incremental adding. +SELECT curr.recno, + curr.union_compressed_multiset, + hll_add(prev.union_compressed_multiset, curr.raw_value::hll_hashval) + FROM test_ptwysrqk prev, test_ptwysrqk curr + WHERE curr.recno > 1 + AND curr.recno = prev.recno + 1 + AND curr.union_compressed_multiset != + hll_add(prev.union_compressed_multiset, curr.raw_value::hll_hashval) + ORDER BY curr.recno; + +-- Test cardinality of incremental adds. +SELECT curr.recno, + curr.cardinality, + hll_cardinality(hll_add(prev.union_compressed_multiset, + curr.raw_value::hll_hashval)) + FROM test_ptwysrqk prev, test_ptwysrqk curr + WHERE curr.recno > 1 + AND curr.recno = prev.recno + 1 + AND round(curr.cardinality::numeric, 10) != + round(hll_cardinality(hll_add(prev.union_compressed_multiset, + curr.raw_value::hll_hashval))::numeric, + 10) + ORDER BY curr.recno; + +DROP TABLE test_ptwysrqk; + diff --git a/external/hll/sql/cumulative_add_sparse_edge.sql b/external/hll/sql/cumulative_add_sparse_edge.sql new file mode 100644 index 00000000000..4987d80c9cb --- /dev/null +++ b/external/hll/sql/cumulative_add_sparse_edge.sql @@ -0,0 +1,52 @@ +-- ================================================================ +-- Setup the table +-- + +SELECT hll_set_output_version(1); + +-- This test relies on a non-standard fixed sparse-to-compressed +-- threshold value. +-- +SELECT hll_set_max_sparse(512); + +DROP TABLE IF EXISTS test_eopzdzwz; + +CREATE TABLE test_eopzdzwz ( + recno SERIAL, + cardinality double precision, + raw_value bigint, + union_compressed_multiset hll +); + +-- Copy the CSV data into the table +-- +\copy test_eopzdzwz (cardinality, raw_value, union_compressed_multiset) from sql/data/cumulative_add_sparse_edge.csv with csv header + +SELECT COUNT(*) FROM test_eopzdzwz; + +-- Test incremental adding. +SELECT curr.recno, + curr.union_compressed_multiset, + hll_add(prev.union_compressed_multiset, hll_hashval(curr.raw_value)) + FROM test_eopzdzwz prev, test_eopzdzwz curr + WHERE curr.recno > 1 + AND curr.recno = prev.recno + 1 + AND curr.union_compressed_multiset != + hll_add(prev.union_compressed_multiset, hll_hashval(curr.raw_value)) + ORDER BY curr.recno; + +-- Test cardinality of incremental adds. +SELECT curr.recno, + curr.cardinality, + hll_cardinality(hll_add(prev.union_compressed_multiset, + hll_hashval(curr.raw_value))) + FROM test_eopzdzwz prev, test_eopzdzwz curr + WHERE curr.recno > 1 + AND curr.recno = prev.recno + 1 + AND curr.cardinality != + hll_cardinality(hll_add(prev.union_compressed_multiset, + hll_hashval(curr.raw_value))) + ORDER BY curr.recno; + +DROP TABLE test_eopzdzwz; + diff --git a/external/hll/sql/cumulative_add_sparse_random.sql b/external/hll/sql/cumulative_add_sparse_random.sql new file mode 100644 index 00000000000..198560f1208 --- /dev/null +++ b/external/hll/sql/cumulative_add_sparse_random.sql @@ -0,0 +1,47 @@ +-- ================================================================ +-- Setup the table +-- + +SELECT hll_set_output_version(1); + +DROP TABLE IF EXISTS test_beelewuo; + +CREATE TABLE test_beelewuo ( + recno SERIAL, + cardinality double precision, + raw_value bigint, + union_compressed_multiset hll +); + +-- Copy the CSV data into the table +-- +\copy test_beelewuo (cardinality, raw_value, union_compressed_multiset) from sql/data/cumulative_add_sparse_random.csv with csv header + +SELECT COUNT(*) FROM test_beelewuo; + +-- Test incremental adding. +SELECT curr.recno, + curr.union_compressed_multiset, + hll_add(prev.union_compressed_multiset, hll_hashval(curr.raw_value)) + FROM test_beelewuo prev, test_beelewuo curr + WHERE curr.recno > 1 + AND curr.recno = prev.recno + 1 + AND curr.union_compressed_multiset != + hll_add(prev.union_compressed_multiset, hll_hashval(curr.raw_value)) + ORDER BY curr.recno; + +-- Test cardinality of incremental adds. +SELECT curr.recno, + curr.cardinality, + hll_cardinality(hll_add(prev.union_compressed_multiset, + hll_hashval(curr.raw_value))) + FROM test_beelewuo prev, test_beelewuo curr + WHERE curr.recno > 1 + AND curr.recno = prev.recno + 1 + AND curr.cardinality != + hll_cardinality(hll_add(prev.union_compressed_multiset, + hll_hashval(curr.raw_value))) + ORDER BY curr.recno; + +DROP TABLE test_beelewuo; + diff --git a/external/hll/sql/cumulative_add_sparse_step.sql b/external/hll/sql/cumulative_add_sparse_step.sql new file mode 100644 index 00000000000..edde1c0a2b8 --- /dev/null +++ b/external/hll/sql/cumulative_add_sparse_step.sql @@ -0,0 +1,47 @@ +-- ================================================================ +-- Setup the table +-- + +SELECT hll_set_output_version(1); + +DROP TABLE IF EXISTS test_lunfjncl; + +CREATE TABLE test_lunfjncl ( + recno SERIAL, + cardinality double precision, + raw_value bigint, + union_compressed_multiset hll +); + +-- Copy the CSV data into the table +-- +\copy test_lunfjncl (cardinality, raw_value, union_compressed_multiset) from sql/data/cumulative_add_sparse_step.csv with csv header + +SELECT COUNT(*) FROM test_lunfjncl; + +-- Test incremental adding. +SELECT curr.recno, + curr.union_compressed_multiset, + hll_add(prev.union_compressed_multiset, hll_hashval(curr.raw_value)) + FROM test_lunfjncl prev, test_lunfjncl curr + WHERE curr.recno > 1 + AND curr.recno = prev.recno + 1 + AND curr.union_compressed_multiset != + hll_add(prev.union_compressed_multiset, hll_hashval(curr.raw_value)) + ORDER BY curr.recno; + +-- Test cardinality of incremental adds. +SELECT curr.recno, + curr.cardinality, + hll_cardinality(hll_add(prev.union_compressed_multiset, + hll_hashval(curr.raw_value))) + FROM test_lunfjncl prev, test_lunfjncl curr + WHERE curr.recno > 1 + AND curr.recno = prev.recno + 1 + AND curr.cardinality != + hll_cardinality(hll_add(prev.union_compressed_multiset, + hll_hashval(curr.raw_value))) + ORDER BY curr.recno; + +DROP TABLE test_lunfjncl; + diff --git a/external/hll/sql/cumulative_union_comprehensive.sql b/external/hll/sql/cumulative_union_comprehensive.sql new file mode 100644 index 00000000000..964ead1bfb1 --- /dev/null +++ b/external/hll/sql/cumulative_union_comprehensive.sql @@ -0,0 +1,95 @@ +-- Setup the table +-- + +SELECT hll_set_output_version(1); + +DROP TABLE IF EXISTS test_rhswkjtc; + +CREATE TABLE test_rhswkjtc ( + recno SERIAL, + cardinality double precision, + compressed_multiset hll, + union_cardinality double precision, + union_compressed_multiset hll +); + +-- Copy the CSV data into the table +-- +\copy test_rhswkjtc (cardinality,compressed_multiset,union_cardinality,union_compressed_multiset) from sql/data/cumulative_union_comprehensive.csv with csv header + +SELECT COUNT(*) FROM test_rhswkjtc; + +-- Cardinality of incremental multisets +-- +SELECT recno, + cardinality, + hll_cardinality(compressed_multiset) + FROM test_rhswkjtc + WHERE cardinality != hll_cardinality(compressed_multiset); + +-- Cardinality of unioned multisets +-- +SELECT recno, + union_cardinality, + hll_cardinality(union_compressed_multiset) + FROM test_rhswkjtc + WHERE union_cardinality != hll_cardinality(union_compressed_multiset); + +-- Test union of incremental multiset. +-- +SELECT curr.recno, + curr.union_compressed_multiset, + hll_union(curr.compressed_multiset, prev.union_compressed_multiset) + FROM test_rhswkjtc prev, test_rhswkjtc curr + WHERE curr.recno > 1 + AND curr.recno = prev.recno + 1 + AND curr.union_compressed_multiset != + hll_union(curr.compressed_multiset, prev.union_compressed_multiset); + +-- Test cardinality of union of incremental multiset. +-- +SELECT curr.recno, + curr.union_cardinality, + hll_cardinality(hll_union(curr.compressed_multiset, + prev.union_compressed_multiset)) + FROM test_rhswkjtc prev, test_rhswkjtc curr + WHERE curr.recno > 1 + AND curr.recno = prev.recno + 1 + AND curr.union_cardinality != + hll_cardinality(hll_union(curr.compressed_multiset, + prev.union_compressed_multiset)); + +-- Test aggregate accumulation +-- +SELECT v1.recno, + v1.union_compressed_multiset, + (select hll_union_agg(compressed_multiset) + from test_rhswkjtc + where recno <= v1.recno) as hll_union_agg + FROM test_rhswkjtc v1 + WHERE v1.union_compressed_multiset != + (select hll_union_agg(compressed_multiset) + from test_rhswkjtc + where recno <= v1.recno); + +-- Test aggregate accumulation with cardinality +-- +SELECT v1.recno, + ceil(v1.union_cardinality), + (select ceiling(hll_cardinality(hll_union_agg(compressed_multiset))) + from test_rhswkjtc + where recno <= v1.recno) as ceiling + FROM test_rhswkjtc v1 + WHERE ceil(v1.union_cardinality) != + (select ceiling(hll_cardinality(hll_union_agg(compressed_multiset))) + from test_rhswkjtc + where recno <= v1.recno); + +-- Window function which calls final functions more then once. +SELECT + recno, + hll_union_agg(test_rhswkjtc.compressed_multiset) OVER prev30 +FROM test_rhswkjtc +window prev30 as (order by recno asc rows 29 preceding); + +DROP TABLE test_rhswkjtc; diff --git a/external/hll/sql/cumulative_union_explicit_explicit.sql b/external/hll/sql/cumulative_union_explicit_explicit.sql new file mode 100644 index 00000000000..27eae6a4ec0 --- /dev/null +++ b/external/hll/sql/cumulative_union_explicit_explicit.sql @@ -0,0 +1,89 @@ +-- Setup the table +-- + +SELECT hll_set_output_version(1); + +DROP TABLE IF EXISTS test_swlnhisq; + +CREATE TABLE test_swlnhisq ( + recno SERIAL, + cardinality double precision, + compressed_multiset hll, + union_cardinality double precision, + union_compressed_multiset hll +); + +-- Copy the CSV data into the table +-- +\copy test_swlnhisq (cardinality,compressed_multiset,union_cardinality,union_compressed_multiset) from sql/data/cumulative_union_explicit_explicit.csv with csv header + +SELECT COUNT(*) FROM test_swlnhisq; + +-- Cardinality of incremental multisets +-- +SELECT recno, + cardinality, + hll_cardinality(compressed_multiset) + FROM test_swlnhisq + WHERE cardinality != hll_cardinality(compressed_multiset); + +-- Cardinality of unioned multisets +-- +SELECT recno, + union_cardinality, + hll_cardinality(union_compressed_multiset) + FROM test_swlnhisq + WHERE union_cardinality != hll_cardinality(union_compressed_multiset); + +-- Test union of incremental multiset. +-- +SELECT curr.recno, + curr.union_compressed_multiset, + hll_union(curr.compressed_multiset, prev.union_compressed_multiset) + FROM test_swlnhisq prev, test_swlnhisq curr + WHERE curr.recno > 1 + AND curr.recno = prev.recno + 1 + AND curr.union_compressed_multiset != + hll_union(curr.compressed_multiset, prev.union_compressed_multiset); + +-- Test cardinality of union of incremental multiset. +-- +SELECT curr.recno, + curr.union_cardinality, + hll_cardinality(hll_union(curr.compressed_multiset, + prev.union_compressed_multiset)) + FROM test_swlnhisq prev, test_swlnhisq curr + WHERE curr.recno > 1 + AND curr.recno = prev.recno + 1 + AND curr.union_cardinality != + hll_cardinality(hll_union(curr.compressed_multiset, + prev.union_compressed_multiset)); + +-- Test aggregate accumulation +-- +SELECT v1.recno, + v1.union_compressed_multiset, + (select hll_union_agg(compressed_multiset) + from test_swlnhisq + where recno <= v1.recno) as hll_union_agg + FROM test_swlnhisq v1 + WHERE v1.union_compressed_multiset != + (select hll_union_agg(compressed_multiset) + from test_swlnhisq + where recno <= v1.recno); + +-- Test aggregate accumulation with cardinality +-- +SELECT v1.recno, + ceil(v1.union_cardinality), + (select ceiling(hll_cardinality(hll_union_agg(compressed_multiset))) + from test_swlnhisq + where recno <= v1.recno) as ceiling + FROM test_swlnhisq v1 + WHERE ceil(v1.union_cardinality) != + (select ceiling(hll_cardinality(hll_union_agg(compressed_multiset))) + from test_swlnhisq + where recno <= v1.recno); + +DROP TABLE test_swlnhisq; + diff --git a/external/hll/sql/cumulative_union_explicit_promotion.sql b/external/hll/sql/cumulative_union_explicit_promotion.sql new file mode 100644 index 00000000000..f5713ebb377 --- /dev/null +++ b/external/hll/sql/cumulative_union_explicit_promotion.sql @@ -0,0 +1,98 @@ +-- Setup the table +-- + +SELECT hll_set_output_version(1); + +-- This test relies on a non-standard fixed sparse-to-compressed +-- threshold value. +-- +SELECT hll_set_max_sparse(512); + +DROP TABLE IF EXISTS test_wsdiietv; + +CREATE TABLE test_wsdiietv ( + recno SERIAL, + cardinality double precision, + compressed_multiset hll, + union_cardinality double precision, + union_compressed_multiset hll +); + +-- Copy the CSV data into the table +-- +\copy test_wsdiietv (cardinality,compressed_multiset,union_cardinality,union_compressed_multiset) from sql/data/cumulative_union_explicit_promotion.csv with csv header + +SELECT COUNT(*) FROM test_wsdiietv; + +-- Cardinality of incremental multisets +-- +SELECT recno, + cardinality, + hll_cardinality(compressed_multiset) + FROM test_wsdiietv + WHERE cardinality != hll_cardinality(compressed_multiset); + +-- Cardinality of unioned multisets +-- +SELECT recno, + union_cardinality, + hll_cardinality(union_compressed_multiset) + FROM test_wsdiietv + WHERE union_cardinality != hll_cardinality(union_compressed_multiset); + +-- Test union of incremental multiset. +-- +SELECT curr.recno, + curr.union_compressed_multiset, + hll_union(curr.compressed_multiset, prev.union_compressed_multiset) + FROM test_wsdiietv prev, test_wsdiietv curr + WHERE curr.recno > 1 + AND curr.recno = prev.recno + 1 + AND curr.union_compressed_multiset != + hll_union(curr.compressed_multiset, prev.union_compressed_multiset) + ORDER BY curr.recno; + +-- Test cardinality of union of incremental multiset. +-- +SELECT curr.recno, + curr.union_cardinality, + hll_cardinality(hll_union(curr.compressed_multiset, + prev.union_compressed_multiset)) + FROM test_wsdiietv prev, test_wsdiietv curr + WHERE curr.recno > 1 + AND curr.recno = prev.recno + 1 + AND curr.union_cardinality != + hll_cardinality(hll_union(curr.compressed_multiset, + prev.union_compressed_multiset)) + ORDER BY curr.recno; + +-- Test aggregate accumulation +-- +SELECT v1.recno, + v1.union_compressed_multiset, + (select hll_union_agg(compressed_multiset) + from test_wsdiietv + where recno <= v1.recno) as hll_union_agg + FROM test_wsdiietv v1 + WHERE v1.union_compressed_multiset != + (select hll_union_agg(compressed_multiset) + from test_wsdiietv + where recno <= v1.recno) + ORDER BY v1.recno; + +-- Test aggregate accumulation with cardinality +-- +SELECT v1.recno, + ceil(v1.union_cardinality), + (select ceiling(hll_cardinality(hll_union_agg(compressed_multiset))) + from test_wsdiietv + where recno <= v1.recno) as ceiling + FROM test_wsdiietv v1 + WHERE ceil(v1.union_cardinality) != + (select ceiling(hll_cardinality(hll_union_agg(compressed_multiset))) + from test_wsdiietv + where recno <= v1.recno) + ORDER BY v1.recno; + +DROP TABLE test_wsdiietv; + diff --git a/external/hll/sql/cumulative_union_probabilistic_probabilistic.sql b/external/hll/sql/cumulative_union_probabilistic_probabilistic.sql new file mode 100644 index 00000000000..5684b3159aa --- /dev/null +++ b/external/hll/sql/cumulative_union_probabilistic_probabilistic.sql @@ -0,0 +1,96 @@ +-- Setup the table +-- + +set extra_float_digits=0; +SELECT hll_set_output_version(1); + +DROP TABLE IF EXISTS test_mpuahgwy; + +CREATE TABLE test_mpuahgwy ( + recno SERIAL, + cardinality double precision, + compressed_multiset hll, + union_cardinality double precision, + union_compressed_multiset hll +); + +-- Copy the CSV data into the table +-- +\copy test_mpuahgwy (cardinality,compressed_multiset,union_cardinality,union_compressed_multiset) from sql/data/cumulative_union_probabilistic_probabilistic.csv with csv header + +SELECT COUNT(*) FROM test_mpuahgwy; + +-- Cardinality of incremental multisets +-- +SELECT recno, + cardinality, + hll_cardinality(compressed_multiset) + FROM test_mpuahgwy + WHERE cardinality != hll_cardinality(compressed_multiset) + ORDER BY recno; + +-- Cardinality of unioned multisets +-- +SELECT recno, + union_cardinality, + hll_cardinality(union_compressed_multiset) + FROM test_mpuahgwy + WHERE union_cardinality != hll_cardinality(union_compressed_multiset) + ORDER BY recno; + +-- Test union of incremental multiset. +-- +SELECT curr.recno, + curr.union_compressed_multiset, + hll_union(curr.compressed_multiset, prev.union_compressed_multiset) + FROM test_mpuahgwy prev, test_mpuahgwy curr + WHERE curr.recno > 1 + AND curr.recno = prev.recno + 1 + AND curr.union_compressed_multiset != + hll_union(curr.compressed_multiset, prev.union_compressed_multiset) + ORDER BY curr.recno; + +-- Test cardinality of union of incremental multiset. +-- +SELECT curr.recno, + curr.union_cardinality, + hll_cardinality(hll_union(curr.compressed_multiset, + prev.union_compressed_multiset)) + FROM test_mpuahgwy prev, test_mpuahgwy curr + WHERE curr.recno > 1 + AND curr.recno = prev.recno + 1 + AND curr.union_cardinality != + hll_cardinality(hll_union(curr.compressed_multiset, + prev.union_compressed_multiset)) + ORDER BY curr.recno; + +-- Test aggregate accumulation +-- +SELECT v1.recno, + v1.union_compressed_multiset, + (select hll_union_agg(compressed_multiset) + from test_mpuahgwy + where recno <= v1.recno) as hll_union_agg + FROM test_mpuahgwy v1 + WHERE v1.union_compressed_multiset != + (select hll_union_agg(compressed_multiset) + from test_mpuahgwy + where recno <= v1.recno) + ORDER BY v1.recno; + +-- Test aggregate accumulation with cardinality +-- +SELECT v1.recno, + ceil(v1.union_cardinality), + (select ceiling(hll_cardinality(hll_union_agg(compressed_multiset))) + from test_mpuahgwy + where recno <= v1.recno) as ceiling + FROM test_mpuahgwy v1 + WHERE ceil(v1.union_cardinality) != + (select ceiling(hll_cardinality(hll_union_agg(compressed_multiset))) + from test_mpuahgwy + where recno <= v1.recno) + ORDER BY v1.recno; + +DROP TABLE test_mpuahgwy; + diff --git a/external/hll/sql/cumulative_union_sparse_full_representation.sql b/external/hll/sql/cumulative_union_sparse_full_representation.sql new file mode 100644 index 00000000000..729fe3ca26e --- /dev/null +++ b/external/hll/sql/cumulative_union_sparse_full_representation.sql @@ -0,0 +1,93 @@ +-- Setup the table +-- + +SELECT hll_set_output_version(1); + +-- This test relies on a non-standard fixed sparse-to-compressed +-- threshold value. +-- +SELECT hll_set_max_sparse(512); + +DROP TABLE IF EXISTS test_tagumlbl; + +CREATE TABLE test_tagumlbl ( + recno SERIAL, + cardinality double precision, + compressed_multiset hll, + union_cardinality double precision, + union_compressed_multiset hll +); + +-- Copy the CSV data into the table +-- +\copy test_tagumlbl (cardinality,compressed_multiset,union_cardinality,union_compressed_multiset) from sql/data/cumulative_union_sparse_full_representation.csv with csv header + +SELECT COUNT(*) FROM test_tagumlbl; + +-- Cardinality of incremental multisets +-- +SELECT recno, + cardinality, + hll_cardinality(compressed_multiset) + FROM test_tagumlbl + WHERE cardinality != hll_cardinality(compressed_multiset); + +-- Cardinality of unioned multisets +-- +SELECT recno, + union_cardinality, + hll_cardinality(union_compressed_multiset) + FROM test_tagumlbl + WHERE union_cardinality != hll_cardinality(union_compressed_multiset); + +-- Test union of incremental multiset. +-- +SELECT curr.recno, + curr.union_compressed_multiset, + hll_union(curr.compressed_multiset, prev.union_compressed_multiset) + FROM test_tagumlbl prev, test_tagumlbl curr + WHERE curr.recno > 1 + AND curr.recno = prev.recno + 1 + AND curr.union_compressed_multiset != + hll_union(curr.compressed_multiset, prev.union_compressed_multiset); + +-- Test cardinality of union of incremental multiset. +-- +SELECT curr.recno, + curr.union_cardinality, + hll_cardinality(hll_union(curr.compressed_multiset, + prev.union_compressed_multiset)) + FROM test_tagumlbl prev, test_tagumlbl curr + WHERE curr.recno > 1 + AND curr.recno = prev.recno + 1 + AND curr.union_cardinality != + hll_cardinality(hll_union(curr.compressed_multiset, + prev.union_compressed_multiset)); + +-- Test aggregate accumulation +-- +SELECT v1.recno, + v1.union_compressed_multiset, + (select hll_union_agg(compressed_multiset) + from test_tagumlbl + where recno <= v1.recno) as hll_union_agg + FROM test_tagumlbl v1 + WHERE v1.union_compressed_multiset != + (select hll_union_agg(compressed_multiset) + from test_tagumlbl + where recno <= v1.recno); + +-- Test aggregate accumulation with cardinality +-- +SELECT v1.recno, + ceil(v1.union_cardinality), + (select ceiling(hll_cardinality(hll_union_agg(compressed_multiset))) + from test_tagumlbl + where recno <= v1.recno) as ceiling + FROM test_tagumlbl v1 + WHERE ceil(v1.union_cardinality) != + (select ceiling(hll_cardinality(hll_union_agg(compressed_multiset))) + from test_tagumlbl + where recno <= v1.recno); + +DROP TABLE test_tagumlbl; diff --git a/external/hll/sql/cumulative_union_sparse_promotion.sql b/external/hll/sql/cumulative_union_sparse_promotion.sql new file mode 100644 index 00000000000..d9dc14601d8 --- /dev/null +++ b/external/hll/sql/cumulative_union_sparse_promotion.sql @@ -0,0 +1,101 @@ +-- Setup the table +-- + +SELECT hll_set_output_version(1); + +-- This test relies on a non-standard fixed sparse-to-compressed +-- threshold value. +-- +SELECT hll_set_max_sparse(512); + +DROP TABLE IF EXISTS test_bsnvqefe; + +CREATE TABLE test_bsnvqefe ( + recno SERIAL, + cardinality double precision, + compressed_multiset hll, + union_cardinality double precision, + union_compressed_multiset hll +); + +-- Copy the CSV data into the table +-- +\copy test_bsnvqefe (cardinality,compressed_multiset,union_cardinality,union_compressed_multiset) from sql/data/cumulative_union_sparse_promotion.csv with csv header + +SELECT COUNT(*) FROM test_bsnvqefe; + +-- Cardinality of incremental multisets +-- +SELECT recno, + cardinality, + hll_cardinality(compressed_multiset) + FROM test_bsnvqefe + WHERE cardinality != hll_cardinality(compressed_multiset) + ORDER BY recno; + +-- Cardinality of unioned multisets +-- +SELECT recno, + union_cardinality, + hll_cardinality(union_compressed_multiset) + FROM test_bsnvqefe + WHERE round(union_cardinality::numeric, 10) != + round(hll_cardinality(union_compressed_multiset)::numeric, 10) + ORDER BY recno; + +-- Test union of incremental multiset. +-- +SELECT curr.recno, + curr.union_compressed_multiset, + hll_union(curr.compressed_multiset, prev.union_compressed_multiset) + FROM test_bsnvqefe prev, test_bsnvqefe curr + WHERE curr.recno > 1 + AND curr.recno = prev.recno + 1 + AND curr.union_compressed_multiset != + hll_union(curr.compressed_multiset, prev.union_compressed_multiset) + ORDER BY curr.recno; + +-- Test cardinality of union of incremental multiset. +-- +SELECT curr.recno, + curr.union_cardinality, + hll_cardinality(hll_union(curr.compressed_multiset, + prev.union_compressed_multiset)) + FROM test_bsnvqefe prev, test_bsnvqefe curr + WHERE curr.recno > 1 + AND curr.recno = prev.recno + 1 + AND round(curr.union_cardinality::numeric, 10) != + round(hll_cardinality(hll_union(curr.compressed_multiset, + prev.union_compressed_multiset))::numeric, + 10) + ORDER BY curr.recno; + +-- Test aggregate accumulation +-- +SELECT v1.recno, + v1.union_compressed_multiset, + (select hll_union_agg(compressed_multiset) + from test_bsnvqefe + where recno <= v1.recno) as hll_union_agg + FROM test_bsnvqefe v1 + WHERE v1.union_compressed_multiset != + (select hll_union_agg(compressed_multiset) + from test_bsnvqefe + where recno <= v1.recno) + ORDER BY v1.recno; + +-- Test aggregate accumulation with cardinality +-- +SELECT v1.recno, + ceil(v1.union_cardinality), + (select ceiling(hll_cardinality(hll_union_agg(compressed_multiset))) + from test_bsnvqefe + where recno <= v1.recno) as ceiling + FROM test_bsnvqefe v1 + WHERE ceil(v1.union_cardinality) != + (select ceiling(hll_cardinality(hll_union_agg(compressed_multiset))) + from test_bsnvqefe + where recno <= v1.recno) + ORDER BY v1.recno; + +DROP TABLE test_bsnvqefe; diff --git a/external/hll/sql/cumulative_union_sparse_sparse.sql b/external/hll/sql/cumulative_union_sparse_sparse.sql new file mode 100644 index 00000000000..5c8e49c3448 --- /dev/null +++ b/external/hll/sql/cumulative_union_sparse_sparse.sql @@ -0,0 +1,88 @@ +-- Setup the table +-- + +SELECT hll_set_output_version(1); + +DROP TABLE IF EXISTS test_bmbffonl; + +CREATE TABLE test_bmbffonl ( + recno SERIAL, + cardinality double precision, + compressed_multiset hll, + union_cardinality double precision, + union_compressed_multiset hll +); + +-- Copy the CSV data into the table +-- +\copy test_bmbffonl (cardinality,compressed_multiset,union_cardinality,union_compressed_multiset) from sql/data/cumulative_union_sparse_sparse.csv with csv header + +SELECT COUNT(*) FROM test_bmbffonl; + +-- Cardinality of incremental multisets +-- +SELECT recno, + cardinality, + hll_cardinality(compressed_multiset) + FROM test_bmbffonl + WHERE cardinality != hll_cardinality(compressed_multiset); + +-- Cardinality of unioned multisets +-- +SELECT recno, + union_cardinality, + hll_cardinality(union_compressed_multiset) + FROM test_bmbffonl + WHERE union_cardinality != hll_cardinality(union_compressed_multiset); + +-- Test union of incremental multiset. +-- +SELECT curr.recno, + curr.union_compressed_multiset, + hll_union(curr.compressed_multiset, prev.union_compressed_multiset) + FROM test_bmbffonl prev, test_bmbffonl curr + WHERE curr.recno > 1 + AND curr.recno = prev.recno + 1 + AND curr.union_compressed_multiset != + hll_union(curr.compressed_multiset, prev.union_compressed_multiset); + +-- Test cardinality of union of incremental multiset. +-- +SELECT curr.recno, + curr.union_cardinality, + hll_cardinality(hll_union(curr.compressed_multiset, + prev.union_compressed_multiset)) + FROM test_bmbffonl prev, test_bmbffonl curr + WHERE curr.recno > 1 + AND curr.recno = prev.recno + 1 + AND curr.union_cardinality != + hll_cardinality(hll_union(curr.compressed_multiset, + prev.union_compressed_multiset)); + +-- Test aggregate accumulation +-- +SELECT v1.recno, + v1.union_compressed_multiset, + (select hll_union_agg(compressed_multiset) + from test_bmbffonl + where recno <= v1.recno) as hll_union_agg + FROM test_bmbffonl v1 + WHERE v1.union_compressed_multiset != + (select hll_union_agg(compressed_multiset) + from test_bmbffonl + where recno <= v1.recno); + +-- Test aggregate accumulation with cardinality +-- +SELECT v1.recno, + ceil(v1.union_cardinality), + (select ceiling(hll_cardinality(hll_union_agg(compressed_multiset))) + from test_bmbffonl + where recno <= v1.recno) as ceiling + FROM test_bmbffonl v1 + WHERE ceil(v1.union_cardinality) != + (select ceiling(hll_cardinality(hll_union_agg(compressed_multiset))) + from test_bmbffonl + where recno <= v1.recno); + +DROP TABLE test_bmbffonl; diff --git a/external/hll/sql/disable_hashagg.sql b/external/hll/sql/disable_hashagg.sql new file mode 100644 index 00000000000..0e90210fcba --- /dev/null +++ b/external/hll/sql/disable_hashagg.sql @@ -0,0 +1,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; diff --git a/external/hll/sql/equal.sql b/external/hll/sql/equal.sql new file mode 100644 index 00000000000..ae6f88d65c6 --- /dev/null +++ b/external/hll/sql/equal.sql @@ -0,0 +1,67 @@ +-- ---------------------------------------------------------------- +-- Regression tests for equality operator with v1 output. +-- ---------------------------------------------------------------- + +SELECT hll_set_output_version(1); + +-- Undefined sets: t +SELECT E'\\x108b7f'::hll = E'\\x108b7f'::hll; + +-- Undefined, different metadata: f +SELECT E'\\x108b7f'::hll = E'\\x108b49'::hll; + +-- Equal empty sets: t +SELECT hll_empty(11,5,256,1) = hll_empty(11,5,256,1); + +-- Different metadata: f +SELECT hll_empty(11,5,256,1) = hll_empty(11,5,256,0); + +-- Different metadata: f +SELECT hll_empty(11,5,256,1) = hll_empty(11,5,128,1); + +-- Different metadata: f +SELECT hll_empty(11,5,256,1) = hll_empty(11,4,256,1); + +-- Different metadata: f +SELECT hll_empty(11,5,256,1) = hll_empty(10,5,256,1); + +-- Same explicit: t +SELECT E'\\x128b7f8895a3f5af28cafe'::hll = E'\\x128b7f8895a3f5af28cafe'::hll; + +-- Different explicit: f +SELECT E'\\x128b7f8895a3f5af28cafe'::hll = E'\\x128b7fda0ce907e4355b60'::hll; + +-- Different explicit lengths: f +SELECT E'\\x128b7f8895a3f5af28cafe'::hll = E'\\x128b7f8895a3f5af28cafeda0ce907e4355b60'::hll; + +-- Same sparse: t +SELECT E'\\x138b7f0001'::hll = E'\\x138b7f0001'::hll; + +-- Different sparse: f +SELECT E'\\x138b7f0001'::hll = E'\\x138b7f0022'::hll; + +-- Different sparse lengths: f +SELECT E'\\x138b7f0001'::hll = E'\\x138b7f00410061'::hll; + +-- Same compressed: t +SELECT hll_add(hll_empty(11,5,0,0), hll_hash_integer(1,0)) = +E'\\x148b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'::hll; + +-- Different compressed: f +SELECT hll_add(hll_empty(11,5,0,0), hll_hash_integer(2,0)) = +E'\\x148b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'::hll; + +-- Different types: f +SELECT E'\\x108b7f'::hll = hll_empty(11,5,256,1); +SELECT E'\\x108b7f'::hll = E'\\x128b7f8895a3f5af28cafe'::hll; +SELECT E'\\x108b7f'::hll = E'\\x138b7f0041'::hll; +SELECT E'\\x108b7f'::hll = hll_add(hll_empty(11,5,0,0), hll_hash_integer(1,0)); +SELECT hll_empty(11,5,256,1) = E'\\x128b408895a3f5af28cafe'::hll; +SELECT hll_empty(11,5,256,1) = E'\\x138b7f0001'::hll; +SELECT hll_empty(11,5,256,1) = + hll_add(hll_empty(11,5,0,0), hll_hash_integer(1,0)); +SELECT E'\\x128b7f8895a3f5af28cafe'::hll = E'\\x138b7f0022'::hll; +SELECT E'\\x128b7f8895a3f5af28cafe'::hll = + hll_add(hll_empty(11,5,0,0), hll_hash_integer(1,0)); +SELECT E'\\x138c40afe180'::hll = + hll_add(hll_empty(11,5,0,0), hll_hash_integer(1,0)); diff --git a/external/hll/sql/explicit_thresh.sql b/external/hll/sql/explicit_thresh.sql new file mode 100644 index 00000000000..3403994d6fe --- /dev/null +++ b/external/hll/sql/explicit_thresh.sql @@ -0,0 +1,167 @@ +-- ---------------------------------------------------------------- +-- Regression tests for explicit threshold control. +-- ---------------------------------------------------------------- + +SELECT hll_set_output_version(1); + +-- Should become explicit. +SELECT hll_add(E'\\x118c49'::hll, hll_hash_integer(1,0)); + +-- Also explicit. +SELECT hll_add(hll_empty(12,5,256,1), hll_hash_integer(1,0)); + +-- ---------------- + +-- Should go straight to sparse. +SELECT hll_add(hll_empty(12,5,0,1), + hll_hash_integer(1,0)); + +-- Should stay sparse. +SELECT hll_add( + hll_add(hll_empty(12,5,0,1), + hll_hash_integer(1,0)), + hll_hash_integer(2,0)); + +-- ---------------- + +-- Should stay explicit for one add. +SELECT hll_add(hll_empty(12,5,1,1), + hll_hash_integer(1,0)); + +-- But not on the second add. +SELECT hll_add( + hll_add(hll_empty(12,5,1,1), + hll_hash_integer(1,0)), + hll_hash_integer(2,0)); + +-- Nor the third. +SELECT hll_add( + hll_add( + hll_add(hll_empty(12,5,1,1), + hll_hash_integer(1,0)), + hll_hash_integer(2,0)), + hll_hash_integer(3,0)); + +-- ---------------- + +-- Should stay explicit for two adds. +SELECT hll_add(hll_empty(12,5,2,1), + hll_hash_integer(1,0)); + +SELECT hll_add( + hll_add(hll_empty(12,5,2,1), + hll_hash_integer(1,0)), + hll_hash_integer(2,0)); + +-- Not explicit anymore. +SELECT hll_add( + hll_add( + hll_add(hll_empty(12,5,2,1), + hll_hash_integer(1,0)), + hll_hash_integer(2,0)), + hll_hash_integer(3,0)); + +-- ---------------- + +-- Should stay explicit for four adds. +SELECT hll_add(hll_empty(12,5,4,1), + hll_hash_integer(1,0)); + +SELECT hll_add( + hll_add(hll_empty(12,5,4,1), + hll_hash_integer(1,0)), + hll_hash_integer(2,0)); + +SELECT hll_add( + hll_add( + hll_add(hll_empty(12,5,4,1), + hll_hash_integer(1,0)), + hll_hash_integer(2,0)), + hll_hash_integer(3,0)); + +SELECT hll_add( + hll_add( + hll_add( + hll_add(hll_empty(12,5,4,1), + hll_hash_integer(1,0)), + hll_hash_integer(2,0)), + hll_hash_integer(3,0)), + hll_hash_integer(4,0)); + +-- Not anymore. +SELECT hll_add( + hll_add( + hll_add( + hll_add( + hll_add(hll_empty(12,5,4,1), + hll_hash_integer(1,0)), + hll_hash_integer(2,0)), + hll_hash_integer(3,0)), + hll_hash_integer(4,0)), + hll_hash_integer(5,0)); + +-- ---------------------------------------------------------------- + +-- Should stay explicit. +SELECT E'\\x128C09810F076F2EFC7D5781A8E923DD4D727381F60023440AC8F3826E20FD0E1C755783418A43C9E2536983D2657BAECEC77085B2C833BF06C38B85EC2FB805FEB9C08A577647206737E98B67F1909C4FBA238C8826ECCD18A1328CB8A65A27F9A2E58E332D3E1C1E8B018E53D45009306837913A1E408B1D83BE927DA34AE676FD6893BCD79BF47657EB957033B0E2A1F9EF96191BCB8D84D1D4967B18FF84CF372697034327A4CA49DE97688D9A869A43E097A62AAE1CE1D2D59839BEC0D573CC36993FFAAC3DD9DCAE9A1713EF73725EDB9A9EACDD27AC70F69B2F47DFF8D609AE9B7A4FEC37666D559BF0AB70FDA186F89DF0868CB5304B979DFD45C697433E799F94C56130B117AFA161FD0F8E175DABA16236AF4726E653A195A90A5F74A02AA3330817521EEDFBA3507CEC7C8EFFEEA4DDFD7A022356FAA708B69996145FD2A7B975333A92C45DA7F504C22BBD8883A8AD40BD99DD3136A8EEBA810AD4107CA97A88A733A3635EAAC55193F00B6ABEAB770C1E27FE3A96AD16681AD304ED0FAE103F67A4732B8FAE78848FA95BB4F0AFB9EA12A8A60235B0F42EFD18F185B4B10788ABF2A627C5B1E81C4F73418369B2347427BE5DBA99B2F219105C2C8EF9B4F4AAD6DAA3018BB500D980CEE8DEBEB52629581B1E9F38B54991A7EE2ADA3DB5E83A5EF27FA458B676ED1B4AD57B1BB72FC20093D243C3B7A270C97E9F60B1B81558085FA73AF4B92EE2526D66F7A9B947C25F6AA0B1C3BAD5BD98CA753A7CBB1AD57319B89CD8BE4D78B4EA777902BE67281D8C16DFB3BE75C448B47B885BBE8724958A2DD547C1307F3E3DC82B19C31B272386EBD3D5C38570F6A6B16AAFC389BD7042E65615C541D6E99556AD8DC64C7451D5E4A410C6E8E17A0B8565C1C72586EF2CA395AFC727BFDF07262E4FC806DD068E0D83DFC95F393EE574D488CA08660086D78399CDB9F2FDBD2C68A3CE23684A013E0402CE9C8E990D340AD0CF54F0AA63651486D0D651B83055D98FD1D6B47BFAE04129D2F0690082673069D466A4F678408E51D618BCBB1713D866D9820F495DE4B9B2DB6CAD89234C26B9DCC981DD4C9389A1E05E8BB7D36479F5E15F18764DE26865E16EEA095E95B9D6E301AEBCD7FB18E9E3D10F4B6322D8EBE6E47D0415918BC6E843946AFF559A84E8DA7FF35746346DEB978C5E6478F1EFEDCBFA7EE0C17F12EDD9AB37B9A86FDBEFE49DA97CB1C23BF022C44555C715F6F09B04B38DD7AEE4F22C88BD8D437311F27B5DB0E9340CFCF57471D55DBD1460F660CDAB03F03B06F6B55BBA28DA1B7EF75C6B35F73E591BF7BED9D4B5F30868F816C1F65ECBE466F94D2F8F21555B84FBACA654EDD11944FBFC9419F653B5F3FCB2B9C023BDBB04FF1C2921C7C365D1FFBD34EDA309EBA8FFCA7C3CF7CD7EFA0149546ADA2D4A210190E5722719B812023E1F61A788768802BC36ABAEFB97D8060A8F1F743E41B70643CE33D5392E620732E58C48B4D31207960AD1274EEC3C07A0D2BAFBC4365507B297476AEA276C0823D06F731E8CEC0849965B6A8A6D0B09CFCA9645744B6F0ACC38CA90A4D6950B30199E6FBA2E590D64E5396A4AC48C0D978892127108BD0FD8CBD2A1668FF10FFF3E568ECFA66110BDDBC4CC046AEB12B1D54A424D4E8612F4CE0A47E70565130958F67D24CBFF15B0439A464B33C71849E2AEE12079F019893C0C103E358E1C3AE416CC2D17901C490FFF8BDF2A0D1DA44FA4DBE9B4E31DB004FA8A0CEBCC1EADC56CFDEBFC791FA8EADDA7813B5D21328CC6AD76D9B12156396BA820C494219447B20A81CDAB23C77CB6E11760A5245B99B846685CFB273B251498B9637A27D40052777179E828209046C2FD1CE6285A7ADF6C9BDC52293A22A87C7B822429C1271B6FFAEEE02AE7D5475682E8792C32B6A13E130F7E2CFACDAD91AF54BC2D5FC77A0AC38F852D9500937CCDC8C02DBCD0FAFAC582322F48F6FC00551A97325A3CBC4186C4B53462FEEF714A0E44347536F04629644834ECBFF843E13794352CCCFC0946B8F0353E0B46E91ADDFC35A150F45BE711D637B4C5D368130F6A397DAC5A505F4A38399B1127B3186EEF3A6716B6650B37A43AAAF949857A41BB3BB019028551C8493C067E67A65FE8523D36145A51288B1B3E05CF2AB6FF496C3ED4466534CE7F0E3F19AE90B58263303F9CF5B2E040E3CD40136A78605D79B84141BECDB31896FD43E73111AE07DA894433E27F945114A945737AA1DCFE7648471C7A3075A27BFF47AE2F865A746FF549C0F7D5C58DAD7D4AC6A258049BD6E64B4752645E76F39E4DA9780D75AF0A6B4DD1665B6856D4F84E75A7D7BECC1DF94EDF2D538BCC83F950B87C338B76F32F50BF8C06E0FE08FE50DFF83F87E1D33B510EC2A8DC498C4551D864D5E42B8A76529A72B2DBDE8F4B552CF1E4A8AB85DD55677ABC4A6D6CC05674E0EAC7181CFD58F6F13D28CA7A365956D8037CB505725958C47B349399765998A979DF2DDFB85A9429AB90400CD25D84AD4C134DE91E5E7F961E93A35FF45EA819B7306D3C885F377E4255EDABB25FE907945CE6C0A16034F743F87AA74260D1D9429FBCAA0860ED6DD80CC3E3CB6383C322196D1EC464FF526FD87CE3E765AD3780E9F97898668AEA231012C91268FB0E6F684DF9926C58FAFCA44F68D16D2B5F0F78EB98D66D7DC0B998C0780F6DC4CCC1230752666E98008FF328B47571765F290D2BB87E71C7E89C4494F41271D144CC0032659B71DE0513743DE1B971F76602BFC11BCF73754B1443CE1E1E74124CCF336150F8752BD6E456B21CC7769E177BE0E0B66F76BE1268218DAE37784EE11732089EF97A8A8099020BE0747B528BF8134C9D4F7B5B54D144123AEB7DCFBF351DDE1AE2'::hll(12,5,256,0); + +-- Should become sparse +SELECT hll_add(E'\\x128C49810F076F2EFC7D5781A8E923DD4D727381F60023440AC8F3826E20FD0E1C755783418A43C9E2536983D2657BAECEC77085B2C833BF06C38B85EC2FB805FEB9C08A577647206737E98B67F1909C4FBA238C8826ECCD18A1328CB8A65A27F9A2E58E332D3E1C1E8B018E53D45009306837913A1E408B1D83BE927DA34AE676FD6893BCD79BF47657EB957033B0E2A1F9EF96191BCB8D84D1D4967B18FF84CF372697034327A4CA49DE97688D9A869A43E097A62AAE1CE1D2D59839BEC0D573CC36993FFAAC3DD9DCAE9A1713EF73725EDB9A9EACDD27AC70F69B2F47DFF8D609AE9B7A4FEC37666D559BF0AB70FDA186F89DF0868CB5304B979DFD45C697433E799F94C56130B117AFA161FD0F8E175DABA16236AF4726E653A195A90A5F74A02AA3330817521EEDFBA3507CEC7C8EFFEEA4DDFD7A022356FAA708B69996145FD2A7B975333A92C45DA7F504C22BBD8883A8AD40BD99DD3136A8EEBA810AD4107CA97A88A733A3635EAAC55193F00B6ABEAB770C1E27FE3A96AD16681AD304ED0FAE103F67A4732B8FAE78848FA95BB4F0AFB9EA12A8A60235B0F42EFD18F185B4B10788ABF2A627C5B1E81C4F73418369B2347427BE5DBA99B2F219105C2C8EF9B4F4AAD6DAA3018BB500D980CEE8DEBEB52629581B1E9F38B54991A7EE2ADA3DB5E83A5EF27FA458B676ED1B4AD57B1BB72FC20093D243C3B7A270C97E9F60B1B81558085FA73AF4B92EE2526D66F7A9B947C25F6AA0B1C3BAD5BD98CA753A7CBB1AD57319B89CD8BE4D78B4EA777902BE67281D8C16DFB3BE75C448B47B885BBE8724958A2DD547C1307F3E3DC82B19C31B272386EBD3D5C38570F6A6B16AAFC389BD7042E65615C541D6E99556AD8DC64C7451D5E4A410C6E8E17A0B8565C1C72586EF2CA395AFC727BFDF07262E4FC806DD068E0D83DFC95F393EE574D488CA08660086D78399CDB9F2FDBD2C68A3CE23684A013E0402CE9C8E990D340AD0CF54F0AA63651486D0D651B83055D98FD1D6B47BFAE04129D2F0690082673069D466A4F678408E51D618BCBB1713D866D9820F495DE4B9B2DB6CAD89234C26B9DCC981DD4C9389A1E05E8BB7D36479F5E15F18764DE26865E16EEA095E95B9D6E301AEBCD7FB18E9E3D10F4B6322D8EBE6E47D0415918BC6E843946AFF559A84E8DA7FF35746346DEB978C5E6478F1EFEDCBFA7EE0C17F12EDD9AB37B9A86FDBEFE49DA97CB1C23BF022C44555C715F6F09B04B38DD7AEE4F22C88BD8D437311F27B5DB0E9340CFCF57471D55DBD1460F660CDAB03F03B06F6B55BBA28DA1B7EF75C6B35F73E591BF7BED9D4B5F30868F816C1F65ECBE466F94D2F8F21555B84FBACA654EDD11944FBFC9419F653B5F3FCB2B9C023BDBB04FF1C2921C7C365D1FFBD34EDA309EBA8FFCA7C3CF7CD7EFA0149546ADA2D4A210190E5722719B812023E1F61A788768802BC36ABAEFB97D8060A8F1F743E41B70643CE33D5392E620732E58C48B4D31207960AD1274EEC3C07A0D2BAFBC4365507B297476AEA276C0823D06F731E8CEC0849965B6A8A6D0B09CFCA9645744B6F0ACC38CA90A4D6950B30199E6FBA2E590D64E5396A4AC48C0D978892127108BD0FD8CBD2A1668FF10FFF3E568ECFA66110BDDBC4CC046AEB12B1D54A424D4E8612F4CE0A47E70565130958F67D24CBFF15B0439A464B33C71849E2AEE12079F019893C0C103E358E1C3AE416CC2D17901C490FFF8BDF2A0D1DA44FA4DBE9B4E31DB004FA8A0CEBCC1EADC56CFDEBFC791FA8EADDA7813B5D21328CC6AD76D9B12156396BA820C494219447B20A81CDAB23C77CB6E11760A5245B99B846685CFB273B251498B9637A27D40052777179E828209046C2FD1CE6285A7ADF6C9BDC52293A22A87C7B822429C1271B6FFAEEE02AE7D5475682E8792C32B6A13E130F7E2CFACDAD91AF54BC2D5FC77A0AC38F852D9500937CCDC8C02DBCD0FAFAC582322F48F6FC00551A97325A3CBC4186C4B53462FEEF714A0E44347536F04629644834ECBFF843E13794352CCCFC0946B8F0353E0B46E91ADDFC35A150F45BE711D637B4C5D368130F6A397DAC5A505F4A38399B1127B3186EEF3A6716B6650B37A43AAAF949857A41BB3BB019028551C8493C067E67A65FE8523D36145A51288B1B3E05CF2AB6FF496C3ED4466534CE7F0E3F19AE90B58263303F9CF5B2E040E3CD40136A78605D79B84141BECDB31896FD43E73111AE07DA894433E27F945114A945737AA1DCFE7648471C7A3075A27BFF47AE2F865A746FF549C0F7D5C58DAD7D4AC6A258049BD6E64B4752645E76F39E4DA9780D75AF0A6B4DD1665B6856D4F84E75A7D7BECC1DF94EDF2D538BCC83F950B87C338B76F32F50BF8C06E0FE08FE50DFF83F87E1D33B510EC2A8DC498C4551D864D5E42B8A76529A72B2DBDE8F4B552CF1E4A8AB85DD55677ABC4A6D6CC05674E0EAC7181CFD58F6F13D28CA7A365956D8037CB505725958C47B349399765998A979DF2DDFB85A9429AB90400CD25D84AD4C134DE91E5E7F961E93A35FF45EA819B7306D3C885F377E4255EDABB25FE907945CE6C0A16034F743F87AA74260D1D9429FBCAA0860ED6DD80CC3E3CB6383C322196D1EC464FF526FD87CE3E765AD3780E9F97898668AEA231012C91268FB0E6F684DF9926C58FAFCA44F68D16D2B5F0F78EB98D66D7DC0B998C0780F6DC4CCC1230752666E98008FF328B47571765F290D2BB87E71C7E89C4494F41271D144CC0032659B71DE0513743DE1B971F76602BFC11BCF73754B1443CE1E1E74124CCF336150F8752BD6E456B21CC7769E177BE0E0B66F76BE1268218DAE37784EE11732089EF97A8A8099020BE0747B528BF8134C9D4F7B5B54D144123AEB7DCFBF351DDE1AE2'::hll(12,5,256,1), +hll_hash_integer(1,0)); + +-- ---------------------------------------------------------------- +-- Test auto explicit threshold values. +-- ---------------------------------------------------------------- + +-- ((((2^12 * 5) + 7) / 8) / 8) = 320 +SELECT hll_print(hll_empty(12,5,-1,1)); + +-- ((((2^10 * 5) + 7) / 8) / 8) = 80 +SELECT hll_print(hll_empty(10,5,-1,1)); + +-- ((((2^10 * 4) + 7) / 8) / 8) = 64 +SELECT hll_print(hll_empty(10,4,-1,1)); + +-- ((((2^10 * 3) + 7) / 8) / 8) = 48 +SELECT hll_print(hll_empty(10,3,-1,1)); + +-- ((((2^2 * 5) + 7) / 8) / 8) = 0 +SELECT hll_print(hll_empty(2,5,-1,1)); + +-- ((((2^4 * 5) + 7) / 8) / 8) = 1 +SELECT hll_print(hll_empty(4,5,-1,1)); + +-- ((((2^4 * 4) + 7) / 8) / 8) = 1 +SELECT hll_print(hll_empty(4,4,-1,1)); + +-- ---------------------------------------------------------------- +-- Test auto explicit threshold action. +-- ---------------------------------------------------------------- + +-- Should have auto-explicit value of 2. +-- ((((2^5 * 5) + 7) / 8) / 8) = 2 +SELECT hll_print(hll_empty(5,5,-1,1)); + +-- Empty +SELECT hll_empty(5,5,-1,1); + +-- Explicit +SELECT hll_add( + hll_empty(5,5,-1,1), + hll_hash_integer(1,0)); + +-- Explicit +SELECT hll_add( + hll_add( + hll_empty(5,5,-1,1), + hll_hash_integer(1,0)), + hll_hash_integer(2,0)); + +-- Now Sparse +SELECT hll_add( + hll_add( + hll_add( + hll_empty(5,5,-1,1), + hll_hash_integer(1,0)), + hll_hash_integer(2,0)), + hll_hash_integer(3,0)); diff --git a/external/hll/sql/hash.sql b/external/hll/sql/hash.sql new file mode 100644 index 00000000000..ad88d041277 --- /dev/null +++ b/external/hll/sql/hash.sql @@ -0,0 +1,102 @@ +-- ---------------------------------------------------------------- +-- Misc Tests on Hash Function +-- ---------------------------------------------------------------- + +SELECT hll_set_output_version(1); + +-- ---------------- boolean + +SELECT hll_hash_boolean(FALSE); +SELECT hll_hash_boolean(TRUE); + +-- ---------------- smallint + +SELECT hll_hash_smallint(0::smallint); +SELECT hll_hash_smallint(100::smallint); +SELECT hll_hash_smallint(-100::smallint); + +-- ---------------- integer + +SELECT hll_hash_integer(0); +SELECT hll_hash_integer(100); +SELECT hll_hash_integer(-100); + +-- ---------------- bigint + +SELECT hll_hash_bigint(0); +SELECT hll_hash_bigint(100); +SELECT hll_hash_bigint(-100); + +-- ---------------- bytea + +-- Check some small values. +SELECT hll_hash_bytea(E'\\x'); +SELECT hll_hash_bytea(E'\\x41'); +SELECT hll_hash_bytea(E'\\x42'); +SELECT hll_hash_bytea(E'\\x4142'); + +-- ---------------- text + +-- Check some small values. +SELECT hll_hash_text(''); +SELECT hll_hash_text('A'); +SELECT hll_hash_text('B'); +SELECT hll_hash_text('AB'); + +-- ---------------- seed stuff + +-- Seed 0 ok. +SELECT hll_hash_bigint(0, 0); + +-- Positive seed ok. +SELECT hll_hash_bigint(0, 1); + +-- Max positive seed ok. +SELECT hll_hash_bigint(0, 2147483647); + +-- WARNING: negative seed values not compatible +SELECT hll_hash_bigint(0, -1); + +-- WARNING: negative seed values not compatible +SELECT hll_hash_bigint(0, -2); + +-- WARNING: negative seed values not compatible +SELECT hll_hash_bigint(0, -2147483648); + +-- WARNING: negative seed values not compatible +SELECT hll_hash_boolean(0, -1); +SELECT hll_hash_smallint(0::smallint, -1); +SELECT hll_hash_integer(0, -1); +SELECT hll_hash_bigint(0, -1); +SELECT hll_hash_bytea(E'\\x', -1); +SELECT hll_hash_text('AB', -1); + +-- ---------------- Matches + +SELECT hll_hash_boolean(FALSE, 0), hll_hash_bytea(E'\\x00', 0); +SELECT hll_hash_boolean(TRUE, 0), hll_hash_bytea(E'\\x01', 0); +SELECT hll_hash_smallint(0::smallint, 0), hll_hash_bytea(E'\\x0000', 0); +SELECT hll_hash_integer(0, 0), hll_hash_bytea(E'\\x00000000', 0); +SELECT hll_hash_bigint(0, 0), hll_hash_bytea(E'\\x0000000000000000', 0); +SELECT hll_hash_bytea(E'\\x4142', 0), hll_hash_text('AB', 0); + +-- ---------------- Default seed = 0 + +SELECT hll_hash_boolean(TRUE) = hll_hash_boolean(TRUE, 0); +SELECT hll_hash_smallint(100::smallint) = hll_hash_smallint(100::smallint, 0); +SELECT hll_hash_integer(100) = hll_hash_integer(100, 0); +SELECT hll_hash_bigint(100) = hll_hash_bigint(100, 0); +SELECT hll_hash_bytea(E'\\x42') = hll_hash_bytea(E'\\x42', 0); +SELECT hll_hash_text('AB') = hll_hash_text('AB', 0); + +-- ---------------- Explicit casts work for already hashed numbers. + +SELECT hll_empty() || 42::hll_hashval; +SELECT hll_empty() || CAST(42 AS hll_hashval); +SELECT hll_empty() || 42::bigint::hll_hashval; +SELECT hll_empty() || CAST(42 AS bigint)::hll_hashval; + +-- ERROR: doesn't cast implicitly +SELECT hll_empty() || 42; +SELECT hll_empty() || 42::bigint; + diff --git a/external/hll/sql/hash_any.sql b/external/hll/sql/hash_any.sql new file mode 100644 index 00000000000..0050221b139 --- /dev/null +++ b/external/hll/sql/hash_any.sql @@ -0,0 +1,48 @@ +-- ---------------------------------------------------------------- +-- Misc Tests on hash_any Function +-- ---------------------------------------------------------------- + +SELECT hll_set_output_version(1); + +-- ---------------- Check hash and hash_any function results match + +SELECT hll_hash_boolean(FALSE) = hll_hash_any(FALSE); +SELECT hll_hash_boolean(TRUE) = hll_hash_any(TRUE); + +SELECT hll_hash_smallint(0::smallint) = hll_hash_any(0::smallint); +SELECT hll_hash_smallint(100::smallint) = hll_hash_any(100::smallint); +SELECT hll_hash_smallint(-100::smallint) = hll_hash_any(-100::smallint); + +SELECT hll_hash_integer(0) = hll_hash_any(0); +SELECT hll_hash_integer(100) = hll_hash_any(100); +SELECT hll_hash_integer(-100) = hll_hash_any(-100); + +SELECT hll_hash_bigint(0) = hll_hash_any(0::bigint); +SELECT hll_hash_bigint(100) = hll_hash_any(100::bigint); +SELECT hll_hash_bigint(-100) = hll_hash_any(-100::bigint); + +SELECT hll_hash_bytea(E'\\x') = hll_hash_any(E'\\x'::bytea); +SELECT hll_hash_bytea(E'\\x41') = hll_hash_any(E'\\x41'::bytea); +SELECT hll_hash_bytea(E'\\x42') = hll_hash_any(E'\\x42'::bytea); +SELECT hll_hash_bytea(E'\\x4142') = hll_hash_any(E'\\x4142'::bytea); + +SELECT hll_hash_text('') = hll_hash_any(''::text); +SELECT hll_hash_text('A') = hll_hash_any('A'::text); +SELECT hll_hash_text('B') = hll_hash_any('B'::text); +SELECT hll_hash_text('AB') = hll_hash_any('AB'::text); + +-- ---------------- Check several types not handled by default hash functions + +-- ---------------- macaddr + +SELECT hll_hash_any('08:00:2b:01:02:03'::macaddr); +SELECT hll_hash_any('08002b010203'::macaddr); +SELECT hll_hash_any('01-23-45-67-89-ab'::macaddr); +SELECT hll_hash_any('012345-6789ab'::macaddr); + +-- ---------------- interval + +SELECT hll_hash_any('1 year 2 months 3 days 4 hours 5 minutes 6seconds'::interval); +SELECT hll_hash_any('P1Y2M3DT4H5M6S'::interval); +SELECT hll_hash_any('1997-06 20 12:00:00'::interval); +SELECT hll_hash_any('P1997-06-20T12:00:00'::interval); diff --git a/external/hll/sql/meta_func.sql b/external/hll/sql/meta_func.sql new file mode 100644 index 00000000000..400249be81b --- /dev/null +++ b/external/hll/sql/meta_func.sql @@ -0,0 +1,53 @@ +-- ---------------------------------------------------------------- +-- Tests for Metadata Functions. +-- ---------------------------------------------------------------- + +SELECT hll_set_output_version(1); + +SELECT hll_schema_version(NULL); +SELECT hll_schema_version(E'\\x108b7f'); +SELECT hll_schema_version(E'\\x118b7f'); +SELECT hll_schema_version(hll_empty(10,4,32,0)); +SELECT hll_schema_version(E'\\x128b498895a3f5af28cafe'); +SELECT hll_schema_version(E'\\x138b400061'); +SELECT hll_schema_version(E'\\x14857f0840008001000020000008042000062884120021'); + +SELECT hll_type(NULL); +SELECT hll_type(E'\\x108b7f'); +SELECT hll_type(E'\\x118b7f'); +SELECT hll_type(hll_empty(10,4,32,0)); +SELECT hll_type(E'\\x128b498895a3f5af28cafe'); +SELECT hll_type(E'\\x138b400061'); +SELECT hll_type(E'\\x14857f0840008001000020000008042000062884120021'); + +SELECT hll_log2m(NULL); +SELECT hll_log2m(E'\\x108b7f'); +SELECT hll_log2m(E'\\x118b7f'); +SELECT hll_log2m(hll_empty(10,4,32,0)); +SELECT hll_log2m(E'\\x128b498895a3f5af28cafe'); +SELECT hll_log2m(E'\\x138b400061'); +SELECT hll_log2m(E'\\x14857f0840008001000020000008042000062884120021'); + +SELECT hll_regwidth(NULL); +SELECT hll_regwidth(E'\\x108b7f'); +SELECT hll_regwidth(E'\\x118b7f'); +SELECT hll_regwidth(hll_empty(10,4,32,0)); +SELECT hll_regwidth(E'\\x128b498895a3f5af28cafe'); +SELECT hll_regwidth(E'\\x138b400061'); +SELECT hll_regwidth(E'\\x14857f0840008001000020000008042000062884120021'); + +SELECT hll_expthresh(NULL); +SELECT hll_expthresh(E'\\x108b7f'); +SELECT hll_expthresh(E'\\x118b7f'); +SELECT hll_expthresh(hll_empty(10,4,32,0)); +SELECT hll_expthresh(E'\\x128b498895a3f5af28cafe'); +SELECT hll_expthresh(E'\\x138b400061'); +SELECT hll_expthresh(E'\\x14857f0840008001000020000008042000062884120021'); + +SELECT hll_sparseon(NULL); +SELECT hll_sparseon(E'\\x108b7f'); +SELECT hll_sparseon(E'\\x118b7f'); +SELECT hll_sparseon(hll_empty(10,4,32,0)); +SELECT hll_sparseon(E'\\x128b498895a3f5af28cafe'); +SELECT hll_sparseon(E'\\x138b400061'); +SELECT hll_sparseon(E'\\x14857f0840008001000020000008042000062884120021'); diff --git a/external/hll/sql/murmur_bigint.sql b/external/hll/sql/murmur_bigint.sql new file mode 100644 index 00000000000..125471e3219 --- /dev/null +++ b/external/hll/sql/murmur_bigint.sql @@ -0,0 +1,25 @@ +-- ================================================================ +-- Setup the table +-- + +SELECT hll_set_output_version(1); + +DROP TABLE IF EXISTS test_seznjqbb; + +CREATE TABLE test_seznjqbb ( + recno SERIAL, + seed integer, + pre_hash_long bigint, + post_hash_long bigint +); + +\copy test_seznjqbb (seed, pre_hash_long, post_hash_long) from sql/data/murmur_bigint.csv with csv header + +SELECT COUNT(*) FROM test_seznjqbb; + +SELECT recno, post_hash_long, hll_hash_bigint(pre_hash_long, seed) + FROM test_seznjqbb + WHERE hll_hashval(post_hash_long) != hll_hash_bigint(pre_hash_long, seed) + ORDER BY recno; + +DROP TABLE test_seznjqbb; diff --git a/external/hll/sql/murmur_bytea.sql b/external/hll/sql/murmur_bytea.sql new file mode 100644 index 00000000000..ca4faa4b55d --- /dev/null +++ b/external/hll/sql/murmur_bytea.sql @@ -0,0 +1,25 @@ +-- ================================================================ +-- Setup the table +-- + +SELECT hll_set_output_version(1); + +DROP TABLE IF EXISTS test_qfwzdmoy; + +CREATE TABLE test_qfwzdmoy ( + recno SERIAL, + seed integer, + pre_hash_long bytea, + post_hash_long bigint +); + +\copy test_qfwzdmoy (seed, pre_hash_long, post_hash_long) from sql/data/murmur_bytea.csv with csv header + +SELECT COUNT(*) FROM test_qfwzdmoy; + +SELECT recno, post_hash_long, hll_hash_bytea(pre_hash_long, seed) + FROM test_qfwzdmoy + WHERE hll_hashval(post_hash_long) != hll_hash_bytea(pre_hash_long, seed) + ORDER BY recno; + +DROP TABLE test_qfwzdmoy; diff --git a/external/hll/sql/nosparse.sql b/external/hll/sql/nosparse.sql new file mode 100644 index 00000000000..88d1b90283a --- /dev/null +++ b/external/hll/sql/nosparse.sql @@ -0,0 +1,17 @@ +-- ---------------------------------------------------------------- +-- Regression tests for explicit threshold control. +-- ---------------------------------------------------------------- + +SELECT hll_set_output_version(1); + +-- Should display sparseon = 1 +SELECT hll_print(hll_empty(12,5,0,1)); + +-- Should display sparseon = 0 +SELECT hll_print(hll_empty(12,5,0,0)); + +-- Should become sparse +SELECT hll_add(hll_empty(12,5,0,1), hll_hash_integer(1,0)); + +-- Should go straight to compressed +SELECT hll_add(hll_empty(12,5,0,0), hll_hash_integer(1,0)); diff --git a/external/hll/sql/notequal.sql b/external/hll/sql/notequal.sql new file mode 100644 index 00000000000..9576e52b30d --- /dev/null +++ b/external/hll/sql/notequal.sql @@ -0,0 +1,68 @@ +-- ---------------------------------------------------------------- +-- Regression tests for inequality operator with v1 output. +-- ---------------------------------------------------------------- + +SELECT hll_set_output_version(1); + +-- Undefined sets: f +SELECT E'\\x108c49'::hll <> E'\\x108c49'::hll; + +-- Undefined, different metadata: t +SELECT E'\\x108c49'::hll <> E'\\x108b49'::hll; + +-- Equal empty sets: f +SELECT hll_empty(11,5,256,1) <> hll_empty(11,5,256,1); + +-- Different metadata: t +SELECT hll_empty(11,5,256,1) <> hll_empty(11,5,256,0); + +-- Different metadata: t +SELECT hll_empty(11,5,256,1) <> hll_empty(11,5,128,1); + +-- Different metadata: t +SELECT hll_empty(11,5,256,1) <> hll_empty(11,4,256,1); + +-- Different metadata: t +SELECT hll_empty(11,5,256,1) <> hll_empty(10,5,256,1); + +-- Same explicit: f +SELECT E'\\x128b7f8895a3f5af28cafe'::hll <> E'\\x128b7f8895a3f5af28cafe'::hll; + +-- Different explicit: t +SELECT E'\\x128b7f8895a3f5af28cafe'::hll <> E'\\x128b7fda0ce907e4355b60'::hll; + +-- Different explicit lengths: t +SELECT E'\\x128b7f8895a3f5af28cafe'::hll <> E'\\x128b7f8895a3f5af28cafeda0ce907e4355b60'::hll; + +-- Same sparse: f +SELECT E'\\x138b7f0001'::hll <> E'\\x138b7f0001'::hll; + +-- Different sparse: t +SELECT E'\\x138b7f0001'::hll <> E'\\x138b7f0022'::hll; + +-- Different sparse lengths: t +SELECT E'\\x138b7f0001'::hll <> E'\\x138b7f00410061'::hll; + +-- Same compressed: f +SELECT hll_add(hll_empty(11,5,0,0), hll_hash_integer(1,0)) <> +E'\\x148b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'::hll; + + +-- Different compressed: t +SELECT hll_add(hll_empty(11,5,0,0), hll_hash_integer(2,0)) <> +E'\\x148b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'::hll; + +-- Different types: t +SELECT E'\\x108b7f'::hll <> hll_empty(11,5,256,1); +SELECT E'\\x108b7f'::hll <> E'\\x128b7f8895a3f5af28cafe'::hll; +SELECT E'\\x108b7f'::hll <> E'\\x138b7f0041'::hll; +SELECT E'\\x108b7f'::hll <> hll_add(hll_empty(11,5,0,0), hll_hash_integer(1,0)); +SELECT hll_empty(11,5,256,1) <> E'\\x128b408895a3f5af28cafe'::hll; +SELECT hll_empty(11,5,256,1) <> E'\\x138b7f0001'::hll; +SELECT hll_empty(11,5,256,1) <> + hll_add(hll_empty(11,5,0,0), hll_hash_integer(1,0)); +SELECT E'\\x128b7f8895a3f5af28cafe'::hll <> E'\\x138b7f0022'::hll; +SELECT E'\\x128b7f8895a3f5af28cafe'::hll <> + hll_add(hll_empty(11,5,0,0), hll_hash_integer(1,0)); +SELECT E'\\x138c40afe180'::hll <> + hll_add(hll_empty(11,5,0,0), hll_hash_integer(1,0)); diff --git a/external/hll/sql/scalar_oob.sql b/external/hll/sql/scalar_oob.sql new file mode 100644 index 00000000000..d8c909050db --- /dev/null +++ b/external/hll/sql/scalar_oob.sql @@ -0,0 +1,84 @@ +-- ---------------------------------------------------------------- +-- Scalar Operations with Out-Of-Band Values. +-- NULL, UNDEFINED, EMPTY, EXPLICIT, SPARSE +-- (Sparse and compressed are the same internally) +-- ---------------------------------------------------------------- + +set extra_float_digits=0; +SELECT hll_set_output_version(1); + +-- Scalar Cardinality ---- + +SELECT hll_cardinality(NULL); + +SELECT hll_cardinality(E'\\x108b7f'::hll); + +SELECT hll_cardinality(E'\\x118b7f'::hll); + +SELECT hll_cardinality(E'\\x128b7f1111111111111111'::hll); + +SELECT hll_cardinality(E'\\x138b7f0001'::hll); + + +-- Scalar Union ---- + +-- NULL + +SELECT hll_union(NULL, NULL); + +SELECT hll_union(NULL, E'\\x108b7f'::hll); + +SELECT hll_union(NULL, E'\\x118b7f'::hll); + +SELECT hll_union(NULL, E'\\x128b7f1111111111111111'::hll); + +SELECT hll_union(NULL, E'\\x138b7f0001'::hll); + +-- UNDEFINED + +SELECT hll_union(E'\\x108b7f'::hll, NULL); + +SELECT hll_union(E'\\x108b7f'::hll, E'\\x108b7f'::hll); + +SELECT hll_union(E'\\x108b7f'::hll, E'\\x118b7f'::hll); + +SELECT hll_union(E'\\x108b7f'::hll, E'\\x128b7f1111111111111111'::hll); + +SELECT hll_union(E'\\x108b7f'::hll, E'\\x138b7f0001'::hll); + +-- EMPTY + +SELECT hll_union(E'\\x118b7f'::hll, NULL); + +SELECT hll_union(E'\\x118b7f'::hll, E'\\x108b7f'::hll); + +SELECT hll_union(E'\\x118b7f'::hll, E'\\x118b7f'::hll); + +SELECT hll_union(E'\\x118b7f'::hll, E'\\x128b7f1111111111111111'::hll); + +SELECT hll_union(E'\\x118b7f'::hll, E'\\x138b7f0001'::hll); + +-- EXPLICIT + +SELECT hll_union(E'\\x128b7f1111111111111111'::hll, NULL); + +SELECT hll_union(E'\\x128b7f1111111111111111'::hll, E'\\x108b7f'::hll); + +SELECT hll_union(E'\\x128b7f1111111111111111'::hll, E'\\x118b7f'::hll); + +SELECT hll_union(E'\\x128b7f1111111111111111'::hll, E'\\x128b7f1111111111111111'::hll); + +SELECT hll_union(E'\\x128b7f1111111111111111'::hll, E'\\x138b7f0001'::hll); + +-- SPARSE + +SELECT hll_union(E'\\x138b7f0001'::hll, NULL); + +SELECT hll_union(E'\\x138b7f0001'::hll, E'\\x108b7f'::hll); + +SELECT hll_union(E'\\x138b7f0001'::hll, E'\\x118b7f'::hll); + +SELECT hll_union(E'\\x138b7f0001'::hll, E'\\x128b7f1111111111111111'::hll); + +SELECT hll_union(E'\\x138b7f0001'::hll, E'\\x138b7f0001'::hll); + diff --git a/external/hll/sql/setup.sql b/external/hll/sql/setup.sql new file mode 100644 index 00000000000..8b94cd9f8d4 --- /dev/null +++ b/external/hll/sql/setup.sql @@ -0,0 +1,9 @@ +CREATE EXTENSION hll VERSION '2.10'; +ALTER EXTENSION hll UPDATE TO '2.11'; +ALTER EXTENSION hll UPDATE TO '2.12'; +ALTER EXTENSION hll UPDATE TO '2.13'; +ALTER EXTENSION hll UPDATE TO '2.14'; +ALTER EXTENSION hll UPDATE TO '2.15'; +ALTER EXTENSION hll UPDATE TO '2.16'; +ALTER EXTENSION hll UPDATE TO '2.17'; +ALTER EXTENSION hll UPDATE TO '2.18'; diff --git a/external/hll/sql/storedproc.sql b/external/hll/sql/storedproc.sql new file mode 100644 index 00000000000..be177aa83eb --- /dev/null +++ b/external/hll/sql/storedproc.sql @@ -0,0 +1,28 @@ +-- ---------------------------------------------------------------- +-- Establishes global setting behavior with stored procedures. +-- ---------------------------------------------------------------- + +-- Outside stored procedure. + +SELECT hll_set_max_sparse(256); +SELECT hll_set_defaults(10,4,128,0); + +-- When defining a stored procedure the global statements don't take +-- effect. + +CREATE OR REPLACE FUNCTION testfunc_azfwygmg() RETURNS void AS $$ +BEGIN +PERFORM hll_set_max_sparse(-1); +PERFORM hll_set_defaults(11,5,-1,1); +END; +$$ LANGUAGE plpgsql; + +SELECT hll_set_max_sparse(256); +SELECT hll_set_defaults(10,4,128,0); + +-- When invoking a stored procedure they work. + +SELECT testfunc_azfwygmg(); + +SELECT hll_set_max_sparse(256); +SELECT hll_set_defaults(10,4,128,0); diff --git a/external/hll/sql/transaction.sql b/external/hll/sql/transaction.sql new file mode 100644 index 00000000000..466f048f7d3 --- /dev/null +++ b/external/hll/sql/transaction.sql @@ -0,0 +1,42 @@ +-- ---------------------------------------------------------------- +-- Establish global statement's properties WRT transactions. +-- ---------------------------------------------------------------- + +-- Outside transaction. + +SELECT hll_set_max_sparse(-1); + +SELECT hll_set_max_sparse(256); + +SELECT hll_set_defaults(11,5,-1,1); + +SELECT hll_set_defaults(10,4,128,0); + +-- Inside transaction - should have an affect later. + +BEGIN; + +SELECT hll_set_max_sparse(-1); + +SELECT hll_set_defaults(11,5,-1,1); + +COMMIT; + +SELECT hll_set_max_sparse(256); + +SELECT hll_set_defaults(10,4,128,0); + +-- Inside Rolled back transaction, should still have an affect later. + +BEGIN; + +SELECT hll_set_max_sparse(-1); + +SELECT hll_set_defaults(11,5,-1,1); + +ROLLBACK; + +SELECT hll_set_max_sparse(256); + +SELECT hll_set_defaults(10,4,128,0); + diff --git a/external/hll/sql/typmod.sql b/external/hll/sql/typmod.sql new file mode 100644 index 00000000000..f62e72631b0 --- /dev/null +++ b/external/hll/sql/typmod.sql @@ -0,0 +1,112 @@ +-- ---------------------------------------------------------------- +-- Type Modifier Signature +-- ---------------------------------------------------------------- + +SELECT hll_set_output_version(1); + +DROP TABLE IF EXISTS test_qiundgkm; + +-- Using all defaults. +CREATE TABLE test_qiundgkm (v1 hll); +\d test_qiundgkm +DROP TABLE test_qiundgkm; + +-- Partial defaults. +CREATE TABLE test_qiundgkm (v1 hll(10)); +\d test_qiundgkm +DROP TABLE test_qiundgkm; + +CREATE TABLE test_qiundgkm (v1 hll(10, 4)); +\d test_qiundgkm +DROP TABLE test_qiundgkm; + +CREATE TABLE test_qiundgkm (v1 hll(10, 4, 64)); +\d test_qiundgkm +DROP TABLE test_qiundgkm; + +CREATE TABLE test_qiundgkm (v1 hll(10, 4, 64, 0)); +\d test_qiundgkm +DROP TABLE test_qiundgkm; + +-- ERROR: invalid number of type modifiers +CREATE TABLE test_qiundgkm (v1 hll(10, 4, 64, 0, 42)); + +-- ---------------------------------------------------------------- +-- Range Check log2nregs +-- ---------------------------------------------------------------- + +-- ERROR: log2m modifier must be between 0 and 17 +CREATE TABLE test_qiundgkm (v1 hll(-1)); + +CREATE TABLE test_qiundgkm (v1 hll(0)); +\d test_qiundgkm +DROP TABLE test_qiundgkm; + +CREATE TABLE test_qiundgkm (v1 hll(31)); +\d test_qiundgkm +DROP TABLE test_qiundgkm; + +-- ERROR: log2m modifier must be between 0 and 17 +CREATE TABLE test_qiundgkm (v1 hll(32)); + +-- ---------------------------------------------------------------- +-- Range Check regwidth +-- ---------------------------------------------------------------- + +-- ERROR: regwidth modifier must be between 0 and 7 +CREATE TABLE test_qiundgkm (v1 hll(11, -1)); + +CREATE TABLE test_qiundgkm (v1 hll(11, 0)); +\d test_qiundgkm +DROP TABLE test_qiundgkm; + +CREATE TABLE test_qiundgkm (v1 hll(11, 7)); +\d test_qiundgkm +DROP TABLE test_qiundgkm; + +-- ERROR: regwidth modifier must be between 0 and 7 +CREATE TABLE test_qiundgkm (v1 hll(11, 8)); + +-- ---------------------------------------------------------------- +-- Range Check expthresh +-- ---------------------------------------------------------------- + +-- ERROR: expthresh modifier must be between -1 and 16383 +CREATE TABLE test_qiundgkm (v1 hll(11, 5, -2)); + +CREATE TABLE test_qiundgkm (v1 hll(11, 5, -1)); +\d test_qiundgkm +DROP TABLE test_qiundgkm; + +CREATE TABLE test_qiundgkm (v1 hll(11, 5, 0)); +\d test_qiundgkm +DROP TABLE test_qiundgkm; + +CREATE TABLE test_qiundgkm (v1 hll(11, 5, 128)); +\d test_qiundgkm +DROP TABLE test_qiundgkm; + +CREATE TABLE test_qiundgkm (v1 hll(11, 5, 4294967296)); +\d test_qiundgkm +DROP TABLE test_qiundgkm; + +-- ERROR: expthresh modifier must be between -1 and 16383 +CREATE TABLE test_qiundgkm (v1 hll(11, 5, 8589934592)); + +-- ---------------------------------------------------------------- +-- Range Check nosparse +-- ---------------------------------------------------------------- + +-- ERROR: nosparse modifier must be 0 or 1 +CREATE TABLE test_qiundgkm (v1 hll(11, 5, 128, -1)); + +CREATE TABLE test_qiundgkm (v1 hll(11, 5, 128, 0)); +\d test_qiundgkm +DROP TABLE test_qiundgkm; + +CREATE TABLE test_qiundgkm (v1 hll(11, 5, 128, 1)); +\d test_qiundgkm +DROP TABLE test_qiundgkm; + +-- ERROR: nosparse modifier must be 0 or 1 +CREATE TABLE test_qiundgkm (v1 hll(11, 5, 128, 2)); diff --git a/external/hll/sql/typmod_insert.sql b/external/hll/sql/typmod_insert.sql new file mode 100644 index 00000000000..bb56403b54f --- /dev/null +++ b/external/hll/sql/typmod_insert.sql @@ -0,0 +1,28 @@ +SELECT hll_set_output_version(1); + +DROP TABLE IF EXISTS test_trsybeqs; + +CREATE TABLE test_trsybeqs ( + val hll(10) +); + +-- ERROR: register count does not match: source uses 2048 and dest uses 1024 +INSERT INTO test_trsybeqs(val) VALUES ( +E'\\x148b7f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000'::hll +); + +-- ERROR: register count does not match: source uses 2048 and dest uses 1024 +INSERT INTO test_trsybeqs(val) VALUES (hll_empty(11)); + +-- ERROR: register count does not match: source uses 2048 and dest uses 1024 +INSERT INTO test_trsybeqs(val) VALUES (E'\\x118b7f'); + +-- ERROR: register count does not match: source uses 2048 and dest uses 1024 +INSERT INTO test_trsybeqs(val) VALUES (E'\\x128b7f1111111111111111'); + +-- These work because they are compatibly sized: +INSERT INTO test_trsybeqs(val) VALUES (hll_empty(10)); +INSERT INTO test_trsybeqs(val) VALUES (E'\\x118a7f'); +INSERT INTO test_trsybeqs(val) VALUES (E'\\x128a7f1111111111111111'); + +DROP TABLE test_trsybeqs; diff --git a/external/hll/sql/union_op.sql b/external/hll/sql/union_op.sql new file mode 100644 index 00000000000..bd865ec5a73 --- /dev/null +++ b/external/hll/sql/union_op.sql @@ -0,0 +1,24 @@ +-- ---------------------------------------------------------------- +-- Regression tests for union operator. +-- ---------------------------------------------------------------- + +SELECT hll_set_output_version(1); + +SELECT hll_empty(11,5,256,1) || hll_empty(11,5,256,1); + +SELECT hll_empty(11,5,256,1) || E'\\x128b498895a3f5af28cafe'::hll; + +SELECT E'\\x128b498895a3f5af28cafe'::hll || E'\\x128b498895a3f5af28cafe'::hll; + +SELECT E'\\x128b498895a3f5af28cafe'::hll || E'\\x128b49da0ce907e4355b60'::hll; + +SELECT hll_empty(11,5,256,1) || hll_hash_integer(1,0); + +SELECT hll_empty(11,5,256,1) + || hll_hash_integer(1,0) + || hll_hash_integer(2,0) + || hll_hash_integer(3,0); + +SELECT hll_hash_integer(1,0) || hll_empty(11,5,256,1); + +SELECT hll_hash_integer(1,0) || hll_empty(11,5,256,1) || hll_hash_integer(2,0); diff --git a/external/hll/update/hll--2.10--2.11.sql b/external/hll/update/hll--2.10--2.11.sql new file mode 100644 index 00000000000..691c38c910f --- /dev/null +++ b/external/hll/update/hll--2.10--2.11.sql @@ -0,0 +1,40 @@ +DROP AGGREGATE hll_add_agg (hll_hashval); +DROP AGGREGATE hll_add_agg (hll_hashval, integer); +DROP AGGREGATE hll_add_agg (hll_hashval, integer, integer); +DROP AGGREGATE hll_add_agg (hll_hashval, integer, integer, bigint); +DROP AGGREGATE hll_add_agg (hll_hashval, integer, integer, bigint, integer); + +CREATE AGGREGATE hll_add_agg (hll_hashval) ( + SFUNC = hll_add_trans0, + STYPE = internal, + SSPACE = 131120, + FINALFUNC = hll_pack +); + +CREATE AGGREGATE hll_add_agg (hll_hashval, integer) ( + SFUNC = hll_add_trans1, + STYPE = internal, + SSPACE = 131120, + FINALFUNC = hll_pack +); + +CREATE AGGREGATE hll_add_agg (hll_hashval, integer, integer) ( + SFUNC = hll_add_trans2, + STYPE = internal, + SSPACE = 131120, + FINALFUNC = hll_pack +); + +CREATE AGGREGATE hll_add_agg (hll_hashval, integer, integer, bigint) ( + SFUNC = hll_add_trans3, + STYPE = internal, + SSPACE = 131120, + FINALFUNC = hll_pack +); + +CREATE AGGREGATE hll_add_agg (hll_hashval, integer, integer, bigint, integer) ( + SFUNC = hll_add_trans4, + STYPE = internal, + SSPACE = 131120, + FINALFUNC = hll_pack +); diff --git a/external/hll/update/hll--2.10.sql b/external/hll/update/hll--2.10.sql new file mode 100644 index 00000000000..f3ccb94eba7 --- /dev/null +++ b/external/hll/update/hll--2.10.sql @@ -0,0 +1,507 @@ +/* Copyright 2013 Aggregate Knowledge, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +-- complain if script is sourced in psql, rather than via CREATE EXTENSION +\echo Use "CREATE EXTENSION hll" to load this file. \quit + +-- ---------------------------------------------------------------- +-- Type +-- ---------------------------------------------------------------- + +CREATE TYPE hll; + +CREATE FUNCTION hll_in(cstring, oid, integer) +RETURNS hll +AS 'MODULE_PATHNAME' +LANGUAGE C STRICT IMMUTABLE; + +CREATE FUNCTION hll_out(hll) +RETURNS cstring +AS 'MODULE_PATHNAME' +LANGUAGE C STRICT IMMUTABLE; + +CREATE FUNCTION hll_recv(internal) +RETURNS hll +AS 'MODULE_PATHNAME' +LANGUAGE C IMMUTABLE STRICT; + +CREATE FUNCTION hll_send(hll) +RETURNS bytea +AS 'MODULE_PATHNAME' +LANGUAGE C IMMUTABLE STRICT; + +CREATE FUNCTION hll_typmod_in(cstring[]) +RETURNS integer +AS 'MODULE_PATHNAME' +LANGUAGE C STRICT IMMUTABLE; + +CREATE FUNCTION hll_typmod_out(integer) +RETURNS cstring +AS 'MODULE_PATHNAME' +LANGUAGE C STRICT IMMUTABLE; + +CREATE FUNCTION hll(hll, integer, boolean) +RETURNS hll +AS 'MODULE_PATHNAME' +LANGUAGE C STRICT IMMUTABLE; + +CREATE TYPE hll ( + INTERNALLENGTH = variable, + INPUT = hll_in, + OUTPUT = hll_out, + TYPMOD_IN = hll_typmod_in, + TYPMOD_OUT = hll_typmod_out, + RECEIVE = hll_recv, + SEND = hll_send, + STORAGE = external +); + +CREATE CAST (hll AS hll) WITH FUNCTION hll(hll, integer, boolean) AS IMPLICIT; + +CREATE CAST (bytea AS hll) WITHOUT FUNCTION; + +-- ---------------------------------------------------------------- +-- Hashed value type +-- ---------------------------------------------------------------- + +CREATE TYPE hll_hashval; + +CREATE FUNCTION hll_hashval_in(cstring, oid, integer) +RETURNS hll_hashval +AS 'MODULE_PATHNAME' +LANGUAGE C STRICT IMMUTABLE; + +CREATE FUNCTION hll_hashval_out(hll_hashval) +RETURNS cstring +AS 'MODULE_PATHNAME' +LANGUAGE C STRICT IMMUTABLE; + +CREATE TYPE hll_hashval ( + INTERNALLENGTH = 8, + PASSEDBYVALUE, + ALIGNMENT = double, + INPUT = hll_hashval_in, + OUTPUT = hll_hashval_out +); + +CREATE FUNCTION hll_hashval_eq(hll_hashval, hll_hashval) +RETURNS bool +AS 'MODULE_PATHNAME' +LANGUAGE C STRICT IMMUTABLE; + +CREATE FUNCTION hll_hashval_ne(hll_hashval, hll_hashval) +RETURNS bool +AS 'MODULE_PATHNAME' +LANGUAGE C STRICT IMMUTABLE; + +CREATE FUNCTION hll_hashval(bigint) +RETURNS hll_hashval +AS 'MODULE_PATHNAME' +LANGUAGE C STRICT IMMUTABLE; + +CREATE FUNCTION hll_hashval_int4(integer) +RETURNS hll_hashval +AS 'MODULE_PATHNAME' +LANGUAGE C STRICT IMMUTABLE; + +CREATE OPERATOR = ( + LEFTARG = hll_hashval, RIGHTARG = hll_hashval, + PROCEDURE = hll_hashval_eq, + COMMUTATOR = '=', NEGATOR = '<>', + RESTRICT = eqsel, JOIN = eqjoinsel, + MERGES +); + +CREATE OPERATOR <> ( + LEFTARG = hll_hashval, RIGHTARG = hll_hashval, + PROCEDURE = hll_hashval_ne, + COMMUTATOR = '<>', NEGATOR = '=', + RESTRICT = neqsel, JOIN = neqjoinsel +); + +-- Only allow explicit casts. +CREATE CAST (bigint AS hll_hashval) WITHOUT FUNCTION; +CREATE CAST (integer AS hll_hashval) WITH FUNCTION hll_hashval_int4(integer); + +-- ---------------------------------------------------------------- +-- Functions +-- ---------------------------------------------------------------- + +-- Equality of multisets. +-- +CREATE FUNCTION hll_eq(hll, hll) +RETURNS bool +AS 'MODULE_PATHNAME' +LANGUAGE C STRICT IMMUTABLE; + +-- Inequality of multisets. +-- +CREATE FUNCTION hll_ne(hll, hll) +RETURNS bool +AS 'MODULE_PATHNAME' +LANGUAGE C STRICT IMMUTABLE; + +-- Cardinality of a multiset. +-- +CREATE FUNCTION hll_cardinality(hll) + RETURNS double precision + AS 'MODULE_PATHNAME' + LANGUAGE C STRICT IMMUTABLE; + +-- Union of a pair of multisets. +-- +CREATE FUNCTION hll_union(hll, hll) + RETURNS hll + AS 'MODULE_PATHNAME' + LANGUAGE C STRICT IMMUTABLE; + +-- Adds an integer hash to a multiset. +-- +CREATE FUNCTION hll_add(hll, hll_hashval) + RETURNS hll + AS 'MODULE_PATHNAME' + LANGUAGE C STRICT IMMUTABLE; + +-- Adds a multiset to an integer hash. +-- +CREATE FUNCTION hll_add_rev(hll_hashval, hll) + RETURNS hll + AS 'MODULE_PATHNAME' + LANGUAGE C STRICT IMMUTABLE; + +-- Pretty-print a multiset. +-- +CREATE FUNCTION hll_print(hll) + RETURNS cstring + AS 'MODULE_PATHNAME' + LANGUAGE C STRICT IMMUTABLE; + +-- Create an empty multiset with parameters. +-- +-- NOTE - we create multiple signatures to avoid coding the defaults +-- in this sql file. This allows the defaults to changed at runtime. +-- +CREATE FUNCTION hll_empty() + RETURNS hll + AS 'MODULE_PATHNAME', 'hll_empty0' + LANGUAGE C STRICT IMMUTABLE; + +CREATE FUNCTION hll_empty(integer) + RETURNS hll + AS 'MODULE_PATHNAME', 'hll_empty1' + LANGUAGE C STRICT IMMUTABLE; + +CREATE FUNCTION hll_empty(integer, integer) + RETURNS hll + AS 'MODULE_PATHNAME', 'hll_empty2' + LANGUAGE C STRICT IMMUTABLE; + +CREATE FUNCTION hll_empty(integer, integer, bigint) + RETURNS hll + AS 'MODULE_PATHNAME', 'hll_empty3' + LANGUAGE C STRICT IMMUTABLE; + +CREATE FUNCTION hll_empty(integer, integer, bigint, integer) + RETURNS hll + AS 'MODULE_PATHNAME', 'hll_empty4' + LANGUAGE C STRICT IMMUTABLE; + +-- Returns the schema version of an hll. +-- +CREATE FUNCTION hll_schema_version(hll) + RETURNS integer + AS 'MODULE_PATHNAME' + LANGUAGE C STRICT IMMUTABLE; + +-- Returns the type of an hll. +-- +CREATE FUNCTION hll_type(hll) + RETURNS integer + AS 'MODULE_PATHNAME' + LANGUAGE C STRICT IMMUTABLE; + +-- Returns the log2m value of an hll. +-- +CREATE FUNCTION hll_log2m(hll) + RETURNS integer + AS 'MODULE_PATHNAME' + LANGUAGE C STRICT IMMUTABLE; + +-- Returns the register width of an hll. +-- +CREATE FUNCTION hll_regwidth(hll) + RETURNS integer + AS 'MODULE_PATHNAME' + LANGUAGE C STRICT IMMUTABLE; + +-- Returns the maximum explicit threshold of an hll. +-- +CREATE FUNCTION hll_expthresh(hll, OUT specified bigint, OUT effective bigint) + AS 'MODULE_PATHNAME' + LANGUAGE C STRICT IMMUTABLE; + +-- Returns the sparse enabled value of an hll. +-- +CREATE FUNCTION hll_sparseon(hll) + RETURNS integer + AS 'MODULE_PATHNAME' + LANGUAGE C STRICT IMMUTABLE; + +-- Set output version. +-- +CREATE FUNCTION hll_set_output_version(integer) + RETURNS integer + AS 'MODULE_PATHNAME' + LANGUAGE C STRICT IMMUTABLE; + +-- Set sparse to full compressed threshold to fixed value. +-- +CREATE FUNCTION hll_set_max_sparse(integer) + RETURNS integer + AS 'MODULE_PATHNAME' + LANGUAGE C STRICT IMMUTABLE; + +-- Change the default type modifier, empty and add aggregate defaults. +CREATE FUNCTION hll_set_defaults(IN i_log2m integer, + IN i_regwidth integer, + IN i_expthresh bigint, + IN i_sparseon integer, + OUT o_log2m integer, + OUT o_regwidth integer, + OUT o_expthresh bigint, + OUT o_sparseon integer) + AS 'MODULE_PATHNAME' + LANGUAGE C STRICT IMMUTABLE; + +-- ---------------------------------------------------------------- +-- Murmur Hashing +-- ---------------------------------------------------------------- + +-- Hash a boolean. +-- +CREATE FUNCTION hll_hash_boolean(boolean, integer default 0) + RETURNS hll_hashval + AS 'MODULE_PATHNAME', 'hll_hash_1byte' + LANGUAGE C STRICT IMMUTABLE; + +-- Hash a smallint. +-- +CREATE FUNCTION hll_hash_smallint(smallint, integer default 0) + RETURNS hll_hashval + AS 'MODULE_PATHNAME', 'hll_hash_2byte' + LANGUAGE C STRICT IMMUTABLE; + +-- Hash an integer. +-- +CREATE FUNCTION hll_hash_integer(integer, integer default 0) + RETURNS hll_hashval + AS 'MODULE_PATHNAME', 'hll_hash_4byte' + LANGUAGE C STRICT IMMUTABLE; + +-- Hash a bigint. +-- +CREATE FUNCTION hll_hash_bigint(bigint, integer default 0) + RETURNS hll_hashval + AS 'MODULE_PATHNAME', 'hll_hash_8byte' + LANGUAGE C STRICT IMMUTABLE; + +-- Hash a byte array. +-- +CREATE FUNCTION hll_hash_bytea(bytea, integer default 0) + RETURNS hll_hashval + AS 'MODULE_PATHNAME', 'hll_hash_varlena' + LANGUAGE C STRICT IMMUTABLE; + +-- Hash a text. +-- +CREATE FUNCTION hll_hash_text(text, integer default 0) + RETURNS hll_hashval + AS 'MODULE_PATHNAME', 'hll_hash_varlena' + LANGUAGE C STRICT IMMUTABLE; + +-- Hash any scalar data type. +-- +CREATE FUNCTION hll_hash_any(anyelement, integer default 0) + RETURNS hll_hashval + AS 'MODULE_PATHNAME', 'hll_hash_any' + LANGUAGE C STRICT IMMUTABLE; + + +-- ---------------------------------------------------------------- +-- Operators +-- ---------------------------------------------------------------- + +CREATE OPERATOR = ( + LEFTARG = hll, RIGHTARG = hll, PROCEDURE = hll_eq, + COMMUTATOR = '=', NEGATOR = '<>', + RESTRICT = eqsel, JOIN = eqjoinsel, + MERGES +); + +CREATE OPERATOR <> ( + LEFTARG = hll, RIGHTARG = hll, PROCEDURE = hll_ne, + COMMUTATOR = '<>', NEGATOR = '=', + RESTRICT = neqsel, JOIN = neqjoinsel +); + +CREATE OPERATOR || ( + LEFTARG = hll, RIGHTARG = hll, PROCEDURE = hll_union +); + +CREATE OPERATOR || ( + LEFTARG = hll, RIGHTARG = hll_hashval, PROCEDURE = hll_add +); + +CREATE OPERATOR || ( + LEFTARG = hll_hashval, RIGHTARG = hll, PROCEDURE = hll_add_rev +); + +CREATE OPERATOR # ( + RIGHTARG = hll, PROCEDURE = hll_cardinality +); + +-- ---------------------------------------------------------------- +-- Aggregates +-- ---------------------------------------------------------------- + +-- Union aggregate transition function, first arg internal data +-- structure, second arg is a packed multiset. +-- +CREATE FUNCTION hll_union_trans(internal, hll) + RETURNS internal + AS 'MODULE_PATHNAME' + LANGUAGE C; + +-- NOTE - unfortunately aggregate functions don't support default +-- arguments so we need to declare 5 signatures. + +-- Add aggregate transition function, first arg internal data +-- structure, second arg is a hashed value. Remaining args are log2n, +-- regwidth, expthresh, sparseon. +-- +CREATE FUNCTION hll_add_trans4(internal, + hll_hashval, + integer, + integer, + bigint, + integer) + RETURNS internal + AS 'MODULE_PATHNAME' + LANGUAGE C; + +CREATE FUNCTION hll_add_trans3(internal, + hll_hashval, + integer, + integer, + bigint) + RETURNS internal + AS 'MODULE_PATHNAME' + LANGUAGE C; + +CREATE FUNCTION hll_add_trans2(internal, + hll_hashval, + integer, + integer) + RETURNS internal + AS 'MODULE_PATHNAME' + LANGUAGE C; + +CREATE FUNCTION hll_add_trans1(internal, + hll_hashval, + integer) + RETURNS internal + AS 'MODULE_PATHNAME' + LANGUAGE C; + +CREATE FUNCTION hll_add_trans0(internal, + hll_hashval) + RETURNS internal + AS 'MODULE_PATHNAME' + LANGUAGE C; + + +-- Converts internal data structure into packed multiset. +-- +CREATE FUNCTION hll_pack(internal) + RETURNS hll + AS 'MODULE_PATHNAME' + LANGUAGE C; + +-- Computes cardinality of internal data structure. +-- +CREATE FUNCTION hll_card_unpacked(internal) + RETURNS double precision + AS 'MODULE_PATHNAME' + LANGUAGE C; + +-- Computes floor(cardinality) of internal data structure. +-- +CREATE FUNCTION hll_floor_card_unpacked(internal) + RETURNS int8 + AS 'MODULE_PATHNAME' + LANGUAGE C; + +-- Computes ceil(cardinality) of internal data structure. +-- +CREATE FUNCTION hll_ceil_card_unpacked(internal) + RETURNS int8 + AS 'MODULE_PATHNAME' + LANGUAGE C; + +-- Union aggregate function, returns hll. +-- +CREATE AGGREGATE hll_union_agg (hll) ( + SFUNC = hll_union_trans, + STYPE = internal, + FINALFUNC = hll_pack +); + +-- NOTE - unfortunately aggregate functions don't support default +-- arguments so we need to declare 5 signatures. + +-- Add aggregate function, returns hll. +CREATE AGGREGATE hll_add_agg (hll_hashval) ( + SFUNC = hll_add_trans0, + STYPE = internal, + FINALFUNC = hll_pack +); + +-- Add aggregate function, returns hll. +CREATE AGGREGATE hll_add_agg (hll_hashval, integer) ( + SFUNC = hll_add_trans1, + STYPE = internal, + FINALFUNC = hll_pack +); + +-- Add aggregate function, returns hll. +CREATE AGGREGATE hll_add_agg (hll_hashval, integer, integer) ( + SFUNC = hll_add_trans2, + STYPE = internal, + FINALFUNC = hll_pack +); + +-- Add aggregate function, returns hll. +CREATE AGGREGATE hll_add_agg (hll_hashval, integer, integer, bigint) ( + SFUNC = hll_add_trans3, + STYPE = internal, + FINALFUNC = hll_pack +); + +-- Add aggregate function, returns hll. +CREATE AGGREGATE hll_add_agg (hll_hashval, integer, integer, bigint, integer) ( + SFUNC = hll_add_trans4, + STYPE = internal, + FINALFUNC = hll_pack +); diff --git a/external/hll/update/hll--2.11--2.12.sql b/external/hll/update/hll--2.11--2.12.sql new file mode 100644 index 00000000000..ccbbd2ecd08 --- /dev/null +++ b/external/hll/update/hll--2.11--2.12.sql @@ -0,0 +1 @@ +-- Empty upgrade file to upgrade extension from 2.11 to 2.12 diff --git a/external/hll/update/hll--2.12--2.13.sql b/external/hll/update/hll--2.12--2.13.sql new file mode 100644 index 00000000000..46c9e1f0752 --- /dev/null +++ b/external/hll/update/hll--2.12--2.13.sql @@ -0,0 +1 @@ +-- Empty upgrade file to upgrade extension from 2.12 to 2.13 diff --git a/external/hll/update/hll--2.13--2.14.sql b/external/hll/update/hll--2.13--2.14.sql new file mode 100644 index 00000000000..850123b23f2 --- /dev/null +++ b/external/hll/update/hll--2.13--2.14.sql @@ -0,0 +1 @@ +-- Empty upgrade file to upgrade extension from 2.13 to 2.14 diff --git a/external/hll/update/hll--2.14--2.15.sql b/external/hll/update/hll--2.14--2.15.sql new file mode 100644 index 00000000000..a9c736cd001 --- /dev/null +++ b/external/hll/update/hll--2.14--2.15.sql @@ -0,0 +1,143 @@ +#if PG_VERSION_NUM < 100000 +#define IFPARALLEL(...) +#else +#define IFPARALLEL(...) __VA_ARGS__ +#endif + +CREATE FUNCTION hll_serialize(internal) +RETURNS bytea +AS 'MODULE_PATHNAME' +LANGUAGE C STRICT IMMUTABLE IFPARALLEL(PARALLEL SAFE); + +CREATE FUNCTION hll_deserialize(bytea, internal) +RETURNS internal +AS 'MODULE_PATHNAME' +LANGUAGE C STRICT IMMUTABLE IFPARALLEL(PARALLEL SAFE); + +CREATE FUNCTION hll_union_internal(internal, internal) +RETURNS internal +AS 'MODULE_PATHNAME' +LANGUAGE C IFPARALLEL(PARALLEL SAFE); + +IFPARALLEL( +ALTER FUNCTION hll_in(cstring, oid, integer) PARALLEL SAFE; +ALTER FUNCTION hll_out(hll) PARALLEL SAFE; +ALTER FUNCTION hll_recv(internal) PARALLEL SAFE; +ALTER FUNCTION hll_send(hll) PARALLEL SAFE; +ALTER FUNCTION hll_typmod_in(cstring[]) PARALLEL SAFE; +ALTER FUNCTION hll_typmod_out(integer) PARALLEL SAFE; +ALTER FUNCTION hll(hll, integer, boolean) PARALLEL SAFE; +ALTER FUNCTION hll_hashval_in(cstring, oid, integer) PARALLEL SAFE; +ALTER FUNCTION hll_hashval_out(hll_hashval) PARALLEL SAFE; +ALTER FUNCTION hll_hashval_eq(hll_hashval, hll_hashval) PARALLEL SAFE; +ALTER FUNCTION hll_hashval_ne(hll_hashval, hll_hashval) PARALLEL SAFE; +ALTER FUNCTION hll_hashval(bigint) PARALLEL SAFE; +ALTER FUNCTION hll_hashval_int4(integer) PARALLEL SAFE; +ALTER FUNCTION hll_eq(hll, hll) PARALLEL SAFE; +ALTER FUNCTION hll_ne(hll, hll) PARALLEL SAFE; +ALTER FUNCTION hll_cardinality(hll) PARALLEL SAFE; +ALTER FUNCTION hll_union(hll, hll) PARALLEL SAFE; +ALTER FUNCTION hll_add(hll, hll_hashval) PARALLEL SAFE; +ALTER FUNCTION hll_add_rev(hll_hashval, hll) PARALLEL SAFE; +ALTER FUNCTION hll_print(hll) PARALLEL SAFE; +ALTER FUNCTION hll_empty() PARALLEL SAFE; +ALTER FUNCTION hll_empty(integer) PARALLEL SAFE; +ALTER FUNCTION hll_empty(integer, integer) PARALLEL SAFE; +ALTER FUNCTION hll_empty(integer, integer, bigint) PARALLEL SAFE; +ALTER FUNCTION hll_empty(integer, integer, bigint, integer) PARALLEL SAFE; +ALTER FUNCTION hll_schema_version(hll) PARALLEL SAFE; +ALTER FUNCTION hll_type(hll) PARALLEL SAFE; +ALTER FUNCTION hll_log2m(hll) PARALLEL SAFE; +ALTER FUNCTION hll_regwidth(hll) PARALLEL SAFE; +ALTER FUNCTION hll_expthresh(hll, OUT specified bigint, OUT effective bigint) PARALLEL SAFE; +ALTER FUNCTION hll_sparseon(hll) PARALLEL SAFE; +ALTER FUNCTION hll_hash_boolean(boolean, integer) PARALLEL SAFE; +ALTER FUNCTION hll_hash_smallint(smallint, integer) PARALLEL SAFE; +ALTER FUNCTION hll_hash_integer(integer, integer) PARALLEL SAFE; +ALTER FUNCTION hll_hash_bigint(bigint, integer) PARALLEL SAFE; +ALTER FUNCTION hll_hash_bytea(bytea, integer) PARALLEL SAFE; +ALTER FUNCTION hll_hash_text(text, integer) PARALLEL SAFE; +ALTER FUNCTION hll_hash_any(anyelement, integer) PARALLEL SAFE; +ALTER FUNCTION hll_union_trans(internal, hll) PARALLEL SAFE; +ALTER FUNCTION hll_add_trans4 PARALLEL SAFE; +ALTER FUNCTION hll_add_trans3 PARALLEL SAFE; +ALTER FUNCTION hll_add_trans2 PARALLEL SAFE; +ALTER FUNCTION hll_add_trans1 PARALLEL SAFE; +ALTER FUNCTION hll_add_trans0 PARALLEL SAFE; +ALTER FUNCTION hll_pack(internal) PARALLEL SAFE; +ALTER FUNCTION hll_card_unpacked(internal) PARALLEL SAFE; +ALTER FUNCTION hll_floor_card_unpacked(internal) PARALLEL SAFE; +ALTER FUNCTION hll_ceil_card_unpacked(internal) PARALLEL SAFE; + +DROP AGGREGATE hll_union_agg (hll); +DROP AGGREGATE hll_add_agg (hll_hashval); +DROP AGGREGATE hll_add_agg (hll_hashval, integer); +DROP AGGREGATE hll_add_agg (hll_hashval, integer, integer); +DROP AGGREGATE hll_add_agg (hll_hashval, integer, integer, bigint); +DROP AGGREGATE hll_add_agg (hll_hashval, integer, integer, bigint, integer); + +CREATE AGGREGATE hll_union_agg (hll) ( + SFUNC = hll_union_trans, + STYPE = internal, + FINALFUNC = hll_pack, + COMBINEFUNC = hll_union_internal, + SERIALFUNC = hll_serialize, + DESERIALFUNC = hll_deserialize, + PARALLEL = SAFE +); + +CREATE AGGREGATE hll_add_agg (hll_hashval) ( + SFUNC = hll_add_trans0, + STYPE = internal, + SSPACE = 131120, + FINALFUNC = hll_pack, + COMBINEFUNC = hll_union_internal, + SERIALFUNC = hll_serialize, + DESERIALFUNC = hll_deserialize, + PARALLEL = SAFE +); + +CREATE AGGREGATE hll_add_agg (hll_hashval, integer) ( + SFUNC = hll_add_trans1, + STYPE = internal, + SSPACE = 131120, + FINALFUNC = hll_pack, + COMBINEFUNC = hll_union_internal, + SERIALFUNC = hll_serialize, + DESERIALFUNC = hll_deserialize, + PARALLEL = SAFE +); + +CREATE AGGREGATE hll_add_agg (hll_hashval, integer, integer) ( + SFUNC = hll_add_trans2, + STYPE = internal, + SSPACE = 131120, + FINALFUNC = hll_pack, + COMBINEFUNC = hll_union_internal, + SERIALFUNC = hll_serialize, + DESERIALFUNC = hll_deserialize, + PARALLEL = SAFE +); + +CREATE AGGREGATE hll_add_agg (hll_hashval, integer, integer, bigint) ( + SFUNC = hll_add_trans3, + STYPE = internal, + SSPACE = 131120, + FINALFUNC = hll_pack, + COMBINEFUNC = hll_union_internal, + SERIALFUNC = hll_serialize, + DESERIALFUNC = hll_deserialize, + PARALLEL = SAFE +); + +CREATE AGGREGATE hll_add_agg (hll_hashval, integer, integer, bigint, integer) ( + SFUNC = hll_add_trans4, + STYPE = internal, + SSPACE = 131120, + FINALFUNC = hll_pack, + COMBINEFUNC = hll_union_internal, + SERIALFUNC = hll_serialize, + DESERIALFUNC = hll_deserialize, + PARALLEL = SAFE +); +) diff --git a/external/hll/update/hll--2.15--2.16.sql b/external/hll/update/hll--2.15--2.16.sql new file mode 100644 index 00000000000..24e0616b5ca --- /dev/null +++ b/external/hll/update/hll--2.15--2.16.sql @@ -0,0 +1 @@ +-- Empty upgrade file to upgrade extension from 2.15 to 2.16 diff --git a/external/hll/update/hll--2.16--2.17.sql b/external/hll/update/hll--2.16--2.17.sql new file mode 100644 index 00000000000..b1af672a7dd --- /dev/null +++ b/external/hll/update/hll--2.16--2.17.sql @@ -0,0 +1 @@ +-- Empty upgrade file to upgrade extension from 2.16 to 2.17 diff --git a/external/hll/update/hll--2.17--2.18.sql b/external/hll/update/hll--2.17--2.18.sql new file mode 100644 index 00000000000..b1af672a7dd --- /dev/null +++ b/external/hll/update/hll--2.17--2.18.sql @@ -0,0 +1 @@ +-- Empty upgrade file to upgrade extension from 2.16 to 2.17 diff --git a/external/pase/Makefile b/external/pase/Makefile index d5a15a54ea5..09837e4a1da 100644 --- a/external/pase/Makefile +++ b/external/pase/Makefile @@ -3,7 +3,7 @@ OBJS = $(patsubst %.c,%.o,$(wildcard type/*.c hnsw/*.c *.c ivfflat/*.c utils/*.c MODULE_big = $(EXTENSION) PG_LDFLAGS = -fopenmp -PG_CPPFLAGS = -fopenmp +PG_CPPFLAGS = -fopenmp -Wno-uninitialized PG_LIBS = -fopenmp DATA = pase--0.0.1.sql PGFILEDESC = "pase - ai similarity search" diff --git a/external/polar_worker/test_read_core_pattern.c b/external/polar_worker/test_read_core_pattern.c index 5840f798759..c9cc58b5980 100644 --- a/external/polar_worker/test_read_core_pattern.c +++ b/external/polar_worker/test_read_core_pattern.c @@ -51,12 +51,14 @@ test_core_pattern_path(void) char core_pattern_path[MAXPGPATH] = {0}; char cwd[MAXPGPATH] = {0}; - getcwd(cwd, MAXPGPATH); + if (!getcwd(cwd, MAXPGPATH)) + exit(EXIT_FAILURE); snprintf(core_pattern_path, MAXPGPATH, "%s/polar_test_core_pattern", cwd); /* case1 */ fd = open(core_pattern_path, O_CREAT | O_WRONLY | PG_BINARY, pg_file_create_mode); - write(fd, &core_pattern, sizeof(core_pattern)); + if (write(fd, &core_pattern, sizeof(core_pattern)) != sizeof(core_pattern)) + exit(EXIT_FAILURE); close(fd); polar_read_core_pattern(core_pattern_path, core_file_path_temp); Assert(!strcmp(core_file_path_temp, cwd)); @@ -64,7 +66,8 @@ test_core_pattern_path(void) /* case2 */ fd = open(core_pattern_path, O_CREAT | O_WRONLY | PG_BINARY, pg_file_create_mode); snprintf(core_pattern, MAXPGPATH, "core"); - write(fd, &core_pattern, sizeof(core_pattern)); + if (write(fd, &core_pattern, sizeof(core_pattern)) != sizeof(core_pattern)) + exit(EXIT_FAILURE); close(fd); polar_read_core_pattern(core_pattern_path, core_file_path_temp); Assert(!strcmp(core_file_path_temp, cwd)); @@ -72,7 +75,8 @@ test_core_pattern_path(void) /* case3 */ fd = open(core_pattern_path, O_CREAT | O_WRONLY | PG_BINARY, pg_file_create_mode); snprintf(core_pattern, MAXPGPATH, "corefile/core"); - write(fd, &core_pattern, sizeof(core_pattern)); + if (write(fd, &core_pattern, sizeof(core_pattern)) != sizeof(core_pattern)) + exit(EXIT_FAILURE); close(fd); polar_read_core_pattern(core_pattern_path, core_file_path_temp); snprintf(core_file_target, MAXPGPATH, "%s/corefile/", cwd); @@ -81,7 +85,8 @@ test_core_pattern_path(void) /* case4 */ fd = open(core_pattern_path, O_CREAT | O_WRONLY | PG_BINARY, pg_file_create_mode); snprintf(core_pattern, MAXPGPATH, "/tmp/corefile/core"); - write(fd, &core_pattern, sizeof(core_pattern)); + if (write(fd, &core_pattern, sizeof(core_pattern)) != sizeof(core_pattern)) + exit(EXIT_FAILURE); close(fd); polar_read_core_pattern(core_pattern_path, core_file_path_temp); snprintf(core_file_target, MAXPGPATH, "/tmp/corefile/"); diff --git a/src/backend/access/logindex/polar_heap_idx.c b/src/backend/access/logindex/polar_heap_idx.c index fea901a0cb1..3753ed6d667 100644 --- a/src/backend/access/logindex/polar_heap_idx.c +++ b/src/backend/access/logindex/polar_heap_idx.c @@ -802,7 +802,7 @@ polar_heap_xlog_lock_updated(XLogReaderState *record, BufferTag *tag, Buffer *bu if (PageGetMaxOffsetNumber(page) >= offnum) lp = PageGetItemId(page, offnum); - if (PageGetMaxOffsetNumber(page) < offnum || !lp || !ItemIdIsNormal(lp)) + if (PageGetMaxOffsetNumber(page) < offnum || !ItemIdIsNormal(lp)) { POLAR_LOG_REDO_INFO(page, record); elog(PANIC, "invalid lp: page_max_off=%ld, offnum=%d, lp=%d", @@ -981,7 +981,7 @@ polar_heap_xlog_delete(XLogReaderState *record, BufferTag *tag, Buffer *buffer) if (PageGetMaxOffsetNumber(page) >= xlrec->offnum) lp = PageGetItemId(page, xlrec->offnum); - if (PageGetMaxOffsetNumber(page) < xlrec->offnum || !lp || !ItemIdIsNormal(lp)) + if (PageGetMaxOffsetNumber(page) < xlrec->offnum || !ItemIdIsNormal(lp)) { POLAR_LOG_REDO_INFO(page, record); elog(PANIC, "invalid lp: page_max_off=%ld, offnum=%d, lp=%d", @@ -1161,7 +1161,7 @@ polar_heap_xlog_update(XLogReaderState *record, BufferTag *tag, Buffer *buffer, if (PageGetMaxOffsetNumber(page) >= offnum) lp = PageGetItemId(page, offnum); - if (PageGetMaxOffsetNumber(page) < offnum || !lp || !ItemIdIsNormal(lp)) + if (PageGetMaxOffsetNumber(page) < offnum || !ItemIdIsNormal(lp)) { POLAR_LOG_REDO_INFO(page, record); elog(PANIC, "invalid lp: page_max_off=%ld, offnum=%d, lp=%d", @@ -1395,7 +1395,7 @@ polar_heap_xlog_confirm(XLogReaderState *record, BufferTag *tag, Buffer *buffer) if (PageGetMaxOffsetNumber(page) >= offnum) lp = PageGetItemId(page, offnum); - if (PageGetMaxOffsetNumber(page) < offnum || !lp || !ItemIdIsNormal(lp)) + if (PageGetMaxOffsetNumber(page) < offnum || !ItemIdIsNormal(lp)) { POLAR_LOG_REDO_INFO(page, record); elog(PANIC, "invalid lp: page_max_off=%ld, offnum=%d, lp=%d", @@ -1453,7 +1453,7 @@ polar_heap_xlog_lock(XLogReaderState *record, BufferTag *tag, Buffer *buffer) if (PageGetMaxOffsetNumber(page) >= offnum) lp = PageGetItemId(page, offnum); - if (PageGetMaxOffsetNumber(page) < offnum || !lp || !ItemIdIsNormal(lp)) + if (PageGetMaxOffsetNumber(page) < offnum || !ItemIdIsNormal(lp)) { POLAR_LOG_REDO_INFO(page, record); elog(PANIC, "invalid lp: page_max_off=%ld, offnum=%d, lp=%d", @@ -1521,7 +1521,7 @@ polar_heap_xlog_inplace(XLogReaderState *record, BufferTag *tag, Buffer *buffer) if (PageGetMaxOffsetNumber(page) >= offnum) lp = PageGetItemId(page, offnum); - if (PageGetMaxOffsetNumber(page) < offnum || !lp || !ItemIdIsNormal(lp)) + if (PageGetMaxOffsetNumber(page) < offnum || !ItemIdIsNormal(lp)) { POLAR_LOG_REDO_INFO(page, record); elog(PANIC, "invalid lp: page_max_off=%ld, offnum=%d, lp=%d", diff --git a/src/test/perl/PostgreSQL/Test/Cluster.pm b/src/test/perl/PostgreSQL/Test/Cluster.pm index 5f517ee3044..382e531f7b7 100644 --- a/src/test/perl/PostgreSQL/Test/Cluster.pm +++ b/src/test/perl/PostgreSQL/Test/Cluster.pm @@ -3809,14 +3809,14 @@ sub stop_child if ($pid eq 0) { - note "child $process_name's pid is 0!\n"; + note "child $process_name\'s pid is 0!\n"; return; } PostgreSQL::Test::Utils::system_or_bail('kill', '-19', $pid); my ($out, $err) = $self->run_command([ 'which', 'pstack' ]); - if ($err =~ qr/which:\s*no\s+pstack\s+in/i) + if ($err =~ qr/which:\s*no\s+pstack\s+in/i || (!$out && !$err)) { note "There's no pstack command!\n"; return;