~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/filesort.cc

  • Committer: tdavies
  • Date: 2010-10-10 05:31:41 UTC
  • mto: (1827.1.3 trunk-drizzle)
  • mto: This revision was merged to the branch mainline in revision 1829.
  • Revision ID: tdavies@molly-20101010053141-7rbcb8fe8a6xxrn8
Bug:621861 Changed C structs to C++ class in the following files: filesort.cc, filesort_info.h, sql_sort.h, table.h. removed the '_st' from the name of some of the classes. For more detail of changes made read the merge proposal notes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
76
76
static void register_used_fields(SORTPARAM *param);
77
77
static int merge_index(SORTPARAM *param,
78
78
                       unsigned char *sort_buffer,
79
 
                       buffpek_st *buffpek,
 
79
                       buffpek *buffpek,
80
80
                       uint32_t maxbuffer,
81
81
                       internal::IO_CACHE *tempfile,
82
82
                       internal::IO_CACHE *outfile);
83
83
static bool save_index(SORTPARAM *param,
84
84
                       unsigned char **sort_keys,
85
85
                       uint32_t count,
86
 
                       filesort_info_st *table_sort);
 
86
                       filesort_info *table_sort);
87
87
static uint32_t suffix_length(uint32_t string_length);
88
88
static uint32_t sortlength(Session *session,
89
89
                           SortField *sortorder,
90
90
                           uint32_t s_length,
91
91
                           bool *multi_byte_charset);
92
 
static sort_addon_field_st *get_addon_fields(Session *session,
 
92
static sort_addon_field *get_addon_fields(Session *session,
93
93
                                             Field **ptabfield,
94
94
                                             uint32_t sortlength,
95
95
                                             uint32_t *plength);
96
 
static void unpack_addon_fields(sort_addon_field_st *addon_field,
 
96
static void unpack_addon_fields(sort_addon_field *addon_field,
97
97
                                unsigned char *buff);
98
98
/**
99
99
  Sort a table.
138
138
  int error;
139
139
  uint32_t memavl, min_sort_memory;
140
140
  uint32_t maxbuffer;
141
 
  buffpek_st *buffpek;
 
141
  buffpek *buffpek_inst;
142
142
  ha_rows records= HA_POS_ERROR;
143
143
  unsigned char **sort_keys= 0;
144
144
  internal::IO_CACHE tempfile, buffpek_pointers, *selected_records_file, *outfile;
145
145
  SORTPARAM param;
146
146
  bool multi_byte_charset;
147
147
 
148
 
  filesort_info_st table_sort;
 
148
  filesort_info table_sort;
149
149
  TableList *tab= table->pos_in_table_list;
150
150
  Item_subselect *subselect= tab ? tab->containing_subselect() : 0;
151
151
 
162
162
    QuickIndexMergeSelect. Work with a copy and put it back at the end
163
163
    when index_merge select has finished with it.
164
164
  */
165
 
  memcpy(&table_sort, &table->sort, sizeof(filesort_info_st));
 
165
  memcpy(&table_sort, &table->sort, sizeof(filesort_info));
166
166
  table->sort.io_cache= NULL;
167
167
 
168
168
  outfile= table_sort.io_cache;
169
169
  my_b_clear(&tempfile);
170
170
  my_b_clear(&buffpek_pointers);
171
 
  buffpek=0;
 
171
  buffpek_inst=0;
172
172
  error= 1;
173
173
  memset(&param, 0, sizeof(param));
174
174
  param.sort_length= sortlength(session, sortorder, s_length, &multi_byte_charset);
272
272
                             &tempfile, selected_records_file)) ==
273
273
      HA_POS_ERROR)
274
274
    goto err;
275
 
  maxbuffer= (uint32_t) (my_b_tell(&buffpek_pointers)/sizeof(*buffpek));
 
275
  maxbuffer= (uint32_t) (my_b_tell(&buffpek_pointers)/sizeof(*buffpek_inst));
276
276
 
277
277
  if (maxbuffer == 0)                   // The whole set is in memory
278
278
  {
285
285
    {
286
286
      if (table_sort.buffpek)
287
287
        free(table_sort.buffpek);
288
 
      table_sort.buffpek= 0;
 
288
      table_sort.buffpek = 0;
289
289
    }
290
290
    if (!(table_sort.buffpek=
291
291
          (unsigned char *) read_buffpek_from_file(&buffpek_pointers, maxbuffer,
292
292
                                 table_sort.buffpek)))
293
293
      goto err;
294
 
    buffpek= (buffpek_st *) table_sort.buffpek;
 
294
    buffpek_inst= (buffpek *) table_sort.buffpek;
295
295
    table_sort.buffpek_len= maxbuffer;
296
296
    close_cached_file(&buffpek_pointers);
297
297
        /* Open cached file if it isn't open */
309
309
    param.keys=((param.keys*(param.rec_length+sizeof(char*))) /
310
310
                param.rec_length-1);
311
311
    maxbuffer--;                                // Offset from 0
312
 
    if (merge_many_buff(&param,(unsigned char*) sort_keys,buffpek,&maxbuffer,
313
 
                        &tempfile))
 
312
    if (merge_many_buff(&param,(unsigned char*) sort_keys,buffpek_inst,&maxbuffer, &tempfile))
314
313
      goto err;
315
314
    if (flush_io_cache(&tempfile) ||
316
315
        reinit_io_cache(&tempfile,internal::READ_CACHE,0L,0,0))
317
316
      goto err;
318
 
    if (merge_index(&param,(unsigned char*) sort_keys,buffpek,maxbuffer,&tempfile,
319
 
                    outfile))
 
317
    if (merge_index(&param,(unsigned char*) sort_keys,buffpek_inst,maxbuffer,&tempfile, outfile))
320
318
      goto err;
321
319
  }
322
320
  if (records > param.max_rows)
331
329
  {
332
330
    free(sort_keys);
333
331
    table_sort.sort_keys= 0;
334
 
    free(buffpek);
 
332
    free(buffpek_inst);
335
333
    table_sort.buffpek= 0;
336
334
    table_sort.buffpek_len= 0;
337
335
  }
359
357
    session->status_var.filesort_rows+= (uint32_t) records;
360
358
  }
361
359
  *examined_rows= param.examined_rows;
362
 
  memcpy(&table->sort, &table_sort, sizeof(filesort_info_st));
 
360
  memcpy(&table->sort, &table_sort, sizeof(filesort_info));
363
361
  DRIZZLE_FILESORT_DONE(error, records);
364
362
  return (error ? HA_POS_ERROR : records);
365
363
} /* filesort */
421
419
static unsigned char *read_buffpek_from_file(internal::IO_CACHE *buffpek_pointers, uint32_t count,
422
420
                                     unsigned char *buf)
423
421
{
424
 
  uint32_t length= sizeof(buffpek_st)*count;
 
422
  uint32_t length= sizeof(buffpek)*count;
425
423
  unsigned char *tmp= buf;
426
 
  if (count > UINT_MAX/sizeof(buffpek_st))
427
 
    return 0; /* sizeof(buffpek_st)*count will overflow */
 
424
  if (count > UINT_MAX/sizeof(buffpek))
 
425
    return 0; /* sizeof(buffpek)*count will overflow */
428
426
  if (!tmp)
429
427
    tmp= (unsigned char *)malloc(length);
430
428
  if (tmp)
447
445
  @param param             Sorting parameter
448
446
  @param select            Use this to get source data
449
447
  @param sort_keys         Array of pointers to sort key + addon buffers.
450
 
  @param buffpek_pointers  File to write buffpek_sts describing sorted segments
 
448
  @param buffpek_pointers  File to write buffpeks describing sorted segments
451
449
                           in tempfile.
452
450
  @param tempfile          File to write sorted sequences of sortkeys to.
453
451
  @param indexfile         If !NULL, use it for source data (contains rowids)
461
459
       {
462
460
         sort sort_keys buffer;
463
461
         dump sorted sequence to 'tempfile';
464
 
         dump buffpek_st describing sequence location into 'buffpek_pointers';
 
462
         dump buffpek describing sequence location into 'buffpek_pointers';
465
463
       }
466
464
       put sort key into 'sort_keys';
467
465
     }
642
640
  @details
643
641
  Sort the buffer and write:
644
642
  -# the sorted sequence to tempfile
645
 
  -# a buffpek_st describing the sorted sequence position to buffpek_pointers
 
643
  -# a buffpek describing the sorted sequence position to buffpek_pointers
646
644
 
647
645
    (was: Skriver en buffert med nycklar till filen)
648
646
 
649
647
  @param param             Sort parameters
650
648
  @param sort_keys         Array of pointers to keys to sort
651
649
  @param count             Number of elements in sort_keys array
652
 
  @param buffpek_pointers  One 'buffpek_st' struct will be written into this file.
653
 
                           The buffpek_st::{file_pos, count} will indicate where
 
650
  @param buffpek_pointers  One 'buffpek' struct will be written into this file.
 
651
                           The buffpek::{file_pos, count} will indicate where
654
652
                           the sorted data was stored.
655
653
  @param tempfile          The sorted sequence will be written into this file.
656
654
 
666
664
{
667
665
  size_t sort_length, rec_length;
668
666
  unsigned char **end;
669
 
  buffpek_st buffpek;
 
667
  buffpek buffpek;
670
668
 
671
669
  sort_length= param->sort_length;
672
670
  rec_length= param->rec_length;
676
674
                       MYF(MY_WME)))
677
675
    goto err;
678
676
  /* check we won't have more buffpeks than we can possibly keep in memory */
679
 
  if (my_b_tell(buffpek_pointers) + sizeof(buffpek_st) > (uint64_t)UINT_MAX)
 
677
  if (my_b_tell(buffpek_pointers) + sizeof(buffpek) > (uint64_t)UINT_MAX)
680
678
    goto err;
681
679
  buffpek.file_pos= my_b_tell(tempfile);
682
680
  if ((ha_rows) count > param->max_rows)
911
909
      In this implementation we use fixed layout for field values -
912
910
      the same for all records.
913
911
    */
914
 
    sort_addon_field_st *addonf= param->addon_field;
 
912
    sort_addon_field *addonf= param->addon_field;
915
913
    unsigned char *nulls= to;
916
914
    assert(addonf != 0);
917
915
    memset(nulls, 0, addonf->offset);
977
975
 
978
976
  if (param->addon_field)
979
977
  {
980
 
    sort_addon_field_st *addonf= param->addon_field;
 
978
    sort_addon_field *addonf= param->addon_field;
981
979
    Field *field;
982
980
    for ( ; (field= addonf->field) ; addonf++)
983
981
      table->setReadSet(field->field_index);
991
989
 
992
990
 
993
991
static bool save_index(SORTPARAM *param, unsigned char **sort_keys, uint32_t count,
994
 
                       filesort_info_st *table_sort)
 
992
                       filesort_info *table_sort)
995
993
{
996
994
  uint32_t offset,res_length;
997
995
  unsigned char *to;
1016
1014
/** Merge buffers to make < MERGEBUFF2 buffers. */
1017
1015
 
1018
1016
int merge_many_buff(SORTPARAM *param, unsigned char *sort_buffer,
1019
 
                    buffpek_st *buffpek, uint32_t *maxbuffer, internal::IO_CACHE *t_file)
 
1017
                    buffpek *buffpek_inst, uint32_t *maxbuffer, internal::IO_CACHE *t_file)
1020
1018
{
1021
1019
  register uint32_t i;
1022
1020
  internal::IO_CACHE t_file2,*from_file,*to_file,*temp;
1023
 
  buffpek_st *lastbuff;
 
1021
  buffpek *lastbuff;
1024
1022
 
1025
1023
  if (*maxbuffer < MERGEBUFF2)
1026
1024
    return(0);
1036
1034
      goto cleanup;
1037
1035
    if (reinit_io_cache(to_file,internal::WRITE_CACHE,0L,0,0))
1038
1036
      goto cleanup;
1039
 
    lastbuff=buffpek;
 
1037
    lastbuff=buffpek_inst;
1040
1038
    for (i=0 ; i <= *maxbuffer-MERGEBUFF*3/2 ; i+=MERGEBUFF)
1041
1039
    {
1042
1040
      if (merge_buffers(param,from_file,to_file,sort_buffer,lastbuff++,
1043
 
                        buffpek+i,buffpek+i+MERGEBUFF-1,0))
 
1041
                        buffpek_inst+i,buffpek_inst+i+MERGEBUFF-1,0))
1044
1042
      goto cleanup;
1045
1043
    }
1046
1044
    if (merge_buffers(param,from_file,to_file,sort_buffer,lastbuff++,
1047
 
                      buffpek+i,buffpek+ *maxbuffer,0))
 
1045
                      buffpek_inst+i,buffpek_inst+ *maxbuffer,0))
1048
1046
      break;
1049
1047
    if (flush_io_cache(to_file))
1050
1048
      break;
1051
1049
    temp=from_file; from_file=to_file; to_file=temp;
1052
1050
    setup_io_cache(from_file);
1053
1051
    setup_io_cache(to_file);
1054
 
    *maxbuffer= (uint32_t) (lastbuff-buffpek)-1;
 
1052
    *maxbuffer= (uint32_t) (lastbuff-buffpek_inst)-1;
1055
1053
  }
1056
1054
cleanup:
1057
1055
  close_cached_file(to_file);                   // This holds old result
1072
1070
    (uint32_t)-1 if something goes wrong
1073
1071
*/
1074
1072
 
1075
 
uint32_t read_to_buffer(internal::IO_CACHE *fromfile, buffpek_st *buffpek,
 
1073
uint32_t read_to_buffer(internal::IO_CACHE *fromfile, buffpek *buffpek_inst,
1076
1074
                        uint32_t rec_length)
1077
1075
{
1078
1076
  register uint32_t count;
1079
1077
  uint32_t length;
1080
1078
 
1081
 
  if ((count= (uint32_t) min((ha_rows) buffpek->max_keys,buffpek->count)))
 
1079
  if ((count= (uint32_t) min((ha_rows) buffpek_inst->max_keys,buffpek_inst->count)))
1082
1080
  {
1083
 
    if (pread(fromfile->file,(unsigned char*) buffpek->base, (length= rec_length*count),buffpek->file_pos) == 0)
 
1081
    if (pread(fromfile->file,(unsigned char*) buffpek_inst->base, (length= rec_length*count),buffpek_inst->file_pos) == 0)
1084
1082
      return((uint32_t) -1);
1085
1083
 
1086
 
    buffpek->key= buffpek->base;
1087
 
    buffpek->file_pos+= length;                 /* New filepos */
1088
 
    buffpek->count-= count;
1089
 
    buffpek->mem_count= count;
 
1084
    buffpek_inst->key= buffpek_inst->base;
 
1085
    buffpek_inst->file_pos+= length;                    /* New filepos */
 
1086
    buffpek_inst->count-= count;
 
1087
    buffpek_inst->mem_count= count;
1090
1088
  }
1091
1089
  return (count*rec_length);
1092
1090
} /* read_to_buffer */
1099
1097
  public:
1100
1098
  compare_functor(qsort2_cmp in_key_compare, void *in_compare_arg)
1101
1099
    : key_compare(in_key_compare), key_compare_arg(in_compare_arg) { }
1102
 
  inline bool operator()(const buffpek_st *i, const buffpek_st *j) const
 
1100
  inline bool operator()(const buffpek *i, const buffpek *j) const
1103
1101
  {
1104
1102
    int val= key_compare(key_compare_arg,
1105
1103
                      &i->key, &j->key);
1112
1110
  Merge buffers to one buffer.
1113
1111
 
1114
1112
  @param param        Sort parameter
1115
 
  @param from_file    File with source data (buffpek_sts point to this file)
 
1113
  @param from_file    File with source data (buffpeks point to this file)
1116
1114
  @param to_file      File to write the sorted result data.
1117
1115
  @param sort_buffer  Buffer for data to store up to MERGEBUFF2 sort keys.
1118
 
  @param lastbuff     OUT Store here buffpek_st describing data written to to_file
1119
 
  @param Fb           First element in source buffpek_sts array
1120
 
  @param Tb           Last element in source buffpek_sts array
 
1116
  @param lastbuff     OUT Store here buffpek describing data written to to_file
 
1117
  @param Fb           First element in source buffpeks array
 
1118
  @param Tb           Last element in source buffpeks array
1121
1119
  @param flag
1122
1120
 
1123
1121
  @retval
1128
1126
 
1129
1127
int merge_buffers(SORTPARAM *param, internal::IO_CACHE *from_file,
1130
1128
                  internal::IO_CACHE *to_file, unsigned char *sort_buffer,
1131
 
                  buffpek_st *lastbuff, buffpek_st *Fb, buffpek_st *Tb,
 
1129
                  buffpek *lastbuff, buffpek *Fb, buffpek *Tb,
1132
1130
                  int flag)
1133
1131
{
1134
1132
  int error;
1138
1136
  ha_rows max_rows,org_max_rows;
1139
1137
  internal::my_off_t to_start_filepos;
1140
1138
  unsigned char *strpos;
1141
 
  buffpek_st *buffpek;
 
1139
  buffpek *buffpek_inst;
1142
1140
  qsort2_cmp cmp;
1143
1141
  void *first_cmp_arg;
1144
1142
  volatile Session::killed_state *killed= &current_session->killed;
1174
1172
    cmp= internal::get_ptr_compare(sort_length);
1175
1173
    first_cmp_arg= (void*) &sort_length;
1176
1174
  }
1177
 
  priority_queue<buffpek_st *, vector<buffpek_st *>, compare_functor > 
 
1175
  priority_queue<buffpek *, vector<buffpek *>, compare_functor >
1178
1176
    queue(compare_functor(cmp, first_cmp_arg));
1179
 
  for (buffpek= Fb ; buffpek <= Tb ; buffpek++)
 
1177
  for (buffpek_inst= Fb ; buffpek_inst <= Tb ; buffpek_inst++)
1180
1178
  {
1181
 
    buffpek->base= strpos;
1182
 
    buffpek->max_keys= maxcount;
1183
 
    strpos+= (uint32_t) (error= (int) read_to_buffer(from_file, buffpek,
 
1179
    buffpek_inst->base= strpos;
 
1180
    buffpek_inst->max_keys= maxcount;
 
1181
    strpos+= (uint32_t) (error= (int) read_to_buffer(from_file, buffpek_inst,
1184
1182
                                                                         rec_length));
1185
1183
    if (error == -1)
1186
1184
      goto err;
1187
 
    buffpek->max_keys= buffpek->mem_count;      // If less data in buffers than expected
1188
 
    queue.push(buffpek);
 
1185
    buffpek_inst->max_keys= buffpek_inst->mem_count;    // If less data in buffers than expected
 
1186
    queue.push(buffpek_inst);
1189
1187
  }
1190
1188
 
1191
1189
  if (param->unique_buff)
1198
1196
       This is safe as we know that there is always more than one element
1199
1197
       in each block to merge (This is guaranteed by the Unique:: algorithm
1200
1198
    */
1201
 
    buffpek= queue.top();
1202
 
    memcpy(param->unique_buff, buffpek->key, rec_length);
1203
 
    if (my_b_write(to_file, (unsigned char*) buffpek->key, rec_length))
 
1199
    buffpek_inst= queue.top();
 
1200
    memcpy(param->unique_buff, buffpek_inst->key, rec_length);
 
1201
    if (my_b_write(to_file, (unsigned char*) buffpek_inst->key, rec_length))
1204
1202
    {
1205
1203
      error=1; goto err;
1206
1204
    }
1207
 
    buffpek->key+= rec_length;
1208
 
    buffpek->mem_count--;
 
1205
    buffpek_inst->key+= rec_length;
 
1206
    buffpek_inst->mem_count--;
1209
1207
    if (!--max_rows)
1210
1208
    {
1211
1209
      error= 0;
1213
1211
    }
1214
1212
    /* Top element has been used */
1215
1213
    queue.pop();
1216
 
    queue.push(buffpek);
 
1214
    queue.push(buffpek_inst);
1217
1215
  }
1218
1216
  else
1219
1217
    cmp= 0;                                        // Not unique
1226
1224
    }
1227
1225
    for (;;)
1228
1226
    {
1229
 
      buffpek= queue.top();
 
1227
      buffpek_inst= queue.top();
1230
1228
      if (cmp)                                        // Remove duplicates
1231
1229
      {
1232
1230
        if (!(*cmp)(first_cmp_arg, &(param->unique_buff),
1233
 
                    (unsigned char**) &buffpek->key))
 
1231
                    (unsigned char**) &buffpek_inst->key))
1234
1232
              goto skip_duplicate;
1235
 
            memcpy(param->unique_buff, buffpek->key, rec_length);
 
1233
            memcpy(param->unique_buff, buffpek_inst->key, rec_length);
1236
1234
      }
1237
1235
      if (flag == 0)
1238
1236
      {
1239
 
        if (my_b_write(to_file,(unsigned char*) buffpek->key, rec_length))
 
1237
        if (my_b_write(to_file,(unsigned char*) buffpek_inst->key, rec_length))
1240
1238
        {
1241
1239
          error=1; goto err;
1242
1240
        }
1243
1241
      }
1244
1242
      else
1245
1243
      {
1246
 
        if (my_b_write(to_file, (unsigned char*) buffpek->key+offset, res_length))
 
1244
        if (my_b_write(to_file, (unsigned char*) buffpek_inst->key+offset, res_length))
1247
1245
        {
1248
1246
          error=1; goto err;
1249
1247
        }
1255
1253
      }
1256
1254
 
1257
1255
    skip_duplicate:
1258
 
      buffpek->key+= rec_length;
1259
 
      if (! --buffpek->mem_count)
 
1256
      buffpek_inst->key+= rec_length;
 
1257
      if (! --buffpek_inst->mem_count)
1260
1258
      {
1261
 
        if (!(error= (int) read_to_buffer(from_file,buffpek,
 
1259
        if (!(error= (int) read_to_buffer(from_file,buffpek_inst,
1262
1260
                                          rec_length)))
1263
1261
        {
1264
1262
          queue.pop();
1269
1267
      }
1270
1268
      /* Top element has been replaced */
1271
1269
      queue.pop();
1272
 
      queue.push(buffpek);
 
1270
      queue.push(buffpek_inst);
1273
1271
    }
1274
1272
  }
1275
 
  buffpek= queue.top();
1276
 
  buffpek->base= sort_buffer;
1277
 
  buffpek->max_keys= param->keys;
 
1273
  buffpek_inst= queue.top();
 
1274
  buffpek_inst->base= sort_buffer;
 
1275
  buffpek_inst->max_keys= param->keys;
1278
1276
 
1279
1277
  /*
1280
1278
    As we know all entries in the buffer are unique, we only have to
1282
1280
  */
1283
1281
  if (cmp)
1284
1282
  {
1285
 
    if (!(*cmp)(first_cmp_arg, &(param->unique_buff), (unsigned char**) &buffpek->key))
 
1283
    if (!(*cmp)(first_cmp_arg, &(param->unique_buff), (unsigned char**) &buffpek_inst->key))
1286
1284
    {
1287
 
      buffpek->key+= rec_length;         // Remove duplicate
1288
 
      --buffpek->mem_count;
 
1285
      buffpek_inst->key+= rec_length;         // Remove duplicate
 
1286
      --buffpek_inst->mem_count;
1289
1287
    }
1290
1288
  }
1291
1289
 
1292
1290
  do
1293
1291
  {
1294
 
    if ((ha_rows) buffpek->mem_count > max_rows)
 
1292
    if ((ha_rows) buffpek_inst->mem_count > max_rows)
1295
1293
    {                                        /* Don't write too many records */
1296
 
      buffpek->mem_count= (uint32_t) max_rows;
1297
 
      buffpek->count= 0;                        /* Don't read more */
 
1294
      buffpek_inst->mem_count= (uint32_t) max_rows;
 
1295
      buffpek_inst->count= 0;                        /* Don't read more */
1298
1296
    }
1299
 
    max_rows-= buffpek->mem_count;
 
1297
    max_rows-= buffpek_inst->mem_count;
1300
1298
    if (flag == 0)
1301
1299
    {
1302
 
      if (my_b_write(to_file,(unsigned char*) buffpek->key,
1303
 
                     (rec_length*buffpek->mem_count)))
 
1300
      if (my_b_write(to_file,(unsigned char*) buffpek_inst->key,
 
1301
                     (rec_length*buffpek_inst->mem_count)))
1304
1302
      {
1305
1303
        error= 1; goto err;
1306
1304
      }
1308
1306
    else
1309
1307
    {
1310
1308
      register unsigned char *end;
1311
 
      strpos= buffpek->key+offset;
1312
 
      for (end= strpos+buffpek->mem_count*rec_length ;
 
1309
      strpos= buffpek_inst->key+offset;
 
1310
      for (end= strpos+buffpek_inst->mem_count*rec_length ;
1313
1311
           strpos != end ;
1314
1312
           strpos+= rec_length)
1315
1313
      {
1320
1318
      }
1321
1319
    }
1322
1320
  }
1323
 
  while ((error=(int) read_to_buffer(from_file,buffpek, rec_length))
 
1321
  while ((error=(int) read_to_buffer(from_file,buffpek_inst, rec_length))
1324
1322
         != -1 && error != 0);
1325
1323
 
1326
1324
end:
1334
1332
        /* Do a merge to output-file (save only positions) */
1335
1333
 
1336
1334
static int merge_index(SORTPARAM *param, unsigned char *sort_buffer,
1337
 
                       buffpek_st *buffpek, uint32_t maxbuffer,
 
1335
                       buffpek *buffpek_inst, uint32_t maxbuffer,
1338
1336
                       internal::IO_CACHE *tempfile, internal::IO_CACHE *outfile)
1339
1337
{
1340
 
  if (merge_buffers(param,tempfile,outfile,sort_buffer,buffpek,buffpek,
1341
 
                    buffpek+maxbuffer,1))
 
1338
  if (merge_buffers(param,tempfile,outfile,sort_buffer,buffpek_inst,buffpek_inst,
 
1339
                    buffpek_inst+maxbuffer,1))
1342
1340
    return(1);
1343
1341
  return(0);
1344
1342
} /* merge_index */
1482
1480
    NULL   if we do not store field values with sort data.
1483
1481
*/
1484
1482
 
1485
 
static sort_addon_field_st *
 
1483
static sort_addon_field *
1486
1484
get_addon_fields(Session *session, Field **ptabfield, uint32_t sortlength, uint32_t *plength)
1487
1485
{
1488
1486
  Field **pfield;
1489
1487
  Field *field;
1490
 
  sort_addon_field_st *addonf;
 
1488
  sort_addon_field *addonf;
1491
1489
  uint32_t length= 0;
1492
1490
  uint32_t fields= 0;
1493
1491
  uint32_t null_fields= 0;
1519
1517
  length+= (null_fields+7)/8;
1520
1518
 
1521
1519
  if (length+sortlength > session->variables.max_length_for_sort_data ||
1522
 
      !(addonf= (sort_addon_field_st *) malloc(sizeof(sort_addon_field_st)*
 
1520
      !(addonf= (sort_addon_field *) malloc(sizeof(sort_addon_field)*
1523
1521
                                            (fields+1))))
1524
1522
    return 0;
1525
1523
 
1569
1567
*/
1570
1568
 
1571
1569
static void
1572
 
unpack_addon_fields(struct sort_addon_field_st *addon_field, unsigned char *buff)
 
1570
unpack_addon_fields(struct sort_addon_field *addon_field, unsigned char *buff)
1573
1571
{
1574
1572
  Field *field;
1575
 
  sort_addon_field_st *addonf= addon_field;
 
1573
  sort_addon_field *addonf= addon_field;
1576
1574
 
1577
1575
  for ( ; (field= addonf->field) ; addonf++)
1578
1576
  {