001: /*
002:
003: Derby - Class org.apache.derby.impl.store.access.heap.HeapScanInfo
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.heap;
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: @see org.apache.derby.iapi.store.access.ScanController#getScanInfo()
042:
043: **/
044: class HeapScanInfo implements ScanInfo {
045: /**
046: * Performance counters ...
047: */
048: private int stat_numpages_visited = 0;
049: private int stat_numrows_visited = 0;
050: private int stat_numrows_qualified = 0;
051: private int stat_numColumnsFetched = 0;
052: private FormatableBitSet stat_validColumns = null;
053:
054: /* Constructors for This class: */
055: HeapScanInfo(HeapScan scan) {
056: // copy perfomance state out of scan, to get a fixed set of stats
057: stat_numpages_visited = scan.getNumPagesVisited();
058: stat_numrows_visited = scan.getNumRowsVisited();
059: stat_numrows_qualified = scan.getNumRowsQualified();
060:
061: stat_validColumns = (scan.getScanColumnList() == null ? null
062: : ((FormatableBitSet) scan.getScanColumnList().clone()));
063:
064: if (stat_validColumns == null) {
065: stat_numColumnsFetched = ((Heap) scan.getOpenConglom()
066: .getConglomerate()).format_ids.length;
067: } else {
068: for (int i = 0; i < stat_validColumns.size(); i++) {
069: if (stat_validColumns.get(i))
070: stat_numColumnsFetched++;
071: }
072: }
073:
074: }
075:
076: /**
077: * Return all information gathered about the scan.
078: * <p>
079: * This routine returns a list of properties which contains all information
080: * gathered about the scan. If a Property is passed in, then that property
081: * list is appeneded to, otherwise a new property object is created and
082: * returned.
083: * <p>
084: * Not all scans may support all properties, if the property is not
085: * supported then it will not be returned. The following is a list of
086: * properties that may be returned:
087: *
088: * numPagesVisited
089: * - the number of pages visited during the scan. For btree scans
090: * this number only includes the leaf pages visited.
091: * numRowsVisited
092: * - the number of rows visited during the scan. This number
093: * includes all rows, including: those marked deleted, those
094: * that don't meet qualification, ...
095: * numRowsQualified
096: * - the number of undeleted rows, which met the qualification.
097: * treeHeight (btree's only)
098: * - for btree's the height of the tree. A tree with one page
099: * has a height of 1. Total number of pages visited in a btree
100: * scan is (treeHeight - 1 + numPagesVisited).
101: * NOTE - this list will be expanded as more information about the scan
102: * is gathered and returned.
103: *
104: * @param prop Property list to fill in.
105: *
106: * @exception StandardException Standard exception policy.
107: **/
108: public Properties getAllScanInfo(Properties prop)
109: throws StandardException {
110: if (prop == null)
111: prop = new Properties();
112:
113: prop.put(MessageService
114: .getTextMessage(SQLState.STORE_RTS_SCAN_TYPE),
115: MessageService.getTextMessage(SQLState.STORE_RTS_HEAP));
116: prop.put(MessageService
117: .getTextMessage(SQLState.STORE_RTS_NUM_PAGES_VISITED),
118: Integer.toString(stat_numpages_visited));
119: prop.put(MessageService
120: .getTextMessage(SQLState.STORE_RTS_NUM_ROWS_VISITED),
121: Integer.toString(stat_numrows_visited));
122: prop.put(MessageService
123: .getTextMessage(SQLState.STORE_RTS_NUM_ROWS_QUALIFIED),
124: Integer.toString(stat_numrows_qualified));
125: prop
126: .put(
127: MessageService
128: .getTextMessage(SQLState.STORE_RTS_NUM_COLUMNS_FETCHED),
129: Integer.toString(stat_numColumnsFetched));
130: prop
131: .put(
132: MessageService
133: .getTextMessage(SQLState.STORE_RTS_COLUMNS_FETCHED_BIT_SET),
134: (stat_validColumns == null ? MessageService
135: .getTextMessage(SQLState.STORE_RTS_ALL)
136: : stat_validColumns.toString()));
137:
138: return (prop);
139: }
140: }
|