PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ histogram_cell_budget()

static int histogram_cell_budget ( double  total_rows,
int  ndims,
int  attstattarget 
)
inlinestatic

Definition at line 107 of file gserialized_estimate_support.h.

108{
109 double budget;
110 double dims_cap;
111 double rows_cap;
112 double attstat;
113 double dims;
114
115 if (ndims <= 0)
116 return 0;
117
118 if (attstattarget <= 0)
119 attstattarget = 1;
120
121 /* Requested resolution coming from PostgreSQL's ANALYZE knob. */
122 attstat = (double)attstattarget;
123 dims = (double)ndims;
124 budget = pow(attstat, dims);
125
126 /* Hard ceiling that keeps the statistics collector responsive. */
127 dims_cap = (double)ndims * 100000.0;
128 if (budget > dims_cap)
129 budget = dims_cap;
130
131 /* Small relations do not need a histogram that dwarfs the sample. */
132 if (total_rows <= 0.0)
133 return 0;
134
135 rows_cap = 10.0 * (double)ndims * total_rows;
136 if (rows_cap < 0.0)
137 rows_cap = 0.0;
138
139 /* Keep intermediate computations in double precision before clamping. */
140 if (rows_cap > (double)INT_MAX)
141 rows_cap = (double)INT_MAX;
142
143 if (budget > rows_cap)
144 budget = rows_cap;
145
146 if (budget >= (double)INT_MAX)
147 return INT_MAX;
148 if (budget <= 0.0)
149 return 0;
150
151 return (int)budget;
152}

Referenced by compute_gserialized_stats_mode(), and histogram_budget_clamps().

Here is the caller graph for this function: