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 */
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>
40
#include <drizzled/type/decimal.h>
42
40
#include "drizzled/internal/m_string.h"
44
42
#include <algorithm>
421
420
void Item_sum::mark_as_sum_func()
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;
510
509
uint32_t convert_blob_length)
514
512
switch (result_type()) {
515
513
case REAL_RESULT:
516
514
field= new Field_double(max_length, maybe_null, name, decimals, true);
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);
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)
528
523
return make_string_field(table);
531
table->setVariableWidth();
532
524
field= new Field_varstring(convert_blob_length, maybe_null,
533
name, collation.collation);
525
name, table->getMutableShare(), collation.collation);
536
527
case DECIMAL_RESULT:
537
528
field= new Field_decimal(max_length, maybe_null, name,
538
decimals, unsigned_flag);
529
decimals, unsigned_flag);
542
533
// This case should never be choosen
548
538
field->init(table);
725
716
field= ((Item_field*) args[0])->field;
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;
768
757
/* TODO: check if the following assignments are really needed */
769
758
if (hybrid_type == DECIMAL_RESULT)
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);
809
798
case DECIMAL_RESULT:
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,
816
hybrid_type= DECIMAL_RESULT;
817
dec_buffs->set_zero();
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,
805
hybrid_type= DECIMAL_RESULT;
806
my_decimal_set_zero(dec_buffs);
828
819
if (hybrid_type == DECIMAL_RESULT)
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)
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;
852
843
if (hybrid_type == DECIMAL_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,
858
850
return (int64_t) rint(val_real());
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);
940
932
virtual void div(Hybrid_type *val, uint64_t u) const
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);
972
964
table_field_type= DRIZZLE_TYPE_DOUBLE;
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.
982
if (table_field_type == DRIZZLE_TYPE_LONG)
984
val.traits= Hybrid_type_traits_fast_decimal::instance();
987
table_field_type= DRIZZLE_TYPE_LONGLONG;
968
Preserving int8, int16, int32 field types gives ~10% performance boost
969
as the size of result tree becomes significantly smaller.
970
Another speed up we gain by using int64_t for intermediate
971
calculations. The range of int64 is enough to hold sum 2^32 distinct
972
integers each <= 2^32.
974
if (table_field_type == DRIZZLE_TYPE_LONG)
976
val.traits= Hybrid_type_traits_fast_decimal::instance();
979
table_field_type= DRIZZLE_TYPE_LONGLONG;
989
981
case DECIMAL_RESULT:
990
982
val.traits= Hybrid_type_traits_decimal::instance();
991
983
if (table_field_type != DRIZZLE_TYPE_LONGLONG)
992
984
table_field_type= DRIZZLE_TYPE_DECIMAL;
998
990
val.traits->fix_length_and_dec(this, args[0]);
1033
1025
field_def.init_for_tmp_table(table_field_type, args[0]->max_length,
1034
1026
args[0]->decimals, args[0]->maybe_null);
1036
if (! (table= session->getInstanceTable(field_list)))
1028
if (! (table= session->create_virtual_tmp_table(field_list)))
1039
1031
/* XXX: check that the case of CHAR(0) works OK */
1165
1157
Item_sum_avg_distinct::fix_length_and_dec()
1167
1159
Item_sum_distinct::fix_length_and_dec();
1168
prec_increment= getSession().variables.div_precincrement;
1160
prec_increment= current_session->variables.div_precincrement;
1170
1162
AVG() will divide val by count. We need to reserve digits
1171
1163
after decimal point as the result can be fractional.
1229
1221
Item_sum_sum::fix_length_and_dec();
1230
1222
maybe_null=null_value=1;
1231
prec_increment= getSession().variables.div_precincrement;
1223
prec_increment= current_session->variables.div_precincrement;
1233
1224
if (hybrid_type == DECIMAL_RESULT)
1235
1226
int precision= args[0]->decimal_precision() + prec_increment;
1236
1227
decimals= min(args[0]->decimals + prec_increment, (unsigned int) DECIMAL_MAX_SCALE);
1237
max_length= class_decimal_precision_to_length(precision, decimals,
1228
max_length= my_decimal_precision_to_length(precision, decimals,
1238
1229
unsigned_flag);
1239
1230
f_precision= min(precision+DECIMAL_LONGLONG_DIGITS, DECIMAL_MAX_PRECISION);
1240
1231
f_scale= args[0]->decimals;
1241
dec_bin_size= class_decimal_get_binary_size(f_precision, f_scale);
1232
dec_bin_size= my_decimal_get_binary_size(f_precision, f_scale);
1244
1235
decimals= min(args[0]->decimals + prec_increment, (unsigned int) NOT_FIXED_DEC);
1264
1255
The easiest way is to do this is to store both value in a string
1265
1256
and unpack on access.
1267
table->setVariableWidth();
1268
1258
field= new Field_varstring(((hybrid_type == DECIMAL_RESULT) ?
1269
1259
dec_bin_size : sizeof(double)) + sizeof(int64_t),
1270
0, name, &my_charset_bin);
1260
0, name, table->getMutableShare(), &my_charset_bin);
1272
1262
else if (hybrid_type == DECIMAL_RESULT)
1273
1263
field= new Field_decimal(max_length, maybe_null, name,
1317
type::Decimal *Item_sum_avg::val_decimal(type::Decimal *val)
1307
my_decimal *Item_sum_avg::val_decimal(my_decimal *val)
1319
type::Decimal sum_buff, cnt;
1320
const type::Decimal *sum_dec;
1309
my_decimal sum_buff, cnt;
1310
const my_decimal *sum_dec;
1321
1311
assert(fixed == 1);
1333
1323
return val_decimal_from_real(val);
1335
1325
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);
1326
int2my_decimal(E_DEC_FATAL_ERROR, count, 0, &cnt);
1327
my_decimal_div(E_DEC_FATAL_ERROR, val, sum_dec, &cnt, prec_increment);
1426
1416
void Item_sum_variance::fix_length_and_dec()
1428
1418
maybe_null= null_value= 1;
1429
prec_increment= getSession().variables.div_precincrement;
1419
prec_increment= current_session->variables.div_precincrement;
1432
1422
According to the SQL2003 standard (Part 2, Foundations; sec 10.9,
1444
1434
case INT_RESULT:
1445
1435
case DECIMAL_RESULT:
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,
1437
int precision= args[0]->decimal_precision()*2 + prec_increment;
1438
decimals= min(args[0]->decimals + prec_increment, (unsigned int) DECIMAL_MAX_SCALE);
1439
max_length= my_decimal_precision_to_length(precision, decimals,
1454
1444
case ROW_RESULT:
1479
1471
The easiest way is to do this is to store both value in a string
1480
1472
and unpack on access.
1482
table->setVariableWidth();
1483
field= new Field_varstring(sizeof(double)*2 + sizeof(int64_t), 0, name, &my_charset_bin);
1474
field= new Field_varstring(sizeof(double)*2 + sizeof(int64_t), 0, name, table->getMutableShare(), &my_charset_bin);
1486
1477
field= new Field_double(max_length, maybe_null, name, decimals, true);
1622
1613
assert(fixed == 1);
1623
1614
if (null_value)
1626
1616
switch (hybrid_type) {
1627
1617
case STRING_RESULT:
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);
1621
String *res; res=val_str(&str_value);
1622
return (res ? my_strntod(res->charset(), (char*) res->ptr(), res->length(),
1623
&end_not_used, &err_not_used) : 0.0);
1635
1625
case INT_RESULT:
1636
1626
return (double) sum_int;
1637
1627
case DECIMAL_RESULT:
1638
class_decimal2double(E_DEC_FATAL_ERROR, &sum_dec, &sum);
1628
my_decimal2double(E_DEC_FATAL_ERROR, &sum_dec, &sum);
1640
1630
case REAL_RESULT:
1642
1632
case ROW_RESULT:
1643
1634
// This case should never be choosen
1651
1640
int64_t Item_sum_hybrid::val_int()
1671
type::Decimal *Item_sum_hybrid::val_decimal(type::Decimal *val)
1660
my_decimal *Item_sum_hybrid::val_decimal(my_decimal *val)
1673
1662
assert(fixed == 1);
1674
1663
if (null_value)
1677
1665
switch (hybrid_type) {
1678
1666
case STRING_RESULT:
1679
val->store(E_DEC_FATAL_ERROR, &value);
1667
string2my_decimal(E_DEC_FATAL_ERROR, &value, val);
1681
1669
case REAL_RESULT:
1682
double2_class_decimal(E_DEC_FATAL_ERROR, sum, val);
1670
double2my_decimal(E_DEC_FATAL_ERROR, sum, val);
1684
1672
case DECIMAL_RESULT:
1687
1675
case INT_RESULT:
1688
int2_class_decimal(E_DEC_FATAL_ERROR, sum_int, unsigned_flag, val);
1676
int2my_decimal(E_DEC_FATAL_ERROR, sum_int, unsigned_flag, val);
1690
1678
case ROW_RESULT:
1691
1680
// This case should never be choosen
1696
1684
return val; // Keep compiler happy
1711
1698
str->set_real(sum,decimals, &my_charset_bin);
1713
1700
case DECIMAL_RESULT:
1714
class_decimal2string(&sum_dec, 0, str);
1701
my_decimal2string(E_DEC_FATAL_ERROR, &sum_dec, 0, 0, 0, str);
1716
1703
case INT_RESULT:
1717
1704
str->set_int(sum_int, unsigned_flag, &my_charset_bin);
1760
1747
switch (hybrid_type) {
1761
1748
case STRING_RESULT:
1750
String *result=args[0]->val_str(&tmp_value);
1751
if (!args[0]->null_value &&
1752
(null_value || sortcmp(&value,result,collation.collation) > 0))
1763
String *result=args[0]->val_str(&tmp_value);
1764
if (!args[0]->null_value &&
1765
(null_value || sortcmp(&value,result,collation.collation) > 0))
1767
value.copy(*result);
1754
value.copy(*result);
1772
1759
case INT_RESULT:
1761
int64_t nr=args[0]->val_int();
1762
if (!args[0]->null_value && (null_value ||
1764
(uint64_t) nr < (uint64_t) sum_int) ||
1765
(!unsigned_flag && nr < sum_int)))
1774
int64_t nr=args[0]->val_int();
1775
if (!args[0]->null_value && (null_value ||
1777
(uint64_t) nr < (uint64_t) sum_int) ||
1778
(!unsigned_flag && nr < sum_int)))
1785
1772
case DECIMAL_RESULT:
1774
my_decimal value_buff, *val= args[0]->val_decimal(&value_buff);
1775
if (!args[0]->null_value &&
1776
(null_value || (my_decimal_cmp(&sum_dec, val) > 0)))
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)))
1791
class_decimal2decimal(val, &sum_dec);
1778
my_decimal2decimal(val, &sum_dec);
1796
1783
case REAL_RESULT:
1785
double nr= args[0]->val_real();
1786
if (!args[0]->null_value && (null_value || nr < sum))
1798
double nr= args[0]->val_real();
1799
if (!args[0]->null_value && (null_value || nr < sum))
1806
1793
case ROW_RESULT:
1807
1795
// This case should never be choosen
1823
1811
switch (hybrid_type) {
1824
1812
case STRING_RESULT:
1814
String *result=args[0]->val_str(&tmp_value);
1815
if (!args[0]->null_value &&
1816
(null_value || sortcmp(&value,result,collation.collation) < 0))
1826
String *result=args[0]->val_str(&tmp_value);
1827
if (!args[0]->null_value &&
1828
(null_value || sortcmp(&value,result,collation.collation) < 0))
1830
value.copy(*result);
1818
value.copy(*result);
1835
1823
case INT_RESULT:
1825
int64_t nr=args[0]->val_int();
1826
if (!args[0]->null_value && (null_value ||
1828
(uint64_t) nr > (uint64_t) sum_int) ||
1829
(!unsigned_flag && nr > sum_int)))
1837
int64_t nr=args[0]->val_int();
1838
if (!args[0]->null_value && (null_value ||
1840
(uint64_t) nr > (uint64_t) sum_int) ||
1841
(!unsigned_flag && nr > sum_int)))
1848
1836
case DECIMAL_RESULT:
1838
my_decimal value_buff, *val= args[0]->val_decimal(&value_buff);
1839
if (!args[0]->null_value &&
1840
(null_value || (my_decimal_cmp(val, &sum_dec) > 0)))
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)))
1854
class_decimal2decimal(val, &sum_dec);
1842
my_decimal2decimal(val, &sum_dec);
1859
1847
case REAL_RESULT:
1849
double nr= args[0]->val_real();
1850
if (!args[0]->null_value && (null_value || nr > sum))
1861
double nr= args[0]->val_real();
1862
if (!args[0]->null_value && (null_value || nr > sum))
1869
1857
case ROW_RESULT:
1870
1859
// This case should never be choosen
1960
1948
switch(hybrid_type) {
1961
1949
case STRING_RESULT:
1963
char buff[MAX_FIELD_WIDTH];
1964
String tmp(buff,sizeof(buff),result_field->charset()),*res;
1966
res=args[0]->val_str(&tmp);
1967
if (args[0]->null_value)
1951
char buff[MAX_FIELD_WIDTH];
1952
String tmp(buff,sizeof(buff),result_field->charset()),*res;
1954
res=args[0]->val_str(&tmp);
1955
if (args[0]->null_value)
1957
result_field->set_null();
1958
result_field->reset();
1962
result_field->set_notnull();
1963
result_field->store(res->ptr(),res->length(),tmp.charset());
1969
int64_t nr=args[0]->val_int();
1973
if (args[0]->null_value)
1976
result_field->set_null();
1979
result_field->set_notnull();
1981
result_field->store(nr, unsigned_flag);
1986
double nr= args[0]->val_real();
1990
if (args[0]->null_value)
1993
result_field->set_null();
1996
result_field->set_notnull();
1998
result_field->store(nr);
2001
case DECIMAL_RESULT:
2003
my_decimal value_buff, *arg_dec= args[0]->val_decimal(&value_buff);
2007
if (args[0]->null_value)
1969
2008
result_field->set_null();
1970
result_field->reset();
1974
2010
result_field->set_notnull();
1975
result_field->store(res->ptr(),res->length(),tmp.charset());
1981
int64_t nr=args[0]->val_int();
1985
if (args[0]->null_value)
1988
result_field->set_null();
1991
result_field->set_notnull();
1993
result_field->store(nr, unsigned_flag);
1998
double nr= args[0]->val_real();
2002
if (args[0]->null_value)
2005
result_field->set_null();
2008
result_field->set_notnull();
2010
result_field->store(nr);
2013
case DECIMAL_RESULT:
2015
type::Decimal value_buff, *arg_dec= args[0]->val_decimal(&value_buff);
2019
if (args[0]->null_value)
2020
result_field->set_null();
2022
result_field->set_notnull();
2025
We must store zero in the field as we will use the field value in
2028
if (!arg_dec) // Null
2029
arg_dec= &decimal_zero;
2030
result_field->store_decimal(arg_dec);
2013
We must store zero in the field as we will use the field value in
2016
if (!arg_dec) // Null
2017
arg_dec= &decimal_zero;
2018
result_field->store_decimal(arg_dec);
2033
2021
case ROW_RESULT:
2041
2030
if (hybrid_type == DECIMAL_RESULT)
2043
type::Decimal value, *arg_val= args[0]->val_decimal(&value);
2032
my_decimal value, *arg_val= args[0]->val_decimal(&value);
2044
2033
if (!arg_val) // Null
2045
2034
arg_val= &decimal_zero;
2046
2035
result_field->store_decimal(arg_val);
2086
arg_dec->val_binary(E_DEC_FATAL_ERROR, res, f_precision, f_scale);
2075
my_decimal2binary(E_DEC_FATAL_ERROR, arg_dec, res, f_precision, f_scale);
2087
2076
res+= dec_bin_size;
2088
2077
int8store(res, tmp);
2128
2117
if (hybrid_type == DECIMAL_RESULT)
2130
type::Decimal value, *arg_val= args[0]->val_decimal(&value);
2119
my_decimal value, *arg_val= args[0]->val_decimal(&value);
2131
2120
if (!args[0]->null_value)
2133
2122
if (!result_field->is_null())
2135
type::Decimal field_value,
2124
my_decimal field_value,
2136
2125
*field_val= result_field->val_decimal(&field_value);
2137
class_decimal_add(E_DEC_FATAL_ERROR, dec_buffs, arg_val, field_val);
2126
my_decimal_add(E_DEC_FATAL_ERROR, dec_buffs, arg_val, field_val);
2138
2127
result_field->store_decimal(dec_buffs);
2179
2168
unsigned char *res=result_field->ptr;
2180
2169
if (hybrid_type == DECIMAL_RESULT)
2182
type::Decimal value, *arg_val= args[0]->val_decimal(&value);
2171
my_decimal value, *arg_val= args[0]->val_decimal(&value);
2183
2172
if (!args[0]->null_value)
2185
binary2_class_decimal(E_DEC_FATAL_ERROR, res,
2174
binary2my_decimal(E_DEC_FATAL_ERROR, res,
2186
2175
dec_buffs + 1, f_precision, f_scale);
2187
2176
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);
2177
my_decimal_add(E_DEC_FATAL_ERROR, dec_buffs, arg_val, dec_buffs + 1);
2178
my_decimal2binary(E_DEC_FATAL_ERROR, dec_buffs,
2179
res, f_precision, f_scale);
2190
2180
res+= dec_bin_size;
2192
2182
int8store(res, field_count);
2239
2228
if (!args[0]->null_value)
2241
result_field->val_str_internal(&tmp_value);
2230
result_field->val_str(&tmp_value);
2243
2232
if (result_field->is_null() ||
2244
2233
(cmp_sign * sortcmp(res_str,&tmp_value,collation.collation)) < 0)
2304
2293
Item_sum_hybrid::min_max_update_decimal_field()
2306
2295
/* 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);
2296
my_decimal old_val, nr_val;
2297
const my_decimal *old_nr= result_field->val_decimal(&old_val);
2298
const my_decimal *nr= args[0]->val_decimal(&nr_val);
2310
2299
if (!args[0]->null_value)
2312
2301
if (result_field->is_null(0))
2316
bool res= class_decimal_cmp(old_nr, nr) > 0;
2305
bool res= my_decimal_cmp(old_nr, nr) > 0;
2317
2306
/* (cmp_sign > 0 && res) || (!(cmp_sign > 0) && !res) */
2318
2307
if ((cmp_sign > 0) ^ (!res))
2380
2369
if ((null_value= !count))
2383
type::Decimal dec_count, dec_field;
2384
binary2_class_decimal(E_DEC_FATAL_ERROR,
2372
my_decimal dec_count, dec_field;
2373
binary2my_decimal(E_DEC_FATAL_ERROR,
2385
2374
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,
2375
int2my_decimal(E_DEC_FATAL_ERROR, count, 0, &dec_count);
2376
my_decimal_div(E_DEC_FATAL_ERROR, dec_buf,
2388
2377
&dec_field, &dec_count, prec_increment);
2389
2378
return dec_buf;
2418
type::Decimal *Item_std_field::val_decimal(type::Decimal *dec_buf)
2407
my_decimal *Item_std_field::val_decimal(my_decimal *dec_buf)
2421
2410
We can't call val_decimal_from_real() for DECIMAL_RESULT as
2422
2411
Item_variance_field::val_real() would cause an infinite loop
2424
type::Decimal tmp_dec, *dec;
2413
my_decimal tmp_dec, *dec;
2426
2415
if (hybrid_type == REAL_RESULT)
2427
2416
return val_decimal_from_real(dec_buf);
2429
2418
dec= Item_variance_field::val_decimal(dec_buf);
2432
class_decimal2double(E_DEC_FATAL_ERROR, dec, &nr);
2421
my_decimal2double(E_DEC_FATAL_ERROR, dec, &nr);
2433
2422
assert(nr >= 0.0);
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);
2424
double2my_decimal(E_DEC_FATAL_ERROR, nr, &tmp_dec);
2425
my_decimal_round(E_DEC_FATAL_ERROR, &tmp_dec, decimals, false, dec_buf);
2437
2426
return dec_buf;
2610
2599
tmp_table_param->force_copy_fields= force_copy_fields;
2611
2600
assert(table == 0);
2613
if (!(table= create_tmp_table(session, tmp_table_param, list, (Order*) 0, 1,
2602
if (!(table= create_tmp_table(session, tmp_table_param, list, (order_st*) 0, 1,
2615
2604
(select_lex->options | session->options),
2616
2605
HA_POS_ERROR, (char*)"")))
2667
2656
uint32_t *length;
2668
2657
compare_key= (qsort_cmp2) composite_key_cmp;
2669
2658
cmp_arg= (void*) this;
2670
field_lengths= (uint32_t*) session->getMemRoot()->allocate(table->getShare()->sizeFields() * sizeof(uint32_t));
2659
field_lengths= (uint32_t*) session->alloc(table->getShare()->sizeFields() * sizeof(uint32_t));
2671
2660
for (tree_key_length= 0, length= field_lengths, field= table->getFields();
2672
2661
field < field_end; ++field, ++length)
2721
2710
if (always_null)
2723
2712
copy_fields(tmp_table_param);
2724
if (copy_funcs(tmp_table_param->items_to_copy, table->in_use))
2713
copy_funcs(tmp_table_param->items_to_copy);
2727
2715
for (Field **field= table->getFields() ; *field ; field++)
2846
2834
const void* key2)
2848
2836
Item_func_group_concat* grp_item= (Item_func_group_concat*) arg;
2849
Order **order_item, **end;
2837
order_st **order_item, **end;
2850
2838
Table *table= grp_item->table;
2852
2840
for (order_item= grp_item->order, end=order_item+ grp_item->arg_count_order;
2920
2908
uint32_t offset= (field->offset(field->getTable()->record[0]) -
2921
2909
table->getShare()->null_bytes);
2922
2910
assert(offset < table->getShare()->getRecordLength());
2923
res= field->val_str_internal(&tmp, key + offset);
2911
res= field->val_str(&tmp, key + offset);
2926
2914
res= (*arg)->val_str(&tmp);
2990
2978
order - arg_count_order
2992
2980
if (!(args= (Item**) memory::sql_alloc(sizeof(Item*) * arg_count +
2993
sizeof(Order*)*arg_count_order)))
2981
sizeof(order_st*)*arg_count_order)))
2996
order= (Order**)(args + arg_count);
2984
order= (order_st**)(args + arg_count);
2998
2986
/* fill args items of show and sort */
2999
2987
List_iterator_fast<Item> li(*select_list);
3004
2992
if (arg_count_order)
3006
Order **order_ptr= order;
3007
for (Order *order_item= (Order*) order_list->first;
2994
order_st **order_ptr= order;
2995
for (order_st *order_item= (order_st*) order_list->first;
3008
2996
order_item != NULL;
3009
2997
order_item= order_item->next)
3052
3040
char warn_buff[DRIZZLE_ERRMSG_SIZE];
3053
3041
snprintf(warn_buff, sizeof(warn_buff), ER(ER_CUT_VALUE_GROUP_CONCAT), count_cut_values);
3054
warning->set_msg(&getSession(), warn_buff);
3042
warning->set_msg(current_session, warn_buff);
3274
3261
if (!(table= create_tmp_table(session, tmp_table_param, all_fields,
3275
(Order*) 0, 0, true,
3262
(order_st*) 0, 0, true,
3276
3263
(select_lex->options | session->options),
3277
3264
HA_POS_ERROR, (char*) "")))