Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Gpdb
提交
daec84f0
G
Gpdb
项目概览
Greenplum
/
Gpdb
通知
7
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Gpdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
daec84f0
编写于
1月 10, 1997
作者:
V
Vadim B. Mikheev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed (I hope) unique btree index implementation.
上级
c6a60570
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
88 addition
and
26 deletion
+88
-26
src/backend/access/nbtree/nbtinsert.c
src/backend/access/nbtree/nbtinsert.c
+88
-26
未找到文件。
src/backend/access/nbtree/nbtinsert.c
浏览文件 @
daec84f0
...
...
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.
8 1996/12/06 09:45:3
0 vadim Exp $
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.
9 1997/01/10 10:06:2
0 vadim Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -17,6 +17,7 @@
#include <utils/memutils.h>
#include <storage/bufpage.h>
#include <access/nbtree.h>
#include <access/heapam.h>
#include <storage/bufmgr.h>
#ifndef HAVE_MEMMOVE
...
...
@@ -41,7 +42,7 @@ static void _bt_updateitem(Relation rel, Size keysz, Buffer buf, Oid bti_oid, BT
* (xid, seqno) pair.
*/
InsertIndexResult
_bt_doinsert
(
Relation
rel
,
BTItem
btitem
,
bool
index_is_unique
,
bool
is_update
)
_bt_doinsert
(
Relation
rel
,
BTItem
btitem
,
bool
index_is_unique
,
Relation
heapRel
)
{
ScanKey
itup_scankey
;
IndexTuple
itup
;
...
...
@@ -60,30 +61,6 @@ _bt_doinsert(Relation rel, BTItem btitem, bool index_is_unique, bool is_update)
/* find the page containing this key */
stack
=
_bt_search
(
rel
,
natts
,
itup_scankey
,
&
buf
);
/* if we're not allowing duplicates, make sure the key isn't */
/* already in the node */
if
(
index_is_unique
&&
!
is_update
)
{
OffsetNumber
offset
;
TupleDesc
itupdesc
;
Page
page
;
itupdesc
=
RelationGetTupleDescriptor
(
rel
);
page
=
BufferGetPage
(
buf
);
offset
=
_bt_binsrch
(
rel
,
buf
,
natts
,
itup_scankey
,
BT_DESCENT
);
/* make sure the offset we're given points to an actual */
/* key on the page before trying to compare it */
if
(
!
PageIsEmpty
(
page
)
&&
offset
<=
PageGetMaxOffsetNumber
(
page
))
{
if
(
!
_bt_compare
(
rel
,
itupdesc
,
page
,
natts
,
itup_scankey
,
offset
))
{
/* it is a duplicate */
elog
(
WARN
,
"Cannot insert a duplicate key into a unique index."
);
}
}
}
blkno
=
BufferGetBlockNumber
(
buf
);
/* trade in our read lock for a write lock */
...
...
@@ -99,6 +76,91 @@ _bt_doinsert(Relation rel, BTItem btitem, bool index_is_unique, bool is_update)
*/
buf
=
_bt_moveright
(
rel
,
buf
,
natts
,
itup_scankey
,
BT_WRITE
);
/* if we're not allowing duplicates, make sure the key isn't */
/* already in the node */
if
(
index_is_unique
)
{
OffsetNumber
offset
,
maxoff
;
Page
page
;
page
=
BufferGetPage
(
buf
);
maxoff
=
PageGetMaxOffsetNumber
(
page
);
offset
=
_bt_binsrch
(
rel
,
buf
,
natts
,
itup_scankey
,
BT_DESCENT
);
/* make sure the offset we're given points to an actual */
/* key on the page before trying to compare it */
if
(
!
PageIsEmpty
(
page
)
&&
offset
<=
maxoff
)
{
TupleDesc
itupdesc
;
BTItem
btitem
;
IndexTuple
itup
;
HeapTuple
htup
;
BTPageOpaque
opaque
;
Buffer
nbuf
;
BlockNumber
blkno
;
itupdesc
=
RelationGetTupleDescriptor
(
rel
);
nbuf
=
InvalidBuffer
;
opaque
=
(
BTPageOpaque
)
PageGetSpecialPointer
(
page
);
while
(
!
_bt_compare
(
rel
,
itupdesc
,
page
,
natts
,
itup_scankey
,
offset
)
)
{
/* they're equal */
btitem
=
(
BTItem
)
PageGetItem
(
page
,
PageGetItemId
(
page
,
offset
));
itup
=
&
(
btitem
->
bti_itup
);
htup
=
heap_fetch
(
heapRel
,
SelfTimeQual
,
&
(
itup
->
t_tid
),
NULL
);
if
(
htup
!=
(
HeapTuple
)
NULL
)
{
/* it is a duplicate */
elog
(
WARN
,
"Cannot insert a duplicate key into a unique index."
);
}
/* get next offnum */
if
(
offset
<
maxoff
)
{
offset
=
OffsetNumberNext
(
offset
);
}
else
{
/* move right ? */
if
(
P_RIGHTMOST
(
opaque
)
)
break
;
if
(
_bt_compare
(
rel
,
itupdesc
,
page
,
natts
,
itup_scankey
,
P_HIKEY
)
)
break
;
/*
* min key of the right page is the same,
* ooh - so many dead duplicates...
*/
blkno
=
opaque
->
btpo_next
;
if
(
nbuf
!=
InvalidBuffer
)
_bt_relbuf
(
rel
,
nbuf
,
BT_READ
);
for
(
nbuf
=
InvalidBuffer
;
;
)
{
nbuf
=
_bt_getbuf
(
rel
,
blkno
,
BT_READ
);
page
=
BufferGetPage
(
nbuf
);
maxoff
=
PageGetMaxOffsetNumber
(
page
);
opaque
=
(
BTPageOpaque
)
PageGetSpecialPointer
(
page
);
offset
=
P_RIGHTMOST
(
opaque
)
?
P_HIKEY
:
P_FIRSTKEY
;
if
(
!
PageIsEmpty
(
page
)
&&
offset
<=
maxoff
)
{
/* Found some key */
break
;
}
else
{
/* Empty or "pseudo"-empty page - get next */
blkno
=
opaque
->
btpo_next
;
_bt_relbuf
(
rel
,
nbuf
,
BT_READ
);
nbuf
=
InvalidBuffer
;
if
(
blkno
==
P_NONE
)
break
;
}
}
if
(
nbuf
==
InvalidBuffer
)
break
;
}
}
if
(
nbuf
!=
InvalidBuffer
)
_bt_relbuf
(
rel
,
nbuf
,
BT_READ
);
}
}
/* do the insertion */
res
=
_bt_insertonpg
(
rel
,
buf
,
stack
,
natts
,
itup_scankey
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录