mirror of
https://github.com/postgres/postgres.git
synced 2025-07-05 07:21:24 +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:
26
src/backend/utils/cache/relcache.c
vendored
26
src/backend/utils/cache/relcache.c
vendored
@ -30,6 +30,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "access/hash.h"
|
||||
#include "access/htup_details.h"
|
||||
#include "access/multixact.h"
|
||||
#include "access/nbtree.h"
|
||||
@ -833,6 +834,7 @@ RelationBuildPartitionKey(Relation relation)
|
||||
Datum datum;
|
||||
MemoryContext partkeycxt,
|
||||
oldcxt;
|
||||
int16 procnum;
|
||||
|
||||
tuple = SearchSysCache1(PARTRELID,
|
||||
ObjectIdGetDatum(RelationGetRelid(relation)));
|
||||
@ -912,6 +914,10 @@ RelationBuildPartitionKey(Relation relation)
|
||||
key->parttypalign = (char *) palloc0(key->partnatts * sizeof(char));
|
||||
key->parttypcoll = (Oid *) palloc0(key->partnatts * sizeof(Oid));
|
||||
|
||||
/* For the hash partitioning, an extended hash function will be used. */
|
||||
procnum = (key->strategy == PARTITION_STRATEGY_HASH) ?
|
||||
HASHEXTENDED_PROC : BTORDER_PROC;
|
||||
|
||||
/* Copy partattrs and fill other per-attribute info */
|
||||
memcpy(key->partattrs, attrs, key->partnatts * sizeof(int16));
|
||||
partexprs_item = list_head(key->partexprs);
|
||||
@ -932,18 +938,20 @@ RelationBuildPartitionKey(Relation relation)
|
||||
key->partopfamily[i] = opclassform->opcfamily;
|
||||
key->partopcintype[i] = opclassform->opcintype;
|
||||
|
||||
/*
|
||||
* A btree support function covers the cases of list and range methods
|
||||
* currently supported.
|
||||
*/
|
||||
/* Get a support function for the specified opfamily and datatypes */
|
||||
funcid = get_opfamily_proc(opclassform->opcfamily,
|
||||
opclassform->opcintype,
|
||||
opclassform->opcintype,
|
||||
BTORDER_PROC);
|
||||
if (!OidIsValid(funcid)) /* should not happen */
|
||||
elog(ERROR, "missing support function %d(%u,%u) in opfamily %u",
|
||||
BTORDER_PROC, opclassform->opcintype, opclassform->opcintype,
|
||||
opclassform->opcfamily);
|
||||
procnum);
|
||||
if (!OidIsValid(funcid))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
|
||||
errmsg("operator class \"%s\" of access method %s is missing support function %d for data type \"%s\"",
|
||||
NameStr(opclassform->opcname),
|
||||
(key->strategy == PARTITION_STRATEGY_HASH) ?
|
||||
"hash" : "btree",
|
||||
procnum,
|
||||
format_type_be(opclassform->opcintype))));
|
||||
|
||||
fmgr_info(funcid, &key->partsupfunc[i]);
|
||||
|
||||
|
Reference in New Issue
Block a user