Skip to content

Commit

Permalink
Reduction of hash conflicts on GpuPreAgg
Browse files Browse the repository at this point in the history
It might invalidate hash-distribution if same values are given.
  • Loading branch information
kaigai committed Mar 17, 2024
1 parent 01e685a commit db68e60
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/executor.c
Original file line number Diff line number Diff line change
Expand Up @@ -650,8 +650,15 @@ pgstromBuildSessionInfo(pgstromTaskState *pts,
pp_info->kexp_groupby_keyload &&
pp_info->kexp_groupby_keycomp)
{
double n_groups = pts->css.ss.ps.plan->plan_rows;

format = KDS_FORMAT_HASH;
hash_nslots = 20000; //to be estimated using num_groups
if (n_groups <= 5000.0)
hash_nslots = 20000;
else if (n_groups <= 4000000.0)
hash_nslots = 20000 + (int)(2.0 * n_groups);
else
hash_nslots = 8020000 + n_groups;
kds_length = (1UL << 30); /* 1GB */
}
setup_kern_data_store(kds_temp, groupby_tdesc_final, kds_length, format);
Expand Down
2 changes: 1 addition & 1 deletion src/gpu_join.c
Original file line number Diff line number Diff line change
Expand Up @@ -1747,7 +1747,7 @@ get_tuple_hashvalue(pgstromTaskInnerState *istate,
bool isnull;

datum = ExecEvalExpr(es, econtext, &isnull);
hash ^= h_func(isnull, datum);
hash = pg_hash_merge(hash, h_func(isnull, datum));
}
hash ^= 0xffffffffU;

Expand Down
2 changes: 1 addition & 1 deletion src/xpu_common.cu
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,7 @@ pgfn_HashValue(XPU_PGFUNCTION_ARGS)
{
if (!expr_ops->xpu_datum_hash(kcxt, &__hash, datum))
return false;
hash ^= __hash;
hash = pg_hash_merge(hash, __hash);
}
}
hash ^= 0xffffffffU;
Expand Down
5 changes: 5 additions & 0 deletions src/xpu_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -2941,6 +2941,11 @@ EXTERN_FUNCTION(void)
pg_kern_ereport(kern_context *kcxt); /* only host code */
EXTERN_FUNCTION(uint32_t)
pg_hash_any(const void *ptr, int sz);
INLINE_FUNCTION(uint32_t)
pg_hash_merge(uint32_t hash_prev, uint32_t hash_next)
{
return ((hash_prev >> 3) | (hash_prev << 29)) ^ hash_next;
}

/* ----------------------------------------------------------------
*
Expand Down

0 comments on commit db68e60

Please sign in to comment.