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) ...@@ -1887,6 +1887,10 @@ heap_drop_with_catalog(Oid relid)
if (parent) if (parent)
{ {
/*
* Invalidate the parent's relcache so that the partition is no longer
* included in its partition descriptor.
*/
CacheInvalidateRelcache(parent); CacheInvalidateRelcache(parent);
heap_close(parent, NoLock); /* keep the lock */ heap_close(parent, NoLock); /* keep the lock */
} }
......
...@@ -1492,7 +1492,7 @@ generate_partition_qual(Relation rel, bool recurse) ...@@ -1492,7 +1492,7 @@ generate_partition_qual(Relation rel, bool recurse)
* Construct values[] and isnull[] arrays for the partition key * Construct values[] and isnull[] arrays for the partition key
* of a tuple. * 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 * slot Heap tuple from which to extract partition key
* estate executor state for evaluating any partition key * estate executor state for evaluating any partition key
* expressions (must be non-NULL) * expressions (must be non-NULL)
...@@ -1565,7 +1565,7 @@ FormPartitionKeyDatum(PartitionDispatch pd, ...@@ -1565,7 +1565,7 @@ FormPartitionKeyDatum(PartitionDispatch pd,
* the latter case. * the latter case.
*/ */
int int
get_partition_for_tuple(PartitionDispatch * pd, get_partition_for_tuple(PartitionDispatch *pd,
TupleTableSlot *slot, TupleTableSlot *slot,
EState *estate, EState *estate,
Oid *failed_at) Oid *failed_at)
......
...@@ -1403,31 +1403,28 @@ BeginCopy(ParseState *pstate, ...@@ -1403,31 +1403,28 @@ BeginCopy(ParseState *pstate,
errmsg("table \"%s\" does not have OIDs", errmsg("table \"%s\" does not have OIDs",
RelationGetRelationName(cstate->rel)))); RelationGetRelationName(cstate->rel))));
/* /* Initialize state for CopyFrom tuple routing. */
* Initialize state for CopyFrom tuple routing. Watch out for
* any foreign partitions.
*/
if (is_from && rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE) if (is_from && rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
{ {
PartitionDispatch *pd;
List *leaf_parts; List *leaf_parts;
ListCell *cell; ListCell *cell;
int i, int i,
num_parted, num_parted;
num_leaf_parts;
ResultRelInfo *leaf_part_rri; ResultRelInfo *leaf_part_rri;
/* Get the tuple-routing information and lock partitions */ /* Get the tuple-routing information and lock partitions */
pd = RelationGetPartitionDispatchInfo(rel, RowExclusiveLock, cstate->partition_dispatch_info =
&num_parted, &leaf_parts); RelationGetPartitionDispatchInfo(rel, RowExclusiveLock,
num_leaf_parts = list_length(leaf_parts); &num_parted,
cstate->partition_dispatch_info = pd; &leaf_parts);
cstate->num_dispatch = num_parted; cstate->num_dispatch = num_parted;
cstate->num_partitions = num_leaf_parts; cstate->num_partitions = list_length(leaf_parts);
cstate->partitions = (ResultRelInfo *) palloc(num_leaf_parts * cstate->partitions = (ResultRelInfo *)
palloc(cstate->num_partitions *
sizeof(ResultRelInfo)); sizeof(ResultRelInfo));
cstate->partition_tupconv_maps = (TupleConversionMap **) cstate->partition_tupconv_maps = (TupleConversionMap **)
palloc0(num_leaf_parts * sizeof(TupleConversionMap *)); palloc0(cstate->num_partitions *
sizeof(TupleConversionMap *));
leaf_part_rri = cstate->partitions; leaf_part_rri = cstate->partitions;
i = 0; i = 0;
...@@ -1438,8 +1435,8 @@ BeginCopy(ParseState *pstate, ...@@ -1438,8 +1435,8 @@ BeginCopy(ParseState *pstate,
/* /*
* We locked all the partitions above including the leaf * We locked all the partitions above including the leaf
* partitions. Note that each of the relations in * partitions. Note that each of the relations in
* cstate->partitions will be closed by CopyFrom() after * cstate->partitions will be closed by CopyFrom() after it's
* it's finished with its processing. * finished with its processing.
*/ */
partrel = heap_open(lfirst_oid(cell), NoLock); partrel = heap_open(lfirst_oid(cell), NoLock);
...@@ -1452,7 +1449,8 @@ BeginCopy(ParseState *pstate, ...@@ -1452,7 +1449,8 @@ BeginCopy(ParseState *pstate,
InitResultRelInfo(leaf_part_rri, InitResultRelInfo(leaf_part_rri,
partrel, partrel,
1, /* dummy */ 1, /* dummy */
false, /* no partition constraint check */ false, /* no partition constraint
* check */
0); 0);
/* Open partition indices */ /* Open partition indices */
...@@ -2486,8 +2484,8 @@ CopyFrom(CopyState cstate) ...@@ -2486,8 +2484,8 @@ CopyFrom(CopyState cstate)
* BEFORE/INSTEAD OF triggers, or we need to evaluate volatile default * BEFORE/INSTEAD OF triggers, or we need to evaluate volatile default
* expressions. Such triggers or expressions might query the table we're * expressions. Such triggers or expressions might query the table we're
* inserting to, and act differently if the tuples that have already been * inserting to, and act differently if the tuples that have already been
* processed and prepared for insertion are not there. We also can't * processed and prepared for insertion are not there. We also can't do
* do it if the table is partitioned. * it if the table is partitioned.
*/ */
if ((resultRelInfo->ri_TrigDesc != NULL && if ((resultRelInfo->ri_TrigDesc != NULL &&
(resultRelInfo->ri_TrigDesc->trig_insert_before_row || (resultRelInfo->ri_TrigDesc->trig_insert_before_row ||
......
This diff is collapsed.
...@@ -1718,26 +1718,26 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags) ...@@ -1718,26 +1718,26 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
if (operation == CMD_INSERT && if (operation == CMD_INSERT &&
rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE) rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
{ {
PartitionDispatch *pd;
int i, int i,
j, j,
num_parted, num_parted;
num_leaf_parts;
List *leaf_parts; List *leaf_parts;
ListCell *cell; ListCell *cell;
ResultRelInfo *leaf_part_rri; ResultRelInfo *leaf_part_rri;
/* Form the partition node tree and lock partitions */ /* Get the tuple-routing information and lock partitions */
pd = RelationGetPartitionDispatchInfo(rel, RowExclusiveLock, mtstate->mt_partition_dispatch_info =
&num_parted, &leaf_parts); RelationGetPartitionDispatchInfo(rel, RowExclusiveLock,
mtstate->mt_partition_dispatch_info = pd; &num_parted,
&leaf_parts);
mtstate->mt_num_dispatch = num_parted; mtstate->mt_num_dispatch = num_parted;
num_leaf_parts = list_length(leaf_parts); mtstate->mt_num_partitions = list_length(leaf_parts);
mtstate->mt_num_partitions = num_leaf_parts;
mtstate->mt_partitions = (ResultRelInfo *) mtstate->mt_partitions = (ResultRelInfo *)
palloc0(num_leaf_parts * sizeof(ResultRelInfo)); palloc0(mtstate->mt_num_partitions *
sizeof(ResultRelInfo));
mtstate->mt_partition_tupconv_maps = (TupleConversionMap **) 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; leaf_part_rri = mtstate->mt_partitions;
i = j = 0; i = j = 0;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group * 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 * NOTES
* the genbki.sh script reads this file and generates .bki * the genbki.sh script reads this file and generates .bki
...@@ -39,17 +39,15 @@ CATALOG(pg_partitioned_table,3350) BKI_WITHOUT_OIDS ...@@ -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 * field of a heap tuple can be reliably accessed using its C struct
* offset, as previous fields are all non-nullable fixed-length fields. * offset, as previous fields are all non-nullable fixed-length fields.
*/ */
int2vector partattrs; /* each member of the array is the int2vector partattrs; /* each member of the array is the attribute
* attribute number of a partition key * number of a partition key column, or 0 if
* column, or 0 if the column is actually * the column is actually an expression */
* an expression */
#ifdef CATALOG_VARLEN #ifdef CATALOG_VARLEN
oidvector partclass; /* operator class to compare keys */ oidvector partclass; /* operator class to compare keys */
oidvector partcollation; /* user-specified collation for keys */ oidvector partcollation; /* user-specified collation for keys */
pg_node_tree partexprs; /* list of expressions in the partitioning pg_node_tree partexprs; /* list of expressions in the partition key;
* key; one item for each zero entry in * one item for each zero entry in partattrs[] */
* partattrs[] */
#endif #endif
} FormData_pg_partitioned_table; } 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