~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table.h

  • Committer: Brian Aker
  • Date: 2008-09-05 22:16:26 UTC
  • mto: This revision was merged to the branch mainline in revision 383.
  • Revision ID: brian@tangent.org-20080905221626-nc631ypag04am60c
Big, fat, UTF-8 patch. This fixes some of the oddities around only one
charset.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 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
 
 */
 
1
/* Copyright (C) 2000-2006 MySQL AB
 
2
 
 
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.
 
6
 
 
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.
 
11
 
 
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 */
 
15
 
20
16
 
21
17
/* Structs that defines the Table */
22
18
 
27
23
#include <drizzled/order.h>
28
24
#include <drizzled/filesort_info.h>
29
25
#include <drizzled/natural_join_column.h>
 
26
#include <drizzled/nested_join.h>
30
27
#include <drizzled/field_iterator.h>
31
 
#include <mysys/hash.h>
32
 
#include <drizzled/handler.h>
33
28
 
34
29
class Item;                             /* Needed by order_st */
35
30
class Item_subselect;
47
42
  INTERNAL_TMP_TABLE, SYSTEM_TMP_TABLE, TMP_TABLE_FRM_FILE_ONLY
48
43
};
49
44
 
50
 
bool mysql_frm_type(Session *session, char *path, enum legacy_db_type *dbt);
 
45
bool mysql_frm_type(THD *thd, char *path, enum legacy_db_type *dbt);
51
46
 
52
47
 
53
48
enum release_type { RELEASE_NORMAL, RELEASE_WAIT_FOR_DROP };
163
158
  KEY  *key_info;                       /* data of keys in database */
164
159
  uint  *blob_field;                    /* Index to blobs in Field arrray*/
165
160
 
166
 
  unsigned char *default_values;                /* row with default values */
 
161
  uchar *default_values;                /* row with default values */
167
162
  LEX_STRING comment;                   /* Comment about table */
168
163
  const CHARSET_INFO *table_charset; /* Default charset of string fields */
169
164
 
197
192
  uint32_t   version, mysql_version;
198
193
  uint32_t   timestamp_offset;          /* Set to offset+1 of record */
199
194
  uint32_t   reclength;                 /* Recordlength */
200
 
  uint32_t   stored_rec_length;         /* Stored record length 
201
 
                                           (no generated-only virtual fields) */
202
195
 
203
196
  plugin_ref db_plugin;                 /* storage engine plugin */
204
197
  inline handlerton *db_type() const    /* table_type for handler */
211
204
  enum ha_choice transactional;
212
205
  enum ha_choice page_checksum;
213
206
 
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 */
 
226
  uint primary_key;
 
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;
 
232
  uchar frm_version;
243
233
  bool null_field_first;
244
234
  bool db_low_byte_first;               /* Portable row format */
245
235
  bool crashed;
272
262
      appropriate values by using table cache key as their source.
273
263
  */
274
264
 
275
 
  void set_table_cache_key(char *key_buff, uint32_t key_length)
 
265
  void set_table_cache_key(char *key_buff, uint key_length)
276
266
  {
277
267
    table_cache_key.str= key_buff;
278
268
    table_cache_key.length= key_length;
302
292
      it should has same life-time as share itself.
303
293
  */
304
294
 
305
 
  void set_table_cache_key(char *key_buff, const char *key, uint32_t key_length)
 
295
  void set_table_cache_key(char *key_buff, const char *key, uint key_length)
306
296
  {
307
297
    memcpy(key_buff, key, key_length);
308
298
    set_table_cache_key(key_buff, key_length);
338
328
  LEX_STRING cset;
339
329
} TABLE_FIELD_W_TYPE;
340
330
 
341
 
bool create_myisam_from_heap(Session *session, Table *table,
 
331
bool create_myisam_from_heap(THD *thd, Table *table,
342
332
                             MI_COLUMNDEF *start_recinfo,
343
333
                             MI_COLUMNDEF **recinfo, 
344
334
                             int error, bool ignore_last_dupp_key_error);
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; }
363
353
 
364
354
  inline bool isNullFieldFirst() { return s->null_field_first; }
370
360
 
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();
384
374
 
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);
386
376
 
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 */
391
381
 
392
382
  handler       *file;
393
383
  Table *next, *prev;
394
384
 
395
 
  Session       *in_use;                        /* Which thread uses this */
 
385
  THD   *in_use;                        /* Which thread uses this */
396
386
  Field **field;                        /* Pointer to fields */
397
387
 
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
 
390
                                           THD::write_row */
 
391
  uchar *insert_values;                  /* used by INSERT ... UPDATE */
402
392
  /* 
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*/
430
419
 
431
420
  TableList *pos_in_table_list;/* Element referring to this table */
432
421
  order_st *group;
433
422
  const char    *alias;                   /* alias or table name */
434
 
  unsigned char         *null_flags;
 
423
  uchar         *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 */
441
430
 
442
431
   Temporary tables:
443
432
 
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).
448
437
 
449
438
   Non-temporary tables:
450
439
 
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...) */
494
483
 
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 */
505
494
 
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)
574
562
  {
668
656
     For string-type columns, this is the maximum number of
669
657
     characters. Otherwise, it is the 'display-length' for the column.
670
658
  */
671
 
  uint32_t field_length;
 
659
  uint field_length;
672
660
  /**
673
661
     This denotes data type for the column. For the most part, there seems to
674
662
     be one entry in the enum for each SQL data type, although there seem to
684
672
     combine them using the bitwise or operator @c |. Both flags are
685
673
     defined in table.h.
686
674
   */
687
 
  uint32_t field_flags;        // Field atributes(maybe_null, signed, unsigned etc.)
 
675
  uint field_flags;        // Field atributes(maybe_null, signed, unsigned etc.)
688
676
  const char* old_name;
689
677
  /**
690
678
     This should be one of @c SKIP_OPEN_TABLE,
691
679
     @c OPEN_FRM_ONLY or @c OPEN_FULL_TABLE.
692
680
  */
693
 
  uint32_t open_method;
 
681
  uint open_method;
694
682
} ST_FIELD_INFO;
695
683
 
696
684
 
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; 
713
701
  bool hidden;
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) */
715
703
};
716
704
 
717
705