在postgresql中手动更改查询的执行计划? [英] Change the execution plan of query in postgresql manually?

查看:316
本文介绍了在postgresql中手动更改查询的执行计划?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Postgresql中手动更改执行计划的操作顺序?例如。如果我一直想在过滤之前进行排序操作(尽管在正常使用Postgresql中没有意义),是否可以通过例如改变手术的内部成本?

Is it possible to change the order of the operations of an execution plan manually in postgresql? E.g. if I always want to have the ordering operation before a filtering (although it doesn't make sense in a normal use of postgresql), is it possible to enforce that manually by e.g. changing the internal costs of an operation?

如果我实现自己的功能怎么办?

What about if I implement my own function? Is it possible to have such a function always being executed at the very end of the sql statement?

推荐答案

还有更多方法-这里显示了一些,但是还有第二种方法,如果要在处理结束时移动函数调用,则只需将COST设置为更高的值即可。自定义函数的默认值为100,但是您可以设置更高的值。

There are more ways - some was showed here, but there are second way, if you would to move function call on end of processing, then just set COST to some higher value. Default for custom functions is 100, but you can set higher value.

CREATE OR REPLACE FUNCTION public.test()
 RETURNS integer
 LANGUAGE plpgsql
 IMMUTABLE COST 1000 -- very expensive function
AS $function$
declare i int;
declare j int;
begin
  i := 1;
  while i < 10000 loop
    j := 1;
    while j < 1000 loop
      j := j + 1;
    end loop;
    i := i + 1;
  end loop;
  return i;
end;
$function$

这篇关于在postgresql中手动更改查询的执行计划?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆