MobilityDB 1.3
Loading...
Searching...
No Matches
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-2025, 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-2025, 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 <fmgr.h>
40#include <catalog/pg_type_d.h> /* for TIMESTAMPTZOID and similar */
41#include <lib/stringinfo.h>
42#include <utils/array.h>
43#include <utils/lsyscache.h>
44/* MEOS */
45#include <meos.h>
46#include "temporal/meos_catalog.h"
47
48/*****************************************************************************/
49
50/* To avoid including fmgrprotos.h */
51extern Datum numeric_float8(PG_FUNCTION_ARGS);
52extern Datum numeric_round(PG_FUNCTION_ARGS);
53extern Datum float8_numeric(PG_FUNCTION_ARGS);
54
55#define PG_GETARG_ANYDATUM(X) (get_typlen(get_fn_expr_argtype(fcinfo->flinfo, X)) == -1 ? \
56 PointerGetDatum(PG_GETARG_VARLENA_P(X)) : PG_GETARG_DATUM(X))
57
58/*****************************************************************************
59 * Generic GIN operator strategy numbers independent of the argument types
60 *****************************************************************************/
61
62#define GinOverlapStrategy 1 /* for && @@ */
63#define GinContainsStrategy 2 /* for @> @? */
64#define GinContainedStrategy 3 /* for <@ ?@ */
65#define GinEqualStrategy 4 /* for = @=*/
66
67/*****************************************************************************
68 * Struct definitions for the unnest operation
69 *****************************************************************************/
70
74typedef struct
75{
76 bool done;
77 int i;
78 int count;
79 Temporal *temp; /* Temporal value to unnest */
80 Datum *values; /* Values obtained by getValues(temp) */
82
83/*****************************************************************************
84 * Struct definitions for GisT indexes copied from PostgreSQL
85 *****************************************************************************/
86
91typedef struct
92{
93 /* Index of entry in the initial array */
94 int index;
95 /* Delta between penalties of entry insertion into different groups */
96 double delta;
98
102typedef struct
103{
104 double lower,
107
108/*****************************************************************************
109 * Definitions for GiST indexes
110 *****************************************************************************/
111
112/* Minimum accepted ratio of split */
113#define LIMIT_RATIO 0.3
114
115/* Convenience macros for NaN-aware comparisons */
116#define FLOAT8_EQ(a,b) (float8_cmp_internal(a, b) == 0)
117#define FLOAT8_LT(a,b) (float8_cmp_internal(a, b) < 0)
118#define FLOAT8_LE(a,b) (float8_cmp_internal(a, b) <= 0)
119#define FLOAT8_GT(a,b) (float8_cmp_internal(a, b) > 0)
120#define FLOAT8_GE(a,b) (float8_cmp_internal(a, b) >= 0)
121#define FLOAT8_MAX(a,b) (FLOAT8_GT(a, b) ? (a) : (b))
122#define FLOAT8_MIN(a,b) (FLOAT8_LT(a, b) ? (a) : (b))
123
124/*****************************************************************************
125 * Struct definitions for SP-GiST indexes
126 *****************************************************************************/
127
129typedef enum
130{
134
135/*****************************************************************************
136 * Typmod definitions
137 *****************************************************************************/
138
139#define TYPMOD_MAXLEN 64
140
141/*
142 * MobilityDB reuses the typmod definitions from PostGIS using the two spare
143 * bits left for storing the temporal subtype.
144 *
145 * The 'typmod' is an int32_t used as follows:
146 * Plus/minus = Top bit.
147 * Spare bits = Next 2 bits -> Used in MobilityDB to store the temporal subtype
148 * SRID = Next 21 bits.
149 * TYPE = Next 6 bits.
150 * ZM Flags = Bottom 2 bits.
151 *
152#define TYPMOD_GET_SRID(typmod) ((((typmod) & 0x0FFFFF00) - ((typmod) & 0x10000000)) >> 8)
153#define TYPMOD_SET_SRID(typmod, srid) ((typmod) = (((typmod) & 0xE00000FF) | ((srid & 0x001FFFFF)<<8)))
154#define TYPMOD_GET_TYPE(typmod) ((typmod & 0x000000FC)>>2)
155#define TYPMOD_SET_TYPE(typmod, type) ((typmod) = (typmod & 0xFFFFFF03) | ((type & 0x0000003F)<<2))
156#define TYPMOD_GET_Z(typmod) ((typmod & 0x00000002)>>1)
157#define TYPMOD_SET_Z(typmod) ((typmod) = typmod | 0x00000002)
158#define TYPMOD_GET_M(typmod) (typmod & 0x00000001)
159#define TYPMOD_SET_M(typmod) ((typmod) = typmod | 0x00000001)
160#define TYPMOD_GET_NDIMS(typmod) (2+TYPMOD_GET_Z(typmod)+TYPMOD_GET_M(typmod))
161 *
162 */
163
164/* Get/set the temporal subtype from the 2 spare bits from PostGIS */
165#define TYPMOD_GET_TEMPSUBTYPE(typmod) ((typmod & 0x60000000)>>29)
166#define TYPMOD_SET_TEMPSUBTYPE(typmod, tempsubtype) ((typmod) = (((typmod) & 0x9FFFFFFF) | ((tempsubtype & 0x00000003)<<29)))
167
173#define TIME_MAX_HEADER_SIZE DOUBLE_PAD(Max(sizeof(Set), sizeof(SpanSet)))
174
175/*****************************************************************************
176 * Miscellaneous
177 *****************************************************************************/
178
179/* Initialization function */
180
181extern void _PG_init(void);
182
183/* Header size in bytes for time types to read from toast */
184
185extern uint32_t time_max_header_size(void);
186
187/* PostgreSQL cache functions */
188
189extern FunctionCallInfo fetch_fcinfo(void);
190extern void store_fcinfo(FunctionCallInfo fcinfo);
191
192/* Input an interpolation string and convert it to the interp enum */
193
194extern interpType input_interp_string(FunctionCallInfo fcinfo, int argno);
195
196/* Send/receive functions */
197
198extern Temporal *temporal_recv(StringInfo buf);
199extern void temporal_write(const Temporal *temp, StringInfo buf);
200
201extern bytea *Datum_as_wkb(FunctionCallInfo fcinfo, Datum value, meosType type,
202 bool extended);
203extern text *Datum_as_hexwkb(FunctionCallInfo fcinfo, Datum value,
204 meosType type);
205
206/* Parameter tests */
207
208extern bool ensure_not_empty_array(ArrayType *array);
209
210/* Comparison functions */
211
212extern Datum EAcomp_temporal_temporal(FunctionCallInfo fcinfo,
213 int (*func)(const Temporal *, const Temporal *));
214extern Datum Tcomp_temporal_temporal(FunctionCallInfo fcinfo,
215 Datum (*func)(Datum, Datum, meosType));
216
217extern Datum Tcomp_temporal_base(FunctionCallInfo fcinfo,
218 Datum (*func)(Datum, Datum, meosType));
219
220/* Indexing functions */
221
222extern Temporal *temporal_slice(Datum tempdatum);
223
224/*****************************************************************************/
225
226#endif /* __PG_TEMPORAL_H__ */
interpType input_interp_string(FunctionCallInfo fcinfo, int argno)
Return a temporal instant from a value and a timestamptz @sqlfn tint(), tfloat(), ....
Definition: temporal.c:521
meosType
Enumeration that defines the built-in and temporal types used in MobilityDB.
Definition: meos_catalog.h:55
interpType
Enumeration that defines the interpolation types used in MEOS.
Definition: meos.h:161
External API of the Mobility Engine Open Source (MEOS) library.
uint32_t time_max_header_size(void)
FunctionCallInfo fetch_fcinfo(void)
Fetch from the cache the fcinfo of the external function.
Definition: temporal.c:104
Temporal * temporal_slice(Datum tempdatum)
Peek into a temporal datum to find the bounding box.
Definition: temporal.c:255
bool ensure_not_empty_array(ArrayType *array)
Ensure that the array is not empty.
Definition: temporal.c:129
Temporal * temporal_recv(StringInfo buf)
Return a temporal value from its binary representation read from a buffer.
Definition: temporal.c:441
void _PG_init(void)
Initialize the MobilityDB extension.
Definition: temporal.c:81
Datum EAcomp_temporal_temporal(FunctionCallInfo fcinfo, int(*func)(const Temporal *, const Temporal *))
Generic function for the ever/always comparison operators.
Definition: temporal_compops.c:99
Datum float8_numeric(PG_FUNCTION_ARGS)
Datum numeric_round(PG_FUNCTION_ARGS)
Datum Tcomp_temporal_temporal(FunctionCallInfo fcinfo, Datum(*func)(Datum, Datum, meosType))
Return the temporal comparison of two temporal values.
Definition: temporal_compops.c:684
Datum Tcomp_temporal_base(FunctionCallInfo fcinfo, Datum(*func)(Datum, Datum, meosType))
Return the temporal comparison of a temporal value and a base value.
Definition: temporal_compops.c:667
text * Datum_as_hexwkb(FunctionCallInfo fcinfo, Datum value, meosType type)
Output a value in the Well-Known Binary (WKB) or Extended Well-Known Binary (EWKB) representation in ...
Definition: type_out.c:253
void store_fcinfo(FunctionCallInfo fcinfo)
Store in the cache the fcinfo of the external function.
Definition: temporal.c:114
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:460
bytea * Datum_as_wkb(FunctionCallInfo fcinfo, Datum value, meosType type, bool extended)
Output a value in the (Extended) Well-Known Binary (WKB or EWKB) representation.
Definition: type_out.c:227
SPGistIndexType
Enumeration for the types of SP-GiST indexes.
Definition: temporal.h:130
@ SPGIST_KDTREE
Definition: temporal.h:132
@ SPGIST_QUADTREE
Definition: temporal.h:131
uintptr_t Datum
Definition: postgres_ext_defs.in.h:7
int index
Definition: temporal.h:94
double delta
Definition: temporal.h:96
Structure to represent information about an entry that can be placed to either group without affectin...
Definition: temporal.h:92
double lower
Definition: temporal.h:104
double upper
Definition: temporal.h:105
Structure to represent a projection of bounding box to an axis.
Definition: temporal.h:103
Datum * values
Definition: temporal.h:80
int count
Definition: temporal.h:78
bool done
Definition: temporal.h:76
int i
Definition: temporal.h:77
Temporal * temp
Definition: temporal.h:79
Structure to represent the state when unnesting a temporal type.
Definition: temporal.h:75
Structure to represent the common structure of temporal values of any temporal subtype.
Definition: meos.h:173
Definition: postgres_ext_defs.in.h:34