1 | /* |
2 | |
3 | Derby - Class org.apache.derby.impl.store.access.sort.MergeSortInfo |
4 | |
5 | Copyright 1999, 2004 The Apache Software Foundation or its licensors, as applicable. |
6 | |
7 | Licensed under the Apache License, Version 2.0 (the "License"); |
8 | you may not use this file except in compliance with the License. |
9 | You may obtain a copy of the License at |
10 | |
11 | http://www.apache.org/licenses/LICENSE-2.0 |
12 | |
13 | Unless required by applicable law or agreed to in writing, software |
14 | distributed under the License is distributed on an "AS IS" BASIS, |
15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | See the License for the specific language governing permissions and |
17 | limitations under the License. |
18 | |
19 | */ |
20 | |
21 | package org.apache.derby.impl.store.access.sort; |
22 | |
23 | import org.apache.derby.iapi.store.access.SortInfo; |
24 | |
25 | import org.apache.derby.iapi.error.StandardException; |
26 | |
27 | import org.apache.derby.iapi.reference.SQLState; |
28 | |
29 | import org.apache.derby.iapi.services.i18n.MessageService; |
30 | |
31 | import java.util.Vector; |
32 | import java.util.Properties; |
33 | |
34 | /** |
35 | |
36 | This object provides performance information related to a sort. |
37 | The information is accumulated during operations on a SortController() and |
38 | then copied into this object and returned by a call to |
39 | SortController.getSortInfo(). |
40 | |
41 | @see org.apache.derby.iapi.store.access.SortController#getSortInfo() |
42 | |
43 | **/ |
44 | class MergeSortInfo implements SortInfo |
45 | { |
46 | /** |
47 | * Performance counters ... |
48 | */ |
49 | |
50 | private String stat_sortType; |
51 | // private long stat_estimMemUsed; |
52 | private int stat_numRowsInput; |
53 | private int stat_numRowsOutput; |
54 | private int stat_numMergeRuns; |
55 | private Vector stat_mergeRunsSize; |
56 | |
57 | |
58 | /* Constructors for This class: */ |
59 | MergeSortInfo(MergeInserter sort) |
60 | { |
61 | // copy perfomance state out of sort, to get a fixed set of stats |
62 | stat_sortType = sort.stat_sortType; |
63 | // stat_estimMemUsed = sort.estimatedMemoryUsed; |
64 | stat_numRowsInput = sort.stat_numRowsInput; |
65 | stat_numRowsOutput = sort.stat_numRowsOutput; |
66 | stat_numMergeRuns = sort.stat_numMergeRuns; |
67 | stat_mergeRunsSize = sort.stat_mergeRunsSize; |
68 | } |
69 | |
70 | /** |
71 | * Return all information gathered about the sort. |
72 | * <p> |
73 | * This routine returns a list of properties which contains all information |
74 | * gathered about the sort. If a Property is passed in, then that property |
75 | * list is appended to, otherwise a new property object is created and |
76 | * returned. |
77 | * <p> |
78 | * Not all sorts may support all properties, if the property is not |
79 | * supported then it will not be returned. The following is a list of |
80 | * properties that may be returned: |
81 | * |
82 | * sortType |
83 | * - type of the sort being performed: |
84 | * internal |
85 | * external |
86 | * numRowsInput |
87 | * - the number of rows input to the sort. This |
88 | * number includes duplicates. |
89 | * numRowsOutput |
90 | * - the number of rows to be output by the sort. This number |
91 | * may be different from numRowsInput since duplicates may not |
92 | * be output. |
93 | * numMergeRuns |
94 | * - the number of merge runs for the sort. |
95 | * Applicable to external sorts only. |
96 | * Note: when a SortController is closed, numMergeRuns may increase by 1, to |
97 | * reflect the additional merge run that may be created for |
98 | * any data still in the sort buffer. |
99 | * mergeRunsSize |
100 | * - the size (number of rows) of each merge run for the sort. |
101 | * Applicable to external sorts only. |
102 | * e.g. [3,3,2] indicates 3 merge runs, where the first two runs |
103 | * have 3 rows each, and the last run has 2 rows. |
104 | * Note: when a SortController is closed, this vector may get an |
105 | * additional element, to reflect the additional merge run that |
106 | * may be created for any data still in the sort buffer. |
107 | * NOTE - this list will be expanded as more information about the sort |
108 | * is gathered and returned. |
109 | * |
110 | * @param prop Property list to fill in. |
111 | * |
112 | * @exception StandardException Standard exception policy. |
113 | **/ |
114 | |
115 | public Properties getAllSortInfo(Properties prop) |
116 | throws StandardException |
117 | { |
118 | if (prop == null) |
119 | prop = new Properties(); |
120 | |
121 | prop.put( |
122 | MessageService.getTextMessage(SQLState.STORE_RTS_SORT_TYPE), |
123 | "external".equals(this.stat_sortType) ? |
124 | MessageService.getTextMessage(SQLState.STORE_RTS_EXTERNAL) : |
125 | MessageService.getTextMessage(SQLState.STORE_RTS_INTERNAL)); |
126 | // prop.put( |
127 | // MessageService.getTextMessage(SQLState.STORE_RTS_ESTIMATED_MEMORY_USED), |
128 | // Long.toString(stat_estimMemUsed)); |
129 | prop.put( |
130 | MessageService.getTextMessage(SQLState.STORE_RTS_NUM_ROWS_INPUT), |
131 | Integer.toString(stat_numRowsInput)); |
132 | prop.put( |
133 | MessageService.getTextMessage(SQLState.STORE_RTS_NUM_ROWS_OUTPUT), |
134 | Integer.toString(stat_numRowsOutput)); |
135 | if (this.stat_sortType == "external") |
136 | { |
137 | prop.put( |
138 | MessageService.getTextMessage(SQLState.STORE_RTS_NUM_MERGE_RUNS), |
139 | Integer.toString(stat_numMergeRuns)); |
140 | prop.put( |
141 | MessageService.getTextMessage(SQLState.STORE_RTS_MERGE_RUNS_SIZE), |
142 | stat_mergeRunsSize.toString()); |
143 | } |
144 | return(prop); |
145 | } |
146 | } |
147 | |
148 | |
149 | /** |
150 | * estimMemUsed IS NOT CURRENTLY SUPPORTED SINCE IT IS UNRELIABLE |
151 | * estimMemUsed |
152 | * - the estimated memory used by the sort. |
153 | * |
154 | * This is only measured when the system runs out of sort |
155 | * buffer space, AND when it tries to avoid doing an external sort. |
156 | * It measures this by subtracting the memory usage at initialization |
157 | * from the memory usage at the time we are trying to avoid doing an |
158 | * external sort. The result could be negative: this probably indicates |
159 | * that there has been some garbage collection in the interim. |
160 | * If the attempt at keeping the sort internal succeeds, the buffer grows |
161 | * but the increased memory usage is not measured. |
162 | * |
163 | * The system may never measure the memory usage. This happens if |
164 | * it never runs out of sort buffer space, or if it is set up not |
165 | * to avoid external sorts. In cases that it is not measured, it returns 0. |
166 | * |
167 | * In future, this info may improve with an improved JVM API. |
168 | */ |
169 | |