summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <sergefp@mysql.com>2004-12-13 20:06:06 +0300
committerunknown <sergefp@mysql.com>2004-12-13 20:06:06 +0300
commit6d7fe8520a938d92a6a7b0e569e8f56d926936ac (patch)
tree64511cf791534c9423364cdf49dc849d5c6dc032 /sql
parent35217aeade288b054c95d4b5bd4dfb9674e2af08 (diff)
downloadmariadb-git-6d7fe8520a938d92a6a7b0e569e8f56d926936ac.tar.gz
Merging fix for BUG#6976 from 4.0 to 4.1
The problem in 4.1 was the same as in 4.0 - fix_fields() not called for created Item_ref. The fix is similar too - initialize Item_refs in ctor (but don't interfere with cases when Item_ref is used by subselects). sql/item.cc: Fix for BUG#6976 ported from 4.0 sql/item_cmpfunc.cc: Fix for BUG#6976 ported from 4.0 sql/item_func.cc: Fix for BUG#6976 ported from 4.0 sql/item_row.cc: Fix for BUG#6976 ported from 4.0 sql/item_strfunc.cc: Fix for BUG#6976 ported from 4.0
Diffstat (limited to 'sql')
-rw-r--r--sql/item.cc4
-rw-r--r--sql/item.h21
-rw-r--r--sql/item_cmpfunc.cc3
-rw-r--r--sql/item_func.cc2
-rw-r--r--sql/item_row.cc3
-rw-r--r--sql/item_strfunc.cc2
6 files changed, 29 insertions, 6 deletions
diff --git a/sql/item.cc b/sql/item.cc
index 31c35e87cd4..85e200920f1 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -1488,9 +1488,9 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
"forward reference in item list");
return -1;
}
-
Item_ref *rf= new Item_ref(last->ref_pointer_array + counter,
- (char *)table_name, (char *)field_name);
+ (char *)table_name, (char *)field_name,
+ this);
if (!rf)
return 1;
thd->change_item_tree(ref, rf);
diff --git a/sql/item.h b/sql/item.h
index 3c4f80e3857..cf697f59727 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -835,6 +835,26 @@ public:
:Item_ident(db_par, table_name_par, field_name_par), ref(0) {}
Item_ref(Item **item, const char *table_name_par, const char *field_name_par)
:Item_ident(NullS, table_name_par, field_name_par), ref(item) {}
+
+ /*
+ This constructor is used when processing GROUP BY and referred Item is
+ available. We set all properties here because fix_fields() will not be
+ called for the created Item_ref. (see BUG#6976)
+ TODO check if we could get rid of *_name_par parameters and if we need to
+ perform similar initialization for other ctors.
+ TODO we probably fix a superset of problems like in BUG#6658. Check this
+ with Bar, and if we have a more broader set of problems like this.
+ */
+ Item_ref(Item **item, const char *table_name_par,
+ const char *field_name_par, Item *src)
+ : Item_ident(NullS, table_name_par, field_name_par), ref(item)
+ {
+ collation.set(src->collation);
+ max_length= src->max_length;
+ decimals= src->decimals;
+ with_sum_func= src->with_sum_func;
+ maybe_null= src->maybe_null;
+ }
/* Constructor need to process subselect with temporary tables (see Item) */
Item_ref(THD *thd, Item_ref *item) :Item_ident(thd, item), ref(item->ref) {}
enum Type type() const { return REF_ITEM; }
@@ -890,6 +910,7 @@ public:
};
class Item_in_subselect;
+
class Item_ref_null_helper: public Item_ref
{
protected:
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index 51212418b09..b225889d916 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -2022,7 +2022,8 @@ void Item_cond::split_sum_func(THD *thd, Item **ref_pointer_array,
{
Item **ref= li.ref();
uint el= fields.elements;
- Item *new_item= new Item_ref(ref_pointer_array + el, 0, item->name);
+ Item *new_item= new Item_ref(ref_pointer_array + el, 0, item->name,
+ item);
fields.push_front(item);
ref_pointer_array[el]= item;
thd->change_item_tree(ref, new_item);
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 98b204d1809..af53a771720 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -349,7 +349,7 @@ void Item_func::split_sum_func(THD *thd, Item **ref_pointer_array,
else if (item->used_tables() || item->type() == SUM_FUNC_ITEM)
{
uint el= fields.elements;
- Item *new_item= new Item_ref(ref_pointer_array + el, 0, item->name);
+ Item *new_item= new Item_ref(ref_pointer_array + el, 0, item->name, item);
new_item->collation.set(item->collation);
fields.push_front(item);
ref_pointer_array[el]= item;
diff --git a/sql/item_row.cc b/sql/item_row.cc
index 289efe45300..b65b0b7b608 100644
--- a/sql/item_row.cc
+++ b/sql/item_row.cc
@@ -95,7 +95,8 @@ void Item_row::split_sum_func(THD *thd, Item **ref_pointer_array,
else if ((*arg)->used_tables() || (*arg)->type() == SUM_FUNC_ITEM)
{
uint el= fields.elements;
- Item *new_item= new Item_ref(ref_pointer_array + el, 0, (*arg)->name);
+ Item *new_item= new Item_ref(ref_pointer_array + el, 0, (*arg)->name,
+ *arg);
fields.push_front(*arg);
ref_pointer_array[el]= *arg;
thd->change_item_tree(arg, new_item);
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index aaeeb9d8bb8..82cbd1fed72 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -1748,7 +1748,7 @@ void Item_func_make_set::split_sum_func(THD *thd, Item **ref_pointer_array,
else if (item->used_tables() || item->type() == SUM_FUNC_ITEM)
{
uint el= fields.elements;
- Item *new_item= new Item_ref(ref_pointer_array + el, 0, item->name);
+ Item *new_item= new Item_ref(ref_pointer_array + el, 0, item->name,item);
fields.push_front(item);
ref_pointer_array[el]= item;
thd->change_item_tree(&item, new_item);