001: /*
002:
003: Derby - Class org.apache.derby.impl.store.access.btree.BTreeScanInfo
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.store.access.btree;
023:
024: import org.apache.derby.iapi.store.access.ScanInfo;
025:
026: import org.apache.derby.iapi.error.StandardException;
027:
028: import org.apache.derby.iapi.reference.SQLState;
029:
030: import org.apache.derby.iapi.services.io.FormatableBitSet;
031: import org.apache.derby.iapi.services.i18n.MessageService;
032: import java.util.Properties;
033:
034: /**
035:
036: This object provides performance information related to an open scan.
037: The information is accumulated during operations on a ScanController() and
038: then copied into this object and returned by a call to
039: ScanController.getStatistic().
040:
041:
042: **/
043: class BTreeScanInfo implements ScanInfo {
044: /**
045: * Performance counters ...
046: */
047: private int stat_numpages_visited = 0;
048: private int stat_numrows_visited = 0;
049: private int stat_numrows_qualified = 0;
050: private int stat_numdeleted_rows_visited = 0;
051: private int stat_numColumnsFetched = 0;
052: private int stat_treeHeight = 0;
053: private FormatableBitSet stat_validColumns = null;
054:
055: /* Constructors for This class: */
056: BTreeScanInfo(BTreeScan scan) {
057: // copy perfomance state out of scan, to get a fixed set of stats
058: stat_numpages_visited = scan.stat_numpages_visited;
059: stat_numrows_visited = scan.stat_numrows_visited;
060: stat_numrows_qualified = scan.stat_numrows_qualified;
061: stat_numdeleted_rows_visited = scan.stat_numdeleted_rows_visited;
062:
063: stat_validColumns = (scan.init_scanColumnList == null ? null
064: : ((FormatableBitSet) scan.init_scanColumnList.clone()));
065:
066: if (stat_validColumns == null) {
067: stat_numColumnsFetched = scan.init_template.length;
068: } else {
069: for (int i = 0; i < stat_validColumns.size(); i++) {
070: if (stat_validColumns.get(i))
071: stat_numColumnsFetched++;
072: }
073: }
074:
075: try {
076: stat_treeHeight = scan.getHeight();
077: } catch (Throwable t) {
078: stat_treeHeight = -1;
079: }
080: }
081:
082: /**
083: * Return all information gathered about the scan.
084: * <p>
085: * This routine returns a list of properties which contains all information
086: * gathered about the scan. If a Property is passed in, then that property
087: * list is appeneded to, otherwise a new property object is created and
088: * returned.
089: * <p>
090: * Not all scans may support all properties, if the property is not
091: * supported then it will not be returned. The following is a list of
092: * properties that may be returned:
093: *
094: * numPagesVisited
095: * - the number of pages visited during the scan. For btree scans
096: * this number only includes the leaf pages visited.
097: * numRowsVisited
098: * - the number of rows visited during the scan. This number
099: * includes all rows, including: those marked deleted, those
100: * that don't meet qualification, ...
101: * numRowsQualified
102: * - the number of undeleted rows, which met the qualification.
103: * treeHeight (btree's only)
104: * - for btree's the height of the tree. A tree with one page
105: * has a height of 1. Total number of pages visited in a btree
106: * scan is (treeHeight - 1 + numPagesVisited).
107: * numColumnsFetched
108: * - the number of columns Fetched - partial scans will result
109: * in fetching less columns than the total number in the scan.
110: * columnsFetched
111: * - The FormatableBitSet.toString() method called on the validColumns arg.
112: * to the scan, unless validColumns was set to null, and in that
113: * case we will return "all".
114: * NOTE - this list will be expanded as more information about the scan
115: * is gathered and returned.
116: *
117: * @param prop Property list to fill in.
118: *
119: * @exception StandardException Standard exception policy.
120: **/
121: public Properties getAllScanInfo(Properties prop)
122: throws StandardException {
123: if (prop == null)
124: prop = new Properties();
125:
126: prop
127: .put(
128: MessageService
129: .getTextMessage(SQLState.STORE_RTS_SCAN_TYPE),
130: MessageService
131: .getTextMessage(SQLState.STORE_RTS_BTREE));
132: prop.put(MessageService
133: .getTextMessage(SQLState.STORE_RTS_NUM_PAGES_VISITED),
134: Integer.toString(stat_numpages_visited));
135: prop.put(MessageService
136: .getTextMessage(SQLState.STORE_RTS_NUM_ROWS_VISITED),
137: Integer.toString(stat_numrows_visited));
138: prop
139: .put(
140: MessageService
141: .getTextMessage(SQLState.STORE_RTS_NUM_DELETED_ROWS_VISITED),
142: Integer.toString(stat_numdeleted_rows_visited));
143: prop.put(MessageService
144: .getTextMessage(SQLState.STORE_RTS_NUM_ROWS_QUALIFIED),
145: Integer.toString(stat_numrows_qualified));
146: prop.put(MessageService
147: .getTextMessage(SQLState.STORE_RTS_TREE_HEIGHT),
148: Integer.toString(stat_treeHeight));
149: prop
150: .put(
151: MessageService
152: .getTextMessage(SQLState.STORE_RTS_NUM_COLUMNS_FETCHED),
153: Integer.toString(stat_numColumnsFetched));
154: prop
155: .put(
156: MessageService
157: .getTextMessage(SQLState.STORE_RTS_COLUMNS_FETCHED_BIT_SET),
158: (stat_validColumns == null ? MessageService
159: .getTextMessage(SQLState.STORE_RTS_ALL)
160: : stat_validColumns.toString()));
161:
162: return (prop);
163: }
164: }
|