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)
......
......@@ -161,11 +161,11 @@ typedef struct CopyStateData
ExprState **defexprs; /* array of default att expressions */
bool volatile_defexprs; /* is any of defexprs volatile? */
List *range_table;
PartitionDispatch *partition_dispatch_info;
int num_dispatch;
int num_partitions;
ResultRelInfo *partitions;
TupleConversionMap **partition_tupconv_maps;
PartitionDispatch *partition_dispatch_info;
int num_dispatch;
int num_partitions;
ResultRelInfo *partitions;
TupleConversionMap **partition_tupconv_maps;
/*
* These variables are used to reduce overhead in textual COPY FROM.
......@@ -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;
ResultRelInfo *leaf_part_rri;
List *leaf_parts;
ListCell *cell;
int i,
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 *
sizeof(ResultRelInfo));
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);
......@@ -1451,8 +1448,9 @@ BeginCopy(ParseState *pstate,
InitResultRelInfo(leaf_part_rri,
partrel,
1, /* dummy */
false, /* no partition constraint check */
1, /* dummy */
false, /* no partition constraint
* check */
0);
/* Open partition indices */
......@@ -1460,9 +1458,9 @@ BeginCopy(ParseState *pstate,
if (!equalTupleDescs(tupDesc, RelationGetDescr(partrel)))
cstate->partition_tupconv_maps[i] =
convert_tuples_by_name(tupDesc,
RelationGetDescr(partrel),
gettext_noop("could not convert row type"));
convert_tuples_by_name(tupDesc,
RelationGetDescr(partrel),
gettext_noop("could not convert row type"));
leaf_part_rri++;
i++;
}
......@@ -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 ||
......@@ -2572,7 +2570,7 @@ CopyFrom(CopyState cstate)
/* Determine the partition to heap_insert the tuple into */
if (cstate->partition_dispatch_info)
{
int leaf_part_index;
int leaf_part_index;
TupleConversionMap *map;
/*
......@@ -2584,7 +2582,7 @@ CopyFrom(CopyState cstate)
* partition, respectively.
*/
leaf_part_index = ExecFindPartition(resultRelInfo,
cstate->partition_dispatch_info,
cstate->partition_dispatch_info,
slot,
estate);
Assert(leaf_part_index >= 0 &&
......@@ -2601,7 +2599,7 @@ CopyFrom(CopyState cstate)
if (resultRelInfo->ri_FdwRoutine)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot route inserted tuples to a foreign table")));
errmsg("cannot route inserted tuples to a foreign table")));
/*
* For ExecInsertIndexTuples() to work on the partition's indexes
......@@ -2752,7 +2750,7 @@ CopyFrom(CopyState cstate)
/* Close all the partitioned tables, leaf partitions, and their indices */
if (cstate->partition_dispatch_info)
{
int i;
int i;
/*
* Remember cstate->partition_dispatch_info[0] corresponds to the root
......
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
......@@ -29,9 +29,9 @@
CATALOG(pg_partitioned_table,3350) BKI_WITHOUT_OIDS
{
Oid partrelid; /* partitioned table oid */
char partstrat; /* partitioning strategy */
int16 partnatts; /* number of partition key columns */
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
......@@ -39,29 +39,27 @@ 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[] */
oidvector partclass; /* operator class to compare keys */
oidvector partcollation; /* user-specified collation for keys */
pg_node_tree partexprs; /* list of expressions in the partition 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.
* 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
* compiler constants for pg_partitioned_table
* ----------------
*/
#define Natts_pg_partitioned_table 7
......@@ -70,7 +68,7 @@ typedef FormData_pg_partitioned_table *Form_pg_partitioned_table;
#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_partcollation 6
#define Anum_pg_partitioned_table_partexprs 7
#endif /* PG_PARTITIONED_TABLE_H */
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