~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/heap/hp_create.c

Merged in changes from Andrey.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
#include "libdrizzle/drizzle_com.h"
18
18
#include "drizzled/error.h"
19
19
 
20
 
static int keys_compare(heap_rb_param *param, uchar *key1, uchar *key2);
21
 
static void init_block(HP_BLOCK *block,uint chunk_length, uint32_t min_records,
 
20
static int keys_compare(heap_rb_param *param, unsigned char *key1, unsigned char *key2);
 
21
static void init_block(HP_BLOCK *block,uint32_t chunk_length, uint32_t min_records,
22
22
                        uint32_t max_records);
23
23
 
24
 
#define FIXED_REC_OVERHEAD (sizeof(uchar))
25
 
#define VARIABLE_REC_OVERHEAD (sizeof(uchar**) + sizeof(uchar))
 
24
#define FIXED_REC_OVERHEAD (sizeof(unsigned char))
 
25
#define VARIABLE_REC_OVERHEAD (sizeof(unsigned char**) + sizeof(unsigned char))
26
26
 
27
27
/* Minimum size that a chunk can take, 12 bytes on 32bit, 24 bytes on 64bit */
28
28
#define VARIABLE_MIN_CHUNK_SIZE \
29
 
        ((sizeof(uchar**) + VARIABLE_REC_OVERHEAD + sizeof(uchar**) - 1) & ~(sizeof(uchar**) - 1))
 
29
        ((sizeof(unsigned char**) + VARIABLE_REC_OVERHEAD + sizeof(unsigned char**) - 1) & ~(sizeof(unsigned char**) - 1))
30
30
 
31
31
 
32
32
/* Create a heap table */
33
33
 
34
 
int heap_create(const char *name, uint keys, HP_KEYDEF *keydef,
35
 
    uint columns, HP_COLUMNDEF *columndef,
36
 
    uint max_key_fieldnr, uint key_part_size,
37
 
    uint reclength, uint keys_memory_size,
 
34
int heap_create(const char *name, uint32_t keys, HP_KEYDEF *keydef,
 
35
    uint32_t columns, HP_COLUMNDEF *columndef,
 
36
    uint32_t max_key_fieldnr, uint32_t key_part_size,
 
37
    uint32_t reclength, uint32_t keys_memory_size,
38
38
    uint32_t max_records, uint32_t min_records,
39
39
    HP_CREATE_INFO *create_info, HP_SHARE **res)
40
40
{
41
 
  uint i, j, key_segs, max_length, length;
 
41
  uint32_t i, j, key_segs, max_length, length;
42
42
  uint32_t max_rows_for_stated_memory;
43
43
  HP_SHARE *share= 0;
44
44
  HA_KEYSEG *keyseg;
55
55
 
56
56
  if (!share)
57
57
  {
58
 
    uint chunk_dataspace_length, chunk_length, is_variable_size;
59
 
    uint fixed_data_length, fixed_column_count;
 
58
    uint32_t chunk_dataspace_length, chunk_length, is_variable_size;
 
59
    uint32_t fixed_data_length, fixed_column_count;
60
60
    HP_KEYDEF *keyinfo;
61
61
 
62
62
    if (create_info->max_chunk_size)
63
63
    {
64
 
      uint configured_chunk_size= create_info->max_chunk_size;
 
64
      uint32_t configured_chunk_size= create_info->max_chunk_size;
65
65
 
66
66
      /* User requested variable-size records, let's see if they're possible */
67
67
 
109
109
    if (is_variable_size)
110
110
    {
111
111
      /* Check whether we have any variable size records past key data */
112
 
      uint has_variable_fields= 0;
 
112
      uint32_t has_variable_fields= 0;
113
113
 
114
114
      fixed_data_length= key_part_size;
115
115
      fixed_column_count= max_key_fieldnr;
155
155
    }
156
156
 
157
157
    /*
158
 
      We store uchar* del_link inside the data area of deleted records,
159
 
      so the data length should be at least sizeof(uchar*)
 
158
      We store unsigned char* del_link inside the data area of deleted records,
 
159
      so the data length should be at least sizeof(unsigned char*)
160
160
    */
161
 
    set_if_bigger(chunk_dataspace_length, sizeof (uchar**));
 
161
    set_if_bigger(chunk_dataspace_length, sizeof (unsigned char**));
162
162
 
163
163
    if (is_variable_size)
164
164
    {
170
170
    }
171
171
 
172
172
    /* Align chunk length to the next pointer */
173
 
    chunk_length= (uint) (chunk_length + sizeof(uchar**) - 1) & ~(sizeof(uchar**) - 1);
 
173
    chunk_length= (uint) (chunk_length + sizeof(unsigned char**) - 1) & ~(sizeof(unsigned char**) - 1);
174
174
 
175
175
 
176
176
    
233
233
      }
234
234
      keyinfo->length= length;
235
235
      length+= keyinfo->rb_tree.size_of_element + 
236
 
               ((keyinfo->algorithm == HA_KEY_ALG_BTREE) ? sizeof(uchar*) : 0);
 
236
               ((keyinfo->algorithm == HA_KEY_ALG_BTREE) ? sizeof(unsigned char*) : 0);
237
237
      if (length > max_length)
238
238
        max_length= length;
239
239
      key_segs+= keyinfo->keysegs;
285
285
      {
286
286
        /* additional HA_KEYTYPE_END keyseg */
287
287
        keyseg->type=     HA_KEYTYPE_END;
288
 
        keyseg->length=   sizeof(uchar*);
 
288
        keyseg->length=   sizeof(unsigned char*);
289
289
        keyseg->flag=     0;
290
290
        keyseg->null_bit= 0;
291
291
        keyseg++;
292
292
 
293
 
        init_tree(&keyinfo->rb_tree, 0, 0, sizeof(uchar*),
 
293
        init_tree(&keyinfo->rb_tree, 0, 0, sizeof(unsigned char*),
294
294
                  (qsort_cmp2)keys_compare, 1, NULL, NULL);
295
295
        keyinfo->delete_key= hp_rb_delete_key;
296
296
        keyinfo->write_key= hp_rb_write_key;
329
329
 
330
330
    if (is_variable_size) {
331
331
      share->recordspace.offset_link= chunk_dataspace_length;
332
 
      share->recordspace.offset_status= share->recordspace.offset_link + sizeof(uchar**);
 
332
      share->recordspace.offset_status= share->recordspace.offset_link + sizeof(unsigned char**);
333
333
    } else {
334
334
      share->recordspace.offset_link= 1<<22; /* Make it likely to fail if anyone uses this offset */
335
335
      share->recordspace.offset_status= chunk_dataspace_length;
338
338
    /* Must be allocated separately for rename to work */
339
339
    if (!(share->name= my_strdup(name,MYF(0))))
340
340
    {
341
 
      my_free((uchar*) share,MYF(0));
 
341
      free((unsigned char*) share);
342
342
      goto err;
343
343
    }
344
344
    thr_lock_init(&share->lock);
345
 
    VOID(pthread_mutex_init(&share->intern_lock,MY_MUTEX_INIT_FAST));
 
345
    pthread_mutex_init(&share->intern_lock,MY_MUTEX_INIT_FAST);
346
346
    if (!create_info->internal_table)
347
347
    {
348
348
      share->open_list.data= (void*) share;
364
364
} /* heap_create */
365
365
 
366
366
 
367
 
static int keys_compare(heap_rb_param *param, uchar *key1, uchar *key2)
 
367
static int keys_compare(heap_rb_param *param, unsigned char *key1, unsigned char *key2)
368
368
{
369
 
  uint not_used[2];
 
369
  uint32_t not_used[2];
370
370
  return ha_key_cmp(param->keyseg, key1, key2, param->key_length, 
371
371
                    param->search_flag, not_used);
372
372
}
373
373
 
374
 
static void init_block(HP_BLOCK *block, uint chunk_length, uint32_t min_records,
 
374
static void init_block(HP_BLOCK *block, uint32_t chunk_length, uint32_t min_records,
375
375
                       uint32_t max_records)
376
376
{
377
 
  uint i,recbuffer,records_in_block;
 
377
  uint32_t i,recbuffer,records_in_block;
378
378
 
379
 
  max_records= max(min_records,max_records);
 
379
  max_records= cmax(min_records,max_records);
380
380
  if (!max_records)
381
381
    max_records= 1000;                  /* As good as quess as anything */
382
382
  
383
383
  /* we want to start each chunk at 8 bytes boundary, round recbuffer to the next 8 */
384
 
  recbuffer= (uint) (chunk_length + sizeof(uchar**) - 1) & ~(sizeof(uchar**) - 1);  
 
384
  recbuffer= (uint) (chunk_length + sizeof(unsigned char**) - 1) & ~(sizeof(unsigned char**) - 1);  
385
385
  records_in_block= max_records / 10;
386
386
  if (records_in_block < 10 && max_records)
387
387
    records_in_block= 10;
444
444
    heap_share_list= list_delete(heap_share_list, &share->open_list);
445
445
  hp_clear(share);                      /* Remove blocks from memory */
446
446
  thr_lock_delete(&share->lock);
447
 
  VOID(pthread_mutex_destroy(&share->intern_lock));
448
 
  my_free((uchar*) share->name, MYF(0));
449
 
  my_free((uchar*) share, MYF(0));
 
447
  pthread_mutex_destroy(&share->intern_lock);
 
448
  free((unsigned char*) share->name);
 
449
  free((unsigned char*) share);
450
450
  return;
451
451
}