MCPcopy Create free account
hub / github.com/MariaDB/server / add_tmp_key

Method add_tmp_key

sql/table.cc:8744–8815  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8742*/
8743
8744bool TABLE::add_tmp_key(uint key, uint key_parts,
8745 uint (*next_field_no) (uchar *), uchar *arg,
8746 bool unique)
8747{
8748 DBUG_ASSERT(key < max_keys);
8749
8750 char buf[NAME_CHAR_LEN];
8751 KEY *keyinfo= key_info + key;
8752 KEY_PART_INFO *key_part_info;
8753 Field **reg_field;
8754 uint i;
8755 bool key_start= TRUE;
8756
8757 keyinfo->name.length= snprintf(buf, sizeof(buf), "key%i", key);
8758
8759 if (!multi_alloc_root(&mem_root,
8760 &key_part_info, sizeof(KEY_PART_INFO)*key_parts,
8761 &keyinfo->rec_per_key,
8762 sizeof(key_info->rec_per_key) * key_parts,
8763 &keyinfo->name.str, keyinfo->name.length+1,
8764 NullS))
8765 return TRUE;
8766 keyinfo->key_part= key_part_info;
8767 strmake((char*) keyinfo->name.str, buf, keyinfo->name.length);
8768
8769 keyinfo->usable_key_parts= keyinfo->user_defined_key_parts= key_parts;
8770 keyinfo->ext_key_parts= keyinfo->user_defined_key_parts;
8771 keyinfo->key_length=0;
8772 keyinfo->algorithm= HA_KEY_ALG_UNDEF;
8773 keyinfo->flags= HA_GENERATED_KEY;
8774 keyinfo->ext_key_flags= keyinfo->flags;
8775 keyinfo->is_statistics_from_stat_tables= FALSE;
8776 if (unique)
8777 keyinfo->flags|= HA_NOSAME;
8778 bzero(keyinfo->rec_per_key, sizeof(ulong)*key_parts);
8779 keyinfo->read_stats= NULL;
8780 keyinfo->collected_stats= NULL;
8781 keyinfo->table= this;
8782 keyinfo->all_nulls_key_parts= 0;
8783 keyinfo->stat_storage_length= 0;
8784
8785 for (i= 0; i < key_parts; i++)
8786 {
8787 uint fld_idx= next_field_no(arg);
8788 reg_field= field + fld_idx;
8789 if (key_start)
8790 (*reg_field)->key_start.set_bit(key);
8791 (*reg_field)->part_of_key.set_bit(key);
8792 create_key_part_by_field(key_part_info, *reg_field, fld_idx+1);
8793 keyinfo->key_length += key_part_info->store_length;
8794 (*reg_field)->flags|= PART_KEY_FLAG;
8795 key_start= FALSE;
8796 key_part_info++;
8797 }
8798 /*
8799 We have to cache index_flags here as the table may be used by the
8800 optimizer before it's opened.
8801 */

Callers 2

initMethod · 0.80

Calls 5

multi_alloc_rootFunction · 0.85
strmakeFunction · 0.85
set_bitMethod · 0.45
index_flagsMethod · 0.45

Tested by

no test coverage detected