@@ -7829,6 +7829,188 @@ bool Item::cache_const_expr_analyzer(uchar **arg)
7829
7829
}
7830
7830
7831
7831
7832
+ /* *
7833
+ Set the maximum number of characters required by any of the items in args.
7834
+ */
7835
+ void Item::aggregate_char_length (Item **args, uint nitems)
7836
+ {
7837
+ uint32 char_length= 0 ;
7838
+ for (uint i= 0 ; i < nitems; i++)
7839
+ set_if_bigger (char_length, args[i]->max_char_length ());
7840
+ fix_char_length (char_length);
7841
+ }
7842
+
7843
+
7844
+ /* *
7845
+ Set ::max_length and ::decimals of function if function is floating point and
7846
+ result length/precision depends on argument ones.
7847
+
7848
+ @param item Argument array.
7849
+ @param nitems Number of arguments in the array.
7850
+ */
7851
+ void Item::aggregate_float_properties (Item **item, uint nitems)
7852
+ {
7853
+ DBUG_ASSERT (result_type () == REAL_RESULT);
7854
+ uint32 length= 0 ;
7855
+ uint8 decimals_cnt= 0 ;
7856
+ uint32 maxl= 0 ;
7857
+ for (uint i=0 ; i < nitems; i++)
7858
+ {
7859
+ if (decimals_cnt != NOT_FIXED_DEC)
7860
+ {
7861
+ set_if_bigger (decimals_cnt, item[i]->decimals );
7862
+ set_if_bigger (length, (item[i]->max_length - item[i]->decimals ));
7863
+ }
7864
+ set_if_bigger (maxl, item[i]->max_length );
7865
+ }
7866
+ if (decimals_cnt != NOT_FIXED_DEC)
7867
+ {
7868
+ maxl= length;
7869
+ length+= decimals_cnt;
7870
+ if (length < maxl) // If previous operation gave overflow
7871
+ maxl= UINT_MAX32;
7872
+ else
7873
+ maxl= length;
7874
+ }
7875
+
7876
+ this ->max_length = maxl;
7877
+ this ->decimals = decimals_cnt;
7878
+ }
7879
+
7880
+ /* *
7881
+ Set precision and decimals of function when this depends on arguments'
7882
+ values for these quantities.
7883
+
7884
+ @param item Argument array.
7885
+ @param nitems Number of arguments in the array.
7886
+ */
7887
+ void Item::aggregate_decimal_properties (Item **item, uint nitems)
7888
+ {
7889
+ DBUG_ASSERT (result_type () == DECIMAL_RESULT);
7890
+ int max_int_part= 0 ;
7891
+ uint8 decimal_cnt= 0 ;
7892
+ for (uint i=0 ; i < nitems ; i++)
7893
+ {
7894
+ set_if_bigger (decimal_cnt, item[i]->decimals );
7895
+ set_if_bigger (max_int_part, item[i]->decimal_int_part ());
7896
+ }
7897
+ int precision= min (max_int_part + decimal_cnt, DECIMAL_MAX_PRECISION);
7898
+ set_data_type_decimal (precision, decimal_cnt);
7899
+ }
7900
+
7901
+
7902
+ /* *
7903
+ Set fractional seconds precision for temporal functions.
7904
+
7905
+ @param item Argument array
7906
+ @param nitems Number of arguments in the array.
7907
+ */
7908
+ void Item::aggregate_temporal_properties (Item **item, uint nitems)
7909
+ {
7910
+ DBUG_ASSERT (result_type () == STRING_RESULT);
7911
+ uint8 decimal_cnt= 0 ;
7912
+
7913
+ switch (data_type ())
7914
+ {
7915
+ case MYSQL_TYPE_DATETIME:
7916
+ for (uint i= 0 ; i < nitems; i++)
7917
+ set_if_bigger (decimal_cnt, item[i]->datetime_precision ());
7918
+ set_if_smaller (decimal_cnt, DATETIME_MAX_DECIMALS);
7919
+ set_data_type_datetime (decimal_cnt);
7920
+ break ;
7921
+
7922
+ case MYSQL_TYPE_TIMESTAMP:
7923
+ for (uint i= 0 ; i < nitems; i++)
7924
+ set_if_bigger (decimal_cnt, item[i]->datetime_precision ());
7925
+ set_if_smaller (decimal_cnt, DATETIME_MAX_DECIMALS);
7926
+ set_data_type_timestamp (decimal_cnt);
7927
+ break ;
7928
+
7929
+ case MYSQL_TYPE_NEWDATE:
7930
+ DBUG_ASSERT (false );
7931
+ set_data_type_date ();
7932
+ set_data_type (MYSQL_TYPE_NEWDATE);
7933
+ break ;
7934
+
7935
+ case MYSQL_TYPE_DATE:
7936
+ set_data_type_date ();
7937
+ break ;
7938
+
7939
+ case MYSQL_TYPE_TIME:
7940
+ for (uint i= 0 ; i < nitems; i++)
7941
+ set_if_bigger (decimal_cnt, item[i]->time_precision ());
7942
+ set_if_smaller (decimal_cnt, DATETIME_MAX_DECIMALS);
7943
+ set_data_type_time (decimal_cnt);
7944
+ break ;
7945
+
7946
+ default :
7947
+ DBUG_ASSERT (false ); /* purecov: inspected */
7948
+ }
7949
+ }
7950
+
7951
+
7952
+ /* *
7953
+ Aggregate string properties (character set, collation and maximum length) for
7954
+ string function.q
7955
+
7956
+ @param field_type Field type.
7957
+ @param name Name of function
7958
+ @param items Argument array.
7959
+ @param nitems Number of arguments.
7960
+
7961
+ @retval False on success, true on error.
7962
+ */
7963
+ bool Item::aggregate_string_properties (enum_field_types field_type,
7964
+ const char *name,
7965
+ Item **items, uint nitems)
7966
+ {
7967
+ DBUG_ASSERT (result_type () == STRING_RESULT);
7968
+ if (agg_item_charsets_for_string_result (collation, name, items, nitems, 1 ))
7969
+ return true ;
7970
+ if (is_temporal_type (field_type))
7971
+ aggregate_temporal_properties (items, nitems);
7972
+ else
7973
+ {
7974
+ decimals= NOT_FIXED_DEC;
7975
+ aggregate_char_length (items, nitems);
7976
+ }
7977
+ return false ;
7978
+ }
7979
+
7980
+
7981
+ /* *
7982
+ This function is used to resolve type for numeric result type of CASE,
7983
+ COALESCE, IF and LEAD/LAG. COALESCE is a CASE abbreviation according to the
7984
+ standard.
7985
+
7986
+ @param result_type The desired result type
7987
+ @param item The arguments of func
7988
+ @param nitems The number of arguments
7989
+ */
7990
+ void Item::aggregate_num_type (Item_result result_type,
7991
+ Item **item,
7992
+ uint nitems)
7993
+ {
7994
+ switch (result_type)
7995
+ {
7996
+ case DECIMAL_RESULT:
7997
+ aggregate_decimal_properties (item, nitems);
7998
+ break ;
7999
+ case REAL_RESULT:
8000
+ aggregate_float_properties (item, nitems);
8001
+ break ;
8002
+ case INT_RESULT:
8003
+ case STRING_RESULT:
8004
+ aggregate_char_length (item, nitems);
8005
+ decimals= 0 ;
8006
+ break ;
8007
+ case ROW_RESULT:
8008
+ default :
8009
+ DBUG_ASSERT (0 );
8010
+ }
8011
+ }
8012
+
8013
+
7832
8014
/* *
7833
8015
Cache item if needed.
7834
8016
@@ -10898,87 +11080,6 @@ void Item_result_field::cleanup()
10898
11080
}
10899
11081
10900
11082
10901
- /* *
10902
- Set char_length to the maximum number of characters required by any
10903
- of this function's or window function's arguments.
10904
-
10905
- This function doesn't set unsigned_flag. Call agg_result_type()
10906
- first to do that.
10907
- */
10908
- void Item_result_field::count_only_length (Item **item, uint nitems)
10909
- {
10910
- uint32 char_length= 0 ;
10911
- for (uint i= 0 ; i < nitems; i++)
10912
- set_if_bigger (char_length, item[i]->max_char_length ());
10913
- fix_char_length (char_length);
10914
- }
10915
-
10916
-
10917
- /* *
10918
- Count max_length and decimals for temporal functions or window functions.
10919
-
10920
- @param item Argument array
10921
- @param nitems Number of arguments in the array.
10922
- */
10923
- void Item_result_field::count_datetime_length (Item **item, uint nitems)
10924
- {
10925
- unsigned_flag= false ;
10926
- decimals= 0 ;
10927
- if (data_type () != MYSQL_TYPE_DATE)
10928
- {
10929
- for (uint i= 0 ; i < nitems; i++)
10930
- set_if_bigger (decimals,
10931
- data_type () == MYSQL_TYPE_TIME ?
10932
- item[i]->time_precision () : item[i]->datetime_precision ());
10933
- }
10934
- set_if_smaller (decimals, DATETIME_MAX_DECIMALS);
10935
- uint len= decimals ? (decimals + 1 ) : 0 ;
10936
- switch (data_type ())
10937
- {
10938
- case MYSQL_TYPE_DATETIME:
10939
- case MYSQL_TYPE_TIMESTAMP:
10940
- len+= MAX_DATETIME_WIDTH;
10941
- break ;
10942
- case MYSQL_TYPE_DATE:
10943
- case MYSQL_TYPE_NEWDATE:
10944
- len+= MAX_DATE_WIDTH;
10945
- break ;
10946
- case MYSQL_TYPE_TIME:
10947
- len+= MAX_TIME_WIDTH;
10948
- break ;
10949
- default :
10950
- DBUG_ASSERT (0 ); /* purecov: inspected */
10951
- }
10952
- fix_char_length (len);
10953
- }
10954
-
10955
-
10956
- /* *
10957
- Calculate max_length and decimals for STRING_RESULT functions or window
10958
- functions.
10959
-
10960
- @param field_type Field type.
10961
- @param items Argument array.
10962
- @param nitems Number of arguments.
10963
-
10964
- @retval False on success, true on error.
10965
- */
10966
- bool Item_result_field::count_string_result_length (enum_field_types field_type,
10967
- Item **items, uint nitems)
10968
- {
10969
- if (agg_item_charsets_for_string_result (collation, func_name (), items, nitems, 1 ))
10970
- return true ;
10971
- if (is_temporal_type (field_type))
10972
- count_datetime_length (items, nitems);
10973
- else
10974
- {
10975
- decimals= NOT_FIXED_DEC;
10976
- count_only_length (items, nitems);
10977
- }
10978
- return false ;
10979
- }
10980
-
10981
-
10982
11083
double Item_result_field::val_real_result ()
10983
11084
{
10984
11085
double res;
@@ -11112,7 +11213,6 @@ bool Item_result_field::is_null_result()
11112
11213
return res;
11113
11214
}
11114
11215
11115
-
11116
11216
/* *
11117
11217
Helper method: Convert string to the given charset, then print.
11118
11218
0 commit comments