~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/sort.c

  • Committer: Brian Aker
  • Date: 2008-10-06 06:47:29 UTC
  • Revision ID: brian@tangent.org-20081006064729-2i9mhjkzyvow9xsm
RemoveĀ uint.

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
 
44
44
/* Functions defined in this file */
45
45
 
46
 
static ha_rows  find_all_keys(MI_SORT_PARAM *info,uint keys,
 
46
static ha_rows  find_all_keys(MI_SORT_PARAM *info,uint32_t keys,
47
47
                                    unsigned char **sort_keys,
48
48
                                    DYNAMIC_ARRAY *buffpek,int *maxbuffer,
49
49
                                    IO_CACHE *tempfile,
50
50
                                    IO_CACHE *tempfile_for_exceptions);
51
51
static int  write_keys(MI_SORT_PARAM *info,unsigned char **sort_keys,
52
 
                             uint count, BUFFPEK *buffpek,IO_CACHE *tempfile);
 
52
                             uint32_t count, BUFFPEK *buffpek,IO_CACHE *tempfile);
53
53
static int  write_key(MI_SORT_PARAM *info, unsigned char *key,
54
54
                            IO_CACHE *tempfile);
55
55
static int  write_index(MI_SORT_PARAM *info,unsigned char * *sort_keys,
56
 
                              uint count);
57
 
static int  merge_many_buff(MI_SORT_PARAM *info,uint keys,
 
56
                              uint32_t count);
 
57
static int  merge_many_buff(MI_SORT_PARAM *info,uint32_t keys,
58
58
                                  unsigned char * *sort_keys,
59
59
                                  BUFFPEK *buffpek,int *maxbuffer,
60
60
                                  IO_CACHE *t_file);
61
 
static uint  read_to_buffer(IO_CACHE *fromfile,BUFFPEK *buffpek,
62
 
                                  uint sort_length);
63
 
static int  merge_buffers(MI_SORT_PARAM *info,uint keys,
 
61
static uint32_t  read_to_buffer(IO_CACHE *fromfile,BUFFPEK *buffpek,
 
62
                                  uint32_t sort_length);
 
63
static int  merge_buffers(MI_SORT_PARAM *info,uint32_t keys,
64
64
                                IO_CACHE *from_file, IO_CACHE *to_file,
65
65
                                unsigned char * *sort_keys, BUFFPEK *lastbuff,
66
66
                                BUFFPEK *Fb, BUFFPEK *Tb);
68
68
                              IO_CACHE *);
69
69
 
70
70
static int  write_keys_varlen(MI_SORT_PARAM *info,unsigned char **sort_keys,
71
 
                                    uint count, BUFFPEK *buffpek,
 
71
                                    uint32_t count, BUFFPEK *buffpek,
72
72
                                    IO_CACHE *tempfile);
73
 
static uint  read_to_buffer_varlen(IO_CACHE *fromfile,BUFFPEK *buffpek,
74
 
                                         uint sort_length);
 
73
static uint32_t  read_to_buffer_varlen(IO_CACHE *fromfile,BUFFPEK *buffpek,
 
74
                                         uint32_t sort_length);
75
75
static int  write_merge_key(MI_SORT_PARAM *info, IO_CACHE *to_file,
76
 
                                  unsigned char *key, uint sort_length, uint count);
 
76
                                  unsigned char *key, uint32_t sort_length, uint32_t count);
77
77
static int  write_merge_key_varlen(MI_SORT_PARAM *info,
78
78
                                         IO_CACHE *to_file,
79
 
                                         unsigned char* key, uint sort_length,
80
 
                                         uint count);
 
79
                                         unsigned char* key, uint32_t sort_length,
 
80
                                         uint32_t count);
81
81
static inline int
82
82
my_var_write(MI_SORT_PARAM *info, IO_CACHE *to_file, unsigned char *bufs);
83
83
 
99
99
                          uint32_t sortbuff_size)
100
100
{
101
101
  int error,maxbuffer,skr;
102
 
  uint memavl,old_memavl,keys,sort_length;
 
102
  uint32_t memavl,old_memavl,keys,sort_length;
103
103
  DYNAMIC_ARRAY buffpek;
104
104
  ha_rows records;
105
105
  unsigned char **sort_keys;
213
213
  if (my_b_inited(&tempfile_for_exceptions))
214
214
  {
215
215
    MI_INFO *idx=info->sort_info->info;
216
 
    uint     keyno=info->key;
217
 
    uint     key_length, ref_length=idx->s->rec_reflength;
 
216
    uint32_t     keyno=info->key;
 
217
    uint32_t     key_length, ref_length=idx->s->rec_reflength;
218
218
 
219
219
    if (!no_messages)
220
220
      printf("  - Adding exceptions\n"); /* purecov: tested */
247
247
 
248
248
/* Search after all keys and place them in a temp. file */
249
249
 
250
 
static ha_rows  find_all_keys(MI_SORT_PARAM *info, uint keys,
 
250
static ha_rows  find_all_keys(MI_SORT_PARAM *info, uint32_t keys,
251
251
                                    unsigned char **sort_keys, DYNAMIC_ARRAY *buffpek,
252
252
                                    int *maxbuffer, IO_CACHE *tempfile,
253
253
                                    IO_CACHE *tempfile_for_exceptions)
254
254
{
255
255
  int error;
256
 
  uint idx;
 
256
  uint32_t idx;
257
257
 
258
258
  idx=error=0;
259
259
  sort_keys[0]=(unsigned char*) (sort_keys+keys);
301
301
{
302
302
  MI_SORT_PARAM *sort_param= (MI_SORT_PARAM*) arg;
303
303
  int error;
304
 
  uint memavl,old_memavl,keys,sort_length;
305
 
  uint idx, maxbuffer;
 
304
  uint32_t memavl,old_memavl,keys,sort_length;
 
305
  uint32_t idx, maxbuffer;
306
306
  unsigned char **sort_keys=0;
307
307
 
308
308
  error=1;
345
345
        keys= idx+1;
346
346
      else
347
347
      {
348
 
        uint skr;
 
348
        uint32_t skr;
349
349
        do
350
350
        {
351
351
          skr= maxbuffer;
472
472
  uint32_t length= 0, keys;
473
473
  ulong *rec_per_key_part= param->rec_per_key_part;
474
474
  int got_error=sort_info->got_error;
475
 
  uint i;
 
475
  uint32_t i;
476
476
  MI_INFO *info=sort_info->info;
477
477
  MYISAM_SHARE *share=info->s;
478
478
  MI_SORT_PARAM *sinfo;
540
540
    }
541
541
    if (sinfo->buffpek.elements)
542
542
    {
543
 
      uint maxbuffer=sinfo->buffpek.elements-1;
 
543
      uint32_t maxbuffer=sinfo->buffpek.elements-1;
544
544
      if (!mergebuf)
545
545
      {
546
546
        length=param->sort_buffer_length;
588
588
    }
589
589
    if (my_b_inited(&sinfo->tempfile_for_exceptions))
590
590
    {
591
 
      uint key_length;
 
591
      uint32_t key_length;
592
592
 
593
593
      if (param->testflag & T_VERBOSE)
594
594
        printf("Key %d  - Dumping 'long' keys\n", sinfo->key+1);
621
621
        /* Write all keys in memory to file for later merge */
622
622
 
623
623
static int  write_keys(MI_SORT_PARAM *info, register unsigned char **sort_keys,
624
 
                             uint count, BUFFPEK *buffpek, IO_CACHE *tempfile)
 
624
                             uint32_t count, BUFFPEK *buffpek, IO_CACHE *tempfile)
625
625
{
626
626
  unsigned char **end;
627
 
  uint sort_length=info->key_length;
 
627
  uint32_t sort_length=info->key_length;
628
628
 
629
629
  my_qsort2((unsigned char*) sort_keys,count,sizeof(unsigned char*),(qsort2_cmp) info->key_cmp,
630
630
            info);
662
662
 
663
663
static int  write_keys_varlen(MI_SORT_PARAM *info,
664
664
                                    register unsigned char **sort_keys,
665
 
                                    uint count, BUFFPEK *buffpek,
 
665
                                    uint32_t count, BUFFPEK *buffpek,
666
666
                                    IO_CACHE *tempfile)
667
667
{
668
668
  unsigned char **end;
689
689
static int  write_key(MI_SORT_PARAM *info, unsigned char *key,
690
690
                            IO_CACHE *tempfile)
691
691
{
692
 
  uint key_length=info->real_key_length;
 
692
  uint32_t key_length=info->real_key_length;
693
693
 
694
694
  if (!my_b_inited(tempfile) &&
695
695
      open_cached_file(tempfile, my_tmpdir(info->tmpdir), "ST",
706
706
/* Write index */
707
707
 
708
708
static int  write_index(MI_SORT_PARAM *info, register unsigned char **sort_keys,
709
 
                              register uint count)
 
709
                              register uint32_t count)
710
710
{
711
711
  my_qsort2((unsigned char*) sort_keys,(size_t) count,sizeof(unsigned char*),
712
712
           (qsort2_cmp) info->key_cmp,info);
721
721
 
722
722
        /* Merge buffers to make < MERGEBUFF2 buffers */
723
723
 
724
 
static int  merge_many_buff(MI_SORT_PARAM *info, uint keys,
 
724
static int  merge_many_buff(MI_SORT_PARAM *info, uint32_t keys,
725
725
                                  unsigned char **sort_keys, BUFFPEK *buffpek,
726
726
                                  int *maxbuffer, IO_CACHE *t_file)
727
727
{
778
778
    -1  Error
779
779
*/
780
780
 
781
 
static uint  read_to_buffer(IO_CACHE *fromfile, BUFFPEK *buffpek,
782
 
                                  uint sort_length)
 
781
static uint32_t  read_to_buffer(IO_CACHE *fromfile, BUFFPEK *buffpek,
 
782
                                  uint32_t sort_length)
783
783
{
784
 
  register uint count;
785
 
  uint length;
 
784
  register uint32_t count;
 
785
  uint32_t length;
786
786
 
787
787
  if ((count=(uint) cmin((ha_rows) buffpek->max_keys,buffpek->count)))
788
788
  {
797
797
  return (count*sort_length);
798
798
} /* read_to_buffer */
799
799
 
800
 
static uint  read_to_buffer_varlen(IO_CACHE *fromfile, BUFFPEK *buffpek,
801
 
                                         uint sort_length)
 
800
static uint32_t  read_to_buffer_varlen(IO_CACHE *fromfile, BUFFPEK *buffpek,
 
801
                                         uint32_t sort_length)
802
802
{
803
 
  register uint count;
 
803
  register uint32_t count;
804
804
  uint16_t length_of_key = 0;
805
 
  uint idx;
 
805
  uint32_t idx;
806
806
  unsigned char *buffp;
807
807
 
808
808
  if ((count=(uint) cmin((ha_rows) buffpek->max_keys,buffpek->count)))
831
831
 
832
832
static int  write_merge_key_varlen(MI_SORT_PARAM *info,
833
833
                                         IO_CACHE *to_file, unsigned char* key,
834
 
                                         uint sort_length, uint count)
 
834
                                         uint32_t sort_length, uint32_t count)
835
835
{
836
 
  uint idx;
 
836
  uint32_t idx;
837
837
  unsigned char *bufs = key;
838
838
 
839
839
  for (idx=1;idx<=count;idx++)
849
849
 
850
850
static int  write_merge_key(MI_SORT_PARAM *info __attribute__((unused)),
851
851
                                  IO_CACHE *to_file, unsigned char *key,
852
 
                                  uint sort_length, uint count)
 
852
                                  uint32_t sort_length, uint32_t count)
853
853
{
854
854
  return my_b_write(to_file, key, (size_t) sort_length*count);
855
855
}
860
860
*/
861
861
 
862
862
static int
863
 
merge_buffers(MI_SORT_PARAM *info, uint keys, IO_CACHE *from_file,
 
863
merge_buffers(MI_SORT_PARAM *info, uint32_t keys, IO_CACHE *from_file,
864
864
              IO_CACHE *to_file, unsigned char **sort_keys, BUFFPEK *lastbuff,
865
865
              BUFFPEK *Fb, BUFFPEK *Tb)
866
866
{
867
867
  int error;
868
 
  uint sort_length,maxcount;
 
868
  uint32_t sort_length,maxcount;
869
869
  ha_rows count;
870
870
  my_off_t to_start_filepos= 0;
871
871
  unsigned char *strpos;
928
928
        if (!(error=(int) info->read_to_buffer(from_file,buffpek,sort_length)))
929
929
        {
930
930
          unsigned char *base=buffpek->base;
931
 
          uint max_keys=buffpek->max_keys;
 
931
          uint32_t max_keys=buffpek->max_keys;
932
932
 
933
933
          queue_remove(&queue,0);
934
934
 
1001
1001
        /* Do a merge to output-file (save only positions) */
1002
1002
 
1003
1003
static int
1004
 
merge_index(MI_SORT_PARAM *info, uint keys, unsigned char **sort_keys,
 
1004
merge_index(MI_SORT_PARAM *info, uint32_t keys, unsigned char **sort_keys,
1005
1005
            BUFFPEK *buffpek, int maxbuffer, IO_CACHE *tempfile)
1006
1006
{
1007
1007
  if (merge_buffers(info,keys,tempfile,(IO_CACHE*) 0,sort_keys,buffpek,buffpek,