Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Gpdb
提交
1bd159e4
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,发现更多精彩内容 >>
提交
1bd159e4
编写于
3月 27, 2003
作者:
T
Tom Lane
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix bogus coding of SET DEFAULT ri triggers ... or at least make it less
bogus than it was. Per bug report from Adrian Pop.
上级
15b9e2c5
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
46 addition
and
83 deletion
+46
-83
src/backend/utils/adt/ri_triggers.c
src/backend/utils/adt/ri_triggers.c
+46
-83
未找到文件。
src/backend/utils/adt/ri_triggers.c
浏览文件 @
1bd159e4
...
...
@@ -17,7 +17,7 @@
*
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
*
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ri_triggers.c,v 1.4
7 2003/03/15 21:19
:40 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ri_triggers.c,v 1.4
8 2003/03/27 19:25
:40 tgl Exp $
*
* ----------
*/
...
...
@@ -37,6 +37,7 @@
#include "executor/spi_priv.h"
#include "optimizer/planmain.h"
#include "parser/parse_oper.h"
#include "rewrite/rewriteHandler.h"
#include "utils/lsyscache.h"
#include "miscadmin.h"
...
...
@@ -2315,10 +2316,8 @@ RI_FKey_setdefault_del(PG_FUNCTION_ARGS)
const
char
*
qualsep
;
Oid
queryoids
[
RI_MAX_NUMKEYS
];
Plan
*
spi_plan
;
AttrDefault
*
defval
;
TargetEntry
*
spi_qptle
;
int
i
,
j
;
int
i
;
List
*
l
;
/* ----------
* The query string built is
...
...
@@ -2355,45 +2354,31 @@ RI_FKey_setdefault_del(PG_FUNCTION_ARGS)
*/
qplan
=
SPI_prepare
(
querystr
,
qkey
.
nkeypairs
,
queryoids
);
/* ----------
* Here now follows very ugly code depending on internals
* of the SPI manager.
*
* EVIL EVIL EVIL (but must be - Jan)
/*
* Scan the plan's targetlist and replace the NULLs by
* appropriate column defaults, if any (if not, they stay
* NULL).
*
* We replace the CONST NULL targetlist expressions
* in the generated plan by (any) default values found
* in the tuple constructor.
* ----------
* XXX This is really ugly; it'd be better to use "UPDATE
* SET foo = DEFAULT", if we had it.
*/
spi_plan
=
(
Plan
*
)
lfirst
(((
_SPI_plan
*
)
qplan
)
->
ptlist
);
if
(
fk_rel
->
rd_att
->
constr
!=
NULL
)
defval
=
fk_rel
->
rd_att
->
constr
->
defval
;
else
defval
=
NULL
;
for
(
i
=
0
;
i
<
qkey
.
nkeypairs
&&
defval
!=
NULL
;
i
++
)
foreach
(
l
,
spi_plan
->
targetlist
)
{
/*
* For each key attribute lookup the tuple constructor
* for a corresponding default value
*/
for
(
j
=
0
;
j
<
fk_rel
->
rd_att
->
constr
->
num_defval
;
j
++
)
TargetEntry
*
tle
=
(
TargetEntry
*
)
lfirst
(
l
);
Node
*
dfl
;
/* Ignore any junk columns or Var=Var columns */
if
(
tle
->
resdom
->
resjunk
)
continue
;
if
(
IsA
(
tle
->
expr
,
Var
))
continue
;
dfl
=
build_column_default
(
fk_rel
,
tle
->
resdom
->
resno
);
if
(
dfl
)
{
if
(
defval
[
j
].
adnum
==
qkey
.
keypair
[
i
][
RI_KEYPAIR_FK_IDX
])
{
/*
* That's the one - push the expression from
* defval.adbin into the plan's targetlist
*/
spi_qptle
=
(
TargetEntry
*
)
nth
(
defval
[
j
].
adnum
-
1
,
spi_plan
->
targetlist
);
spi_qptle
->
expr
=
stringToNode
(
defval
[
j
].
adbin
);
fix_opfuncids
((
Node
*
)
spi_qptle
->
expr
);
break
;
}
fix_opfuncids
(
dfl
);
tle
->
expr
=
(
Expr
*
)
dfl
;
}
}
}
...
...
@@ -2559,10 +2544,8 @@ RI_FKey_setdefault_upd(PG_FUNCTION_ARGS)
const
char
*
qualsep
;
Oid
queryoids
[
RI_MAX_NUMKEYS
];
Plan
*
spi_plan
;
AttrDefault
*
defval
;
TargetEntry
*
spi_qptle
;
int
i
,
j
;
int
i
;
List
*
l
;
/* ----------
* The query string built is
...
...
@@ -2610,50 +2593,30 @@ RI_FKey_setdefault_upd(PG_FUNCTION_ARGS)
qplan
=
SPI_prepare
(
querystr
,
qkey
.
nkeypairs
,
queryoids
);
/*
* Now replace the CONST NULL targetlist expressions in
* the generated plan by (any) default values found in the
* tuple constructor.
* Scan the plan's targetlist and replace the NULLs by
* appropriate column defaults, if any (if not, they stay
* NULL).
*
* XXX This is really ugly; it'd be better to use "UPDATE
* SET foo = DEFAULT", if we had it.
*/
spi_plan
=
(
Plan
*
)
lfirst
(((
_SPI_plan
*
)
qplan
)
->
ptlist
);
if
(
fk_rel
->
rd_att
->
constr
!=
NULL
)
defval
=
fk_rel
->
rd_att
->
constr
->
defval
;
else
defval
=
NULL
;
for
(
i
=
0
;
i
<
qkey
.
nkeypairs
&&
defval
!=
NULL
;
i
++
)
foreach
(
l
,
spi_plan
->
targetlist
)
{
/*
* MATCH <unspecified> - only change columns
* corresponding to changed columns in pk_rel's key.
* This conditional must match the one in the loop
* above that built the SET attrn=NULL list.
*/
if
(
match_type
==
RI_MATCH_TYPE_FULL
||
!
ri_OneKeyEqual
(
pk_rel
,
i
,
old_row
,
new_row
,
&
qkey
,
RI_KEYPAIR_PK_IDX
))
TargetEntry
*
tle
=
(
TargetEntry
*
)
lfirst
(
l
);
Node
*
dfl
;
/* Ignore any junk columns or Var=Var columns */
if
(
tle
->
resdom
->
resjunk
)
continue
;
if
(
IsA
(
tle
->
expr
,
Var
))
continue
;
dfl
=
build_column_default
(
fk_rel
,
tle
->
resdom
->
resno
);
if
(
dfl
)
{
/*
* For each key attribute lookup the tuple
* constructor for a corresponding default value
*/
for
(
j
=
0
;
j
<
fk_rel
->
rd_att
->
constr
->
num_defval
;
j
++
)
{
if
(
defval
[
j
].
adnum
==
qkey
.
keypair
[
i
][
RI_KEYPAIR_FK_IDX
])
{
/*
* That's the one - push the expression
* from defval.adbin into the plan's
* targetlist
*/
spi_qptle
=
(
TargetEntry
*
)
nth
(
defval
[
j
].
adnum
-
1
,
spi_plan
->
targetlist
);
spi_qptle
->
expr
=
stringToNode
(
defval
[
j
].
adbin
);
fix_opfuncids
((
Node
*
)
spi_qptle
->
expr
);
break
;
}
}
fix_opfuncids
(
dfl
);
tle
->
expr
=
(
Expr
*
)
dfl
;
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录