~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/filesort.cc

  • Committer: Eric Herman
  • Date: 2008-12-06 19:42:46 UTC
  • mto: (656.1.6 devel)
  • mto: This revision was merged to the branch mainline in revision 665.
  • Revision ID: eric@mysql.com-20081206194246-5cdexuu81i366eek
removed trailing whitespace with simple script:

for file in $(find . -name "*.c") $(find . -name "*.cc") $(find . -name "*.h"); do ruby -pe 'gsub(/\s+$/, $/)' < $file > $file.out; mv $file.out $file; done;

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000-2006 MySQL AB  
 
1
/* Copyright (C) 2000-2006 MySQL AB
2
2
 
3
3
   This program is free software; you can redistribute it and/or modify
4
4
   it under the terms of the GNU General Public License as published by
46
46
                       BUFFPEK *buffpek,
47
47
                       uint32_t maxbuffer,IO_CACHE *tempfile,
48
48
                       IO_CACHE *outfile);
49
 
static bool save_index(SORTPARAM *param,unsigned char **sort_keys, uint32_t count, 
 
49
static bool save_index(SORTPARAM *param,unsigned char **sort_keys, uint32_t count,
50
50
                       filesort_info_st *table_sort);
51
51
static uint32_t suffix_length(uint32_t string_length);
52
52
static uint32_t sortlength(Session *session, SORT_FIELD *sortorder, uint32_t s_length,
101
101
  BUFFPEK *buffpek;
102
102
  ha_rows records= HA_POS_ERROR;
103
103
  unsigned char **sort_keys= 0;
104
 
  IO_CACHE tempfile, buffpek_pointers, *selected_records_file, *outfile; 
 
104
  IO_CACHE tempfile, buffpek_pointers, *selected_records_file, *outfile;
105
105
  SORTPARAM param;
106
106
  bool multi_byte_charset;
107
107
 
117
117
  */
118
118
  ha_release_temporary_latches(session);
119
119
 
120
 
  /* 
121
 
    Don't use table->sort in filesort as it is also used by 
122
 
    QUICK_INDEX_MERGE_SELECT. Work with a copy and put it back at the end 
 
120
  /*
 
121
    Don't use table->sort in filesort as it is also used by
 
122
    QUICK_INDEX_MERGE_SELECT. Work with a copy and put it back at the end
123
123
    when index_merge select has finished with it.
124
124
  */
125
125
  memcpy(&table_sort, &table->sort, sizeof(filesort_info_st));
126
126
  table->sort.io_cache= NULL;
127
 
  
 
127
 
128
128
  outfile= table_sort.io_cache;
129
129
  my_b_clear(&tempfile);
130
130
  my_b_clear(&buffpek_pointers);
137
137
  param.addon_length= 0;
138
138
  if (!(table->file->ha_table_flags() & HA_FAST_KEY_READ) && !sort_positions)
139
139
  {
140
 
    /* 
141
 
      Get the descriptors of all fields whose values are appended 
 
140
    /*
 
141
      Get the descriptors of all fields whose values are appended
142
142
      to sorted fields and get its total length in param.spack_length.
143
143
    */
144
 
    param.addon_field= get_addon_fields(session, table->field, 
 
144
    param.addon_field= get_addon_fields(session, table->field,
145
145
                                        param.sort_length,
146
146
                                        &param.addon_length);
147
147
  }
159
159
  else
160
160
  {
161
161
    param.res_length= param.ref_length;
162
 
    /* 
163
 
      The reference to the record is considered 
 
162
    /*
 
163
      The reference to the record is considered
164
164
      as an additional sorted field
165
165
    */
166
166
    param.sort_length+= param.ref_length;
188
188
  {
189
189
    records= table->file->estimate_rows_upper_bound();
190
190
    /*
191
 
      If number of records is not known, use as much of sort buffer 
192
 
      as possible. 
 
191
      If number of records is not known, use as much of sort buffer
 
192
      as possible.
193
193
    */
194
194
    if (records == HA_POS_ERROR)
195
195
      records--;  // we use 'records+1' below.
579
579
 
580
580
  if (session->is_error())
581
581
    return(HA_POS_ERROR);
582
 
  
 
582
 
583
583
  /* Signal we should use orignal column read and write maps */
584
584
  sort_form->column_bitmaps_set(save_read_set, save_write_set);
585
585
 
814
814
          if (maybe_null)
815
815
          {
816
816
            if (item->null_value)
817
 
            { 
 
817
            {
818
818
              memset(to, 0, sort_field->length+1);
819
819
              to++;
820
820
              break;
843
843
          break;
844
844
        }
845
845
      case ROW_RESULT:
846
 
      default: 
 
846
      default:
847
847
        // This case should never be choosen
848
848
        assert(0);
849
849
        break;
866
866
 
867
867
  if (param->addon_field)
868
868
  {
869
 
    /* 
 
869
    /*
870
870
      Save field values appended to sorted fields.
871
871
      First null bit indicators are appended then field values follow.
872
872
      In this implementation we use fixed layout for field values -
952
952
}
953
953
 
954
954
 
955
 
static bool save_index(SORTPARAM *param, unsigned char **sort_keys, uint32_t count, 
 
955
static bool save_index(SORTPARAM *param, unsigned char **sort_keys, uint32_t count,
956
956
                       filesort_info_st *table_sort)
957
957
{
958
958
  uint32_t offset,res_length;
963
963
  offset= param->rec_length-res_length;
964
964
  if ((ha_rows) count > param->max_rows)
965
965
    count=(uint32_t) param->max_rows;
966
 
  if (!(to= table_sort->record_pointers= 
 
966
  if (!(to= table_sort->record_pointers=
967
967
        (unsigned char*) malloc(res_length*count)))
968
968
    return(1);                 /* purecov: inspected */
969
969
  for (unsigned char **end= sort_keys+count ; sort_keys != end ; sort_keys++)
1142
1142
 
1143
1143
  /* The following will fire if there is not enough space in sort_buffer */
1144
1144
  assert(maxcount!=0);
1145
 
  
 
1145
 
1146
1146
  if (param->unique_buff)
1147
1147
  {
1148
1148
    cmp= param->compare;
1170
1170
 
1171
1171
  if (param->unique_buff)
1172
1172
  {
1173
 
    /* 
 
1173
    /*
1174
1174
       Called by Unique::get()
1175
1175
       Copy the first argument to param->unique_buff for unique removal.
1176
1176
       Store it also in 'to_file'.
1289
1289
      for (end= strpos+buffpek->mem_count*rec_length ;
1290
1290
           strpos != end ;
1291
1291
           strpos+= rec_length)
1292
 
      {     
 
1292
      {
1293
1293
        if (my_b_write(to_file, (unsigned char *) strpos, res_length))
1294
1294
        {
1295
 
          error=1; goto err;                        
 
1295
          error=1; goto err;
1296
1296
        }
1297
1297
      }
1298
1298
    }
1390
1390
        sortorder->length=sortorder->item->max_length;
1391
1391
        set_if_smaller(sortorder->length, session->variables.max_sort_length);
1392
1392
        if (use_strnxfrm((cs=sortorder->item->collation.collation)))
1393
 
        { 
 
1393
        {
1394
1394
          sortorder->length= cs->coll->strnxfrmlen(cs, sortorder->length);
1395
1395
          sortorder->need_strxnfrm= 1;
1396
1396
          *multi_byte_charset= 1;
1407
1407
        break;
1408
1408
      case DECIMAL_RESULT:
1409
1409
        sortorder->length=
1410
 
          my_decimal_get_binary_size(sortorder->item->max_length - 
 
1410
          my_decimal_get_binary_size(sortorder->item->max_length -
1411
1411
                                     (sortorder->item->decimals ? 1 : 0),
1412
1412
                                     sortorder->item->decimals);
1413
1413
        break;
1415
1415
        sortorder->length=sizeof(double);
1416
1416
        break;
1417
1417
      case ROW_RESULT:
1418
 
      default: 
 
1418
      default:
1419
1419
        // This case should never be choosen
1420
1420
        assert(0);
1421
1421
        break;
1437
1437
 
1438
1438
  The function first finds out what fields are used in the result set.
1439
1439
  Then it calculates the length of the buffer to store the values of
1440
 
  these fields together with the value of sort values. 
 
1440
  these fields together with the value of sort values.
1441
1441
  If the calculated length is not greater than max_length_for_sort_data
1442
1442
  the function allocates memory for an array of descriptors containing
1443
1443
  layouts for the values of the non-sorted fields in the buffer and
1475
1475
    Note for future refinement:
1476
1476
    This this a too strong condition.
1477
1477
    Actually we need only the fields referred in the
1478
 
    result set. And for some of them it makes sense to use 
 
1478
    result set. And for some of them it makes sense to use
1479
1479
    the values directly from sorted fields.
1480
1480
  */
1481
1481
  *plength= 0;
1490
1490
    if (field->maybe_null())
1491
1491
      null_fields++;
1492
1492
    fields++;
1493
 
  } 
 
1493
  }
1494
1494
  if (!fields)
1495
1495
    return 0;
1496
1496
  length+= (null_fields+7)/8;
1525
1525
    addonf++;
1526
1526
  }
1527
1527
  addonf->field= 0;     // Put end marker
1528
 
  
 
1528
 
1529
1529
  return (addonf-fields);
1530
1530
}
1531
1531
 
1545
1545
    void.
1546
1546
*/
1547
1547
 
1548
 
static void 
 
1548
static void
1549
1549
unpack_addon_fields(struct st_sort_addon_field *addon_field, unsigned char *buff)
1550
1550
{
1551
1551
  Field *field;