1
/* Copyright (C) 2000 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
/* Defines used by filesort and uniques */
22
The structure SORT_ADDON_FIELD describes a fixed layout
23
for field values appended to sorted values in records to be sorted
25
Only fixed layout is supported now.
26
Null bit maps for the appended values is placed before the values
27
themselves. Offsets are from the last sorted field, that is from the
28
record referefence, which is still last component of sorted records.
29
It is preserved for backward compatiblility.
30
The structure is used tp store values of the additional fields
31
in the sort buffer. It is used also when these values are read
32
from a temporary file/buffer. As the reading procedures are beyond the
33
scope of the 'filesort' code the values have to be retrieved via
34
the callback function 'unpack_addon_fields'.
37
typedef struct st_sort_addon_field { /* Sort addon packed field */
38
Field *field; /* Original field */
39
uint offset; /* Offset from the last sorted field */
40
uint null_offset; /* Offset to to null bit from the last sorted field */
41
uint length; /* Length in the sort buffer */
42
uint8 null_bit; /* Null bit mask for the field */
45
typedef struct st_buffpek { /* Struktur om sorteringsbuffrarna */
46
my_off_t file_pos; /* Where we are in the sort file */
47
uchar *base,*key; /* key pointers */
48
ha_rows count; /* Number of rows in table */
49
ulong mem_count; /* numbers of keys in memory */
50
ulong max_keys; /* Max keys in buffert */
53
struct BUFFPEK_COMPARE_CONTEXT
55
qsort_cmp2 key_compare;
56
void *key_compare_arg;
59
typedef struct st_sort_param {
60
uint rec_length; /* Length of sorted records */
61
uint sort_length; /* Length of sorted columns */
62
uint ref_length; /* Length of record ref. */
63
uint addon_length; /* Length of added packed fields */
64
uint res_length; /* Length of records in final sorted file/buffer */
65
uint keys; /* Max keys / buffer */
66
ha_rows max_rows,examined_rows;
67
TABLE *sort_form; /* For quicker make_sortkey */
68
SORT_FIELD *local_sortorder;
70
SORT_ADDON_FIELD *addon_field; /* Descriptors for companion fields */
74
/* The fields below are used only by Unique class */
76
BUFFPEK_COMPARE_CONTEXT cmp_context;
80
int merge_many_buff(SORTPARAM *param, uchar *sort_buffer,
82
uint *maxbuffer, IO_CACHE *t_file);
83
uint read_to_buffer(IO_CACHE *fromfile,BUFFPEK *buffpek,
85
int merge_buffers(SORTPARAM *param,IO_CACHE *from_file,
86
IO_CACHE *to_file, uchar *sort_buffer,
87
BUFFPEK *lastbuff,BUFFPEK *Fb,
88
BUFFPEK *Tb,int flag);
89
void reuse_freed_buff(QUEUE *queue, BUFFPEK *reuse, uint key_length);