~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/sql_sort.h

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000 MySQL AB
 
2
 
 
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.
 
6
 
 
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.
 
11
 
 
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 */
 
15
 
 
16
/* Defines used by filesort and uniques */
 
17
 
 
18
#define MERGEBUFF               7
 
19
#define MERGEBUFF2              15
 
20
 
 
21
/*
 
22
   The structure SORT_ADDON_FIELD describes a fixed layout
 
23
   for field values appended to sorted values in records to be sorted
 
24
   in the sort buffer.
 
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'.
 
35
*/
 
36
 
 
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 */
 
43
} SORT_ADDON_FIELD;
 
44
 
 
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 */
 
51
} BUFFPEK;
 
52
 
 
53
struct BUFFPEK_COMPARE_CONTEXT
 
54
{
 
55
  qsort_cmp2 key_compare;
 
56
  void *key_compare_arg;
 
57
};
 
58
 
 
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;
 
69
  SORT_FIELD *end;
 
70
  SORT_ADDON_FIELD *addon_field; /* Descriptors for companion fields */
 
71
  uchar *unique_buff;
 
72
  bool not_killable;
 
73
  char* tmp_buffer;
 
74
  /* The fields below are used only by Unique class */
 
75
  qsort2_cmp compare;
 
76
  BUFFPEK_COMPARE_CONTEXT cmp_context;
 
77
} SORTPARAM;
 
78
 
 
79
 
 
80
int merge_many_buff(SORTPARAM *param, uchar *sort_buffer,
 
81
                    BUFFPEK *buffpek,
 
82
                    uint *maxbuffer, IO_CACHE *t_file);
 
83
uint read_to_buffer(IO_CACHE *fromfile,BUFFPEK *buffpek,
 
84
                    uint sort_length);
 
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);