Greenplum報錯--query plan with multiple segworker groups is not supported


報錯信息:

ERROR:  query plan with multiple segworker groups is not supported
HINT:  likely caused by a function that reads or modifies data in a distributed table
CONTEXT:  PL/pgSQL function actv_comp(date,date) line 4 at RETURN QUERY

 

我們可能經常會遇到需要在query調用自定義函數的情況,但是在Greenplum中,如果函數中有query,然后又在query中調用該函數則會報錯。

 

例子:

創建函數

iap=# create or replace function f1() returns text as $$
declare
c1 text;
begin
execute 'select info from tt1 limit 1' into c1;
return c1;
end;
$$ language plpgsql;

query中調用:

iap=# select f1() from tt1;
ERROR: query plan with multiple segworker groups is not supported
HINT: likely caused by a function that reads or modifies data in a distributed table
CONTEXT: SQL statement 'select info from tt1 limit 1'
PL/pgSQL function f1() line 5 at EXECUTE statement

這是由於greenplum中MPP的特性,每個節點中只保存部分數據,GP6開始支持復制表,那么我們需要將該表改成復制表,保證每個節點中都有一份完整的數據。

除此之外,我們還需要將該函數修改成immutable類型。

 

—修改表分布為REPLICATED類型

alter table tt1 set Distributed REPLICATED;

 

二修改函數為immutable類型

iap=# create or replace function f1() returns text as $$
declare
c1 text;
begin
execute 'select info from tt1 limit 1' into c1;
return c1;
end;
$$ language plpgsql immutable;
CREATE FUNCTION

 

再次調用:

iap=# select f1() from tt1 limit 1;
f1
----------------------------------
d810ed19ec188ddf3af8a14dbd341c3c
(1 row)

 

總結:
如果你需要在query中調用UDF函數,碰到“ERROR: query plan with multiple segworker groups is not supported”報錯,那么解決方案如下:

  1. 修改表為復制表
  2. 修改函數為immutable類型

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM