Skip to main content

MODULARHASH

  • February 24, 2018
  • 1 reply
  • 5 views

crowe

I see that the MODULARHASH function is no longer in the docs, but the DBD still uses it and it is not in the deprecated functionality list. Anyone know that fate of MODULARHASH?

1 reply

Ben_Vandiver
Forum|alt.badge.img
  • Participating Frequently
  • February 27, 2018

I believe that any instance of MODULARHASH() that appears in a projection segmentation clause is silently rewritten to HASH():
bvandiver=> create table foo (a int);
CREATE TABLE
bvandiver=> create projection foop as select * from foo segmented by modularhash(a) all nodes;
CREATE PROJECTION
bvandiver=> select projection_name,segment_expression from projections;
projection_name | segment_expression
-----------------+--------------------
foop | hash(foo.a)
(1 row)

Really ancient databases might not do this (created prior to 5.0).

If you use modularhash elsewhere, I suspect it still works as modularhash:
bvandiver=> explain select sum(a) from foo group by modularhash(a) % 4;


QUERY PLAN DESCRIPTION:


explain select sum(a) from foo group by modularhash(a) % 4;

Access Path:
+-GROUPBY HASH (GLOBAL RESEGMENT GROUPS) (LOCAL RESEGMENT GROUPS) [Cost: 265, Rows: 10K (NO STATISTICS)] (PATH ID: 1)
| Aggregates: sum(foo.a)
| Group By: (modularhash_internal(foo.a) % 4)
| Execute on: All Nodes
| +---> STORAGE ACCESS for foo [Cost: 202, Rows: 10K (NO STATISTICS)] (PATH ID: 2)
| | Projection: public.foop
| | Materialize: foo.a
| | Execute on: All Nodes

I don’t see where DBD uses modularhash()