~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2000-2006 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
1802.10.2 by Monty Taylor
Update all of the copyright headers to include the correct address.
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
1 by brian
clean slate
15
16
/* This file is included by all internal myisam files */
17
2234 by Brian Aker
Mass removal of ifdef/endif in favor of pragma once.
18
#pragma once
77.1.3 by Monty Taylor
MyISAM cleanups.
19
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
20
#include <config.h>
2041.3.13 by Brian Aker
Merge in changes such that we are strict with error type.
21
1 by brian
clean slate
22
#include "myisam.h"			/* Structs & some defines */
23
#include "myisampack.h"			/* packing of keys */
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
24
#include <drizzled/tree.h>
25
#include <drizzled/internal/my_pthread.h>
1241.9.43 by Monty Taylor
Merged trunk. Also renamed thr_lock. Doh. I hate it when I do both.
26
#include <drizzled/thr_lock.h>
543 by Monty Taylor
Renamed drizzle_common again. Removed sql_common. (empty)
27
#include <drizzled/common.h>
2041.3.13 by Brian Aker
Merge in changes such that we are strict with error type.
28
#include <drizzled/enum.h>
2221.7.4 by Olaf van der Spek
Refactor
29
#include <drizzled/dynamic_array.h>
2241.4.14 by Stewart Smith
remove some includes from my_sys.h and instead only include where needed. This helps reduce the number of files that have to be rebuilt when you change some of the more widely included header files (such as the drizzled::identifier ones)
30
#include <drizzled/error_t.h>
1 by brian
clean slate
31
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
32
#include <assert.h>
33
#include <fcntl.h>
612.2.13 by Monty Taylor
Work on removing global.h from headers that should be installed.
34
#include <string.h>
916.1.32 by Padraig O'Sullivan
Refactoring MyISAM storage engine again based on LIST replacement with
35
#include <list>
612.2.13 by Monty Taylor
Work on removing global.h from headers that should be installed.
36
1703.1.3 by Brian Aker
Replace pthread mutex with boost based one for myisam.
37
#include <boost/thread/mutex.hpp>
38
489.1.6 by Monty Taylor
Removed RAID garbage.
39
#if defined(my_write)
1 by brian
clean slate
40
#undef my_write				/* undef map from my_nosys; We need test-if-disk full */
41
#endif
42
1689.2.22 by Brian Aker
Shuffle out dead crap around keycache.
43
/* Typical key cash */
44
static const uint32_t KEY_CACHE_SIZE= 8*1024*1024;
45
46
/* Default size of a key cache block  */
47
static const uint32_t KEY_CACHE_BLOCK_SIZE= 1024;
48
1 by brian
clean slate
49
typedef struct st_mi_status_info
50
{
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
51
  drizzled::ha_rows records;			/* Rows in table */
52
  drizzled::ha_rows del;				/* Removed rows */
53
  drizzled::internal::my_off_t empty;			/* lost space in datafile */
54
  drizzled::internal::my_off_t key_empty;			/* lost space in indexfile */
55
  drizzled::internal::my_off_t key_file_length;
56
  drizzled::internal::my_off_t data_file_length;
2241.4.37 by Stewart Smith
remove the drizzled::internal namespace prefix from teh typedef for ha_checksum - it's just for myisam now
57
  ha_checksum checksum;
1 by brian
clean slate
58
} MI_STATUS_INFO;
59
60
typedef struct st_mi_state_info
61
{
62
  struct {				/* Fileheader */
481 by Brian Aker
Remove all of uchar.
63
    unsigned char file_version[4];
64
    unsigned char options[2];
65
    unsigned char header_length[2];
66
    unsigned char state_info_length[2];
67
    unsigned char base_info_length[2];
68
    unsigned char base_pos[2];
69
    unsigned char key_parts[2];			/* Key parts */
70
    unsigned char unique_key_parts[2];		/* Key parts + unique parts */
71
    unsigned char keys;				/* number of keys in file */
72
    unsigned char uniques;			/* number of UNIQUE definitions */
73
    unsigned char language;			/* Language for indexes */
74
    unsigned char max_block_size_index;		/* max keyblock size */
75
    unsigned char fulltext_keys;
76
    unsigned char not_used;                     /* To align to 8 */
1 by brian
clean slate
77
  } header;
78
79
  MI_STATUS_INFO state;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
80
  drizzled::ha_rows split;			/* number of split blocks */
81
  drizzled::internal::my_off_t dellink;			/* Link to next removed block */
151 by Brian Aker
Ulonglong to uint64_t
82
  uint64_t auto_increment;
1 by brian
clean slate
83
  ulong process;			/* process that updated table last */
84
  ulong unique;				/* Unique number for this process */
85
  ulong update_count;			/* Updated for each write lock */
86
  ulong status;
87
  ulong *rec_per_key_part;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
88
  drizzled::internal::my_off_t *key_root;			/* Start of key trees */
89
  drizzled::internal::my_off_t *key_del;			/* delete links for trees */
90
  drizzled::internal::my_off_t rec_per_key_rows;		/* Rows when calculating rec_per_key */
1 by brian
clean slate
91
92
  ulong sec_index_changed;		/* Updated when new sec_index */
93
  ulong sec_index_used;			/* which extra index are in use */
151 by Brian Aker
Ulonglong to uint64_t
94
  uint64_t key_map;			/* Which keys are in use */
2241.4.37 by Stewart Smith
remove the drizzled::internal namespace prefix from teh typedef for ha_checksum - it's just for myisam now
95
  ha_checksum checksum;                 /* Table checksum */
1 by brian
clean slate
96
  ulong version;			/* timestamp of create */
97
  time_t create_time;			/* Time when created database */
98
  time_t recover_time;			/* Time for last recover */
99
  time_t check_time;			/* Time for last check */
100
  uint	sortkey;			/* sorted by this key  (not used) */
482 by Brian Aker
Remove uint.
101
  uint32_t open_count;
206 by Brian Aker
Removed final uint dead types.
102
  uint8_t changed;			/* Changed since myisamchk */
1 by brian
clean slate
103
104
  /* the following isn't saved on disk */
482 by Brian Aker
Remove uint.
105
  uint32_t state_diff_length;		/* Should be 0 */
1 by brian
clean slate
106
  uint	state_length;			/* Length of state header in file */
107
  ulong *key_info;
108
} MI_STATE_INFO;
109
110
#define MI_STATE_INFO_SIZE	(24+14*8+7*4+2*2+8)
111
#define MI_STATE_KEY_SIZE	8
112
#define MI_STATE_KEYBLOCK_SIZE  8
113
#define MI_STATE_KEYSEG_SIZE	4
114
#define MI_STATE_EXTRA_SIZE ((MI_MAX_KEY+MI_MAX_KEY_BLOCK_SIZE)*MI_STATE_KEY_SIZE + MI_MAX_KEY*MI_MAX_KEY_SEG*MI_STATE_KEYSEG_SIZE)
115
#define MI_KEYDEF_SIZE		(2+ 5*2)
116
#define MI_UNIQUEDEF_SIZE	(2+1+1)
117
#define HA_KEYSEG_SIZE		(6+ 2*2 + 4*2)
118
#define MI_COLUMNDEF_SIZE	(2*3+1)
119
#define MI_BASE_INFO_SIZE	(5*8 + 8*4 + 4 + 4*2 + 16)
120
#define MI_INDEX_BLOCK_MARGIN	16	/* Safety margin for .MYI tables */
121
122
typedef struct st_mi_base_info
123
{
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
124
  drizzled::internal::my_off_t keystart;			/* Start of keys */
125
  drizzled::internal::my_off_t max_data_file_length;
126
  drizzled::internal::my_off_t max_key_file_length;
127
  drizzled::internal::my_off_t margin_key_file_length;
128
  drizzled::ha_rows records,reloc;		/* Create information */
1 by brian
clean slate
129
  ulong mean_row_length;		/* Create information */
130
  ulong reclength;			/* length of unpacked record */
131
  ulong pack_reclength;			/* Length of full packed rec. */
132
  ulong min_pack_length;
133
  ulong max_pack_length;		/* Max possibly length of packed rec.*/
134
  ulong min_block_length;
135
  ulong fields,				/* fields in table */
136
       pack_fields;			/* packed fields in table */
482 by Brian Aker
Remove uint.
137
  uint32_t rec_reflength;			/* = 2-8 */
138
  uint32_t key_reflength;			/* = 2-8 */
139
  uint32_t keys;				/* same as in state.header */
140
  uint32_t auto_key;			/* Which key-1 is a auto key */
141
  uint32_t blobs;				/* Number of blobs */
142
  uint32_t pack_bits;			/* Length of packed bits */
143
  uint32_t max_key_block_length;		/* Max block length */
144
  uint32_t max_key_length;			/* Max key length */
1 by brian
clean slate
145
  /* Extra allocation when using dynamic record format */
482 by Brian Aker
Remove uint.
146
  uint32_t extra_alloc_bytes;
147
  uint32_t extra_alloc_procent;
1 by brian
clean slate
148
  /* Info about raid */
482 by Brian Aker
Remove uint.
149
  uint32_t raid_type,raid_chunks;
489.1.6 by Monty Taylor
Removed RAID garbage.
150
  uint32_t raid_chunksize;
1 by brian
clean slate
151
  /* The following are from the header */
482 by Brian Aker
Remove uint.
152
  uint32_t key_parts,all_key_parts;
1 by brian
clean slate
153
} MI_BASE_INFO;
154
155
156
	/* Structs used intern in database */
157
158
typedef struct st_mi_blob		/* Info of record */
159
{
160
  ulong offset;				/* Offset to blob in record */
482 by Brian Aker
Remove uint.
161
  uint32_t pack_length;			/* Type of packed length */
1 by brian
clean slate
162
  ulong length;				/* Calc:ed for each record */
163
} MI_BLOB;
164
165
166
typedef struct st_mi_isam_pack {
167
  ulong header_length;
482 by Brian Aker
Remove uint.
168
  uint32_t ref_length;
481 by Brian Aker
Remove all of uchar.
169
  unsigned char version;
1 by brian
clean slate
170
} MI_PACK;
171
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
172
#define MAX_NONMAPPED_INSERTS 1000
1 by brian
clean slate
173
174
typedef struct st_mi_isam_share {	/* Shared between opens */
175
  MI_STATE_INFO state;
176
  MI_BASE_INFO base;
177
  MI_KEYDEF  ft2_keyinfo;		/* Second-level ft-key definition */
178
  MI_KEYDEF  *keyinfo;			/* Key definitions */
179
  MI_UNIQUEDEF *uniqueinfo;		/* unique definitions */
180
  HA_KEYSEG *keyparts;			/* key part info */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
181
  drizzled::MI_COLUMNDEF *rec;			/* Pointer to field information */
1 by brian
clean slate
182
  MI_PACK    pack;			/* Data about packed records */
183
  MI_BLOB    *blobs;			/* Pointer to blobs */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
184
  std::list<drizzled::Session *> *in_use;         /* List of threads using this table */
1 by brian
clean slate
185
  char  *unique_file_name;		/* realpath() of index file */
186
  char  *data_file_name,		/* Resolved path names from symlinks */
187
        *index_file_name;
481 by Brian Aker
Remove all of uchar.
188
  unsigned char *file_map;			/* mem-map of file if possible */
1689.2.15 by Brian Aker
Encapsulate the key cache object in myisam.
189
private:
1689.2.16 by Brian Aker
This places keycache directly into the table (ie it is now mapped 1=1).
190
  drizzled::KEY_CACHE key_cache;			/* ref to the current key cache */
1689.2.15 by Brian Aker
Encapsulate the key cache object in myisam.
191
public:
192
  drizzled::KEY_CACHE *getKeyCache()
193
  {
1689.2.16 by Brian Aker
This places keycache directly into the table (ie it is now mapped 1=1).
194
    return &key_cache;
1689.2.15 by Brian Aker
Encapsulate the key cache object in myisam.
195
  }
196
1689.2.16 by Brian Aker
This places keycache directly into the table (ie it is now mapped 1=1).
197
  void setKeyCache();
1689.2.15 by Brian Aker
Encapsulate the key cache object in myisam.
198
1 by brian
clean slate
199
  MI_DECODE_TREE *decode_trees;
206 by Brian Aker
Removed final uint dead types.
200
  uint16_t *decode_tables;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
201
  int (*read_record)(struct st_myisam_info*, drizzled::internal::my_off_t, unsigned char*);
481 by Brian Aker
Remove all of uchar.
202
  int (*write_record)(struct st_myisam_info*, const unsigned char*);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
203
  int (*update_record)(struct st_myisam_info*, drizzled::internal::my_off_t, const unsigned char*);
1 by brian
clean slate
204
  int (*delete_record)(struct st_myisam_info*);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
205
  int (*read_rnd)(struct st_myisam_info*, unsigned char*, drizzled::internal::my_off_t, bool);
481 by Brian Aker
Remove all of uchar.
206
  int (*compare_record)(struct st_myisam_info*, const unsigned char *);
1 by brian
clean slate
207
  /* Function to use for a row checksum. */
2241.4.37 by Stewart Smith
remove the drizzled::internal namespace prefix from teh typedef for ha_checksum - it's just for myisam now
208
  ha_checksum (*calc_checksum)(struct st_myisam_info*, const unsigned char *);
1 by brian
clean slate
209
  int (*compare_unique)(struct st_myisam_info*, MI_UNIQUEDEF *,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
210
			const unsigned char *record, drizzled::internal::my_off_t pos);
211
  size_t (*file_read)(MI_INFO *, unsigned char *, size_t, drizzled::internal::my_off_t, drizzled::myf);
212
  size_t (*file_write)(MI_INFO *, const unsigned char *, size_t, drizzled::internal::my_off_t, drizzled::myf);
1 by brian
clean slate
213
  ulong this_process;			/* processid */
214
  ulong last_process;			/* For table-change-check */
215
  ulong last_version;			/* Version on start */
1816.2.4 by Monty Taylor
Cleaned up a bunch more warnings.
216
  uint64_t options;			/* Options used */
1 by brian
clean slate
217
  ulong min_pack_length;		/* Theese are used by packed data */
218
  ulong max_pack_length;
219
  ulong state_diff_length;
220
  uint	rec_reflength;			/* rec_reflength in use now */
482 by Brian Aker
Remove uint.
221
  uint32_t  unique_name_length;
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
222
  int	kfile;				/* Shared keyfile */
223
  int	data_file;			/* Shared data file */
1 by brian
clean slate
224
  int	mode;				/* mode of file on open */
225
  uint	reopen;				/* How many times reopened */
226
  uint	w_locks,r_locks,tot_locks;	/* Number of read/write locks */
227
  uint	blocksize;			/* blocksize of keyfile */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
228
  drizzled::myf write_flag;
229
  enum drizzled::data_file_type data_file_type;
1 by brian
clean slate
230
  /* Below flag is needed to make log tables work with concurrent insert */
281 by Brian Aker
Converted myisam away from my_bool
231
  bool is_log_table;
1 by brian
clean slate
232
281 by Brian Aker
Converted myisam away from my_bool
233
  bool  changed,			/* If changed since lock */
1 by brian
clean slate
234
    global_changed,			/* If changed since open */
235
    not_flushed,
236
    temporary,delay_key_write,
237
    concurrent_insert;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
238
  drizzled::internal::my_off_t mmaped_length;
482 by Brian Aker
Remove uint.
239
  uint32_t     nonmmaped_inserts;           /* counter of writing in non-mmaped
1 by brian
clean slate
240
                                           area */
241
} MYISAM_SHARE;
242
243
482 by Brian Aker
Remove uint.
244
typedef uint32_t mi_bit_type;
1 by brian
clean slate
245
246
typedef struct st_mi_bit_buff {		/* Used for packing of record */
247
  mi_bit_type current_byte;
482 by Brian Aker
Remove uint.
248
  uint32_t bits;
481 by Brian Aker
Remove all of uchar.
249
  unsigned char *pos,*end,*blob_pos,*blob_end;
482 by Brian Aker
Remove uint.
250
  uint32_t error;
1 by brian
clean slate
251
} MI_BIT_BUFF;
252
253
281 by Brian Aker
Converted myisam away from my_bool
254
typedef bool (*index_cond_func_t)(void *param);
1 by brian
clean slate
255
256
struct st_myisam_info {
257
  MYISAM_SHARE *s;			/* Shared between open:s */
258
  MI_STATUS_INFO *state,save_state;
259
  MI_BLOB     *blobs;			/* Pointer to blobs */
260
  MI_BIT_BUFF  bit_buff;
261
  /* accumulate indexfile changes between write's */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
262
  drizzled::TREE	        *bulk_insert;
263
  drizzled::Session *in_use;                      /* Thread using this table          */
1 by brian
clean slate
264
  char *filename;			/* parameter to open filename       */
481 by Brian Aker
Remove all of uchar.
265
  unsigned char *buff,				/* Temp area for key                */
1 by brian
clean slate
266
	*lastkey,*lastkey2;		/* Last used search key             */
481 by Brian Aker
Remove all of uchar.
267
  unsigned char *first_mbr_key;			/* Searhed spatial key              */
268
  unsigned char	*rec_buff;			/* Tempbuff for recordpack          */
269
  unsigned char *int_keypos,			/* Save position for next/previous  */
1 by brian
clean slate
270
        *int_maxpos;			/*  -""-  */
482 by Brian Aker
Remove uint.
271
  uint32_t  int_nod_flag;			/*  -""-  */
205 by Brian Aker
uint32 -> uin32_t
272
  uint32_t int_keytree_version;		/*  -""-  */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
273
  int (*read_record)(struct st_myisam_info*, drizzled::internal::my_off_t, unsigned char*);
1 by brian
clean slate
274
  ulong this_unique;			/* uniq filenumber or thread */
275
  ulong last_unique;			/* last unique number */
276
  ulong this_loop;			/* counter for this open */
277
  ulong last_loop;			/* last used counter */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
278
  drizzled::internal::my_off_t lastpos,			/* Last record position */
1 by brian
clean slate
279
	nextpos;			/* Position to next record */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
280
  drizzled::internal::my_off_t save_lastpos;
281
  drizzled::internal::my_off_t pos;				/* Intern variable */
282
  drizzled::internal::my_off_t last_keypage;		/* Last key page read */
283
  drizzled::internal::my_off_t last_search_keypage;		/* Last keypage when searching */
284
  drizzled::internal::my_off_t dupp_key_pos;
2241.4.37 by Stewart Smith
remove the drizzled::internal namespace prefix from teh typedef for ha_checksum - it's just for myisam now
285
  ha_checksum checksum;                 /* Temp storage for row checksum */
1 by brian
clean slate
286
  /* QQ: the folloing two xxx_length fields should be removed,
287
     as they are not compatible with parallel repair */
288
  ulong packed_length,blob_length;	/* Length of found, packed record */
289
  int  dfile;				/* The datafile */
482 by Brian Aker
Remove uint.
290
  uint32_t opt_flag;			/* Optim. for space/speed */
291
  uint32_t update;				/* If file changed since open */
1 by brian
clean slate
292
  int	lastinx;			/* Last used index */
293
  uint	lastkey_length;			/* Length of key in lastkey */
294
  uint	last_rkey_length;		/* Last length in mi_rkey() */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
295
  enum drizzled::ha_rkey_function last_key_func;  /* CONTAIN, OVERLAP, etc */
482 by Brian Aker
Remove uint.
296
  uint32_t  save_lastkey_length;
297
  uint32_t  pack_key_length;                /* For MYISAMMRG */
206 by Brian Aker
Removed final uint dead types.
298
  uint16_t last_used_keyseg;              /* For MyISAMMRG */
1 by brian
clean slate
299
  int	errkey;				/* Got last error on this key */
300
  int   lock_type;			/* How database was locked */
301
  int   tmp_lock_type;			/* When locked by readinfo */
302
  uint	data_changed;			/* Somebody has changed data */
303
  uint	save_update;			/* When using KEY_READ */
304
  int	save_lastinx;
2296.1.1 by Mark Atwood
Merge in Fixes of Brian's IOCACHE.
305
  drizzled::internal::io_cache_st rec_cache;			/* When cacheing records */
482 by Brian Aker
Remove uint.
306
  uint32_t  preload_buff_size;              /* When preloading indexes */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
307
  drizzled::myf lock_wait;			/* is 0 or MY_DONT_WAIT */
281 by Brian Aker
Converted myisam away from my_bool
308
  bool was_locked;			/* Was locked in panic */
309
  bool append_insert_at_end;		/* Set if concurrent insert */
310
  bool quick_mode;
311
  bool page_changed;		/* If info->buff can't be used for rnext */
312
  bool buff_used;		/* If info->buff has to be reread for rnext */
313
  bool once_flags;           /* For MYISAMMRG */
1 by brian
clean slate
314
315
  index_cond_func_t index_cond_func;   /* Index condition function */
316
  void *index_cond_func_arg;           /* parameter for the func */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
317
  drizzled::THR_LOCK_DATA lock;
481 by Brian Aker
Remove all of uchar.
318
  unsigned char  *rtree_recursion_state;	/* For RTREE */
1 by brian
clean slate
319
  int     rtree_recursion_depth;
320
};
321
322
typedef struct st_buffpek {
1241.9.45 by Monty Taylor
Added a header for qsort_cmp.
323
  off_t file_pos;                    /* Where we are in the sort file */
481 by Brian Aker
Remove all of uchar.
324
  unsigned char *base,*key;                     /* Key pointers */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
325
  drizzled::ha_rows count;                        /* Number of rows in table */
1 by brian
clean slate
326
  ulong mem_count;                      /* numbers of keys in memory */
327
  ulong max_keys;                       /* Max keys in buffert */
328
} BUFFPEK;
329
330
typedef struct st_mi_sort_param
331
{
332
  pthread_t  thr;
2296.1.1 by Mark Atwood
Merge in Fixes of Brian's IOCACHE.
333
  drizzled::internal::io_cache_st read_cache, tempfile, tempfile_for_exceptions;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
334
  drizzled::DYNAMIC_ARRAY buffpek;
1 by brian
clean slate
335
  MI_BIT_BUFF   bit_buff;               /* For parallel repair of packrec. */
336
337
  /*
338
    The next two are used to collect statistics, see update_key_parts for
339
    description.
340
  */
151 by Brian Aker
Ulonglong to uint64_t
341
  uint64_t unique[MI_MAX_KEY_SEG+1];
342
  uint64_t notnull[MI_MAX_KEY_SEG+1];
1 by brian
clean slate
343
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
344
  drizzled::internal::my_off_t pos,max_pos,filepos,start_recpos;
482 by Brian Aker
Remove uint.
345
  uint32_t key, key_length,real_key_length,sortbuff_size;
346
  uint32_t maxbuffers, keys, find_length, sort_keys_length;
281 by Brian Aker
Converted myisam away from my_bool
347
  bool fix_datafile, master;
348
  bool calc_checksum;                /* calculate table checksum */
1 by brian
clean slate
349
  MI_KEYDEF *keyinfo;
350
  HA_KEYSEG *seg;
351
  SORT_INFO *sort_info;
481 by Brian Aker
Remove all of uchar.
352
  unsigned char **sort_keys;
353
  unsigned char *rec_buff;
1 by brian
clean slate
354
  void *wordlist, *wordptr;
1253.1.3 by Monty Taylor
MEM_ROOT == memory::Root
355
  drizzled::memory::Root wordroot;
481 by Brian Aker
Remove all of uchar.
356
  unsigned char *record;
1 by brian
clean slate
357
  int (*key_cmp)(struct st_mi_sort_param *, const void *, const void *);
358
  int (*key_read)(struct st_mi_sort_param *,void *);
359
  int (*key_write)(struct st_mi_sort_param *, const void *);
360
  void (*lock_in_memory)(MI_CHECK *);
481 by Brian Aker
Remove all of uchar.
361
  int (*write_keys)(struct st_mi_sort_param *, register unsigned char **,
2296.1.1 by Mark Atwood
Merge in Fixes of Brian's IOCACHE.
362
                     uint32_t , struct st_buffpek *, drizzled::internal::io_cache_st *);
363
  unsigned int (*read_to_buffer)(drizzled::internal::io_cache_st *,struct st_buffpek *, uint);
364
  int (*write_key)(struct st_mi_sort_param *, drizzled::internal::io_cache_st *,unsigned char *,
1 by brian
clean slate
365
                       uint, uint);
366
} MI_SORT_PARAM;
367
368
	/* Some defines used by isam-funktions */
369
370
#define USE_WHOLE_KEY	MI_MAX_KEY_BUFF*2 /* Use whole key in _mi_search() */
371
#define F_EXTRA_LCK	-1
372
373
	/* bits in opt_flag */
374
#define MEMMAP_USED	32
375
#define REMEMBER_OLD_POS 64
376
377
#define WRITEINFO_UPDATE_KEYFILE	1
378
#define WRITEINFO_NO_UNLOCK		2
379
380
        /* once_flags */
381
#define USE_PACKED_KEYS         1
382
#define RRND_PRESERVE_LASTINX   2
383
384
	/* bits in state.changed */
385
386
#define STATE_CHANGED		1
387
#define STATE_CRASHED		2
388
#define STATE_CRASHED_ON_REPAIR 4
389
#define STATE_NOT_ANALYZED	8
390
#define STATE_NOT_OPTIMIZED_KEYS 16
391
#define STATE_NOT_SORTED_PAGES	32
392
393
	/* options to mi_read_cache */
394
395
#define READING_NEXT	1
396
#define READING_HEADER	2
397
51.1.127 by Monty Taylor
Fixed the _mi_report_crashed warning (and a couple of others)
398
1 by brian
clean slate
399
#define mi_getint(x)	((uint) mi_uint2korr(x) & 32767)
206 by Brian Aker
Removed final uint dead types.
400
#define mi_putint(x,y,nod) { uint16_t boh=(nod ? (uint16_t) 32768 : 0) + (uint16_t) (y);\
1 by brian
clean slate
401
			  mi_int2store(x,boh); }
402
#define mi_test_if_nod(x) (x[0] & 128 ? info->s->base.key_reflength : 0)
403
#define mi_report_crashed(A, B) _mi_report_crashed((A), (B), __FILE__, __LINE__)
404
#define mi_mark_crashed(x) do{(x)->s->state.changed|= STATE_CRASHED; \
405
                              mi_report_crashed((x), 0); \
406
                           }while(0)
407
#define mi_mark_crashed_on_repair(x) do{(x)->s->state.changed|= \
408
                                        STATE_CRASHED|STATE_CRASHED_ON_REPAIR; \
409
                                        (x)->update|= HA_STATE_CHANGED; \
410
                                     }while(0)
411
#define mi_is_crashed(x) ((x)->s->state.changed & STATE_CRASHED)
412
#define mi_is_crashed_on_repair(x) ((x)->s->state.changed & STATE_CRASHED_ON_REPAIR)
413
#define mi_print_error(SHARE, ERRNO)                     \
414
        mi_report_error((ERRNO), (SHARE)->index_file_name)
415
416
/* Functions to store length of space packed keys, VARCHAR or BLOB keys */
417
418
#define store_key_length(key,length) \
419
{ if ((length) < 255) \
420
  { *(key)=(length); } \
421
  else \
422
  { *(key)=255; mi_int2store((key)+1,(length)); } \
423
}
424
425
#define get_key_full_length(length,key) \
481 by Brian Aker
Remove all of uchar.
426
{ if ((unsigned char) *(key) != 255) \
427
    length= ((uint) (unsigned char) *((key)++))+1; \
1 by brian
clean slate
428
  else \
429
  { length=mi_uint2korr((key)+1)+3; (key)+=3; } \
430
}
431
432
#define get_key_full_length_rdonly(length,key) \
481 by Brian Aker
Remove all of uchar.
433
{ if ((unsigned char) *(key) != 255) \
434
    length= ((uint) (unsigned char) *((key)))+1; \
1 by brian
clean slate
435
  else \
436
  { length=mi_uint2korr((key)+1)+3; } \
437
}
438
439
#define get_pack_length(length) ((length) >= 255 ? 3 : 1)
440
441
#define MI_MIN_BLOCK_LENGTH	20	/* Because of delete-link */
442
#define MI_EXTEND_BLOCK_LENGTH	20	/* Don't use to small record-blocks */
443
#define MI_SPLIT_LENGTH	((MI_EXTEND_BLOCK_LENGTH+4)*2)
444
#define MI_MAX_DYN_BLOCK_HEADER	20	/* Max prefix of record-block */
445
#define MI_BLOCK_INFO_HEADER_LENGTH 20
446
#define MI_DYN_DELETE_BLOCK_HEADER 20	/* length of delete-block-header */
447
#define MI_DYN_MAX_BLOCK_LENGTH	((1L << 24)-4L)
448
#define MI_DYN_MAX_ROW_LENGTH	(MI_DYN_MAX_BLOCK_LENGTH - MI_SPLIT_LENGTH)
449
#define MI_DYN_ALIGN_SIZE	4	/* Align blocks on this */
450
#define MI_MAX_DYN_HEADER_BYTE	13	/* max header byte for dynamic rows */
451
#define MI_MAX_BLOCK_LENGTH	((((ulong) 1 << 24)-1) & (~ (ulong) (MI_DYN_ALIGN_SIZE-1)))
205 by Brian Aker
uint32 -> uin32_t
452
#define MI_REC_BUFF_OFFSET      ALIGN_SIZE(MI_DYN_DELETE_BLOCK_HEADER+sizeof(uint32_t))
1 by brian
clean slate
453
454
#define MEMMAP_EXTRA_MARGIN	7	/* Write this as a suffix for file */
455
456
#define PACK_TYPE_SELECTED	1	/* Bits in field->pack_type */
457
#define PACK_TYPE_SPACE_FIELDS	2
458
#define PACK_TYPE_ZERO_FILL	4
459
#define MI_FOUND_WRONG_KEY 32738	/* Impossible value from ha_key_cmp */
460
461
#define MI_MAX_KEY_BLOCK_SIZE	(MI_MAX_KEY_BLOCK_LENGTH/MI_MIN_KEY_BLOCK_LENGTH)
462
#define MI_BLOCK_SIZE(key_length,data_pointer,key_pointer,block_size) (((((key_length)+(data_pointer)+(key_pointer))*4+(key_pointer)+2)/(block_size)+1)*(block_size))
463
#define MI_MAX_KEYPTR_SIZE	5        /* For calculating block lengths */
464
#define MI_MIN_KEYBLOCK_LENGTH	50         /* When to split delete blocks */
465
466
#define MI_MIN_SIZE_BULK_INSERT_TREE 16384             /* this is per key */
467
#define MI_MIN_ROWS_TO_USE_BULK_INSERT 100
468
#define MI_MIN_ROWS_TO_DISABLE_INDEXES 100
469
#define MI_MIN_ROWS_TO_USE_WRITE_CACHE 10
470
471
/* The UNIQUE check is done with a hashed long key */
472
473
#define MI_UNIQUE_HASH_TYPE	HA_KEYTYPE_ULONG_INT
474
#define mi_unique_store(A,B)    mi_int4store((A),(B))
475
1703.1.3 by Brian Aker
Replace pthread mutex with boost based one for myisam.
476
extern boost::mutex THR_LOCK_myisam;
1 by brian
clean slate
477
478
	/* Some extern variables */
479
916.1.32 by Padraig O'Sullivan
Refactoring MyISAM storage engine again based on LIST replacement with
480
extern std::list<MI_INFO *> myisam_open_list;
481 by Brian Aker
Remove all of uchar.
481
extern unsigned char  myisam_file_magic[], myisam_pack_file_magic[];
482 by Brian Aker
Remove uint.
482
extern uint32_t  myisam_read_vec[], myisam_readnext_vec[];
483
extern uint32_t myisam_quick_table_bits;
1 by brian
clean slate
484
extern ulong myisam_pid;
485
486
	/* This is used by _mi_calc_xxx_key_length och _mi_store_key */
487
488
typedef struct st_mi_s_param
489
{
490
  uint	ref_length,key_length,
491
	n_ref_length,
492
	n_length,
493
	totlength,
494
	part_of_prev_key,prev_length,pack_marker;
481 by Brian Aker
Remove all of uchar.
495
  unsigned char *key, *prev_key,*next_key_pos;
281 by Brian Aker
Converted myisam away from my_bool
496
  bool store_not_null;
1 by brian
clean slate
497
} MI_KEY_PARAM;
498
499
	/* Prototypes for intern functions */
500
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
501
extern int _mi_read_dynamic_record(MI_INFO *info,drizzled::internal::my_off_t filepos,unsigned char *buf);
481 by Brian Aker
Remove all of uchar.
502
extern int _mi_write_dynamic_record(MI_INFO*, const unsigned char*);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
503
extern int _mi_update_dynamic_record(MI_INFO*, drizzled::internal::my_off_t, const unsigned char*);
1 by brian
clean slate
504
extern int _mi_delete_dynamic_record(MI_INFO *info);
481 by Brian Aker
Remove all of uchar.
505
extern int _mi_cmp_dynamic_record(MI_INFO *info,const unsigned char *record);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
506
extern int _mi_read_rnd_dynamic_record(MI_INFO *, unsigned char *,drizzled::internal::my_off_t, bool);
481 by Brian Aker
Remove all of uchar.
507
extern int _mi_write_blob_record(MI_INFO*, const unsigned char*);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
508
extern int _mi_update_blob_record(MI_INFO*, drizzled::internal::my_off_t, const unsigned char*);
509
extern int _mi_read_static_record(MI_INFO *info, drizzled::internal::my_off_t filepos,unsigned char *buf);
481 by Brian Aker
Remove all of uchar.
510
extern int _mi_write_static_record(MI_INFO*, const unsigned char*);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
511
extern int _mi_update_static_record(MI_INFO*, drizzled::internal::my_off_t, const unsigned char*);
1 by brian
clean slate
512
extern int _mi_delete_static_record(MI_INFO *info);
481 by Brian Aker
Remove all of uchar.
513
extern int _mi_cmp_static_record(MI_INFO *info,const unsigned char *record);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
514
extern int _mi_read_rnd_static_record(MI_INFO*, unsigned char *,drizzled::internal::my_off_t, bool);
482 by Brian Aker
Remove uint.
515
extern int _mi_ck_write(MI_INFO *info,uint32_t keynr,unsigned char *key,uint32_t length);
1 by brian
clean slate
516
extern int _mi_ck_real_write_btree(MI_INFO *info, MI_KEYDEF *keyinfo,
482 by Brian Aker
Remove uint.
517
                                   unsigned char *key, uint32_t key_length,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
518
                                   drizzled::internal::my_off_t *root, uint32_t comp_flag);
519
extern int _mi_enlarge_root(MI_INFO *info,MI_KEYDEF *keyinfo,unsigned char *key, drizzled::internal::my_off_t *root);
481 by Brian Aker
Remove all of uchar.
520
extern int _mi_insert(MI_INFO *info,MI_KEYDEF *keyinfo,unsigned char *key,
521
		      unsigned char *anc_buff,unsigned char *key_pos,unsigned char *key_buff,
522
		      unsigned char *father_buff, unsigned char *father_keypos,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
523
		      drizzled::internal::my_off_t father_page, bool insert_last);
481 by Brian Aker
Remove all of uchar.
524
extern int _mi_split_page(MI_INFO *info,MI_KEYDEF *keyinfo,unsigned char *key,
525
			  unsigned char *buff,unsigned char *key_buff, bool insert_last);
482 by Brian Aker
Remove uint.
526
extern unsigned char *_mi_find_half_pos(uint32_t nod_flag,MI_KEYDEF *keyinfo,unsigned char *page,
527
				unsigned char *key,uint32_t *return_key_length,
481 by Brian Aker
Remove all of uchar.
528
				unsigned char **after_key);
482 by Brian Aker
Remove uint.
529
extern int _mi_calc_static_key_length(MI_KEYDEF *keyinfo,uint32_t nod_flag,
481 by Brian Aker
Remove all of uchar.
530
				      unsigned char *key_pos, unsigned char *org_key,
531
				      unsigned char *key_buff,
532
				      unsigned char *key, MI_KEY_PARAM *s_temp);
482 by Brian Aker
Remove uint.
533
extern int _mi_calc_var_key_length(MI_KEYDEF *keyinfo,uint32_t nod_flag,
481 by Brian Aker
Remove all of uchar.
534
				   unsigned char *key_pos, unsigned char *org_key,
535
				   unsigned char *key_buff,
536
				   unsigned char *key, MI_KEY_PARAM *s_temp);
482 by Brian Aker
Remove uint.
537
extern int _mi_calc_var_pack_key_length(MI_KEYDEF *keyinfo,uint32_t nod_flag,
481 by Brian Aker
Remove all of uchar.
538
					unsigned char *key_pos, unsigned char *org_key,
539
					unsigned char *prev_key,
540
					unsigned char *key, MI_KEY_PARAM *s_temp);
482 by Brian Aker
Remove uint.
541
extern int _mi_calc_bin_pack_key_length(MI_KEYDEF *keyinfo,uint32_t nod_flag,
481 by Brian Aker
Remove all of uchar.
542
					unsigned char *key_pos,unsigned char *org_key,
543
					unsigned char *prev_key,
544
					unsigned char *key, MI_KEY_PARAM *s_temp);
545
void _mi_store_static_key(MI_KEYDEF *keyinfo,  unsigned char *key_pos,
1 by brian
clean slate
546
			   MI_KEY_PARAM *s_temp);
481 by Brian Aker
Remove all of uchar.
547
void _mi_store_var_pack_key(MI_KEYDEF *keyinfo,  unsigned char *key_pos,
1 by brian
clean slate
548
			     MI_KEY_PARAM *s_temp);
549
#ifdef NOT_USED
481 by Brian Aker
Remove all of uchar.
550
void _mi_store_pack_key(MI_KEYDEF *keyinfo,  unsigned char *key_pos,
1 by brian
clean slate
551
			 MI_KEY_PARAM *s_temp);
552
#endif
481 by Brian Aker
Remove all of uchar.
553
void _mi_store_bin_pack_key(MI_KEYDEF *keyinfo,  unsigned char *key_pos,
1 by brian
clean slate
554
			    MI_KEY_PARAM *s_temp);
555
482 by Brian Aker
Remove uint.
556
extern int _mi_ck_delete(MI_INFO *info,uint32_t keynr,unsigned char *key,uint32_t key_length);
598.1.1 by Super-User
Fixed solaris build crap.
557
int _mi_readinfo(MI_INFO *info,int lock_flag,int check_keybuffer);
482 by Brian Aker
Remove uint.
558
extern int _mi_writeinfo(MI_INFO *info,uint32_t options);
1 by brian
clean slate
559
extern int _mi_test_if_changed(MI_INFO *info);
560
extern int _mi_mark_file_changed(MI_INFO *info);
561
extern int _mi_decrement_open_count(MI_INFO *info);
562
extern int _mi_check_index(MI_INFO *info,int inx);
482 by Brian Aker
Remove uint.
563
extern int _mi_search(MI_INFO *info,MI_KEYDEF *keyinfo,unsigned char *key,uint32_t key_len,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
564
		      uint32_t nextflag,drizzled::internal::my_off_t pos);
1 by brian
clean slate
565
extern int _mi_bin_search(struct st_myisam_info *info,MI_KEYDEF *keyinfo,
482 by Brian Aker
Remove uint.
566
			  unsigned char *page,unsigned char *key,uint32_t key_len,uint32_t comp_flag,
481 by Brian Aker
Remove all of uchar.
567
			  unsigned char * *ret_pos,unsigned char *buff, bool *was_last_key);
568
extern int _mi_seq_search(MI_INFO *info,MI_KEYDEF *keyinfo,unsigned char *page,
482 by Brian Aker
Remove uint.
569
			  unsigned char *key,uint32_t key_len,uint32_t comp_flag,
481 by Brian Aker
Remove all of uchar.
570
			  unsigned char **ret_pos,unsigned char *buff, bool *was_last_key);
571
extern int _mi_prefix_search(MI_INFO *info,MI_KEYDEF *keyinfo,unsigned char *page,
482 by Brian Aker
Remove uint.
572
			  unsigned char *key,uint32_t key_len,uint32_t comp_flag,
481 by Brian Aker
Remove all of uchar.
573
			  unsigned char **ret_pos,unsigned char *buff, bool *was_last_key);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
574
extern drizzled::internal::my_off_t _mi_kpos(uint32_t nod_flag,unsigned char *after_key);
575
extern void _mi_kpointer(MI_INFO *info,unsigned char *buff,drizzled::internal::my_off_t pos);
576
extern drizzled::internal::my_off_t _mi_dpos(MI_INFO *info, uint32_t nod_flag,unsigned char *after_key);
577
extern drizzled::internal::my_off_t _mi_rec_pos(MYISAM_SHARE *info, unsigned char *ptr);
578
void _mi_dpointer(MI_INFO *info, unsigned char *buff,drizzled::internal::my_off_t pos);
482 by Brian Aker
Remove uint.
579
extern uint32_t _mi_get_static_key(MI_KEYDEF *keyinfo,uint32_t nod_flag,unsigned char * *page,
481 by Brian Aker
Remove all of uchar.
580
			       unsigned char *key);
482 by Brian Aker
Remove uint.
581
extern uint32_t _mi_get_pack_key(MI_KEYDEF *keyinfo,uint32_t nod_flag,unsigned char * *page,
481 by Brian Aker
Remove all of uchar.
582
			     unsigned char *key);
482 by Brian Aker
Remove uint.
583
extern uint32_t _mi_get_binary_pack_key(MI_KEYDEF *keyinfo, uint32_t nod_flag,
481 by Brian Aker
Remove all of uchar.
584
				    unsigned char **page_pos, unsigned char *key);
585
extern unsigned char *_mi_get_last_key(MI_INFO *info,MI_KEYDEF *keyinfo,unsigned char *keypos,
586
			       unsigned char *lastkey,unsigned char *endpos,
482 by Brian Aker
Remove uint.
587
			       uint32_t *return_key_length);
481 by Brian Aker
Remove all of uchar.
588
extern unsigned char *_mi_get_key(MI_INFO *info, MI_KEYDEF *keyinfo, unsigned char *page,
482 by Brian Aker
Remove uint.
589
			  unsigned char *key, unsigned char *keypos, uint32_t *return_key_length);
590
extern uint32_t _mi_keylength(MI_KEYDEF *keyinfo,unsigned char *key);
591
extern uint32_t _mi_keylength_part(MI_KEYDEF *keyinfo, register unsigned char *key,
1 by brian
clean slate
592
			       HA_KEYSEG *end);
481 by Brian Aker
Remove all of uchar.
593
extern unsigned char *_mi_move_key(MI_KEYDEF *keyinfo,unsigned char *to,unsigned char *from);
594
extern int _mi_search_next(MI_INFO *info,MI_KEYDEF *keyinfo,unsigned char *key,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
595
			   uint32_t key_length,uint32_t nextflag,drizzled::internal::my_off_t pos);
596
extern int _mi_search_first(MI_INFO *info,MI_KEYDEF *keyinfo,drizzled::internal::my_off_t pos);
597
extern int _mi_search_last(MI_INFO *info,MI_KEYDEF *keyinfo,drizzled::internal::my_off_t pos);
598
extern unsigned char *_mi_fetch_keypage(MI_INFO *info,MI_KEYDEF *keyinfo,drizzled::internal::my_off_t page,
481 by Brian Aker
Remove all of uchar.
599
				int level,unsigned char *buff,int return_buffer);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
600
extern int _mi_write_keypage(MI_INFO *info,MI_KEYDEF *keyinfo,drizzled::internal::my_off_t page,
481 by Brian Aker
Remove all of uchar.
601
			     int level, unsigned char *buff);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
602
extern int _mi_dispose(MI_INFO *info,MI_KEYDEF *keyinfo,drizzled::internal::my_off_t pos,
1 by brian
clean slate
603
                      int level);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
604
extern drizzled::internal::my_off_t _mi_new(MI_INFO *info,MI_KEYDEF *keyinfo,int level);
482 by Brian Aker
Remove uint.
605
extern uint32_t _mi_make_key(MI_INFO *info,uint32_t keynr,unsigned char *key,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
606
			 const unsigned char *record,drizzled::internal::my_off_t filepos);
482 by Brian Aker
Remove uint.
607
extern uint32_t _mi_pack_key(register MI_INFO *info, uint32_t keynr, unsigned char *key,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
608
                         unsigned char *old, drizzled::key_part_map keypart_map,
1 by brian
clean slate
609
                         HA_KEYSEG **last_used_keyseg);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
610
extern int _mi_read_key_record(MI_INFO *info,drizzled::internal::my_off_t filepos,unsigned char *buf);
2296.1.1 by Mark Atwood
Merge in Fixes of Brian's IOCACHE.
611
extern int _mi_read_cache(drizzled::internal::io_cache_st *info,unsigned char *buff,drizzled::internal::my_off_t pos,
482 by Brian Aker
Remove uint.
612
			  uint32_t length,int re_read_if_possibly);
481 by Brian Aker
Remove all of uchar.
613
extern uint64_t retrieve_auto_increment(MI_INFO *info,const unsigned char *record);
1 by brian
clean slate
614
656.1.39 by Monty Taylor
Removed my_seek, my_tell, my_fwrite, my_fseek.
615
unsigned char *mi_alloc_rec_buff(MI_INFO *info, size_t length, unsigned char **buf);
1 by brian
clean slate
616
#define mi_get_rec_buff_ptr(info,buf)                              \
617
        ((((info)->s->options & HA_OPTION_PACK_RECORD) && (buf)) ? \
618
        (buf) - MI_REC_BUFF_OFFSET : (buf))
619
#define mi_get_rec_buff_len(info,buf)                              \
205 by Brian Aker
uint32 -> uin32_t
620
        (*((uint32_t *)(mi_get_rec_buff_ptr(info,buf))))
1 by brian
clean slate
621
481 by Brian Aker
Remove all of uchar.
622
extern ulong _mi_rec_unpack(MI_INFO *info,unsigned char *to,unsigned char *from,
1 by brian
clean slate
623
			    ulong reclength);
481 by Brian Aker
Remove all of uchar.
624
extern bool _mi_rec_check(MI_INFO *info,const unsigned char *record, unsigned char *packpos,
281 by Brian Aker
Converted myisam away from my_bool
625
                             ulong packed_length, bool with_checkum);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
626
extern int _mi_write_part_record(MI_INFO *info,drizzled::internal::my_off_t filepos,ulong length,
627
				 drizzled::internal::my_off_t next_filepos,unsigned char **record,
1 by brian
clean slate
628
				 ulong *reclength,int *flag);
481 by Brian Aker
Remove all of uchar.
629
extern void _mi_print_key(FILE *stream,HA_KEYSEG *keyseg,const unsigned char *key,
482 by Brian Aker
Remove uint.
630
			  uint32_t length);
281 by Brian Aker
Converted myisam away from my_bool
631
extern bool _mi_read_pack_info(MI_INFO *info,bool fix_keys);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
632
extern int _mi_read_pack_record(MI_INFO *info,drizzled::internal::my_off_t filepos,unsigned char *buf);
633
extern int _mi_read_rnd_pack_record(MI_INFO*, unsigned char *,drizzled::internal::my_off_t, bool);
1 by brian
clean slate
634
extern int _mi_pack_rec_unpack(MI_INFO *info, MI_BIT_BUFF *bit_buff,
481 by Brian Aker
Remove all of uchar.
635
                               unsigned char *to, unsigned char *from, ulong reclength);
1 by brian
clean slate
636
637
struct st_sort_info;
638
639
640
typedef struct st_mi_block_info {	/* Parameter to _mi_get_block_info */
481 by Brian Aker
Remove all of uchar.
641
  unsigned char header[MI_BLOCK_INFO_HEADER_LENGTH];
1 by brian
clean slate
642
  ulong rec_len;
643
  ulong data_len;
644
  ulong block_len;
645
  ulong blob_len;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
646
  drizzled::internal::my_off_t filepos;
647
  drizzled::internal::my_off_t next_filepos;
648
  drizzled::internal::my_off_t prev_filepos;
482 by Brian Aker
Remove uint.
649
  uint32_t second_read;
650
  uint32_t offset;
1 by brian
clean slate
651
} MI_BLOCK_INFO;
652
653
	/* bits in return from _mi_get_block_info */
654
655
#define BLOCK_FIRST	1
656
#define BLOCK_LAST	2
657
#define BLOCK_DELETED	4
658
#define BLOCK_ERROR	8	/* Wrong data */
659
#define BLOCK_SYNC_ERROR 16	/* Right data at wrong place */
660
#define BLOCK_FATAL_ERROR 32	/* hardware-error */
661
662
#define NEED_MEM	((uint) 10*4*(IO_SIZE+32)+32) /* Nead for recursion */
663
#define MAXERR			20
664
#define BUFFERS_WHEN_SORTING	16		/* Alloc for sort-key-tree */
1183.4.3 by Stewart Smith
remove MY_HOW_OFTEN_TO_WRITE. Think this was a leftover from unireg. MyISAM has a 'how often to write' define that is defined to this, just put the value directly in myisamdef.h
665
#define WRITE_COUNT		1000
1 by brian
clean slate
666
#define INDEX_TMP_EXT		".TMM"
667
#define DATA_TMP_EXT		".TMD"
668
669
#define UPDATE_TIME		1
670
#define UPDATE_STAT		2
671
#define UPDATE_SORT		4
672
#define UPDATE_AUTO_INC		8
673
#define UPDATE_OPEN_COUNT	16
674
675
#define USE_BUFFER_INIT		(((1024L*512L-MALLOC_OVERHEAD)/IO_SIZE)*IO_SIZE)
676
#define READ_BUFFER_INIT	(1024L*256L-MALLOC_OVERHEAD)
677
#define SORT_BUFFER_INIT	(2048L*1024L-MALLOC_OVERHEAD)
678
#define MIN_SORT_BUFFER		(4096-MALLOC_OVERHEAD)
679
680
#define fast_mi_writeinfo(INFO) if (!(INFO)->s->tot_locks) (void) _mi_writeinfo((INFO),0)
681
#define fast_mi_readinfo(INFO) ((INFO)->lock_type == F_UNLCK) && _mi_readinfo((INFO),F_RDLCK,1)
682
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
683
extern uint32_t _mi_get_block_info(MI_BLOCK_INFO *,int, drizzled::internal::my_off_t);
482 by Brian Aker
Remove uint.
684
extern uint32_t _mi_rec_pack(MI_INFO *info,unsigned char *to,const unsigned char *from);
685
extern uint32_t _mi_pack_get_block_info(MI_INFO *myisam, MI_BIT_BUFF *bit_buff,
481 by Brian Aker
Remove all of uchar.
686
                                    MI_BLOCK_INFO *info, unsigned char **rec_buff_p,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
687
                                    int file, drizzled::internal::my_off_t filepos);
482 by Brian Aker
Remove uint.
688
extern void _my_store_blob_length(unsigned char *pos,uint32_t pack_length,uint32_t length);
1 by brian
clean slate
689
extern void mi_report_error(int errcode, const char *file_name);
2054.1.2 by Brian Aker
Rename of the Loooongggggg error type over to simply drizzled::error_t
690
extern void mi_report_error(drizzled::error_t errcode, const char *file_name);
481 by Brian Aker
Remove all of uchar.
691
extern size_t mi_mmap_pread(MI_INFO *info, unsigned char *Buffer,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
692
                            size_t Count, drizzled::internal::my_off_t offset, drizzled::myf MyFlags);
481 by Brian Aker
Remove all of uchar.
693
extern size_t mi_mmap_pwrite(MI_INFO *info, const unsigned char *Buffer,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
694
                             size_t Count, drizzled::internal::my_off_t offset, drizzled::myf MyFlags);
481 by Brian Aker
Remove all of uchar.
695
extern size_t mi_nommap_pread(MI_INFO *info, unsigned char *Buffer,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
696
                              size_t Count, drizzled::internal::my_off_t offset, drizzled::myf MyFlags);
481 by Brian Aker
Remove all of uchar.
697
extern size_t mi_nommap_pwrite(MI_INFO *info, const unsigned char *Buffer,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
698
                               size_t Count, drizzled::internal::my_off_t offset, drizzled::myf MyFlags);
1 by brian
clean slate
699
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
700
uint32_t mi_state_info_write(int file, MI_STATE_INFO *state, uint32_t pWrite);
701
uint32_t mi_state_info_read_dsk(int file, MI_STATE_INFO *state, bool pRead);
702
uint32_t mi_base_info_write(int file, MI_BASE_INFO *base);
703
int mi_keyseg_write(int file, const HA_KEYSEG *keyseg);
704
uint32_t mi_keydef_write(int file, MI_KEYDEF *keydef);
705
uint32_t mi_uniquedef_write(int file, MI_UNIQUEDEF *keydef);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
706
uint32_t mi_recinfo_write(int file, drizzled::MI_COLUMNDEF *recinfo);
1 by brian
clean slate
707
extern int mi_disable_indexes(MI_INFO *info);
708
extern int mi_enable_indexes(MI_INFO *info);
709
extern int mi_indexes_are_disabled(MI_INFO *info);
481 by Brian Aker
Remove all of uchar.
710
ulong _my_calc_total_blob_length(MI_INFO *info, const unsigned char *record);
2241.4.37 by Stewart Smith
remove the drizzled::internal namespace prefix from teh typedef for ha_checksum - it's just for myisam now
711
ha_checksum mi_checksum(MI_INFO *info, const unsigned char *buf);
712
ha_checksum mi_static_checksum(MI_INFO *info, const unsigned char *buf);
481 by Brian Aker
Remove all of uchar.
713
bool mi_check_unique(MI_INFO *info, MI_UNIQUEDEF *def, unsigned char *record,
2241.4.37 by Stewart Smith
remove the drizzled::internal namespace prefix from teh typedef for ha_checksum - it's just for myisam now
714
		     ha_checksum unique_hash, drizzled::internal::my_off_t pos);
715
ha_checksum mi_unique_hash(MI_UNIQUEDEF *def, const unsigned char *buf);
1 by brian
clean slate
716
int _mi_cmp_static_unique(MI_INFO *info, MI_UNIQUEDEF *def,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
717
			   const unsigned char *record, drizzled::internal::my_off_t pos);
1 by brian
clean slate
718
int _mi_cmp_dynamic_unique(MI_INFO *info, MI_UNIQUEDEF *def,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
719
			   const unsigned char *record, drizzled::internal::my_off_t pos);
481 by Brian Aker
Remove all of uchar.
720
int mi_unique_comp(MI_UNIQUEDEF *def, const unsigned char *a, const unsigned char *b,
281 by Brian Aker
Converted myisam away from my_bool
721
		   bool null_are_equal);
1 by brian
clean slate
722
723
extern MI_INFO *test_if_reopen(char *filename);
281 by Brian Aker
Converted myisam away from my_bool
724
bool check_table_is_closed(const char *name, const char *where);
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
725
int mi_open_datafile(MI_INFO *info, MYISAM_SHARE *share, int file_to_dup);
1 by brian
clean slate
726
int mi_open_keyfile(MYISAM_SHARE *share);
727
void mi_setup_functions(register MYISAM_SHARE *share);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
728
bool mi_dynmap_file(MI_INFO *info, drizzled::internal::my_off_t size);
729
void mi_remap_file(MI_INFO *info, drizzled::internal::my_off_t size);
1 by brian
clean slate
730
482 by Brian Aker
Remove uint.
731
int mi_check_index_cond(register MI_INFO *info, uint32_t keynr, unsigned char *record);
1 by brian
clean slate
732
733
    /* Functions needed by mi_check */
734
volatile int *killed_ptr(MI_CHECK *param);
398.1.9 by Monty Taylor
Cleaned up stuff out of global.h.
735
void mi_check_print_error(MI_CHECK *param, const char *fmt,...);
736
void mi_check_print_warning(MI_CHECK *param, const char *fmt,...);
737
void mi_check_print_info(MI_CHECK *param, const char *fmt,...);
1 by brian
clean slate
738
int flush_pending_blocks(MI_SORT_PARAM *param);
739
int thr_write_keys(MI_SORT_PARAM *sort_param);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
740
int flush_blocks(MI_CHECK *param, drizzled::KEY_CACHE *key_cache, int file);
1 by brian
clean slate
741
742
int sort_write_record(MI_SORT_PARAM *sort_param);
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
743
int _create_index_by_sort(MI_SORT_PARAM *info,bool no_messages, size_t);
1 by brian
clean slate
744
745
extern void mi_set_index_cond_func(MI_INFO *info, index_cond_func_t func,
746
                                   void *func_arg);
36 by Brian Aker
Moved pread over to just supporting myisam (someone can refactor from here
747
/* Just for myisam legacy */
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
748
extern size_t my_pwrite(int Filedes,const unsigned char *Buffer,size_t Count,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
749
                        drizzled::internal::my_off_t offset,drizzled::myf MyFlags);
750
extern size_t my_pread(int Filedes,unsigned char *Buffer,size_t Count,drizzled::internal::my_off_t offset,
751
                       drizzled::myf MyFlags);
77 by Brian Aker
Resolved merge from Monty
752
753
/* Needed for handler */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
754
void mi_disable_non_unique_index(MI_INFO *info, drizzled::ha_rows rows);
779.1.28 by Monty Taylor
More __attribute__ removal.
755
void _mi_report_crashed(MI_INFO *file, const char *message, const char *sfile,
756
                        uint32_t sline);
51.1.127 by Monty Taylor
Fixed the _mi_report_crashed warning (and a couple of others)
757
2241.4.28 by Stewart Smith
move DFLT_INIT_HITS define to myisam_priv.h - only used by myisam
758
759
#define DFLT_INIT_HITS  3