NDB 字段相关 mysql7.5.4

来源:互联网 发布:10月非农数据预测 编辑:程序博客网 时间:2024/05/29 06:44

字段:

通过NdbDictionary::Column 提供接口界面

class NdbDictionary::Column{NdbColumnImpl * impl;};
  1. NdbColumnImpl继承NdbDictionary::Column,基本只提供字段属性的set/get;
  2. 通过NdbColumnImpl实现底层操作;
  3. 同时column不提供对record中字段数据进行操作的操作接口。

创建

1. 在存储引擎handler接口create中调用create_ndb_column

static intcreate_ndb_column(THD *thd,                  NDBCOL &col,                  Field *field,                  HA_CREATE_INFO *create_info,                  column_format_type default_format= COLUMN_FORMAT_TYPE_DEFAULT);

根据field,create_info设置col的各成员变量,如m_type,m_autoIncrement…;
note: 此时不设置字段大小 m_attrSize

2. 之后调用 addColumn 把字段加入表中

int NdbDictionary::Table::addColumn(const Column & c){  NdbColumnImpl* col = new NdbColumnImpl;  if (col ==  NULL)  {    errno = ENOMEM;    return -1;  }  (* col) = NdbColumnImpl::getImpl(c);  if (m_impl.m_columns.push_back(col))  //  {    return -1;  }  if (m_impl.buildColumnHash())    //hash  {    return -1;  }  col->m_column_no = m_impl.m_columns.size() - 1;  return 0;}

此时设置column的m_column_no属性,

3. 之后调用createTable在data节点创建表

NdbDictionary::Dictionary::createTable()    NdbDictionaryImpl:::createTable()        NdbDictInterface::createTable()            serializeTableDesc  //计算column size            sendCreateTable    //发送给 data节点        NdbDictInterface::getTable()     //从data节点获取表            NdbDictInterface::parseTableInfo  // 获取表,字段信息

在serializeTableDesc节点序列化表信息以便网络传输。
note:在其中,通过DictTabInfo::Attribute结构表示字段信息,通过Column填充Attribute,并计算字段attribute 大小(m_attrSize element size)

 // check type and compute attribute size and array size    if (! tmpAttr.translateExtType()) {

mysql field to ndb column

由于在mysql中的一些field在ndb中不一定存在,所以字段顺序在mysql表和ndb表中可能不同,通过Ndb_table_map来映射mysql中的field与ndb中的column。在构造中通过mysqlTable->field[fieldId]->stored_in_db判断field是否有对应column,建立映射map。

m_map_by_field[fieldId] = colId;
m_map_by_col[colId] = fieldId;

索引

*note:
1. 添加进索引的索引字段不为表中字段,是不同对象。*

0 0
原创粉丝点击