oracle table field types, and SQL unreasonable business, due to implicit conversion

Production encountered a problem today, SQL business is very simple, single-table queries and table with only three fields, there is a primary key ID, and filtered through a primary key ID, business ID page will pass more than a hundred calls came SQL, this table data volume size is more than 100 million, but this happens to SQL execution to run 15 seconds, totally affect the business can not be used.

select a,b,c from t where t.id in (1111,222,333,444,555..........)

I did not start to view the table design, but directly read the execution plan,

1 alter session set statistics_level=all;
2 执行SQL
3 select * from table(dbms_xplan.display_cursor(null,null,'ALLSTATS LAST')

Implementation plan to go directly to a full table scan, but there are a bunch of information in the filtering predicate

to_number(t.id)=1111 or to_number(t.id)=2222 ..............

See here flew to guess the specific problem, query T table ID field is VARCHAR2 type, and SQL in a digital type, SQL directly after an implicit conversion, the index will not walk, go directly to the whole table. The follow-up was found, but also because the business does not care about, after rising table data, performance issues become increasingly prominent was only thrown out

Reproduced in: https: //blog.51cto.com/2012ivan/2410375

Guess you like

Origin blog.csdn.net/weixin_34143774/article/details/92837889