2018-04-15 02:12:14 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* partcache.h
|
|
|
|
*
|
2024-01-04 02:49:05 +01:00
|
|
|
* Copyright (c) 1996-2024, PostgreSQL Global Development Group
|
2018-04-15 02:12:14 +02:00
|
|
|
*
|
|
|
|
* src/include/utils/partcache.h
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef PARTCACHE_H
|
|
|
|
#define PARTCACHE_H
|
|
|
|
|
|
|
|
#include "access/attnum.h"
|
|
|
|
#include "fmgr.h"
|
2022-11-03 16:25:54 +01:00
|
|
|
#include "nodes/parsenodes.h"
|
2018-04-15 02:12:14 +02:00
|
|
|
#include "nodes/pg_list.h"
|
|
|
|
#include "nodes/primnodes.h"
|
|
|
|
#include "partitioning/partdefs.h"
|
|
|
|
#include "utils/relcache.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Information about the partition key of a relation
|
|
|
|
*/
|
|
|
|
typedef struct PartitionKeyData
|
|
|
|
{
|
2022-11-03 16:25:54 +01:00
|
|
|
PartitionStrategy strategy; /* partitioning strategy */
|
2018-04-15 02:12:14 +02:00
|
|
|
int16 partnatts; /* number of columns in the partition key */
|
|
|
|
AttrNumber *partattrs; /* attribute numbers of columns in the
|
2018-11-15 23:22:19 +01:00
|
|
|
* partition key or 0 if it's an expr */
|
2018-04-15 02:12:14 +02:00
|
|
|
List *partexprs; /* list of expressions in the partitioning
|
2018-11-15 23:22:19 +01:00
|
|
|
* key, one for each zero-valued partattrs */
|
2018-04-15 02:12:14 +02:00
|
|
|
|
|
|
|
Oid *partopfamily; /* OIDs of operator families */
|
|
|
|
Oid *partopcintype; /* OIDs of opclass declared input data types */
|
|
|
|
FmgrInfo *partsupfunc; /* lookup info for support funcs */
|
|
|
|
|
|
|
|
/* Partitioning collation per attribute */
|
|
|
|
Oid *partcollation;
|
|
|
|
|
|
|
|
/* Type information per attribute */
|
|
|
|
Oid *parttypid;
|
|
|
|
int32 *parttypmod;
|
|
|
|
int16 *parttyplen;
|
|
|
|
bool *parttypbyval;
|
|
|
|
char *parttypalign;
|
|
|
|
Oid *parttypcoll;
|
|
|
|
} PartitionKeyData;
|
|
|
|
|
Load relcache entries' partitioning data on-demand, not immediately.
Formerly the rd_partkey and rd_partdesc data structures were always
populated immediately when a relcache entry was built or rebuilt.
This patch changes things so that they are populated only when they
are first requested. (Hence, callers *must* now always use
RelationGetPartitionKey or RelationGetPartitionDesc; just fetching
the pointer directly is no longer acceptable.)
This seems to have some performance benefits, but the main reason to do
it is that it eliminates a recursive-reload failure that occurs if the
partkey or partdesc expressions contain any references to the relation's
rowtype (as discovered by Amit Langote). In retrospect, since loading
these data structures might result in execution of nearly-arbitrary code
via eval_const_expressions, it was a dumb idea to require that to happen
during relcache entry rebuild.
Also, fix things so that old copies of a relcache partition descriptor
will be dropped when the cache entry's refcount goes to zero. In the
previous coding it was possible for such copies to survive for the
lifetime of the session, as I'd complained of in a previous discussion.
(This management technique still isn't perfect, but it's better than
before.) Improve the commentary explaining how that works and why
it's safe to hand out direct pointers to these relcache substructures.
In passing, improve RelationBuildPartitionDesc by using the same
memory-context-parent-swap approach used by RelationBuildPartitionKey,
thereby making it less dependent on strong assumptions about what
partition_bounds_copy does. Avoid doing get_rel_relkind in the
critical section, too.
Patch by Amit Langote and Tom Lane; Robert Haas deserves some credit
for prior work in the area, too. Although this is a pre-existing
problem, no back-patch: the patch seems too invasive to be safe to
back-patch, and the bug it fixes is a corner case that seems
relatively unlikely to cause problems in the field.
Discussion: https://postgr.es/m/CA+HiwqFUzjfj9HEsJtYWcr1SgQ_=iCAvQ=O2Sx6aQxoDu4OiHw@mail.gmail.com
Discussion: https://postgr.es/m/CA+TgmoY3bRmGB6-DUnoVy5fJoreiBJ43rwMrQRCdPXuKt4Ykaw@mail.gmail.com
2019-12-25 20:43:13 +01:00
|
|
|
|
|
|
|
extern PartitionKey RelationGetPartitionKey(Relation rel);
|
2018-04-15 02:12:14 +02:00
|
|
|
extern List *RelationGetPartitionQual(Relation rel);
|
|
|
|
extern Expr *get_partition_qual_relid(Oid relid);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PartitionKey inquiry functions
|
|
|
|
*/
|
|
|
|
static inline int
|
|
|
|
get_partition_strategy(PartitionKey key)
|
|
|
|
{
|
|
|
|
return key->strategy;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
get_partition_natts(PartitionKey key)
|
|
|
|
{
|
|
|
|
return key->partnatts;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline List *
|
|
|
|
get_partition_exprs(PartitionKey key)
|
|
|
|
{
|
|
|
|
return key->partexprs;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PartitionKey inquiry functions - one column
|
|
|
|
*/
|
|
|
|
static inline int16
|
|
|
|
get_partition_col_attnum(PartitionKey key, int col)
|
|
|
|
{
|
|
|
|
return key->partattrs[col];
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline Oid
|
|
|
|
get_partition_col_typid(PartitionKey key, int col)
|
|
|
|
{
|
|
|
|
return key->parttypid[col];
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int32
|
|
|
|
get_partition_col_typmod(PartitionKey key, int col)
|
|
|
|
{
|
|
|
|
return key->parttypmod[col];
|
|
|
|
}
|
|
|
|
|
2019-01-25 11:27:59 +01:00
|
|
|
static inline Oid
|
|
|
|
get_partition_col_collation(PartitionKey key, int col)
|
|
|
|
{
|
|
|
|
return key->partcollation[col];
|
|
|
|
}
|
|
|
|
|
2018-04-15 02:12:14 +02:00
|
|
|
#endif /* PARTCACHE_H */
|