| 5646 | */ |
| 5647 | |
| 5648 | static bool |
| 5649 | make_join_statistics(JOIN *join, List<TABLE_LIST> &tables_list, |
| 5650 | DYNAMIC_ARRAY *keyuse_array) |
| 5651 | { |
| 5652 | int error= 0; |
| 5653 | uint i,table_count,const_count,key; |
| 5654 | uint sort_space; |
| 5655 | table_map found_const_table_map, all_table_map; |
| 5656 | key_map const_ref, eq_part; |
| 5657 | bool has_expensive_keyparts; |
| 5658 | TABLE **table_vector; |
| 5659 | JOIN_TAB *stat,*stat_end,*s,**stat_ref, **stat_vector; |
| 5660 | KEYUSE *keyuse,*start_keyuse; |
| 5661 | table_map outer_join=0; |
| 5662 | table_map no_rows_const_tables= 0; |
| 5663 | SARGABLE_PARAM *sargables= 0; |
| 5664 | List_iterator<TABLE_LIST> ti(tables_list); |
| 5665 | TABLE_LIST *tables; |
| 5666 | THD *thd= join->thd; |
| 5667 | DBUG_ENTER("make_join_statistics"); |
| 5668 | |
| 5669 | table_count=join->table_count; |
| 5670 | const uint sj_nests= join->select_lex->sj_nests.elements; // Changed by pull-out |
| 5671 | |
| 5672 | /* |
| 5673 | best_extension_by_limited_search need sort space for 2POSITIION |
| 5674 | objects per remaining table, which gives us |
| 5675 | 2*(T + T-1 + T-2 + T-3...1 POSITIONS) = 2*(T+1)/2*T = (T*T+T) |
| 5676 | */ |
| 5677 | join->sort_space= sort_space= (table_count*table_count + table_count); |
| 5678 | |
| 5679 | /* |
| 5680 | best_positions is ok to allocate with alloc() as we copy things to it with |
| 5681 | memcpy() |
| 5682 | */ |
| 5683 | |
| 5684 | if (!multi_alloc_root(join->thd->mem_root, |
| 5685 | &stat, sizeof(JOIN_TAB)*(table_count), |
| 5686 | &stat_ref, sizeof(JOIN_TAB*)* MAX_TABLES, |
| 5687 | &stat_vector, sizeof(JOIN_TAB*)* (table_count +1), |
| 5688 | &table_vector, sizeof(TABLE*)*(table_count*2), |
| 5689 | &join->positions, sizeof(POSITION)*(table_count + 1), |
| 5690 | &join->sort_positions, sizeof(POSITION)*(sort_space), |
| 5691 | &join->best_positions, |
| 5692 | sizeof(POSITION)*(table_count + 1), |
| 5693 | NullS)) |
| 5694 | DBUG_RETURN(1); |
| 5695 | |
| 5696 | /* The following should be optimized to only clear critical things */ |
| 5697 | bzero((void*)stat, sizeof(JOIN_TAB)* table_count); |
| 5698 | join->top_join_tab_count= table_count; |
| 5699 | |
| 5700 | /* Initialize POSITION objects */ |
| 5701 | for (i=0 ; i <= table_count ; i++) |
| 5702 | (void) new ((char*) (join->positions + i)) POSITION; |
| 5703 | for (i=0 ; i < sort_space ; i++) |
| 5704 | (void) new ((char*) (join->sort_positions + i)) POSITION; |
| 5705 |
no test coverage detected