Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/apache/derby/impl/sql/execute/rts/RunTimeStatisticsImpl.java


1   /*
2   
3      Derby - Class org.apache.derby.impl.sql.execute.rts.RunTimeStatisticsImpl
4   
5      Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable.
6   
7      Licensed under the Apache License, Version 2.0 (the "License");
8      you may not use this file except in compliance with the License.
9      You may obtain a copy of the License at
10  
11        http://www.apache.org/licenses/LICENSE-2.0
12  
13     Unless required by applicable law or agreed to in writing, software
14     distributed under the License is distributed on an "AS IS" BASIS,
15     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16     See the License for the specific language governing permissions and
17     limitations under the License.
18  
19   */
20  
21  package org.apache.derby.impl.sql.execute.rts;
22  
23  import org.apache.derby.iapi.services.io.StoredFormatIds;
24  import org.apache.derby.iapi.services.io.Formatable;
25  
26  import org.apache.derby.iapi.services.i18n.MessageService;
27  import org.apache.derby.iapi.reference.SQLState;
28  
29  import org.apache.derby.iapi.services.io.FormatableHashtable;
30  
31  import org.apache.derby.iapi.sql.execute.RunTimeStatistics;
32  import java.util.Vector;
33  
34  import java.io.ObjectOutput;
35  import java.io.ObjectInput;
36  import java.io.IOException;
37  
38  import java.sql.Timestamp;
39  
40  /**
41    RunTimeStatistics implemenation.
42  
43    @author jerry
44  
45  */
46  public final class RunTimeStatisticsImpl implements RunTimeStatistics
47  {
48  
49  
50    /* Leave these fields public for object inspectors */
51    public String  statementText;
52    public String  statementName;
53    public String  spsName;
54    public long     parseTime;
55    public long     bindTime;
56    public long     optimizeTime;
57    public long     generateTime;
58    public long  compileTime;
59    public long  executeTime;
60    public Timestamp beginCompilationTimestamp;
61    public Timestamp endCompilationTimestamp;
62    public Timestamp beginExecutionTimestamp;
63    public Timestamp endExecutionTimestamp;
64    public ResultSetStatistics topResultSetStatistics;
65    public ResultSetStatistics[] subqueryTrackingArray;
66  
67    // CONSTRUCTORS
68    /**
69     * 
70     */
71      public  RunTimeStatisticsImpl(
72                    String spsName,
73                    String statementName,
74                    String statementText,
75                    long compileTime,
76                    long parseTime,
77                    long bindTime,
78                    long optimizeTime,
79                    long generateTime,
80                    long executeTime,
81                    Timestamp beginCompilationTimestamp,
82                    Timestamp endCompilationTimestamp,
83                    Timestamp beginExecutionTimestamp,
84                    Timestamp endExecutionTimestamp,
85                    ResultSetStatistics[] subqueryTrackingArray,
86                    ResultSetStatistics topResultSetStatistics)
87    {
88      this.spsName = spsName;
89      this.statementName = statementName;
90      this.statementText = statementText;
91      this.compileTime = compileTime;
92      this.parseTime = parseTime;
93      this.bindTime = bindTime;
94      this.optimizeTime = optimizeTime;
95      this.generateTime = generateTime;
96      this.executeTime = executeTime;
97      this.beginCompilationTimestamp = beginCompilationTimestamp;
98      this.endCompilationTimestamp = endCompilationTimestamp;
99      this.beginExecutionTimestamp = beginExecutionTimestamp;
100     this.endExecutionTimestamp = endExecutionTimestamp;
101     this.subqueryTrackingArray = subqueryTrackingArray;
102     this.topResultSetStatistics = topResultSetStatistics;
103   }
104 
105   // RunTimeStatistics methods
106   /**
107    * Get the total compile time for the associated query in milliseconds.
108    * Compile time can be divided into parse, bind, optimize and generate times.
109    * 
110    * @return long    The total compile time for the associated query in milliseconds.
111    */
112   public long getCompileTimeInMillis()
113   {
114     return compileTime;
115   }
116 
117   /**
118    * Get the parse time for the associated query in milliseconds.
119    * 
120    * @return long    The parse time for the associated query in milliseconds.
121    */
122   public long getParseTimeInMillis()
123   {
124     return parseTime;
125   }
126 
127   /**
128    * Get the bind time for the associated query in milliseconds.
129    * 
130    * @return long    The bind time for the associated query in milliseconds.
131    */
132   public long getBindTimeInMillis()
133   {
134     return bindTime;
135   }
136 
137   /**
138    * Get the optimize time for the associated query in milliseconds.
139    * 
140    * @return long    The optimize time for the associated query in milliseconds.
141    */
142   public long getOptimizeTimeInMillis()
143   {
144     return optimizeTime;
145   }
146 
147   /**
148    * Get the generate time for the associated query in milliseconds.
149    * 
150    * @return long    The generate time for the associated query in milliseconds.
151    */
152   public long getGenerateTimeInMillis()
153   {
154     return generateTime;
155   }
156 
157   /**
158    * Get the execute time for the associated query in milliseconds.
159    * 
160    * @return long    The execute time for the associated query in milliseconds.
161    */
162   public long getExecuteTimeInMillis()
163   {
164     return executeTime;
165   }
166 
167   /**
168    * Get the timestamp for the beginning of query compilation. 
169    *
170    * @return java.sql.Timestamp  The timestamp for the beginning of query compilation.
171    */
172   public Timestamp getBeginCompilationTimestamp()
173   {
174     return beginCompilationTimestamp;
175   }
176 
177   /**
178    * Get the timestamp for the end of query compilation. 
179    *
180    * @return java.sql.Timestamp  The timestamp for the end of query compilation.
181    */
182   public Timestamp getEndCompilationTimestamp()
183   {
184     return endCompilationTimestamp;
185   }
186 
187   /**
188    * Get the timestamp for the beginning of query execution. 
189    *
190    * @return java.sql.Timestamp  The timestamp for the beginning of query execution.
191    */
192   public Timestamp getBeginExecutionTimestamp()
193   {
194     return beginExecutionTimestamp;
195   }
196 
197   /**
198    * Get the timestamp for the end of query execution. 
199    *
200    * @return java.sql.Timestamp  The timestamp for the end of query execution.
201    */
202   public Timestamp getEndExecutionTimestamp()
203   {
204     return endExecutionTimestamp;
205   }
206 
207   /**
208    * Get the name of the associated query or statement.
209    * (This will be an internally generated name if the
210    * user did not assign a name.)
211    *
212    * @return java.lang.String  The name of the associated query or statement.
213    */
214   public String getStatementName()  
215   {
216     return statementName;
217   }
218 
219   /**
220    * Get the name of the Stored Prepared Statement 
221    * for the statement.
222    *
223    * @return java.lang.String  The SPS name of the associated query or statement.
224    */
225   public String getSPSName()  
226   {
227     return spsName;
228   }
229 
230   /**
231    * Get the text for the associated query or statement.
232    *
233    * @return java.lang.String  The text for the associated query or statement.
234    */
235   public String getStatementText()
236   {
237     return statementText;
238   }
239 
240   /**
241    * Get the estimated row count for the number of rows returned
242    * by the associated query or statement.
243    *
244    * @return  The estimated number of rows returned by the associated
245    * query or statement.
246    */
247   public double getEstimatedRowCount()
248   {
249     if (topResultSetStatistics == null)
250     {
251       return 0.0;
252     }
253     return topResultSetStatistics.getEstimatedRowCount();
254   }
255 
256   /**
257    * Get the execution plan for the associated query or statement as a String.
258    *
259    * @return java.lang.String  The execution plan for the associated query or statement.
260    */
261   public String getStatementExecutionPlanText()  
262   {
263     if (topResultSetStatistics == null)
264     {
265       return (String) null;
266     }
267 
268     String subqueryInfo = "";
269 
270     /* Dump out the statistics for any subqueries */
271 
272     if (subqueryTrackingArray != null)
273     {
274       boolean  foundAttached = false;
275 
276       for (int index = 0; index < subqueryTrackingArray.length; index++)
277       {
278         if (subqueryTrackingArray[index] != null)
279         {
280           /* Only print attached subqueries message once */
281           if (! foundAttached)
282           {
283             subqueryInfo = MessageService.getTextMessage(
284                       SQLState.RTS_MATERIALIZED_SUBQS) +
285                     ":\n";
286             foundAttached = true;
287           }
288           subqueryInfo = subqueryInfo +
289             subqueryTrackingArray[index].getStatementExecutionPlanText(1);
290         }
291       }
292     }
293     return subqueryInfo +
294       topResultSetStatistics.getStatementExecutionPlanText(0);
295   }
296 
297   /**
298    * Get the information on the nodes relating to table and index scans
299    * from the execution plan for the associated query or statement as a String.
300    *
301    * @return java.lang.String  The nodes relating to table and index scans
302    * from the execution plan for the associated query or statement.
303    */
304   public String getScanStatisticsText()
305   {
306     return (topResultSetStatistics == null) ? 
307       (String)null :
308       topResultSetStatistics.getScanStatisticsText(null, 0);
309   }
310 
311   /**
312    * Get the information on the nodes relating to table and index scans
313    * for table tableName from the execution plan for the associated query 
314    * or statement as a String.
315    *
316    * @param tableName table for which user seeks statistics.
317    *
318    * @return java.lang.String  The nodes relating to table and index scans
319    * from the execution plan for the associated query or statement for 
320    * tableName.
321    */
322   public String getScanStatisticsText(String tableName)
323   {
324     if (topResultSetStatistics == null) 
325       return (String)null;
326     String s = topResultSetStatistics.getScanStatisticsText(tableName, 0);
327     return (s.equals("")) ? null : s;
328   }
329 
330 
331 
332   // Class implementation
333   
334   public String toString()
335   {
336     String spstext = 
337       (spsName != null) ? 
338           ("Stored Prepared Statement Name: \n\t" + spsName + "\n") : 
339           "";
340     return 
341       spstext +
342       MessageService.getTextMessage(SQLState.RTS_STATEMENT_NAME) +
343         ": \n\t" + statementName + "\n" +
344       MessageService.getTextMessage(SQLState.RTS_STATEMENT_TEXT) +
345         ": \n\t" + statementText + "\n" +
346       MessageService.getTextMessage(SQLState.RTS_PARSE_TIME) +
347         ": " + parseTime + "\n" +
348       MessageService.getTextMessage(SQLState.RTS_BIND_TIME) +
349         ": " + bindTime + "\n" +
350       MessageService.getTextMessage(SQLState.RTS_OPTIMIZE_TIME) +
351         ": " + optimizeTime + "\n" +
352       MessageService.getTextMessage(SQLState.RTS_GENERATE_TIME) +
353         ": " + generateTime + "\n" +
354       MessageService.getTextMessage(SQLState.RTS_COMPILE_TIME) +
355         ": " + compileTime + "\n" +
356       MessageService.getTextMessage(SQLState.RTS_EXECUTE_TIME) +
357         ": " + executeTime + "\n" +
358       MessageService.getTextMessage(SQLState.RTS_BEGIN_COMP_TS) +
359         " : " + beginCompilationTimestamp + "\n" +
360       MessageService.getTextMessage(SQLState.RTS_END_COMP_TS) +
361         " : " + endCompilationTimestamp + "\n" +
362       MessageService.getTextMessage(SQLState.RTS_BEGIN_EXE_TS) +
363         " : " + beginExecutionTimestamp + "\n" +
364       MessageService.getTextMessage(SQLState.RTS_END_EXE_TS) +
365         " : " + endExecutionTimestamp + "\n" +
366       MessageService.getTextMessage(SQLState.RTS_STMT_EXE_PLAN_TXT) +
367         ": \n" + getStatementExecutionPlanText();
368   }
369 
370   /**
371    * Get the objects to be displayed when this tree object is expanded.
372    * <P>
373    * The objects returned can be of any type, including addtional Inspectables.
374    *
375    * @return java.util.Vector  A vector of objects.
376    */
377   public Vector getChildren(){
378     Vector children = new Vector();
379     children.addElement(topResultSetStatistics);
380     return children;
381   }
382 
383 }