LCOV - differential code coverage report
Current view: top level - contrib/btree_gist - btree_ts.c (source / functions) Coverage Total Hit UBC GNC CBC DCB
Current: 4b3c9325757dfd8f2312e9f1a8decf4431f344ae vs e87b024bfb8dd55e3049b1b6e6ab4e810cf1abc8 Lines: 100.0 % 171 171 3 168 3
Current Date: 2026-11-28 16:48:44 +0900 Functions: 100.0 % 37 37 3 34
Baseline: lcov-20261128-baseline Branches: 76.9 % 52 40 12 40
Baseline Date: 2026-11-28 16:48:48 +0900 Line coverage date bins:
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
(1,7] days: 100.0 % 17 17 17
(30,360] days: 100.0 % 7 7 3 4
(360..) days: 100.0 % 147 147 147
Function coverage date bins:
(360..) days: 100.0 % 37 37 3 34
Branch coverage date bins:
(1,7] days: 100.0 % 8 8 8
(360..) days: 72.7 % 44 32 12 32

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : /*
                                  2                 :                :  * contrib/btree_gist/btree_ts.c
                                  3                 :                :  */
                                  4                 :                : #include "postgres.h"
                                  5                 :                : 
                                  6                 :                : #include <limits.h>
                                  7                 :                : 
                                  8                 :                : #include "btree_gist.h"
                                  9                 :                : #include "btree_utils_num.h"
                                 10                 :                : #include "common/int.h"
                                 11                 :                : #include "utils/fmgrprotos.h"
                                 12                 :                : #include "utils/timestamp.h"
                                 13                 :                : #include "utils/float.h"
                                 14                 :                : #include "utils/rel.h"
                                 15                 :                : #include "utils/sortsupport.h"
                                 16                 :                : 
                                 17                 :                : typedef struct
                                 18                 :                : {
                                 19                 :                :     Timestamp   lower;
                                 20                 :                :     Timestamp   upper;
                                 21                 :                : } tsKEY;
                                 22                 :                : 
                                 23                 :                : /* GiST support functions */
 8219 teodor@sigaev.ru           24                 :CBC           5 : PG_FUNCTION_INFO_V1(gbt_ts_compress);
                                 25                 :              4 : PG_FUNCTION_INFO_V1(gbt_tstz_compress);
 4264 heikki.linnakangas@i       26                 :              6 : PG_FUNCTION_INFO_V1(gbt_ts_fetch);
 8219 teodor@sigaev.ru           27                 :              6 : PG_FUNCTION_INFO_V1(gbt_ts_union);
                                 28                 :              6 : PG_FUNCTION_INFO_V1(gbt_ts_picksplit);
                                 29                 :              5 : PG_FUNCTION_INFO_V1(gbt_ts_consistent);
 5750 tgl@sss.pgh.pa.us          30                 :              5 : PG_FUNCTION_INFO_V1(gbt_ts_distance);
 8219 teodor@sigaev.ru           31                 :              4 : PG_FUNCTION_INFO_V1(gbt_tstz_consistent);
 5750 tgl@sss.pgh.pa.us          32                 :              4 : PG_FUNCTION_INFO_V1(gbt_tstz_distance);
 8219 teodor@sigaev.ru           33                 :              6 : PG_FUNCTION_INFO_V1(gbt_ts_penalty);
                                 34                 :              6 : PG_FUNCTION_INFO_V1(gbt_ts_same);
  604 heikki.linnakangas@i       35                 :              6 : PG_FUNCTION_INFO_V1(gbt_ts_sortsupport);
                                 36                 :                : 
                                 37                 :                : 
                                 38                 :                : /* define for comparison */
                                 39                 :                : 
                                 40                 :                : static bool
 3539 andrew@dunslane.net        41                 :          12431 : gbt_tsgt(const void *a, const void *b, FmgrInfo *flinfo)
                                 42                 :                : {
 6795 tgl@sss.pgh.pa.us          43                 :          12431 :     const Timestamp *aa = (const Timestamp *) a;
                                 44                 :          12431 :     const Timestamp *bb = (const Timestamp *) b;
                                 45                 :                : 
                                 46                 :          12431 :     return DatumGetBool(DirectFunctionCall2(timestamp_gt,
                                 47                 :                :                                             TimestampGetDatum(*aa),
                                 48                 :                :                                             TimestampGetDatum(*bb)));
                                 49                 :                : }
                                 50                 :                : 
                                 51                 :                : static bool
 3539 andrew@dunslane.net        52                 :           2350 : gbt_tsge(const void *a, const void *b, FmgrInfo *flinfo)
                                 53                 :                : {
 6795 tgl@sss.pgh.pa.us          54                 :           2350 :     const Timestamp *aa = (const Timestamp *) a;
                                 55                 :           2350 :     const Timestamp *bb = (const Timestamp *) b;
                                 56                 :                : 
                                 57                 :           2350 :     return DatumGetBool(DirectFunctionCall2(timestamp_ge,
                                 58                 :                :                                             TimestampGetDatum(*aa),
                                 59                 :                :                                             TimestampGetDatum(*bb)));
                                 60                 :                : }
                                 61                 :                : 
                                 62                 :                : static bool
 3539 andrew@dunslane.net        63                 :           5001 : gbt_tseq(const void *a, const void *b, FmgrInfo *flinfo)
                                 64                 :                : {
 6795 tgl@sss.pgh.pa.us          65                 :           5001 :     const Timestamp *aa = (const Timestamp *) a;
                                 66                 :           5001 :     const Timestamp *bb = (const Timestamp *) b;
                                 67                 :                : 
                                 68                 :           5001 :     return DatumGetBool(DirectFunctionCall2(timestamp_eq,
                                 69                 :                :                                             TimestampGetDatum(*aa),
                                 70                 :                :                                             TimestampGetDatum(*bb)));
                                 71                 :                : }
                                 72                 :                : 
                                 73                 :                : static bool
 3539 andrew@dunslane.net        74                 :           3645 : gbt_tsle(const void *a, const void *b, FmgrInfo *flinfo)
                                 75                 :                : {
 6795 tgl@sss.pgh.pa.us          76                 :           3645 :     const Timestamp *aa = (const Timestamp *) a;
                                 77                 :           3645 :     const Timestamp *bb = (const Timestamp *) b;
                                 78                 :                : 
                                 79                 :           3645 :     return DatumGetBool(DirectFunctionCall2(timestamp_le,
                                 80                 :                :                                             TimestampGetDatum(*aa),
                                 81                 :                :                                             TimestampGetDatum(*bb)));
                                 82                 :                : }
                                 83                 :                : 
                                 84                 :                : static bool
 3539 andrew@dunslane.net        85                 :          12969 : gbt_tslt(const void *a, const void *b, FmgrInfo *flinfo)
                                 86                 :                : {
 6795 tgl@sss.pgh.pa.us          87                 :          12969 :     const Timestamp *aa = (const Timestamp *) a;
                                 88                 :          12969 :     const Timestamp *bb = (const Timestamp *) b;
                                 89                 :                : 
                                 90                 :          12969 :     return DatumGetBool(DirectFunctionCall2(timestamp_lt,
                                 91                 :                :                                             TimestampGetDatum(*aa),
                                 92                 :                :                                             TimestampGetDatum(*bb)));
                                 93                 :                : }
                                 94                 :                : 
                                 95                 :                : static int
 3539 andrew@dunslane.net        96                 :           4830 : gbt_tskey_cmp(const void *a, const void *b, FmgrInfo *flinfo)
                                 97                 :                : {
 5557 peter_e@gmx.net            98                 :           4830 :     tsKEY      *ia = (tsKEY *) (((const Nsrt *) a)->t);
                                 99                 :           4830 :     tsKEY      *ib = (tsKEY *) (((const Nsrt *) b)->t);
                                100                 :                :     int         res;
                                101                 :                : 
  472 tgl@sss.pgh.pa.us         102                 :           4830 :     res = DatumGetInt32(DirectFunctionCall2(timestamp_cmp, TimestampGetDatum(ia->lower), TimestampGetDatum(ib->lower)));
 6205 teodor@sigaev.ru          103         [ +  + ]:           4830 :     if (res == 0)
  472 tgl@sss.pgh.pa.us         104                 :           3743 :         return DatumGetInt32(DirectFunctionCall2(timestamp_cmp, TimestampGetDatum(ia->upper), TimestampGetDatum(ib->upper)));
                                105                 :                : 
 6205 teodor@sigaev.ru          106                 :           1087 :     return res;
                                107                 :                : }
                                108                 :                : 
                                109                 :                : static float8
 3539 andrew@dunslane.net       110                 :           1688 : gbt_ts_dist(const void *a, const void *b, FmgrInfo *flinfo)
                                111                 :                : {
 5750 tgl@sss.pgh.pa.us         112                 :           1688 :     const Timestamp *aa = (const Timestamp *) a;
                                113                 :           1688 :     const Timestamp *bb = (const Timestamp *) b;
                                114                 :                :     Interval   *i;
                                115                 :                :     int64       diff;
                                116                 :                : 
                                117                 :                :     /*
                                118                 :                :      * Treat same-sign infinities as equal, as the float8 opclass does; but
                                119                 :                :      * any other case involving infinite inputs yields infinite distance.
                                120                 :                :      */
                                121   [ +  +  +  +  :           1688 :     if (TIMESTAMP_NOT_FINITE(*aa) || TIMESTAMP_NOT_FINITE(*bb))
                                        +  +  +  + ]
    5                           122         [ +  + ]:           1145 :         return (*aa == *bb) ? 0.0 : get_float8_infinity();
                                123                 :                : 
                                124                 :                :     /*
                                125                 :                :      * Some valid timestamps are too far apart for their difference to fit in
                                126                 :                :      * an interval.  Avoid throwing an error in that case, just do the
                                127                 :                :      * computation ourselves.  (This is not exactly comparable to what
                                128                 :                :      * timestamp_mi does, since we don't apply interval_justify_hours, but it
                                129                 :                :      * should be close enough.)
                                130                 :                :      */
                                131         [ +  + ]:            543 :     if (pg_sub_s64_overflow(*aa, *bb, &diff))
                                132                 :              1 :         return fabs(((float8) *aa - (float8) *bb) / USECS_PER_SEC);
                                133                 :                : 
                                134                 :                :     /* Otherwise we use timestamp_mi and convert its output to seconds */
 5750                           135                 :            542 :     i = DatumGetIntervalP(DirectFunctionCall2(timestamp_mi,
                                136                 :                :                                               TimestampGetDatum(*aa),
                                137                 :                :                                               TimestampGetDatum(*bb)));
 1513 peter@eisentraut.org      138                 :            542 :     return fabs(INTERVAL_TO_SEC(i));
                                139                 :                : }
                                140                 :                : 
                                141                 :                : static const gbtree_ninfo tinfo =
                                142                 :                : {
                                143                 :                :     gbt_t_ts,
                                144                 :                :     sizeof(Timestamp),
                                145                 :                :     16,                         /* sizeof(gbtreekey16) */
                                146                 :                :     gbt_tsgt,
                                147                 :                :     gbt_tsge,
                                148                 :                :     gbt_tseq,
                                149                 :                :     gbt_tsle,
                                150                 :                :     gbt_tslt,
                                151                 :                :     gbt_tskey_cmp,
                                152                 :                :     gbt_ts_dist
                                153                 :                : };
                                154                 :                : 
                                155                 :                : 
 5750 tgl@sss.pgh.pa.us         156                 :              4 : PG_FUNCTION_INFO_V1(ts_dist);
                                157                 :                : Datum
                                158                 :            578 : ts_dist(PG_FUNCTION_ARGS)
                                159                 :                : {
                                160                 :            578 :     Timestamp   a = PG_GETARG_TIMESTAMP(0);
                                161                 :            578 :     Timestamp   b = PG_GETARG_TIMESTAMP(1);
                                162                 :                :     Interval   *r;
                                163                 :                : 
                                164   [ +  +  +  +  :            578 :     if (TIMESTAMP_NOT_FINITE(a) || TIMESTAMP_NOT_FINITE(b))
                                        +  -  -  + ]
                                165                 :                :     {
  358 michael@paquier.xyz       166                 :             30 :         Interval   *p = palloc_object(Interval);
                                167                 :                : 
    5 tgl@sss.pgh.pa.us         168         [ +  + ]:             30 :         if (a == b)
                                169                 :                :         {
                                170                 :                :             /* same-sign infinities are equal, as in gbt_ts_dist */
                                171                 :              6 :             p->day = 0;
                                172                 :              6 :             p->month = 0;
                                173                 :              6 :             p->time = 0;
                                174                 :                :         }
                                175                 :                :         else
                                176                 :                :         {
                                177                 :                :             /* for all other cases, report interval +Infinity */
                                178                 :             24 :             p->day = INT_MAX;
                                179                 :             24 :             p->month = INT_MAX;
                                180                 :             24 :             p->time = PG_INT64_MAX;
                                181                 :                :         }
 5750                           182                 :             30 :         PG_RETURN_INTERVAL_P(p);
                                183                 :                :     }
                                184                 :                :     else
 5711 bruce@momjian.us          185                 :            548 :         r = DatumGetIntervalP(DirectFunctionCall2(timestamp_mi,
                                186                 :                :                                                   PG_GETARG_DATUM(0),
                                187                 :                :                                                   PG_GETARG_DATUM(1)));
                                188                 :            548 :     PG_RETURN_INTERVAL_P(abs_interval(r));
                                189                 :                : }
                                190                 :                : 
 5750 tgl@sss.pgh.pa.us         191                 :              4 : PG_FUNCTION_INFO_V1(tstz_dist);
                                192                 :                : Datum
                                193                 :            558 : tstz_dist(PG_FUNCTION_ARGS)
                                194                 :                : {
 5711 bruce@momjian.us          195                 :            558 :     TimestampTz a = PG_GETARG_TIMESTAMPTZ(0);
                                196                 :            558 :     TimestampTz b = PG_GETARG_TIMESTAMPTZ(1);
                                197                 :                :     Interval   *r;
                                198                 :                : 
 5750 tgl@sss.pgh.pa.us         199   [ +  +  +  +  :            558 :     if (TIMESTAMP_NOT_FINITE(a) || TIMESTAMP_NOT_FINITE(b))
                                        +  -  -  + ]
                                200                 :                :     {
  358 michael@paquier.xyz       201                 :             24 :         Interval   *p = palloc_object(Interval);
                                202                 :                : 
    5 tgl@sss.pgh.pa.us         203         [ +  + ]:             24 :         if (a == b)
                                204                 :                :         {
                                205                 :                :             /* same-sign infinities are equal, as in gbt_ts_dist */
                                206                 :              6 :             p->day = 0;
                                207                 :              6 :             p->month = 0;
                                208                 :              6 :             p->time = 0;
                                209                 :                :         }
                                210                 :                :         else
                                211                 :                :         {
                                212                 :                :             /* for all other cases, report interval +Infinity */
                                213                 :             18 :             p->day = INT_MAX;
                                214                 :             18 :             p->month = INT_MAX;
                                215                 :             18 :             p->time = PG_INT64_MAX;
                                216                 :                :         }
 5750                           217                 :             24 :         PG_RETURN_INTERVAL_P(p);
                                218                 :                :     }
                                219                 :                : 
                                220                 :            534 :     r = DatumGetIntervalP(DirectFunctionCall2(timestamp_mi,
                                221                 :                :                                               PG_GETARG_DATUM(0),
                                222                 :                :                                               PG_GETARG_DATUM(1)));
 5711 bruce@momjian.us          223                 :            534 :     PG_RETURN_INTERVAL_P(abs_interval(r));
                                224                 :                : }
                                225                 :                : 
                                226                 :                : /**************************************************
                                227                 :                :  * GiST support functions
                                228                 :                :  **************************************************/
                                229                 :                : 
                                230                 :                : static inline Timestamp
 6795 tgl@sss.pgh.pa.us         231                 :           7178 : tstz_to_ts_gmt(TimestampTz ts)
                                232                 :                : {
                                233                 :                :     /* No timezone correction is needed, since GMT is offset 0 by definition */
 4426                           234                 :           7178 :     return (Timestamp) ts;
                                235                 :                : }
                                236                 :                : 
                                237                 :                : 
                                238                 :                : Datum
 8219 teodor@sigaev.ru          239                 :           2614 : gbt_ts_compress(PG_FUNCTION_ARGS)
                                240                 :                : {
 8126 bruce@momjian.us          241                 :           2614 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
                                242                 :                : 
 4265 heikki.linnakangas@i      243                 :           2614 :     PG_RETURN_POINTER(gbt_num_compress(entry, &tinfo));
                                244                 :                : }
                                245                 :                : 
                                246                 :                : Datum
 8219 teodor@sigaev.ru          247                 :            551 : gbt_tstz_compress(PG_FUNCTION_ARGS)
                                248                 :                : {
 8126 bruce@momjian.us          249                 :            551 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
                                250                 :                :     GISTENTRY  *retval;
                                251                 :                : 
                                252         [ +  + ]:            551 :     if (entry->leafkey)
                                253                 :                :     {
  358 michael@paquier.xyz       254                 :            549 :         tsKEY      *r = palloc_object(tsKEY);
 6795 tgl@sss.pgh.pa.us         255                 :            549 :         TimestampTz ts = DatumGetTimestampTz(entry->key);
                                256                 :                :         Timestamp   gmt;
                                257                 :                : 
                                258                 :            549 :         gmt = tstz_to_ts_gmt(ts);
                                259                 :                : 
  358 michael@paquier.xyz       260                 :            549 :         retval = palloc_object(GISTENTRY);
 8126 bruce@momjian.us          261                 :            549 :         r->lower = r->upper = gmt;
                                262                 :            549 :         gistentryinit(*retval, PointerGetDatum(r),
                                263                 :                :                       entry->rel, entry->page,
                                264                 :                :                       entry->offset, false);
                                265                 :                :     }
                                266                 :                :     else
                                267                 :              2 :         retval = entry;
                                268                 :                : 
                                269                 :            551 :     PG_RETURN_POINTER(retval);
                                270                 :                : }
                                271                 :                : 
                                272                 :                : Datum
 4264 heikki.linnakangas@i      273                 :           1678 : gbt_ts_fetch(PG_FUNCTION_ARGS)
                                274                 :                : {
                                275                 :           1678 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
                                276                 :                : 
                                277                 :           1678 :     PG_RETURN_POINTER(gbt_num_fetch(entry, &tinfo));
                                278                 :                : }
                                279                 :                : 
                                280                 :                : Datum
 8219 teodor@sigaev.ru          281                 :           2204 : gbt_ts_consistent(PG_FUNCTION_ARGS)
                                282                 :                : {
 8126 bruce@momjian.us          283                 :           2204 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
 6795 tgl@sss.pgh.pa.us         284                 :           2204 :     Timestamp   query = PG_GETARG_TIMESTAMP(1);
 6802                           285                 :           2204 :     StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
                                286                 :                : #ifdef NOT_USED
                                287                 :                :     Oid         subtype = PG_GETARG_OID(3);
                                288                 :                : #endif
                                289                 :           2204 :     bool       *recheck = (bool *) PG_GETARG_POINTER(4);
 8126 bruce@momjian.us          290                 :           2204 :     tsKEY      *kkk = (tsKEY *) DatumGetPointer(entry->key);
                                291                 :                :     GBT_NUMKEY_R key;
                                292                 :                : 
                                293                 :                :     /* All cases served by this function are exact */
 6802 tgl@sss.pgh.pa.us         294                 :           2204 :     *recheck = false;
                                295                 :                : 
 6379 bruce@momjian.us          296                 :           2204 :     key.lower = (GBT_NUMKEY *) &kkk->lower;
                                297                 :           2204 :     key.upper = (GBT_NUMKEY *) &kkk->upper;
                                298                 :                : 
  148 tgl@sss.pgh.pa.us         299                 :GNC        2204 :     PG_RETURN_BOOL(gbt_num_consistent(&key, &query, strategy,
                                300                 :                :                                       GIST_LEAF(entry), &tinfo, fcinfo->flinfo));
                                301                 :                : }
                                302                 :                : 
                                303                 :                : Datum
 5750 tgl@sss.pgh.pa.us         304                 :CBC         860 : gbt_ts_distance(PG_FUNCTION_ARGS)
                                305                 :                : {
                                306                 :            860 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
                                307                 :            860 :     Timestamp   query = PG_GETARG_TIMESTAMP(1);
                                308                 :                : #ifdef NOT_USED
                                309                 :                :     Oid         subtype = PG_GETARG_OID(3);
                                310                 :                : #endif
                                311                 :            860 :     tsKEY      *kkk = (tsKEY *) DatumGetPointer(entry->key);
                                312                 :                :     GBT_NUMKEY_R key;
                                313                 :                : 
                                314                 :            860 :     key.lower = (GBT_NUMKEY *) &kkk->lower;
                                315                 :            860 :     key.upper = (GBT_NUMKEY *) &kkk->upper;
                                316                 :                : 
  730 peter@eisentraut.org      317                 :            860 :     PG_RETURN_FLOAT8(gbt_num_distance(&key, &query, GIST_LEAF(entry),
                                318                 :                :                                       &tinfo, fcinfo->flinfo));
                                319                 :                : }
                                320                 :                : 
                                321                 :                : Datum
 8219 teodor@sigaev.ru          322                 :           5799 : gbt_tstz_consistent(PG_FUNCTION_ARGS)
                                323                 :                : {
 8126 bruce@momjian.us          324                 :           5799 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
 6379                           325                 :           5799 :     TimestampTz query = PG_GETARG_TIMESTAMPTZ(1);
 6802 tgl@sss.pgh.pa.us         326                 :           5799 :     StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
                                327                 :                : #ifdef NOT_USED
                                328                 :                :     Oid         subtype = PG_GETARG_OID(3);
                                329                 :                : #endif
                                330                 :           5799 :     bool       *recheck = (bool *) PG_GETARG_POINTER(4);
 8126 bruce@momjian.us          331                 :           5799 :     char       *kkk = (char *) DatumGetPointer(entry->key);
                                332                 :                :     GBT_NUMKEY_R key;
                                333                 :                :     Timestamp   qqq;
                                334                 :                : 
                                335                 :                :     /* All cases served by this function are exact */
 6802 tgl@sss.pgh.pa.us         336                 :           5799 :     *recheck = false;
                                337                 :                : 
 6379 bruce@momjian.us          338                 :           5799 :     key.lower = (GBT_NUMKEY *) &kkk[0];
                                339                 :           5799 :     key.upper = (GBT_NUMKEY *) &kkk[MAXALIGN(tinfo.size)];
 6795 tgl@sss.pgh.pa.us         340                 :           5799 :     qqq = tstz_to_ts_gmt(query);
                                341                 :                : 
  148 tgl@sss.pgh.pa.us         342                 :GNC        5799 :     PG_RETURN_BOOL(gbt_num_consistent(&key, &qqq, strategy,
                                343                 :                :                                       GIST_LEAF(entry), &tinfo, fcinfo->flinfo));
                                344                 :                : }
                                345                 :                : 
                                346                 :                : Datum
 5750 tgl@sss.pgh.pa.us         347                 :CBC         830 : gbt_tstz_distance(PG_FUNCTION_ARGS)
                                348                 :                : {
                                349                 :            830 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
                                350                 :            830 :     TimestampTz query = PG_GETARG_TIMESTAMPTZ(1);
                                351                 :                : #ifdef NOT_USED
                                352                 :                :     Oid         subtype = PG_GETARG_OID(3);
                                353                 :                : #endif
                                354                 :            830 :     char       *kkk = (char *) DatumGetPointer(entry->key);
                                355                 :                :     GBT_NUMKEY_R key;
                                356                 :                :     Timestamp   qqq;
                                357                 :                : 
                                358                 :            830 :     key.lower = (GBT_NUMKEY *) &kkk[0];
                                359                 :            830 :     key.upper = (GBT_NUMKEY *) &kkk[MAXALIGN(tinfo.size)];
                                360                 :            830 :     qqq = tstz_to_ts_gmt(query);
                                361                 :                : 
  730 peter@eisentraut.org      362                 :            830 :     PG_RETURN_FLOAT8(gbt_num_distance(&key, &qqq, GIST_LEAF(entry),
                                363                 :                :                                       &tinfo, fcinfo->flinfo));
                                364                 :                : }
                                365                 :                : 
                                366                 :                : 
                                367                 :                : Datum
 8219 teodor@sigaev.ru          368                 :           1858 : gbt_ts_union(PG_FUNCTION_ARGS)
                                369                 :                : {
 8126 bruce@momjian.us          370                 :           1858 :     GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
  103 michael@paquier.xyz       371                 :GNC        1858 :     void       *out = palloc_object(tsKEY);
                                372                 :                : 
 8126 bruce@momjian.us          373                 :CBC        1858 :     *(int *) PG_GETARG_POINTER(1) = sizeof(tsKEY);
  730 peter@eisentraut.org      374                 :           1858 :     PG_RETURN_POINTER(gbt_num_union(out, entryvec, &tinfo, fcinfo->flinfo));
                                375                 :                : }
                                376                 :                : 
                                377                 :                : 
                                378                 :                : #define penalty_check_max_float(val) \
                                379                 :                :     do { \
                                380                 :                :         if ( val > FLT_MAX ) \
                                381                 :                :                 val = FLT_MAX; \
                                382                 :                :         if ( val < -FLT_MAX ) \
                                383                 :                :                 val = -FLT_MAX; \
                                384                 :                :     } while (0)
                                385                 :                : 
                                386                 :                : 
                                387                 :                : Datum
 8219 teodor@sigaev.ru          388                 :           4086 : gbt_ts_penalty(PG_FUNCTION_ARGS)
                                389                 :                : {
 8126 bruce@momjian.us          390                 :           4086 :     tsKEY      *origentry = (tsKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
                                391                 :           4086 :     tsKEY      *newentry = (tsKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
                                392                 :           4086 :     float      *result = (float *) PG_GETARG_POINTER(2);
                                393                 :                : 
                                394                 :                :     double      orgdbl[2],
                                395                 :                :                 newdbl[2];
                                396                 :                : 
                                397                 :                :     /*
                                398                 :                :      * We are always using "double" timestamps here. Precision should be good
                                399                 :                :      * enough.
                                400                 :                :      */
 7714                           401                 :           4086 :     orgdbl[0] = ((double) origentry->lower);
                                402                 :           4086 :     orgdbl[1] = ((double) origentry->upper);
                                403                 :           4086 :     newdbl[0] = ((double) newentry->lower);
                                404                 :           4086 :     newdbl[1] = ((double) newentry->upper);
                                405                 :                : 
                                406   [ -  +  -  + ]:           4086 :     penalty_check_max_float(orgdbl[0]);
                                407   [ -  +  -  + ]:           4086 :     penalty_check_max_float(orgdbl[1]);
                                408   [ -  +  -  + ]:           4086 :     penalty_check_max_float(newdbl[0]);
                                409   [ -  +  -  + ]:           4086 :     penalty_check_max_float(newdbl[1]);
                                410                 :                : 
                                411                 :           4086 :     penalty_num(result, orgdbl[0], orgdbl[1], newdbl[0], newdbl[1]);
                                412                 :                : 
 8126                           413                 :           4086 :     PG_RETURN_POINTER(result);
                                414                 :                : }
                                415                 :                : 
                                416                 :                : 
                                417                 :                : Datum
 8219 teodor@sigaev.ru          418                 :             21 : gbt_ts_picksplit(PG_FUNCTION_ARGS)
                                419                 :                : {
 2494 alvherre@alvh.no-ip.      420                 :             21 :     PG_RETURN_POINTER(gbt_num_picksplit((GistEntryVector *) PG_GETARG_POINTER(0),
                                421                 :                :                                         (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
                                422                 :                :                                         &tinfo, fcinfo->flinfo));
                                423                 :                : }
                                424                 :                : 
                                425                 :                : Datum
 8219 teodor@sigaev.ru          426                 :           1835 : gbt_ts_same(PG_FUNCTION_ARGS)
                                427                 :                : {
 8126 bruce@momjian.us          428                 :           1835 :     tsKEY      *b1 = (tsKEY *) PG_GETARG_POINTER(0);
                                429                 :           1835 :     tsKEY      *b2 = (tsKEY *) PG_GETARG_POINTER(1);
                                430                 :           1835 :     bool       *result = (bool *) PG_GETARG_POINTER(2);
                                431                 :                : 
 3539 andrew@dunslane.net       432                 :           1835 :     *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
 8126 bruce@momjian.us          433                 :           1835 :     PG_RETURN_POINTER(result);
                                434                 :                : }
                                435                 :                : 
                                436                 :                : static int
  604 heikki.linnakangas@i      437                 :          11115 : gbt_ts_ssup_cmp(Datum x, Datum y, SortSupport ssup)
                                438                 :                : {
                                439                 :          11115 :     tsKEY      *arg1 = (tsKEY *) DatumGetPointer(x);
                                440                 :          11115 :     tsKEY      *arg2 = (tsKEY *) DatumGetPointer(y);
                                441                 :                : 
                                442                 :                :     /* for leaf items we expect lower == upper, so only compare lower */
                                443                 :          11115 :     return DatumGetInt32(DirectFunctionCall2(timestamp_cmp,
                                444                 :                :                                              TimestampGetDatum(arg1->lower),
                                445                 :                :                                              TimestampGetDatum(arg2->lower)));
                                446                 :                : }
                                447                 :                : 
                                448                 :                : Datum
                                449                 :              4 : gbt_ts_sortsupport(PG_FUNCTION_ARGS)
                                450                 :                : {
                                451                 :              4 :     SortSupport ssup = (SortSupport) PG_GETARG_POINTER(0);
                                452                 :                : 
                                453                 :              4 :     ssup->comparator = gbt_ts_ssup_cmp;
                                454                 :              4 :     ssup->ssup_extra = NULL;
                                455                 :                : 
                                456                 :              4 :     PG_RETURN_VOID();
                                457                 :                : }
        

Generated by: LCOV version 2.0-1