postgresql “LANGUAGE plpgsql VOLATILE COST 100”在函数中是什么意思
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21673394/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does "LANGUAGE plpgsql VOLATILE COST 100" mean in functions
提问by Ankit Lamba
I am new to Postgres triggers. I saw an example of triggers on www.postgresql.organd I didn't understand what is LANGUAGE plpgsql VOLATILE COST 100;
at the end of the trigger-function.
我是 Postgres 触发器的新手。我在www.postgresql.org上看到了一个触发器示例,但我不明白LANGUAGE plpgsql VOLATILE COST 100;
触发器函数的末尾是什么。
What is the use of this line?
这条线有什么用?
I saw a question related to this what does “LANGUAGE 'plpgsql' VOLATILE” mean?but it is only about volatile
, what is cost 100
and language
in this line?
我看到一个与此相关的问题“LANGUAGE 'plpgsql' VOLATILE”是什么意思?但只有约volatile
,什么是cost 100
与language
在这一行?
回答by deepak
LANGUAGE plpgsql VOLATILE COST 100;
语言 plpgsql 挥发性成本 100;
LANGUAGE:-programming language used for creating the stored procedure in PostgreSQL. Here it is plpgsql.
LANGUAGE:-用于在 PostgreSQL 中创建存储过程的编程语言。这里是plpgsql。
(before going to volatile and cost there is something you need to know first...'query optimizer' for which we are giving these informations. The query optimizer used to determine the most efficient way to execute a given query.)
(在进入 volatile 和 cost 之前,您需要先了解一些事情......我们提供这些信息的'查询优化器'。查询优化器用于确定执行给定查询的最有效方式。)
VOLATILE:-In PostgreSQL Every function has a volatility classification and volatile is one of volatility classification. A VOLATILE function can do anything, including modifying the database. It is default, so it can be omitted.
VOLATILE:-在 PostgreSQL 中,每个函数都有一个波动性分类,而 volatile 是波动性分类之一。VOLATILE 函数可以做任何事情,包括修改数据库。它是默认值,因此可以省略。
COST 100:- COST is completely independent from VOLATILE. It declares the cost per row of the result, which is used by the query planner to find the cheapest plan. The default is COST 100 which also can be omitted. Its better to leave it at the default.
COST 100:- COST 完全独立于 VOLATILE。它声明结果的每行成本,查询计划器使用它来查找最便宜的计划。默认值为 COST 100,也可以省略。最好将其保留为默认值。
In these statement we are giving information's about function to query optimizer. Here it... what language are using and what is the volatility of the function and what is the cost per row of the result.
在这些语句中,我们向查询优化器提供有关函数的信息。在这里......使用的是什么语言,函数的波动性是多少,结果的每行成本是多少。
回答by Pavel Stehule
You can use more programming languages for stored procedures programming in Postgres. So mandatory attribut LANGUAGE specifies used language - plpgsql, sql, plpython, plperl, ...
您可以使用更多的编程语言在 Postgres 中进行存储过程编程。所以强制属性 LANGUAGE 指定使用的语言 - plpgsql, sql, plpython, plperl, ...
These functions are black box for optimizer - optimizer doesn't know what is inside and how expensive this code is. Optimizer can choose a way how a SQL query will be calculated and it can prefer or minimize a evaluation of some functions. Functions with low cost are preferred and function with high cost is penalized. COST is +/- value how function is expensive (how function is fast or slow). Almost all built-in functions have COST 1, pgAdmin uses a COST 100 for custom function - it shows an expectation so plpgsql functions will be slower than built-in functions. COST is not linear - so it doesn't mean so plpgsql function is 100x slower than built-in function.
这些函数是优化器的黑匣子——优化器不知道里面是什么以及这段代码有多昂贵。优化器可以选择如何计算 SQL 查询的方式,并且可以首选或最小化对某些函数的评估。成本低的功能是首选,成本高的功能会受到惩罚。COST 是 +/- 值函数如何昂贵(函数如何快或慢)。几乎所有内置函数的 COST 为 1,pgAdmin 对自定义函数使用 COST 100 - 它显示了一个期望,因此 plpgsql 函数将比内置函数慢。COST 不是线性的——所以这并不意味着 plpgsql 函数比内置函数慢 100 倍。