~drizzle-trunk/drizzle/development

798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2009 Sun Microsystems
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; either version 2 of the License, or
9
 *  (at your option) any later version.
10
 *
11
 *  This program is distributed in the hope that it will be useful,
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 *  GNU General Public License for more details.
15
 *
16
 *  You should have received a copy of the GNU General Public License
17
 *  along with this program; if not, write to the Free Software
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 */
20
21
/*
22
  This class is shared between different table objects. There is one
23
  instance of table share per one table in the database.
24
*/
25
class TABLE_SHARE
26
{
27
public:
28
  TABLE_SHARE() {}                    /* Remove gcc warning */
29
30
  /** Category of this table. */
31
  enum_table_category table_category;
32
33
  /* hash of field names (contains pointers to elements of field array) */
34
  HASH	name_hash;			/* hash of field names */
35
  MEM_ROOT mem_root;
36
  TYPELIB keynames;			/* Pointers to keynames */
37
  TYPELIB fieldnames;			/* Pointer to fieldnames */
38
  TYPELIB *intervals;			/* pointer to interval info */
39
  pthread_mutex_t mutex;                /* For locking the share  */
40
  pthread_cond_t cond;			/* To signal that share is ready */
41
  TABLE_SHARE *next,		/* Link to unused shares */
42
    **prev;
43
44
  /* The following is copied to each Table on OPEN */
45
  Field **field;
46
  Field **found_next_number_field;
47
  Field *timestamp_field;               /* Used only during open */
48
  KEY  *key_info;			/* data of keys in database */
49
  uint	*blob_field;			/* Index to blobs in Field arrray*/
50
51
  unsigned char	*default_values;		/* row with default values */
52
  LEX_STRING comment;			/* Comment about table */
53
  const CHARSET_INFO *table_charset; /* Default charset of string fields */
54
55
  MY_BITMAP all_set;
56
  /*
57
    Key which is used for looking-up table in table cache and in the list
58
    of thread's temporary tables. Has the form of:
59
      "database_name\0table_name\0" + optional part for temporary tables.
60
61
    Note that all three 'table_cache_key', 'db' and 'table_name' members
62
    must be set (and be non-zero) for tables in table cache. They also
63
    should correspond to each other.
64
    To ensure this one can use set_table_cache() methods.
65
  */
66
  LEX_STRING table_cache_key;
67
  LEX_STRING db;                        /* Pointer to db */
68
  LEX_STRING table_name;                /* Table name (for open) */
69
  LEX_STRING path;	/* Path to .frm file (from datadir) */
70
  LEX_STRING normalized_path;		/* unpack_filename(path) */
71
  LEX_STRING connect_string;
72
73
  /*
74
     Set of keys in use, implemented as a Bitmap.
75
     Excludes keys disabled by ALTER Table ... DISABLE KEYS.
76
  */
77
  key_map keys_in_use;
78
  key_map keys_for_keyread;
79
  ha_rows min_rows, max_rows;		/* create information */
80
  uint32_t   avg_row_length;		/* create information */
81
  uint32_t   block_size;                   /* create information */
82
  uint32_t   version, mysql_version;
83
  uint32_t   timestamp_offset;		/* Set to offset+1 of record */
84
  uint32_t   reclength;			/* Recordlength */
85
  uint32_t   stored_rec_length;         /* Stored record length
86
                                           (no generated-only virtual fields) */
87
88
  plugin_ref db_plugin;			/* storage engine plugin */
89
  inline handlerton *db_type() const	/* table_type for handler */
90
  {
91
    // assert(db_plugin);
92
    return db_plugin ? plugin_data(db_plugin, handlerton*) : NULL;
93
  }
94
  enum row_type row_type;		/* How rows are stored */
95
  enum tmp_table_type tmp_table;
96
  enum ha_choice page_checksum;
97
98
  uint32_t ref_count;       /* How many Table objects uses this */
99
  uint32_t open_count;			/* Number of tables in open list */
100
  uint32_t blob_ptr_size;			/* 4 or 8 */
101
  uint32_t key_block_size;			/* create key_block_size, if used */
102
  uint32_t null_bytes;
103
  uint32_t last_null_bit_pos;
104
  uint32_t fields;				/* Number of fields */
105
  uint32_t stored_fields;                   /* Number of stored fields
106
                                           (i.e. without generated-only ones) */
107
  uint32_t rec_buff_length;                 /* Size of table->record[] buffer */
108
  uint32_t keys, key_parts;
109
  uint32_t max_key_length, max_unique_length, total_key_length;
110
  uint32_t uniques;                         /* Number of UNIQUE index */
111
  uint32_t null_fields;			/* number of null fields */
112
  uint32_t blob_fields;			/* number of blob fields */
113
  uint32_t timestamp_field_offset;		/* Field number for timestamp field */
114
  uint32_t varchar_fields;                  /* number of varchar fields */
115
  uint32_t db_create_options;		/* Create options from database */
116
  uint32_t db_options_in_use;		/* Options in use */
117
  uint32_t db_record_offset;		/* if HA_REC_IN_SEQ */
118
  uint32_t rowid_field_offset;		/* Field_nr +1 to rowid field */
119
  /* Index of auto-updated TIMESTAMP field in field array */
120
  uint32_t primary_key;
121
  uint32_t next_number_index;               /* autoincrement key number */
122
  uint32_t next_number_key_offset;          /* autoinc keypart offset in a key */
123
  uint32_t next_number_keypart;             /* autoinc keypart number in a key */
124
  uint32_t error, open_errno, errarg;       /* error from open_table_def() */
125
  uint32_t column_bitmap_size;
126
127
  uint32_t vfields;                         /* Number of virtual fields */
128
  bool db_low_byte_first;		/* Portable row format */
129
  bool crashed;
130
  bool name_lock, replace_with_name_lock;
131
  bool waiting_on_cond;                 /* Protection against free */
132
  uint32_t table_map_id;                   /* for row-based replication */
133
  uint64_t table_map_version;
134
135
  /*
136
    Cache for row-based replication table share checks that does not
137
    need to be repeated. Possible values are: -1 when cache value is
138
    not calculated yet, 0 when table *shall not* be replicated, 1 when
139
    table *may* be replicated.
140
  */
141
  int cached_row_logging_check;
142
143
  /*
144
    Set share's table cache key and update its db and table name appropriately.
145
146
    SYNOPSIS
147
      set_table_cache_key()
148
        key_buff    Buffer with already built table cache key to be
149
                    referenced from share.
150
        key_length  Key length.
151
152
    NOTES
153
      Since 'key_buff' buffer will be referenced from share it should has same
154
      life-time as share itself.
155
      This method automatically ensures that TABLE_SHARE::table_name/db have
156
      appropriate values by using table cache key as their source.
157
  */
158
159
  void set_table_cache_key(char *key_buff, uint32_t key_length)
160
  {
161
    table_cache_key.str= key_buff;
162
    table_cache_key.length= key_length;
163
    /*
164
      Let us use the fact that the key is "db/0/table_name/0" + optional
165
      part for temporary tables.
166
    */
167
    db.str=            table_cache_key.str;
168
    db.length=         strlen(db.str);
169
    table_name.str=    db.str + db.length + 1;
170
    table_name.length= strlen(table_name.str);
171
  }
172
173
174
  /*
175
    Set share's table cache key and update its db and table name appropriately.
176
177
    SYNOPSIS
178
      set_table_cache_key()
179
        key_buff    Buffer to be used as storage for table cache key
180
                    (should be at least key_length bytes).
181
        key         Value for table cache key.
182
        key_length  Key length.
183
184
    NOTE
185
      Since 'key_buff' buffer will be used as storage for table cache key
186
      it should has same life-time as share itself.
187
  */
188
189
  void set_table_cache_key(char *key_buff, const char *key, uint32_t key_length)
190
  {
191
    memcpy(key_buff, key, key_length);
192
    set_table_cache_key(key_buff, key_length);
193
  }
194
195
  inline bool honor_global_locks()
196
  {
197
    return (table_category == TABLE_CATEGORY_USER);
198
  }
199
200
  inline uint32_t get_table_def_version()
201
  {
202
    return table_map_id;
203
  }
204
205
};