Skip to content
Advertisement

Extremely Huge time take for executing my following query?

I just make some queries for select data from my server. The query is:

But this query almost take one day. Any idea for optimize this query please?

Advertisement

Answer

You provide close to no information that is required to help with performance problem, so only a general checklist can be provided

Check the Query

The query does not qualify the columns clengthand plength so please check if they are defined in the table ds_comp – if not, maybe you do not need to join to this table at all…

Also I assume that docidno is a primary key of ds_doc and archiveno is PK of ds_arch. If not you query will work, but you will get a different result as you expect due to duplication caused by the join (this may also cause excesive elapsed time)!

Verify the Execution Plan

Produce the execution plan for your query in text form (to be able to post it) as follows

Remember that you are joining complete tables (not only few rows for some ID), so if you see INDEX ACCESS or NESTED LOOP there is a problem that explains the long runtime.

You want to see only HASH JOIN and FULL TABLE SCAN in your plan.

Index Access

Contrary to some recommendations in other answers if you want to profit from Index definition you do not need indexes on join columns (as explained above). What you can do is to cover all required attributes in indexes and perform the query using only indexes and ommit the table access at all. This will help if the tables are bright, i.e. the row size is large.

This definition will be needed

and you will receive this plan

Note the INDEX FULL SCAN and INDEX FAST FULL SCAN which means you are scanning the data from the index only and you do not need to perform the full table scan.

Use Parallel Option

With your rather simple query there is not much option to improve something. What works always is to deploy a parallel query using the /*+ PARALLEL(N) */ hint.

The precontition is that your database is configured for this option and you have hardware that can deploy it.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement