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-2001, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
11 * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.121 2002/02/23 01:31:34 petere Exp $
13 *-------------------------------------------------------------------------
25 #define BOOTSTRAP_INCLUDE /* mask out stuff in tcop/tcopprot.h */
27 #include "access/genam.h"
28 #include "access/heapam.h"
29 #include "access/xlog.h"
30 #include "bootstrap/bootstrap.h"
31 #include "catalog/catname.h"
32 #include "catalog/index.h"
33 #include "catalog/pg_type.h"
34 #include "libpq/pqsignal.h"
35 #include "miscadmin.h"
36 #include "storage/proc.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 */
151 * At bootstrap time, we first declare all the indices to be built, and
152 * then build them. The IndexList structure stores enough information
153 * to allow us to build the indices after they've been declared.
156 typedef struct _IndexList
161 struct _IndexList *il_next;
164 static IndexList *ILHead = (IndexList *) NULL;
167 /* ----------------------------------------------------------------
169 * ----------------------------------------------------------------
173 * error handling / abort routines
184 usage help for the bootstrap backen
191 " postgres -boot [-d] [-D datadir] [-F] [-o file] [-x num] dbname\n"
193 " -D datadir data directory\n"
194 " -F turn off fsync\n"
195 " -o file send debug output to file\n"
196 " -x num internal use\n"));
204 BootstrapMain(int argc, char *argv[])
205 /* ----------------------------------------------------------------
206 * The main loop for handling the backend in bootstrap mode
207 * the bootstrap mode is used to initialize the template database
208 * the bootstrap backend doesn't speak SQL, but instead expects
209 * commands in a special bootstrap language.
211 * The arguments passed in to BootstrapMain are the run-time arguments
212 * without the argument '-boot', the caller is required to have
213 * removed -boot from the run-time args
214 * ----------------------------------------------------------------
220 int xlogop = BS_XLOG_NOP;
221 char *potential_DataDir = NULL;
227 MyProcPid = getpid();
230 * Fire up essential subsystems: error and memory management
232 * If we are running under the postmaster, this is done already.
234 if (!IsUnderPostmaster)
236 EnableExceptionHandling(true);
241 * process command arguments
244 /* Set defaults, to be overriden by explicit options below */
246 if (!IsUnderPostmaster)
248 ResetAllOptions(true);
249 potential_DataDir = getenv("PGDATA"); /* Null if no PGDATA
253 while ((flag = getopt(argc, argv, "B:dD:Fo:px:")) != -1)
258 potential_DataDir = optarg;
261 DebugMode = true; /* print out debugging info while
265 SetConfigOption("fsync", "false", PGC_POSTMASTER, PGC_S_ARGV);
268 StrNCpy(OutputFileName, optarg, MAXPGPATH);
271 xlogop = atoi(optarg);
274 /* indicates fork from postmaster */
277 SetConfigOption("shared_buffers", optarg, PGC_POSTMASTER, PGC_S_ARGV);
285 if (argc - optind != 1)
288 dbName = argv[optind];
292 if (!IsUnderPostmaster)
294 if (!potential_DataDir)
297 gettext("%s does not know where to find the database system data.\n"
298 "You must specify the directory that contains the database system\n"
299 "either by specifying the -D invocation option or by setting the\n"
300 "PGDATA environment variable.\n\n"),
304 SetDataDir(potential_DataDir);
307 /* Validate we have been given a reasonable-looking DataDir */
309 ValidatePgVersion(DataDir);
311 if (IsUnderPostmaster)
314 * Properly accept or ignore signals the postmaster might send us
316 pqsignal(SIGHUP, SIG_IGN);
317 pqsignal(SIGINT, SIG_IGN); /* ignore query-cancel */
318 pqsignal(SIGTERM, die);
319 pqsignal(SIGQUIT, quickdie);
320 pqsignal(SIGALRM, SIG_IGN);
321 pqsignal(SIGPIPE, SIG_IGN);
322 pqsignal(SIGUSR1, SIG_IGN);
323 pqsignal(SIGUSR2, SIG_IGN);
326 * Reset some signals that are accepted by postmaster but not here
328 pqsignal(SIGCHLD, SIG_DFL);
329 pqsignal(SIGTTIN, SIG_DFL);
330 pqsignal(SIGTTOU, SIG_DFL);
331 pqsignal(SIGCONT, SIG_DFL);
332 pqsignal(SIGWINCH, SIG_DFL);
335 * Unblock signals (they were blocked when the postmaster forked
338 PG_SETMASK(&UnBlockSig);
342 /* Set up appropriately for interactive use */
343 pqsignal(SIGHUP, die);
344 pqsignal(SIGINT, die);
345 pqsignal(SIGTERM, die);
346 pqsignal(SIGQUIT, die);
349 * Create lockfile for data directory.
351 if (!CreateDataDirLockFile(DataDir, false))
355 SetProcessingMode(BootstrapProcessing);
356 IgnoreSystemIndexes(true);
365 SetProcessingMode(NormalProcessing);
373 case BS_XLOG_BOOTSTRAP:
378 case BS_XLOG_CHECKPOINT:
379 if (IsUnderPostmaster)
380 InitDummyProcess(); /* needed to get LWLocks */
382 CreateCheckPoint(false);
384 proc_exit(0); /* done */
386 case BS_XLOG_STARTUP:
388 proc_exit(0); /* done */
390 case BS_XLOG_SHUTDOWN:
392 proc_exit(0); /* done */
395 elog(STOP, "Unsupported XLOG op %d", xlogop);
399 SetProcessingMode(BootstrapProcessing);
402 * backend initialization
404 InitPostgres(dbName, NULL);
406 for (i = 0; i < MAXATTR; i++)
408 attrtypes[i] = (Form_pg_attribute) NULL;
411 for (i = 0; i < STRTABLESIZE; ++i)
413 for (i = 0; i < HASHTABLESIZE; ++i)
417 * abort processing resumes here
419 if (sigsetjmp(Warn_restart, 1) != 0)
422 AbortCurrentTransaction();
430 * the sed script boot.sed renamed yyparse to Int_yyparse for the
431 * bootstrap parser to avoid conflicts with the normal SQL parser
435 SetProcessingMode(NormalProcessing);
436 CreateCheckPoint(true);
437 SetProcessingMode(BootstrapProcessing);
439 /* clean up processing */
440 StartTransactionCommand();
443 /* not reached, here to make compiler happy */
448 /* ----------------------------------------------------------------
449 * MANUAL BACKEND INTERACTIVE INTERFACE COMMANDS
450 * ----------------------------------------------------------------
458 boot_openrel(char *relname)
466 if (strlen(relname) >= NAMEDATALEN - 1)
467 relname[NAMEDATALEN - 1] = '\0';
469 if (Typ == (struct typmap **) NULL)
471 rel = heap_openr(TypeRelationName, NoLock);
472 scan = heap_beginscan(rel, 0, SnapshotNow, 0, (ScanKey) NULL);
474 while (HeapTupleIsValid(tup = heap_getnext(scan, 0)))
477 app = Typ = ALLOC(struct typmap *, i + 1);
479 *app++ = ALLOC(struct typmap, 1);
480 *app = (struct typmap *) NULL;
481 scan = heap_beginscan(rel, 0, SnapshotNow, 0, (ScanKey) NULL);
483 while (HeapTupleIsValid(tup = heap_getnext(scan, 0)))
485 (*app)->am_oid = tup->t_data->t_oid;
486 memcpy((char *) &(*app)->am_typ,
487 (char *) GETSTRUCT(tup),
488 sizeof((*app)->am_typ));
492 heap_close(rel, NoLock);
499 elog(DEBUG, "open relation %s, attrsize %d", relname ? relname : "(null)",
500 (int) ATTRIBUTE_TUPLE_SIZE);
502 reldesc = heap_openr(relname, NoLock);
503 numattr = reldesc->rd_rel->relnatts;
504 for (i = 0; i < numattr; i++)
506 if (attrtypes[i] == NULL)
507 attrtypes[i] = AllocateAttribute();
508 memmove((char *) attrtypes[i],
509 (char *) reldesc->rd_att->attrs[i],
510 ATTRIBUTE_TUPLE_SIZE);
512 /* Some old pg_attribute tuples might not have attisset. */
515 * If the attname is attisset, don't look for it - it may not be
518 if (namestrcmp(&attrtypes[i]->attname, "attisset") == 0)
519 attrtypes[i]->attisset = get_attisset(RelationGetRelid(reldesc),
520 NameStr(attrtypes[i]->attname));
522 attrtypes[i]->attisset = false;
526 Form_pg_attribute at = attrtypes[i];
528 elog(DEBUG, "create attribute %d name %s len %d num %d type %u",
529 i, NameStr(at->attname), at->attlen, at->attnum,
547 if (strcmp(RelationGetRelationName(reldesc), name) != 0)
548 elog(ERROR, "closerel: close of '%s' when '%s' was expected",
549 name, relname ? relname : "(null)");
552 elog(ERROR, "closerel: close of '%s' before any relation was opened",
558 elog(ERROR, "no open relation to close");
562 elog(DEBUG, "close relation %s", relname ? relname : "(null)");
563 heap_close(reldesc, NoLock);
564 reldesc = (Relation) NULL;
573 * define a <field,type> pair
574 * if there are n fields in a relation to be created, this routine
575 * will be called n times
579 DefineAttr(char *name, char *type, int attnum)
586 elog(DEBUG, "warning: no open relations allowed with 'create' command");
590 typeoid = gettype(type);
591 if (attrtypes[attnum] == (Form_pg_attribute) NULL)
592 attrtypes[attnum] = AllocateAttribute();
593 if (Typ != (struct typmap **) NULL)
595 attrtypes[attnum]->atttypid = Ap->am_oid;
596 namestrcpy(&attrtypes[attnum]->attname, name);
598 elog(DEBUG, "column %s %s", NameStr(attrtypes[attnum]->attname), type);
599 attrtypes[attnum]->attnum = 1 + attnum; /* fillatt */
600 attlen = attrtypes[attnum]->attlen = Ap->am_typ.typlen;
601 attrtypes[attnum]->attbyval = Ap->am_typ.typbyval;
602 attrtypes[attnum]->attstorage = Ap->am_typ.typstorage;;
603 attrtypes[attnum]->attalign = Ap->am_typ.typalign;
607 attrtypes[attnum]->atttypid = Procid[typeoid].oid;
608 namestrcpy(&attrtypes[attnum]->attname, name);
610 elog(DEBUG, "column %s %s", NameStr(attrtypes[attnum]->attname), type);
611 attrtypes[attnum]->attnum = 1 + attnum; /* fillatt */
612 attlen = attrtypes[attnum]->attlen = Procid[typeoid].len;
613 attrtypes[attnum]->attstorage = 'p';
616 * Cheat like mad to fill in these items from the length only.
617 * This only has to work for types used in the system catalogs...
622 attrtypes[attnum]->attbyval = true;
623 attrtypes[attnum]->attalign = 'c';
626 attrtypes[attnum]->attbyval = true;
627 attrtypes[attnum]->attalign = 's';
630 attrtypes[attnum]->attbyval = true;
631 attrtypes[attnum]->attalign = 'i';
634 attrtypes[attnum]->attbyval = false;
635 attrtypes[attnum]->attalign = 'i';
639 attrtypes[attnum]->attcacheoff = -1;
640 attrtypes[attnum]->atttypmod = -1;
647 * If objectid is not zero, it is a specific OID to assign to the tuple.
648 * Otherwise, an OID will be assigned (if necessary) by heap_insert.
652 InsertOneTuple(Oid objectid)
659 elog(DEBUG, "inserting row oid %u, %d columns", objectid, numattr);
661 tupDesc = CreateTupleDesc(numattr, attrtypes);
662 tuple = heap_formtuple(tupDesc, values, Blanks);
663 pfree(tupDesc); /* just free's tupDesc, not the attrtypes */
665 if (objectid != (Oid) 0)
666 tuple->t_data->t_oid = objectid;
667 heap_insert(reldesc, tuple);
668 heap_freetuple(tuple);
670 elog(DEBUG, "row inserted");
673 * Reset blanks for next tuple
675 for (i = 0; i < numattr; i++)
684 InsertOneValue(char *value, int i)
690 AssertArg(i >= 0 || i < MAXATTR);
693 elog(DEBUG, "inserting column %d value '%s'", i, value);
695 if (Typ != (struct typmap **) NULL)
700 elog(DEBUG, "Typ != NULL");
702 while (*app && (*app)->am_oid != reldesc->rd_att->attrs[i]->atttypid)
707 elog(FATAL, "unable to find atttypid %u in Typ list",
708 reldesc->rd_att->attrs[i]->atttypid);
710 values[i] = OidFunctionCall3(ap->am_typ.typinput,
711 CStringGetDatum(value),
712 ObjectIdGetDatum(ap->am_typ.typelem),
714 prt = DatumGetCString(OidFunctionCall3(ap->am_typ.typoutput,
716 ObjectIdGetDatum(ap->am_typ.typelem),
719 elog(DEBUG, " -> %s", prt);
724 for (typeindex = 0; typeindex < n_types; typeindex++)
726 if (Procid[typeindex].oid == attrtypes[i]->atttypid)
729 if (typeindex >= n_types)
730 elog(ERROR, "type oid %u not found", attrtypes[i]->atttypid);
732 elog(DEBUG, "Typ == NULL, typeindex = %u", typeindex);
733 values[i] = OidFunctionCall3(Procid[typeindex].inproc,
734 CStringGetDatum(value),
735 ObjectIdGetDatum(Procid[typeindex].elem),
737 prt = DatumGetCString(OidFunctionCall3(Procid[typeindex].outproc,
739 ObjectIdGetDatum(Procid[typeindex].elem),
742 elog(DEBUG, " -> %s", prt);
746 elog(DEBUG, "inserted");
757 elog(DEBUG, "inserting column %d NULL", i);
758 Assert(i >= 0 || i < MAXATTR);
759 values[i] = PointerGetDatum(NULL);
763 #define MORE_THAN_THE_NUMBER_OF_CATALOGS 256
766 BootstrapAlreadySeen(Oid id)
768 static Oid seenArray[MORE_THAN_THE_NUMBER_OF_CATALOGS];
769 static int nseen = 0;
775 for (i = 0; i < nseen; i++)
777 if (seenArray[i] == id)
785 seenArray[nseen] = id;
798 static int beenhere = 0;
804 elog(FATAL, "Memory manager fault: cleanup called twice.\n");
807 if (reldesc != (Relation) NULL)
808 heap_close(reldesc, NoLock);
809 CommitTransactionCommand();
826 if (Typ != (struct typmap **) NULL)
828 for (app = Typ; *app != (struct typmap *) NULL; app++)
830 if (strncmp(NameStr((*app)->am_typ.typname), type, NAMEDATALEN) == 0)
833 return (*app)->am_oid;
839 for (i = 0; i <= n_types; i++)
841 if (strncmp(type, Procid[i].name, NAMEDATALEN) == 0)
845 elog(DEBUG, "external type: %s", type);
846 rel = heap_openr(TypeRelationName, NoLock);
847 scan = heap_beginscan(rel, 0, SnapshotNow, 0, (ScanKey) NULL);
849 while (HeapTupleIsValid(tup = heap_getnext(scan, 0)))
852 app = Typ = ALLOC(struct typmap *, i + 1);
854 *app++ = ALLOC(struct typmap, 1);
855 *app = (struct typmap *) NULL;
856 scan = heap_beginscan(rel, 0, SnapshotNow, 0, (ScanKey) NULL);
858 while (HeapTupleIsValid(tup = heap_getnext(scan, 0)))
860 (*app)->am_oid = tup->t_data->t_oid;
861 memmove((char *) &(*app++)->am_typ,
862 (char *) GETSTRUCT(tup),
863 sizeof((*app)->am_typ));
866 heap_close(rel, NoLock);
867 return gettype(type);
869 elog(ERROR, "Error: unknown type '%s'.\n", type);
871 /* not reached, here to make compiler happy */
879 static Form_pg_attribute /* XXX */
882 Form_pg_attribute attribute = (Form_pg_attribute) malloc(ATTRIBUTE_TUPLE_SIZE);
884 if (!PointerIsValid(attribute))
885 elog(FATAL, "AllocateAttribute: malloc failed");
886 MemSet(attribute, 0, ATTRIBUTE_TUPLE_SIZE);
893 * XXX arrays of "basetype" are always "_basetype".
894 * this is an evil hack inherited from rel. 3.1.
895 * XXX array dimension is thrown away because we
896 * don't support fixed-dimension arrays. again,
899 * the string passed in must have a '[' character in it
901 * the string returned is a pointer to static storage and should NOT
902 * be freed by the CALLER.
906 MapArrayTypeName(char *s)
910 static char newStr[NAMEDATALEN]; /* array type names < NAMEDATALEN
913 if (s == NULL || s[0] == '\0')
918 for (i = 0; i < NAMEDATALEN - 1 && s[i] != '['; i++, j++)
928 * returns the string table position of the identifier
929 * passed to it. We add it to the table if we can't find it.
933 EnterString(char *str)
940 node = FindStr(str, len, 0);
945 node = AddStr(str, len, 0);
952 * when given an idnum into the 'string-table' return the string
953 * associated with the idnum
957 LexIDStr(int ident_num)
959 return strtable[ident_num];
966 * Compute a hash function for a given string. We look at the first,
967 * the last, and the middle character of a string to try to get spread
968 * the strings out. The function is rather arbitrary, except that we
969 * are mod'ing by a prime number.
973 CompHash(char *str, int len)
977 result = (NUM * str[0] + NUMSQR * str[len - 1] + NUMCUBE * str[(len - 1) / 2]);
979 return result % HASHTABLESIZE;
986 * This routine looks for the specified string in the hash
987 * table. It returns a pointer to the hash node found,
988 * or NULL if the string is not in the table.
992 FindStr(char *str, int length, hashnode *mderef)
996 node = hashtable[CompHash(str, length)];
1000 * We must differentiate between string constants that might have
1001 * the same value as a identifier and the identifier itself.
1003 if (!strcmp(str, strtable[node->strnum]))
1005 return node; /* no need to check */
1010 /* Couldn't find it in the list */
1017 * This function adds the specified string, along with its associated
1018 * data, to the hash table and the string table. We return the node
1019 * so that the calling routine can find out the unique id that AddStr
1020 * has assigned to this string.
1024 AddStr(char *str, int strlength, int mderef)
1032 if (++strtable_end == STRTABLESIZE)
1034 /* Error, string table overflow, so we Punt */
1036 "There are too many string constants and identifiers for the compiler to handle.");
1042 * Some of the utilites (eg, define type, create relation) assume that
1043 * the string they're passed is a NAMEDATALEN. We get array bound
1044 * read violations from purify if we don't allocate at least
1045 * NAMEDATALEN bytes for strings of this sort. Because we're lazy, we
1046 * allocate at least NAMEDATALEN bytes all the time.
1049 if ((len = strlength + 1) < NAMEDATALEN)
1052 strtable[strtable_end] = malloc((unsigned) len);
1053 strcpy(strtable[strtable_end], str);
1055 /* Now put a node in the hash table */
1057 newnode = (hashnode *) malloc(sizeof(hashnode) * 1);
1058 newnode->strnum = strtable_end;
1059 newnode->next = NULL;
1061 /* Find out where it goes */
1063 hashresult = CompHash(str, strlength);
1064 if (hashtable[hashresult] == NULL)
1065 hashtable[hashresult] = newnode;
1067 { /* There is something in the list */
1068 trail = hashtable[hashresult];
1070 while (temp != NULL)
1075 trail->next = newnode;
1083 * index_register() -- record an index that has been set up for building
1086 * At bootstrap time, we define a bunch of indices on system catalogs.
1087 * We postpone actually building the indices until just before we're
1088 * finished with initialization, however. This is because more classes
1089 * and indices may be defined, and we want to be sure that all of them
1090 * are present in the index.
1093 index_register(char *heap,
1095 IndexInfo *indexInfo)
1098 MemoryContext oldcxt;
1101 * XXX mao 10/31/92 -- don't gc index reldescs, associated info at
1102 * bootstrap time. we'll declare the indices now, but want to create
1107 nogc = AllocSetContextCreate((MemoryContext) NULL,
1109 ALLOCSET_DEFAULT_MINSIZE,
1110 ALLOCSET_DEFAULT_INITSIZE,
1111 ALLOCSET_DEFAULT_MAXSIZE);
1113 oldcxt = MemoryContextSwitchTo(nogc);
1115 newind = (IndexList *) palloc(sizeof(IndexList));
1116 newind->il_heap = pstrdup(heap);
1117 newind->il_ind = pstrdup(ind);
1118 newind->il_info = (IndexInfo *) palloc(sizeof(IndexInfo));
1120 memcpy(newind->il_info, indexInfo, sizeof(IndexInfo));
1121 /* predicate will likely be null, but may as well copy it */
1122 newind->il_info->ii_Predicate = (List *)
1123 copyObject(indexInfo->ii_Predicate);
1125 newind->il_next = ILHead;
1128 MemoryContextSwitchTo(oldcxt);
1134 for (; ILHead != (IndexList *) NULL; ILHead = ILHead->il_next)
1139 heap = heap_openr(ILHead->il_heap, NoLock);
1140 ind = index_openr(ILHead->il_ind);
1141 index_build(heap, ind, ILHead->il_info);
1144 * In normal processing mode, index_build would close the heap and
1145 * index, but in bootstrap mode it will not.
1149 * All of the rest of this routine is needed only because in
1150 * bootstrap processing we don't increment xact id's. The normal
1151 * DefineIndex code replaces a pg_class tuple with updated info
1152 * including the relhasindex flag (which we need to have updated).
1153 * Unfortunately, there are always two indices defined on each
1154 * catalog causing us to update the same pg_class tuple twice for
1155 * each catalog getting an index during bootstrap resulting in the
1156 * ghost tuple problem (see heap_update). To get around this we
1157 * change the relhasindex field ourselves in this routine keeping
1158 * track of what catalogs we already changed so that we don't
1159 * modify those tuples twice. The normal mechanism for updating
1160 * pg_class is disabled during bootstrap.
1164 if (!BootstrapAlreadySeen(RelationGetRelid(heap)))
1165 UpdateStats(RelationGetRelid(heap), 0);
1167 /* XXX Probably we ought to close the heap and index here? */