~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/sum.cc

Merge Joe, plus I updated the tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
 
17
17
/**
33
33
#include <drizzled/item/sum.h>
34
34
#include <drizzled/field/decimal.h>
35
35
#include <drizzled/field/double.h>
36
 
#include <drizzled/field/int64.h>
 
36
#include <drizzled/field/int64_t.h>
37
37
#include <drizzled/field/date.h>
38
38
#include <drizzled/field/datetime.h>
39
39
 
40
 
#include <drizzled/type/decimal.h>
41
 
 
42
40
#include "drizzled/internal/m_string.h"
43
41
 
44
42
#include <algorithm>
48
46
namespace drizzled
49
47
{
50
48
 
 
49
extern my_decimal decimal_zero;
51
50
extern plugin::StorageEngine *heap_engine;
52
51
 
53
52
/**
412
411
  if (arg_count <= 2)
413
412
    args=tmp_args;
414
413
  else
415
 
    if (!(args= (Item**) session->getMemRoot()->allocate(sizeof(Item*)*arg_count)))
 
414
    if (!(args= (Item**) session->alloc(sizeof(Item*)*arg_count)))
416
415
      return;
417
416
  memcpy(args, item->args, sizeof(Item*)*arg_count);
418
417
}
420
419
 
421
420
void Item_sum::mark_as_sum_func()
422
421
{
423
 
  Select_Lex *cur_select= getSession().getLex()->current_select;
 
422
  Select_Lex *cur_select= current_session->lex->current_select;
424
423
  cur_select->n_sum_items++;
425
424
  cur_select->with_sum_func= 1;
426
425
  with_sum_func= 1;
509
508
                                  Table *table,
510
509
                                  uint32_t convert_blob_length)
511
510
{
512
 
  Field *field= NULL;
513
 
 
 
511
  Field *field;
514
512
  switch (result_type()) {
515
513
  case REAL_RESULT:
516
514
    field= new Field_double(max_length, maybe_null, name, decimals, true);
517
515
    break;
518
 
 
519
516
  case INT_RESULT:
520
 
    field= new field::Int64(max_length, maybe_null, name, unsigned_flag);
 
517
    field= new Field_int64_t(max_length, maybe_null, name, unsigned_flag);
521
518
    break;
522
 
 
523
519
  case STRING_RESULT:
524
520
    if (max_length/collation.collation->mbmaxlen <= 255 ||
525
521
        convert_blob_length > Field_varstring::MAX_SIZE ||
526
522
        !convert_blob_length)
527
 
    {
528
523
      return make_string_field(table);
529
 
    }
530
 
 
531
 
    table->setVariableWidth();
532
524
    field= new Field_varstring(convert_blob_length, maybe_null,
533
 
                               name, collation.collation);
 
525
                               name, table->getMutableShare(), collation.collation);
534
526
    break;
535
 
 
536
527
  case DECIMAL_RESULT:
537
528
    field= new Field_decimal(max_length, maybe_null, name,
538
 
                             decimals, unsigned_flag);
 
529
                                 decimals, unsigned_flag);
539
530
    break;
540
 
 
541
531
  case ROW_RESULT:
 
532
  default:
542
533
    // This case should never be choosen
543
534
    assert(0);
544
535
    return 0;
545
536
  }
546
 
 
547
537
  if (field)
548
538
    field->init(table);
549
 
 
550
539
  return field;
551
540
}
552
541
 
584
573
}
585
574
 
586
575
 
587
 
type::Decimal *Item_sum_num::val_decimal(type::Decimal *decimal_value)
 
576
my_decimal *Item_sum_num::val_decimal(my_decimal *decimal_value)
588
577
{
589
578
  return val_decimal_from_real(decimal_value);
590
579
}
597
586
}
598
587
 
599
588
 
600
 
type::Decimal *Item_sum_int::val_decimal(type::Decimal *decimal_value)
 
589
my_decimal *Item_sum_int::val_decimal(my_decimal *decimal_value)
601
590
{
602
591
  return val_decimal_from_int(decimal_value);
603
592
}
644
633
    sum_int= item->sum_int;
645
634
    break;
646
635
  case DECIMAL_RESULT:
647
 
    class_decimal2decimal(&item->sum_dec, &sum_dec);
 
636
    my_decimal2decimal(&item->sum_dec, &sum_dec);
648
637
    break;
649
638
  case REAL_RESULT:
650
639
    sum= item->sum;
656
645
    */
657
646
    break;
658
647
  case ROW_RESULT:
 
648
  default:
659
649
    assert(0);
660
650
  }
661
651
  collation.set(item->collation);
684
674
    break;
685
675
  case DECIMAL_RESULT:
686
676
    max_length= item->max_length;
687
 
    sum_dec.set_zero();
 
677
    my_decimal_set_zero(&sum_dec);
688
678
    break;
689
679
  case REAL_RESULT:
690
680
    max_length= float_length(decimals);
694
684
    max_length= item->max_length;
695
685
    break;
696
686
  case ROW_RESULT:
 
687
  default:
697
688
    assert(0);
698
689
  };
699
690
  /* MIN/MAX can return NULL for empty set indepedent of the used column */
724
715
  {
725
716
    field= ((Item_field*) args[0])->field;
726
717
 
727
 
    if ((field= create_tmp_field_from_field(&getSession(), field, name, table,
 
718
    if ((field= create_tmp_field_from_field(current_session, field, name, table,
728
719
                                            NULL, convert_blob_length)))
729
720
      field->flags&= ~NOT_NULL_FLAG;
730
721
    return field;
745
736
  default:
746
737
    return Item_sum::create_tmp_field(group, table, convert_blob_length);
747
738
  }
748
 
 
749
739
  if (field)
750
740
    field->init(table);
751
 
 
752
741
  return field;
753
742
}
754
743
 
768
757
  /* TODO: check if the following assignments are really needed */
769
758
  if (hybrid_type == DECIMAL_RESULT)
770
759
  {
771
 
    class_decimal2decimal(item->dec_buffs, dec_buffs);
772
 
    class_decimal2decimal(item->dec_buffs + 1, dec_buffs + 1);
 
760
    my_decimal2decimal(item->dec_buffs, dec_buffs);
 
761
    my_decimal2decimal(item->dec_buffs + 1, dec_buffs + 1);
773
762
  }
774
763
  else
775
764
    sum= item->sum;
787
776
  if (hybrid_type == DECIMAL_RESULT)
788
777
  {
789
778
    curr_dec_buff= 0;
790
 
    dec_buffs->set_zero();
 
779
    my_decimal_set_zero(dec_buffs);
791
780
  }
792
781
  else
793
782
    sum= 0.0;
807
796
    break;
808
797
  case INT_RESULT:
809
798
  case DECIMAL_RESULT:
810
 
    {
811
 
      /* SUM result can't be longer than length(arg) + length(MAX_ROWS) */
812
 
      int precision= args[0]->decimal_precision() + DECIMAL_LONGLONG_DIGITS;
813
 
      max_length= class_decimal_precision_to_length(precision, decimals,
814
 
                                                 unsigned_flag);
815
 
      curr_dec_buff= 0;
816
 
      hybrid_type= DECIMAL_RESULT;
817
 
      dec_buffs->set_zero();
818
 
      break;
819
 
    }
 
799
  {
 
800
    /* SUM result can't be longer than length(arg) + length(MAX_ROWS) */
 
801
    int precision= args[0]->decimal_precision() + DECIMAL_LONGLONG_DIGITS;
 
802
    max_length= my_decimal_precision_to_length(precision, decimals,
 
803
                                               unsigned_flag);
 
804
    curr_dec_buff= 0;
 
805
    hybrid_type= DECIMAL_RESULT;
 
806
    my_decimal_set_zero(dec_buffs);
 
807
    break;
 
808
  }
820
809
  case ROW_RESULT:
 
810
  default:
821
811
    assert(0);
822
812
  }
 
813
  return;
823
814
}
824
815
 
825
816
 
827
818
{
828
819
  if (hybrid_type == DECIMAL_RESULT)
829
820
  {
830
 
    type::Decimal value, *val= args[0]->val_decimal(&value);
 
821
    my_decimal value, *val= args[0]->val_decimal(&value);
831
822
    if (!args[0]->null_value)
832
823
    {
833
 
      class_decimal_add(E_DEC_FATAL_ERROR, dec_buffs + (curr_dec_buff^1),
 
824
      my_decimal_add(E_DEC_FATAL_ERROR, dec_buffs + (curr_dec_buff^1),
834
825
                     val, dec_buffs + curr_dec_buff);
835
826
      curr_dec_buff^= 1;
836
827
      null_value= 0;
852
843
  if (hybrid_type == DECIMAL_RESULT)
853
844
  {
854
845
    int64_t result;
855
 
    (dec_buffs + curr_dec_buff)->val_int32(E_DEC_FATAL_ERROR, unsigned_flag, &result);
 
846
    my_decimal2int(E_DEC_FATAL_ERROR, dec_buffs + curr_dec_buff, unsigned_flag,
 
847
                   &result);
856
848
    return result;
857
849
  }
858
850
  return (int64_t) rint(val_real());
863
855
{
864
856
  assert(fixed == 1);
865
857
  if (hybrid_type == DECIMAL_RESULT)
866
 
    class_decimal2double(E_DEC_FATAL_ERROR, dec_buffs + curr_dec_buff, &sum);
 
858
    my_decimal2double(E_DEC_FATAL_ERROR, dec_buffs + curr_dec_buff, &sum);
867
859
  return sum;
868
860
}
869
861
 
876
868
}
877
869
 
878
870
 
879
 
type::Decimal *Item_sum_sum::val_decimal(type::Decimal *val)
 
871
my_decimal *Item_sum_sum::val_decimal(my_decimal *val)
880
872
{
881
873
  if (hybrid_type == DECIMAL_RESULT)
882
874
    return (dec_buffs + curr_dec_buff);
939
931
 
940
932
  virtual void div(Hybrid_type *val, uint64_t u) const
941
933
  {
942
 
    int2_class_decimal(E_DEC_FATAL_ERROR, val->integer, 0, val->dec_buf);
 
934
    int2my_decimal(E_DEC_FATAL_ERROR, val->integer, 0, val->dec_buf);
943
935
    val->used_dec_buf_no= 0;
944
936
    val->traits= Hybrid_type_traits_decimal::instance();
945
937
    val->traits->div(val, u);
961
953
{
962
954
  assert(args[0]->fixed);
963
955
 
964
 
  null_value= maybe_null= true;
965
956
  table_field_type= args[0]->field_type();
966
957
 
967
958
  /* Adjust tmp table type according to the chosen aggregation type */
972
963
    table_field_type= DRIZZLE_TYPE_DOUBLE;
973
964
    break;
974
965
  case INT_RESULT:
975
 
    /*
976
 
      Preserving int8, int16, int32 field types gives ~10% performance boost
977
 
      as the size of result tree becomes significantly smaller.
978
 
      Another speed up we gain by using int64_t for intermediate
979
 
      calculations. The range of int64 is enough to hold sum 2^32 distinct
980
 
      integers each <= 2^32.
981
 
    */
982
 
    if (table_field_type == DRIZZLE_TYPE_LONG)
983
 
    {
984
 
      val.traits= Hybrid_type_traits_fast_decimal::instance();
985
 
      break;
986
 
    }
987
 
    table_field_type= DRIZZLE_TYPE_LONGLONG;
988
 
    /* fallthrough */
 
966
  /*
 
967
    Preserving int8, int16, int32 field types gives ~10% performance boost
 
968
    as the size of result tree becomes significantly smaller.
 
969
    Another speed up we gain by using int64_t for intermediate
 
970
    calculations. The range of int64 is enough to hold sum 2^32 distinct
 
971
    integers each <= 2^32.
 
972
  */
 
973
  if (table_field_type == DRIZZLE_TYPE_LONG)
 
974
  {
 
975
    val.traits= Hybrid_type_traits_fast_decimal::instance();
 
976
    break;
 
977
  }
 
978
  table_field_type= DRIZZLE_TYPE_LONGLONG;
 
979
  /* fallthrough */
989
980
  case DECIMAL_RESULT:
990
981
    val.traits= Hybrid_type_traits_decimal::instance();
991
982
    if (table_field_type != DRIZZLE_TYPE_LONGLONG)
992
983
      table_field_type= DRIZZLE_TYPE_DECIMAL;
993
984
    break;
994
985
  case ROW_RESULT:
 
986
  default:
995
987
    assert(0);
996
988
  }
997
 
 
998
989
  val.traits->fix_length_and_dec(this, args[0]);
999
990
}
1000
991
 
1033
1024
  field_def.init_for_tmp_table(table_field_type, args[0]->max_length,
1034
1025
                               args[0]->decimals, args[0]->maybe_null);
1035
1026
 
1036
 
  if (! (table= session->getInstanceTable(field_list)))
 
1027
  if (! (table= session->create_virtual_tmp_table(field_list)))
1037
1028
    return(true);
1038
1029
 
1039
1030
  /* XXX: check that the case of CHAR(0) works OK */
1133
1124
}
1134
1125
 
1135
1126
 
1136
 
type::Decimal *Item_sum_distinct::val_decimal(type::Decimal *to)
 
1127
my_decimal *Item_sum_distinct::val_decimal(my_decimal *to)
1137
1128
{
1138
1129
  calculate_val_and_count();
1139
1130
  if (null_value)
1165
1156
Item_sum_avg_distinct::fix_length_and_dec()
1166
1157
{
1167
1158
  Item_sum_distinct::fix_length_and_dec();
1168
 
  prec_increment= getSession().variables.div_precincrement;
 
1159
  prec_increment= current_session->variables.div_precincrement;
1169
1160
  /*
1170
1161
    AVG() will divide val by count. We need to reserve digits
1171
1162
    after decimal point as the result can be fractional.
1228
1219
{
1229
1220
  Item_sum_sum::fix_length_and_dec();
1230
1221
  maybe_null=null_value=1;
1231
 
  prec_increment= getSession().variables.div_precincrement;
1232
 
 
 
1222
  prec_increment= current_session->variables.div_precincrement;
1233
1223
  if (hybrid_type == DECIMAL_RESULT)
1234
1224
  {
1235
1225
    int precision= args[0]->decimal_precision() + prec_increment;
1236
1226
    decimals= min(args[0]->decimals + prec_increment, (unsigned int) DECIMAL_MAX_SCALE);
1237
 
    max_length= class_decimal_precision_to_length(precision, decimals,
 
1227
    max_length= my_decimal_precision_to_length(precision, decimals,
1238
1228
                                               unsigned_flag);
1239
1229
    f_precision= min(precision+DECIMAL_LONGLONG_DIGITS, DECIMAL_MAX_PRECISION);
1240
1230
    f_scale=  args[0]->decimals;
1241
 
    dec_bin_size= class_decimal_get_binary_size(f_precision, f_scale);
 
1231
    dec_bin_size= my_decimal_get_binary_size(f_precision, f_scale);
1242
1232
  }
1243
1233
  else {
1244
1234
    decimals= min(args[0]->decimals + prec_increment, (unsigned int) NOT_FIXED_DEC);
1264
1254
      The easiest way is to do this is to store both value in a string
1265
1255
      and unpack on access.
1266
1256
    */
1267
 
    table->setVariableWidth();
1268
1257
    field= new Field_varstring(((hybrid_type == DECIMAL_RESULT) ?
1269
1258
                                dec_bin_size : sizeof(double)) + sizeof(int64_t),
1270
 
                               0, name, &my_charset_bin);
 
1259
                               0, name, table->getMutableShare(), &my_charset_bin);
1271
1260
  }
1272
1261
  else if (hybrid_type == DECIMAL_RESULT)
1273
1262
    field= new Field_decimal(max_length, maybe_null, name,
1314
1303
}
1315
1304
 
1316
1305
 
1317
 
type::Decimal *Item_sum_avg::val_decimal(type::Decimal *val)
 
1306
my_decimal *Item_sum_avg::val_decimal(my_decimal *val)
1318
1307
{
1319
 
  type::Decimal sum_buff, cnt;
1320
 
  const type::Decimal *sum_dec;
 
1308
  my_decimal sum_buff, cnt;
 
1309
  const my_decimal *sum_dec;
1321
1310
  assert(fixed == 1);
1322
1311
  if (!count)
1323
1312
  {
1333
1322
    return val_decimal_from_real(val);
1334
1323
 
1335
1324
  sum_dec= dec_buffs + curr_dec_buff;
1336
 
  int2_class_decimal(E_DEC_FATAL_ERROR, count, 0, &cnt);
1337
 
  class_decimal_div(E_DEC_FATAL_ERROR, val, sum_dec, &cnt, prec_increment);
 
1325
  int2my_decimal(E_DEC_FATAL_ERROR, count, 0, &cnt);
 
1326
  my_decimal_div(E_DEC_FATAL_ERROR, val, sum_dec, &cnt, prec_increment);
1338
1327
  return val;
1339
1328
}
1340
1329
 
1426
1415
void Item_sum_variance::fix_length_and_dec()
1427
1416
{
1428
1417
  maybe_null= null_value= 1;
1429
 
  prec_increment= getSession().variables.div_precincrement;
 
1418
  prec_increment= current_session->variables.div_precincrement;
1430
1419
 
1431
1420
  /*
1432
1421
    According to the SQL2003 standard (Part 2, Foundations; sec 10.9,
1443
1432
    break;
1444
1433
  case INT_RESULT:
1445
1434
  case DECIMAL_RESULT:
1446
 
    {
1447
 
      int precision= args[0]->decimal_precision()*2 + prec_increment;
1448
 
      decimals= min(args[0]->decimals + prec_increment, (unsigned int) DECIMAL_MAX_SCALE);
1449
 
      max_length= class_decimal_precision_to_length(precision, decimals,
1450
 
                                                 unsigned_flag);
 
1435
  {
 
1436
    int precision= args[0]->decimal_precision()*2 + prec_increment;
 
1437
    decimals= min(args[0]->decimals + prec_increment, (unsigned int) DECIMAL_MAX_SCALE);
 
1438
    max_length= my_decimal_precision_to_length(precision, decimals,
 
1439
                                               unsigned_flag);
1451
1440
 
1452
 
      break;
1453
 
    }
 
1441
    break;
 
1442
  }
1454
1443
  case ROW_RESULT:
 
1444
  default:
1455
1445
    assert(0);
1456
1446
  }
 
1447
  return;
1457
1448
}
1458
1449
 
1459
1450
 
1479
1470
      The easiest way is to do this is to store both value in a string
1480
1471
      and unpack on access.
1481
1472
    */
1482
 
    table->setVariableWidth();
1483
 
    field= new Field_varstring(sizeof(double)*2 + sizeof(int64_t), 0, name, &my_charset_bin);
 
1473
    field= new Field_varstring(sizeof(double)*2 + sizeof(int64_t), 0, name, table->getMutableShare(), &my_charset_bin);
1484
1474
  }
1485
1475
  else
1486
1476
    field= new Field_double(max_length, maybe_null, name, decimals, true);
1542
1532
}
1543
1533
 
1544
1534
 
1545
 
type::Decimal *Item_sum_variance::val_decimal(type::Decimal *dec_buf)
 
1535
my_decimal *Item_sum_variance::val_decimal(my_decimal *dec_buf)
1546
1536
{
1547
1537
  assert(fixed == 1);
1548
1538
  return val_decimal_from_real(dec_buf);
1606
1596
    sum_int= 0;
1607
1597
    break;
1608
1598
  case DECIMAL_RESULT:
1609
 
    sum_dec.set_zero();
 
1599
    my_decimal_set_zero(&sum_dec);
1610
1600
    break;
1611
1601
  case REAL_RESULT:
1612
1602
    sum= 0.0;
1622
1612
  assert(fixed == 1);
1623
1613
  if (null_value)
1624
1614
    return 0.0;
1625
 
 
1626
1615
  switch (hybrid_type) {
1627
1616
  case STRING_RESULT:
1628
 
    {
1629
 
      char *end_not_used;
1630
 
      int err_not_used;
1631
 
      String *res;  res=val_str(&str_value);
1632
 
      return (res ? my_strntod(res->charset(), (char*) res->ptr(), res->length(),
1633
 
                               &end_not_used, &err_not_used) : 0.0);
1634
 
    }
 
1617
  {
 
1618
    char *end_not_used;
 
1619
    int err_not_used;
 
1620
    String *res;  res=val_str(&str_value);
 
1621
    return (res ? my_strntod(res->charset(), (char*) res->ptr(), res->length(),
 
1622
                             &end_not_used, &err_not_used) : 0.0);
 
1623
  }
1635
1624
  case INT_RESULT:
1636
1625
    return (double) sum_int;
1637
1626
  case DECIMAL_RESULT:
1638
 
    class_decimal2double(E_DEC_FATAL_ERROR, &sum_dec, &sum);
 
1627
    my_decimal2double(E_DEC_FATAL_ERROR, &sum_dec, &sum);
1639
1628
    return sum;
1640
1629
  case REAL_RESULT:
1641
1630
    return sum;
1642
1631
  case ROW_RESULT:
 
1632
  default:
1643
1633
    // This case should never be choosen
1644
 
    break;
 
1634
    assert(0);
 
1635
    return 0;
1645
1636
  }
1646
 
 
1647
 
  assert(0);
1648
 
  return 0;
1649
1637
}
1650
1638
 
1651
1639
int64_t Item_sum_hybrid::val_int()
1659
1647
  case DECIMAL_RESULT:
1660
1648
  {
1661
1649
    int64_t result;
1662
 
    sum_dec.val_int32(E_DEC_FATAL_ERROR, unsigned_flag, &result);
 
1650
    my_decimal2int(E_DEC_FATAL_ERROR, &sum_dec, unsigned_flag, &result);
1663
1651
    return sum_int;
1664
1652
  }
1665
1653
  default:
1668
1656
}
1669
1657
 
1670
1658
 
1671
 
type::Decimal *Item_sum_hybrid::val_decimal(type::Decimal *val)
 
1659
my_decimal *Item_sum_hybrid::val_decimal(my_decimal *val)
1672
1660
{
1673
1661
  assert(fixed == 1);
1674
1662
  if (null_value)
1675
1663
    return 0;
1676
 
 
1677
1664
  switch (hybrid_type) {
1678
1665
  case STRING_RESULT:
1679
 
    val->store(E_DEC_FATAL_ERROR, &value);
 
1666
    string2my_decimal(E_DEC_FATAL_ERROR, &value, val);
1680
1667
    break;
1681
1668
  case REAL_RESULT:
1682
 
    double2_class_decimal(E_DEC_FATAL_ERROR, sum, val);
 
1669
    double2my_decimal(E_DEC_FATAL_ERROR, sum, val);
1683
1670
    break;
1684
1671
  case DECIMAL_RESULT:
1685
1672
    val= &sum_dec;
1686
1673
    break;
1687
1674
  case INT_RESULT:
1688
 
    int2_class_decimal(E_DEC_FATAL_ERROR, sum_int, unsigned_flag, val);
 
1675
    int2my_decimal(E_DEC_FATAL_ERROR, sum_int, unsigned_flag, val);
1689
1676
    break;
1690
1677
  case ROW_RESULT:
 
1678
  default:
1691
1679
    // This case should never be choosen
1692
1680
    assert(0);
1693
1681
    break;
1694
1682
  }
1695
 
 
1696
1683
  return val;                                   // Keep compiler happy
1697
1684
}
1698
1685
 
1703
1690
  assert(fixed == 1);
1704
1691
  if (null_value)
1705
1692
    return 0;
1706
 
 
1707
1693
  switch (hybrid_type) {
1708
1694
  case STRING_RESULT:
1709
1695
    return &value;
1711
1697
    str->set_real(sum,decimals, &my_charset_bin);
1712
1698
    break;
1713
1699
  case DECIMAL_RESULT:
1714
 
    class_decimal2string(&sum_dec, 0, str);
 
1700
    my_decimal2string(E_DEC_FATAL_ERROR, &sum_dec, 0, 0, 0, str);
1715
1701
    return str;
1716
1702
  case INT_RESULT:
1717
1703
    str->set_int(sum_int, unsigned_flag, &my_charset_bin);
1719
1705
  case ROW_RESULT:
1720
1706
  default:
1721
1707
    // This case should never be choosen
 
1708
    assert(0);
1722
1709
    break;
1723
1710
  }
1724
 
 
1725
1711
  return str;                                   // Keep compiler happy
1726
1712
}
1727
1713
 
1759
1745
{
1760
1746
  switch (hybrid_type) {
1761
1747
  case STRING_RESULT:
 
1748
  {
 
1749
    String *result=args[0]->val_str(&tmp_value);
 
1750
    if (!args[0]->null_value &&
 
1751
        (null_value || sortcmp(&value,result,collation.collation) > 0))
1762
1752
    {
1763
 
      String *result=args[0]->val_str(&tmp_value);
1764
 
      if (!args[0]->null_value &&
1765
 
          (null_value || sortcmp(&value,result,collation.collation) > 0))
1766
 
      {
1767
 
        value.copy(*result);
1768
 
        null_value=0;
1769
 
      }
 
1753
      value.copy(*result);
 
1754
      null_value=0;
1770
1755
    }
1771
 
    break;
 
1756
  }
 
1757
  break;
1772
1758
  case INT_RESULT:
 
1759
  {
 
1760
    int64_t nr=args[0]->val_int();
 
1761
    if (!args[0]->null_value && (null_value ||
 
1762
                                 (unsigned_flag &&
 
1763
                                  (uint64_t) nr < (uint64_t) sum_int) ||
 
1764
                                 (!unsigned_flag && nr < sum_int)))
1773
1765
    {
1774
 
      int64_t nr=args[0]->val_int();
1775
 
      if (!args[0]->null_value && (null_value ||
1776
 
                                   (unsigned_flag &&
1777
 
                                    (uint64_t) nr < (uint64_t) sum_int) ||
1778
 
                                   (!unsigned_flag && nr < sum_int)))
1779
 
      {
1780
 
        sum_int=nr;
1781
 
        null_value=0;
1782
 
      }
 
1766
      sum_int=nr;
 
1767
      null_value=0;
1783
1768
    }
1784
 
    break;
 
1769
  }
 
1770
  break;
1785
1771
  case DECIMAL_RESULT:
 
1772
  {
 
1773
    my_decimal value_buff, *val= args[0]->val_decimal(&value_buff);
 
1774
    if (!args[0]->null_value &&
 
1775
        (null_value || (my_decimal_cmp(&sum_dec, val) > 0)))
1786
1776
    {
1787
 
      type::Decimal value_buff, *val= args[0]->val_decimal(&value_buff);
1788
 
      if (!args[0]->null_value &&
1789
 
          (null_value || (class_decimal_cmp(&sum_dec, val) > 0)))
1790
 
      {
1791
 
        class_decimal2decimal(val, &sum_dec);
1792
 
        null_value= 0;
1793
 
      }
 
1777
      my_decimal2decimal(val, &sum_dec);
 
1778
      null_value= 0;
1794
1779
    }
1795
 
    break;
 
1780
  }
 
1781
  break;
1796
1782
  case REAL_RESULT:
 
1783
  {
 
1784
    double nr= args[0]->val_real();
 
1785
    if (!args[0]->null_value && (null_value || nr < sum))
1797
1786
    {
1798
 
      double nr= args[0]->val_real();
1799
 
      if (!args[0]->null_value && (null_value || nr < sum))
1800
 
      {
1801
 
        sum=nr;
1802
 
        null_value=0;
1803
 
      }
 
1787
      sum=nr;
 
1788
      null_value=0;
1804
1789
    }
1805
 
    break;
 
1790
  }
 
1791
  break;
1806
1792
  case ROW_RESULT:
 
1793
  default:
1807
1794
    // This case should never be choosen
1808
1795
    assert(0);
1809
1796
    break;
1822
1809
{
1823
1810
  switch (hybrid_type) {
1824
1811
  case STRING_RESULT:
 
1812
  {
 
1813
    String *result=args[0]->val_str(&tmp_value);
 
1814
    if (!args[0]->null_value &&
 
1815
        (null_value || sortcmp(&value,result,collation.collation) < 0))
1825
1816
    {
1826
 
      String *result=args[0]->val_str(&tmp_value);
1827
 
      if (!args[0]->null_value &&
1828
 
          (null_value || sortcmp(&value,result,collation.collation) < 0))
1829
 
      {
1830
 
        value.copy(*result);
1831
 
        null_value=0;
1832
 
      }
 
1817
      value.copy(*result);
 
1818
      null_value=0;
1833
1819
    }
1834
 
    break;
 
1820
  }
 
1821
  break;
1835
1822
  case INT_RESULT:
 
1823
  {
 
1824
    int64_t nr=args[0]->val_int();
 
1825
    if (!args[0]->null_value && (null_value ||
 
1826
                                 (unsigned_flag &&
 
1827
                                  (uint64_t) nr > (uint64_t) sum_int) ||
 
1828
                                 (!unsigned_flag && nr > sum_int)))
1836
1829
    {
1837
 
      int64_t nr=args[0]->val_int();
1838
 
      if (!args[0]->null_value && (null_value ||
1839
 
                                   (unsigned_flag &&
1840
 
                                    (uint64_t) nr > (uint64_t) sum_int) ||
1841
 
                                   (!unsigned_flag && nr > sum_int)))
1842
 
      {
1843
 
        sum_int=nr;
1844
 
        null_value=0;
1845
 
      }
 
1830
      sum_int=nr;
 
1831
      null_value=0;
1846
1832
    }
1847
 
    break;
 
1833
  }
 
1834
  break;
1848
1835
  case DECIMAL_RESULT:
 
1836
  {
 
1837
    my_decimal value_buff, *val= args[0]->val_decimal(&value_buff);
 
1838
    if (!args[0]->null_value &&
 
1839
        (null_value || (my_decimal_cmp(val, &sum_dec) > 0)))
1849
1840
    {
1850
 
      type::Decimal value_buff, *val= args[0]->val_decimal(&value_buff);
1851
 
      if (!args[0]->null_value &&
1852
 
          (null_value || (class_decimal_cmp(val, &sum_dec) > 0)))
1853
 
      {
1854
 
        class_decimal2decimal(val, &sum_dec);
1855
 
        null_value= 0;
1856
 
      }
 
1841
      my_decimal2decimal(val, &sum_dec);
 
1842
      null_value= 0;
1857
1843
    }
1858
 
    break;
 
1844
  }
 
1845
  break;
1859
1846
  case REAL_RESULT:
 
1847
  {
 
1848
    double nr= args[0]->val_real();
 
1849
    if (!args[0]->null_value && (null_value || nr > sum))
1860
1850
    {
1861
 
      double nr= args[0]->val_real();
1862
 
      if (!args[0]->null_value && (null_value || nr > sum))
1863
 
      {
1864
 
        sum=nr;
1865
 
        null_value=0;
1866
 
      }
 
1851
      sum=nr;
 
1852
      null_value=0;
1867
1853
    }
1868
 
    break;
 
1854
  }
 
1855
  break;
1869
1856
  case ROW_RESULT:
 
1857
  default:
1870
1858
    // This case should never be choosen
1871
1859
    assert(0);
1872
1860
    break;
1873
1861
  }
1874
 
 
1875
1862
  return 0;
1876
1863
}
1877
1864
 
1959
1946
{
1960
1947
  switch(hybrid_type) {
1961
1948
  case STRING_RESULT:
1962
 
    {
1963
 
      char buff[MAX_FIELD_WIDTH];
1964
 
      String tmp(buff,sizeof(buff),result_field->charset()),*res;
1965
 
 
1966
 
      res=args[0]->val_str(&tmp);
1967
 
      if (args[0]->null_value)
1968
 
      {
 
1949
  {
 
1950
    char buff[MAX_FIELD_WIDTH];
 
1951
    String tmp(buff,sizeof(buff),result_field->charset()),*res;
 
1952
 
 
1953
    res=args[0]->val_str(&tmp);
 
1954
    if (args[0]->null_value)
 
1955
    {
 
1956
      result_field->set_null();
 
1957
      result_field->reset();
 
1958
    }
 
1959
    else
 
1960
    {
 
1961
      result_field->set_notnull();
 
1962
      result_field->store(res->ptr(),res->length(),tmp.charset());
 
1963
    }
 
1964
    break;
 
1965
  }
 
1966
  case INT_RESULT:
 
1967
  {
 
1968
    int64_t nr=args[0]->val_int();
 
1969
 
 
1970
    if (maybe_null)
 
1971
    {
 
1972
      if (args[0]->null_value)
 
1973
      {
 
1974
        nr=0;
 
1975
        result_field->set_null();
 
1976
      }
 
1977
      else
 
1978
        result_field->set_notnull();
 
1979
    }
 
1980
    result_field->store(nr, unsigned_flag);
 
1981
    break;
 
1982
  }
 
1983
  case REAL_RESULT:
 
1984
  {
 
1985
    double nr= args[0]->val_real();
 
1986
 
 
1987
    if (maybe_null)
 
1988
    {
 
1989
      if (args[0]->null_value)
 
1990
      {
 
1991
        nr=0.0;
 
1992
        result_field->set_null();
 
1993
      }
 
1994
      else
 
1995
        result_field->set_notnull();
 
1996
    }
 
1997
    result_field->store(nr);
 
1998
    break;
 
1999
  }
 
2000
  case DECIMAL_RESULT:
 
2001
  {
 
2002
    my_decimal value_buff, *arg_dec= args[0]->val_decimal(&value_buff);
 
2003
 
 
2004
    if (maybe_null)
 
2005
    {
 
2006
      if (args[0]->null_value)
1969
2007
        result_field->set_null();
1970
 
        result_field->reset();
1971
 
      }
1972
2008
      else
1973
 
      {
1974
2009
        result_field->set_notnull();
1975
 
        result_field->store(res->ptr(),res->length(),tmp.charset());
1976
 
      }
1977
 
      break;
1978
 
    }
1979
 
  case INT_RESULT:
1980
 
    {
1981
 
      int64_t nr=args[0]->val_int();
1982
 
 
1983
 
      if (maybe_null)
1984
 
      {
1985
 
        if (args[0]->null_value)
1986
 
        {
1987
 
          nr=0;
1988
 
          result_field->set_null();
1989
 
        }
1990
 
        else
1991
 
          result_field->set_notnull();
1992
 
      }
1993
 
      result_field->store(nr, unsigned_flag);
1994
 
      break;
1995
 
    }
1996
 
  case REAL_RESULT:
1997
 
    {
1998
 
      double nr= args[0]->val_real();
1999
 
 
2000
 
      if (maybe_null)
2001
 
      {
2002
 
        if (args[0]->null_value)
2003
 
        {
2004
 
          nr=0.0;
2005
 
          result_field->set_null();
2006
 
        }
2007
 
        else
2008
 
          result_field->set_notnull();
2009
 
      }
2010
 
      result_field->store(nr);
2011
 
      break;
2012
 
    }
2013
 
  case DECIMAL_RESULT:
2014
 
    {
2015
 
      type::Decimal value_buff, *arg_dec= args[0]->val_decimal(&value_buff);
2016
 
 
2017
 
      if (maybe_null)
2018
 
      {
2019
 
        if (args[0]->null_value)
2020
 
          result_field->set_null();
2021
 
        else
2022
 
          result_field->set_notnull();
2023
 
      }
2024
 
      /*
2025
 
        We must store zero in the field as we will use the field value in
2026
 
        add()
2027
 
      */
2028
 
      if (!arg_dec)                               // Null
2029
 
        arg_dec= &decimal_zero;
2030
 
      result_field->store_decimal(arg_dec);
2031
 
      break;
2032
 
    }
 
2010
    }
 
2011
    /*
 
2012
      We must store zero in the field as we will use the field value in
 
2013
      add()
 
2014
    */
 
2015
    if (!arg_dec)                               // Null
 
2016
      arg_dec= &decimal_zero;
 
2017
    result_field->store_decimal(arg_dec);
 
2018
    break;
 
2019
  }
2033
2020
  case ROW_RESULT:
 
2021
  default:
2034
2022
    assert(0);
2035
2023
  }
2036
2024
}
2040
2028
{
2041
2029
  if (hybrid_type == DECIMAL_RESULT)
2042
2030
  {
2043
 
    type::Decimal value, *arg_val= args[0]->val_decimal(&value);
 
2031
    my_decimal value, *arg_val= args[0]->val_decimal(&value);
2044
2032
    if (!arg_val)                               // Null
2045
2033
      arg_val= &decimal_zero;
2046
2034
    result_field->store_decimal(arg_val);
2075
2063
  if (hybrid_type == DECIMAL_RESULT)
2076
2064
  {
2077
2065
    int64_t tmp;
2078
 
    type::Decimal value, *arg_dec= args[0]->val_decimal(&value);
 
2066
    my_decimal value, *arg_dec= args[0]->val_decimal(&value);
2079
2067
    if (args[0]->null_value)
2080
2068
    {
2081
2069
      arg_dec= &decimal_zero;
2083
2071
    }
2084
2072
    else
2085
2073
      tmp= 1;
2086
 
    arg_dec->val_binary(E_DEC_FATAL_ERROR, res, f_precision, f_scale);
 
2074
    my_decimal2binary(E_DEC_FATAL_ERROR, arg_dec, res, f_precision, f_scale);
2087
2075
    res+= dec_bin_size;
2088
2076
    int8store(res, tmp);
2089
2077
  }
2127
2115
{
2128
2116
  if (hybrid_type == DECIMAL_RESULT)
2129
2117
  {
2130
 
    type::Decimal value, *arg_val= args[0]->val_decimal(&value);
 
2118
    my_decimal value, *arg_val= args[0]->val_decimal(&value);
2131
2119
    if (!args[0]->null_value)
2132
2120
    {
2133
2121
      if (!result_field->is_null())
2134
2122
      {
2135
 
        type::Decimal field_value,
 
2123
        my_decimal field_value,
2136
2124
                   *field_val= result_field->val_decimal(&field_value);
2137
 
        class_decimal_add(E_DEC_FATAL_ERROR, dec_buffs, arg_val, field_val);
 
2125
        my_decimal_add(E_DEC_FATAL_ERROR, dec_buffs, arg_val, field_val);
2138
2126
        result_field->store_decimal(dec_buffs);
2139
2127
      }
2140
2128
      else
2179
2167
  unsigned char *res=result_field->ptr;
2180
2168
  if (hybrid_type == DECIMAL_RESULT)
2181
2169
  {
2182
 
    type::Decimal value, *arg_val= args[0]->val_decimal(&value);
 
2170
    my_decimal value, *arg_val= args[0]->val_decimal(&value);
2183
2171
    if (!args[0]->null_value)
2184
2172
    {
2185
 
      binary2_class_decimal(E_DEC_FATAL_ERROR, res,
 
2173
      binary2my_decimal(E_DEC_FATAL_ERROR, res,
2186
2174
                        dec_buffs + 1, f_precision, f_scale);
2187
2175
      field_count= sint8korr(res + dec_bin_size);
2188
 
      class_decimal_add(E_DEC_FATAL_ERROR, dec_buffs, arg_val, dec_buffs + 1);
2189
 
      dec_buffs->val_binary(E_DEC_FATAL_ERROR, res, f_precision, f_scale);
 
2176
      my_decimal_add(E_DEC_FATAL_ERROR, dec_buffs, arg_val, dec_buffs + 1);
 
2177
      my_decimal2binary(E_DEC_FATAL_ERROR, dec_buffs,
 
2178
                        res, f_precision, f_scale);
2190
2179
      res+= dec_bin_size;
2191
2180
      field_count++;
2192
2181
      int8store(res, field_count);
2224
2213
  case DECIMAL_RESULT:
2225
2214
    min_max_update_decimal_field();
2226
2215
    break;
2227
 
  case REAL_RESULT:
2228
 
  case ROW_RESULT:
 
2216
  default:
2229
2217
    min_max_update_real_field();
2230
2218
  }
2231
2219
}
2238
2226
 
2239
2227
  if (!args[0]->null_value)
2240
2228
  {
2241
 
    result_field->val_str_internal(&tmp_value);
 
2229
    result_field->val_str(&tmp_value);
2242
2230
 
2243
2231
    if (result_field->is_null() ||
2244
2232
        (cmp_sign * sortcmp(res_str,&tmp_value,collation.collation)) < 0)
2304
2292
Item_sum_hybrid::min_max_update_decimal_field()
2305
2293
{
2306
2294
  /* TODO: optimize: do not get result_field in case of args[0] is NULL */
2307
 
  type::Decimal old_val, nr_val;
2308
 
  const type::Decimal *old_nr= result_field->val_decimal(&old_val);
2309
 
  const type::Decimal *nr= args[0]->val_decimal(&nr_val);
 
2295
  my_decimal old_val, nr_val;
 
2296
  const my_decimal *old_nr= result_field->val_decimal(&old_val);
 
2297
  const my_decimal *nr= args[0]->val_decimal(&nr_val);
2310
2298
  if (!args[0]->null_value)
2311
2299
  {
2312
2300
    if (result_field->is_null(0))
2313
2301
      old_nr=nr;
2314
2302
    else
2315
2303
    {
2316
 
      bool res= class_decimal_cmp(old_nr, nr) > 0;
 
2304
      bool res= my_decimal_cmp(old_nr, nr) > 0;
2317
2305
      /* (cmp_sign > 0 && res) || (!(cmp_sign > 0) && !res) */
2318
2306
      if ((cmp_sign > 0) ^ (!res))
2319
2307
        old_nr=nr;
2370
2358
}
2371
2359
 
2372
2360
 
2373
 
type::Decimal *Item_avg_field::val_decimal(type::Decimal *dec_buf)
 
2361
my_decimal *Item_avg_field::val_decimal(my_decimal *dec_buf)
2374
2362
{
2375
2363
  // fix_fields() never calls for this Item
2376
2364
  if (hybrid_type == REAL_RESULT)
2380
2368
  if ((null_value= !count))
2381
2369
    return 0;
2382
2370
 
2383
 
  type::Decimal dec_count, dec_field;
2384
 
  binary2_class_decimal(E_DEC_FATAL_ERROR,
 
2371
  my_decimal dec_count, dec_field;
 
2372
  binary2my_decimal(E_DEC_FATAL_ERROR,
2385
2373
                    field->ptr, &dec_field, f_precision, f_scale);
2386
 
  int2_class_decimal(E_DEC_FATAL_ERROR, count, 0, &dec_count);
2387
 
  class_decimal_div(E_DEC_FATAL_ERROR, dec_buf,
 
2374
  int2my_decimal(E_DEC_FATAL_ERROR, count, 0, &dec_count);
 
2375
  my_decimal_div(E_DEC_FATAL_ERROR, dec_buf,
2388
2376
                 &dec_field, &dec_count, prec_increment);
2389
2377
  return dec_buf;
2390
2378
}
2415
2403
}
2416
2404
 
2417
2405
 
2418
 
type::Decimal *Item_std_field::val_decimal(type::Decimal *dec_buf)
 
2406
my_decimal *Item_std_field::val_decimal(my_decimal *dec_buf)
2419
2407
{
2420
2408
  /*
2421
2409
    We can't call val_decimal_from_real() for DECIMAL_RESULT as
2422
2410
    Item_variance_field::val_real() would cause an infinite loop
2423
2411
  */
2424
 
  type::Decimal tmp_dec, *dec;
 
2412
  my_decimal tmp_dec, *dec;
2425
2413
  double nr;
2426
2414
  if (hybrid_type == REAL_RESULT)
2427
2415
    return val_decimal_from_real(dec_buf);
2429
2417
  dec= Item_variance_field::val_decimal(dec_buf);
2430
2418
  if (!dec)
2431
2419
    return 0;
2432
 
  class_decimal2double(E_DEC_FATAL_ERROR, dec, &nr);
 
2420
  my_decimal2double(E_DEC_FATAL_ERROR, dec, &nr);
2433
2421
  assert(nr >= 0.0);
2434
2422
  nr= sqrt(nr);
2435
 
  double2_class_decimal(E_DEC_FATAL_ERROR, nr, &tmp_dec);
2436
 
  class_decimal_round(E_DEC_FATAL_ERROR, &tmp_dec, decimals, false, dec_buf);
 
2423
  double2my_decimal(E_DEC_FATAL_ERROR, nr, &tmp_dec);
 
2424
  my_decimal_round(E_DEC_FATAL_ERROR, &tmp_dec, decimals, false, dec_buf);
2437
2425
  return dec_buf;
2438
2426
}
2439
2427
 
2610
2598
  tmp_table_param->force_copy_fields= force_copy_fields;
2611
2599
  assert(table == 0);
2612
2600
 
2613
 
  if (!(table= create_tmp_table(session, tmp_table_param, list, (Order*) 0, 1,
 
2601
  if (!(table= create_tmp_table(session, tmp_table_param, list, (order_st*) 0, 1,
2614
2602
                                0,
2615
2603
                                (select_lex->options | session->options),
2616
2604
                                HA_POS_ERROR, (char*)"")))
2667
2655
        uint32_t *length;
2668
2656
        compare_key= (qsort_cmp2) composite_key_cmp;
2669
2657
        cmp_arg= (void*) this;
2670
 
        field_lengths= (uint32_t*) session->getMemRoot()->allocate(table->getShare()->sizeFields() * sizeof(uint32_t));
 
2658
        field_lengths= (uint32_t*) session->alloc(table->getShare()->sizeFields() * sizeof(uint32_t));
2671
2659
        for (tree_key_length= 0, length= field_lengths, field= table->getFields();
2672
2660
             field < field_end; ++field, ++length)
2673
2661
        {
2721
2709
  if (always_null)
2722
2710
    return 0;
2723
2711
  copy_fields(tmp_table_param);
2724
 
  if (copy_funcs(tmp_table_param->items_to_copy, table->in_use))
2725
 
    return true;
 
2712
  copy_funcs(tmp_table_param->items_to_copy);
2726
2713
 
2727
2714
  for (Field **field= table->getFields() ; *field ; field++)
2728
2715
  {
2830
2817
    */
2831
2818
    Field *field= item->get_tmp_table_field();
2832
2819
    int res;
2833
 
    uint32_t offset= field->offset(field->getTable()->record[0])-table->getShare()->null_bytes;
 
2820
    uint32_t offset= field->offset(field->table->record[0])-table->getShare()->null_bytes;
2834
2821
    if((res= field->cmp((unsigned char*)key1 + offset, (unsigned char*)key2 + offset)))
2835
2822
      return res;
2836
2823
  }
2846
2833
                                    const void* key2)
2847
2834
{
2848
2835
  Item_func_group_concat* grp_item= (Item_func_group_concat*) arg;
2849
 
  Order **order_item, **end;
 
2836
  order_st **order_item, **end;
2850
2837
  Table *table= grp_item->table;
2851
2838
 
2852
2839
  for (order_item= grp_item->order, end=order_item+ grp_item->arg_count_order;
2867
2854
    if (field && !item->const_item())
2868
2855
    {
2869
2856
      int res;
2870
 
      uint32_t offset= (field->offset(field->getTable()->record[0]) -
 
2857
      uint32_t offset= (field->offset(field->table->record[0]) -
2871
2858
                    table->getShare()->null_bytes);
2872
2859
      if ((res= field->cmp((unsigned char*)key1 + offset, (unsigned char*)key2 + offset)))
2873
2860
        return (*order_item)->asc ? res : -res;
2890
2877
                  Item_func_group_concat *item)
2891
2878
{
2892
2879
  Table *table= item->table;
2893
 
  String tmp((char *)table->getUpdateRecord(), table->getShare()->getRecordLength(),
 
2880
  String tmp((char *)table->record[1], table->getShare()->getRecordLength(),
2894
2881
             default_charset_info);
2895
2882
  String tmp2;
2896
2883
  String *result= &item->result;
2917
2904
        because it contains both order and arg list fields.
2918
2905
      */
2919
2906
      Field *field= (*arg)->get_tmp_table_field();
2920
 
      uint32_t offset= (field->offset(field->getTable()->record[0]) -
 
2907
      uint32_t offset= (field->offset(field->table->record[0]) -
2921
2908
                    table->getShare()->null_bytes);
2922
2909
      assert(offset < table->getShare()->getRecordLength());
2923
 
      res= field->val_str_internal(&tmp, key + offset);
 
2910
      res= field->val_str(&tmp, key + offset);
2924
2911
    }
2925
2912
    else
2926
2913
      res= (*arg)->val_str(&tmp);
2990
2977
    order - arg_count_order
2991
2978
  */
2992
2979
  if (!(args= (Item**) memory::sql_alloc(sizeof(Item*) * arg_count +
2993
 
                                 sizeof(Order*)*arg_count_order)))
 
2980
                                 sizeof(order_st*)*arg_count_order)))
2994
2981
    return;
2995
2982
 
2996
 
  order= (Order**)(args + arg_count);
 
2983
  order= (order_st**)(args + arg_count);
2997
2984
 
2998
2985
  /* fill args items of show and sort */
2999
2986
  List_iterator_fast<Item> li(*select_list);
3003
2990
 
3004
2991
  if (arg_count_order)
3005
2992
  {
3006
 
    Order **order_ptr= order;
3007
 
    for (Order *order_item= (Order*) order_list->first;
 
2993
    order_st **order_ptr= order;
 
2994
    for (order_st *order_item= (order_st*) order_list->first;
3008
2995
         order_item != NULL;
3009
2996
         order_item= order_item->next)
3010
2997
    {
3051
3038
  {
3052
3039
    char warn_buff[DRIZZLE_ERRMSG_SIZE];
3053
3040
    snprintf(warn_buff, sizeof(warn_buff), ER(ER_CUT_VALUE_GROUP_CONCAT), count_cut_values);
3054
 
    warning->set_msg(&getSession(), warn_buff);
 
3041
    warning->set_msg(current_session, warn_buff);
3055
3042
    warning= 0;
3056
3043
  }
3057
3044
 
3117
3104
  if (always_null)
3118
3105
    return 0;
3119
3106
  copy_fields(tmp_table_param);
3120
 
  if (copy_funcs(tmp_table_param->items_to_copy, table->in_use))
3121
 
    return true;
 
3107
  copy_funcs(tmp_table_param->items_to_copy);
3122
3108
 
3123
3109
  for (uint32_t i= 0; i < arg_count_field; i++)
3124
3110
  {
3272
3258
    field list.
3273
3259
  */
3274
3260
  if (!(table= create_tmp_table(session, tmp_table_param, all_fields,
3275
 
                                (Order*) 0, 0, true,
 
3261
                                (order_st*) 0, 0, true,
3276
3262
                                (select_lex->options | session->options),
3277
3263
                                HA_POS_ERROR, (char*) "")))
3278
3264
  {