00001 /* Copyright (C) 2001 MySQL AB 00002 00003 This program is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation; either version 2 of the License, or 00006 (at your option) any later version. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 00016 00017 /* 00018 Function to handle quick removal of duplicates 00019 This code is used when doing multi-table deletes to find the rows in 00020 reference tables that needs to be deleted. 00021 00022 The basic idea is as follows: 00023 00024 Store first all strings in a binary tree, ignoring duplicates. 00025 When the tree uses more memory than 'max_heap_table_size', 00026 write the tree (in sorted order) out to disk and start with a new tree. 00027 When all data has been generated, merge the trees (removing any found 00028 duplicates). 00029 00030 The unique entries will be returned in sort order, to ensure that we do the 00031 deletes in disk order. 00032 */ 00033 00034 #include "mysql_priv.h" 00035 #include "sql_sort.h" 00036 00037 00038 int unique_write_to_file(gptr key, element_count count, Unique *unique) 00039 { 00040 /* 00041 Use unique->size (size of element stored in the tree) and not 00042 unique->tree.size_of_element. The latter is different from unique->size 00043 when tree implementation chooses to store pointer to key in TREE_ELEMENT 00044 (instead of storing the element itself there) 00045 */ 00046 return my_b_write(&unique->file, (byte*) key, 00047 unique->size) ? 1 : 0; 00048 } 00049 00050 int unique_write_to_ptrs(gptr key, element_count count, Unique *unique) 00051 { 00052 memcpy(unique->record_pointers, key, unique->size); 00053 unique->record_pointers+=unique->size; 00054 return 0; 00055 } 00056 00057 Unique::Unique(qsort_cmp2 comp_func, void * comp_func_fixed_arg, 00058 uint size_arg, ulong max_in_memory_size_arg) 00059 :max_in_memory_size(max_in_memory_size_arg), size(size_arg), elements(0) 00060 { 00061 my_b_clear(&file); 00062 init_tree(&tree, max_in_memory_size / 16, 0, size, comp_func, 0, NULL, 00063 comp_func_fixed_arg); 00064 /* If the following fail's the next add will also fail */ 00065 my_init_dynamic_array(&file_ptrs, sizeof(BUFFPEK), 16, 16); 00066 /* 00067 If you change the following, change it in get_max_elements function, too. 00068 */ 00069 max_elements= max_in_memory_size / ALIGN_SIZE(sizeof(TREE_ELEMENT)+size); 00070 VOID(open_cached_file(&file, mysql_tmpdir,TEMP_PREFIX, DISK_BUFFER_SIZE, 00071 MYF(MY_WME))); 00072 } 00073 00074 00075 /* 00076 Calculate log2(n!) 00077 00078 NOTES 00079 Stirling's approximate formula is used: 00080 00081 n! ~= sqrt(2*M_PI*n) * (n/M_E)^n 00082 00083 Derivation of formula used for calculations is as follows: 00084 00085 log2(n!) = log(n!)/log(2) = log(sqrt(2*M_PI*n)*(n/M_E)^n) / log(2) = 00086 00087 = (log(2*M_PI*n)/2 + n*log(n/M_E)) / log(2). 00088 */ 00089 00090 inline double log2_n_fact(double x) 00091 { 00092 return (log(2*M_PI*x)/2 + x*log(x/M_E)) / M_LN2; 00093 } 00094 00095 00096 /* 00097 Calculate cost of merge_buffers function call for given sequence of 00098 input stream lengths and store the number of rows in result stream in *last. 00099 00100 SYNOPSIS 00101 get_merge_buffers_cost() 00102 buff_elems Array of #s of elements in buffers 00103 elem_size Size of element stored in buffer 00104 first Pointer to first merged element size 00105 last Pointer to last merged element size 00106 00107 RETURN 00108 Cost of merge_buffers operation in disk seeks. 00109 00110 NOTES 00111 It is assumed that no rows are eliminated during merge. 00112 The cost is calculated as 00113 00114 cost(read_and_write) + cost(merge_comparisons). 00115 00116 All bytes in the sequences is read and written back during merge so cost 00117 of disk io is 2*elem_size*total_buf_elems/IO_SIZE (2 is for read + write) 00118 00119 For comparisons cost calculations we assume that all merged sequences have 00120 the same length, so each of total_buf_size elements will be added to a sort 00121 heap with (n_buffers-1) elements. This gives the comparison cost: 00122 00123 total_buf_elems* log2(n_buffers) / TIME_FOR_COMPARE_ROWID; 00124 */ 00125 00126 static double get_merge_buffers_cost(uint *buff_elems, uint elem_size, 00127 uint *first, uint *last) 00128 { 00129 uint total_buf_elems= 0; 00130 for (uint *pbuf= first; pbuf <= last; pbuf++) 00131 total_buf_elems+= *pbuf; 00132 *last= total_buf_elems; 00133 00134 int n_buffers= last - first + 1; 00135 00136 /* Using log2(n)=log(n)/log(2) formula */ 00137 return 2*((double)total_buf_elems*elem_size) / IO_SIZE + 00138 total_buf_elems*log((double) n_buffers) / (TIME_FOR_COMPARE_ROWID * M_LN2); 00139 } 00140 00141 00142 /* 00143 Calculate cost of merging buffers into one in Unique::get, i.e. calculate 00144 how long (in terms of disk seeks) the two calls 00145 merge_many_buffs(...); 00146 merge_buffers(...); 00147 will take. 00148 00149 SYNOPSIS 00150 get_merge_many_buffs_cost() 00151 buffer buffer space for temporary data, at least 00152 Unique::get_cost_calc_buff_size bytes 00153 maxbuffer # of full buffers 00154 max_n_elems # of elements in first maxbuffer buffers 00155 last_n_elems # of elements in last buffer 00156 elem_size size of buffer element 00157 00158 NOTES 00159 maxbuffer+1 buffers are merged, where first maxbuffer buffers contain 00160 max_n_elems elements each and last buffer contains last_n_elems elements. 00161 00162 The current implementation does a dumb simulation of merge_many_buffs 00163 function actions. 00164 00165 RETURN 00166 Cost of merge in disk seeks. 00167 */ 00168 00169 static double get_merge_many_buffs_cost(uint *buffer, 00170 uint maxbuffer, uint max_n_elems, 00171 uint last_n_elems, int elem_size) 00172 { 00173 register int i; 00174 double total_cost= 0.0; 00175 uint *buff_elems= buffer; /* #s of elements in each of merged sequences */ 00176 00177 /* 00178 Set initial state: first maxbuffer sequences contain max_n_elems elements 00179 each, last sequence contains last_n_elems elements. 00180 */ 00181 for (i = 0; i < (int)maxbuffer; i++) 00182 buff_elems[i]= max_n_elems; 00183 buff_elems[maxbuffer]= last_n_elems; 00184 00185 /* 00186 Do it exactly as merge_many_buff function does, calling 00187 get_merge_buffers_cost to get cost of merge_buffers. 00188 */ 00189 if (maxbuffer >= MERGEBUFF2) 00190 { 00191 while (maxbuffer >= MERGEBUFF2) 00192 { 00193 uint lastbuff= 0; 00194 for (i = 0; i <= (int) maxbuffer - MERGEBUFF*3/2; i += MERGEBUFF) 00195 { 00196 total_cost+=get_merge_buffers_cost(buff_elems, elem_size, 00197 buff_elems + i, 00198 buff_elems + i + MERGEBUFF-1); 00199 lastbuff++; 00200 } 00201 total_cost+=get_merge_buffers_cost(buff_elems, elem_size, 00202 buff_elems + i, 00203 buff_elems + maxbuffer); 00204 maxbuffer= lastbuff; 00205 } 00206 } 00207 00208 /* Simulate final merge_buff call. */ 00209 total_cost += get_merge_buffers_cost(buff_elems, elem_size, 00210 buff_elems, buff_elems + maxbuffer); 00211 return total_cost; 00212 } 00213 00214 00215 /* 00216 Calculate cost of using Unique for processing nkeys elements of size 00217 key_size using max_in_memory_size memory. 00218 00219 SYNOPSIS 00220 Unique::get_use_cost() 00221 buffer space for temporary data, use Unique::get_cost_calc_buff_size 00222 to get # bytes needed. 00223 nkeys #of elements in Unique 00224 key_size size of each elements in bytes 00225 max_in_memory_size amount of memory Unique will be allowed to use 00226 00227 RETURN 00228 Cost in disk seeks. 00229 00230 NOTES 00231 cost(using_unqiue) = 00232 cost(create_trees) + (see #1) 00233 cost(merge) + (see #2) 00234 cost(read_result) (see #3) 00235 00236 1. Cost of trees creation 00237 For each Unique::put operation there will be 2*log2(n+1) elements 00238 comparisons, where n runs from 1 tree_size (we assume that all added 00239 elements are different). Together this gives: 00240 00241 n_compares = 2*(log2(2) + log2(3) + ... + log2(N+1)) = 2*log2((N+1)!) 00242 00243 then cost(tree_creation) = n_compares*ROWID_COMPARE_COST; 00244 00245 Total cost of creating trees: 00246 (n_trees - 1)*max_size_tree_cost + non_max_size_tree_cost. 00247 00248 Approximate value of log2(N!) is calculated by log2_n_fact function. 00249 00250 2. Cost of merging. 00251 If only one tree is created by Unique no merging will be necessary. 00252 Otherwise, we model execution of merge_many_buff function and count 00253 #of merges. (The reason behind this is that number of buffers is small, 00254 while size of buffers is big and we don't want to loose precision with 00255 O(x)-style formula) 00256 00257 3. If only one tree is created by Unique no disk io will happen. 00258 Otherwise, ceil(key_len*n_keys) disk seeks are necessary. We assume 00259 these will be random seeks. 00260 */ 00261 00262 double Unique::get_use_cost(uint *buffer, uint nkeys, uint key_size, 00263 ulong max_in_memory_size) 00264 { 00265 ulong max_elements_in_tree; 00266 ulong last_tree_elems; 00267 int n_full_trees; /* number of trees in unique - 1 */ 00268 double result; 00269 00270 max_elements_in_tree= 00271 max_in_memory_size / ALIGN_SIZE(sizeof(TREE_ELEMENT)+key_size); 00272 00273 n_full_trees= nkeys / max_elements_in_tree; 00274 last_tree_elems= nkeys % max_elements_in_tree; 00275 00276 /* Calculate cost of creating trees */ 00277 result= 2*log2_n_fact(last_tree_elems + 1.0); 00278 if (n_full_trees) 00279 result+= n_full_trees * log2_n_fact(max_elements_in_tree + 1.0); 00280 result /= TIME_FOR_COMPARE_ROWID; 00281 00282 DBUG_PRINT("info",("unique trees sizes: %u=%u*%lu + %lu", nkeys, 00283 n_full_trees, n_full_trees?max_elements_in_tree:0, 00284 last_tree_elems)); 00285 00286 if (!n_full_trees) 00287 return result; 00288 00289 /* 00290 There is more then one tree and merging is necessary. 00291 First, add cost of writing all trees to disk, assuming that all disk 00292 writes are sequential. 00293 */ 00294 result += DISK_SEEK_BASE_COST * n_full_trees * 00295 ceil(((double) key_size)*max_elements_in_tree / IO_SIZE); 00296 result += DISK_SEEK_BASE_COST * ceil(((double) key_size)*last_tree_elems / IO_SIZE); 00297 00298 /* Cost of merge */ 00299 double merge_cost= get_merge_many_buffs_cost(buffer, n_full_trees, 00300 max_elements_in_tree, 00301 last_tree_elems, key_size); 00302 if (merge_cost < 0.0) 00303 return merge_cost; 00304 00305 result += merge_cost; 00306 /* 00307 Add cost of reading the resulting sequence, assuming there were no 00308 duplicate elements. 00309 */ 00310 result += ceil((double)key_size*nkeys/IO_SIZE); 00311 00312 return result; 00313 } 00314 00315 Unique::~Unique() 00316 { 00317 close_cached_file(&file); 00318 delete_tree(&tree); 00319 delete_dynamic(&file_ptrs); 00320 } 00321 00322 00323 /* Write tree to disk; clear tree */ 00324 bool Unique::flush() 00325 { 00326 BUFFPEK file_ptr; 00327 elements+= tree.elements_in_tree; 00328 file_ptr.count=tree.elements_in_tree; 00329 file_ptr.file_pos=my_b_tell(&file); 00330 00331 if (tree_walk(&tree, (tree_walk_action) unique_write_to_file, 00332 (void*) this, left_root_right) || 00333 insert_dynamic(&file_ptrs, (gptr) &file_ptr)) 00334 return 1; 00335 delete_tree(&tree); 00336 return 0; 00337 } 00338 00339 00340 /* 00341 Clear the tree and the file. 00342 You must call reset() if you want to reuse Unique after walk(). 00343 */ 00344 00345 void 00346 Unique::reset() 00347 { 00348 reset_tree(&tree); 00349 /* 00350 If elements != 0, some trees were stored in the file (see how 00351 flush() works). Note, that we can not count on my_b_tell(&file) == 0 00352 here, because it can return 0 right after walk(), and walk() does not 00353 reset any Unique member. 00354 */ 00355 if (elements) 00356 { 00357 reset_dynamic(&file_ptrs); 00358 reinit_io_cache(&file, WRITE_CACHE, 0L, 0, 1); 00359 } 00360 elements= 0; 00361 } 00362 00363 /* 00364 The comparison function, passed to queue_init() in merge_walk() must 00365 use comparison function of Uniques::tree, but compare members of struct 00366 BUFFPEK. 00367 */ 00368 00369 struct BUFFPEK_COMPARE_CONTEXT 00370 { 00371 qsort_cmp2 key_compare; 00372 void *key_compare_arg; 00373 }; 00374 00375 C_MODE_START 00376 00377 static int buffpek_compare(void *arg, byte *key_ptr1, byte *key_ptr2) 00378 { 00379 BUFFPEK_COMPARE_CONTEXT *ctx= (BUFFPEK_COMPARE_CONTEXT *) arg; 00380 return ctx->key_compare(ctx->key_compare_arg, 00381 *((byte **) key_ptr1), *((byte **)key_ptr2)); 00382 } 00383 00384 C_MODE_END 00385 00386 00387 /* 00388 DESCRIPTION 00389 Function is very similar to merge_buffers, but instead of writing sorted 00390 unique keys to the output file, it invokes walk_action for each key. 00391 This saves I/O if you need to pass through all unique keys only once. 00392 SYNOPSIS 00393 merge_walk() 00394 All params are 'IN' (but see comment for begin, end): 00395 merge_buffer buffer to perform cached piece-by-piece loading 00396 of trees; initially the buffer is empty 00397 merge_buffer_size size of merge_buffer. Must be aligned with 00398 key_length 00399 key_length size of tree element; key_length * (end - begin) 00400 must be less or equal than merge_buffer_size. 00401 begin pointer to BUFFPEK struct for the first tree. 00402 end pointer to BUFFPEK struct for the last tree; 00403 end > begin and [begin, end) form a consecutive 00404 range. BUFFPEKs structs in that range are used and 00405 overwritten in merge_walk(). 00406 walk_action element visitor. Action is called for each unique 00407 key. 00408 walk_action_arg argument to walk action. Passed to it on each call. 00409 compare elements comparison function 00410 compare_arg comparison function argument 00411 file file with all trees dumped. Trees in the file 00412 must contain sorted unique values. Cache must be 00413 initialized in read mode. 00414 RETURN VALUE 00415 0 ok 00416 <> 0 error 00417 */ 00418 00419 static bool merge_walk(uchar *merge_buffer, uint merge_buffer_size, 00420 uint key_length, BUFFPEK *begin, BUFFPEK *end, 00421 tree_walk_action walk_action, void *walk_action_arg, 00422 qsort_cmp2 compare, void *compare_arg, 00423 IO_CACHE *file) 00424 { 00425 BUFFPEK_COMPARE_CONTEXT compare_context = { compare, compare_arg }; 00426 QUEUE queue; 00427 if (end <= begin || 00428 merge_buffer_size < key_length * (end - begin + 1) || 00429 init_queue(&queue, end - begin, offsetof(BUFFPEK, key), 0, 00430 buffpek_compare, &compare_context)) 00431 return 1; 00432 /* we need space for one key when a piece of merge buffer is re-read */ 00433 merge_buffer_size-= key_length; 00434 uchar *save_key_buff= merge_buffer + merge_buffer_size; 00435 uint max_key_count_per_piece= merge_buffer_size/(end-begin)/key_length; 00436 /* if piece_size is aligned reuse_freed_buffer will always hit */ 00437 uint piece_size= max_key_count_per_piece * key_length; 00438 uint bytes_read; /* to hold return value of read_to_buffer */ 00439 BUFFPEK *top; 00440 int res= 1; 00441 /* 00442 Invariant: queue must contain top element from each tree, until a tree 00443 is not completely walked through. 00444 Here we're forcing the invariant, inserting one element from each tree 00445 to the queue. 00446 */ 00447 for (top= begin; top != end; ++top) 00448 { 00449 top->base= merge_buffer + (top - begin) * piece_size; 00450 top->max_keys= max_key_count_per_piece; 00451 bytes_read= read_to_buffer(file, top, key_length); 00452 if (bytes_read == (uint) (-1)) 00453 goto end; 00454 DBUG_ASSERT(bytes_read); 00455 queue_insert(&queue, (byte *) top); 00456 } 00457 top= (BUFFPEK *) queue_top(&queue); 00458 while (queue.elements > 1) 00459 { 00460 /* 00461 Every iteration one element is removed from the queue, and one is 00462 inserted by the rules of the invariant. If two adjacent elements on 00463 the top of the queue are not equal, biggest one is unique, because all 00464 elements in each tree are unique. Action is applied only to unique 00465 elements. 00466 */ 00467 void *old_key= top->key; 00468 /* 00469 read next key from the cache or from the file and push it to the 00470 queue; this gives new top. 00471 */ 00472 top->key+= key_length; 00473 if (--top->mem_count) 00474 queue_replaced(&queue); 00475 else /* next piece should be read */ 00476 { 00477 /* save old_key not to overwrite it in read_to_buffer */ 00478 memcpy(save_key_buff, old_key, key_length); 00479 old_key= save_key_buff; 00480 bytes_read= read_to_buffer(file, top, key_length); 00481 if (bytes_read == (uint) (-1)) 00482 goto end; 00483 else if (bytes_read > 0) /* top->key, top->mem_count are reset */ 00484 queue_replaced(&queue); /* in read_to_buffer */ 00485 else 00486 { 00487 /* 00488 Tree for old 'top' element is empty: remove it from the queue and 00489 give all its memory to the nearest tree. 00490 */ 00491 queue_remove(&queue, 0); 00492 reuse_freed_buff(&queue, top, key_length); 00493 } 00494 } 00495 top= (BUFFPEK *) queue_top(&queue); 00496 /* new top has been obtained; if old top is unique, apply the action */ 00497 if (compare(compare_arg, old_key, top->key)) 00498 { 00499 if (walk_action(old_key, 1, walk_action_arg)) 00500 goto end; 00501 } 00502 } 00503 /* 00504 Applying walk_action to the tail of the last tree: this is safe because 00505 either we had only one tree in the beginning, either we work with the 00506 last tree in the queue. 00507 */ 00508 do 00509 { 00510 do 00511 { 00512 if (walk_action(top->key, 1, walk_action_arg)) 00513 goto end; 00514 top->key+= key_length; 00515 } 00516 while (--top->mem_count); 00517 bytes_read= read_to_buffer(file, top, key_length); 00518 if (bytes_read == (uint) (-1)) 00519 goto end; 00520 } 00521 while (bytes_read); 00522 res= 0; 00523 end: 00524 delete_queue(&queue); 00525 return res; 00526 } 00527 00528 00529 /* 00530 DESCRIPTION 00531 Walks consecutively through all unique elements: 00532 if all elements are in memory, then it simply invokes 'tree_walk', else 00533 all flushed trees are loaded to memory piece-by-piece, pieces are 00534 sorted, and action is called for each unique value. 00535 Note: so as merging resets file_ptrs state, this method can change 00536 internal Unique state to undefined: if you want to reuse Unique after 00537 walk() you must call reset() first! 00538 SYNOPSIS 00539 Unique:walk() 00540 All params are 'IN': 00541 action function-visitor, typed in include/my_tree.h 00542 function is called for each unique element 00543 arg argument for visitor, which is passed to it on each call 00544 RETURN VALUE 00545 0 OK 00546 <> 0 error 00547 */ 00548 00549 bool Unique::walk(tree_walk_action action, void *walk_action_arg) 00550 { 00551 if (elements == 0) /* the whole tree is in memory */ 00552 return tree_walk(&tree, action, walk_action_arg, left_root_right); 00553 00554 /* flush current tree to the file to have some memory for merge buffer */ 00555 if (flush()) 00556 return 1; 00557 if (flush_io_cache(&file) || reinit_io_cache(&file, READ_CACHE, 0L, 0, 0)) 00558 return 1; 00559 uchar *merge_buffer= (uchar *) my_malloc(max_in_memory_size, MYF(0)); 00560 if (merge_buffer == 0) 00561 return 1; 00562 int res= merge_walk(merge_buffer, max_in_memory_size, size, 00563 (BUFFPEK *) file_ptrs.buffer, 00564 (BUFFPEK *) file_ptrs.buffer + file_ptrs.elements, 00565 action, walk_action_arg, 00566 tree.compare, tree.custom_arg, &file); 00567 x_free(merge_buffer); 00568 return res; 00569 } 00570 00571 /* 00572 Modify the TABLE element so that when one calls init_records() 00573 the rows will be read in priority order. 00574 */ 00575 00576 bool Unique::get(TABLE *table) 00577 { 00578 SORTPARAM sort_param; 00579 table->sort.found_records=elements+tree.elements_in_tree; 00580 00581 if (my_b_tell(&file) == 0) 00582 { 00583 /* Whole tree is in memory; Don't use disk if you don't need to */ 00584 if ((record_pointers=table->sort.record_pointers= (byte*) 00585 my_malloc(size * tree.elements_in_tree, MYF(0)))) 00586 { 00587 (void) tree_walk(&tree, (tree_walk_action) unique_write_to_ptrs, 00588 this, left_root_right); 00589 return 0; 00590 } 00591 } 00592 /* Not enough memory; Save the result to file && free memory used by tree */ 00593 if (flush()) 00594 return 1; 00595 00596 IO_CACHE *outfile=table->sort.io_cache; 00597 BUFFPEK *file_ptr= (BUFFPEK*) file_ptrs.buffer; 00598 uint maxbuffer= file_ptrs.elements - 1; 00599 uchar *sort_buffer; 00600 my_off_t save_pos; 00601 bool error=1; 00602 00603 /* Open cached file if it isn't open */ 00604 outfile=table->sort.io_cache=(IO_CACHE*) my_malloc(sizeof(IO_CACHE), 00605 MYF(MY_ZEROFILL)); 00606 00607 if (!outfile || ! my_b_inited(outfile) && 00608 open_cached_file(outfile,mysql_tmpdir,TEMP_PREFIX,READ_RECORD_BUFFER, 00609 MYF(MY_WME))) 00610 return 1; 00611 reinit_io_cache(outfile,WRITE_CACHE,0L,0,0); 00612 00613 bzero((char*) &sort_param,sizeof(sort_param)); 00614 sort_param.max_rows= elements; 00615 sort_param.sort_form=table; 00616 sort_param.rec_length= sort_param.sort_length= sort_param.ref_length= 00617 size; 00618 sort_param.keys= max_in_memory_size / sort_param.sort_length; 00619 sort_param.not_killable=1; 00620 00621 if (!(sort_buffer=(uchar*) my_malloc((sort_param.keys+1) * 00622 sort_param.sort_length, 00623 MYF(0)))) 00624 return 1; 00625 sort_param.unique_buff= sort_buffer+(sort_param.keys* 00626 sort_param.sort_length); 00627 00628 /* Merge the buffers to one file, removing duplicates */ 00629 if (merge_many_buff(&sort_param,sort_buffer,file_ptr,&maxbuffer,&file)) 00630 goto err; 00631 if (flush_io_cache(&file) || 00632 reinit_io_cache(&file,READ_CACHE,0L,0,0)) 00633 goto err; 00634 if (merge_buffers(&sort_param, &file, outfile, sort_buffer, file_ptr, 00635 file_ptr, file_ptr+maxbuffer,0)) 00636 goto err; 00637 error=0; 00638 err: 00639 x_free((gptr) sort_buffer); 00640 if (flush_io_cache(outfile)) 00641 error=1; 00642 00643 /* Setup io_cache for reading */ 00644 save_pos=outfile->pos_in_file; 00645 if (reinit_io_cache(outfile,READ_CACHE,0L,0,0)) 00646 error=1; 00647 outfile->end_of_file=save_pos; 00648 return error; 00649 }
1.4.7

