~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/structs.h

  • Committer: Daniel Nichter
  • Date: 2011-10-23 16:01:37 UTC
  • mto: This revision was merged to the branch mainline in revision 2448.
  • Revision ID: daniel@percona.com-20111023160137-7ac3blgz8z4tf8za
Add Administration Getting Started and Logging.  Capitalize SQL clause keywords.

Show diffs side-by-side

added added

removed removed

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