PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
btree_ts.c File Reference
#include "postgres.h"
#include <limits.h>
#include "btree_gist.h"
#include "btree_utils_num.h"
#include "utils/builtins.h"
#include "utils/datetime.h"
Include dependency graph for btree_ts.c:

Go to the source code of this file.

Data Structures

struct  tsKEY
 

Macros

#define TimestampGetDatumFast(X)   PointerGetDatum(&(X))
 
#define penalty_check_max_float(val)
 

Functions

 PG_FUNCTION_INFO_V1 (gbt_ts_compress)
 
 PG_FUNCTION_INFO_V1 (gbt_tstz_compress)
 
 PG_FUNCTION_INFO_V1 (gbt_ts_fetch)
 
 PG_FUNCTION_INFO_V1 (gbt_ts_union)
 
 PG_FUNCTION_INFO_V1 (gbt_ts_picksplit)
 
 PG_FUNCTION_INFO_V1 (gbt_ts_consistent)
 
 PG_FUNCTION_INFO_V1 (gbt_ts_distance)
 
 PG_FUNCTION_INFO_V1 (gbt_tstz_consistent)
 
 PG_FUNCTION_INFO_V1 (gbt_tstz_distance)
 
 PG_FUNCTION_INFO_V1 (gbt_ts_penalty)
 
 PG_FUNCTION_INFO_V1 (gbt_ts_same)
 
static bool gbt_tsgt (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_tsge (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_tseq (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_tsle (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_tslt (const void *a, const void *b, FmgrInfo *flinfo)
 
static int gbt_tskey_cmp (const void *a, const void *b, FmgrInfo *flinfo)
 
static float8 gbt_ts_dist (const void *a, const void *b, FmgrInfo *flinfo)
 
 PG_FUNCTION_INFO_V1 (ts_dist)
 
Datum ts_dist (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (tstz_dist)
 
Datum tstz_dist (PG_FUNCTION_ARGS)
 
static Timestamp tstz_to_ts_gmt (TimestampTz ts)
 
Datum gbt_ts_compress (PG_FUNCTION_ARGS)
 
Datum gbt_tstz_compress (PG_FUNCTION_ARGS)
 
Datum gbt_ts_fetch (PG_FUNCTION_ARGS)
 
Datum gbt_ts_consistent (PG_FUNCTION_ARGS)
 
Datum gbt_ts_distance (PG_FUNCTION_ARGS)
 
Datum gbt_tstz_consistent (PG_FUNCTION_ARGS)
 
Datum gbt_tstz_distance (PG_FUNCTION_ARGS)
 
Datum gbt_ts_union (PG_FUNCTION_ARGS)
 
Datum gbt_ts_penalty (PG_FUNCTION_ARGS)
 
Datum gbt_ts_picksplit (PG_FUNCTION_ARGS)
 
Datum gbt_ts_same (PG_FUNCTION_ARGS)
 

Variables

static const gbtree_ninfo tinfo
 

Macro Definition Documentation

#define penalty_check_max_float (   val)
Value:
do { \
if ( val > FLT_MAX ) \
val = FLT_MAX; \
if ( val < -FLT_MAX ) \
val = -FLT_MAX; \
} while(false);
long val
Definition: informix.c:689

Definition at line 347 of file btree_ts.c.

Referenced by gbt_ts_penalty().

#define TimestampGetDatumFast (   X)    PointerGetDatum(&(X))

Definition at line 38 of file btree_ts.c.

Referenced by gbt_ts_dist(), gbt_tseq(), gbt_tsge(), gbt_tsgt(), gbt_tskey_cmp(), gbt_tsle(), and gbt_tslt().

Function Documentation

Datum gbt_ts_compress ( PG_FUNCTION_ARGS  )

Definition at line 207 of file btree_ts.c.

References gbt_num_compress(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

208 {
209  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
210 
212 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
GISTENTRY * gbt_num_compress(GISTENTRY *entry, const gbtree_ninfo *tinfo)
static const gbtree_ninfo tinfo
Definition: btree_ts.c:129
Datum gbt_ts_consistent ( PG_FUNCTION_ARGS  )

Definition at line 250 of file btree_ts.c.

References DatumGetPointer, gbt_num_consistent(), GIST_LEAF, GISTENTRY::key, tsKEY::lower, GBT_NUMKEY_R::lower, PG_GETARG_POINTER, PG_GETARG_TIMESTAMP, PG_GETARG_UINT16, PG_RETURN_BOOL, tsKEY::upper, and GBT_NUMKEY_R::upper.

251 {
252  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
253  Timestamp query = PG_GETARG_TIMESTAMP(1);
255 
256  /* Oid subtype = PG_GETARG_OID(3); */
257  bool *recheck = (bool *) PG_GETARG_POINTER(4);
258  tsKEY *kkk = (tsKEY *) DatumGetPointer(entry->key);
259  GBT_NUMKEY_R key;
260 
261  /* All cases served by this function are exact */
262  *recheck = false;
263 
264  key.lower = (GBT_NUMKEY *) &kkk->lower;
265  key.upper = (GBT_NUMKEY *) &kkk->upper;
266 
268  gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo, fcinfo->flinfo)
269  );
270 }
#define GIST_LEAF(entry)
Definition: gist.h:133
const GBT_NUMKEY * lower
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
uint16 StrategyNumber
Definition: stratnum.h:22
const GBT_NUMKEY * upper
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
bool gbt_num_consistent(const GBT_NUMKEY_R *key, const void *query, const StrategyNumber *strategy, bool is_leaf, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
Timestamp lower
Definition: btree_ts.c:15
Definition: btree_ts.c:13
Datum key
Definition: gist.h:123
char GBT_NUMKEY
int64 Timestamp
Definition: timestamp.h:38
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
Timestamp upper
Definition: btree_ts.c:16
#define PG_GETARG_UINT16(n)
Definition: fmgr.h:237
#define DatumGetPointer(X)
Definition: postgres.h:555
static const gbtree_ninfo tinfo
Definition: btree_ts.c:129
static float8 gbt_ts_dist ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 113 of file btree_ts.c.

References Abs, DatumGetIntervalP, DirectFunctionCall2, get_float8_infinity(), i, INTERVAL_TO_SEC, timestamp_mi(), TIMESTAMP_NOT_FINITE, and TimestampGetDatumFast.

114 {
115  const Timestamp *aa = (const Timestamp *) a;
116  const Timestamp *bb = (const Timestamp *) b;
117  Interval *i;
118 
120  return get_float8_infinity();
121 
124  TimestampGetDatumFast(*bb)));
125  return (float8) Abs(INTERVAL_TO_SEC(i));
126 }
#define DatumGetIntervalP(X)
Definition: timestamp.h:29
Datum timestamp_mi(PG_FUNCTION_ARGS)
Definition: timestamp.c:2603
#define Abs(x)
Definition: c.h:801
#define TIMESTAMP_NOT_FINITE(j)
Definition: timestamp.h:122
double float8
Definition: c.h:375
double get_float8_infinity(void)
Definition: float.c:121
int64 Timestamp
Definition: timestamp.h:38
#define TimestampGetDatumFast(X)
Definition: btree_ts.c:38
int i
#define INTERVAL_TO_SEC(ivp)
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:587
Datum gbt_ts_distance ( PG_FUNCTION_ARGS  )

Definition at line 273 of file btree_ts.c.

References DatumGetPointer, gbt_num_distance(), GIST_LEAF, GISTENTRY::key, tsKEY::lower, GBT_NUMKEY_R::lower, PG_GETARG_POINTER, PG_GETARG_TIMESTAMP, PG_RETURN_FLOAT8, tsKEY::upper, and GBT_NUMKEY_R::upper.

274 {
275  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
276  Timestamp query = PG_GETARG_TIMESTAMP(1);
277 
278  /* Oid subtype = PG_GETARG_OID(3); */
279  tsKEY *kkk = (tsKEY *) DatumGetPointer(entry->key);
280  GBT_NUMKEY_R key;
281 
282  key.lower = (GBT_NUMKEY *) &kkk->lower;
283  key.upper = (GBT_NUMKEY *) &kkk->upper;
284 
286  gbt_num_distance(&key, (void *) &query, GIST_LEAF(entry), &tinfo, fcinfo->flinfo)
287  );
288 }
#define GIST_LEAF(entry)
Definition: gist.h:133
const GBT_NUMKEY * lower
float8 gbt_num_distance(const GBT_NUMKEY_R *key, const void *query, bool is_leaf, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
const GBT_NUMKEY * upper
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
Timestamp lower
Definition: btree_ts.c:15
Definition: btree_ts.c:13
Datum key
Definition: gist.h:123
char GBT_NUMKEY
int64 Timestamp
Definition: timestamp.h:38
Timestamp upper
Definition: btree_ts.c:16
#define DatumGetPointer(X)
Definition: postgres.h:555
static const gbtree_ninfo tinfo
Definition: btree_ts.c:129
Datum gbt_ts_fetch ( PG_FUNCTION_ARGS  )

Definition at line 242 of file btree_ts.c.

References gbt_num_fetch(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

243 {
244  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
245 
247 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
GISTENTRY * gbt_num_fetch(GISTENTRY *entry, const gbtree_ninfo *tinfo)
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
static const gbtree_ninfo tinfo
Definition: btree_ts.c:129
Datum gbt_ts_penalty ( PG_FUNCTION_ARGS  )

Definition at line 356 of file btree_ts.c.

References DatumGetPointer, tsKEY::lower, penalty_check_max_float, penalty_num, PG_GETARG_POINTER, PG_RETURN_POINTER, result, and tsKEY::upper.

357 {
358  tsKEY *origentry = (tsKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
359  tsKEY *newentry = (tsKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
360  float *result = (float *) PG_GETARG_POINTER(2);
361 
362  double orgdbl[2],
363  newdbl[2];
364 
365  /*
366  * We are always using "double" timestamps here. Precision should be good
367  * enough.
368  */
369  orgdbl[0] = ((double) origentry->lower);
370  orgdbl[1] = ((double) origentry->upper);
371  newdbl[0] = ((double) newentry->lower);
372  newdbl[1] = ((double) newentry->upper);
373 
374  penalty_check_max_float(orgdbl[0]);
375  penalty_check_max_float(orgdbl[1]);
376  penalty_check_max_float(newdbl[0]);
377  penalty_check_max_float(newdbl[1]);
378 
379  penalty_num(result, orgdbl[0], orgdbl[1], newdbl[0], newdbl[1]);
380 
381  PG_RETURN_POINTER(result);
382 
383 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
return result
Definition: formatting.c:1633
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
Timestamp lower
Definition: btree_ts.c:15
Definition: btree_ts.c:13
#define penalty_num(result, olower, oupper, nlower, nupper)
Timestamp upper
Definition: btree_ts.c:16
#define DatumGetPointer(X)
Definition: postgres.h:555
#define penalty_check_max_float(val)
Definition: btree_ts.c:347
Datum gbt_ts_picksplit ( PG_FUNCTION_ARGS  )

Definition at line 387 of file btree_ts.c.

References gbt_num_picksplit(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

388 {
392  &tinfo, fcinfo->flinfo
393  ));
394 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
GIST_SPLITVEC * gbt_num_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
static const gbtree_ninfo tinfo
Definition: btree_ts.c:129
Datum gbt_ts_same ( PG_FUNCTION_ARGS  )

Definition at line 397 of file btree_ts.c.

References gbt_num_same(), PG_GETARG_POINTER, PG_RETURN_POINTER, and result.

398 {
399  tsKEY *b1 = (tsKEY *) PG_GETARG_POINTER(0);
400  tsKEY *b2 = (tsKEY *) PG_GETARG_POINTER(1);
401  bool *result = (bool *) PG_GETARG_POINTER(2);
402 
403  *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
404  PG_RETURN_POINTER(result);
405 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
bool gbt_num_same(const GBT_NUMKEY *a, const GBT_NUMKEY *b, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
return result
Definition: formatting.c:1633
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
Definition: btree_ts.c:13
static const gbtree_ninfo tinfo
Definition: btree_ts.c:129
Datum gbt_ts_union ( PG_FUNCTION_ARGS  )

Definition at line 337 of file btree_ts.c.

References gbt_num_union(), palloc(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

338 {
340  void *out = palloc(sizeof(tsKEY));
341 
342  *(int *) PG_GETARG_POINTER(1) = sizeof(tsKEY);
343  PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo, fcinfo->flinfo));
344 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
Definition: btree_ts.c:13
void * palloc(Size size)
Definition: mcxt.c:848
static const gbtree_ninfo tinfo
Definition: btree_ts.c:129
void * gbt_num_union(GBT_NUMKEY *out, const GistEntryVector *entryvec, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
static bool gbt_tseq ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 65 of file btree_ts.c.

References DatumGetBool, DirectFunctionCall2, timestamp_eq(), and TimestampGetDatumFast.

66 {
67  const Timestamp *aa = (const Timestamp *) a;
68  const Timestamp *bb = (const Timestamp *) b;
69 
72  TimestampGetDatumFast(*bb)));
73 }
#define DatumGetBool(X)
Definition: postgres.h:399
Datum timestamp_eq(PG_FUNCTION_ARGS)
Definition: timestamp.c:2029
int64 Timestamp
Definition: timestamp.h:38
#define TimestampGetDatumFast(X)
Definition: btree_ts.c:38
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:587
static bool gbt_tsge ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 54 of file btree_ts.c.

References DatumGetBool, DirectFunctionCall2, timestamp_ge(), and TimestampGetDatumFast.

55 {
56  const Timestamp *aa = (const Timestamp *) a;
57  const Timestamp *bb = (const Timestamp *) b;
58 
61  TimestampGetDatumFast(*bb)));
62 }
#define DatumGetBool(X)
Definition: postgres.h:399
Datum timestamp_ge(PG_FUNCTION_ARGS)
Definition: timestamp.c:2074
int64 Timestamp
Definition: timestamp.h:38
#define TimestampGetDatumFast(X)
Definition: btree_ts.c:38
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:587
static bool gbt_tsgt ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 43 of file btree_ts.c.

References DatumGetBool, DirectFunctionCall2, timestamp_gt(), and TimestampGetDatumFast.

44 {
45  const Timestamp *aa = (const Timestamp *) a;
46  const Timestamp *bb = (const Timestamp *) b;
47 
50  TimestampGetDatumFast(*bb)));
51 }
Datum timestamp_gt(PG_FUNCTION_ARGS)
Definition: timestamp.c:2056
#define DatumGetBool(X)
Definition: postgres.h:399
int64 Timestamp
Definition: timestamp.h:38
#define TimestampGetDatumFast(X)
Definition: btree_ts.c:38
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:587
static int gbt_tskey_cmp ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 99 of file btree_ts.c.

References DatumGetInt32, DirectFunctionCall2, tsKEY::lower, timestamp_cmp(), TimestampGetDatumFast, and tsKEY::upper.

100 {
101  tsKEY *ia = (tsKEY *) (((const Nsrt *) a)->t);
102  tsKEY *ib = (tsKEY *) (((const Nsrt *) b)->t);
103  int res;
104 
106  if (res == 0)
108 
109  return res;
110 }
#define DatumGetInt32(X)
Definition: postgres.h:478
Datum timestamp_cmp(PG_FUNCTION_ARGS)
Definition: timestamp.c:2083
Timestamp lower
Definition: btree_ts.c:15
Definition: btree_ts.c:13
#define TimestampGetDatumFast(X)
Definition: btree_ts.c:38
Timestamp upper
Definition: btree_ts.c:16
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:587
static bool gbt_tsle ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 76 of file btree_ts.c.

References DatumGetBool, DirectFunctionCall2, timestamp_le(), and TimestampGetDatumFast.

77 {
78  const Timestamp *aa = (const Timestamp *) a;
79  const Timestamp *bb = (const Timestamp *) b;
80 
83  TimestampGetDatumFast(*bb)));
84 }
#define DatumGetBool(X)
Definition: postgres.h:399
int64 Timestamp
Definition: timestamp.h:38
#define TimestampGetDatumFast(X)
Definition: btree_ts.c:38
Datum timestamp_le(PG_FUNCTION_ARGS)
Definition: timestamp.c:2065
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:587
static bool gbt_tslt ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 87 of file btree_ts.c.

References DatumGetBool, DirectFunctionCall2, timestamp_lt(), and TimestampGetDatumFast.

88 {
89  const Timestamp *aa = (const Timestamp *) a;
90  const Timestamp *bb = (const Timestamp *) b;
91 
94  TimestampGetDatumFast(*bb)));
95 }
Datum timestamp_lt(PG_FUNCTION_ARGS)
Definition: timestamp.c:2047
#define DatumGetBool(X)
Definition: postgres.h:399
int64 Timestamp
Definition: timestamp.h:38
#define TimestampGetDatumFast(X)
Definition: btree_ts.c:38
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:587
Datum gbt_tstz_compress ( PG_FUNCTION_ARGS  )

Definition at line 216 of file btree_ts.c.

References DatumGetTimestampTz, FALSE, gistentryinit, gmt, GISTENTRY::key, GISTENTRY::leafkey, tsKEY::lower, GISTENTRY::offset, GISTENTRY::page, palloc(), PG_GETARG_POINTER, PG_RETURN_POINTER, PointerGetDatum, GISTENTRY::rel, tstz_to_ts_gmt(), and tsKEY::upper.

217 {
218  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
219  GISTENTRY *retval;
220 
221  if (entry->leafkey)
222  {
223  tsKEY *r = (tsKEY *) palloc(sizeof(tsKEY));
224  TimestampTz ts = DatumGetTimestampTz(entry->key);
225  Timestamp gmt;
226 
227  gmt = tstz_to_ts_gmt(ts);
228 
229  retval = palloc(sizeof(GISTENTRY));
230  r->lower = r->upper = gmt;
231  gistentryinit(*retval, PointerGetDatum(r),
232  entry->rel, entry->page,
233  entry->offset, FALSE);
234  }
235  else
236  retval = entry;
237 
238  PG_RETURN_POINTER(retval);
239 }
Relation rel
Definition: gist.h:124
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
int64 TimestampTz
Definition: timestamp.h:39
#define PointerGetDatum(X)
Definition: postgres.h:562
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
Timestamp lower
Definition: btree_ts.c:15
Definition: btree_ts.c:13
Page page
Definition: gist.h:125
#define FALSE
Definition: c.h:219
Datum key
Definition: gist.h:123
#define DatumGetTimestampTz(X)
Definition: timestamp.h:28
bool leafkey
Definition: gist.h:127
int64 Timestamp
Definition: timestamp.h:38
static Timestamp tstz_to_ts_gmt(TimestampTz ts)
Definition: btree_ts.c:199
#define gistentryinit(e, k, r, pg, o, l)
Definition: gist.h:169
Timestamp upper
Definition: btree_ts.c:16
void * palloc(Size size)
Definition: mcxt.c:848
OffsetNumber offset
Definition: gist.h:126
static const char gmt[]
Definition: localtime.c:51
Datum gbt_tstz_consistent ( PG_FUNCTION_ARGS  )

Definition at line 291 of file btree_ts.c.

References DatumGetPointer, gbt_num_consistent(), GIST_LEAF, GISTENTRY::key, GBT_NUMKEY_R::lower, MAXALIGN, PG_GETARG_POINTER, PG_GETARG_TIMESTAMPTZ, PG_GETARG_UINT16, PG_RETURN_BOOL, gbtree_ninfo::size, tstz_to_ts_gmt(), and GBT_NUMKEY_R::upper.

292 {
293  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
296 
297  /* Oid subtype = PG_GETARG_OID(3); */
298  bool *recheck = (bool *) PG_GETARG_POINTER(4);
299  char *kkk = (char *) DatumGetPointer(entry->key);
300  GBT_NUMKEY_R key;
301  Timestamp qqq;
302 
303  /* All cases served by this function are exact */
304  *recheck = false;
305 
306  key.lower = (GBT_NUMKEY *) &kkk[0];
307  key.upper = (GBT_NUMKEY *) &kkk[MAXALIGN(tinfo.size)];
308  qqq = tstz_to_ts_gmt(query);
309 
311  gbt_num_consistent(&key, (void *) &qqq, &strategy, GIST_LEAF(entry), &tinfo, fcinfo->flinfo)
312  );
313 }
#define GIST_LEAF(entry)
Definition: gist.h:133
const GBT_NUMKEY * lower
int64 TimestampTz
Definition: timestamp.h:39
uint16 StrategyNumber
Definition: stratnum.h:22
const GBT_NUMKEY * upper
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
bool gbt_num_consistent(const GBT_NUMKEY_R *key, const void *query, const StrategyNumber *strategy, bool is_leaf, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
Datum key
Definition: gist.h:123
char GBT_NUMKEY
int64 Timestamp
Definition: timestamp.h:38
static Timestamp tstz_to_ts_gmt(TimestampTz ts)
Definition: btree_ts.c:199
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define MAXALIGN(LEN)
Definition: c.h:576
#define PG_GETARG_UINT16(n)
Definition: fmgr.h:237
#define DatumGetPointer(X)
Definition: postgres.h:555
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36
static const gbtree_ninfo tinfo
Definition: btree_ts.c:129
Datum gbt_tstz_distance ( PG_FUNCTION_ARGS  )

Definition at line 316 of file btree_ts.c.

References DatumGetPointer, gbt_num_distance(), GIST_LEAF, GISTENTRY::key, GBT_NUMKEY_R::lower, MAXALIGN, PG_GETARG_POINTER, PG_GETARG_TIMESTAMPTZ, PG_RETURN_FLOAT8, gbtree_ninfo::size, tstz_to_ts_gmt(), and GBT_NUMKEY_R::upper.

317 {
318  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
320 
321  /* Oid subtype = PG_GETARG_OID(3); */
322  char *kkk = (char *) DatumGetPointer(entry->key);
323  GBT_NUMKEY_R key;
324  Timestamp qqq;
325 
326  key.lower = (GBT_NUMKEY *) &kkk[0];
327  key.upper = (GBT_NUMKEY *) &kkk[MAXALIGN(tinfo.size)];
328  qqq = tstz_to_ts_gmt(query);
329 
331  gbt_num_distance(&key, (void *) &qqq, GIST_LEAF(entry), &tinfo, fcinfo->flinfo)
332  );
333 }
#define GIST_LEAF(entry)
Definition: gist.h:133
const GBT_NUMKEY * lower
float8 gbt_num_distance(const GBT_NUMKEY_R *key, const void *query, bool is_leaf, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
int64 TimestampTz
Definition: timestamp.h:39
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
const GBT_NUMKEY * upper
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
Datum key
Definition: gist.h:123
char GBT_NUMKEY
int64 Timestamp
Definition: timestamp.h:38
static Timestamp tstz_to_ts_gmt(TimestampTz ts)
Definition: btree_ts.c:199
#define MAXALIGN(LEN)
Definition: c.h:576
#define DatumGetPointer(X)
Definition: postgres.h:555
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36
static const gbtree_ninfo tinfo
Definition: btree_ts.c:129
PG_FUNCTION_INFO_V1 ( gbt_ts_compress  )
PG_FUNCTION_INFO_V1 ( gbt_tstz_compress  )
PG_FUNCTION_INFO_V1 ( gbt_ts_fetch  )
PG_FUNCTION_INFO_V1 ( gbt_ts_union  )
PG_FUNCTION_INFO_V1 ( gbt_ts_picksplit  )
PG_FUNCTION_INFO_V1 ( gbt_ts_consistent  )
PG_FUNCTION_INFO_V1 ( gbt_ts_distance  )
PG_FUNCTION_INFO_V1 ( gbt_tstz_consistent  )
PG_FUNCTION_INFO_V1 ( gbt_tstz_distance  )
PG_FUNCTION_INFO_V1 ( gbt_ts_penalty  )
PG_FUNCTION_INFO_V1 ( gbt_ts_same  )
PG_FUNCTION_INFO_V1 ( ts_dist  )
PG_FUNCTION_INFO_V1 ( tstz_dist  )
Datum ts_dist ( PG_FUNCTION_ARGS  )

Definition at line 146 of file btree_ts.c.

References abs_interval(), DatumGetIntervalP, Interval::day, DirectFunctionCall2, Interval::month, palloc(), PG_GETARG_DATUM, PG_GETARG_TIMESTAMP, PG_INT64_MAX, PG_RETURN_INTERVAL_P, Interval::time, timestamp_mi(), and TIMESTAMP_NOT_FINITE.

147 {
150  Interval *r;
151 
153  {
154  Interval *p = palloc(sizeof(Interval));
155 
156  p->day = INT_MAX;
157  p->month = INT_MAX;
158  p->time = PG_INT64_MAX;
160  }
161  else
163  PG_GETARG_DATUM(0),
164  PG_GETARG_DATUM(1)));
166 }
#define PG_INT64_MAX
Definition: c.h:328
#define DatumGetIntervalP(X)
Definition: timestamp.h:29
#define PG_RETURN_INTERVAL_P(x)
Definition: timestamp.h:41
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:233
Datum timestamp_mi(PG_FUNCTION_ARGS)
Definition: timestamp.c:2603
int32 day
Definition: timestamp.h:47
#define TIMESTAMP_NOT_FINITE(j)
Definition: timestamp.h:122
TimeOffset time
Definition: timestamp.h:45
int32 month
Definition: timestamp.h:48
int64 Timestamp
Definition: timestamp.h:38
Interval * abs_interval(Interval *a)
void * palloc(Size size)
Definition: mcxt.c:848
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:587
Datum tstz_dist ( PG_FUNCTION_ARGS  )

Definition at line 170 of file btree_ts.c.

References abs_interval(), DatumGetIntervalP, Interval::day, DirectFunctionCall2, Interval::month, palloc(), PG_GETARG_DATUM, PG_GETARG_TIMESTAMPTZ, PG_INT64_MAX, PG_RETURN_INTERVAL_P, Interval::time, timestamp_mi(), and TIMESTAMP_NOT_FINITE.

171 {
174  Interval *r;
175 
177  {
178  Interval *p = palloc(sizeof(Interval));
179 
180  p->day = INT_MAX;
181  p->month = INT_MAX;
182  p->time = PG_INT64_MAX;
184  }
185 
187  PG_GETARG_DATUM(0),
188  PG_GETARG_DATUM(1)));
190 }
#define PG_INT64_MAX
Definition: c.h:328
#define DatumGetIntervalP(X)
Definition: timestamp.h:29
#define PG_RETURN_INTERVAL_P(x)
Definition: timestamp.h:41
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:233
Datum timestamp_mi(PG_FUNCTION_ARGS)
Definition: timestamp.c:2603
int32 day
Definition: timestamp.h:47
#define TIMESTAMP_NOT_FINITE(j)
Definition: timestamp.h:122
TimeOffset time
Definition: timestamp.h:45
int32 month
Definition: timestamp.h:48
Interval * abs_interval(Interval *a)
void * palloc(Size size)
Definition: mcxt.c:848
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:587
static Timestamp tstz_to_ts_gmt ( TimestampTz  ts)
inlinestatic

Definition at line 199 of file btree_ts.c.

Referenced by gbt_tstz_compress(), gbt_tstz_consistent(), and gbt_tstz_distance().

200 {
201  /* No timezone correction is needed, since GMT is offset 0 by definition */
202  return (Timestamp) ts;
203 }
int64 Timestamp
Definition: timestamp.h:38

Variable Documentation

const gbtree_ninfo tinfo
static
Initial value:
=
{
sizeof(Timestamp),
16,
}
static bool gbt_tslt(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_ts.c:87
static bool gbt_tseq(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_ts.c:65
int64 Timestamp
Definition: timestamp.h:38
static int gbt_tskey_cmp(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_ts.c:99
static bool gbt_tsge(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_ts.c:54
static float8 gbt_ts_dist(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_ts.c:113
static bool gbt_tsgt(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_ts.c:43
static bool gbt_tsle(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_ts.c:76

Definition at line 129 of file btree_ts.c.