KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > store > access > btree > BTreeScanInfo


1 /*
2
3    Derby - Class org.apache.derby.impl.store.access.btree.BTreeScanInfo
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.store.access.btree;
23
24 import org.apache.derby.iapi.store.access.ScanInfo;
25
26 import org.apache.derby.iapi.error.StandardException;
27
28 import org.apache.derby.iapi.reference.SQLState;
29
30 import org.apache.derby.iapi.services.io.FormatableBitSet;
31 import org.apache.derby.iapi.services.i18n.MessageService;
32 import java.util.Properties JavaDoc;
33
34 /**
35
36   This object provides performance information related to an open scan.
37   The information is accumulated during operations on a ScanController() and
38   then copied into this object and returned by a call to
39   ScanController.getStatistic().
40
41
42 **/

43 class BTreeScanInfo implements ScanInfo
44 {
45     /**
46      * Performance counters ...
47      */

48     private int stat_numpages_visited = 0;
49     private int stat_numrows_visited = 0;
50     private int stat_numrows_qualified = 0;
51     private int stat_numdeleted_rows_visited = 0;
52     private int stat_numColumnsFetched = 0;
53     private int stat_treeHeight = 0;
54     private FormatableBitSet stat_validColumns = null;
55
56     /* Constructors for This class: */
57     BTreeScanInfo(BTreeScan scan)
58     {
59         // copy perfomance state out of scan, to get a fixed set of stats
60
stat_numpages_visited = scan.stat_numpages_visited;
61         stat_numrows_visited = scan.stat_numrows_visited;
62         stat_numrows_qualified = scan.stat_numrows_qualified;
63         stat_numdeleted_rows_visited = scan.stat_numdeleted_rows_visited;
64
65         stat_validColumns =
66             (scan.init_scanColumnList == null ?
67                 null : ((FormatableBitSet) scan.init_scanColumnList.clone()));
68
69         if (stat_validColumns == null)
70         {
71             stat_numColumnsFetched = scan.init_template.length;
72         }
73         else
74         {
75             for (int i = 0; i < stat_validColumns.size(); i++)
76             {
77                 if (stat_validColumns.get(i))
78                     stat_numColumnsFetched++;
79             }
80         }
81
82         try
83         {
84             stat_treeHeight = scan.getHeight();
85         }
86         catch (Throwable JavaDoc t)
87         {
88             stat_treeHeight = -1;
89         }
90     }
91
92     /**
93      * Return all information gathered about the scan.
94      * <p>
95      * This routine returns a list of properties which contains all information
96      * gathered about the scan. If a Property is passed in, then that property
97      * list is appeneded to, otherwise a new property object is created and
98      * returned.
99      * <p>
100      * Not all scans may support all properties, if the property is not
101      * supported then it will not be returned. The following is a list of
102      * properties that may be returned:
103      *
104      * numPagesVisited
105      * - the number of pages visited during the scan. For btree scans
106      * this number only includes the leaf pages visited.
107      * numRowsVisited
108      * - the number of rows visited during the scan. This number
109      * includes all rows, including: those marked deleted, those
110      * that don't meet qualification, ...
111      * numRowsQualified
112      * - the number of undeleted rows, which met the qualification.
113      * treeHeight (btree's only)
114      * - for btree's the height of the tree. A tree with one page
115      * has a height of 1. Total number of pages visited in a btree
116      * scan is (treeHeight - 1 + numPagesVisited).
117      * numColumnsFetched
118      * - the number of columns Fetched - partial scans will result
119      * in fetching less columns than the total number in the scan.
120      * columnsFetched
121      * - The FormatableBitSet.toString() method called on the validColumns arg.
122      * to the scan, unless validColumns was set to null, and in that
123      * case we will return "all".
124      * NOTE - this list will be expanded as more information about the scan
125      * is gathered and returned.
126      *
127      * @param prop Property list to fill in.
128      *
129      * @exception StandardException Standard exception policy.
130      **/

131     public Properties JavaDoc getAllScanInfo(Properties JavaDoc prop)
132         throws StandardException
133     {
134         if (prop == null)
135             prop = new Properties JavaDoc();
136
137         prop.put(
138             MessageService.getTextMessage(SQLState.STORE_RTS_SCAN_TYPE),
139             MessageService.getTextMessage(SQLState.STORE_RTS_BTREE));
140         prop.put(
141             MessageService.getTextMessage(SQLState.STORE_RTS_NUM_PAGES_VISITED),
142             Integer.toString(stat_numpages_visited));
143         prop.put(
144             MessageService.getTextMessage(SQLState.STORE_RTS_NUM_ROWS_VISITED),
145             Integer.toString(stat_numrows_visited));
146         prop.put(
147             MessageService.getTextMessage(
148                                 SQLState.STORE_RTS_NUM_DELETED_ROWS_VISITED),
149             Integer.toString(stat_numdeleted_rows_visited));
150         prop.put(
151             MessageService.getTextMessage(
152                                 SQLState.STORE_RTS_NUM_ROWS_QUALIFIED),
153             Integer.toString(stat_numrows_qualified));
154         prop.put(
155             MessageService.getTextMessage(
156                                 SQLState.STORE_RTS_TREE_HEIGHT),
157             Integer.toString(stat_treeHeight));
158         prop.put(
159             MessageService.getTextMessage(
160                                 SQLState.STORE_RTS_NUM_COLUMNS_FETCHED),
161             Integer.toString(stat_numColumnsFetched));
162         prop.put(
163             MessageService.getTextMessage(
164                                 SQLState.STORE_RTS_COLUMNS_FETCHED_BIT_SET),
165             (stat_validColumns == null ?
166                 MessageService.getTextMessage(
167                                 SQLState.STORE_RTS_ALL) :
168                 stat_validColumns.toString()));
169
170         return(prop);
171     }
172 }
173
Popular Tags