Commit da6f3e45 authored by Alvaro Herrera's avatar Alvaro Herrera

Reorganize partitioning code

There's been a massive addition of partitioning code in PostgreSQL 11,
with little oversight on its placement, resulting in a
catalog/partition.c with poorly defined boundaries and responsibilities.
This commit tries to set a couple of distinct modules to separate things
a little bit.  There are no code changes here, only code movement.

There are three new files:
  src/backend/utils/cache/partcache.c
  src/include/partitioning/partdefs.h
  src/include/utils/partcache.h

The previous arrangement of #including catalog/partition.h almost
everywhere is no more.

Authors: Amit Langote and Álvaro Herrera
Discussion: https://postgr.es/m/98e8d509-790a-128c-be7f-e48a5b2d8d97@lab.ntt.co.jp
	https://postgr.es/m/11aa0c50-316b-18bb-722d-c23814f39059@lab.ntt.co.jp
	https://postgr.es/m/143ed9a4-6038-76d4-9a55-502035815e68@lab.ntt.co.jp
	https://postgr.es/m/20180413193503.nynq7bnmgh6vs5vm@alvherre.pgsql
parent b39fd897
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "funcapi.h" #include "funcapi.h"
#include "miscadmin.h" #include "miscadmin.h"
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/rel.h"
PG_FUNCTION_INFO_V1(hash_page_type); PG_FUNCTION_INFO_V1(hash_page_type);
PG_FUNCTION_INFO_V1(hash_page_stats); PG_FUNCTION_INFO_V1(hash_page_stats);
......
...@@ -76,6 +76,7 @@ ...@@ -76,6 +76,7 @@
#include "storage/ipc.h" #include "storage/ipc.h"
#include "storage/spin.h" #include "storage/spin.h"
#include "tcop/utility.h" #include "tcop/utility.h"
#include "utils/acl.h"
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/memutils.h" #include "utils/memutils.h"
......
...@@ -77,6 +77,7 @@ ...@@ -77,6 +77,7 @@
#include "utils/fmgroids.h" #include "utils/fmgroids.h"
#include "utils/inval.h" #include "utils/inval.h"
#include "utils/lsyscache.h" #include "utils/lsyscache.h"
#include "utils/partcache.h"
#include "utils/rel.h" #include "utils/rel.h"
#include "utils/ruleutils.h" #include "utils/ruleutils.h"
#include "utils/snapmgr.h" #include "utils/snapmgr.h"
......
This diff is collapsed.
...@@ -18,9 +18,11 @@ ...@@ -18,9 +18,11 @@
#include "access/heapam.h" #include "access/heapam.h"
#include "access/htup_details.h" #include "access/htup_details.h"
#include "access/sysattr.h" #include "access/sysattr.h"
#include "access/tupconvert.h"
#include "catalog/dependency.h" #include "catalog/dependency.h"
#include "catalog/indexing.h" #include "catalog/indexing.h"
#include "catalog/objectaccess.h" #include "catalog/objectaccess.h"
#include "catalog/partition.h"
#include "catalog/pg_constraint.h" #include "catalog/pg_constraint.h"
#include "catalog/pg_operator.h" #include "catalog/pg_operator.h"
#include "catalog/pg_type.h" #include "catalog/pg_type.h"
......
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
#include "utils/inval.h" #include "utils/inval.h"
#include "utils/lsyscache.h" #include "utils/lsyscache.h"
#include "utils/memutils.h" #include "utils/memutils.h"
#include "utils/partcache.h"
#include "utils/regproc.h" #include "utils/regproc.h"
#include "utils/snapmgr.h" #include "utils/snapmgr.h"
#include "utils/syscache.h" #include "utils/syscache.h"
......
...@@ -77,6 +77,7 @@ ...@@ -77,6 +77,7 @@
#include "parser/parse_type.h" #include "parser/parse_type.h"
#include "parser/parse_utilcmd.h" #include "parser/parse_utilcmd.h"
#include "parser/parser.h" #include "parser/parser.h"
#include "partitioning/partbounds.h"
#include "pgstat.h" #include "pgstat.h"
#include "rewrite/rewriteDefine.h" #include "rewrite/rewriteDefine.h"
#include "rewrite/rewriteHandler.h" #include "rewrite/rewriteHandler.h"
...@@ -92,6 +93,7 @@ ...@@ -92,6 +93,7 @@
#include "utils/inval.h" #include "utils/inval.h"
#include "utils/lsyscache.h" #include "utils/lsyscache.h"
#include "utils/memutils.h" #include "utils/memutils.h"
#include "utils/partcache.h"
#include "utils/relcache.h" #include "utils/relcache.h"
#include "utils/ruleutils.h" #include "utils/ruleutils.h"
#include "utils/snapmgr.h" #include "utils/snapmgr.h"
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "catalog/index.h" #include "catalog/index.h"
#include "catalog/indexing.h" #include "catalog/indexing.h"
#include "catalog/objectaccess.h" #include "catalog/objectaccess.h"
#include "catalog/partition.h"
#include "catalog/pg_constraint.h" #include "catalog/pg_constraint.h"
#include "catalog/pg_inherits.h" #include "catalog/pg_inherits.h"
#include "catalog/pg_proc.h" #include "catalog/pg_proc.h"
......
...@@ -42,7 +42,6 @@ ...@@ -42,7 +42,6 @@
#include "access/transam.h" #include "access/transam.h"
#include "access/xact.h" #include "access/xact.h"
#include "catalog/namespace.h" #include "catalog/namespace.h"
#include "catalog/partition.h"
#include "catalog/pg_publication.h" #include "catalog/pg_publication.h"
#include "commands/matview.h" #include "commands/matview.h"
#include "commands/trigger.h" #include "commands/trigger.h"
...@@ -60,6 +59,7 @@ ...@@ -60,6 +59,7 @@
#include "utils/acl.h" #include "utils/acl.h"
#include "utils/lsyscache.h" #include "utils/lsyscache.h"
#include "utils/memutils.h" #include "utils/memutils.h"
#include "utils/partcache.h"
#include "utils/rls.h" #include "utils/rls.h"
#include "utils/ruleutils.h" #include "utils/ruleutils.h"
#include "utils/snapmgr.h" #include "utils/snapmgr.h"
......
...@@ -11,9 +11,9 @@ ...@@ -11,9 +11,9 @@
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include "postgres.h" #include "postgres.h"
#include "catalog/partition.h"
#include "catalog/pg_inherits.h" #include "catalog/pg_inherits.h"
#include "catalog/pg_type.h" #include "catalog/pg_type.h"
#include "executor/execPartition.h" #include "executor/execPartition.h"
...@@ -22,10 +22,15 @@ ...@@ -22,10 +22,15 @@
#include "mb/pg_wchar.h" #include "mb/pg_wchar.h"
#include "miscadmin.h" #include "miscadmin.h"
#include "nodes/makefuncs.h" #include "nodes/makefuncs.h"
#include "partitioning/partbounds.h"
#include "partitioning/partprune.h"
#include "utils/lsyscache.h" #include "utils/lsyscache.h"
#include "utils/partcache.h"
#include "utils/rel.h"
#include "utils/rls.h" #include "utils/rls.h"
#include "utils/ruleutils.h" #include "utils/ruleutils.h"
static PartitionDispatch *RelationGetPartitionDispatchInfo(Relation rel, static PartitionDispatch *RelationGetPartitionDispatchInfo(Relation rel,
int *num_parted, List **leaf_part_oids); int *num_parted, List **leaf_part_oids);
static void get_partition_dispatch_recurse(Relation rel, Relation parent, static void get_partition_dispatch_recurse(Relation rel, Relation parent,
...@@ -35,6 +40,8 @@ static void FormPartitionKeyDatum(PartitionDispatch pd, ...@@ -35,6 +40,8 @@ static void FormPartitionKeyDatum(PartitionDispatch pd,
EState *estate, EState *estate,
Datum *values, Datum *values,
bool *isnull); bool *isnull);
static int get_partition_for_tuple(Relation relation, Datum *values,
bool *isnull);
static char *ExecBuildSlotPartitionKeyDescription(Relation rel, static char *ExecBuildSlotPartitionKeyDescription(Relation rel,
Datum *values, Datum *values,
bool *isnull, bool *isnull,
...@@ -1022,6 +1029,110 @@ FormPartitionKeyDatum(PartitionDispatch pd, ...@@ -1022,6 +1029,110 @@ FormPartitionKeyDatum(PartitionDispatch pd,
elog(ERROR, "wrong number of partition key expressions"); elog(ERROR, "wrong number of partition key expressions");
} }
/*
* get_partition_for_tuple
* Finds partition of relation which accepts the partition key specified
* in values and isnull
*
* Return value is index of the partition (>= 0 and < partdesc->nparts) if one
* found or -1 if none found.
*/
int
get_partition_for_tuple(Relation relation, Datum *values, bool *isnull)
{
int bound_offset;
int part_index = -1;
PartitionKey key = RelationGetPartitionKey(relation);
PartitionDesc partdesc = RelationGetPartitionDesc(relation);
/* Route as appropriate based on partitioning strategy. */
switch (key->strategy)
{
case PARTITION_STRATEGY_HASH:
{
PartitionBoundInfo boundinfo = partdesc->boundinfo;
int greatest_modulus = get_hash_partition_greatest_modulus(boundinfo);
uint64 rowHash = compute_hash_value(key->partnatts,
key->partsupfunc,
values, isnull);
part_index = boundinfo->indexes[rowHash % greatest_modulus];
}
break;
case PARTITION_STRATEGY_LIST:
if (isnull[0])
{
if (partition_bound_accepts_nulls(partdesc->boundinfo))
part_index = partdesc->boundinfo->null_index;
}
else
{
bool equal = false;
bound_offset = partition_list_bsearch(key->partsupfunc,
key->partcollation,
partdesc->boundinfo,
values[0], &equal);
if (bound_offset >= 0 && equal)
part_index = partdesc->boundinfo->indexes[bound_offset];
}
break;
case PARTITION_STRATEGY_RANGE:
{
bool equal = false,
range_partkey_has_null = false;
int i;
/*
* No range includes NULL, so this will be accepted by the
* default partition if there is one, and otherwise rejected.
*/
for (i = 0; i < key->partnatts; i++)
{
if (isnull[i])
{
range_partkey_has_null = true;
break;
}
}
if (!range_partkey_has_null)
{
bound_offset = partition_range_datum_bsearch(key->partsupfunc,
key->partcollation,
partdesc->boundinfo,
key->partnatts,
values,
&equal);
/*
* The bound at bound_offset is less than or equal to the
* tuple value, so the bound at offset+1 is the upper
* bound of the partition we're looking for, if there
* actually exists one.
*/
part_index = partdesc->boundinfo->indexes[bound_offset + 1];
}
}
break;
default:
elog(ERROR, "unexpected partition strategy: %d",
(int) key->strategy);
}
/*
* part_index < 0 means we failed to find a partition of this parent. Use
* the default partition, if there is one.
*/
if (part_index < 0)
part_index = partdesc->boundinfo->default_index;
return part_index;
}
/* /*
* ExecBuildSlotPartitionKeyDescription * ExecBuildSlotPartitionKeyDescription
* *
......
...@@ -15,12 +15,12 @@ ...@@ -15,12 +15,12 @@
#include "postgres.h" #include "postgres.h"
#include "miscadmin.h" #include "miscadmin.h"
#include "catalog/partition.h"
#include "optimizer/clauses.h" #include "optimizer/clauses.h"
#include "optimizer/joininfo.h" #include "optimizer/joininfo.h"
#include "optimizer/pathnode.h" #include "optimizer/pathnode.h"
#include "optimizer/paths.h" #include "optimizer/paths.h"
#include "optimizer/prep.h" #include "optimizer/prep.h"
#include "partitioning/partbounds.h"
#include "utils/lsyscache.h" #include "utils/lsyscache.h"
#include "utils/memutils.h" #include "utils/memutils.h"
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include "optimizer/plancat.h" #include "optimizer/plancat.h"
#include "optimizer/predtest.h" #include "optimizer/predtest.h"
#include "optimizer/prep.h" #include "optimizer/prep.h"
#include "partitioning/partbounds.h"
#include "parser/parse_relation.h" #include "parser/parse_relation.h"
#include "parser/parsetree.h" #include "parser/parsetree.h"
#include "rewrite/rewriteManip.h" #include "rewrite/rewriteManip.h"
...@@ -45,8 +46,9 @@ ...@@ -45,8 +46,9 @@
#include "storage/bufmgr.h" #include "storage/bufmgr.h"
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/lsyscache.h" #include "utils/lsyscache.h"
#include "utils/syscache.h" #include "utils/partcache.h"
#include "utils/rel.h" #include "utils/rel.h"
#include "utils/syscache.h"
#include "utils/snapmgr.h" #include "utils/snapmgr.h"
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include <limits.h> #include <limits.h>
#include "miscadmin.h" #include "miscadmin.h"
#include "catalog/partition.h"
#include "optimizer/clauses.h" #include "optimizer/clauses.h"
#include "optimizer/cost.h" #include "optimizer/cost.h"
#include "optimizer/pathnode.h" #include "optimizer/pathnode.h"
...@@ -27,6 +26,7 @@ ...@@ -27,6 +26,7 @@
#include "optimizer/prep.h" #include "optimizer/prep.h"
#include "optimizer/restrictinfo.h" #include "optimizer/restrictinfo.h"
#include "optimizer/tlist.h" #include "optimizer/tlist.h"
#include "partitioning/partbounds.h"
#include "utils/hsearch.h" #include "utils/hsearch.h"
......
...@@ -63,6 +63,7 @@ ...@@ -63,6 +63,7 @@
#include "utils/acl.h" #include "utils/acl.h"
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/lsyscache.h" #include "utils/lsyscache.h"
#include "utils/partcache.h"
#include "utils/rel.h" #include "utils/rel.h"
#include "utils/ruleutils.h" #include "utils/ruleutils.h"
#include "utils/syscache.h" #include "utils/syscache.h"
......
...@@ -12,6 +12,6 @@ subdir = src/backend/partitioning ...@@ -12,6 +12,6 @@ subdir = src/backend/partitioning
top_builddir = ../../.. top_builddir = ../../..
include $(top_builddir)/src/Makefile.global include $(top_builddir)/src/Makefile.global
OBJS = partprune.o OBJS = partprune.o partbounds.o
include $(top_srcdir)/src/backend/common.mk include $(top_srcdir)/src/backend/common.mk
This diff is collapsed.
...@@ -68,6 +68,7 @@ ...@@ -68,6 +68,7 @@
#include "utils/acl.h" #include "utils/acl.h"
#include "utils/guc.h" #include "utils/guc.h"
#include "utils/syscache.h" #include "utils/syscache.h"
#include "utils/rel.h"
/* Hook for plugins to get control in ProcessUtility() */ /* Hook for plugins to get control in ProcessUtility() */
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#include "access/sysattr.h" #include "access/sysattr.h"
#include "catalog/dependency.h" #include "catalog/dependency.h"
#include "catalog/indexing.h" #include "catalog/indexing.h"
#include "catalog/partition.h"
#include "catalog/pg_aggregate.h" #include "catalog/pg_aggregate.h"
#include "catalog/pg_am.h" #include "catalog/pg_am.h"
#include "catalog/pg_authid.h" #include "catalog/pg_authid.h"
...@@ -64,6 +63,7 @@ ...@@ -64,6 +63,7 @@
#include "utils/guc.h" #include "utils/guc.h"
#include "utils/hsearch.h" #include "utils/hsearch.h"
#include "utils/lsyscache.h" #include "utils/lsyscache.h"
#include "utils/partcache.h"
#include "utils/rel.h" #include "utils/rel.h"
#include "utils/ruleutils.h" #include "utils/ruleutils.h"
#include "utils/snapmgr.h" #include "utils/snapmgr.h"
......
...@@ -12,8 +12,8 @@ subdir = src/backend/utils/cache ...@@ -12,8 +12,8 @@ subdir = src/backend/utils/cache
top_builddir = ../../../.. top_builddir = ../../../..
include $(top_builddir)/src/Makefile.global include $(top_builddir)/src/Makefile.global
OBJS = attoptcache.o catcache.o evtcache.o inval.o plancache.o relcache.o \ OBJS = attoptcache.o catcache.o evtcache.o inval.o lsyscache.o \
relmapper.o relfilenodemap.o spccache.o syscache.o lsyscache.o \ partcache.o plancache.o relcache.o relmapper.o relfilenodemap.o \
typcache.o ts_cache.o spccache.o syscache.o ts_cache.o typcache.o
include $(top_srcdir)/src/backend/common.mk include $(top_srcdir)/src/backend/common.mk
This diff is collapsed.
...@@ -73,6 +73,7 @@ ...@@ -73,6 +73,7 @@
#include "optimizer/cost.h" #include "optimizer/cost.h"
#include "optimizer/prep.h" #include "optimizer/prep.h"
#include "optimizer/var.h" #include "optimizer/var.h"
#include "partitioning/partbounds.h"
#include "pgstat.h" #include "pgstat.h"
#include "rewrite/rewriteDefine.h" #include "rewrite/rewriteDefine.h"
#include "rewrite/rowsecurity.h" #include "rewrite/rowsecurity.h"
...@@ -85,6 +86,7 @@ ...@@ -85,6 +86,7 @@
#include "utils/inval.h" #include "utils/inval.h"
#include "utils/lsyscache.h" #include "utils/lsyscache.h"
#include "utils/memutils.h" #include "utils/memutils.h"
#include "utils/partcache.h"
#include "utils/relmapper.h" #include "utils/relmapper.h"
#include "utils/resowner_private.h" #include "utils/resowner_private.h"
#include "utils/snapmgr.h" #include "utils/snapmgr.h"
...@@ -265,7 +267,6 @@ static HeapTuple ScanPgRelation(Oid targetRelId, bool indexOK, bool force_non_hi ...@@ -265,7 +267,6 @@ static HeapTuple ScanPgRelation(Oid targetRelId, bool indexOK, bool force_non_hi
static Relation AllocateRelationDesc(Form_pg_class relp); static Relation AllocateRelationDesc(Form_pg_class relp);
static void RelationParseRelOptions(Relation relation, HeapTuple tuple); static void RelationParseRelOptions(Relation relation, HeapTuple tuple);
static void RelationBuildTupleDesc(Relation relation); static void RelationBuildTupleDesc(Relation relation);
static void RelationBuildPartitionKey(Relation relation);
static Relation RelationBuildDesc(Oid targetRelId, bool insertIt); static Relation RelationBuildDesc(Oid targetRelId, bool insertIt);
static void RelationInitPhysicalAddr(Relation relation); static void RelationInitPhysicalAddr(Relation relation);
static void load_critical_index(Oid indexoid, Oid heapoid); static void load_critical_index(Oid indexoid, Oid heapoid);
...@@ -873,211 +874,6 @@ RelationBuildRuleLock(Relation relation) ...@@ -873,211 +874,6 @@ RelationBuildRuleLock(Relation relation)
relation->rd_rules = rulelock; relation->rd_rules = rulelock;
} }
/*
* RelationBuildPartitionKey
* Build and attach to relcache partition key data of relation
*
* Partitioning key data is a complex structure; to avoid complicated logic to
* free individual elements whenever the relcache entry is flushed, we give it
* its own memory context, child of CacheMemoryContext, which can easily be
* deleted on its own. To avoid leaking memory in that context in case of an
* error partway through this function, the context is initially created as a
* child of CurTransactionContext and only re-parented to CacheMemoryContext
* at the end, when no further errors are possible. Also, we don't make this
* context the current context except in very brief code sections, out of fear
* that some of our callees allocate memory on their own which would be leaked
* permanently.
*/
static void
RelationBuildPartitionKey(Relation relation)
{
Form_pg_partitioned_table form;
HeapTuple tuple;
bool isnull;
int i;
PartitionKey key;
AttrNumber *attrs;
oidvector *opclass;
oidvector *collation;
ListCell *partexprs_item;
Datum datum;
MemoryContext partkeycxt,
oldcxt;
int16 procnum;
tuple = SearchSysCache1(PARTRELID,
ObjectIdGetDatum(RelationGetRelid(relation)));
/*
* The following happens when we have created our pg_class entry but not
* the pg_partitioned_table entry yet.
*/
if (!HeapTupleIsValid(tuple))
return;
partkeycxt = AllocSetContextCreate(CurTransactionContext,
"partition key",
ALLOCSET_SMALL_SIZES);
MemoryContextCopyAndSetIdentifier(partkeycxt,
RelationGetRelationName(relation));
key = (PartitionKey) MemoryContextAllocZero(partkeycxt,
sizeof(PartitionKeyData));
/* Fixed-length attributes */
form = (Form_pg_partitioned_table) GETSTRUCT(tuple);
key->strategy = form->partstrat;
key->partnatts = form->partnatts;
/*
* We can rely on the first variable-length attribute being mapped to the
* relevant field of the catalog's C struct, because all previous
* attributes are non-nullable and fixed-length.
*/
attrs = form->partattrs.values;
/* But use the hard way to retrieve further variable-length attributes */
/* Operator class */
datum = SysCacheGetAttr(PARTRELID, tuple,
Anum_pg_partitioned_table_partclass, &isnull);
Assert(!isnull);
opclass = (oidvector *) DatumGetPointer(datum);
/* Collation */
datum = SysCacheGetAttr(PARTRELID, tuple,
Anum_pg_partitioned_table_partcollation, &isnull);
Assert(!isnull);
collation = (oidvector *) DatumGetPointer(datum);
/* Expressions */
datum = SysCacheGetAttr(PARTRELID, tuple,
Anum_pg_partitioned_table_partexprs, &isnull);
if (!isnull)
{
char *exprString;
Node *expr;
exprString = TextDatumGetCString(datum);
expr = stringToNode(exprString);
pfree(exprString);
/*
* Run the expressions through const-simplification since the planner
* will be comparing them to similarly-processed qual clause operands,
* and may fail to detect valid matches without this step; fix
* opfuncids while at it. We don't need to bother with
* canonicalize_qual() though, because partition expressions should be
* in canonical form already (ie, no need for OR-merging or constant
* elimination).
*/
expr = eval_const_expressions(NULL, expr);
fix_opfuncids(expr);
oldcxt = MemoryContextSwitchTo(partkeycxt);
key->partexprs = (List *) copyObject(expr);
MemoryContextSwitchTo(oldcxt);
}
oldcxt = MemoryContextSwitchTo(partkeycxt);
key->partattrs = (AttrNumber *) palloc0(key->partnatts * sizeof(AttrNumber));
key->partopfamily = (Oid *) palloc0(key->partnatts * sizeof(Oid));
key->partopcintype = (Oid *) palloc0(key->partnatts * sizeof(Oid));
key->partsupfunc = (FmgrInfo *) palloc0(key->partnatts * sizeof(FmgrInfo));
key->partcollation = (Oid *) palloc0(key->partnatts * sizeof(Oid));
/* Gather type and collation info as well */
key->parttypid = (Oid *) palloc0(key->partnatts * sizeof(Oid));
key->parttypmod = (int32 *) palloc0(key->partnatts * sizeof(int32));
key->parttyplen = (int16 *) palloc0(key->partnatts * sizeof(int16));
key->parttypbyval = (bool *) palloc0(key->partnatts * sizeof(bool));
key->parttypalign = (char *) palloc0(key->partnatts * sizeof(char));
key->parttypcoll = (Oid *) palloc0(key->partnatts * sizeof(Oid));
MemoryContextSwitchTo(oldcxt);
/* determine support function number to search for */
procnum = (key->strategy == PARTITION_STRATEGY_HASH) ?
HASHEXTENDED_PROC : BTORDER_PROC;
/* Copy partattrs and fill other per-attribute info */
memcpy(key->partattrs, attrs, key->partnatts * sizeof(int16));
partexprs_item = list_head(key->partexprs);
for (i = 0; i < key->partnatts; i++)
{
AttrNumber attno = key->partattrs[i];
HeapTuple opclasstup;
Form_pg_opclass opclassform;
Oid funcid;
/* Collect opfamily information */
opclasstup = SearchSysCache1(CLAOID,
ObjectIdGetDatum(opclass->values[i]));
if (!HeapTupleIsValid(opclasstup))
elog(ERROR, "cache lookup failed for opclass %u", opclass->values[i]);
opclassform = (Form_pg_opclass) GETSTRUCT(opclasstup);
key->partopfamily[i] = opclassform->opcfamily;
key->partopcintype[i] = opclassform->opcintype;
/* Get a support function for the specified opfamily and datatypes */
funcid = get_opfamily_proc(opclassform->opcfamily,
opclassform->opcintype,
opclassform->opcintype,
procnum);
if (!OidIsValid(funcid))
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("operator class \"%s\" of access method %s is missing support function %d for type %s",
NameStr(opclassform->opcname),
(key->strategy == PARTITION_STRATEGY_HASH) ?
"hash" : "btree",
procnum,
format_type_be(opclassform->opcintype))));
fmgr_info_cxt(funcid, &key->partsupfunc[i], partkeycxt);
/* Collation */
key->partcollation[i] = collation->values[i];
/* Collect type information */
if (attno != 0)
{
Form_pg_attribute att = TupleDescAttr(relation->rd_att, attno - 1);
key->parttypid[i] = att->atttypid;
key->parttypmod[i] = att->atttypmod;
key->parttypcoll[i] = att->attcollation;
}
else
{
if (partexprs_item == NULL)
elog(ERROR, "wrong number of partition key expressions");
key->parttypid[i] = exprType(lfirst(partexprs_item));
key->parttypmod[i] = exprTypmod(lfirst(partexprs_item));
key->parttypcoll[i] = exprCollation(lfirst(partexprs_item));
partexprs_item = lnext(partexprs_item);
}
get_typlenbyvalalign(key->parttypid[i],
&key->parttyplen[i],
&key->parttypbyval[i],
&key->parttypalign[i]);
ReleaseSysCache(opclasstup);
}
ReleaseSysCache(tuple);
/*
* Success --- reparent our context and make the relcache point to the
* newly constructed key
*/
MemoryContextSetParent(partkeycxt, CacheMemoryContext);
relation->rd_partkeycxt = partkeycxt;
relation->rd_partkey = key;
}
/* /*
* equalRuleLocks * equalRuleLocks
* *
......
...@@ -15,13 +15,14 @@ ...@@ -15,13 +15,14 @@
#include "postgres.h" #include "postgres.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "access/htup_details.h" #include "access/htup_details.h"
#include "access/xlog_internal.h" #include "access/xlog_internal.h"
#include "access/xlog.h"
#include "catalog/pg_control.h" #include "catalog/pg_control.h"
#include "catalog/pg_type.h" #include "catalog/pg_type.h"
#include "common/controldata_utils.h" #include "common/controldata_utils.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/pg_lsn.h" #include "utils/pg_lsn.h"
#include "utils/timestamp.h" #include "utils/timestamp.h"
......
This diff is collapsed.
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include "catalog/dependency.h" #include "catalog/dependency.h"
#include "catalog/objectaddress.h" #include "catalog/objectaddress.h"
#include "nodes/parsenodes.h" #include "nodes/parsenodes.h"
#include "catalog/partition.h"
#include "storage/lock.h" #include "storage/lock.h"
#include "utils/relcache.h" #include "utils/relcache.h"
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#ifndef EXECPARTITION_H #ifndef EXECPARTITION_H
#define EXECPARTITION_H #define EXECPARTITION_H
#include "catalog/partition.h"
#include "nodes/execnodes.h" #include "nodes/execnodes.h"
#include "nodes/parsenodes.h" #include "nodes/parsenodes.h"
#include "nodes/plannodes.h" #include "nodes/plannodes.h"
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#ifndef EXECUTOR_H #ifndef EXECUTOR_H
#define EXECUTOR_H #define EXECUTOR_H
#include "catalog/partition.h"
#include "executor/execdesc.h" #include "executor/execdesc.h"
#include "nodes/parsenodes.h" #include "nodes/parsenodes.h"
#include "utils/memutils.h" #include "utils/memutils.h"
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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