Greenplum中的函数

Greenplum中的函数,第1张

概述在GREENPLUM中函数大致分为三种类型: IMMUTABLE, STABLE, VOLATILE IMMUTABLE 返回值依赖于参数值,只要参数不变,返回值是确定的。 STABLE 返回值依赖于参数值以及执行是否垮语句。 在参数值相同的情况下,多次执行该函数返回结果可能会不同。像 current_timestamp这一类函数就是STABLE的,在同一个事务中它们的返回值是确定的。但是不同事务

在GREENPLUM中函数大致分为三种类型: IMMUtable,Stable,VolATILE

IMMUtable

返回值依赖于参数值,只要参数不变,返回值是确定的。

Stable

返回值依赖于参数值以及执行是否垮语句。

在参数值相同的情况下,多次执行该函数返回结果可能会不同。像 current_timestamp这一类函数就是Stable的,在同一个事务中它们的返回值是确定的。但是不同事务间多次执行相同的语句返回结果就可能有所不同。

VolATILE

即便是在同一个事务同一条语句中,这类函数的返回值也可能有所不同。

在GREENPLUM中,由于是分布式数据库,为了保证节点之间的一致性,Stable和VolATILE两类函数是不能在SEGMENT级别执行的。

用户自定义的函数如果不指定类别默认是VolATILE的。

下面是摘自GP admin文档中的一些内容

A function can be one of three types: IMMUtable,or VolATILE. Greenplum Database offers full support of all IMMUtable functions. An immutable function is a function that relIEs only on information directly present in its argument List and will always return the same result when given the same argument values.
The use of Stable and VolATILE functions is restricted in Greenplum Database. Stable indicates that within a single table scan the function will consistently return the same result for the same argument values,but that its result Could change across sql statements. Functions whose results depend on database lookups or parameter variables are classifIEd as Stable. Also note that the current_timestamp family of functions qualify as stable,since their values do not change within a transaction.
VolATILE indicates that the function value can change even within a single table scan. relatively few database functions are volatile in this sense; some examples are random(),currval(),timeofday(). But note that any function that has sIDe-effects must be classifIEd volatile,even if its result is quite predictable (for example,setval()).
In Greenplum Database,the data is divIDed up across the segments — each segment is,in a sense,its own distinct Postgresql database. To prevent data from becoming out-of-sync across the segments,any function classifIEd as Stable or VolATILE cannot be executed at the segment level if it contains sql or modifIEs the database in any way. For example,functions such as random() or timeofday() are not allowed to execute on distributed data in Greenplum Database because they Could potentially cause inconsistent data between the segment instances.

To ensure data consistency,VolATILE and Stable functions can safely be used in statements that are evaluated on and execute from the master. For example,the following statements are always executed on the master (statements without a FROM clause):
SELECT setval('myseq',201);
SELECT foo();
In cases where a statement has a FROM clause containing a distributed table and the function used in the FROM clause simply returns a set of rows,execution may be allowed on the segments:
SELECT * from foo();
One exception to this rule are functions that return a table reference (rangeFuncs) or functions that use the refCursor datatype. These types of functions cannot be used at all in Greenplum Database.

##########################################################

IMMUtable indicates that the function cannot modify the database and always returns the same result when given the same argument values. It does not do database lookups or otherwise use information not directly present in its argument List. If this option is given,any call of the function with all-constant arguments can be immediately replaced with the function value. Stable indicates that the function cannot modify the database,and that within a single table scan it will consistently return the same result for the same argument values,but that its result Could change across sql statements. This is the appropriate selection for functions whose results depend on database lookups,parameter values (such as the current time zone),and so on. Also note that the current_timestamp family of functions qualify as stable,since their values do not change within a transaction. VolATILE indicates that the function value can change even within a single table scan,so no optimizations can be made. relatively few database functions are volatile in this sense; some examples are random(),even if its result is quite predictable,to prevent calls from being optimized away; an example is setval().

总结

以上是内存溢出为你收集整理的Greenplum中的函数全部内容,希望文章能够帮你解决Greenplum中的函数所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1180078.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-02
下一篇 2022-06-02

发表评论

登录后才能评论

评论列表(0条)

保存