MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / find_join_elements_new

Function find_join_elements_new

sqladvisor/main.cc:210–255  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

208}
209
210void find_join_elements_new(TABLE_LIST *join_table) {
211 if (join_table->nested_join != NULL) {
212 List_iterator<TABLE_LIST> li_join_list(
213 join_table->nested_join->join_list);
214 TABLE_LIST * table_right = li_join_list++;
215 TABLE_LIST * table_left = li_join_list++;
216 if ( ! is_not_tmp_table(table_right) || ! is_not_tmp_table(table_left)) {
217 return; //临时表不做处理
218 }
219
220 //当join条件是using on时,join条件存在nest_join_table中
221 if (join_table->join_using_fields != NULL
222 && join_table->is_natural_join) {
223 if (join_table->nested_join->join_list.elements == 2) {
224 mysql_sql_parse_join(join_table);
225 }
226 }
227 //right join会转换成left join. 所以不判断right join
228 if (table_right->outer_join == JOIN_TYPE_LEFT || table_right->straight
229 || table_left->outer_join == JOIN_TYPE_LEFT
230 || table_left->straight) {
231 //当左节点是叶子节点,右节点是非叶子节点时,即使是left join, 也是以右节点为驱动表
232 if (table_right->nested_join != NULL
233 && table_left->nested_join == NULL) {
234 find_join_elements_new(table_right);
235 if (table_left->join_cond())
236 mysql_sql_parse_join(table_left->join_cond());
237 } else {
238 find_join_elements_new(table_left);
239 if (table_right->join_cond())
240 mysql_sql_parse_join(table_right->join_cond());
241 }
242 } else {
243 find_join_elements_new(table_right);
244 find_join_elements_new(table_left);
245 }
246 } else {
247 //获取join条件,nest_join_table会为空,条件只保存在叶子节点中。如果左右都是叶子节点,一般只会存在右节点中
248 if (join_table->join_cond()) {
249 mysql_sql_parse_join(join_table->join_cond());
250 }
251 if (TABLE_DRIVERD.count(join_table) == 0) {
252 TABLE_DRIVERD.insert(join_table);
253 }
254 }
255}
256
257bool sql_execute(LEX *lex) {
258 enum_sql_command command_type = lex->sql_command;

Callers 1

mysql_sql_parse_adminFunction · 0.85

Calls 4

is_not_tmp_tableFunction · 0.85
mysql_sql_parse_joinFunction · 0.85
join_condMethod · 0.80
insertMethod · 0.45

Tested by

no test coverage detected