KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.execute.rts.RealDistinctScanStatistics
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.util.PropertyUtil;
25
26 import org.apache.derby.iapi.services.i18n.MessageService;
27 import org.apache.derby.iapi.reference.SQLState;
28
29 import java.util.Enumeration JavaDoc;
30 import java.util.Hashtable JavaDoc;
31 import java.util.Properties JavaDoc;
32
33
34 /**
35   ResultSetStatistics implemenation for DistinctScanResultSet.
36
37   @author jerry
38
39 */

40 public class RealDistinctScanStatistics
41     extends RealHashScanStatistics
42 {
43
44     // CONSTRUCTORS
45

46     /**
47      *
48      *
49      */

50     public RealDistinctScanStatistics(
51                                     int numOpens,
52                                     int rowsSeen,
53                                     int rowsFiltered,
54                                     long constructorTime,
55                                     long openTime,
56                                     long nextTime,
57                                     long closeTime,
58                                     int resultSetNumber,
59                                     String JavaDoc tableName,
60                                     String JavaDoc indexName,
61                                     boolean isConstraint,
62                                     int hashtableSize,
63                                     int[] hashKeyColumns,
64                                     String JavaDoc scanQualifiers,
65                                     String JavaDoc nextQualifiers,
66                                     Properties JavaDoc scanProperties,
67                                     String JavaDoc startPosition,
68                                     String JavaDoc stopPosition,
69                                     String JavaDoc isolationLevel,
70                                     String JavaDoc lockString,
71                                     double optimizerEstimatedRowCount,
72                                     double optimizerEstimatedCost
73                                     )
74     {
75         super(
76             numOpens,
77             rowsSeen,
78             rowsFiltered,
79             constructorTime,
80             openTime,
81             nextTime,
82             closeTime,
83             resultSetNumber,
84             tableName,
85             indexName,
86             isConstraint,
87             hashtableSize,
88             hashKeyColumns,
89             scanQualifiers,
90             nextQualifiers,
91             scanProperties,
92             startPosition,
93             stopPosition,
94             isolationLevel,
95             lockString,
96             optimizerEstimatedRowCount,
97             optimizerEstimatedCost
98             );
99     }
100
101     // ResultSetStatistics methods
102

103     /**
104      * Return the statement execution plan as a String.
105      *
106      * @param depth Indentation level.
107      *
108      * @return String The statement executio plan as a String.
109      */

110     public String JavaDoc getStatementExecutionPlanText(int depth)
111     {
112         String JavaDoc header;
113         String JavaDoc isolationString = null;
114
115         initFormatInfo(depth);
116
117         if (indexName != null)
118         {
119             header =
120               indent + MessageService.getTextMessage(
121                 SQLState.RTS_DISTINCT_SCAN_RS_USING,
122                 tableName,
123                 isConstraint ?
124                     MessageService.getTextMessage(SQLState.RTS_CONSTRAINT) :
125                     MessageService.getTextMessage(SQLState.RTS_INDEX),
126                 indexName);
127         }
128         else
129         {
130             header =
131                 indent +
132                 MessageService.getTextMessage(
133                                     SQLState.RTS_DISTINCT_SCAN_RS,
134                                     tableName);
135         }
136
137         header = header + " " +
138                     MessageService.getTextMessage(
139                                     SQLState.RTS_LOCKING,
140                                     isolationLevel,
141                                     lockString) +
142                   ": \n";
143
144         String JavaDoc scanInfo =
145             indent +
146             MessageService.getTextMessage(SQLState.RTS_SCAN_INFO) +
147                 ": \n" +
148             PropertyUtil.sortProperties(scanProperties, subIndent);
149         
150         String JavaDoc hashKeyColumnString;
151         if (hashKeyColumns.length == 1)
152         {
153             hashKeyColumnString = MessageService.getTextMessage(
154                                                     SQLState.RTS_DISTINCT_COL) +
155                                     " " + hashKeyColumns[0];
156         }
157         else
158         {
159             hashKeyColumnString = MessageService.getTextMessage(
160                                                 SQLState.RTS_DISTINCT_COLS) +
161                                     " (" + hashKeyColumns[0];
162             for (int index = 1; index < hashKeyColumns.length; index++)
163             {
164                 hashKeyColumnString = hashKeyColumnString + "," + hashKeyColumns[index];
165             }
166             hashKeyColumnString = hashKeyColumnString + ")";
167         }
168
169         return
170             header +
171             indent + MessageService.getTextMessage(SQLState.RTS_NUM_OPENS) +
172                     " = " + numOpens + "\n" +
173             indent + MessageService.getTextMessage(
174                                                 SQLState.RTS_HASH_TABLE_SIZE) +
175                     " = " + hashtableSize + "\n" +
176             indent + hashKeyColumnString + "\n" +
177             indent + MessageService.getTextMessage(SQLState.RTS_ROWS_SEEN) +
178                     " = " + rowsSeen + "\n" +
179             indent + MessageService.getTextMessage(
180                                                 SQLState.RTS_ROWS_FILTERED) +
181                     " = " + rowsFiltered + "\n" +
182             dumpTimeStats(indent, subIndent) + "\n" +
183             dumpEstimatedCosts(subIndent) + "\n" +
184             ((rowsSeen > 0)
185                 ?
186                     subIndent +
187                         MessageService.getTextMessage(
188                                                     SQLState.RTS_NEXT_TIME) +
189                         " = " + (nextTime / rowsSeen) + "\n"
190                 :
191                     "") + "\n" +
192             scanInfo +
193             subIndent + MessageService.getTextMessage(
194                                                 SQLState.RTS_START_POSITION) +
195                         ":\n" + startPosition +
196             subIndent + MessageService.getTextMessage(
197                                                 SQLState.RTS_STOP_POSITION) +
198                         ":\n" + stopPosition +
199             subIndent + MessageService.getTextMessage(
200                                                 SQLState.RTS_SCAN_QUALS) +
201                         ":\n" + scanQualifiers + "\n" +
202             subIndent +
203                         MessageService.getTextMessage(
204                                                 SQLState.RTS_NEXT_QUALS) +
205                         ":\n" + nextQualifiers + "\n" +
206             // RESOLVE - estimated row count and cost will eventually
207
// be displayed for all nodes
208
dumpEstimatedCosts(subIndent);
209     }
210
211     /**
212      * Return information on the scan nodes from the statement execution
213      * plan as a String.
214      *
215      * @param depth Indentation level.
216      * @param tableName if not NULL then print information for this table only
217      *
218      * @return String The information on the scan nodes from the
219      * statement execution plan as a String.
220      */

221     public String JavaDoc getScanStatisticsText(String JavaDoc tableName, int depth)
222     {
223         if ((tableName == null) || tableName.equals(this.tableName))
224             return getStatementExecutionPlanText(depth);
225         else
226             return (String JavaDoc)"";
227     }
228
229     // Formatable methods
230

231  
232     // Class implementation
233

234     public String JavaDoc toString()
235     {
236         return getStatementExecutionPlanText(0);
237     }
238     /**
239      * If this node is on a database item (like a table or an index), then provide a
240    * string that describes the on item.
241    *
242      */

243     public String JavaDoc getNodeOn()
244     {
245         return MessageService.getTextMessage(
246                                         SQLState.RTS_ON_USING,
247                                         tableName,
248                                         indexName);
249     }
250     /**
251      * Format for display, a name for this node.
252      *
253      */

254     public String JavaDoc getNodeName()
255     {
256         return MessageService.getTextMessage(SQLState.RTS_DISTINCT_SCAN);
257     }
258 }
259
Popular Tags