gooderp18绿色标准版
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

124 lines
4.3KB

  1. /*-------------------------------------------------------------------------
  2. *
  3. * statistics.h
  4. * Extended statistics and selectivity estimation functions.
  5. *
  6. * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
  7. * Portions Copyright (c) 1994, Regents of the University of California
  8. *
  9. * src/include/statistics/statistics.h
  10. *
  11. *-------------------------------------------------------------------------
  12. */
  13. #ifndef STATISTICS_H
  14. #define STATISTICS_H
  15. #include "commands/vacuum.h"
  16. #include "nodes/pathnodes.h"
  17. #define STATS_MAX_DIMENSIONS 8 /* max number of attributes */
  18. /* Multivariate distinct coefficients */
  19. #define STATS_NDISTINCT_MAGIC 0xA352BFA4 /* struct identifier */
  20. #define STATS_NDISTINCT_TYPE_BASIC 1 /* struct version */
  21. /* MVDistinctItem represents a single combination of columns */
  22. typedef struct MVNDistinctItem
  23. {
  24. double ndistinct; /* ndistinct value for this combination */
  25. Bitmapset *attrs; /* attr numbers of items */
  26. } MVNDistinctItem;
  27. /* A MVNDistinct object, comprising all possible combinations of columns */
  28. typedef struct MVNDistinct
  29. {
  30. uint32 magic; /* magic constant marker */
  31. uint32 type; /* type of ndistinct (BASIC) */
  32. uint32 nitems; /* number of items in the statistic */
  33. MVNDistinctItem items[FLEXIBLE_ARRAY_MEMBER];
  34. } MVNDistinct;
  35. /* Multivariate functional dependencies */
  36. #define STATS_DEPS_MAGIC 0xB4549A2C /* marks serialized bytea */
  37. #define STATS_DEPS_TYPE_BASIC 1 /* basic dependencies type */
  38. /*
  39. * Functional dependencies, tracking column-level relationships (values
  40. * in one column determine values in another one).
  41. */
  42. typedef struct MVDependency
  43. {
  44. double degree; /* degree of validity (0-1) */
  45. AttrNumber nattributes; /* number of attributes */
  46. AttrNumber attributes[FLEXIBLE_ARRAY_MEMBER]; /* attribute numbers */
  47. } MVDependency;
  48. typedef struct MVDependencies
  49. {
  50. uint32 magic; /* magic constant marker */
  51. uint32 type; /* type of MV Dependencies (BASIC) */
  52. uint32 ndeps; /* number of dependencies */
  53. MVDependency *deps[FLEXIBLE_ARRAY_MEMBER]; /* dependencies */
  54. } MVDependencies;
  55. /* used to flag stats serialized to bytea */
  56. #define STATS_MCV_MAGIC 0xE1A651C2 /* marks serialized bytea */
  57. #define STATS_MCV_TYPE_BASIC 1 /* basic MCV list type */
  58. /* max items in MCV list (should be equal to max default_statistics_target) */
  59. #define STATS_MCVLIST_MAX_ITEMS 10000
  60. /*
  61. * Multivariate MCV (most-common value) lists
  62. *
  63. * A straightforward extension of MCV items - i.e. a list (array) of
  64. * combinations of attribute values, together with a frequency and null flags.
  65. */
  66. typedef struct MCVItem
  67. {
  68. double frequency; /* frequency of this combination */
  69. double base_frequency; /* frequency if independent */
  70. bool *isnull; /* NULL flags */
  71. Datum *values; /* item values */
  72. } MCVItem;
  73. /* multivariate MCV list - essentially an array of MCV items */
  74. typedef struct MCVList
  75. {
  76. uint32 magic; /* magic constant marker */
  77. uint32 type; /* type of MCV list (BASIC) */
  78. uint32 nitems; /* number of MCV items in the array */
  79. AttrNumber ndimensions; /* number of dimensions */
  80. Oid types[STATS_MAX_DIMENSIONS]; /* OIDs of data types */
  81. MCVItem items[FLEXIBLE_ARRAY_MEMBER]; /* array of MCV items */
  82. } MCVList;
  83. extern MVNDistinct *statext_ndistinct_load(Oid mvoid);
  84. extern MVDependencies *statext_dependencies_load(Oid mvoid);
  85. extern MCVList *statext_mcv_load(Oid mvoid);
  86. extern void BuildRelationExtStatistics(Relation onerel, double totalrows,
  87. int numrows, HeapTuple *rows,
  88. int natts, VacAttrStats **vacattrstats);
  89. extern bool statext_is_kind_built(HeapTuple htup, char kind);
  90. extern Selectivity dependencies_clauselist_selectivity(PlannerInfo *root,
  91. List *clauses,
  92. int varRelid,
  93. JoinType jointype,
  94. SpecialJoinInfo *sjinfo,
  95. RelOptInfo *rel,
  96. Bitmapset **estimatedclauses);
  97. extern Selectivity statext_clauselist_selectivity(PlannerInfo *root,
  98. List *clauses,
  99. int varRelid,
  100. JoinType jointype,
  101. SpecialJoinInfo *sjinfo,
  102. RelOptInfo *rel,
  103. Bitmapset **estimatedclauses);
  104. extern bool has_stats_of_kind(List *stats, char requiredkind);
  105. extern StatisticExtInfo *choose_best_statistics(List *stats, char requiredkind,
  106. Bitmapset **clause_attnums,
  107. int nclauses);
  108. #endif /* STATISTICS_H */
上海开阖软件有限公司 沪ICP备12045867号-1