~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table.h

  • Committer: Brian Aker
  • Date: 2009-05-21 18:09:02 UTC
  • mfrom: (1030.1.3 merge)
  • Revision ID: brian@gaz-20090521180902-5vrm1b0vbe5cby1j
MergeĀ forĀ Brian

Show diffs side-by-side

added added

removed removed

Lines of Context:
70
70
 
71
71
class Table {
72
72
public:
 
73
  Table() {}                               /* Remove gcc warning */
 
74
 
 
75
  TableShare    *s;
 
76
  Field **field;                        /* Pointer to fields */
 
77
 
 
78
  handler       *file;
 
79
  Table *next;
 
80
  Table *prev;
 
81
 
 
82
  MY_BITMAP     *read_set;          /* Active column sets */
 
83
  MY_BITMAP     *write_set;          /* Active column sets */
 
84
 
 
85
  uint32_t              tablenr;
 
86
  uint32_t db_stat;             /* mode of file as in handler.h */
 
87
 
73
88
  my_bitmap_map *bitmap_init_value;
74
89
  MY_BITMAP     def_read_set, def_write_set, tmp_set; /* containers */
75
 
  MY_BITMAP     *read_set, *write_set;          /* Active column sets */
76
 
 
77
 
  TableShare    *s;
78
 
  Table() {}                               /* Remove gcc warning */
79
 
 
80
 
  /* SHARE methods */
81
 
  inline TableShare *getShare() { return s; } /* Get rid of this long term */
82
 
  inline void setShare(TableShare *new_share) { s= new_share; } /* Get rid of this long term */
83
 
  inline uint32_t sizeKeys() { return s->keys; }
84
 
  inline uint32_t sizeFields() { return s->fields; }
85
 
  inline uint32_t getRecordLength() { return s->reclength; }
86
 
  inline uint32_t sizeBlobFields() { return s->blob_fields; }
87
 
  inline uint32_t *getBlobField() { return s->blob_field; }
88
 
  inline uint32_t getNullBytes() { return s->null_bytes; }
89
 
  inline uint32_t getNullFields() { return s->null_fields; }
90
 
  inline unsigned char *getDefaultValues() { return s->default_values; }
91
 
 
92
 
  inline bool isDatabaseLowByteFirst() { return s->db_low_byte_first; }         /* Portable row format */
93
 
  inline bool isCrashed() { return s->crashed; }
94
 
  inline bool isNameLock() { return s->name_lock; }
95
 
  inline bool isReplaceWithNameLock() { return s->replace_with_name_lock; }
96
 
  inline bool isWaitingOnCondition() { return s->waiting_on_cond; }                 /* Protection against free */
97
 
 
98
 
  /* For TMP tables, should be pulled out as a class */
99
 
  void updateCreateInfo(HA_CREATE_INFO *create_info);
100
 
  void setup_tmp_table_column_bitmaps(unsigned char *bitmaps);
101
 
  bool create_myisam_tmp_table(KEY *keyinfo,
102
 
                               MI_COLUMNDEF *start_recinfo,
103
 
                               MI_COLUMNDEF **recinfo,
104
 
                               uint64_t options);
105
 
  void free_tmp_table(Session *session);
106
 
  bool open_tmp_table();
107
 
  size_t max_row_length(const unsigned char *data);
108
 
  uint32_t find_shortest_key(const key_map *usable_keys);
109
 
  bool compare_record(Field **ptr);
110
 
  bool compare_record();
111
 
  /* TODO: the (re)storeRecord's may be able to be further condensed */
112
 
  void storeRecord();
113
 
  void storeRecordAsInsert();
114
 
  void storeRecordAsDefault();
115
 
  void restoreRecord();
116
 
  void restoreRecordAsDefault();
117
 
  void emptyRecord();
118
 
  bool table_check_intact(const uint32_t table_f_count, const TABLE_FIELD_W_TYPE *table_def);
119
 
 
120
 
  /* See if this can be blown away */
121
 
  inline uint32_t getDBStat () { return db_stat; }
122
 
  inline uint32_t setDBStat () { return db_stat; }
123
 
  uint32_t db_stat;             /* mode of file as in handler.h */
124
 
 
125
 
  handler       *file;
126
 
  Table *next, *prev;
127
90
 
128
91
  Session       *in_use;                        /* Which thread uses this */
129
 
  Field **field;                        /* Pointer to fields */
130
92
 
131
93
  unsigned char *record[2];                     /* Pointer to records */
132
94
  unsigned char *write_row_record;              /* Used as optimisation in
133
95
                                           Session::write_row */
134
96
  unsigned char *insert_values;                  /* used by INSERT ... UPDATE */
135
 
  /*
136
 
    Map of keys that can be used to retrieve all data from this table
137
 
    needed by the query without reading the row.
138
 
  */
139
 
  key_map covering_keys;
140
 
  key_map quick_keys, merge_keys;
141
 
  /*
142
 
    A set of keys that can be used in the query that references this
143
 
    table.
144
 
 
145
 
    All indexes disabled on the table's TableShare (see Table::s) will be
146
 
    subtracted from this set upon instantiation. Thus for any Table t it holds
147
 
    that t.keys_in_use_for_query is a subset of t.s.keys_in_use. Generally we
148
 
    must not introduce any new keys here (see setup_tables).
149
 
 
150
 
    The set is implemented as a bitmap.
151
 
  */
152
 
  key_map keys_in_use_for_query;
153
 
  /* Map of keys that can be used to calculate GROUP BY without sorting */
154
 
  key_map keys_in_use_for_group_by;
155
 
  /* Map of keys that can be used to calculate ORDER BY without sorting */
156
 
  key_map keys_in_use_for_order_by;
157
97
  KEY  *key_info;                       /* data of keys in database */
158
 
 
159
98
  Field *next_number_field;             /* Set if next_number is activated */
160
99
  Field *found_next_number_field;       /* Set on open */
161
100
  Field_timestamp *timestamp_field;
164
103
  order_st *group;
165
104
  const char    *alias;                   /* alias or table name */
166
105
  unsigned char         *null_flags;
167
 
  /*
168
 
   The ID of the query that opened and is using this table. Has different
169
 
   meanings depending on the table type.
170
 
 
171
 
   Temporary tables:
172
 
 
173
 
   table->query_id is set to session->query_id for the duration of a statement
174
 
   and is reset to 0 once it is closed by the same statement. A non-zero
175
 
   table->query_id means that a statement is using the table even if it's
176
 
   not the current statement (table is in use by some outer statement).
177
 
 
178
 
   Non-temporary tables:
179
 
 
180
 
   Under pre-locked or LOCK TABLES mode: query_id is set to session->query_id
181
 
   for the duration of a statement and is reset to 0 once it is closed by
182
 
   the same statement. A non-zero query_id is used to control which tables
183
 
   in the list of pre-opened and locked tables are actually being used.
184
 
  */
185
 
  query_id_t    query_id;
186
 
 
187
 
  /*
188
 
    For each key that has quick_keys.test(key) == true: estimate of #records
189
 
    and max #key parts that range access would use.
190
 
  */
191
 
  ha_rows       quick_rows[MAX_KEY];
192
 
 
193
 
  /* Bitmaps of key parts that =const for the entire join. */
194
 
  key_part_map  const_key_parts[MAX_KEY];
195
 
 
196
 
  uint          quick_key_parts[MAX_KEY];
197
 
  uint          quick_n_ranges[MAX_KEY];
198
 
 
199
 
  /*
200
 
    Estimate of number of records that satisfy SARGable part of the table
201
 
    condition, or table->file->records if no SARGable condition could be
202
 
    constructed.
203
 
    This value is used by join optimizer as an estimate of number of records
204
 
    that will pass the table condition (condition that depends on fields of
205
 
    this table and constants)
206
 
  */
207
 
  ha_rows       quick_condition_rows;
208
 
 
209
 
  /*
210
 
    If this table has TIMESTAMP field with auto-set property (pointed by
211
 
    timestamp_field member) then this variable indicates during which
212
 
    operations (insert only/on update/in both cases) we should set this
213
 
    field to current timestamp. If there are no such field in this table
214
 
    or we should not automatically set its value during execution of current
215
 
    statement then the variable contains TIMESTAMP_NO_AUTO_SET (i.e. 0).
216
 
 
217
 
    Value of this variable is set for each statement in open_table() and
218
 
    if needed cleared later in statement processing code (see mysql_update()
219
 
    as example).
220
 
  */
221
 
  timestamp_auto_set_type timestamp_field_type;
222
 
  table_map     map;                    /* ID bit of table (1,2,4,8,16...) */
223
106
 
224
107
  uint32_t          lock_position;          /* Position in DRIZZLE_LOCK.table */
225
108
  uint32_t          lock_data_start;        /* Start pos. in DRIZZLE_LOCK.locks */
226
109
  uint32_t          lock_count;             /* Number of locks */
227
 
  uint          tablenr,used_fields;
 
110
  uint32_t used_fields;
228
111
  uint32_t          temp_pool_slot;             /* Used by intern temp tables */
229
 
  uint          status;                 /* What's in record[0] */
 
112
  uint32_t              status;                 /* What's in record[0] */
230
113
  /* number of select if it is derived table */
231
114
  uint32_t          derived_select_number;
232
115
  int           current_lock;           /* Type of lock on table */
247
130
 
248
131
  bool force_index;
249
132
  bool distinct,const_table,no_rows;
250
 
  bool key_read, no_keyread;
 
133
  bool key_read;
 
134
  bool no_keyread;
251
135
  /*
252
136
    Placeholder for an open table which prevents other connections
253
137
    from taking name-locks on this table. Typically used with
266
150
    not rely on that.
267
151
  */
268
152
  bool open_placeholder;
269
 
  bool locked_by_logger;
270
 
  bool no_replicate;
271
153
  bool locked_by_name;
272
154
  bool no_cache;
273
155
  /*
279
161
  bool insert_or_update;             /* Can be used by the handler */
280
162
  bool alias_name_used;         /* true if table_name is alias */
281
163
  bool get_fields_in_item_tree;      /* Signal to fix_field */
 
164
  int report_error(int error);
 
165
  int closefrm(bool free_share);
 
166
  uint32_t tmpkeyval();
 
167
 
 
168
  /*
 
169
   The ID of the query that opened and is using this table. Has different
 
170
   meanings depending on the table type.
 
171
 
 
172
   Temporary tables:
 
173
 
 
174
   table->query_id is set to session->query_id for the duration of a statement
 
175
   and is reset to 0 once it is closed by the same statement. A non-zero
 
176
   table->query_id means that a statement is using the table even if it's
 
177
   not the current statement (table is in use by some outer statement).
 
178
 
 
179
   Non-temporary tables:
 
180
 
 
181
   Under pre-locked or LOCK TABLES mode: query_id is set to session->query_id
 
182
   for the duration of a statement and is reset to 0 once it is closed by
 
183
   the same statement. A non-zero query_id is used to control which tables
 
184
   in the list of pre-opened and locked tables are actually being used.
 
185
  */
 
186
  query_id_t    query_id;
 
187
 
 
188
  /*
 
189
    Estimate of number of records that satisfy SARGable part of the table
 
190
    condition, or table->file->records if no SARGable condition could be
 
191
    constructed.
 
192
    This value is used by join optimizer as an estimate of number of records
 
193
    that will pass the table condition (condition that depends on fields of
 
194
    this table and constants)
 
195
  */
 
196
  ha_rows       quick_condition_rows;
 
197
 
 
198
  /*
 
199
    If this table has TIMESTAMP field with auto-set property (pointed by
 
200
    timestamp_field member) then this variable indicates during which
 
201
    operations (insert only/on update/in both cases) we should set this
 
202
    field to current timestamp. If there are no such field in this table
 
203
    or we should not automatically set its value during execution of current
 
204
    statement then the variable contains TIMESTAMP_NO_AUTO_SET (i.e. 0).
 
205
 
 
206
    Value of this variable is set for each statement in open_table() and
 
207
    if needed cleared later in statement processing code (see mysql_update()
 
208
    as example).
 
209
  */
 
210
  timestamp_auto_set_type timestamp_field_type;
 
211
  table_map     map;                    /* ID bit of table (1,2,4,8,16...) */
282
212
 
283
213
  REGINFO reginfo;                      /* field connections */
 
214
 
 
215
  /*
 
216
    Map of keys that can be used to retrieve all data from this table
 
217
    needed by the query without reading the row.
 
218
  */
 
219
  key_map covering_keys;
 
220
 
 
221
 
 
222
  key_map quick_keys;
 
223
  key_map merge_keys;
 
224
 
 
225
  /*
 
226
    A set of keys that can be used in the query that references this
 
227
    table.
 
228
 
 
229
    All indexes disabled on the table's TableShare (see Table::s) will be
 
230
    subtracted from this set upon instantiation. Thus for any Table t it holds
 
231
    that t.keys_in_use_for_query is a subset of t.s.keys_in_use. Generally we
 
232
    must not introduce any new keys here (see setup_tables).
 
233
 
 
234
    The set is implemented as a bitmap.
 
235
  */
 
236
  key_map keys_in_use_for_query;
 
237
  /* Map of keys that can be used to calculate GROUP BY without sorting */
 
238
  key_map keys_in_use_for_group_by;
 
239
  /* Map of keys that can be used to calculate ORDER BY without sorting */
 
240
  key_map keys_in_use_for_order_by;
 
241
 
 
242
  /*
 
243
    For each key that has quick_keys.test(key) == true: estimate of #records
 
244
    and max #key parts that range access would use.
 
245
  */
 
246
  ha_rows       quick_rows[MAX_KEY];
 
247
 
 
248
  /* Bitmaps of key parts that =const for the entire join. */
 
249
  key_part_map  const_key_parts[MAX_KEY];
 
250
 
 
251
  uint32_t              quick_key_parts[MAX_KEY];
 
252
  uint32_t              quick_n_ranges[MAX_KEY];
 
253
 
284
254
  MEM_ROOT mem_root;
285
255
  filesort_info_st sort;
286
256
 
 
257
 
 
258
 
 
259
  /* SHARE methods */
 
260
  inline TableShare *getShare() { return s; } /* Get rid of this long term */
 
261
  inline void setShare(TableShare *new_share) { s= new_share; } /* Get rid of this long term */
 
262
  inline uint32_t sizeKeys() { return s->keys; }
 
263
  inline uint32_t sizeFields() { return s->fields; }
 
264
  inline uint32_t getRecordLength() { return s->reclength; }
 
265
  inline uint32_t sizeBlobFields() { return s->blob_fields; }
 
266
  inline uint32_t *getBlobField() { return s->blob_field; }
 
267
  inline uint32_t getNullBytes() { return s->null_bytes; }
 
268
  inline uint32_t getNullFields() { return s->null_fields; }
 
269
  inline unsigned char *getDefaultValues() { return s->default_values; }
 
270
 
 
271
  inline bool isDatabaseLowByteFirst() { return s->db_low_byte_first; }         /* Portable row format */
 
272
  inline bool isCrashed() { return s->crashed; }
 
273
  inline bool isNameLock() { return s->name_lock; }
 
274
  inline bool isReplaceWithNameLock() { return s->replace_with_name_lock; }
 
275
  inline bool isWaitingOnCondition() { return s->waiting_on_cond; }                 /* Protection against free */
 
276
 
 
277
  /* For TMP tables, should be pulled out as a class */
 
278
  void updateCreateInfo(HA_CREATE_INFO *create_info);
 
279
  void setup_tmp_table_column_bitmaps(unsigned char *bitmaps);
 
280
  bool create_myisam_tmp_table(KEY *keyinfo,
 
281
                               MI_COLUMNDEF *start_recinfo,
 
282
                               MI_COLUMNDEF **recinfo,
 
283
                               uint64_t options);
 
284
  void free_tmp_table(Session *session);
 
285
  bool open_tmp_table();
 
286
  size_t max_row_length(const unsigned char *data);
 
287
  uint32_t find_shortest_key(const key_map *usable_keys);
 
288
  bool compare_record(Field **ptr);
 
289
  bool compare_record();
 
290
  /* TODO: the (re)storeRecord's may be able to be further condensed */
 
291
  void storeRecord();
 
292
  void storeRecordAsInsert();
 
293
  void storeRecordAsDefault();
 
294
  void restoreRecord();
 
295
  void restoreRecordAsDefault();
 
296
  void emptyRecord();
 
297
  bool table_check_intact(const uint32_t table_f_count, const TABLE_FIELD_W_TYPE *table_def);
 
298
 
 
299
  /* See if this can be blown away */
 
300
  inline uint32_t getDBStat () { return db_stat; }
 
301
  inline uint32_t setDBStat () { return db_stat; }
287
302
  bool fill_item_list(List<Item> *item_list) const;
288
303
  void reset_item_list(List<Item> *item_list) const;
289
304
  void clear_column_bitmaps(void);
356
371
  inline bool needs_reopen_or_name_lock()
357
372
  { return s->version != refresh_version; }
358
373
 
359
 
  int report_error(int error);
360
 
  int closefrm(bool free_share);
361
 
  uint32_t tmpkeyval();
362
 
 
363
374
  /**
364
375
    clean/setup table fields and map.
365
376