Home > Software engineering >  how to reduce the cost of the query?
how to reduce the cost of the query?

Time:12-10

select * from ITEM_STG where STATUS = 'PROCESSED_CROSSREF' AND TRUNC(Creation_date) < Trunc(sysdate)-10

  • in explain plan showing cost as 6156 I tried to create index on creation date and status column has already index on this table after creating index we check the cost its not reduce. How to reduce the cost and time for this query.

CodePudding user response:

Try:

select 
  * 
from ITEM_STG 
where STATUS = 'PROCESSED_CROSSREF' 
  AND Creation_date < Trunc(sysdate)-10

I don't even have to know the Database Management System. But if you apply * any * expression to a column in a table that you want to use as part of a join or filter condition, any index on that column will be ignored. There is no reliable way for the optimiser to guess what the expression will do to the column's value, so any cost optimising prediction is impossible. The expression could make things better, in theory, but more often than not, it makes things worse.

So the optimiser will just ignore any data access improvement database objects in evaluating the query.

CodePudding user response:

First, try to precise the select statement with the desired column, even if you want to get all columns. Then, try reduce your set avoiding aggregated statements and sorting the condition statement from most weight to the most soft operation in order to simplify the payload into your DBMS. Ensure first the quality of your query before trying something on indexation strategy. Otherwise, your index rules will be not take in account.

SELECT c1,c2,c3
FROM ITEM_STG
WHERE 1=1
AND STATUS = 'PROCESSED_CROSSREF'
AND TRUNC(Creation_date) < TRUNC(sysdate)     
AND TRUNC(sysdate) = TRUNC(sysdate)-10
  • Related