简体   繁体   中英

How to reduce the cost?

select * from XXCNN_AR_FIN016_MONTH_END
where period_name like '%-15'

I tried to create index on column period name but cost will not reduce.

Cost of this query is 12702.

After creating index, explain plan is showing options as storage full. For this I want to ask you the question: after creating index, why its not showing index scan or other scan?

How do I reduce the cost and time for this?

Too few data to answer, I'm afraid.

Though, you didn't say what kind of an index you created. Did you try a function-based index?

CREATE INDEX i1_xx
   ON xxcnn_ar_fin016_month_end (SUBSTR (period_name, -2));

and rewrite query to

SELECT *
  FROM xxcnn_ar_fin016_month_end
 WHERE SUBSTR (period_name, -2) = '15';

If leading characters are specified in the LIKE pattern, index can be used (for patterns like this '51-%').

The solution is to create functional index using REVERSE function

CREATE INDEX IDX_XXCNN_AR_FIN016_MONTH_END_reverse ON XXCNN_AR_FIN016_MONTH_END(REVERSE(period_name ));

And then query like this:

select * from XXCNN_AR_FIN016_MONTH_END
where REVERSE(period_namex) like REVERSE('%-15');

Oracle will recognize REVERSE() function in the query predicate and will use index.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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