KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.execute.rts.RealTableScanStatistics
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 import org.apache.derby.iapi.util.PropertyUtil;
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 import org.apache.derby.iapi.services.io.FormatableProperties;
32
33 import java.io.ObjectOutput JavaDoc;
34 import java.io.ObjectInput JavaDoc;
35 import java.io.IOException JavaDoc;
36
37 import java.util.Enumeration JavaDoc;
38 import java.util.Properties JavaDoc;
39
40
41 /**
42   ResultSetStatistics implemenation for TableScanResultSet.
43
44   @author jerry
45
46 */

47 public class RealTableScanStatistics
48     extends RealNoPutResultSetStatistics
49 {
50
51     /* Leave these fields public for object inspectors */
52     public boolean isConstraint;
53     public boolean coarserLock;
54     public int fetchSize;
55     public String JavaDoc isolationLevel;
56     public String JavaDoc tableName;
57     public String JavaDoc userSuppliedOptimizerOverrides;
58     public String JavaDoc indexName;
59     public String JavaDoc lockString;
60     public String JavaDoc qualifiers;
61     public String JavaDoc startPosition;
62     public String JavaDoc stopPosition;
63     public FormatableProperties scanProperties;
64
65     // CONSTRUCTORS
66

67     /**
68      *
69      *
70      */

71     public RealTableScanStatistics(int numOpens,
72                                     int rowsSeen,
73                                     int rowsFiltered,
74                                     long constructorTime,
75                                     long openTime,
76                                     long nextTime,
77                                     long closeTime,
78                                     int resultSetNumber,
79                                     String JavaDoc tableName,
80                                     String JavaDoc userSuppliedOptimizerOverrides,
81                                     String JavaDoc indexName,
82                                     boolean isConstraint,
83                                     String JavaDoc qualifiers,
84                                     Properties scanProperties,
85                                     String JavaDoc startPosition,
86                                     String JavaDoc stopPosition,
87                                     String JavaDoc isolationLevel,
88                                     String JavaDoc lockString,
89                                     int fetchSize,
90                                     boolean coarserLock,
91                                     double optimizerEstimatedRowCount,
92                                     double optimizerEstimatedCost
93                                     )
94     {
95         super(
96             numOpens,
97             rowsSeen,
98             rowsFiltered,
99             constructorTime,
100             openTime,
101             nextTime,
102             closeTime,
103             resultSetNumber,
104             optimizerEstimatedRowCount,
105             optimizerEstimatedCost
106             );
107         this.tableName = tableName;
108         this.userSuppliedOptimizerOverrides = userSuppliedOptimizerOverrides;
109         this.indexName = indexName;
110         this.isConstraint = isConstraint;
111         this.qualifiers = qualifiers;
112         this.scanProperties = new FormatableProperties();
113         for (Enumeration JavaDoc e = scanProperties.keys(); e.hasMoreElements(); )
114         {
115             String JavaDoc key = (String JavaDoc)e.nextElement();
116             this.scanProperties.put(key, scanProperties.get(key));
117         }
118         this.startPosition = startPosition;
119         this.stopPosition = stopPosition;
120         this.isolationLevel = isolationLevel;
121         this.lockString = lockString;
122         this.fetchSize = fetchSize;
123         this.coarserLock = coarserLock;
124     }
125
126     // ResultSetStatistics methods
127

128     /**
129      * Return the statement execution plan as a String.
130      *
131      * @param depth Indentation level
132      *
133      * @return String The statement executio plan as a String.
134      */

135     public String JavaDoc getStatementExecutionPlanText(int depth)
136     {
137         String JavaDoc header = "";
138         String JavaDoc isolationString = null;
139
140         initFormatInfo(depth);
141
142         if (userSuppliedOptimizerOverrides != null)
143         {
144             header =
145                 indent + MessageService.getTextMessage(SQLState.RTS_USER_SUPPLIED_OPTIMIZER_OVERRIDES_FOR_TABLE,
146                         tableName, userSuppliedOptimizerOverrides);
147             header = header + "\n";
148         }
149         if (indexName != null)
150         {
151             header = header +
152                 indent + MessageService.getTextMessage(
153                                             SQLState.RTS_IS_RS_USING,
154                                             tableName,
155                                             MessageService.getTextMessage(
156                                                 (isConstraint) ?
157                                                     SQLState.RTS_CONSTRAINT :
158                                                     SQLState.RTS_INDEX),
159                                             indexName);
160                 
161         }
162         else
163         {
164             header = header +
165                 indent + MessageService.getTextMessage(
166                                             SQLState.RTS_TS_RS_FOR,
167                                             tableName);
168         }
169
170         header = header + " " + MessageService.getTextMessage(
171                                             SQLState.RTS_LOCKING_OPTIMIZER,
172                                             isolationLevel,
173                                             lockString);
174
175         /* Did we get (or already have) a coarser lock then requested
176          * due to a covering lock, lock escalation or configuration
177          * for table locking.
178          */

179         if (coarserLock)
180         {
181             header = header + " (" + MessageService.getTextMessage(
182                                                     SQLState.RTS_ACTUAL_TABLE) +
183                                 ")";
184         }
185
186         header = header + "\n";
187
188         String JavaDoc scanInfo =
189             indent + MessageService.getTextMessage(SQLState.RTS_SCAN_INFO) +
190                         ": \n" +
191                         PropertyUtil.sortProperties(scanProperties, subIndent);
192
193         return
194             header +
195             indent + MessageService.getTextMessage(SQLState.RTS_NUM_OPENS) +
196                 " = " + numOpens + "\n" +
197             indent + MessageService.getTextMessage(SQLState.RTS_ROWS_SEEN) +
198                 " = " + rowsSeen + "\n" +
199             indent + MessageService.getTextMessage(
200                                                 SQLState.RTS_ROWS_FILTERED) +
201                 " = " + rowsFiltered + "\n" +
202             indent + MessageService.getTextMessage(SQLState.RTS_FETCH_SIZE) +
203                 " = " + fetchSize + "\n" +
204             dumpTimeStats(indent, subIndent) + "\n" +
205             ((rowsSeen > 0)
206                 ?
207                     subIndent + MessageService.getTextMessage(
208                                                     SQLState.RTS_NEXT_TIME) +
209                                 " = " + (nextTime / rowsSeen) + "\n"
210                 :
211                     "") + "\n" +
212             scanInfo +
213             subIndent + MessageService.getTextMessage(
214                                                 SQLState.RTS_START_POSITION) +
215                 ": \n" + startPosition +
216             subIndent + MessageService.getTextMessage(
217                                                 SQLState.RTS_STOP_POSITION) +
218                 ": \n" + stopPosition +
219             subIndent + MessageService.getTextMessage(SQLState.RTS_QUALS) +
220                 ":\n" + qualifiers + "\n" +
221             // RESOLVE - estimated row count and cost will eventually
222
// be displayed for all nodes
223
dumpEstimatedCosts(subIndent);
224     }
225
226     /**
227      * Return information on the scan nodes from the statement execution
228      * plan as a String.
229      *
230      * @param depth Indentation level.
231      * @param tableName if not NULL then print information for this table only
232      *
233      * @return String The information on the scan nodes from the
234      * statement execution plan as a String.
235      */

236     public String JavaDoc getScanStatisticsText(String JavaDoc tableName, int depth)
237     {
238         if ((tableName == null) || (tableName.equals(this.tableName)))
239             return getStatementExecutionPlanText(depth);
240         else
241             return "";
242     }
243
244
245     // Class implementation
246

247     public String JavaDoc toString()
248     {
249         return getStatementExecutionPlanText(0);
250     }
251
252     /**
253    * Format for display, a name for this node.
254      *
255      */

256   public String JavaDoc getNodeName(){
257     return MessageService.getTextMessage(
258                 indexName == null ?
259                 SQLState.RTS_TABLE_SCAN :
260                 SQLState.RTS_INDEX_SCAN);
261   }
262
263     /**
264      * If this node is on a database item (like a table or an index), then provide a
265    * string that describes the on item.
266    *
267      */

268   public String JavaDoc getNodeOn(){
269     if (indexName == null)
270       return MessageService.getTextMessage(SQLState.RTS_ON, tableName);
271     else
272       return MessageService.getTextMessage(SQLState.RTS_ON_USING,
273                                                 tableName,
274                                                 indexName);
275   }
276 }
277
Popular Tags