Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Gpdb
提交
9e9584cc
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,发现更多精彩内容 >>
提交
9e9584cc
编写于
8月 22, 1997
作者:
V
Vadim B. Mikheev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Store attr DEFAULT info in heap_create
上级
55f7d4ea
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
117 addition
and
2 deletion
+117
-2
src/backend/catalog/heap.c
src/backend/catalog/heap.c
+117
-2
未找到文件。
src/backend/catalog/heap.c
浏览文件 @
9e9584cc
...
...
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.2
0 1997/08/21 03:01:21 momjian
Exp $
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.2
1 1997/08/22 02:58:51 vadim
Exp $
*
* INTERFACE ROUTINES
* heap_creatr() - Create an uncataloged heap relation
...
...
@@ -39,10 +39,13 @@
#include <catalog/pg_proc.h>
#include <catalog/pg_index.h>
#include <catalog/pg_type.h>
#include <catalog/pg_attrdef.h>
#include <catalog/pg_relcheck.h>
#include <storage/bufmgr.h>
#include <storage/lmgr.h>
#include <storage/smgr.h>
#include <parser/catalog_utils.h>
#include <parser/parse_query.h>
#include <rewrite/rewriteRemove.h>
#include <utils/builtins.h>
#include <utils/mcxt.h>
...
...
@@ -64,6 +67,9 @@ static void RelationRemoveIndexes(Relation relation);
static
void
RelationRemoveInheritance
(
Relation
relation
);
static
void
RemoveFromTempRelList
(
Relation
r
);
static
void
addNewRelationType
(
char
*
typeName
,
Oid
new_rel_oid
);
static
void
StoreConstraints
(
Relation
rel
);
static
void
StoreAttrDefault
(
Relation
rel
,
AttrDefault
*
attrdef
);
static
void
StoreRelCheck
(
Relation
rel
,
ConstrCheck
*
check
);
/* ----------------------------------------------------------------
...
...
@@ -272,7 +278,7 @@ heap_creatr(char *name,
/* ----------
create a new tuple descriptor from the one passed in
*/
rdesc
->
rd_att
=
CreateTupleDescCopy
(
tupDesc
);
rdesc
->
rd_att
=
CreateTupleDescCopy
Constr
(
tupDesc
);
/* ----------------
* initialize the fields of our new relation descriptor
...
...
@@ -298,6 +304,8 @@ heap_creatr(char *name,
rdesc
->
rd_rel
->
relkind
=
RELKIND_UNCATALOGED
;
rdesc
->
rd_rel
->
relnatts
=
natts
;
rdesc
->
rd_rel
->
relsmgr
=
smgr
;
if
(
tupDesc
->
constr
)
rdesc
->
rd_rel
->
relchecks
=
tupDesc
->
constr
->
num_check
;
for
(
i
=
0
;
i
<
natts
;
i
++
)
{
rdesc
->
rd_att
->
attrs
[
i
]
->
attrelid
=
relid
;
...
...
@@ -814,6 +822,8 @@ heap_create(char relname[],
arch
,
natts
);
StoreConstraints
(
new_rel_desc
);
/* ----------------
* ok, the relation has been cataloged, so close our relations
* and return the oid of the newly created relation.
...
...
@@ -1458,3 +1468,108 @@ DestroyTempRels(void)
tempRels
=
NULL
;
}
static
void
StoreConstraints
(
Relation
rel
)
{
TupleConstr
*
constr
=
rel
->
rd_att
->
constr
;
int
i
;
if
(
!
constr
)
return
;
if
(
constr
->
num_defval
>
0
)
{
for
(
i
=
0
;
i
<
constr
->
num_defval
;
i
++
)
StoreAttrDefault
(
rel
,
&
(
constr
->
defval
[
i
]));
}
if
(
constr
->
num_check
>
0
)
{
for
(
i
=
0
;
i
<
constr
->
num_check
;
i
++
)
StoreRelCheck
(
rel
,
&
(
constr
->
check
[
i
]));
}
return
;
}
extern
List
*
flatten_tlist
(
List
*
tlist
);
extern
List
*
pg_plan
(
char
*
query_string
,
Oid
*
typev
,
int
nargs
,
QueryTreeList
**
queryListP
,
CommandDest
dest
);
static
void
StoreAttrDefault
(
Relation
rel
,
AttrDefault
*
attrdef
)
{
char
str
[
MAX_PARSE_BUFFER
];
char
cast
[
2
*
NAMEDATALEN
]
=
{
0
};
AttributeTupleForm
atp
=
rel
->
rd_att
->
attrs
[
attrdef
->
adnum
-
1
];
QueryTreeList
*
queryTree_list
;
Query
*
query
;
List
*
planTree_list
;
TargetEntry
*
te
;
Resdom
*
resdom
;
Node
*
expr
;
char
*
adbin
;
MemoryContext
oldcxt
;
Relation
adrel
;
Relation
idescs
[
Num_pg_attrdef_indices
];
HeapTuple
tuple
;
Datum
values
[
4
];
char
nulls
[
4
]
=
{
' '
,
' '
,
' '
,
' '
};
extern
GlobalMemory
CacheCxt
;
start:
;
sprintf
(
str
,
"select %s%s from %.*s"
,
attrdef
->
adsrc
,
cast
,
NAMEDATALEN
,
rel
->
rd_rel
->
relname
.
data
);
planTree_list
=
(
List
*
)
pg_plan
(
str
,
NULL
,
0
,
&
queryTree_list
,
None
);
query
=
(
Query
*
)
(
queryTree_list
->
qtrees
[
0
]);
if
(
length
(
query
->
rtable
)
>
1
||
flatten_tlist
(
query
->
targetList
)
!=
NIL
)
elog
(
WARN
,
"AttributeDefault: cannot use attribute(s)"
);
te
=
(
TargetEntry
*
)
lfirst
(
query
->
targetList
);
resdom
=
te
->
resdom
;
expr
=
te
->
expr
;
if
(
IsA
(
expr
,
Const
)
)
{
if
(
((
Const
*
)
expr
)
->
consttype
!=
atp
->
atttypid
)
{
if
(
*
cast
!=
0
)
elog
(
WARN
,
"AttributeDefault: casting failed - const type mismatched"
);
sprintf
(
cast
,
":: %s"
,
get_id_typname
(
atp
->
atttypid
));
goto
start
;
}
}
else
if
(
exprType
(
expr
)
!=
atp
->
atttypid
)
elog
(
WARN
,
"AttributeDefault: type mismatched"
);
adbin
=
nodeToString
(
expr
);
oldcxt
=
MemoryContextSwitchTo
((
MemoryContext
)
CacheCxt
);
attrdef
->
adbin
=
(
char
*
)
palloc
(
strlen
(
adbin
)
+
1
);
strcpy
(
attrdef
->
adbin
,
adbin
);
(
void
)
MemoryContextSwitchTo
(
oldcxt
);
pfree
(
adbin
);
values
[
Anum_pg_attrdef_adrelid
-
1
]
=
rel
->
rd_id
;
values
[
Anum_pg_attrdef_adnum
-
1
]
=
attrdef
->
adnum
;
values
[
Anum_pg_attrdef_adbin
-
1
]
=
PointerGetDatum
(
textin
(
attrdef
->
adbin
));
values
[
Anum_pg_attrdef_adsrc
-
1
]
=
PointerGetDatum
(
textin
(
attrdef
->
adsrc
));
adrel
=
heap_openr
(
AttrDefaultRelationName
);
tuple
=
heap_formtuple
(
adrel
->
rd_att
,
values
,
nulls
);
CatalogOpenIndices
(
Num_pg_attrdef_indices
,
Name_pg_attrdef_indices
,
idescs
);
heap_insert
(
adrel
,
tuple
);
CatalogIndexInsert
(
idescs
,
Num_pg_attrdef_indices
,
adrel
,
tuple
);
CatalogCloseIndices
(
Num_pg_attrdef_indices
,
idescs
);
pfree
(
DatumGetPointer
(
values
[
Anum_pg_attrdef_adbin
-
1
]));
pfree
(
DatumGetPointer
(
values
[
Anum_pg_attrdef_adsrc
-
1
]));
pfree
(
tuple
);
}
static
void
StoreRelCheck
(
Relation
rel
,
ConstrCheck
*
check
)
{
return
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录