#include <sql_select.h>
Inheritance diagram for JOIN:


Definition at line 201 of file sql_select.h.
| JOIN::JOIN | ( | const JOIN & | rhs | ) | [private] |
| JOIN::JOIN | ( | THD * | thd_arg, | |
| List< Item > & | fields_arg, | |||
| ulonglong | select_options_arg, | |||
| select_result * | result_arg | |||
| ) | [inline] |
Definition at line 310 of file sql_select.h.
References init().
00312 :fields_list(fields_arg) 00313 { 00314 init(thd_arg, fields_arg, select_options_arg, result_arg); 00315 }
Here is the call graph for this function:

| bool JOIN::alloc_func_list | ( | ) |
Definition at line 13378 of file sql_select.cc.
References DBUG_ENTER, DBUG_RETURN, base_list::elements, fields_list, rollup, send_group_parts, st_rollup::state, st_rollup::STATE_NONE, sum_funcs, sum_funcs_end, and tmp_table_param.
Referenced by exec(), and prepare().
13379 { 13380 uint func_count, group_parts; 13381 DBUG_ENTER("alloc_func_list"); 13382 13383 func_count= tmp_table_param.sum_func_count; 13384 /* 13385 If we are using rollup, we need a copy of the summary functions for 13386 each level 13387 */ 13388 if (rollup.state != ROLLUP::STATE_NONE) 13389 func_count*= (send_group_parts+1); 13390 13391 group_parts= send_group_parts; 13392 /* 13393 If distinct, reserve memory for possible 13394 disctinct->group_by optimization 13395 */ 13396 if (select_distinct) 13397 group_parts+= fields_list.elements; 13398 13399 /* This must use calloc() as rollup_make_fields depends on this */ 13400 sum_funcs= (Item_sum**) thd->calloc(sizeof(Item_sum**) * (func_count+1) + 13401 sizeof(Item_sum***) * (group_parts+1)); 13402 sum_funcs_end= (Item_sum***) (sum_funcs+func_count+1); 13403 DBUG_RETURN(sum_funcs == 0); 13404 }
Here is the caller graph for this function:

| bool JOIN::change_result | ( | select_result * | result | ) |
Definition at line 14830 of file sql_select.cc.
References DBUG_ENTER, DBUG_RETURN, FALSE, fields_list, procedure, result, select_lex, and TRUE.
Referenced by mysql_select(), and Sensitive_cursor::open().
14831 { 14832 DBUG_ENTER("JOIN::change_result"); 14833 result= res; 14834 if (!procedure && (result->prepare(fields_list, select_lex->master_unit()) || 14835 result->prepare2())) 14836 { 14837 DBUG_RETURN(TRUE); 14838 } 14839 DBUG_RETURN(FALSE); 14840 }
Here is the caller graph for this function:

| void JOIN::cleanup | ( | bool | full | ) |
Definition at line 5948 of file sql_select.cc.
References st_join_table::cleanup(), DBUG_ENTER, DBUG_VOID_RETURN, List< T >::delete_elements(), st_table::file, filesort_free_buffers(), free_io_cache(), group_fields, handler::ha_index_or_rnd_end(), join_tab, st_join_table::table, tmp_join, and tmp_table_param.
Referenced by destroy(), and join_free().
05949 { 05950 DBUG_ENTER("JOIN::cleanup"); 05951 05952 if (table) 05953 { 05954 JOIN_TAB *tab,*end; 05955 /* 05956 Only a sorted table may be cached. This sorted table is always the 05957 first non const table in join->table 05958 */ 05959 if (tables > const_tables) // Test for not-const tables 05960 { 05961 free_io_cache(table[const_tables]); 05962 filesort_free_buffers(table[const_tables]); 05963 } 05964 05965 if (full) 05966 { 05967 for (tab= join_tab, end= tab+tables; tab != end; tab++) 05968 tab->cleanup(); 05969 table= 0; 05970 tables= 0; 05971 } 05972 else 05973 { 05974 for (tab= join_tab, end= tab+tables; tab != end; tab++) 05975 { 05976 if (tab->table) 05977 tab->table->file->ha_index_or_rnd_end(); 05978 } 05979 } 05980 } 05981 /* 05982 We are not using tables anymore 05983 Unlock all tables. We may be in an INSERT .... SELECT statement. 05984 */ 05985 if (full) 05986 { 05987 if (tmp_join) 05988 tmp_table_param.copy_field= 0; 05989 group_fields.delete_elements(); 05990 /* 05991 We can't call delete_elements() on copy_funcs as this will cause 05992 problems in free_elements() as some of the elements are then deleted. 05993 */ 05994 tmp_table_param.copy_funcs.empty(); 05995 /* 05996 If we have tmp_join and 'this' JOIN is not tmp_join and 05997 tmp_table_param.copy_field's of them are equal then we have to remove 05998 pointer to tmp_table_param.copy_field from tmp_join, because it qill 05999 be removed in tmp_table_param.cleanup(). 06000 */ 06001 if (tmp_join && 06002 tmp_join != this && 06003 tmp_join->tmp_table_param.copy_field == 06004 tmp_table_param.copy_field) 06005 { 06006 tmp_join->tmp_table_param.copy_field= 06007 tmp_join->tmp_table_param.save_copy_field= 0; 06008 } 06009 tmp_table_param.cleanup(); 06010 } 06011 DBUG_VOID_RETURN; 06012 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void JOIN::clear | ( | ) |
Definition at line 14131 of file sql_select.cc.
References clear_tables(), copy_fields(), func, sum_funcs, and tmp_table_param.
Referenced by end_send_group(), and end_write_group().
14132 { 14133 clear_tables(this); 14134 copy_fields(&tmp_table_param); 14135 14136 if (sum_funcs) 14137 { 14138 Item_sum *func, **func_ptr= sum_funcs; 14139 while ((func= *(func_ptr++))) 14140 func->clear(); 14141 } 14142 }
Here is the call graph for this function:

Here is the caller graph for this function:

| int JOIN::destroy | ( | ) |
Definition at line 1851 of file sql_select.cc.
References cleanup(), st_join_table::cleanup(), cond_equal, DBUG_ENTER, DBUG_RETURN, delete_dynamic(), destroy(), error, exec_tmp_table1, exec_tmp_table2, free_tmp_table(), join_tab, keyuse, procedure, select, select_lex, tmp_join, and tmp_table_param.
Referenced by destroy().
01852 { 01853 DBUG_ENTER("JOIN::destroy"); 01854 select_lex->join= 0; 01855 01856 if (tmp_join) 01857 { 01858 if (join_tab != tmp_join->join_tab) 01859 { 01860 JOIN_TAB *tab, *end; 01861 for (tab= join_tab, end= tab+tables ; tab != end ; tab++) 01862 tab->cleanup(); 01863 } 01864 tmp_join->tmp_join= 0; 01865 tmp_table_param.copy_field=0; 01866 DBUG_RETURN(tmp_join->destroy()); 01867 } 01868 cond_equal= 0; 01869 01870 cleanup(1); 01871 if (exec_tmp_table1) 01872 free_tmp_table(thd, exec_tmp_table1); 01873 if (exec_tmp_table2) 01874 free_tmp_table(thd, exec_tmp_table2); 01875 delete select; 01876 delete_dynamic(&keyuse); 01877 delete procedure; 01878 DBUG_RETURN(error); 01879 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void JOIN::exec | ( | ) |
Definition at line 1310 of file sql_select.cc.
References all_fields, alloc_func_list(), calc_group_buffer(), Procedure::change_columns(), change_refs_to_tmp_fields(), change_to_use_tmp_fields(), SQL_SELECT::cond, Item::COND_FALSE, cond_value, conds, const_table_map, const_tables, count_field_types(), create_sort_index(), create_tmp_table(), DBUG_ENTER, DBUG_EXECUTE, DBUG_PRINT, DBUG_VOID_RETURN, st_table::distinct, do_select(), do_send_rows, base_list::elements, Procedure::end_of_records(), end_read_record(), error, exec_tmp_table1, exec_tmp_table2, FALSE, fields_list, st_table::file, st_join_table::first_inner, Procedure::flags, get_schema_tables_result(), group, st_table::group, group_list, HA_STATUS_VARIABLE, having, handler::info(), init_items_ref_array(), int(), st_join_table::is_using_loose_index_scan(), items0, items1, items2, items3, join_free(), join_tab, st_join_table::keyuse, st_reginfo::lock_type, make_cond_for_table(), make_group_fields(), make_simple_join(), make_sum_func_list(), st_table::map, no_order, OPTION_FOUND_ROWS, OPTION_SCHEMA_TABLE, order, print_where(), PROC_GROUP, procedure, procedure_fields_list, Item::quick_fix_field(), st_join_table::read_record, ref_pointer_array, st_table::reginfo, remove_duplicates(), result, return_zero_rows(), save_join_tab(), st_join_table::select, st_join_table::select_cond, select_describe(), select_distinct, select_lex, select_limit, select_options, Protocol::SEND_EOF, Protocol::SEND_NUM_ROWS, send_records, Procedure::send_row(), send_row_on_empty_set(), set_items_ref_array(), setup_copy_fields(), setup_sum_funcs(), simple_group, simple_order, skip_sort_order, sort_and_group, st_join_table::sorted, sum_funcs, sum_funcs2, sum_funcs_end, sum_funcs_end2, st_join_table::table, tables, tables_list, test_if_skip_sort_order(), test_if_subpart(), thd, TL_UNLOCK, tmp_all_fields1, tmp_all_fields2, tmp_all_fields3, tmp_fields_list1, tmp_fields_list2, tmp_fields_list3, tmp_having, tmp_join, tmp_table_param, Item::top_level_item(), TRUE, unit, Procedure::update_refs(), Item::update_used_tables(), Item::val_int(), and zero_result_cause.
Referenced by subselect_single_select_engine::exec(), and mysql_select().
01311 { 01312 List<Item> *columns_list= &fields_list; 01313 int tmp_error; 01314 DBUG_ENTER("JOIN::exec"); 01315 01316 error= 0; 01317 if (procedure) 01318 { 01319 procedure_fields_list= fields_list; 01320 if (procedure->change_columns(procedure_fields_list) || 01321 result->prepare(procedure_fields_list, unit)) 01322 { 01323 thd->limit_found_rows= thd->examined_row_count= 0; 01324 DBUG_VOID_RETURN; 01325 } 01326 columns_list= &procedure_fields_list; 01327 } 01328 (void) result->prepare2(); // Currently, this cannot fail. 01329 01330 if (!tables_list) 01331 { // Only test of functions 01332 if (select_options & SELECT_DESCRIBE) 01333 select_describe(this, FALSE, FALSE, FALSE, 01334 (zero_result_cause?zero_result_cause:"No tables used")); 01335 else 01336 { 01337 result->send_fields(*columns_list, 01338 Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF); 01339 /* 01340 We have to test for 'conds' here as the WHERE may not be constant 01341 even if we don't have any tables for prepared statements or if 01342 conds uses something like 'rand()'. 01343 */ 01344 if (cond_value != Item::COND_FALSE && 01345 (!conds || conds->val_int()) && 01346 (!having || having->val_int())) 01347 { 01348 if (do_send_rows && 01349 (procedure ? (procedure->send_row(procedure_fields_list) || 01350 procedure->end_of_records()) : result->send_data(fields_list))) 01351 error= 1; 01352 else 01353 { 01354 error= (int) result->send_eof(); 01355 send_records= ((select_options & OPTION_FOUND_ROWS) ? 1 : 01356 thd->sent_row_count); 01357 } 01358 } 01359 else 01360 { 01361 error=(int) result->send_eof(); 01362 send_records= 0; 01363 } 01364 } 01365 /* Single select (without union) always returns 0 or 1 row */ 01366 thd->limit_found_rows= send_records; 01367 thd->examined_row_count= 0; 01368 DBUG_VOID_RETURN; 01369 } 01370 thd->limit_found_rows= thd->examined_row_count= 0; 01371 01372 if (zero_result_cause) 01373 { 01374 (void) return_zero_rows(this, result, select_lex->leaf_tables, 01375 *columns_list, 01376 send_row_on_empty_set(), 01377 select_options, 01378 zero_result_cause, 01379 having); 01380 DBUG_VOID_RETURN; 01381 } 01382 01383 if (select_options & SELECT_DESCRIBE) 01384 { 01385 /* 01386 Check if we managed to optimize ORDER BY away and don't use temporary 01387 table to resolve ORDER BY: in that case, we only may need to do 01388 filesort for GROUP BY. 01389 */ 01390 if (!order && !no_order && (!skip_sort_order || !need_tmp)) 01391 { 01392 /* 01393 Reset 'order' to 'group_list' and reinit variables describing 01394 'order' 01395 */ 01396 order= group_list; 01397 simple_order= simple_group; 01398 skip_sort_order= 0; 01399 } 01400 if (order && 01401 (const_tables == tables || 01402 ((simple_order || skip_sort_order) && 01403 test_if_skip_sort_order(&join_tab[const_tables], order, 01404 select_limit, 0)))) 01405 order=0; 01406 having= tmp_having; 01407 select_describe(this, need_tmp, 01408 order != 0 && !skip_sort_order, 01409 select_distinct); 01410 DBUG_VOID_RETURN; 01411 } 01412 01413 JOIN *curr_join= this; 01414 List<Item> *curr_all_fields= &all_fields; 01415 List<Item> *curr_fields_list= &fields_list; 01416 TABLE *curr_tmp_table= 0; 01417 01418 if ((curr_join->select_lex->options & OPTION_SCHEMA_TABLE) && 01419 get_schema_tables_result(curr_join)) 01420 { 01421 DBUG_VOID_RETURN; 01422 } 01423 01424 /* Create a tmp table if distinct or if the sort is too complicated */ 01425 if (need_tmp) 01426 { 01427 if (tmp_join) 01428 { 01429 /* 01430 We are in a non cacheable sub query. Get the saved join structure 01431 after optimization. 01432 (curr_join may have been modified during last exection and we need 01433 to reset it) 01434 */ 01435 curr_join= tmp_join; 01436 } 01437 curr_tmp_table= exec_tmp_table1; 01438 01439 /* Copy data to the temporary table */ 01440 thd->proc_info= "Copying to tmp table"; 01441 DBUG_PRINT("info", ("%s", thd->proc_info)); 01442 if (!curr_join->sort_and_group && 01443 curr_join->const_tables != curr_join->tables) 01444 curr_join->join_tab[curr_join->const_tables].sorted= 0; 01445 if ((tmp_error= do_select(curr_join, (List<Item> *) 0, curr_tmp_table, 0))) 01446 { 01447 error= tmp_error; 01448 DBUG_VOID_RETURN; 01449 } 01450 curr_tmp_table->file->info(HA_STATUS_VARIABLE); 01451 01452 if (curr_join->having) 01453 curr_join->having= curr_join->tmp_having= 0; // Allready done 01454 01455 /* Change sum_fields reference to calculated fields in tmp_table */ 01456 curr_join->all_fields= *curr_all_fields; 01457 if (!items1) 01458 { 01459 items1= items0 + all_fields.elements; 01460 if (sort_and_group || curr_tmp_table->group) 01461 { 01462 if (change_to_use_tmp_fields(thd, items1, 01463 tmp_fields_list1, tmp_all_fields1, 01464 fields_list.elements, all_fields)) 01465 DBUG_VOID_RETURN; 01466 } 01467 else 01468 { 01469 if (change_refs_to_tmp_fields(thd, items1, 01470 tmp_fields_list1, tmp_all_fields1, 01471 fields_list.elements, all_fields)) 01472 DBUG_VOID_RETURN; 01473 } 01474 curr_join->tmp_all_fields1= tmp_all_fields1; 01475 curr_join->tmp_fields_list1= tmp_fields_list1; 01476 curr_join->items1= items1; 01477 } 01478 curr_all_fields= &tmp_all_fields1; 01479 curr_fields_list= &tmp_fields_list1; 01480 curr_join->set_items_ref_array(items1); 01481 01482 if (sort_and_group || curr_tmp_table->group) 01483 { 01484 curr_join->tmp_table_param.field_count+= 01485 curr_join->tmp_table_param.sum_func_count+ 01486 curr_join->tmp_table_param.func_count; 01487 curr_join->tmp_table_param.sum_func_count= 01488 curr_join->tmp_table_param.func_count= 0; 01489 } 01490 else 01491 { 01492 curr_join->tmp_table_param.field_count+= 01493 curr_join->tmp_table_param.func_count; 01494 curr_join->tmp_table_param.func_count= 0; 01495 } 01496 01497 // procedure can't be used inside subselect => we do nothing special for it 01498 if (procedure) 01499 procedure->update_refs(); 01500 01501 if (curr_tmp_table->group) 01502 { // Already grouped 01503 if (!curr_join->order && !curr_join->no_order && !skip_sort_order) 01504 curr_join->order= curr_join->group_list; /* order by group */ 01505 curr_join->group_list= 0; 01506 } 01507 01508 /* 01509 If we have different sort & group then we must sort the data by group 01510 and copy it to another tmp table 01511 This code is also used if we are using distinct something 01512 we haven't been able to store in the temporary table yet 01513 like SEC_TO_TIME(SUM(...)). 01514 */ 01515 01516 if (curr_join->group_list && (!test_if_subpart(curr_join->group_list, 01517 curr_join->order) || 01518 curr_join->select_distinct) || 01519 (curr_join->select_distinct && 01520 curr_join->tmp_table_param.using_indirect_summary_function)) 01521 { /* Must copy to another table */ 01522 DBUG_PRINT("info",("Creating group table")); 01523 01524 /* Free first data from old join */ 01525 curr_join->join_free(); 01526 if (make_simple_join(curr_join, curr_tmp_table)) 01527 DBUG_VOID_RETURN; 01528 calc_group_buffer(curr_join, group_list); 01529 count_field_types(&curr_join->tmp_table_param, 01530 curr_join->tmp_all_fields1, 01531 curr_join->select_distinct && !curr_join->group_list); 01532 curr_join->tmp_table_param.hidden_field_count= 01533 (curr_join->tmp_all_fields1.elements- 01534 curr_join->tmp_fields_list1.elements); 01535 01536 01537 if (exec_tmp_table2) 01538 curr_tmp_table= exec_tmp_table2; 01539 else 01540 { 01541 /* group data to new table */ 01542 01543 /* 01544 If the access method is loose index scan then all MIN/MAX 01545 functions are precomputed, and should be treated as regular 01546 functions. See extended comment in JOIN::exec. 01547 */ 01548 if (curr_join->join_tab->is_using_loose_index_scan()) 01549 curr_join->tmp_table_param.precomputed_group_by= TRUE; 01550 01551 if (!(curr_tmp_table= 01552 exec_tmp_table2= create_tmp_table(thd, 01553 &curr_join->tmp_table_param, 01554 *curr_all_fields, 01555 (ORDER*) 0, 01556 curr_join->select_distinct && 01557 !curr_join->group_list, 01558 1, curr_join->select_options, 01559 HA_POS_ERROR, 01560 (char *) ""))) 01561 DBUG_VOID_RETURN; 01562 curr_join->exec_tmp_table2= exec_tmp_table2; 01563 } 01564 if (curr_join->group_list) 01565 { 01566 thd->proc_info= "Creating sort index"; 01567 if (curr_join->join_tab == join_tab && save_join_tab()) 01568 { 01569 DBUG_VOID_RETURN; 01570 } 01571 if (create_sort_index(thd, curr_join, curr_join->group_list, 01572 HA_POS_ERROR, HA_POS_ERROR) || 01573 make_group_fields(this, curr_join)) 01574 { 01575 DBUG_VOID_RETURN; 01576 } 01577 } 01578 01579 thd->proc_info="Copying to group table"; 01580 DBUG_PRINT("info", ("%s", thd->proc_info)); 01581 tmp_error= -1; 01582 if (curr_join != this) 01583 { 01584 if (sum_funcs2) 01585 { 01586 curr_join->sum_funcs= sum_funcs2; 01587 curr_join->sum_funcs_end= sum_funcs_end2; 01588 } 01589 else 01590 { 01591 curr_join->alloc_func_list(); 01592 sum_funcs2= curr_join->sum_funcs; 01593 sum_funcs_end2= curr_join->sum_funcs_end; 01594 } 01595 } 01596 if (curr_join->make_sum_func_list(*curr_all_fields, *curr_fields_list, 01597 1, TRUE)) 01598 DBUG_VOID_RETURN; 01599 curr_join->group_list= 0; 01600 if (!curr_join->sort_and_group && 01601 curr_join->const_tables != curr_join->tables) 01602 curr_join->join_tab[curr_join->const_tables].sorted= 0; 01603 if (setup_sum_funcs(curr_join->thd, curr_join->sum_funcs) || 01604 (tmp_error= do_select(curr_join, (List<Item> *) 0, curr_tmp_table, 01605 0))) 01606 { 01607 error= tmp_error; 01608 DBUG_VOID_RETURN; 01609 } 01610 end_read_record(&curr_join->join_tab->read_record); 01611 curr_join->const_tables= curr_join->tables; // Mark free for cleanup() 01612 curr_join->join_tab[0].table= 0; // Table is freed 01613 01614 // No sum funcs anymore 01615 if (!items2) 01616 { 01617 items2= items1 + all_fields.elements; 01618 if (change_to_use_tmp_fields(thd, items2, 01619 tmp_fields_list2, tmp_all_fields2, 01620 fields_list.elements, tmp_all_fields1)) 01621 DBUG_VOID_RETURN; 01622 curr_join->tmp_fields_list2= tmp_fields_list2; 01623 curr_join->tmp_all_fields2= tmp_all_fields2; 01624 } 01625 curr_fields_list= &curr_join->tmp_fields_list2; 01626 curr_all_fields= &curr_join->tmp_all_fields2; 01627 curr_join->set_items_ref_array(items2); 01628 curr_join->tmp_table_param.field_count+= 01629 curr_join->tmp_table_param.sum_func_count; 01630 curr_join->tmp_table_param.sum_func_count= 0; 01631 } 01632 if (curr_tmp_table->distinct) 01633 curr_join->select_distinct=0; /* Each row is unique */ 01634 01635 curr_join->join_free(); /* Free quick selects */ 01636 if (curr_join->select_distinct && ! curr_join->group_list) 01637 { 01638 thd->proc_info="Removing duplicates"; 01639 if (curr_join->tmp_having) 01640 curr_join->tmp_having->update_used_tables(); 01641 if (remove_duplicates(curr_join, curr_tmp_table, 01642 *curr_fields_list, curr_join->tmp_having)) 01643 DBUG_VOID_RETURN; 01644 curr_join->tmp_having=0; 01645 curr_join->select_distinct=0; 01646 } 01647 curr_tmp_table->reginfo.lock_type= TL_UNLOCK; 01648 if (make_simple_join(curr_join, curr_tmp_table)) 01649 DBUG_VOID_RETURN; 01650 calc_group_buffer(curr_join, curr_join->group_list); 01651 count_field_types(&curr_join->tmp_table_param, *curr_all_fields, 0); 01652 01653 } 01654 if (procedure) 01655 count_field_types(&curr_join->tmp_table_param, *curr_all_fields, 0); 01656 01657 if (curr_join->group || curr_join->tmp_table_param.sum_func_count || 01658 (procedure && (procedure->flags & PROC_GROUP))) 01659 { 01660 if (make_group_fields(this, curr_join)) 01661 { 01662 DBUG_VOID_RETURN; 01663 } 01664 if (!items3) 01665 { 01666 if (!items0) 01667 init_items_ref_array(); 01668 items3= ref_pointer_array + (all_fields.elements*4); 01669 setup_copy_fields(thd, &curr_join->tmp_table_param, 01670 items3, tmp_fields_list3, tmp_all_fields3, 01671 curr_fields_list->elements, *curr_all_fields); 01672 tmp_table_param.save_copy_funcs= curr_join->tmp_table_param.copy_funcs; 01673 tmp_table_param.save_copy_field= curr_join->tmp_table_param.copy_field; 01674 tmp_table_param.save_copy_field_end= 01675 curr_join->tmp_table_param.copy_field_end; 01676 curr_join->tmp_all_fields3= tmp_all_fields3; 01677 curr_join->tmp_fields_list3= tmp_fields_list3; 01678 } 01679 else 01680 { 01681 curr_join->tmp_table_param.copy_funcs= tmp_table_param.save_copy_funcs; 01682 curr_join->tmp_table_param.copy_field= tmp_table_param.save_copy_field; 01683 curr_join->tmp_table_param.copy_field_end= 01684 tmp_table_param.save_copy_field_end; 01685 } 01686 curr_fields_list= &tmp_fields_list3; 01687 curr_all_fields= &tmp_all_fields3; 01688 curr_join->set_items_ref_array(items3); 01689 01690 if (curr_join->make_sum_func_list(*curr_all_fields, *curr_fields_list, 01691 1, TRUE) || 01692 setup_sum_funcs(curr_join->thd, curr_join->sum_funcs) || 01693 thd->is_fatal_error) 01694 DBUG_VOID_RETURN; 01695 } 01696 if (curr_join->group_list || curr_join->order) 01697 { 01698 DBUG_PRINT("info",("Sorting for send_fields")); 01699 thd->proc_info="Sorting result"; 01700 /* If we have already done the group, add HAVING to sorted table */ 01701 if (curr_join->tmp_having && ! curr_join->group_list && 01702 ! curr_join->sort_and_group) 01703 { 01704 // Some tables may have been const 01705 curr_join->tmp_having->update_used_tables(); 01706 JOIN_TAB *curr_table= &curr_join->join_tab[curr_join->const_tables]; 01707 table_map used_tables= (curr_join->const_table_map | 01708 curr_table->table->map); 01709 01710 Item* sort_table_cond= make_cond_for_table(curr_join->tmp_having, 01711 used_tables, 01712 used_tables); 01713 if (sort_table_cond) 01714 { 01715 if (!curr_table->select) 01716 if (!(curr_table->select= new SQL_SELECT)) 01717 DBUG_VOID_RETURN; 01718 if (!curr_table->select->cond) 01719 curr_table->select->cond= sort_table_cond; 01720 else // This should never happen 01721 { 01722 if (!(curr_table->select->cond= 01723 new Item_cond_and(curr_table->select->cond, 01724 sort_table_cond))) 01725 DBUG_VOID_RETURN; 01726 /* 01727 Item_cond_and do not need fix_fields for execution, its parameters 01728 are fixed or do not need fix_fields, too 01729 */ 01730 curr_table->select->cond->quick_fix_field(); 01731 } 01732 curr_table->select_cond= curr_table->select->cond; 01733 curr_table->select_cond->top_level_item(); 01734 DBUG_EXECUTE("where",print_where(curr_table->select->cond, 01735 "select and having");); 01736 curr_join->tmp_having= make_cond_for_table(curr_join->tmp_having, 01737 ~ (table_map) 0, 01738 ~used_tables); 01739 DBUG_EXECUTE("where",print_where(curr_join->tmp_having, 01740 "having after sort");); 01741 } 01742 } 01743 { 01744 if (group) 01745 curr_join->select_limit= HA_POS_ERROR; 01746 else 01747 { 01748 /* 01749 We can abort sorting after thd->select_limit rows if we there is no 01750 WHERE clause for any tables after the sorted one. 01751 */ 01752 JOIN_TAB *curr_table= &curr_join->join_tab[curr_join->const_tables+1]; 01753 JOIN_TAB *end_table= &curr_join->join_tab[curr_join->tables]; 01754 for (; curr_table < end_table ; curr_table++) 01755 { 01756 /* 01757 table->keyuse is set in the case there was an original WHERE clause 01758 on the table that was optimized away. 01759 */ 01760 if (curr_table->select_cond || 01761 (curr_table->keyuse && !curr_table->first_inner)) 01762 { 01763 /* We have to sort all rows */ 01764 curr_join->select_limit= HA_POS_ERROR; 01765 break; 01766 } 01767 } 01768 } 01769 if (curr_join->join_tab == join_tab && save_join_tab()) 01770 { 01771 DBUG_VOID_RETURN; 01772 } 01773 /* 01774 Here we sort rows for ORDER BY/GROUP BY clause, if the optimiser 01775 chose FILESORT to be faster than INDEX SCAN or there is no 01776 suitable index present. 01777 Note, that create_sort_index calls test_if_skip_sort_order and may 01778 finally replace sorting with index scan if there is a LIMIT clause in 01779 the query. XXX: it's never shown in EXPLAIN! 01780 OPTION_FOUND_ROWS supersedes LIMIT and is taken into account. 01781 */ 01782 if (create_sort_index(thd, curr_join, 01783 curr_join->group_list ? 01784 curr_join->group_list : curr_join->order, 01785 curr_join->select_limit, 01786 (select_options & OPTION_FOUND_ROWS ? 01787 HA_POS_ERROR : unit->select_limit_cnt))) 01788 DBUG_VOID_RETURN; 01789 if (curr_join->const_tables != curr_join->tables && 01790 !curr_join->join_tab[curr_join->const_tables].table->sort.io_cache) 01791 { 01792 /* 01793 If no IO cache exists for the first table then we are using an 01794 INDEX SCAN and no filesort. Thus we should not remove the sorted 01795 attribute on the INDEX SCAN. 01796 */ 01797 skip_sort_order= 1; 01798 } 01799 } 01800 } 01801 /* XXX: When can we have here thd->net.report_error not zero? */ 01802 if (thd->net.report_error) 01803 { 01804 error= thd->net.report_error; 01805 DBUG_VOID_RETURN; 01806 } 01807 curr_join->having= curr_join->tmp_having; 01808 curr_join->fields= curr_fields_list; 01809 curr_join->procedure= procedure; 01810 01811 if (is_top_level_join() && thd->cursor && tables != const_tables) 01812 { 01813 /* 01814 We are here if this is JOIN::exec for the last select of the main unit 01815 and the client requested to open a cursor. 01816 We check that not all tables are constant because this case is not 01817 handled by do_select() separately, and this case is not implemented 01818 for cursors yet. 01819 */ 01820 DBUG_ASSERT(error == 0); 01821 /* 01822 curr_join is used only for reusable joins - that is, 01823 to perform SELECT for each outer row (like in subselects). 01824 This join is main, so we know for sure that curr_join == join. 01825 */ 01826 DBUG_ASSERT(curr_join == this); 01827 /* Open cursor for the last join sweep */ 01828 error= thd->cursor->open(this); 01829 } 01830 else 01831 { 01832 thd->proc_info="Sending data"; 01833 DBUG_PRINT("info", ("%s", thd->proc_info)); 01834 result->send_fields((procedure ? curr_join->procedure_fields_list : 01835 *curr_fields_list), 01836 Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF); 01837 error= do_select(curr_join, curr_fields_list, NULL, procedure); 01838 thd->limit_found_rows= curr_join->send_records; 01839 thd->examined_row_count= curr_join->examined_rows; 01840 } 01841 01842 DBUG_VOID_RETURN; 01843 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void JOIN::init | ( | THD * | thd_arg, | |
| List< Item > & | fields_arg, | |||
| ulonglong | select_options_arg, | |||
| select_result * | result_arg | |||
| ) | [inline] |
Definition at line 317 of file sql_select.h.
References all_fields, bzero, cond_equal, const_tables, do_send_rows, error, examined_rows, exec_tmp_table1, exec_tmp_table2, FALSE, fetch_limit, fields_list, first_record, found_records, HA_POS_ERROR, having, having_history, hidden_group_fields, items0, items1, items2, items3, join_list, join_tab, join_tab_save, keyuse, lock, need_tmp, no_order, optimized, procedure, ref_pointer_array, ref_pointer_array_size, result, resume_nested_loop, return_tab, rollup, select, SELECT_DISTINCT, select_distinct, select_lex, select_options, send_records, simple_group, simple_order, skip_sort_order, sort_and_group, st_rollup::state, st_rollup::STATE_NONE, sum_funcs, sum_funcs2, table, tables, test, thd, tmp_having, tmp_join, tmp_table_param, and zero_result_cause.
Referenced by JOIN().
00319 { 00320 join_tab= join_tab_save= 0; 00321 table= 0; 00322 tables= 0; 00323 const_tables= 0; 00324 join_list= 0; 00325 sort_and_group= 0; 00326 first_record= 0; 00327 do_send_rows= 1; 00328 resume_nested_loop= FALSE; 00329 send_records= 0; 00330 found_records= 0; 00331 fetch_limit= HA_POS_ERROR; 00332 examined_rows= 0; 00333 exec_tmp_table1= 0; 00334 exec_tmp_table2= 0; 00335 thd= thd_arg; 00336 sum_funcs= sum_funcs2= 0; 00337 procedure= 0; 00338 having= tmp_having= having_history= 0; 00339 select_options= select_options_arg; 00340 result= result_arg; 00341 lock= thd_arg->lock; 00342 select_lex= 0; //for safety 00343 tmp_join= 0; 00344 select_distinct= test(select_options & SELECT_DISTINCT); 00345 no_order= 0; 00346 simple_order= 0; 00347 simple_group= 0; 00348 skip_sort_order= 0; 00349 need_tmp= 0; 00350 hidden_group_fields= 0; /*safety*/ 00351 error= 0; 00352 select= 0; 00353 return_tab= 0; 00354 ref_pointer_array= items0= items1= items2= items3= 0; 00355 ref_pointer_array_size= 0; 00356 zero_result_cause= 0; 00357 optimized= 0; 00358 cond_equal= 0; 00359 00360 all_fields= fields_arg; 00361 fields_list= fields_arg; 00362 bzero((char*) &keyuse,sizeof(keyuse)); 00363 tmp_table_param.init(); 00364 tmp_table_param.end_write_records= HA_POS_ERROR; 00365 rollup.state= ROLLUP::STATE_NONE; 00366 }
Here is the caller graph for this function:

| void JOIN::init_items_ref_array | ( | ) | [inline] |
Definition at line 386 of file sql_select.h.
References all_fields, current_ref_pointer_array, base_list::elements, items0, memcpy, ref_pointer_array, and ref_pointer_array_size.
Referenced by exec().
00387 { 00388 items0= ref_pointer_array + all_fields.elements; 00389 memcpy(items0, ref_pointer_array, ref_pointer_array_size); 00390 current_ref_pointer_array= items0; 00391 }
Here is the caller graph for this function:

| bool JOIN::is_top_level_join | ( | ) | const [inline] |
Definition at line 416 of file sql_select.h.
References select_lex, thd, and unit.
00417 { 00418 return (unit == &thd->lex->unit && (unit->fake_select_lex == 0 || 00419 select_lex == unit->fake_select_lex)); 00420 }
| void JOIN::join_free | ( | ) |
Definition at line 5881 of file sql_select.cc.
References cleanup(), DBUG_ENTER, DBUG_VOID_RETURN, full(), lock, mysql_unlock_read_tables(), select_lex, SELECT_NO_UNLOCK, select_options, and unit.
Referenced by do_select(), exec(), and return_zero_rows().
05882 { 05883 SELECT_LEX_UNIT *unit; 05884 SELECT_LEX *sl; 05885 /* 05886 Optimization: if not EXPLAIN and we are done with the JOIN, 05887 free all tables. 05888 */ 05889 bool full= (!select_lex->uncacheable && !thd->lex->describe); 05890 bool can_unlock= full; 05891 DBUG_ENTER("JOIN::join_free"); 05892 05893 cleanup(full); 05894 05895 for (unit= select_lex->first_inner_unit(); unit; unit= unit->next_unit()) 05896 for (sl= unit->first_select(); sl; sl= sl->next_select()) 05897 { 05898 Item_subselect *subselect= sl->master_unit()->item; 05899 bool full_local= full && (!subselect || subselect->is_evaluated()); 05900 /* 05901 If this join is evaluated, we can fully clean it up and clean up all 05902 its underlying joins even if they are correlated -- they will not be 05903 used any more anyway. 05904 If this join is not yet evaluated, we still must clean it up to 05905 close its table cursors -- it may never get evaluated, as in case of 05906 ... HAVING FALSE OR a IN (SELECT ...)) 05907 but all table cursors must be closed before the unlock. 05908 */ 05909 sl->cleanup_all_joins(full_local); 05910 /* Can't unlock if at least one JOIN is still needed */ 05911 can_unlock= can_unlock && full_local; 05912 } 05913 05914 /* 05915 We are not using tables anymore 05916 Unlock all tables. We may be in an INSERT .... SELECT statement. 05917 */ 05918 if (can_unlock && lock && thd->lock && 05919 !(select_options & SELECT_NO_UNLOCK) && 05920 !select_lex->subquery_in_having && 05921 (select_lex == (thd->lex->unit.fake_select_lex ? 05922 thd->lex->unit.fake_select_lex : &thd->lex->select_lex))) 05923 { 05924 /* 05925 TODO: unlock tables even if the join isn't top level select in the 05926 tree. 05927 */ 05928 mysql_unlock_read_tables(thd, lock); // Don't free join->lock 05929 lock= 0; 05930 } 05931 05932 DBUG_VOID_RETURN; 05933 }
Here is the call graph for this function:

Here is the caller graph for this function:

| bool JOIN::make_sum_func_list | ( | List< Item > & | all_fields, | |
| List< Item > & | send_fields, | |||
| bool | before_group_by, | |||
| bool | recompute = FALSE | |||
| ) |
Definition at line 13422 of file sql_select.cc.
References Item::const_item(), DBUG_ENTER, DBUG_RETURN, FALSE, func, rollup, rollup_make_fields(), send_fields(), send_group_parts, st_rollup::state, st_rollup::STATE_INITED, st_rollup::STATE_NONE, st_rollup::STATE_READY, Item::SUM_FUNC_ITEM, sum_funcs, sum_funcs_end, TRUE, and Item::type().
Referenced by exec(), and get_best_group_min_max().
13424 { 13425 List_iterator_fast<Item> it(field_list); 13426 Item_sum **func; 13427 Item *item; 13428 DBUG_ENTER("make_sum_func_list"); 13429 13430 if (*sum_funcs && !recompute) 13431 DBUG_RETURN(FALSE); /* We have already initialized sum_funcs. */ 13432 13433 func= sum_funcs; 13434 while ((item=it++)) 13435 { 13436 if (item->type() == Item::SUM_FUNC_ITEM && !item->const_item()) 13437 *func++= (Item_sum*) item; 13438 } 13439 if (before_group_by && rollup.state == ROLLUP::STATE_INITED) 13440 { 13441 rollup.state= ROLLUP::STATE_READY; 13442 if (rollup_make_fields(field_list, send_fields, &func)) 13443 DBUG_RETURN(TRUE); // Should never happen 13444 } 13445 else if (rollup.state == ROLLUP::STATE_NONE) 13446 { 13447 for (uint i=0 ; i <= send_group_parts ;i++) 13448 sum_funcs_end[i]= func; 13449 } 13450 else if (rollup.state == ROLLUP::STATE_READY) 13451 DBUG_RETURN(FALSE); // Don't put end marker 13452 *func=0; // End marker 13453 DBUG_RETURN(FALSE); 13454 }
Here is the call graph for this function:

Here is the caller graph for this function:

| int JOIN::optimize | ( | ) |
Definition at line 550 of file sql_select.cc.
References all_fields, backup, best_read, build_bitmap_for_nested_joins(), cond_equal, Item::COND_FALSE, cond_value, conds, const_table_map, const_tables, Item::copy_andor_structure(), DBUG_ENTER, DBUG_EXECUTE, DBUG_PRINT, DBUG_RETURN, DESCRIBE_EXTENDED, do_send_rows, st_table_list::embedding, ER, ER_TOO_BIG_SELECT, error, Item::fix_fields(), found_const_table_map, get_sort_by_table(), group_list, HA_POS_ERROR, having, join_list, join_tab, keyuse, make_cond_for_table(), make_join_statistics(), make_outerjoin_info(), make_select(), map2table, my_message(), MYF, mysql_unlock_some_tables(), st_table_list::next_leaf, st_table_list::on_expr, opt_sum_query(), optimize_cond(), optimized, OPTION_BIG_SELECTS, OPTION_FOUND_ROWS, order, outer_join, print_where(), PSEUDO_TABLE_BITS, RAND_TABLE_BIT, reset_nj_counters(), result, row_limit, sel, select, SELECT_DESCRIBE, select_distinct, select_lex, select_limit, SELECT_NO_UNLOCK, select_options, simplify_joins(), sort_by_table, substitute_for_best_equal_field(), table, st_table_list::table, tables, tables_list, thd, tmp_table_param, TRUE, unit, Item::update_used_tables(), Item::used_tables(), and zero_result_cause.
Referenced by subselect_single_select_engine::exec(), and mysql_select().
00551 { 00552 DBUG_ENTER("JOIN::optimize"); 00553 // to prevent double initialization on EXPLAIN 00554 if (optimized) 00555 DBUG_RETURN(0); 00556 optimized= 1; 00557 00558 row_limit= ((select_distinct || order || group_list) ? HA_POS_ERROR : 00559 unit->select_limit_cnt); 00560 /* select_limit is used to decide if we are likely to scan the whole table */ 00561 select_limit= unit->select_limit_cnt; 00562 if (having || (select_options & OPTION_FOUND_ROWS)) 00563 select_limit= HA_POS_ERROR; 00564 do_send_rows = (unit->select_limit_cnt) ? 1 : 0; 00565 // Ignore errors of execution if option IGNORE present 00566 if (thd->lex->ignore) 00567 thd->lex->current_select->no_error= 1; 00568 #ifdef HAVE_REF_TO_FIELDS // Not done yet 00569 /* Add HAVING to WHERE if possible */ 00570 if (having && !group_list && !sum_func_count) 00571 { 00572 if (!conds) 00573 { 00574 conds= having; 00575 having= 0; 00576 } 00577 else if ((conds=new Item_cond_and(conds,having))) 00578 { 00579 /* 00580 Item_cond_and can't be fixed after creation, so we do not check 00581 conds->fixed 00582 */ 00583 conds->fix_fields(thd, &conds); 00584 conds->change_ref_to_fields(thd, tables_list); 00585 conds->top_level_item(); 00586 having= 0; 00587 } 00588 } 00589 #endif 00590 SELECT_LEX *sel= thd->lex->current_select; 00591 if (sel->first_cond_optimization) 00592 { 00593 /* 00594 The following code will allocate the new items in a permanent 00595 MEMROOT for prepared statements and stored procedures. 00596 */ 00597 00598 Query_arena *arena= thd->stmt_arena, backup; 00599 if (arena->is_conventional()) 00600 arena= 0; // For easier test 00601 else 00602 thd->set_n_backup_active_arena(arena, &backup); 00603 00604 sel->first_cond_optimization= 0; 00605 00606 /* Convert all outer joins to inner joins if possible */ 00607 conds= simplify_joins(this, join_list, conds, TRUE); 00608 build_bitmap_for_nested_joins(join_list, 0); 00609 00610 sel->prep_where= conds ? conds->copy_andor_structure(thd) : 0; 00611 sel->prep_having= having ? having->copy_andor_structure(thd) : 0; 00612 00613 if (arena) 00614 thd->restore_active_arena(arena, &backup); 00615 } 00616 00617 conds= optimize_cond(this, conds, join_list, &cond_value); 00618 if (thd->net.report_error) 00619 { 00620 error= 1; 00621 DBUG_PRINT("error",("Error from optimize_cond")); 00622 DBUG_RETURN(1); 00623 } 00624 00625 { 00626 Item::cond_result having_value; 00627 having= optimize_cond(this, having, join_list, &having_value); 00628 if (thd->net.report_error) 00629 { 00630 error= 1; 00631 DBUG_PRINT("error",("Error from optimize_cond")); 00632 DBUG_RETURN(1); 00633 } 00634 00635 if (cond_value == Item::COND_FALSE || having_value == Item::COND_FALSE || 00636 (!unit->select_limit_cnt && !(select_options & OPTION_FOUND_ROWS))) 00637 { /* Impossible cond */ 00638 DBUG_PRINT("info", (having_value == Item::COND_FALSE ? 00639 "Impossible HAVING" : "Impossible WHERE")); 00640 zero_result_cause= having_value == Item::COND_FALSE ? 00641 "Impossible HAVING" : "Impossible WHERE"; 00642 error= 0; 00643 DBUG_RETURN(0); 00644 } 00645 } 00646 00647 #ifdef WITH_PARTITION_STORAGE_ENGINE 00648 { 00649 TABLE_LIST *tbl; 00650 for (tbl= select_lex->leaf_tables; tbl; tbl= tbl->next_leaf) 00651 { 00652 /* 00653 If tbl->embedding!=NULL that means that this table is in the inner 00654 part of the nested outer join, and we can't do partition pruning 00655 (TODO: check if this limitation can be lifted) 00656 */ 00657 if (!tbl->embedding) 00658 { 00659 Item *prune_cond= tbl->on_expr? tbl->on_expr : conds; 00660 tbl->table->no_partitions_used= prune_partitions(thd, tbl->table, 00661 prune_cond); 00662 } 00663 } 00664 } 00665 #endif 00666 00667 /* Optimize count(*), min() and max() */ 00668 if (tables_list && tmp_table_param.sum_func_count && ! group_list) 00669 { 00670 int res; 00671 /* 00672 opt_sum_query() returns -1 if no rows match to the WHERE conditions, 00673 or 1 if all items were resolved, or 0, or an error number HA_ERR_... 00674 */ 00675 if ((res=opt_sum_query(select_lex->leaf_tables, all_fields, conds))) 00676 { 00677 if (res > 1) 00678 { 00679 DBUG_PRINT("error",("Error from opt_sum_query")); 00680 DBUG_RETURN(1); 00681 } 00682 if (res < 0) 00683 { 00684 DBUG_PRINT("info",("No matching min/max row")); 00685 zero_result_cause= "No matching min/max row"; 00686 error=0; 00687 DBUG_RETURN(0); 00688 } 00689 DBUG_PRINT("info",("Select tables optimized away")); 00690 zero_result_cause= "Select tables optimized away"; 00691 tables_list= 0; // All tables resolved 00692 /* 00693 Extract all table-independent conditions and replace the WHERE 00694 clause with them. All other conditions were computed by opt_sum_query 00695 and the MIN/MAX/COUNT function(s) have been replaced by constants, 00696 so there is no need to compute the whole WHERE clause again. 00697 Notice that make_cond_for_table() will always succeed to remove all 00698 computed conditions, because opt_sum_query() is applicable only to 00699 conjunctions. 00700 Preserve conditions for EXPLAIN. 00701 */ 00702 if (conds && !(thd->lex->describe & DESCRIBE_EXTENDED)) 00703 { 00704 COND *table_independent_conds= 00705 make_cond_for_table(conds, PSEUDO_TABLE_BITS, 0); 00706 DBUG_EXECUTE("where", 00707 print_where(table_independent_conds, 00708 "where after opt_sum_query()");); 00709 conds= table_independent_conds; 00710 } 00711 } 00712 } 00713 if (!tables_list) 00714 { 00715 DBUG_PRINT("info",("No tables")); 00716 error= 0; 00717 DBUG_RETURN(0); 00718 } 00719 error= -1; // Error is sent to client 00720 sort_by_table= get_sort_by_table(order, group_list, select_lex->leaf_tables); 00721 00722 /* Calculate how to do the join */ 00723 thd->proc_info= "statistics"; 00724 if (make_join_statistics(this, select_lex->leaf_tables, conds, &keyuse) || 00725 thd->is_fatal_error) 00726 { 00727 DBUG_PRINT("error",("Error: make_join_statistics() failed")); 00728 DBUG_RETURN(1); 00729 } 00730 00731 /* Remove distinct if only const tables */ 00732 select_distinct= select_distinct && (const_tables != tables); 00733 thd->proc_info= "preparing"; 00734 if (result->initialize_tables(this)) 00735 { 00736 DBUG_PRINT("error",("Error: initialize_tables() failed")); 00737 DBUG_RETURN(1); // error == -1 00738 } 00739 if (const_table_map != found_const_table_map && 00740 !(select_options & SELECT_DESCRIBE) && 00741 (!conds || 00742 !(conds->used_tables() & RAND_TABLE_BIT) || 00743 select_lex->master_unit() == &thd->lex->unit)) // upper level SELECT 00744 { 00745 zero_result_cause= "no matching row in const table"; 00746 DBUG_PRINT("error",("Error: %s", zero_result_cause)); 00747 error= 0; 00748 DBUG_RETURN(0); 00749 } 00750 if (!(thd->options & OPTION_BIG_SELECTS) && 00751 best_read > (double) thd->variables.max_join_size && 00752 !(select_options & SELECT_DESCRIBE)) 00753 { /* purecov: inspected */ 00754 my_message(ER_TOO_BIG_SELECT, ER(ER_TOO_BIG_SELECT), MYF(0)); 00755 error= -1; 00756 DBUG_RETURN(1); 00757 } 00758 if (const_tables && !thd->locked_tables && 00759 !(select_options & SELECT_NO_UNLOCK)) 00760 mysql_unlock_some_tables(thd, table, const_tables); 00761 if (!conds && outer_join) 00762 { 00763 /* Handle the case where we have an OUTER JOIN without a WHERE */ 00764 conds=new Item_int((longlong) 1,1); // Always true 00765 } 00766 select= make_select(*table, const_table_map, 00767 const_table_map, conds, 1, &error); 00768 if (error) 00769 { /* purecov: inspected */ 00770 error= -1; /* purecov: inspected */ 00771 DBUG_PRINT("error",("Error: make_select() failed")); 00772 DBUG_RETURN(1); 00773 } 00774 00775 reset_nj_counters(join_list); 00776 make_outerjoin_info(this); 00777 00778 /* 00779 Among the equal fields belonging to the same multiple equality 00780 choose the one that is to be retrieved first and substitute 00781 all references to these in where condition for a reference for 00782 the selected field. 00783 */ 00784 if (conds) 00785 { 00786 conds= substitute_for_best_equal_field(conds, cond_equal, map2table); 00787 conds->update_used_tables(); 00788 DBUG_EXECUTE("where", print_where(conds, "after substitute_best_equal");); 00789 } 00790 /* 00791 Permorm the the optimization on fields evaluation mentioned above 00792 for all on expressions. 00793 */ 00794 for (JOIN_TAB *tab= join_tab + const_tables; tab < join_tab + tables ; tab++) 00795 { 00796 if (*tab->on_expr_ref) 00797 { 00798 *tab->on_expr_ref= substitute_for_best_equal_field(*tab->on_expr_ref, 00799 tab->cond_equal, 00800 map2table); 00801 (*tab->on_expr_ref)->update_used_tables(); 00802 } 00803 } 00804 00805 if (make_join_select(this, select, conds)) 00806 { 00807 zero_result_cause= 00808 "Impossible WHERE noticed after reading const tables"; 00809 DBUG_RETURN(0); // error == 0 00810 } 00811 00812 error= -1; /* if goto err */ 00813 00814 /* Optimize distinct away if possible */ 00815 { 00816 ORDER *org_order= order; 00817 order=remove_const(this, order,conds,1, &simple_order); 00818 /* 00819 If we are using ORDER BY NULL or ORDER BY const_expression, 00820 return result in any order (even if we are using a GROUP BY) 00821 */ 00822 if (!order && org_order) 00823 skip_sort_order= 1; 00824 } 00825 if (group_list || tmp_table_param.sum_func_count) 00826 { 00827 if (! hidden_group_fields && rollup.state == ROLLUP::STATE_NONE) 00828 select_distinct=0; 00829 } 00830 else if (select_distinct && tables - const_tables == 1) 00831 { 00832 /* 00833 We are only using one table. In this case we change DISTINCT to a 00834 GROUP BY query if: 00835 - The GROUP BY can be done through indexes (no sort) and the ORDER 00836 BY only uses selected fields. 00837 (In this case we can later optimize away GROUP BY and ORDER BY) 00838 - We are scanning the whole table without LIMIT 00839 This can happen if: 00840 - We are using CALC_FOUND_ROWS 00841 - We are using an ORDER BY that can't be optimized away. 00842 00843 We don't want to use this optimization when we are using LIMIT 00844 because in this case we can just create a temporary table that 00845 holds LIMIT rows and stop when this table is full. 00846 */ 00847 JOIN_TAB *tab= &join_tab[const_tables]; 00848 bool all_order_fields_used; 00849 if (order) 00850 skip_sort_order= test_if_skip_sort_order(tab, order, select_limit, 1); 00851 if ((group_list=create_distinct_group(thd, select_lex->ref_pointer_array, 00852 order, fields_list, 00853 &all_order_fields_used))) 00854 { 00855 bool skip_group= (skip_sort_order && 00856 test_if_skip_sort_order(tab, group_list, select_limit, 00857 1) != 0); 00858 if ((skip_group && all_order_fields_used) || 00859 select_limit == HA_POS_ERROR || 00860 (order && !skip_sort_order)) 00861 { 00862 /* Change DISTINCT to GROUP BY */ 00863 select_distinct= 0; 00864 no_order= !order; 00865 if (all_order_fields_used) 00866 { 00867 if (order && skip_sort_order) 00868 { 00869 /* 00870 Force MySQL to read the table in sorted order to get result in 00871 ORDER BY order. 00872 */ 00873 tmp_table_param.quick_group=0; 00874 } 00875 order=0; 00876 } 00877 group=1; // For end_write_group 00878 } 00879 else 00880 group_list= 0; 00881 } 00882 else if (thd->is_fatal_error) // End of memory 00883 DBUG_RETURN(1); 00884 } 00885 simple_group= 0; 00886 { 00887 ORDER *old_group_list; 00888 group_list= remove_const(this, (old_group_list= group_list), conds, 00889 rollup.state == ROLLUP::STATE_NONE, 00890 &simple_group); 00891 if (old_group_list && !group_list) 00892 select_distinct= 0; 00893 } 00894 /* 00895 Check if we can optimize away GROUP BY/DISTINCT. 00896 We can do that if there are no aggregate functions and the 00897 fields in DISTINCT clause (if present) and/or columns in GROUP BY 00898 (if present) contain direct references to all key parts of 00899 an unique index (in whatever order). 00900 Note that the unique keys for DISTINCT and GROUP BY should not 00901 be the same (as long as they are unique). 00902 00903 The FROM clause must contain a single non-constant table. 00904 */ 00905 if (tables - const_tables == 1 && (group_list || select_distinct) && 00906 !tmp_table_param.sum_func_count && 00907 (!join_tab[const_tables].select || 00908 !join_tab[const_tables].select->quick || 00909 join_tab[const_tables].select->quick->get_type() != 00910 QUICK_SELECT_I::QS_TYPE_GROUP_MIN_MAX)) 00911 { 00912 if (group_list && 00913 list_contains_unique_index(join_tab[const_tables].table, 00914 find_field_in_order_list, 00915 (void *) group_list)) 00916 { 00917 group_list= 0; 00918 group= 0; 00919 } 00920 if (select_distinct && 00921 list_contains_unique_index(join_tab[const_tables].table, 00922 find_field_in_item_list, 00923 (void *) &fields_list)) 00924 { 00925 select_distinct= 0; 00926 } 00927 } 00928 if (!group_list && group) 00929 { 00930 order=0; // The output has only one row 00931 simple_order=1; 00932 select_distinct= 0; // No need in distinct for 1 row 00933 } 00934 00935 calc_group_buffer(this, group_list); 00936 send_group_parts= tmp_table_param.group_parts; /* Save org parts */ 00937 if (procedure && procedure->group) 00938 { 00939 group_list= procedure->group= remove_const(this, procedure->group, conds, 00940 1, &simple_group); 00941 calc_group_buffer(this, group_list); 00942 } 00943 00944 if (test_if_subpart(group_list, order) || 00945 (!group_list && tmp_table_param.sum_func_count)) 00946 order=0; 00947 00948 // Can't use sort on head table if using row cache 00949 if (full_join) 00950 { 00951 if (group_list) 00952 simple_group=0; 00953 if (order) 00954 simple_order=0; 00955 } 00956 00957 /* 00958 Check if we need to create a temporary table. 00959 This has to be done if all tables are not already read (const tables) 00960 and one of the following conditions holds: 00961 - We are using DISTINCT (simple distinct's are already optimized away) 00962 - We are using an ORDER BY or GROUP BY on fields not in the first table 00963 - We are using different ORDER BY and GROUP BY orders 00964 - The user wants us to buffer the result. 00965 */ 00966 need_tmp= (const_tables != tables && 00967 ((select_distinct || !simple_order || !simple_group) || 00968 (group_list && order) || 00969 test(select_options & OPTION_BUFFER_RESULT))); 00970 00971 // No cache for MATCH 00972 make_join_readinfo(this, 00973 (select_options & (SELECT_DESCRIBE | 00974 SELECT_NO_JOIN_CACHE)) | 00975 (select_lex->ftfunc_list->elements ? 00976 SELECT_NO_JOIN_CACHE : 0)); 00977 00978 /* Perform FULLTEXT search before all regular searches */ 00979 if (!(select_options & SELECT_DESCRIBE)) 00980 init_ftfuncs(thd, select_lex, test(order)); 00981 00982 /* 00983 is this simple IN subquery? 00984 */ 00985 if (!group_list && !order && 00986 unit->item && unit->item->substype() == Item_subselect::IN_SUBS && 00987 tables == 1 && conds && 00988 !unit->first_select()->next_select()) 00989 { 00990 if (!having) 00991 { 00992 Item *where= 0; 00993 if (join_tab[0].type == JT_EQ_REF && 00994 join_tab[0].ref.items[0]->name == in_left_expr_name) 00995 { 00996 if (test_in_subselect(&where)) 00997 { 00998 join_tab[0].type= JT_UNIQUE_SUBQUERY; 00999 error= 0; 01000 DBUG_RETURN(unit->item-> 01001 change_engine(new 01002 subselect_uniquesubquery_engine(thd, 01003 join_tab, 01004 unit->item, 01005 where))); 01006 } 01007 } 01008 else if (join_tab[0].type == JT_REF && 01009 join_tab[0].ref.items[0]->name == in_left_expr_name) 01010 { 01011 if (test_in_subselect(&where)) 01012 { 01013 join_tab[0].type= JT_INDEX_SUBQUERY; 01014 error= 0; 01015 DBUG_RETURN(unit->item-> 01016 change_engine(new 01017 subselect_indexsubquery_engine(thd, 01018 join_tab, 01019 unit->item, 01020 where, 01021 0))); 01022 } 01023 } 01024 } else if (join_tab[0].type == JT_REF_OR_NULL && 01025 join_tab[0].ref.items[0]->name == in_left_expr_name && 01026 having->type() == Item::FUNC_ITEM && 01027 ((Item_func *) having)->functype() == 01028 Item_func::ISNOTNULLTEST_FUNC) 01029 { 01030 join_tab[0].type= JT_INDEX_SUBQUERY; 01031 error= 0; 01032 01033 if ((conds= remove_additional_cond(conds))) 01034 join_tab->info= "Using index; Using where"; 01035 else 01036 join_tab->info= "Using index"; 01037 01038 DBUG_RETURN(unit->item-> 01039 change_engine(new subselect_indexsubquery_engine(thd, 01040 join_tab, 01041 unit->item, 01042 conds, 01043 1))); 01044 } 01045 01046 } 01047 /* 01048 Need to tell handlers that to play it safe, it should fetch all 01049 columns of the primary key of the tables: this is because MySQL may 01050 build row pointers for the rows, and for all columns of the primary key 01051 the read set has not necessarily been set by the server code. 01052 */ 01053 if (need_tmp || select_distinct || group_list || order) 01054 { 01055 for (uint i = const_tables; i < tables; i++) 01056 join_tab[i].table->prepare_for_position(); 01057 } 01058 01059 DBUG_EXECUTE("info",TEST_join(this);); 01060 01061 if (const_tables != tables) 01062 { 01063 /* 01064 Because filesort always does a full table scan or a quick range scan 01065 we must add the removed reference to the select for the table. 01066 We only need to do this when we have a simple_order or simple_group 01067 as in other cases the join is done before the sort. 01068 */ 01069 if ((order || group_list) && 01070 join_tab[const_tables].type != JT_ALL && 01071 join_tab[const_tables].type != JT_FT && 01072 join_tab[const_tables].type != JT_REF_OR_NULL && 01073 (order && simple_order || group_list && simple_group)) 01074 { 01075 if (add_ref_to_table_cond(thd,&join_tab[const_tables])) 01076 DBUG_RETURN(1); 01077 } 01078 01079 if (!(select_options & SELECT_BIG_RESULT) && 01080 ((group_list && 01081 (!simple_group || 01082 !test_if_skip_sort_order(&join_tab[const_tables], group_list, 01083 unit->select_limit_cnt, 0))) || 01084 select_distinct) && 01085 tmp_table_param.quick_group && !procedure) 01086 { 01087 need_tmp=1; simple_order=simple_group=0; // Force tmp table without sort 01088 } 01089 if (order) 01090 { 01091 /* 01092 Force using of tmp table if sorting by a SP or UDF function due to 01093 their expensive and probably non-deterministic nature. 01094 */ 01095 for (ORDER *tmp_order= order; tmp_order ; tmp_order=tmp_order->next) 01096 { 01097 Item *item= *tmp_order->item; 01098 if (item->walk(&Item::is_expensive_processor, 0, (byte*)0)) 01099 { 01100 /* Force tmp table without sort */ 01101 need_tmp=1; simple_order=simple_group=0; 01102 break; 01103 } 01104 } 01105 } 01106 } 01107 01108 tmp_having= having; 01109 if (select_options & SELECT_DESCRIBE) 01110 { 01111 error= 0; 01112 DBUG_RETURN(0); 01113 } 01114 having= 0; 01115 01116 /* 01117 The loose index scan access method guarantees that all grouping or 01118 duplicate row elimination (for distinct) is already performed 01119 during data retrieval, and that all MIN/MAX functions are already 01120 computed for each group. Thus all MIN/MAX functions should be 01121 treated as regular functions, and there is no need to perform 01122 grouping in the main execution loop. 01123 Notice that currently loose index scan is applicable only for 01124 single table queries, thus it is sufficient to test only the first 01125 join_tab element of the plan for its access method. 01126 */ 01127 if (join_tab->is_using_loose_index_scan()) 01128 tmp_table_param.precomputed_group_by= TRUE; 01129 01130 /* Create a tmp table if distinct or if the sort is too complicated */ 01131 if (need_tmp) 01132 { 01133 DBUG_PRINT("info",("Creating tmp table")); 01134 thd->proc_info="Creating tmp table"; 01135 01136 init_items_ref_array(); 01137 01138 tmp_table_param.hidden_field_count= (all_fields.elements - 01139 fields_list.elements); 01140 if (!(exec_tmp_table1= 01141 create_tmp_table(thd, &tmp_table_param, all_fields, 01142 ((!simple_group && !procedure && 01143 !(test_flags & TEST_NO_KEY_GROUP)) ? 01144 group_list : (ORDER*) 0), 01145 group_list ? 0 : select_distinct, 01146 group_list && simple_group, 01147 select_options, 01148 (order == 0 || skip_sort_order || 01149 test(select_options & OPTION_BUFFER_RESULT)) ? 01150 select_limit : HA_POS_ERROR, 01151 (char *) ""))) 01152 DBUG_RETURN(1); 01153 01154 /* 01155 We don't have to store rows in temp table that doesn't match HAVING if: 01156 - we are sorting the table and writing complete group rows to the 01157 temp table. 01158 - We are using DISTINCT without resolving the distinct as a GROUP BY 01159 on all columns. 01160 01161 If having is not handled here, it will be checked before the row 01162 is sent to the client. 01163 */ 01164 if (tmp_having && 01165 (sort_and_group || (exec_tmp_table1->distinct && !group_list))) 01166 having= tmp_having; 01167 01168 /* if group or order on first table, sort first */ 01169 if (group_list && simple_group) 01170 { 01171 DBUG_PRINT("info",("Sorting for group")); 01172 thd->proc_info="Sorting for group"; 01173 if (create_sort_index(thd, this, group_list, 01174 HA_POS_ERROR, HA_POS_ERROR) || 01175 alloc_group_fields(this, group_list) || 01176 make_sum_func_list(all_fields, fields_list, 1) || 01177 setup_sum_funcs(thd, sum_funcs)) 01178 DBUG_RETURN(1); 01179 group_list=0; 01180 } 01181 else 01182 { 01183 if (make_sum_func_list(all_fields, fields_list, 0) || 01184 setup_sum_funcs(thd, sum_funcs)) 01185 DBUG_RETURN(1); 01186 if (!group_list && ! exec_tmp_table1->distinct && order && simple_order) 01187 { 01188 DBUG_PRINT("info",("Sorting for order")); 01189 thd->proc_info="Sorting for order"; 01190 if (create_sort_index(thd, this, order, 01191 HA_POS_ERROR, HA_POS_ERROR)) 01192 DBUG_RETURN(1); 01193 order=0; 01194 } 01195 } 01196 01197 /* 01198 Optimize distinct when used on some of the tables 01199 SELECT DISTINCT t1.a FROM t1,t2 WHERE t1.b=t2.b 01200 In this case we can stop scanning t2 when we have found one t1.a 01201 */ 01202 01203 if (exec_tmp_table1->distinct) 01204 { 01205 table_map used_tables= thd->used_tables; 01206 JOIN_TAB *last_join_tab= join_tab+tables-1; 01207 do 01208 { 01209 if (used_tables & last_join_tab->table->map) 01210 break; 01211 last_join_tab->not_used_in_distinct=1; 01212 } while (last_join_tab-- != join_tab); 01213 /* Optimize "select distinct b from t1 order by key_part_1 limit #" */ 01214 if (order && skip_sort_order) 01215 { 01216 /* Should always succeed */ 01217 if (test_if_skip_sort_order(&join_tab[const_tables], 01218 order, unit->select_limit_cnt, 0)) 01219 order=0; 01220 } 01221 } 01222 01223 if (select_lex->uncacheable && !is_top_level_join()) 01224 { 01225 /* If this join belongs to an uncacheable subquery */ 01226 if (!(tmp_join= (JOIN*)thd->alloc(sizeof(JOIN)))) 01227 DBUG_RETURN(-1); 01228 error= 0; // Ensure that tmp_join.error= 0 01229 restore_tmp(); 01230 } 01231 } 01232 01233 error= 0; 01234 DBUG_RETURN(0); 01235 }
Here is the call graph for this function:

Here is the caller graph for this function:

| int JOIN::prepare | ( | Item *** | rref_pointer_array, | |
| TABLE_LIST * | tables, | |||
| uint | wind_num, | |||
| COND * | conds, | |||
| uint | og_num, | |||
| ORDER * | order, | |||
| ORDER * | group, | |||
| Item * | having, | |||
| ORDER * | proc_param, | |||
| SELECT_LEX * | select, | |||
| SELECT_LEX_UNIT * | unit | |||
| ) |
Definition at line 309 of file sql_select.cc.
References all_fields, alloc_func_list(), Item::check_cols(), conds, Item::const_during_execution(), count_field_types(), DBUG_ENTER, DBUG_RETURN, base_list::elements, ER, ER_DIFF_GROUPS_PROC, ER_MIX_OF_GROUP_FUNC_AND_FIELDS, ER_ORDER_WITH_PROC, ER_WRONG_SUM_SELECT, err, error, FALSE, fields_list, Item::fix_fields(), Item::fixed, flag, Procedure::flags, group, Procedure::group, group_list, having, hidden_group_fields, join_list, MARK_COLUMNS_READ, my_message(), MYF, st_order::next, Item_sum::next, st_table_list::next_leaf, optimized, OPTION_SETUP_TABLES_DONE, order, Procedure::param_fields, PROC_NO_SORT, proc_param, procedure, Item_sum::ref_by, ref_pointer_array, ref_pointer_array_size, Item_subselect::RES_ERROR, Item_subselect::RES_OK, result, rollup_init(), SELECT_ACL, select_lex, select_options, Item_subselect::select_transformer(), send_group_parts, setup_fields(), setup_ftfuncs(), setup_new_fields(), setup_procedure(), setup_tables_and_check_access(), setup_wild(), setup_without_group(), Item::split_sum_func2(), tables, tables_list, test_if_subpart(), thd, tmp_table_param, TRUE, union_part, unit, and Item::with_sum_func.
Referenced by mysql_select(), and subselect_single_select_engine::prepare().
00316 { 00317 DBUG_ENTER("JOIN::prepare"); 00318 00319 // to prevent double initialization on EXPLAIN 00320 if (optimized) 00321 DBUG_RETURN(0); 00322 00323 conds= conds_init; 00324 order= order_init; 00325 group_list= group_init; 00326 having= having_init; 00327 proc_param= proc_param_init; 00328 tables_list= tables_init; 00329 select_lex= select_lex_arg; 00330 select_lex->join= this; 00331 join_list= &select_lex->top_join_list; 00332 union_part= (unit_arg->first_select()->next_select() != 0); 00333 00334 /* 00335 If we have already executed SELECT, then it have not sense to prevent 00336 its table from update (see unique_table()) 00337 */ 00338 if (thd->derived_tables_processing) 00339 select_lex->exclude_from_table_unique_test= TRUE; 00340 00341 /* Check that all tables, fields, conds and order are ok */ 00342 00343 if ((!(select_options & OPTION_SETUP_TABLES_DONE) && 00344 setup_tables_and_check_access(thd, &select_lex->context, join_list, 00345 tables_list, 00346 &select_lex->leaf_tables, FALSE, 00347 SELECT_ACL)) || 00348 setup_wild(thd, tables_list, fields_list, &all_fields, wild_num) || 00349 select_lex->setup_ref_array(thd, og_num) || 00350 setup_fields(thd, (*rref_pointer_array), fields_list, MARK_COLUMNS_READ, 00351 &all_fields, 1) || 00352 setup_without_group(thd, (*rref_pointer_array), tables_list, 00353 select_lex->leaf_tables, fields_list, 00354 all_fields, &conds, order, group_list, 00355 &hidden_group_fields)) 00356 DBUG_RETURN(-1); /* purecov: inspected */ 00357 00358 ref_pointer_array= *rref_pointer_array; 00359 00360 if (having) 00361 { 00362 nesting_map save_allow_sum_func= thd->lex->allow_sum_func; 00363 thd->where="having clause"; 00364 thd->lex->allow_sum_func|= 1 << select_lex_arg->nest_level; 00365 select_lex->having_fix_field= 1; 00366 bool having_fix_rc= (!having->fixed && 00367 (having->fix_fields(thd, &having) || 00368 having->check_cols(1))); 00369 select_lex->having_fix_field= 0; 00370 if (having_fix_rc || thd->net.report_error) 00371 DBUG_RETURN(-1); /* purecov: inspected */ 00372 thd->lex->allow_sum_func= save_allow_sum_func; 00373 } 00374 00375 if (!thd->lex->view_prepare_mode) 00376 { 00377 Item_subselect *subselect; 00378 /* Is it subselect? */ 00379 if ((subselect= select_lex->master_unit()->item)) 00380 { 00381 Item_subselect::trans_res res; 00382 if ((res= subselect->select_transformer(this)) != 00383 Item_subselect::RES_OK) 00384 { 00385 select_lex->fix_prepare_information(thd, &conds); 00386 DBUG_RETURN((res == Item_subselect::RES_ERROR)); 00387 } 00388 } 00389 } 00390 00391 if (having && having->with_sum_func) 00392 having->split_sum_func2(thd, ref_pointer_array, all_fields, 00393 &having, TRUE); 00394 if (select_lex->inner_sum_func_list) 00395 { 00396 Item_sum *end=select_lex->inner_sum_func_list; 00397 Item_sum *item_sum= end; 00398 do 00399 { 00400 item_sum= item_sum->next; 00401 item_sum->split_sum_func2(thd, ref_pointer_array, 00402 all_fields, item_sum->ref_by, FALSE); 00403 } while (item_sum != end); 00404 } 00405 00406 if (setup_ftfuncs(select_lex)) /* should be after having->fix_fields */ 00407 DBUG_RETURN(-1); 00408 00409 00410 /* 00411 Check if one one uses a not constant column with group functions 00412 and no GROUP BY. 00413 TODO: Add check of calculation of GROUP functions and fields: 00414 SELECT COUNT(*)+table.col1 from table1; 00415 */ 00416 { 00417 if (!group_list) 00418 { 00419 uint flag=0; 00420 List_iterator_fast<Item> it(fields_list); 00421 Item *item; 00422 while ((item= it++)) 00423 { 00424 if (item->with_sum_func) 00425 flag|=1; 00426 else if (!(flag & 2) && !item->const_during_execution()) 00427 flag|=2; 00428 } 00429 if (flag == 3) 00430 { 00431 my_message(ER_MIX_OF_GROUP_FUNC_AND_FIELDS, 00432 ER(ER_MIX_OF_GROUP_FUNC_AND_FIELDS), MYF(0)); 00433 DBUG_RETURN(-1); 00434 } 00435 } 00436 TABLE_LIST *table_ptr; 00437 for (table_ptr= select_lex->leaf_tables; 00438 table_ptr; 00439 table_ptr= table_ptr->next_leaf) 00440 tables++; 00441 } 00442 { 00443 /* Caclulate the number of groups */ 00444 send_group_parts= 0; 00445 for (ORDER *group_tmp= group_list ; group_tmp ; group_tmp= group_tmp->next) 00446 send_group_parts++; 00447 } 00448 00449 procedure= setup_procedure(thd, proc_param, result, fields_list, &error); 00450 if (error) 00451 goto err; /* purecov: inspected */ 00452 if (procedure) 00453 { 00454 if (setup_new_fields(thd, fields_list, all_fields, 00455 procedure->param_fields)) 00456 goto err; /* purecov: inspected */ 00457 if (procedure->group) 00458 { 00459 if (!test_if_subpart(procedure->group,group_list)) 00460 { /* purecov: inspected */ 00461 my_message(ER_DIFF_GROUPS_PROC, ER(ER_DIFF_GROUPS_PROC), 00462 MYF(0)); /* purecov: inspected */ 00463 goto err; /* purecov: inspected */ 00464 } 00465 } 00466 if (order && (procedure->flags & PROC_NO_SORT)) 00467 { /* purecov: inspected */ 00468 my_message(ER_ORDER_WITH_PROC, ER(ER_ORDER_WITH_PROC), 00469 MYF(0)); /* purecov: inspected */ 00470 goto err; /* purecov: inspected */ 00471 } 00472 } 00473 00474 /* Init join struct */ 00475 count_field_types(&tmp_table_param, all_fields, 0); 00476 ref_pointer_array_size= all_fields.elements*sizeof(Item*); 00477 this->group= group_list != 0; 00478 unit= unit_arg; 00479 00480 #ifdef RESTRICTED_GROUP 00481 if (sum_func_count && !group_list && (func_count || field_count)) 00482 { 00483 my_message(ER_WRONG_SUM_SELECT,ER(ER_WRONG_SUM_SELECT),MYF(0)); 00484 goto err; 00485 } 00486 #endif 00487 if (!procedure && result && result->prepare(fields_list, unit_arg)) 00488 goto err; /* purecov: inspected */ 00489 00490 if (select_lex->olap == ROLLUP_TYPE && rollup_init()) 00491 goto err; 00492 if (alloc_func_list()) 00493 goto err; 00494 00495 select_lex->fix_prepare_information(thd, &conds); 00496 DBUG_RETURN(0); // All OK 00497 00498 err: 00499 delete procedure; /* purecov: inspected */ 00500 procedure= 0; 00501 DBUG_RETURN(-1); /* purecov: inspected */ 00502 }
Here is the call graph for this function:

Here is the caller graph for this function:

| int JOIN::reinit | ( | ) |
Definition at line 1248 of file sql_select.cc.
References DBUG_ENTER, DBUG_RETURN, handler::delete_all_rows(), exec_tmp_table1, exec_tmp_table2, handler::extra(), st_table::file, filesort_free_buffers(), first_record, free_io_cache(), func, HA_EXTRA_RESET_STATE, items0, join_tab, join_tab_save, memcpy, restore_tmp(), select_lex, set_items_ref_array(), sum_funcs, tmp_join, ULL, and unit.
Referenced by subselect_single_select_engine::exec().
01249 { 01250 DBUG_ENTER("JOIN::reinit"); 01251 01252 unit->offset_limit_cnt= (ha_rows)(select_lex->offset_limit ? 01253 select_lex->offset_limit->val_uint() : 01254 ULL(0)); 01255 01256 first_record= 0; 01257 01258 if (exec_tmp_table1) 01259 { 01260 exec_tmp_table1->file->extra(HA_EXTRA_RESET_STATE); 01261 exec_tmp_table1->file->delete_all_rows(); 01262 free_io_cache(exec_tmp_table1); 01263 filesort_free_buffers(exec_tmp_table1); 01264 } 01265 if (exec_tmp_table2) 01266 { 01267 exec_tmp_table2->file->extra(HA_EXTRA_RESET_STATE); 01268 exec_tmp_table2->file->delete_all_rows(); 01269 free_io_cache(exec_tmp_table2); 01270 filesort_free_buffers(exec_tmp_table2); 01271 } 01272 if (items0) 01273 set_items_ref_array(items0); 01274 01275 if (join_tab_save) 01276 memcpy(join_tab, join_tab_save, sizeof(JOIN_TAB) * tables); 01277 01278 if (tmp_join) 01279 restore_tmp(); 01280 01281 /* Reset of sum functions */ 01282 if (sum_funcs) 01283 { 01284 Item_sum *func, **func_ptr= sum_funcs; 01285 while ((func= *(func_ptr++))) 01286 func->clear(); 01287 } 01288 01289 DBUG_RETURN(0); 01290 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void JOIN::restore_tmp | ( | ) |
| bool JOIN::rollup_init | ( | ) |
Definition at line 13831 of file sql_select.cc.
References all_fields, change_group_ref(), base_list::elements, base_list::empty(), FALSE, st_rollup::fields, fields_list, Item::FUNC_ITEM, st_order::item, Item::maybe_null, new(), st_order::next, st_rollup::null_items, List< T >::push_back(), ref_pointer_array_size, st_rollup::ref_pointer_arrays, rollup, send_group_parts, st_rollup::state, st_rollup::STATE_INITED, tmp_table_param, Item::type(), and Item::with_sum_func.
Referenced by prepare().
13832 { 13833 uint i,j; 13834 Item **ref_array; 13835 13836 tmp_table_param.quick_group= 0; // Can't create groups in tmp table 13837 rollup.state= ROLLUP::STATE_INITED; 13838 13839 /* 13840 Create pointers to the different sum function groups 13841 These are updated by rollup_make_fields() 13842 */ 13843 tmp_table_param.group_parts= send_group_parts; 13844 13845 if (!(rollup.null_items= (Item_null_result**) thd->alloc((sizeof(Item*) + 13846 sizeof(Item**) + 13847 sizeof(List<Item>) + 13848 ref_pointer_array_size) 13849 * send_group_parts ))) 13850 return 1; 13851 13852 rollup.fields= (List<Item>*) (rollup.null_items + send_group_parts); 13853 rollup.ref_pointer_arrays= (Item***) (rollup.fields + send_group_parts); 13854 ref_array= (Item**) (rollup.ref_pointer_arrays+send_group_parts); 13855 13856 /* 13857 Prepare space for field list for the different levels 13858 These will be filled up in rollup_make_fields() 13859 */ 13860 for (i= 0 ; i < send_group_parts ; i++) 13861 { 13862 rollup.null_items[i]= new (thd->mem_root) Item_null_result(); 13863 List<Item> *rollup_fields= &rollup.fields[i]; 13864 rollup_fields->empty(); 13865 rollup.ref_pointer_arrays[i]= ref_array; 13866 ref_array+= all_fields.elements; 13867 } 13868 for (i= 0 ; i < send_group_parts; i++) 13869 { 13870 for (j=0 ; j < fields_list.elements ; j++) 13871 rollup.fields[i].push_back(rollup.null_items[i]); 13872 } 13873 List_iterator_fast<Item> it(all_fields); 13874 Item *item; 13875 while ((item= it++)) 13876 { 13877 ORDER *group_tmp; 13878 for (group_tmp= group_list; group_tmp; group_tmp= group_tmp->next) 13879 { 13880 if (*group_tmp->item == item) 13881 item->maybe_null= 1; 13882 } 13883 if (item->type() == Item::FUNC_ITEM) 13884 { 13885 bool changed= FALSE; 13886 if (change_group_ref(thd, (Item_func *) item, group_list, &changed)) 13887 return 1; 13888 /* 13889 We have to prevent creation of a field in a temporary table for 13890 an expression that contains GROUP BY attributes. 13891 Marking the expression item as 'with_sum_func' will ensure this. 13892 */ 13893 if (changed) 13894 item->with_sum_func= 1; 13895 } 13896 } 13897 return 0; 13898 }
Here is the call graph for this function:

Here is the caller graph for this function:

| bool JOIN::rollup_make_fields | ( | List< Item > & | all_fields, | |
| List< Item > & | fields, | |||
| Item_sum *** | func | |||
| ) |
Definition at line 13919 of file sql_select.cc.
References Item::const_item(), Item::copy_or_same(), base_list::elements, st_rollup::fields, func, Item::get_tmp_table_field(), List< T >::head(), st_order::item, Item::maybe_null, new(), st_order::next, pos(), st_rollup::ref_pointer_arrays, List_iterator< T >::replace(), List_iterator_fast< T >::rewind(), rollup, send_group_parts, Item::SUM_FUNC_ITEM, sum_funcs_end, and Item::type().
Referenced by make_sum_func_list().
13921 { 13922 List_iterator_fast<Item> it(fields_arg); 13923 Item *first_field= sel_fields.head(); 13924 uint level; 13925 13926 /* 13927 Create field lists for the different levels 13928 13929 The idea here is to have a separate field list for each rollup level to 13930 avoid all runtime checks of which columns should be NULL. 13931 13932 The list is stored in reverse order to get sum function in such an order 13933 in func that it makes it easy to reset them with init_sum_functions() 13934 13935 Assuming: SELECT a, b, c SUM(b) FROM t1 GROUP BY a,b WITH ROLLUP 13936 13937 rollup.fields[0] will contain list where a,b,c is NULL 13938 rollup.fields[1] will contain list where b,c is NULL 13939 ... 13940 rollup.ref_pointer_array[#] points to fields for rollup.fields[#] 13941 ... 13942 sum_funcs_end[0] points to all sum functions 13943 sum_funcs_end[1] points to all sum functions, except grand totals 13944 ... 13945 */ 13946 13947 for (level=0 ; level < send_group_parts ; level++) 13948 { 13949 uint i; 13950 uint pos= send_group_parts - level -1; 13951 bool real_fields= 0; 13952 Item *item; 13953 List_iterator<Item> new_it(rollup.fields[pos]); 13954 Item **ref_array_start= rollup.ref_pointer_arrays[pos]; 13955 ORDER *start_group; 13956 13957 /* Point to first hidden field */ 13958 Item **ref_array= ref_array_start + fields_arg.elements-1; 13959 13960 /* Remember where the sum functions ends for the previous level */ 13961 sum_funcs_end[pos+1]= *func; 13962 13963 /* Find the start of the group for this level */ 13964 for (i= 0, start_group= group_list ; 13965 i++ < pos ; 13966 start_group= start_group->next) 13967 ; 13968 13969 it.rewind(); 13970 while ((item= it++)) 13971 { 13972 if (item == first_field) 13973 { 13974 real_fields= 1; // End of hidden fields 13975 ref_array= ref_array_start; 13976 } 13977 13978 if (item->type() == Item::SUM_FUNC_ITEM && !item->const_item()) 13979 { 13980 /* 13981 This is a top level summary function that must be replaced with 13982 a sum function that is reset for this level. 13983 13984 NOTE: This code creates an object which is not that nice in a 13985 sub select. Fortunately it's not common to have rollup in 13986 sub selects. 13987 */ 13988 item= item->copy_or_same(thd); 13989 ((Item_sum*) item)->make_unique(); 13990 *(*func)= (Item_sum*) item; 13991 (*func)++; 13992 } 13993 else 13994 { 13995 /* Check if this is something that is part of this group by */ 13996 ORDER *group_tmp; 13997 for (group_tmp= start_group, i= pos ; 13998 group_tmp ; group_tmp= group_tmp->next, i++) 13999 { 14000 if (*group_tmp->item == item) 14001 { 14002 /* 14003 This is an element that is used by the GROUP BY and should be 14004 set to NULL in this level 14005 */ 14006 Item_null_result *null_item= new (thd->mem_root) Item_null_result(); 14007 if (!null_item) 14008 return 1; 14009 item->maybe_null= 1; // Value will be null sometimes 14010 null_item->result_field= item->get_tmp_table_field(); 14011 item= null_item; 14012 break; 14013 } 14014 } 14015 } 14016 *ref_array= item; 14017 if (real_fields) 14018 { 14019 (void) new_it++; // Point to next item 14020 new_it.replace(item); // Replace previous 14021 ref_array++; 14022 } 14023 else 14024 ref_array--; 14025 } 14026 } 14027 sum_funcs_end[0]= *func; // Point to last function 14028 return 0; 14029 }
Here is the call graph for this function:

Here is the caller graph for this function:

| int JOIN::rollup_send_data | ( | uint | idx | ) |
Definition at line 14049 of file sql_select.cc.
References current_ref_pointer_array, do_send_rows, st_rollup::fields, having, memcpy, ref_pointer_array, ref_pointer_array_size, st_rollup::ref_pointer_arrays, result, rollup, send_group_parts, send_records, set_items_ref_array(), and Item::val_int().
Referenced by end_send_group().
14050 { 14051 uint i; 14052 for (i= send_group_parts ; i-- > idx ; ) 14053 { 14054 /* Get reference pointers to sum functions in place */ 14055 memcpy((char*) ref_pointer_array, 14056 (char*) rollup.ref_pointer_arrays[i], 14057 ref_pointer_array_size); 14058 if ((!having || having->val_int())) 14059 { 14060 if (send_records < unit->select_limit_cnt && do_send_rows && 14061 result->send_data(rollup.fields[i])) 14062 return 1; 14063 send_records++; 14064 } 14065 } 14066 /* Restore ref_pointer_array */ 14067 set_items_ref_array(current_ref_pointer_array); 14068 return 0; 14069 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 14090 of file sql_select.cc.
References copy_sum_funcs(), create_myisam_from_heap(), current_ref_pointer_array, st_rollup::fields, st_table::file, having, Item::is_result_field(), memcpy, Item::NULL_ITEM, st_table::record, ref_pointer_array, ref_pointer_array_size, st_rollup::ref_pointer_arrays, rollup, Item::save_in_result_field(), send_group_parts, set_items_ref_array(), sum_funcs_end, table, tmp_table_param, Item::type(), Item::val_int(), and handler::write_row().
Referenced by end_write_group().
14091 { 14092 uint i; 14093 for (i= send_group_parts ; i-- > idx ; ) 14094 { 14095 /* Get reference pointers to sum functions in place */ 14096 memcpy((char*) ref_pointer_array, 14097 (char*) rollup.ref_pointer_arrays[i], 14098 ref_pointer_array_size); 14099 if ((!having || having->val_int())) 14100 { 14101 int error; 14102 Item *item; 14103 List_iterator_fast<Item> it(rollup.fields[i]); 14104 while ((item= it++)) 14105 { 14106 if (item->type() == Item::NULL_ITEM && item->is_result_field()) 14107 item->save_in_result_field(1); 14108 } 14109 copy_sum_funcs(sum_funcs_end[i+1], sum_funcs_end[i]); 14110 if ((error= table->file->write_row(table->record[0]))) 14111 { 14112 if (create_myisam_from_heap(thd, table, &tmp_table_param, 14113 error, 0)) 14114 return 1; 14115 } 14116 } 14117 } 14118 /* Restore ref_pointer_array */ 14119 set_items_ref_array(current_ref_pointer_array); 14120 return 0; 14121 }
Here is the call graph for this function:

Here is the caller graph for this function:

| bool JOIN::save_join_tab | ( | ) |
Definition at line 1294 of file sql_select.cc.
References join_tab, join_tab_save, and select_lex.
Referenced by exec().
01295 { 01296 if (!join_tab_save && select_lex->master_unit()->uncacheable) 01297 { 01298 if (!(join_tab_save= (JOIN_TAB*)thd->memdup((gptr) join_tab, 01299 sizeof(JOIN_TAB) * tables))) 01300 return 1; 01301 } 01302 return 0; 01303 }
Here is the caller graph for this function:

| bool JOIN::send_row_on_empty_set | ( | ) | [inline] |
Definition at line 410 of file sql_select.h.
References do_send_rows, group_list, and tmp_table_param.
Referenced by do_select(), and exec().
00411 { 00412 return (do_send_rows && tmp_table_param.sum_func_count != 0 && 00413 !group_list); 00414 }
Here is the caller graph for this function:

| void JOIN::set_items_ref_array | ( | Item ** | ptr | ) | [inline] |
Definition at line 381 of file sql_select.h.
References current_ref_pointer_array, memcpy, ref_pointer_array, and ref_pointer_array_size.
Referenced by exec(), reinit(), rollup_send_data(), and rollup_write_data().
00382 { 00383 memcpy((char*) ref_pointer_array, (char*) ptr, ref_pointer_array_size); 00384 current_ref_pointer_array= ptr; 00385 }
Here is the caller graph for this function:

Definition at line 517 of file sql_select.cc.
References Item_func::COND_AND_FUNC, Item::COND_ITEM, conds, Item_func::EQ_FUNC, Item::FIELD_ITEM, Item::FUNC_ITEM, st_join_table::info, join_tab, Item::REF_ITEM, remove_additional_cond(), Item::type(), and where.
00518 { 00519 if (conds->type() == Item::FUNC_ITEM && 00520 ((Item_func *)this->conds)->functype() == Item_func::EQ_FUNC && 00521 ((Item_func *)conds)->arguments()[0]->type() == Item::REF_ITEM && 00522 ((Item_func *)conds)->arguments()[1]->type() == Item::FIELD_ITEM) 00523 { 00524 join_tab->info= "Using index"; 00525 *where= 0; 00526 return 1; 00527 } 00528 if (conds->type() == Item::COND_ITEM && 00529 ((class Item_func *)this->conds)->functype() == 00530 Item_func::COND_AND_FUNC) 00531 { 00532 if ((*where= remove_additional_cond(conds))) 00533 join_tab->info= "Using index; Using where"; 00534 else 00535 join_tab->info= "Using index"; 00536 return 1; 00537 } 00538 return 0; 00539 }
Here is the call graph for this function:

Definition at line 284 of file sql_select.h.
Referenced by exec(), get_best_group_min_max(), init(), init_items_ref_array(), optimize(), prepare(), rollup_init(), and Item_in_subselect::single_value_transformer().
| POSITION JOIN::best_positions[MAX_TABLES+1] |
Definition at line 231 of file sql_select.h.
Referenced by find_best(), get_best_combination(), greedy_search(), optimize_straight_join(), print_plan(), and select_describe().
| double JOIN::best_read |
Definition at line 239 of file sql_select.h.
Referenced by choose_plan(), find_best(), greedy_search(), optimize(), optimize_straight_join(), and print_plan().
Definition at line 206 of file sql_select.h.
Referenced by best_extension_by_limited_search(), cache_record_length(), choose_plan(), find_best(), greedy_search(), make_join_statistics(), optimize_straight_join(), print_plan(), and set_position().
Definition at line 298 of file sql_select.h.
Referenced by destroy(), init(), optimize(), and optimize_cond().
Definition at line 294 of file sql_select.h.
Referenced by do_select(), exec(), get_best_group_min_max(), join_read_const_table(), mysql_select(), optimize(), prepare(), Item_in_subselect::row_value_transformer(), Item_singlerow_subselect::select_transformer(), Item_in_subselect::single_value_transformer(), and test_in_subselect().
Definition at line 219 of file sql_select.h.
Referenced by best_access_path(), create_ref_for_key(), exec(), make_simple_join(), optimize(), optimize_keyuse(), remove_const(), and test_if_skip_sort_order().
Definition at line 210 of file sql_select.h.
Referenced by add_not_null_conds(), best_access_path(), cache_record_length(), choose_plan(), clear_tables(), create_sort_index(), determine_search_depth(), do_select(), exec(), Sensitive_cursor::fetch(), find_best(), get_best_combination(), greedy_search(), init(), make_join_readinfo(), make_outerjoin_info(), make_simple_join(), Sensitive_cursor::open(), optimize(), optimize_straight_join(), and remove_const().
Definition at line 237 of file sql_select.h.
Referenced by check_interleaving_with_nj(), choose_plan(), and restore_prev_nj_state().
Definition at line 303 of file sql_select.h.
Referenced by init_items_ref_array(), rollup_send_data(), rollup_write_data(), and set_items_ref_array().
Definition at line 213 of file sql_select.h.
Referenced by end_send(), end_send_group(), end_write(), exec(), init(), make_simple_join(), optimize(), rollup_send_data(), and send_row_on_empty_set().
| int JOIN::error |
Definition at line 291 of file sql_select.h.
Referenced by destroy(), exec(), subselect_single_select_engine::exec(), get_schema_tables_result(), init(), mysql_select(), optimize(), prepare(), and select_describe().
Definition at line 220 of file sql_select.h.
Referenced by create_sort_index(), evaluate_join_record(), and init().
Definition at line 230 of file sql_select.h.
Referenced by end_send(), end_send_group(), Sensitive_cursor::fetch(), init(), and Sensitive_cursor::open().
Definition at line 240 of file sql_select.h.
Referenced by do_select(), end_send(), end_send_group(), and Sensitive_cursor::open().
Definition at line 289 of file sql_select.h.
Referenced by add_group_and_distinct_keys(), alloc_func_list(), change_result(), exec(), get_best_group_min_max(), init(), prepare(), and rollup_init().
Definition at line 212 of file sql_select.h.
Referenced by end_send_group(), end_write_group(), init(), make_simple_join(), and reinit().
Definition at line 220 of file sql_select.h.
Referenced by end_update(), end_write(), evaluate_join_record(), and init().
Definition at line 212 of file sql_select.h.
Referenced by calc_group_buffer(), end_send_group(), end_write_group(), exec(), make_simple_join(), and prepare().
Definition at line 241 of file sql_select.h.
Referenced by alloc_group_fields(), cleanup(), end_send_group(), end_write_group(), and make_group_fields().
Definition at line 293 of file sql_select.h.
Referenced by add_group_and_distinct_keys(), exec(), get_best_group_min_max(), make_group_fields(), optimize(), prepare(), and send_row_on_empty_set().
Definition at line 250 of file sql_select.h.
Referenced by end_send(), end_send_group(), end_write(), end_write_group(), exec(), init(), mysql_select(), optimize(), prepare(), rollup_send_data(), rollup_write_data(), Item_in_subselect::row_value_transformer(), Item_singlerow_subselect::select_transformer(), and Item_in_subselect::single_value_transformer().
Definition at line 303 of file sql_select.h.
Referenced by exec(), init(), init_items_ref_array(), and reinit().
| Item ** JOIN::items1 |
| Item ** JOIN::items2 |
| Item ** JOIN::items3 |
Definition at line 297 of file sql_select.h.
Referenced by choose_plan(), init(), optimize(), prepare(), and update_ref_and_keys().
Definition at line 206 of file sql_select.h.
Referenced by add_not_null_conds(), cleanup(), create_sort_index(), destroy(), do_select(), end_send(), end_update(), error_if_full_join(), exec(), Sensitive_cursor::fetch(), flush_cached_records(), get_best_combination(), get_schema_tables_result(), init(), make_join_readinfo(), make_outerjoin_info(), make_simple_join(), Sensitive_cursor::open(), optimize(), reinit(), remove_const(), save_join_tab(), select_describe(), test_in_subselect(), TEST_join(), and update_depend_map().
Definition at line 207 of file sql_select.h.
Referenced by get_best_combination(), only_eq_ref_tables(), optimize(), and update_depend_map().
Definition at line 212 of file sql_select.h.
Definition at line 293 of file sql_select.h.
Referenced by exec(), make_join_readinfo(), optimize(), and prepare().
| POSITION JOIN::positions[MAX_TABLES+1] |
Definition at line 231 of file sql_select.h.
Referenced by best_access_path(), best_extension_by_limited_search(), find_best(), greedy_search(), optimize_straight_join(), prev_record_reads(), print_plan(), and set_position().
Definition at line 249 of file sql_select.h.
Referenced by change_result(), destroy(), do_select(), end_send(), end_send_group(), end_write_group(), exec(), init(), prepare(), and setup_end_select_func().
Definition at line 301 of file sql_select.h.
Referenced by exec(), init(), init_items_ref_array(), prepare(), rollup_send_data(), rollup_write_data(), and set_items_ref_array().
Definition at line 304 of file sql_select.h.
Referenced by init(), init_items_ref_array(), prepare(), rollup_init(), rollup_send_data(), rollup_write_data(), and set_items_ref_array().
| select_result* JOIN::result |
Definition at line 254 of file sql_select.h.
Referenced by change_result(), do_select(), end_send(), end_send_group(), exec(), init(), optimize(), prepare(), rollup_send_data(), and select_describe().
Definition at line 218 of file sql_select.h.
Referenced by Sensitive_cursor::fetch(), init(), and sub_select().
Definition at line 300 of file sql_select.h.
Referenced by evaluate_join_record(), evaluate_null_complemented_join_record(), init(), and sub_select().
Definition at line 263 of file sql_select.h.
Referenced by alloc_func_list(), end_send_group(), end_write_group(), init(), make_sum_func_list(), rollup_init(), rollup_make_fields(), rollup_send_data(), and rollup_write_data().
Definition at line 265 of file sql_select.h.
Referenced by add_group_and_distinct_keys(), exec(), get_best_group_min_max(), init(), and optimize().
| SELECT_LEX* JOIN::select_lex |
Definition at line 260 of file sql_select.h.
Referenced by change_result(), create_sort_index(), destroy(), exec(), init(), is_top_level_join(), join_free(), join_read_const_table(), optimize(), prepare(), reinit(), Item_in_subselect::row_value_transformer(), save_join_tab(), select_describe(), Item_singlerow_subselect::select_transformer(), and Item_in_subselect::single_value_transformer().
Definition at line 220 of file sql_select.h.
Referenced by exec(), make_join_readinfo(), and optimize().
Definition at line 253 of file sql_select.h.
Referenced by choose_plan(), create_ref_for_key(), end_send(), end_send_group(), end_write(), exec(), find_best(), init(), join_free(), make_join_readinfo(), mysql_select(), optimize(), prepare(), remove_duplicates(), and test_if_skip_sort_order().
Definition at line 211 of file sql_select.h.
Referenced by alloc_func_list(), end_send(), end_send_group(), end_write_group(), make_sum_func_list(), prepare(), rollup_init(), rollup_make_fields(), rollup_send_data(), and rollup_write_data().
Definition at line 220 of file sql_select.h.
Referenced by do_select(), end_send(), end_send_group(), end_unique_update(), end_update(), end_write(), exec(), init(), make_simple_join(), Sensitive_cursor::open(), and rollup_send_data().
Definition at line 279 of file sql_select.h.
Referenced by exec(), init(), and make_join_readinfo().
Definition at line 212 of file sql_select.h.
Referenced by alloc_group_fields(), end_send(), exec(), init(), make_group_fields(), make_simple_join(), and setup_end_select_func().
Definition at line 209 of file sql_select.h.
Referenced by best_access_path(), find_best(), make_join_readinfo(), optimize(), and optimize_straight_join().
Definition at line 246 of file sql_select.h.
Referenced by alloc_func_list(), clear(), end_send_group(), end_unique_update(), end_update(), end_write_group(), exec(), get_best_group_min_max(), init(), QUICK_GROUP_MIN_MAX_SELECT::init(), make_sum_func_list(), reinit(), and setup_end_select_func().
Definition at line 246 of file sql_select.h.
Referenced by alloc_func_list(), end_send_group(), end_write_group(), exec(), make_sum_func_list(), rollup_make_fields(), and rollup_write_data().
Definition at line 209 of file sql_select.h.
Referenced by clear_tables(), get_best_combination(), init(), make_simple_join(), optimize(), and rollup_write_data().
Definition at line 210 of file sql_select.h.
Referenced by choose_plan(), create_sort_index(), determine_search_depth(), do_select(), end_send(), end_update(), error_if_full_join(), exec(), get_best_combination(), get_best_group_min_max(), get_schema_tables_result(), get_sweep_read_cost(), greedy_search(), init(), make_join_readinfo(), make_join_statistics(), make_simple_join(), Sensitive_cursor::open(), optimize(), prepare(), remove_const(), select_describe(), sub_select(), TEST_join(), and update_depend_map().
| THD* JOIN::thd |
Definition at line 245 of file sql_select.h.
Referenced by add_not_null_conds(), alloc_group_fields(), best_extension_by_limited_search(), cache_record_length(), calc_group_buffer(), choose_plan(), Sensitive_cursor::close(), cmp_buffer_with_ref(), create_ref_for_key(), do_select(), end_unique_update(), end_update(), end_write(), end_write_group(), evaluate_join_record(), exec(), Sensitive_cursor::fetch(), find_best(), flush_cached_records(), get_best_combination(), get_schema_tables_result(), init(), is_top_level_join(), join_ft_read_first(), join_init_read_record(), join_read_always_key(), join_read_const(), join_read_last_key(), make_join_readinfo(), make_join_select(), make_join_statistics(), make_simple_join(), Sensitive_cursor::open(), optimize(), optimize_cond(), optimize_straight_join(), prepare(), QUICK_GROUP_MIN_MAX_SELECT::QUICK_GROUP_MIN_MAX_SELECT(), remove_duplicates(), return_zero_rows(), select_describe(), simplify_joins(), sub_select(), sub_select_cache(), test_if_quick_select(), and test_if_skip_sort_order().
Definition at line 262 of file sql_select.h.
Referenced by cleanup(), destroy(), exec(), init(), reinit(), and restore_tmp().
Definition at line 242 of file sql_select.h.
Referenced by do_select(), end_send(), end_unique_update(), end_update(), end_write(), end_write_group(), Sensitive_cursor::open(), and setup_end_select_func().
| TMP_TABLE_PARAM JOIN::tmp_table_param |
Definition at line 255 of file sql_select.h.
Referenced by alloc_func_list(), calc_group_buffer(), cleanup(), clear(), destroy(), do_select(), end_send_group(), end_unique_update(), end_update(), end_write(), end_write_group(), exec(), QUICK_GROUP_MIN_MAX_SELECT::get_next(), init(), make_simple_join(), optimize(), prepare(), rollup_init(), rollup_write_data(), send_row_on_empty_set(), setup_end_select_func(), and Item_in_subselect::single_value_transformer().
| SELECT_LEX_UNIT* JOIN::unit |
Definition at line 258 of file sql_select.h.
Referenced by best_access_path(), end_send(), end_send_group(), end_write(), exec(), is_top_level_join(), join_free(), make_simple_join(), Sensitive_cursor::open(), optimize(), prepare(), reinit(), remove_duplicates(), select_describe(), and test_if_skip_sort_order().
| const char* JOIN::zero_result_cause |
1.4.7

