@@ -2582,51 +2582,35 @@ int mysql_add_invisible_field(THD *thd, List<Create_field> * field_list,
2582
2582
return 0 ;
2583
2583
}
2584
2584
2585
- #define LONG_HASH_FIELD_NAME_LENGTH 30
2586
- static inline void make_long_hash_field_name (LEX_CSTRING *buf, uint num)
2585
+ #define INTERNAL_FIELD_NAME_LENGTH 30
2586
+
2587
+ static Lex_ident_column make_internal_field_name (THD *thd, const char *prefix,
2588
+ List<Create_field> *create_list)
2587
2589
{
2588
- buf->length = my_snprintf ((char *)buf->str ,
2589
- LONG_HASH_FIELD_NAME_LENGTH, " DB_ROW_HASH_%u" , num);
2590
+ char buf[INTERNAL_FIELD_NAME_LENGTH]= {0 };
2591
+ LEX_CSTRING name= { buf, 0 };
2592
+ bool dup_found= true ;
2593
+ for (uint num= 1 ; dup_found; num++)
2594
+ {
2595
+ name.length = my_snprintf (buf, sizeof (buf), " %s%u" , prefix, num);
2596
+ for (auto &dup_field : *create_list)
2597
+ if ((dup_found= dup_field.field_name .streq (name)))
2598
+ break ;
2599
+ }
2600
+ return Lex_ident_column (thd->strmake_lex_cstring (name));
2590
2601
}
2591
2602
2592
- /* *
2593
- Add fully invisible hash field to table in case of long
2594
- unique column
2595
- @param thd Thread Context.
2596
- @param create_list List of table fields.
2597
- @param key_info current long unique key info
2598
- */
2599
- static Create_field *add_hash_field (THD *thd, List<Create_field> *create_list,
2600
- KEY *key_info)
2603
+ static Create_field *add_internal_field (THD *thd, Type_handler *type_handler,
2604
+ uint flags, const char *prefix,
2605
+ List<Create_field> *create_list)
2601
2606
{
2602
- List_iterator<Create_field> it (*create_list);
2603
- Create_field *dup_field, *cf= new (thd->mem_root ) Create_field ();
2604
- cf->flags |= UNSIGNED_FLAG | LONG_UNIQUE_HASH_FIELD;
2605
- cf->decimals = 0 ;
2606
- cf->length = cf->char_length = cf->pack_length = HA_HASH_FIELD_LENGTH;
2607
+ class Column_derived_attributes dat (&my_charset_bin);
2608
+ Create_field *cf= new (thd->mem_root ) Create_field ();
2609
+ cf->flags |= flags | NOT_NULL_FLAG;
2607
2610
cf->invisible = INVISIBLE_FULL;
2608
- cf->pack_flag |= FIELDFLAG_MAYBE_NULL;
2609
- cf->vcol_info = new (thd->mem_root ) Virtual_column_info ();
2610
- cf->vcol_info ->set_vcol_type (VCOL_GENERATED_VIRTUAL);
2611
- uint num= 1 ;
2612
- Lex_ident_column field_name;
2613
- field_name.str = (char *)thd->alloc (LONG_HASH_FIELD_NAME_LENGTH);
2614
- make_long_hash_field_name (&field_name, num);
2615
- /*
2616
- Check for collisions
2617
- */
2618
- while ((dup_field= it++))
2619
- {
2620
- if (dup_field->field_name .streq (field_name))
2621
- {
2622
- num++;
2623
- make_long_hash_field_name (&field_name, num);
2624
- it.rewind ();
2625
- }
2626
- }
2627
- cf->field_name = Lex_ident_column (field_name);
2628
- cf->set_handler (&type_handler_slonglong);
2629
- key_info->algorithm = HA_KEY_ALG_LONG_HASH;
2611
+ cf->field_name = make_internal_field_name (thd, prefix, create_list);
2612
+ cf->set_handler (type_handler);
2613
+ cf->prepare_stage1 (thd, thd->mem_root , COLUMN_DEFINITION_TABLE_FIELD, &dat);
2630
2614
create_list->push_back (cf,thd->mem_root );
2631
2615
return cf;
2632
2616
}
@@ -3523,19 +3507,24 @@ mysql_prepare_create_table_finalize(THD *thd, HA_CREATE_INFO *create_info,
3523
3507
!(file->ha_table_flags () & HA_CAN_HASH_KEYS ) &&
3524
3508
file->ha_table_flags () & HA_CAN_VIRTUAL_COLUMNS))
3525
3509
{
3526
- Create_field *hash_fld= add_hash_field (thd, &alter_info->create_list ,
3527
- key_info);
3510
+ Create_field *hash_fld=
3511
+ add_internal_field (thd, &type_handler_ulonglong,
3512
+ UNSIGNED_FLAG | LONG_UNIQUE_HASH_FIELD,
3513
+ " DB_ROW_HASH_" , &alter_info->create_list );
3528
3514
if (!hash_fld)
3529
3515
DBUG_RETURN (TRUE );
3516
+ key_info->algorithm = HA_KEY_ALG_LONG_HASH;
3530
3517
hash_fld->offset = record_offset;
3531
3518
hash_fld->charset = create_info->default_table_charset ;
3519
+ hash_fld->vcol_info = new (thd->mem_root ) Virtual_column_info ();
3520
+ hash_fld->vcol_info ->set_vcol_type (VCOL_GENERATED_VIRTUAL);
3521
+ DBUG_ASSERT (hash_fld->pack_length == HA_HASH_FIELD_LENGTH);
3532
3522
record_offset+= hash_fld->pack_length ;
3533
3523
if (key_info->flags & HA_NULL_PART_KEY)
3534
- null_fields++;
3535
- else
3536
3524
{
3537
- hash_fld->flags |= NOT_NULL_FLAG;
3538
- hash_fld->pack_flag &= ~FIELDFLAG_MAYBE_NULL;
3525
+ null_fields++;
3526
+ hash_fld->flags &= ~NOT_NULL_FLAG;
3527
+ hash_fld->pack_flag |= FIELDFLAG_MAYBE_NULL;
3539
3528
}
3540
3529
}
3541
3530
if (validate_comment_length (thd, &key->key_create_info .comment ,
0 commit comments