~ubuntu-branches/debian/squeeze/mysql-5.1/squeeze

« back to all changes in this revision

Viewing changes to sql/ha_partition.h

  • Committer: Package Import Robot
  • Author(s): Moritz Muehlenhoff
  • Date: 2014-01-14 10:40:30 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20140114104030-44alii0hx3x3g41y
Tags: 5.1.73-1
* New upstream release
  http://dev.mysql.com/doc/relnotes/mysql/5.1/en/news-5-1-73.html
* Update patches
* Disable flaky test rpl.rpl_innodb_bug28430 breaking the build. It's  marked
  as experimental by upstream and the internet is full of reports about it's
  unrelialibity

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright 2005-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
1
/*
 
2
   Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
2
3
 
3
4
  This program is free software; you can redistribute it and/or modify
4
5
  it under the terms of the GNU General Public License as published by
11
12
 
12
13
  You should have received a copy of the GNU General Public License
13
14
  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
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
 
16
*/
15
17
 
16
18
#ifdef __GNUC__
17
19
#pragma interface                               /* gcc class implementation */
44
46
typedef struct st_ha_data_partition
45
47
{
46
48
  ulonglong next_auto_inc_val;                 /**< first non reserved value */
 
49
  pthread_mutex_t LOCK_auto_inc;
47
50
  bool auto_inc_initialized;
48
51
} HA_DATA_PARTITION;
49
52
 
53
56
                                        HA_CAN_FULLTEXT | \
54
57
                                        HA_DUPLICATE_POS | \
55
58
                                        HA_CAN_SQL_HANDLER | \
56
 
                                        HA_CAN_INSERT_DELAYED | \
57
 
                                        HA_PRIMARY_KEY_REQUIRED_FOR_POSITION)
 
59
                                        HA_CAN_INSERT_DELAYED)
 
60
 
 
61
/* First 4 bytes in the .par file is the number of 32-bit words in the file */
 
62
#define PAR_WORD_SIZE 4
 
63
/* offset to the .par file checksum */
 
64
#define PAR_CHECKSUM_OFFSET 4
 
65
/* offset to the total number of partitions */
 
66
#define PAR_NUM_PARTS_OFFSET 8
 
67
/* offset to the engines array */
 
68
#define PAR_ENGINES_OFFSET 12
 
69
 
58
70
class ha_partition :public handler
59
71
{
60
72
private:
71
83
  /* Data for the partition handler */
72
84
  int  m_mode;                          // Open mode
73
85
  uint m_open_test_lock;                // Open test_if_locked
74
 
  char *m_file_buffer;                  // Buffer with names
 
86
  char *m_file_buffer;                  // Content of the .par file 
75
87
  char *m_name_buffer_ptr;              // Pointer to first partition name
76
88
  plugin_ref *m_engine_array;           // Array of types of the handlers
77
89
  handler **m_file;                     // Array of references to handler inst.
133
145
  bool m_is_sub_partitioned;             // Is subpartitioned
134
146
  bool m_ordered_scan_ongoing;
135
147
 
 
148
  /* 
 
149
    If set, this object was created with ha_partition::clone and doesn't
 
150
    "own" the m_part_info structure.
 
151
  */
 
152
  ha_partition *m_is_clone_of;
 
153
  MEM_ROOT *m_clone_mem_root;
 
154
  
136
155
  /*
137
156
    We keep track if all underlying handlers are MyISAM since MyISAM has a
138
157
    great number of extra flags not needed by other handlers.
155
174
  */
156
175
  bool m_extra_cache;
157
176
  uint m_extra_cache_size;
 
177
  /* The same goes for HA_EXTRA_PREPARE_FOR_UPDATE */
 
178
  bool m_extra_prepare_for_update;
 
179
  /* Which partition has active cache */
 
180
  uint m_extra_cache_part_id;
158
181
 
159
182
  void init_handler_variables();
160
183
  /*
165
188
  PARTITION_SHARE *share;               /* Shared lock info */
166
189
#endif
167
190
 
168
 
  /* 
169
 
    TRUE <=> this object was created with ha_partition::clone and doesn't
170
 
    "own" the m_part_info structure.
171
 
  */
172
 
  bool is_clone;
173
191
  bool auto_increment_lock;             /**< lock reading/updating auto_inc */
174
192
  /**
175
193
    Flag to keep the auto_increment lock through out the statement.
182
200
  /** used for prediction of start_bulk_insert rows */
183
201
  enum_monotonicity_info m_part_func_monotonicity_info;
184
202
public:
185
 
  handler *clone(MEM_ROOT *mem_root);
 
203
  handler *clone(const char *name, MEM_ROOT *mem_root);
186
204
  virtual void set_part_info(partition_info *part_info)
187
205
  {
188
206
     m_part_info= part_info;
201
219
  */
202
220
    ha_partition(handlerton *hton, TABLE_SHARE * table);
203
221
    ha_partition(handlerton *hton, partition_info * part_info);
 
222
    ha_partition(handlerton *hton, TABLE_SHARE *share,
 
223
                 partition_info *part_info_arg,
 
224
                 ha_partition *clone_arg,
 
225
                 MEM_ROOT *clone_mem_root_arg);
204
226
   ~ha_partition();
205
227
  /*
206
228
    A partition handler has no characteristics in itself. It only inherits
263
285
    delete_table, rename_table and create uses very similar logic which
264
286
    is packed into this routine.
265
287
  */
266
 
  uint del_ren_cre_table(const char *from, const char *to,
 
288
  int del_ren_cre_table(const char *from, const char *to,
267
289
                         TABLE *table_arg, HA_CREATE_INFO *create_info);
268
290
  /*
269
291
    One method to create the table_name.par file containing the names of the
271
293
    And one method to read it in.
272
294
  */
273
295
  bool create_handler_file(const char *name);
274
 
  bool get_from_handler_file(const char *name, MEM_ROOT *mem_root);
 
296
  bool setup_engine_array(MEM_ROOT *mem_root);
 
297
  bool read_par_file(const char *name);
 
298
  bool get_from_handler_file(const char *name, MEM_ROOT *mem_root,
 
299
                             bool is_clone);
275
300
  bool new_handlers_from_part_info(MEM_ROOT *mem_root);
276
301
  bool create_handlers(MEM_ROOT *mem_root);
277
302
  void clear_handler_file();
448
473
  virtual int index_init(uint idx, bool sorted);
449
474
  virtual int index_end();
450
475
 
 
476
  /**
 
477
    @breif
 
478
    Positions an index cursor to the index specified in the hanlde. Fetches the
 
479
    row if available. If the key value is null, begin at first key of the
 
480
    index.
 
481
  */
 
482
  virtual int index_read_idx_map(uchar *buf, uint index, const uchar *key,
 
483
                                 key_part_map keypart_map,
 
484
                                 enum ha_rkey_function find_flag);
451
485
  /*
452
486
    These methods are used to jump to next or previous entry in the index
453
487
    scan. There are also methods to jump to first and last entry.
483
517
  virtual int read_range_next();
484
518
 
485
519
private:
 
520
  bool init_record_priority_queue();
 
521
  void destroy_record_priority_queue();
486
522
  int common_index_read(uchar * buf, bool have_start_key);
487
523
  int common_first_last(uchar * buf);
488
524
  int partition_scan_set_up(uchar * buf, bool idx_read_flag);
489
525
  int handle_unordered_next(uchar * buf, bool next_same);
490
526
  int handle_unordered_scan_next_partition(uchar * buf);
491
 
  uchar *queue_buf(uint part_id)
492
 
    {
493
 
      return (m_ordered_rec_buffer +
494
 
              (part_id * (m_rec_length + PARTITION_BYTES_IN_POS)));
495
 
    }
496
 
  uchar *rec_buf(uint part_id)
497
 
    {
498
 
      return (queue_buf(part_id) +
499
 
              PARTITION_BYTES_IN_POS);
500
 
    }
501
527
  int handle_ordered_index_scan(uchar * buf, bool reverse_order);
502
528
  int handle_ordered_next(uchar * buf, bool next_same);
503
529
  int handle_ordered_prev(uchar * buf);
519
545
  virtual int extra(enum ha_extra_function operation);
520
546
  virtual int extra_opt(enum ha_extra_function operation, ulong cachesize);
521
547
  virtual int reset(void);
 
548
  /*
 
549
    Do not allow caching of partitioned tables, since we cannot return
 
550
    a callback or engine_data that would work for a generic engine.
 
551
  */
 
552
  virtual my_bool register_query_cache_table(THD *thd, char *table_key,
 
553
                                             uint key_length,
 
554
                                             qc_engine_callback
 
555
                                               *engine_callback,
 
556
                                             ulonglong *engine_data)
 
557
  {
 
558
    *engine_callback= NULL;
 
559
    *engine_data= 0;
 
560
    return FALSE;
 
561
  }
522
562
 
523
563
private:
524
564
  static const uint NO_CURRENT_PART_ID;
766
806
 
767
807
    HA_PRIMARY_KEY_REQUIRED_FOR_POSITION:
768
808
    Does the storage engine need a PK for position?
769
 
    Used with hidden primary key in InnoDB.
770
 
    Hidden primary keys cannot be supported by partitioning, since the
771
 
    partitioning expressions columns must be a part of the primary key.
772
809
    (InnoDB)
773
810
 
774
811
    HA_FILE_BASED is always set for partition handler since we use a
939
976
    DBUG_ASSERT(table_share->ha_data && !auto_increment_lock);
940
977
    if(table_share->tmp_table == NO_TMP_TABLE)
941
978
    {
 
979
      HA_DATA_PARTITION *ha_data= (HA_DATA_PARTITION*) table_share->ha_data;
942
980
      auto_increment_lock= TRUE;
943
 
      pthread_mutex_lock(&table_share->mutex);
 
981
      pthread_mutex_lock(&ha_data->LOCK_auto_inc);
944
982
    }
945
983
  }
946
984
  virtual void unlock_auto_increment()
953
991
    */
954
992
    if(auto_increment_lock && !auto_increment_safe_stmt_log_lock)
955
993
    {
956
 
      pthread_mutex_unlock(&table_share->mutex);
 
994
      HA_DATA_PARTITION *ha_data= (HA_DATA_PARTITION*) table_share->ha_data;
 
995
      pthread_mutex_unlock(&ha_data->LOCK_auto_inc);
957
996
      auto_increment_lock= FALSE;
958
997
    }
959
998
  }