98
100
static bool make_simple_join(JOIN *join,Table *tmp_table);
99
101
static void make_outerjoin_info(JOIN *join);
100
102
static bool make_join_select(JOIN *join, optimizer::SqlSelect *select,COND *item);
101
static bool make_join_readinfo(JOIN *join, uint64_t options, uint32_t no_jbuf_after);
103
static bool make_join_readinfo(JOIN *join);
102
104
static void update_depend_map(JOIN *join);
103
105
static void update_depend_map(JOIN *join, order_st *order);
104
106
static order_st *remove_constants(JOIN *join,order_st *first_order,COND *cond, bool change_list, bool *simple_order);
2819
2813
join->found_records++;
2820
if ((error=table->cursor->ha_write_row(table->record[0])))
2814
if ((error=table->cursor->insertRecord(table->record[0])))
2822
2816
if (!table->cursor->is_fatal_error(error, HA_CHECK_DUP))
2824
if (create_myisam_from_heap(join->session, table,
2825
join->tmp_table_param.start_recinfo,
2826
&join->tmp_table_param.recinfo,
2828
return NESTED_LOOP_ERROR; // Not a table_is_full error
2829
table->s->uniques= 0; // To ensure rows are the same
2819
my_error(ER_USE_SQL_BIG_RESULT, MYF(0));
2820
return NESTED_LOOP_ERROR; // Table is_full error
2831
2822
if (++join->send_records >= join->tmp_table_param.end_write_records && join->do_send_rows)
2900
2891
init_tmptable_sum_functions(join->sum_funcs);
2901
2892
copy_funcs(join->tmp_table_param.items_to_copy);
2902
if ((error=table->cursor->ha_write_row(table->record[0])))
2893
if ((error=table->cursor->insertRecord(table->record[0])))
2904
if (create_myisam_from_heap(join->session, table,
2905
join->tmp_table_param.start_recinfo,
2906
&join->tmp_table_param.recinfo,
2908
return NESTED_LOOP_ERROR; // Not a table_is_full error
2909
/* Change method to update rows */
2910
table->cursor->ha_index_init(0, 0);
2911
join->join_tab[join->tables-1].next_select= end_unique_update;
2895
my_error(ER_USE_SQL_BIG_RESULT, MYF(0));
2896
return NESTED_LOOP_ERROR; // Table is_full error
2913
2898
join->send_records++;
2914
2899
return NESTED_LOOP_OK;
4891
4873
produce sorted output.
4893
4875
tab->sorted= sorted;
4894
sorted= 0; // only first must be sorted
4876
sorted= false; // only first must be sorted
4895
4878
if (tab->insideout_match_tab)
4897
if (!(tab->insideout_buf= (unsigned char*)join->session->alloc(tab->table->key_info
4880
if (! (tab->insideout_buf= (unsigned char*) join->session->alloc(tab->table->key_info
4902
switch (tab->type) {
4903
case AM_SYSTEM: // Only happens with left join
4904
table->status=STATUS_NO_RECORD;
4905
tab->read_first_record= join_read_system;
4906
tab->read_record.read_record= join_no_more_records;
4908
case AM_CONST: // Only happens with left join
4909
table->status=STATUS_NO_RECORD;
4910
tab->read_first_record= join_read_const;
4911
tab->read_record.read_record= join_no_more_records;
4912
if (table->covering_keys.test(tab->ref.key) &&
4916
table->cursor->extra(HA_EXTRA_KEYREAD);
4920
table->status=STATUS_NO_RECORD;
4923
delete tab->select->quick;
4924
tab->select->quick=0;
4928
tab->read_first_record= join_read_key;
4929
tab->read_record.read_record= join_no_more_records;
4930
if (table->covering_keys.test(tab->ref.key) && !table->no_keyread)
4933
table->cursor->extra(HA_EXTRA_KEYREAD);
4936
case AM_REF_OR_NULL:
4938
table->status=STATUS_NO_RECORD;
4941
delete tab->select->quick;
4942
tab->select->quick=0;
4946
if (table->covering_keys.test(tab->ref.key) && !table->no_keyread)
4949
table->cursor->extra(HA_EXTRA_KEYREAD);
4951
if (tab->type == AM_REF)
4953
tab->read_first_record= join_read_always_key;
4954
tab->read_record.read_record= tab->insideout_match_tab?
4955
join_read_next_same_diff : join_read_next_same;
4959
tab->read_first_record= join_read_always_key_or_null;
4960
tab->read_record.read_record= join_read_next_same_or_null;
4965
If previous table use cache
4966
If the incoming data set is already sorted don't use cache.
4968
table->status=STATUS_NO_RECORD;
4969
using_join_cache= false;
4970
if (i != join->const_tables && !(options & SELECT_NO_JOIN_CACHE) &&
4971
tab->use_quick != 2 && !tab->first_inner && i <= no_jbuf_after &&
4972
!tab->insideout_match_tab)
4974
if ((options & SELECT_DESCRIBE) ||
4975
!join_init_cache(join->session,join->join_tab+join->const_tables,
4976
i-join->const_tables))
4978
using_join_cache= true;
4979
tab[-1].next_select=sub_select_cache; /* Patch previous */
4982
/* These init changes read_record */
4983
if (tab->use_quick == 2)
4985
join->session->server_status|=SERVER_QUERY_NO_GOOD_INDEX_USED;
4986
tab->read_first_record= join_init_quick_read_record;
4988
status_var_increment(join->session->status_var.select_range_check_count);
4992
tab->read_first_record= join_init_read_record;
4993
if (i == join->const_tables)
4995
if (tab->select && tab->select->quick)
4998
status_var_increment(join->session->status_var.select_range_count);
5002
join->session->server_status|=SERVER_QUERY_NO_INDEX_USED;
5004
status_var_increment(join->session->status_var.select_scan_count);
5009
if (tab->select && tab->select->quick)
5012
status_var_increment(join->session->status_var.select_full_range_join_count);
5016
join->session->server_status|=SERVER_QUERY_NO_INDEX_USED;
5018
status_var_increment(join->session->status_var.select_full_join_count);
5021
if (!table->no_keyread)
5023
if (tab->select && tab->select->quick &&
5024
tab->select->quick->index != MAX_KEY && //not index_merge
5025
table->covering_keys.test(tab->select->quick->index))
5028
table->cursor->extra(HA_EXTRA_KEYREAD);
5030
else if (!table->covering_keys.none() &&
5031
!(tab->select && tab->select->quick))
5032
{ // Only read index tree
5033
if (!tab->insideout_match_tab)
5036
See bug #26447: "Using the clustered index for a table scan
5037
is always faster than using a secondary index".
5039
if (table->s->primary_key != MAX_KEY &&
5040
table->cursor->primary_key_is_clustered())
5041
tab->index= table->s->primary_key;
5043
tab->index= table->find_shortest_key(&table->covering_keys);
5045
tab->read_first_record= join_read_first;
5046
tab->type= AM_NEXT; // Read with index_first / index_next
4886
optimizer::AccessMethodFactory &factory= optimizer::AccessMethodFactory::singleton();
4887
boost::shared_ptr<optimizer::AccessMethod> access_method(factory.createAccessMethod(tab->type));
4889
if (! access_method)
4893
* Is abort() the correct thing to call here? I call this here because it was what was called in
4894
* the default case for the switch statement that used to be here.
4899
access_method->getStats(table, tab);
5058
join->join_tab[join->tables-1].next_select=0; /* Set by do_select */
4902
join->join_tab[join->tables-1].next_select= NULL; /* Set by do_select */
5062
4907
/** Update the dependency map for the tables. */
6175
Determine if the set is already ordered for order_st BY, so it can
6176
disable join cache because it will change the ordering of the results.
6177
Code handles sort table that is at any location (not only first after
6178
the const tables) despite the fact that it's currently prohibited.
6179
We must disable join cache if the first non-const table alone is
6180
ordered. If there is a temp table the ordering is done as a last
6181
operation and doesn't prevent join cache usage.
6183
static uint32_t make_join_orderinfo(JOIN *join)
6187
return join->tables;
6189
for (i=join->const_tables ; i < join->tables ; i++)
6191
JoinTable *tab= join->join_tab+i;
6192
Table *table= tab->table;
6193
if ((table == join->sort_by_table &&
6194
(!join->order || join->skip_sort_order)) ||
6195
(join->sort_by_table == (Table *) 1 && i != join->const_tables))
6204
6021
Create a condition for a const reference and add this to the