1 21 22 package org.apache.derby.impl.sql.execute.rts; 23 24 import org.apache.derby.iapi.services.io.StoredFormatIds; 25 import org.apache.derby.iapi.services.io.Formatable; 26 27 import org.apache.derby.iapi.services.i18n.MessageService; 28 import org.apache.derby.iapi.reference.SQLState; 29 30 import org.apache.derby.iapi.services.io.FormatableHashtable; 31 32 import org.apache.derby.iapi.sql.execute.RunTimeStatistics; 33 import java.util.Vector ; 34 35 import java.io.ObjectOutput ; 36 import java.io.ObjectInput ; 37 import java.io.IOException ; 38 39 import java.sql.Timestamp ; 40 41 47 public final class RunTimeStatisticsImpl implements RunTimeStatistics 48 { 49 50 51 52 public String statementText; 53 public String statementName; 54 public String spsName; 55 public long parseTime; 56 public long bindTime; 57 public long optimizeTime; 58 public long generateTime; 59 public long compileTime; 60 public long executeTime; 61 public Timestamp beginCompilationTimestamp; 62 public Timestamp endCompilationTimestamp; 63 public Timestamp beginExecutionTimestamp; 64 public Timestamp endExecutionTimestamp; 65 public ResultSetStatistics topResultSetStatistics; 66 public ResultSetStatistics[] subqueryTrackingArray; 67 68 72 public RunTimeStatisticsImpl( 73 String spsName, 74 String statementName, 75 String statementText, 76 long compileTime, 77 long parseTime, 78 long bindTime, 79 long optimizeTime, 80 long generateTime, 81 long executeTime, 82 Timestamp beginCompilationTimestamp, 83 Timestamp endCompilationTimestamp, 84 Timestamp beginExecutionTimestamp, 85 Timestamp endExecutionTimestamp, 86 ResultSetStatistics[] subqueryTrackingArray, 87 ResultSetStatistics topResultSetStatistics) 88 { 89 this.spsName = spsName; 90 this.statementName = statementName; 91 this.statementText = statementText; 92 this.compileTime = compileTime; 93 this.parseTime = parseTime; 94 this.bindTime = bindTime; 95 this.optimizeTime = optimizeTime; 96 this.generateTime = generateTime; 97 this.executeTime = executeTime; 98 this.beginCompilationTimestamp = beginCompilationTimestamp; 99 this.endCompilationTimestamp = endCompilationTimestamp; 100 this.beginExecutionTimestamp = beginExecutionTimestamp; 101 this.endExecutionTimestamp = endExecutionTimestamp; 102 this.subqueryTrackingArray = subqueryTrackingArray; 103 this.topResultSetStatistics = topResultSetStatistics; 104 } 105 106 113 public long getCompileTimeInMillis() 114 { 115 return compileTime; 116 } 117 118 123 public long getParseTimeInMillis() 124 { 125 return parseTime; 126 } 127 128 133 public long getBindTimeInMillis() 134 { 135 return bindTime; 136 } 137 138 143 public long getOptimizeTimeInMillis() 144 { 145 return optimizeTime; 146 } 147 148 153 public long getGenerateTimeInMillis() 154 { 155 return generateTime; 156 } 157 158 163 public long getExecuteTimeInMillis() 164 { 165 return executeTime; 166 } 167 168 173 public Timestamp getBeginCompilationTimestamp() 174 { 175 return beginCompilationTimestamp; 176 } 177 178 183 public Timestamp getEndCompilationTimestamp() 184 { 185 return endCompilationTimestamp; 186 } 187 188 193 public Timestamp getBeginExecutionTimestamp() 194 { 195 return beginExecutionTimestamp; 196 } 197 198 203 public Timestamp getEndExecutionTimestamp() 204 { 205 return endExecutionTimestamp; 206 } 207 208 215 public String getStatementName() 216 { 217 return statementName; 218 } 219 220 226 public String getSPSName() 227 { 228 return spsName; 229 } 230 231 236 public String getStatementText() 237 { 238 return statementText; 239 } 240 241 248 public double getEstimatedRowCount() 249 { 250 if (topResultSetStatistics == null) 251 { 252 return 0.0; 253 } 254 return topResultSetStatistics.getEstimatedRowCount(); 255 } 256 257 262 public String getStatementExecutionPlanText() 263 { 264 if (topResultSetStatistics == null) 265 { 266 return (String ) null; 267 } 268 269 String subqueryInfo = ""; 270 271 272 273 if (subqueryTrackingArray != null) 274 { 275 boolean foundAttached = false; 276 277 for (int index = 0; index < subqueryTrackingArray.length; index++) 278 { 279 if (subqueryTrackingArray[index] != null) 280 { 281 282 if (! foundAttached) 283 { 284 subqueryInfo = MessageService.getTextMessage( 285 SQLState.RTS_MATERIALIZED_SUBQS) + 286 ":\n"; 287 foundAttached = true; 288 } 289 subqueryInfo = subqueryInfo + 290 subqueryTrackingArray[index].getStatementExecutionPlanText(1); 291 } 292 } 293 } 294 return subqueryInfo + 295 topResultSetStatistics.getStatementExecutionPlanText(0); 296 } 297 298 305 public String getScanStatisticsText() 306 { 307 return (topResultSetStatistics == null) ? 308 (String )null : 309 topResultSetStatistics.getScanStatisticsText(null, 0); 310 } 311 312 323 public String getScanStatisticsText(String tableName) 324 { 325 if (topResultSetStatistics == null) 326 return (String )null; 327 String s = topResultSetStatistics.getScanStatisticsText(tableName, 0); 328 return (s.equals("")) ? null : s; 329 } 330 331 332 333 335 public String toString() 336 { 337 String spstext = 338 (spsName != null) ? 339 ("Stored Prepared Statement Name: \n\t" + spsName + "\n") : 340 ""; 341 return 342 spstext + 343 MessageService.getTextMessage(SQLState.RTS_STATEMENT_NAME) + 344 ": \n\t" + statementName + "\n" + 345 MessageService.getTextMessage(SQLState.RTS_STATEMENT_TEXT) + 346 ": \n\t" + statementText + "\n" + 347 MessageService.getTextMessage(SQLState.RTS_PARSE_TIME) + 348 ": " + parseTime + "\n" + 349 MessageService.getTextMessage(SQLState.RTS_BIND_TIME) + 350 ": " + bindTime + "\n" + 351 MessageService.getTextMessage(SQLState.RTS_OPTIMIZE_TIME) + 352 ": " + optimizeTime + "\n" + 353 MessageService.getTextMessage(SQLState.RTS_GENERATE_TIME) + 354 ": " + generateTime + "\n" + 355 MessageService.getTextMessage(SQLState.RTS_COMPILE_TIME) + 356 ": " + compileTime + "\n" + 357 MessageService.getTextMessage(SQLState.RTS_EXECUTE_TIME) + 358 ": " + executeTime + "\n" + 359 MessageService.getTextMessage(SQLState.RTS_BEGIN_COMP_TS) + 360 " : " + beginCompilationTimestamp + "\n" + 361 MessageService.getTextMessage(SQLState.RTS_END_COMP_TS) + 362 " : " + endCompilationTimestamp + "\n" + 363 MessageService.getTextMessage(SQLState.RTS_BEGIN_EXE_TS) + 364 " : " + beginExecutionTimestamp + "\n" + 365 MessageService.getTextMessage(SQLState.RTS_END_EXE_TS) + 366 " : " + endExecutionTimestamp + "\n" + 367 MessageService.getTextMessage(SQLState.RTS_STMT_EXE_PLAN_TXT) + 368 ": \n" + getStatementExecutionPlanText(); 369 } 370 371 378 public Vector getChildren(){ 379 Vector children = new Vector (); 380 children.addElement(topResultSetStatistics); 381 return children; 382 } 383 384 } 385 | Popular Tags |