Search in sources :

Example 1 with XPLAINStatementDescriptor

use of org.apache.derby.impl.sql.catalog.XPLAINStatementDescriptor in project derby by apache.

the class XPLAINSystemTableVisitor method doXPLAIN.

/**
 * the interface method, which gets called by the Top-ResultSet, which starts
 *  the tree traversal.
 */
public void doXPLAIN(RunTimeStatistics rss, Activation activation) throws StandardException {
    // save this activation
    this.activation = activation;
    // reset this visitor
    reset();
    // get the timings settings
    considerTimingInformation = lcc.getStatisticsTiming();
    // placeholder for the stmt timings UUID
    UUID stmtTimingsUUID = null;
    // 1. create new stmt timings descriptor
    if (considerTimingInformation) {
        stmtTimingsUUID = dd.getUUIDFactory().createUUID();
        Timestamp endExeTS = rss.getEndExecutionTimestamp();
        Timestamp beginExeTS = rss.getBeginExecutionTimestamp();
        long exeTime;
        if (endExeTS != null && beginExeTS != null) {
            exeTime = endExeTS.getTime() - beginExeTS.getTime();
        } else {
            exeTime = 0;
        }
        stmtTimings = new XPLAINStatementTimingsDescriptor(// the Timing UUID
        stmtTimingsUUID, // the Parse Time
        rss.getParseTimeInMillis(), // the Bind Time
        rss.getBindTimeInMillis(), // the Optimize Time
        rss.getOptimizeTimeInMillis(), // the Generate Time
        rss.getGenerateTimeInMillis(), // the Compile Time
        rss.getCompileTimeInMillis(), // the Execute Time, TODO resolve why getExecutionTime() returns 0
        exeTime, // the Begin Compilation TS
        rss.getBeginCompilationTimestamp(), // the End   Compilation TS
        rss.getEndCompilationTimestamp(), // the Begin Execution   TS
        rss.getBeginExecutionTimestamp(), // the End   Execution   TS
        rss.getEndExecutionTimestamp());
    }
    // 2. create new Statement Descriptor
    // create new UUID
    stmtUUID = dd.getUUIDFactory().createUUID();
    // extract stmt type
    String type = XPLAINUtil.getStatementType(rss.getStatementText());
    // TODO improve usability to switch between call stmt explanation on or off
    if (type.equalsIgnoreCase("C") && no_call_stmts)
        return;
    // get transaction ID
    String xaID = lcc.getTransactionExecute().getTransactionIdString();
    // get session ID
    String sessionID = Integer.toString(lcc.getInstanceNumber());
    // get the JVM ID
    String jvmID = Integer.toString(JVMInfo.JDK_ID);
    // get the OS ID
    String osID = System.getProperty("os.name");
    // the current system time
    long current = System.currentTimeMillis();
    // the xplain type
    String XPLAINtype = lcc.getXplainOnlyMode() ? XPLAINUtil.XPLAIN_ONLY : XPLAINUtil.XPLAIN_FULL;
    // the xplain time
    Timestamp time = new Timestamp(current);
    // the thread id
    String threadID = Thread.currentThread().toString();
    stmt = new XPLAINStatementDescriptor(// unique statement UUID
    stmtUUID, // the statement name
    rss.getStatementName(), // the statement type
    type, // the statement text
    rss.getStatementText(), // the JVM ID
    jvmID, // the OS ID
    osID, // the EXPLAIN tpye
    XPLAINtype, // the EXPLAIN Timestamp
    time, // the Thread ID
    threadID, // the transaction ID
    xaID, // the Session ID
    sessionID, // the Database name
    lcc.getDbname(), // the DRDA ID
    lcc.getDrdaID(), // Timing ID, if available
    stmtTimingsUUID);
    try {
        // add it to system catalog
        addStmtDescriptorsToSystemCatalog();
        // get TopRSS and start the traversal of the RSS-tree
        rss.acceptFromTopResultSet(this);
        // add the filled lists to the dictionary
        addArraysToSystemCatalogs();
    } catch (SQLException e) {
        throw StandardException.plainWrapException(e);
    }
    // clean up to free kept resources
    clean();
}
Also used : XPLAINStatementDescriptor(org.apache.derby.impl.sql.catalog.XPLAINStatementDescriptor) SQLException(java.sql.SQLException) XPLAINStatementTimingsDescriptor(org.apache.derby.impl.sql.catalog.XPLAINStatementTimingsDescriptor) UUID(org.apache.derby.catalog.UUID) Timestamp(java.sql.Timestamp)

Example 2 with XPLAINStatementDescriptor

use of org.apache.derby.impl.sql.catalog.XPLAINStatementDescriptor in project derby by apache.

the class SystemProcedures method SYSCS_SET_XPLAIN_SCHEMA.

/**
 * This procedure sets the current xplain schema.
 * If the schema is not set, runtime statistics are captured as a
 * textual stream printout. If it is set, statisitcs information is
 * stored in that schema in user tables.
 * @param schemaName May be an empty string.
 * @throws SQLException
 */
public static void SYSCS_SET_XPLAIN_SCHEMA(String schemaName) throws SQLException, StandardException {
    try {
        // make sure that application code doesn't bypass security checks
        // by calling this public entry point
        SecurityUtil.authorize(Securable.SET_XPLAIN_SCHEMA);
    } catch (StandardException se) {
        throw PublicAPI.wrapStandardException(se);
    }
    LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC();
    TransactionController tc = lcc.getTransactionExecute();
    if (schemaName == null || schemaName.trim().length() == 0) {
        lcc.setXplainSchema(null);
        return;
    }
    boolean statsSave = lcc.getRunTimeStatisticsMode();
    lcc.setRunTimeStatisticsMode(false);
    createXplainSchema(schemaName);
    createXplainTable(lcc, schemaName, new XPLAINStatementDescriptor());
    createXplainTable(lcc, schemaName, new XPLAINStatementTimingsDescriptor());
    createXplainTable(lcc, schemaName, new XPLAINResultSetDescriptor());
    createXplainTable(lcc, schemaName, new XPLAINResultSetTimingsDescriptor());
    createXplainTable(lcc, schemaName, new XPLAINScanPropsDescriptor());
    createXplainTable(lcc, schemaName, new XPLAINSortPropsDescriptor());
    lcc.setRunTimeStatisticsMode(statsSave);
    lcc.setXplainSchema(schemaName);
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) XPLAINSortPropsDescriptor(org.apache.derby.impl.sql.catalog.XPLAINSortPropsDescriptor) XPLAINStatementDescriptor(org.apache.derby.impl.sql.catalog.XPLAINStatementDescriptor) XPLAINResultSetDescriptor(org.apache.derby.impl.sql.catalog.XPLAINResultSetDescriptor) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) XPLAINScanPropsDescriptor(org.apache.derby.impl.sql.catalog.XPLAINScanPropsDescriptor) XPLAINStatementTimingsDescriptor(org.apache.derby.impl.sql.catalog.XPLAINStatementTimingsDescriptor) TransactionController(org.apache.derby.iapi.store.access.TransactionController) XPLAINResultSetTimingsDescriptor(org.apache.derby.impl.sql.catalog.XPLAINResultSetTimingsDescriptor)

Aggregations

XPLAINStatementDescriptor (org.apache.derby.impl.sql.catalog.XPLAINStatementDescriptor)2 XPLAINStatementTimingsDescriptor (org.apache.derby.impl.sql.catalog.XPLAINStatementTimingsDescriptor)2 SQLException (java.sql.SQLException)1 Timestamp (java.sql.Timestamp)1 UUID (org.apache.derby.catalog.UUID)1 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)1 TransactionController (org.apache.derby.iapi.store.access.TransactionController)1 XPLAINResultSetDescriptor (org.apache.derby.impl.sql.catalog.XPLAINResultSetDescriptor)1 XPLAINResultSetTimingsDescriptor (org.apache.derby.impl.sql.catalog.XPLAINResultSetTimingsDescriptor)1 XPLAINScanPropsDescriptor (org.apache.derby.impl.sql.catalog.XPLAINScanPropsDescriptor)1 XPLAINSortPropsDescriptor (org.apache.derby.impl.sql.catalog.XPLAINSortPropsDescriptor)1 StandardException (org.apache.derby.shared.common.error.StandardException)1