mirror of
https://github.com/postgres/postgres.git
synced 2025-06-17 17:02:08 +03:00
Add hash partitioning.
Hash partitioning is useful when you want to partition a growing data set evenly. This can be useful to keep table sizes reasonable, which makes maintenance operations such as VACUUM faster, or to enable partition-wise join. At present, we still depend on constraint exclusion for partitioning pruning, and the shape of the partition constraints for hash partitioning is such that that doesn't work. Work is underway to fix that, which should both improve performance and make partitioning pruning work with hash partitioning. Amul Sul, reviewed and tested by Dilip Kumar, Ashutosh Bapat, Yugo Nagata, Rajkumar Raghuwanshi, Jesper Pedersen, and by me. A few final tweaks also by me. Discussion: http://postgr.es/m/CAAJ_b96fhpJAP=ALbETmeLk1Uni_GFZD938zgenhF49qgDTjaQ@mail.gmail.com
This commit is contained in:
@ -3310,6 +3310,11 @@ transformPartitionBound(ParseState *pstate, Relation parent,
|
||||
|
||||
if (spec->is_default)
|
||||
{
|
||||
if (strategy == PARTITION_STRATEGY_HASH)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_TABLE_DEFINITION),
|
||||
errmsg("a hash-partitioned table may not have a default partition")));
|
||||
|
||||
/*
|
||||
* In case of the default partition, parser had no way to identify the
|
||||
* partition strategy. Assign the parent's strategy to the default
|
||||
@ -3320,7 +3325,27 @@ transformPartitionBound(ParseState *pstate, Relation parent,
|
||||
return result_spec;
|
||||
}
|
||||
|
||||
if (strategy == PARTITION_STRATEGY_LIST)
|
||||
if (strategy == PARTITION_STRATEGY_HASH)
|
||||
{
|
||||
if (spec->strategy != PARTITION_STRATEGY_HASH)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_TABLE_DEFINITION),
|
||||
errmsg("invalid bound specification for a hash partition"),
|
||||
parser_errposition(pstate, exprLocation((Node *) spec))));
|
||||
|
||||
if (spec->modulus <= 0)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_TABLE_DEFINITION),
|
||||
errmsg("modulus for hash partition must be a positive integer")));
|
||||
|
||||
Assert(spec->remainder >= 0);
|
||||
|
||||
if (spec->remainder >= spec->modulus)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_TABLE_DEFINITION),
|
||||
errmsg("remainder for hash partition must be less than modulus")));
|
||||
}
|
||||
else if (strategy == PARTITION_STRATEGY_LIST)
|
||||
{
|
||||
ListCell *cell;
|
||||
char *colname;
|
||||
@ -3485,7 +3510,7 @@ transformPartitionBound(ParseState *pstate, Relation parent,
|
||||
static void
|
||||
validateInfiniteBounds(ParseState *pstate, List *blist)
|
||||
{
|
||||
ListCell *lc;
|
||||
ListCell *lc;
|
||||
PartitionRangeDatumKind kind = PARTITION_RANGE_DATUM_VALUE;
|
||||
|
||||
foreach(lc, blist)
|
||||
|
Reference in New Issue
Block a user