~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
472 by Monty Taylor
Moved qsort declarations.
20
#ifndef _DRIZZLED_SQL_SORT_H
471 by Monty Taylor
Added header protections.
21
#define _DRIZZLED_SQL_SORT_H
22
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.
23
typedef struct st_sort_field SORT_FIELD;
471 by Monty Taylor
Added header protections.
24
1 by brian
clean slate
25
/* Defines used by filesort and uniques */
26
27
#define MERGEBUFF		7
28
#define MERGEBUFF2		15
29
30
/*
31
   The structure SORT_ADDON_FIELD describes a fixed layout
32
   for field values appended to sorted values in records to be sorted
33
   in the sort buffer.
34
   Only fixed layout is supported now.
35
   Null bit maps for the appended values is placed before the values 
36
   themselves. Offsets are from the last sorted field, that is from the
37
   record referefence, which is still last component of sorted records.
38
   It is preserved for backward compatiblility.
39
   The structure is used tp store values of the additional fields 
40
   in the sort buffer. It is used also when these values are read
41
   from a temporary file/buffer. As the reading procedures are beyond the
42
   scope of the 'filesort' code the values have to be retrieved via
43
   the callback function 'unpack_addon_fields'.
44
*/
45
46
typedef struct st_sort_addon_field {  /* Sort addon packed field */
47
  Field *field;          /* Original field */
482 by Brian Aker
Remove uint.
48
  uint32_t   offset;         /* Offset from the last sorted field */
49
  uint32_t   null_offset;    /* Offset to to null bit from the last sorted field */
50
  uint32_t   length;         /* Length in the sort buffer */
206 by Brian Aker
Removed final uint dead types.
51
  uint8_t  null_bit;       /* Null bit mask for the field */
1 by brian
clean slate
52
} SORT_ADDON_FIELD;
53
54
typedef struct st_buffpek {		/* Struktur om sorteringsbuffrarna */
55
  my_off_t file_pos;			/* Where we are in the sort file */
481 by Brian Aker
Remove all of uchar.
56
  unsigned char *base,*key;			/* key pointers */
1 by brian
clean slate
57
  ha_rows count;			/* Number of rows in table */
58
  ulong mem_count;			/* numbers of keys in memory */
59
  ulong max_keys;			/* Max keys in buffert */
60
} BUFFPEK;
61
62
struct BUFFPEK_COMPARE_CONTEXT
63
{
64
  qsort_cmp2 key_compare;
65
  void *key_compare_arg;
66
};
67
68
typedef struct st_sort_param {
482 by Brian Aker
Remove uint.
69
  uint32_t rec_length;          /* Length of sorted records */
70
  uint32_t sort_length;			/* Length of sorted columns */
71
  uint32_t ref_length;			/* Length of record ref. */
72
  uint32_t addon_length;        /* Length of added packed fields */
73
  uint32_t res_length;          /* Length of records in final sorted file/buffer */
74
  uint32_t keys;				/* Max keys / buffer */
1 by brian
clean slate
75
  ha_rows max_rows,examined_rows;
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
76
  Table *sort_form;			/* For quicker make_sortkey */
1 by brian
clean slate
77
  SORT_FIELD *local_sortorder;
78
  SORT_FIELD *end;
79
  SORT_ADDON_FIELD *addon_field; /* Descriptors for companion fields */
481 by Brian Aker
Remove all of uchar.
80
  unsigned char *unique_buff;
1 by brian
clean slate
81
  bool not_killable;
82
  char* tmp_buffer;
83
  /* The fields below are used only by Unique class */
84
  qsort2_cmp compare;
85
  BUFFPEK_COMPARE_CONTEXT cmp_context;
86
} SORTPARAM;
87
88
481 by Brian Aker
Remove all of uchar.
89
int merge_many_buff(SORTPARAM *param, unsigned char *sort_buffer,
1 by brian
clean slate
90
		    BUFFPEK *buffpek,
482 by Brian Aker
Remove uint.
91
		    uint32_t *maxbuffer, IO_CACHE *t_file);
92
uint32_t read_to_buffer(IO_CACHE *fromfile,BUFFPEK *buffpek,
93
		    uint32_t sort_length);
1 by brian
clean slate
94
int merge_buffers(SORTPARAM *param,IO_CACHE *from_file,
481 by Brian Aker
Remove all of uchar.
95
		  IO_CACHE *to_file, unsigned char *sort_buffer,
1 by brian
clean slate
96
		  BUFFPEK *lastbuff,BUFFPEK *Fb,
97
		  BUFFPEK *Tb,int flag);
482 by Brian Aker
Remove uint.
98
void reuse_freed_buff(QUEUE *queue, BUFFPEK *reuse, uint32_t key_length);
471 by Monty Taylor
Added header protections.
99
100
#endif