| 984 | */ |
| 985 | |
| 986 | static |
| 987 | bool mysql_derived_optimize(THD *thd, LEX *lex, TABLE_LIST *derived) |
| 988 | { |
| 989 | SELECT_LEX_UNIT *unit= derived->get_unit(); |
| 990 | SELECT_LEX *first_select= unit->first_select(); |
| 991 | SELECT_LEX *save_current_select= lex->current_select; |
| 992 | bool res= FALSE; |
| 993 | DBUG_ENTER("mysql_derived_optimize"); |
| 994 | DBUG_PRINT("enter", ("Alias: '%s' Unit: %p", |
| 995 | (derived->alias.str ? derived->alias.str : "<NULL>"), |
| 996 | derived->get_unit())); |
| 997 | if (derived->merged) |
| 998 | { |
| 999 | DBUG_PRINT("info", ("Irreversibly merged: exit")); |
| 1000 | DBUG_RETURN(FALSE); |
| 1001 | } |
| 1002 | |
| 1003 | if (derived->is_materialized_derived() && derived->dt_handler) |
| 1004 | { |
| 1005 | /* Create an object for execution of the query specifying the table */ |
| 1006 | if (!(derived->pushdown_derived= |
| 1007 | new (thd->mem_root) Pushdown_derived(derived, derived->dt_handler))) |
| 1008 | DBUG_RETURN(TRUE); |
| 1009 | } |
| 1010 | |
| 1011 | lex->current_select= first_select; |
| 1012 | |
| 1013 | if (unit->is_unit_op()) |
| 1014 | { |
| 1015 | if (unit->optimized) |
| 1016 | DBUG_RETURN(FALSE); |
| 1017 | // optimize union without execution |
| 1018 | res= unit->optimize(); |
| 1019 | } |
| 1020 | else if (unit->derived) |
| 1021 | { |
| 1022 | if (!derived->is_merged_derived()) |
| 1023 | { |
| 1024 | JOIN *join= first_select->join; |
| 1025 | unit->set_limit(unit->global_parameters()); |
| 1026 | if (join && |
| 1027 | join->optimization_state == JOIN::OPTIMIZATION_PHASE_1_DONE && |
| 1028 | join->with_two_phase_optimization) |
| 1029 | { |
| 1030 | if (unit->optimized_2) |
| 1031 | DBUG_RETURN(FALSE); |
| 1032 | unit->optimized_2= TRUE; |
| 1033 | } |
| 1034 | else |
| 1035 | { |
| 1036 | if (unit->optimized) |
| 1037 | DBUG_RETURN(FALSE); |
| 1038 | unit->optimized= TRUE; |
| 1039 | if (!join) |
| 1040 | { |
| 1041 | /* |
| 1042 | This happens when derived is used in SELECT for which |
| 1043 | zer_result_cause != 0. |
nothing calls this directly
no test coverage detected