gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
5.0KB

  1. /*-------------------------------------------------------------------------
  2. *
  3. * partbounds.h
  4. *
  5. * Copyright (c) 2007-2019, PostgreSQL Global Development Group
  6. *
  7. * src/include/partitioning/partbounds.h
  8. *
  9. *-------------------------------------------------------------------------
  10. */
  11. #ifndef PARTBOUNDS_H
  12. #define PARTBOUNDS_H
  13. #include "fmgr.h"
  14. #include "nodes/parsenodes.h"
  15. #include "nodes/pg_list.h"
  16. #include "partitioning/partdefs.h"
  17. #include "utils/relcache.h"
  18. /*
  19. * PartitionBoundInfoData encapsulates a set of partition bounds. It is
  20. * usually associated with partitioned tables as part of its partition
  21. * descriptor, but may also be used to represent a virtual partitioned
  22. * table such as a partitioned joinrel within the planner.
  23. *
  24. * A list partition datum that is known to be NULL is never put into the
  25. * datums array. Instead, it is tracked using the null_index field.
  26. *
  27. * In the case of range partitioning, ndatums will typically be far less than
  28. * 2 * nparts, because a partition's upper bound and the next partition's lower
  29. * bound are the same in most common cases, and we only store one of them (the
  30. * upper bound). In case of hash partitioning, ndatums will be same as the
  31. * number of partitions.
  32. *
  33. * For range and list partitioned tables, datums is an array of datum-tuples
  34. * with key->partnatts datums each. For hash partitioned tables, it is an array
  35. * of datum-tuples with 2 datums, modulus and remainder, corresponding to a
  36. * given partition.
  37. *
  38. * The datums in datums array are arranged in increasing order as defined by
  39. * functions qsort_partition_rbound_cmp(), qsort_partition_list_value_cmp() and
  40. * qsort_partition_hbound_cmp() for range, list and hash partitioned tables
  41. * respectively. For range and list partitions this simply means that the
  42. * datums in the datums array are arranged in increasing order as defined by
  43. * the partition key's operator classes and collations.
  44. *
  45. * In the case of list partitioning, the indexes array stores one entry for
  46. * every datum, which is the index of the partition that accepts a given datum.
  47. * In case of range partitioning, it stores one entry per distinct range
  48. * datum, which is the index of the partition for which a given datum
  49. * is an upper bound. In the case of hash partitioning, the number of the
  50. * entries in the indexes array is same as the greatest modulus amongst all
  51. * partitions. For a given partition key datum-tuple, the index of the
  52. * partition which would accept that datum-tuple would be given by the entry
  53. * pointed by remainder produced when hash value of the datum-tuple is divided
  54. * by the greatest modulus.
  55. */
  56. typedef struct PartitionBoundInfoData
  57. {
  58. char strategy; /* hash, list or range? */
  59. int ndatums; /* Length of the datums following array */
  60. Datum **datums;
  61. PartitionRangeDatumKind **kind; /* The kind of each range bound datum;
  62. * NULL for hash and list partitioned
  63. * tables */
  64. int *indexes; /* Partition indexes */
  65. int null_index; /* Index of the null-accepting partition; -1
  66. * if there isn't one */
  67. int default_index; /* Index of the default partition; -1 if there
  68. * isn't one */
  69. } PartitionBoundInfoData;
  70. #define partition_bound_accepts_nulls(bi) ((bi)->null_index != -1)
  71. #define partition_bound_has_default(bi) ((bi)->default_index != -1)
  72. extern int get_hash_partition_greatest_modulus(PartitionBoundInfo b);
  73. extern uint64 compute_partition_hash_value(int partnatts, FmgrInfo *partsupfunc,
  74. Oid *partcollation,
  75. Datum *values, bool *isnull);
  76. extern List *get_qual_from_partbound(Relation rel, Relation parent,
  77. PartitionBoundSpec *spec);
  78. extern PartitionBoundInfo partition_bounds_create(PartitionBoundSpec **boundspecs,
  79. int nparts, PartitionKey key, int **mapping);
  80. extern bool partition_bounds_equal(int partnatts, int16 *parttyplen,
  81. bool *parttypbyval, PartitionBoundInfo b1,
  82. PartitionBoundInfo b2);
  83. extern PartitionBoundInfo partition_bounds_copy(PartitionBoundInfo src,
  84. PartitionKey key);
  85. extern bool partitions_are_ordered(PartitionBoundInfo boundinfo, int nparts);
  86. extern void check_new_partition_bound(char *relname, Relation parent,
  87. PartitionBoundSpec *spec);
  88. extern void check_default_partition_contents(Relation parent,
  89. Relation defaultRel,
  90. PartitionBoundSpec *new_spec);
  91. extern int32 partition_rbound_datum_cmp(FmgrInfo *partsupfunc,
  92. Oid *partcollation,
  93. Datum *rb_datums, PartitionRangeDatumKind *rb_kind,
  94. Datum *tuple_datums, int n_tuple_datums);
  95. extern int partition_list_bsearch(FmgrInfo *partsupfunc,
  96. Oid *partcollation,
  97. PartitionBoundInfo boundinfo,
  98. Datum value, bool *is_equal);
  99. extern int partition_range_datum_bsearch(FmgrInfo *partsupfunc,
  100. Oid *partcollation,
  101. PartitionBoundInfo boundinfo,
  102. int nvalues, Datum *values, bool *is_equal);
  103. extern int partition_hash_bsearch(PartitionBoundInfo boundinfo,
  104. int modulus, int remainder);
  105. #endif /* PARTBOUNDS_H */
上海开阖软件有限公司 沪ICP备12045867号-1