select round(avg(et_gsm_sınyal)) as sinyal,mahalle_kodu,ilce_kodu,sebeke
from
(select et_gsm_sınyal,sozlesme_no,SUBSTR(et_operator,1,5) as sebeke
from thkol316old
where tarih >= ADD_MONTHS (TRUNC (SYSDATE, 'MM'), -1)
AND tarih < TRUNC(SYSDATE, 'MM')) okuma,
(select sozlesme_no,ilce_kodu,mahalle_kodu from commt020) bilgiler
where okuma.sozlesme_no=bilgiler.sozlesme_no
group by mahalle_kodu,ilce_kodu,sebeke;
此查询有效,但效果很慢。
响应时间约为550秒。
我应该更快地完成此查询工作?
这是执行计划
SELECT STATEMENT 7547
HASH
GROUP BY 7547
FILTER
Filter Predicates
ADD_MONTHS(TRUNC(SYSDATE@!,'fmmm'),-1)
NESTED LOOPS
NESTED LOOPS
7546
TABLE ACCESS
COMMT020 BY GLOBAL INDEX ROWID 3 ROW LOCATION ROW LOCATION`
答案 0 :(得分:0)
首先,我会尝试使用普通的表连接而不是更笨拙的内联视图 - 加入,我希望以下内容可行(我还没有创建表并尝试过):
select round(avg(okuma.et_gsm_sınyal)) as sinyal,
bilgiler.mahalle_kodu,bilgiler.ilce_kodu, SUBSTR(okuma.et_operator,1,5) as sebeke
from thkol316old okuma
inner join commt020 bilgiler on okuma.sozlesme_no=bilgiler.sozlesme_no
where okuma.tarih >= ADD_MONTHS (TRUNC (SYSDATE, 'MM'), -1)
AND okuma.tarih < TRUNC(SYSDATE, 'MM')
group by bilgiler.mahalle_kodu,bilgiler.ilce_kodu, SUBSTR(okuma.et_operator,1,5);
然后,如果事情仍然很慢:
答案 1 :(得分:0)
显然
列tarih未为表thkol316old索引
create index tarih_idx on thkol316old (tarih);
然后
analyze table commt020 compute statistics;
analyze table thkol316old compute statistics;
在Oracle分析表中,生成用于创建查询执行计划的信息。每次更改表格时,您可能还想分析它。许多大型系统都按计划进行。
答案 2 :(得分:0)
首先,您不需要BILIGILER内联视图来从COMMT020表中选择几个列,您可以直接从该表中选择:
SELECT ROUND(AVG(et_gsm_s1nyal)) AS sinyal,
mahalle_kodu,ilce_kodu,sebeke
FROM (
SELECT et_gsm_s1nyal,
sozlesme_no,
SUBSTR(et_operator,1,5) AS sebeke
FROM thkol316old
WHERE tarih >= ADD_MONTHS (TRUNC (SYSDATE, 'MM'), -1)
AND tarih < TRUNC(SYSDATE, 'MM')
) okuma, commt020
WHERE okuma.sozlesme_no = commt020.sozlesme_no
GROUP BY mahalle_kodu,ilce_kodu,sebeke
/
然后,让我们使用ANSI连接表达式重写连接。我更喜欢ANSI连接而不是旧的Oracle风格连接,因为它们允许将连接条件与过滤条件分开,从而更清晰地了解实际发生的情况。此外,为表分配别名并清楚地指出我们从哪个表中选择哪些列是一种很好的方式。
SELECT ROUND(AVG(o.et_gsm_s1nyal)) AS sinyal,
c.mahalle_kodu, c.ilce_kodu, o.sebeke
FROM (
SELECT th.et_gsm_s1nyal,
th.sozlesme_no,
SUBSTR(th.et_operator,1,5) AS sebeke
FROM thkol316old th
WHERE th.tarih >= ADD_MONTHS (TRUNC (SYSDATE, 'MM'), -1)
AND th.tarih < TRUNC(SYSDATE, 'MM')
) okuma o
JOIN commt020 c ON o.sozlesme_no = c.sozlesme_no
GROUP BY c.mahalle_kodu, c.ilce_kodu, o.sebeke
/
现在它比剩余的内联视图更加清晰。虽然在不知道这些表的详细信息的情况下很难分辨,但是你可能会更好地“展开”内联视图并用直接连接替换它:
SELECT ROUND(AVG(th.et_gsm_s1nyal)) AS sinyal,
c.mahalle_kodu,
c.ilce_kodu,
SUBSTR(th.et_operator,1,5) AS sebeke
FROM commt020 c
JOIN thkol316old th ON c.sozlesme_no = th.sozlesme_no
WHERE th.tarih >= ADD_MONTHS (TRUNC (SYSDATE, 'MM'), -1)
AND th.tarih < TRUNC(SYSDATE, 'MM')
GROUP BY c.mahalle_kodu, c.ilce_kodu, SUBSTR(th.et_operator,1,5)
/
不幸的是,优化此查询还需要其他信息,例如: