简体   繁体   English

调优 Oracle 查询慢速 select

[英]Tuning Oracle Query for slow select

I'm working on an oracle query that is doing a select on a huge table, however the joins with other tables seem to be costing a lot in terms of time of processing.我正在处理一个 oracle 查询,该查询正在一个巨大的表上执行 select,但是与其他表的连接似乎在处理时间方面花费了很多。

I'm looking for tips on how to improve the working of this query.我正在寻找有关如何改进此查询工作的提示。

I'm attaching a version of the query and the explain plan of it.我附上了一个版本的查询和它的解释计划。

Query询问

 SELECT
    l.gl_date,
    l.REST_OF_TABLES
    (
        SELECT
            MAX(tt.task_id)
        FROM
            bbb.jeg_pa_tasks tt
        WHERE
            l.project_id = tt.project_id
            AND l.task_number = tt.task_number
    ) task_id
FROM
    aaa.jeg_labor_history   l,
    bbb.jeg_pa_projects_all     p
WHERE
    p.org_id = 2165
    AND l.project_id = p.project_id
    AND p.project_status_code = '1000'

解释计划

Something to mention: This query takes data from oracle to send it to a sql server database, so I need it to be this big, I can't narrow the scope of the query.需要说明的是:这个查询从 oracle 中获取数据发送到 sql 服务器数据库,所以我需要它这么大,我不能缩小查询的 scope。 the purpose is to set it to a sql server job with SSIS so it runs periodically目的是将其设置为具有 SSIS 的 sql 服务器作业,以便定期运行

As I don't know exactly how many rows this query is returning or how many rows this table/view has.因为我不知道这个查询返回多少行或者这个表/视图有多少行。

I can provide you few simple tips which might be helpful for you for better query performance:我可以为您提供一些简单的提示,这些提示可能对您提高查询性能有所帮助:

  1. Check Indexes.检查索引。 There should be indexes on all fields used in the WHERE and JOIN portions of the SQL statement. SQL 语句的 WHERE 和 JOIN 部分中使用的所有字段都应该有索引。

  2. Limit the size of your working data set.限制工作数据集的大小。

  3. Only select columns you need.您只需要 select 列。

  4. Remove unnecessary tables.删除不必要的表格。

  5. Remove calculated columns in JOIN and WHERE clauses.删除 JOIN 和 WHERE 子句中的计算列。

  6. Use inner join, instead of outer join if possible.如果可能,请使用内连接,而不是外连接。

You view contains lot of data so you can also break down and limit only the information you need from this view您的视图包含大量数据,因此您还可以分解并仅限制此视图中您需要的信息

One obvious suggestion is not to use sub query in select clause.一个明显的建议是不要在 select 子句中使用子查询。

Instead, you can try to join the tables.相反,您可以尝试加入表格。

SELECT
    l.gl_date,
    l.REST_OF_TABLES
    t.task_id
FROM
    aaa.jeg_labor_history   l
    Join bbb.jeg_pa_projects_all p
    On (l.project_id = p.project_id)
    Left join (SELECT
        tt.project_id, 
        tt.task_number,
        MAX(tt.task_id) task_id
    FROM
        bbb.jeg_pa_tasks tt
    Group by tt.project_id, tt.task_number) t
    On (l.project_id = t.project_id
            AND l.task_number = t.task_number)
WHERE
    p.org_id = 2165
    AND p.project_status_code = '1000';

Cheers!!干杯!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM