gputf8=# delete from hgh_test1
gputf8=# where c2 in (select c2 from hgh_test2);
ERROR: Cannot parallelize that DELETE yet
DETAIL: Passage of data from one segment to another is not yet supported during DELETE operations.
HINT: The WHERE condition must specify equty between corresponding DISTRIBUTED BY columns of the target table and all joined tables.
有如下两表:
gputf8=# d hgh_test1
Table "ireport.hgh_test1"
Column | Type | Modifiers
--------+---------+-----------
c1 | numeric |
c2 | numeric |
Distributed by: (c1)
gputf8=# d hgh_test2
Table "ireport.hgh_test2"
Column | Type | Modifiers
--------+---------+-----------
c1 | numeric |
c2 | numeric |
Distributed by: (c1)
他们的distributed键都是c1。
然后执行
gputf8=# delete from hgh_test1
gputf8=# where c2 in (select c2 from hgh_test2);
ERROR: Cannot parallelize that DELETE yet
DETAIL: Passage of data from one segment to another is not yet supported during DELETE operations.
HINT: The WHERE condition must specify equty between corresponding DISTRIBUTED BY columns of the target table and all joined tables.
这时报Cannot parallelize that DELETE yet错误
我们再换个写法
gputf8=# delete from hgh_test1 a using hgh_test2 b
gputf8=# where a.c2=b.c2;
ERROR: Cannot parallelize that DELETE yet
DETAIL: Passage of data from one segment to another is not yet supported during DELETE operations.
HINT: The WHERE condition must specify equty between corresponding DISTRIBUTED BY columns of the target table and all joined tables.
报同样的错误。
从它的提示中我们可以知道,GP在做delete操作时并不支持非distributed键的带in的子查询。
那么我们用exists行不行呢?
gputf8=# delete from hgh_test1 a
gputf8=# where exists (select 1 from hgh_test2 b where a.c2=b.c2);
ERROR: Cannot parallelize that DELETE yet
DETAIL: Passage of data from one segment to another is not yet supported during DELETE operations.
HINT: The WHERE condition must specify equty between corresponding DISTRIBUTED BY columns of the target table and all joined tables.
杯具了!还是不行。。。
但我们不可避免的会有需要做这样的操作的时候,那怎么办呢?
看来我们只能修改表的distributed键了。但是很多时候我们不能或者不想改变表的distributed键。
这时如果我们引入一张临时表,就可以解决这个问题。
gputf8=# create table hgh_tmp as
gputf8=# select a.*
gputf8=# from hgh_test1 a left outer join hgh_test2 b
gputf8=# on a.c2=b.c2
gputf8=# where b.c2 is null
gputf8=# distributed by (c1);
SELECT 1
让后我们再把表rename一下就可以得到我们需要的结果了!
gputf8=# alter table hgh_test1 rename to hgh_tmp1;
ALTER TABLE
gputf8=# alter table hgh_tmp rename to hgh_test1;
ALTER TABLE
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/21713687/viewspace-1035104/ ,如需转载,请注明出处,否则将追究法律责任。