LCOV - code coverage report
Current view: top level - src/test/regress - regress.c (source / functions) Hit Total Coverage
Test: PostgreSQL 14devel Lines: 382 422 90.5 %
Date: 2020-11-27 12:05:55 Functions: 41 43 95.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*------------------------------------------------------------------------
       2             :  *
       3             :  * regress.c
       4             :  *   Code for various C-language functions defined as part of the
       5             :  *   regression tests.
       6             :  *
       7             :  * This code is released under the terms of the PostgreSQL License.
       8             :  *
       9             :  * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
      10             :  * Portions Copyright (c) 1994, Regents of the University of California
      11             :  *
      12             :  * src/test/regress/regress.c
      13             :  *
      14             :  *-------------------------------------------------------------------------
      15             :  */
      16             : 
      17             : #include "postgres.h"
      18             : 
      19             : #include <math.h>
      20             : #include <signal.h>
      21             : 
      22             : #include "access/detoast.h"
      23             : #include "access/htup_details.h"
      24             : #include "access/transam.h"
      25             : #include "access/xact.h"
      26             : #include "catalog/pg_operator.h"
      27             : #include "catalog/pg_type.h"
      28             : #include "commands/sequence.h"
      29             : #include "commands/trigger.h"
      30             : #include "executor/executor.h"
      31             : #include "executor/spi.h"
      32             : #include "miscadmin.h"
      33             : #include "nodes/supportnodes.h"
      34             : #include "optimizer/optimizer.h"
      35             : #include "optimizer/plancat.h"
      36             : #include "port/atomics.h"
      37             : #include "storage/spin.h"
      38             : #include "utils/builtins.h"
      39             : #include "utils/geo_decls.h"
      40             : #include "utils/memutils.h"
      41             : #include "utils/rel.h"
      42             : #include "utils/typcache.h"
      43             : 
      44             : #define EXPECT_TRUE(expr)   \
      45             :     do { \
      46             :         if (!(expr)) \
      47             :             elog(ERROR, \
      48             :                  "%s was unexpectedly false in file \"%s\" line %u", \
      49             :                  #expr, __FILE__, __LINE__); \
      50             :     } while (0)
      51             : 
      52             : #define EXPECT_EQ_U32(result_expr, expected_expr)   \
      53             :     do { \
      54             :         uint32      result = (result_expr); \
      55             :         uint32      expected = (expected_expr); \
      56             :         if (result != expected) \
      57             :             elog(ERROR, \
      58             :                  "%s yielded %u, expected %s in file \"%s\" line %u", \
      59             :                  #result_expr, result, #expected_expr, __FILE__, __LINE__); \
      60             :     } while (0)
      61             : 
      62             : #define EXPECT_EQ_U64(result_expr, expected_expr)   \
      63             :     do { \
      64             :         uint64      result = (result_expr); \
      65             :         uint64      expected = (expected_expr); \
      66             :         if (result != expected) \
      67             :             elog(ERROR, \
      68             :                  "%s yielded " UINT64_FORMAT ", expected %s in file \"%s\" line %u", \
      69             :                  #result_expr, result, #expected_expr, __FILE__, __LINE__); \
      70             :     } while (0)
      71             : 
      72             : #define LDELIM          '('
      73             : #define RDELIM          ')'
      74             : #define DELIM           ','
      75             : 
      76             : static void regress_lseg_construct(LSEG *lseg, Point *pt1, Point *pt2);
      77             : 
      78          60 : PG_MODULE_MAGIC;
      79             : 
      80             : 
      81             : /* return the point where two paths intersect, or NULL if no intersection. */
      82          10 : PG_FUNCTION_INFO_V1(interpt_pp);
      83             : 
      84             : Datum
      85        3584 : interpt_pp(PG_FUNCTION_ARGS)
      86             : {
      87        3584 :     PATH       *p1 = PG_GETARG_PATH_P(0);
      88        3584 :     PATH       *p2 = PG_GETARG_PATH_P(1);
      89             :     int         i,
      90             :                 j;
      91             :     LSEG        seg1,
      92             :                 seg2;
      93             :     bool        found;          /* We've found the intersection */
      94             : 
      95        3584 :     found = false;              /* Haven't found it yet */
      96             : 
      97       11764 :     for (i = 0; i < p1->npts - 1 && !found; i++)
      98             :     {
      99        8180 :         regress_lseg_construct(&seg1, &p1->p[i], &p1->p[i + 1]);
     100       25092 :         for (j = 0; j < p2->npts - 1 && !found; j++)
     101             :         {
     102       16912 :             regress_lseg_construct(&seg2, &p2->p[j], &p2->p[j + 1]);
     103       16912 :             if (DatumGetBool(DirectFunctionCall2(lseg_intersect,
     104             :                                                  LsegPGetDatum(&seg1),
     105             :                                                  LsegPGetDatum(&seg2))))
     106        3576 :                 found = true;
     107             :         }
     108             :     }
     109             : 
     110        3584 :     if (!found)
     111           8 :         PG_RETURN_NULL();
     112             : 
     113             :     /*
     114             :      * Note: DirectFunctionCall2 will kick out an error if lseg_interpt()
     115             :      * returns NULL, but that should be impossible since we know the two
     116             :      * segments intersect.
     117             :      */
     118        3576 :     PG_RETURN_DATUM(DirectFunctionCall2(lseg_interpt,
     119             :                                         LsegPGetDatum(&seg1),
     120             :                                         LsegPGetDatum(&seg2)));
     121             : }
     122             : 
     123             : 
     124             : /* like lseg_construct, but assume space already allocated */
     125             : static void
     126       25092 : regress_lseg_construct(LSEG *lseg, Point *pt1, Point *pt2)
     127             : {
     128       25092 :     lseg->p[0].x = pt1->x;
     129       25092 :     lseg->p[0].y = pt1->y;
     130       25092 :     lseg->p[1].x = pt2->x;
     131       25092 :     lseg->p[1].y = pt2->y;
     132       25092 : }
     133             : 
     134          10 : PG_FUNCTION_INFO_V1(overpaid);
     135             : 
     136             : Datum
     137          24 : overpaid(PG_FUNCTION_ARGS)
     138             : {
     139          24 :     HeapTupleHeader tuple = PG_GETARG_HEAPTUPLEHEADER(0);
     140             :     bool        isnull;
     141             :     int32       salary;
     142             : 
     143          24 :     salary = DatumGetInt32(GetAttributeByName(tuple, "salary", &isnull));
     144          24 :     if (isnull)
     145           0 :         PG_RETURN_NULL();
     146          24 :     PG_RETURN_BOOL(salary > 699);
     147             : }
     148             : 
     149             : /* New type "widget"
     150             :  * This used to be "circle", but I added circle to builtins,
     151             :  *  so needed to make sure the names do not collide. - tgl 97/04/21
     152             :  */
     153             : 
     154             : typedef struct
     155             : {
     156             :     Point       center;
     157             :     double      radius;
     158             : } WIDGET;
     159             : 
     160          14 : PG_FUNCTION_INFO_V1(widget_in);
     161          10 : PG_FUNCTION_INFO_V1(widget_out);
     162             : 
     163             : #define NARGS   3
     164             : 
     165             : Datum
     166          16 : widget_in(PG_FUNCTION_ARGS)
     167             : {
     168          16 :     char       *str = PG_GETARG_CSTRING(0);
     169             :     char       *p,
     170             :                *coord[NARGS];
     171             :     int         i;
     172             :     WIDGET     *result;
     173             : 
     174         112 :     for (i = 0, p = str; *p && i < NARGS && *p != RDELIM; p++)
     175             :     {
     176          96 :         if (*p == DELIM || (*p == LDELIM && i == 0))
     177          48 :             coord[i++] = p + 1;
     178             :     }
     179             : 
     180          16 :     if (i < NARGS)
     181           0 :         ereport(ERROR,
     182             :                 (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
     183             :                  errmsg("invalid input syntax for type %s: \"%s\"",
     184             :                         "widget", str)));
     185             : 
     186          16 :     result = (WIDGET *) palloc(sizeof(WIDGET));
     187          16 :     result->center.x = atof(coord[0]);
     188          16 :     result->center.y = atof(coord[1]);
     189          16 :     result->radius = atof(coord[2]);
     190             : 
     191          16 :     PG_RETURN_POINTER(result);
     192             : }
     193             : 
     194             : Datum
     195           8 : widget_out(PG_FUNCTION_ARGS)
     196             : {
     197           8 :     WIDGET     *widget = (WIDGET *) PG_GETARG_POINTER(0);
     198           8 :     char       *str = psprintf("(%g,%g,%g)",
     199             :                                widget->center.x, widget->center.y, widget->radius);
     200             : 
     201           8 :     PG_RETURN_CSTRING(str);
     202             : }
     203             : 
     204          10 : PG_FUNCTION_INFO_V1(pt_in_widget);
     205             : 
     206             : Datum
     207           8 : pt_in_widget(PG_FUNCTION_ARGS)
     208             : {
     209           8 :     Point      *point = PG_GETARG_POINT_P(0);
     210           8 :     WIDGET     *widget = (WIDGET *) PG_GETARG_POINTER(1);
     211             :     float8      distance;
     212             : 
     213           8 :     distance = DatumGetFloat8(DirectFunctionCall2(point_distance,
     214             :                                                   PointPGetDatum(point),
     215             :                                                   PointPGetDatum(&widget->center)));
     216             : 
     217           8 :     PG_RETURN_BOOL(distance < widget->radius);
     218             : }
     219             : 
     220          10 : PG_FUNCTION_INFO_V1(reverse_name);
     221             : 
     222             : Datum
     223          32 : reverse_name(PG_FUNCTION_ARGS)
     224             : {
     225          32 :     char       *string = PG_GETARG_CSTRING(0);
     226             :     int         i;
     227             :     int         len;
     228             :     char       *new_string;
     229             : 
     230          32 :     new_string = palloc0(NAMEDATALEN);
     231         224 :     for (i = 0; i < NAMEDATALEN && string[i]; ++i)
     232             :         ;
     233          32 :     if (i == NAMEDATALEN || !string[i])
     234          32 :         --i;
     235          32 :     len = i;
     236         224 :     for (; i >= 0; --i)
     237         192 :         new_string[len - i] = string[i];
     238          32 :     PG_RETURN_CSTRING(new_string);
     239             : }
     240             : 
     241          10 : PG_FUNCTION_INFO_V1(trigger_return_old);
     242             : 
     243             : Datum
     244          60 : trigger_return_old(PG_FUNCTION_ARGS)
     245             : {
     246          60 :     TriggerData *trigdata = (TriggerData *) fcinfo->context;
     247             :     HeapTuple   tuple;
     248             : 
     249          60 :     if (!CALLED_AS_TRIGGER(fcinfo))
     250           0 :         elog(ERROR, "trigger_return_old: not fired by trigger manager");
     251             : 
     252          60 :     tuple = trigdata->tg_trigtuple;
     253             : 
     254          60 :     return PointerGetDatum(tuple);
     255             : }
     256             : 
     257             : #define TTDUMMY_INFINITY    999999
     258             : 
     259             : static SPIPlanPtr splan = NULL;
     260             : static bool ttoff = false;
     261             : 
     262          10 : PG_FUNCTION_INFO_V1(ttdummy);
     263             : 
     264             : Datum
     265          40 : ttdummy(PG_FUNCTION_ARGS)
     266             : {
     267          40 :     TriggerData *trigdata = (TriggerData *) fcinfo->context;
     268             :     Trigger    *trigger;        /* to get trigger name */
     269             :     char      **args;           /* arguments */
     270             :     int         attnum[2];      /* fnumbers of start/stop columns */
     271             :     Datum       oldon,
     272             :                 oldoff;
     273             :     Datum       newon,
     274             :                 newoff;
     275             :     Datum      *cvals;          /* column values */
     276             :     char       *cnulls;         /* column nulls */
     277             :     char       *relname;        /* triggered relation name */
     278             :     Relation    rel;            /* triggered relation */
     279             :     HeapTuple   trigtuple;
     280          40 :     HeapTuple   newtuple = NULL;
     281             :     HeapTuple   rettuple;
     282             :     TupleDesc   tupdesc;        /* tuple description */
     283             :     int         natts;          /* # of attributes */
     284             :     bool        isnull;         /* to know is some column NULL or not */
     285             :     int         ret;
     286             :     int         i;
     287             : 
     288          40 :     if (!CALLED_AS_TRIGGER(fcinfo))
     289           0 :         elog(ERROR, "ttdummy: not fired by trigger manager");
     290          40 :     if (!TRIGGER_FIRED_FOR_ROW(trigdata->tg_event))
     291           0 :         elog(ERROR, "ttdummy: must be fired for row");
     292          40 :     if (!TRIGGER_FIRED_BEFORE(trigdata->tg_event))
     293           0 :         elog(ERROR, "ttdummy: must be fired before event");
     294          40 :     if (TRIGGER_FIRED_BY_INSERT(trigdata->tg_event))
     295           0 :         elog(ERROR, "ttdummy: cannot process INSERT event");
     296          40 :     if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
     297          32 :         newtuple = trigdata->tg_newtuple;
     298             : 
     299          40 :     trigtuple = trigdata->tg_trigtuple;
     300             : 
     301          40 :     rel = trigdata->tg_relation;
     302          40 :     relname = SPI_getrelname(rel);
     303             : 
     304             :     /* check if TT is OFF for this relation */
     305          40 :     if (ttoff)                  /* OFF - nothing to do */
     306             :     {
     307          20 :         pfree(relname);
     308          20 :         return PointerGetDatum((newtuple != NULL) ? newtuple : trigtuple);
     309             :     }
     310             : 
     311          20 :     trigger = trigdata->tg_trigger;
     312             : 
     313          20 :     if (trigger->tgnargs != 2)
     314           0 :         elog(ERROR, "ttdummy (%s): invalid (!= 2) number of arguments %d",
     315             :              relname, trigger->tgnargs);
     316             : 
     317          20 :     args = trigger->tgargs;
     318          20 :     tupdesc = rel->rd_att;
     319          20 :     natts = tupdesc->natts;
     320             : 
     321          60 :     for (i = 0; i < 2; i++)
     322             :     {
     323          40 :         attnum[i] = SPI_fnumber(tupdesc, args[i]);
     324          40 :         if (attnum[i] <= 0)
     325           0 :             elog(ERROR, "ttdummy (%s): there is no attribute %s",
     326             :                  relname, args[i]);
     327          40 :         if (SPI_gettypeid(tupdesc, attnum[i]) != INT4OID)
     328           0 :             elog(ERROR, "ttdummy (%s): attribute %s must be of integer type",
     329             :                  relname, args[i]);
     330             :     }
     331             : 
     332          20 :     oldon = SPI_getbinval(trigtuple, tupdesc, attnum[0], &isnull);
     333          20 :     if (isnull)
     334           0 :         elog(ERROR, "ttdummy (%s): %s must be NOT NULL", relname, args[0]);
     335             : 
     336          20 :     oldoff = SPI_getbinval(trigtuple, tupdesc, attnum[1], &isnull);
     337          20 :     if (isnull)
     338           0 :         elog(ERROR, "ttdummy (%s): %s must be NOT NULL", relname, args[1]);
     339             : 
     340          20 :     if (newtuple != NULL)       /* UPDATE */
     341             :     {
     342          16 :         newon = SPI_getbinval(newtuple, tupdesc, attnum[0], &isnull);
     343          16 :         if (isnull)
     344           0 :             elog(ERROR, "ttdummy (%s): %s must be NOT NULL", relname, args[0]);
     345          16 :         newoff = SPI_getbinval(newtuple, tupdesc, attnum[1], &isnull);
     346          16 :         if (isnull)
     347           0 :             elog(ERROR, "ttdummy (%s): %s must be NOT NULL", relname, args[1]);
     348             : 
     349          16 :         if (oldon != newon || oldoff != newoff)
     350           4 :             ereport(ERROR,
     351             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
     352             :                      errmsg("ttdummy (%s): you cannot change %s and/or %s columns (use set_ttdummy)",
     353             :                             relname, args[0], args[1])));
     354             : 
     355          12 :         if (newoff != TTDUMMY_INFINITY)
     356             :         {
     357           4 :             pfree(relname);     /* allocated in upper executor context */
     358           4 :             return PointerGetDatum(NULL);
     359             :         }
     360             :     }
     361           4 :     else if (oldoff != TTDUMMY_INFINITY)    /* DELETE */
     362             :     {
     363           0 :         pfree(relname);
     364           0 :         return PointerGetDatum(NULL);
     365             :     }
     366             : 
     367          12 :     newoff = DirectFunctionCall1(nextval, CStringGetTextDatum("ttdummy_seq"));
     368             :     /* nextval now returns int64; coerce down to int32 */
     369          12 :     newoff = Int32GetDatum((int32) DatumGetInt64(newoff));
     370             : 
     371             :     /* Connect to SPI manager */
     372          12 :     if ((ret = SPI_connect()) < 0)
     373           0 :         elog(ERROR, "ttdummy (%s): SPI_connect returned %d", relname, ret);
     374             : 
     375             :     /* Fetch tuple values and nulls */
     376          12 :     cvals = (Datum *) palloc(natts * sizeof(Datum));
     377          12 :     cnulls = (char *) palloc(natts * sizeof(char));
     378          60 :     for (i = 0; i < natts; i++)
     379             :     {
     380          48 :         cvals[i] = SPI_getbinval((newtuple != NULL) ? newtuple : trigtuple,
     381             :                                  tupdesc, i + 1, &isnull);
     382          48 :         cnulls[i] = (isnull) ? 'n' : ' ';
     383             :     }
     384             : 
     385             :     /* change date column(s) */
     386          12 :     if (newtuple)               /* UPDATE */
     387             :     {
     388           8 :         cvals[attnum[0] - 1] = newoff;  /* start_date eq current date */
     389           8 :         cnulls[attnum[0] - 1] = ' ';
     390           8 :         cvals[attnum[1] - 1] = TTDUMMY_INFINITY;    /* stop_date eq INFINITY */
     391           8 :         cnulls[attnum[1] - 1] = ' ';
     392             :     }
     393             :     else
     394             :         /* DELETE */
     395             :     {
     396           4 :         cvals[attnum[1] - 1] = newoff;  /* stop_date eq current date */
     397           4 :         cnulls[attnum[1] - 1] = ' ';
     398             :     }
     399             : 
     400             :     /* if there is no plan ... */
     401          12 :     if (splan == NULL)
     402             :     {
     403             :         SPIPlanPtr  pplan;
     404             :         Oid        *ctypes;
     405             :         char       *query;
     406             : 
     407             :         /* allocate space in preparation */
     408           4 :         ctypes = (Oid *) palloc(natts * sizeof(Oid));
     409           4 :         query = (char *) palloc(100 + 16 * natts);
     410             : 
     411             :         /*
     412             :          * Construct query: INSERT INTO _relation_ VALUES ($1, ...)
     413             :          */
     414           4 :         sprintf(query, "INSERT INTO %s VALUES (", relname);
     415          20 :         for (i = 1; i <= natts; i++)
     416             :         {
     417          16 :             sprintf(query + strlen(query), "$%d%s",
     418             :                     i, (i < natts) ? ", " : ")");
     419          16 :             ctypes[i - 1] = SPI_gettypeid(tupdesc, i);
     420             :         }
     421             : 
     422             :         /* Prepare plan for query */
     423           4 :         pplan = SPI_prepare(query, natts, ctypes);
     424           4 :         if (pplan == NULL)
     425           0 :             elog(ERROR, "ttdummy (%s): SPI_prepare returned %s", relname, SPI_result_code_string(SPI_result));
     426             : 
     427           4 :         if (SPI_keepplan(pplan))
     428           0 :             elog(ERROR, "ttdummy (%s): SPI_keepplan failed", relname);
     429             : 
     430           4 :         splan = pplan;
     431             :     }
     432             : 
     433          12 :     ret = SPI_execp(splan, cvals, cnulls, 0);
     434             : 
     435          12 :     if (ret < 0)
     436           0 :         elog(ERROR, "ttdummy (%s): SPI_execp returned %d", relname, ret);
     437             : 
     438             :     /* Tuple to return to upper Executor ... */
     439          12 :     if (newtuple)               /* UPDATE */
     440           8 :         rettuple = SPI_modifytuple(rel, trigtuple, 1, &(attnum[1]), &newoff, NULL);
     441             :     else                        /* DELETE */
     442           4 :         rettuple = trigtuple;
     443             : 
     444          12 :     SPI_finish();               /* don't forget say Bye to SPI mgr */
     445             : 
     446          12 :     pfree(relname);
     447             : 
     448          12 :     return PointerGetDatum(rettuple);
     449             : }
     450             : 
     451          10 : PG_FUNCTION_INFO_V1(set_ttdummy);
     452             : 
     453             : Datum
     454          12 : set_ttdummy(PG_FUNCTION_ARGS)
     455             : {
     456          12 :     int32       on = PG_GETARG_INT32(0);
     457             : 
     458          12 :     if (ttoff)                  /* OFF currently */
     459             :     {
     460           4 :         if (on == 0)
     461           0 :             PG_RETURN_INT32(0);
     462             : 
     463             :         /* turn ON */
     464           4 :         ttoff = false;
     465           4 :         PG_RETURN_INT32(0);
     466             :     }
     467             : 
     468             :     /* ON currently */
     469           8 :     if (on != 0)
     470           0 :         PG_RETURN_INT32(1);
     471             : 
     472             :     /* turn OFF */
     473           8 :     ttoff = true;
     474             : 
     475           8 :     PG_RETURN_INT32(1);
     476             : }
     477             : 
     478             : 
     479             : /*
     480             :  * Type int44 has no real-world use, but the regression tests use it
     481             :  * (under the alias "city_budget").  It's a four-element vector of int4's.
     482             :  */
     483             : 
     484             : /*
     485             :  *      int44in         - converts "num, num, ..." to internal form
     486             :  *
     487             :  *      Note: Fills any missing positions with zeroes.
     488             :  */
     489          10 : PG_FUNCTION_INFO_V1(int44in);
     490             : 
     491             : Datum
     492           8 : int44in(PG_FUNCTION_ARGS)
     493             : {
     494           8 :     char       *input_string = PG_GETARG_CSTRING(0);
     495           8 :     int32      *result = (int32 *) palloc(4 * sizeof(int32));
     496             :     int         i;
     497             : 
     498           8 :     i = sscanf(input_string,
     499             :                "%d, %d, %d, %d",
     500             :                &result[0],
     501             :                &result[1],
     502             :                &result[2],
     503             :                &result[3]);
     504          12 :     while (i < 4)
     505           4 :         result[i++] = 0;
     506             : 
     507           8 :     PG_RETURN_POINTER(result);
     508             : }
     509             : 
     510             : /*
     511             :  *      int44out        - converts internal form to "num, num, ..."
     512             :  */
     513          14 : PG_FUNCTION_INFO_V1(int44out);
     514             : 
     515             : Datum
     516          16 : int44out(PG_FUNCTION_ARGS)
     517             : {
     518          16 :     int32      *an_array = (int32 *) PG_GETARG_POINTER(0);
     519          16 :     char       *result = (char *) palloc(16 * 4);
     520             : 
     521          48 :     snprintf(result, 16 * 4, "%d,%d,%d,%d",
     522             :              an_array[0],
     523          16 :              an_array[1],
     524          16 :              an_array[2],
     525          16 :              an_array[3]);
     526             : 
     527          16 :     PG_RETURN_CSTRING(result);
     528             : }
     529             : 
     530          10 : PG_FUNCTION_INFO_V1(make_tuple_indirect);
     531             : Datum
     532          84 : make_tuple_indirect(PG_FUNCTION_ARGS)
     533             : {
     534          84 :     HeapTupleHeader rec = PG_GETARG_HEAPTUPLEHEADER(0);
     535             :     HeapTupleData tuple;
     536             :     int         ncolumns;
     537             :     Datum      *values;
     538             :     bool       *nulls;
     539             : 
     540             :     Oid         tupType;
     541             :     int32       tupTypmod;
     542             :     TupleDesc   tupdesc;
     543             : 
     544             :     HeapTuple   newtup;
     545             : 
     546             :     int         i;
     547             : 
     548             :     MemoryContext old_context;
     549             : 
     550             :     /* Extract type info from the tuple itself */
     551          84 :     tupType = HeapTupleHeaderGetTypeId(rec);
     552          84 :     tupTypmod = HeapTupleHeaderGetTypMod(rec);
     553          84 :     tupdesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
     554          84 :     ncolumns = tupdesc->natts;
     555             : 
     556             :     /* Build a temporary HeapTuple control structure */
     557          84 :     tuple.t_len = HeapTupleHeaderGetDatumLength(rec);
     558          84 :     ItemPointerSetInvalid(&(tuple.t_self));
     559          84 :     tuple.t_tableOid = InvalidOid;
     560          84 :     tuple.t_data = rec;
     561             : 
     562          84 :     values = (Datum *) palloc(ncolumns * sizeof(Datum));
     563          84 :     nulls = (bool *) palloc(ncolumns * sizeof(bool));
     564             : 
     565          84 :     heap_deform_tuple(&tuple, tupdesc, values, nulls);
     566             : 
     567          84 :     old_context = MemoryContextSwitchTo(TopTransactionContext);
     568             : 
     569         420 :     for (i = 0; i < ncolumns; i++)
     570             :     {
     571             :         struct varlena *attr;
     572             :         struct varlena *new_attr;
     573             :         struct varatt_indirect redirect_pointer;
     574             : 
     575             :         /* only work on existing, not-null varlenas */
     576         336 :         if (TupleDescAttr(tupdesc, i)->attisdropped ||
     577         336 :             nulls[i] ||
     578         292 :             TupleDescAttr(tupdesc, i)->attlen != -1)
     579         128 :             continue;
     580             : 
     581         208 :         attr = (struct varlena *) DatumGetPointer(values[i]);
     582             : 
     583             :         /* don't recursively indirect */
     584         208 :         if (VARATT_IS_EXTERNAL_INDIRECT(attr))
     585           0 :             continue;
     586             : 
     587             :         /* copy datum, so it still lives later */
     588         208 :         if (VARATT_IS_EXTERNAL_ONDISK(attr))
     589           0 :             attr = detoast_external_attr(attr);
     590             :         else
     591             :         {
     592         208 :             struct varlena *oldattr = attr;
     593             : 
     594         208 :             attr = palloc0(VARSIZE_ANY(oldattr));
     595         208 :             memcpy(attr, oldattr, VARSIZE_ANY(oldattr));
     596             :         }
     597             : 
     598             :         /* build indirection Datum */
     599         208 :         new_attr = (struct varlena *) palloc0(INDIRECT_POINTER_SIZE);
     600         208 :         redirect_pointer.pointer = attr;
     601         208 :         SET_VARTAG_EXTERNAL(new_attr, VARTAG_INDIRECT);
     602         208 :         memcpy(VARDATA_EXTERNAL(new_attr), &redirect_pointer,
     603             :                sizeof(redirect_pointer));
     604             : 
     605         208 :         values[i] = PointerGetDatum(new_attr);
     606             :     }
     607             : 
     608          84 :     newtup = heap_form_tuple(tupdesc, values, nulls);
     609          84 :     pfree(values);
     610          84 :     pfree(nulls);
     611          84 :     ReleaseTupleDesc(tupdesc);
     612             : 
     613          84 :     MemoryContextSwitchTo(old_context);
     614             : 
     615             :     /*
     616             :      * We intentionally don't use PG_RETURN_HEAPTUPLEHEADER here, because that
     617             :      * would cause the indirect toast pointers to be flattened out of the
     618             :      * tuple immediately, rendering subsequent testing irrelevant.  So just
     619             :      * return the HeapTupleHeader pointer as-is.  This violates the general
     620             :      * rule that composite Datums shouldn't contain toast pointers, but so
     621             :      * long as the regression test scripts don't insert the result of this
     622             :      * function into a container type (record, array, etc) it should be OK.
     623             :      */
     624          84 :     PG_RETURN_POINTER(newtup->t_data);
     625             : }
     626             : 
     627           4 : PG_FUNCTION_INFO_V1(regress_putenv);
     628             : 
     629             : Datum
     630           2 : regress_putenv(PG_FUNCTION_ARGS)
     631             : {
     632             :     MemoryContext oldcontext;
     633             :     char       *envbuf;
     634             : 
     635           2 :     if (!superuser())
     636           0 :         elog(ERROR, "must be superuser to change environment variables");
     637             : 
     638           2 :     oldcontext = MemoryContextSwitchTo(TopMemoryContext);
     639           2 :     envbuf = text_to_cstring((text *) PG_GETARG_POINTER(0));
     640           2 :     MemoryContextSwitchTo(oldcontext);
     641             : 
     642           2 :     if (putenv(envbuf) != 0)
     643           0 :         elog(ERROR, "could not set environment variable: %m");
     644             : 
     645           2 :     PG_RETURN_VOID();
     646             : }
     647             : 
     648             : /* Sleep until no process has a given PID. */
     649           6 : PG_FUNCTION_INFO_V1(wait_pid);
     650             : 
     651             : Datum
     652           2 : wait_pid(PG_FUNCTION_ARGS)
     653             : {
     654           2 :     int         pid = PG_GETARG_INT32(0);
     655             : 
     656           2 :     if (!superuser())
     657           0 :         elog(ERROR, "must be superuser to check PID liveness");
     658             : 
     659           4 :     while (kill(pid, 0) == 0)
     660             :     {
     661           2 :         CHECK_FOR_INTERRUPTS();
     662           2 :         pg_usleep(50000);
     663             :     }
     664             : 
     665           2 :     if (errno != ESRCH)
     666           0 :         elog(ERROR, "could not check PID %d liveness: %m", pid);
     667             : 
     668           2 :     PG_RETURN_VOID();
     669             : }
     670             : 
     671             : static void
     672           4 : test_atomic_flag(void)
     673             : {
     674             :     pg_atomic_flag flag;
     675             : 
     676           4 :     pg_atomic_init_flag(&flag);
     677           4 :     EXPECT_TRUE(pg_atomic_unlocked_test_flag(&flag));
     678           4 :     EXPECT_TRUE(pg_atomic_test_set_flag(&flag));
     679           4 :     EXPECT_TRUE(!pg_atomic_unlocked_test_flag(&flag));
     680           4 :     EXPECT_TRUE(!pg_atomic_test_set_flag(&flag));
     681           4 :     pg_atomic_clear_flag(&flag);
     682           4 :     EXPECT_TRUE(pg_atomic_unlocked_test_flag(&flag));
     683           4 :     EXPECT_TRUE(pg_atomic_test_set_flag(&flag));
     684           4 :     pg_atomic_clear_flag(&flag);
     685           4 : }
     686             : 
     687             : static void
     688           4 : test_atomic_uint32(void)
     689             : {
     690             :     pg_atomic_uint32 var;
     691             :     uint32      expected;
     692             :     int         i;
     693             : 
     694           4 :     pg_atomic_init_u32(&var, 0);
     695           4 :     EXPECT_EQ_U32(pg_atomic_read_u32(&var), 0);
     696           4 :     pg_atomic_write_u32(&var, 3);
     697           4 :     EXPECT_EQ_U32(pg_atomic_read_u32(&var), 3);
     698           4 :     EXPECT_EQ_U32(pg_atomic_fetch_add_u32(&var, pg_atomic_read_u32(&var) - 2),
     699             :                   3);
     700           4 :     EXPECT_EQ_U32(pg_atomic_fetch_sub_u32(&var, 1), 4);
     701           4 :     EXPECT_EQ_U32(pg_atomic_sub_fetch_u32(&var, 3), 0);
     702           4 :     EXPECT_EQ_U32(pg_atomic_add_fetch_u32(&var, 10), 10);
     703           4 :     EXPECT_EQ_U32(pg_atomic_exchange_u32(&var, 5), 10);
     704           4 :     EXPECT_EQ_U32(pg_atomic_exchange_u32(&var, 0), 5);
     705             : 
     706             :     /* test around numerical limits */
     707           4 :     EXPECT_EQ_U32(pg_atomic_fetch_add_u32(&var, INT_MAX), 0);
     708           4 :     EXPECT_EQ_U32(pg_atomic_fetch_add_u32(&var, INT_MAX), INT_MAX);
     709           4 :     pg_atomic_fetch_add_u32(&var, 2);   /* wrap to 0 */
     710           4 :     EXPECT_EQ_U32(pg_atomic_fetch_add_u32(&var, PG_INT16_MAX), 0);
     711           4 :     EXPECT_EQ_U32(pg_atomic_fetch_add_u32(&var, PG_INT16_MAX + 1),
     712             :                   PG_INT16_MAX);
     713           4 :     EXPECT_EQ_U32(pg_atomic_fetch_add_u32(&var, PG_INT16_MIN),
     714             :                   2 * PG_INT16_MAX + 1);
     715           4 :     EXPECT_EQ_U32(pg_atomic_fetch_add_u32(&var, PG_INT16_MIN - 1),
     716             :                   PG_INT16_MAX);
     717           4 :     pg_atomic_fetch_add_u32(&var, 1);   /* top up to UINT_MAX */
     718           4 :     EXPECT_EQ_U32(pg_atomic_read_u32(&var), UINT_MAX);
     719           4 :     EXPECT_EQ_U32(pg_atomic_fetch_sub_u32(&var, INT_MAX), UINT_MAX);
     720           4 :     EXPECT_EQ_U32(pg_atomic_read_u32(&var), (uint32) INT_MAX + 1);
     721           4 :     EXPECT_EQ_U32(pg_atomic_sub_fetch_u32(&var, INT_MAX), 1);
     722           4 :     pg_atomic_sub_fetch_u32(&var, 1);
     723           4 :     expected = PG_INT16_MAX;
     724           4 :     EXPECT_TRUE(!pg_atomic_compare_exchange_u32(&var, &expected, 1));
     725           4 :     expected = PG_INT16_MAX + 1;
     726           4 :     EXPECT_TRUE(!pg_atomic_compare_exchange_u32(&var, &expected, 1));
     727           4 :     expected = PG_INT16_MIN;
     728           4 :     EXPECT_TRUE(!pg_atomic_compare_exchange_u32(&var, &expected, 1));
     729           4 :     expected = PG_INT16_MIN - 1;
     730           4 :     EXPECT_TRUE(!pg_atomic_compare_exchange_u32(&var, &expected, 1));
     731             : 
     732             :     /* fail exchange because of old expected */
     733           4 :     expected = 10;
     734           4 :     EXPECT_TRUE(!pg_atomic_compare_exchange_u32(&var, &expected, 1));
     735             : 
     736             :     /* CAS is allowed to fail due to interrupts, try a couple of times */
     737           8 :     for (i = 0; i < 1000; i++)
     738             :     {
     739           8 :         expected = 0;
     740           8 :         if (!pg_atomic_compare_exchange_u32(&var, &expected, 1))
     741           4 :             break;
     742             :     }
     743           4 :     if (i == 1000)
     744           0 :         elog(ERROR, "atomic_compare_exchange_u32() never succeeded");
     745           4 :     EXPECT_EQ_U32(pg_atomic_read_u32(&var), 1);
     746           4 :     pg_atomic_write_u32(&var, 0);
     747             : 
     748             :     /* try setting flagbits */
     749           4 :     EXPECT_TRUE(!(pg_atomic_fetch_or_u32(&var, 1) & 1));
     750           4 :     EXPECT_TRUE(pg_atomic_fetch_or_u32(&var, 2) & 1);
     751           4 :     EXPECT_EQ_U32(pg_atomic_read_u32(&var), 3);
     752             :     /* try clearing flagbits */
     753           4 :     EXPECT_EQ_U32(pg_atomic_fetch_and_u32(&var, ~2) & 3, 3);
     754           4 :     EXPECT_EQ_U32(pg_atomic_fetch_and_u32(&var, ~1), 1);
     755             :     /* no bits set anymore */
     756           4 :     EXPECT_EQ_U32(pg_atomic_fetch_and_u32(&var, ~0), 0);
     757           4 : }
     758             : 
     759             : static void
     760           4 : test_atomic_uint64(void)
     761             : {
     762             :     pg_atomic_uint64 var;
     763             :     uint64      expected;
     764             :     int         i;
     765             : 
     766           4 :     pg_atomic_init_u64(&var, 0);
     767           4 :     EXPECT_EQ_U64(pg_atomic_read_u64(&var), 0);
     768           4 :     pg_atomic_write_u64(&var, 3);
     769           4 :     EXPECT_EQ_U64(pg_atomic_read_u64(&var), 3);
     770           4 :     EXPECT_EQ_U64(pg_atomic_fetch_add_u64(&var, pg_atomic_read_u64(&var) - 2),
     771             :                   3);
     772           4 :     EXPECT_EQ_U64(pg_atomic_fetch_sub_u64(&var, 1), 4);
     773           4 :     EXPECT_EQ_U64(pg_atomic_sub_fetch_u64(&var, 3), 0);
     774           4 :     EXPECT_EQ_U64(pg_atomic_add_fetch_u64(&var, 10), 10);
     775           4 :     EXPECT_EQ_U64(pg_atomic_exchange_u64(&var, 5), 10);
     776           4 :     EXPECT_EQ_U64(pg_atomic_exchange_u64(&var, 0), 5);
     777             : 
     778             :     /* fail exchange because of old expected */
     779           4 :     expected = 10;
     780           4 :     EXPECT_TRUE(!pg_atomic_compare_exchange_u64(&var, &expected, 1));
     781             : 
     782             :     /* CAS is allowed to fail due to interrupts, try a couple of times */
     783           8 :     for (i = 0; i < 100; i++)
     784             :     {
     785           8 :         expected = 0;
     786           8 :         if (!pg_atomic_compare_exchange_u64(&var, &expected, 1))
     787           4 :             break;
     788             :     }
     789           4 :     if (i == 100)
     790           0 :         elog(ERROR, "atomic_compare_exchange_u64() never succeeded");
     791           4 :     EXPECT_EQ_U64(pg_atomic_read_u64(&var), 1);
     792             : 
     793           4 :     pg_atomic_write_u64(&var, 0);
     794             : 
     795             :     /* try setting flagbits */
     796           4 :     EXPECT_TRUE(!(pg_atomic_fetch_or_u64(&var, 1) & 1));
     797           4 :     EXPECT_TRUE(pg_atomic_fetch_or_u64(&var, 2) & 1);
     798           4 :     EXPECT_EQ_U64(pg_atomic_read_u64(&var), 3);
     799             :     /* try clearing flagbits */
     800           4 :     EXPECT_EQ_U64((pg_atomic_fetch_and_u64(&var, ~2) & 3), 3);
     801           4 :     EXPECT_EQ_U64(pg_atomic_fetch_and_u64(&var, ~1), 1);
     802             :     /* no bits set anymore */
     803           4 :     EXPECT_EQ_U64(pg_atomic_fetch_and_u64(&var, ~0), 0);
     804           4 : }
     805             : 
     806             : /*
     807             :  * Perform, fairly minimal, testing of the spinlock implementation.
     808             :  *
     809             :  * It's likely worth expanding these to actually test concurrency etc, but
     810             :  * having some regularly run tests is better than none.
     811             :  */
     812             : static void
     813           4 : test_spinlock(void)
     814             : {
     815             :     /*
     816             :      * Basic tests for spinlocks, as well as the underlying operations.
     817             :      *
     818             :      * We embed the spinlock in a struct with other members to test that the
     819             :      * spinlock operations don't perform too wide writes.
     820             :      */
     821             :     {
     822             :         struct test_lock_struct
     823             :         {
     824             :             char        data_before[4];
     825             :             slock_t     lock;
     826             :             char        data_after[4];
     827             :         } struct_w_lock;
     828             : 
     829           4 :         memcpy(struct_w_lock.data_before, "abcd", 4);
     830           4 :         memcpy(struct_w_lock.data_after, "ef12", 4);
     831             : 
     832             :         /* test basic operations via the SpinLock* API */
     833           4 :         SpinLockInit(&struct_w_lock.lock);
     834           4 :         SpinLockAcquire(&struct_w_lock.lock);
     835           4 :         SpinLockRelease(&struct_w_lock.lock);
     836             : 
     837             :         /* test basic operations via underlying S_* API */
     838           4 :         S_INIT_LOCK(&struct_w_lock.lock);
     839           4 :         S_LOCK(&struct_w_lock.lock);
     840           4 :         S_UNLOCK(&struct_w_lock.lock);
     841             : 
     842             :         /* and that "contended" acquisition works */
     843           4 :         s_lock(&struct_w_lock.lock, "testfile", 17, "testfunc");
     844           4 :         S_UNLOCK(&struct_w_lock.lock);
     845             : 
     846             :         /*
     847             :          * Check, using TAS directly, that a single spin cycle doesn't block
     848             :          * when acquiring an already acquired lock.
     849             :          */
     850             : #ifdef TAS
     851           4 :         S_LOCK(&struct_w_lock.lock);
     852             : 
     853           4 :         if (!TAS(&struct_w_lock.lock))
     854           0 :             elog(ERROR, "acquired already held spinlock");
     855             : 
     856             : #ifdef TAS_SPIN
     857           4 :         if (!TAS_SPIN(&struct_w_lock.lock))
     858           0 :             elog(ERROR, "acquired already held spinlock");
     859             : #endif                          /* defined(TAS_SPIN) */
     860             : 
     861           4 :         S_UNLOCK(&struct_w_lock.lock);
     862             : #endif                          /* defined(TAS) */
     863             : 
     864             :         /*
     865             :          * Verify that after all of this the non-lock contents are still
     866             :          * correct.
     867             :          */
     868           4 :         if (memcmp(struct_w_lock.data_before, "abcd", 4) != 0)
     869           0 :             elog(ERROR, "padding before spinlock modified");
     870           4 :         if (memcmp(struct_w_lock.data_after, "ef12", 4) != 0)
     871           0 :             elog(ERROR, "padding after spinlock modified");
     872             :     }
     873             : 
     874             :     /*
     875             :      * Ensure that allocating more than INT32_MAX emulated spinlocks
     876             :      * works. That's interesting because the spinlock emulation uses a 32bit
     877             :      * integer to map spinlocks onto semaphores. There've been bugs...
     878             :      */
     879             : #ifndef HAVE_SPINLOCKS
     880             :     {
     881             :         /*
     882             :          * Initialize enough spinlocks to advance counter close to
     883             :          * wraparound. It's too expensive to perform acquire/release for each,
     884             :          * as those may be syscalls when the spinlock emulation is used (and
     885             :          * even just atomic TAS would be expensive).
     886             :          */
     887             :         for (uint32 i = 0; i < INT32_MAX - 100000; i++)
     888             :         {
     889             :             slock_t lock;
     890             : 
     891             :             SpinLockInit(&lock);
     892             :         }
     893             : 
     894             :         for (uint32 i = 0; i < 200000; i++)
     895             :         {
     896             :             slock_t lock;
     897             : 
     898             :             SpinLockInit(&lock);
     899             : 
     900             :             SpinLockAcquire(&lock);
     901             :             SpinLockRelease(&lock);
     902             :             SpinLockAcquire(&lock);
     903             :             SpinLockRelease(&lock);
     904             :         }
     905             :     }
     906             : #endif
     907           4 : }
     908             : 
     909             : /*
     910             :  * Verify that performing atomic ops inside a spinlock isn't a
     911             :  * problem. Realistically that's only going to be a problem when both
     912             :  * --disable-spinlocks and --disable-atomics are used, but it's cheap enough
     913             :  * to just always test.
     914             :  *
     915             :  * The test works by initializing enough atomics that we'd conflict if there
     916             :  * were an overlap between a spinlock and an atomic by holding a spinlock
     917             :  * while manipulating more than NUM_SPINLOCK_SEMAPHORES atomics.
     918             :  *
     919             :  * NUM_TEST_ATOMICS doesn't really need to be more than
     920             :  * NUM_SPINLOCK_SEMAPHORES, but it seems better to test a bit more
     921             :  * extensively.
     922             :  */
     923             : static void
     924           4 : test_atomic_spin_nest(void)
     925             : {
     926             :     slock_t lock;
     927             : #define NUM_TEST_ATOMICS (NUM_SPINLOCK_SEMAPHORES + NUM_ATOMICS_SEMAPHORES + 27)
     928             :     pg_atomic_uint32 atomics32[NUM_TEST_ATOMICS];
     929             :     pg_atomic_uint64 atomics64[NUM_TEST_ATOMICS];
     930             : 
     931           4 :     SpinLockInit(&lock);
     932             : 
     933         880 :     for (int i = 0; i < NUM_TEST_ATOMICS; i++)
     934             :     {
     935         876 :         pg_atomic_init_u32(&atomics32[i], 0);
     936         876 :         pg_atomic_init_u64(&atomics64[i], 0);
     937             :     }
     938             : 
     939             :     /* just so it's not all zeroes */
     940         880 :     for (int i = 0; i < NUM_TEST_ATOMICS; i++)
     941             :     {
     942         876 :         EXPECT_EQ_U32(pg_atomic_fetch_add_u32(&atomics32[i], i), 0);
     943         876 :         EXPECT_EQ_U64(pg_atomic_fetch_add_u64(&atomics64[i], i), 0);
     944             :     }
     945             : 
     946             :     /* test whether we can do atomic op with lock held */
     947           4 :     SpinLockAcquire(&lock);
     948         880 :     for (int i = 0; i < NUM_TEST_ATOMICS; i++)
     949             :     {
     950         876 :         EXPECT_EQ_U32(pg_atomic_fetch_sub_u32(&atomics32[i], i), i);
     951         876 :         EXPECT_EQ_U32(pg_atomic_read_u32(&atomics32[i]), 0);
     952         876 :         EXPECT_EQ_U64(pg_atomic_fetch_sub_u64(&atomics64[i], i), i);
     953         876 :         EXPECT_EQ_U64(pg_atomic_read_u64(&atomics64[i]), 0);
     954             :     }
     955           4 :     SpinLockRelease(&lock);
     956           4 : }
     957             : #undef NUM_TEST_ATOMICS
     958             : 
     959          10 : PG_FUNCTION_INFO_V1(test_atomic_ops);
     960             : Datum
     961           4 : test_atomic_ops(PG_FUNCTION_ARGS)
     962             : {
     963           4 :     test_atomic_flag();
     964             : 
     965           4 :     test_atomic_uint32();
     966             : 
     967           4 :     test_atomic_uint64();
     968             : 
     969             :     /*
     970             :      * Arguably this shouldn't be tested as part of this function, but it's
     971             :      * closely enough related that that seems ok for now.
     972             :      */
     973           4 :     test_spinlock();
     974             : 
     975           4 :     test_atomic_spin_nest();
     976             : 
     977           4 :     PG_RETURN_BOOL(true);
     978             : }
     979             : 
     980           6 : PG_FUNCTION_INFO_V1(test_fdw_handler);
     981             : Datum
     982           0 : test_fdw_handler(PG_FUNCTION_ARGS)
     983             : {
     984           0 :     elog(ERROR, "test_fdw_handler is not implemented");
     985             :     PG_RETURN_NULL();
     986             : }
     987             : 
     988          10 : PG_FUNCTION_INFO_V1(test_support_func);
     989             : Datum
     990          40 : test_support_func(PG_FUNCTION_ARGS)
     991             : {
     992          40 :     Node       *rawreq = (Node *) PG_GETARG_POINTER(0);
     993          40 :     Node       *ret = NULL;
     994             : 
     995          40 :     if (IsA(rawreq, SupportRequestSelectivity))
     996             :     {
     997             :         /*
     998             :          * Assume that the target is int4eq; that's safe as long as we don't
     999             :          * attach this to any other boolean-returning function.
    1000             :          */
    1001           4 :         SupportRequestSelectivity *req = (SupportRequestSelectivity *) rawreq;
    1002             :         Selectivity s1;
    1003             : 
    1004           4 :         if (req->is_join)
    1005           0 :             s1 = join_selectivity(req->root, Int4EqualOperator,
    1006             :                                   req->args,
    1007             :                                   req->inputcollid,
    1008             :                                   req->jointype,
    1009           0 :                                   req->sjinfo);
    1010             :         else
    1011           4 :             s1 = restriction_selectivity(req->root, Int4EqualOperator,
    1012             :                                          req->args,
    1013             :                                          req->inputcollid,
    1014             :                                          req->varRelid);
    1015             : 
    1016           4 :         req->selectivity = s1;
    1017           4 :         ret = (Node *) req;
    1018             :     }
    1019             : 
    1020          40 :     if (IsA(rawreq, SupportRequestCost))
    1021             :     {
    1022             :         /* Provide some generic estimate */
    1023          12 :         SupportRequestCost *req = (SupportRequestCost *) rawreq;
    1024             : 
    1025          12 :         req->startup = 0;
    1026          12 :         req->per_tuple = 2 * cpu_operator_cost;
    1027          12 :         ret = (Node *) req;
    1028             :     }
    1029             : 
    1030          40 :     if (IsA(rawreq, SupportRequestRows))
    1031             :     {
    1032             :         /*
    1033             :          * Assume that the target is generate_series_int4; that's safe as long
    1034             :          * as we don't attach this to any other set-returning function.
    1035             :          */
    1036           8 :         SupportRequestRows *req = (SupportRequestRows *) rawreq;
    1037             : 
    1038           8 :         if (req->node && IsA(req->node, FuncExpr))    /* be paranoid */
    1039             :         {
    1040           8 :             List       *args = ((FuncExpr *) req->node)->args;
    1041           8 :             Node       *arg1 = linitial(args);
    1042           8 :             Node       *arg2 = lsecond(args);
    1043             : 
    1044           8 :             if (IsA(arg1, Const) &&
    1045           8 :                 !((Const *) arg1)->constisnull &&
    1046           8 :                 IsA(arg2, Const) &&
    1047           8 :                 !((Const *) arg2)->constisnull)
    1048             :             {
    1049           8 :                 int32       val1 = DatumGetInt32(((Const *) arg1)->constvalue);
    1050           8 :                 int32       val2 = DatumGetInt32(((Const *) arg2)->constvalue);
    1051             : 
    1052           8 :                 req->rows = val2 - val1 + 1;
    1053           8 :                 ret = (Node *) req;
    1054             :             }
    1055             :         }
    1056             :     }
    1057             : 
    1058          40 :     PG_RETURN_POINTER(ret);
    1059             : }
    1060             : 
    1061           6 : PG_FUNCTION_INFO_V1(test_opclass_options_func);
    1062             : Datum
    1063           0 : test_opclass_options_func(PG_FUNCTION_ARGS)
    1064             : {
    1065           0 :     PG_RETURN_NULL();
    1066             : }

Generated by: LCOV version 1.13