Search in sources :

Example 1 with RunTimeStatistics

use of org.apache.derby.iapi.sql.execute.RunTimeStatistics in project derby by apache.

the class BaseJDBCTestCase method checkEstimatedRowCount.

/**
 * Return estimated row count for runtime statistics.
 * Requires caller first turned on RuntimeStatistics, executed a query and closed the ResultSet.
 *
 * For client calls we just return as we can't find out this information.
 * @param conn
 * @param expectedCount
 * @throws SQLException
 */
public static void checkEstimatedRowCount(Connection conn, double expectedCount) throws SQLException {
    if (!(conn instanceof EmbedConnection)) {
        return;
    }
    EmbedConnection econn = (EmbedConnection) conn;
    LanguageConnectionContext lcc = (LanguageConnectionContext) getLanguageConnectionContext(econn);
    RunTimeStatistics rts = lcc.getRunTimeStatisticsObject();
    assertNotNull(" RuntimeStatistics is null. Did you call SYSCS_UTIL.SYSCS_SET_RUNTIMESTATISTICS(1)?", rts);
    assertEquals((long) expectedCount, (long) rts.getEstimatedRowCount());
}
Also used : RunTimeStatistics(org.apache.derby.iapi.sql.execute.RunTimeStatistics) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) EmbedConnection(org.apache.derby.impl.jdbc.EmbedConnection)

Example 2 with RunTimeStatistics

use of org.apache.derby.iapi.sql.execute.RunTimeStatistics in project derby by apache.

the class NoPutResultSetImpl method close.

/**
 *		Close needs to invalidate any dependent statements, if this is a cursor.
 *		Must be called by any subclasses that override close().
 *		@exception StandardException on error
 */
public void close() throws StandardException {
    if (!isOpen)
        return;
    /* If this is the top ResultSet then we must
		 * close all of the open subqueries for the
		 * entire query.
		 */
    if (isTopResultSet) {
        /*
			** If run time statistics tracing is turned on, then now is the
			** time to dump out the information.
			*/
        LanguageConnectionContext lcc = getLanguageConnectionContext();
        // only if statistics is switched on, collect & derive them
        if (lcc.getRunTimeStatisticsMode() && !lcc.getStatementContext().getStatementWasInvalidated()) {
            endExecutionTime = getCurrentTimeMillis();
            // get the ResultSetStatisticsFactory, which gathers RuntimeStatistics
            ExecutionFactory ef = lcc.getLanguageConnectionFactory().getExecutionFactory();
            ResultSetStatisticsFactory rssf;
            rssf = ef.getResultSetStatisticsFactory();
            // get the RuntimeStatisticsImpl object which is the wrapper for all
            // gathered statistics about all the different resultsets
            RunTimeStatistics rsImpl = rssf.getRunTimeStatistics(activation, this, subqueryTrackingArray);
            // save the RTW (wrapper)object in the lcc
            lcc.setRunTimeStatisticsObject(rsImpl);
            // now explain gathered statistics, using an appropriate visitor
            XPLAINVisitor visitor = ef.getXPLAINFactory().getXPLAINVisitor();
            visitor.doXPLAIN(rsImpl, activation);
        }
        int staLength = (subqueryTrackingArray == null) ? 0 : subqueryTrackingArray.length;
        for (int index = 0; index < staLength; index++) {
            if (subqueryTrackingArray[index] == null) {
                continue;
            }
            if (subqueryTrackingArray[index].isClosed()) {
                continue;
            }
            subqueryTrackingArray[index].close();
        }
    }
    isOpen = false;
}
Also used : RunTimeStatistics(org.apache.derby.iapi.sql.execute.RunTimeStatistics) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) ResultSetStatisticsFactory(org.apache.derby.iapi.sql.execute.ResultSetStatisticsFactory) ExecutionFactory(org.apache.derby.iapi.sql.execute.ExecutionFactory) XPLAINVisitor(org.apache.derby.iapi.sql.execute.xplain.XPLAINVisitor)

Aggregations

LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)2 RunTimeStatistics (org.apache.derby.iapi.sql.execute.RunTimeStatistics)2 ExecutionFactory (org.apache.derby.iapi.sql.execute.ExecutionFactory)1 ResultSetStatisticsFactory (org.apache.derby.iapi.sql.execute.ResultSetStatisticsFactory)1 XPLAINVisitor (org.apache.derby.iapi.sql.execute.xplain.XPLAINVisitor)1 EmbedConnection (org.apache.derby.impl.jdbc.EmbedConnection)1