001: /*
002:
003: Derby - Class org.apache.derby.impl.sql.execute.rts.RealDistinctScanStatistics
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.util.PropertyUtil;
025:
026: import org.apache.derby.iapi.services.i18n.MessageService;
027: import org.apache.derby.iapi.reference.SQLState;
028:
029: import java.util.Enumeration;
030: import java.util.Hashtable;
031: import java.util.Properties;
032:
033: /**
034: ResultSetStatistics implemenation for DistinctScanResultSet.
035:
036: @author jerry
037:
038: */
039: public class RealDistinctScanStatistics extends RealHashScanStatistics {
040:
041: // CONSTRUCTORS
042:
043: /**
044: *
045: *
046: */
047: public RealDistinctScanStatistics(int numOpens, int rowsSeen,
048: int rowsFiltered, long constructorTime, long openTime,
049: long nextTime, long closeTime, int resultSetNumber,
050: String tableName, String indexName, boolean isConstraint,
051: int hashtableSize, int[] hashKeyColumns,
052: String scanQualifiers, String nextQualifiers,
053: Properties scanProperties, String startPosition,
054: String stopPosition, String isolationLevel,
055: String lockString, double optimizerEstimatedRowCount,
056: double optimizerEstimatedCost) {
057: super (numOpens, rowsSeen, rowsFiltered, constructorTime,
058: openTime, nextTime, closeTime, resultSetNumber,
059: tableName, indexName, isConstraint, hashtableSize,
060: hashKeyColumns, scanQualifiers, nextQualifiers,
061: scanProperties, startPosition, stopPosition,
062: isolationLevel, lockString, optimizerEstimatedRowCount,
063: optimizerEstimatedCost);
064: }
065:
066: // ResultSetStatistics methods
067:
068: /**
069: * Return the statement execution plan as a String.
070: *
071: * @param depth Indentation level.
072: *
073: * @return String The statement executio plan as a String.
074: */
075: public String getStatementExecutionPlanText(int depth) {
076: String header;
077: String isolationString = null;
078:
079: initFormatInfo(depth);
080:
081: if (indexName != null) {
082: header = indent
083: + MessageService
084: .getTextMessage(
085: SQLState.RTS_DISTINCT_SCAN_RS_USING,
086: tableName,
087: isConstraint ? MessageService
088: .getTextMessage(SQLState.RTS_CONSTRAINT)
089: : MessageService
090: .getTextMessage(SQLState.RTS_INDEX),
091: indexName);
092: } else {
093: header = indent
094: + MessageService.getTextMessage(
095: SQLState.RTS_DISTINCT_SCAN_RS, tableName);
096: }
097:
098: header = header
099: + " "
100: + MessageService.getTextMessage(SQLState.RTS_LOCKING,
101: isolationLevel, lockString) + ": \n";
102:
103: String scanInfo = indent
104: + MessageService.getTextMessage(SQLState.RTS_SCAN_INFO)
105: + ": \n"
106: + PropertyUtil
107: .sortProperties(scanProperties, subIndent);
108:
109: String hashKeyColumnString;
110: if (hashKeyColumns.length == 1) {
111: hashKeyColumnString = MessageService
112: .getTextMessage(SQLState.RTS_DISTINCT_COL)
113: + " " + hashKeyColumns[0];
114: } else {
115: hashKeyColumnString = MessageService
116: .getTextMessage(SQLState.RTS_DISTINCT_COLS)
117: + " (" + hashKeyColumns[0];
118: for (int index = 1; index < hashKeyColumns.length; index++) {
119: hashKeyColumnString = hashKeyColumnString + ","
120: + hashKeyColumns[index];
121: }
122: hashKeyColumnString = hashKeyColumnString + ")";
123: }
124:
125: return header
126: + indent
127: + MessageService.getTextMessage(SQLState.RTS_NUM_OPENS)
128: + " = "
129: + numOpens
130: + "\n"
131: + indent
132: + MessageService
133: .getTextMessage(SQLState.RTS_HASH_TABLE_SIZE)
134: + " = "
135: + hashtableSize
136: + "\n"
137: + indent
138: + hashKeyColumnString
139: + "\n"
140: + indent
141: + MessageService.getTextMessage(SQLState.RTS_ROWS_SEEN)
142: + " = "
143: + rowsSeen
144: + "\n"
145: + indent
146: + MessageService
147: .getTextMessage(SQLState.RTS_ROWS_FILTERED)
148: + " = "
149: + rowsFiltered
150: + "\n"
151: + dumpTimeStats(indent, subIndent)
152: + "\n"
153: + dumpEstimatedCosts(subIndent)
154: + "\n"
155: + ((rowsSeen > 0) ? subIndent
156: + MessageService
157: .getTextMessage(SQLState.RTS_NEXT_TIME)
158: + " = " + (nextTime / rowsSeen) + "\n" : "")
159: + "\n"
160: + scanInfo
161: + subIndent
162: + MessageService
163: .getTextMessage(SQLState.RTS_START_POSITION)
164: + ":\n"
165: + startPosition
166: + subIndent
167: + MessageService
168: .getTextMessage(SQLState.RTS_STOP_POSITION)
169: + ":\n"
170: + stopPosition
171: + subIndent
172: + MessageService
173: .getTextMessage(SQLState.RTS_SCAN_QUALS)
174: + ":\n"
175: + scanQualifiers
176: + "\n"
177: + subIndent
178: + MessageService
179: .getTextMessage(SQLState.RTS_NEXT_QUALS)
180: + ":\n" + nextQualifiers + "\n" +
181: // RESOLVE - estimated row count and cost will eventually
182: // be displayed for all nodes
183: dumpEstimatedCosts(subIndent);
184: }
185:
186: /**
187: * Return information on the scan nodes from the statement execution
188: * plan as a String.
189: *
190: * @param depth Indentation level.
191: * @param tableName if not NULL then print information for this table only
192: *
193: * @return String The information on the scan nodes from the
194: * statement execution plan as a String.
195: */
196: public String getScanStatisticsText(String tableName, int depth) {
197: if ((tableName == null) || tableName.equals(this .tableName))
198: return getStatementExecutionPlanText(depth);
199: else
200: return (String) "";
201: }
202:
203: // Formatable methods
204:
205: // Class implementation
206:
207: public String toString() {
208: return getStatementExecutionPlanText(0);
209: }
210:
211: /**
212: * If this node is on a database item (like a table or an index), then provide a
213: * string that describes the on item.
214: *
215: */
216: public String getNodeOn() {
217: return MessageService.getTextMessage(SQLState.RTS_ON_USING,
218: tableName, indexName);
219: }
220:
221: /**
222: * Format for display, a name for this node.
223: *
224: */
225: public String getNodeName() {
226: return MessageService
227: .getTextMessage(SQLState.RTS_DISTINCT_SCAN);
228: }
229: }
|