MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / Sort

Method Sort

src/jrd/sort.cpp:153–258  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

151
152
153Sort::Sort(Database* dbb,
154 SortOwner* owner,
155 ULONG record_length,
156 FB_SIZE_T keys,
157 FB_SIZE_T unique_keys,
158 const sort_key_def* key_description,
159 FPTR_REJECT_DUP_CALLBACK call_back,
160 void* user_arg,
161 FB_UINT64 max_records)
162 : m_dbb(dbb), m_owner(owner),
163 m_last_record(NULL), m_next_pointer(NULL), m_records(0),
164 m_runs(NULL), m_merge(NULL), m_free_runs(NULL),
165 m_flags(0), m_merge_pool(NULL),
166 m_description(m_owner->getPool(), keys)
167{
168/**************************************
169 *
170 * Initialize for a sort. All we really need is a description
171 * of the sort keys. Return the address of a sort context block.
172 * If duplicate control is required, the user may specify a call
173 * back routine. If supplied, the call back routine is called
174 * with three argument: the two records and the user supplied
175 * argument. If the call back routine returns TRUE, the second
176 * duplicate record is eliminated.
177 *
178 * hvlad: when duplicates are eliminating only first unique_keys will be
179 * compared. This is used at creation of unique index since sort key
180 * includes index key (which must be unique) and record numbers.
181 *
182 **************************************/
183 fb_assert(m_owner);
184 fb_assert(unique_keys <= keys);
185
186 try
187 {
188 // Allocate and setup a sort context block, including copying the
189 // key description vector. Round the record length up to the next
190 // longword, and add a longword to a pointer back to the pointer slot.
191
192 MemoryPool& pool = m_owner->getPool();
193
194 const ULONG record_size = ROUNDUP(record_length + SIZEOF_SR_BCKPTR, FB_ALIGNMENT);
195 m_longs = record_size >> SHIFTLONG;
196
197 m_min_alloc_size = record_size * MIN_RECORDS_TO_ALLOC;
198 m_max_alloc_size = MAX(m_min_alloc_size, MAX_SORT_BUFFER_SIZE);
199
200 m_dup_callback = call_back;
201 m_dup_callback_arg = user_arg;
202 m_max_records = max_records;
203
204 for (FB_SIZE_T i = 0; i < keys; i++)
205 {
206 m_description.add(key_description[i]);
207 }
208
209 const sort_key_def* p = m_description.end() - 1;
210

Callers

nothing calls this directly

Calls 12

TempSpaceClass · 0.85
GdsClass · 0.85
getSkdOffsetMethod · 0.80
getSkdLengthMethod · 0.80
linkSortMethod · 0.80
StatusVectorClass · 0.70
initFunction · 0.50
addMethod · 0.45
endMethod · 0.45
raiseMethod · 0.45
appendMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected