~drizzle-trunk/drizzle/development

390.1.2 by Monty Taylor
Fixed copyright headers in drizzled/
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2008 Sun Microsystems
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; version 2 of the License.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License
16
 *  along with this program; if not, write to the Free Software
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 */
1 by brian
clean slate
19
1122.2.10 by Monty Taylor
Fixed all of the include guards.
20
#ifndef DRIZZLED_SQL_SORT_H
21
#define DRIZZLED_SQL_SORT_H
471 by Monty Taylor
Added header protections.
22
1241.9.46 by Monty Taylor
Removed some more evil.
23
#include <unistd.h>
24
1241.9.23 by Monty Taylor
Removed sql_table.h from server_includes.h.
25
#include "drizzled/base.h"
1241.9.45 by Monty Taylor
Added a header for qsort_cmp.
26
#include "drizzled/qsort_cmp.h"
1241.9.12 by Monty Taylor
Trims more out of server_includes.h.
27
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
28
typedef struct st_sort_field SORT_FIELD;
1241.9.21 by Monty Taylor
Removed sql_string.h from server_includes.h.
29
typedef struct st_io_cache IO_CACHE;
1237.9.4 by Padraig O'Sullivan
Removed the inclusion of drizzled/field.h in the server_includes header file.
30
class Field;
1241.9.30 by Monty Taylor
More cruft gone.
31
class Table;
471 by Monty Taylor
Added header protections.
32
1241.9.45 by Monty Taylor
Added a header for qsort_cmp.
33
1 by brian
clean slate
34
/* Defines used by filesort and uniques */
35
36
#define MERGEBUFF		7
37
#define MERGEBUFF2		15
38
39
/*
40
   The structure SORT_ADDON_FIELD describes a fixed layout
41
   for field values appended to sorted values in records to be sorted
42
   in the sort buffer.
43
   Only fixed layout is supported now.
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
44
   Null bit maps for the appended values is placed before the values
1 by brian
clean slate
45
   themselves. Offsets are from the last sorted field, that is from the
46
   record referefence, which is still last component of sorted records.
47
   It is preserved for backward compatiblility.
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
48
   The structure is used tp store values of the additional fields
1 by brian
clean slate
49
   in the sort buffer. It is used also when these values are read
50
   from a temporary file/buffer. As the reading procedures are beyond the
51
   scope of the 'filesort' code the values have to be retrieved via
52
   the callback function 'unpack_addon_fields'.
53
*/
54
55
typedef struct st_sort_addon_field {  /* Sort addon packed field */
56
  Field *field;          /* Original field */
482 by Brian Aker
Remove uint.
57
  uint32_t   offset;         /* Offset from the last sorted field */
58
  uint32_t   null_offset;    /* Offset to to null bit from the last sorted field */
59
  uint32_t   length;         /* Length in the sort buffer */
206 by Brian Aker
Removed final uint dead types.
60
  uint8_t  null_bit;       /* Null bit mask for the field */
1 by brian
clean slate
61
} SORT_ADDON_FIELD;
62
63
typedef struct st_buffpek {		/* Struktur om sorteringsbuffrarna */
1241.9.45 by Monty Taylor
Added a header for qsort_cmp.
64
  off_t file_pos;			/* Where we are in the sort file */
481 by Brian Aker
Remove all of uchar.
65
  unsigned char *base,*key;			/* key pointers */
1 by brian
clean slate
66
  ha_rows count;			/* Number of rows in table */
1241.9.46 by Monty Taylor
Removed some more evil.
67
  size_t mem_count;			/* numbers of keys in memory */
68
  size_t max_keys;			/* Max keys in buffert */
1 by brian
clean slate
69
} BUFFPEK;
70
71
struct BUFFPEK_COMPARE_CONTEXT
72
{
73
  qsort_cmp2 key_compare;
74
  void *key_compare_arg;
75
};
76
77
typedef struct st_sort_param {
482 by Brian Aker
Remove uint.
78
  uint32_t rec_length;          /* Length of sorted records */
79
  uint32_t sort_length;			/* Length of sorted columns */
80
  uint32_t ref_length;			/* Length of record ref. */
81
  uint32_t addon_length;        /* Length of added packed fields */
82
  uint32_t res_length;          /* Length of records in final sorted file/buffer */
83
  uint32_t keys;				/* Max keys / buffer */
1 by brian
clean slate
84
  ha_rows max_rows,examined_rows;
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
85
  Table *sort_form;			/* For quicker make_sortkey */
1 by brian
clean slate
86
  SORT_FIELD *local_sortorder;
87
  SORT_FIELD *end;
88
  SORT_ADDON_FIELD *addon_field; /* Descriptors for companion fields */
481 by Brian Aker
Remove all of uchar.
89
  unsigned char *unique_buff;
1 by brian
clean slate
90
  bool not_killable;
91
  char* tmp_buffer;
92
  /* The fields below are used only by Unique class */
93
  qsort2_cmp compare;
94
  BUFFPEK_COMPARE_CONTEXT cmp_context;
95
} SORTPARAM;
96
97
481 by Brian Aker
Remove all of uchar.
98
int merge_many_buff(SORTPARAM *param, unsigned char *sort_buffer,
1 by brian
clean slate
99
		    BUFFPEK *buffpek,
482 by Brian Aker
Remove uint.
100
		    uint32_t *maxbuffer, IO_CACHE *t_file);
101
uint32_t read_to_buffer(IO_CACHE *fromfile,BUFFPEK *buffpek,
102
		    uint32_t sort_length);
1 by brian
clean slate
103
int merge_buffers(SORTPARAM *param,IO_CACHE *from_file,
481 by Brian Aker
Remove all of uchar.
104
		  IO_CACHE *to_file, unsigned char *sort_buffer,
1 by brian
clean slate
105
		  BUFFPEK *lastbuff,BUFFPEK *Fb,
106
		  BUFFPEK *Tb,int flag);
471 by Monty Taylor
Added header protections.
107
1122.2.10 by Monty Taylor
Fixed all of the include guards.
108
#endif /* DRIZZLED_SQL_SORT_H */