KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > execute > rts > RealHashTableStatistics


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.execute.rts.RealHashTableStatistics
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.sql.execute.rts;
23
24 import org.apache.derby.iapi.services.io.StoredFormatIds;
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 import org.apache.derby.iapi.services.io.FormatableProperties;
31
32 import java.io.ObjectOutput JavaDoc;
33 import java.io.ObjectInput JavaDoc;
34 import java.io.IOException JavaDoc;
35
36 import java.util.Enumeration JavaDoc;
37 import java.util.Properties JavaDoc;
38
39
40 /**
41   ResultSetStatistics implemenation for HashTableResultSet.
42
43   @author jerry
44
45 */

46 public class RealHashTableStatistics
47     extends RealNoPutResultSetStatistics
48 {
49
50     /* Leave these fields public for object inspectors */
51     public int hashtableSize;
52     public int[] hashKeyColumns;
53     public String JavaDoc isolationLevel;
54     public String JavaDoc nextQualifiers;
55     public FormatableProperties scanProperties;
56     public ResultSetStatistics childResultSetStatistics;
57     public ResultSetStatistics[] subqueryTrackingArray;
58
59     // CONSTRUCTORS
60

61     /**
62      *
63      *
64      */

65     public RealHashTableStatistics(
66                                     int numOpens,
67                                     int rowsSeen,
68                                     int rowsFiltered,
69                                     long constructorTime,
70                                     long openTime,
71                                     long nextTime,
72                                     long closeTime,
73                                     int resultSetNumber,
74                                     int hashtableSize,
75                                     int[] hashKeyColumns,
76                                     String JavaDoc nextQualifiers,
77                                     Properties scanProperties,
78                                     double optimizerEstimatedRowCount,
79                                     double optimizerEstimatedCost,
80                                     ResultSetStatistics[] subqueryTrackingArray,
81                                     ResultSetStatistics childResultSetStatistics
82                                     )
83     {
84         super(
85             numOpens,
86             rowsSeen,
87             rowsFiltered,
88             constructorTime,
89             openTime,
90             nextTime,
91             closeTime,
92             resultSetNumber,
93             optimizerEstimatedRowCount,
94             optimizerEstimatedCost
95             );
96         this.hashtableSize = hashtableSize;
97         this.hashKeyColumns = hashKeyColumns;
98         this.nextQualifiers = nextQualifiers;
99         this.scanProperties = new FormatableProperties();
100         if (scanProperties != null)
101         {
102             for (Enumeration JavaDoc e = scanProperties.keys(); e.hasMoreElements(); )
103             {
104                 String JavaDoc key = (String JavaDoc)e.nextElement();
105                 this.scanProperties.put(key, scanProperties.get(key));
106             }
107         }
108         this.subqueryTrackingArray = subqueryTrackingArray;
109         this.childResultSetStatistics = childResultSetStatistics;
110     }
111
112     // ResultSetStatistics methods
113

114     /**
115      * Return the statement execution plan as a String.
116      *
117      * @param depth Indentation level.
118      *
119      * @return String The statement executio plan as a String.
120      */

121     public String JavaDoc getStatementExecutionPlanText(int depth)
122     {
123         String JavaDoc subqueryInfo = "";
124
125         initFormatInfo(depth);
126
127         /* Dump out the statistics for any subqueries */
128
129         if (subqueryTrackingArray != null)
130         {
131             boolean foundAttached = false;
132
133             for (int index = 0; index < subqueryTrackingArray.length; index++)
134             {
135                 if (subqueryTrackingArray[index] != null)
136                 {
137                     /* Only print attached subqueries message once */
138                     if (! foundAttached)
139                     {
140                         subqueryInfo = indent +
141                             MessageService.getTextMessage(
142                                                     SQLState.RTS_ATTACHED_SQS) +
143                             ":\n";
144                         foundAttached = true;
145                     }
146                     subqueryInfo = subqueryInfo +
147                         subqueryTrackingArray[index].getStatementExecutionPlanText(sourceDepth);
148                 }
149             }
150         }
151
152         initFormatInfo(depth);
153         
154         String JavaDoc hashKeyColumnString;
155         if (hashKeyColumns.length == 1)
156         {
157             hashKeyColumnString =
158                     MessageService.getTextMessage(SQLState.RTS_HASH_KEY) +
159                     " " +
160                     hashKeyColumns[0];
161         }
162         else
163         {
164             hashKeyColumnString =
165                     MessageService.getTextMessage(SQLState.RTS_HASH_KEYS) +
166                     " (" + hashKeyColumns[0];
167             for (int index = 1; index < hashKeyColumns.length; index++)
168             {
169                 hashKeyColumnString = hashKeyColumnString + "," + hashKeyColumns[index];
170             }
171             hashKeyColumnString = hashKeyColumnString + ")";
172         }
173
174         return
175             indent + MessageService.getTextMessage(
176                                                 SQLState.RTS_HASH_TABLE_RS) +
177                                         " (" + resultSetNumber + "):" + "\n" +
178             indent + MessageService.getTextMessage(
179                                                 SQLState.RTS_NUM_OPENS) +
180                                         " = " + numOpens + "\n" +
181             indent + MessageService.getTextMessage(
182                                                 SQLState.RTS_HASH_TABLE_SIZE) +
183                                         " = " + hashtableSize + "\n" +
184             indent + hashKeyColumnString + "\n" +
185             indent + MessageService.getTextMessage(
186                                                 SQLState.RTS_ROWS_SEEN) +
187                                         " = " + rowsSeen + "\n" +
188             indent + MessageService.getTextMessage(
189                                                 SQLState.RTS_ROWS_FILTERED) +
190                                         " = " + rowsFiltered + "\n" +
191             dumpTimeStats(indent, subIndent) + "\n" +
192             dumpEstimatedCosts(subIndent) + "\n" +
193             ((rowsSeen > 0)
194                 ?
195                     subIndent +
196                     MessageService.getTextMessage(SQLState.RTS_NEXT_TIME) +
197                     " = " + (nextTime / rowsSeen) + "\n"
198                 :
199                     "") + "\n" +
200             subIndent + MessageService.getTextMessage(
201                                                     SQLState.RTS_NEXT_QUALS) +
202                                         ":\n" + nextQualifiers + "\n" +
203             indent + MessageService.getTextMessage(SQLState.RTS_SOURCE_RS) +
204                                         ":\n" +
205             childResultSetStatistics.getStatementExecutionPlanText(sourceDepth);
206     }
207
208     /**
209      * Return information on the scan nodes from the statement execution
210      * plan as a String.
211      *
212      * @param depth Indentation level.
213      * @param tableName if not NULL then print information for this table only
214      *
215      * @return String The information on the scan nodes from the
216      * statement execution plan as a String.
217      */

218     public String JavaDoc getScanStatisticsText(String JavaDoc tableName, int depth)
219     {
220         if (tableName == null)
221             return getStatementExecutionPlanText(depth);
222         else
223             return (String JavaDoc)null;
224     }
225
226
227     // Class implementation
228

229     public String JavaDoc toString()
230     {
231         return getStatementExecutionPlanText(0);
232     }
233     /**
234      * If this node is on a database item (like a table or an index), then provide a
235    * string that describes the on item.
236    *
237      */

238   public String JavaDoc getNodeOn(){
239     return "";
240   }
241     /**
242    * Format for display, a name for this node.
243      *
244      */

245   public String JavaDoc getNodeName(){
246     return MessageService.getTextMessage(SQLState.RTS_HASH_TABLE);
247   }
248 }
249
Popular Tags