001: /*
002:
003: Derby - Class org.apache.derby.impl.sql.execute.rts.RealSetOpResultSetStatistics
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.i18n.MessageService;
025: import org.apache.derby.iapi.reference.SQLState;
026:
027: import org.apache.derby.impl.sql.compile.IntersectOrExceptNode;
028:
029: /**
030: ResultSetStatistics implementation for SetOpResultSet.
031:
032: @author yip
033:
034: */
035: public class RealSetOpResultSetStatistics extends
036: RealNoPutResultSetStatistics {
037:
038: /* Leave these fields public for object inspectors */
039: public int opType;
040: public int rowsSeenLeft;
041: public int rowsSeenRight;
042: public int rowsReturned;
043: public ResultSetStatistics leftResultSetStatistics;
044: public ResultSetStatistics rightResultSetStatistics;
045:
046: // CONSTRUCTORS
047:
048: /**
049: * Constructs a new <code>RealSetOpResultSetStatistics</code> object
050: * to represent the runtime statistics for <code>SetOpResultSet</code>.
051: *
052: * @param opType set operation type
053: * @param numOpens number of open
054: * @param rowsSeen rows seen
055: * @param rowsFiltered rows filtered
056: * @param constructorTime the time for construction
057: * @param openTime the time for open operation
058: * @param nextTime the time for next operation
059: * @param closeTime the time for close operation
060: * @param resultSetNumber the result set number
061: * @param rowsSeenLeft rows seen by left source input
062: * @param rowsSeenRight rows seen by right source input
063: * @param rowsReturned rows returned
064: * @param optimizerEstimatedRowCount optimizer estimated row count
065: * @param optimizerEstimatedCost optimizer estimated cost
066: * @param leftResultSetStatistics left source runtime statistics
067: * @param rightResultSetStatistics right source runtime statistics
068: *
069: * @see org.apache.derby.impl.sql.execute.SetOpResultSet
070: */
071: public RealSetOpResultSetStatistics(int opType, int numOpens,
072: int rowsSeen, int rowsFiltered, long constructorTime,
073: long openTime, long nextTime, long closeTime,
074: int resultSetNumber, int rowsSeenLeft, int rowsSeenRight,
075: int rowsReturned, double optimizerEstimatedRowCount,
076: double optimizerEstimatedCost,
077: ResultSetStatistics leftResultSetStatistics,
078: ResultSetStatistics rightResultSetStatistics) {
079: super (numOpens, rowsSeen, rowsFiltered, constructorTime,
080: openTime, nextTime, closeTime, resultSetNumber,
081: optimizerEstimatedRowCount, optimizerEstimatedCost);
082:
083: this .opType = opType;
084: this .rowsSeenLeft = rowsSeenLeft;
085: this .rowsSeenRight = rowsSeenRight;
086: this .rowsReturned = rowsReturned;
087: this .leftResultSetStatistics = leftResultSetStatistics;
088: this .rightResultSetStatistics = rightResultSetStatistics;
089: }
090:
091: // ResultSetStatistics methods
092:
093: /**
094: * Return the statement execution plan as a <code>String</code>.
095: *
096: * @param depth Indentation level.
097: *
098: * @return the statement execution plan as a <code>String</code>.
099: */
100: public String getStatementExecutionPlanText(int depth) {
101: initFormatInfo(depth);
102:
103: String rs = (opType == IntersectOrExceptNode.INTERSECT_OP) ? (SQLState.RTS_INTERSECT_RS)
104: : (SQLState.RTS_EXCEPT_RS);
105:
106: return indent
107: + MessageService.getTextMessage(rs)
108: + ":\n"
109: + indent
110: + MessageService.getTextMessage(SQLState.RTS_NUM_OPENS)
111: + " = "
112: + numOpens
113: + "\n"
114: + indent
115: + MessageService
116: .getTextMessage(SQLState.RTS_ROWS_SEEN_LEFT)
117: + " = "
118: + rowsSeenLeft
119: + "\n"
120: + indent
121: + MessageService
122: .getTextMessage(SQLState.RTS_ROWS_SEEN_RIGHT)
123: + " = "
124: + rowsSeenRight
125: + "\n"
126: + indent
127: + MessageService
128: .getTextMessage(SQLState.RTS_ROWS_RETURNED)
129: + " = "
130: + rowsReturned
131: + "\n"
132: + dumpTimeStats(indent, subIndent)
133: + "\n"
134: + dumpEstimatedCosts(subIndent)
135: + "\n"
136: + indent
137: + MessageService.getTextMessage(SQLState.RTS_LEFT_RS)
138: + ":\n"
139: + leftResultSetStatistics
140: .getStatementExecutionPlanText(sourceDepth)
141: + "\n"
142: + indent
143: + MessageService.getTextMessage(SQLState.RTS_RIGHT_RS)
144: + ":\n"
145: + rightResultSetStatistics
146: .getStatementExecutionPlanText(sourceDepth)
147: + "\n";
148: }
149:
150: /**
151: * Return information on the scan nodes from the statement execution
152: * plan as a <code>String</code>.
153: *
154: * @param depth Indentation level.
155: * @param tableName if not NULL then print information for this table only
156: *
157: * @return String The information on the scan nodes from the
158: * statement execution plan as a <code>String</code>.
159: */
160: public String getScanStatisticsText(String tableName, int depth) {
161: return leftResultSetStatistics.getScanStatisticsText(tableName,
162: depth)
163: + rightResultSetStatistics.getScanStatisticsText(
164: tableName, depth);
165: }
166:
167: // Class implementation
168:
169: /**
170: * Return the runtime statistics of this object in textual representation
171: *
172: * @return the runtime statistics of this object in textual representation
173: * as a <code>String</code>.
174: */
175: public String toString() {
176: return getStatementExecutionPlanText(0);
177: }
178:
179: /**
180: * Retrieves the children runtime statistics of this <code>
181: * RealSetOpResultSetStatistics</code> object
182: *
183: * @return the children runtime statistics of this <code>
184: * RealSetOpResultSetStatistics</code> object stored in a <code>
185: * Vector</code>.
186: *
187: */
188: public java.util.Vector getChildren() {
189: java.util.Vector children = new java.util.Vector();
190: children.addElement(leftResultSetStatistics);
191: children.addElement(rightResultSetStatistics);
192: return children;
193: }
194:
195: /**
196: * Format for display, a name for this node.
197: *
198: * @return the name of the node as a <code>String</code>.
199: */
200: public String getNodeName() {
201: String nodeName = (opType == IntersectOrExceptNode.INTERSECT_OP) ? (SQLState.RTS_INTERSECT)
202: : (SQLState.RTS_EXCEPT);
203:
204: return MessageService.getTextMessage(nodeName);
205: }
206: }
|