InnoDBのレコード構造 ExtraDataについて(その2)

NYのJFK空港にて出発までの待ち時間中にカフェでInnoDBのソースを漁っていたら発見.

まずは、MySQL-4.0.21/innobase/include/dict0mem.h

/* Data structure for a column in a table */
struct dict_col_struct{
    hash_node_t hash;   /* hash chain node */
    ulint       ind;    /* table column position (they are numbered
                starting from 0) */
    ulint       clust_pos;/* position of the column in the
                clustered index */
    ulint       ord_part;/* count of how many times this column
                appears in ordering fields of an index */
    char*       name;   /* name */
    dtype_t     type;   /* data type */
    dict_table_t*   table;  /* back pointer to table of this column */
    ulint       aux;    /* this is used as an auxiliary variable 
                in some of the functions below */
};

#define DICT_MAX_COL_PREFIX_LEN 512

/* Data structure for a field in an index */
struct dict_field_struct{
    dict_col_t* col;        /* pointer to the table column */
    char*       name;       /* name of the column */
    ulint       order;      /* flags for ordering this field:
                    DICT_DESCEND, ... */
    ulint       prefix_len; /* 0 or the length of the column
                    prefix in a MySQL index of type, e.g.,
                    INDEX (textcol(25)); must be smaller
                    than DICT_MAX_COL_PREFIX_LEN */
};

香ばしい個所を発見.DICT_MAX_COL_PREFIX_LEN 512か.

続いて、MySQL-4.0.21/innobase/data/idata0data.c

/* We do not store externally fields which are smaller than
DICT_MAX_COL_PREFIX_LEN */

ut_a(DICT_MAX_COL_PREFIX_LEN > REC_1BYTE_OFFS_LIMIT);

if (longest < BTR_EXTERN_FIELD_REF_SIZE + 10
                + DICT_MAX_COL_PREFIX_LEN) {
    /* Cannot shorten more */

    mem_heap_free(heap);

    return(NULL);
}

はい、確定.

さらに今度はMySQL 5.1系を漁る.

MySQL 5.0.18/innobase/include/dict0mem.hにて

/* DICT_MAX_INDEX_COL_LEN is measured in bytes and is the max index column
length + 1. Starting from 4.1.6, we set it to < 3 * 256, so that one can
create a column prefix index on 255 characters of a TEXT field also in the
UTF-8 charset. In that charset, a character may take at most 3 bytes. */

#define DICT_MAX_INDEX_COL_LEN     768

はい、命中.

MySQL 4.1.6から768バイトになったと丁寧に書いてありますな.理由は1文字辺り3バイト使うキャラクタセットで255文字格納したとしても,Clustered Indexを有効とするためか.納得.いわゆるMySQL 4.1系でのマルチバイト文字コード対応の影響ですよと.

そんなワケで本件も一件落着也.あとはWikiにまとめるだけだ.

この768バイトの情報は,,,さすがにMyNA MLには流さんでいいかw いいかげんしつこいだろうし・・・.