001: /*
002:
003: Derby - Class org.apache.derby.impl.sql.execute.rts.RealNestedLoopJoinStatistics
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:
031: import java.io.ObjectOutput;
032: import java.io.ObjectInput;
033: import java.io.IOException;
034:
035: /**
036: ResultSetStatistics implemenation for NestedLoopJoinResultSet.
037:
038: @author jerry
039:
040: */
041: public class RealNestedLoopJoinStatistics extends
042: RealJoinResultSetStatistics {
043:
044: /* Leave these fields public for object inspectors */
045: public boolean oneRowRightSide;
046: public ResultSetStatistics leftResultSetStatistics;
047: public ResultSetStatistics rightResultSetStatistics;
048:
049: /* KLUDGE - Prior to 2.5, all joins were nested loop in the join node.
050: * "Make" this a HashJoin if the right child is a HashScan.
051: */
052: protected String nodeName;
053: protected String resultSetName;
054:
055: // CONSTRUCTORS
056:
057: /**
058: *
059: *
060: */
061: public RealNestedLoopJoinStatistics(int numOpens, int rowsSeen,
062: int rowsFiltered, long constructorTime, long openTime,
063: long nextTime, long closeTime, int resultSetNumber,
064: int rowsSeenLeft, int rowsSeenRight, int rowsReturned,
065: long restrictionTime, boolean oneRowRightSide,
066: double optimizerEstimatedRowCount,
067: double optimizerEstimatedCost,
068: String userSuppliedOptimizerOverrides,
069: ResultSetStatistics leftResultSetStatistics,
070: ResultSetStatistics rightResultSetStatistics) {
071: super (numOpens, rowsSeen, rowsFiltered, constructorTime,
072: openTime, nextTime, closeTime, resultSetNumber,
073: rowsSeenLeft, rowsSeenRight, rowsReturned,
074: restrictionTime, optimizerEstimatedRowCount,
075: optimizerEstimatedCost, userSuppliedOptimizerOverrides);
076: this .oneRowRightSide = oneRowRightSide;
077: this .leftResultSetStatistics = leftResultSetStatistics;
078: this .rightResultSetStatistics = rightResultSetStatistics;
079:
080: setNames();
081: }
082:
083: // ResultSetStatistics methods
084:
085: /**
086: * Return the statement execution plan as a String.
087: *
088: * @param depth Indentation level.
089: *
090: * @return String The statement execution plan as a String.
091: */
092: public String getStatementExecutionPlanText(int depth) {
093: initFormatInfo(depth);
094:
095: String header = "";
096: if (userSuppliedOptimizerOverrides != null) {
097: header = indent
098: + MessageService
099: .getTextMessage(
100: SQLState.RTS_USER_SUPPLIED_OPTIMIZER_OVERRIDES_FOR_JOIN,
101: userSuppliedOptimizerOverrides);
102: header = header + "\n";
103: }
104:
105: return header
106: + indent
107: + resultSetName
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_FILTERED)
129: + " = "
130: + rowsFiltered
131: + "\n"
132: + indent
133: + MessageService
134: .getTextMessage(SQLState.RTS_ROWS_RETURNED)
135: + " = "
136: + rowsReturned
137: + "\n"
138: + dumpTimeStats(indent, subIndent)
139: + "\n"
140: + dumpEstimatedCosts(subIndent)
141: + "\n"
142: + indent
143: + MessageService.getTextMessage(SQLState.RTS_LEFT_RS)
144: + ":\n"
145: + leftResultSetStatistics
146: .getStatementExecutionPlanText(sourceDepth)
147: + "\n"
148: + indent
149: + MessageService.getTextMessage(SQLState.RTS_RIGHT_RS)
150: + ":\n"
151: + rightResultSetStatistics
152: .getStatementExecutionPlanText(sourceDepth)
153: + "\n";
154: }
155:
156: /**
157: * Return information on the scan nodes from the statement execution
158: * plan as a String.
159: *
160: * @param depth Indentation level.
161: * @param tableName if not NULL then print information for this table only
162: *
163: * @return String The information on the scan nodes from the
164: * statement execution plan as a String.
165: */
166: public String getScanStatisticsText(String tableName, int depth) {
167: return leftResultSetStatistics.getScanStatisticsText(tableName,
168: depth)
169: + rightResultSetStatistics.getScanStatisticsText(
170: tableName, depth);
171: }
172:
173: // Class implementation
174:
175: public String toString() {
176: return getStatementExecutionPlanText(0);
177: }
178:
179: public java.util.Vector getChildren() {
180: java.util.Vector children = new java.util.Vector();
181: children.addElement(leftResultSetStatistics);
182: children.addElement(rightResultSetStatistics);
183: return children;
184: }
185:
186: /**
187: * Format for display, a name for this node.
188: *
189: */
190: public String getNodeName() {
191: return nodeName;
192: }
193:
194: protected void setNames() {
195: if (nodeName == null) {
196: if (oneRowRightSide) {
197: nodeName = MessageService
198: .getTextMessage(SQLState.RTS_NESTED_LOOP_EXISTS_JOIN);
199: resultSetName = MessageService
200: .getTextMessage(SQLState.RTS_NESTED_LOOP_EXISTS_JOIN_RS);
201: } else {
202: nodeName = MessageService
203: .getTextMessage(SQLState.RTS_NESTED_LOOP_JOIN);
204: resultSetName = MessageService
205: .getTextMessage(SQLState.RTS_NESTED_LOOP_JOIN_RS);
206: }
207: }
208: }
209: }
|