001: /*
002:
003: Derby - Class org.apache.derby.impl.sql.execute.rts.RealHashTableStatistics
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.impl.sql.execute.rts;
023:
024: import org.apache.derby.iapi.services.io.StoredFormatIds;
025:
026: import org.apache.derby.iapi.services.i18n.MessageService;
027: import org.apache.derby.iapi.reference.SQLState;
028:
029: import org.apache.derby.iapi.services.io.FormatableHashtable;
030: import org.apache.derby.iapi.services.io.FormatableProperties;
031:
032: import java.io.ObjectOutput;
033: import java.io.ObjectInput;
034: import java.io.IOException;
035:
036: import java.util.Enumeration;
037: import java.util.Properties;
038:
039: /**
040: ResultSetStatistics implemenation for HashTableResultSet.
041:
042: @author jerry
043:
044: */
045: public class RealHashTableStatistics extends
046: RealNoPutResultSetStatistics {
047:
048: /* Leave these fields public for object inspectors */
049: public int hashtableSize;
050: public int[] hashKeyColumns;
051: public String isolationLevel;
052: public String nextQualifiers;
053: public FormatableProperties scanProperties;
054: public ResultSetStatistics childResultSetStatistics;
055: public ResultSetStatistics[] subqueryTrackingArray;
056:
057: // CONSTRUCTORS
058:
059: /**
060: *
061: *
062: */
063: public RealHashTableStatistics(int numOpens, int rowsSeen,
064: int rowsFiltered, long constructorTime, long openTime,
065: long nextTime, long closeTime, int resultSetNumber,
066: int hashtableSize, int[] hashKeyColumns,
067: String nextQualifiers, Properties scanProperties,
068: double optimizerEstimatedRowCount,
069: double optimizerEstimatedCost,
070: ResultSetStatistics[] subqueryTrackingArray,
071: ResultSetStatistics childResultSetStatistics) {
072: super (numOpens, rowsSeen, rowsFiltered, constructorTime,
073: openTime, nextTime, closeTime, resultSetNumber,
074: optimizerEstimatedRowCount, optimizerEstimatedCost);
075: this .hashtableSize = hashtableSize;
076: this .hashKeyColumns = hashKeyColumns;
077: this .nextQualifiers = nextQualifiers;
078: this .scanProperties = new FormatableProperties();
079: if (scanProperties != null) {
080: for (Enumeration e = scanProperties.keys(); e
081: .hasMoreElements();) {
082: String key = (String) e.nextElement();
083: this .scanProperties.put(key, scanProperties.get(key));
084: }
085: }
086: this .subqueryTrackingArray = subqueryTrackingArray;
087: this .childResultSetStatistics = childResultSetStatistics;
088: }
089:
090: // ResultSetStatistics methods
091:
092: /**
093: * Return the statement execution plan as a String.
094: *
095: * @param depth Indentation level.
096: *
097: * @return String The statement executio plan as a String.
098: */
099: public String getStatementExecutionPlanText(int depth) {
100: String subqueryInfo = "";
101:
102: initFormatInfo(depth);
103:
104: /* Dump out the statistics for any subqueries */
105:
106: if (subqueryTrackingArray != null) {
107: boolean foundAttached = false;
108:
109: for (int index = 0; index < subqueryTrackingArray.length; index++) {
110: if (subqueryTrackingArray[index] != null) {
111: /* Only print attached subqueries message once */
112: if (!foundAttached) {
113: subqueryInfo = indent
114: + MessageService
115: .getTextMessage(SQLState.RTS_ATTACHED_SQS)
116: + ":\n";
117: foundAttached = true;
118: }
119: subqueryInfo = subqueryInfo
120: + subqueryTrackingArray[index]
121: .getStatementExecutionPlanText(sourceDepth);
122: }
123: }
124: }
125:
126: initFormatInfo(depth);
127:
128: String hashKeyColumnString;
129: if (hashKeyColumns.length == 1) {
130: hashKeyColumnString = MessageService
131: .getTextMessage(SQLState.RTS_HASH_KEY)
132: + " " + hashKeyColumns[0];
133: } else {
134: hashKeyColumnString = MessageService
135: .getTextMessage(SQLState.RTS_HASH_KEYS)
136: + " (" + hashKeyColumns[0];
137: for (int index = 1; index < hashKeyColumns.length; index++) {
138: hashKeyColumnString = hashKeyColumnString + ","
139: + hashKeyColumns[index];
140: }
141: hashKeyColumnString = hashKeyColumnString + ")";
142: }
143:
144: return indent
145: + MessageService
146: .getTextMessage(SQLState.RTS_HASH_TABLE_RS)
147: + " ("
148: + resultSetNumber
149: + "):"
150: + "\n"
151: + indent
152: + MessageService.getTextMessage(SQLState.RTS_NUM_OPENS)
153: + " = "
154: + numOpens
155: + "\n"
156: + indent
157: + MessageService
158: .getTextMessage(SQLState.RTS_HASH_TABLE_SIZE)
159: + " = "
160: + hashtableSize
161: + "\n"
162: + indent
163: + hashKeyColumnString
164: + "\n"
165: + indent
166: + MessageService.getTextMessage(SQLState.RTS_ROWS_SEEN)
167: + " = "
168: + rowsSeen
169: + "\n"
170: + indent
171: + MessageService
172: .getTextMessage(SQLState.RTS_ROWS_FILTERED)
173: + " = "
174: + rowsFiltered
175: + "\n"
176: + dumpTimeStats(indent, subIndent)
177: + "\n"
178: + dumpEstimatedCosts(subIndent)
179: + "\n"
180: + ((rowsSeen > 0) ? subIndent
181: + MessageService
182: .getTextMessage(SQLState.RTS_NEXT_TIME)
183: + " = " + (nextTime / rowsSeen) + "\n" : "")
184: + "\n"
185: + subIndent
186: + MessageService
187: .getTextMessage(SQLState.RTS_NEXT_QUALS)
188: + ":\n"
189: + nextQualifiers
190: + "\n"
191: + indent
192: + MessageService.getTextMessage(SQLState.RTS_SOURCE_RS)
193: + ":\n"
194: + childResultSetStatistics
195: .getStatementExecutionPlanText(sourceDepth);
196: }
197:
198: /**
199: * Return information on the scan nodes from the statement execution
200: * plan as a String.
201: *
202: * @param depth Indentation level.
203: * @param tableName if not NULL then print information for this table only
204: *
205: * @return String The information on the scan nodes from the
206: * statement execution plan as a String.
207: */
208: public String getScanStatisticsText(String tableName, int depth) {
209: if (tableName == null)
210: return getStatementExecutionPlanText(depth);
211: else
212: return (String) null;
213: }
214:
215: // Class implementation
216:
217: public String toString() {
218: return getStatementExecutionPlanText(0);
219: }
220:
221: /**
222: * If this node is on a database item (like a table or an index), then provide a
223: * string that describes the on item.
224: *
225: */
226: public String getNodeOn() {
227: return "";
228: }
229:
230: /**
231: * Format for display, a name for this node.
232: *
233: */
234: public String getNodeName() {
235: return MessageService.getTextMessage(SQLState.RTS_HASH_TABLE);
236: }
237: }
|