Commit 4b9a98e1 authored by Robert Haas's avatar Robert Haas

Clean up code, comments, and formatting for table partitioning.

Amit Langote, plus pgindent-ing by me.  Inspired in part by review
comments from Tomas Vondra.
parent acddbe22
......@@ -1887,6 +1887,10 @@ heap_drop_with_catalog(Oid relid)
if (parent)
{
/*
* Invalidate the parent's relcache so that the partition is no longer
* included in its partition descriptor.
*/
CacheInvalidateRelcache(parent);
heap_close(parent, NoLock); /* keep the lock */
}
......
......@@ -1492,7 +1492,7 @@ generate_partition_qual(Relation rel, bool recurse)
* Construct values[] and isnull[] arrays for the partition key
* of a tuple.
*
* pkinfo partition key execution info
* pd Partition dispatch object of the partitioned table
* slot Heap tuple from which to extract partition key
* estate executor state for evaluating any partition key
* expressions (must be non-NULL)
......@@ -1565,7 +1565,7 @@ FormPartitionKeyDatum(PartitionDispatch pd,
* the latter case.
*/
int
get_partition_for_tuple(PartitionDispatch * pd,
get_partition_for_tuple(PartitionDispatch *pd,
TupleTableSlot *slot,
EState *estate,
Oid *failed_at)
......
......@@ -1403,31 +1403,28 @@ BeginCopy(ParseState *pstate,
errmsg("table \"%s\" does not have OIDs",
RelationGetRelationName(cstate->rel))));
/*
* Initialize state for CopyFrom tuple routing. Watch out for
* any foreign partitions.
*/
/* Initialize state for CopyFrom tuple routing. */
if (is_from && rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
{
PartitionDispatch *pd;
List *leaf_parts;
ListCell *cell;
int i,
num_parted,
num_leaf_parts;
num_parted;
ResultRelInfo *leaf_part_rri;
/* Get the tuple-routing information and lock partitions */
pd = RelationGetPartitionDispatchInfo(rel, RowExclusiveLock,
&num_parted, &leaf_parts);
num_leaf_parts = list_length(leaf_parts);
cstate->partition_dispatch_info = pd;
cstate->partition_dispatch_info =
RelationGetPartitionDispatchInfo(rel, RowExclusiveLock,
&num_parted,
&leaf_parts);
cstate->num_dispatch = num_parted;
cstate->num_partitions = num_leaf_parts;
cstate->partitions = (ResultRelInfo *) palloc(num_leaf_parts *
cstate->num_partitions = list_length(leaf_parts);
cstate->partitions = (ResultRelInfo *)
palloc(cstate->num_partitions *
sizeof(ResultRelInfo));
cstate->partition_tupconv_maps = (TupleConversionMap **)
palloc0(num_leaf_parts * sizeof(TupleConversionMap *));
palloc0(cstate->num_partitions *
sizeof(TupleConversionMap *));
leaf_part_rri = cstate->partitions;
i = 0;
......@@ -1438,8 +1435,8 @@ BeginCopy(ParseState *pstate,
/*
* We locked all the partitions above including the leaf
* partitions. Note that each of the relations in
* cstate->partitions will be closed by CopyFrom() after
* it's finished with its processing.
* cstate->partitions will be closed by CopyFrom() after it's
* finished with its processing.
*/
partrel = heap_open(lfirst_oid(cell), NoLock);
......@@ -1452,7 +1449,8 @@ BeginCopy(ParseState *pstate,
InitResultRelInfo(leaf_part_rri,
partrel,
1, /* dummy */
false, /* no partition constraint check */
false, /* no partition constraint
* check */
0);
/* Open partition indices */
......@@ -2486,8 +2484,8 @@ CopyFrom(CopyState cstate)
* BEFORE/INSTEAD OF triggers, or we need to evaluate volatile default
* expressions. Such triggers or expressions might query the table we're
* inserting to, and act differently if the tuples that have already been
* processed and prepared for insertion are not there. We also can't
* do it if the table is partitioned.
* processed and prepared for insertion are not there. We also can't do
* it if the table is partitioned.
*/
if ((resultRelInfo->ri_TrigDesc != NULL &&
(resultRelInfo->ri_TrigDesc->trig_insert_before_row ||
......
This diff is collapsed.
......@@ -1718,26 +1718,26 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
if (operation == CMD_INSERT &&
rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
{
PartitionDispatch *pd;
int i,
j,
num_parted,
num_leaf_parts;
num_parted;
List *leaf_parts;
ListCell *cell;
ResultRelInfo *leaf_part_rri;
/* Form the partition node tree and lock partitions */
pd = RelationGetPartitionDispatchInfo(rel, RowExclusiveLock,
&num_parted, &leaf_parts);
mtstate->mt_partition_dispatch_info = pd;
/* Get the tuple-routing information and lock partitions */
mtstate->mt_partition_dispatch_info =
RelationGetPartitionDispatchInfo(rel, RowExclusiveLock,
&num_parted,
&leaf_parts);
mtstate->mt_num_dispatch = num_parted;
num_leaf_parts = list_length(leaf_parts);
mtstate->mt_num_partitions = num_leaf_parts;
mtstate->mt_num_partitions = list_length(leaf_parts);
mtstate->mt_partitions = (ResultRelInfo *)
palloc0(num_leaf_parts * sizeof(ResultRelInfo));
palloc0(mtstate->mt_num_partitions *
sizeof(ResultRelInfo));
mtstate->mt_partition_tupconv_maps = (TupleConversionMap **)
palloc0(num_leaf_parts * sizeof(TupleConversionMap *));
palloc0(mtstate->mt_num_partitions *
sizeof(TupleConversionMap *));
leaf_part_rri = mtstate->mt_partitions;
i = j = 0;
......
......@@ -7,7 +7,7 @@
*
* Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/include/catalog/pg_partitioned_table.h $
* src/include/catalog/pg_partitioned_table.h
*
* NOTES
* the genbki.sh script reads this file and generates .bki
......@@ -39,17 +39,15 @@ CATALOG(pg_partitioned_table,3350) BKI_WITHOUT_OIDS
* 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 */
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[] */
pg_node_tree partexprs; /* list of expressions in the partition key;
* one item for each zero entry in partattrs[] */
#endif
} FormData_pg_partitioned_table;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment