mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Merge branch 'github/10.1' into 10.2
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
/* Copyright (c) 2000, 2016 Oracle and/or its affiliates.
|
||||
Copyright (c) 2009, 2016 MariaDB
|
||||
Copyright (c) 2009, 2018 MariaDB Corporation
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@ -280,6 +280,9 @@ JOIN_TAB *next_depth_first_tab(JOIN* join, JOIN_TAB* tab);
|
||||
|
||||
static JOIN_TAB *next_breadth_first_tab(JOIN_TAB *first_top_tab,
|
||||
uint n_top_tabs_count, JOIN_TAB *tab);
|
||||
static bool find_order_in_list(THD *, Ref_ptr_array, TABLE_LIST *, ORDER *,
|
||||
List<Item> &, List<Item> &, bool, bool, bool);
|
||||
|
||||
static double table_cond_selectivity(JOIN *join, uint idx, JOIN_TAB *s,
|
||||
table_map rem_tables);
|
||||
void set_postjoin_aggr_write_func(JOIN_TAB *tab);
|
||||
@ -331,7 +334,7 @@ bool dbug_user_var_equals_int(THD *thd, const char *name, int value)
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
@ -707,6 +710,9 @@ JOIN::prepare(TABLE_LIST *tables_init,
|
||||
join_list= &select_lex->top_join_list;
|
||||
union_part= unit_arg->is_union();
|
||||
|
||||
// simple check that we got usable conds
|
||||
dbug_print_item(conds);
|
||||
|
||||
if (select_lex->handle_derived(thd->lex, DT_PREPARE))
|
||||
DBUG_RETURN(1);
|
||||
|
||||
@ -822,9 +828,15 @@ JOIN::prepare(TABLE_LIST *tables_init,
|
||||
{
|
||||
nesting_map save_allow_sum_func= thd->lex->allow_sum_func;
|
||||
thd->lex->allow_sum_func|= (nesting_map)1 << select_lex->nest_level;
|
||||
if (setup_order(thd, ref_ptrs, tables_list, fields_list,
|
||||
all_fields, select_lex->order_list.first))
|
||||
DBUG_RETURN(-1);
|
||||
thd->where= "order clause";
|
||||
for (ORDER *order= select_lex->order_list.first; order; order= order->next)
|
||||
{
|
||||
/* Don't add the order items to all fields. Just resolve them to ensure
|
||||
the query is valid, we'll drop them immediately after. */
|
||||
if (find_order_in_list(thd, ref_ptrs, tables_list, order,
|
||||
fields_list, all_fields, false, false, false))
|
||||
DBUG_RETURN(-1);
|
||||
}
|
||||
thd->lex->allow_sum_func= save_allow_sum_func;
|
||||
select_lex->order_list.empty();
|
||||
}
|
||||
@ -3140,8 +3152,11 @@ bool JOIN::shrink_join_buffers(JOIN_TAB *jt,
|
||||
ulonglong curr_space,
|
||||
ulonglong needed_space)
|
||||
{
|
||||
JOIN_TAB *tab;
|
||||
JOIN_CACHE *cache;
|
||||
for (JOIN_TAB *tab= join_tab+const_tables; tab < jt; tab++)
|
||||
for (tab= first_linear_tab(this, WITHOUT_BUSH_ROOTS, WITHOUT_CONST_TABLES);
|
||||
tab != jt;
|
||||
tab= next_linear_tab(this, tab, WITHOUT_BUSH_ROOTS))
|
||||
{
|
||||
cache= tab->cache;
|
||||
if (cache)
|
||||
@ -3278,6 +3293,17 @@ void JOIN::save_explain_data(Explain_query *output, bool can_overwrite,
|
||||
bool need_tmp_table, bool need_order,
|
||||
bool distinct)
|
||||
{
|
||||
/*
|
||||
If there is SELECT in this statemet with the same number it must be the
|
||||
same SELECT
|
||||
*/
|
||||
DBUG_ASSERT(select_lex->select_number == UINT_MAX ||
|
||||
select_lex->select_number == INT_MAX ||
|
||||
!output ||
|
||||
!output->get_select(select_lex->select_number) ||
|
||||
output->get_select(select_lex->select_number)->select_lex ==
|
||||
select_lex);
|
||||
|
||||
if (select_lex->select_number != UINT_MAX &&
|
||||
select_lex->select_number != INT_MAX /* this is not a UNION's "fake select */ &&
|
||||
have_query_plan != JOIN::QEP_NOT_PRESENT_YET &&
|
||||
@ -10553,7 +10579,7 @@ void JOIN::drop_unused_derived_keys()
|
||||
tmp_tbl->use_index(tab->ref.key);
|
||||
if (tmp_tbl->s->keys)
|
||||
{
|
||||
if (tab->ref.key >= 0)
|
||||
if (tab->ref.key >= 0 && tab->ref.key < MAX_KEY)
|
||||
tab->ref.key= 0;
|
||||
else
|
||||
tmp_tbl->s->keys= 0;
|
||||
@ -12375,8 +12401,8 @@ static void update_depend_map(JOIN *join)
|
||||
uint i;
|
||||
for (i=0 ; i < ref->key_parts ; i++,item++)
|
||||
depend_map|=(*item)->used_tables();
|
||||
ref->depend_map=depend_map & ~OUTER_REF_TABLE_BIT;
|
||||
depend_map&= ~OUTER_REF_TABLE_BIT;
|
||||
ref->depend_map= depend_map;
|
||||
for (JOIN_TAB **tab=join->map2table;
|
||||
depend_map ;
|
||||
tab++,depend_map>>=1 )
|
||||
@ -12780,7 +12806,7 @@ public:
|
||||
}
|
||||
static void operator delete(void *ptr __attribute__((unused)),
|
||||
size_t size __attribute__((unused)))
|
||||
{ TRASH(ptr, size); }
|
||||
{ TRASH_FREE(ptr, size); }
|
||||
|
||||
Item *and_level;
|
||||
Item_bool_func2 *cmp_func;
|
||||
@ -15788,9 +15814,10 @@ COND *
|
||||
Item_func_isnull::remove_eq_conds(THD *thd, Item::cond_result *cond_value,
|
||||
bool top_level_arg)
|
||||
{
|
||||
if (args[0]->type() == Item::FIELD_ITEM)
|
||||
Item *real_item= args[0]->real_item();
|
||||
if (real_item->type() == Item::FIELD_ITEM)
|
||||
{
|
||||
Field *field= ((Item_field*) args[0])->field;
|
||||
Field *field= ((Item_field*) real_item)->field;
|
||||
|
||||
if (((field->type() == MYSQL_TYPE_DATE) ||
|
||||
(field->type() == MYSQL_TYPE_DATETIME)) &&
|
||||
@ -17012,7 +17039,7 @@ create_tmp_table(THD *thd, TMP_TABLE_PARAM *param, List<Item> &fields,
|
||||
field->set_notnull();
|
||||
memcpy(field->ptr,
|
||||
orig_field->ptr_in_record(orig_field->table->s->default_values),
|
||||
field->pack_length());
|
||||
field->pack_length_in_rec());
|
||||
}
|
||||
}
|
||||
|
||||
@ -22236,7 +22263,10 @@ cp_buffer_from_ref(THD *thd, TABLE *table, TABLE_REF *ref)
|
||||
SELECT list)
|
||||
@param[in,out] all_fields All select, group and order by fields
|
||||
@param[in] is_group_field True if order is a GROUP field, false if
|
||||
ORDER by field
|
||||
ORDER by field
|
||||
@param[in] add_to_all_fields If the item is to be added to all_fields and
|
||||
ref_pointer_array, this flag can be set to
|
||||
false to stop the automatic insertion.
|
||||
@param[in] from_window_spec If true then order is from a window spec
|
||||
|
||||
@retval
|
||||
@ -22246,9 +22276,11 @@ cp_buffer_from_ref(THD *thd, TABLE *table, TABLE_REF *ref)
|
||||
*/
|
||||
|
||||
static bool
|
||||
find_order_in_list(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables,
|
||||
find_order_in_list(THD *thd, Ref_ptr_array ref_pointer_array,
|
||||
TABLE_LIST *tables,
|
||||
ORDER *order, List<Item> &fields, List<Item> &all_fields,
|
||||
bool is_group_field, bool from_window_spec)
|
||||
bool is_group_field, bool add_to_all_fields,
|
||||
bool from_window_spec)
|
||||
{
|
||||
Item *order_item= *order->item; /* The item from the GROUP/ORDER caluse. */
|
||||
Item::Type order_item_type;
|
||||
@ -22385,6 +22417,9 @@ find_order_in_list(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables
|
||||
thd->is_error()))
|
||||
return TRUE; /* Wrong field. */
|
||||
|
||||
if (!add_to_all_fields)
|
||||
return FALSE;
|
||||
|
||||
uint el= all_fields.elements;
|
||||
/* Add new field to field list. */
|
||||
all_fields.push_front(order_item, thd->mem_root);
|
||||
@ -22413,7 +22448,7 @@ find_order_in_list(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables
|
||||
*/
|
||||
|
||||
int setup_order(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables,
|
||||
List<Item> &fields, List<Item> &all_fields, ORDER *order,
|
||||
List<Item> &fields, List<Item> &all_fields, ORDER *order,
|
||||
bool from_window_spec)
|
||||
{
|
||||
enum_parsing_place context_analysis_place=
|
||||
@ -22422,7 +22457,7 @@ int setup_order(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables,
|
||||
for (; order; order=order->next)
|
||||
{
|
||||
if (find_order_in_list(thd, ref_pointer_array, tables, order, fields,
|
||||
all_fields, FALSE, from_window_spec))
|
||||
all_fields, false, true, from_window_spec))
|
||||
return 1;
|
||||
if ((*order->item)->with_window_func &&
|
||||
context_analysis_place != IN_ORDER_BY)
|
||||
@ -22481,7 +22516,7 @@ setup_group(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables,
|
||||
for (ord= order; ord; ord= ord->next)
|
||||
{
|
||||
if (find_order_in_list(thd, ref_pointer_array, tables, ord, fields,
|
||||
all_fields, TRUE, from_window_spec))
|
||||
all_fields, true, true, from_window_spec))
|
||||
return 1;
|
||||
(*ord->item)->marker= UNDEF_POS; /* Mark found */
|
||||
if ((*ord->item)->with_sum_func && context_analysis_place == IN_GROUP_BY)
|
||||
@ -22806,6 +22841,7 @@ get_sort_by_table(ORDER *a,ORDER *b, List<TABLE_LIST> &tables,
|
||||
if (!map || (map & (RAND_TABLE_BIT | OUTER_REF_TABLE_BIT)))
|
||||
DBUG_RETURN(0);
|
||||
|
||||
map&= ~const_tables;
|
||||
while ((table= ti++) && !(map & table->table->map)) ;
|
||||
if (map != table->table->map)
|
||||
DBUG_RETURN(0); // More than one table
|
||||
@ -24786,6 +24822,11 @@ int JOIN::save_explain_data_intern(Explain_query *output,
|
||||
{
|
||||
explain= new (output->mem_root) Explain_select(output->mem_root,
|
||||
thd->lex->analyze_stmt);
|
||||
if (!explain)
|
||||
DBUG_RETURN(1); // EoM
|
||||
#ifndef DBUG_OFF
|
||||
explain->select_lex= select_lex;
|
||||
#endif
|
||||
join->select_lex->set_explain_type(true);
|
||||
|
||||
explain->select_id= join->select_lex->select_number;
|
||||
|
Reference in New Issue
Block a user