29 #include "procedure.h"
30 #include "sql_analyse.h"
31 #include "sql_class.h"
37 int sortcmp2(
void* cmp_arg __attribute__((unused)),
40 return sortcmp(a,b,a->charset());
43 int compare_double2(
void* cmp_arg __attribute__((unused)),
44 const double *s,
const double *t)
46 return compare_double(s,t);
49 int compare_longlong2(
void* cmp_arg __attribute__((unused)),
50 const longlong *s,
const longlong *t)
52 return compare_longlong(s,t);
55 int compare_ulonglong2(
void* cmp_arg __attribute__((unused)),
56 const ulonglong *s,
const ulonglong *t)
58 return compare_ulonglong(s,t);
61 int compare_decimal2(
int* len,
const char *s,
const char *t)
63 return memcmp(s, t, *len);
77 DBUG_ENTER(
"proc_analyse_init");
79 DBUG_ASSERT(thd->lex->sql_command == SQLCOM_SELECT);
85 f_end= f_info + field_list.elements;
94 switch (item->result_type()) {
97 if (item->type() == Item::FIELD_ITEM &&
98 ((
Item_field*) item)->field->type() == MYSQL_TYPE_LONGLONG &&
99 ((Field_longlong*) ((
Item_field*) item)->field)->unsigned_flag)
116 if (new_field == NULL)
131 bool test_if_number(
NUM_INFO *info, const
char *str, uint str_len)
133 const char *begin, *end= str + str_len;
134 DBUG_ENTER(
"test_if_number");
140 for (; str != end && my_isspace(system_charset_info, *str); str++) ;
147 if (++str == end || *str ==
'0')
153 for (; str != end && my_isdigit(system_charset_info,*str); str++)
155 if (!info->integers && *str ==
'0' && (str + 1) != end &&
156 my_isdigit(system_charset_info,*(str + 1)))
160 if (str == end && info->integers)
162 char *endpos= (
char*) end;
164 info->ullval= (ulonglong) my_strtoll10(begin, &endpos, &error);
165 if (info->integers == 1)
167 info->maybe_zerofill = 1;
170 if (*str ==
'.' || *str ==
'e' || *str ==
'E')
174 if ((str + 1) == end)
176 char *endpos= (
char*) str;
178 info->ullval= (ulonglong) my_strtoll10(begin, &endpos, &error);
181 if (*str ==
'e' || *str ==
'E')
184 if (*str !=
'-' && *str !=
'+')
186 for (str++; str != end && my_isdigit(system_charset_info,*str); str++) ;
194 for (str++; *(end - 1) ==
'0'; end--) ;
197 char *endpos= (
char*) str;
199 info->ullval= (ulonglong) my_strtoll10(begin, &endpos, &error);
202 for (; str != end && my_isdigit(system_charset_info,*str); str++)
206 info->dval = my_atof(begin);
226 if (((longlong) info->ullval) < 0)
228 ev_info->llval = - max<longlong>((ulonglong) -ev_info->llval,
230 ev_info->min_dval = - max<double>(-ev_info->min_dval, info->dval);
234 if ((check_ulonglong(num, info->integers) == DECIMAL_NUM))
236 ev_info->ullval = max<ulonglong>(ev_info->ullval, info->ullval);
237 ev_info->max_dval = max<double>(ev_info->max_dval, info->dval);
243 void free_string(
String *s)
249 void field_str::add()
251 char buff[MAX_FIELD_WIDTH], *ptr;
252 String s(buff,
sizeof(buff),&my_charset_bin), *res;
255 if (!(res= item->str_result(&s)))
261 if (!(length = res->length()))
265 ptr = (
char*) res->ptr();
266 if (*(ptr + (length - 1)) ==
' ')
270 if (can_be_still_num)
272 memset(&num_info, 0,
sizeof(num_info));
273 if (!test_if_number(&num_info, res->ptr(), (uint) length))
274 can_be_still_num = 0;
277 memset(&ev_num_info, 0,
sizeof(ev_num_info));
278 was_zero_fill = num_info.zerofill;
280 else if (num_info.zerofill != was_zero_fill && !was_maybe_zerofill)
281 can_be_still_num = 0;
282 if (can_be_still_num)
283 can_be_still_num = get_ev_num_info(&ev_num_info, &num_info, res->ptr());
284 was_maybe_zerofill = num_info.maybe_zerofill;
293 min_length = max_length = length; sum=length;
298 if (length < min_length)
300 if (length > max_length)
303 if (sortcmp(res, &min_arg,item->collation.collation) < 0)
305 if (sortcmp(res, &max_arg,item->collation.collation) > 0)
313 if (!tree_search(&tree, (
void*) &s, tree.custom_arg))
316 if (!tree_insert(&tree, (
void*) &s, 0, tree.custom_arg))
323 memset(&s, 0,
sizeof(s));
324 if ((treemem += length) > pc->max_treemem)
333 if ((num_info.zerofill && (max_length != min_length)) ||
334 (was_zero_fill && (max_length != min_length)))
335 can_be_still_num = 0;
339 void field_real::add()
341 char buff[MAX_FIELD_WIDTH], *ptr, *end;
342 double num= item->val_result();
343 uint length, zero_count, decs;
346 if (item->null_value)
354 if ((decs = decimals()) == NOT_FIXED_DEC)
356 length= sprintf(buff,
"%g", num);
357 if (rint(num) != num)
358 max_notzero_dec_len = 1;
363 buff[
sizeof(buff)-1]=0;
364 snprintf(buff,
sizeof(buff)-1,
"%-.*f", (
int) decs, num);
365 length = (uint) strlen(buff);
367 length= sprintf(buff,
"%-.*f", (
int) decs, num);
371 end = buff + length - 1 - decs + max_notzero_dec_len;
374 for (ptr = buff + length - 1; ptr > end && *ptr ==
'0'; ptr--)
377 if ((decs - zero_count > max_notzero_dec_len))
378 max_notzero_dec_len = decs - zero_count;
383 if (!(element = tree_insert(&tree, (
void*) &num, 0, tree.custom_arg)))
392 else if (element->count == 1 && (tree_elements++) >= pc->max_tree_elements)
402 min_arg = max_arg = sum = num;
404 min_length = max_length = length;
409 sum_sqr += num * num;
410 if (length < min_length)
412 if (length > max_length)
414 if (compare_double(&num, &min_arg) < 0)
416 if (compare_double(&num, &max_arg) > 0)
422 void field_decimal::add()
425 my_decimal dec_buf, *dec= item->val_decimal_result(&dec_buf);
430 if (item->null_value)
436 my_decimal_round(E_DEC_FATAL_ERROR, dec, item->decimals, FALSE,&rounded);
439 length= my_decimal_string_length(dec);
441 if (decimal_is_zero(dec))
447 my_decimal2binary(E_DEC_FATAL_ERROR, dec, buf,
448 item->max_length, item->decimals);
449 if (!(element = tree_insert(&tree, (
void*)buf, 0, tree.custom_arg)))
458 else if (element->count == 1 && (tree_elements++) >= pc->max_tree_elements)
468 min_arg = max_arg = sum[0] = *dec;
469 my_decimal_mul(E_DEC_FATAL_ERROR, sum_sqr, dec, dec);
471 min_length = max_length = length;
473 else if (!decimal_is_zero(dec))
475 int next_cur_sum= cur_sum ^ 1;
478 my_decimal_add(E_DEC_FATAL_ERROR, sum+next_cur_sum, sum+cur_sum, dec);
479 my_decimal_mul(E_DEC_FATAL_ERROR, &sqr_buf, dec, dec);
480 my_decimal_add(E_DEC_FATAL_ERROR,
481 sum_sqr+next_cur_sum, sum_sqr+cur_sum, &sqr_buf);
482 cur_sum= next_cur_sum;
483 if (length < min_length)
485 if (length > max_length)
499 void field_longlong::add()
501 char buff[MAX_FIELD_WIDTH];
502 longlong num= item->val_int_result();
503 uint length= (uint) (longlong10_to_str(num, buff, -10) - buff);
506 if (item->null_value)
516 if (!(element = tree_insert(&tree, (
void*) &num, 0, tree.custom_arg)))
525 else if (element->count == 1 && (tree_elements++) >= pc->max_tree_elements)
535 min_arg = max_arg = sum = num;
537 min_length = max_length = length;
542 sum_sqr += num * num;
543 if (length < min_length)
545 if (length > max_length)
547 if (compare_longlong(&num, &min_arg) < 0)
549 if (compare_longlong(&num, &max_arg) > 0)
555 void field_ulonglong::add()
557 char buff[MAX_FIELD_WIDTH];
558 longlong num= item->val_int_result();
559 uint length= (uint) (longlong10_to_str(num, buff, 10) - buff);
562 if (item->null_value)
572 if (!(element = tree_insert(&tree, (
void*) &num, 0, tree.custom_arg)))
581 else if (element->count == 1 && (tree_elements++) >= pc->max_tree_elements)
591 min_arg = max_arg = sum = num;
593 min_length = max_length = length;
598 sum_sqr += num * num;
599 if (length < min_length)
601 if (length > max_length)
603 if (compare_ulonglong((ulonglong*) &num, &min_arg) < 0)
605 if (compare_ulonglong((ulonglong*) &num, &max_arg) > 0)
617 for (;f != f_end; f++)
625 bool select_analyse::send_eof()
628 char buff[MAX_FIELD_WIDTH];
629 String *res, s_min(buff,
sizeof(buff),&my_charset_bin),
630 s_max(buff,
sizeof(buff),&my_charset_bin),
631 ans(buff,
sizeof(buff),&my_charset_bin);
636 for (; f != f_end; f++)
638 func_items[0]->set((*f)->item->full_name());
641 func_items[1]->null_value = 1;
642 func_items[2]->null_value = 1;
646 func_items[1]->null_value = 0;
647 res = (*f)->get_min_arg(&s_min);
648 func_items[1]->set(res->ptr(), res->length(), res->charset());
649 func_items[2]->null_value = 0;
650 res = (*f)->get_max_arg(&s_max);
651 func_items[2]->set(res->ptr(), res->length(), res->charset());
653 func_items[3]->set((longlong) (*f)->min_length);
654 func_items[4]->set((longlong) (*f)->max_length);
655 func_items[5]->set((longlong) (*f)->empty);
656 func_items[6]->set((longlong) (*f)->nulls);
657 res = (*f)->avg(&s_max, rows);
658 func_items[7]->set(res->ptr(), res->length(), res->charset());
659 func_items[8]->null_value = 0;
660 res = (*f)->std(&s_max, rows);
662 func_items[8]->null_value = 1;
664 func_items[8]->set(res->ptr(), res->length(), res->charset());
675 if (((*f)->treemem || (*f)->tree_elements) &&
676 (*f)->tree.elements_in_tree &&
677 (((*f)->treemem ? max_treemem : max_tree_elements) >
678 (((*f)->treemem ? (*f)->treemem : (*f)->tree_elements) +
679 ((*f)->tree.elements_in_tree * 3 - 1 + 6))))
682 String tmp_str(tmp,
sizeof(tmp),&my_charset_bin);
685 tree_info.str = &tmp_str;
687 tree_info.item = (*f)->item;
689 tmp_str.set(STRING_WITH_LEN(
"ENUM("),&my_charset_bin);
690 tree_walk(&(*f)->tree, (*f)->collect_enum(), (
char*) &tree_info,
695 tmp_str.append(STRING_WITH_LEN(
" NOT NULL"));
696 output_str_length = tmp_str.length();
697 func_items[9]->set(tmp_str.ptr(), tmp_str.length(), tmp_str.charset());
698 if (result->send_data(result_fields))
704 if (!(*f)->treemem && !(*f)->tree_elements)
705 ans.append(STRING_WITH_LEN(
"CHAR(0)"));
706 else if ((*f)->item->type() == Item::FIELD_ITEM)
708 switch (((
Item_field*) (*f)->item)->field->real_type())
710 case MYSQL_TYPE_TIMESTAMP:
711 ans.append(STRING_WITH_LEN(
"TIMESTAMP"));
713 case MYSQL_TYPE_DATETIME:
714 ans.append(STRING_WITH_LEN(
"DATETIME"));
716 case MYSQL_TYPE_DATE:
717 case MYSQL_TYPE_NEWDATE:
718 ans.append(STRING_WITH_LEN(
"DATE"));
721 ans.append(STRING_WITH_LEN(
"SET"));
723 case MYSQL_TYPE_YEAR:
724 ans.append(STRING_WITH_LEN(
"YEAR"));
726 case MYSQL_TYPE_TIME:
727 ans.append(STRING_WITH_LEN(
"TIME"));
729 case MYSQL_TYPE_DECIMAL:
730 ans.append(STRING_WITH_LEN(
"DECIMAL"));
733 ans.append(STRING_WITH_LEN(
" ZEROFILL"));
736 (*f)->get_opt_type(&ans, rows);
741 ans.append(STRING_WITH_LEN(
" NOT NULL"));
742 func_items[9]->set(ans.ptr(), ans.length(), ans.charset());
743 if (result->send_data(result_fields))
747 return result->send_eof();
754 void field_str::get_opt_type(
String *answer, ha_rows total_rows)
756 char buff[MAX_FIELD_WIDTH];
758 if (can_be_still_num)
760 if (num_info.is_float)
761 sprintf(buff,
"DOUBLE");
762 else if (num_info.decimals)
764 if (num_info.dval > -FLT_MAX && num_info.dval < FLT_MAX)
765 sprintf(buff,
"FLOAT(%d,%d)", (num_info.integers + num_info.decimals), num_info.decimals);
767 sprintf(buff,
"DOUBLE(%d,%d)", (num_info.integers + num_info.decimals), num_info.decimals);
769 else if (ev_num_info.llval >= -128 &&
770 ev_num_info.ullval <=
771 (ulonglong) (ev_num_info.llval >= 0 ? 255 : 127))
772 sprintf(buff,
"TINYINT(%d)", num_info.integers);
773 else if (ev_num_info.llval >= INT_MIN16 &&
774 ev_num_info.ullval <= (ulonglong) (ev_num_info.llval >= 0 ?
775 UINT_MAX16 : INT_MAX16))
776 sprintf(buff,
"SMALLINT(%d)", num_info.integers);
777 else if (ev_num_info.llval >= INT_MIN24 &&
778 ev_num_info.ullval <= (ulonglong) (ev_num_info.llval >= 0 ?
779 UINT_MAX24 : INT_MAX24))
780 sprintf(buff,
"MEDIUMINT(%d)", num_info.integers);
781 else if (ev_num_info.llval >= INT_MIN32 &&
782 ev_num_info.ullval <= (ulonglong) (ev_num_info.llval >= 0 ?
783 UINT_MAX32 : INT_MAX32))
784 sprintf(buff,
"INT(%d)", num_info.integers);
786 sprintf(buff,
"BIGINT(%d)", num_info.integers);
787 answer->append(buff, (uint) strlen(buff));
788 if (ev_num_info.llval >= 0 && ev_num_info.min_dval >= 0)
789 answer->append(STRING_WITH_LEN(
" UNSIGNED"));
790 if (num_info.zerofill)
791 answer->append(STRING_WITH_LEN(
" ZEROFILL"));
793 else if (max_length < 256)
797 if (item->collation.collation == &my_charset_bin)
798 answer->append(STRING_WITH_LEN(
"TINYBLOB"));
800 answer->append(STRING_WITH_LEN(
"TINYTEXT"));
802 else if ((max_length * (total_rows - nulls)) < (sum + total_rows))
804 sprintf(buff,
"CHAR(%d)", (
int) max_length);
805 answer->append(buff, (uint) strlen(buff));
809 sprintf(buff,
"VARCHAR(%d)", (
int) max_length);
810 answer->append(buff, (uint) strlen(buff));
813 else if (max_length < (1L << 16))
815 if (item->collation.collation == &my_charset_bin)
816 answer->append(STRING_WITH_LEN(
"BLOB"));
818 answer->append(STRING_WITH_LEN(
"TEXT"));
820 else if (max_length < (1L << 24))
822 if (item->collation.collation == &my_charset_bin)
823 answer->append(STRING_WITH_LEN(
"MEDIUMBLOB"));
825 answer->append(STRING_WITH_LEN(
"MEDIUMTEXT"));
829 if (item->collation.collation == &my_charset_bin)
830 answer->append(STRING_WITH_LEN(
"LONGBLOB"));
832 answer->append(STRING_WITH_LEN(
"LONGTEXT"));
837 void field_real::get_opt_type(
String *answer,
838 ha_rows total_rows __attribute__((unused)))
840 char buff[MAX_FIELD_WIDTH];
842 if (!max_notzero_dec_len)
844 int len= (int) max_length - ((item->decimals == NOT_FIXED_DEC) ?
845 0 : (item->decimals + 1));
847 if (min_arg >= -128 && max_arg <= (min_arg >= 0 ? 255 : 127))
848 sprintf(buff,
"TINYINT(%d)", len);
849 else if (min_arg >= INT_MIN16 && max_arg <= (min_arg >= 0 ?
850 UINT_MAX16 : INT_MAX16))
851 sprintf(buff,
"SMALLINT(%d)", len);
852 else if (min_arg >= INT_MIN24 && max_arg <= (min_arg >= 0 ?
853 UINT_MAX24 : INT_MAX24))
854 sprintf(buff,
"MEDIUMINT(%d)", len);
855 else if (min_arg >= INT_MIN32 && max_arg <= (min_arg >= 0 ?
856 UINT_MAX32 : INT_MAX32))
857 sprintf(buff,
"INT(%d)", len);
859 sprintf(buff,
"BIGINT(%d)", len);
860 answer->append(buff, (uint) strlen(buff));
862 answer->append(STRING_WITH_LEN(
" UNSIGNED"));
864 else if (item->decimals == NOT_FIXED_DEC)
866 if (min_arg >= -FLT_MAX && max_arg <= FLT_MAX)
867 answer->append(STRING_WITH_LEN(
"FLOAT"));
869 answer->append(STRING_WITH_LEN(
"DOUBLE"));
873 if (min_arg >= -FLT_MAX && max_arg <= FLT_MAX)
874 sprintf(buff,
"FLOAT(%d,%d)", (
int) max_length - (item->decimals + 1) + max_notzero_dec_len,
875 max_notzero_dec_len);
877 sprintf(buff,
"DOUBLE(%d,%d)", (
int) max_length - (item->decimals + 1) + max_notzero_dec_len,
878 max_notzero_dec_len);
879 answer->append(buff, (uint) strlen(buff));
882 if (item->type() == Item::FIELD_ITEM &&
884 (max_length - (item->decimals + 1)) != 1 &&
886 answer->append(STRING_WITH_LEN(
" ZEROFILL"));
890 void field_longlong::get_opt_type(
String *answer,
891 ha_rows total_rows __attribute__((unused)))
893 char buff[MAX_FIELD_WIDTH];
895 if (min_arg >= -128 && max_arg <= (min_arg >= 0 ? 255 : 127))
896 sprintf(buff,
"TINYINT(%d)", (
int) max_length);
897 else if (min_arg >= INT_MIN16 && max_arg <= (min_arg >= 0 ?
898 UINT_MAX16 : INT_MAX16))
899 sprintf(buff,
"SMALLINT(%d)", (
int) max_length);
900 else if (min_arg >= INT_MIN24 && max_arg <= (min_arg >= 0 ?
901 UINT_MAX24 : INT_MAX24))
902 sprintf(buff,
"MEDIUMINT(%d)", (
int) max_length);
903 else if (min_arg >= INT_MIN32 && max_arg <= (min_arg >= 0 ?
904 UINT_MAX32 : INT_MAX32))
905 sprintf(buff,
"INT(%d)", (
int) max_length);
907 sprintf(buff,
"BIGINT(%d)", (
int) max_length);
908 answer->append(buff, (uint) strlen(buff));
910 answer->append(STRING_WITH_LEN(
" UNSIGNED"));
913 if ((item->type() == Item::FIELD_ITEM) &&
917 answer->append(STRING_WITH_LEN(
" ZEROFILL"));
921 void field_ulonglong::get_opt_type(
String *answer,
922 ha_rows total_rows __attribute__((unused)))
924 char buff[MAX_FIELD_WIDTH];
927 sprintf(buff,
"TINYINT(%d) UNSIGNED", (
int) max_length);
928 else if (max_arg <= ((2 * INT_MAX16) + 1))
929 sprintf(buff,
"SMALLINT(%d) UNSIGNED", (
int) max_length);
930 else if (max_arg <= ((2 * INT_MAX24) + 1))
931 sprintf(buff,
"MEDIUMINT(%d) UNSIGNED", (
int) max_length);
932 else if (max_arg < (((ulonglong) 1) << 32))
933 sprintf(buff,
"INT(%d) UNSIGNED", (
int) max_length);
935 sprintf(buff,
"BIGINT(%d) UNSIGNED", (
int) max_length);
937 answer->append(buff, (uint) strlen(buff));
938 if (item->type() == Item::FIELD_ITEM &&
942 answer->append(STRING_WITH_LEN(
" ZEROFILL"));
946 void field_decimal::get_opt_type(
String *answer,
947 ha_rows total_rows __attribute__((unused)))
950 char buff[MAX_FIELD_WIDTH];
953 my_decimal_set_zero(&zero);
956 length= my_snprintf(buff,
sizeof(buff),
"DECIMAL(%d, %d)",
957 (
int) (max_length - (item->decimals ? 1 : 0)),
960 length= (uint) (strmov(buff+length,
" UNSIGNED")- buff);
961 answer->append(buff, length);
967 my_decimal2string(E_DEC_FATAL_ERROR, &min_arg, 0, 0,
'0', str);
974 my_decimal2string(E_DEC_FATAL_ERROR, &max_arg, 0, 0,
'0', str);
983 s->set_real((
double) 0.0, 1,my_thd_charset);
987 int prec_increment= current_thd->variables.div_precincrement;
989 int2my_decimal(E_DEC_FATAL_ERROR, rows - nulls, FALSE, &num);
990 my_decimal_div(E_DEC_FATAL_ERROR, &avg_val, sum+cur_sum, &num, prec_increment);
992 my_decimal_round(E_DEC_FATAL_ERROR, &avg_val,
993 min(sum[cur_sum].frac + prec_increment, DECIMAL_MAX_SCALE),
995 my_decimal2string(E_DEC_FATAL_ERROR, &rounded_avg, 0, 0,
'0', s);
1002 if (!(rows - nulls))
1004 s->set_real((
double) 0.0, 1,my_thd_charset);
1009 int prec_increment= current_thd->variables.div_precincrement;
1011 int2my_decimal(E_DEC_FATAL_ERROR, rows - nulls, FALSE, &num);
1012 my_decimal_mul(E_DEC_FATAL_ERROR, &sum2, sum+cur_sum, sum+cur_sum);
1013 my_decimal_div(E_DEC_FATAL_ERROR, &tmp, &sum2, &num, prec_increment);
1014 my_decimal_sub(E_DEC_FATAL_ERROR, &sum2, sum_sqr+cur_sum, &tmp);
1015 my_decimal_div(E_DEC_FATAL_ERROR, &tmp, &sum2, &num, prec_increment);
1016 my_decimal2double(E_DEC_FATAL_ERROR, &tmp, &std_sqr);
1017 s->set_real(((
double) std_sqr <= 0.0 ? 0.0 : sqrt(std_sqr)),
1018 min(item->decimals + prec_increment, NOT_FIXED_DEC), my_thd_charset);
1024 int collect_string(
String *element,
1025 element_count count __attribute__((unused)),
1029 info->str->append(
',');
1032 info->str->append(
'\'');
1033 if (append_escaped(info->str, element))
1035 info->str->append(
'\'');
1040 int collect_real(
double *element, element_count count __attribute__((unused)),
1043 char buff[MAX_FIELD_WIDTH];
1044 String s(buff,
sizeof(buff),current_thd->charset());
1047 info->str->append(
',');
1050 info->str->append(
'\'');
1051 s.set_real(*element, info->item->decimals, current_thd->charset());
1052 info->str->append(s);
1053 info->str->append(
'\'');
1058 int collect_decimal(uchar *element, element_count count,
1062 String s(buff,
sizeof(buff),&my_charset_bin);
1065 info->str->append(
',');
1069 binary2my_decimal(E_DEC_FATAL_ERROR, element, &dec,
1070 info->item->max_length, info->item->decimals);
1072 info->str->append(
'\'');
1073 my_decimal2string(E_DEC_FATAL_ERROR, &dec, 0, 0,
'0', &s);
1074 info->str->append(s);
1075 info->str->append(
'\'');
1080 int collect_longlong(longlong *element,
1081 element_count count __attribute__((unused)),
1084 char buff[MAX_FIELD_WIDTH];
1085 String s(buff,
sizeof(buff),&my_charset_bin);
1088 info->str->append(
',');
1091 info->str->append(
'\'');
1092 s.set(*element, current_thd->charset());
1093 info->str->append(s);
1094 info->str->append(
'\'');
1099 int collect_ulonglong(ulonglong *element,
1100 element_count count __attribute__((unused)),
1103 char buff[MAX_FIELD_WIDTH];
1104 String s(buff,
sizeof(buff),&my_charset_bin);
1107 info->str->append(
',');
1110 info->str->append(
'\'');
1111 s.set(*element, current_thd->charset());
1112 info->str->append(s);
1113 info->str->append(
'\'');
1121 bool select_analyse::change_columns()
1125 func_items[1]->maybe_null = 1;
1127 func_items[2]->maybe_null = 1;
1134 func_items[8]->maybe_null = 1;
1136 max(64
U, output_str_length));
1137 result_fields.empty();
1138 for (uint
i = 0;
i < array_elements(func_items);
i++)
1140 if (func_items[
i] == NULL)
1142 result_fields.push_back(func_items[
i]);
1148 void select_analyse::cleanup()
1152 for (
field_info **f= f_info; f != f_end; f++)
1154 f_info= f_end= NULL;
1157 output_str_length= 0;
1161 bool select_analyse::send_result_set_metadata(
List<Item> &fields, uint flag)
1163 return (init(fields) || change_columns() ||
1164 result->send_result_set_metadata(result_fields, flag));
1168 void select_analyse::abort_result_set()
1171 return result->abort_result_set();
1175 int compare_double(
const double *s,
const double *t)
1177 return ((*s < *t) ? -1 : *s > *t ? 1 : 0);
1180 int compare_longlong(
const longlong *s,
const longlong *t)
1182 return ((*s < *t) ? -1 : *s > *t ? 1 : 0);
1185 int compare_ulonglong(
const ulonglong *s,
const ulonglong *t)
1187 return ((*s < *t) ? -1 : *s > *t ? 1 : 0);
1191 uint check_ulonglong(
const char *str, uint length)
1193 const char *long_str =
"2147483647", *ulonglong_str =
"18446744073709551615";
1194 const uint long_len = 10, ulonglong_len = 20;
1196 while (*str ==
'0' && length)
1200 if (length < long_len)
1203 uint smaller, bigger;
1206 if (length == long_len)
1212 else if (length > ulonglong_len)
1216 cmp = ulonglong_str;
1218 bigger = DECIMAL_NUM;
1220 while (*cmp && *cmp++ == *str++) ;
1221 return ((uchar) str[-1] <= (uchar) cmp[-1]) ? smaller : bigger;
1245 char *from, *end, c;
1247 if (to_str->
realloc(to_str->length() + from_str->length()))
1250 from= (
char*) from_str->ptr();
1251 end= from + from_str->length();
1252 for (; from < end; from++)
1266 goto normal_character;
1268 if (to_str->append(
'\\'))
1272 if (to_str->append(c))