michael nesterenko
michael nesterenko

Reputation: 14439

force query to v$session_longops

I have query that takes a lot time to execute (distinct operation). But that query is not listed in v$session_longops. How can I force query to be put to v$session_longops.

Upvotes: 3

Views: 2065

Answers (1)

Justin Cave
Justin Cave

Reputation: 231671

Unfortunately, if you're talking about a single SQL query, you probably can't force it to show up in V$SESSION_LONGOPS. Oracle writes a query to V$SESSION_LONGOPS when one step takes more than 6 seconds. But you can have a very long-running query that is composed of many very short steps. A nested loop join where both inner and outer queries are using an index to fetch the data, for example, can run for a long time but no individual operation may take more than a small fraction of a second. If that's the case, it is generally worth comparing the optimizer's estimated cardinality against the actual cardinality. It is quite possible that Oracle is executing a large number of short operations because it is underestimating the cardinality of various steps of the operation. Getting better estimates for the optimizer may result both in a more efficient query plan and the longer operations being tracked in V$SESSION_LONGOPS.

If you are talking about a PL/SQL process that happens to issue one or more SQL queries, Rajesh's comment is spot on. You can use the DBMS_APPLICATION_INFO.SET_SESSION_LONGOPS method to have the progress of your PL/SQL process tracked in V$SESSION_LONGOPS.

Upvotes: 4

Related Questions