Note that there are some explanatory texts on larger screens.

plurals
  1. POPerformance issues with JDBC
    primarykey
    data
    text
    <p>I'm currently facing an issue where a specific SQL-query is taking about 30 seconds to issue from within my Java application but &lt;1 sec in a SQL-client (SQL Developer). </p> <p>In the the question,<br> <a href="https://stackoverflow.com/questions/1339549/slow-query-in-java-by-jdbc-but-not-in-other-systems-toad">Slow query in Java by JDBC but not in other systems (TOAD)</a>, it is suggested that using a PreparedStatement bound to java variables could make the query execute far slower than in the SQL-client (TOAD in that case) because Oracle is getting confused about which indexes to use. Could this be an issue with a PreparedStatement without parameters as well?</p> <p>What could otherwise be the issue? </p> <p>The query looks something like </p> <pre><code>select sum(col1), sum(col2), max(select ...) from view_ where time_id = get_time_id(to_date('2010-10-10','yyyy-mm-dd')) </code></pre> <p>where view_ is a complex view containing aggregations of tables and other complex views. The query is executed as a PreparedStatement but without any parameters. It doesn't seem to make a difference whether we use prepared statement or just plain statements.</p> <p>Since the execution plan is quite huge I can't post all if it here, but the relevant difference seems to be: </p> <pre> UNION-ALL TABLE ACCESS FULL GVC_WH.PLAYER_FACT_DAILY TABLE 37 6717151 596,934.317 19940 240 7621178231 19502 </pre> <pre> UNION-ALL TABLE ACCESS BY INDEX ROWID GVC_WH.PLAYER_FACT_DAILY TABLE 38 2657 236.120 2429 30 20544658 2428 INDEX RANGE SCAN GVC_WH.PK_AGG_PLAYER INDEX (UNIQUE) 37 2657 16 1 638743 16 </pre> <p>Where the first snippet is from when running it with the JDBC Thin Client and the second from when running it inside SQL Developer. It's not picking up the correct index when running as a statement (makes no difference whether I use a prepared statement or not) with the JDBC Thin Client. The time difference i 30 seconds for the first and 0.5 seconds for the second. </p> <p>Could it be that using the function get_time_id prohibits the use of the index when used though JDBC, even though it is not function on the column and even though it seems to be working in SQL Developer? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload