A statement causes high CPU occupancy in Oracle database

after the execution of a SQL statement, it seems that the CPU occupancy of the Oracle database (12c) server has been pulled up, causing all database operations to be slowed down. SQL itself is not special. The logic is as follows:

"select sum(a.shuliang) sl from a,b where a.someid_a=? and a.someid_b=? and b.someid_c=? and a.id=b.id"

        ps = con.prepareStatement(sql);
        if (params != null) {
            for (int i = 0; i < params.size(); iPP) {
                Object v = params.get(i);
                ps.setObject(i + 1, v);
            }
        }
        rs = ps.executeQuery();

there has been no problem with the program using the above SQL. One day, I found that the database will slow down as long as it is executed. Then after the above SQL parameter values are directly inserted into the SQL in the program (below), the problem of slowing down no longer occurs, and other SQL in the same processing also use the parameter form, but only this SQL has a problem.

"select sum(a.shuliang) sl from a,b where a.someid_a=""+A+"" and a.someid_b=""+B+"" and b.someid_c=""+C+"" and a.id=b.id"

solve.

Mar.10,2021

if the sql statement in oracle uses bound variables, the execution plan formed by sampling data according to the variables may be inconsistent with the actual data distribution, resulting in poor performance. The sql formed by
string concatenation does not have this kind of problem, but it will lead to too much hard parsing, and the overall performance of the database will be seriously affected if too much sql is executed in parallel.

if you can confirm a reasonable execution plan, you can solidify the execution plan through hints or outline.

Menu