PostgreSQL Source Code  git master
bootstrap.h File Reference
#include "nodes/execnodes.h"
#include "nodes/parsenodes.h"
Include dependency graph for bootstrap.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define MAXATTR   40
 
#define BOOTCOL_NULL_AUTO   1
 
#define BOOTCOL_NULL_FORCE_NULL   2
 
#define BOOTCOL_NULL_FORCE_NOT_NULL   3
 

Functions

void BootstrapModeMain (int argc, char *argv[], bool check_only) pg_attribute_noreturn()
 
void closerel (char *relname)
 
void boot_openrel (char *relname)
 
void DefineAttr (char *name, char *type, int attnum, int nullness)
 
void InsertOneTuple (void)
 
void InsertOneValue (char *value, int i)
 
void InsertOneNull (int i)
 
void index_register (Oid heap, Oid ind, const IndexInfo *indexInfo)
 
void build_indices (void)
 
void boot_get_type_io_data (Oid typid, int16 *typlen, bool *typbyval, char *typalign, char *typdelim, Oid *typioparam, Oid *typinput, Oid *typoutput)
 
int boot_yyparse (void)
 
int boot_yylex (void)
 
void boot_yyerror (const char *message) pg_attribute_noreturn()
 

Variables

PGDLLIMPORT Relation boot_reldesc
 
PGDLLIMPORT Form_pg_attribute attrtypes [MAXATTR]
 
PGDLLIMPORT int numattr
 

Macro Definition Documentation

◆ BOOTCOL_NULL_AUTO

#define BOOTCOL_NULL_AUTO   1

Definition at line 27 of file bootstrap.h.

◆ BOOTCOL_NULL_FORCE_NOT_NULL

#define BOOTCOL_NULL_FORCE_NOT_NULL   3

Definition at line 29 of file bootstrap.h.

◆ BOOTCOL_NULL_FORCE_NULL

#define BOOTCOL_NULL_FORCE_NULL   2

Definition at line 28 of file bootstrap.h.

◆ MAXATTR

#define MAXATTR   40

Definition at line 25 of file bootstrap.h.

Function Documentation

◆ boot_get_type_io_data()

void boot_get_type_io_data ( Oid  typid,
int16 typlen,
bool typbyval,
char *  typalign,
char *  typdelim,
Oid typioparam,
Oid typinput,
Oid typoutput 
)

Definition at line 806 of file bootstrap.c.

814 {
815  if (Typ != NIL)
816  {
817  /* We have the boot-time contents of pg_type, so use it */
818  struct typmap *ap = NULL;
819  ListCell *lc;
820 
821  foreach(lc, Typ)
822  {
823  ap = lfirst(lc);
824  if (ap->am_oid == typid)
825  break;
826  }
827 
828  if (!ap || ap->am_oid != typid)
829  elog(ERROR, "type OID %u not found in Typ list", typid);
830 
831  *typlen = ap->am_typ.typlen;
832  *typbyval = ap->am_typ.typbyval;
833  *typalign = ap->am_typ.typalign;
834  *typdelim = ap->am_typ.typdelim;
835 
836  /* XXX this logic must match getTypeIOParam() */
837  if (OidIsValid(ap->am_typ.typelem))
838  *typioparam = ap->am_typ.typelem;
839  else
840  *typioparam = typid;
841 
842  *typinput = ap->am_typ.typinput;
843  *typoutput = ap->am_typ.typoutput;
844  }
845  else
846  {
847  /* We don't have pg_type yet, so use the hard-wired TypInfo array */
848  int typeindex;
849 
850  for (typeindex = 0; typeindex < n_types; typeindex++)
851  {
852  if (TypInfo[typeindex].oid == typid)
853  break;
854  }
855  if (typeindex >= n_types)
856  elog(ERROR, "type OID %u not found in TypInfo", typid);
857 
858  *typlen = TypInfo[typeindex].len;
859  *typbyval = TypInfo[typeindex].byval;
860  *typalign = TypInfo[typeindex].align;
861  /* We assume typdelim is ',' for all boot-time types */
862  *typdelim = ',';
863 
864  /* XXX this logic must match getTypeIOParam() */
865  if (OidIsValid(TypInfo[typeindex].elem))
866  *typioparam = TypInfo[typeindex].elem;
867  else
868  *typioparam = typid;
869 
870  *typinput = TypInfo[typeindex].inproc;
871  *typoutput = TypInfo[typeindex].outproc;
872  }
873 }
static const int n_types
Definition: bootstrap.c:141
static const struct typinfo TypInfo[]
Definition: bootstrap.c:88
static List * Typ
Definition: bootstrap.c:149
#define OidIsValid(objectId)
Definition: c.h:775
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:224
#define lfirst(lc)
Definition: pg_list.h:172
#define NIL
Definition: pg_list.h:68
char typalign
Definition: pg_type.h:176
char align
Definition: bootstrap.c:81
Oid outproc
Definition: bootstrap.c:85
int16 len
Definition: bootstrap.c:79
bool byval
Definition: bootstrap.c:80
Oid elem
Definition: bootstrap.c:78
Oid inproc
Definition: bootstrap.c:84
Oid am_oid
Definition: bootstrap.c:145
FormData_pg_type am_typ
Definition: bootstrap.c:146

References typinfo::align, typmap::am_oid, typmap::am_typ, typinfo::byval, typinfo::elem, elog, ERROR, typinfo::inproc, typinfo::len, lfirst, n_types, NIL, OidIsValid, typinfo::outproc, Typ, typalign, and TypInfo.

Referenced by get_type_io_data(), and InsertOneValue().

◆ boot_openrel()

void boot_openrel ( char *  relname)

Definition at line 408 of file bootstrap.c.

409 {
410  int i;
411 
412  if (strlen(relname) >= NAMEDATALEN)
413  relname[NAMEDATALEN - 1] = '\0';
414 
415  /*
416  * pg_type must be filled before any OPEN command is executed, hence we
417  * can now populate Typ if we haven't yet.
418  */
419  if (Typ == NIL)
421 
422  if (boot_reldesc != NULL)
423  closerel(NULL);
424 
425  elog(DEBUG4, "open relation %s, attrsize %d",
427 
430  for (i = 0; i < numattr; i++)
431  {
432  if (attrtypes[i] == NULL)
434  memmove((char *) attrtypes[i],
435  (char *) TupleDescAttr(boot_reldesc->rd_att, i),
437 
438  {
440 
441  elog(DEBUG4, "create attribute %d name %s len %d num %d type %u",
442  i, NameStr(at->attname), at->attlen, at->attnum,
443  at->atttypid);
444  }
445  }
446 }
void closerel(char *relname)
Definition: bootstrap.c:453
static void populate_typ_list(void)
Definition: bootstrap.c:695
Relation boot_reldesc
Definition: bootstrap.c:59
Form_pg_attribute attrtypes[MAXATTR]
Definition: bootstrap.c:61
int numattr
Definition: bootstrap.c:62
static Form_pg_attribute AllocateAttribute(void)
Definition: bootstrap.c:883
#define NameStr(name)
Definition: c.h:746
#define DEBUG4
Definition: elog.h:27
int i
Definition: isn.c:73
#define NoLock
Definition: lockdefs.h:34
RangeVar * makeRangeVar(char *schemaname, char *relname, int location)
Definition: makefuncs.c:424
#define ATTRIBUTE_FIXED_PART_SIZE
Definition: pg_attribute.h:201
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:209
NameData relname
Definition: pg_class.h:38
#define NAMEDATALEN
#define RelationGetNumberOfAttributes(relation)
Definition: rel.h:511
TupleDesc rd_att
Definition: rel.h:112
Relation table_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: table.c:83
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92

References AllocateAttribute(), ATTRIBUTE_FIXED_PART_SIZE, attrtypes, boot_reldesc, closerel(), DEBUG4, elog, i, makeRangeVar(), NAMEDATALEN, NameStr, NIL, NoLock, numattr, populate_typ_list(), RelationData::rd_att, RelationGetNumberOfAttributes, relname, table_openrv(), TupleDescAttr, and Typ.

◆ boot_yyerror()

void boot_yyerror ( const char *  message)

◆ boot_yylex()

int boot_yylex ( void  )

◆ boot_yyparse()

int boot_yyparse ( void  )

Referenced by BootstrapModeMain().

◆ BootstrapModeMain()

void BootstrapModeMain ( int  argc,
char *  argv[],
bool  check_only 
)

Definition at line 199 of file bootstrap.c.

200 {
201  int i;
202  char *progname = argv[0];
203  int flag;
204  char *userDoption = NULL;
205 
207 
208  InitStandaloneProcess(argv[0]);
209 
210  /* Set defaults, to be overridden by explicit options below */
212 
213  /* an initial --boot or --check should be present */
214  Assert(argc > 1
215  && (strcmp(argv[1], "--boot") == 0
216  || strcmp(argv[1], "--check") == 0));
217  argv++;
218  argc--;
219 
220  while ((flag = getopt(argc, argv, "B:c:d:D:Fkr:X:-:")) != -1)
221  {
222  switch (flag)
223  {
224  case 'B':
225  SetConfigOption("shared_buffers", optarg, PGC_POSTMASTER, PGC_S_ARGV);
226  break;
227  case 'c':
228  case '-':
229  {
230  char *name,
231  *value;
232 
234  if (!value)
235  {
236  if (flag == '-')
237  ereport(ERROR,
238  (errcode(ERRCODE_SYNTAX_ERROR),
239  errmsg("--%s requires a value",
240  optarg)));
241  else
242  ereport(ERROR,
243  (errcode(ERRCODE_SYNTAX_ERROR),
244  errmsg("-c %s requires a value",
245  optarg)));
246  }
247 
249  pfree(name);
250  pfree(value);
251  break;
252  }
253  case 'D':
255  break;
256  case 'd':
257  {
258  /* Turn on debugging for the bootstrap process. */
259  char *debugstr;
260 
261  debugstr = psprintf("debug%s", optarg);
262  SetConfigOption("log_min_messages", debugstr,
264  SetConfigOption("client_min_messages", debugstr,
266  pfree(debugstr);
267  }
268  break;
269  case 'F':
270  SetConfigOption("fsync", "false", PGC_POSTMASTER, PGC_S_ARGV);
271  break;
272  case 'k':
274  break;
275  case 'r':
277  break;
278  case 'X':
280  break;
281  default:
282  write_stderr("Try \"%s --help\" for more information.\n",
283  progname);
284  proc_exit(1);
285  break;
286  }
287  }
288 
289  if (argc != optind)
290  {
291  write_stderr("%s: invalid command-line arguments\n", progname);
292  proc_exit(1);
293  }
294 
295  /* Acquire configuration parameters */
297  proc_exit(1);
298 
299  /*
300  * Validate we have been given a reasonable-looking DataDir and change
301  * into it
302  */
303  checkDataDir();
304  ChangeToDataDir();
305 
306  CreateDataDirLockFile(false);
307 
309  IgnoreSystemIndexes = true;
310 
312 
314 
315  /*
316  * XXX: It might make sense to move this into its own function at some
317  * point. Right now it seems like it'd cause more code duplication than
318  * it's worth.
319  */
320  if (check_only)
321  {
323  CheckerModeMain();
324  abort();
325  }
326 
327  /*
328  * Do backend-like initialization for bootstrap mode
329  */
330  InitProcess();
331 
332  BaseInit();
333 
335  BootStrapXLOG();
336 
337  /*
338  * To ensure that src/common/link-canary.c is linked into the backend, we
339  * must call it from somewhere. Here is as good as anywhere.
340  */
342  elog(ERROR, "backend is incorrectly linked to frontend functions");
343 
344  InitPostgres(NULL, InvalidOid, NULL, InvalidOid, 0, NULL);
345 
346  /* Initialize stuff for bootstrap-file processing */
347  for (i = 0; i < MAXATTR; i++)
348  {
349  attrtypes[i] = NULL;
350  Nulls[i] = false;
351  }
352 
353  /*
354  * Process bootstrap input.
355  */
357  boot_yyparse();
359 
360  /*
361  * We should now know about all mapped relations, so it's okay to write
362  * out the initial relation mapping files.
363  */
365 
366  /* Clean up and exit */
367  cleanup();
368  proc_exit(0);
369 }
#define write_stderr(str)
Definition: parallel.c:184
static void CheckerModeMain(void)
Definition: bootstrap.c:181
static void cleanup(void)
Definition: bootstrap.c:682
static void bootstrap_signals(void)
Definition: bootstrap.c:381
uint32 bootstrap_data_checksum_version
Definition: bootstrap.c:44
static bool Nulls[MAXATTR]
Definition: bootstrap.c:153
#define MAXATTR
Definition: bootstrap.h:25
int boot_yyparse(void)
#define PG_DATA_CHECKSUM_VERSION
Definition: bufpage.h:203
#define Assert(condition)
Definition: c.h:858
int errcode(int sqlerrcode)
Definition: elog.c:857
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ereport(elevel,...)
Definition: elog.h:149
bool IsUnderPostmaster
Definition: globals.c:117
char OutputFileName[MAXPGPATH]
Definition: globals.c:76
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:4285
bool SelectConfigFiles(const char *userDoption, const char *progname)
Definition: guc.c:1786
void ParseLongOption(const char *string, char **name, char **value)
Definition: guc.c:6321
void InitializeGUCOptions(void)
Definition: guc.c:1532
@ PGC_S_DYNAMIC_DEFAULT
Definition: guc.h:110
@ PGC_S_ARGV
Definition: guc.h:113
@ PGC_INTERNAL
Definition: guc.h:69
@ PGC_POSTMASTER
Definition: guc.h:70
static struct @155 value
void proc_exit(int code)
Definition: ipc.c:104
void CreateSharedMemoryAndSemaphores(void)
Definition: ipci.c:199
const char * progname
Definition: main.c:44
char * pstrdup(const char *in)
Definition: mcxt.c:1695
void pfree(void *pointer)
Definition: mcxt.c:1520
@ NormalProcessing
Definition: miscadmin.h:449
@ BootstrapProcessing
Definition: miscadmin.h:447
#define SetProcessingMode(mode)
Definition: miscadmin.h:460
void ChangeToDataDir(void)
Definition: miscinit.c:454
void InitStandaloneProcess(const char *argv0)
Definition: miscinit.c:181
bool IgnoreSystemIndexes
Definition: miscinit.c:80
void checkDataDir(void)
Definition: miscinit.c:341
void CreateDataDirLockFile(bool amPostmaster)
Definition: miscinit.c:1455
#define MAXPGPATH
PGDLLIMPORT int optind
Definition: getopt.c:50
int getopt(int nargc, char *const *nargv, const char *ostr)
Definition: getopt.c:71
PGDLLIMPORT char * optarg
Definition: getopt.c:52
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
static const char * userDoption
Definition: postgres.c:161
#define InvalidOid
Definition: postgres_ext.h:36
void InitializeMaxBackends(void)
Definition: postinit.c:575
void BaseInit(void)
Definition: postinit.c:645
void InitPostgres(const char *in_dbname, Oid dboid, const char *username, Oid useroid, bits32 flags, char *out_dbname)
Definition: postinit.c:736
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
void RelationMapFinishBootstrap(void)
Definition: relmapper.c:625
void InitProcess(void)
Definition: proc.c:296
char * flag(int b)
Definition: test-ctype.c:33
const char * name
void StartTransactionCommand(void)
Definition: xact.c:2995
void CommitTransactionCommand(void)
Definition: xact.c:3093
void BootStrapXLOG(void)
Definition: xlog.c:5000

References Assert, attrtypes, BaseInit(), boot_yyparse(), bootstrap_data_checksum_version, bootstrap_signals(), BootstrapProcessing, BootStrapXLOG(), ChangeToDataDir(), checkDataDir(), CheckerModeMain(), cleanup(), CommitTransactionCommand(), CreateDataDirLockFile(), CreateSharedMemoryAndSemaphores(), elog, ereport, errcode(), errmsg(), ERROR, flag(), getopt(), i, IgnoreSystemIndexes, InitializeGUCOptions(), InitializeMaxBackends(), InitPostgres(), InitProcess(), InitStandaloneProcess(), InvalidOid, IsUnderPostmaster, MAXATTR, MAXPGPATH, name, NormalProcessing, Nulls, optarg, optind, OutputFileName, ParseLongOption(), pfree(), PG_DATA_CHECKSUM_VERSION, pg_link_canary_is_frontend(), PGC_INTERNAL, PGC_POSTMASTER, PGC_S_ARGV, PGC_S_DYNAMIC_DEFAULT, proc_exit(), progname, psprintf(), pstrdup(), RelationMapFinishBootstrap(), SelectConfigFiles(), SetConfigOption(), SetProcessingMode, StartTransactionCommand(), strlcpy(), userDoption, value, and write_stderr.

Referenced by main().

◆ build_indices()

void build_indices ( void  )

Definition at line 951 of file bootstrap.c.

952 {
953  for (; ILHead != NULL; ILHead = ILHead->il_next)
954  {
955  Relation heap;
956  Relation ind;
957 
958  /* need not bother with locks during bootstrap */
959  heap = table_open(ILHead->il_heap, NoLock);
961 
962  index_build(heap, ind, ILHead->il_info, false, false);
963 
965  table_close(heap, NoLock);
966  }
967 }
static IndexList * ILHead
Definition: bootstrap.c:171
void index_build(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, bool isreindex, bool parallel)
Definition: index.c:2941
void index_close(Relation relation, LOCKMODE lockmode)
Definition: indexam.c:177
Relation index_open(Oid relationId, LOCKMODE lockmode)
Definition: indexam.c:133
Oid il_heap
Definition: bootstrap.c:165
struct _IndexList * il_next
Definition: bootstrap.c:168
Oid il_ind
Definition: bootstrap.c:166
IndexInfo * il_info
Definition: bootstrap.c:167
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:40

References _IndexList::il_heap, _IndexList::il_ind, _IndexList::il_info, _IndexList::il_next, ILHead, index_build(), index_close(), index_open(), NoLock, table_close(), and table_open().

◆ closerel()

void closerel ( char *  relname)

Definition at line 453 of file bootstrap.c.

454 {
455  if (relname)
456  {
457  if (boot_reldesc)
458  {
459  if (strcmp(RelationGetRelationName(boot_reldesc), relname) != 0)
460  elog(ERROR, "close of %s when %s was expected",
462  }
463  else
464  elog(ERROR, "close of %s before any relation was opened",
465  relname);
466  }
467 
468  if (boot_reldesc == NULL)
469  elog(ERROR, "no open relation to close");
470  else
471  {
472  elog(DEBUG4, "close relation %s",
475  boot_reldesc = NULL;
476  }
477 }
#define RelationGetRelationName(relation)
Definition: rel.h:539

References boot_reldesc, DEBUG4, elog, ERROR, NoLock, RelationGetRelationName, relname, and table_close().

Referenced by boot_openrel(), cleanup(), and DefineAttr().

◆ DefineAttr()

void DefineAttr ( char *  name,
char *  type,
int  attnum,
int  nullness 
)

Definition at line 490 of file bootstrap.c.

491 {
492  Oid typeoid;
493 
494  if (boot_reldesc != NULL)
495  {
496  elog(WARNING, "no open relations allowed with CREATE command");
497  closerel(NULL);
498  }
499 
500  if (attrtypes[attnum] == NULL)
503 
505  elog(DEBUG4, "column %s %s", NameStr(attrtypes[attnum]->attname), type);
506  attrtypes[attnum]->attnum = attnum + 1;
507 
508  typeoid = gettype(type);
509 
510  if (Typ != NIL)
511  {
512  attrtypes[attnum]->atttypid = Ap->am_oid;
513  attrtypes[attnum]->attlen = Ap->am_typ.typlen;
514  attrtypes[attnum]->attbyval = Ap->am_typ.typbyval;
515  attrtypes[attnum]->attalign = Ap->am_typ.typalign;
516  attrtypes[attnum]->attstorage = Ap->am_typ.typstorage;
517  attrtypes[attnum]->attcompression = InvalidCompressionMethod;
518  attrtypes[attnum]->attcollation = Ap->am_typ.typcollation;
519  /* if an array type, assume 1-dimensional attribute */
520  if (Ap->am_typ.typelem != InvalidOid && Ap->am_typ.typlen < 0)
521  attrtypes[attnum]->attndims = 1;
522  else
523  attrtypes[attnum]->attndims = 0;
524  }
525  else
526  {
527  attrtypes[attnum]->atttypid = TypInfo[typeoid].oid;
528  attrtypes[attnum]->attlen = TypInfo[typeoid].len;
529  attrtypes[attnum]->attbyval = TypInfo[typeoid].byval;
530  attrtypes[attnum]->attalign = TypInfo[typeoid].align;
531  attrtypes[attnum]->attstorage = TypInfo[typeoid].storage;
532  attrtypes[attnum]->attcompression = InvalidCompressionMethod;
533  attrtypes[attnum]->attcollation = TypInfo[typeoid].collation;
534  /* if an array type, assume 1-dimensional attribute */
535  if (TypInfo[typeoid].elem != InvalidOid &&
536  attrtypes[attnum]->attlen < 0)
537  attrtypes[attnum]->attndims = 1;
538  else
539  attrtypes[attnum]->attndims = 0;
540  }
541 
542  /*
543  * If a system catalog column is collation-aware, force it to use C
544  * collation, so that its behavior is independent of the database's
545  * collation. This is essential to allow template0 to be cloned with a
546  * different database collation.
547  */
548  if (OidIsValid(attrtypes[attnum]->attcollation))
549  attrtypes[attnum]->attcollation = C_COLLATION_OID;
550 
551  attrtypes[attnum]->attcacheoff = -1;
552  attrtypes[attnum]->atttypmod = -1;
553  attrtypes[attnum]->attislocal = true;
554 
555  if (nullness == BOOTCOL_NULL_FORCE_NOT_NULL)
556  {
557  attrtypes[attnum]->attnotnull = true;
558  }
559  else if (nullness == BOOTCOL_NULL_FORCE_NULL)
560  {
561  attrtypes[attnum]->attnotnull = false;
562  }
563  else
564  {
565  Assert(nullness == BOOTCOL_NULL_AUTO);
566 
567  /*
568  * Mark as "not null" if type is fixed-width and prior columns are
569  * likewise fixed-width and not-null. This corresponds to case where
570  * column can be accessed directly via C struct declaration.
571  */
572  if (attrtypes[attnum]->attlen > 0)
573  {
574  int i;
575 
576  /* check earlier attributes */
577  for (i = 0; i < attnum; i++)
578  {
579  if (attrtypes[i]->attlen <= 0 ||
581  break;
582  }
583  if (i == attnum)
584  attrtypes[attnum]->attnotnull = true;
585  }
586  }
587 }
static Oid gettype(char *type)
Definition: bootstrap.c:735
static struct typmap * Ap
Definition: bootstrap.c:150
#define BOOTCOL_NULL_FORCE_NULL
Definition: bootstrap.h:28
#define BOOTCOL_NULL_FORCE_NOT_NULL
Definition: bootstrap.h:29
#define BOOTCOL_NULL_AUTO
Definition: bootstrap.h:27
#define MemSet(start, val, len)
Definition: c.h:1020
#define WARNING
Definition: elog.h:36
void namestrcpy(Name name, const char *str)
Definition: name.c:233
NameData attname
Definition: pg_attribute.h:41
int16 attnum
Definition: pg_attribute.h:74
int16 attlen
Definition: pg_attribute.h:59
bool attnotnull
Definition: pg_attribute.h:130
unsigned int Oid
Definition: postgres_ext.h:31
Oid oid
Definition: bootstrap.c:77
Oid collation
Definition: bootstrap.c:83
char storage
Definition: bootstrap.c:82
#define InvalidCompressionMethod
const char * type

References typinfo::align, AllocateAttribute(), typmap::am_oid, typmap::am_typ, Ap, Assert, attlen, attname, attnotnull, attnum, ATTRIBUTE_FIXED_PART_SIZE, attrtypes, boot_reldesc, BOOTCOL_NULL_AUTO, BOOTCOL_NULL_FORCE_NOT_NULL, BOOTCOL_NULL_FORCE_NULL, typinfo::byval, closerel(), typinfo::collation, DEBUG4, elog, gettype(), i, InvalidCompressionMethod, InvalidOid, typinfo::len, MemSet, name, NameStr, namestrcpy(), NIL, typinfo::oid, OidIsValid, typinfo::storage, Typ, type, TypInfo, and WARNING.

◆ index_register()

void index_register ( Oid  heap,
Oid  ind,
const IndexInfo indexInfo 
)

Definition at line 901 of file bootstrap.c.

904 {
905  IndexList *newind;
906  MemoryContext oldcxt;
907 
908  /*
909  * XXX mao 10/31/92 -- don't gc index reldescs, associated info at
910  * bootstrap time. we'll declare the indexes now, but want to create them
911  * later.
912  */
913 
914  if (nogc == NULL)
916  "BootstrapNoGC",
918 
919  oldcxt = MemoryContextSwitchTo(nogc);
920 
921  newind = (IndexList *) palloc(sizeof(IndexList));
922  newind->il_heap = heap;
923  newind->il_ind = ind;
924  newind->il_info = (IndexInfo *) palloc(sizeof(IndexInfo));
925 
926  memcpy(newind->il_info, indexInfo, sizeof(IndexInfo));
927  /* expressions will likely be null, but may as well copy it */
928  newind->il_info->ii_Expressions =
929  copyObject(indexInfo->ii_Expressions);
930  newind->il_info->ii_ExpressionsState = NIL;
931  /* predicate will likely be null, but may as well copy it */
932  newind->il_info->ii_Predicate =
933  copyObject(indexInfo->ii_Predicate);
934  newind->il_info->ii_PredicateState = NULL;
935  /* no exclusion constraints at bootstrap time, so no need to copy */
936  Assert(indexInfo->ii_ExclusionOps == NULL);
937  Assert(indexInfo->ii_ExclusionProcs == NULL);
938  Assert(indexInfo->ii_ExclusionStrats == NULL);
939 
940  newind->il_next = ILHead;
941  ILHead = newind;
942 
943  MemoryContextSwitchTo(oldcxt);
944 }
static MemoryContext nogc
Definition: bootstrap.c:155
void * palloc(Size size)
Definition: mcxt.c:1316
#define AllocSetContextCreate
Definition: memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:160
#define copyObject(obj)
Definition: nodes.h:224
MemoryContextSwitchTo(old_ctx)
uint16 * ii_ExclusionStrats
Definition: execnodes.h:193
ExprState * ii_PredicateState
Definition: execnodes.h:190
Oid * ii_ExclusionOps
Definition: execnodes.h:191
List * ii_ExpressionsState
Definition: execnodes.h:188
List * ii_Expressions
Definition: execnodes.h:187
Oid * ii_ExclusionProcs
Definition: execnodes.h:192
List * ii_Predicate
Definition: execnodes.h:189

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, Assert, copyObject, IndexInfo::ii_ExclusionOps, IndexInfo::ii_ExclusionProcs, IndexInfo::ii_ExclusionStrats, IndexInfo::ii_Expressions, IndexInfo::ii_ExpressionsState, IndexInfo::ii_Predicate, IndexInfo::ii_PredicateState, _IndexList::il_heap, _IndexList::il_ind, _IndexList::il_info, _IndexList::il_next, ILHead, MemoryContextSwitchTo(), NIL, nogc, and palloc().

Referenced by index_create().

◆ InsertOneNull()

void InsertOneNull ( int  i)

Definition at line 664 of file bootstrap.c.

665 {
666  elog(DEBUG4, "inserting column %d NULL", i);
667  Assert(i >= 0 && i < MAXATTR);
668  if (TupleDescAttr(boot_reldesc->rd_att, i)->attnotnull)
669  elog(ERROR,
670  "NULL value specified for not-null column \"%s\" of relation \"%s\"",
673  values[i] = PointerGetDatum(NULL);
674  Nulls[i] = true;
675 }
static Datum values[MAXATTR]
Definition: bootstrap.c:152
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:322

References Assert, boot_reldesc, DEBUG4, elog, ERROR, i, MAXATTR, NameStr, Nulls, PointerGetDatum(), RelationData::rd_att, RelationGetRelationName, TupleDescAttr, and values.

◆ InsertOneTuple()

void InsertOneTuple ( void  )

Definition at line 598 of file bootstrap.c.

599 {
600  HeapTuple tuple;
601  TupleDesc tupDesc;
602  int i;
603 
604  elog(DEBUG4, "inserting row with %d columns", numattr);
605 
606  tupDesc = CreateTupleDesc(numattr, attrtypes);
607  tuple = heap_form_tuple(tupDesc, values, Nulls);
608  pfree(tupDesc); /* just free's tupDesc, not the attrtypes */
609 
611  heap_freetuple(tuple);
612  elog(DEBUG4, "row inserted");
613 
614  /*
615  * Reset null markers for next tuple
616  */
617  for (i = 0; i < numattr; i++)
618  Nulls[i] = false;
619 }
void simple_heap_insert(Relation relation, HeapTuple tup)
Definition: heapam.c:2624
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition: heaptuple.c:1116
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1434
TupleDesc CreateTupleDesc(int natts, Form_pg_attribute *attrs)
Definition: tupdesc.c:112

References attrtypes, boot_reldesc, CreateTupleDesc(), DEBUG4, elog, heap_form_tuple(), heap_freetuple(), i, Nulls, numattr, pfree(), simple_heap_insert(), and values.

◆ InsertOneValue()

void InsertOneValue ( char *  value,
int  i 
)

Definition at line 626 of file bootstrap.c.

627 {
628  Oid typoid;
629  int16 typlen;
630  bool typbyval;
631  char typalign;
632  char typdelim;
633  Oid typioparam;
634  Oid typinput;
635  Oid typoutput;
636 
637  Assert(i >= 0 && i < MAXATTR);
638 
639  elog(DEBUG4, "inserting column %d value \"%s\"", i, value);
640 
641  typoid = TupleDescAttr(boot_reldesc->rd_att, i)->atttypid;
642 
643  boot_get_type_io_data(typoid,
644  &typlen, &typbyval, &typalign,
645  &typdelim, &typioparam,
646  &typinput, &typoutput);
647 
648  values[i] = OidInputFunctionCall(typinput, value, typioparam, -1);
649 
650  /*
651  * We use ereport not elog here so that parameters aren't evaluated unless
652  * the message is going to be printed, which generally it isn't
653  */
654  ereport(DEBUG4,
655  (errmsg_internal("inserted -> %s",
656  OidOutputFunctionCall(typoutput, values[i]))));
657 }
void boot_get_type_io_data(Oid typid, int16 *typlen, bool *typbyval, char *typalign, char *typdelim, Oid *typioparam, Oid *typinput, Oid *typoutput)
Definition: bootstrap.c:806
signed short int16
Definition: c.h:493
int errmsg_internal(const char *fmt,...)
Definition: elog.c:1157
Datum OidInputFunctionCall(Oid functionId, char *str, Oid typioparam, int32 typmod)
Definition: fmgr.c:1754
char * OidOutputFunctionCall(Oid functionId, Datum val)
Definition: fmgr.c:1763

References Assert, boot_get_type_io_data(), boot_reldesc, DEBUG4, elog, ereport, errmsg_internal(), i, MAXATTR, OidInputFunctionCall(), OidOutputFunctionCall(), RelationData::rd_att, TupleDescAttr, typalign, value, and values.

Variable Documentation

◆ attrtypes

Definition at line 61 of file bootstrap.c.

Referenced by boot_openrel(), BootstrapModeMain(), DefineAttr(), and InsertOneTuple().

◆ boot_reldesc

PGDLLIMPORT Relation boot_reldesc
extern

◆ numattr

PGDLLIMPORT int numattr
extern

Definition at line 62 of file bootstrap.c.

Referenced by boot_openrel(), InsertOneTuple(), and tsvector_update_trigger().