INNODB 字段相关

字段

结构

innodb 使用dict_col_t表示字段属性,用dfield_t在进行sql操作时表示row record中的字段。

dict_col_t
/** Data structure for a column in a table */
struct dict_col_t{
    /*----------------------*/
    /** The following are copied from dtype_t,
    so that all bit-fields can be packed tightly. */
    /* @{ */
    unsigned    prtype:32;  /*!< precise type; MySQL data
                    type, charset code, flags to
                    indicate nullability,
                    signedness, whether this is a
                    binary string, whether this is
                    a true VARCHAR where MySQL
                    uses 2 bytes to store the length */
    unsigned    mtype:8;    /*!< main data type */

    /* the remaining fields do not affect alphabetical ordering: */

    unsigned    len:16;     /*!< length; for MySQL data this
                    is field->pack_length(),
                    except that for a >= 5.0.3
                    type true VARCHAR this is the
                    maximum byte length of the
                    string data (in addition to
                    the string, MySQL uses 1 or 2
                    bytes to store the string length) */

    unsigned    mbminmaxlen:5;  /*!< minimum and maximum length of a
                    character, in bytes;
                    DATA_MBMINMAXLEN(mbminlen,mbmaxlen);
                    mbminlen=DATA_MBMINLEN(mbminmaxlen);
                    mbmaxlen=DATA_MBMINLEN(mbminmaxlen) */
    /*----------------------*/
    /* End of definitions copied from dtype_t */
    /* @} */

    unsigned    ind:10;     /*!< table column position
                    (starting from 0) */
    unsigned    ord_part:1; /*!< nonzero if this column
                    appears in the ordering fields
                    of an index */
    unsigned    max_prefix:12;  /*!< maximum index prefix length on
                    this column. Our current max limit is
                    3072 for Barracuda table */
};
dfield_t
/** Structure for an SQL data field */
struct dfield_t{
    void*       data;   /*!< pointer to data */
    unsigned    ext:1;  /*!< TRUE=externally stored, FALSE=local */
    unsigned    spatial_status:2;
                /*!< spatial status of externally stored field
                in undo log for purge */
    unsigned    len;    /*!< data length; UNIV_SQL_NULL if SQL null */
    dtype_t     type;   /*!< type of data */

    /** Create a deep copy of this object
    @param[in]  heap    the memory heap in which the clone will be
                created.
    @return the cloned object. */
    dfield_t* clone(mem_heap_t* heap);
};

建表时创建字段

在创建表时,先依据字段数分配内存,再填充各字段。

dict_mem_table_create
    mem_heap_create  //分配内存
    mem_heap_alloc(heap, table->n_cols *                  sizeof(dict_col_t)));   //设置字段结构内存
    mem_heap_alloc(heap, n_v_cols * sizeof(*table->v_cols)));           //设置虚字段结构内存

dict_mem_table_add_col
    dict_add_col_name
    dict_table_get_nth_col  //获取指向字段所在内存位置指针
    dict_mem_fill_column_struct //根据指针填充字段信息
or
dict_mem_table_add_v_col
if(stored)
dict_mem_table_add_s_col
.....
....
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

紫无之紫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值