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

Commit07a65b2

Browse files
committed
Commit of a *MAJOR* patch from Dan McGuirk <djm@indirect.com>
Changes: * Unique index capability works using the syntax 'create unique index'. * Duplicate OID's in the system tables are removed. I put little scripts called 'duplicate_oids' and 'find_oid' in include/catalog that help to find and remove duplicate OID's. I also moved 'unused_oids' from backend/catalog to include/catalog, since it has to be in the same directory as the include files in order to work. * The backend tries converting the name of a function or aggregate to all lowercase if the original name given doesn't work (mostly for compatibility with ODBC). * You can 'SELECT NULL' to your heart's content. * I put my _bt_updateitem fix in instead, which uses _bt_insertonpg so that even if the new key is so big that the page has to be split, everything still works. * All literal references to system catalog OID's have been replaced with references to define'd constants from the catalog header files. * I added a couple of node copy functions. I think this was a preliminary attempt to get rules to work.
1 parent0cec8fe commit07a65b2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+861
-588
lines changed

‎src/backend/access/gist/gist.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ gistbuild(Relation heap,
292292
* It doesn't do any work; just locks the relation and passes the buck.
293293
*/
294294
InsertIndexResult
295-
gistinsert(Relationr,Datum*datum,char*nulls,ItemPointerht_ctid)
295+
gistinsert(Relationr,Datum*datum,char*nulls,ItemPointerht_ctid,boolis_update)
296296
{
297297
InsertIndexResultres;
298298
IndexTupleitup;

‎src/backend/access/hash/hash.c

Lines changed: 2 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/access/hash/hash.c,v 1.10 1996/11/05 09:40:17 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/access/hash/hash.c,v 1.11 1996/11/13 20:46:48 scrappy Exp $
1111
*
1212
* NOTES
1313
* This file contains only the public interface routines.
@@ -257,7 +257,7 @@ hashbuild(Relation heap,
257257
* to the caller.
258258
*/
259259
InsertIndexResult
260-
hashinsert(Relationrel,Datum*datum,char*nulls,ItemPointerht_ctid)
260+
hashinsert(Relationrel,Datum*datum,char*nulls,ItemPointerht_ctid,boolis_update)
261261
{
262262
HashItemhitem;
263263
IndexTupleitup;

‎src/backend/access/index/indexam.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/access/index/indexam.c,v 1.7 1996/11/05 10:02:03 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/access/index/indexam.c,v 1.8 1996/11/13 20:46:59 scrappy Exp $
1111
*
1212
* INTERFACE ROUTINES
1313
*index_open - open an index relation by relationId
@@ -164,7 +164,8 @@ InsertIndexResult
164164
index_insert(Relationrelation,
165165
Datum*datum,
166166
char*nulls,
167-
ItemPointerheap_t_ctid)
167+
ItemPointerheap_t_ctid,
168+
boolis_update)
168169
{
169170
RegProcedureprocedure;
170171
InsertIndexResultspecificResult;
@@ -177,7 +178,7 @@ index_insert(Relation relation,
177178
* ----------------
178179
*/
179180
specificResult= (InsertIndexResult)
180-
fmgr(procedure,relation,datum,nulls,heap_t_ctid,NULL);
181+
fmgr(procedure,relation,datum,nulls,heap_t_ctid,is_update,NULL);
181182

182183
/* ----------------
183184
*the insert proc is supposed to return a "specific result" and

‎src/backend/access/nbtree/nbtinsert.c

Lines changed: 102 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.6 1996/11/05 10:35:29 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.7 1996/11/13 20:47:11 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -31,7 +31,10 @@ static OffsetNumber _bt_findsplitloc(Relation rel, Page page, OffsetNumber start
3131
staticvoid_bt_newroot(Relationrel,Bufferlbuf,Bufferrbuf);
3232
staticOffsetNumber_bt_pgaddtup(Relationrel,Bufferbuf,intkeysz,ScanKeyitup_scankey,Sizeitemsize,BTItembtitem,BTItemafteritem);
3333
staticbool_bt_goesonpg(Relationrel,Bufferbuf,Sizekeysz,ScanKeyscankey,BTItemafteritem);
34+
35+
#if0
3436
staticvoid_bt_updateitem(Relationrel,Sizekeysz,Bufferbuf,Oidbti_oid,BTItemnewItem);
37+
#endif
3538

3639
/*
3740
* _bt_doinsert() -- Handle insertion of a single btitem in the tree.
@@ -41,7 +44,7 @@ static void _bt_updateitem(Relation rel, Size keysz, Buffer buf, Oid bti_oid, BT
4144
*(xid, seqno) pair.
4245
*/
4346
InsertIndexResult
44-
_bt_doinsert(Relationrel,BTItembtitem)
47+
_bt_doinsert(Relationrel,BTItembtitem,boolindex_is_unique,boolis_update)
4548
{
4649
ScanKeyitup_scankey;
4750
IndexTupleitup;
@@ -59,6 +62,31 @@ _bt_doinsert(Relation rel, BTItem btitem)
5962

6063
/* find the page containing this key */
6164
stack=_bt_search(rel,natts,itup_scankey,&buf);
65+
66+
/* if we're not allowing duplicates, make sure the key isn't */
67+
/* already in the node */
68+
if(index_is_unique&& !is_update) {
69+
OffsetNumberoffset;
70+
TupleDescitupdesc;
71+
Pagepage;
72+
73+
itupdesc=RelationGetTupleDescriptor(rel);
74+
page=BufferGetPage(buf);
75+
76+
offset=_bt_binsrch(rel,buf,natts,itup_scankey,BT_DESCENT);
77+
78+
/* make sure the offset we're given points to an actual */
79+
/* key on the page before trying to compare it */
80+
if(!PageIsEmpty(page)&&
81+
offset <=PageGetMaxOffsetNumber(page)) {
82+
if(!_bt_compare(rel,itupdesc,page,
83+
natts,itup_scankey,offset)) {
84+
/* it is a duplicate */
85+
elog(WARN,"Cannot insert a duplicate key into a unique index.");
86+
}
87+
}
88+
}
89+
6290
blkno=BufferGetBlockNumber(buf);
6391

6492
/* trade in our read lock for a write lock */
@@ -137,6 +165,10 @@ _bt_insertonpg(Relation rel,
137165
InsertIndexResultnewres;
138166
BTItemnew_item= (BTItem)NULL;
139167
BTItemlowLeftItem;
168+
OffsetNumberleftmost_offset;
169+
Pageppage;
170+
BTPageOpaqueppageop;
171+
BlockNumberbknum;
140172

141173
page=BufferGetPage(buf);
142174
itemsz=IndexTupleDSize(btitem->bti_itup)
@@ -236,14 +268,67 @@ _bt_insertonpg(Relation rel,
236268
lowLeftItem=
237269
(BTItem)PageGetItem(page,
238270
PageGetItemId(page,P_FIRSTKEY));
239-
/* page must have right pointer after split */
240-
_bt_updateitem(rel,keysz,pbuf,stack->bts_btitem->bti_oid,
241-
lowLeftItem);
271+
272+
/* this method does not work--_bt_updateitem tries to */
273+
/* overwrite an entry with another entry that might be */
274+
/* bigger. if lowLeftItem is bigger, it corrupts the */
275+
/* parent page. instead, we have to delete the original */
276+
/* leftmost item from the parent, and insert the new one */
277+
/* with a regular _bt_insertonpg (it could cause a split */
278+
/* because it's bigger than what was there before). */
279+
/* --djm 8/21/96 */
280+
281+
/* _bt_updateitem(rel, keysz, pbuf, stack->bts_btitem->bti_oid,
282+
lowLeftItem); */
283+
284+
/* get the parent page */
285+
ppage=BufferGetPage(pbuf);
286+
ppageop= (BTPageOpaque)PageGetSpecialPointer(ppage);
287+
288+
/* figure out which key is leftmost (if the parent page */
289+
/* is rightmost, too, it must be the root) */
290+
if(P_RIGHTMOST(ppageop)) {
291+
leftmost_offset=P_HIKEY;
292+
}else {
293+
leftmost_offset=P_FIRSTKEY;
242294
}
295+
PageIndexTupleDelete(ppage,leftmost_offset);
296+
297+
/* don't write anything out yet--we still have the write */
298+
/* lock, and now we call another _bt_insertonpg to */
299+
/* insert the correct leftmost key */
300+
301+
/* make a new leftmost item, using the tuple data from */
302+
/* lowLeftItem. point it to the left child. */
303+
/* update it on the stack at the same time. */
304+
bknum=BufferGetBlockNumber(buf);
305+
pfree(stack->bts_btitem);
306+
stack->bts_btitem=_bt_formitem(&(lowLeftItem->bti_itup));
307+
ItemPointerSet(&(stack->bts_btitem->bti_itup.t_tid),
308+
bknum,P_HIKEY);
309+
310+
/* unlock the children before doing this */
311+
_bt_relbuf(rel,buf,BT_WRITE);
312+
_bt_relbuf(rel,rbuf,BT_WRITE);
313+
314+
/* a regular _bt_binsrch should find the right place to */
315+
/* put the new entry, since it should be lower than any */
316+
/* other key on the page, therefore set afteritem to NULL */
317+
newskey=_bt_mkscankey(rel,&(stack->bts_btitem->bti_itup));
318+
newres=_bt_insertonpg(rel,pbuf,stack->bts_parent,
319+
keysz,newskey,stack->bts_btitem,
320+
NULL);
321+
322+
pfree(newres);
323+
pfree(newskey);
243324

244-
/* don't need the children anymore */
325+
/* we have now lost our lock on the parent buffer, and */
326+
/* need to get it back. */
327+
pbuf=_bt_getstackbuf(rel,stack,BT_WRITE);
328+
}else {
245329
_bt_relbuf(rel,buf,BT_WRITE);
246330
_bt_relbuf(rel,rbuf,BT_WRITE);
331+
}
247332

248333
newskey=_bt_mkscankey(rel,&(new_item->bti_itup));
249334
newres=_bt_insertonpg(rel,pbuf,stack->bts_parent,
@@ -787,6 +872,8 @@ _bt_itemcmp(Relation rel,
787872
return (true);
788873
}
789874

875+
#if0
876+
/* gone since updating in place doesn't work in general --djm 11/13/96 */
790877
/*
791878
*_bt_updateitem() -- updates the key of the item identified by the
792879
* oid with the key of newItem (done in place if
@@ -804,9 +891,9 @@ _bt_updateitem(Relation rel,
804891
OffsetNumbermaxoff;
805892
OffsetNumberi;
806893
ItemPointerDataitemPtrData;
807-
BTItemitem,itemCopy;
894+
BTItemitem;
808895
IndexTupleoldIndexTuple,newIndexTuple;
809-
intnewSize,oldSize,first;
896+
intfirst;
810897

811898
page=BufferGetPage(buf);
812899
maxoff=PageGetMaxOffsetNumber(page);
@@ -825,48 +912,18 @@ _bt_updateitem(Relation rel,
825912
elog(FATAL,"_bt_getstackbuf was lying!!");
826913
}
827914

915+
if(IndexTupleDSize(newItem->bti_itup)>
916+
IndexTupleDSize(item->bti_itup)) {
917+
elog(NOTICE,"trying to overwrite a smaller value with a bigger one in _bt_updateitem");
918+
elog(WARN,"this is not good.");
919+
}
920+
828921
oldIndexTuple=&(item->bti_itup);
829922
newIndexTuple=&(newItem->bti_itup);
830-
oldSize=DOUBLEALIGN(IndexTupleSize(oldIndexTuple));
831-
newSize=DOUBLEALIGN(IndexTupleSize(newIndexTuple));
832-
#ifdefNBTINSERT_PATCH_DEBUG
833-
printf("_bt_updateitem: newSize=%d, oldSize=%d\n",newSize,oldSize);
834-
#endif
835923

836-
/*
837-
* If new and old item have the same size do the update in place
838-
* and return.
839-
*/
840-
if (oldSize==newSize) {
841924
/* keep the original item pointer */
842925
ItemPointerCopy(&(oldIndexTuple->t_tid),&itemPtrData);
843926
CopyIndexTuple(newIndexTuple,&oldIndexTuple);
844927
ItemPointerCopy(&itemPtrData,&(oldIndexTuple->t_tid));
845-
return;
846-
}
847-
848-
/*
849-
* If new and old items have different size the update in place
850-
* is not possible. In this case the old item is deleted and the
851-
* new one is inserted.
852-
* The new insertion should be done using _bt_insertonpg which
853-
* would also takes care of the page splitting if needed, but
854-
* unfortunately it doesn't work, so PageAddItem is used instead.
855-
* There is the possibility that there is not enough space in the
856-
* page and the item is not inserted.
857-
*/
858-
itemCopy=palloc(newSize);
859-
memmove((char*)itemCopy, (char*)newItem,newSize);
860-
itemCopy->bti_oid=item->bti_oid;
861-
newIndexTuple=&(itemCopy->bti_itup);
862-
ItemPointerCopy(&(oldIndexTuple->t_tid),&(newIndexTuple->t_tid));
863-
864-
/*
865-
* Get the offset number of the item then delete it and insert
866-
* the new item in the same place.
867-
*/
868-
i=OffsetNumberPrev(i);
869-
PageIndexTupleDelete(page,i);
870-
PageAddItem(page, (Item)itemCopy,newSize,i,LP_USED);
871-
pfree(itemCopy);
872928
}
929+
#endif

‎src/backend/access/nbtree/nbtree.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtree.c,v 1.9 1996/11/05 10:35:32 scrappy Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtree.c,v 1.10 1996/11/13 20:47:18 scrappy Exp $
1212
*
1313
* NOTES
1414
* This file contains only the public interface routines.
@@ -74,13 +74,17 @@ btbuild(Relation heap,
7474
Oidhrelid,irelid;
7575
Node*pred,*oldPred;
7676
void*spool;
77+
boolisunique;
7778

7879
/* note that this is a new btree */
7980
BuildingBtree= true;
8081

8182
pred=predInfo->pred;
8283
oldPred=predInfo->oldPred;
8384

85+
/* see if index is unique */
86+
isunique=IndexIsUniqueNoCache(RelationGetRelationId(index));
87+
8488
/* initialize the btree index metadata page (if this is a new index) */
8589
if (oldPred==NULL)
8690
_bt_metapinit(index);
@@ -218,7 +222,7 @@ btbuild(Relation heap,
218222
if (FastBuild) {
219223
_bt_spool(index,btitem,spool);
220224
}else {
221-
res=_bt_doinsert(index,btitem);
225+
res=_bt_doinsert(index,btitem,isunique, false);
222226
}
223227

224228
pfree(btitem);
@@ -289,7 +293,7 @@ btbuild(Relation heap,
289293
*return an InsertIndexResult to the caller.
290294
*/
291295
InsertIndexResult
292-
btinsert(Relationrel,Datum*datum,char*nulls,ItemPointerht_ctid)
296+
btinsert(Relationrel,Datum*datum,char*nulls,ItemPointerht_ctid,boolis_update)
293297
{
294298
BTItembtitem;
295299
IndexTupleitup;
@@ -304,7 +308,9 @@ btinsert(Relation rel, Datum *datum, char *nulls, ItemPointer ht_ctid)
304308

305309
btitem=_bt_formitem(itup);
306310

307-
res=_bt_doinsert(rel,btitem);
311+
res=_bt_doinsert(rel,btitem,
312+
IndexIsUnique(RelationGetRelationId(rel)),is_update);
313+
308314
pfree(btitem);
309315
pfree(itup);
310316

‎src/backend/access/nbtree/nbtsearch.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.8 1996/11/05 10:35:34 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.9 1996/11/13 20:47:20 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -29,7 +29,7 @@
2929

3030
staticBTStack_bt_searchr(Relationrel,intkeysz,ScanKeyscankey,Buffer*bufP,BTStackstack_in);
3131
staticOffsetNumber_bt_firsteq(Relationrel,TupleDescitupdesc,Pagepage,Sizekeysz,ScanKeyscankey,OffsetNumberoffnum);
32-
staticint_bt_compare(Relationrel,TupleDescitupdesc,Pagepage,intkeysz,ScanKeyscankey,OffsetNumberoffnum);
32+
int_bt_compare(Relationrel,TupleDescitupdesc,Pagepage,intkeysz,ScanKeyscankey,OffsetNumberoffnum);
3333
staticbool_bt_twostep(IndexScanDescscan,Buffer*bufP,ScanDirectiondir);
3434
staticRetrieveIndexResult_bt_endpoint(IndexScanDescscan,ScanDirectiondir);
3535

@@ -413,7 +413,7 @@ _bt_firsteq(Relation rel,
413413
*a new minimal key is inserted, the leftmost entry on the leftmost
414414
*page is less than all possible keys, by definition.
415415
*/
416-
staticint
416+
int
417417
_bt_compare(Relationrel,
418418
TupleDescitupdesc,
419419
Pagepage,

‎src/backend/access/rtree/rtree.c

Lines changed: 2 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/access/rtree/Attic/rtree.c,v 1.9 1996/11/05 10:54:18 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtree.c,v 1.10 1996/11/13 20:47:35 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -277,7 +277,7 @@ rtbuild(Relation heap,
277277
* It doesn't do any work; just locks the relation and passes the buck.
278278
*/
279279
InsertIndexResult
280-
rtinsert(Relationr,Datum*datum,char*nulls,ItemPointerht_ctid)
280+
rtinsert(Relationr,Datum*datum,char*nulls,ItemPointerht_ctid,boolis_update)
281281
{
282282
InsertIndexResultres;
283283
IndexTupleitup;

‎src/backend/bootstrap/bootparse.y

Lines changed: 2 additions & 2 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.3 1996/10/21 08:31:18 scrappy Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootparse.y,v 1.4 1996/11/13 20:47:45 scrappy Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -231,7 +231,7 @@ DeclareIndexStmt:
231231
DefineIndex(LexIDStr($5),
232232
LexIDStr($3),
233233
LexIDStr($7),
234-
params, NIL, 0, NIL);
234+
params, NIL, 0,0,NIL);
235235
DO_END;
236236
}
237237
;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp