001: /*
002:
003: Derby - Class org.apache.derby.impl.sql.execute.rts.RealProjectRestrictStatistics
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 ProjectRestrictResultSet.
037:
038: @author jerry
039:
040: */
041: public class RealProjectRestrictStatistics extends
042: RealNoPutResultSetStatistics {
043:
044: /* Leave these fields public for object inspectors */
045: public boolean doesProjection;
046: public boolean restriction;
047: public long restrictionTime;
048: public long projectionTime;
049: public ResultSetStatistics childResultSetStatistics;
050: public ResultSetStatistics[] subqueryTrackingArray;
051:
052: // CONSTRUCTORS
053:
054: /**
055: *
056: *
057: */
058: public RealProjectRestrictStatistics(int numOpens, int rowsSeen,
059: int rowsFiltered, long constructorTime, long openTime,
060: long nextTime, long closeTime, int resultSetNumber,
061: long restrictionTime, long projectionTime,
062: ResultSetStatistics[] subqueryTrackingArray,
063: boolean restriction, boolean doesProjection,
064: double optimizerEstimatedRowCount,
065: double optimizerEstimatedCost,
066: ResultSetStatistics childResultSetStatistics) {
067: super (numOpens, rowsSeen, rowsFiltered, constructorTime,
068: openTime, nextTime, closeTime, resultSetNumber,
069: optimizerEstimatedRowCount, optimizerEstimatedCost);
070: this .restriction = restriction;
071: this .doesProjection = doesProjection;
072: this .restrictionTime = restrictionTime;
073: this .projectionTime = projectionTime;
074: this .subqueryTrackingArray = subqueryTrackingArray;
075: this .childResultSetStatistics = childResultSetStatistics;
076: }
077:
078: // ResultSetStatistics methods
079:
080: /**
081: * Return the statement execution plan as a String.
082: *
083: * @param depth Indentation level.
084: *
085: * @return String The statement execution plan as a String.
086: */
087: public String getStatementExecutionPlanText(int depth) {
088: String subqueryInfo = "";
089:
090: initFormatInfo(depth);
091:
092: /* Dump out the statistics for any subqueries */
093:
094: if (subqueryTrackingArray != null) {
095: boolean foundAttached = false;
096:
097: for (int index = 0; index < subqueryTrackingArray.length; index++) {
098: if (subqueryTrackingArray[index] != null) {
099: /* Only print attached subqueries message once */
100: if (!foundAttached) {
101: subqueryInfo = indent
102: + MessageService
103: .getTextMessage(SQLState.RTS_ATTACHED_SQS)
104: + ":\n";
105: foundAttached = true;
106: }
107: subqueryInfo = subqueryInfo
108: + subqueryTrackingArray[index]
109: .getStatementExecutionPlanText(sourceDepth);
110: }
111: }
112: }
113:
114: return subqueryInfo
115: + indent
116: + MessageService.getTextMessage(SQLState.RTS_PR_RS)
117: + " ("
118: + resultSetNumber
119: + "):"
120: + "\n"
121: + indent
122: + MessageService.getTextMessage(SQLState.RTS_NUM_OPENS)
123: + " = "
124: + numOpens
125: + "\n"
126: + indent
127: + MessageService.getTextMessage(SQLState.RTS_ROWS_SEEN)
128: + " = "
129: + rowsSeen
130: + "\n"
131: + indent
132: + MessageService
133: .getTextMessage(SQLState.RTS_ROWS_FILTERED)
134: + " = "
135: + rowsFiltered
136: + "\n"
137: + indent
138: + MessageService
139: .getTextMessage(SQLState.RTS_RESTRICTION)
140: + " = "
141: + restriction
142: + "\n"
143: + indent
144: + MessageService
145: .getTextMessage(SQLState.RTS_PROJECTION)
146: + " = "
147: + doesProjection
148: + "\n"
149: + dumpTimeStats(indent, subIndent)
150: + "\n"
151: + subIndent
152: + MessageService
153: .getTextMessage(SQLState.RTS_RESTRICTION_TIME)
154: + " = "
155: + restrictionTime
156: + "\n"
157: + subIndent
158: + MessageService
159: .getTextMessage(SQLState.RTS_PROJECTION_TIME)
160: + " = "
161: + projectionTime
162: + "\n"
163: + dumpEstimatedCosts(subIndent)
164: + "\n"
165: + indent
166: + MessageService.getTextMessage(SQLState.RTS_SOURCE_RS)
167: + ":"
168: + "\n"
169: + childResultSetStatistics
170: .getStatementExecutionPlanText(sourceDepth);
171: }
172:
173: /**
174: * Return information on the scan nodes from the statement execution
175: * plan as a String.
176: *
177: * @param depth Indentation level.
178: * @param tableName if not NULL then print information for this table only
179: *
180: * @return String The information on the scan nodes from the
181: * statement execution plan as a String.
182: */
183: public String getScanStatisticsText(String tableName, int depth) {
184: String subqueryInfo = "";
185:
186: /* Dump out the statistics for any subqueries */
187:
188: /* RESOLVE - until we externalize RunTimeStats, we just use
189: * this.subqueryTrackingArray since we are currently getting called
190: * on a close() and the StatementContext has changed and doesn't have
191: * a pointer to the top result set. When we externalize RunTimeStats,
192: * the JDBC Driver will have to push a new context and we will have
193: * to assign the top resultset there. (Not sure what to do about
194: * insert/update/delete.)
195: *
196: NoPutResultSet[] subqueryTrackingArray = sc.getSubqueryTrackingArray();
197: */
198:
199: if (subqueryTrackingArray != null) {
200: for (int index = 0; index < subqueryTrackingArray.length; index++) {
201: if (subqueryTrackingArray[index] != null) {
202: subqueryInfo = subqueryInfo
203: + "\n"
204: + MessageService
205: .getTextMessage(SQLState.RTS_BEGIN_SQ_NUMBER)
206: + " "
207: + index
208: + "\n"
209: + subqueryTrackingArray[index]
210: .getScanStatisticsText(tableName,
211: depth)
212: + MessageService
213: .getTextMessage(SQLState.RTS_END_SQ_NUMBER)
214: + " " + index + "\n\n";
215: }
216: }
217: }
218:
219: return subqueryInfo
220: + childResultSetStatistics.getScanStatisticsText(
221: tableName, depth);
222: }
223:
224: // Class implementation
225:
226: public String toString() {
227: return getStatementExecutionPlanText(0);
228: }
229:
230: public java.util.Vector getChildren() {
231: java.util.Vector children = new java.util.Vector();
232: children.addElement(childResultSetStatistics);
233:
234: // get all of our subqueries
235: if (subqueryTrackingArray != null) {
236: for (int index = 0; index < subqueryTrackingArray.length; index++) {
237: if (subqueryTrackingArray[index] != null) {
238: children.addElement(subqueryTrackingArray[index]);
239: }
240: }
241: }
242: return children;
243: }
244:
245: /**
246: * Format for display, a name for this node.
247: *
248: */
249: public String getNodeName() {
250: return MessageService.getTextMessage(SQLState.RTS_PR);
251: }
252: }
|