~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/structs.h

code clean move Item_func_num1 and Item_func_connection_id to functions directory

Show diffs side-by-side

added added

removed removed

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