LCOV - differential code coverage report
Current view: top level - src/backend/utils/adt - pg_upgrade_support.c (source / functions) Coverage Total Hit UNC UIC UBC GIC GNC CBC EUB ECB DUB DCB
Current: Differential Code Coverage HEAD vs 15 Lines: 63.9 % 108 69 1 6 32 3 6 60 5 3 2 6
Current Date: 2023-04-08 15:15:32 Functions: 81.2 % 16 13 1 1 1 1 3 9 1 1
Baseline: 15
Baseline Date: 2023-04-08 15:09:40
Legend: Lines: hit not hit

           TLA  Line data    Source code
       1                 : /*
       2                 :  *  pg_upgrade_support.c
       3                 :  *
       4                 :  *  server-side functions to set backend global variables
       5                 :  *  to control oid and relfilenumber assignment, and do other special
       6                 :  *  hacks needed for pg_upgrade.
       7                 :  *
       8                 :  *  Copyright (c) 2010-2023, PostgreSQL Global Development Group
       9                 :  *  src/backend/utils/adt/pg_upgrade_support.c
      10                 :  */
      11                 : 
      12                 : #include "postgres.h"
      13                 : 
      14                 : #include "catalog/binary_upgrade.h"
      15                 : #include "catalog/heap.h"
      16                 : #include "catalog/namespace.h"
      17                 : #include "catalog/pg_type.h"
      18                 : #include "commands/extension.h"
      19                 : #include "miscadmin.h"
      20                 : #include "utils/array.h"
      21                 : #include "utils/builtins.h"
      22                 : 
      23                 : 
      24                 : #define CHECK_IS_BINARY_UPGRADE                                 \
      25                 : do {                                                            \
      26                 :     if (!IsBinaryUpgrade)                                       \
      27                 :         ereport(ERROR,                                          \
      28                 :                 (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),    \
      29                 :                  errmsg("function can only be called when server is in binary upgrade mode"))); \
      30                 : } while (0)
      31                 : 
      32                 : Datum
      33 UBC           0 : binary_upgrade_set_next_pg_tablespace_oid(PG_FUNCTION_ARGS)
      34                 : {
      35               0 :     Oid         tbspoid = PG_GETARG_OID(0);
      36                 : 
      37               0 :     CHECK_IS_BINARY_UPGRADE;
      38               0 :     binary_upgrade_next_pg_tablespace_oid = tbspoid;
      39                 : 
      40               0 :     PG_RETURN_VOID();
      41                 : }
      42                 : 
      43                 : Datum
      44 CBC         720 : binary_upgrade_set_next_pg_type_oid(PG_FUNCTION_ARGS)
      45                 : {
      46             720 :     Oid         typoid = PG_GETARG_OID(0);
      47                 : 
      48             720 :     CHECK_IS_BINARY_UPGRADE;
      49             720 :     binary_upgrade_next_pg_type_oid = typoid;
      50                 : 
      51             720 :     PG_RETURN_VOID();
      52                 : }
      53                 : 
      54                 : Datum
      55             719 : binary_upgrade_set_next_array_pg_type_oid(PG_FUNCTION_ARGS)
      56                 : {
      57             719 :     Oid         typoid = PG_GETARG_OID(0);
      58                 : 
      59             719 :     CHECK_IS_BINARY_UPGRADE;
      60             719 :     binary_upgrade_next_array_pg_type_oid = typoid;
      61                 : 
      62             719 :     PG_RETURN_VOID();
      63                 : }
      64                 : 
      65                 : Datum
      66               4 : binary_upgrade_set_next_multirange_pg_type_oid(PG_FUNCTION_ARGS)
      67                 : {
      68               4 :     Oid         typoid = PG_GETARG_OID(0);
      69                 : 
      70               4 :     CHECK_IS_BINARY_UPGRADE;
      71               4 :     binary_upgrade_next_mrng_pg_type_oid = typoid;
      72                 : 
      73               4 :     PG_RETURN_VOID();
      74                 : }
      75                 : 
      76                 : Datum
      77               4 : binary_upgrade_set_next_multirange_array_pg_type_oid(PG_FUNCTION_ARGS)
      78                 : {
      79               4 :     Oid         typoid = PG_GETARG_OID(0);
      80                 : 
      81               4 :     CHECK_IS_BINARY_UPGRADE;
      82               4 :     binary_upgrade_next_mrng_array_pg_type_oid = typoid;
      83                 : 
      84               4 :     PG_RETURN_VOID();
      85                 : }
      86                 : 
      87                 : Datum
      88             721 : binary_upgrade_set_next_heap_pg_class_oid(PG_FUNCTION_ARGS)
      89                 : {
      90             721 :     Oid         reloid = PG_GETARG_OID(0);
      91                 : 
      92             721 :     CHECK_IS_BINARY_UPGRADE;
      93             721 :     binary_upgrade_next_heap_pg_class_oid = reloid;
      94                 : 
      95             721 :     PG_RETURN_VOID();
      96                 : }
      97                 : 
      98                 : Datum
      99             588 : binary_upgrade_set_next_heap_relfilenode(PG_FUNCTION_ARGS)
     100                 : {
     101 GNC         588 :     RelFileNumber relfilenumber = PG_GETARG_OID(0);
     102                 : 
     103 CBC         588 :     CHECK_IS_BINARY_UPGRADE;
     104 GNC         588 :     binary_upgrade_next_heap_pg_class_relfilenumber = relfilenumber;
     105                 : 
     106 CBC         588 :     PG_RETURN_VOID();
     107                 : }
     108                 : 
     109                 : Datum
     110             482 : binary_upgrade_set_next_index_pg_class_oid(PG_FUNCTION_ARGS)
     111                 : {
     112             482 :     Oid         reloid = PG_GETARG_OID(0);
     113                 : 
     114             482 :     CHECK_IS_BINARY_UPGRADE;
     115             482 :     binary_upgrade_next_index_pg_class_oid = reloid;
     116                 : 
     117             482 :     PG_RETURN_VOID();
     118                 : }
     119                 : 
     120                 : Datum
     121             488 : binary_upgrade_set_next_index_relfilenode(PG_FUNCTION_ARGS)
     122                 : {
     123 GNC         488 :     RelFileNumber relfilenumber = PG_GETARG_OID(0);
     124                 : 
     125 CBC         488 :     CHECK_IS_BINARY_UPGRADE;
     126 GNC         488 :     binary_upgrade_next_index_pg_class_relfilenumber = relfilenumber;
     127                 : 
     128 CBC         488 :     PG_RETURN_VOID();
     129                 : }
     130                 : 
     131                 : Datum
     132             244 : binary_upgrade_set_next_toast_pg_class_oid(PG_FUNCTION_ARGS)
     133                 : {
     134             244 :     Oid         reloid = PG_GETARG_OID(0);
     135                 : 
     136             244 :     CHECK_IS_BINARY_UPGRADE;
     137             244 :     binary_upgrade_next_toast_pg_class_oid = reloid;
     138                 : 
     139             244 :     PG_RETURN_VOID();
     140                 : }
     141                 : 
     142                 : Datum
     143             244 : binary_upgrade_set_next_toast_relfilenode(PG_FUNCTION_ARGS)
     144                 : {
     145 GNC         244 :     RelFileNumber relfilenumber = PG_GETARG_OID(0);
     146                 : 
     147 CBC         244 :     CHECK_IS_BINARY_UPGRADE;
     148 GNC         244 :     binary_upgrade_next_toast_pg_class_relfilenumber = relfilenumber;
     149                 : 
     150 CBC         244 :     PG_RETURN_VOID();
     151                 : }
     152                 : 
     153                 : Datum
     154              44 : binary_upgrade_set_next_pg_enum_oid(PG_FUNCTION_ARGS)
     155                 : {
     156              44 :     Oid         enumoid = PG_GETARG_OID(0);
     157                 : 
     158              44 :     CHECK_IS_BINARY_UPGRADE;
     159              44 :     binary_upgrade_next_pg_enum_oid = enumoid;
     160                 : 
     161              44 :     PG_RETURN_VOID();
     162                 : }
     163                 : 
     164                 : Datum
     165               1 : binary_upgrade_set_next_pg_authid_oid(PG_FUNCTION_ARGS)
     166                 : {
     167               1 :     Oid         authoid = PG_GETARG_OID(0);
     168                 : 
     169               1 :     CHECK_IS_BINARY_UPGRADE;
     170               1 :     binary_upgrade_next_pg_authid_oid = authoid;
     171               1 :     PG_RETURN_VOID();
     172                 : }
     173                 : 
     174                 : Datum
     175 UBC           0 : binary_upgrade_create_empty_extension(PG_FUNCTION_ARGS)
     176                 : {
     177                 :     text       *extName;
     178                 :     text       *schemaName;
     179                 :     bool        relocatable;
     180                 :     text       *extVersion;
     181                 :     Datum       extConfig;
     182                 :     Datum       extCondition;
     183                 :     List       *requiredExtensions;
     184                 : 
     185               0 :     CHECK_IS_BINARY_UPGRADE;
     186                 : 
     187                 :     /* We must check these things before dereferencing the arguments */
     188               0 :     if (PG_ARGISNULL(0) ||
     189               0 :         PG_ARGISNULL(1) ||
     190               0 :         PG_ARGISNULL(2) ||
     191               0 :         PG_ARGISNULL(3))
     192               0 :         elog(ERROR, "null argument to binary_upgrade_create_empty_extension is not allowed");
     193                 : 
     194               0 :     extName = PG_GETARG_TEXT_PP(0);
     195               0 :     schemaName = PG_GETARG_TEXT_PP(1);
     196               0 :     relocatable = PG_GETARG_BOOL(2);
     197               0 :     extVersion = PG_GETARG_TEXT_PP(3);
     198                 : 
     199               0 :     if (PG_ARGISNULL(4))
     200               0 :         extConfig = PointerGetDatum(NULL);
     201                 :     else
     202               0 :         extConfig = PG_GETARG_DATUM(4);
     203                 : 
     204               0 :     if (PG_ARGISNULL(5))
     205               0 :         extCondition = PointerGetDatum(NULL);
     206                 :     else
     207               0 :         extCondition = PG_GETARG_DATUM(5);
     208                 : 
     209               0 :     requiredExtensions = NIL;
     210               0 :     if (!PG_ARGISNULL(6))
     211                 :     {
     212               0 :         ArrayType  *textArray = PG_GETARG_ARRAYTYPE_P(6);
     213                 :         Datum      *textDatums;
     214                 :         int         ndatums;
     215                 :         int         i;
     216                 : 
     217 UNC           0 :         deconstruct_array_builtin(textArray, TEXTOID, &textDatums, NULL, &ndatums);
     218 UBC           0 :         for (i = 0; i < ndatums; i++)
     219 EUB             :         {
     220 UIC           0 :             char       *extName = TextDatumGetCString(textDatums[i]);
     221 UBC           0 :             Oid         extOid = get_extension_oid(extName, false);
     222                 : 
     223 UIC           0 :             requiredExtensions = lappend_oid(requiredExtensions, extOid);
     224                 :         }
     225 EUB             :     }
     226                 : 
     227 UBC           0 :     InsertExtensionTuple(text_to_cstring(extName),
     228                 :                          GetUserId(),
     229               0 :                          get_namespace_oid(text_to_cstring(schemaName), false),
     230                 :                          relocatable,
     231 UIC           0 :                          text_to_cstring(extVersion),
     232                 :                          extConfig,
     233                 :                          extCondition,
     234 EUB             :                          requiredExtensions);
     235                 : 
     236 UIC           0 :     PG_RETURN_VOID();
     237                 : }
     238 EUB             : 
     239                 : Datum
     240 UBC           0 : binary_upgrade_set_record_init_privs(PG_FUNCTION_ARGS)
     241                 : {
     242               0 :     bool        record_init_privs = PG_GETARG_BOOL(0);
     243 EUB             : 
     244 UIC           0 :     CHECK_IS_BINARY_UPGRADE;
     245 UBC           0 :     binary_upgrade_record_init_privs = record_init_privs;
     246                 : 
     247 UIC           0 :     PG_RETURN_VOID();
     248                 : }
     249 ECB             : 
     250                 : Datum
     251 CBC           2 : binary_upgrade_set_missing_value(PG_FUNCTION_ARGS)
     252 ECB             : {
     253 CBC           2 :     Oid         table_id = PG_GETARG_OID(0);
     254               2 :     text       *attname = PG_GETARG_TEXT_P(1);
     255               2 :     text       *value = PG_GETARG_TEXT_P(2);
     256 GIC           2 :     char       *cattname = text_to_cstring(attname);
     257 CBC           2 :     char       *cvalue = text_to_cstring(value);
     258 ECB             : 
     259 GIC           2 :     CHECK_IS_BINARY_UPGRADE;
     260 CBC           2 :     SetAttrMissing(table_id, cattname, cvalue);
     261                 : 
     262 GIC           2 :     PG_RETURN_VOID();
     263                 : }
        

Generated by: LCOV version v1.16-55-g56c0a2a