1 /*-------------------------------------------------------------------------
4 * routines to support running postgres in 'bootstrap' mode
5 * bootstrap mode is used to create the initial template database
7 * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
8 * Portions Copyright (c) 1994, Regents of the University of California
11 * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.102 2000/12/28 13:00:12 vadim Exp $
13 *-------------------------------------------------------------------------
22 #define BOOTSTRAP_INCLUDE /* mask out stuff in tcop/tcopprot.h */
28 #include "access/genam.h"
29 #include "access/heapam.h"
30 #include "access/xlog.h"
31 #include "bootstrap/bootstrap.h"
32 #include "catalog/catname.h"
33 #include "catalog/index.h"
34 #include "catalog/pg_type.h"
35 #include "libpq/pqsignal.h"
36 #include "miscadmin.h"
37 #include "tcop/tcopprot.h"
38 #include "utils/builtins.h"
39 #include "utils/exc.h"
40 #include "utils/fmgroids.h"
41 #include "utils/guc.h"
42 #include "utils/lsyscache.h"
43 #include "utils/relcache.h"
46 #define ALLOC(t, c) ((t *) calloc((unsigned)(c), sizeof(t)))
49 extern int Int_yyparse(void);
50 static hashnode *AddStr(char *str, int strlength, int mderef);
51 static Form_pg_attribute AllocateAttribute(void);
52 static bool BootstrapAlreadySeen(Oid id);
53 static int CompHash(char *str, int len);
54 static hashnode *FindStr(char *str, int length, hashnode *mderef);
55 static Oid gettype(char *type);
56 static void cleanup(void);
63 * In the lexical analyzer, we need to get the reference number quickly from
64 * the string, and the string from the reference number. Thus we have
65 * as our data structure a hash table, where the hashing key taken from
66 * the particular string. The hash table is chained. One of the fields
67 * of the hash table node is an index into the array of character pointers.
68 * The unique index number that every string is assigned is simply the
69 * position of its string pointer in the array of string pointers.
72 #define STRTABLESIZE 10000
73 #define HASHTABLESIZE 503
75 /* Hash function numbers */
80 char *strtable[STRTABLESIZE];
81 hashnode *hashtable[HASHTABLESIZE];
83 static int strtable_end = -1; /* Tells us last occupied string space */
86 * Basic information associated with each type. This is used before
89 * XXX several of these input/output functions do catalog scans
90 * (e.g., F_REGPROCIN scans pg_proc). this obviously creates some
91 * order dependencies in the catalog creation process.
95 char name[NAMEDATALEN];
103 static struct typinfo Procid[] = {
104 {"bool", BOOLOID, 0, 1, F_BOOLIN, F_BOOLOUT},
105 {"bytea", BYTEAOID, 0, -1, F_BYTEAIN, F_BYTEAOUT},
106 {"char", CHAROID, 0, 1, F_CHARIN, F_CHAROUT},
107 {"name", NAMEOID, 0, NAMEDATALEN, F_NAMEIN, F_NAMEOUT},
108 {"int2", INT2OID, 0, 2, F_INT2IN, F_INT2OUT},
109 {"int2vector", INT2VECTOROID, 0, INDEX_MAX_KEYS * 2, F_INT2VECTORIN, F_INT2VECTOROUT},
110 {"int4", INT4OID, 0, 4, F_INT4IN, F_INT4OUT},
111 {"regproc", REGPROCOID, 0, 4, F_REGPROCIN, F_REGPROCOUT},
112 {"text", TEXTOID, 0, -1, F_TEXTIN, F_TEXTOUT},
113 {"oid", OIDOID, 0, 4, F_OIDIN, F_OIDOUT},
114 {"tid", TIDOID, 0, 6, F_TIDIN, F_TIDOUT},
115 {"xid", XIDOID, 0, 4, F_XIDIN, F_XIDOUT},
116 {"cid", CIDOID, 0, 4, F_CIDIN, F_CIDOUT},
117 {"oidvector", 30, 0, INDEX_MAX_KEYS * 4, F_OIDVECTORIN, F_OIDVECTOROUT},
118 {"smgr", 210, 0, 2, F_SMGRIN, F_SMGROUT},
119 {"_int4", 1007, INT4OID, -1, F_ARRAY_IN, F_ARRAY_OUT},
120 {"_aclitem", 1034, 1033, -1, F_ARRAY_IN, F_ARRAY_OUT}
123 static int n_types = sizeof(Procid) / sizeof(struct typinfo);
128 FormData_pg_type am_typ;
131 static struct typmap **Typ = (struct typmap **) NULL;
132 static struct typmap *Ap = (struct typmap *) NULL;
134 static int Warnings = 0;
135 static char Blanks[MAXATTR];
137 static char *relname; /* current relation name */
139 Form_pg_attribute attrtypes[MAXATTR]; /* points to attribute info */
140 static Datum values[MAXATTR]; /* corresponding attribute values */
141 int numattr; /* number of attributes for cur. rel */
145 static MemoryContext nogc = NULL; /* special no-gc mem context */
150 extern void SetRedoRecPtr(void);
153 * At bootstrap time, we first declare all the indices to be built, and
154 * then build them. The IndexList structure stores enough information
155 * to allow us to build the indices after they've been declared.
158 typedef struct _IndexList
163 struct _IndexList *il_next;
166 static IndexList *ILHead = (IndexList *) NULL;
169 /* ----------------------------------------------------------------
171 * ----------------------------------------------------------------
175 * error handling / abort routines
186 usage help for the bootstrap backen
191 fprintf(stderr, "Usage: postgres -boot [-d] [-C] [-F] [-O] [-Q] ");
192 fprintf(stderr, "[-P portno] [dbName]\n");
193 fprintf(stderr, " d: debug mode\n");
194 fprintf(stderr, " C: disable version checking\n");
195 fprintf(stderr, " F: turn off fsync\n");
196 fprintf(stderr, " O: set BootstrapProcessing mode\n");
197 fprintf(stderr, " P portno: specify port number\n");
205 BootstrapMain(int argc, char *argv[])
206 /* ----------------------------------------------------------------
207 * The main loop for handling the backend in bootstrap mode
208 * the bootstrap mode is used to initialize the template database
209 * the bootstrap backend doesn't speak SQL, but instead expects
210 * commands in a special bootstrap language.
212 * The arguments passed in to BootstrapMain are the run-time arguments
213 * without the argument '-boot', the caller is required to have
214 * removed -boot from the run-time args
215 * ----------------------------------------------------------------
221 int xlogop = BS_XLOG_NOP;
222 char *potential_DataDir = NULL;
224 /* --------------------
226 * -------------------
229 MyProcPid = getpid();
232 * Fire up essential subsystems: error and memory management
234 * If we are running under the postmaster, this is done already.
236 if (!IsUnderPostmaster)
238 EnableExceptionHandling(true);
243 * process command arguments
247 /* Set defaults, to be overriden by explicit options below */
251 if (!IsUnderPostmaster)
254 potential_DataDir = getenv("PGDATA"); /* Null if no PGDATA variable */
257 while ((flag = getopt(argc, argv, "D:dCQx:pB:F")) != EOF)
262 potential_DataDir = optarg;
265 DebugMode = true; /* print out debugging info while
278 xlogop = atoi(optarg);
281 /* indicates fork from postmaster */
284 NBuffers = atoi(optarg);
292 if (argc - optind > 1)
294 else if (argc - optind == 1)
295 dbName = argv[optind];
297 SetProcessingMode(BootstrapProcessing);
298 IgnoreSystemIndexes(true);
300 if (!IsUnderPostmaster)
302 if (!potential_DataDir)
304 fprintf(stderr, "%s does not know where to find the database system "
305 "data. You must specify the directory that contains the "
306 "database system either by specifying the -D invocation "
307 "option or by setting the PGDATA environment variable.\n\n",
311 SetDataDir(potential_DataDir);
317 dbName = getenv("USER");
320 fputs("bootstrap backend: failed, no db name specified\n", stderr);
321 fputs(" and no USER enviroment variable\n", stderr);
330 if (!IsUnderPostmaster)
332 pqsignal(SIGINT, (pqsigfunc) die);
333 pqsignal(SIGHUP, (pqsigfunc) die);
334 pqsignal(SIGTERM, (pqsigfunc) die);
340 SetProcessingMode(NormalProcessing);
341 if (xlogop == BS_XLOG_NOP)
343 else if (xlogop == BS_XLOG_BOOTSTRAP)
350 if (xlogop == BS_XLOG_CHECKPOINT)
353 CreateCheckPoint(false);
356 else if (xlogop == BS_XLOG_STARTUP)
358 else if (xlogop == BS_XLOG_SHUTDOWN)
361 elog(STOP, "Unsupported XLOG op %d", xlogop);
364 SetProcessingMode(BootstrapProcessing);
367 * backend initialization
369 InitPostgres(dbName, NULL);
372 for (i = 0; i < MAXATTR; i++)
374 attrtypes[i] = (Form_pg_attribute) NULL;
377 for (i = 0; i < STRTABLESIZE; ++i)
379 for (i = 0; i < HASHTABLESIZE; ++i)
383 * abort processing resumes here
386 pqsignal(SIGHUP, handle_warn);
388 if (sigsetjmp(Warn_restart, 1) != 0)
391 AbortCurrentTransaction();
400 * the sed script boot.sed renamed yyparse to Int_yyparse for the
401 * bootstrap parser to avoid conflicts with the normal SQL parser
405 SetProcessingMode(NormalProcessing);
406 CreateCheckPoint(true);
407 SetProcessingMode(BootstrapProcessing);
409 /* clean up processing */
410 StartTransactionCommand();
413 /* not reached, here to make compiler happy */
418 /* ----------------------------------------------------------------
419 * MANUAL BACKEND INTERACTIVE INTERFACE COMMANDS
420 * ----------------------------------------------------------------
428 boot_openrel(char *relname)
436 if (strlen(relname) >= NAMEDATALEN - 1)
437 relname[NAMEDATALEN - 1] = '\0';
439 if (Typ == (struct typmap **) NULL)
441 rel = heap_openr(TypeRelationName, NoLock);
442 scan = heap_beginscan(rel, 0, SnapshotNow, 0, (ScanKey) NULL);
444 while (HeapTupleIsValid(tup = heap_getnext(scan, 0)))
447 app = Typ = ALLOC(struct typmap *, i + 1);
449 *app++ = ALLOC(struct typmap, 1);
450 *app = (struct typmap *) NULL;
451 scan = heap_beginscan(rel, 0, SnapshotNow, 0, (ScanKey) NULL);
453 while (HeapTupleIsValid(tup = heap_getnext(scan, 0)))
455 (*app)->am_oid = tup->t_data->t_oid;
456 memcpy((char *) &(*app)->am_typ,
457 (char *) GETSTRUCT(tup),
458 sizeof((*app)->am_typ));
462 heap_close(rel, NoLock);
469 printf("Amopen: relation %s. attrsize %d\n", relname ? relname : "(null)",
470 (int) ATTRIBUTE_TUPLE_SIZE);
472 reldesc = heap_openr(relname, NoLock);
473 numattr = reldesc->rd_rel->relnatts;
474 for (i = 0; i < numattr; i++)
476 if (attrtypes[i] == NULL)
477 attrtypes[i] = AllocateAttribute();
478 memmove((char *) attrtypes[i],
479 (char *) reldesc->rd_att->attrs[i],
480 ATTRIBUTE_TUPLE_SIZE);
482 /* Some old pg_attribute tuples might not have attisset. */
485 * If the attname is attisset, don't look for it - it may not be
488 if (namestrcmp(&attrtypes[i]->attname, "attisset") == 0)
489 attrtypes[i]->attisset = get_attisset(RelationGetRelid(reldesc),
490 NameStr(attrtypes[i]->attname));
492 attrtypes[i]->attisset = false;
496 Form_pg_attribute at = attrtypes[i];
498 printf("create attribute %d name %s len %d num %d type %d\n",
499 i, NameStr(at->attname), at->attlen, at->attnum,
518 if (strcmp(RelationGetRelationName(reldesc), name) != 0)
519 elog(ERROR, "closerel: close of '%s' when '%s' was expected",
520 name, relname ? relname : "(null)");
523 elog(ERROR, "closerel: close of '%s' before any relation was opened",
529 elog(ERROR, "Warning: no opened relation to close.\n");
533 printf("Amclose: relation %s.\n", relname ? relname : "(null)");
534 heap_close(reldesc, NoLock);
535 reldesc = (Relation) NULL;
544 * define a <field,type> pair
545 * if there are n fields in a relation to be created, this routine
546 * will be called n times
550 DefineAttr(char *name, char *type, int attnum)
557 fputs("Warning: no open relations allowed with 't' command.\n", stderr);
561 typeoid = gettype(type);
562 if (attrtypes[attnum] == (Form_pg_attribute) NULL)
563 attrtypes[attnum] = AllocateAttribute();
564 if (Typ != (struct typmap **) NULL)
566 attrtypes[attnum]->atttypid = Ap->am_oid;
567 namestrcpy(&attrtypes[attnum]->attname, name);
569 printf("<%s %s> ", NameStr(attrtypes[attnum]->attname), type);
570 attrtypes[attnum]->attnum = 1 + attnum; /* fillatt */
571 attlen = attrtypes[attnum]->attlen = Ap->am_typ.typlen;
572 attrtypes[attnum]->attbyval = Ap->am_typ.typbyval;
573 attrtypes[attnum]->attstorage = Ap->am_typ.typstorage;;
574 attrtypes[attnum]->attalign = Ap->am_typ.typalign;
578 attrtypes[attnum]->atttypid = Procid[typeoid].oid;
579 namestrcpy(&attrtypes[attnum]->attname, name);
581 printf("<%s %s> ", NameStr(attrtypes[attnum]->attname), type);
582 attrtypes[attnum]->attnum = 1 + attnum; /* fillatt */
583 attlen = attrtypes[attnum]->attlen = Procid[typeoid].len;
584 attrtypes[attnum]->attstorage = 'p';
587 * Cheat like mad to fill in these items from the length only.
588 * This only has to work for types used in the system catalogs...
593 attrtypes[attnum]->attbyval = true;
594 attrtypes[attnum]->attalign = 'c';
597 attrtypes[attnum]->attbyval = true;
598 attrtypes[attnum]->attalign = 's';
601 attrtypes[attnum]->attbyval = true;
602 attrtypes[attnum]->attalign = 'i';
605 attrtypes[attnum]->attbyval = false;
606 attrtypes[attnum]->attalign = 'i';
610 attrtypes[attnum]->attcacheoff = -1;
611 attrtypes[attnum]->atttypmod = -1;
617 * assumes that 'oid' will not be zero.
621 InsertOneTuple(Oid objectid)
630 printf("InsertOneTuple oid %u, %d attrs\n", objectid, numattr);
634 tupDesc = CreateTupleDesc(numattr, attrtypes);
635 tuple = heap_formtuple(tupDesc, values, Blanks);
636 pfree(tupDesc); /* just free's tupDesc, not the attrtypes */
638 if (objectid != (Oid) 0)
639 tuple->t_data->t_oid = objectid;
640 heap_insert(reldesc, tuple);
641 heap_freetuple(tuple);
644 printf("End InsertOneTuple, objectid=%u\n", objectid);
649 * Reset blanks for next tuple
651 for (i = 0; i < numattr; i++)
660 InsertOneValue(Oid objectid, char *value, int i)
667 printf("Inserting value: '%s'\n", value);
668 if (i < 0 || i >= MAXATTR)
670 printf("i out of range: %d\n", i);
674 if (Typ != (struct typmap **) NULL)
681 while (*app && (*app)->am_oid != reldesc->rd_att->attrs[i]->atttypid)
686 printf("Unable to find atttypid in Typ list! %u\n",
687 reldesc->rd_att->attrs[i]->atttypid
691 values[i] = OidFunctionCall3(ap->am_typ.typinput,
692 CStringGetDatum(value),
693 ObjectIdGetDatum(ap->am_typ.typelem),
695 prt = DatumGetCString(OidFunctionCall3(ap->am_typ.typoutput,
697 ObjectIdGetDatum(ap->am_typ.typelem),
705 for (typeindex = 0; typeindex < n_types; typeindex++)
707 if (Procid[typeindex].oid == attrtypes[i]->atttypid)
710 if (typeindex >= n_types)
711 elog(ERROR, "can't find type OID %u", attrtypes[i]->atttypid);
713 printf("Typ == NULL, typeindex = %u idx = %d\n", typeindex, i);
714 values[i] = OidFunctionCall3(Procid[typeindex].inproc,
715 CStringGetDatum(value),
716 ObjectIdGetDatum(Procid[typeindex].elem),
718 prt = DatumGetCString(OidFunctionCall3(Procid[typeindex].outproc,
720 ObjectIdGetDatum(Procid[typeindex].elem),
728 puts("End InsertValue");
741 printf("Inserting null\n");
742 if (i < 0 || i >= MAXATTR)
743 elog(FATAL, "i out of range (too many attrs): %d\n", i);
744 values[i] = PointerGetDatum(NULL);
748 #define MORE_THAN_THE_NUMBER_OF_CATALOGS 256
751 BootstrapAlreadySeen(Oid id)
753 static Oid seenArray[MORE_THAN_THE_NUMBER_OF_CATALOGS];
754 static int nseen = 0;
760 for (i = 0; i < nseen; i++)
762 if (seenArray[i] == id)
770 seenArray[nseen] = id;
783 static int beenhere = 0;
789 elog(FATAL, "Memory manager fault: cleanup called twice.\n");
792 if (reldesc != (Relation) NULL)
793 heap_close(reldesc, NoLock);
794 CommitTransactionCommand();
811 if (Typ != (struct typmap **) NULL)
813 for (app = Typ; *app != (struct typmap *) NULL; app++)
815 if (strncmp(NameStr((*app)->am_typ.typname), type, NAMEDATALEN) == 0)
818 return (*app)->am_oid;
824 for (i = 0; i <= n_types; i++)
826 if (strncmp(type, Procid[i].name, NAMEDATALEN) == 0)
830 printf("bootstrap.c: External Type: %s\n", type);
831 rel = heap_openr(TypeRelationName, NoLock);
832 scan = heap_beginscan(rel, 0, SnapshotNow, 0, (ScanKey) NULL);
834 while (HeapTupleIsValid(tup = heap_getnext(scan, 0)))
837 app = Typ = ALLOC(struct typmap *, i + 1);
839 *app++ = ALLOC(struct typmap, 1);
840 *app = (struct typmap *) NULL;
841 scan = heap_beginscan(rel, 0, SnapshotNow, 0, (ScanKey) NULL);
843 while (HeapTupleIsValid(tup = heap_getnext(scan, 0)))
845 (*app)->am_oid = tup->t_data->t_oid;
846 memmove((char *) &(*app++)->am_typ,
847 (char *) GETSTRUCT(tup),
848 sizeof((*app)->am_typ));
851 heap_close(rel, NoLock);
852 return gettype(type);
854 elog(ERROR, "Error: unknown type '%s'.\n", type);
856 /* not reached, here to make compiler happy */
864 static Form_pg_attribute /* XXX */
867 Form_pg_attribute attribute = (Form_pg_attribute) malloc(ATTRIBUTE_TUPLE_SIZE);
869 if (!PointerIsValid(attribute))
870 elog(FATAL, "AllocateAttribute: malloc failed");
871 MemSet(attribute, 0, ATTRIBUTE_TUPLE_SIZE);
878 * XXX arrays of "basetype" are always "_basetype".
879 * this is an evil hack inherited from rel. 3.1.
880 * XXX array dimension is thrown away because we
881 * don't support fixed-dimension arrays. again,
884 * the string passed in must have a '[' character in it
886 * the string returned is a pointer to static storage and should NOT
887 * be freed by the CALLER.
891 MapArrayTypeName(char *s)
895 static char newStr[NAMEDATALEN]; /* array type names < NAMEDATALEN
898 if (s == NULL || s[0] == '\0')
903 for (i = 0; i < NAMEDATALEN - 1 && s[i] != '['; i++, j++)
913 * returns the string table position of the identifier
914 * passed to it. We add it to the table if we can't find it.
918 EnterString(char *str)
925 node = FindStr(str, len, 0);
930 node = AddStr(str, len, 0);
937 * when given an idnum into the 'string-table' return the string
938 * associated with the idnum
942 LexIDStr(int ident_num)
944 return strtable[ident_num];
951 * Compute a hash function for a given string. We look at the first,
952 * the last, and the middle character of a string to try to get spread
953 * the strings out. The function is rather arbitrary, except that we
954 * are mod'ing by a prime number.
958 CompHash(char *str, int len)
962 result = (NUM * str[0] + NUMSQR * str[len - 1] + NUMCUBE * str[(len - 1) / 2]);
964 return result % HASHTABLESIZE;
971 * This routine looks for the specified string in the hash
972 * table. It returns a pointer to the hash node found,
973 * or NULL if the string is not in the table.
977 FindStr(char *str, int length, hashnode *mderef)
981 node = hashtable[CompHash(str, length)];
986 * We must differentiate between string constants that might have
987 * the same value as a identifier and the identifier itself.
989 if (!strcmp(str, strtable[node->strnum]))
991 return node; /* no need to check */
996 /* Couldn't find it in the list */
1003 * This function adds the specified string, along with its associated
1004 * data, to the hash table and the string table. We return the node
1005 * so that the calling routine can find out the unique id that AddStr
1006 * has assigned to this string.
1010 AddStr(char *str, int strlength, int mderef)
1018 if (++strtable_end == STRTABLESIZE)
1020 /* Error, string table overflow, so we Punt */
1022 "There are too many string constants and identifiers for the compiler to handle.");
1028 * Some of the utilites (eg, define type, create relation) assume that
1029 * the string they're passed is a NAMEDATALEN. We get array bound
1030 * read violations from purify if we don't allocate at least
1031 * NAMEDATALEN bytes for strings of this sort. Because we're lazy, we
1032 * allocate at least NAMEDATALEN bytes all the time.
1035 if ((len = strlength + 1) < NAMEDATALEN)
1038 strtable[strtable_end] = malloc((unsigned) len);
1039 strcpy(strtable[strtable_end], str);
1041 /* Now put a node in the hash table */
1043 newnode = (hashnode *) malloc(sizeof(hashnode) * 1);
1044 newnode->strnum = strtable_end;
1045 newnode->next = NULL;
1047 /* Find out where it goes */
1049 hashresult = CompHash(str, strlength);
1050 if (hashtable[hashresult] == NULL)
1051 hashtable[hashresult] = newnode;
1053 { /* There is something in the list */
1054 trail = hashtable[hashresult];
1056 while (temp != NULL)
1061 trail->next = newnode;
1069 * index_register() -- record an index that has been set up for building
1072 * At bootstrap time, we define a bunch of indices on system catalogs.
1073 * We postpone actually building the indices until just before we're
1074 * finished with initialization, however. This is because more classes
1075 * and indices may be defined, and we want to be sure that all of them
1076 * are present in the index.
1079 index_register(char *heap,
1081 IndexInfo *indexInfo)
1084 MemoryContext oldcxt;
1087 * XXX mao 10/31/92 -- don't gc index reldescs, associated info at
1088 * bootstrap time. we'll declare the indices now, but want to create
1093 nogc = AllocSetContextCreate((MemoryContext) NULL,
1095 ALLOCSET_DEFAULT_MINSIZE,
1096 ALLOCSET_DEFAULT_INITSIZE,
1097 ALLOCSET_DEFAULT_MAXSIZE);
1099 oldcxt = MemoryContextSwitchTo(nogc);
1101 newind = (IndexList *) palloc(sizeof(IndexList));
1102 newind->il_heap = pstrdup(heap);
1103 newind->il_ind = pstrdup(ind);
1104 newind->il_info = (IndexInfo *) palloc(sizeof(IndexInfo));
1106 memcpy(newind->il_info, indexInfo, sizeof(IndexInfo));
1107 /* predicate will likely be null anyway, but may as well copy it */
1108 newind->il_info->ii_Predicate = copyObject(indexInfo->ii_Predicate);
1110 newind->il_next = ILHead;
1113 MemoryContextSwitchTo(oldcxt);
1119 for (; ILHead != (IndexList *) NULL; ILHead = ILHead->il_next)
1124 heap = heap_openr(ILHead->il_heap, NoLock);
1125 ind = index_openr(ILHead->il_ind);
1126 index_build(heap, ind, ILHead->il_info, NULL);
1129 * In normal processing mode, index_build would close the heap and
1130 * index, but in bootstrap mode it will not.
1134 * All of the rest of this routine is needed only because in
1135 * bootstrap processing we don't increment xact id's. The normal
1136 * DefineIndex code replaces a pg_class tuple with updated info
1137 * including the relhasindex flag (which we need to have updated).
1138 * Unfortunately, there are always two indices defined on each
1139 * catalog causing us to update the same pg_class tuple twice for
1140 * each catalog getting an index during bootstrap resulting in the
1141 * ghost tuple problem (see heap_update). To get around this we
1142 * change the relhasindex field ourselves in this routine keeping
1143 * track of what catalogs we already changed so that we don't
1144 * modify those tuples twice. The normal mechanism for updating
1145 * pg_class is disabled during bootstrap.
1149 if (!BootstrapAlreadySeen(RelationGetRelid(heap)))
1150 UpdateStats(RelationGetRelid(heap), 0);
1152 /* XXX Probably we ought to close the heap and index here? */