~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/structs.h

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

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