LCOV - code coverage report
Current view: top level - contrib/btree_gist - btree_ts.c (source / functions) Coverage Total Hit
Test: PostgreSQL 20devel Lines: 100.0 % 171 171
Test Date: 2026-12-01 02:16:10 Functions: 100.0 % 37 37
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
Branches: 76.9 % 52 40

             Branch data     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 */
      24                 :           5 : PG_FUNCTION_INFO_V1(gbt_ts_compress);
      25                 :           4 : PG_FUNCTION_INFO_V1(gbt_tstz_compress);
      26                 :           6 : PG_FUNCTION_INFO_V1(gbt_ts_fetch);
      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);
      30                 :           5 : PG_FUNCTION_INFO_V1(gbt_ts_distance);
      31                 :           4 : PG_FUNCTION_INFO_V1(gbt_tstz_consistent);
      32                 :           4 : PG_FUNCTION_INFO_V1(gbt_tstz_distance);
      33                 :           6 : PG_FUNCTION_INFO_V1(gbt_ts_penalty);
      34                 :           6 : PG_FUNCTION_INFO_V1(gbt_ts_same);
      35                 :           6 : PG_FUNCTION_INFO_V1(gbt_ts_sortsupport);
      36                 :             : 
      37                 :             : 
      38                 :             : /* define for comparison */
      39                 :             : 
      40                 :             : static bool
      41                 :       12431 : gbt_tsgt(const void *a, const void *b, FmgrInfo *flinfo)
      42                 :             : {
      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
      52                 :        2350 : gbt_tsge(const void *a, const void *b, FmgrInfo *flinfo)
      53                 :             : {
      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
      63                 :        5001 : gbt_tseq(const void *a, const void *b, FmgrInfo *flinfo)
      64                 :             : {
      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
      74                 :        3645 : gbt_tsle(const void *a, const void *b, FmgrInfo *flinfo)
      75                 :             : {
      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
      85                 :       12969 : gbt_tslt(const void *a, const void *b, FmgrInfo *flinfo)
      86                 :             : {
      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
      96                 :        4839 : gbt_tskey_cmp(const void *a, const void *b, FmgrInfo *flinfo)
      97                 :             : {
      98                 :        4839 :     tsKEY      *ia = (tsKEY *) (((const Nsrt *) a)->t);
      99                 :        4839 :     tsKEY      *ib = (tsKEY *) (((const Nsrt *) b)->t);
     100                 :             :     int         res;
     101                 :             : 
     102                 :        4839 :     res = DatumGetInt32(DirectFunctionCall2(timestamp_cmp, TimestampGetDatum(ia->lower), TimestampGetDatum(ib->lower)));
     103         [ +  + ]:        4839 :     if (res == 0)
     104                 :        3752 :         return DatumGetInt32(DirectFunctionCall2(timestamp_cmp, TimestampGetDatum(ia->upper), TimestampGetDatum(ib->upper)));
     105                 :             : 
     106                 :        1087 :     return res;
     107                 :             : }
     108                 :             : 
     109                 :             : static float8
     110                 :        1688 : gbt_ts_dist(const void *a, const void *b, FmgrInfo *flinfo)
     111                 :             : {
     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))
             +  +  +  + ]
     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 */
     135                 :         542 :     i = DatumGetIntervalP(DirectFunctionCall2(timestamp_mi,
     136                 :             :                                               TimestampGetDatum(*aa),
     137                 :             :                                               TimestampGetDatum(*bb)));
     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                 :             : 
     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                 :             :     {
     166                 :          30 :         Interval   *p = palloc_object(Interval);
     167                 :             : 
     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                 :             :         }
     182                 :          30 :         PG_RETURN_INTERVAL_P(p);
     183                 :             :     }
     184                 :             :     else
     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                 :             : 
     191                 :           4 : PG_FUNCTION_INFO_V1(tstz_dist);
     192                 :             : Datum
     193                 :         558 : tstz_dist(PG_FUNCTION_ARGS)
     194                 :             : {
     195                 :         558 :     TimestampTz a = PG_GETARG_TIMESTAMPTZ(0);
     196                 :         558 :     TimestampTz b = PG_GETARG_TIMESTAMPTZ(1);
     197                 :             :     Interval   *r;
     198                 :             : 
     199   [ +  +  +  +  :         558 :     if (TIMESTAMP_NOT_FINITE(a) || TIMESTAMP_NOT_FINITE(b))
             +  -  -  + ]
     200                 :             :     {
     201                 :          24 :         Interval   *p = palloc_object(Interval);
     202                 :             : 
     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                 :             :         }
     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)));
     223                 :         534 :     PG_RETURN_INTERVAL_P(abs_interval(r));
     224                 :             : }
     225                 :             : 
     226                 :             : /**************************************************
     227                 :             :  * GiST support functions
     228                 :             :  **************************************************/
     229                 :             : 
     230                 :             : static inline Timestamp
     231                 :        7178 : tstz_to_ts_gmt(TimestampTz ts)
     232                 :             : {
     233                 :             :     /* No timezone correction is needed, since GMT is offset 0 by definition */
     234                 :        7178 :     return (Timestamp) ts;
     235                 :             : }
     236                 :             : 
     237                 :             : 
     238                 :             : Datum
     239                 :        2614 : gbt_ts_compress(PG_FUNCTION_ARGS)
     240                 :             : {
     241                 :        2614 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
     242                 :             : 
     243                 :        2614 :     PG_RETURN_POINTER(gbt_num_compress(entry, &tinfo));
     244                 :             : }
     245                 :             : 
     246                 :             : Datum
     247                 :         551 : gbt_tstz_compress(PG_FUNCTION_ARGS)
     248                 :             : {
     249                 :         551 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
     250                 :             :     GISTENTRY  *retval;
     251                 :             : 
     252         [ +  + ]:         551 :     if (entry->leafkey)
     253                 :             :     {
     254                 :         549 :         tsKEY      *r = palloc_object(tsKEY);
     255                 :         549 :         TimestampTz ts = DatumGetTimestampTz(entry->key);
     256                 :             :         Timestamp   gmt;
     257                 :             : 
     258                 :         549 :         gmt = tstz_to_ts_gmt(ts);
     259                 :             : 
     260                 :         549 :         retval = palloc_object(GISTENTRY);
     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
     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
     281                 :        2204 : gbt_ts_consistent(PG_FUNCTION_ARGS)
     282                 :             : {
     283                 :        2204 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
     284                 :        2204 :     Timestamp   query = PG_GETARG_TIMESTAMP(1);
     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);
     290                 :        2204 :     tsKEY      *kkk = (tsKEY *) DatumGetPointer(entry->key);
     291                 :             :     GBT_NUMKEY_R key;
     292                 :             : 
     293                 :             :     /* All cases served by this function are exact */
     294                 :        2204 :     *recheck = false;
     295                 :             : 
     296                 :        2204 :     key.lower = (GBT_NUMKEY *) &kkk->lower;
     297                 :        2204 :     key.upper = (GBT_NUMKEY *) &kkk->upper;
     298                 :             : 
     299                 :        2204 :     PG_RETURN_BOOL(gbt_num_consistent(&key, &query, strategy,
     300                 :             :                                       GIST_LEAF(entry), &tinfo, fcinfo->flinfo));
     301                 :             : }
     302                 :             : 
     303                 :             : Datum
     304                 :         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                 :             : 
     317                 :         860 :     PG_RETURN_FLOAT8(gbt_num_distance(&key, &query, GIST_LEAF(entry),
     318                 :             :                                       &tinfo, fcinfo->flinfo));
     319                 :             : }
     320                 :             : 
     321                 :             : Datum
     322                 :        5799 : gbt_tstz_consistent(PG_FUNCTION_ARGS)
     323                 :             : {
     324                 :        5799 :     GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
     325                 :        5799 :     TimestampTz query = PG_GETARG_TIMESTAMPTZ(1);
     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);
     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 */
     336                 :        5799 :     *recheck = false;
     337                 :             : 
     338                 :        5799 :     key.lower = (GBT_NUMKEY *) &kkk[0];
     339                 :        5799 :     key.upper = (GBT_NUMKEY *) &kkk[MAXALIGN(tinfo.size)];
     340                 :        5799 :     qqq = tstz_to_ts_gmt(query);
     341                 :             : 
     342                 :        5799 :     PG_RETURN_BOOL(gbt_num_consistent(&key, &qqq, strategy,
     343                 :             :                                       GIST_LEAF(entry), &tinfo, fcinfo->flinfo));
     344                 :             : }
     345                 :             : 
     346                 :             : Datum
     347                 :         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                 :             : 
     362                 :         830 :     PG_RETURN_FLOAT8(gbt_num_distance(&key, &qqq, GIST_LEAF(entry),
     363                 :             :                                       &tinfo, fcinfo->flinfo));
     364                 :             : }
     365                 :             : 
     366                 :             : 
     367                 :             : Datum
     368                 :        1858 : gbt_ts_union(PG_FUNCTION_ARGS)
     369                 :             : {
     370                 :        1858 :     GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
     371                 :        1858 :     void       *out = palloc_object(tsKEY);
     372                 :             : 
     373                 :        1858 :     *(int *) PG_GETARG_POINTER(1) = sizeof(tsKEY);
     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
     388                 :        4109 : gbt_ts_penalty(PG_FUNCTION_ARGS)
     389                 :             : {
     390                 :        4109 :     tsKEY      *origentry = (tsKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
     391                 :        4109 :     tsKEY      *newentry = (tsKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
     392                 :        4109 :     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                 :             :      */
     401                 :        4109 :     orgdbl[0] = ((double) origentry->lower);
     402                 :        4109 :     orgdbl[1] = ((double) origentry->upper);
     403                 :        4109 :     newdbl[0] = ((double) newentry->lower);
     404                 :        4109 :     newdbl[1] = ((double) newentry->upper);
     405                 :             : 
     406   [ -  +  -  + ]:        4109 :     penalty_check_max_float(orgdbl[0]);
     407   [ -  +  -  + ]:        4109 :     penalty_check_max_float(orgdbl[1]);
     408   [ -  +  -  + ]:        4109 :     penalty_check_max_float(newdbl[0]);
     409   [ -  +  -  + ]:        4109 :     penalty_check_max_float(newdbl[1]);
     410                 :             : 
     411                 :        4109 :     penalty_num(result, orgdbl[0], orgdbl[1], newdbl[0], newdbl[1]);
     412                 :             : 
     413                 :        4109 :     PG_RETURN_POINTER(result);
     414                 :             : }
     415                 :             : 
     416                 :             : 
     417                 :             : Datum
     418                 :          21 : gbt_ts_picksplit(PG_FUNCTION_ARGS)
     419                 :             : {
     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
     426                 :        1835 : gbt_ts_same(PG_FUNCTION_ARGS)
     427                 :             : {
     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                 :             : 
     432                 :        1835 :     *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
     433                 :        1835 :     PG_RETURN_POINTER(result);
     434                 :             : }
     435                 :             : 
     436                 :             : static int
     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