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

Go to the source code of this file.

Macros

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

Typedefs

typedef void * yyscan_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)
 
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 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.

Typedef Documentation

◆ yyscan_t

typedef void* yyscan_t

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

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

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

443{
444 int i;
445
446 if (strlen(relname) >= NAMEDATALEN)
447 relname[NAMEDATALEN - 1] = '\0';
448
449 /*
450 * pg_type must be filled before any OPEN command is executed, hence we
451 * can now populate Typ if we haven't yet.
452 */
453 if (Typ == NIL)
455
456 if (boot_reldesc != NULL)
457 closerel(NULL);
458
459 elog(DEBUG4, "open relation %s, attrsize %d",
461
464 for (i = 0; i < numattr; i++)
465 {
466 if (attrtypes[i] == NULL)
468 memmove(attrtypes[i],
471
472 {
474
475 elog(DEBUG4, "create attribute %d name %s len %d num %d type %u",
476 i, NameStr(at->attname), at->attlen, at->attnum,
477 at->atttypid);
478 }
479 }
480}
void closerel(char *relname)
Definition: bootstrap.c:487
static void populate_typ_list(void)
Definition: bootstrap.c:728
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:916
#define NameStr(name)
Definition: c.h:756
#define DEBUG4
Definition: elog.h:27
int i
Definition: isn.c:77
#define NoLock
Definition: lockdefs.h:34
RangeVar * makeRangeVar(char *schemaname, char *relname, int location)
Definition: makefuncs.c:473
#define ATTRIBUTE_FIXED_PART_SIZE
Definition: pg_attribute.h:194
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:202
NameData relname
Definition: pg_class.h:38
#define NAMEDATALEN
#define RelationGetNumberOfAttributes(relation)
Definition: rel.h:521
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:160

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

pg_noreturn 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}

References elog, and ERROR.

◆ 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()

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

Definition at line 200 of file bootstrap.c.

201{
202 int i;
203 char *progname = argv[0];
204 int flag;
205 char *userDoption = NULL;
206 uint32 bootstrap_data_checksum_version = 0; /* No checksum */
207 yyscan_t scanner;
208
210
211 InitStandaloneProcess(argv[0]);
212
213 /* Set defaults, to be overridden by explicit options below */
215
216 /* an initial --boot or --check should be present */
217 Assert(argc > 1
218 && (strcmp(argv[1], "--boot") == 0
219 || strcmp(argv[1], "--check") == 0));
220 argv++;
221 argc--;
222
223 while ((flag = getopt(argc, argv, "B:c:d:D:Fkr:X:-:")) != -1)
224 {
225 switch (flag)
226 {
227 case 'B':
228 SetConfigOption("shared_buffers", optarg, PGC_POSTMASTER, PGC_S_ARGV);
229 break;
230 case '-':
231
232 /*
233 * Error if the user misplaced a special must-be-first option
234 * for dispatching to a subprogram. parse_dispatch_option()
235 * returns DISPATCH_POSTMASTER if it doesn't find a match, so
236 * error for anything else.
237 */
240 (errcode(ERRCODE_SYNTAX_ERROR),
241 errmsg("--%s must be first argument", optarg)));
242
243 /* FALLTHROUGH */
244 case 'c':
245 {
246 char *name,
247 *value;
248
250 if (!value)
251 {
252 if (flag == '-')
254 (errcode(ERRCODE_SYNTAX_ERROR),
255 errmsg("--%s requires a value",
256 optarg)));
257 else
259 (errcode(ERRCODE_SYNTAX_ERROR),
260 errmsg("-c %s requires a value",
261 optarg)));
262 }
263
265 pfree(name);
266 pfree(value);
267 break;
268 }
269 case 'D':
271 break;
272 case 'd':
273 {
274 /* Turn on debugging for the bootstrap process. */
275 char *debugstr;
276
277 debugstr = psprintf("debug%s", optarg);
278 SetConfigOption("log_min_messages", debugstr,
280 SetConfigOption("client_min_messages", debugstr,
282 pfree(debugstr);
283 }
284 break;
285 case 'F':
286 SetConfigOption("fsync", "false", PGC_POSTMASTER, PGC_S_ARGV);
287 break;
288 case 'k':
289 bootstrap_data_checksum_version = PG_DATA_CHECKSUM_VERSION;
290 break;
291 case 'r':
293 break;
294 case 'X':
296 break;
297 default:
298 write_stderr("Try \"%s --help\" for more information.\n",
299 progname);
300 proc_exit(1);
301 break;
302 }
303 }
304
305 if (argc != optind)
306 {
307 write_stderr("%s: invalid command-line arguments\n", progname);
308 proc_exit(1);
309 }
310
311 /* Acquire configuration parameters */
313 proc_exit(1);
314
315 /*
316 * Validate we have been given a reasonable-looking DataDir and change
317 * into it
318 */
319 checkDataDir();
321
323
325 IgnoreSystemIndexes = true;
326
328
329 /*
330 * Even though bootstrapping runs in single-process mode, initialize
331 * postmaster child slots array so that --check can detect running out of
332 * shared memory or other resources if max_connections is set too high.
333 */
335
337
339
340 /*
341 * Estimate number of openable files. This is essential too in --check
342 * mode, because on some platforms semaphores count as open files.
343 */
345
346 /*
347 * XXX: It might make sense to move this into its own function at some
348 * point. Right now it seems like it'd cause more code duplication than
349 * it's worth.
350 */
351 if (check_only)
352 {
355 abort();
356 }
357
358 /*
359 * Do backend-like initialization for bootstrap mode
360 */
361 InitProcess();
362
363 BaseInit();
364
366 BootStrapXLOG(bootstrap_data_checksum_version);
367
368 /*
369 * To ensure that src/common/link-canary.c is linked into the backend, we
370 * must call it from somewhere. Here is as good as anywhere.
371 */
373 elog(ERROR, "backend is incorrectly linked to frontend functions");
374
375 InitPostgres(NULL, InvalidOid, NULL, InvalidOid, 0, NULL);
376
377 /* Initialize stuff for bootstrap-file processing */
378 for (i = 0; i < MAXATTR; i++)
379 {
380 attrtypes[i] = NULL;
381 Nulls[i] = false;
382 }
383
384 if (boot_yylex_init(&scanner) != 0)
385 elog(ERROR, "yylex_init() failed: %m");
386
387 /*
388 * Process bootstrap input.
389 */
391 boot_yyparse(scanner);
393
394 /*
395 * We should now know about all mapped relations, so it's okay to write
396 * out the initial relation mapping files.
397 */
399
400 /* Clean up and exit */
401 cleanup();
402 proc_exit(0);
403}
#define write_stderr(str)
Definition: parallel.c:186
static void CheckerModeMain(void)
Definition: bootstrap.c:182
static void cleanup(void)
Definition: bootstrap.c:715
static void bootstrap_signals(void)
Definition: bootstrap.c:415
static bool Nulls[MAXATTR]
Definition: bootstrap.c:154
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
uint32_t uint32
Definition: c.h:543
void * yyscan_t
Definition: cubedata.h:65
int errcode(int sqlerrcode)
Definition: elog.c:863
int errmsg(const char *fmt,...)
Definition: elog.c:1080
#define ereport(elevel,...)
Definition: elog.h:150
void set_max_safe_fds(void)
Definition: fd.c:1041
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:4196
bool SelectConfigFiles(const char *userDoption, const char *progname)
Definition: guc.c:1655
void ParseLongOption(const char *string, char **name, char **value)
Definition: guc.c:6205
void InitializeGUCOptions(void)
Definition: guc.c:1407
@ 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
Assert(PointerIsAligned(start, uint64))
static struct @171 value
void proc_exit(int code)
Definition: ipc.c:104
void CreateSharedMemoryAndSemaphores(void)
Definition: ipci.c:190
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:1759
void pfree(void *pointer)
Definition: mcxt.c:1594
@ NormalProcessing
Definition: miscadmin.h:472
@ BootstrapProcessing
Definition: miscadmin.h:470
#define SetProcessingMode(mode)
Definition: miscadmin.h:483
void ChangeToDataDir(void)
Definition: miscinit.c:409
void InitStandaloneProcess(const char *argv0)
Definition: miscinit.c:175
bool IgnoreSystemIndexes
Definition: miscinit.c:81
void checkDataDir(void)
Definition: miscinit.c:296
void CreateDataDirLockFile(bool amPostmaster)
Definition: miscinit.c:1463
#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:154
#define InvalidOid
Definition: postgres_ext.h:37
void InitializeMaxBackends(void)
Definition: postinit.c:550
void BaseInit(void)
Definition: postinit.c:607
void InitializeFastPathLocks(void)
Definition: postinit.c:575
void InitPostgres(const char *in_dbname, Oid dboid, const char *username, Oid useroid, bits32 flags, char *out_dbname)
Definition: postinit.c:707
@ DISPATCH_POSTMASTER
Definition: postmaster.h:139
char * psprintf(const char *fmt,...)
Definition: psprintf.c:43
void RelationMapFinishBootstrap(void)
Definition: relmapper.c:625
void InitProcess(void)
Definition: proc.c:395
char * flag(int b)
Definition: test-ctype.c:33
const char * name
void StartTransactionCommand(void)
Definition: xact.c:3077
void CommitTransactionCommand(void)
Definition: xact.c:3175
void BootStrapXLOG(uint32 data_checksum_version)
Definition: xlog.c:5089

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

985{
986 for (; ILHead != NULL; ILHead = ILHead->il_next)
987 {
988 Relation heap;
990
991 /* need not bother with locks during bootstrap */
994
995 index_build(heap, ind, ILHead->il_info, false, false);
996
998 table_close(heap, NoLock);
999 }
1000}
static IndexList * ILHead
Definition: bootstrap.c:172
void index_build(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, bool isreindex, bool parallel)
Definition: index.c:3002
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:166
struct _IndexList * il_next
Definition: bootstrap.c:169
Oid il_ind
Definition: bootstrap.c:167
IndexInfo * il_info
Definition: bootstrap.c:168
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 487 of file bootstrap.c.

488{
489 if (relname)
490 {
491 if (boot_reldesc)
492 {
494 elog(ERROR, "close of %s when %s was expected",
496 }
497 else
498 elog(ERROR, "close of %s before any relation was opened",
499 relname);
500 }
501
502 if (boot_reldesc == NULL)
503 elog(ERROR, "no open relation to close");
504 else
505 {
506 elog(DEBUG4, "close relation %s",
509 boot_reldesc = NULL;
510 }
511}
#define RelationGetRelationName(relation)
Definition: rel.h:549

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

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

937{
938 IndexList *newind;
939 MemoryContext oldcxt;
940
941 /*
942 * XXX mao 10/31/92 -- don't gc index reldescs, associated info at
943 * bootstrap time. we'll declare the indexes now, but want to create them
944 * later.
945 */
946
947 if (nogc == NULL)
949 "BootstrapNoGC",
951
952 oldcxt = MemoryContextSwitchTo(nogc);
953
954 newind = (IndexList *) palloc(sizeof(IndexList));
955 newind->il_heap = heap;
956 newind->il_ind = ind;
957 newind->il_info = (IndexInfo *) palloc(sizeof(IndexInfo));
958
959 memcpy(newind->il_info, indexInfo, sizeof(IndexInfo));
960 /* expressions will likely be null, but may as well copy it */
961 newind->il_info->ii_Expressions =
962 copyObject(indexInfo->ii_Expressions);
964 /* predicate will likely be null, but may as well copy it */
965 newind->il_info->ii_Predicate =
966 copyObject(indexInfo->ii_Predicate);
967 newind->il_info->ii_PredicateState = NULL;
968 /* no exclusion constraints at bootstrap time, so no need to copy */
969 Assert(indexInfo->ii_ExclusionOps == NULL);
970 Assert(indexInfo->ii_ExclusionProcs == NULL);
971 Assert(indexInfo->ii_ExclusionStrats == NULL);
972
973 newind->il_next = ILHead;
974 ILHead = newind;
975
976 MemoryContextSwitchTo(oldcxt);
977}
static MemoryContext nogc
Definition: bootstrap.c:156
void * palloc(Size size)
Definition: mcxt.c:1365
#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:192
ExprState * ii_PredicateState
Definition: execnodes.h:185
Oid * ii_ExclusionOps
Definition: execnodes.h:188
List * ii_ExpressionsState
Definition: execnodes.h:180
List * ii_Expressions
Definition: execnodes.h:178
Oid * ii_ExclusionProcs
Definition: execnodes.h:190
List * ii_Predicate
Definition: execnodes.h:183

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

698{
699 elog(DEBUG4, "inserting column %d NULL", i);
700 Assert(i >= 0 && i < MAXATTR);
701 if (TupleDescAttr(boot_reldesc->rd_att, i)->attnotnull)
702 elog(ERROR,
703 "NULL value specified for not-null column \"%s\" of relation \"%s\"",
706 values[i] = PointerGetDatum(NULL);
707 Nulls[i] = true;
708}
static Datum values[MAXATTR]
Definition: bootstrap.c:153
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:332

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

632{
633 HeapTuple tuple;
634 TupleDesc tupDesc;
635 int i;
636
637 elog(DEBUG4, "inserting row with %d columns", numattr);
638
640 tuple = heap_form_tuple(tupDesc, values, Nulls);
641 pfree(tupDesc); /* just free's tupDesc, not the attrtypes */
642
644 heap_freetuple(tuple);
645 elog(DEBUG4, "row inserted");
646
647 /*
648 * Reset null markers for next tuple
649 */
650 for (i = 0; i < numattr; i++)
651 Nulls[i] = false;
652}
void simple_heap_insert(Relation relation, HeapTuple tup)
Definition: heapam.c:2731
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:229

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

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