~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/structs.h

Moved base64.h to mysys.

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
 
 */
20
 
 
21
 
/* The old structures from unireg */
22
 
 
23
 
class Table;
24
 
class Field;
25
 
 
26
 
typedef struct st_date_time_format {
27
 
  unsigned char positions[8];
28
 
  char  time_separator;                 /* Separator between hour and minute */
29
 
  uint32_t flag;                                /* For future */
30
 
  LEX_STRING format;
31
 
} DATE_TIME_FORMAT;
32
 
 
33
 
 
34
 
typedef struct st_keyfile_info {        /* used with ha_info() */
35
 
  unsigned char ref[MAX_REFLENGTH];             /* Pointer to current row */
36
 
  unsigned char dupp_ref[MAX_REFLENGTH];        /* Pointer to dupp row */
37
 
  uint32_t ref_length;                  /* Length of ref (1-8) */
38
 
  uint32_t block_size;                  /* index block size */
39
 
  File filenr;                          /* (uniq) filenr for table */
40
 
  ha_rows records;                      /* Records i datafilen */
41
 
  ha_rows deleted;                      /* Deleted records */
42
 
  uint64_t data_file_length;            /* Length off data file */
43
 
  uint64_t max_data_file_length;        /* Length off data file */
44
 
  uint64_t index_file_length;
45
 
  uint64_t max_index_file_length;
46
 
  uint64_t delete_length;               /* Free bytes */
47
 
  uint64_t auto_increment_value;
48
 
  int errkey,sortkey;                   /* Last errorkey and sorted by */
49
 
  time_t create_time;                   /* When table was created */
50
 
  time_t check_time;
51
 
  time_t update_time;
52
 
  ulong mean_rec_length;                /* physical reclength */
53
 
} KEYFILE_INFO;
54
 
 
55
 
 
56
 
typedef struct st_key_part_info {       /* Info about a key part */
57
 
  Field *field;
58
 
  uint  offset;                         /* offset in record (from 0) */
59
 
  uint  null_offset;                    /* Offset to null_bit in record */
60
 
  /* Length of key part in bytes, excluding NULL flag and length bytes */
61
 
  uint16_t length;
62
 
  /*
63
 
    Number of bytes required to store the keypart value. This may be
64
 
    different from the "length" field as it also counts
65
 
     - possible NULL-flag byte (see HA_KEY_NULL_LENGTH) [if null_bit != 0,
66
 
       the first byte stored at offset is 1 if null, 0 if non-null; the
67
 
       actual value is stored from offset+1].
68
 
     - possible HA_KEY_BLOB_LENGTH bytes needed to store actual value length.
69
 
  */
70
 
  uint16_t store_length;
71
 
  uint16_t key_type;
72
 
  uint16_t fieldnr;                     /* Fieldnum in UNIREG (1,2,3,...) */
73
 
  uint16_t key_part_flag;                       /* 0 or HA_REVERSE_SORT */
74
 
  uint8_t type;
75
 
  uint8_t null_bit;                     /* Position to null_bit */
76
 
} KEY_PART_INFO ;
77
 
 
78
 
 
79
 
typedef struct st_key {
80
 
  uint  key_length;                     /* Tot length of key */
81
 
  ulong flags;                          /* dupp key and pack flags */
82
 
  uint  key_parts;                      /* How many key_parts */
83
 
  uint32_t  extra_length;
84
 
  uint  usable_key_parts;               /* Should normally be = key_parts */
85
 
  uint32_t  block_size;
86
 
  enum  ha_key_alg algorithm;
87
 
  KEY_PART_INFO *key_part;
88
 
  char  *name;                          /* Name of key */
89
 
  /*
90
 
    Array of AVG(#records with the same field value) for 1st ... Nth key part.
91
 
    0 means 'not known'.
92
 
    For temporary heap tables this member is NULL.
93
 
  */
94
 
  ulong *rec_per_key;
95
 
  Table *table;
96
 
  LEX_STRING comment;
97
 
} KEY;
98
 
 
99
 
 
100
 
struct st_join_table;
101
 
 
102
 
typedef struct st_reginfo {             /* Extra info about reg */
103
 
  struct st_join_table *join_tab;       /* Used by SELECT() */
104
 
  enum thr_lock_type lock_type;         /* How database is used */
105
 
  bool not_exists_optimize;
106
 
  bool impossible_range;
107
 
} REGINFO;
108
 
 
109
 
 
110
 
struct st_read_record;                          /* For referense later */
111
 
class SQL_SELECT;
112
 
class THD;
113
 
class handler;
114
 
struct st_join_table;
115
 
 
116
 
typedef struct st_read_record {                 /* Parameter to read_record */
117
 
  Table *table;                 /* Head-form */
118
 
  handler *file;
119
 
  Table **forms;                        /* head and ref forms */
120
 
  int (*read_record)(struct st_read_record *);
121
 
  THD *thd;
122
 
  SQL_SELECT *select;
123
 
  uint32_t cache_records;
124
 
  uint32_t ref_length,struct_length,reclength,rec_cache_size,error_offset;
125
 
  uint32_t index;
126
 
  unsigned char *ref_pos;                               /* pointer to form->refpos */
127
 
  unsigned char *record;
128
 
  unsigned char *rec_buf;                /* to read field values  after filesort */
129
 
  unsigned char *cache,*cache_pos,*cache_end,*read_positions;
130
 
  IO_CACHE *io_cache;
131
 
  bool print_error, ignore_not_found_rows;
132
 
  struct st_join_table *do_insideout_scan;
133
 
} READ_RECORD;
134
 
 
135
 
 
136
 
typedef struct {
137
 
  ulong year,month,day,hour;
138
 
  uint64_t minute,second,second_part;
139
 
  bool neg;
140
 
} INTERVAL;
141
 
 
142
 
 
143
 
typedef struct st_known_date_time_format {
144
 
  const char *format_name;
145
 
  const char *date_format;
146
 
  const char *datetime_format;
147
 
  const char *time_format;
148
 
} KNOWN_DATE_TIME_FORMAT;
149
 
 
150
 
enum SHOW_COMP_OPTION { SHOW_OPTION_YES, SHOW_OPTION_NO, SHOW_OPTION_DISABLED};
151
 
 
152
 
extern const char *show_comp_option_name[];
153
 
 
154
 
typedef int *(*update_var)(THD *, struct st_mysql_show_var *);
155
 
 
156
 
typedef struct  st_lex_user {
157
 
  LEX_STRING user, host, password;
158
 
} LEX_USER;
159
 
 
160
 
/*
161
 
  This structure specifies the maximum amount of resources which
162
 
  can be consumed by each account. Zero value of a member means
163
 
  there is no limit.
164
 
*/
165
 
typedef struct user_resources {
166
 
  /* Maximum number of queries/statements per hour. */
167
 
  uint32_t questions;
168
 
  /*
169
 
     Maximum number of updating statements per hour (which statements are
170
 
     updating is defined by sql_command_flags array).
171
 
  */
172
 
  uint32_t updates;
173
 
  /* Maximum number of connections established per hour. */
174
 
  uint32_t conn_per_hour;
175
 
  /* Maximum number of concurrent connections. */
176
 
  uint32_t user_conn;
177
 
  /*
178
 
     Values of this enum and specified_limits member are used by the
179
 
     parser to store which user limits were specified in GRANT statement.
180
 
  */
181
 
  enum {QUERIES_PER_HOUR= 1, UPDATES_PER_HOUR= 2, CONNECTIONS_PER_HOUR= 4,
182
 
        USER_CONNECTIONS= 8};
183
 
  uint32_t specified_limits;
184
 
} USER_RESOURCES;
185
 
 
186
 
 
187
 
/*
188
 
  This structure is used for counting resources consumed and for checking
189
 
  them against specified user limits.
190
 
*/
191
 
typedef struct  user_conn {
192
 
  /*
193
 
     Pointer to user+host key (pair separated by '\0') defining the entity
194
 
     for which resources are counted (By default it is user account thus
195
 
     priv_user/priv_host pair is used. If --old-style-user-limits option
196
 
     is enabled, resources are counted for each user+host separately).
197
 
  */
198
 
  char *user;
199
 
  /* Pointer to host part of the key. */
200
 
  char *host;
201
 
  /**
202
 
     The moment of time when per hour counters were reset last time
203
 
     (i.e. start of "hour" for conn_per_hour, updates, questions counters).
204
 
  */
205
 
  uint64_t reset_utime;
206
 
  /* Total length of the key. */
207
 
  uint32_t len;
208
 
  /* Current amount of concurrent connections for this account. */
209
 
  uint32_t connections;
210
 
  /*
211
 
     Current number of connections per hour, number of updating statements
212
 
     per hour and total number of statements per hour for this account.
213
 
  */
214
 
  uint32_t conn_per_hour, updates, questions;
215
 
  /* Maximum amount of resources which account is allowed to consume. */
216
 
  USER_RESOURCES user_resources;
217
 
} USER_CONN;
218
 
 
219
 
        /* Bits in form->update */
220
 
#define REG_MAKE_DUPP           1       /* Make a copy of record when read */
221
 
#define REG_NEW_RECORD          2       /* Write a new record if not found */
222
 
#define REG_UPDATE              4       /* Uppdate record */
223
 
#define REG_DELETE              8       /* Delete found record */
224
 
#define REG_PROG                16      /* User is updating database */
225
 
#define REG_CLEAR_AFTER_WRITE   32
226
 
#define REG_MAY_BE_UPDATED      64
227
 
#define REG_AUTO_UPDATE         64      /* Used in D-forms for scroll-tables */
228
 
#define REG_OVERWRITE           128
229
 
#define REG_SKIP_DUP            256
230
 
 
231
 
        /* Bits in form->status */
232
 
#define STATUS_NO_RECORD        (1+2)   /* Record isn't usably */
233
 
#define STATUS_GARBAGE          1
234
 
#define STATUS_NOT_FOUND        2       /* No record in database when needed */
235
 
#define STATUS_NO_PARENT        4       /* Parent record wasn't found */
236
 
#define STATUS_NOT_READ         8       /* Record isn't read */
237
 
#define STATUS_UPDATED          16      /* Record is updated by formula */
238
 
#define STATUS_NULL_ROW         32      /* table->null_row is set */
239
 
#define STATUS_DELETED          64
240
 
 
241
 
/*
242
 
  Such interval is "discrete": it is the set of
243
 
  { auto_inc_interval_min + k * increment,
244
 
    0 <= k <= (auto_inc_interval_values-1) }
245
 
  Where "increment" is maintained separately by the user of this class (and is
246
 
  currently only thd->variables.auto_increment_increment).
247
 
  It mustn't derive from Sql_alloc, because SET INSERT_ID needs to
248
 
  allocate memory which must stay allocated for use by the next statement.
249
 
*/
250
 
class Discrete_interval {
251
 
private:
252
 
  uint64_t interval_min;
253
 
  uint64_t interval_values;
254
 
  uint64_t  interval_max;    // excluded bound. Redundant.
255
 
public:
256
 
  Discrete_interval *next;    // used when linked into Discrete_intervals_list
257
 
  void replace(uint64_t start, uint64_t val, uint64_t incr)
258
 
  {
259
 
    interval_min=    start;
260
 
    interval_values= val;
261
 
    interval_max=    (val == UINT64_MAX) ? val : start + val * incr;
262
 
  }
263
 
  Discrete_interval(uint64_t start, uint64_t val, uint64_t incr) :
264
 
    next(NULL) { replace(start, val, incr); };
265
 
  Discrete_interval() : next(NULL) { replace(0, 0, 0); };
266
 
  uint64_t minimum() const { return interval_min;    };
267
 
  uint64_t values()  const { return interval_values; };
268
 
  uint64_t maximum() const { return interval_max;    };
269
 
  /*
270
 
    If appending [3,5] to [1,2], we merge both in [1,5] (they should have the
271
 
    same increment for that, user of the class has to ensure that). That is
272
 
    just a space optimization. Returns 0 if merge succeeded.
273
 
  */
274
 
  bool merge_if_contiguous(uint64_t start, uint64_t val, uint64_t incr)
275
 
  {
276
 
    if (interval_max == start)
277
 
    {
278
 
      if (val == UINT64_MAX)
279
 
      {
280
 
        interval_values=   interval_max= val;
281
 
      }
282
 
      else
283
 
      {
284
 
        interval_values+=  val;
285
 
        interval_max=      start + val * incr;
286
 
      }
287
 
      return 0;
288
 
    }
289
 
    return 1;
290
 
  };
291
 
};
292
 
 
293
 
/* List of Discrete_interval objects */
294
 
class Discrete_intervals_list {
295
 
private:
296
 
  Discrete_interval        *head;
297
 
  Discrete_interval        *tail;
298
 
  /*
299
 
    When many intervals are provided at the beginning of the execution of a
300
 
    statement (in a replication slave or SET INSERT_ID), "current" points to
301
 
    the interval being consumed by the thread now (so "current" goes from
302
 
    "head" to "tail" then to NULL).
303
 
  */
304
 
  Discrete_interval        *current;
305
 
  uint32_t                  elements; // number of elements
306
 
 
307
 
  /* helper function for copy construct and assignment operator */
308
 
  void copy_(const Discrete_intervals_list& from)
309
 
  {
310
 
    for (Discrete_interval *i= from.head; i; i= i->next)
311
 
    {
312
 
      Discrete_interval j= *i;
313
 
      append(&j);
314
 
    }
315
 
  }
316
 
public:
317
 
  Discrete_intervals_list() : head(NULL), current(NULL), elements(0) {};
318
 
  Discrete_intervals_list(const Discrete_intervals_list& from)
319
 
  {
320
 
    copy_(from);
321
 
  }
322
 
  void operator=(const Discrete_intervals_list& from)
323
 
  {
324
 
    empty();
325
 
    copy_(from);
326
 
  }
327
 
  void empty_no_free()
328
 
  {
329
 
    head= current= NULL;
330
 
    elements= 0;
331
 
  }
332
 
  void empty()
333
 
  {
334
 
    for (Discrete_interval *i= head; i;)
335
 
    {
336
 
      Discrete_interval *next= i->next;
337
 
      delete i;
338
 
      i= next;
339
 
    }
340
 
    empty_no_free();
341
 
  }
342
 
 
343
 
  const Discrete_interval* get_next()
344
 
  {
345
 
    Discrete_interval *tmp= current;
346
 
    if (current != NULL)
347
 
      current= current->next;
348
 
    return tmp;
349
 
  }
350
 
  ~Discrete_intervals_list() { empty(); };
351
 
  bool append(uint64_t start, uint64_t val, uint64_t incr);
352
 
  bool append(Discrete_interval *interval);
353
 
  uint64_t minimum()     const { return (head ? head->minimum() : 0); };
354
 
  uint64_t maximum()     const { return (head ? tail->maximum() : 0); };
355
 
  uint32_t      nb_elements() const { return elements; }
356
 
};