@@ -3679,6 +3679,41 @@ void select_max_min_finder_subselect::cleanup()
36793679}
36803680
36813681
3682+ void select_max_min_finder_subselect::set_op (const Type_handler *th)
3683+ {
3684+ if (th->is_val_native_ready ())
3685+ {
3686+ op= &select_max_min_finder_subselect::cmp_native;
3687+ return ;
3688+ }
3689+
3690+ switch (th->cmp_type ()) {
3691+ case REAL_RESULT:
3692+ op= &select_max_min_finder_subselect::cmp_real;
3693+ break ;
3694+ case INT_RESULT:
3695+ op= &select_max_min_finder_subselect::cmp_int;
3696+ break ;
3697+ case STRING_RESULT:
3698+ op= &select_max_min_finder_subselect::cmp_str;
3699+ break ;
3700+ case DECIMAL_RESULT:
3701+ op= &select_max_min_finder_subselect::cmp_decimal;
3702+ break ;
3703+ case TIME_RESULT:
3704+ if (th->field_type () == MYSQL_TYPE_TIME)
3705+ op= &select_max_min_finder_subselect::cmp_time;
3706+ else
3707+ op= &select_max_min_finder_subselect::cmp_str;
3708+ break ;
3709+ case ROW_RESULT:
3710+ // This case should never be chosen
3711+ DBUG_ASSERT (0 );
3712+ op= 0 ;
3713+ }
3714+ }
3715+
3716+
36823717int select_max_min_finder_subselect::send_data (List<Item> &items)
36833718{
36843719 DBUG_ENTER (" select_max_min_finder_subselect::send_data" );
@@ -3697,30 +3732,7 @@ int select_max_min_finder_subselect::send_data(List<Item> &items)
36973732 if (!cache)
36983733 {
36993734 cache= val_item->get_cache (thd);
3700- switch (val_item->cmp_type ()) {
3701- case REAL_RESULT:
3702- op= &select_max_min_finder_subselect::cmp_real;
3703- break ;
3704- case INT_RESULT:
3705- op= &select_max_min_finder_subselect::cmp_int;
3706- break ;
3707- case STRING_RESULT:
3708- op= &select_max_min_finder_subselect::cmp_str;
3709- break ;
3710- case DECIMAL_RESULT:
3711- op= &select_max_min_finder_subselect::cmp_decimal;
3712- break ;
3713- case TIME_RESULT:
3714- if (val_item->field_type () == MYSQL_TYPE_TIME)
3715- op= &select_max_min_finder_subselect::cmp_time;
3716- else
3717- op= &select_max_min_finder_subselect::cmp_str;
3718- break ;
3719- case ROW_RESULT:
3720- // This case should never be chosen
3721- DBUG_ASSERT (0 );
3722- op= 0 ;
3723- }
3735+ set_op (val_item->type_handler ());
37243736 }
37253737 cache->store (val_item);
37263738 it->store (0 , cache);
@@ -3814,6 +3826,26 @@ bool select_max_min_finder_subselect::cmp_str()
38143826 return (sortcmp (val1, val2, cache->collation .collation ) < 0 );
38153827}
38163828
3829+
3830+ bool select_max_min_finder_subselect::cmp_native ()
3831+ {
3832+ NativeBuffer<STRING_BUFFER_USUAL_SIZE> cvalue, mvalue;
3833+ Item *maxmin= ((Item_singlerow_subselect *)item)->element_index (0 );
3834+ bool cvalue_is_null= cache->val_native (thd, &cvalue);
3835+ bool mvalue_is_null= maxmin->val_native (thd, &mvalue);
3836+
3837+ /* Ignore NULLs for ANY and keep them for ALL subqueries */
3838+ if (cvalue_is_null)
3839+ return (is_all && !mvalue_is_null) || (!is_all && mvalue_is_null);
3840+ if (mvalue_is_null)
3841+ return !is_all;
3842+
3843+ const Type_handler *th= cache->type_handler ();
3844+ return fmax ? th->cmp_native (cvalue, mvalue) > 0 :
3845+ th->cmp_native (cvalue, mvalue) < 0 ;
3846+ }
3847+
3848+
38173849int select_exists_subselect::send_data (List<Item> &items)
38183850{
38193851 DBUG_ENTER (" select_exists_subselect::send_data" );
0 commit comments