Skip to content
Permalink
Browse files
Merge remote-tracking branch 'origin/10.1' into 10.2
  • Loading branch information
abarkov committed Nov 9, 2017
2 parents 7c85a8d + 0fdb0bd commit 6233398
Show file tree
Hide file tree
Showing 18 changed files with 191 additions and 52 deletions.
@@ -1458,6 +1458,20 @@ CONCAT(NAME_CONST('name',15),'오')
15오
SET NAMES latin1;
#
# MDEV-14116 INET6_NTOA output is set as null to varchar(39) variable
#
CREATE PROCEDURE p1()
BEGIN
DECLARE ip_full_addr varchar(39) DEFAULT "";
SELECT INET6_NTOA(UNHEX('20000000000000000000000000000000')) into ip_full_addr;
SELECT ip_full_addr;
END;
$$
CALL p1();
ip_full_addr
2000::
DROP PROCEDURE p1;
#
# Start of 10.2 tests
#
#
@@ -934,5 +934,42 @@ f2
foo
set optimizer_switch= @optimizer_switch_save;
DROP TABLE t1;
#
# MDEV-14164: Unknown column error when adding aggregate to function
# in oracle style procedure FOR loop
#
CREATE TABLE t1(id INT, val INT);
CREATE PROCEDURE p1()
BEGIN
DECLARE cur1 CURSOR FOR SELECT * FROM (
SELECT DISTINCT id FROM t1) a
WHERE NOT EXISTS (SELECT * FROM ( SELECT id FROM t1) b
WHERE a.id=b.id);
OPEN cur1;
CLOSE cur1;
OPEN cur1;
CLOSE cur1;
END;
//
CALL p1();
DROP PROCEDURE p1;
DROP TABLE t1;
CREATE TABLE t1(id INT, val INT);
CREATE PROCEDURE p1()
BEGIN
SELECT * FROM (SELECT DISTINCT id FROM t1) a
WHERE NOT a.id IN (SELECT b.id FROM t1 b);
SELECT * FROM (SELECT DISTINCT id FROM t1) a
WHERE NOT EXISTS (SELECT * FROM t1 b WHERE a.id=b.id);
END;
//
CALL p1();
id
id
CALL p1();
id
id
DROP PROCEDURE p1;
DROP TABLE t1;
# End of 10.0 tests
set optimizer_switch=default;
@@ -1103,6 +1103,23 @@ SELECT COERCIBILITY(NAME_CONST('name',15));
SELECT CONCAT(NAME_CONST('name',15),'오');
SET NAMES latin1;

--echo #
--echo # MDEV-14116 INET6_NTOA output is set as null to varchar(39) variable
--echo #

DELIMITER $$;
CREATE PROCEDURE p1()
BEGIN
DECLARE ip_full_addr varchar(39) DEFAULT "";
SELECT INET6_NTOA(UNHEX('20000000000000000000000000000000')) into ip_full_addr;
SELECT ip_full_addr;
END;
$$
DELIMITER ;$$
CALL p1();
DROP PROCEDURE p1;


--echo #
--echo # Start of 10.2 tests
--echo #
@@ -786,6 +786,46 @@ set optimizer_switch= @optimizer_switch_save;

DROP TABLE t1;

--echo #
--echo # MDEV-14164: Unknown column error when adding aggregate to function
--echo # in oracle style procedure FOR loop
--echo #

CREATE TABLE t1(id INT, val INT);
DELIMITER //;
CREATE PROCEDURE p1()
BEGIN
DECLARE cur1 CURSOR FOR SELECT * FROM (
SELECT DISTINCT id FROM t1) a
WHERE NOT EXISTS (SELECT * FROM ( SELECT id FROM t1) b
WHERE a.id=b.id);
OPEN cur1;
CLOSE cur1;
OPEN cur1;
CLOSE cur1;
END;
//
DELIMITER ;//
CALL p1();
DROP PROCEDURE p1;
DROP TABLE t1;

CREATE TABLE t1(id INT, val INT);
DELIMITER //;
CREATE PROCEDURE p1()
BEGIN
SELECT * FROM (SELECT DISTINCT id FROM t1) a
WHERE NOT a.id IN (SELECT b.id FROM t1 b);
SELECT * FROM (SELECT DISTINCT id FROM t1) a
WHERE NOT EXISTS (SELECT * FROM t1 b WHERE a.id=b.id);
END;
//
DELIMITER ;//
CALL p1();
CALL p1();
DROP PROCEDURE p1;
DROP TABLE t1;

--echo # End of 10.0 tests

#restore defaults
@@ -2881,7 +2881,8 @@ table_map Item_field::all_used_tables() const
return (get_depended_from() ? OUTER_REF_TABLE_BIT : field->table->map);
}

void Item_field::fix_after_pullout(st_select_lex *new_parent, Item **ref)
void Item_field::fix_after_pullout(st_select_lex *new_parent, Item **ref,
bool merge)
{
if (new_parent == get_depended_from())
depended_from= NULL;
@@ -2925,6 +2926,19 @@ void Item_field::fix_after_pullout(st_select_lex *new_parent, Item **ref)
if (!need_change)
return;

if (!merge)
{
/*
It is transformation without merge.
This field was "outer" for the inner SELECT where it was taken and
moved up.
"Outer" fields uses normal SELECT_LEX context of upper SELECTs for
name resolution, so we can switch everything to it safely.
*/
this->context= &new_parent->context;
return;
}

Name_resolution_context *ctx= new Name_resolution_context();
if (context->select_lex == new_parent)
{
@@ -8596,18 +8610,19 @@ bool Item_outer_ref::fix_fields(THD *thd, Item **reference)


void Item_outer_ref::fix_after_pullout(st_select_lex *new_parent,
Item **ref_arg)
Item **ref_arg, bool merge)
{
if (get_depended_from() == new_parent)
{
*ref_arg= outer_ref;
(*ref_arg)->fix_after_pullout(new_parent, ref_arg);
(*ref_arg)->fix_after_pullout(new_parent, ref_arg, merge);
}
}

void Item_ref::fix_after_pullout(st_select_lex *new_parent, Item **refptr)
void Item_ref::fix_after_pullout(st_select_lex *new_parent, Item **refptr,
bool merge)
{
(*ref)->fix_after_pullout(new_parent, ref);
(*ref)->fix_after_pullout(new_parent, ref, merge);
if (get_depended_from() == new_parent)
depended_from= NULL;
}
@@ -775,7 +775,9 @@ class Item: public Value_source,
Fix after some tables has been pulled out. Basically re-calculate all
attributes that are dependent on the tables.
*/
virtual void fix_after_pullout(st_select_lex *new_parent, Item **ref) {};
virtual void fix_after_pullout(st_select_lex *new_parent, Item **ref,
bool merge)
{};

/*
This method should be used in case where we are sure that we do not need
@@ -2546,7 +2548,7 @@ class Item_field :public Item_ident
bool send(Protocol *protocol, String *str_arg);
void reset_field(Field *f);
bool fix_fields(THD *, Item **);
void fix_after_pullout(st_select_lex *new_parent, Item **ref);
void fix_after_pullout(st_select_lex *new_parent, Item **ref, bool merge);
void make_field(THD *thd, Send_field *tmp_field);
int save_in_field(Field *field,bool no_conversions);
void save_org_in_field(Field *field, fast_field_copier optimizer_data);
@@ -4257,7 +4259,7 @@ class Item_ref :public Item_ident
bool send(Protocol *prot, String *tmp);
void make_field(THD *thd, Send_field *field);
bool fix_fields(THD *, Item **);
void fix_after_pullout(st_select_lex *new_parent, Item **ref);
void fix_after_pullout(st_select_lex *new_parent, Item **ref, bool merge);
int save_in_field(Field *field, bool no_conversions);
void save_org_in_field(Field *field, fast_field_copier optimizer_data);
fast_field_copier setup_fast_field_copier(Field *field)
@@ -4559,9 +4561,9 @@ class Item_cache_wrapper :public Item_result_field
Item *it= ((Item *) item)->real_item();
return orig_item->eq(it, binary_cmp);
}
void fix_after_pullout(st_select_lex *new_parent, Item **refptr)
void fix_after_pullout(st_select_lex *new_parent, Item **refptr, bool merge)
{
orig_item->fix_after_pullout(new_parent, &orig_item);
orig_item->fix_after_pullout(new_parent, &orig_item, merge);
}
int save_in_field(Field *to, bool no_conversions);
enum Item_result result_type () const { return orig_item->result_type(); }
@@ -4831,7 +4833,7 @@ class Item_outer_ref :public Item_direct_ref
outer_ref->save_org_in_field(result_field, NULL);
}
bool fix_fields(THD *, Item **);
void fix_after_pullout(st_select_lex *new_parent, Item **ref);
void fix_after_pullout(st_select_lex *new_parent, Item **ref, bool merge);
table_map used_tables() const
{
return (*ref)->const_item() ? 0 : OUTER_REF_TABLE_BIT;
@@ -1256,10 +1256,11 @@ bool Item_in_optimizer::is_top_level_item()
}


void Item_in_optimizer::fix_after_pullout(st_select_lex *new_parent, Item **ref)
void Item_in_optimizer::fix_after_pullout(st_select_lex *new_parent,
Item **ref, bool merge)
{
/* This will re-calculate attributes of our Item_in_subselect: */
Item_bool_func::fix_after_pullout(new_parent, ref);
Item_bool_func::fix_after_pullout(new_parent, ref, merge);

/* Then, re-calculate not_null_tables_cache: */
eval_not_null_tables(NULL);
@@ -2086,10 +2087,11 @@ bool Item_func_between::count_sargable_conds(void *arg)
}


void Item_func_between::fix_after_pullout(st_select_lex *new_parent, Item **ref)
void Item_func_between::fix_after_pullout(st_select_lex *new_parent,
Item **ref, bool merge)
{
/* This will re-calculate attributes of the arguments */
Item_func_opt_neg::fix_after_pullout(new_parent, ref);
Item_func_opt_neg::fix_after_pullout(new_parent, ref, merge);
/* Then, re-calculate not_null_tables_cache according to our special rules */
eval_not_null_tables(NULL);
}
@@ -2430,10 +2432,11 @@ Item_func_if::eval_not_null_tables(void *opt_arg)
}


void Item_func_if::fix_after_pullout(st_select_lex *new_parent, Item **ref)
void Item_func_if::fix_after_pullout(st_select_lex *new_parent,
Item **ref, bool merge)
{
/* This will re-calculate attributes of the arguments */
Item_func::fix_after_pullout(new_parent, ref);
Item_func::fix_after_pullout(new_parent, ref, merge);
/* Then, re-calculate not_null_tables_cache according to our special rules */
eval_not_null_tables(NULL);
}
@@ -4164,10 +4167,11 @@ Item_func_in::eval_not_null_tables(void *opt_arg)
}


void Item_func_in::fix_after_pullout(st_select_lex *new_parent, Item **ref)
void Item_func_in::fix_after_pullout(st_select_lex *new_parent, Item **ref,
bool merge)
{
/* This will re-calculate attributes of the arguments */
Item_func_opt_neg::fix_after_pullout(new_parent, ref);
Item_func_opt_neg::fix_after_pullout(new_parent, ref, merge);
/* Then, re-calculate not_null_tables_cache according to our special rules */
eval_not_null_tables(NULL);
}
@@ -4689,7 +4693,8 @@ Item_cond::eval_not_null_tables(void *opt_arg)
}


void Item_cond::fix_after_pullout(st_select_lex *new_parent, Item **ref)
void Item_cond::fix_after_pullout(st_select_lex *new_parent, Item **ref,
bool merge)
{
List_iterator<Item> li(list);
Item *item;
@@ -4702,7 +4707,7 @@ void Item_cond::fix_after_pullout(st_select_lex *new_parent, Item **ref)
while ((item=li++))
{
table_map tmp_table_map;
item->fix_after_pullout(new_parent, li.ref());
item->fix_after_pullout(new_parent, li.ref(), merge);
item= *li.ref();
used_tables_and_const_cache_join(item);

@@ -359,7 +359,7 @@ class Item_in_optimizer: public Item_bool_func
virtual void get_cache_parameters(List<Item> &parameters);
bool is_top_level_item();
bool eval_not_null_tables(void *opt_arg);
void fix_after_pullout(st_select_lex *new_parent, Item **ref);
void fix_after_pullout(st_select_lex *new_parent, Item **ref, bool merge);
bool invisible_mode();
void reset_cache() { cache= NULL; }
Item *get_copy(THD *thd, MEM_ROOT *mem_root)
@@ -879,7 +879,7 @@ class Item_func_between :public Item_func_opt_neg
void fix_length_and_dec();
virtual void print(String *str, enum_query_type query_type);
bool eval_not_null_tables(void *opt_arg);
void fix_after_pullout(st_select_lex *new_parent, Item **ref);
void fix_after_pullout(st_select_lex *new_parent, Item **ref, bool merge);
bool count_sargable_conds(void *arg);
void add_key_fields(JOIN *join, KEY_FIELD **key_fields,
uint *and_level, table_map usable_tables,
@@ -1045,7 +1045,7 @@ class Item_func_if :public Item_func_case_abbreviation2
}
const char *func_name() const { return "if"; }
bool eval_not_null_tables(void *opt_arg);
void fix_after_pullout(st_select_lex *new_parent, Item **ref);
void fix_after_pullout(st_select_lex *new_parent, Item **ref, bool merge);
Item *get_copy(THD *thd, MEM_ROOT *mem_root)
{ return get_item_copy<Item_func_if>(thd, mem_root, this); }
private:
@@ -1691,7 +1691,7 @@ class Item_func_in :public Item_func_opt_neg
const char *func_name() const { return "in"; }
enum precedence precedence() const { return CMP_PRECEDENCE; }
bool eval_not_null_tables(void *opt_arg);
void fix_after_pullout(st_select_lex *new_parent, Item **ref);
void fix_after_pullout(st_select_lex *new_parent, Item **ref, bool merge);
bool count_sargable_conds(void *arg);
Item *get_copy(THD *thd, MEM_ROOT *mem_root)
{ return get_item_copy<Item_func_in>(thd, mem_root, this); }
@@ -2196,7 +2196,7 @@ class Item_cond :public Item_bool_func
list.append(nlist);
}
bool fix_fields(THD *, Item **ref);
void fix_after_pullout(st_select_lex *new_parent, Item **ref);
void fix_after_pullout(st_select_lex *new_parent, Item **ref, bool merge);

enum Type type() const { return COND_ITEM; }
List<Item>* argument_list() { return &list; }
@@ -273,7 +273,8 @@ Item_func::eval_not_null_tables(void *opt_arg)
}


void Item_func::fix_after_pullout(st_select_lex *new_parent, Item **ref)
void Item_func::fix_after_pullout(st_select_lex *new_parent, Item **ref,
bool merge)
{
Item **arg,**arg_end;

@@ -284,7 +285,7 @@ void Item_func::fix_after_pullout(st_select_lex *new_parent, Item **ref)
{
for (arg=args, arg_end=args+arg_count; arg != arg_end ; arg++)
{
(*arg)->fix_after_pullout(new_parent, arg);
(*arg)->fix_after_pullout(new_parent, arg, merge);
Item *item= *arg;

used_tables_and_const_cache_join(item);
@@ -126,7 +126,7 @@ class Item_func :public Item_func_or_sum
Item_func_or_sum::cleanup();
used_tables_and_const_cache_init();
}
void fix_after_pullout(st_select_lex *new_parent, Item **ref);
void fix_after_pullout(st_select_lex *new_parent, Item **ref, bool merge);
void quick_fix_field();
table_map not_null_tables() const;
void update_used_tables()

0 comments on commit 6233398

Please sign in to comment.