Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
partbounds.h147 linesDownload Raw Back to partitioning
1/*-------------------------------------------------------------------------2 *3 * partbounds.h4 *5 * Copyright (c) 2007-2023, PostgreSQL Global Development Group6 *7 * src/include/partitioning/partbounds.h8 *9 *-------------------------------------------------------------------------10 */11#ifndef PARTBOUNDS_H12#define PARTBOUNDS_H13 14#include "fmgr.h"15#include "parser/parse_node.h"16#include "partitioning/partdefs.h"17 18struct RelOptInfo;				/* avoid including pathnodes.h here */19 20 21/*22 * PartitionBoundInfoData encapsulates a set of partition bounds. It is23 * usually associated with partitioned tables as part of its partition24 * descriptor, but may also be used to represent a virtual partitioned25 * table such as a partitioned joinrel within the planner.26 *27 * A list partition datum that is known to be NULL is never put into the28 * datums array. Instead, it is tracked using the null_index field.29 *30 * In the case of range partitioning, ndatums will typically be far less than31 * 2 * nparts, because a partition's upper bound and the next partition's lower32 * bound are the same in most common cases, and we only store one of them (the33 * upper bound).  In case of hash partitioning, ndatums will be the same as the34 * number of partitions.35 *36 * For range and list partitioned tables, datums is an array of datum-tuples37 * with key->partnatts datums each.  For hash partitioned tables, it is an array38 * of datum-tuples with 2 datums, modulus and remainder, corresponding to a39 * given partition.40 *41 * The datums in datums array are arranged in increasing order as defined by42 * functions qsort_partition_rbound_cmp(), qsort_partition_list_value_cmp() and43 * qsort_partition_hbound_cmp() for range, list and hash partitioned tables44 * respectively. For range and list partitions this simply means that the45 * datums in the datums array are arranged in increasing order as defined by46 * the partition key's operator classes and collations.47 *48 * In the case of list partitioning, the indexes array stores one entry for49 * each datum-array entry, which is the index of the partition that accepts50 * rows matching that datum.  So nindexes == ndatums.51 *52 * In the case of range partitioning, the indexes array stores one entry per53 * distinct range datum, which is the index of the partition for which that54 * datum is an upper bound (or -1 for a "gap" that has no partition).  It is55 * convenient to have an extra -1 entry representing values above the last56 * range datum, so nindexes == ndatums + 1.57 *58 * In the case of hash partitioning, the number of entries in the indexes59 * array is the same as the greatest modulus amongst all partitions (which60 * is a multiple of all partition moduli), so nindexes == greatest modulus.61 * The indexes array is indexed according to the hash key's remainder modulo62 * the greatest modulus, and it contains either the partition index accepting63 * that remainder, or -1 if there is no partition for that remainder.64 *65 * For LIST partitioned tables, we track the partition indexes of partitions66 * which are possibly "interleaved" partitions.  A partition is considered67 * interleaved if it allows multiple values and there exists at least one68 * other partition which could contain a value that lies between those values.69 * For example, if a partition exists FOR VALUES IN(3,5) and another partition70 * exists FOR VALUES IN (4), then the IN(3,5) partition is an interleaved71 * partition.  The same is possible with DEFAULT partitions since they can72 * contain any value that does not belong in another partition.  This field73 * only serves as proof that a particular partition is not interleaved, not74 * proof that it is interleaved.  When we're uncertain, we marked the75 * partition as interleaved.  The interleaved_parts field is only ever set for76 * RELOPT_BASEREL and RELOPT_OTHER_MEMBER_REL, it is always left NULL for join77 * relations.78 */79typedef struct PartitionBoundInfoData80{81	PartitionStrategy strategy; /* hash, list or range? */82	int			ndatums;		/* Length of the datums[] array */83	Datum	  **datums;84	PartitionRangeDatumKind **kind; /* The kind of each range bound datum;85									 * NULL for hash and list partitioned86									 * tables */87	Bitmapset  *interleaved_parts;	/* Partition indexes of partitions which88									 * may be interleaved. See above. This is89									 * only set for LIST partitioned tables */90	int			nindexes;		/* Length of the indexes[] array */91	int		   *indexes;		/* Partition indexes */92	int			null_index;		/* Index of the null-accepting partition; -193								 * if there isn't one */94	int			default_index;	/* Index of the default partition; -1 if there95								 * isn't one */96} PartitionBoundInfoData;97 98#define partition_bound_accepts_nulls(bi) ((bi)->null_index != -1)99#define partition_bound_has_default(bi) ((bi)->default_index != -1)100 101extern int	get_hash_partition_greatest_modulus(PartitionBoundInfo bound);102extern uint64 compute_partition_hash_value(int partnatts, FmgrInfo *partsupfunc,103										   Oid *partcollation,104										   Datum *values, bool *isnull);105extern List *get_qual_from_partbound(Relation parent,106									 PartitionBoundSpec *spec);107extern PartitionBoundInfo partition_bounds_create(PartitionBoundSpec **boundspecs,108												  int nparts, PartitionKey key, int **mapping);109extern bool partition_bounds_equal(int partnatts, int16 *parttyplen,110								   bool *parttypbyval, PartitionBoundInfo b1,111								   PartitionBoundInfo b2);112extern PartitionBoundInfo partition_bounds_copy(PartitionBoundInfo src,113												PartitionKey key);114extern PartitionBoundInfo partition_bounds_merge(int partnatts,115												 FmgrInfo *partsupfunc,116												 Oid *partcollation,117												 struct RelOptInfo *outer_rel,118												 struct RelOptInfo *inner_rel,119												 JoinType jointype,120												 List **outer_parts,121												 List **inner_parts);122extern bool partitions_are_ordered(PartitionBoundInfo boundinfo,123								   Bitmapset *live_parts);124extern void check_new_partition_bound(char *relname, Relation parent,125									  PartitionBoundSpec *spec,126									  ParseState *pstate);127extern void check_default_partition_contents(Relation parent,128											 Relation default_rel,129											 PartitionBoundSpec *new_spec);130 131extern int32 partition_rbound_datum_cmp(FmgrInfo *partsupfunc,132										Oid *partcollation,133										Datum *rb_datums, PartitionRangeDatumKind *rb_kind,134										Datum *tuple_datums, int n_tuple_datums);135extern int	partition_list_bsearch(FmgrInfo *partsupfunc,136								   Oid *partcollation,137								   PartitionBoundInfo boundinfo,138								   Datum value, bool *is_equal);139extern int	partition_range_datum_bsearch(FmgrInfo *partsupfunc,140										  Oid *partcollation,141										  PartitionBoundInfo boundinfo,142										  int nvalues, Datum *values, bool *is_equal);143extern int	partition_hash_bsearch(PartitionBoundInfo boundinfo,144								   int modulus, int remainder);145 146#endif							/* PARTBOUNDS_H */147 
codekingpro/portable-devtools · Team Ai