1
#ifndef STRUCTS_INCLUDED
2
#define STRUCTS_INCLUDED
4
/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
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; version 2 of the License.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software Foundation,
17
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
21
/* The old structures from unireg */
23
#include "sql_plugin.h" /* plugin_ref */
24
#include "sql_const.h" /* MAX_REFLENGTH */
25
#include "my_time.h" /* enum_mysql_timestamp_type */
26
#include "thr_lock.h" /* thr_lock_type */
27
#include "my_base.h" /* ha_rows, ha_key_alg */
34
typedef struct st_date_time_format {
36
char time_separator; /* Separator between hour and minute */
37
uint flag; /* For future */
42
typedef struct st_keyfile_info { /* used with ha_info() */
43
uchar ref[MAX_REFLENGTH]; /* Pointer to current row */
44
uchar dupp_ref[MAX_REFLENGTH]; /* Pointer to dupp row */
45
uint ref_length; /* Length of ref (1-8) */
46
uint 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
ulonglong data_file_length; /* Length off data file */
51
ulonglong max_data_file_length; /* Length off data file */
52
ulonglong index_file_length;
53
ulonglong max_index_file_length;
54
ulonglong delete_length; /* Free bytes */
55
ulonglong auto_increment_value;
56
int errkey,sortkey; /* Last errorkey and sorted by */
57
time_t create_time; /* When table was created */
60
ulong mean_rec_length; /* physical reclength */
64
class KEY_PART_INFO { /* Info about a key part */
67
uint offset; /* offset in record (from 0) */
68
uint null_offset; /* Offset to null_bit in record */
69
/* Length of key part in bytes, excluding NULL flag and length bytes */
72
Number of bytes required to store the keypart value. This may be
73
different from the "length" field as it also counts
74
- possible NULL-flag byte (see HA_KEY_NULL_LENGTH)
75
- possible HA_KEY_BLOB_LENGTH bytes needed to store actual value length.
79
uint16 fieldnr; /* Fieldnum in UNIREG */
80
uint16 key_part_flag; /* 0 or HA_REVERSE_SORT */
82
uint8 null_bit; /* Position to null_bit */
83
void init_from_field(Field *fld); /** Fill data from given field */
84
void init_flags(); /** Set key_part_flag from field */
88
typedef struct st_key {
89
/** Tot length of key */
91
/** dupp key and pack flags */
93
/** dupp key and pack flags for actual key parts */
95
/** How many key_parts */
96
uint user_defined_key_parts;
97
/** How many key_parts including hidden parts */
98
uint actual_key_parts;
100
Key parts allocated for primary key parts extension but
101
not used due to some reasons(no primary key, duplicated key parts)
103
uint unused_key_parts;
104
/** Should normally be = key_parts */
105
uint usable_key_parts;
107
enum ha_key_alg algorithm;
109
Note that parser is used when the table is opened for use, and
110
parser_name is used when the table is being created.
114
/** Fulltext [pre]parser */
116
/** Fulltext [pre]parser name */
117
LEX_STRING *parser_name;
119
KEY_PART_INFO *key_part;
123
Array of AVG(#records with the same field value) for 1st ... Nth key part.
125
For temporary heap tables this member is NULL.
129
int bdb_return_if_eq;
136
struct st_join_table;
138
typedef struct st_reginfo { /* Extra info about reg */
139
struct st_join_table *join_tab; /* Used by SELECT() */
140
enum thr_lock_type lock_type; /* How database is used */
141
bool not_exists_optimize;
143
TRUE <=> range optimizer found that there is no rows satisfying
146
bool impossible_range;
151
Originally MySQL used MYSQL_TIME structure inside server only, but since
152
4.1 it's exported to user in the new client API. Define aliases for
153
new names to keep existing code simple.
156
typedef enum enum_mysql_timestamp_type timestamp_type;
160
ulong year,month,day,hour;
161
ulonglong minute,second,second_part;
166
typedef struct st_known_date_time_format {
167
const char *format_name;
168
const char *date_format;
169
const char *datetime_format;
170
const char *time_format;
171
} KNOWN_DATE_TIME_FORMAT;
173
extern const char *show_comp_option_name[];
175
typedef int *(*update_var)(THD *, struct st_mysql_show_var *);
177
typedef struct st_lex_user {
178
LEX_STRING user, host, password, plugin, auth;
179
bool uses_identified_by_clause;
180
bool uses_identified_with_clause;
181
bool uses_authentication_string_clause;
182
bool uses_identified_by_password_clause;
186
This structure specifies the maximum amount of resources which
187
can be consumed by each account. Zero value of a member means
190
typedef struct user_resources {
191
/* Maximum number of queries/statements per hour. */
194
Maximum number of updating statements per hour (which statements are
195
updating is defined by sql_command_flags array).
198
/* Maximum number of connections established per hour. */
200
/* Maximum number of concurrent connections. */
203
Values of this enum and specified_limits member are used by the
204
parser to store which user limits were specified in GRANT statement.
206
enum {QUERIES_PER_HOUR= 1, UPDATES_PER_HOUR= 2, CONNECTIONS_PER_HOUR= 4,
207
USER_CONNECTIONS= 8};
208
uint specified_limits;
213
This structure is used for counting resources consumed and for checking
214
them against specified user limits.
216
typedef struct user_conn {
218
Pointer to user+host key (pair separated by '\0') defining the entity
219
for which resources are counted (By default it is user account thus
220
priv_user/priv_host pair is used. If --old-style-user-limits option
221
is enabled, resources are counted for each user+host separately).
224
/* Pointer to host part of the key. */
227
The moment of time when per hour counters were reset last time
228
(i.e. start of "hour" for conn_per_hour, updates, questions counters).
230
ulonglong reset_utime;
231
/* Total length of the key. */
233
/* Current amount of concurrent connections for this account. */
236
Current number of connections per hour, number of updating statements
237
per hour and total number of statements per hour for this account.
239
uint conn_per_hour, updates, questions;
240
/* Maximum amount of resources which account is allowed to consume. */
241
USER_RESOURCES user_resources;
244
/* Bits in form->update */
245
#define REG_MAKE_DUPP 1 /* Make a copy of record when read */
246
#define REG_NEW_RECORD 2 /* Write a new record if not found */
247
#define REG_UPDATE 4 /* Uppdate record */
248
#define REG_DELETE 8 /* Delete found record */
249
#define REG_PROG 16 /* User is updating database */
250
#define REG_CLEAR_AFTER_WRITE 32
251
#define REG_MAY_BE_UPDATED 64
252
#define REG_AUTO_UPDATE 64 /* Used in D-forms for scroll-tables */
253
#define REG_OVERWRITE 128
254
#define REG_SKIP_DUP 256
257
Flags for TABLE::status (maximum 8 bits). Do NOT add new ones.
258
@todo: GARBAGE and NOT_FOUND could be unified. UPDATED and DELETED could be
259
changed to "bool current_row_has_already_been_modified" in the
260
multi_update/delete objects (one such bool per to-be-modified table).
261
@todo aim at removing the status. There should be more local ways.
263
#define STATUS_GARBAGE 1
265
Means we were searching for a row and didn't find it. This is used by
266
storage engines (@see handler::index_read_map()) and the Server layer.
268
#define STATUS_NOT_FOUND 2
269
/// Reserved for use by multi-table update. Means the row has been updated.
270
#define STATUS_UPDATED 16
272
Means that table->null_row is set. This is an artificial NULL-filled row
273
(one example: in outer join, if no match has been found in inner table).
275
#define STATUS_NULL_ROW 32
276
/// Reserved for use by multi-table delete. Means the row has been deleted.
277
#define STATUS_DELETED 64
280
Such interval is "discrete": it is the set of
281
{ auto_inc_interval_min + k * increment,
282
0 <= k <= (auto_inc_interval_values-1) }
283
Where "increment" is maintained separately by the user of this class (and is
284
currently only thd->variables.auto_increment_increment).
285
It mustn't derive from Sql_alloc, because SET INSERT_ID needs to
286
allocate memory which must stay allocated for use by the next statement.
288
class Discrete_interval {
290
ulonglong interval_min;
291
ulonglong interval_values;
292
ulonglong interval_max; // excluded bound. Redundant.
294
Discrete_interval *next; // used when linked into Discrete_intervals_list
296
/// Determine if the given value is within the interval
297
bool in_range(const ulonglong value) const
299
return ((value >= interval_min) && (value < interval_max));
302
void replace(ulonglong start, ulonglong val, ulonglong incr)
305
interval_values= val;
306
interval_max= (val == ULONGLONG_MAX) ? val : start + val * incr;
308
Discrete_interval(ulonglong start, ulonglong val, ulonglong incr) :
309
next(NULL) { replace(start, val, incr); };
310
Discrete_interval() : next(NULL) { replace(0, 0, 0); };
311
ulonglong minimum() const { return interval_min; };
312
ulonglong values() const { return interval_values; };
313
ulonglong maximum() const { return interval_max; };
315
If appending [3,5] to [1,2], we merge both in [1,5] (they should have the
316
same increment for that, user of the class has to ensure that). That is
317
just a space optimization. Returns 0 if merge succeeded.
319
bool merge_if_contiguous(ulonglong start, ulonglong val, ulonglong incr)
321
if (interval_max == start)
323
if (val == ULONGLONG_MAX)
325
interval_values= interval_max= val;
329
interval_values+= val;
330
interval_max= start + val * incr;
338
/// List of Discrete_interval objects
339
class Discrete_intervals_list {
342
Discrete_intervals_list objects are used to remember the
343
intervals of autoincrement values that have been used by the
344
current INSERT statement, so that the values can be written to the
345
binary log. However, the binary log can currently only store the
346
beginning of the first interval (because WL#3404 is not yet
347
implemented). Hence, it is currently not necessary to store
348
anything else than the first interval, in the list. When WL#3404 is
349
implemented, we should change the '# define' below.
351
#define DISCRETE_INTERVAL_LIST_HAS_MAX_ONE_ELEMENT 1
355
To avoid heap allocation in the common case when there is only one
356
interval in the list, we store the first interval here.
358
Discrete_interval first_interval;
359
Discrete_interval *head;
360
Discrete_interval *tail;
362
When many intervals are provided at the beginning of the execution of a
363
statement (in a replication slave or SET INSERT_ID), "current" points to
364
the interval being consumed by the thread now (so "current" goes from
365
"head" to "tail" then to NULL).
367
Discrete_interval *current;
368
uint elements; ///< number of elements
369
void operator=(Discrete_intervals_list &); // prevent use of this
370
bool append(Discrete_interval *new_interval)
372
if (unlikely(new_interval == NULL))
374
DBUG_PRINT("info",("adding new auto_increment interval"));
376
head= current= new_interval;
378
tail->next= new_interval;
383
void copy_shallow(const Discrete_intervals_list *other)
385
const Discrete_interval *o_first_interval= &other->first_interval;
386
first_interval= other->first_interval;
387
head= other->head == o_first_interval ? &first_interval : other->head;
388
tail= other->tail == o_first_interval ? &first_interval : other->tail;
390
other->current == o_first_interval ? &first_interval : other->current;
391
elements= other->elements;
393
Discrete_intervals_list(const Discrete_intervals_list &other)
394
{ copy_shallow(&other); }
397
Discrete_intervals_list()
398
: head(NULL), tail(NULL), current(NULL), elements(0) {}
403
// first element, not on heap, should not be delete-d; start with next:
404
for (Discrete_interval *i= head->next; i;)
406
#ifdef DISCRETE_INTERVAL_LIST_HAS_MAX_ONE_ELEMENT
409
Discrete_interval *next= i->next;
414
head= tail= current= NULL;
417
void swap(Discrete_intervals_list *other)
419
const Discrete_intervals_list tmp(*other);
420
other->copy_shallow(this);
423
const Discrete_interval *get_next()
425
const Discrete_interval *tmp= current;
427
current= current->next;
430
~Discrete_intervals_list() { empty(); };
432
Appends an interval to the list.
434
@param start start of interval
435
@val how many values it contains
436
@param incr what increment between each value
438
@retval false success
440
bool append(ulonglong start, ulonglong val, ulonglong incr)
442
// If there are no intervals, add one.
445
first_interval.replace(start, val, incr);
446
return append(&first_interval);
448
// If this interval can be merged with previous, do that.
449
if (tail->merge_if_contiguous(start, val, incr) == 0)
451
// If this interval cannot be merged, append it.
452
#ifdef DISCRETE_INTERVAL_LIST_HAS_MAX_ONE_ELEMENT
454
We cannot create yet another interval as we already contain one. This
455
situation can happen. Assume innodb_autoinc_lock_mode>=1 and
456
CREATE TABLE T(A INT AUTO_INCREMENT PRIMARY KEY) ENGINE=INNODB;
457
INSERT INTO T VALUES (NULL),(NULL),(1025),(NULL);
458
Then InnoDB will reserve [1,4] (because of 4 rows) then
459
[1026,1026]. Only the first interval is important for
460
statement-based binary logging as it tells the starting point. So we
461
ignore the second interval:
465
return append(new Discrete_interval(start, val, incr));
468
ulonglong minimum() const { return (head ? head->minimum() : 0); };
469
ulonglong maximum() const { return (head ? tail->maximum() : 0); };
470
uint nb_elements() const { return elements; }
473
#endif /* STRUCTS_INCLUDED */