PostgreSQL Source Code git master
Loading...
Searching...
No Matches
bootstrap.h File Reference
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
 

Typedefs

typedef voidyyscan_t
 

Functions

pg_noreturn void BootstrapModeMain (int argc, char *argv[], bool check_only)
 
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, Oid *typcollation)
 
Oid boot_get_role_oid (const char *rolname)
 
int boot_yyparse (yyscan_t yyscanner)
 
int boot_yylex_init (yyscan_t *yyscannerp)
 
int boot_yylex (union YYSTYPE *yylval_param, yyscan_t yyscanner)
 
pg_noreturn void boot_yyerror (yyscan_t yyscanner, const char *message)
 

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 28 of file bootstrap.h.

◆ BOOTCOL_NULL_FORCE_NOT_NULL

#define BOOTCOL_NULL_FORCE_NOT_NULL   3

Definition at line 30 of file bootstrap.h.

◆ BOOTCOL_NULL_FORCE_NULL

#define BOOTCOL_NULL_FORCE_NULL   2

Definition at line 29 of file bootstrap.h.

◆ MAXATTR

#define MAXATTR   40

Definition at line 26 of file bootstrap.h.

Typedef Documentation

◆ yyscan_t

Definition at line 63 of file bootstrap.h.

Function Documentation

◆ boot_get_role_oid()

Oid boot_get_role_oid ( const char rolname)
extern

Definition at line 1087 of file bootstrap.c.

1088{
1089 for (int i = 0; i < lengthof(RolInfo); i++)
1090 {
1091 if (strcmp(RolInfo[i].rolname, rolname) == 0)
1092 return RolInfo[i].oid;
1093 }
1094 return InvalidOid;
1095}
static const struct rolinfo RolInfo[]
Definition bootstrap.c:167
#define lengthof(array)
Definition c.h:875
int i
Definition isn.c:77
NameData rolname
Definition pg_authid.h:36
#define InvalidOid
static int fb(int x)

References fb(), i, InvalidOid, lengthof, RolInfo, and rolname.

Referenced by aclparse().

◆ 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,
Oid typcollation 
)
extern

Definition at line 1004 of file bootstrap.c.

1013{
1014 if (Typ != NIL)
1015 {
1016 /* We have the boot-time contents of pg_type, so use it */
1017 struct typmap *ap = NULL;
1018 ListCell *lc;
1019
1020 foreach(lc, Typ)
1021 {
1022 ap = lfirst(lc);
1023 if (ap->am_oid == typid)
1024 break;
1025 }
1026
1027 if (!ap || ap->am_oid != typid)
1028 elog(ERROR, "type OID %u not found in Typ list", typid);
1029
1030 *typlen = ap->am_typ.typlen;
1031 *typbyval = ap->am_typ.typbyval;
1032 *typalign = ap->am_typ.typalign;
1033 *typdelim = ap->am_typ.typdelim;
1034
1035 /* XXX this logic must match getTypeIOParam() */
1036 if (OidIsValid(ap->am_typ.typelem))
1037 *typioparam = ap->am_typ.typelem;
1038 else
1039 *typioparam = typid;
1040
1041 *typinput = ap->am_typ.typinput;
1042 *typoutput = ap->am_typ.typoutput;
1043
1044 *typcollation = ap->am_typ.typcollation;
1045 }
1046 else
1047 {
1048 /* We don't have pg_type yet, so use the hard-wired TypInfo array */
1049 int typeindex;
1050
1051 for (typeindex = 0; typeindex < n_types; typeindex++)
1052 {
1053 if (TypInfo[typeindex].oid == typid)
1054 break;
1055 }
1056 if (typeindex >= n_types)
1057 elog(ERROR, "type OID %u not found in TypInfo", typid);
1058
1059 *typlen = TypInfo[typeindex].len;
1060 *typbyval = TypInfo[typeindex].byval;
1062 /* We assume typdelim is ',' for all boot-time types */
1063 *typdelim = ',';
1064
1065 /* XXX this logic must match getTypeIOParam() */
1066 if (OidIsValid(TypInfo[typeindex].elem))
1067 *typioparam = TypInfo[typeindex].elem;
1068 else
1069 *typioparam = typid;
1070
1072 *typoutput = TypInfo[typeindex].outproc;
1073
1074 *typcollation = TypInfo[typeindex].collation;
1075 }
1076}
static const int n_types
Definition bootstrap.c:140
static const struct typinfo TypInfo[]
Definition bootstrap.c:91
static List * Typ
Definition bootstrap.c:148
#define OidIsValid(objectId)
Definition c.h:860
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
#define lfirst(lc)
Definition pg_list.h:172
#define NIL
Definition pg_list.h:68
char typalign
Definition pg_type.h:178
char align
Definition bootstrap.c:84
Oid outproc
Definition bootstrap.c:88
int16 len
Definition bootstrap.c:82
bool byval
Definition bootstrap.c:83
Oid collation
Definition bootstrap.c:86
Oid elem
Definition bootstrap.c:81
Oid inproc
Definition bootstrap.c:87

References typinfo::align, typinfo::byval, typinfo::collation, typinfo::elem, elog, ERROR, fb(), typinfo::inproc, typinfo::len, lfirst, n_types, NIL, OidIsValid, typinfo::outproc, Typ, typalign, and TypInfo.

Referenced by get_type_io_data(), InsertOneProargdefaultsValue(), and InsertOneValue().

◆ boot_openrel()

void boot_openrel ( char relname)
extern

Definition at line 477 of file bootstrap.c.

478{
479 int i;
480
481 if (strlen(relname) >= NAMEDATALEN)
482 relname[NAMEDATALEN - 1] = '\0';
483
484 /*
485 * pg_type must be filled before any OPEN command is executed, hence we
486 * can now populate Typ if we haven't yet.
487 */
488 if (Typ == NIL)
490
491 if (boot_reldesc != NULL)
492 closerel(NULL);
493
494 elog(DEBUG4, "open relation %s, attrsize %d",
496
499 for (i = 0; i < numattr; i++)
500 {
501 if (attrtypes[i] == NULL)
506
507 {
509
510 elog(DEBUG4, "create attribute %d name %s len %d num %d type %u",
511 i, NameStr(at->attname), at->attlen, at->attnum,
512 at->atttypid);
513 }
514 }
515}
void closerel(char *relname)
Definition bootstrap.c:522
static void populate_typ_list(void)
Definition bootstrap.c:892
Relation boot_reldesc
Definition bootstrap.c:62
Form_pg_attribute attrtypes[MAXATTR]
Definition bootstrap.c:64
int numattr
Definition bootstrap.c:65
static Form_pg_attribute AllocateAttribute(void)
Definition bootstrap.c:1105
#define NameStr(name)
Definition c.h:837
#define DEBUG4
Definition elog.h:27
#define NoLock
Definition lockdefs.h:34
RangeVar * makeRangeVar(char *schemaname, char *relname, int location)
Definition makefuncs.c:473
#define ATTRIBUTE_FIXED_PART_SIZE
FormData_pg_attribute * Form_pg_attribute
NameData relname
Definition pg_class.h:40
#define NAMEDATALEN
#define RelationGetNumberOfAttributes(relation)
Definition rel.h:520
TupleDesc rd_att
Definition rel.h:112
Relation table_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition table.c:83
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
Definition tupdesc.h:178

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

◆ boot_yyerror()

pg_noreturn void boot_yyerror ( yyscan_t  yyscanner,
const char message 
)
extern

Definition at line 132 of file bootscanner.l.

133{
134 struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; /* needed for yylineno
135 * macro */
136
137 elog(ERROR, "%s at line %d", message, yylineno);
138}

References elog, ERROR, and fb().

◆ boot_yylex()

int boot_yylex ( union YYSTYPE yylval_param,
yyscan_t  yyscanner 
)
extern

◆ boot_yylex_init()

int boot_yylex_init ( yyscan_t yyscannerp)
extern

Referenced by BootstrapModeMain().

◆ boot_yyparse()

int boot_yyparse ( yyscan_t  yyscanner)
extern

Referenced by BootstrapModeMain().

◆ BootstrapModeMain()

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

Definition at line 235 of file bootstrap.c.

236{
237 int i;
238 char *progname = argv[0];
239 int flag;
240 char *userDoption = NULL;
241 uint32 bootstrap_data_checksum_version = 0; /* No checksum */
242 yyscan_t scanner;
243
245
246 InitStandaloneProcess(argv[0]);
247
248 /* Set defaults, to be overridden by explicit options below */
250
251 /* an initial --boot or --check should be present */
252 Assert(argc > 1
253 && (strcmp(argv[1], "--boot") == 0
254 || strcmp(argv[1], "--check") == 0));
255 argv++;
256 argc--;
257
258 while ((flag = getopt(argc, argv, "B:c:d:D:Fkr:X:-:")) != -1)
259 {
260 switch (flag)
261 {
262 case 'B':
263 SetConfigOption("shared_buffers", optarg, PGC_POSTMASTER, PGC_S_ARGV);
264 break;
265 case '-':
266
267 /*
268 * Error if the user misplaced a special must-be-first option
269 * for dispatching to a subprogram. parse_dispatch_option()
270 * returns DISPATCH_POSTMASTER if it doesn't find a match, so
271 * error for anything else.
272 */
276 errmsg("--%s must be first argument", optarg)));
277
279 case 'c':
280 {
281 char *name,
282 *value;
283
285 if (!value)
286 {
287 if (flag == '-')
290 errmsg("--%s requires a value",
291 optarg)));
292 else
295 errmsg("-c %s requires a value",
296 optarg)));
297 }
298
300 pfree(name);
301 pfree(value);
302 break;
303 }
304 case 'D':
306 break;
307 case 'd':
308 {
309 /* Turn on debugging for the bootstrap process. */
310 char *debugstr;
311
312 debugstr = psprintf("debug%s", optarg);
313 SetConfigOption("log_min_messages", debugstr,
315 SetConfigOption("client_min_messages", debugstr,
318 }
319 break;
320 case 'F':
321 SetConfigOption("fsync", "false", PGC_POSTMASTER, PGC_S_ARGV);
322 break;
323 case 'k':
325 break;
326 case 'r':
328 break;
329 case 'X':
331 break;
332 default:
333 write_stderr("Try \"%s --help\" for more information.\n",
334 progname);
335 proc_exit(1);
336 break;
337 }
338 }
339
340 if (argc != optind)
341 {
342 write_stderr("%s: invalid command-line arguments\n", progname);
343 proc_exit(1);
344 }
345
346 /* Acquire configuration parameters */
348 proc_exit(1);
349
350 /*
351 * Validate we have been given a reasonable-looking DataDir and change
352 * into it
353 */
354 checkDataDir();
356
358
360 IgnoreSystemIndexes = true;
361
363
364 /*
365 * Even though bootstrapping runs in single-process mode, initialize
366 * postmaster child slots array so that --check can detect running out of
367 * shared memory or other resources if max_connections is set too high.
368 */
370
372
374
375 /*
376 * Estimate number of openable files. This is essential too in --check
377 * mode, because on some platforms semaphores count as open files.
378 */
380
381 /*
382 * XXX: It might make sense to move this into its own function at some
383 * point. Right now it seems like it'd cause more code duplication than
384 * it's worth.
385 */
386 if (check_only)
387 {
390 abort();
391 }
392
393 /*
394 * Do backend-like initialization for bootstrap mode
395 */
396 InitProcess();
397
398 BaseInit();
399
402
403 /*
404 * To ensure that src/common/link-canary.c is linked into the backend, we
405 * must call it from somewhere. Here is as good as anywhere.
406 */
408 elog(ERROR, "backend is incorrectly linked to frontend functions");
409
411
412 /* Initialize stuff for bootstrap-file processing */
413 for (i = 0; i < MAXATTR; i++)
414 {
415 attrtypes[i] = NULL;
416 Nulls[i] = false;
417 }
418
419 if (boot_yylex_init(&scanner) != 0)
420 elog(ERROR, "yylex_init() failed: %m");
421
422 /*
423 * Process bootstrap input.
424 */
426 boot_yyparse(scanner);
428
429 /*
430 * We should now know about all mapped relations, so it's okay to write
431 * out the initial relation mapping files.
432 */
434
435 /* Clean up and exit */
436 cleanup();
437 proc_exit(0);
438}
#define write_stderr(str)
Definition parallel.c:186
static void CheckerModeMain(void)
Definition bootstrap.c:217
static void cleanup(void)
Definition bootstrap.c:879
static void bootstrap_signals(void)
Definition bootstrap.c:450
static bool Nulls[MAXATTR]
Definition bootstrap.c:189
int boot_yylex_init(yyscan_t *yyscannerp)
#define MAXATTR
Definition bootstrap.h:26
int boot_yyparse(yyscan_t yyscanner)
#define PG_DATA_CHECKSUM_VERSION
Definition bufpage.h:232
#define Assert(condition)
Definition c.h:945
uint32_t uint32
Definition c.h:618
#define pg_fallthrough
Definition c.h:152
void * yyscan_t
Definition cubedata.h:65
int errcode(int sqlerrcode)
Definition elog.c:874
#define ereport(elevel,...)
Definition elog.h:150
void set_max_safe_fds(void)
Definition fd.c:1045
bool IsUnderPostmaster
Definition globals.c:120
char OutputFileName[MAXPGPATH]
Definition globals.c:79
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition guc.c:4228
bool SelectConfigFiles(const char *userDoption, const char *progname)
Definition guc.c:1656
void ParseLongOption(const char *string, char **name, char **value)
Definition guc.c:6237
void InitializeGUCOptions(void)
Definition guc.c:1408
@ PGC_S_DYNAMIC_DEFAULT
Definition guc.h:114
@ PGC_S_ARGV
Definition guc.h:117
@ PGC_INTERNAL
Definition guc.h:73
@ PGC_POSTMASTER
Definition guc.h:74
static struct @174 value
void proc_exit(int code)
Definition ipc.c:105
void CreateSharedMemoryAndSemaphores(void)
Definition ipci.c:192
DispatchOption parse_dispatch_option(const char *name)
Definition main.c:244
const char * progname
Definition main.c:44
char * pstrdup(const char *in)
Definition mcxt.c:1781
void pfree(void *pointer)
Definition mcxt.c:1616
@ NormalProcessing
Definition miscadmin.h:472
@ BootstrapProcessing
Definition miscadmin.h:470
#define SetProcessingMode(mode)
Definition miscadmin.h:483
void ChangeToDataDir(void)
Definition miscinit.c:410
void InitStandaloneProcess(const char *argv0)
Definition miscinit.c:176
bool IgnoreSystemIndexes
Definition miscinit.c:82
void checkDataDir(void)
Definition miscinit.c:297
void CreateDataDirLockFile(bool amPostmaster)
Definition miscinit.c:1464
static char * errmsg
#define MAXPGPATH
PGDLLIMPORT int optind
Definition getopt.c:51
int getopt(int nargc, char *const *nargv, const char *ostr)
Definition getopt.c:72
PGDLLIMPORT char * optarg
Definition getopt.c:53
void InitPostmasterChildSlots(void)
Definition pmchild.c:97
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition strlcpy.c:45
static const char * userDoption
Definition postgres.c:156
void InitializeMaxBackends(void)
Definition postinit.c:559
void BaseInit(void)
Definition postinit.c:616
void InitializeFastPathLocks(void)
Definition postinit.c:584
void InitPostgres(const char *in_dbname, Oid dboid, const char *username, Oid useroid, bits32 flags, char *out_dbname)
Definition postinit.c:719
@ DISPATCH_POSTMASTER
Definition postmaster.h:139
char * psprintf(const char *fmt,...)
Definition psprintf.c:43
void RelationMapFinishBootstrap(void)
Definition relmapper.c:626
void InitProcess(void)
Definition proc.c:380
char * flag(int b)
Definition test-ctype.c:33
const char * name
void StartTransactionCommand(void)
Definition xact.c:3081
void CommitTransactionCommand(void)
Definition xact.c:3179
void BootStrapXLOG(uint32 data_checksum_version)
Definition xlog.c:5110

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

Referenced by main().

◆ build_indices()

void build_indices ( void  )
extern

Definition at line 1173 of file bootstrap.c.

1174{
1175 for (; ILHead != NULL; ILHead = ILHead->il_next)
1176 {
1177 Relation heap;
1178 Relation ind;
1179
1180 /* need not bother with locks during bootstrap */
1181 heap = table_open(ILHead->il_heap, NoLock);
1183
1184 index_build(heap, ind, ILHead->il_info, false, false);
1185
1187 table_close(heap, NoLock);
1188 }
1189}
static IndexList * ILHead
Definition bootstrap.c:207
void index_build(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, bool isreindex, bool parallel)
Definition index.c:3003
void index_close(Relation relation, LOCKMODE lockmode)
Definition indexam.c:177
Relation index_open(Oid relationId, LOCKMODE lockmode)
Definition indexam.c:133
struct _IndexList * il_next
Definition bootstrap.c:204
IndexInfo * il_info
Definition bootstrap.c:203
void table_close(Relation relation, LOCKMODE lockmode)
Definition table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition table.c:40

References fb(), _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)
extern

Definition at line 522 of file bootstrap.c.

523{
524 if (relname)
525 {
526 if (boot_reldesc)
527 {
529 elog(ERROR, "close of %s when %s was expected",
531 }
532 else
533 elog(ERROR, "close of %s before any relation was opened",
534 relname);
535 }
536
537 if (boot_reldesc == NULL)
538 elog(ERROR, "no open relation to close");
539 else
540 {
541 elog(DEBUG4, "close relation %s",
545 }
546}
#define RelationGetRelationName(relation)
Definition rel.h:548

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

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

◆ DefineAttr()

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

Definition at line 559 of file bootstrap.c.

560{
561 Oid typeoid;
562
563 if (boot_reldesc != NULL)
564 {
565 elog(WARNING, "no open relations allowed with CREATE command");
566 closerel(NULL);
567 }
568
569 if (attrtypes[attnum] == NULL)
572
574 elog(DEBUG4, "column %s %s", NameStr(attrtypes[attnum]->attname), type);
575 attrtypes[attnum]->attnum = attnum + 1;
576
577 typeoid = gettype(type);
578
579 if (Typ != NIL)
580 {
581 attrtypes[attnum]->atttypid = Ap->am_oid;
582 attrtypes[attnum]->attlen = Ap->am_typ.typlen;
583 attrtypes[attnum]->attbyval = Ap->am_typ.typbyval;
584 attrtypes[attnum]->attalign = Ap->am_typ.typalign;
585 attrtypes[attnum]->attstorage = Ap->am_typ.typstorage;
586 attrtypes[attnum]->attcompression = InvalidCompressionMethod;
587 attrtypes[attnum]->attcollation = Ap->am_typ.typcollation;
588 /* if an array type, assume 1-dimensional attribute */
589 if (Ap->am_typ.typelem != InvalidOid && Ap->am_typ.typlen < 0)
590 attrtypes[attnum]->attndims = 1;
591 else
592 attrtypes[attnum]->attndims = 0;
593 }
594 else
595 {
596 attrtypes[attnum]->atttypid = TypInfo[typeoid].oid;
597 attrtypes[attnum]->attlen = TypInfo[typeoid].len;
598 attrtypes[attnum]->attbyval = TypInfo[typeoid].byval;
599 attrtypes[attnum]->attalign = TypInfo[typeoid].align;
600 attrtypes[attnum]->attstorage = TypInfo[typeoid].storage;
601 attrtypes[attnum]->attcompression = InvalidCompressionMethod;
602 attrtypes[attnum]->attcollation = TypInfo[typeoid].collation;
603 /* if an array type, assume 1-dimensional attribute */
604 if (TypInfo[typeoid].elem != InvalidOid &&
605 attrtypes[attnum]->attlen < 0)
606 attrtypes[attnum]->attndims = 1;
607 else
608 attrtypes[attnum]->attndims = 0;
609 }
610
611 /*
612 * If a system catalog column is collation-aware, force it to use C
613 * collation, so that its behavior is independent of the database's
614 * collation. This is essential to allow template0 to be cloned with a
615 * different database collation.
616 */
617 if (OidIsValid(attrtypes[attnum]->attcollation))
618 attrtypes[attnum]->attcollation = C_COLLATION_OID;
619
620 attrtypes[attnum]->atttypmod = -1;
621 attrtypes[attnum]->attislocal = true;
622
624 {
625 attrtypes[attnum]->attnotnull = true;
626 }
628 {
629 attrtypes[attnum]->attnotnull = false;
630 }
631 else
632 {
634
635 /*
636 * Mark as "not null" if type is fixed-width and prior columns are
637 * likewise fixed-width and not-null. This corresponds to case where
638 * column can be accessed directly via C struct declaration.
639 */
640 if (attrtypes[attnum]->attlen > 0)
641 {
642 int i;
643
644 /* check earlier attributes */
645 for (i = 0; i < attnum; i++)
646 {
647 if (attrtypes[i]->attlen <= 0 ||
649 break;
650 }
651 if (i == attnum)
652 attrtypes[attnum]->attnotnull = true;
653 }
654 }
655}
static Oid gettype(char *type)
Definition bootstrap.c:932
static struct typmap * Ap
Definition bootstrap.c:149
#define BOOTCOL_NULL_FORCE_NULL
Definition bootstrap.h:29
#define BOOTCOL_NULL_FORCE_NOT_NULL
Definition bootstrap.h:30
#define BOOTCOL_NULL_AUTO
Definition bootstrap.h:28
#define MemSet(start, val, len)
Definition c.h:1109
#define WARNING
Definition elog.h:36
void namestrcpy(Name name, const char *str)
Definition name.c:233
NameData attname
int16 attnum
int16 attlen
bool attnotnull
unsigned int Oid
Oid oid
Definition bootstrap.c:80
char storage
Definition bootstrap.c:85
Oid am_oid
Definition bootstrap.c:144
FormData_pg_type am_typ
Definition bootstrap.c:145
#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, fb(), 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 
)
extern

Definition at line 1123 of file bootstrap.c.

1126{
1129
1130 /*
1131 * XXX mao 10/31/92 -- don't gc index reldescs, associated info at
1132 * bootstrap time. we'll declare the indexes now, but want to create them
1133 * later.
1134 */
1135
1136 if (nogc == NULL)
1138 "BootstrapNoGC",
1140
1142
1144 newind->il_heap = heap;
1145 newind->il_ind = ind;
1146 newind->il_info = palloc_object(IndexInfo);
1147
1148 memcpy(newind->il_info, indexInfo, sizeof(IndexInfo));
1149 /* expressions will likely be null, but may as well copy it */
1150 newind->il_info->ii_Expressions =
1151 copyObject(indexInfo->ii_Expressions);
1152 newind->il_info->ii_ExpressionsState = NIL;
1153 /* predicate will likely be null, but may as well copy it */
1154 newind->il_info->ii_Predicate =
1155 copyObject(indexInfo->ii_Predicate);
1156 newind->il_info->ii_PredicateState = NULL;
1157 /* no exclusion constraints at bootstrap time, so no need to copy */
1158 Assert(indexInfo->ii_ExclusionOps == NULL);
1159 Assert(indexInfo->ii_ExclusionProcs == NULL);
1160 Assert(indexInfo->ii_ExclusionStrats == NULL);
1161
1162 newind->il_next = ILHead;
1163 ILHead = newind;
1164
1166}
static MemoryContext nogc
Definition bootstrap.c:191
#define palloc_object(type)
Definition fe_memutils.h:74
#define AllocSetContextCreate
Definition memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition memutils.h:160
#define copyObject(obj)
Definition nodes.h:232
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition palloc.h:124
uint16 * ii_ExclusionStrats
Definition execnodes.h:203
Oid * ii_ExclusionOps
Definition execnodes.h:199
List * ii_Expressions
Definition execnodes.h:189
Oid * ii_ExclusionProcs
Definition execnodes.h:201
List * ii_Predicate
Definition execnodes.h:194

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, Assert, copyObject, fb(), IndexInfo::ii_ExclusionOps, IndexInfo::ii_ExclusionProcs, IndexInfo::ii_ExclusionStrats, IndexInfo::ii_Expressions, IndexInfo::ii_Predicate, ILHead, MemoryContextSwitchTo(), NIL, nogc, and palloc_object.

Referenced by index_create().

◆ InsertOneNull()

void InsertOneNull ( int  i)
extern

Definition at line 861 of file bootstrap.c.

862{
863 elog(DEBUG4, "inserting column %d NULL", i);
864 Assert(i >= 0 && i < MAXATTR);
865 if (TupleDescAttr(boot_reldesc->rd_att, i)->attnotnull)
866 elog(ERROR,
867 "NULL value specified for not-null column \"%s\" of relation \"%s\"",
871 Nulls[i] = true;
872}
static Datum values[MAXATTR]
Definition bootstrap.c:188
static Datum PointerGetDatum(const void *X)
Definition postgres.h:342

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

◆ InsertOneTuple()

void InsertOneTuple ( void  )
extern

Definition at line 666 of file bootstrap.c.

667{
668 HeapTuple tuple;
669 TupleDesc tupDesc;
670 int i;
671
672 elog(DEBUG4, "inserting row with %d columns", numattr);
673
675 tuple = heap_form_tuple(tupDesc, values, Nulls);
676 pfree(tupDesc); /* just free's tupDesc, not the attrtypes */
677
679 heap_freetuple(tuple);
680 elog(DEBUG4, "row inserted");
681
682 /*
683 * Reset null markers for next tuple
684 */
685 for (i = 0; i < numattr; i++)
686 Nulls[i] = false;
687}
void simple_heap_insert(Relation relation, HeapTuple tup)
Definition heapam.c:2796
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition heaptuple.c:1037
void heap_freetuple(HeapTuple htup)
Definition heaptuple.c:1384
TupleDesc CreateTupleDesc(int natts, Form_pg_attribute *attrs)
Definition tupdesc.c:216

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 
)
extern

Definition at line 694 of file bootstrap.c.

695{
697 Oid typoid;
698 int16 typlen;
699 bool typbyval;
700 char typalign;
701 char typdelim;
702 Oid typioparam;
704 Oid typoutput;
705 Oid typcollation;
706
707 Assert(i >= 0 && i < MAXATTR);
708
709 elog(DEBUG4, "inserting column %d value \"%s\"", i, value);
710
712 typoid = attr->atttypid;
713
715 &typlen, &typbyval, &typalign,
716 &typdelim, &typioparam,
717 &typinput, &typoutput,
718 &typcollation);
719
720 /*
721 * pg_node_tree values can't be inserted normally (pg_node_tree_in would
722 * just error out), so provide special cases for such columns that we
723 * would like to fill during bootstrap.
724 */
725 if (typoid == PG_NODE_TREEOID)
726 {
727 /* pg_proc.proargdefaults */
731 else /* maybe other cases later */
732 elog(ERROR, "can't handle pg_node_tree input for %s.%s",
734 NameStr(attr->attname));
735 }
736 else
737 {
738 /* Normal case */
739 values[i] = OidInputFunctionCall(typinput, value, typioparam, -1);
740 }
741
742 /*
743 * We use ereport not elog here so that parameters aren't evaluated unless
744 * the message is going to be printed, which generally it isn't
745 */
747 (errmsg_internal("inserted -> %s",
748 OidOutputFunctionCall(typoutput, values[i]))));
749}
void boot_get_type_io_data(Oid typid, int16 *typlen, bool *typbyval, char *typalign, char *typdelim, Oid *typioparam, Oid *typinput, Oid *typoutput, Oid *typcollation)
Definition bootstrap.c:1004
static void InsertOneProargdefaultsValue(char *value)
Definition bootstrap.c:761
int16_t int16
Definition c.h:613
int int errmsg_internal(const char *fmt,...) pg_attribute_printf(1
Datum OidInputFunctionCall(Oid functionId, char *str, Oid typioparam, int32 typmod)
Definition fmgr.c:1755
char * OidOutputFunctionCall(Oid functionId, Datum val)
Definition fmgr.c:1764
#define RelationGetRelid(relation)
Definition rel.h:514
#define RelationGetDescr(relation)
Definition rel.h:540

References Assert, boot_get_type_io_data(), boot_reldesc, DEBUG4, elog, ereport, errmsg_internal(), ERROR, fb(), i, InsertOneProargdefaultsValue(), MAXATTR, NameStr, OidInputFunctionCall(), OidOutputFunctionCall(), RelationGetDescr, RelationGetRelationName, RelationGetRelid, TupleDescAttr(), typalign, value, and values.

Variable Documentation

◆ attrtypes

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

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