@@ -3698,6 +3698,41 @@ void select_max_min_finder_subselect::cleanup()
36983698}
36993699
37003700
3701+ void select_max_min_finder_subselect::set_op (const Type_handler *th)
3702+ {
3703+ if (th->is_val_native_ready ())
3704+ {
3705+ op= &select_max_min_finder_subselect::cmp_native;
3706+ return ;
3707+ }
3708+
3709+ switch (th->cmp_type ()) {
3710+ case REAL_RESULT:
3711+ op= &select_max_min_finder_subselect::cmp_real;
3712+ break ;
3713+ case INT_RESULT:
3714+ op= &select_max_min_finder_subselect::cmp_int;
3715+ break ;
3716+ case STRING_RESULT:
3717+ op= &select_max_min_finder_subselect::cmp_str;
3718+ break ;
3719+ case DECIMAL_RESULT:
3720+ op= &select_max_min_finder_subselect::cmp_decimal;
3721+ break ;
3722+ case TIME_RESULT:
3723+ if (th->field_type () == MYSQL_TYPE_TIME)
3724+ op= &select_max_min_finder_subselect::cmp_time;
3725+ else
3726+ op= &select_max_min_finder_subselect::cmp_str;
3727+ break ;
3728+ case ROW_RESULT:
3729+ // This case should never be chosen
3730+ DBUG_ASSERT (0 );
3731+ op= 0 ;
3732+ }
3733+ }
3734+
3735+
37013736int select_max_min_finder_subselect::send_data (List<Item> &items)
37023737{
37033738 DBUG_ENTER (" select_max_min_finder_subselect::send_data" );
@@ -3716,30 +3751,7 @@ int select_max_min_finder_subselect::send_data(List<Item> &items)
37163751 if (!cache)
37173752 {
37183753 cache= val_item->get_cache (thd);
3719- switch (val_item->cmp_type ()) {
3720- case REAL_RESULT:
3721- op= &select_max_min_finder_subselect::cmp_real;
3722- break ;
3723- case INT_RESULT:
3724- op= &select_max_min_finder_subselect::cmp_int;
3725- break ;
3726- case STRING_RESULT:
3727- op= &select_max_min_finder_subselect::cmp_str;
3728- break ;
3729- case DECIMAL_RESULT:
3730- op= &select_max_min_finder_subselect::cmp_decimal;
3731- break ;
3732- case TIME_RESULT:
3733- if (val_item->field_type () == MYSQL_TYPE_TIME)
3734- op= &select_max_min_finder_subselect::cmp_time;
3735- else
3736- op= &select_max_min_finder_subselect::cmp_str;
3737- break ;
3738- case ROW_RESULT:
3739- // This case should never be choosen
3740- DBUG_ASSERT (0 );
3741- op= 0 ;
3742- }
3754+ set_op (val_item->type_handler ());
37433755 }
37443756 cache->store (val_item);
37453757 it->store (0 , cache);
@@ -3833,6 +3845,26 @@ bool select_max_min_finder_subselect::cmp_str()
38333845 return (sortcmp (val1, val2, cache->collation .collation ) < 0 );
38343846}
38353847
3848+
3849+ bool select_max_min_finder_subselect::cmp_native ()
3850+ {
3851+ NativeBuffer<STRING_BUFFER_USUAL_SIZE> cvalue, mvalue;
3852+ Item *maxmin= ((Item_singlerow_subselect *)item)->element_index (0 );
3853+ bool cvalue_is_null= cache->val_native (thd, &cvalue);
3854+ bool mvalue_is_null= maxmin->val_native (thd, &mvalue);
3855+
3856+ /* Ignore NULLs for ANY and keep them for ALL subqueries */
3857+ if (cvalue_is_null)
3858+ return (is_all && !mvalue_is_null) || (!is_all && mvalue_is_null);
3859+ if (mvalue_is_null)
3860+ return !is_all;
3861+
3862+ const Type_handler *th= cache->type_handler ();
3863+ return fmax ? th->cmp_native (cvalue, mvalue) > 0 :
3864+ th->cmp_native (cvalue, mvalue) < 0 ;
3865+ }
3866+
3867+
38363868int select_exists_subselect::send_data (List<Item> &items)
38373869{
38383870 DBUG_ENTER (" select_exists_subselect::send_data" );
0 commit comments