~drizzle-trunk/drizzle/development

390.1.2 by Monty Taylor
Fixed copyright headers in drizzled/
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
 */
1 by brian
clean slate
20
21
/* The old structures from unireg */
22
481.1.16 by Monty Taylor
Merged iocache.h addition.
23
#include <mysys/iocache.h>
24
327.1.1 by Brian Aker
First pass in encapsulating table (it is now an object, no longer a structure).
25
class Table;
1 by brian
clean slate
26
class Field;
27
28
typedef struct st_date_time_format {
481 by Brian Aker
Remove all of uchar.
29
  unsigned char positions[8];
1 by brian
clean slate
30
  char  time_separator;			/* Separator between hour and minute */
482 by Brian Aker
Remove uint.
31
  uint32_t flag;				/* For future */
1 by brian
clean slate
32
  LEX_STRING format;
33
} DATE_TIME_FORMAT;
34
35
36
typedef struct st_keyfile_info {	/* used with ha_info() */
481 by Brian Aker
Remove all of uchar.
37
  unsigned char ref[MAX_REFLENGTH];		/* Pointer to current row */
38
  unsigned char dupp_ref[MAX_REFLENGTH];	/* Pointer to dupp row */
482 by Brian Aker
Remove uint.
39
  uint32_t ref_length;			/* Length of ref (1-8) */
40
  uint32_t block_size;			/* index block size */
1 by brian
clean slate
41
  File filenr;				/* (uniq) filenr for table */
42
  ha_rows records;			/* Records i datafilen */
43
  ha_rows deleted;			/* Deleted records */
151 by Brian Aker
Ulonglong to uint64_t
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;
1 by brian
clean slate
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;
520.1.16 by Brian Aker
More test updates (one ulong fix)
54
  uint64_t mean_rec_length;		/* physical reclength */
1 by brian
clean slate
55
} KEYFILE_INFO;
56
57
58
typedef struct st_key_part_info {	/* Info about a key part */
59
  Field *field;
60
  uint	offset;				/* offset in record (from 0) */
61
  uint	null_offset;			/* Offset to null_bit in record */
62
  /* Length of key part in bytes, excluding NULL flag and length bytes */
206 by Brian Aker
Removed final uint dead types.
63
  uint16_t length;
1 by brian
clean slate
64
  /*
65
    Number of bytes required to store the keypart value. This may be
66
    different from the "length" field as it also counts
67
     - possible NULL-flag byte (see HA_KEY_NULL_LENGTH) [if null_bit != 0,
68
       the first byte stored at offset is 1 if null, 0 if non-null; the
69
       actual value is stored from offset+1].
70
     - possible HA_KEY_BLOB_LENGTH bytes needed to store actual value length.
71
  */
206 by Brian Aker
Removed final uint dead types.
72
  uint16_t store_length;
73
  uint16_t key_type;
74
  uint16_t fieldnr;			/* Fieldnum in UNIREG (1,2,3,...) */
75
  uint16_t key_part_flag;			/* 0 or HA_REVERSE_SORT */
76
  uint8_t type;
77
  uint8_t null_bit;			/* Position to null_bit */
1 by brian
clean slate
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 */
482 by Brian Aker
Remove uint.
85
  uint32_t  extra_length;
1 by brian
clean slate
86
  uint	usable_key_parts;		/* Should normally be = key_parts */
482 by Brian Aker
Remove uint.
87
  uint32_t  block_size;
1 by brian
clean slate
88
  enum  ha_key_alg algorithm;
89
  KEY_PART_INFO *key_part;
90
  char	*name;				/* Name of key */
91
  /*
92
    Array of AVG(#records with the same field value) for 1st ... Nth key part.
93
    0 means 'not known'.
94
    For temporary heap tables this member is NULL.
95
  */
96
  ulong *rec_per_key;
327.1.1 by Brian Aker
First pass in encapsulating table (it is now an object, no longer a structure).
97
  Table *table;
1 by brian
clean slate
98
  LEX_STRING comment;
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() */
106
  enum thr_lock_type lock_type;		/* How database is used */
107
  bool not_exists_optimize;
108
  bool impossible_range;
109
} REGINFO;
110
111
112
struct st_read_record;				/* For referense later */
113
class SQL_SELECT;
520.1.21 by Brian Aker
THD -> Session rename
114
class Session;
1 by brian
clean slate
115
class handler;
116
struct st_join_table;
117
118
typedef struct st_read_record {			/* Parameter to read_record */
327.1.1 by Brian Aker
First pass in encapsulating table (it is now an object, no longer a structure).
119
  Table *table;			/* Head-form */
1 by brian
clean slate
120
  handler *file;
327.1.1 by Brian Aker
First pass in encapsulating table (it is now an object, no longer a structure).
121
  Table **forms;			/* head and ref forms */
1 by brian
clean slate
122
  int (*read_record)(struct st_read_record *);
520.1.22 by Brian Aker
Second pass of thd cleanup
123
  Session *session;
1 by brian
clean slate
124
  SQL_SELECT *select;
482 by Brian Aker
Remove uint.
125
  uint32_t cache_records;
126
  uint32_t ref_length,struct_length,reclength,rec_cache_size,error_offset;
127
  uint32_t index;
481 by Brian Aker
Remove all of uchar.
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;
1 by brian
clean slate
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 {
520.1.16 by Brian Aker
More test updates (one ulong fix)
139
  uint32_t year;
140
  uint32_t month;
141
  uint32_t day;
142
  uint32_t hour;
151 by Brian Aker
Ulonglong to uint64_t
143
  uint64_t minute,second,second_part;
1 by brian
clean slate
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
520.1.21 by Brian Aker
THD -> Session rename
159
typedef int *(*update_var)(Session *, struct st_mysql_show_var *);
1 by brian
clean slate
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. */
482 by Brian Aker
Remove uint.
172
  uint32_t questions;
1 by brian
clean slate
173
  /*
174
     Maximum number of updating statements per hour (which statements are
175
     updating is defined by sql_command_flags array).
176
  */
482 by Brian Aker
Remove uint.
177
  uint32_t updates;
1 by brian
clean slate
178
  /* Maximum number of connections established per hour. */
482 by Brian Aker
Remove uint.
179
  uint32_t conn_per_hour;
1 by brian
clean slate
180
  /* Maximum number of concurrent connections. */
482 by Brian Aker
Remove uint.
181
  uint32_t user_conn;
1 by brian
clean slate
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};
482 by Brian Aker
Remove uint.
188
  uint32_t specified_limits;
1 by brian
clean slate
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
  */
151 by Brian Aker
Ulonglong to uint64_t
210
  uint64_t reset_utime;
1 by brian
clean slate
211
  /* Total length of the key. */
482 by Brian Aker
Remove uint.
212
  uint32_t len;
1 by brian
clean slate
213
  /* Current amount of concurrent connections for this account. */
482 by Brian Aker
Remove uint.
214
  uint32_t connections;
1 by brian
clean slate
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
  */
482 by Brian Aker
Remove uint.
219
  uint32_t conn_per_hour, updates, questions;
1 by brian
clean slate
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
235
236
	/* Bits in form->status */
237
#define STATUS_NO_RECORD	(1+2)	/* Record isn't usably */
238
#define STATUS_GARBAGE		1
239
#define STATUS_NOT_FOUND	2	/* No record in database when needed */
240
#define STATUS_NO_PARENT	4	/* Parent record wasn't found */
241
#define STATUS_NOT_READ		8	/* Record isn't read */
242
#define STATUS_UPDATED		16	/* Record is updated by formula */
243
#define STATUS_NULL_ROW		32	/* table->null_row is set */
244
#define STATUS_DELETED		64
245
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
520.1.22 by Brian Aker
Second pass of thd cleanup
251
  currently only session->variables.auto_increment_increment).
1 by brian
clean slate
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:
151 by Brian Aker
Ulonglong to uint64_t
257
  uint64_t interval_min;
258
  uint64_t interval_values;
259
  uint64_t  interval_max;    // excluded bound. Redundant.
1 by brian
clean slate
260
public:
261
  Discrete_interval *next;    // used when linked into Discrete_intervals_list
151 by Brian Aker
Ulonglong to uint64_t
262
  void replace(uint64_t start, uint64_t val, uint64_t incr)
1 by brian
clean slate
263
  {
264
    interval_min=    start;
265
    interval_values= val;
163 by Brian Aker
Merge Monty's code.
266
    interval_max=    (val == UINT64_MAX) ? val : start + val * incr;
1 by brian
clean slate
267
  }
151 by Brian Aker
Ulonglong to uint64_t
268
  Discrete_interval(uint64_t start, uint64_t val, uint64_t incr) :
509.2.6 by Monty Taylor
Cleaned up class definiton style issues.
269
    interval_min(start), interval_values(val),
270
    interval_max((val == UINT64_MAX) ? val : start + val * incr),
271
    next(NULL)
272
  {};
273
  Discrete_interval() :
274
    interval_min(0), interval_values(0),
275
    interval_max(0), next(NULL)
276
  {};
151 by Brian Aker
Ulonglong to uint64_t
277
  uint64_t minimum() const { return interval_min;    };
278
  uint64_t values()  const { return interval_values; };
279
  uint64_t maximum() const { return interval_max;    };
1 by brian
clean slate
280
  /*
281
    If appending [3,5] to [1,2], we merge both in [1,5] (they should have the
282
    same increment for that, user of the class has to ensure that). That is
283
    just a space optimization. Returns 0 if merge succeeded.
284
  */
151 by Brian Aker
Ulonglong to uint64_t
285
  bool merge_if_contiguous(uint64_t start, uint64_t val, uint64_t incr)
1 by brian
clean slate
286
  {
287
    if (interval_max == start)
288
    {
163 by Brian Aker
Merge Monty's code.
289
      if (val == UINT64_MAX)
1 by brian
clean slate
290
      {
291
        interval_values=   interval_max= val;
292
      }
293
      else
294
      {
295
        interval_values+=  val;
296
        interval_max=      start + val * incr;
297
      }
298
      return 0;
299
    }
300
    return 1;
301
  };
302
};
303
304
/* List of Discrete_interval objects */
305
class Discrete_intervals_list {
306
private:
307
  Discrete_interval        *head;
308
  Discrete_interval        *tail;
309
  /*
310
    When many intervals are provided at the beginning of the execution of a
311
    statement (in a replication slave or SET INSERT_ID), "current" points to
312
    the interval being consumed by the thread now (so "current" goes from
313
    "head" to "tail" then to NULL).
314
  */
315
  Discrete_interval        *current;
482 by Brian Aker
Remove uint.
316
  uint32_t                  elements; // number of elements
1 by brian
clean slate
317
318
  /* helper function for copy construct and assignment operator */
319
  void copy_(const Discrete_intervals_list& from)
320
  {
321
    for (Discrete_interval *i= from.head; i; i= i->next)
322
    {
323
      Discrete_interval j= *i;
324
      append(&j);
325
    }
326
  }
327
public:
509.2.6 by Monty Taylor
Cleaned up class definiton style issues.
328
  Discrete_intervals_list() :
329
    head(NULL), tail(NULL),
330
    current(NULL), elements(0) {};
331
  Discrete_intervals_list(const Discrete_intervals_list& from) :
332
    head(NULL), tail(NULL),
333
    current(NULL), elements(0)
1 by brian
clean slate
334
  {
335
    copy_(from);
336
  }
509.2.6 by Monty Taylor
Cleaned up class definiton style issues.
337
  Discrete_intervals_list& operator=(const Discrete_intervals_list& from)
1 by brian
clean slate
338
  {
339
    empty();
340
    copy_(from);
509.2.6 by Monty Taylor
Cleaned up class definiton style issues.
341
    return *this;
1 by brian
clean slate
342
  }
343
  void empty_no_free()
344
  {
345
    head= current= NULL;
346
    elements= 0;
347
  }
348
  void empty()
349
  {
350
    for (Discrete_interval *i= head; i;)
351
    {
352
      Discrete_interval *next= i->next;
353
      delete i;
354
      i= next;
355
    }
356
    empty_no_free();
357
  }
358
359
  const Discrete_interval* get_next()
360
  {
361
    Discrete_interval *tmp= current;
362
    if (current != NULL)
363
      current= current->next;
364
    return tmp;
365
  }
366
  ~Discrete_intervals_list() { empty(); };
151 by Brian Aker
Ulonglong to uint64_t
367
  bool append(uint64_t start, uint64_t val, uint64_t incr);
1 by brian
clean slate
368
  bool append(Discrete_interval *interval);
151 by Brian Aker
Ulonglong to uint64_t
369
  uint64_t minimum()     const { return (head ? head->minimum() : 0); };
370
  uint64_t maximum()     const { return (head ? tail->maximum() : 0); };
482 by Brian Aker
Remove uint.
371
  uint32_t      nb_elements() const { return elements; }
1 by brian
clean slate
372
};