KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.execute.rts.RealProjectRestrictStatistics
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 ProjectRestrictResultSet.
37
38   @author jerry
39
40 */

41 public class RealProjectRestrictStatistics
42     extends RealNoPutResultSetStatistics
43 {
44
45     /* Leave these fields public for object inspectors */
46     public boolean doesProjection;
47     public boolean restriction;
48     public long restrictionTime;
49     public long projectionTime;
50     public ResultSetStatistics childResultSetStatistics;
51     public ResultSetStatistics[] subqueryTrackingArray;
52
53     // CONSTRUCTORS
54

55     /**
56      *
57      *
58      */

59     public RealProjectRestrictStatistics(
60                                 int numOpens,
61                                 int rowsSeen,
62                                 int rowsFiltered,
63                                 long constructorTime,
64                                 long openTime,
65                                 long nextTime,
66                                 long closeTime,
67                                 int resultSetNumber,
68                                 long restrictionTime,
69                                 long projectionTime,
70                                 ResultSetStatistics[] subqueryTrackingArray,
71                                 boolean restriction,
72                                 boolean doesProjection,
73                                 double optimizerEstimatedRowCount,
74                                 double optimizerEstimatedCost,
75                                 ResultSetStatistics childResultSetStatistics
76                                 )
77     {
78         super(
79             numOpens,
80             rowsSeen,
81             rowsFiltered,
82             constructorTime,
83             openTime,
84             nextTime,
85             closeTime,
86             resultSetNumber,
87             optimizerEstimatedRowCount,
88             optimizerEstimatedCost
89             );
90         this.restriction = restriction;
91         this.doesProjection = doesProjection;
92         this.restrictionTime = restrictionTime;
93         this.projectionTime = projectionTime;
94         this.subqueryTrackingArray = subqueryTrackingArray;
95         this.childResultSetStatistics = childResultSetStatistics;
96     }
97
98     // ResultSetStatistics methods
99

100     /**
101      * Return the statement execution plan as a String.
102      *
103      * @param depth Indentation level.
104      *
105      * @return String The statement execution plan as a String.
106      */

107     public String JavaDoc getStatementExecutionPlanText(int depth)
108     {
109         String JavaDoc subqueryInfo = "";
110
111         initFormatInfo(depth);
112
113         /* Dump out the statistics for any subqueries */
114
115         if (subqueryTrackingArray != null)
116         {
117             boolean foundAttached = false;
118
119             for (int index = 0; index < subqueryTrackingArray.length; index++)
120             {
121                 if (subqueryTrackingArray[index] != null)
122                 {
123                     /* Only print attached subqueries message once */
124                     if (! foundAttached)
125                     {
126                         subqueryInfo = indent +
127                             MessageService.getTextMessage(
128                                                 SQLState.RTS_ATTACHED_SQS) +
129                                 ":\n";
130                         foundAttached = true;
131                     }
132                     subqueryInfo = subqueryInfo +
133                         subqueryTrackingArray[index].getStatementExecutionPlanText(sourceDepth);
134                 }
135             }
136         }
137
138         return
139             subqueryInfo +
140             indent + MessageService.getTextMessage(SQLState.RTS_PR_RS) +
141                 " (" + resultSetNumber + "):" + "\n" +
142             indent + MessageService.getTextMessage(SQLState.RTS_NUM_OPENS) +
143                 " = " + numOpens + "\n" +
144             indent + MessageService.getTextMessage(SQLState.RTS_ROWS_SEEN) +
145                 " = " + rowsSeen + "\n" +
146             indent + MessageService.getTextMessage(
147                                                 SQLState.RTS_ROWS_FILTERED) +
148                 " = " + rowsFiltered + "\n" +
149             indent + MessageService.getTextMessage(
150                                                     SQLState.RTS_RESTRICTION) +
151                 " = " + restriction + "\n" +
152             indent + MessageService.getTextMessage(SQLState.RTS_PROJECTION) +
153                 " = " + doesProjection + "\n" +
154             dumpTimeStats(indent, subIndent) + "\n" +
155             subIndent + MessageService.getTextMessage(
156                                                 SQLState.RTS_RESTRICTION_TIME) +
157                 " = " + restrictionTime + "\n" +
158             subIndent + MessageService.getTextMessage(
159                                                 SQLState.RTS_PROJECTION_TIME) +
160                 " = " + projectionTime + "\n" +
161             dumpEstimatedCosts(subIndent) + "\n" +
162             indent + MessageService.getTextMessage(SQLState.RTS_SOURCE_RS) +
163                 ":" + "\n" +
164             childResultSetStatistics.getStatementExecutionPlanText(sourceDepth);
165     }
166
167     /**
168      * Return information on the scan nodes from the statement execution
169      * plan as a String.
170      *
171      * @param depth Indentation level.
172      * @param tableName if not NULL then print information for this table only
173      *
174      * @return String The information on the scan nodes from the
175      * statement execution plan as a String.
176      */

177     public String JavaDoc getScanStatisticsText(String JavaDoc tableName, int depth)
178     {
179         String JavaDoc subqueryInfo = "";
180
181         /* Dump out the statistics for any subqueries */
182
183         /* RESOLVE - until we externalize RunTimeStats, we just use
184          * this.subqueryTrackingArray since we are currently getting called
185          * on a close() and the StatementContext has changed and doesn't have
186          * a pointer to the top result set. When we externalize RunTimeStats,
187          * the JDBC Driver will have to push a new context and we will have
188          * to assign the top resultset there. (Not sure what to do about
189          * insert/update/delete.)
190          *
191         NoPutResultSet[] subqueryTrackingArray = sc.getSubqueryTrackingArray();
192          */

193
194         if (subqueryTrackingArray != null)
195         {
196             for (int index = 0; index < subqueryTrackingArray.length; index++)
197             {
198                 if (subqueryTrackingArray[index] != null)
199                 {
200                     subqueryInfo = subqueryInfo +
201                                    "\n" +
202                                     MessageService.getTextMessage(
203                                                 SQLState.RTS_BEGIN_SQ_NUMBER) +
204                                     " " + index + "\n" +
205                         subqueryTrackingArray[index].getScanStatisticsText(tableName, depth) +
206                         MessageService.getTextMessage(
207                                                 SQLState.RTS_END_SQ_NUMBER) +
208                         " " + index + "\n\n";
209                 }
210             }
211         }
212
213         return subqueryInfo
214             + childResultSetStatistics.getScanStatisticsText(tableName, depth);
215     }
216
217
218
219     // Class implementation
220

221     public String JavaDoc toString()
222     {
223         return getStatementExecutionPlanText(0);
224     }
225   public java.util.Vector JavaDoc getChildren(){
226     java.util.Vector JavaDoc children = new java.util.Vector JavaDoc();
227     children.addElement(childResultSetStatistics);
228
229     // get all of our subqueries
230
if (subqueryTrackingArray != null)
231     {
232         for (int index = 0; index < subqueryTrackingArray.length; index++)
233         {
234             if (subqueryTrackingArray[index] != null)
235             {
236                 children.addElement(subqueryTrackingArray[index]);
237             }
238         }
239     }
240     return children;
241   }
242     /**
243    * Format for display, a name for this node.
244      *
245      */

246   public String JavaDoc getNodeName(){
247     return MessageService.getTextMessage(SQLState.RTS_PR);
248   }
249 }
250
Popular Tags