Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2e2189a

Browse files
author
Hiroshi Inoue
committed
Make it possible to execute crashed CREATE/DROP commands again.
Now indexes of pg_class and pg_type are unique indexesand guarantee the uniqueness of correponding attributes.heap_create() was changed to take another boolean parameterwhich allows to postpone the creation of disk file.The name of rd_nonameunlinked was changed to rd_unlinked.It is used generally(not only for noname relations) now.Requires initdb.
1 parenta2c834f commit2e2189a

File tree

14 files changed

+156
-58
lines changed

14 files changed

+156
-58
lines changed

‎src/backend/bootstrap/bootparse.y

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootparse.y,v 1.27 1999/07/17 20:16:46 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootparse.y,v 1.28 1999/11/04 08:00:58 inoue Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -80,7 +80,7 @@ static Oid objectid;
8080
%token<ival>CONSTID
8181
%tokenOPENXCLOSEXCREATEINSERT_TUPLE
8282
%tokenSTRINGXDEFINE
83-
%tokenXDECLAREINDEXONUSINGXBUILDINDICES
83+
%tokenXDECLAREINDEXONUSINGXBUILDINDICESUNIQUE
8484
%tokenCOMMAEQUALSLPARENRPAREN
8585
%tokenOBJ_IDXBOOTSTRAPNULLVAL
8686
%startTopLevel
@@ -106,6 +106,7 @@ Boot_Query :
106106
|Boot_CreateStmt
107107
|Boot_InsertStmt
108108
|Boot_DeclareIndexStmt
109+
|Boot_DeclareUniqueIndexStmt
109110
|Boot_BuildIndsStmt
110111
;
111112

@@ -164,7 +165,7 @@ Boot_CreateStmt:
164165
puts("creating bootstrap relation");
165166
tupdesc = CreateTupleDesc(numattr,attrtypes);
166167
reldesc = heap_create(LexIDStr($3), tupdesc,
167-
false,false);
168+
false,false,true);
168169
if (DebugMode)
169170
puts("bootstrap relation created ok");
170171
}
@@ -230,6 +231,19 @@ Boot_DeclareIndexStmt:
230231
}
231232
;
232233

234+
Boot_DeclareUniqueIndexStmt:
235+
XDECLARE UNIQUE INDEX boot_ident ON boot_ident USING boot_ident LPAREN boot_index_params RPAREN
236+
{
237+
DO_START;
238+
239+
DefineIndex(LexIDStr($6),
240+
LexIDStr($4),
241+
LexIDStr($8),
242+
$10, NIL, 1, 0, 0, NIL);
243+
DO_END;
244+
}
245+
;
246+
233247
Boot_BuildIndsStmt:
234248
XBUILD INDICES{ build_indices(); }
235249

‎src/backend/bootstrap/bootscanner.l

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootscanner.l,v 1.15 1999/09/11 22:26:41 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootscanner.l,v 1.16 1999/11/04 08:00:58 inoue Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -90,6 +90,7 @@ insert{ return(INSERT_TUPLE); }
9090
"declare"{return(XDECLARE); }
9191
"build"{return(XBUILD); }
9292
"indices"{return(INDICES); }
93+
"unique"{return(UNIQUE); }
9394
"index"{return(INDEX); }
9495
"on"{return(ON); }
9596
"using"{return(USING); }

‎src/backend/catalog/genbki.sh.in

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
#
1212
# IDENTIFICATION
13-
# $Header: /cvsroot/pgsql/src/backend/catalog/Attic/genbki.sh.in,v 1.3 1999/06/0421:12:06 tgl Exp $
13+
# $Header: /cvsroot/pgsql/src/backend/catalog/Attic/genbki.sh.in,v 1.4 1999/11/0408:00:56 inoue Exp $
1414
#
1515
# NOTES
1616
# non-essential whitespace is removed from the generated file.
@@ -164,6 +164,20 @@ raw == 1 { print; next; }
164164
print "declare index " data
165165
}
166166
167+
/^DECLARE_UNIQUE_INDEX\(/ {
168+
# ----
169+
# end any prior catalog data insertions before starting a define unique index
170+
# ----
171+
if (reln_open == 1) {
172+
#print "show";
173+
print "close " catalog;
174+
reln_open = 0;
175+
}
176+
177+
data = substr($0, 22, length($0) - 22);
178+
print "declare unique index " data
179+
}
180+
167181
/^BUILD_INDICES/{ print "build indices"; }
168182
169183
# ----------------

‎src/backend/catalog/heap.c

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.105 1999/10/26 03:12:33 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.106 1999/11/04 08:00:56 inoue Exp $
1111
*
1212
*
1313
* INTERFACE ROUTINES
@@ -176,7 +176,8 @@ Relation
176176
heap_create(char*relname,
177177
TupleDesctupDesc,
178178
boolisnoname,
179-
boolistemp)
179+
boolistemp,
180+
boolstorage_create)
180181
{
181182
unsignedi;
182183
Oidrelid;
@@ -264,7 +265,8 @@ heap_create(char *relname,
264265

265266
rel= (Relation)palloc(len);
266267
MemSet((char*)rel,0,len);
267-
268+
rel->rd_fd=-1;/* table is not open */
269+
rel->rd_unlinked= TRUE;/* table is not created yet */
268270
/*
269271
* create a new tuple descriptor from the one passed in
270272
*/
@@ -316,9 +318,9 @@ heap_create(char *relname,
316318
* ----------------
317319
*/
318320

319-
rel->rd_nonameunlinked= TRUE;/*change once table is created */
320-
rel->rd_fd= (File)smgrcreate(DEFAULT_SMGR,rel);
321-
rel->rd_nonameunlinked= FALSE;
321+
/*smgrcreate() is moved to heap_storage_create() */
322+
if (storage_create)
323+
heap_storage_create(rel);
322324

323325
RelationRegisterRelation(rel);
324326

@@ -334,6 +336,19 @@ heap_create(char *relname,
334336
returnrel;
335337
}
336338

339+
bool
340+
heap_storage_create(Relationrel)
341+
{
342+
boolsmgrcall= false;
343+
344+
if (rel->rd_unlinked)
345+
{
346+
rel->rd_fd= (File)smgrcreate(DEFAULT_SMGR,rel);
347+
rel->rd_unlinked= FALSE;
348+
smgrcall= true;
349+
}
350+
returnsmgrcall;
351+
}
337352

338353
/* ----------------------------------------------------------------
339354
*heap_create_with_catalog- Create a cataloged relation
@@ -795,16 +810,26 @@ heap_create_with_catalog(char *relname,
795810
}
796811

797812
/* ----------------
798-
*ok, relation does not already exist so now we
799-
*create an uncataloged relation and pull its relation oid
800-
*from the newly formed relation descriptor.
813+
*get_temp_rel_by_name() couldn't check the simultaneous
814+
*creation. Uniqueness will be really checked by unique
815+
*indexes of system tables but we couldn't check it here.
816+
*We have to pospone to create the disk file for this
817+
*relation.
818+
*Another boolean parameter "storage_create" was added
819+
*to heap_create() function. If the parameter is false
820+
*heap_create() only registers an uncataloged relation
821+
*to relation cache and heap_storage_create() should be
822+
*called later.
823+
*We could pull its relation oid from the newly formed
824+
*relation descriptor.
801825
*
802-
*Note: The call to heap_create() does all the "real" work
803-
*of creating the disk file for the relation.
804-
*This changes relname for noname and temp tables.
826+
*Note: The call to heap_create() changes relname for
827+
*noname and temp tables.
828+
*The call to heap_storage_create() does all the "real"
829+
*work of creating the disk file for the relation.
805830
* ----------------
806831
*/
807-
new_rel_desc=heap_create(relname,tupdesc, false,istemp);
832+
new_rel_desc=heap_create(relname,tupdesc, false,istemp, false);
808833

809834
new_rel_oid=new_rel_desc->rd_att->attrs[0]->attrelid;
810835

@@ -843,6 +868,10 @@ heap_create_with_catalog(char *relname,
843868
pfree(temp_relname);
844869
}
845870

871+
/*
872+
* We create the disk file for this relation here
873+
*/
874+
heap_storage_create(new_rel_desc);
846875
/* ----------------
847876
*ok, the relation has been cataloged, so close our relations
848877
*and return the oid of the newly created relation.
@@ -1519,10 +1548,10 @@ heap_destroy_with_catalog(char *relname)
15191548
*unlink the relation's physical file and finish up.
15201549
* ----------------
15211550
*/
1522-
if (!(rel->rd_isnoname)|| !(rel->rd_nonameunlinked))
1551+
if (!(rel->rd_isnoname)|| !(rel->rd_unlinked))
15231552
smgrunlink(DEFAULT_SMGR,rel);
15241553

1525-
rel->rd_nonameunlinked= TRUE;
1554+
rel->rd_unlinked= TRUE;
15261555

15271556
/*
15281557
* Close relcache entry, but *keep* AccessExclusiveLock on the
@@ -1548,9 +1577,9 @@ void
15481577
heap_destroy(Relationrel)
15491578
{
15501579
ReleaseRelationBuffers(rel);
1551-
if (!(rel->rd_isnoname)|| !(rel->rd_nonameunlinked))
1580+
if (!(rel->rd_isnoname)|| !(rel->rd_unlinked))
15521581
smgrunlink(DEFAULT_SMGR,rel);
1553-
rel->rd_nonameunlinked= TRUE;
1582+
rel->rd_unlinked= TRUE;
15541583
heap_close(rel,NoLock);
15551584
RemoveFromNoNameRelList(rel);
15561585
}

‎src/backend/catalog/index.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.93 1999/11/01 02:29:24 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.94 1999/11/04 08:00:56 inoue Exp $
1111
*
1212
*
1313
* INTERFACE ROUTINES
@@ -997,7 +997,7 @@ index_create(char *heapRelationName,
997997
* ----------------
998998
*/
999999
indexRelation=heap_create(indexRelationName,
1000-
indexTupDesc, false,istemp);
1000+
indexTupDesc, false,istemp, false);
10011001

10021002
/* ----------------
10031003
* construct the index relation descriptor
@@ -1014,6 +1014,10 @@ index_create(char *heapRelationName,
10141014
*/
10151015
indexoid=UpdateRelationRelation(indexRelation,temp_relname);
10161016

1017+
/*
1018+
* We create the disk file for this relation here
1019+
*/
1020+
heap_storage_create(indexRelation);
10171021
/* ----------------
10181022
* Now get the index procedure (only relevant for functional indices).
10191023
* ----------------

‎src/backend/executor/execAmi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Copyright (c) 1994, Regents of the University of California
77
*
8-
*$Id: execAmi.c,v 1.42 1999/09/18 19:06:47 tgl Exp $
8+
*$Id: execAmi.c,v 1.43 1999/11/04 08:00:57 inoue Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -503,7 +503,7 @@ ExecCreatR(TupleDesc tupType,
503503
* heap_create creates a name if the argument to heap_create is
504504
* '\0 '
505505
*/
506-
relDesc=heap_create(NULL,tupType, true, false);
506+
relDesc=heap_create(NULL,tupType, true, false, true);
507507
}
508508
else
509509
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp