MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
structs.h
1 #ifndef STRUCTS_INCLUDED
2 #define STRUCTS_INCLUDED
3 
4 /* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
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; version 2 of the License.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software Foundation,
17  51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
18 
19 
20 
21 /* The old structures from unireg */
22 
23 #include "sql_plugin.h" /* plugin_ref */
24 #include "sql_const.h" /* MAX_REFLENGTH */
25 #include "my_time.h" /* enum_mysql_timestamp_type */
26 #include "thr_lock.h" /* thr_lock_type */
27 #include "my_base.h" /* ha_rows, ha_key_alg */
28 
29 struct TABLE;
30 class Field;
31 
32 class THD;
33 
34 typedef struct st_date_time_format {
35  uchar positions[8];
36  char time_separator; /* Separator between hour and minute */
37  uint flag; /* For future */
38  LEX_STRING format;
40 
41 
42 typedef struct st_keyfile_info { /* used with ha_info() */
43  uchar ref[MAX_REFLENGTH]; /* Pointer to current row */
44  uchar dupp_ref[MAX_REFLENGTH]; /* Pointer to dupp row */
45  uint ref_length; /* Length of ref (1-8) */
46  uint block_size; /* index block size */
47  File filenr; /* (uniq) filenr for table */
48  ha_rows records; /* Records i datafilen */
49  ha_rows deleted; /* Deleted records */
50  ulonglong data_file_length; /* Length off data file */
51  ulonglong max_data_file_length; /* Length off data file */
52  ulonglong index_file_length;
53  ulonglong max_index_file_length;
54  ulonglong delete_length; /* Free bytes */
55  ulonglong auto_increment_value;
56  int errkey,sortkey; /* Last errorkey and sorted by */
57  time_t create_time; /* When table was created */
58  time_t check_time;
59  time_t update_time;
60  ulong mean_rec_length; /* physical reclength */
61 } KEYFILE_INFO;
62 
63 
64 class KEY_PART_INFO { /* Info about a key part */
65 public:
66  Field *field;
67  uint offset; /* offset in record (from 0) */
68  uint null_offset; /* Offset to null_bit in record */
69  /* Length of key part in bytes, excluding NULL flag and length bytes */
70  uint16 length;
71  /*
72  Number of bytes required to store the keypart value. This may be
73  different from the "length" field as it also counts
74  - possible NULL-flag byte (see HA_KEY_NULL_LENGTH)
75  - possible HA_KEY_BLOB_LENGTH bytes needed to store actual value length.
76  */
77  uint16 store_length;
78  uint16 key_type;
79  uint16 fieldnr; /* Fieldnum in UNIREG */
80  uint16 key_part_flag; /* 0 or HA_REVERSE_SORT */
81  uint8 type;
82  uint8 null_bit; /* Position to null_bit */
83  void init_from_field(Field *fld);
84  void init_flags();
85 };
86 
87 
88 typedef struct st_key {
90  uint key_length;
92  ulong flags;
94  ulong actual_flags;
106  uint block_size;
107  enum ha_key_alg algorithm;
112  union
113  {
118  };
119  KEY_PART_INFO *key_part;
121  char *name;
127  ulong *rec_per_key;
128  union {
129  int bdb_return_if_eq;
130  } handler;
131  TABLE *table;
132  LEX_STRING comment;
133 } KEY;
134 
135 
136 struct st_join_table;
137 
138 typedef struct st_reginfo { /* Extra info about reg */
139  struct st_join_table *join_tab; /* Used by SELECT() */
140  enum thr_lock_type lock_type; /* How database is used */
141  bool not_exists_optimize;
142  /*
143  TRUE <=> range optimizer found that there is no rows satisfying
144  table conditions.
145  */
146  bool impossible_range;
147 } REGINFO;
148 
149 
150 /*
151  Originally MySQL used MYSQL_TIME structure inside server only, but since
152  4.1 it's exported to user in the new client API. Define aliases for
153  new names to keep existing code simple.
154 */
155 
156 typedef enum enum_mysql_timestamp_type timestamp_type;
157 
158 
159 typedef struct {
160  ulong year,month,day,hour;
161  ulonglong minute,second,second_part;
162  bool neg;
163 } INTERVAL;
164 
165 
167  const char *format_name;
168  const char *date_format;
169  const char *datetime_format;
170  const char *time_format;
172 
173 extern const char *show_comp_option_name[];
174 
175 typedef int *(*update_var)(THD *, struct st_mysql_show_var *);
176 
177 typedef struct st_lex_user {
178  LEX_STRING user, host, password, plugin, auth;
179  bool uses_identified_by_clause;
180  bool uses_identified_with_clause;
181  bool uses_authentication_string_clause;
182  bool uses_identified_by_password_clause;
183 } LEX_USER;
184 
185 /*
186  This structure specifies the maximum amount of resources which
187  can be consumed by each account. Zero value of a member means
188  there is no limit.
189 */
190 typedef struct user_resources {
191  /* Maximum number of queries/statements per hour. */
192  uint questions;
193  /*
194  Maximum number of updating statements per hour (which statements are
195  updating is defined by sql_command_flags array).
196  */
197  uint updates;
198  /* Maximum number of connections established per hour. */
199  uint conn_per_hour;
200  /* Maximum number of concurrent connections. */
201  uint user_conn;
202  /*
203  Values of this enum and specified_limits member are used by the
204  parser to store which user limits were specified in GRANT statement.
205  */
206  enum {QUERIES_PER_HOUR= 1, UPDATES_PER_HOUR= 2, CONNECTIONS_PER_HOUR= 4,
207  USER_CONNECTIONS= 8};
208  uint specified_limits;
210 
211 
212 /*
213  This structure is used for counting resources consumed and for checking
214  them against specified user limits.
215 */
216 typedef struct user_conn {
217  /*
218  Pointer to user+host key (pair separated by '\0') defining the entity
219  for which resources are counted (By default it is user account thus
220  priv_user/priv_host pair is used. If --old-style-user-limits option
221  is enabled, resources are counted for each user+host separately).
222  */
223  char *user;
224  /* Pointer to host part of the key. */
225  char *host;
230  ulonglong reset_utime;
231  /* Total length of the key. */
232  uint len;
233  /* Current amount of concurrent connections for this account. */
234  uint connections;
235  /*
236  Current number of connections per hour, number of updating statements
237  per hour and total number of statements per hour for this account.
238  */
239  uint conn_per_hour, updates, questions;
240  /* Maximum amount of resources which account is allowed to consume. */
242 } USER_CONN;
243 
244  /* Bits in form->update */
245 #define REG_MAKE_DUPP 1 /* Make a copy of record when read */
246 #define REG_NEW_RECORD 2 /* Write a new record if not found */
247 #define REG_UPDATE 4 /* Uppdate record */
248 #define REG_DELETE 8 /* Delete found record */
249 #define REG_PROG 16 /* User is updating database */
250 #define REG_CLEAR_AFTER_WRITE 32
251 #define REG_MAY_BE_UPDATED 64
252 #define REG_AUTO_UPDATE 64 /* Used in D-forms for scroll-tables */
253 #define REG_OVERWRITE 128
254 #define REG_SKIP_DUP 256
255 
263 #define STATUS_GARBAGE 1
264 
268 #define STATUS_NOT_FOUND 2
269 
270 #define STATUS_UPDATED 16
271 
275 #define STATUS_NULL_ROW 32
276 
277 #define STATUS_DELETED 64
278 
279 /*
280  Such interval is "discrete": it is the set of
281  { auto_inc_interval_min + k * increment,
282  0 <= k <= (auto_inc_interval_values-1) }
283  Where "increment" is maintained separately by the user of this class (and is
284  currently only thd->variables.auto_increment_increment).
285  It mustn't derive from Sql_alloc, because SET INSERT_ID needs to
286  allocate memory which must stay allocated for use by the next statement.
287 */
289 private:
290  ulonglong interval_min;
291  ulonglong interval_values;
292  ulonglong interval_max; // excluded bound. Redundant.
293 public:
294  Discrete_interval *next; // used when linked into Discrete_intervals_list
295 
297  bool in_range(const ulonglong value) const
298  {
299  return ((value >= interval_min) && (value < interval_max));
300  }
301 
302  void replace(ulonglong start, ulonglong val, ulonglong incr)
303  {
304  interval_min= start;
305  interval_values= val;
306  interval_max= (val == ULONGLONG_MAX) ? val : start + val * incr;
307  }
308  Discrete_interval(ulonglong start, ulonglong val, ulonglong incr) :
309  next(NULL) { replace(start, val, incr); };
310  Discrete_interval() : next(NULL) { replace(0, 0, 0); };
311  ulonglong minimum() const { return interval_min; };
312  ulonglong values() const { return interval_values; };
313  ulonglong maximum() const { return interval_max; };
314  /*
315  If appending [3,5] to [1,2], we merge both in [1,5] (they should have the
316  same increment for that, user of the class has to ensure that). That is
317  just a space optimization. Returns 0 if merge succeeded.
318  */
319  bool merge_if_contiguous(ulonglong start, ulonglong val, ulonglong incr)
320  {
321  if (interval_max == start)
322  {
323  if (val == ULONGLONG_MAX)
324  {
325  interval_values= interval_max= val;
326  }
327  else
328  {
329  interval_values+= val;
330  interval_max= start + val * incr;
331  }
332  return 0;
333  }
334  return 1;
335  };
336 };
337 
340 
351 #define DISCRETE_INTERVAL_LIST_HAS_MAX_ONE_ELEMENT 1
352 
353 private:
358  Discrete_interval first_interval;
359  Discrete_interval *head;
360  Discrete_interval *tail;
367  Discrete_interval *current;
368  uint elements;
369  void operator=(Discrete_intervals_list &); // prevent use of this
370  bool append(Discrete_interval *new_interval)
371  {
372  if (unlikely(new_interval == NULL))
373  return true;
374  DBUG_PRINT("info",("adding new auto_increment interval"));
375  if (head == NULL)
376  head= current= new_interval;
377  else
378  tail->next= new_interval;
379  tail= new_interval;
380  elements++;
381  return false;
382  }
383  void copy_shallow(const Discrete_intervals_list *other)
384  {
385  const Discrete_interval *o_first_interval= &other->first_interval;
386  first_interval= other->first_interval;
387  head= other->head == o_first_interval ? &first_interval : other->head;
388  tail= other->tail == o_first_interval ? &first_interval : other->tail;
389  current=
390  other->current == o_first_interval ? &first_interval : other->current;
391  elements= other->elements;
392  }
394  { copy_shallow(&other); }
395 
396 public:
398  : head(NULL), tail(NULL), current(NULL), elements(0) {}
399  void empty()
400  {
401  if (head)
402  {
403  // first element, not on heap, should not be delete-d; start with next:
404  for (Discrete_interval *i= head->next; i;)
405  {
406 #ifdef DISCRETE_INTERVAL_LIST_HAS_MAX_ONE_ELEMENT
407  DBUG_ASSERT(0);
408 #endif
409  Discrete_interval *next= i->next;
410  delete i;
411  i= next;
412  }
413  }
414  head= tail= current= NULL;
415  elements= 0;
416  }
417  void swap(Discrete_intervals_list *other)
418  {
419  const Discrete_intervals_list tmp(*other);
420  other->copy_shallow(this);
421  copy_shallow(&tmp);
422  }
423  const Discrete_interval *get_next()
424  {
425  const Discrete_interval *tmp= current;
426  if (current != NULL)
427  current= current->next;
428  return tmp;
429  }
430  ~Discrete_intervals_list() { empty(); };
440  bool append(ulonglong start, ulonglong val, ulonglong incr)
441  {
442  // If there are no intervals, add one.
443  if (head == NULL)
444  {
445  first_interval.replace(start, val, incr);
446  return append(&first_interval);
447  }
448  // If this interval can be merged with previous, do that.
449  if (tail->merge_if_contiguous(start, val, incr) == 0)
450  return false;
451  // If this interval cannot be merged, append it.
452 #ifdef DISCRETE_INTERVAL_LIST_HAS_MAX_ONE_ELEMENT
453  /*
454  We cannot create yet another interval as we already contain one. This
455  situation can happen. Assume innodb_autoinc_lock_mode>=1 and
456  CREATE TABLE T(A INT AUTO_INCREMENT PRIMARY KEY) ENGINE=INNODB;
457  INSERT INTO T VALUES (NULL),(NULL),(1025),(NULL);
458  Then InnoDB will reserve [1,4] (because of 4 rows) then
459  [1026,1026]. Only the first interval is important for
460  statement-based binary logging as it tells the starting point. So we
461  ignore the second interval:
462  */
463  return false;
464 #else
465  return append(new Discrete_interval(start, val, incr));
466 #endif
467  }
468  ulonglong minimum() const { return (head ? head->minimum() : 0); };
469  ulonglong maximum() const { return (head ? tail->maximum() : 0); };
470  uint nb_elements() const { return elements; }
471 };
472 
473 #endif /* STRUCTS_INCLUDED */