mirror of
https://github.com/postgres/postgres.git
synced 2025-11-04 20:11:56 +03:00
Implement table partitioning.
Table partitioning is like table inheritance and reuses much of the existing infrastructure, but there are some important differences. The parent is called a partitioned table and is always empty; it may not have indexes or non-inherited constraints, since those make no sense for a relation with no data of its own. The children are called partitions and contain all of the actual data. Each partition has an implicit partitioning constraint. Multiple inheritance is not allowed, and partitioning and inheritance can't be mixed. Partitions can't have extra columns and may not allow nulls unless the parent does. Tuples inserted into the parent are automatically routed to the correct partition, so tuple-routing ON INSERT triggers are not needed. Tuple routing isn't yet supported for partitions which are foreign tables, and it doesn't handle updates that cross partition boundaries. Currently, tables can be range-partitioned or list-partitioned. List partitioning is limited to a single column, but range partitioning can involve multiple columns. A partitioning "column" can be an expression. Because table partitioning is less general than table inheritance, it is hoped that it will be easier to reason about properties of partitions, and therefore that this will serve as a better foundation for a variety of possible optimizations, including query planner optimizations. The tuple routing based which this patch does based on the implicit partitioning constraints is an example of this, but it seems likely that many other useful optimizations are also possible. Amit Langote, reviewed and tested by Robert Haas, Ashutosh Bapat, Amit Kapila, Rajkumar Raghuwanshi, Corey Huinker, Jaime Casanova, Rushabh Lathia, Erik Rijkers, among others. Minor revisions by me.
This commit is contained in:
@@ -699,6 +699,79 @@ typedef struct XmlSerialize
|
||||
int location; /* token location, or -1 if unknown */
|
||||
} XmlSerialize;
|
||||
|
||||
/* Partitioning related definitions */
|
||||
|
||||
/*
|
||||
* PartitionElem - a column in the partition key
|
||||
*/
|
||||
typedef struct PartitionElem
|
||||
{
|
||||
NodeTag type;
|
||||
char *name; /* name of column to partition on, or NULL */
|
||||
Node *expr; /* expression to partition on, or NULL */
|
||||
List *collation; /* name of collation; NIL = default */
|
||||
List *opclass; /* name of desired opclass; NIL = default */
|
||||
int location; /* token location, or -1 if unknown */
|
||||
} PartitionElem;
|
||||
|
||||
/*
|
||||
* PartitionSpec - partition key specification
|
||||
*/
|
||||
typedef struct PartitionSpec
|
||||
{
|
||||
NodeTag type;
|
||||
char *strategy; /* partitioning strategy ('list' or 'range') */
|
||||
List *partParams; /* List of PartitionElems */
|
||||
int location; /* token location, or -1 if unknown */
|
||||
} PartitionSpec;
|
||||
|
||||
#define PARTITION_STRATEGY_LIST 'l'
|
||||
#define PARTITION_STRATEGY_RANGE 'r'
|
||||
|
||||
/*
|
||||
* PartitionBoundSpec - a partition bound specification
|
||||
*/
|
||||
typedef struct PartitionBoundSpec
|
||||
{
|
||||
NodeTag type;
|
||||
|
||||
char strategy;
|
||||
|
||||
/* List partition values */
|
||||
List *listdatums;
|
||||
|
||||
/*
|
||||
* Range partition lower and upper bounds; each member of the lists
|
||||
* is a PartitionRangeDatum (see below).
|
||||
*/
|
||||
List *lowerdatums;
|
||||
List *upperdatums;
|
||||
|
||||
int location;
|
||||
} PartitionBoundSpec;
|
||||
|
||||
/*
|
||||
* PartitionRangeDatum
|
||||
*/
|
||||
typedef struct PartitionRangeDatum
|
||||
{
|
||||
NodeTag type;
|
||||
|
||||
bool infinite;
|
||||
Node *value;
|
||||
|
||||
int location;
|
||||
} PartitionRangeDatum;
|
||||
|
||||
/*
|
||||
* PartitionCmd - ALTER TABLE partition commands
|
||||
*/
|
||||
typedef struct PartitionCmd
|
||||
{
|
||||
NodeTag type;
|
||||
RangeVar *name;
|
||||
Node *bound;
|
||||
} PartitionCmd;
|
||||
|
||||
/****************************************************************************
|
||||
* Nodes for a Query tree
|
||||
@@ -1549,7 +1622,9 @@ typedef enum AlterTableType
|
||||
AT_DisableRowSecurity, /* DISABLE ROW SECURITY */
|
||||
AT_ForceRowSecurity, /* FORCE ROW SECURITY */
|
||||
AT_NoForceRowSecurity, /* NO FORCE ROW SECURITY */
|
||||
AT_GenericOptions /* OPTIONS (...) */
|
||||
AT_GenericOptions, /* OPTIONS (...) */
|
||||
AT_AttachPartition, /* ATTACH PARTITION */
|
||||
AT_DetachPartition /* DETACH PARTITION */
|
||||
} AlterTableType;
|
||||
|
||||
typedef struct ReplicaIdentityStmt
|
||||
@@ -1775,6 +1850,8 @@ typedef struct CreateStmt
|
||||
List *tableElts; /* column definitions (list of ColumnDef) */
|
||||
List *inhRelations; /* relations to inherit from (list of
|
||||
* inhRelation) */
|
||||
Node *partbound; /* FOR VALUES clause */
|
||||
PartitionSpec *partspec; /* PARTITION BY clause */
|
||||
TypeName *ofTypename; /* OF typename */
|
||||
List *constraints; /* constraints (list of Constraint nodes) */
|
||||
List *options; /* options from WITH clause */
|
||||
|
||||
Reference in New Issue
Block a user