【发布时间】:2010-07-20 00:31:46
【问题描述】:
下面的查询需要 20 秒才能运行。 user_table 有 40054 记录。 other_table 有 14000 记录
select count(a.user_id) from user_table a, other_table b
where a.user_id = b.user_id;
我们的限制是任何运行超过 8 秒的查询都会被终止...>_
begin
FOR i IN role_user_rec.FIRST .. role_user_rec.LAST LOOP
SELECT COUNT (a.user_id) INTO v_into FROM user_table a
WHERE TRIM(role_user_rec(i).user_id) = TRIM(a.user_id);
v_count := v_count + v_into;
END LOOP;
我知道限制很糟糕,这不是effecient 做事的方式,但有没有其他方法可以让这个循环运行得更快?
【问题讨论】:
-
您可以考虑为您的查询发布解释计划。
-
这是如何执行的?: select count(*) from user_table a where a.user_id in (select user_id from other_table where user_id is not null)
-
role_user_rec 来自哪里?如果这是另一个查询的结果,也许可以将两者结合起来给您一个查询.... role_user_rec(i).user_id 和 user_table.user_id 是什么数据类型?
标签: oracle optimization loops