KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > execute > rts > RealNestedLoopJoinStatistics


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.execute.rts.RealNestedLoopJoinStatistics
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.sql.execute.rts;
23
24 import org.apache.derby.iapi.services.io.StoredFormatIds;
25
26 import org.apache.derby.iapi.services.i18n.MessageService;
27 import org.apache.derby.iapi.reference.SQLState;
28
29 import org.apache.derby.iapi.services.io.FormatableHashtable;
30
31 import java.io.ObjectOutput JavaDoc;
32 import java.io.ObjectInput JavaDoc;
33 import java.io.IOException JavaDoc;
34
35 /**
36   ResultSetStatistics implemenation for NestedLoopJoinResultSet.
37
38   @author jerry
39
40 */

41 public class RealNestedLoopJoinStatistics
42     extends RealJoinResultSetStatistics
43 {
44
45     /* Leave these fields public for object inspectors */
46     public boolean oneRowRightSide;
47     public ResultSetStatistics leftResultSetStatistics;
48     public ResultSetStatistics rightResultSetStatistics;
49
50     /* KLUDGE - Prior to 2.5, all joins were nested loop in the join node.
51      * "Make" this a HashJoin if the right child is a HashScan.
52      */

53     protected String JavaDoc nodeName ;
54     protected String JavaDoc resultSetName;
55
56     // CONSTRUCTORS
57

58     /**
59      *
60      *
61      */

62     public RealNestedLoopJoinStatistics(
63                                 int numOpens,
64                                 int rowsSeen,
65                                 int rowsFiltered,
66                                 long constructorTime,
67                                 long openTime,
68                                 long nextTime,
69                                 long closeTime,
70                                 int resultSetNumber,
71                                 int rowsSeenLeft,
72                                 int rowsSeenRight,
73                                 int rowsReturned,
74                                 long restrictionTime,
75                                 boolean oneRowRightSide,
76                                 double optimizerEstimatedRowCount,
77                                 double optimizerEstimatedCost,
78                                 String JavaDoc userSuppliedOptimizerOverrides,
79                                 ResultSetStatistics leftResultSetStatistics,
80                                 ResultSetStatistics rightResultSetStatistics
81                                 )
82     {
83         super(
84             numOpens,
85             rowsSeen,
86             rowsFiltered,
87             constructorTime,
88             openTime,
89             nextTime,
90             closeTime,
91             resultSetNumber,
92             rowsSeenLeft,
93             rowsSeenRight,
94             rowsReturned,
95             restrictionTime,
96             optimizerEstimatedRowCount,
97             optimizerEstimatedCost,
98             userSuppliedOptimizerOverrides
99             );
100         this.oneRowRightSide = oneRowRightSide;
101         this.leftResultSetStatistics = leftResultSetStatistics;
102         this.rightResultSetStatistics = rightResultSetStatistics;
103
104         setNames();
105     }
106
107     // ResultSetStatistics methods
108

109     /**
110      * Return the statement execution plan as a String.
111      *
112      * @param depth Indentation level.
113      *
114      * @return String The statement execution plan as a String.
115      */

116     public String JavaDoc getStatementExecutionPlanText(int depth)
117     {
118         initFormatInfo(depth);
119
120         String JavaDoc header = "";
121         if (userSuppliedOptimizerOverrides != null)
122         {
123             header =
124                 indent + MessageService.getTextMessage(SQLState.RTS_USER_SUPPLIED_OPTIMIZER_OVERRIDES_FOR_JOIN,
125                         userSuppliedOptimizerOverrides);
126             header = header + "\n";
127         }
128         
129         return
130         header +
131             indent + resultSetName + ":\n" +
132             indent + MessageService.getTextMessage(SQLState.RTS_NUM_OPENS) +
133                 " = " + numOpens + "\n" +
134             indent + MessageService.getTextMessage(
135                                                 SQLState.RTS_ROWS_SEEN_LEFT) +
136                 " = " + rowsSeenLeft + "\n" +
137             indent + MessageService.getTextMessage(
138                                                 SQLState.RTS_ROWS_SEEN_RIGHT) +
139                 " = " + rowsSeenRight + "\n" +
140             indent + MessageService.getTextMessage(
141                                                 SQLState.RTS_ROWS_FILTERED) +
142                 " = " + rowsFiltered + "\n" +
143             indent + MessageService.getTextMessage(
144                                                 SQLState.RTS_ROWS_RETURNED) +
145                 " = " + rowsReturned + "\n" +
146             dumpTimeStats(indent, subIndent) + "\n" +
147             dumpEstimatedCosts(subIndent) + "\n" +
148             indent + MessageService.getTextMessage(
149                                                 SQLState.RTS_LEFT_RS) +
150                 ":\n" +
151             leftResultSetStatistics.getStatementExecutionPlanText(sourceDepth) +
152                 "\n" +
153             indent + MessageService.getTextMessage(SQLState.RTS_RIGHT_RS) +
154                 ":\n" +
155             rightResultSetStatistics.getStatementExecutionPlanText(sourceDepth) + "\n";
156     }
157
158
159     /**
160      * Return information on the scan nodes from the statement execution
161      * plan as a String.
162      *
163      * @param depth Indentation level.
164      * @param tableName if not NULL then print information for this table only
165      *
166      * @return String The information on the scan nodes from the
167      * statement execution plan as a String.
168      */

169     public String JavaDoc getScanStatisticsText(String JavaDoc tableName, int depth)
170     {
171         return leftResultSetStatistics.getScanStatisticsText(tableName, depth)
172             + rightResultSetStatistics.getScanStatisticsText(tableName, depth);
173     }
174
175
176
177     // Class implementation
178

179     public String JavaDoc toString()
180     {
181         return getStatementExecutionPlanText(0);
182     }
183
184     public java.util.Vector JavaDoc getChildren()
185     {
186         java.util.Vector JavaDoc children = new java.util.Vector JavaDoc();
187         children.addElement(leftResultSetStatistics);
188         children.addElement(rightResultSetStatistics);
189         return children;
190     }
191
192     /**
193      * Format for display, a name for this node.
194      *
195      */

196     public String JavaDoc getNodeName()
197     {
198         return nodeName;
199     }
200
201     protected void setNames()
202     {
203         if (nodeName == null)
204         {
205             if (oneRowRightSide)
206             {
207                 nodeName = MessageService.getTextMessage(
208                                         SQLState.RTS_NESTED_LOOP_EXISTS_JOIN);
209                 resultSetName = MessageService.getTextMessage(
210                                     SQLState.RTS_NESTED_LOOP_EXISTS_JOIN_RS);
211             }
212             else
213             {
214                 nodeName = MessageService.getTextMessage(
215                                         SQLState.RTS_NESTED_LOOP_JOIN);
216                 resultSetName = MessageService.getTextMessage(
217                                     SQLState.RTS_NESTED_LOOP_JOIN_RS);
218             }
219         }
220     }
221 }
222
Popular Tags