【发布时间】:2015-03-28 21:46:46
【问题描述】:
我正在运行以下功能。使用小得多的表对其进行测试可以按预期工作(18 行 - 约 400 毫秒)。但是,当指向我的真实数据(315000 行)时,它运行了 48 小时并且仍在运行。这比我在线性外推下的预期要长得多。
- 有没有更好的方法来做到这一点?
- 有没有办法测试它在运行时是否在做它应该做的事情?
有没有办法优化下面的功能?
DO
$do$
DECLARE r public.tablex%rowtype;
BEGIN
FOR r IN SELECT id FROM public.tablex
LOOP
IF (select cast((select trunc(random() * 6 + 1)) as integer) = 5) THEN
UPDATE public.tablex SET test='variable1' WHERE id = r.id;
ELSIF (select cast((select trunc(random() * 6 + 1)) as integer) = 6) THEN
UPDATE public.tablex SET test='variable2' WHERE id = r.id;
END IF;
END LOOP;
RETURN;
END
$do$;
【问题讨论】:
标签: performance postgresql random sql-update plpgsql