MobilityDB  1.0
tpoint_analyze.h
Go to the documentation of this file.
1 /*****************************************************************************
2  *
3  * This MobilityDB code is provided under The PostgreSQL License.
4  *
5  * Copyright (c) 2016-2021, Université libre de Bruxelles and MobilityDB
6  * contributors
7  *
8  * Permission to use, copy, modify, and distribute this software and its
9  * documentation for any purpose, without fee, and without a written
10  * agreement is hereby granted, provided that the above copyright notice and
11  * this paragraph and the following two paragraphs appear in all copies.
12  *
13  * IN NO EVENT SHALL UNIVERSITE LIBRE DE BRUXELLES BE LIABLE TO ANY PARTY FOR
14  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
15  * LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
16  * EVEN IF UNIVERSITE LIBRE DE BRUXELLES HAS BEEN ADVISED OF THE POSSIBILITY
17  * OF SUCH DAMAGE.
18  *
19  * UNIVERSITE LIBRE DE BRUXELLES SPECIFICALLY DISCLAIMS ANY WARRANTIES,
20  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21  * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON
22  * AN "AS IS" BASIS, AND UNIVERSITE LIBRE DE BRUXELLES HAS NO OBLIGATIONS TO
23  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 
24  *
25  *****************************************************************************/
26 
32 #ifndef __TPOINT_ANALYZE_H__
33 #define __TPOINT_ANALYZE_H__
34 
35 #include <postgres.h>
36 #include <fmgr.h>
37 #include <catalog/pg_type.h>
38 #include <commands/vacuum.h>
39 #include <liblwgeom.h>
40 
41 /*****************************************************************************/
42 
48 #define ND_DIMS 4
49 
55 typedef struct ND_BOX_T
56 {
57  float4 min[ND_DIMS];
58  float4 max[ND_DIMS];
59 } ND_BOX;
60 
64 typedef struct ND_IBOX_T
65 {
66  int min[ND_DIMS];
67  int max[ND_DIMS];
68 } ND_IBOX;
69 
76 typedef struct ND_STATS_T
77 {
78  /* Dimensionality of the histogram. */
79  float4 ndims;
80 
81  /* Size of n-d histogram in each dimension. */
82  float4 size[ND_DIMS];
83 
84  /* Lower-left (min) and upper-right (max) spatial bounds of histogram. */
86 
87  /* How many rows in the table itself? */
89 
90  /* How many rows were in the sample that built this histogram? */
92 
93  /* How many not-Null/Empty features were in the sample? */
95 
96  /* How many features actually got sampled in the histogram? */
98 
99  /* How many cells in histogram? (sizex*sizey*sizez*sizem) */
101 
102  /* How many cells did those histogram features cover? */
103  /* Since we are pro-rating coverage, this number should */
104  /* now always equal histogram_features */
106 
107  /* Variable length # of floats for histogram */
108  float4 value[1];
109 } ND_STATS;
110 
111 extern int nd_box_init(ND_BOX *a);
112 extern int nd_box_init_bounds(ND_BOX *a);
113 extern int nd_box_merge(const ND_BOX *source, ND_BOX *target);
114 extern void nd_box_from_gbox(const GBOX *gbox, ND_BOX *nd_box);
115 extern int nd_increment(ND_IBOX *ibox, int ndims, int *counter);
116 extern int nd_box_overlap(const ND_STATS *nd_stats, const ND_BOX *nd_box, ND_IBOX *nd_ibox);
117 extern int nd_box_intersects(const ND_BOX *a, const ND_BOX *b, int ndims);
118 extern double nd_box_ratio_overlaps(const ND_BOX *b1, const ND_BOX *b2, int ndims);
119 
120 extern void gserialized_compute_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc,
121  int sample_rows, double total_rows, int mode);
122 
123 extern Datum tpoint_analyze(PG_FUNCTION_ARGS);
124 
125 /*****************************************************************************/
126 
127 #endif
struct ND_BOX_T ND_BOX
N-dimensional box type for calculations, to avoid doing explicit axis conversions from GBOX in all ca...
#define ND_DIMS
The maximum number of dimensions our code can handle.
Definition: tpoint_analyze.h:48
float4 cells_covered
Definition: tpoint_analyze.h:105
float4 not_null_features
Definition: tpoint_analyze.h:94
float4 sample_features
Definition: tpoint_analyze.h:91
float4 histogram_cells
Definition: tpoint_analyze.h:100
void nd_box_from_gbox(const GBOX *gbox, ND_BOX *nd_box)
Set the values of an ND_BOX from a GBOX.
Definition: tpoint_analyze.c:281
struct ND_IBOX_T ND_IBOX
N-dimensional box index type.
ND_BOX extent
Definition: tpoint_analyze.h:85
int nd_box_overlap(const ND_STATS *nd_stats, const ND_BOX *nd_box, ND_IBOX *nd_ibox)
What stats cells overlap with this ND_BOX? Put the lowest cell addresses in ND_IBOX->min and the high...
Definition: tpoint_analyze.c:194
int nd_box_merge(const ND_BOX *source, ND_BOX *target)
Expand the bounds of target to include source.
Definition: tpoint_analyze.c:178
int nd_box_intersects(const ND_BOX *a, const ND_BOX *b, int ndims)
Returns true if ND_BOX a overlaps b, false otherwise.
Definition: tpoint_analyze.c:224
N-dimensional box index type.
Definition: tpoint_analyze.h:64
float4 table_features
Definition: tpoint_analyze.h:88
float4 histogram_features
Definition: tpoint_analyze.h:97
void gserialized_compute_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc, int sample_rows, double total_rows, int mode)
The gserialized_analyze_nd sets this function as a callback on the stats object when called by the AN...
Definition: tpoint_analyze.c:514
float4 max[ND_DIMS]
Definition: tpoint_analyze.h:58
int nd_box_init(ND_BOX *a)
Zero out an ND_BOX.
Definition: tpoint_analyze.c:138
double nd_box_ratio_overlaps(const ND_BOX *b1, const ND_BOX *b2, int ndims)
Returns the proportion of b2 that is covered by b1.
Definition: tpoint_analyze.c:239
int nd_box_init_bounds(ND_BOX *a)
Prepare an ND_BOX for bounds calculation: set the maxes to the smallest thing possible and the mins t...
Definition: tpoint_analyze.c:150
float4 min[ND_DIMS]
Definition: tpoint_analyze.h:57
float4 ndims
Definition: tpoint_analyze.h:79
N-dimensional statistics structure.
Definition: tpoint_analyze.h:76
Datum tpoint_analyze(PG_FUNCTION_ARGS)
Compute the statistics for temporal point columns.
Definition: tpoint_analyze.c:1083
struct ND_STATS_T ND_STATS
N-dimensional statistics structure.
N-dimensional box type for calculations, to avoid doing explicit axis conversions from GBOX in all ca...
Definition: tpoint_analyze.h:55
int nd_increment(ND_IBOX *ibox, int ndims, int *counter)
Given an n-d index array (counter), and a domain to increment it in (ibox) increment it by one...
Definition: tpoint_analyze.c:328