mirror of https://github.com/postgres/postgres
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.pull/18/head
parent
b7e1ae2328
commit
f0e44751d7
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,83 @@ |
||||
/*-------------------------------------------------------------------------
|
||||
* |
||||
* partition.h |
||||
* Header file for structures and utility functions related to |
||||
* partitioning |
||||
* |
||||
* Copyright (c) 2007-2016, PostgreSQL Global Development Group |
||||
* |
||||
* src/include/catalog/partition.h |
||||
* |
||||
*------------------------------------------------------------------------- |
||||
*/ |
||||
#ifndef PARTITION_H |
||||
#define PARTITION_H |
||||
|
||||
#include "fmgr.h" |
||||
#include "executor/tuptable.h" |
||||
#include "nodes/execnodes.h" |
||||
#include "parser/parse_node.h" |
||||
#include "utils/rel.h" |
||||
|
||||
/*
|
||||
* PartitionBoundInfo encapsulates a set of partition bounds. It is usually |
||||
* associated with partitioned tables as part of its partition descriptor. |
||||
* |
||||
* The internal structure is opaque outside partition.c. |
||||
*/ |
||||
typedef struct PartitionBoundInfoData *PartitionBoundInfo; |
||||
|
||||
/*
|
||||
* Information about partitions of a partitioned table. |
||||
*/ |
||||
typedef struct PartitionDescData |
||||
{ |
||||
int nparts; /* Number of partitions */ |
||||
Oid *oids; /* OIDs of partitions */ |
||||
PartitionBoundInfo boundinfo; /* collection of partition bounds */ |
||||
} PartitionDescData; |
||||
|
||||
typedef struct PartitionDescData *PartitionDesc; |
||||
|
||||
/*-----------------------
|
||||
* PartitionDispatch - information about one partitioned table in a partition |
||||
* hiearchy required to route a tuple to one of its partitions |
||||
* |
||||
* reldesc Relation descriptor of the table |
||||
* key Partition key information of the table |
||||
* keystate Execution state required for expressions in the partition key |
||||
* partdesc Partition descriptor of the table |
||||
* indexes Array with partdesc->nparts members (for details on what |
||||
* individual members represent, see how they are set in |
||||
* RelationGetPartitionDispatchInfo()) |
||||
*----------------------- |
||||
*/ |
||||
typedef struct PartitionDispatchData |
||||
{ |
||||
Relation reldesc; |
||||
PartitionKey key; |
||||
List *keystate; /* list of ExprState */ |
||||
PartitionDesc partdesc; |
||||
int *indexes; |
||||
} PartitionDispatchData; |
||||
|
||||
typedef struct PartitionDispatchData *PartitionDispatch; |
||||
|
||||
extern void RelationBuildPartitionDesc(Relation relation); |
||||
extern bool partition_bounds_equal(PartitionKey key, |
||||
PartitionBoundInfo p1, PartitionBoundInfo p2); |
||||
|
||||
extern void check_new_partition_bound(char *relname, Relation parent, Node *bound); |
||||
extern Oid get_partition_parent(Oid relid); |
||||
extern List *get_qual_from_partbound(Relation rel, Relation parent, Node *bound); |
||||
extern List *RelationGetPartitionQual(Relation rel, bool recurse); |
||||
|
||||
/* For tuple routing */ |
||||
extern PartitionDispatch *RelationGetPartitionDispatchInfo(Relation rel, |
||||
int lockmode, int *num_parted, |
||||
List **leaf_part_oids); |
||||
extern int get_partition_for_tuple(PartitionDispatch *pd, |
||||
TupleTableSlot *slot, |
||||
EState *estate, |
||||
Oid *failed_at); |
||||
#endif /* PARTITION_H */ |
||||
@ -0,0 +1,76 @@ |
||||
/*-------------------------------------------------------------------------
|
||||
* |
||||
* pg_partitioned_table.h |
||||
* definition of the system "partitioned table" relation |
||||
* along with the relation's initial contents. |
||||
* |
||||
* |
||||
* Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group |
||||
* |
||||
* $PostgreSQL: pgsql/src/include/catalog/pg_partitioned_table.h $ |
||||
* |
||||
* NOTES |
||||
* the genbki.sh script reads this file and generates .bki |
||||
* information from the DATA() statements. |
||||
* |
||||
*------------------------------------------------------------------------- |
||||
*/ |
||||
#ifndef PG_PARTITIONED_TABLE_H |
||||
#define PG_PARTITIONED_TABLE_H |
||||
|
||||
#include "catalog/genbki.h" |
||||
|
||||
/* ----------------
|
||||
* pg_partitioned_table definition. cpp turns this into |
||||
* typedef struct FormData_pg_partitioned_table |
||||
* ---------------- |
||||
*/ |
||||
#define PartitionedRelationId 3350 |
||||
|
||||
CATALOG(pg_partitioned_table,3350) BKI_WITHOUT_OIDS |
||||
{ |
||||
Oid partrelid; /* partitioned table oid */ |
||||
char partstrat; /* partitioning strategy */ |
||||
int16 partnatts; /* number of partition key columns */ |
||||
|
||||
/*
|
||||
* variable-length fields start here, but we allow direct access to |
||||
* partattrs via the C struct. That's because the first variable-length |
||||
* field of a heap tuple can be reliably accessed using its C struct |
||||
* offset, as previous fields are all non-nullable fixed-length fields. |
||||
*/ |
||||
int2vector partattrs; /* each member of the array is the
|
||||
* attribute number of a partition key |
||||
* column, or 0 if the column is actually |
||||
* an expression */ |
||||
|
||||
#ifdef CATALOG_VARLEN |
||||
oidvector partclass; /* operator class to compare keys */ |
||||
oidvector partcollation; /* user-specified collation for keys */ |
||||
pg_node_tree partexprs; /* list of expressions in the partitioning
|
||||
* key; one item for each zero entry in |
||||
* partattrs[] */ |
||||
#endif |
||||
} FormData_pg_partitioned_table; |
||||
|
||||
/* ----------------
|
||||
* Form_pg_partitioned_table corresponds to a pointer to a tuple with |
||||
* the format of pg_partitioned_table relation. |
||||
* ---------------- |
||||
*/ |
||||
typedef FormData_pg_partitioned_table *Form_pg_partitioned_table; |
||||
|
||||
/* ----------------
|
||||
* compiler constants for pg_partitioned_table |
||||
* ---------------- |
||||
*/ |
||||
#define Natts_pg_partitioned_table 7 |
||||
#define Anum_pg_partitioned_table_partrelid 1 |
||||
#define Anum_pg_partitioned_table_partstrat 2 |
||||
#define Anum_pg_partitioned_table_partnatts 3 |
||||
#define Anum_pg_partitioned_table_partattrs 4 |
||||
#define Anum_pg_partitioned_table_partclass 5 |
||||
#define Anum_pg_partitioned_table_partcollation 6 |
||||
#define Anum_pg_partitioned_table_partexprs 7 |
||||
|
||||
#endif /* PG_PARTITIONED_TABLE_H */ |
||||
Loading…
Reference in new issue