MySQL社区

 找回密码
 注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

搜索
查看: 4797|回复: 2
打印 上一主题 下一主题

mysql 表 结构包括那些成员

[复制链接]
跳转到指定楼层
1#
发表于 2008-8-15 19:13:33 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
原以为一个表包括的东西很少的,就只有表的名字,类型,字段的数目,字段的类型,字段的排列,字符集,key的数目,每条字段的数目。。。
近来在研究myisam是如何处理blob的时候,看了一下Table.h这个文件的代码,发现,原来一个表是如此复杂的!
  由于我对mysql的表了解不深,所以看了代码还是有很多不明白!有没有人推荐一些资料看看,让我知道下面的每一个成员究竟对应什么东西呢?
  
  TABLE_SHARE 结构的代码如下/*
  This structure is shared between different table objects. There is one
  instance of table share per one table in the database.
*/

typedef struct st_table_share
{
  st_table_share() {}                    /* Remove gcc warning */

  /** Category of this table. */
  TABLE_CATEGORY table_category;

  /* hash of field names (contains pointers to elements of field array) */
  HASH        name_hash;                        /* hash of field names */
  MEM_ROOT mem_root;
  TYPELIB keynames;                        /* Pointers to keynames */
  TYPELIB fieldnames;                        /* Pointer to fieldnames */
  TYPELIB *intervals;                        /* pointer to interval info */
  pthread_mutex_t mutex;                /* For locking the share  */
  pthread_cond_t cond;                        /* To signal that share is ready */
  struct st_table_share *next,                /* Link to unused shares */
    **prev;
#ifdef NOT_YET
  struct st_table *open_tables;                /* link to open tables */
#endif

  /* The following is copied to each TABLE on OPEN */
  Field **field;
  Field **found_next_number_field;
  Field *timestamp_field;               /* Used only during open */
  KEY  *key_info;                        /* data of keys in database */
  uint        *blob_field;                        /* Index(下标) to blobs in Field arrray*/

  uchar        *default_values;                /* row with default values */
  LEX_STRING comment;                        /* Comment about table */
  CHARSET_INFO *table_charset;                /* Default charset of string fields */

  MY_BITMAP all_set;
  /*
    Key which is used for looking-up table in table cache and in the list
    of thread's temporary tables. Has the form of:
      "database_name\0table_name\0" + optional part for temporary tables.

    Note that all three 'table_cache_key', 'db' and 'table_name' members
    must be set (and be non-zero) for tables in table cache. They also
    should correspond to each other.
    To ensure this one can use set_table_cache() methods.
  */
  LEX_STRING table_cache_key;
  LEX_STRING db;                        /* Pointer to db */
  LEX_STRING table_name;                /* Table name (for open) */
  LEX_STRING path;                        /* Path to .frm file (from datadir) */
  LEX_STRING normalized_path;                /* unpack_filename(path) */
  LEX_STRING connect_string;

  /*
     Set of keys in use, implemented as a Bitmap.
     Excludes keys disabled by ALTER TABLE ... DISABLE KEYS.
  */
  key_map keys_in_use;
  key_map keys_for_keyread;
  ha_rows min_rows, max_rows;                /* create information */
  ulong   avg_row_length;                /* create information */
  ulong   raid_chunksize;
  ulong   version, mysql_version;
  ulong   timestamp_offset;                /* Set to offset+1 of record */
  ulong   reclength;                        /* Recordlength 记录长度*/

  plugin_ref db_plugin;                        /* storage engine plugin */
  inline handlerton *db_type() const        /* table_type for handler */
  {
    // DBUG_ASSERT(db_plugin);
    return db_plugin ? plugin_data(db_plugin, handlerton*) : NULL;
  }
  enum row_type row_type;                /* How rows are stored */
  enum ha_storage_media default_storage_media;
  char *tablespace;
  enum tmp_table_type tmp_table;
  enum ha_choice transactional;

  uint ref_count;                       /* How many TABLE objects uses this */
  uint open_count;                        /* Number of tables in open list */
  uint blob_ptr_size;                        /* 4 or 8 */
  uint key_block_size;                        /* create key_block_size, if used */
  uint null_bytes, last_null_bit_pos;
  uint fields;                                /* Number of fields */
  uint rec_buff_length;                 /* Size of table->record[] buffer */
  uint keys, key_parts;
  uint max_key_length, max_unique_length, total_key_length;
  uint uniques;                         /* Number of UNIQUE index */
  uint null_fields;                        /* number of null fields */
  uint blob_fields;                        /* number of blob fields 有多少blob*/
  uint timestamp_field_offset;                /* Field number for timestamp field */
  uint varchar_fields;                  /* number of varchar fields */
  uint db_create_options;                /* Create options from database */
  uint db_options_in_use;                /* Options in use */
  uint db_record_offset;                /* if HA_REC_IN_SEQ */
  uint raid_type, raid_chunks;
  uint rowid_field_offset;                /* Field_nr +1 to rowid field */
  /* Index of auto-updated TIMESTAMP field in field array */
  uint primary_key;
  uint next_number_index;               /* autoincrement key number */
  uint next_number_key_offset;          /* autoinc keypart offset in a key */
  uint next_number_keypart;             /* autoinc keypart number in a key */
  uint error, open_errno, errarg;       /* error from open_table_def() */
  uint column_bitmap_size;
  uchar frm_version;
  bool null_field_first;
  bool system;                          /* Set if system table (one record) */
  bool crypted;                         /* If .frm file is crypted */
  bool db_low_byte_first;                /* Portable row format */
  bool crashed;
  bool is_view;
  bool name_lock, replace_with_name_lock;
  bool waiting_on_cond;                 /* Protection against free */
  ulong table_map_id;                   /* for row-based replication */
  ulonglong table_map_version;

  /*
    Cache for row-based replication table share checks that does not
    need to be repeated. Possible values are: -1 when cache value is
    not calculated yet, 0 when table *shall not* be replicated, 1 when
    table *may* be replicated.
  */
  int cached_row_logging_check;

#ifdef WITH_PARTITION_STORAGE_ENGINE
  bool auto_partitioned;
  const char *partition_info;
  uint  partition_info_len;
  uint  partition_info_buffer_size;
  const char *part_state;
  uint part_state_len;
  handlerton *default_part_db_type;
#endif


  /*
    Set share's table cache key and update its db and table name appropriately.

    SYNOPSIS
      set_table_cache_key()
        key_buff    Buffer with already built table cache key to be
                    referenced from share.
        key_length  Key length.

    NOTES
      Since 'key_buff' buffer will be referenced from share it should has same
      life-time as share itself.
      This method automatically ensures that TABLE_SHARE::table_name/db have
      appropriate values by using table cache key as their source.
  */

  void set_table_cache_key(char *key_buff, uint key_length)
  {
    table_cache_key.str= key_buff;
    table_cache_key.length= key_length;
    /*
      Let us use the fact that the key is "db/0/table_name/0" + optional
      part for temporary tables.
    */
    db.str=            table_cache_key.str;
    db.length=         strlen(db.str);
    table_name.str=    db.str + db.length + 1;
    table_name.length= strlen(table_name.str);
  }


  /*
    Set share's table cache key and update its db and table name appropriately.

    SYNOPSIS
      set_table_cache_key()
        key_buff    Buffer to be used as storage for table cache key
                    (should be at least key_length bytes).
        key         Value for table cache key.
        key_length  Key length.

    NOTE
      Since 'key_buff' buffer will be used as storage for table cache key
      it should has same life-time as share itself.
  */

  void set_table_cache_key(char *key_buff, const char *key, uint key_length)
  {
    memcpy(key_buff, key, key_length);
    set_table_cache_key(key_buff, key_length);
  }

  inline bool honor_global_locks()
  {
    return ((table_category == TABLE_CATEGORY_USER)
            || (table_category == TABLE_CATEGORY_SYSTEM));
  }

  inline bool require_write_privileges()
  {
    return (table_category == TABLE_CATEGORY_PERFORMANCE);
  }
} TABLE_SHARE;

查看了一些资料,就知道下面几个成员的意思!其他的还请各位帮忙!
/*

struct st_table *open_tables;
        指向打开该表的TABLE结构实例;
ulong   reclength;
        记录长度;
uint ref_count;      
        对应的TABLE对象数目;
uint fields;         
        字段数目;
uint keys;         
        索引数目;
KEY  *key_info;     
        指向表的索引结构;
uint null_fields;
        NULL字段的数目;
uint *blob_field
        BLOB字段在Field数组里面的下标
uint blob_fields;
        BLOB字段的数目;
uint varchar_fields;      
        varchar字段的数目;
LEX_STRING table_name;         
        表名称;
LEX_STRING path;         
        .frm文件路径(表定义文件);
        */
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
收藏收藏 分享淘帖 顶 踩
2#
 楼主| 发表于 2008-8-15 19:15:30 | 只看该作者
虽然源代码中有一些说明,但是,我还是看不明白!
3#
发表于 2008-8-18 10:28:51 | 只看该作者
看源码的人毕竟是少数吧

继续努力,加油!

有共同研究经历的来讨论吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|申请友链|小黑屋|Archiver|手机版|MySQL社区 ( 京ICP备07012489号   
联系人:周生; 联系电话:13911732319

GMT+8, 2024-5-8 10:07 , Processed in 0.067041 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表