Skip to content

Commit 17a19e6

Browse files
author
Timon Karnezos
committed
Added documentation for hll_hash_any. Fixed formatting issues in documentation.
1 parent e512d00 commit 17a19e6

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

README.markdown

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,19 @@ The hashing functions we've made available are listed below:
240240
<code>hll_hash_text('foobar', 123/*hash seed*/)</code>
241241
</td>
242242
</tr>
243+
<tr>
244+
<td><code>hll_hash_any</code></td>
245+
<td><code>any</code></td>
246+
<td>
247+
<code>hll_hash_any(anyval)</code><br/>
248+
<strong>or</strong><br/>
249+
<code>hll_hash_any(anyval, 123/*hash seed*/)</code>
250+
</td>
251+
</tr>
243252
</table>
244253

254+
**NOTE:** `hll_hash_any` dynamically dispatches to the appropriate type-specific function, which makes it slower than the type-specific ones it wraps. Use it only when the input type is not known beforehand.
255+
245256
So what if you don't want to hash your input?
246257

247258
postgres=# select 1234 || hll_empty();

REFERENCE.markdown

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
11
Types
22
=====
33

4-
`hll` - the HLL data structure. Casts between `bytea` and `hll` are supported, should you choose to generate the contents of the `hll` outside of the normal means. See `STORAGE.markdown`.
4+
`hll`
5+
-----
6+
7+
The HLL data structure. Casts between `bytea` and `hll` are supported, should you choose to generate the contents of the `hll` outside of the normal means. See `STORAGE.markdown`.
8+
9+
`SELECT hll_cardinality(E'\\xDEADBEEF');`
10+
11+
OR
512

6-
`SELECT hll_cardinality(E'\\xDEADBEEF');` OR
713
`SELECT hll_cardinality(E'\\xDEADBEEF'::hll);`
814

9-
`hll_hashval` - represents a hashed data value. Backed by a 64-bit integer (`int8in`). Typically only output by the `hll_hash_*` functions. `bigint` and `integer` can both be cast to it if you want to skip hashing those values with the typical `123::hll_hashval`. Note that an `integer` that is cast will also be cast, with sign extension, to a 64-bit integer.
15+
`hll_hashval`
16+
-------------
17+
18+
Represents a hashed data value. Backed by a 64-bit integer (`int8in`). Typically only output by the `hll_hash_*` functions. `bigint` and `integer` can both be cast to it if you want to skip hashing those values with the typical `123::hll_hashval`. Note that an `integer` that is cast will also be cast, with sign extension, to a 64-bit integer.
1019

1120
Defaults Functions
1221
==================
1322

1423
All defaults for the `hll_empty` and `hll_add_agg` functions are in the C file, not in the SQL control file. The defaults can be changed (per connection) with:
1524

16-
`SELECT hll_set_defaults(log2m, regwidth, expthresh, sparseon);` - returns a 4-tuple with the values of the prior defaults in the same order as the arguments.
25+
`SELECT hll_set_defaults(log2m, regwidth, expthresh, sparseon);`
26+
27+
This returns a 4-tuple with the values of the prior defaults in the same order as the arguments.
1728

1829
Basic Operational Functions
1930
===========================
@@ -70,8 +81,15 @@ All values inserted into an `hll` should be hashed, and as a result `hll_add` an
7081
All the `hll_hash_*` functions below accept a seed value, which defaults to `0`. We discourage negative seeds in order to maintain hashed-value compatibility with the [Google Guava implementation of the 128-bit version of Murmur3](http://guava-libraries.googlecode.com/git/guava/src/com/google/common/hash/Murmur3_128HashFunction.java). Negative hash seeds will produce a warning when used.
7182

7283
`hll_hash_boolean(boolean)` - hashes the `boolean` value into a `hll_hashval`.
84+
7385
`hll_hash_smallint(smallint)` - hashes the `smallint` value into a `hll_hashval`.
86+
7487
`hll_hash_integer(integer)` - hashes the `integer` value into a `hll_hashval`.
88+
7589
`hll_hash_bigint(bigint)` - hashes the `bigint` value into a `hll_hashval`.
90+
7691
`hll_hash_bytea(bytea)` - hashes the `bytea` value into a `hll_hashval`.
77-
`hll_hash_text(text)` - hashes the `text` value into a `hll_hashval`.
92+
93+
`hll_hash_text(text)` - hashes the `text` value into a `hll_hashval`.
94+
95+
`hll_hash_any(scalar)` - hashes any PG data type by resolving the type dynamically and dispatching to the correct function for that type. This is significantly slower than the type-specific hash functions, and should only be used when the input type is not known beforehand.

0 commit comments

Comments
 (0)