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 *name)
 
void boot_openrel (char *name)
 
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, 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 *str) 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 820 of file bootstrap.c.

828 {
829  if (Typ != NIL)
830  {
831  /* We have the boot-time contents of pg_type, so use it */
832  struct typmap *ap = NULL;
833  ListCell *lc;
834 
835  foreach(lc, Typ)
836  {
837  ap = lfirst(lc);
838  if (ap->am_oid == typid)
839  break;
840  }
841 
842  if (!ap || ap->am_oid != typid)
843  elog(ERROR, "type OID %u not found in Typ list", typid);
844 
845  *typlen = ap->am_typ.typlen;
846  *typbyval = ap->am_typ.typbyval;
847  *typalign = ap->am_typ.typalign;
848  *typdelim = ap->am_typ.typdelim;
849 
850  /* XXX this logic must match getTypeIOParam() */
851  if (OidIsValid(ap->am_typ.typelem))
852  *typioparam = ap->am_typ.typelem;
853  else
854  *typioparam = typid;
855 
856  *typinput = ap->am_typ.typinput;
857  *typoutput = ap->am_typ.typoutput;
858  }
859  else
860  {
861  /* We don't have pg_type yet, so use the hard-wired TypInfo array */
862  int typeindex;
863 
864  for (typeindex = 0; typeindex < n_types; typeindex++)
865  {
866  if (TypInfo[typeindex].oid == typid)
867  break;
868  }
869  if (typeindex >= n_types)
870  elog(ERROR, "type OID %u not found in TypInfo", typid);
871 
872  *typlen = TypInfo[typeindex].len;
873  *typbyval = TypInfo[typeindex].byval;
874  *typalign = TypInfo[typeindex].align;
875  /* We assume typdelim is ',' for all boot-time types */
876  *typdelim = ',';
877 
878  /* XXX this logic must match getTypeIOParam() */
879  if (OidIsValid(TypInfo[typeindex].elem))
880  *typioparam = TypInfo[typeindex].elem;
881  else
882  *typioparam = typid;
883 
884  *typinput = TypInfo[typeindex].inproc;
885  *typoutput = TypInfo[typeindex].outproc;
886  }
887 }
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:721
#define ERROR
Definition: elog.h:33
#define lfirst(lc)
Definition: pg_list.h:170
#define NIL
Definition: pg_list.h:66
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 *  name)

Definition at line 421 of file bootstrap.c.

422 {
423  int i;
424 
425  if (strlen(relname) >= NAMEDATALEN)
426  relname[NAMEDATALEN - 1] = '\0';
427 
428  /*
429  * pg_type must be filled before any OPEN command is executed, hence we
430  * can now populate Typ if we haven't yet.
431  */
432  if (Typ == NIL)
434 
435  if (boot_reldesc != NULL)
436  closerel(NULL);
437 
438  elog(DEBUG4, "open relation %s, attrsize %d",
440 
443  for (i = 0; i < numattr; i++)
444  {
445  if (attrtypes[i] == NULL)
447  memmove((char *) attrtypes[i],
448  (char *) TupleDescAttr(boot_reldesc->rd_att, i),
450 
451  {
453 
454  elog(DEBUG4, "create attribute %d name %s len %d num %d type %u",
455  i, NameStr(at->attname), at->attlen, at->attnum,
456  at->atttypid);
457  }
458  }
459 }
void closerel(char *name)
Definition: bootstrap.c:466
static void populate_typ_list(void)
Definition: bootstrap.c:709
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:897
#define NameStr(name)
Definition: c.h:692
#define DEBUG4
Definition: elog.h:21
int i
Definition: isn.c:73
#define NoLock
Definition: lockdefs.h:34
RangeVar * makeRangeVar(char *schemaname, char *relname, int location)
Definition: makefuncs.c:423
#define ATTRIBUTE_FIXED_PART_SIZE
Definition: pg_attribute.h:199
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:207
NameData relname
Definition: pg_class.h:38
#define NAMEDATALEN
#define RelationGetNumberOfAttributes(relation)
Definition: rel.h:494
TupleDesc rd_att
Definition: rel.h:110
Relation table_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: table.c:102
#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 *  str)

◆ 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 'D':
233  break;
234  case 'd':
235  {
236  /* Turn on debugging for the bootstrap process. */
237  char *debugstr;
238 
239  debugstr = psprintf("debug%s", optarg);
240  SetConfigOption("log_min_messages", debugstr,
242  SetConfigOption("client_min_messages", debugstr,
244  pfree(debugstr);
245  }
246  break;
247  case 'F':
248  SetConfigOption("fsync", "false", PGC_POSTMASTER, PGC_S_ARGV);
249  break;
250  case 'k':
252  break;
253  case 'r':
255  break;
256  case 'X':
257  {
258  int WalSegSz = strtoul(optarg, NULL, 0);
259 
261  ereport(ERROR,
262  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
263  errmsg("-X requires a power of two value between 1 MB and 1 GB")));
264  SetConfigOption("wal_segment_size", optarg, PGC_INTERNAL,
266  }
267  break;
268  case 'c':
269  case '-':
270  {
271  char *name,
272  *value;
273 
275  if (!value)
276  {
277  if (flag == '-')
278  ereport(ERROR,
279  (errcode(ERRCODE_SYNTAX_ERROR),
280  errmsg("--%s requires a value",
281  optarg)));
282  else
283  ereport(ERROR,
284  (errcode(ERRCODE_SYNTAX_ERROR),
285  errmsg("-c %s requires a value",
286  optarg)));
287  }
288 
290  free(name);
291  free(value);
292  break;
293  }
294  default:
295  write_stderr("Try \"%s --help\" for more information.\n",
296  progname);
297  proc_exit(1);
298  break;
299  }
300  }
301 
302  if (argc != optind)
303  {
304  write_stderr("%s: invalid command-line arguments\n", progname);
305  proc_exit(1);
306  }
307 
308  /* Acquire configuration parameters */
310  proc_exit(1);
311 
312  /*
313  * Validate we have been given a reasonable-looking DataDir and change
314  * into it
315  */
316  checkDataDir();
317  ChangeToDataDir();
318 
319  CreateDataDirLockFile(false);
320 
322  IgnoreSystemIndexes = true;
323 
325 
327 
328  /*
329  * XXX: It might make sense to move this into its own function at some
330  * point. Right now it seems like it'd cause more code duplication than
331  * it's worth.
332  */
333  if (check_only)
334  {
336  CheckerModeMain();
337  abort();
338  }
339 
340  /*
341  * Do backend-like initialization for bootstrap mode
342  */
343  InitProcess();
344 
345  BaseInit();
346 
348  BootStrapXLOG();
349 
350  /*
351  * To ensure that src/common/link-canary.c is linked into the backend, we
352  * must call it from somewhere. Here is as good as anywhere.
353  */
355  elog(ERROR, "backend is incorrectly linked to frontend functions");
356 
357  InitPostgres(NULL, InvalidOid, NULL, InvalidOid, NULL, false);
358 
359  /* Initialize stuff for bootstrap-file processing */
360  for (i = 0; i < MAXATTR; i++)
361  {
362  attrtypes[i] = NULL;
363  Nulls[i] = false;
364  }
365 
366  /*
367  * Process bootstrap input.
368  */
370  boot_yyparse();
372 
373  /*
374  * We should now know about all mapped relations, so it's okay to write
375  * out the initial relation mapping files.
376  */
378 
379  /* Clean up and exit */
380  cleanup();
381  proc_exit(0);
382 }
#define write_stderr(str)
Definition: parallel.c:186
static void CheckerModeMain(void)
Definition: bootstrap.c:185
static void cleanup(void)
Definition: bootstrap.c:696
static void bootstrap_signals(void)
Definition: bootstrap.c:394
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:199
int errcode(int sqlerrcode)
Definition: elog.c:693
int errmsg(const char *fmt,...)
Definition: elog.c:904
#define ereport(elevel,...)
Definition: elog.h:143
const char * name
Definition: encode.c:561
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:8373
bool SelectConfigFiles(const char *userDoption, const char *progname)
Definition: guc.c:6096
void ParseLongOption(const char *string, char **name, char **value)
Definition: guc.c:11333
void InitializeGUCOptions(void)
Definition: guc.c:5835
@ PGC_S_DYNAMIC_DEFAULT
Definition: guc.h:111
@ PGC_S_ARGV
Definition: guc.h:114
@ PGC_INTERNAL
Definition: guc.h:70
@ PGC_POSTMASTER
Definition: guc.h:71
#define free(a)
Definition: header.h:65
static struct @151 value
void proc_exit(int code)
Definition: ipc.c:104
void CreateSharedMemoryAndSemaphores(void)
Definition: ipci.c:173
Assert(fmt[strlen(fmt) - 1] !='\n')
const char * progname
Definition: main.c:50
char * pstrdup(const char *in)
Definition: mcxt.c:1305
void pfree(void *pointer)
Definition: mcxt.c:1175
@ NormalProcessing
Definition: miscadmin.h:401
@ BootstrapProcessing
Definition: miscadmin.h:399
#define SetProcessingMode(mode)
Definition: miscadmin.h:412
void ChangeToDataDir(void)
Definition: miscinit.c:431
void InitStandaloneProcess(const char *argv0)
Definition: miscinit.c:175
bool IgnoreSystemIndexes
Definition: miscinit.c:80
void checkDataDir(void)
Definition: miscinit.c:318
void CreateDataDirLockFile(bool amPostmaster)
Definition: miscinit.c:1294
#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:170
#define InvalidOid
Definition: postgres_ext.h:36
void InitializeMaxBackends(void)
Definition: postinit.c:551
void BaseInit(void)
Definition: postinit.c:573
void InitPostgres(const char *in_dbname, Oid dboid, const char *username, Oid useroid, char *out_dbname, bool override_allow_connections)
Definition: postinit.c:646
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
void RelationMapFinishBootstrap(void)
Definition: relmapper.c:619
void InitProcess(void)
Definition: proc.c:301
uint32 WalSegSz
Definition: streamutil.c:34
char * flag(int b)
Definition: test-ctype.c:33
void StartTransactionCommand(void)
Definition: xact.c:2925
void CommitTransactionCommand(void)
Definition: xact.c:3022
void BootStrapXLOG(void)
Definition: xlog.c:4493
#define IsValidWalSegSize(size)
Definition: xlog_internal.h:96

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(), free, getopt(), i, IgnoreSystemIndexes, InitializeGUCOptions(), InitializeMaxBackends(), InitPostgres(), InitProcess(), InitStandaloneProcess(), InvalidOid, IsUnderPostmaster, IsValidWalSegSize, 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, WalSegSz, and write_stderr.

Referenced by main().

◆ build_indices()

void build_indices ( void  )

Definition at line 965 of file bootstrap.c.

966 {
967  for (; ILHead != NULL; ILHead = ILHead->il_next)
968  {
969  Relation heap;
970  Relation ind;
971 
972  /* need not bother with locks during bootstrap */
973  heap = table_open(ILHead->il_heap, NoLock);
975 
976  index_build(heap, ind, ILHead->il_info, false, false);
977 
979  table_close(heap, NoLock);
980  }
981 }
static IndexList * ILHead
Definition: bootstrap.c:175
void index_build(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, bool isreindex, bool parallel)
Definition: index.c:2943
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:167
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39

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 *  name)

Definition at line 466 of file bootstrap.c.

467 {
468  if (name)
469  {
470  if (boot_reldesc)
471  {
472  if (strcmp(RelationGetRelationName(boot_reldesc), name) != 0)
473  elog(ERROR, "close of %s when %s was expected",
475  }
476  else
477  elog(ERROR, "close of %s before any relation was opened",
478  name);
479  }
480 
481  if (boot_reldesc == NULL)
482  elog(ERROR, "no open relation to close");
483  else
484  {
485  elog(DEBUG4, "close relation %s",
488  boot_reldesc = NULL;
489  }
490 }
#define RelationGetRelationName(relation)
Definition: rel.h:522

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

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

◆ DefineAttr()

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

Definition at line 503 of file bootstrap.c.

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

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, generate_unaccent_rules::type, TypInfo, and WARNING.

◆ index_register()

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

Definition at line 915 of file bootstrap.c.

918 {
919  IndexList *newind;
920  MemoryContext oldcxt;
921 
922  /*
923  * XXX mao 10/31/92 -- don't gc index reldescs, associated info at
924  * bootstrap time. we'll declare the indexes now, but want to create them
925  * later.
926  */
927 
928  if (nogc == NULL)
930  "BootstrapNoGC",
932 
933  oldcxt = MemoryContextSwitchTo(nogc);
934 
935  newind = (IndexList *) palloc(sizeof(IndexList));
936  newind->il_heap = heap;
937  newind->il_ind = ind;
938  newind->il_info = (IndexInfo *) palloc(sizeof(IndexInfo));
939 
940  memcpy(newind->il_info, indexInfo, sizeof(IndexInfo));
941  /* expressions will likely be null, but may as well copy it */
942  newind->il_info->ii_Expressions =
943  copyObject(indexInfo->ii_Expressions);
944  newind->il_info->ii_ExpressionsState = NIL;
945  /* predicate will likely be null, but may as well copy it */
946  newind->il_info->ii_Predicate =
947  copyObject(indexInfo->ii_Predicate);
948  newind->il_info->ii_PredicateState = NULL;
949  /* no exclusion constraints at bootstrap time, so no need to copy */
950  Assert(indexInfo->ii_ExclusionOps == NULL);
951  Assert(indexInfo->ii_ExclusionProcs == NULL);
952  Assert(indexInfo->ii_ExclusionStrats == NULL);
953 
954  newind->il_next = ILHead;
955  ILHead = newind;
956 
957  MemoryContextSwitchTo(oldcxt);
958 }
static MemoryContext nogc
Definition: bootstrap.c:159
void * palloc(Size size)
Definition: mcxt.c:1068
#define AllocSetContextCreate
Definition: memutils.h:173
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:197
#define copyObject(obj)
Definition: nodes.h:690
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
uint16 * ii_ExclusionStrats
Definition: execnodes.h:170
ExprState * ii_PredicateState
Definition: execnodes.h:167
Oid * ii_ExclusionOps
Definition: execnodes.h:168
List * ii_ExpressionsState
Definition: execnodes.h:165
List * ii_Expressions
Definition: execnodes.h:164
Oid * ii_ExclusionProcs
Definition: execnodes.h:169
List * ii_Predicate
Definition: execnodes.h:166

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

679 {
680  elog(DEBUG4, "inserting column %d NULL", i);
681  Assert(i >= 0 && i < MAXATTR);
682  if (TupleDescAttr(boot_reldesc->rd_att, i)->attnotnull)
683  elog(ERROR,
684  "NULL value specified for not-null column \"%s\" of relation \"%s\"",
687  values[i] = PointerGetDatum(NULL);
688  Nulls[i] = true;
689 }
static Datum values[MAXATTR]
Definition: bootstrap.c:156
#define PointerGetDatum(X)
Definition: postgres.h:600

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

613 {
614  HeapTuple tuple;
615  TupleDesc tupDesc;
616  int i;
617 
618  elog(DEBUG4, "inserting row with %d columns", numattr);
619 
620  tupDesc = CreateTupleDesc(numattr, attrtypes);
621  tuple = heap_form_tuple(tupDesc, values, Nulls);
622  pfree(tupDesc); /* just free's tupDesc, not the attrtypes */
623 
625  heap_freetuple(tuple);
626  elog(DEBUG4, "row inserted");
627 
628  /*
629  * Reset null markers for next tuple
630  */
631  for (i = 0; i < numattr; i++)
632  Nulls[i] = false;
633 }
void simple_heap_insert(Relation relation, HeapTuple tup)
Definition: heapam.c:2608
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1338
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 640 of file bootstrap.c.

641 {
642  Oid typoid;
643  int16 typlen;
644  bool typbyval;
645  char typalign;
646  char typdelim;
647  Oid typioparam;
648  Oid typinput;
649  Oid typoutput;
650 
651  AssertArg(i >= 0 && i < MAXATTR);
652 
653  elog(DEBUG4, "inserting column %d value \"%s\"", i, value);
654 
655  typoid = TupleDescAttr(boot_reldesc->rd_att, i)->atttypid;
656 
657  boot_get_type_io_data(typoid,
658  &typlen, &typbyval, &typalign,
659  &typdelim, &typioparam,
660  &typinput, &typoutput);
661 
662  values[i] = OidInputFunctionCall(typinput, value, typioparam, -1);
663 
664  /*
665  * We use ereport not elog here so that parameters aren't evaluated unless
666  * the message is going to be printed, which generally it isn't
667  */
668  ereport(DEBUG4,
669  (errmsg_internal("inserted -> %s",
670  OidOutputFunctionCall(typoutput, values[i]))));
671 }
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:820
signed short int16
Definition: c.h:439
#define AssertArg(condition)
Definition: c.h:817
int errmsg_internal(const char *fmt,...)
Definition: elog.c:991
Datum OidInputFunctionCall(Oid functionId, char *str, Oid typioparam, int32 typmod)
Definition: fmgr.c:1630
char * OidOutputFunctionCall(Oid functionId, Datum val)
Definition: fmgr.c:1639

References AssertArg, 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().