Hi, Aleksey,

Despite the email subject, this is a combined diff of three commits,

  git diff 071c20fd23b2 2fecd944d6dc

On Apr 04, Aleksey Midenkov wrote:
> diff --git a/sql/field.cc b/sql/field.cc
> index 8b96c473ab6..d6be66cf399 100644
> --- a/sql/field.cc
> +++ b/sql/field.cc
> @@ -2516,7 +2521,7 @@ Field *Field::new_key_field(MEM_ROOT *root, TABLE 
> *new_table,
>                              uchar *new_null_ptr, uint new_null_bit)
>  {
>    Field *tmp;
> -  if ((tmp= make_new_field(root, new_table, table == new_table)))
> +  if ((tmp= make_new_field({root, new_table, table == new_table})))

it's a creative trick, I admit, but let's not do it.
looks very weird, we don't have it anywhere else.
it's not needed either, because you don't need to pass down a new
argument, see below

>    {
>      tmp->ptr=      new_ptr;
>      tmp->null_ptr= new_null_ptr;
> @@ -8278,12 +8281,28 @@ int Field_varstring::cmp_binary(const uchar *a_ptr, 
> const uchar *b_ptr,
>  }
>  
>  
> -Field *Field_varstring::make_new_field(MEM_ROOT *root, TABLE *new_table,
> -                                       bool keep_type)
> +Field *Field_varstring::make_new_field(make_new_field_args args)
>  {
> -  Field_varstring *res= (Field_varstring*) Field::make_new_field(root,
> -                                                                 new_table,
> -                                                                 keep_type);
> +  Field_varstring *res= (Field_varstring*) Field::make_new_field(args);
> +  if (res)
> +    res->length_bytes= length_bytes;
> +  return res;
> +}
> +
> +
> +Field *Field_varstring_compressed::make_new_field(make_new_field_args args)
> +{
> +  Field_varstring *res;
> +  if (args.tmp_field)

tmp field is a field of a tmp table. Unfortunately,
INTERNAL_TMP_TABLE value of new_table->s->tmp_table is very overloaded
and no longer means internal temporary table anymore. I think we'll
need to fix it someday.

But a smaller fix for today could be, like


@@ -1113,6 +1113,11 @@ struct TABLE_SHARE
     return (tmp_table == SYSTEM_TMP_TABLE) ? 0 : table_map_id;
   }
 
+  bool is_optimizer_tmp_table()
+  {
+    return tmp_table == INTERNAL_TMP_TABLE && !db.length && table_name.length;
+  }
+

using the fact that optimizer tmp tables are all named "(temporary)"
or something like that and have no db.

Using this one can do a fix, like
@@ -8281,11 +8279,23 @@ int Field_varstring::cmp_binary(const uchar *a_ptr, con>
 Field *Field_varstring::make_new_field(MEM_ROOT *root, TABLE *new_table,
                                        bool keep_type)
 {
-  Field_varstring *res= (Field_varstring*) Field::make_new_field(root,
+  Field_varstring *res;
+  if (new_table->s->optimizer_tmp_table())
+  {
+    res= new (root) Field_varstring(ptr, field_length, length_bytes, null_ptr,
+                                    null_bit, Field::NONE, &field_name,
+                                    new_table->s, charset());
+    if (res)
+      res->init_for_make_new_field(new_table, orig_table);
+  }
+  else
+  {
+    res= (Field_varstring*) Field::make_new_field(root,
                                                   new_table,
                                                   keep_type);
     if (res)
       res->length_bytes= length_bytes;
+  }
   return res;
 }
 

> +  {
> +    /* Compressed fields can't have keys (see 
> Field_varstring_compressed::key_cmp()). */
> +    res= new (args.root) Field_varstring(*this);
> +    res->init_new_field(args);
> +    /* See Column_definition::create_length_to_internal_length_string() */
> +    res->field_length--;
> +  }
> +  else
> +    res= (Field_varstring*) Field::make_new_field(args);
>    if (res)
>      res->length_bytes= length_bytes;
>    return res;

Regards,
Sergei
Chief Architect, MariaDB Server
and secur...@mariadb.org
_______________________________________________
developers mailing list -- developers@lists.mariadb.org
To unsubscribe send an email to developers-le...@lists.mariadb.org

Reply via email to