1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
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.
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.
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
1
/* Copyright (C) 2000-2006 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
21
17
/* Structs that defines the Table */
211
204
enum ha_choice transactional;
212
205
enum ha_choice page_checksum;
214
uint32_t ref_count; /* How many Table objects uses this */
215
uint32_t open_count; /* Number of tables in open list */
216
uint32_t blob_ptr_size; /* 4 or 8 */
217
uint32_t key_block_size; /* create key_block_size, if used */
218
uint32_t null_bytes, last_null_bit_pos;
219
uint32_t fields; /* Number of fields */
220
uint32_t stored_fields; /* Number of stored fields
221
(i.e. without generated-only ones) */
222
uint32_t rec_buff_length; /* Size of table->record[] buffer */
223
uint32_t keys, key_parts;
224
uint32_t max_key_length, max_unique_length, total_key_length;
225
uint32_t uniques; /* Number of UNIQUE index */
226
uint32_t null_fields; /* number of null fields */
227
uint32_t blob_fields; /* number of blob fields */
228
uint32_t timestamp_field_offset; /* Field number for timestamp field */
229
uint32_t varchar_fields; /* number of varchar fields */
230
uint32_t db_create_options; /* Create options from database */
231
uint32_t db_options_in_use; /* Options in use */
232
uint32_t db_record_offset; /* if HA_REC_IN_SEQ */
233
uint32_t rowid_field_offset; /* Field_nr +1 to rowid field */
207
uint ref_count; /* How many Table objects uses this */
208
uint open_count; /* Number of tables in open list */
209
uint blob_ptr_size; /* 4 or 8 */
210
uint key_block_size; /* create key_block_size, if used */
211
uint null_bytes, last_null_bit_pos;
212
uint fields; /* Number of fields */
213
uint rec_buff_length; /* Size of table->record[] buffer */
214
uint keys, key_parts;
215
uint max_key_length, max_unique_length, total_key_length;
216
uint uniques; /* Number of UNIQUE index */
217
uint null_fields; /* number of null fields */
218
uint blob_fields; /* number of blob fields */
219
uint timestamp_field_offset; /* Field number for timestamp field */
220
uint varchar_fields; /* number of varchar fields */
221
uint db_create_options; /* Create options from database */
222
uint db_options_in_use; /* Options in use */
223
uint db_record_offset; /* if HA_REC_IN_SEQ */
224
uint rowid_field_offset; /* Field_nr +1 to rowid field */
234
225
/* Index of auto-updated TIMESTAMP field in field array */
235
uint32_t primary_key;
236
uint32_t next_number_index; /* autoincrement key number */
237
uint32_t next_number_key_offset; /* autoinc keypart offset in a key */
238
uint32_t next_number_keypart; /* autoinc keypart number in a key */
239
uint32_t error, open_errno, errarg; /* error from open_table_def() */
240
uint32_t column_bitmap_size;
241
unsigned char frm_version;
242
uint32_t vfields; /* Number of virtual fields */
227
uint next_number_index; /* autoincrement key number */
228
uint next_number_key_offset; /* autoinc keypart offset in a key */
229
uint next_number_keypart; /* autoinc keypart number in a key */
230
uint error, open_errno, errarg; /* error from open_table_def() */
231
uint column_bitmap_size;
243
233
bool null_field_first;
244
234
bool db_low_byte_first; /* Portable row format */
352
342
/* SHARE methods */
353
343
inline TABLE_SHARE *getShare() { return s; } /* Get rid of this long term */
354
344
inline void setShare(TABLE_SHARE *new_share) { s= new_share; } /* Get rid of this long term */
355
inline uint32_t sizeKeys() { return s->keys; }
356
inline uint32_t sizeFields() { return s->fields; }
357
inline uint32_t getRecordLength() { return s->reclength; }
358
inline uint32_t sizeBlobFields() { return s->blob_fields; }
359
inline uint32_t *getBlobField() { return s->blob_field; }
360
inline uint32_t getNullBytes() { return s->null_bytes; }
361
inline uint32_t getNullFields() { return s->null_fields; }
345
inline uint sizeKeys() { return s->keys; }
346
inline uint sizeFields() { return s->fields; }
347
inline uint getRecordLength() { return s->reclength; }
348
inline uint sizeBlobFields() { return s->blob_fields; }
349
inline uint *getBlobField() { return s->blob_field; }
350
inline uint getNullBytes() { return s->null_bytes; }
351
inline uint getNullFields() { return s->null_fields; }
362
352
inline unsigned char *getDefaultValues() { return s->default_values; }
364
354
inline bool isNullFieldFirst() { return s->null_field_first; }
371
361
/* For TMP tables, should be pulled out as a class */
372
362
void updateCreateInfo(HA_CREATE_INFO *create_info);
373
void setup_tmp_table_column_bitmaps(unsigned char *bitmaps);
363
void setup_tmp_table_column_bitmaps(uchar *bitmaps);
374
364
bool create_myisam_tmp_table(KEY *keyinfo,
375
365
MI_COLUMNDEF *start_recinfo,
376
366
MI_COLUMNDEF **recinfo,
377
367
uint64_t options);
378
void free_tmp_table(Session *session);
368
void free_tmp_table(THD *thd);
379
369
bool open_tmp_table();
380
size_t max_row_length(const unsigned char *data);
381
uint32_t find_shortest_key(const key_map *usable_keys);
370
size_t max_row_length(const uchar *data);
371
uint find_shortest_key(const key_map *usable_keys);
382
372
bool compare_record(Field **ptr);
383
373
bool compare_record();
385
bool table_check_intact(const uint32_t table_f_count, const TABLE_FIELD_W_TYPE *table_def);
375
bool table_check_intact(const uint table_f_count, const TABLE_FIELD_W_TYPE *table_def);
387
377
/* See if this can be blown away */
388
inline uint32_t getDBStat () { return db_stat; }
389
inline uint32_t setDBStat () { return db_stat; }
378
inline uint getDBStat () { return db_stat; }
379
inline uint setDBStat () { return db_stat; }
390
380
uint db_stat; /* mode of file as in handler.h */
393
383
Table *next, *prev;
395
Session *in_use; /* Which thread uses this */
385
THD *in_use; /* Which thread uses this */
396
386
Field **field; /* Pointer to fields */
398
unsigned char *record[2]; /* Pointer to records */
399
unsigned char *write_row_record; /* Used as optimisation in
400
Session::write_row */
401
unsigned char *insert_values; /* used by INSERT ... UPDATE */
388
uchar *record[2]; /* Pointer to records */
389
uchar *write_row_record; /* Used as optimisation in
391
uchar *insert_values; /* used by INSERT ... UPDATE */
403
393
Map of keys that can be used to retrieve all data from this table
404
394
needed by the query without reading the row.
426
416
Field *next_number_field; /* Set if next_number is activated */
427
417
Field *found_next_number_field; /* Set on open */
428
418
Field_timestamp *timestamp_field;
429
Field **vfield; /* Pointer to virtual fields*/
431
420
TableList *pos_in_table_list;/* Element referring to this table */
433
422
const char *alias; /* alias or table name */
434
unsigned char *null_flags;
435
424
my_bitmap_map *bitmap_init_value;
436
425
MY_BITMAP def_read_set, def_write_set, tmp_set; /* containers */
437
426
MY_BITMAP *read_set, *write_set; /* Active column sets */
442
431
Temporary tables:
444
table->query_id is set to session->query_id for the duration of a statement
433
table->query_id is set to thd->query_id for the duration of a statement
445
434
and is reset to 0 once it is closed by the same statement. A non-zero
446
435
table->query_id means that a statement is using the table even if it's
447
436
not the current statement (table is in use by some outer statement).
449
438
Non-temporary tables:
451
Under pre-locked or LOCK TABLES mode: query_id is set to session->query_id
440
Under pre-locked or LOCK TABLES mode: query_id is set to thd->query_id
452
441
for the duration of a statement and is reset to 0 once it is closed by
453
442
the same statement. A non-zero query_id is used to control which tables
454
443
in the list of pre-opened and locked tables are actually being used.
492
481
timestamp_auto_set_type timestamp_field_type;
493
482
table_map map; /* ID bit of table (1,2,4,8,16...) */
495
uint32_t lock_position; /* Position in DRIZZLE_LOCK.table */
496
uint32_t lock_data_start; /* Start pos. in DRIZZLE_LOCK.locks */
497
uint32_t lock_count; /* Number of locks */
484
uint lock_position; /* Position in DRIZZLE_LOCK.table */
485
uint lock_data_start; /* Start pos. in DRIZZLE_LOCK.locks */
486
uint lock_count; /* Number of locks */
498
487
uint tablenr,used_fields;
499
uint32_t temp_pool_slot; /* Used by intern temp tables */
488
uint temp_pool_slot; /* Used by intern temp tables */
500
489
uint status; /* What's in record[0] */
501
490
/* number of select if it is derived table */
502
uint32_t derived_select_number;
491
uint derived_select_number;
503
492
int current_lock; /* Type of lock on table */
504
493
bool copy_blobs; /* copy_blobs when storing */
561
550
void reset_item_list(List<Item> *item_list) const;
562
551
void clear_column_bitmaps(void);
563
552
void prepare_for_position(void);
564
void mark_columns_used_by_index_no_reset(uint32_t index, MY_BITMAP *map);
565
void mark_columns_used_by_index(uint32_t index);
553
void mark_columns_used_by_index_no_reset(uint index, MY_BITMAP *map);
554
void mark_columns_used_by_index(uint index);
566
555
void restore_column_maps_after_mark_index();
567
556
void mark_auto_increment_column(void);
568
557
void mark_columns_needed_for_update(void);
569
558
void mark_columns_needed_for_delete(void);
570
559
void mark_columns_needed_for_insert(void);
571
void mark_virtual_columns(void);
572
560
inline void column_bitmaps_set(MY_BITMAP *read_set_arg,
573
561
MY_BITMAP *write_set_arg)
702
690
const char* table_name;
703
691
ST_FIELD_INFO *fields_info;
704
692
/* Create information_schema table */
705
Table *(*create_table) (Session *session, TableList *table_list);
693
Table *(*create_table) (THD *thd, TableList *table_list);
706
694
/* Fill table with data */
707
int (*fill_table) (Session *session, TableList *tables, COND *cond);
695
int (*fill_table) (THD *thd, TableList *tables, COND *cond);
708
696
/* Handle fileds for old SHOW */
709
int (*old_format) (Session *session, struct ST_SCHEMA_TABLE *schema_table);
710
int (*process_table) (Session *session, TableList *tables, Table *table,
697
int (*old_format) (THD *thd, struct ST_SCHEMA_TABLE *schema_table);
698
int (*process_table) (THD *thd, TableList *tables, Table *table,
711
699
bool res, LEX_STRING *db_name, LEX_STRING *table_name);
712
700
int idx_field1, idx_field2;
714
uint32_t i_s_requested_object; /* the object we need to open(Table | VIEW) */
702
uint i_s_requested_object; /* the object we need to open(Table | VIEW) */