MobilityDB 1.1
temporal.h
Go to the documentation of this file.
1/*****************************************************************************
2 *
3 * This MobilityDB code is provided under The PostgreSQL License.
4 * Copyright (c) 2016-2023, Université libre de Bruxelles and MobilityDB
5 * contributors
6 *
7 * MobilityDB includes portions of PostGIS version 3 source code released
8 * under the GNU General Public License (GPLv2 or later).
9 * Copyright (c) 2001-2023, PostGIS contributors
10 *
11 * Permission to use, copy, modify, and distribute this software and its
12 * documentation for any purpose, without fee, and without a written
13 * agreement is hereby granted, provided that the above copyright notice and
14 * this paragraph and the following two paragraphs appear in all copies.
15 *
16 * IN NO EVENT SHALL UNIVERSITE LIBRE DE BRUXELLES BE LIABLE TO ANY PARTY FOR
17 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
18 * LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
19 * EVEN IF UNIVERSITE LIBRE DE BRUXELLES HAS BEEN ADVISED OF THE POSSIBILITY
20 * OF SUCH DAMAGE.
21 *
22 * UNIVERSITE LIBRE DE BRUXELLES SPECIFICALLY DISCLAIMS ANY WARRANTIES,
23 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24 * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON
25 * AN "AS IS" BASIS, AND UNIVERSITE LIBRE DE BRUXELLES HAS NO OBLIGATIONS TO
26 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 
27 *
28 *****************************************************************************/
29
34#ifndef __PG_TEMPORAL_H__
35#define __PG_TEMPORAL_H__
36
37/* PostgreSQL */
38#include <postgres.h>
39#include <lib/stringinfo.h>
40/* MEOS */
41#include "general/meos_catalog.h"
42#include "general/span.h"
43#include "general/set.h"
44#include "general/tbox.h"
45#include "point/stbox.h"
46
47/*****************************************************************************/
48
49#include <c.h>
50#include <utils/palloc.h>
51#include <utils/elog.h>
52#include <utils/array.h>
53#include <utils/lsyscache.h>
54#include <catalog/pg_type_d.h> /* for TIMESTAMPTZOID and similar */
55#include "pg_point/postgis.h"
56
57// #if POSTGRESQL_VERSION_NUMBER < 130000
58// #if USE_FLOAT4_BYVAL
59// #error Postgres needs to be configured with USE_FLOAT4_BYVAL
60// #endif
61// #endif
62
63// #if USE_FLOAT8_BYVAL
64// #error Postgres needs to be configured with USE_FLOAT8_BYVAL
65// #endif
66
67/* To avoid including fmgrprotos.h */
68extern Datum numeric_float8(PG_FUNCTION_ARGS);
69extern Datum numeric_round(PG_FUNCTION_ARGS);
70extern Datum float8_numeric(PG_FUNCTION_ARGS);
71
72#define PG_GETARG_ANYDATUM(X) (get_typlen(get_fn_expr_argtype(fcinfo->flinfo, X)) == -1 ? \
73 PointerGetDatum(PG_GETARG_VARLENA_P(X)) : PG_GETARG_DATUM(X))
74
75/*****************************************************************************
76 * Additional operator strategy numbers used in the GiST and SP-GiST temporal
77 * opclasses with respect to those defined in the file stratnum.h
78 *****************************************************************************/
79
80#define RTOverBeforeStrategyNumber 28 /* for &<# */
81#define RTBeforeStrategyNumber 29 /* for <<# */
82#define RTAfterStrategyNumber 30 /* for #>> */
83#define RTOverAfterStrategyNumber 31 /* for #&> */
84#define RTOverFrontStrategyNumber 32 /* for &</ */
85#define RTFrontStrategyNumber 33 /* for <</ */
86#define RTBackStrategyNumber 34 /* for />> */
87#define RTOverBackStrategyNumber 35 /* for /&> */
88
89/*****************************************************************************
90 * Generic oGIN perator strategy numbers indepenedent of the argument types
91 *****************************************************************************/
92
93#define GinOverlapStrategy 1 /* for && @@ */
94#define GinContainsStrategy 2 /* for @> @? */
95#define GinContainedStrategy 3 /* for <@ ?@ */
96#define GinEqualStrategy 4 /* for = @=*/
97
98/*****************************************************************************
99 * Struct definitions for the unnest operation
100 *****************************************************************************/
101
105typedef struct
106{
107 bool done;
108 int i;
109 int count;
110 Temporal *temp; /* Temporal value to unnest */
111 Datum *values; /* Values obtained by getValues(temp) */
113
114/*****************************************************************************
115 * Struct definitions for GisT indexes copied from PostgreSQL
116 *****************************************************************************/
117
122typedef struct
123{
124 /* Index of entry in the initial array */
125 int index;
126 /* Delta between penalties of entry insertion into different groups */
127 double delta;
129
133typedef struct
134{
135 double lower,
138
139/*****************************************************************************
140 * Definitions for GiST indexes
141 *****************************************************************************/
142
143/* Minimum accepted ratio of split */
144#define LIMIT_RATIO 0.3
145
146/* Convenience macros for NaN-aware comparisons */
147#define FLOAT8_EQ(a,b) (float8_cmp_internal(a, b) == 0)
148#define FLOAT8_LT(a,b) (float8_cmp_internal(a, b) < 0)
149#define FLOAT8_LE(a,b) (float8_cmp_internal(a, b) <= 0)
150#define FLOAT8_GT(a,b) (float8_cmp_internal(a, b) > 0)
151#define FLOAT8_GE(a,b) (float8_cmp_internal(a, b) >= 0)
152#define FLOAT8_MAX(a,b) (FLOAT8_GT(a, b) ? (a) : (b))
153#define FLOAT8_MIN(a,b) (FLOAT8_LT(a, b) ? (a) : (b))
154
155/*****************************************************************************
156 * Struct definitions for SP-GiST indexes
157 *****************************************************************************/
158
160typedef enum
161{
165
166/*****************************************************************************
167 * Typmod definitions
168 *****************************************************************************/
169
170#define TYPMOD_GET_SUBTYPE(typmod) ((int16) ((typmod == -1) ? (0) : (typmod & 0x0000000F)))
171
176{
179};
180
181#define TEMPSUBTYPE_STRUCT_ARRAY_LEN \
182 (sizeof tempsubtype_struct_array/sizeof(struct tempsubtype_struct))
183#define TEMPSUBTYPE_MAX_LEN 13
184
185/* Initialization function */
186
187extern void _PG_init(void);
188
189/* Miscellaneous */
190
191extern uint32_t time_max_header_size(void);
192
193/* PostgreSQL cache functions */
194
195extern FunctionCallInfo fetch_fcinfo();
196extern void store_fcinfo(FunctionCallInfo fcinfo);
197
198/* Typmod functions */
199
200extern const char *tempsubtype_name(int16 subtype);
201extern bool tempsubtype_from_string(const char *str, int16 *subtype);
202
203/* Send/receive functions */
204
205extern Temporal *temporal_recv(StringInfo buf);
206extern void temporal_write(const Temporal *temp, StringInfo buf);
207
208/* Parameter tests */
209
210extern void ensure_non_empty_array(ArrayType *array);
211
212/*****************************************************************************/
213
214#endif /* __PG_TEMPORAL_H__ */
signed short int16
Functions for building a cache of temporal types and operators.
Definition: meos_catalog.h:41
uint32_t time_max_header_size(void)
Return the size in bytes to read from toast to get the basic information from a variable-length time ...
Definition: temporal.c:96
const char * tempsubtype_name(int16 subtype)
Return the string representation of the subtype of the temporal type corresponding to the enum value.
Definition: temporal.c:182
Temporal * temporal_recv(StringInfo buf)
Return a temporal value from its binary representation read from a buffer.
Definition: temporal.c:527
void _PG_init(void)
Initialize the MobilityDB extension.
Definition: temporal.c:80
Datum float8_numeric(PG_FUNCTION_ARGS)
Datum numeric_round(PG_FUNCTION_ARGS)
void ensure_non_empty_array(ArrayType *array)
Ensure that the array is not empty.
Definition: temporal.c:141
void store_fcinfo(FunctionCallInfo fcinfo)
Store in the cache the fcinfo of the external function.
Definition: temporal.c:126
FunctionCallInfo fetch_fcinfo()
Fetch from the cache the fcinfo of the external function.
Definition: temporal.c:116
Datum numeric_float8(PG_FUNCTION_ARGS)
Basic functions for temporal types of any subtype.
void temporal_write(const Temporal *temp, StringInfo buf)
Write the binary representation of a temporal value into a buffer.
Definition: temporal.c:546
SPGistIndexType
Enumeration for the types of SP-GiST indexes.
Definition: temporal.h:161
@ SPGIST_KDTREE
Definition: temporal.h:163
@ SPGIST_QUADTREE
Definition: temporal.h:162
bool tempsubtype_from_string(const char *str, int16 *subtype)
Return the enum value corresponding to the string representation of the concrete subtype of a tempora...
Definition: temporal.c:192
uintptr_t Datum
Definition: pg_ext_defs.in.h:4
int index
Definition: temporal.h:125
double delta
Definition: temporal.h:127
Structure to represent information about an entry that can be placed to either group without affectin...
Definition: temporal.h:123
double lower
Definition: temporal.h:135
double upper
Definition: temporal.h:136
Structure to represent a projection of bounding box to an axis.
Definition: temporal.h:134
Datum * values
Definition: temporal.h:111
int count
Definition: temporal.h:109
bool done
Definition: temporal.h:107
int i
Definition: temporal.h:108
Temporal * temp
Definition: temporal.h:110
Structure to represent the state when unnesting a temporal type.
Definition: temporal.h:106
Structure to represent the common structure of temporal values of any temporal subtype.
Definition: meos.h:136
char * subtypeName
string representing the temporal type
Definition: temporal.h:177
int16 subtype
subtype
Definition: temporal.h:178
Structure to represent the temporal subtype array.
Definition: temporal.h:176