summaryrefslogtreecommitdiff
path: root/sql/item.cc
diff options
context:
space:
mode:
authormhansson/martin@linux-st28.site <>2007-12-11 20:15:03 +0100
committermhansson/martin@linux-st28.site <>2007-12-11 20:15:03 +0100
commit867a78654946c7c7ebed430b2b8437e837a0455d (patch)
tree9615a0eaca93ca19b59f1a93f0a77b7875a88468 /sql/item.cc
parent7f67efccef94449ef6c797583a2695b27a9b7376 (diff)
downloadmariadb-git-867a78654946c7c7ebed430b2b8437e837a0455d.tar.gz
Bug#32848: Data type conversion bug in union subselects in MySQL 5.0.38
There were two problems when inferring the correct field types resulting from UNION queries. - If the type is NULL for all corresponding fields in the UNION, the resulting type would be NULL, while the type is BINARY(0) if there is just a single SELECT NULL. - If one SELECT in the UNION uses a subselect, a temporary table is created to represent the subselect, and the result type defaults to a STRING type, hiding the fact that the type was unknown(just a NULL value). Fixed by remembering whenever a field was created from a NULL value and pass type NULL to the type coercion if that is the case, and creating a string field as result of UNION only if the type would otherwise be NULL.
Diffstat (limited to 'sql/item.cc')
-rw-r--r--sql/item.cc4
1 files changed, 4 insertions, 0 deletions
diff --git a/sql/item.cc b/sql/item.cc
index 3177c0fb1e8..5df0f441619 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -6569,6 +6569,8 @@ enum_field_types Item_type_holder::get_real_type(Item *item)
*/
Field *field= ((Item_field *) item)->field;
enum_field_types type= field->real_type();
+ if (field->is_created_from_null_item)
+ return MYSQL_TYPE_NULL;
/* work around about varchar type field detection */
if (type == MYSQL_TYPE_STRING && field->type() == MYSQL_TYPE_VAR_STRING)
return MYSQL_TYPE_VAR_STRING;
@@ -6820,6 +6822,8 @@ Field *Item_type_holder::make_field_by_type(TABLE *table)
Field::NONE, name,
table, get_set_pack_length(enum_set_typelib->count),
enum_set_typelib, collation.collation);
+ case MYSQL_TYPE_NULL:
+ return make_string_field(table);
default:
break;
}