001: /*
002:
003: Derby - Class org.apache.derby.impl.sql.execute.rts.RealSortStatistics
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: import org.apache.derby.iapi.util.PropertyUtil;
032:
033: import java.io.ObjectOutput;
034: import java.io.ObjectInput;
035: import java.io.IOException;
036:
037: import java.util.Enumeration;
038: import java.util.Properties;
039:
040: /**
041: ResultSetStatistics implemenation for SortResultSet.
042:
043: @author jerry
044:
045: */
046: public class RealSortStatistics extends RealNoPutResultSetStatistics {
047:
048: /* Leave these fields public for object inspectors */
049: public int rowsInput;
050: public int rowsReturned;
051: public boolean eliminateDuplicates;
052: public boolean inSortedOrder;
053: public ResultSetStatistics childResultSetStatistics;
054: public FormatableProperties sortProperties;
055:
056: // CONSTRUCTORS
057:
058: /**
059: *
060: *
061: */
062: public RealSortStatistics(int numOpens, int rowsSeen,
063: int rowsFiltered, long constructorTime, long openTime,
064: long nextTime, long closeTime, int resultSetNumber,
065: int rowsInput, int rowsReturned,
066: boolean eliminateDuplicates, boolean inSortedOrder,
067: Properties sortProperties,
068: double optimizerEstimatedRowCount,
069: double optimizerEstimatedCost,
070: ResultSetStatistics childResultSetStatistics) {
071: super (numOpens, rowsSeen, rowsFiltered, constructorTime,
072: openTime, nextTime, closeTime, resultSetNumber,
073: optimizerEstimatedRowCount, optimizerEstimatedCost);
074: this .rowsInput = rowsInput;
075: this .rowsReturned = rowsReturned;
076: this .eliminateDuplicates = eliminateDuplicates;
077: this .inSortedOrder = inSortedOrder;
078: this .childResultSetStatistics = childResultSetStatistics;
079: this .sortProperties = new FormatableProperties();
080: for (Enumeration e = sortProperties.keys(); e.hasMoreElements();) {
081: String key = (String) e.nextElement();
082: this .sortProperties.put(key, sortProperties.get(key));
083: }
084: }
085:
086: // ResultSetStatistics methods
087:
088: /**
089: * Return the statement execution plan as a String.
090: *
091: * @param depth Indentation level.
092: *
093: * @return String The statement execution plan as a String.
094: */
095: public String getStatementExecutionPlanText(int depth) {
096: initFormatInfo(depth);
097:
098: String sortInfo = (inSortedOrder) ? "" : indent
099: + MessageService.getTextMessage(SQLState.RTS_SORT_INFO)
100: + ": \n"
101: + PropertyUtil
102: .sortProperties(sortProperties, subIndent);
103:
104: return indent
105: + MessageService.getTextMessage(SQLState.RTS_SORT_RS)
106: + ":\n"
107: + indent
108: + MessageService.getTextMessage(SQLState.RTS_NUM_OPENS)
109: + " = "
110: + numOpens
111: + "\n"
112: + indent
113: + MessageService
114: .getTextMessage(SQLState.RTS_ROWS_INPUT)
115: + " = "
116: + rowsInput
117: + "\n"
118: + indent
119: + MessageService
120: .getTextMessage(SQLState.RTS_ROWS_RETURNED)
121: + " = "
122: + rowsReturned
123: + "\n"
124: + indent
125: + MessageService
126: .getTextMessage(SQLState.RTS_ELIMINATE_DUPS)
127: + " = "
128: + eliminateDuplicates
129: + "\n"
130: + indent
131: + MessageService
132: .getTextMessage(SQLState.RTS_IN_SORTED_ORDER)
133: + " = "
134: + inSortedOrder
135: + "\n"
136: + sortInfo
137: + dumpTimeStats(indent, subIndent)
138: + "\n"
139: + dumpEstimatedCosts(subIndent)
140: + "\n"
141: + indent
142: + MessageService.getTextMessage(SQLState.RTS_SOURCE_RS)
143: + ":\n"
144: + childResultSetStatistics
145: .getStatementExecutionPlanText(sourceDepth)
146: + "\n";
147: }
148:
149: /**
150: * Return information on the scan nodes from the statement execution
151: * plan as a String.
152: *
153: * @param depth Indentation level.
154: * @param tableName if not NULL then print information for this table only
155: *
156: * @return String The information on the scan nodes from the
157: * statement execution plan as a String.
158: */
159: public String getScanStatisticsText(String tableName, int depth) {
160: return childResultSetStatistics.getScanStatisticsText(
161: tableName, depth);
162: }
163:
164: // Class implementation
165:
166: public String toString() {
167: return getStatementExecutionPlanText(0);
168: }
169:
170: public java.util.Vector getChildren() {
171: java.util.Vector children = new java.util.Vector();
172: children.addElement(childResultSetStatistics);
173: return children;
174: }
175:
176: /**
177: * Format for display, a name for this node.
178: *
179: */
180: public String getNodeName() {
181: return MessageService.getTextMessage(SQLState.RTS_SORT);
182: }
183: }
|