pg_aggregate.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*-------------------------------------------------------------------------
  2. *
  3. * pg_aggregate.h
  4. * definition of the "aggregate" system catalog (pg_aggregate)
  5. *
  6. *
  7. * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
  8. * Portions Copyright (c) 1994, Regents of the University of California
  9. *
  10. * src/include/catalog/pg_aggregate.h
  11. *
  12. * NOTES
  13. * The Catalog.pm module reads this file and derives schema
  14. * information.
  15. *
  16. *-------------------------------------------------------------------------
  17. */
  18. #ifndef PG_AGGREGATE_H
  19. #define PG_AGGREGATE_H
  20. #include "catalog/genbki.h"
  21. #include "catalog/pg_aggregate_d.h"
  22. #include "catalog/objectaddress.h"
  23. #include "nodes/pg_list.h"
  24. /* ----------------------------------------------------------------
  25. * pg_aggregate definition.
  26. * cpp turns this into typedef struct FormData_pg_aggregate
  27. * ----------------------------------------------------------------
  28. */
  29. CATALOG(pg_aggregate,2600,AggregateRelationId)
  30. {
  31. /* pg_proc OID of the aggregate itself */
  32. regproc aggfnoid BKI_LOOKUP(pg_proc);
  33. /* aggregate kind, see AGGKIND_ categories below */
  34. char aggkind BKI_DEFAULT(n);
  35. /* number of arguments that are "direct" arguments */
  36. int16 aggnumdirectargs BKI_DEFAULT(0);
  37. /* transition function */
  38. regproc aggtransfn BKI_LOOKUP(pg_proc);
  39. /* final function (0 if none) */
  40. regproc aggfinalfn BKI_DEFAULT(-) BKI_LOOKUP_OPT(pg_proc);
  41. /* combine function (0 if none) */
  42. regproc aggcombinefn BKI_DEFAULT(-) BKI_LOOKUP_OPT(pg_proc);
  43. /* function to convert transtype to bytea (0 if none) */
  44. regproc aggserialfn BKI_DEFAULT(-) BKI_LOOKUP_OPT(pg_proc);
  45. /* function to convert bytea to transtype (0 if none) */
  46. regproc aggdeserialfn BKI_DEFAULT(-) BKI_LOOKUP_OPT(pg_proc);
  47. /* forward function for moving-aggregate mode (0 if none) */
  48. regproc aggmtransfn BKI_DEFAULT(-) BKI_LOOKUP_OPT(pg_proc);
  49. /* inverse function for moving-aggregate mode (0 if none) */
  50. regproc aggminvtransfn BKI_DEFAULT(-) BKI_LOOKUP_OPT(pg_proc);
  51. /* final function for moving-aggregate mode (0 if none) */
  52. regproc aggmfinalfn BKI_DEFAULT(-) BKI_LOOKUP_OPT(pg_proc);
  53. /* true to pass extra dummy arguments to aggfinalfn */
  54. bool aggfinalextra BKI_DEFAULT(f);
  55. /* true to pass extra dummy arguments to aggmfinalfn */
  56. bool aggmfinalextra BKI_DEFAULT(f);
  57. /* tells whether aggfinalfn modifies transition state */
  58. char aggfinalmodify BKI_DEFAULT(r);
  59. /* tells whether aggmfinalfn modifies transition state */
  60. char aggmfinalmodify BKI_DEFAULT(r);
  61. /* associated sort operator (0 if none) */
  62. Oid aggsortop BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_operator);
  63. /* type of aggregate's transition (state) data */
  64. Oid aggtranstype BKI_LOOKUP(pg_type);
  65. /* estimated size of state data (0 for default estimate) */
  66. int32 aggtransspace BKI_DEFAULT(0);
  67. /* type of moving-aggregate state data (0 if none) */
  68. Oid aggmtranstype BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_type);
  69. /* estimated size of moving-agg state (0 for default est) */
  70. int32 aggmtransspace BKI_DEFAULT(0);
  71. #ifdef CATALOG_VARLEN /* variable-length fields start here */
  72. /* initial value for transition state (can be NULL) */
  73. text agginitval BKI_DEFAULT(_null_);
  74. /* initial value for moving-agg state (can be NULL) */
  75. text aggminitval BKI_DEFAULT(_null_);
  76. #endif
  77. } FormData_pg_aggregate;
  78. /* ----------------
  79. * Form_pg_aggregate corresponds to a pointer to a tuple with
  80. * the format of pg_aggregate relation.
  81. * ----------------
  82. */
  83. typedef FormData_pg_aggregate *Form_pg_aggregate;
  84. DECLARE_TOAST(pg_aggregate, 4159, 4160);
  85. DECLARE_UNIQUE_INDEX_PKEY(pg_aggregate_fnoid_index, 2650, AggregateFnoidIndexId, on pg_aggregate using btree(aggfnoid oid_ops));
  86. #ifdef EXPOSE_TO_CLIENT_CODE
  87. /*
  88. * Symbolic values for aggkind column. We distinguish normal aggregates
  89. * from ordered-set aggregates (which have two sets of arguments, namely
  90. * direct and aggregated arguments) and from hypothetical-set aggregates
  91. * (which are a subclass of ordered-set aggregates in which the last
  92. * direct arguments have to match up in number and datatypes with the
  93. * aggregated arguments).
  94. */
  95. #define AGGKIND_NORMAL 'n'
  96. #define AGGKIND_ORDERED_SET 'o'
  97. #define AGGKIND_HYPOTHETICAL 'h'
  98. /* Use this macro to test for "ordered-set agg including hypothetical case" */
  99. #define AGGKIND_IS_ORDERED_SET(kind) ((kind) != AGGKIND_NORMAL)
  100. /*
  101. * Symbolic values for aggfinalmodify and aggmfinalmodify columns.
  102. * Preferably, finalfns do not modify the transition state value at all,
  103. * but in some cases that would cost too much performance. We distinguish
  104. * "pure read only" and "trashes it arbitrarily" cases, as well as the
  105. * intermediate case where multiple finalfn calls are allowed but the
  106. * transfn cannot be applied anymore after the first finalfn call.
  107. */
  108. #define AGGMODIFY_READ_ONLY 'r'
  109. #define AGGMODIFY_SHAREABLE 's'
  110. #define AGGMODIFY_READ_WRITE 'w'
  111. #endif /* EXPOSE_TO_CLIENT_CODE */
  112. extern ObjectAddress AggregateCreate(const char *aggName,
  113. Oid aggNamespace,
  114. bool replace,
  115. char aggKind,
  116. int numArgs,
  117. int numDirectArgs,
  118. oidvector *parameterTypes,
  119. Datum allParameterTypes,
  120. Datum parameterModes,
  121. Datum parameterNames,
  122. List *parameterDefaults,
  123. Oid variadicArgType,
  124. List *aggtransfnName,
  125. List *aggfinalfnName,
  126. List *aggcombinefnName,
  127. List *aggserialfnName,
  128. List *aggdeserialfnName,
  129. List *aggmtransfnName,
  130. List *aggminvtransfnName,
  131. List *aggmfinalfnName,
  132. bool finalfnExtraArgs,
  133. bool mfinalfnExtraArgs,
  134. char finalfnModify,
  135. char mfinalfnModify,
  136. List *aggsortopName,
  137. Oid aggTransType,
  138. int32 aggTransSpace,
  139. Oid aggmTransType,
  140. int32 aggmTransSpace,
  141. const char *agginitval,
  142. const char *aggminitval,
  143. char proparallel);
  144. #endif /* PG_AGGREGATE_H */