#include "mysql_priv.h"#include "sql_select.h"Include dependency graph for sql_derived.cc:

Go to the source code of this file.
Functions | |
| bool | mysql_handle_derived (LEX *lex, bool(*processor)(THD *, LEX *, TABLE_LIST *)) |
| bool | mysql_derived_prepare (THD *thd, LEX *lex, TABLE_LIST *orig_table_list) |
| bool | mysql_derived_filling (THD *thd, LEX *lex, TABLE_LIST *orig_table_list) |
| bool mysql_derived_filling | ( | THD * | thd, | |
| LEX * | lex, | |||
| TABLE_LIST * | orig_table_list | |||
| ) |
Definition at line 230 of file sql_derived.cc.
References st_table_list::derived, st_table_list::derived_result, FALSE, HA_POS_ERROR, mysql_select(), NULL, OPTION_FOUND_ROWS, SELECT_NO_UNLOCK, st_table_list::table, and TRUE.
Referenced by open_and_lock_tables().
00231 { 00232 TABLE *table= orig_table_list->table; 00233 SELECT_LEX_UNIT *unit= orig_table_list->derived; 00234 bool res= FALSE; 00235 00236 /*check that table creation pass without problem and it is derived table */ 00237 if (table && unit) 00238 { 00239 SELECT_LEX *first_select= unit->first_select(); 00240 select_union *derived_result= orig_table_list->derived_result; 00241 SELECT_LEX *save_current_select= lex->current_select; 00242 bool is_union= first_select->next_select() && 00243 first_select->next_select()->linkage == UNION_TYPE; 00244 if (is_union) 00245 { 00246 // execute union without clean up 00247 res= unit->exec(); 00248 } 00249 else 00250 { 00251 unit->set_limit(first_select); 00252 if (unit->select_limit_cnt == HA_POS_ERROR) 00253 first_select->options&= ~OPTION_FOUND_ROWS; 00254 00255 lex->current_select= first_select; 00256 res= mysql_select(thd, &first_select->ref_pointer_array, 00257 (TABLE_LIST*) first_select->table_list.first, 00258 first_select->with_wild, 00259 first_select->item_list, first_select->where, 00260 (first_select->order_list.elements+ 00261 first_select->group_list.elements), 00262 (ORDER *) first_select->order_list.first, 00263 (ORDER *) first_select->group_list.first, 00264 first_select->having, (ORDER*) NULL, 00265 (first_select->options | thd->options | 00266 SELECT_NO_UNLOCK), 00267 derived_result, unit, first_select); 00268 } 00269 00270 if (!res) 00271 { 00272 /* 00273 Here we entirely fix both TABLE_LIST and list of SELECT's as 00274 there were no derived tables 00275 */ 00276 if (derived_result->flush()) 00277 res= TRUE; 00278 00279 if (!lex->describe) 00280 unit->cleanup(); 00281 } 00282 else 00283 unit->cleanup(); 00284 lex->current_select= save_current_select; 00285 } 00286 return res; 00287 }
Here is the call graph for this function:

Here is the caller graph for this function:

| bool mysql_derived_prepare | ( | THD * | thd, | |
| LEX * | lex, | |||
| TABLE_LIST * | orig_table_list | |||
| ) |
Definition at line 102 of file sql_derived.cc.
References st_table_list::alias, check_duplicate_names(), create_options, st_table_list::db, st_table_list::db_length, DBUG_ENTER, DBUG_RETURN, st_table_list::derived, st_table_list::derived_result, st_table::derived_select_number, ER_BAD_FIELD_ERROR, ER_SP_DOES_NOT_EXIST, ER_VIEW_INVALID, exit, FALSE, st_table::file, free_tmp_table(), st_table_list::grant, st_table::grant, HA_STATUS_VARIABLE, handler::info(), LEX_STRING::length, st_table_list::merge_underlying_list, my_error(), MYF, st_table::next, NULL, st_grant_info::privilege, st_table_list::referencing_view, st_table::s, SELECT_ACL, st_table_list::set_underlying_merge(), LEX_STRING::str, st_table_list::table, st_table_share::table_name, st_table_list::table_name, st_table_list::table_name_length, TMP_TABLE, st_table_share::tmp_table, TMP_TABLE_ALL_COLUMNS, TRUE, and st_table_list::view.
Referenced by mysql_multi_update_prepare(), open_and_lock_tables(), and open_normal_and_derived_tables().
00103 { 00104 SELECT_LEX_UNIT *unit= orig_table_list->derived; 00105 ulonglong create_options; 00106 DBUG_ENTER("mysql_derived_prepare"); 00107 bool res= FALSE; 00108 if (unit) 00109 { 00110 SELECT_LEX *first_select= unit->first_select(); 00111 TABLE *table= 0; 00112 select_union *derived_result; 00113 bool is_union= first_select->next_select() && 00114 first_select->next_select()->linkage == UNION_TYPE; 00115 00116 /* prevent name resolving out of derived table */ 00117 for (SELECT_LEX *sl= first_select; sl; sl= sl->next_select()) 00118 sl->context.outer_context= 0; 00119 00120 if (!(derived_result= new select_union)) 00121 DBUG_RETURN(TRUE); // out of memory 00122 00123 // st_select_lex_unit::prepare correctly work for single select 00124 if ((res= unit->prepare(thd, derived_result, 0))) 00125 goto exit; 00126 00127 if ((res= check_duplicate_names(unit->types, 0))) 00128 goto exit; 00129 00130 create_options= (first_select->options | thd->options | 00131 TMP_TABLE_ALL_COLUMNS); 00132 /* 00133 Temp table is created so that it hounours if UNION without ALL is to be 00134 processed 00135 00136 As 'distinct' parameter we always pass FALSE (0), because underlying 00137 query will control distinct condition by itself. Correct test of 00138 distinct underlying query will be is_union && 00139 !unit->union_distinct->next_select() (i.e. it is union and last distinct 00140 SELECT is last SELECT of UNION). 00141 */ 00142 if ((res= derived_result->create_result_table(thd, &unit->types, FALSE, 00143 create_options, 00144 orig_table_list->alias))) 00145 goto exit; 00146 00147 table= derived_result->table; 00148 00149 exit: 00150 /* Hide "Unknown column" or "Unknown function" error */ 00151 if (orig_table_list->view) 00152 { 00153 if (thd->net.last_errno == ER_BAD_FIELD_ERROR || 00154 thd->net.last_errno == ER_SP_DOES_NOT_EXIST) 00155 { 00156 thd->clear_error(); 00157 my_error(ER_VIEW_INVALID, MYF(0), orig_table_list->db, 00158 orig_table_list->table_name); 00159 } 00160 } 00161 00162 /* 00163 if it is preparation PS only or commands that need only VIEW structure 00164 then we do not need real data and we can skip execution (and parameters 00165 is not defined, too) 00166 */ 00167 if (res) 00168 { 00169 if (table) 00170 free_tmp_table(thd, table); 00171 delete derived_result; 00172 } 00173 else 00174 { 00175 if (!thd->fill_derived_tables()) 00176 { 00177 delete derived_result; 00178 derived_result= NULL; 00179 } 00180 orig_table_list->derived_result= derived_result; 00181 orig_table_list->table= table; 00182 orig_table_list->table_name= table->s->table_name.str; 00183 orig_table_list->table_name_length= table->s->table_name.length; 00184 table->derived_select_number= first_select->select_number; 00185 table->s->tmp_table= TMP_TABLE; 00186 #ifndef NO_EMBEDDED_ACCESS_CHECKS 00187 if (orig_table_list->referencing_view) 00188 table->grant= orig_table_list->grant; 00189 else 00190 table->grant.privilege= SELECT_ACL; 00191 #endif 00192 orig_table_list->db= (char *)""; 00193 orig_table_list->db_length= 0; 00194 // Force read of table stats in the optimizer 00195 table->file->info(HA_STATUS_VARIABLE); 00196 /* Add new temporary table to list of open derived tables */ 00197 table->next= thd->derived_tables; 00198 thd->derived_tables= table; 00199 } 00200 } 00201 else if (orig_table_list->merge_underlying_list) 00202 orig_table_list->set_underlying_merge(); 00203 DBUG_RETURN(res); 00204 }
Here is the call graph for this function:

Here is the caller graph for this function:

| bool mysql_handle_derived | ( | LEX * | lex, | |
| bool(*)(THD *, LEX *, TABLE_LIST *) | processor | |||
| ) |
Definition at line 43 of file sql_derived.cc.
References FALSE, TRUE, and UNCACHEABLE_EXPLAIN.
Referenced by mysql_multi_update_prepare(), open_and_lock_tables(), and open_normal_and_derived_tables().
00044 { 00045 bool res= FALSE; 00046 if (lex->derived_tables) 00047 { 00048 lex->thd->derived_tables_processing= TRUE; 00049 for (SELECT_LEX *sl= lex->all_selects_list; 00050 sl; 00051 sl= sl->next_select_in_list()) 00052 { 00053 for (TABLE_LIST *cursor= sl->get_table_list(); 00054 cursor; 00055 cursor= cursor->next_local) 00056 { 00057 if ((res= (*processor)(lex->thd, lex, cursor))) 00058 goto out; 00059 } 00060 if (lex->describe) 00061 { 00062 /* 00063 Force join->join_tmp creation, because we will use this JOIN 00064 twice for EXPLAIN and we have to have unchanged join for EXPLAINing 00065 */ 00066 sl->uncacheable|= UNCACHEABLE_EXPLAIN; 00067 sl->master_unit()->uncacheable|= UNCACHEABLE_EXPLAIN; 00068 } 00069 } 00070 } 00071 out: 00072 lex->thd->derived_tables_processing= FALSE; 00073 return res; 00074 }
Here is the caller graph for this function:

1.4.7

