diff --git a/src/executor.c b/src/executor.c index 810df614e..7e7621b3a 100644 --- a/src/executor.c +++ b/src/executor.c @@ -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); diff --git a/src/gpu_join.c b/src/gpu_join.c index 4b28c409d..4802f0a82 100644 --- a/src/gpu_join.c +++ b/src/gpu_join.c @@ -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; diff --git a/src/xpu_common.cu b/src/xpu_common.cu index 9c501586c..f96b4d254 100644 --- a/src/xpu_common.cu +++ b/src/xpu_common.cu @@ -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; diff --git a/src/xpu_common.h b/src/xpu_common.h index 58db708ae..38cb7b5bd 100644 --- a/src/xpu_common.h +++ b/src/xpu_common.h @@ -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; +} /* ---------------------------------------------------------------- *