PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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
 
#define YY_TYPEDEF_YY_SCANNER_T
 

Typedefs

typedef void * yyscan_t
 

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 (yyscan_t yyscanner)
 
int boot_yylex_init (yyscan_t *yyscannerp)
 
int boot_yylex (union YYSTYPE *yylval_param, yyscan_t yyscanner)
 
void boot_yyerror (yyscan_t yyscanner, 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.

◆ YY_TYPEDEF_YY_SCANNER_T

#define YY_TYPEDEF_YY_SCANNER_T

Definition at line 60 of file bootstrap.h.

Typedef Documentation

◆ yyscan_t

typedef void* yyscan_t

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

845{
846 if (Typ != NIL)
847 {
848 /* We have the boot-time contents of pg_type, so use it */
849 struct typmap *ap = NULL;
850 ListCell *lc;
851
852 foreach(lc, Typ)
853 {
854 ap = lfirst(lc);
855 if (ap->am_oid == typid)
856 break;
857 }
858
859 if (!ap || ap->am_oid != typid)
860 elog(ERROR, "type OID %u not found in Typ list", typid);
861
862 *typlen = ap->am_typ.typlen;
863 *typbyval = ap->am_typ.typbyval;
864 *typalign = ap->am_typ.typalign;
865 *typdelim = ap->am_typ.typdelim;
866
867 /* XXX this logic must match getTypeIOParam() */
868 if (OidIsValid(ap->am_typ.typelem))
869 *typioparam = ap->am_typ.typelem;
870 else
871 *typioparam = typid;
872
873 *typinput = ap->am_typ.typinput;
874 *typoutput = ap->am_typ.typoutput;
875 }
876 else
877 {
878 /* We don't have pg_type yet, so use the hard-wired TypInfo array */
879 int typeindex;
880
881 for (typeindex = 0; typeindex < n_types; typeindex++)
882 {
883 if (TypInfo[typeindex].oid == typid)
884 break;
885 }
886 if (typeindex >= n_types)
887 elog(ERROR, "type OID %u not found in TypInfo", typid);
888
889 *typlen = TypInfo[typeindex].len;
890 *typbyval = TypInfo[typeindex].byval;
891 *typalign = TypInfo[typeindex].align;
892 /* We assume typdelim is ',' for all boot-time types */
893 *typdelim = ',';
894
895 /* XXX this logic must match getTypeIOParam() */
896 if (OidIsValid(TypInfo[typeindex].elem))
897 *typioparam = TypInfo[typeindex].elem;
898 else
899 *typioparam = typid;
900
901 *typinput = TypInfo[typeindex].inproc;
902 *typoutput = TypInfo[typeindex].outproc;
903 }
904}
static const int n_types
Definition: bootstrap.c:140
static const struct typinfo TypInfo[]
Definition: bootstrap.c:87
static List * Typ
Definition: bootstrap.c:148
#define OidIsValid(objectId)
Definition: c.h:729
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:225
#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:80
Oid outproc
Definition: bootstrap.c:84
int16 len
Definition: bootstrap.c:78
bool byval
Definition: bootstrap.c:79
Oid elem
Definition: bootstrap.c:77
Oid inproc
Definition: bootstrap.c:83
Oid am_oid
Definition: bootstrap.c:144
FormData_pg_type am_typ
Definition: bootstrap.c:145

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

441{
442 int i;
443
444 if (strlen(relname) >= NAMEDATALEN)
445 relname[NAMEDATALEN - 1] = '\0';
446
447 /*
448 * pg_type must be filled before any OPEN command is executed, hence we
449 * can now populate Typ if we haven't yet.
450 */
451 if (Typ == NIL)
453
454 if (boot_reldesc != NULL)
455 closerel(NULL);
456
457 elog(DEBUG4, "open relation %s, attrsize %d",
459
462 for (i = 0; i < numattr; i++)
463 {
464 if (attrtypes[i] == NULL)
466 memmove((char *) attrtypes[i],
469
470 {
472
473 elog(DEBUG4, "create attribute %d name %s len %d num %d type %u",
474 i, NameStr(at->attname), at->attlen, at->attnum,
475 at->atttypid);
476 }
477 }
478}
void closerel(char *relname)
Definition: bootstrap.c:485
static void populate_typ_list(void)
Definition: bootstrap.c:726
Relation boot_reldesc
Definition: bootstrap.c:58
Form_pg_attribute attrtypes[MAXATTR]
Definition: bootstrap.c:60
int numattr
Definition: bootstrap.c:61
static Form_pg_attribute AllocateAttribute(void)
Definition: bootstrap.c:914
#define NameStr(name)
Definition: c.h:700
#define DEBUG4
Definition: elog.h:27
int i
Definition: isn.c:72
#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:192
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:200
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
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
Definition: tupdesc.h:152

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 ( yyscan_t  yyscanner,
const char *  message 
)

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}
static core_yyscan_t yyscanner
Definition: pl_scanner.c:106

References elog, ERROR, and yyscanner.

◆ boot_yylex()

int boot_yylex ( union YYSTYPE yylval_param,
yyscan_t  yyscanner 
)

◆ boot_yylex_init()

int boot_yylex_init ( yyscan_t yyscannerp)

Referenced by BootstrapModeMain().

◆ boot_yyparse()

int boot_yyparse ( yyscan_t  yyscanner)

Referenced by BootstrapModeMain().

◆ BootstrapModeMain()

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

Definition at line 198 of file bootstrap.c.

199{
200 int i;
201 char *progname = argv[0];
202 int flag;
203 char *userDoption = NULL;
204 uint32 bootstrap_data_checksum_version = 0; /* No checksum */
205 yyscan_t scanner;
206
208
209 InitStandaloneProcess(argv[0]);
210
211 /* Set defaults, to be overridden by explicit options below */
213
214 /* an initial --boot or --check should be present */
215 Assert(argc > 1
216 && (strcmp(argv[1], "--boot") == 0
217 || strcmp(argv[1], "--check") == 0));
218 argv++;
219 argc--;
220
221 while ((flag = getopt(argc, argv, "B:c:d:D:Fkr:X:-:")) != -1)
222 {
223 switch (flag)
224 {
225 case 'B':
226 SetConfigOption("shared_buffers", optarg, PGC_POSTMASTER, PGC_S_ARGV);
227 break;
228 case '-':
229
230 /*
231 * Error if the user misplaced a special must-be-first option
232 * for dispatching to a subprogram. parse_dispatch_option()
233 * returns DISPATCH_POSTMASTER if it doesn't find a match, so
234 * error for anything else.
235 */
238 (errcode(ERRCODE_SYNTAX_ERROR),
239 errmsg("--%s must be first argument", optarg)));
240
241 /* FALLTHROUGH */
242 case 'c':
243 {
244 char *name,
245 *value;
246
248 if (!value)
249 {
250 if (flag == '-')
252 (errcode(ERRCODE_SYNTAX_ERROR),
253 errmsg("--%s requires a value",
254 optarg)));
255 else
257 (errcode(ERRCODE_SYNTAX_ERROR),
258 errmsg("-c %s requires a value",
259 optarg)));
260 }
261
263 pfree(name);
264 pfree(value);
265 break;
266 }
267 case 'D':
269 break;
270 case 'd':
271 {
272 /* Turn on debugging for the bootstrap process. */
273 char *debugstr;
274
275 debugstr = psprintf("debug%s", optarg);
276 SetConfigOption("log_min_messages", debugstr,
278 SetConfigOption("client_min_messages", debugstr,
280 pfree(debugstr);
281 }
282 break;
283 case 'F':
284 SetConfigOption("fsync", "false", PGC_POSTMASTER, PGC_S_ARGV);
285 break;
286 case 'k':
287 bootstrap_data_checksum_version = PG_DATA_CHECKSUM_VERSION;
288 break;
289 case 'r':
291 break;
292 case 'X':
294 break;
295 default:
296 write_stderr("Try \"%s --help\" for more information.\n",
297 progname);
298 proc_exit(1);
299 break;
300 }
301 }
302
303 if (argc != optind)
304 {
305 write_stderr("%s: invalid command-line arguments\n", progname);
306 proc_exit(1);
307 }
308
309 /* Acquire configuration parameters */
311 proc_exit(1);
312
313 /*
314 * Validate we have been given a reasonable-looking DataDir and change
315 * into it
316 */
317 checkDataDir();
319
321
323 IgnoreSystemIndexes = true;
324
326
327 /*
328 * Even though bootstrapping runs in single-process mode, initialize
329 * postmaster child slots array so that --check can detect running out of
330 * shared memory or other resources if max_connections is set too high.
331 */
333
335
337
338 /*
339 * Estimate number of openable files. This is essential too in --check
340 * mode, because on some platforms semaphores count as open files.
341 */
343
344 /*
345 * XXX: It might make sense to move this into its own function at some
346 * point. Right now it seems like it'd cause more code duplication than
347 * it's worth.
348 */
349 if (check_only)
350 {
353 abort();
354 }
355
356 /*
357 * Do backend-like initialization for bootstrap mode
358 */
359 InitProcess();
360
361 BaseInit();
362
364 BootStrapXLOG(bootstrap_data_checksum_version);
365
366 /*
367 * To ensure that src/common/link-canary.c is linked into the backend, we
368 * must call it from somewhere. Here is as good as anywhere.
369 */
371 elog(ERROR, "backend is incorrectly linked to frontend functions");
372
373 InitPostgres(NULL, InvalidOid, NULL, InvalidOid, 0, NULL);
374
375 /* Initialize stuff for bootstrap-file processing */
376 for (i = 0; i < MAXATTR; i++)
377 {
378 attrtypes[i] = NULL;
379 Nulls[i] = false;
380 }
381
382 if (boot_yylex_init(&scanner) != 0)
383 elog(ERROR, "yylex_init() failed: %m");
384
385 /*
386 * Process bootstrap input.
387 */
389 boot_yyparse(scanner);
391
392 /*
393 * We should now know about all mapped relations, so it's okay to write
394 * out the initial relation mapping files.
395 */
397
398 /* Clean up and exit */
399 cleanup();
400 proc_exit(0);
401}
#define write_stderr(str)
Definition: parallel.c:186
static void CheckerModeMain(void)
Definition: bootstrap.c:180
static void cleanup(void)
Definition: bootstrap.c:713
static void bootstrap_signals(void)
Definition: bootstrap.c:413
static bool Nulls[MAXATTR]
Definition: bootstrap.c:152
int boot_yylex_init(yyscan_t *yyscannerp)
#define MAXATTR
Definition: bootstrap.h:25
int boot_yyparse(yyscan_t yyscanner)
#define PG_DATA_CHECKSUM_VERSION
Definition: bufpage.h:206
#define Assert(condition)
Definition: c.h:812
uint32_t uint32
Definition: c.h:485
void * yyscan_t
Definition: cubedata.h:67
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ereport(elevel,...)
Definition: elog.h:149
void set_max_safe_fds(void)
Definition: fd.c:1043
bool IsUnderPostmaster
Definition: globals.c:119
char OutputFileName[MAXPGPATH]
Definition: globals.c:78
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:4332
bool SelectConfigFiles(const char *userDoption, const char *progname)
Definition: guc.c:1784
void ParseLongOption(const char *string, char **name, char **value)
Definition: guc.c:6362
void InitializeGUCOptions(void)
Definition: guc.c:1530
@ 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 @161 value
void proc_exit(int code)
Definition: ipc.c:104
void CreateSharedMemoryAndSemaphores(void)
Definition: ipci.c:198
DispatchOption parse_dispatch_option(const char *name)
Definition: main.c:243
const char * progname
Definition: main.c:44
char * pstrdup(const char *in)
Definition: mcxt.c:1696
void pfree(void *pointer)
Definition: mcxt.c:1521
@ NormalProcessing
Definition: miscadmin.h:461
@ BootstrapProcessing
Definition: miscadmin.h:459
#define SetProcessingMode(mode)
Definition: miscadmin.h:472
void ChangeToDataDir(void)
Definition: miscinit.c:457
void InitStandaloneProcess(const char *argv0)
Definition: miscinit.c:175
bool IgnoreSystemIndexes
Definition: miscinit.c:81
void checkDataDir(void)
Definition: miscinit.c:344
void CreateDataDirLockFile(bool amPostmaster)
Definition: miscinit.c:1511
#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:86
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
static const char * userDoption
Definition: postgres.c:152
#define InvalidOid
Definition: postgres_ext.h:36
void InitializeMaxBackends(void)
Definition: postinit.c:545
void BaseInit(void)
Definition: postinit.c:606
void InitializeFastPathLocks(void)
Definition: postinit.c:577
void InitPostgres(const char *in_dbname, Oid dboid, const char *username, Oid useroid, bits32 flags, char *out_dbname)
Definition: postinit.c:700
@ DISPATCH_POSTMASTER
Definition: postmaster.h:152
char * psprintf(const char *fmt,...)
Definition: psprintf.c:43
void RelationMapFinishBootstrap(void)
Definition: relmapper.c:625
void InitProcess(void)
Definition: proc.c:341
char * flag(int b)
Definition: test-ctype.c:33
const char * name
void StartTransactionCommand(void)
Definition: xact.c:3051
void CommitTransactionCommand(void)
Definition: xact.c:3149
void BootStrapXLOG(uint32 data_checksum_version)
Definition: xlog.c:5033

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, 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_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  )

Definition at line 982 of file bootstrap.c.

983{
984 for (; ILHead != NULL; ILHead = ILHead->il_next)
985 {
986 Relation heap;
988
989 /* need not bother with locks during bootstrap */
992
993 index_build(heap, ind, ILHead->il_info, false, false);
994
996 table_close(heap, NoLock);
997 }
998}
static IndexList * ILHead
Definition: bootstrap.c:170
void index_build(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, bool isreindex, bool parallel)
Definition: index.c:2972
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:164
struct _IndexList * il_next
Definition: bootstrap.c:167
Oid il_ind
Definition: bootstrap.c:165
IndexInfo * il_info
Definition: bootstrap.c:166
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 485 of file bootstrap.c.

486{
487 if (relname)
488 {
489 if (boot_reldesc)
490 {
492 elog(ERROR, "close of %s when %s was expected",
494 }
495 else
496 elog(ERROR, "close of %s before any relation was opened",
497 relname);
498 }
499
500 if (boot_reldesc == NULL)
501 elog(ERROR, "no open relation to close");
502 else
503 {
504 elog(DEBUG4, "close relation %s",
507 boot_reldesc = NULL;
508 }
509}
#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 522 of file bootstrap.c.

523{
524 Oid typeoid;
525
526 if (boot_reldesc != NULL)
527 {
528 elog(WARNING, "no open relations allowed with CREATE command");
529 closerel(NULL);
530 }
531
532 if (attrtypes[attnum] == NULL)
535
537 elog(DEBUG4, "column %s %s", NameStr(attrtypes[attnum]->attname), type);
538 attrtypes[attnum]->attnum = attnum + 1;
539
540 typeoid = gettype(type);
541
542 if (Typ != NIL)
543 {
544 attrtypes[attnum]->atttypid = Ap->am_oid;
545 attrtypes[attnum]->attlen = Ap->am_typ.typlen;
546 attrtypes[attnum]->attbyval = Ap->am_typ.typbyval;
547 attrtypes[attnum]->attalign = Ap->am_typ.typalign;
548 attrtypes[attnum]->attstorage = Ap->am_typ.typstorage;
549 attrtypes[attnum]->attcompression = InvalidCompressionMethod;
550 attrtypes[attnum]->attcollation = Ap->am_typ.typcollation;
551 /* if an array type, assume 1-dimensional attribute */
552 if (Ap->am_typ.typelem != InvalidOid && Ap->am_typ.typlen < 0)
553 attrtypes[attnum]->attndims = 1;
554 else
555 attrtypes[attnum]->attndims = 0;
556 }
557 else
558 {
559 attrtypes[attnum]->atttypid = TypInfo[typeoid].oid;
560 attrtypes[attnum]->attlen = TypInfo[typeoid].len;
561 attrtypes[attnum]->attbyval = TypInfo[typeoid].byval;
562 attrtypes[attnum]->attalign = TypInfo[typeoid].align;
563 attrtypes[attnum]->attstorage = TypInfo[typeoid].storage;
564 attrtypes[attnum]->attcompression = InvalidCompressionMethod;
565 attrtypes[attnum]->attcollation = TypInfo[typeoid].collation;
566 /* if an array type, assume 1-dimensional attribute */
567 if (TypInfo[typeoid].elem != InvalidOid &&
568 attrtypes[attnum]->attlen < 0)
569 attrtypes[attnum]->attndims = 1;
570 else
571 attrtypes[attnum]->attndims = 0;
572 }
573
574 /*
575 * If a system catalog column is collation-aware, force it to use C
576 * collation, so that its behavior is independent of the database's
577 * collation. This is essential to allow template0 to be cloned with a
578 * different database collation.
579 */
580 if (OidIsValid(attrtypes[attnum]->attcollation))
581 attrtypes[attnum]->attcollation = C_COLLATION_OID;
582
583 attrtypes[attnum]->atttypmod = -1;
584 attrtypes[attnum]->attislocal = true;
585
586 if (nullness == BOOTCOL_NULL_FORCE_NOT_NULL)
587 {
588 attrtypes[attnum]->attnotnull = true;
589 }
590 else if (nullness == BOOTCOL_NULL_FORCE_NULL)
591 {
592 attrtypes[attnum]->attnotnull = false;
593 }
594 else
595 {
596 Assert(nullness == BOOTCOL_NULL_AUTO);
597
598 /*
599 * Mark as "not null" if type is fixed-width and prior columns are
600 * likewise fixed-width and not-null. This corresponds to case where
601 * column can be accessed directly via C struct declaration.
602 */
603 if (attrtypes[attnum]->attlen > 0)
604 {
605 int i;
606
607 /* check earlier attributes */
608 for (i = 0; i < attnum; i++)
609 {
610 if (attrtypes[i]->attlen <= 0 ||
612 break;
613 }
614 if (i == attnum)
615 attrtypes[attnum]->attnotnull = true;
616 }
617 }
618}
static Oid gettype(char *type)
Definition: bootstrap.c:766
static struct typmap * Ap
Definition: bootstrap.c:149
#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:974
#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:121
unsigned int Oid
Definition: postgres_ext.h:31
Oid oid
Definition: bootstrap.c:76
Oid collation
Definition: bootstrap.c:82
char storage
Definition: bootstrap.c:81
#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 932 of file bootstrap.c.

935{
936 IndexList *newind;
937 MemoryContext oldcxt;
938
939 /*
940 * XXX mao 10/31/92 -- don't gc index reldescs, associated info at
941 * bootstrap time. we'll declare the indexes now, but want to create them
942 * later.
943 */
944
945 if (nogc == NULL)
947 "BootstrapNoGC",
949
950 oldcxt = MemoryContextSwitchTo(nogc);
951
952 newind = (IndexList *) palloc(sizeof(IndexList));
953 newind->il_heap = heap;
954 newind->il_ind = ind;
955 newind->il_info = (IndexInfo *) palloc(sizeof(IndexInfo));
956
957 memcpy(newind->il_info, indexInfo, sizeof(IndexInfo));
958 /* expressions will likely be null, but may as well copy it */
959 newind->il_info->ii_Expressions =
960 copyObject(indexInfo->ii_Expressions);
962 /* predicate will likely be null, but may as well copy it */
963 newind->il_info->ii_Predicate =
964 copyObject(indexInfo->ii_Predicate);
965 newind->il_info->ii_PredicateState = NULL;
966 /* no exclusion constraints at bootstrap time, so no need to copy */
967 Assert(indexInfo->ii_ExclusionOps == NULL);
968 Assert(indexInfo->ii_ExclusionProcs == NULL);
969 Assert(indexInfo->ii_ExclusionStrats == NULL);
970
971 newind->il_next = ILHead;
972 ILHead = newind;
973
974 MemoryContextSwitchTo(oldcxt);
975}
static MemoryContext nogc
Definition: bootstrap.c:154
void * palloc(Size size)
Definition: mcxt.c:1317
#define AllocSetContextCreate
Definition: memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:160
#define copyObject(obj)
Definition: nodes.h:224
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:124
uint16 * ii_ExclusionStrats
Definition: execnodes.h:195
ExprState * ii_PredicateState
Definition: execnodes.h:192
Oid * ii_ExclusionOps
Definition: execnodes.h:193
List * ii_ExpressionsState
Definition: execnodes.h:190
List * ii_Expressions
Definition: execnodes.h:189
Oid * ii_ExclusionProcs
Definition: execnodes.h:194
List * ii_Predicate
Definition: execnodes.h:191

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

696{
697 elog(DEBUG4, "inserting column %d NULL", i);
698 Assert(i >= 0 && i < MAXATTR);
699 if (TupleDescAttr(boot_reldesc->rd_att, i)->attnotnull)
700 elog(ERROR,
701 "NULL value specified for not-null column \"%s\" of relation \"%s\"",
704 values[i] = PointerGetDatum(NULL);
705 Nulls[i] = true;
706}
static Datum values[MAXATTR]
Definition: bootstrap.c:151
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 629 of file bootstrap.c.

630{
631 HeapTuple tuple;
632 TupleDesc tupDesc;
633 int i;
634
635 elog(DEBUG4, "inserting row with %d columns", numattr);
636
638 tuple = heap_form_tuple(tupDesc, values, Nulls);
639 pfree(tupDesc); /* just free's tupDesc, not the attrtypes */
640
642 heap_freetuple(tuple);
643 elog(DEBUG4, "row inserted");
644
645 /*
646 * Reset null markers for next tuple
647 */
648 for (i = 0; i < numattr; i++)
649 Nulls[i] = false;
650}
void simple_heap_insert(Relation relation, HeapTuple tup)
Definition: heapam.c:2619
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition: heaptuple.c:1117
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1435
TupleDesc CreateTupleDesc(int natts, Form_pg_attribute *attrs)
Definition: tupdesc.c:212

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

658{
659 Oid typoid;
660 int16 typlen;
661 bool typbyval;
662 char typalign;
663 char typdelim;
664 Oid typioparam;
665 Oid typinput;
666 Oid typoutput;
667
668 Assert(i >= 0 && i < MAXATTR);
669
670 elog(DEBUG4, "inserting column %d value \"%s\"", i, value);
671
672 typoid = TupleDescAttr(boot_reldesc->rd_att, i)->atttypid;
673
675 &typlen, &typbyval, &typalign,
676 &typdelim, &typioparam,
677 &typinput, &typoutput);
678
679 values[i] = OidInputFunctionCall(typinput, value, typioparam, -1);
680
681 /*
682 * We use ereport not elog here so that parameters aren't evaluated unless
683 * the message is going to be printed, which generally it isn't
684 */
686 (errmsg_internal("inserted -> %s",
687 OidOutputFunctionCall(typoutput, values[i]))));
688}
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:837
int16_t int16
Definition: c.h:480
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 60 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 61 of file bootstrap.c.

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