PostgreSQL Source Code  git master
bootstrap.h File Reference
#include "nodes/execnodes.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 26 of file bootstrap.h.

◆ BOOTCOL_NULL_FORCE_NOT_NULL

#define BOOTCOL_NULL_FORCE_NOT_NULL   3

Definition at line 28 of file bootstrap.h.

◆ BOOTCOL_NULL_FORCE_NULL

#define BOOTCOL_NULL_FORCE_NULL   2

Definition at line 27 of file bootstrap.h.

◆ MAXATTR

#define MAXATTR   40

Definition at line 24 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 811 of file bootstrap.c.

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

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 412 of file bootstrap.c.

413 {
414  int i;
415 
416  if (strlen(relname) >= NAMEDATALEN)
417  relname[NAMEDATALEN - 1] = '\0';
418 
419  /*
420  * pg_type must be filled before any OPEN command is executed, hence we
421  * can now populate Typ if we haven't yet.
422  */
423  if (Typ == NIL)
425 
426  if (boot_reldesc != NULL)
427  closerel(NULL);
428 
429  elog(DEBUG4, "open relation %s, attrsize %d",
431 
434  for (i = 0; i < numattr; i++)
435  {
436  if (attrtypes[i] == NULL)
438  memmove((char *) attrtypes[i],
439  (char *) TupleDescAttr(boot_reldesc->rd_att, i),
441 
442  {
444 
445  elog(DEBUG4, "create attribute %d name %s len %d num %d type %u",
446  i, NameStr(at->attname), at->attlen, at->attnum,
447  at->atttypid);
448  }
449  }
450 }
void closerel(char *relname)
Definition: bootstrap.c:457
static void populate_typ_list(void)
Definition: bootstrap.c:700
Relation boot_reldesc
Definition: bootstrap.c:63
Form_pg_attribute attrtypes[MAXATTR]
Definition: bootstrap.c:65
int numattr
Definition: bootstrap.c:66
static Form_pg_attribute AllocateAttribute(void)
Definition: bootstrap.c:888
#define NameStr(name)
Definition: c.h:735
#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:425
#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:510
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 203 of file bootstrap.c.

204 {
205  int i;
206  char *progname = argv[0];
207  int flag;
208  char *userDoption = NULL;
209 
211 
212  InitStandaloneProcess(argv[0]);
213 
214  /* Set defaults, to be overridden by explicit options below */
216 
217  /* an initial --boot or --check should be present */
218  Assert(argc > 1
219  && (strcmp(argv[1], "--boot") == 0
220  || strcmp(argv[1], "--check") == 0));
221  argv++;
222  argc--;
223 
224  while ((flag = getopt(argc, argv, "B:c:d:D:Fkr:X:-:")) != -1)
225  {
226  switch (flag)
227  {
228  case 'B':
229  SetConfigOption("shared_buffers", optarg, PGC_POSTMASTER, PGC_S_ARGV);
230  break;
231  case 'c':
232  case '-':
233  {
234  char *name,
235  *value;
236 
238  if (!value)
239  {
240  if (flag == '-')
241  ereport(ERROR,
242  (errcode(ERRCODE_SYNTAX_ERROR),
243  errmsg("--%s requires a value",
244  optarg)));
245  else
246  ereport(ERROR,
247  (errcode(ERRCODE_SYNTAX_ERROR),
248  errmsg("-c %s requires a value",
249  optarg)));
250  }
251 
253  pfree(name);
254  pfree(value);
255  break;
256  }
257  case 'D':
259  break;
260  case 'd':
261  {
262  /* Turn on debugging for the bootstrap process. */
263  char *debugstr;
264 
265  debugstr = psprintf("debug%s", optarg);
266  SetConfigOption("log_min_messages", debugstr,
268  SetConfigOption("client_min_messages", debugstr,
270  pfree(debugstr);
271  }
272  break;
273  case 'F':
274  SetConfigOption("fsync", "false", PGC_POSTMASTER, PGC_S_ARGV);
275  break;
276  case 'k':
278  break;
279  case 'r':
281  break;
282  case 'X':
284  break;
285  default:
286  write_stderr("Try \"%s --help\" for more information.\n",
287  progname);
288  proc_exit(1);
289  break;
290  }
291  }
292 
293  if (argc != optind)
294  {
295  write_stderr("%s: invalid command-line arguments\n", progname);
296  proc_exit(1);
297  }
298 
299  /* Acquire configuration parameters */
301  proc_exit(1);
302 
303  /*
304  * Validate we have been given a reasonable-looking DataDir and change
305  * into it
306  */
307  checkDataDir();
308  ChangeToDataDir();
309 
310  CreateDataDirLockFile(false);
311 
313  IgnoreSystemIndexes = true;
314 
316 
318 
319  /*
320  * XXX: It might make sense to move this into its own function at some
321  * point. Right now it seems like it'd cause more code duplication than
322  * it's worth.
323  */
324  if (check_only)
325  {
327  CheckerModeMain();
328  abort();
329  }
330 
331  /*
332  * Do backend-like initialization for bootstrap mode
333  */
334  InitProcess();
335 
336  BaseInit();
337 
339  BootStrapXLOG();
340 
341  /*
342  * To ensure that src/common/link-canary.c is linked into the backend, we
343  * must call it from somewhere. Here is as good as anywhere.
344  */
346  elog(ERROR, "backend is incorrectly linked to frontend functions");
347 
348  InitPostgres(NULL, InvalidOid, NULL, InvalidOid, false, false, NULL);
349 
350  /* Initialize stuff for bootstrap-file processing */
351  for (i = 0; i < MAXATTR; i++)
352  {
353  attrtypes[i] = NULL;
354  Nulls[i] = false;
355  }
356 
357  /*
358  * Process bootstrap input.
359  */
361  boot_yyparse();
363 
364  /*
365  * We should now know about all mapped relations, so it's okay to write
366  * out the initial relation mapping files.
367  */
369 
370  /* Clean up and exit */
371  cleanup();
372  proc_exit(0);
373 }
#define write_stderr(str)
Definition: parallel.c:184
static void CheckerModeMain(void)
Definition: bootstrap.c:185
static void cleanup(void)
Definition: bootstrap.c:687
static void bootstrap_signals(void)
Definition: bootstrap.c:385
uint32 bootstrap_data_checksum_version
Definition: bootstrap.c:48
static bool Nulls[MAXATTR]
Definition: bootstrap.c:157
#define MAXATTR
Definition: bootstrap.h:24
int boot_yyparse(void)
#define PG_DATA_CHECKSUM_VERSION
Definition: bufpage.h:203
int errcode(int sqlerrcode)
Definition: elog.c:858
int errmsg(const char *fmt,...)
Definition: elog.c:1069
#define ereport(elevel,...)
Definition: elog.h:149
bool IsUnderPostmaster
Definition: globals.c:113
char OutputFileName[MAXPGPATH]
Definition: globals.c:74
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:4176
bool SelectConfigFiles(const char *userDoption, const char *progname)
Definition: guc.c:1749
void ParseLongOption(const char *string, char **name, char **value)
Definition: guc.c:6186
void InitializeGUCOptions(void)
Definition: guc.c:1495
@ 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 @148 value
void proc_exit(int code)
Definition: ipc.c:104
void CreateSharedMemoryAndSemaphores(void)
Definition: ipci.c:175
Assert(fmt[strlen(fmt) - 1] !='\n')
const char * progname
Definition: main.c:45
char * pstrdup(const char *in)
Definition: mcxt.c:1644
void pfree(void *pointer)
Definition: mcxt.c:1456
@ NormalProcessing
Definition: miscadmin.h:409
@ BootstrapProcessing
Definition: miscadmin.h:407
#define SetProcessingMode(mode)
Definition: miscadmin.h:420
void ChangeToDataDir(void)
Definition: miscinit.c:449
void InitStandaloneProcess(const char *argv0)
Definition: miscinit.c:182
bool IgnoreSystemIndexes
Definition: miscinit.c:80
void checkDataDir(void)
Definition: miscinit.c:336
void CreateDataDirLockFile(bool amPostmaster)
Definition: miscinit.c:1441
#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:159
#define InvalidOid
Definition: postgres_ext.h:36
void InitializeMaxBackends(void)
Definition: postinit.c:559
void BaseInit(void)
Definition: postinit.c:629
void InitPostgres(const char *in_dbname, Oid dboid, const char *username, Oid useroid, bool load_session_libraries, bool override_allow_connections, char *out_dbname)
Definition: postinit.c:718
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
void RelationMapFinishBootstrap(void)
Definition: relmapper.c:625
void InitProcess(void)
Definition: proc.c:297
char * flag(int b)
Definition: test-ctype.c:33
const char * name
void StartTransactionCommand(void)
Definition: xact.c:2937
void CommitTransactionCommand(void)
Definition: xact.c:3034
void BootStrapXLOG(void)
Definition: xlog.c:4669

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 956 of file bootstrap.c.

957 {
958  for (; ILHead != NULL; ILHead = ILHead->il_next)
959  {
960  Relation heap;
961  Relation ind;
962 
963  /* need not bother with locks during bootstrap */
964  heap = table_open(ILHead->il_heap, NoLock);
966 
967  index_build(heap, ind, ILHead->il_info, false, false);
968 
970  table_close(heap, NoLock);
971  }
972 }
static IndexList * ILHead
Definition: bootstrap.c:175
void index_build(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, bool isreindex, bool parallel)
Definition: index.c:2962
void index_close(Relation relation, LOCKMODE lockmode)
Definition: indexam.c:158
Relation index_open(Oid relationId, LOCKMODE lockmode)
Definition: indexam.c:132
Oid il_heap
Definition: bootstrap.c:169
struct _IndexList * il_next
Definition: bootstrap.c:172
Oid il_ind
Definition: bootstrap.c:170
IndexInfo * il_info
Definition: bootstrap.c:171
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 457 of file bootstrap.c.

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

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 494 of file bootstrap.c.

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

909 {
910  IndexList *newind;
911  MemoryContext oldcxt;
912 
913  /*
914  * XXX mao 10/31/92 -- don't gc index reldescs, associated info at
915  * bootstrap time. we'll declare the indexes now, but want to create them
916  * later.
917  */
918 
919  if (nogc == NULL)
921  "BootstrapNoGC",
923 
924  oldcxt = MemoryContextSwitchTo(nogc);
925 
926  newind = (IndexList *) palloc(sizeof(IndexList));
927  newind->il_heap = heap;
928  newind->il_ind = ind;
929  newind->il_info = (IndexInfo *) palloc(sizeof(IndexInfo));
930 
931  memcpy(newind->il_info, indexInfo, sizeof(IndexInfo));
932  /* expressions will likely be null, but may as well copy it */
933  newind->il_info->ii_Expressions =
934  copyObject(indexInfo->ii_Expressions);
935  newind->il_info->ii_ExpressionsState = NIL;
936  /* predicate will likely be null, but may as well copy it */
937  newind->il_info->ii_Predicate =
938  copyObject(indexInfo->ii_Predicate);
939  newind->il_info->ii_PredicateState = NULL;
940  /* no exclusion constraints at bootstrap time, so no need to copy */
941  Assert(indexInfo->ii_ExclusionOps == NULL);
942  Assert(indexInfo->ii_ExclusionProcs == NULL);
943  Assert(indexInfo->ii_ExclusionStrats == NULL);
944 
945  newind->il_next = ILHead;
946  ILHead = newind;
947 
948  MemoryContextSwitchTo(oldcxt);
949 }
static MemoryContext nogc
Definition: bootstrap.c:159
void * palloc(Size size)
Definition: mcxt.c:1226
#define AllocSetContextCreate
Definition: memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:153
#define copyObject(obj)
Definition: nodes.h:244
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:138
uint16 * ii_ExclusionStrats
Definition: execnodes.h:186
ExprState * ii_PredicateState
Definition: execnodes.h:183
Oid * ii_ExclusionOps
Definition: execnodes.h:184
List * ii_ExpressionsState
Definition: execnodes.h:181
List * ii_Expressions
Definition: execnodes.h:180
Oid * ii_ExclusionProcs
Definition: execnodes.h:185
List * ii_Predicate
Definition: execnodes.h:182

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 669 of file bootstrap.c.

670 {
671  elog(DEBUG4, "inserting column %d NULL", i);
672  Assert(i >= 0 && i < MAXATTR);
673  if (TupleDescAttr(boot_reldesc->rd_att, i)->attnotnull)
674  elog(ERROR,
675  "NULL value specified for not-null column \"%s\" of relation \"%s\"",
678  values[i] = PointerGetDatum(NULL);
679  Nulls[i] = true;
680 }
static Datum values[MAXATTR]
Definition: bootstrap.c:156
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 603 of file bootstrap.c.

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

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 631 of file bootstrap.c.

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

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 65 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 66 of file bootstrap.c.

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