~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/mysql_priv.h

  • Committer: Brian Aker
  • Date: 2008-07-13 22:45:08 UTC
  • Revision ID: brian@tangent.org-20080713224508-hb20z4okblotb39a
longlong replacement

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
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; version 2 of the License.
9
 
 *
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.
14
 
 *
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
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
 
1
/* Copyright (C) 2000-2003 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 */
19
15
 
20
16
/**
21
17
  @file
23
19
  @details
24
20
  Mostly this file is used in the server. But a little part of it is used in
25
21
  mysqlbinlog too (definition of SELECT_DISTINCT and others).
26
 
  The consequence is that 90% of the file is wrapped in \#ifndef DRIZZLE_CLIENT,
 
22
  The consequence is that 90% of the file is wrapped in \#ifndef MYSQL_CLIENT,
27
23
  except the part which must be in the server and in the client.
28
 
 
29
 
  @TODO Name this file better. "priv" could mean private, privileged, privileges.
30
 
*/
31
 
 
32
 
#ifndef DRIZZLE_SERVER_SERVER_INCLUDES_H
33
 
#define DRIZZLE_SERVER_SERVER_INCLUDES_H
34
 
 
35
 
/* Some forward declarations just for the server */
36
 
 
 
24
*/
 
25
 
 
26
#ifndef MYSQL_PRIV_H
 
27
#define MYSQL_PRIV_H
 
28
 
 
29
#ifndef MYSQL_CLIENT
 
30
 
 
31
#include <my_global.h>
 
32
#include <drizzle_version.h>
 
33
#include <my_sys.h>
 
34
#include <my_time.h>
 
35
#include <m_string.h>
 
36
#include <hash.h>
 
37
#include <signal.h>
 
38
#include <thr_lock.h>
 
39
#include <my_base.h>                    /* Needed by field.h */
 
40
#include <queues.h>
 
41
#include "sql_bitmap.h"
 
42
#include "sql_array.h"
 
43
#include "sql_plugin.h"
 
44
#include "scheduler.h"
 
45
 
 
46
#ifdef HAVE_DTRACE
 
47
#define _DTRACE_VERSION 1
 
48
#endif
 
49
#include "probes.h"
 
50
 
 
51
#include <netdb.h>
 
52
 
 
53
/**
 
54
  Query type constants.
 
55
 
 
56
  QT_ORDINARY -- ordinary SQL query.
 
57
  QT_IS -- SQL query to be shown in INFORMATION_SCHEMA (in utf8 and without
 
58
  character set introducers).
 
59
*/
 
60
enum enum_query_type
 
61
{
 
62
  QT_ORDINARY,
 
63
  QT_IS
 
64
};
 
65
 
 
66
/* TODO convert all these three maps to Bitmap classes */
 
67
typedef uint64_t table_map;          /* Used for table bits in join */
 
68
#if MAX_INDEXES <= 64
 
69
typedef Bitmap<64>  key_map;          /* Used for finding keys */
 
70
#else
 
71
typedef Bitmap<((MAX_INDEXES+7)/8*8)> key_map; /* Used for finding keys */
 
72
#endif
 
73
typedef ulong nesting_map;  /* Used for flags of nesting constructs */
 
74
/*
 
75
  Used to identify NESTED_JOIN structures within a join (applicable only to
 
76
  structures that have not been simplified away and embed more the one
 
77
  element)
 
78
*/
 
79
typedef uint64_t nested_join_map;
 
80
 
 
81
/* query_id */
 
82
typedef uint64_t query_id_t;
 
83
extern query_id_t global_query_id;
 
84
 
 
85
/* increment query_id and return it.  */
 
86
inline query_id_t next_query_id() { return global_query_id++; }
 
87
 
 
88
/* useful constants */
 
89
extern const key_map key_map_empty;
 
90
extern key_map key_map_full;          /* Should be threaded as const */
 
91
extern const char *primary_key_name;
 
92
 
 
93
#include "drizzle_com.h"
 
94
#include <violite.h>
 
95
#include "unireg.h"
 
96
 
 
97
void init_sql_alloc(MEM_ROOT *root, uint block_size, uint pre_alloc_size);
 
98
void *sql_alloc(size_t);
 
99
void *sql_calloc(size_t);
 
100
char *sql_strdup(const char *str);
 
101
char *sql_strmake(const char *str, size_t len);
 
102
void *sql_memdup(const void * ptr, size_t size);
 
103
void sql_element_free(void *ptr);
 
104
char *sql_strmake_with_convert(const char *str, size_t arg_length,
 
105
                               CHARSET_INFO *from_cs,
 
106
                               size_t max_res_length,
 
107
                               CHARSET_INFO *to_cs, size_t *result_length);
 
108
uint kill_one_thread(THD *thd, ulong id, bool only_kill_query);
 
109
void sql_kill(THD *thd, ulong id, bool only_kill_query);
 
110
bool net_request_file(NET* net, const char* fname);
 
111
char* query_table_status(THD *thd,const char *db,const char *table_name);
 
112
 
 
113
#define x_free(A)       { my_free((uchar*) (A),MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR)); }
 
114
#define safeFree(x)     { if(x) { my_free((uchar*) x,MYF(0)); x = NULL; } }
 
115
#define PREV_BITS(type,A)       ((type) (((type) 1 << (A)) -1))
 
116
#define all_bits_set(A,B) ((A) & (B) != (B))
 
117
 
 
118
extern CHARSET_INFO *system_charset_info, *files_charset_info ;
 
119
extern CHARSET_INFO *national_charset_info, *table_alias_charset;
 
120
 
 
121
enum Derivation
 
122
{
 
123
  DERIVATION_IGNORABLE= 5,
 
124
  DERIVATION_COERCIBLE= 4,
 
125
  DERIVATION_SYSCONST= 3,
 
126
  DERIVATION_IMPLICIT= 2,
 
127
  DERIVATION_NONE= 1,
 
128
  DERIVATION_EXPLICIT= 0
 
129
};
 
130
 
 
131
 
 
132
typedef struct my_locale_st
 
133
{
 
134
  uint  number;
 
135
  const char *name;
 
136
  const char *description;
 
137
  const bool is_ascii;
 
138
  TYPELIB *month_names;
 
139
  TYPELIB *ab_month_names;
 
140
  TYPELIB *day_names;
 
141
  TYPELIB *ab_day_names;
 
142
#ifdef __cplusplus 
 
143
  my_locale_st(uint number_par,
 
144
               const char *name_par, const char *descr_par, bool is_ascii_par,
 
145
               TYPELIB *month_names_par, TYPELIB *ab_month_names_par,
 
146
               TYPELIB *day_names_par, TYPELIB *ab_day_names_par) : 
 
147
    number(number_par),
 
148
    name(name_par), description(descr_par), is_ascii(is_ascii_par),
 
149
    month_names(month_names_par), ab_month_names(ab_month_names_par),
 
150
    day_names(day_names_par), ab_day_names(ab_day_names_par)
 
151
  {}
 
152
#endif
 
153
} MY_LOCALE;
 
154
 
 
155
extern MY_LOCALE my_locale_en_US;
 
156
extern MY_LOCALE *my_locales[];
 
157
extern MY_LOCALE *my_default_lc_time_names;
 
158
 
 
159
MY_LOCALE *my_locale_by_name(const char *name);
 
160
MY_LOCALE *my_locale_by_number(uint number);
 
161
 
 
162
/*************************************************************************/
 
163
 
 
164
/**
 
165
 Object_creation_ctx -- interface for creation context of database objects
 
166
 (views, stored routines, events, triggers). Creation context -- is a set
 
167
 of attributes, that should be fixed at the creation time and then be used
 
168
 each time the object is parsed or executed.
 
169
*/
 
170
 
 
171
class Object_creation_ctx
 
172
{
 
173
public:
 
174
  Object_creation_ctx *set_n_backup(THD *thd);
 
175
 
 
176
  void restore_env(THD *thd, Object_creation_ctx *backup_ctx);
 
177
 
 
178
protected:
 
179
  Object_creation_ctx() {}
 
180
  virtual Object_creation_ctx *create_backup_ctx(THD *thd) const = 0;
 
181
 
 
182
  virtual void change_env(THD *thd) const = 0;
 
183
 
 
184
public:
 
185
  virtual ~Object_creation_ctx()
 
186
  { }
 
187
};
 
188
 
 
189
/*************************************************************************/
 
190
 
 
191
/**
 
192
 Default_object_creation_ctx -- default implementation of
 
193
 Object_creation_ctx.
 
194
*/
 
195
 
 
196
class Default_object_creation_ctx : public Object_creation_ctx
 
197
{
 
198
public:
 
199
  CHARSET_INFO *get_client_cs()
 
200
  {
 
201
    return m_client_cs;
 
202
  }
 
203
 
 
204
  CHARSET_INFO *get_connection_cl()
 
205
  {
 
206
    return m_connection_cl;
 
207
  }
 
208
 
 
209
protected:
 
210
  Default_object_creation_ctx(THD *thd);
 
211
 
 
212
  Default_object_creation_ctx(CHARSET_INFO *client_cs,
 
213
                              CHARSET_INFO *connection_cl);
 
214
 
 
215
protected:
 
216
  virtual Object_creation_ctx *create_backup_ctx(THD *thd) const;
 
217
 
 
218
  virtual void change_env(THD *thd) const;
 
219
 
 
220
protected:
 
221
  /**
 
222
    client_cs stores the value of character_set_client session variable.
 
223
    The only character set attribute is used.
 
224
 
 
225
    Client character set is included into query context, because we save
 
226
    query in the original character set, which is client character set. So,
 
227
    in order to parse the query properly we have to switch client character
 
228
    set on parsing.
 
229
  */
 
230
  CHARSET_INFO *m_client_cs;
 
231
 
 
232
  /**
 
233
    connection_cl stores the value of collation_connection session
 
234
    variable. Both character set and collation attributes are used.
 
235
 
 
236
    Connection collation is included into query context, becase it defines
 
237
    the character set and collation of text literals in internal
 
238
    representation of query (item-objects).
 
239
  */
 
240
  CHARSET_INFO *m_connection_cl;
 
241
};
 
242
 
 
243
 
 
244
/**
 
245
  Opening modes for open_temporary_table and open_table_from_share
 
246
*/
 
247
 
 
248
enum open_table_mode
 
249
{
 
250
  OTM_OPEN= 0,
 
251
  OTM_CREATE= 1,
 
252
  OTM_ALTER= 2
 
253
};
 
254
 
 
255
/***************************************************************************
 
256
  Configuration parameters
 
257
****************************************************************************/
 
258
 
 
259
#define ACL_CACHE_SIZE          256
 
260
#define MAX_PASSWORD_LENGTH     32
 
261
#define HOST_CACHE_SIZE         128
 
262
#define MAX_ACCEPT_RETRY        10      // Test accept this many times
 
263
#define MAX_FIELDS_BEFORE_HASH  32
 
264
#define USER_VARS_HASH_SIZE     16
 
265
#define TABLE_OPEN_CACHE_MIN    64
 
266
#define TABLE_OPEN_CACHE_DEFAULT 64
 
267
 
 
268
/* 
 
269
 Value of 9236 discovered through binary search 2006-09-26 on Ubuntu Dapper
 
270
 Drake, libc6 2.3.6-0ubuntu2, Linux kernel 2.6.15-27-686, on x86.  (Added 
 
271
 100 bytes as reasonable buffer against growth and other environments'
 
272
 requirements.)
 
273
 
 
274
 Feel free to raise this by the smallest amount you can to get the
 
275
 "execution_constants" test to pass.
 
276
 */
 
277
#define STACK_MIN_SIZE          12000   ///< Abort if less stack during eval.
 
278
 
 
279
#define STACK_MIN_SIZE_FOR_OPEN 1024*80
 
280
#define STACK_BUFF_ALLOC        352     ///< For stack overrun checks
 
281
#ifndef MYSQLD_NET_RETRY_COUNT
 
282
#define MYSQLD_NET_RETRY_COUNT  10      ///< Abort read after this many int.
 
283
#endif
 
284
#define TEMP_POOL_SIZE          128
 
285
 
 
286
#define QUERY_ALLOC_BLOCK_SIZE          8192
 
287
#define QUERY_ALLOC_PREALLOC_SIZE       8192
 
288
#define TRANS_ALLOC_BLOCK_SIZE          4096
 
289
#define TRANS_ALLOC_PREALLOC_SIZE       4096
 
290
#define RANGE_ALLOC_BLOCK_SIZE          4096
 
291
#define ACL_ALLOC_BLOCK_SIZE            1024
 
292
#define UDF_ALLOC_BLOCK_SIZE            1024
 
293
#define TABLE_ALLOC_BLOCK_SIZE          1024
 
294
#define BDB_LOG_ALLOC_BLOCK_SIZE        1024
 
295
#define WARN_ALLOC_BLOCK_SIZE           2048
 
296
#define WARN_ALLOC_PREALLOC_SIZE        1024
 
297
#define PROFILE_ALLOC_BLOCK_SIZE  2048
 
298
#define PROFILE_ALLOC_PREALLOC_SIZE 1024
 
299
 
 
300
/*
 
301
  The following parameters is to decide when to use an extra cache to
 
302
  optimise seeks when reading a big table in sorted order
 
303
*/
 
304
#define MIN_FILE_LENGTH_TO_USE_ROW_CACHE (10L*1024*1024)
 
305
#define MIN_ROWS_TO_USE_TABLE_CACHE      100
 
306
#define MIN_ROWS_TO_USE_BULK_INSERT      100
 
307
 
 
308
/**
 
309
  The following is used to decide if MySQL should use table scanning
 
310
  instead of reading with keys.  The number says how many evaluation of the
 
311
  WHERE clause is comparable to reading one extra row from a table.
 
312
*/
 
313
#define TIME_FOR_COMPARE   5    // 5 compares == one read
 
314
 
 
315
/**
 
316
  Number of comparisons of table rowids equivalent to reading one row from a 
 
317
  table.
 
318
*/
 
319
#define TIME_FOR_COMPARE_ROWID  (TIME_FOR_COMPARE*2)
 
320
 
 
321
/*
 
322
  For sequential disk seeks the cost formula is:
 
323
    DISK_SEEK_BASE_COST + DISK_SEEK_PROP_COST * #blocks_to_skip  
 
324
  
 
325
  The cost of average seek 
 
326
    DISK_SEEK_BASE_COST + DISK_SEEK_PROP_COST*BLOCKS_IN_AVG_SEEK =1.0.
 
327
*/
 
328
#define DISK_SEEK_BASE_COST ((double)0.9)
 
329
 
 
330
#define BLOCKS_IN_AVG_SEEK  128
 
331
 
 
332
#define DISK_SEEK_PROP_COST ((double)0.1/BLOCKS_IN_AVG_SEEK)
 
333
 
 
334
 
 
335
/**
 
336
  Number of rows in a reference table when refereed through a not unique key.
 
337
  This value is only used when we don't know anything about the key
 
338
  distribution.
 
339
*/
 
340
#define MATCHING_ROWS_IN_OTHER_TABLE 10
 
341
 
 
342
/** Don't pack string keys shorter than this (if PACK_KEYS=1 isn't used). */
 
343
#define KEY_DEFAULT_PACK_LENGTH 8
 
344
 
 
345
/** Characters shown for the command in 'show processlist'. */
 
346
#define PROCESS_LIST_WIDTH 100
 
347
/* Characters shown for the command in 'information_schema.processlist' */
 
348
#define PROCESS_LIST_INFO_WIDTH 65535
 
349
 
 
350
#define PRECISION_FOR_DOUBLE 53
 
351
#define PRECISION_FOR_FLOAT  24
 
352
 
 
353
/*
 
354
  Default time to wait before aborting a new client connection
 
355
  that does not respond to "initial server greeting" timely
 
356
*/
 
357
#define CONNECT_TIMEOUT         10
 
358
 
 
359
/* The following can also be changed from the command line */
 
360
#define DEFAULT_CONCURRENCY     10
 
361
#define FLUSH_TIME              0               /**< Don't flush tables */
 
362
#define MAX_CONNECT_ERRORS      10              ///< errors before disabling host
 
363
 
 
364
#define INTERRUPT_PRIOR 10
 
365
#define CONNECT_PRIOR   9
 
366
#define WAIT_PRIOR      8
 
367
#define QUERY_PRIOR     6
 
368
 
 
369
        /* Bits from testflag */
 
370
#define TEST_PRINT_CACHED_TABLES 1
 
371
#define TEST_NO_KEY_GROUP        2
 
372
#define TEST_MIT_THREAD         4
 
373
#define TEST_BLOCKING           8
 
374
#define TEST_KEEP_TMP_TABLES    16
 
375
#define TEST_READCHECK          64      /**< Force use of readcheck */
 
376
#define TEST_NO_EXTRA           128
 
377
#define TEST_CORE_ON_SIGNAL     256     /**< Give core if signal */
 
378
#define TEST_NO_STACKTRACE      512
 
379
#define TEST_SIGINT             1024    /**< Allow sigint on threads */
 
380
#define TEST_SYNCHRONIZATION    2048    /**< get server to do sleep in
 
381
                                           some places */
 
382
#endif
 
383
 
 
384
/*
 
385
   This is included in the server and in the client.
 
386
   Options for select set by the yacc parser (stored in lex->options).
 
387
 
 
388
   XXX:
 
389
   log_event.h defines OPTIONS_WRITTEN_TO_BIN_LOG to specify what THD
 
390
   options list are written into binlog. These options can NOT change their
 
391
   values, or it will break replication between version.
 
392
 
 
393
   context is encoded as following:
 
394
   SELECT - SELECT_LEX_NODE::options
 
395
   THD    - THD::options
 
396
   intern - neither. used only as
 
397
            func(..., select_node->options | thd->options | OPTION_XXX, ...)
 
398
 
 
399
   TODO: separate three contexts above, move them to separate bitfields.
 
400
*/
 
401
 
 
402
#define SELECT_DISTINCT         (1ULL << 0)     // SELECT, user
 
403
#define SELECT_STRAIGHT_JOIN    (1ULL << 1)     // SELECT, user
 
404
#define SELECT_DESCRIBE         (1ULL << 2)     // SELECT, user
 
405
#define SELECT_SMALL_RESULT     (1ULL << 3)     // SELECT, user
 
406
#define SELECT_BIG_RESULT       (1ULL << 4)     // SELECT, user
 
407
#define OPTION_FOUND_ROWS       (1ULL << 5)     // SELECT, user
 
408
#define SELECT_NO_JOIN_CACHE    (1ULL << 7)     // intern
 
409
#define OPTION_BIG_TABLES       (1ULL << 8)     // THD, user
 
410
#define OPTION_BIG_SELECTS      (1ULL << 9)     // THD, user
 
411
#define OPTION_LOG_OFF          (1ULL << 10)    // THD, user
 
412
#define OPTION_QUOTE_SHOW_CREATE (1ULL << 11)   // THD, user, unused
 
413
#define TMP_TABLE_ALL_COLUMNS   (1ULL << 12)    // SELECT, intern
 
414
#define OPTION_WARNINGS         (1ULL << 13)    // THD, user
 
415
#define OPTION_AUTO_IS_NULL     (1ULL << 14)    // THD, user, binlog
 
416
#define OPTION_FOUND_COMMENT    (1ULL << 15)    // SELECT, intern, parser
 
417
#define OPTION_SAFE_UPDATES     (1ULL << 16)    // THD, user
 
418
#define OPTION_BUFFER_RESULT    (1ULL << 17)    // SELECT, user
 
419
#define OPTION_BIN_LOG          (1ULL << 18)    // THD, user
 
420
#define OPTION_NOT_AUTOCOMMIT   (1ULL << 19)    // THD, user
 
421
#define OPTION_BEGIN            (1ULL << 20)    // THD, intern
 
422
#define OPTION_TABLE_LOCK       (1ULL << 21)    // THD, intern
 
423
#define OPTION_QUICK            (1ULL << 22)    // SELECT (for DELETE)
 
424
#define OPTION_KEEP_LOG         (1ULL << 23)    // THD, user
 
425
 
 
426
/* The following is used to detect a conflict with DISTINCT */
 
427
#define SELECT_ALL              (1ULL << 24)    // SELECT, user, parser
 
428
 
 
429
/** The following can be set when importing tables in a 'wrong order'
 
430
   to suppress foreign key checks */
 
431
#define OPTION_NO_FOREIGN_KEY_CHECKS    (1ULL << 26) // THD, user, binlog
 
432
/** The following speeds up inserts to InnoDB tables by suppressing unique
 
433
   key checks in some cases */
 
434
#define OPTION_RELAXED_UNIQUE_CHECKS    (1ULL << 27) // THD, user, binlog
 
435
#define SELECT_NO_UNLOCK                (1ULL << 28) // SELECT, intern
 
436
#define OPTION_SCHEMA_TABLE             (1ULL << 29) // SELECT, intern
 
437
/** Flag set if setup_tables already done */
 
438
#define OPTION_SETUP_TABLES_DONE        (1ULL << 30) // intern
 
439
/** If not set then the thread will ignore all warnings with level notes. */
 
440
#define OPTION_SQL_NOTES                (1ULL << 31) // THD, user
 
441
/**
 
442
  Force the used temporary table to be a MyISAM table (because we will use
 
443
  fulltext functions when reading from it.
 
444
*/
 
445
#define TMP_TABLE_FORCE_MYISAM          (1ULL << 32)
 
446
#define OPTION_PROFILING                (1ULL << 33)
 
447
 
 
448
/*
 
449
  Dont report errors for individual rows,
 
450
  But just report error on commit (or read ofcourse)
 
451
*/
 
452
#define OPTION_ALLOW_BATCH              (1ULL << 33) // THD, intern (slave)
 
453
 
 
454
/**
 
455
  Maximum length of time zone name that we support
 
456
  (Time zone name is char(64) in db). mysqlbinlog needs it.
 
457
*/
 
458
#define MAX_TIME_ZONE_NAME_LENGTH       (NAME_LEN + 1)
 
459
 
 
460
/* The rest of the file is included in the server only */
 
461
#ifndef MYSQL_CLIENT
 
462
 
 
463
/* Bits for different SQL modes modes (including ANSI mode) */
 
464
#define MODE_REAL_AS_FLOAT              1
 
465
#define MODE_PIPES_AS_CONCAT            2
 
466
#define MODE_ANSI_QUOTES                4
 
467
#define MODE_IGNORE_SPACE               8
 
468
#define MODE_NOT_USED                   16
 
469
#define MODE_ONLY_FULL_GROUP_BY         32
 
470
#define MODE_NO_UNSIGNED_SUBTRACTION    64
 
471
#define MODE_NO_DIR_IN_CREATE           128
 
472
#define MODE_POSTGRESQL                 256
 
473
#define MODE_ORACLE                     512
 
474
#define MODE_MSSQL                      1024
 
475
#define MODE_DB2                        2048
 
476
#define MODE_MAXDB                      4096
 
477
#define MODE_NO_KEY_OPTIONS             8192
 
478
#define MODE_NO_TABLE_OPTIONS           16384
 
479
#define MODE_NO_FIELD_OPTIONS           32768
 
480
#define MODE_MYSQL323                   65536L
 
481
#define MODE_MYSQL40                    (MODE_MYSQL323*2)
 
482
#define MODE_ANSI                       (MODE_MYSQL40*2)
 
483
#define MODE_NO_AUTO_VALUE_ON_ZERO      (MODE_ANSI*2)
 
484
#define MODE_NO_BACKSLASH_ESCAPES       (MODE_NO_AUTO_VALUE_ON_ZERO*2)
 
485
#define MODE_STRICT_TRANS_TABLES        (MODE_NO_BACKSLASH_ESCAPES*2)
 
486
#define MODE_STRICT_ALL_TABLES          (MODE_STRICT_TRANS_TABLES*2)
 
487
#define MODE_NO_ZERO_IN_DATE            (MODE_STRICT_ALL_TABLES*2)
 
488
#define MODE_NO_ZERO_DATE               (MODE_NO_ZERO_IN_DATE*2)
 
489
#define MODE_INVALID_DATES              (MODE_NO_ZERO_DATE*2)
 
490
#define MODE_ERROR_FOR_DIVISION_BY_ZERO (MODE_INVALID_DATES*2)
 
491
#define MODE_TRADITIONAL                (MODE_ERROR_FOR_DIVISION_BY_ZERO*2)
 
492
#define MODE_NO_AUTO_CREATE_USER        (MODE_TRADITIONAL*2)
 
493
#define MODE_HIGH_NOT_PRECEDENCE        (MODE_NO_AUTO_CREATE_USER*2)
 
494
#define MODE_NO_ENGINE_SUBSTITUTION     (MODE_HIGH_NOT_PRECEDENCE*2)
 
495
#define MODE_PAD_CHAR_TO_FULL_LENGTH    (1ULL << 31)
 
496
 
 
497
 
 
498
/* @@optimizer_switch flags */
 
499
#define OPTIMIZER_SWITCH_NO_MATERIALIZATION 1
 
500
#define OPTIMIZER_SWITCH_NO_SEMIJOIN 2
 
501
 
 
502
 
 
503
/*
 
504
  Replication uses 8 bytes to store SQL_MODE in the binary log. The day you
 
505
  use strictly more than 64 bits by adding one more define above, you should
 
506
  contact the replication team because the replication code should then be
 
507
  updated (to store more bytes on disk).
 
508
 
 
509
  NOTE: When adding new SQL_MODE types, make sure to also add them to
 
510
  the scripts used for creating the MySQL system tables
 
511
  in scripts/mysql_system_tables.sql and scripts/mysql_system_tables_fix.sql
 
512
 
 
513
*/
 
514
 
 
515
#define RAID_BLOCK_SIZE 1024
 
516
 
 
517
#define MY_CHARSET_BIN_MB_MAXLEN 1
 
518
 
 
519
// uncachable cause
 
520
#define UNCACHEABLE_DEPENDENT   1
 
521
#define UNCACHEABLE_RAND        2
 
522
#define UNCACHEABLE_SIDEEFFECT  4
 
523
/// forcing to save JOIN for explain
 
524
#define UNCACHEABLE_EXPLAIN     8
 
525
/** Don't evaluate subqueries in prepare even if they're not correlated */
 
526
#define UNCACHEABLE_PREPARE    16
 
527
/* For uncorrelated SELECT in an UNION with some correlated SELECTs */
 
528
#define UNCACHEABLE_UNITED     32
 
529
 
 
530
/* Used to check GROUP BY list in the MODE_ONLY_FULL_GROUP_BY mode */
 
531
#define UNDEF_POS (-1)
 
532
 
 
533
/* BINLOG_DUMP options */
 
534
 
 
535
#define BINLOG_DUMP_NON_BLOCK   1
 
536
 
 
537
/* sql_show.cc:show_log_files() */
 
538
#define SHOW_LOG_STATUS_FREE "FREE"
 
539
#define SHOW_LOG_STATUS_INUSE "IN USE"
 
540
 
 
541
struct TABLE_LIST;
 
542
class String;
 
543
void view_store_options(THD *thd, TABLE_LIST *table, String *buff);
 
544
 
 
545
/* Options to add_table_to_list() */
 
546
#define TL_OPTION_UPDATING      1
 
547
#define TL_OPTION_FORCE_INDEX   2
 
548
#define TL_OPTION_IGNORE_LEAVES 4
 
549
#define TL_OPTION_ALIAS         8
 
550
 
 
551
/* Some portable defines */
 
552
 
 
553
#define portable_sizeof_char_ptr 8
 
554
 
 
555
#define tmp_file_prefix "#sql"                  /**< Prefix for tmp tables */
 
556
#define tmp_file_prefix_length 4
 
557
 
 
558
/* Flags for calc_week() function.  */
 
559
#define WEEK_MONDAY_FIRST    1
 
560
#define WEEK_YEAR            2
 
561
#define WEEK_FIRST_WEEKDAY   4
 
562
 
 
563
#define STRING_BUFFER_USUAL_SIZE 80
 
564
 
 
565
/*
 
566
  Some defines for exit codes for ::is_equal class functions.
 
567
*/
 
568
#define IS_EQUAL_NO 0
 
569
#define IS_EQUAL_YES 1
 
570
#define IS_EQUAL_PACK_LENGTH 2
 
571
 
 
572
enum enum_parsing_place
 
573
{
 
574
  NO_MATTER,
 
575
  IN_HAVING,
 
576
  SELECT_LIST,
 
577
  IN_WHERE,
 
578
  IN_ON
 
579
};
 
580
 
 
581
struct st_table;
 
582
 
 
583
#define thd_proc_info(thd, msg)  set_thd_proc_info(thd, msg, __func__, __FILE__, __LINE__)
 
584
class THD;
 
585
 
 
586
enum enum_check_fields
 
587
{
 
588
  CHECK_FIELD_IGNORE,
 
589
  CHECK_FIELD_WARN,
 
590
  CHECK_FIELD_ERROR_FOR_NULL
 
591
};
 
592
 
 
593
                                  
 
594
/** Struct to handle simple linked lists. */
 
595
typedef struct st_sql_list {
 
596
  uint elements;
 
597
  uchar *first;
 
598
  uchar **next;
 
599
 
 
600
  st_sql_list() {}                              /* Remove gcc warning */
 
601
  inline void empty()
 
602
  {
 
603
    elements=0;
 
604
    first=0;
 
605
    next= &first;
 
606
  }
 
607
  inline void link_in_list(uchar *element,uchar **next_ptr)
 
608
  {
 
609
    elements++;
 
610
    (*next)=element;
 
611
    next= next_ptr;
 
612
    *next=0;
 
613
  }
 
614
  inline void save_and_clear(struct st_sql_list *save)
 
615
  {
 
616
    *save= *this;
 
617
    empty();
 
618
  }
 
619
  inline void push_front(struct st_sql_list *save)
 
620
  {
 
621
    *save->next= first;                         /* link current list last */
 
622
    first= save->first;
 
623
    elements+= save->elements;
 
624
  }
 
625
  inline void push_back(struct st_sql_list *save)
 
626
  {
 
627
    if (save->first)
 
628
    {
 
629
      *next= save->first;
 
630
      next= save->next;
 
631
      elements+= save->elements;
 
632
    }
 
633
  }
 
634
} SQL_LIST;
 
635
 
 
636
 
 
637
extern pthread_key(THD*, THR_THD);
 
638
inline THD *_current_thd(void)
 
639
{
 
640
  return (THD *)pthread_getspecific(THR_THD);
 
641
}
 
642
#define current_thd _current_thd()
 
643
 
 
644
/** 
 
645
  The meat of thd_proc_info(THD*, char*), a macro that packs the last
 
646
  three calling-info parameters. 
 
647
*/
 
648
extern "C"
 
649
const char *set_thd_proc_info(THD *thd, const char *info, 
 
650
                              const char *calling_func, 
 
651
                              const char *calling_file, 
 
652
                              const unsigned int calling_line);
 
653
 
 
654
/*
 
655
  External variables
 
656
*/
 
657
extern ulong server_id;
 
658
 
 
659
 
 
660
typedef my_bool (*qc_engine_callback)(THD *thd, char *table_key,
 
661
                                      uint key_length,
 
662
                                      uint64_t *engine_data);
 
663
#include "sql_string.h"
 
664
#include "sql_list.h"
 
665
#include "sql_map.h"
 
666
#include "my_decimal.h"
 
667
#include "handler.h"
 
668
#include "table.h"
 
669
#include "sql_error.h"
 
670
#include "field.h"                              /* Field definitions */
 
671
#include "protocol.h"
 
672
#include "sql_udf.h"
 
673
 
 
674
class user_var_entry;
 
675
class Security_context;
 
676
enum enum_var_type
 
677
{
 
678
  OPT_DEFAULT= 0, OPT_SESSION, OPT_GLOBAL
 
679
};
 
680
class sys_var;
 
681
#ifdef MYSQL_SERVER
37
682
class Comp_creator;
38
683
typedef Comp_creator* (*chooser_compare_func_creator)(bool invert);
39
 
 
40
 
/**
41
 
 * Contains all headers, definitions, and declarations common to 
42
 
 * the server and the plugin infrastructure, and not the client 
43
 
 */
44
 
#include <drizzled/common_includes.h>       
45
 
/* Range optimization API/library */
46
 
#include <drizzled/opt_range.h>
47
 
/* Simple error injection (crash) module */
48
 
#include <drizzled/error_injection.h>
49
 
/* API for connecting, logging in to a drizzled server */
50
 
#include <drizzled/connect.h>
51
 
/* Routines for dropping, repairing, checking schema tables */
52
 
#include <drizzled/sql_table.h>
53
 
 
54
 
/* sql_db.cc */
 
684
#endif
 
685
#include "item.h"
 
686
extern my_decimal decimal_zero;
 
687
 
 
688
/* sql_parse.cc */
 
689
void free_items(Item *item);
 
690
void cleanup_items(Item *item);
 
691
class THD;
 
692
void close_thread_tables(THD *thd);
 
693
 
 
694
bool multi_update_precheck(THD *thd, TABLE_LIST *tables);
 
695
bool multi_delete_precheck(THD *thd, TABLE_LIST *tables);
 
696
int mysql_multi_update_prepare(THD *thd);
 
697
int mysql_multi_delete_prepare(THD *thd);
 
698
bool mysql_insert_select_prepare(THD *thd);
 
699
bool update_precheck(THD *thd, TABLE_LIST *tables);
 
700
bool delete_precheck(THD *thd, TABLE_LIST *tables);
 
701
bool insert_precheck(THD *thd, TABLE_LIST *tables);
 
702
bool create_table_precheck(THD *thd, TABLE_LIST *tables,
 
703
                           TABLE_LIST *create_table);
 
704
int append_query_string(CHARSET_INFO *csinfo,
 
705
                        String const *from, String *to);
 
706
 
 
707
bool check_string_byte_length(LEX_STRING *str, const char *err_msg,
 
708
                              uint max_byte_length);
 
709
bool check_string_char_length(LEX_STRING *str, const char *err_msg,
 
710
                              uint max_char_length, CHARSET_INFO *cs,
 
711
                              bool no_error);
 
712
bool check_identifier_name(LEX_STRING *str, uint max_char_length,
 
713
                           uint err_code, const char *param_for_err_msg);
 
714
inline bool check_identifier_name(LEX_STRING *str, uint err_code)
 
715
{
 
716
  return check_identifier_name(str, NAME_CHAR_LEN, err_code, "");
 
717
}
 
718
inline bool check_identifier_name(LEX_STRING *str)
 
719
{
 
720
  return check_identifier_name(str, NAME_CHAR_LEN, 0, "");
 
721
}
 
722
 
 
723
bool test_if_data_home_dir(const char *dir);
 
724
 
 
725
bool parse_sql(THD *thd,
 
726
               class Lex_input_stream *lip,
 
727
               class Object_creation_ctx *creation_ctx);
 
728
 
 
729
enum enum_mysql_completiontype {
 
730
  ROLLBACK_RELEASE=-2, ROLLBACK=1,  ROLLBACK_AND_CHAIN=7,
 
731
  COMMIT_RELEASE=-1,   COMMIT=0,    COMMIT_AND_CHAIN=6
 
732
};
 
733
 
 
734
bool begin_trans(THD *thd);
 
735
bool end_active_trans(THD *thd);
 
736
int end_trans(THD *thd, enum enum_mysql_completiontype completion);
 
737
 
 
738
Item *negate_expression(THD *thd, Item *expr);
 
739
 
 
740
/* log.cc */
 
741
int vprint_msg_to_log(enum loglevel level, const char *format, va_list args);
 
742
void sql_print_error(const char *format, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
 
743
void sql_print_warning(const char *format, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
 
744
void sql_print_information(const char *format, ...)
 
745
  ATTRIBUTE_FORMAT(printf, 1, 2);
 
746
typedef void (*sql_print_message_func)(const char *format, ...)
 
747
  ATTRIBUTE_FORMAT(printf, 1, 2);
 
748
extern sql_print_message_func sql_print_message_handlers[];
 
749
 
 
750
int error_log_print(enum loglevel level, const char *format,
 
751
                    va_list args);
 
752
 
 
753
bool slow_log_print(THD *thd, const char *query, uint query_length,
 
754
                    uint64_t current_utime);
 
755
 
 
756
bool general_log_print(THD *thd, enum enum_server_command command,
 
757
                       const char *format,...);
 
758
 
 
759
bool general_log_write(THD *thd, enum enum_server_command command,
 
760
                       const char *query, uint query_length);
 
761
 
 
762
#include "sql_class.h"
 
763
#include "slave.h" // for tables_ok(), rpl_filter
 
764
#include "tztime.h"
 
765
#ifdef MYSQL_SERVER
 
766
#include "opt_range.h"
 
767
 
 
768
 
 
769
/*
 
770
  Error injector Macros to enable easy testing of recovery after failures
 
771
  in various error cases.
 
772
*/
 
773
#ifndef ERROR_INJECT_SUPPORT
 
774
 
 
775
#define ERROR_INJECT(x) 0
 
776
#define ERROR_INJECT_ACTION(x,action) 0
 
777
#define ERROR_INJECT_CRASH(x) 0
 
778
#define ERROR_INJECT_VALUE(x) 0
 
779
#define ERROR_INJECT_VALUE_ACTION(x,action) 0
 
780
#define ERROR_INJECT_VALUE_CRASH(x) 0
 
781
#define SET_ERROR_INJECT_VALUE(x)
 
782
 
 
783
#else
 
784
 
 
785
inline bool check_and_unset_keyword(const char *dbug_str)
 
786
{
 
787
  const char *extra_str= "-d,";
 
788
  char total_str[200];
 
789
  if (_db_strict_keyword_ (dbug_str))
 
790
  {
 
791
    strxmov(total_str, extra_str, dbug_str, NullS);
 
792
    return 1;
 
793
  }
 
794
  return 0;
 
795
}
 
796
 
 
797
 
 
798
inline bool
 
799
check_and_unset_inject_value(int value)
 
800
{
 
801
  THD *thd= current_thd;
 
802
  if (thd->error_inject_value == (uint)value)
 
803
  {
 
804
    thd->error_inject_value= 0;
 
805
    return 1;
 
806
  }
 
807
  return 0;
 
808
}
 
809
 
 
810
/*
 
811
  ERROR INJECT MODULE:
 
812
  --------------------
 
813
  These macros are used to insert macros from the application code.
 
814
  The event that activates those error injections can be activated
 
815
  from SQL by using:
 
816
  SET SESSION dbug=+d,code;
 
817
 
 
818
  After the error has been injected, the macros will automatically
 
819
  remove the debug code, thus similar to using:
 
820
  SET SESSION dbug=-d,code
 
821
  from SQL.
 
822
 
 
823
  ERROR_INJECT_CRASH will inject a crash of the MySQL Server if code
 
824
  is set when macro is called. ERROR_INJECT_CRASH can be used in
 
825
  if-statements, it will always return false unless of course it
 
826
  crashes in which case it doesn't return at all.
 
827
 
 
828
  ERROR_INJECT_ACTION will inject the action specified in the action
 
829
  parameter of the macro, before performing the action the code will
 
830
  be removed such that no more events occur. ERROR_INJECT_ACTION
 
831
  can also be used in if-statements and always returns FALSE.
 
832
  ERROR_INJECT can be used in a normal if-statement, where the action
 
833
  part is performed in the if-block. The macro returns TRUE if the
 
834
  error was activated and otherwise returns FALSE. If activated the
 
835
  code is removed.
 
836
 
 
837
  Sometimes it is necessary to perform error inject actions as a serie
 
838
  of events. In this case one can use one variable on the THD object.
 
839
  Thus one sets this value by using e.g. SET_ERROR_INJECT_VALUE(100).
 
840
  Then one can later test for it by using ERROR_INJECT_CRASH_VALUE,
 
841
  ERROR_INJECT_ACTION_VALUE and ERROR_INJECT_VALUE. This have the same
 
842
  behaviour as the above described macros except that they use the
 
843
  error inject value instead of a code used by debug macros.
 
844
*/
 
845
#define SET_ERROR_INJECT_VALUE(x) \
 
846
  current_thd->error_inject_value= (x)
 
847
#define ERROR_INJECT_ACTION(code, action) \
 
848
  (check_and_unset_keyword(code) ? ((action), 0) : 0)
 
849
#define ERROR_INJECT(code) \
 
850
  check_and_unset_keyword(code)
 
851
#define ERROR_INJECT_VALUE(value) \
 
852
  check_and_unset_inject_value(value)
 
853
#define ERROR_INJECT_VALUE_ACTION(value,action) \
 
854
  (check_and_unset_inject_value(value) ? (action) : 0)
 
855
#define ERROR_INJECT_VALUE_CRASH(value) \
 
856
  ERROR_INJECT_VALUE_ACTION(value, (abort(), 0))
 
857
 
 
858
#endif
 
859
 
 
860
void write_bin_log(THD *thd, bool clear_error,
 
861
                   char const *query, ulong query_length);
 
862
 
 
863
/* sql_connect.cc */
 
864
int check_user(THD *thd, enum enum_server_command command, 
 
865
               const char *passwd, uint passwd_len, const char *db,
 
866
               bool check_count);
 
867
pthread_handler_t handle_one_connection(void *arg);
 
868
bool init_new_connection_handler_thread();
 
869
void reset_mqh(LEX_USER *lu, bool get_them);
 
870
bool check_mqh(THD *thd, uint check_command);
 
871
void time_out_user_resource_limits(THD *thd, USER_CONN *uc);
 
872
void decrease_user_connections(USER_CONN *uc);
 
873
void thd_init_client_charset(THD *thd, uint cs_number);
 
874
bool setup_connection_thread_globals(THD *thd);
 
875
bool login_connection(THD *thd);
 
876
void prepare_new_connection_state(THD* thd);
 
877
void end_connection(THD *thd);
 
878
 
 
879
 
55
880
int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create, bool silent);
56
881
bool mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create);
57
882
bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent);
 
883
bool mysql_upgrade_db(THD *thd, LEX_STRING *old_db);
 
884
void mysql_binlog_send(THD* thd, char* log_ident, my_off_t pos, ushort flags);
 
885
void mysql_client_binlog_statement(THD *thd);
 
886
bool mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists,
 
887
                    my_bool drop_temporary);
 
888
int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
 
889
                         bool drop_temporary, bool drop_view, bool log_query);
 
890
bool quick_rm_table(handlerton *base,const char *db,
 
891
                    const char *table_name, uint flags);
 
892
void close_cached_table(THD *thd, TABLE *table);
 
893
bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list, bool silent);
 
894
bool do_rename(THD *thd, TABLE_LIST *ren_table, char *new_db,
 
895
                      char *new_table_name, char *new_table_alias,
 
896
                      bool skip_error);
 
897
 
58
898
bool mysql_change_db(THD *thd, const LEX_STRING *new_db_name,
59
899
                     bool force_switch);
 
900
 
60
901
bool mysql_opt_change_db(THD *thd,
61
902
                         const LEX_STRING *new_db_name,
62
903
                         LEX_STRING *saved_db_name,
63
904
                         bool force_switch,
64
905
                         bool *cur_db_changed);
65
906
 
66
 
/* sql_repl.cc */
67
 
void write_bin_log(THD *thd, bool clear_error,
68
 
                   char const *query, ulong query_length);
69
 
void mysql_binlog_send(THD* thd, char* log_ident, my_off_t pos, uint16_t flags);
70
 
void mysql_client_binlog_statement(THD *thd);
71
 
 
72
 
/* sql_rename.cc */
73
 
bool mysql_rename_tables(THD *thd, TableList *table_list, bool silent);
74
 
bool do_rename(THD *thd, TableList *ren_table, char *new_db,
75
 
                      char *new_table_name, char *new_table_alias,
76
 
                      bool skip_error);
77
 
 
78
 
/* sql_parse.cc */
79
 
void mysql_parse(THD *thd, const char *inBuf, uint32_t length,
 
907
void mysql_parse(THD *thd, const char *inBuf, uint length,
80
908
                 const char ** semicolon);
81
909
 
82
 
bool mysql_test_parse_for_slave(THD *thd,char *inBuf,uint32_t length);
83
 
 
84
 
 
 
910
bool mysql_test_parse_for_slave(THD *thd,char *inBuf,uint length);
85
911
bool is_update_query(enum enum_sql_command command);
86
 
 
87
 
bool alloc_query(THD *thd, const char *packet, uint32_t packet_length);
88
 
 
 
912
bool alloc_query(THD *thd, const char *packet, uint packet_length);
 
913
void mysql_init_select(LEX *lex);
89
914
void mysql_reset_thd_for_next_command(THD *thd);
90
 
 
 
915
bool mysql_new_select(LEX *lex, bool move_down);
91
916
void create_select_for_variable(const char *var_name);
92
 
 
93
917
void mysql_init_multi_delete(LEX *lex);
94
 
 
95
918
bool multi_delete_set_locks_and_link_aux_tables(LEX *lex);
96
 
 
 
919
void init_max_user_conn(void);
97
920
void init_update_queries(void);
98
 
 
 
921
void free_max_user_conn(void);
 
922
pthread_handler_t handle_bootstrap(void *arg);
 
923
int mysql_execute_command(THD *thd);
99
924
bool do_command(THD *thd);
100
 
 
101
925
bool dispatch_command(enum enum_server_command command, THD *thd,
102
 
                      char* packet, uint32_t packet_length);
103
 
 
 
926
                      char* packet, uint packet_length);
104
927
void log_slow_statement(THD *thd);
105
 
 
 
928
bool check_dup(const char *db, const char *name, TABLE_LIST *tables);
 
929
bool compare_record(TABLE *table);
106
930
bool append_file_to_dir(THD *thd, const char **filename_ptr, 
107
931
                        const char *table_name);
108
 
 
109
 
bool reload_cache(THD *thd, ulong options, TableList *tables, bool *write_to_binlog);
110
 
 
111
 
bool check_simple_select();
112
 
 
113
 
/* @TODO <UNUSED> */
114
 
void mysql_init_select(LEX *lex);
115
 
bool mysql_new_select(LEX *lex, bool move_down);
116
 
void init_max_user_conn(void);
117
 
void free_max_user_conn(void);
118
 
pthread_handler_t handle_bootstrap(void *arg);
119
 
int mysql_execute_command(THD *thd);
120
 
bool check_dup(const char *db, const char *name, TableList *tables);
121
 
bool check_table_access(THD *thd, ulong want_access, TableList *tables,
 
932
void wait_while_table_is_used(THD *thd, TABLE *table,
 
933
                              enum ha_extra_function function);
 
934
bool table_cache_init(void);
 
935
void table_cache_free(void);
 
936
bool table_def_init(void);
 
937
void table_def_free(void);
 
938
void assign_new_table_id(TABLE_SHARE *share);
 
939
uint cached_open_tables(void);
 
940
uint cached_table_definitions(void);
 
941
void kill_mysql(void);
 
942
void close_connection(THD *thd, uint errcode, bool lock);
 
943
bool reload_cache(THD *thd, ulong options, TABLE_LIST *tables, bool *write_to_binlog);
 
944
bool check_table_access(THD *thd, ulong want_access, TABLE_LIST *tables,
122
945
                        bool no_errors,
123
946
                        bool any_combination_of_privileges_will_do,
124
 
                        uint32_t number);
 
947
                        uint number);
 
948
 
 
949
#endif /* MYSQL_SERVER */
 
950
#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
 
951
bool check_global_access(THD *thd, ulong want_access);
 
952
#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
 
953
#ifdef MYSQL_SERVER
 
954
 
125
955
/*
126
956
  General routine to change field->ptr of a NULL-terminated array of Field
127
957
  objects. Useful when needed to call val_int, val_str or similar and the
129
959
  set_key_field_ptr changes all fields of an index using a key_info object.
130
960
  All methods presume that there is at least one field to change.
131
961
*/
132
 
void set_field_ptr(Field **ptr, const unsigned char *new_buf, const unsigned char *old_buf);
133
 
void set_key_field_ptr(KEY *key_info, const unsigned char *new_buf,
134
 
                       const unsigned char *old_buf);
135
 
/* </UNUSED> */
136
 
 
137
 
/* sql_base.cc */
138
 
void table_cache_free(void);
139
 
bool table_cache_init(void);
140
 
bool table_def_init(void);
141
 
void table_def_free(void);
142
 
void assign_new_table_id(TABLE_SHARE *share);
143
 
uint32_t cached_open_tables(void);
144
 
uint32_t cached_table_definitions(void);
145
 
 
146
 
/* drizzled.cc */
147
 
void kill_mysql(void);
148
 
void close_connection(THD *thd, uint32_t errcode, bool lock);
149
 
 
150
 
/* sql_select.cc */
151
 
Table *create_virtual_tmp_table(THD *thd, List<Create_field> &field_list);
152
 
 
153
 
/* handler.cc */
 
962
 
 
963
void set_field_ptr(Field **ptr, const uchar *new_buf, const uchar *old_buf);
 
964
void set_key_field_ptr(KEY *key_info, const uchar *new_buf,
 
965
                       const uchar *old_buf);
 
966
 
 
967
bool mysql_checksum_table(THD* thd, TABLE_LIST* table_list,
 
968
                          HA_CHECK_OPT* check_opt);
 
969
bool mysql_check_table(THD* thd, TABLE_LIST* table_list,
 
970
                       HA_CHECK_OPT* check_opt);
 
971
bool mysql_repair_table(THD* thd, TABLE_LIST* table_list,
 
972
                        HA_CHECK_OPT* check_opt);
 
973
bool mysql_analyze_table(THD* thd, TABLE_LIST* table_list,
 
974
                         HA_CHECK_OPT* check_opt);
 
975
bool mysql_optimize_table(THD* thd, TABLE_LIST* table_list,
 
976
                          HA_CHECK_OPT* check_opt);
 
977
bool mysql_assign_to_keycache(THD* thd, TABLE_LIST* table_list,
 
978
                              LEX_STRING *key_cache_name);
 
979
bool mysql_preload_keys(THD* thd, TABLE_LIST* table_list);
 
980
int reassign_keycache_tables(THD* thd, KEY_CACHE *src_cache,
 
981
                             KEY_CACHE *dst_cache);
 
982
TABLE *create_virtual_tmp_table(THD *thd, List<Create_field> &field_list);
 
983
 
154
984
bool mysql_xa_recover(THD *thd);
155
985
 
156
 
SORT_FIELD * make_unireg_sortorder(order_st *order, uint32_t *length,
 
986
bool check_simple_select();
 
987
 
 
988
SORT_FIELD * make_unireg_sortorder(ORDER *order, uint *length,
157
989
                                  SORT_FIELD *sortorder);
158
 
int setup_order(THD *thd, Item **ref_pointer_array, TableList *tables,
159
 
                List<Item> &fields, List <Item> &all_fields, order_st *order);
160
 
int setup_group(THD *thd, Item **ref_pointer_array, TableList *tables,
161
 
                List<Item> &fields, List<Item> &all_fields, order_st *order,
 
990
int setup_order(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
 
991
                List<Item> &fields, List <Item> &all_fields, ORDER *order);
 
992
int setup_group(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
 
993
                List<Item> &fields, List<Item> &all_fields, ORDER *order,
162
994
                bool *hidden_group_fields);
163
995
bool fix_inner_refs(THD *thd, List<Item> &all_fields, SELECT_LEX *select,
164
996
                   Item **ref_pointer_array);
166
998
bool handle_select(THD *thd, LEX *lex, select_result *result,
167
999
                   ulong setup_tables_done_option);
168
1000
bool mysql_select(THD *thd, Item ***rref_pointer_array,
169
 
                  TableList *tables, uint32_t wild_num,  List<Item> &list,
170
 
                  COND *conds, uint32_t og_num, order_st *order, order_st *group,
171
 
                  Item *having, order_st *proc_param, uint64_t select_type, 
 
1001
                  TABLE_LIST *tables, uint wild_num,  List<Item> &list,
 
1002
                  COND *conds, uint og_num, ORDER *order, ORDER *group,
 
1003
                  Item *having, ORDER *proc_param, uint64_t select_type, 
172
1004
                  select_result *result, SELECT_LEX_UNIT *unit, 
173
1005
                  SELECT_LEX *select_lex);
174
1006
void free_underlaid_joins(THD *thd, SELECT_LEX *select);
180
1012
                 SELECT_LEX_UNIT *unit, ulong setup_tables_done_option);
181
1013
bool mysql_handle_derived(LEX *lex, bool (*processor)(THD *thd,
182
1014
                                                      LEX *lex,
183
 
                                                      TableList *table));
184
 
bool mysql_derived_prepare(THD *thd, LEX *lex, TableList *t);
185
 
bool mysql_derived_filling(THD *thd, LEX *lex, TableList *t);
186
 
Field *create_tmp_field(THD *thd, Table *table,Item *item, Item::Type type,
 
1015
                                                      TABLE_LIST *table));
 
1016
bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *t);
 
1017
bool mysql_derived_filling(THD *thd, LEX *lex, TABLE_LIST *t);
 
1018
Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
187
1019
                        Item ***copy_func, Field **from_field,
188
1020
                        Field **def_field,
189
1021
                        bool group, bool modify_item,
190
1022
                        bool table_cant_handle_bit_fields,
191
1023
                        bool make_copy_field,
192
 
                        uint32_t convert_blob_length);
 
1024
                        uint convert_blob_length);
193
1025
void sp_prepare_create_field(THD *thd, Create_field *sql_field);
194
1026
int prepare_create_field(Create_field *sql_field, 
195
 
                         uint32_t *blob_columns, 
 
1027
                         uint *blob_columns, 
196
1028
                         int *timestamps, int *timestamps_with_niladic,
197
1029
                         int64_t table_flags);
198
1030
bool mysql_create_table(THD *thd,const char *db, const char *table_name,
199
1031
                        HA_CREATE_INFO *create_info,
200
1032
                        Alter_info *alter_info,
201
 
                        bool tmp_table, uint32_t select_field_count);
 
1033
                        bool tmp_table, uint select_field_count);
202
1034
bool mysql_create_table_no_lock(THD *thd, const char *db,
203
1035
                                const char *table_name,
204
1036
                                HA_CREATE_INFO *create_info,
205
1037
                                Alter_info *alter_info,
206
 
                                bool tmp_table, uint32_t select_field_count);
 
1038
                                bool tmp_table, uint select_field_count);
207
1039
 
208
1040
bool mysql_alter_table(THD *thd, char *new_db, char *new_name,
209
1041
                       HA_CREATE_INFO *create_info,
210
 
                       TableList *table_list,
 
1042
                       TABLE_LIST *table_list,
211
1043
                       Alter_info *alter_info,
212
 
                       uint32_t order_num, order_st *order, bool ignore);
213
 
bool mysql_recreate_table(THD *thd, TableList *table_list);
214
 
bool mysql_create_like_table(THD *thd, TableList *table,
215
 
                             TableList *src_table,
 
1044
                       uint order_num, ORDER *order, bool ignore);
 
1045
bool mysql_recreate_table(THD *thd, TABLE_LIST *table_list);
 
1046
bool mysql_create_like_table(THD *thd, TABLE_LIST *table,
 
1047
                             TABLE_LIST *src_table,
216
1048
                             HA_CREATE_INFO *create_info);
217
1049
bool mysql_rename_table(handlerton *base, const char *old_db,
218
1050
                        const char * old_name, const char *new_db,
219
 
                        const char * new_name, uint32_t flags);
220
 
bool mysql_prepare_update(THD *thd, TableList *table_list,
221
 
                          Item **conds, uint32_t order_num, order_st *order);
222
 
int mysql_update(THD *thd,TableList *tables,List<Item> &fields,
 
1051
                        const char * new_name, uint flags);
 
1052
bool mysql_prepare_update(THD *thd, TABLE_LIST *table_list,
 
1053
                          Item **conds, uint order_num, ORDER *order);
 
1054
int mysql_update(THD *thd,TABLE_LIST *tables,List<Item> &fields,
223
1055
                 List<Item> &values,COND *conds,
224
 
                 uint32_t order_num, order_st *order, ha_rows limit,
 
1056
                 uint order_num, ORDER *order, ha_rows limit,
225
1057
                 enum enum_duplicates handle_duplicates, bool ignore);
226
 
bool mysql_multi_update(THD *thd, TableList *table_list,
 
1058
bool mysql_multi_update(THD *thd, TABLE_LIST *table_list,
227
1059
                        List<Item> *fields, List<Item> *values,
228
1060
                        COND *conds, uint64_t options,
229
1061
                        enum enum_duplicates handle_duplicates, bool ignore,
230
1062
                        SELECT_LEX_UNIT *unit, SELECT_LEX *select_lex);
231
 
bool mysql_prepare_insert(THD *thd, TableList *table_list, Table *table,
 
1063
bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list, TABLE *table,
232
1064
                          List<Item> &fields, List_item *values,
233
1065
                          List<Item> &update_fields,
234
1066
                          List<Item> &update_values, enum_duplicates duplic,
235
1067
                          COND **where, bool select_insert,
236
1068
                          bool check_fields, bool abort_on_warning);
237
 
bool mysql_insert(THD *thd,TableList *table,List<Item> &fields,
 
1069
bool mysql_insert(THD *thd,TABLE_LIST *table,List<Item> &fields,
238
1070
                  List<List_item> &values, List<Item> &update_fields,
239
1071
                  List<Item> &update_values, enum_duplicates flag,
240
1072
                  bool ignore);
241
 
int check_that_all_fields_are_given_values(THD *thd, Table *entry,
242
 
                                           TableList *table_list);
243
 
void prepare_triggers_for_insert_stmt(Table *table);
244
 
int mysql_prepare_delete(THD *thd, TableList *table_list, Item **conds);
245
 
bool mysql_delete(THD *thd, TableList *table_list, COND *conds,
 
1073
int check_that_all_fields_are_given_values(THD *thd, TABLE *entry,
 
1074
                                           TABLE_LIST *table_list);
 
1075
void prepare_triggers_for_insert_stmt(TABLE *table);
 
1076
int mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds);
 
1077
bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
246
1078
                  SQL_LIST *order, ha_rows rows, uint64_t options,
247
1079
                  bool reset_auto_increment);
248
 
bool mysql_truncate(THD *thd, TableList *table_list, bool dont_send_ok);
249
 
uint32_t create_table_def_key(THD *thd, char *key, TableList *table_list,
 
1080
bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok);
 
1081
bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create);
 
1082
uint create_table_def_key(THD *thd, char *key, TABLE_LIST *table_list,
250
1083
                          bool tmp_table);
251
 
TABLE_SHARE *get_table_share(THD *thd, TableList *table_list, char *key,
252
 
                             uint32_t key_length, uint32_t db_flags, int *error);
 
1084
TABLE_SHARE *get_table_share(THD *thd, TABLE_LIST *table_list, char *key,
 
1085
                             uint key_length, uint db_flags, int *error);
253
1086
void release_table_share(TABLE_SHARE *share, enum release_type type);
254
1087
TABLE_SHARE *get_cached_table_share(const char *db, const char *table_name);
255
 
Table *open_ltable(THD *thd, TableList *table_list, thr_lock_type update,
256
 
                   uint32_t lock_flags);
257
 
Table *open_table(THD *thd, TableList *table_list, bool *refresh, uint32_t flags);
258
 
bool name_lock_locked_table(THD *thd, TableList *tables);
259
 
bool reopen_name_locked_table(THD* thd, TableList* table_list, bool link_in);
260
 
Table *table_cache_insert_placeholder(THD *thd, const char *key,
261
 
                                      uint32_t key_length);
 
1088
TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type update,
 
1089
                   uint lock_flags);
 
1090
TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT* mem,
 
1091
                  bool *refresh, uint flags);
 
1092
bool name_lock_locked_table(THD *thd, TABLE_LIST *tables);
 
1093
bool reopen_name_locked_table(THD* thd, TABLE_LIST* table_list, bool link_in);
 
1094
TABLE *table_cache_insert_placeholder(THD *thd, const char *key,
 
1095
                                      uint key_length);
262
1096
bool lock_table_name_if_not_cached(THD *thd, const char *db,
263
 
                                   const char *table_name, Table **table);
264
 
Table *find_locked_table(THD *thd, const char *db,const char *table_name);
265
 
void detach_merge_children(Table *table, bool clear_refs);
266
 
bool fix_merge_after_open(TableList *old_child_list, TableList **old_last,
267
 
                          TableList *new_child_list, TableList **new_last);
268
 
bool reopen_table(Table *table);
 
1097
                                   const char *table_name, TABLE **table);
 
1098
TABLE *find_locked_table(THD *thd, const char *db,const char *table_name);
 
1099
void detach_merge_children(TABLE *table, bool clear_refs);
 
1100
bool fix_merge_after_open(TABLE_LIST *old_child_list, TABLE_LIST **old_last,
 
1101
                          TABLE_LIST *new_child_list, TABLE_LIST **new_last);
 
1102
bool reopen_table(TABLE *table);
269
1103
bool reopen_tables(THD *thd,bool get_locks,bool in_refresh);
270
1104
void close_data_files_and_morph_locks(THD *thd, const char *db,
271
1105
                                      const char *table_name);
272
 
void close_handle_and_leave_table_as_lock(Table *table);
 
1106
void close_handle_and_leave_table_as_lock(TABLE *table);
273
1107
bool open_new_frm(THD *thd, TABLE_SHARE *share, const char *alias,
274
 
                  uint32_t db_stat, uint32_t prgflag,
275
 
                  uint32_t ha_open_flags, Table *outparam,
276
 
                  TableList *table_desc, MEM_ROOT *mem_root);
 
1108
                  uint db_stat, uint prgflag,
 
1109
                  uint ha_open_flags, TABLE *outparam,
 
1110
                  TABLE_LIST *table_desc, MEM_ROOT *mem_root);
277
1111
bool wait_for_tables(THD *thd);
278
 
bool table_is_used(Table *table, bool wait_for_name_lock);
279
 
Table *drop_locked_tables(THD *thd,const char *db, const char *table_name);
 
1112
bool table_is_used(TABLE *table, bool wait_for_name_lock);
 
1113
TABLE *drop_locked_tables(THD *thd,const char *db, const char *table_name);
280
1114
void abort_locked_tables(THD *thd,const char *db, const char *table_name);
281
1115
void execute_init_command(THD *thd, sys_var_str *init_command_var,
282
1116
                          rw_lock_t *var_mutex);
288
1122
                                  IGNORE_EXCEPT_NON_UNIQUE};
289
1123
Field *
290
1124
find_field_in_tables(THD *thd, Item_ident *item,
291
 
                     TableList *first_table, TableList *last_table,
 
1125
                     TABLE_LIST *first_table, TABLE_LIST *last_table,
292
1126
                     Item **ref, find_item_error_report_type report_error,
293
1127
                     bool check_privileges, bool register_tree_change);
294
1128
Field *
295
 
find_field_in_table_ref(THD *thd, TableList *table_list,
296
 
                        const char *name, uint32_t length,
 
1129
find_field_in_table_ref(THD *thd, TABLE_LIST *table_list,
 
1130
                        const char *name, uint length,
297
1131
                        const char *item_name, const char *db_name,
298
1132
                        const char *table_name, Item **ref,
299
1133
                        bool check_privileges, bool allow_rowid,
300
 
                        uint32_t *cached_field_index_ptr,
301
 
                        bool register_tree_change, TableList **actual_table);
302
 
Field *
303
 
find_field_in_table(THD *thd, Table *table, const char *name, uint32_t length,
304
 
                    bool allow_rowid, uint32_t *cached_field_index_ptr);
305
 
Field *
306
 
find_field_in_table_sef(Table *table, const char *name);
307
 
 
 
1134
                        uint *cached_field_index_ptr,
 
1135
                        bool register_tree_change, TABLE_LIST **actual_table);
 
1136
Field *
 
1137
find_field_in_table(THD *thd, TABLE *table, const char *name, uint length,
 
1138
                    bool allow_rowid, uint *cached_field_index_ptr);
 
1139
Field *
 
1140
find_field_in_table_sef(TABLE *table, const char *name);
 
1141
 
 
1142
#endif /* MYSQL_SERVER */
 
1143
 
 
1144
#ifdef MYSQL_SERVER
308
1145
/* sql_do.cc */
309
1146
bool mysql_do(THD *thd, List<Item> &values);
310
1147
 
311
1148
/* sql_analyse.h */
312
1149
bool append_escaped(String *to_str, String *from_str);
313
1150
 
314
 
#include <drizzled/show.h>
 
1151
/* sql_show.cc */
 
1152
bool mysqld_show_open_tables(THD *thd,const char *wild);
 
1153
bool mysqld_show_logs(THD *thd);
 
1154
void append_identifier(THD *thd, String *packet, const char *name,
 
1155
                       uint length);
 
1156
#endif /* MYSQL_SERVER */
 
1157
#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
 
1158
int get_quote_char_for_identifier(THD *thd, const char *name, uint length);
 
1159
#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
 
1160
#ifdef MYSQL_SERVER
 
1161
void mysqld_list_fields(THD *thd,TABLE_LIST *table, const char *wild);
 
1162
int mysqld_dump_create_info(THD *thd, TABLE_LIST *table_list, int fd);
 
1163
bool mysqld_show_create(THD *thd, TABLE_LIST *table_list);
 
1164
bool mysqld_show_create_db(THD *thd, char *dbname, HA_CREATE_INFO *create);
 
1165
 
 
1166
void mysqld_list_processes(THD *thd,const char *user,bool verbose);
 
1167
int mysqld_show_status(THD *thd);
 
1168
int mysqld_show_variables(THD *thd,const char *wild);
 
1169
bool mysqld_show_storage_engines(THD *thd);
 
1170
bool mysqld_show_authors(THD *thd);
 
1171
bool mysqld_show_contributors(THD *thd);
 
1172
bool mysqld_show_privileges(THD *thd);
 
1173
bool mysqld_show_column_types(THD *thd);
 
1174
bool mysqld_help (THD *thd, const char *text);
 
1175
void calc_sum_of_all_status(STATUS_VAR *to);
 
1176
 
 
1177
void append_definer(THD *thd, String *buffer, const LEX_STRING *definer_user,
 
1178
                    const LEX_STRING *definer_host);
 
1179
 
 
1180
int add_status_vars(SHOW_VAR *list);
 
1181
void remove_status_vars(SHOW_VAR *list);
 
1182
void init_status_vars();
 
1183
void free_status_vars();
 
1184
void reset_status_vars();
315
1185
 
316
1186
/* information schema */
317
1187
extern LEX_STRING INFORMATION_SCHEMA_NAME;
318
1188
/* log tables */
319
 
extern LEX_STRING DRIZZLE_SCHEMA_NAME;
 
1189
extern LEX_STRING MYSQL_SCHEMA_NAME;
320
1190
extern LEX_STRING GENERAL_LOG_NAME;
321
1191
extern LEX_STRING SLOW_LOG_NAME;
322
1192
 
327
1197
                         enum enum_schema_tables schema_table_idx);
328
1198
int make_schema_select(THD *thd,  SELECT_LEX *sel,
329
1199
                       enum enum_schema_tables schema_table_idx);
330
 
int mysql_schema_table(THD *thd, LEX *lex, TableList *table_list);
 
1200
int mysql_schema_table(THD *thd, LEX *lex, TABLE_LIST *table_list);
331
1201
bool get_schema_tables_result(JOIN *join,
332
1202
                              enum enum_schema_table_state executed_place);
333
1203
enum enum_schema_tables get_schema_table_idx(ST_SCHEMA_TABLE *schema_table);
335
1205
#define is_schema_db(X) \
336
1206
  !my_strcasecmp(system_charset_info, INFORMATION_SCHEMA_NAME.str, (X))
337
1207
 
 
1208
/* sql_prepare.cc */
 
1209
 
 
1210
void mysql_stmt_prepare(THD *thd, const char *packet, uint packet_length);
 
1211
void mysql_stmt_execute(THD *thd, char *packet, uint packet_length);
 
1212
void mysql_stmt_close(THD *thd, char *packet);
 
1213
void mysql_sql_stmt_prepare(THD *thd);
 
1214
void mysql_sql_stmt_execute(THD *thd);
 
1215
void mysql_sql_stmt_close(THD *thd);
 
1216
void mysql_stmt_fetch(THD *thd, char *packet, uint packet_length);
 
1217
void mysql_stmt_reset(THD *thd, char *packet);
 
1218
void mysql_stmt_get_longdata(THD *thd, char *pos, ulong packet_length);
 
1219
void reinit_stmt_before_use(THD *thd, LEX *lex);
 
1220
 
338
1221
/* sql_handler.cc */
339
 
bool mysql_ha_open(THD *thd, TableList *tables, bool reopen);
340
 
bool mysql_ha_close(THD *thd, TableList *tables);
341
 
bool mysql_ha_read(THD *, TableList *,enum enum_ha_read_modes,char *,
 
1222
bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen);
 
1223
bool mysql_ha_close(THD *thd, TABLE_LIST *tables);
 
1224
bool mysql_ha_read(THD *, TABLE_LIST *,enum enum_ha_read_modes,char *,
342
1225
                   List<Item> *,enum ha_rkey_function,Item *,ha_rows,ha_rows);
343
1226
void mysql_ha_flush(THD *thd);
344
 
void mysql_ha_rm_tables(THD *thd, TableList *tables, bool is_locked);
 
1227
void mysql_ha_rm_tables(THD *thd, TABLE_LIST *tables, bool is_locked);
345
1228
void mysql_ha_cleanup(THD *thd);
346
1229
 
347
1230
/* sql_base.cc */
348
1231
#define TMP_TABLE_KEY_EXTRA 8
349
 
void set_item_name(Item *item,char *pos,uint32_t length);
 
1232
void set_item_name(Item *item,char *pos,uint length);
350
1233
bool add_field_to_list(THD *thd, LEX_STRING *field_name, enum enum_field_types type,
351
1234
                       char *length, char *decimal,
352
 
                       uint32_t type_modifier,
 
1235
                       uint type_modifier,
353
1236
                       enum column_format_type column_format,
354
1237
                       Item *default_value, Item *on_update_value,
355
1238
                       LEX_STRING *comment,
356
1239
                       char *change, List<String> *interval_list,
357
 
                       const CHARSET_INFO * const cs);
 
1240
                       CHARSET_INFO *cs);
358
1241
Create_field * new_create_field(THD *thd, char *field_name, enum_field_types type,
359
1242
                                char *length, char *decimals,
360
 
                                uint32_t type_modifier, 
 
1243
                                uint type_modifier, 
361
1244
                                Item *default_value, Item *on_update_value,
362
1245
                                LEX_STRING *comment, char *change, 
363
1246
                                List<String> *interval_list, CHARSET_INFO *cs);
364
1247
void store_position_for_column(const char *name);
365
1248
bool add_to_list(THD *thd, SQL_LIST &list,Item *group,bool asc);
366
1249
bool push_new_name_resolution_context(THD *thd,
367
 
                                      TableList *left_op,
368
 
                                      TableList *right_op);
369
 
void add_join_on(TableList *b,Item *expr);
370
 
void add_join_natural(TableList *a,TableList *b,List<String> *using_fields,
 
1250
                                      TABLE_LIST *left_op,
 
1251
                                      TABLE_LIST *right_op);
 
1252
void add_join_on(TABLE_LIST *b,Item *expr);
 
1253
void add_join_natural(TABLE_LIST *a,TABLE_LIST *b,List<String> *using_fields,
371
1254
                      SELECT_LEX *lex);
372
1255
bool add_proc_to_list(THD *thd, Item *item);
373
 
void unlink_open_table(THD *thd, Table *find, bool unlock);
374
 
void drop_open_table(THD *thd, Table *table, const char *db_name,
 
1256
void unlink_open_table(THD *thd, TABLE *find, bool unlock);
 
1257
void drop_open_table(THD *thd, TABLE *table, const char *db_name,
375
1258
                     const char *table_name);
376
 
void update_non_unique_table_error(TableList *update,
 
1259
void update_non_unique_table_error(TABLE_LIST *update,
377
1260
                                   const char *operation,
378
 
                                   TableList *duplicate);
 
1261
                                   TABLE_LIST *duplicate);
379
1262
 
380
 
SQL_SELECT *make_select(Table *head, table_map const_tables,
 
1263
SQL_SELECT *make_select(TABLE *head, table_map const_tables,
381
1264
                        table_map read_tables, COND *conds,
382
1265
                        bool allow_null_cond,  int *error);
383
1266
extern Item **not_found_item;
408
1291
  RESOLVED_WITH_NO_ALIAS,
409
1292
  RESOLVED_AGAINST_ALIAS
410
1293
};
411
 
Item ** find_item_in_list(Item *item, List<Item> &items, uint32_t *counter,
 
1294
Item ** find_item_in_list(Item *item, List<Item> &items, uint *counter,
412
1295
                          find_item_error_report_type report_error,
413
1296
                          enum_resolution_type *resolution);
414
 
bool get_key_map_from_key_list(key_map *map, Table *table,
 
1297
bool get_key_map_from_key_list(key_map *map, TABLE *table,
415
1298
                               List<String> *index_list);
416
1299
bool insert_fields(THD *thd, Name_resolution_context *context,
417
1300
                   const char *db_name, const char *table_name,
418
1301
                   List_iterator<Item> *it, bool any_privileges);
419
1302
bool setup_tables(THD *thd, Name_resolution_context *context,
420
 
                  List<TableList> *from_clause, TableList *tables,
421
 
                  TableList **leaves, bool select_insert);
 
1303
                  List<TABLE_LIST> *from_clause, TABLE_LIST *tables,
 
1304
                  TABLE_LIST **leaves, bool select_insert);
422
1305
bool setup_tables_and_check_access(THD *thd, 
423
1306
                                   Name_resolution_context *context,
424
 
                                   List<TableList> *from_clause, 
425
 
                                   TableList *tables, 
426
 
                                   TableList **leaves, 
 
1307
                                   List<TABLE_LIST> *from_clause, 
 
1308
                                   TABLE_LIST *tables, 
 
1309
                                   TABLE_LIST **leaves, 
427
1310
                                   bool select_insert);
428
 
int setup_wild(THD *thd, TableList *tables, List<Item> &fields,
429
 
               List<Item> *sum_func_list, uint32_t wild_num);
 
1311
int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields,
 
1312
               List<Item> *sum_func_list, uint wild_num);
430
1313
bool setup_fields(THD *thd, Item** ref_pointer_array,
431
1314
                  List<Item> &item, enum_mark_columns mark_used_columns,
432
1315
                  List<Item> *sum_func_list, bool allow_sum_func);
437
1320
                                      bool allow_sum_func)
438
1321
{
439
1322
  bool res;
 
1323
  thd->lex->select_lex.no_wrap_view_item= true;
440
1324
  res= setup_fields(thd, ref_pointer_array, item, mark_used_columns, sum_func_list,
441
1325
                    allow_sum_func);
 
1326
  thd->lex->select_lex.no_wrap_view_item= false;
442
1327
  return res;
443
1328
}
444
 
int setup_conds(THD *thd, TableList *tables, TableList *leaves,
 
1329
int setup_conds(THD *thd, TABLE_LIST *tables, TABLE_LIST *leaves,
445
1330
                COND **conds);
446
1331
int setup_ftfuncs(SELECT_LEX* select);
447
1332
int init_ftfuncs(THD *thd, SELECT_LEX* select, bool no_order);
448
1333
void wait_for_condition(THD *thd, pthread_mutex_t *mutex,
449
1334
                        pthread_cond_t *cond);
450
 
int open_tables(THD *thd, TableList **tables, uint32_t *counter, uint32_t flags);
 
1335
int open_tables(THD *thd, TABLE_LIST **tables, uint *counter, uint flags);
451
1336
/* open_and_lock_tables with optional derived handling */
452
 
int open_and_lock_tables_derived(THD *thd, TableList *tables, bool derived);
 
1337
int open_and_lock_tables_derived(THD *thd, TABLE_LIST *tables, bool derived);
453
1338
/* simple open_and_lock_tables without derived handling */
454
 
inline int simple_open_n_lock_tables(THD *thd, TableList *tables)
 
1339
inline int simple_open_n_lock_tables(THD *thd, TABLE_LIST *tables)
455
1340
{
456
1341
  return open_and_lock_tables_derived(thd, tables, false);
457
1342
}
458
1343
/* open_and_lock_tables with derived handling */
459
 
inline int open_and_lock_tables(THD *thd, TableList *tables)
 
1344
inline int open_and_lock_tables(THD *thd, TABLE_LIST *tables)
460
1345
{
461
1346
  return open_and_lock_tables_derived(thd, tables, true);
462
1347
}
463
1348
/* simple open_and_lock_tables without derived handling for single table */
464
 
Table *open_n_lock_single_table(THD *thd, TableList *table_l,
 
1349
TABLE *open_n_lock_single_table(THD *thd, TABLE_LIST *table_l,
465
1350
                                thr_lock_type lock_type);
466
 
bool open_normal_and_derived_tables(THD *thd, TableList *tables, uint32_t flags);
467
 
int lock_tables(THD *thd, TableList *tables, uint32_t counter, bool *need_reopen);
468
 
int decide_logging_format(THD *thd, TableList *tables);
469
 
Table *open_temporary_table(THD *thd, const char *path, const char *db,
 
1351
bool open_normal_and_derived_tables(THD *thd, TABLE_LIST *tables, uint flags);
 
1352
int lock_tables(THD *thd, TABLE_LIST *tables, uint counter, bool *need_reopen);
 
1353
int decide_logging_format(THD *thd, TABLE_LIST *tables);
 
1354
TABLE *open_temporary_table(THD *thd, const char *path, const char *db,
470
1355
                            const char *table_name, bool link_in_list,
471
1356
                            open_table_mode open_mode);
472
1357
bool rm_temporary_table(handlerton *base, char *path, bool frm_only);
473
 
void free_io_cache(Table *entry);
474
 
void intern_close_table(Table *entry);
475
 
bool close_thread_table(THD *thd, Table **table_ptr);
 
1358
void free_io_cache(TABLE *entry);
 
1359
void intern_close_table(TABLE *entry);
 
1360
bool close_thread_table(THD *thd, TABLE **table_ptr);
476
1361
void close_temporary_tables(THD *thd);
477
 
void close_tables_for_reopen(THD *thd, TableList **tables);
478
 
TableList *find_table_in_list(TableList *table,
479
 
                               TableList *TableList::*link,
 
1362
void close_tables_for_reopen(THD *thd, TABLE_LIST **tables);
 
1363
TABLE_LIST *find_table_in_list(TABLE_LIST *table,
 
1364
                               TABLE_LIST *TABLE_LIST::*link,
480
1365
                               const char *db_name,
481
1366
                               const char *table_name);
482
 
TableList *unique_table(THD *thd, TableList *table, TableList *table_list,
 
1367
TABLE_LIST *unique_table(THD *thd, TABLE_LIST *table, TABLE_LIST *table_list,
483
1368
                         bool check_alias);
484
 
Table *find_temporary_table(THD *thd, const char *db, const char *table_name);
485
 
Table *find_temporary_table(THD *thd, TableList *table_list);
486
 
int drop_temporary_table(THD *thd, TableList *table_list);
487
 
void close_temporary_table(THD *thd, Table *table, bool free_share,
 
1369
TABLE *find_temporary_table(THD *thd, const char *db, const char *table_name);
 
1370
TABLE *find_temporary_table(THD *thd, TABLE_LIST *table_list);
 
1371
int drop_temporary_table(THD *thd, TABLE_LIST *table_list);
 
1372
void close_temporary_table(THD *thd, TABLE *table, bool free_share,
488
1373
                           bool delete_table);
489
 
void close_temporary(Table *table, bool free_share, bool delete_table);
490
 
bool rename_temporary_table(THD* thd, Table *table, const char *new_db,
 
1374
void close_temporary(TABLE *table, bool free_share, bool delete_table);
 
1375
bool rename_temporary_table(THD* thd, TABLE *table, const char *new_db,
491
1376
                            const char *table_name);
492
1377
void remove_db_from_cache(const char *db);
493
1378
void flush_tables();
500
1385
#define RTFC_WAIT_OTHER_THREAD_FLAG 0x0002
501
1386
#define RTFC_CHECK_KILLED_FLAG      0x0004
502
1387
bool remove_table_from_cache(THD *thd, const char *db, const char *table,
503
 
                             uint32_t flags);
 
1388
                             uint flags);
504
1389
 
505
1390
#define NORMAL_PART_NAME 0
506
1391
#define TEMP_PART_NAME 1
507
1392
#define RENAMED_PART_NAME 2
 
1393
void create_partition_name(char *out, const char *in1,
 
1394
                           const char *in2, uint name_variant,
 
1395
                           bool translate);
 
1396
void create_subpartition_name(char *out, const char *in1,
 
1397
                              const char *in2, const char *in3,
 
1398
                              uint name_variant);
508
1399
 
509
1400
void mem_alloc_error(size_t size);
510
1401
 
 
1402
enum ddl_log_entry_code
 
1403
{
 
1404
  /*
 
1405
    DDL_LOG_EXECUTE_CODE:
 
1406
      This is a code that indicates that this is a log entry to
 
1407
      be executed, from this entry a linked list of log entries
 
1408
      can be found and executed.
 
1409
    DDL_LOG_ENTRY_CODE:
 
1410
      An entry to be executed in a linked list from an execute log
 
1411
      entry.
 
1412
    DDL_IGNORE_LOG_ENTRY_CODE:
 
1413
      An entry that is to be ignored
 
1414
  */
 
1415
  DDL_LOG_EXECUTE_CODE = 'e',
 
1416
  DDL_LOG_ENTRY_CODE = 'l',
 
1417
  DDL_IGNORE_LOG_ENTRY_CODE = 'i'
 
1418
};
 
1419
 
 
1420
enum ddl_log_action_code
 
1421
{
 
1422
  /*
 
1423
    The type of action that a DDL_LOG_ENTRY_CODE entry is to
 
1424
    perform.
 
1425
    DDL_LOG_DELETE_ACTION:
 
1426
      Delete an entity
 
1427
    DDL_LOG_RENAME_ACTION:
 
1428
      Rename an entity
 
1429
    DDL_LOG_REPLACE_ACTION:
 
1430
      Rename an entity after removing the previous entry with the
 
1431
      new name, that is replace this entry.
 
1432
  */
 
1433
  DDL_LOG_DELETE_ACTION = 'd',
 
1434
  DDL_LOG_RENAME_ACTION = 'r',
 
1435
  DDL_LOG_REPLACE_ACTION = 's'
 
1436
};
 
1437
 
 
1438
 
 
1439
typedef struct st_ddl_log_entry
 
1440
{
 
1441
  const char *name;
 
1442
  const char *from_name;
 
1443
  const char *handler_name;
 
1444
  uint next_entry;
 
1445
  uint entry_pos;
 
1446
  enum ddl_log_entry_code entry_type;
 
1447
  enum ddl_log_action_code action_type;
 
1448
  /*
 
1449
    Most actions have only one phase. REPLACE does however have two
 
1450
    phases. The first phase removes the file with the new name if
 
1451
    there was one there before and the second phase renames the
 
1452
    old name to the new name.
 
1453
  */
 
1454
  char phase;
 
1455
} DDL_LOG_ENTRY;
 
1456
 
 
1457
typedef struct st_ddl_log_memory_entry
 
1458
{
 
1459
  uint entry_pos;
 
1460
  struct st_ddl_log_memory_entry *next_log_entry;
 
1461
  struct st_ddl_log_memory_entry *prev_log_entry;
 
1462
  struct st_ddl_log_memory_entry *next_active_log_entry;
 
1463
} DDL_LOG_MEMORY_ENTRY;
 
1464
 
 
1465
 
 
1466
bool write_ddl_log_entry(DDL_LOG_ENTRY *ddl_log_entry,
 
1467
                           DDL_LOG_MEMORY_ENTRY **active_entry);
 
1468
bool write_execute_ddl_log_entry(uint first_entry,
 
1469
                                   bool complete,
 
1470
                                   DDL_LOG_MEMORY_ENTRY **active_entry);
 
1471
bool deactivate_ddl_log_entry(uint entry_no);
 
1472
void release_ddl_log_memory_entry(DDL_LOG_MEMORY_ENTRY *log_entry);
 
1473
bool sync_ddl_log();
 
1474
void release_ddl_log();
 
1475
void execute_ddl_log_recovery();
 
1476
bool execute_ddl_log_entry(THD *thd, uint first_entry);
 
1477
 
 
1478
extern pthread_mutex_t LOCK_gdl;
 
1479
 
511
1480
#define WFRM_WRITE_SHADOW 1
512
1481
#define WFRM_INSTALL_SHADOW 2
513
1482
#define WFRM_PACK_FRM 4
514
1483
#define WFRM_KEEP_SHARE 8
515
1484
 
516
 
bool close_cached_tables(THD *thd, TableList *tables, bool have_lock,
 
1485
/* Functions to work with system tables. */
 
1486
bool open_system_tables_for_read(THD *thd, TABLE_LIST *table_list,
 
1487
                                 Open_tables_state *backup);
 
1488
void close_system_tables(THD *thd, Open_tables_state *backup);
 
1489
TABLE *open_system_table_for_update(THD *thd, TABLE_LIST *one_table);
 
1490
 
 
1491
bool close_cached_tables(THD *thd, TABLE_LIST *tables, bool have_lock,
517
1492
                         bool wait_for_refresh, bool wait_for_placeholders);
518
1493
bool close_cached_connection_tables(THD *thd, bool wait_for_refresh,
519
1494
                                    LEX_STRING *connect_string,
521
1496
void copy_field_from_tmp_record(Field *field,int offset);
522
1497
bool fill_record(THD * thd, List<Item> &fields, List<Item> &values, bool ignore_errors);
523
1498
bool fill_record(THD *thd, Field **field, List<Item> &values, bool ignore_errors);
524
 
OPEN_TableList *list_open_tables(THD *thd, const char *db, const char *wild);
 
1499
OPEN_TABLE_LIST *list_open_tables(THD *thd, const char *db, const char *wild);
525
1500
 
526
 
inline TableList *find_table_in_global_list(TableList *table,
 
1501
inline TABLE_LIST *find_table_in_global_list(TABLE_LIST *table,
527
1502
                                             const char *db_name,
528
1503
                                             const char *table_name)
529
1504
{
530
 
  return find_table_in_list(table, &TableList::next_global,
 
1505
  return find_table_in_list(table, &TABLE_LIST::next_global,
531
1506
                            db_name, table_name);
532
1507
}
533
1508
 
534
 
inline TableList *find_table_in_local_list(TableList *table,
 
1509
inline TABLE_LIST *find_table_in_local_list(TABLE_LIST *table,
535
1510
                                            const char *db_name,
536
1511
                                            const char *table_name)
537
1512
{
538
 
  return find_table_in_list(table, &TableList::next_local,
 
1513
  return find_table_in_list(table, &TABLE_LIST::next_local,
539
1514
                            db_name, table_name);
540
1515
}
541
1516
 
544
1519
bool eval_const_cond(COND *cond);
545
1520
 
546
1521
/* sql_load.cc */
547
 
int mysql_load(THD *thd, sql_exchange *ex, TableList *table_list,
 
1522
int mysql_load(THD *thd, sql_exchange *ex, TABLE_LIST *table_list,
548
1523
                List<Item> &fields_vars, List<Item> &set_fields,
549
1524
                List<Item> &set_values_list,
550
1525
                enum enum_duplicates handle_duplicates, bool ignore,
551
1526
                bool local_file);
552
 
int write_record(THD *thd, Table *table, COPY_INFO *info);
 
1527
int write_record(THD *thd, TABLE *table, COPY_INFO *info);
 
1528
 
 
1529
/* sql_manager.cc */
 
1530
extern ulong volatile manager_status;
 
1531
extern bool volatile manager_thread_in_use, mqh_used;
 
1532
extern pthread_t manager_thread;
 
1533
pthread_handler_t handle_manager(void *arg);
 
1534
bool mysql_manager_submit(void (*action)());
553
1535
 
554
1536
 
555
1537
/* sql_test.cc */
556
1538
void print_where(COND *cond,const char *info, enum_query_type query_type);
557
1539
void print_cached_tables(void);
558
 
void TEST_filesort(SORT_FIELD *sortorder,uint32_t s_length);
559
 
void print_plan(JOIN* join,uint32_t idx, double record_count, double read_time,
 
1540
void TEST_filesort(SORT_FIELD *sortorder,uint s_length);
 
1541
void print_plan(JOIN* join,uint idx, double record_count, double read_time,
560
1542
                double current_read_time, const char *info);
561
1543
void print_keyuse_array(DYNAMIC_ARRAY *keyuse_array);
562
 
void dump_TableList_graph(SELECT_LEX *select_lex, TableList* tl);
 
1544
void dump_TABLE_LIST_graph(SELECT_LEX *select_lex, TABLE_LIST* tl);
563
1545
void mysql_print_status();
564
1546
 
565
1547
/* key.cc */
566
 
int find_ref_key(KEY *key, uint32_t key_count, unsigned char *record, Field *field,
567
 
                 uint32_t *key_length, uint32_t *keypart);
568
 
void key_copy(unsigned char *to_key, unsigned char *from_record, KEY *key_info, uint32_t key_length);
569
 
void key_restore(unsigned char *to_record, unsigned char *from_key, KEY *key_info,
570
 
                 uint16_t key_length);
571
 
void key_zero_nulls(unsigned char *tuple, KEY *key_info);
572
 
bool key_cmp_if_same(Table *form,const unsigned char *key,uint32_t index,uint32_t key_length);
573
 
void key_unpack(String *to,Table *form,uint32_t index);
574
 
bool is_key_used(Table *table, uint32_t idx, const MY_BITMAP *fields);
575
 
int key_cmp(KEY_PART_INFO *key_part, const unsigned char *key, uint32_t key_length);
576
 
extern "C" int key_rec_cmp(void *key_info, unsigned char *a, unsigned char *b);
 
1548
int find_ref_key(KEY *key, uint key_count, uchar *record, Field *field,
 
1549
                 uint *key_length, uint *keypart);
 
1550
void key_copy(uchar *to_key, uchar *from_record, KEY *key_info, uint key_length);
 
1551
void key_restore(uchar *to_record, uchar *from_key, KEY *key_info,
 
1552
                 uint key_length);
 
1553
void key_zero_nulls(uchar *tuple, KEY *key_info);
 
1554
bool key_cmp_if_same(TABLE *form,const uchar *key,uint index,uint key_length);
 
1555
void key_unpack(String *to,TABLE *form,uint index);
 
1556
bool is_key_used(TABLE *table, uint idx, const MY_BITMAP *fields);
 
1557
int key_cmp(KEY_PART_INFO *key_part, const uchar *key, uint key_length);
 
1558
extern "C" int key_rec_cmp(void *key_info, uchar *a, uchar *b);
577
1559
 
578
1560
bool init_errmessage(void);
 
1561
#endif /* MYSQL_SERVER */
 
1562
void sql_perror(const char *message);
 
1563
 
 
1564
bool fn_format_relative_to_data_home(char * to, const char *name,
 
1565
                                     const char *dir, const char *extension);
 
1566
#ifdef MYSQL_SERVER
579
1567
File open_binlog(IO_CACHE *log, const char *log_file_name,
580
1568
                 const char **errmsg);
581
1569
 
582
1570
/* mysqld.cc */
583
1571
extern void MYSQLerror(const char*);
584
1572
void refresh_status(THD *thd);
585
 
bool mysql_rm_tmp_tables(void);
 
1573
my_bool mysql_rm_tmp_tables(void);
586
1574
void handle_connection_in_main_thread(THD *thd);
587
1575
void create_thread_to_handle_connection(THD *thd);
588
1576
void unlink_thd(THD *thd);
591
1579
 
592
1580
/* item_func.cc */
593
1581
extern bool check_reserved_words(LEX_STRING *name);
594
 
extern enum_field_types agg_field_type(Item **items, uint32_t nitems);
 
1582
extern enum_field_types agg_field_type(Item **items, uint nitems);
595
1583
 
596
1584
/* strfunc.cc */
597
 
uint64_t find_set(TYPELIB *lib, const char *x, uint32_t length, const CHARSET_INFO * const cs,
598
 
                   char **err_pos, uint32_t *err_len, bool *set_warning);
599
 
uint32_t find_type(const TYPELIB *lib, const char *find, uint32_t length,
 
1585
uint64_t find_set(TYPELIB *lib, const char *x, uint length, CHARSET_INFO *cs,
 
1586
                   char **err_pos, uint *err_len, bool *set_warning);
 
1587
uint find_type(const TYPELIB *lib, const char *find, uint length,
600
1588
               bool part_match);
601
 
uint32_t find_type2(const TYPELIB *lib, const char *find, uint32_t length,
602
 
                const CHARSET_INFO *cs);
 
1589
uint find_type2(const TYPELIB *lib, const char *find, uint length,
 
1590
                CHARSET_INFO *cs);
603
1591
void unhex_type2(TYPELIB *lib);
604
 
uint32_t check_word(TYPELIB *lib, const char *val, const char *end,
 
1592
uint check_word(TYPELIB *lib, const char *val, const char *end,
605
1593
                const char **end_of_word);
606
1594
int find_string_in_array(LEX_STRING * const haystack, LEX_STRING * const needle,
607
 
                         const CHARSET_INFO * const cs);
608
 
 
609
 
 
610
 
bool is_keyword(const char *name, uint32_t len);
 
1595
                         CHARSET_INFO * const cs);
 
1596
 
 
1597
 
 
1598
bool is_keyword(const char *name, uint len);
611
1599
 
612
1600
#define MY_DB_OPT_FILE "db.opt"
613
1601
bool my_database_names_init(void);
616
1604
bool load_db_opt(THD *thd, const char *path, HA_CREATE_INFO *create);
617
1605
bool load_db_opt_by_name(THD *thd, const char *db_name,
618
1606
                         HA_CREATE_INFO *db_create_info);
619
 
const CHARSET_INFO *get_default_db_collation(THD *thd, const char *db_name);
 
1607
CHARSET_INFO *get_default_db_collation(THD *thd, const char *db_name);
620
1608
bool my_dbopt_init(void);
621
1609
void my_dbopt_cleanup(void);
622
1610
extern int creating_database; // How many database locks are made
627
1615
*/
628
1616
 
629
1617
extern time_t server_start_time, flush_status_time;
630
 
extern char *opt_mysql_tmpdir;
 
1618
#endif /* MYSQL_SERVER */
 
1619
#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
 
1620
extern uint mysql_data_home_len;
 
1621
extern char *mysql_data_home,server_version[SERVER_VERSION_LENGTH],
 
1622
            mysql_real_data_home[], mysql_unpacked_real_data_home[];
 
1623
extern CHARSET_INFO *character_set_filesystem;
 
1624
#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
 
1625
#ifdef MYSQL_SERVER
 
1626
extern char *opt_mysql_tmpdir, mysql_charsets_dir[];
631
1627
            
632
1628
#define mysql_tmpdir (my_tmpdir(&mysql_tmpdir_list))
633
1629
extern MY_TMPDIR mysql_tmpdir_list;
634
1630
extern const LEX_STRING command_name[];
635
1631
extern const char *first_keyword, *my_localhost, *delayed_user, *binary_keyword;
 
1632
extern const char **errmesg;                    /* Error messages */
636
1633
extern const char *myisam_recover_options_str;
637
1634
extern const char *in_left_expr_name, *in_additional_cond, *in_having_cond;
638
1635
extern const char * const TRG_EXT;
644
1641
extern Ge_creator ge_creator;
645
1642
extern Le_creator le_creator;
646
1643
extern char language[FN_REFLEN];
 
1644
#endif /* MYSQL_SERVER */
 
1645
#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
 
1646
extern char reg_ext[FN_EXTLEN];
 
1647
extern uint reg_ext_length;
 
1648
#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
 
1649
#ifdef MYSQL_SERVER
647
1650
extern char glob_hostname[FN_REFLEN], mysql_home[FN_REFLEN];
648
1651
extern char pidfile_name[FN_REFLEN], system_time_zone[30], *opt_init_file;
649
1652
extern char log_error_file[FN_REFLEN], *opt_tc_log_file;
660
1663
extern ulong max_connections,max_connect_errors, connect_timeout;
661
1664
extern bool slave_allow_batching;
662
1665
extern ulong slave_net_timeout, slave_trans_retries;
663
 
extern uint32_t max_user_connections;
 
1666
extern uint max_user_connections;
664
1667
extern ulong what_to_log,flush_time;
 
1668
extern ulong query_buff_size;
 
1669
extern ulong max_prepared_stmt_count, prepared_stmt_count;
665
1670
extern ulong binlog_cache_size, max_binlog_cache_size, open_files_limit;
666
1671
extern ulong max_binlog_size, max_relay_log_size;
667
1672
extern ulong opt_binlog_rows_event_max_size;
668
1673
extern ulong rpl_recovery_rank, thread_cache_size, thread_pool_size;
669
1674
extern ulong back_log;
 
1675
#endif /* MYSQL_SERVER */
 
1676
#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
 
1677
extern ulong specialflag;
 
1678
#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
 
1679
#ifdef MYSQL_SERVER
670
1680
extern ulong current_pid;
671
1681
extern ulong expire_logs_days, sync_binlog_period, sync_binlog_counter;
672
1682
extern ulong opt_tc_log_size, tc_log_max_pages_used, tc_log_page_size;
673
1683
extern ulong tc_log_page_waits;
674
1684
extern bool relay_log_purge;
675
 
extern bool opt_innodb_safe_binlog, opt_innodb;
676
 
extern uint32_t test_flags,select_errors,ha_open_options;
677
 
extern uint32_t protocol_version, mysqld_port, dropping_tables;
678
 
extern uint32_t delay_key_write_options;
 
1685
extern my_bool opt_innodb_safe_binlog, opt_innodb;
 
1686
extern uint test_flags,select_errors,ha_open_options;
 
1687
extern uint protocol_version, mysqld_port, dropping_tables;
 
1688
extern uint delay_key_write_options;
 
1689
#endif /* MYSQL_SERVER */
 
1690
#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
 
1691
extern uint lower_case_table_names;
 
1692
#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
 
1693
#ifdef MYSQL_SERVER
679
1694
extern bool opt_endinfo, using_udf_functions;
680
1695
extern bool locked_in_memory;
681
1696
extern bool opt_using_transactions;
 
1697
#endif /* MYSQL_SERVER */
 
1698
#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
 
1699
#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
 
1700
#ifdef MYSQL_SERVER
682
1701
extern bool using_update_log, server_id_supplied;
683
1702
extern bool opt_update_log, opt_bin_log, opt_error_log;
684
1703
extern bool opt_log; 
685
1704
extern bool opt_slow_log;
686
1705
extern ulong log_output_options;
687
1706
extern bool opt_log_queries_not_using_indexes;
 
1707
extern bool opt_disable_networking, opt_skip_show_db;
688
1708
extern bool opt_character_set_client_handshake;
689
1709
extern bool volatile abort_loop, shutdown_in_progress;
690
 
extern uint32_t volatile thread_count, thread_running, global_read_lock;
691
 
extern uint32_t connection_count;
 
1710
extern uint volatile thread_count, thread_running, global_read_lock;
 
1711
extern uint connection_count;
692
1712
extern bool opt_sql_bin_update;
693
1713
extern bool opt_safe_user_create;
694
 
extern bool opt_no_mix_types;
695
 
extern bool opt_safe_show_db, opt_myisam_use_mmap;
 
1714
extern my_bool opt_no_mix_types;
 
1715
extern my_bool opt_safe_show_db, opt_myisam_use_mmap;
696
1716
extern bool opt_local_infile;
697
1717
extern bool opt_slave_compressed_protocol;
698
1718
extern bool use_temp_pool;
699
1719
extern ulong slave_exec_mode_options;
700
1720
extern bool opt_readonly;
 
1721
extern bool lower_case_file_system;
 
1722
extern bool opt_enable_named_pipe;
 
1723
extern bool opt_sync_frm;
701
1724
extern bool opt_secure_auth;
702
1725
extern char* opt_secure_file_priv;
703
1726
extern bool opt_log_slow_admin_statements;
704
1727
extern bool opt_log_slow_slave_statements;
705
1728
extern bool opt_noacl;
706
1729
extern bool opt_old_style_user_limits;
707
 
extern uint32_t opt_crash_binlog_innodb;
 
1730
extern uint opt_crash_binlog_innodb;
 
1731
extern char *shared_memory_base_name;
 
1732
extern my_bool opt_enable_shared_memory;
708
1733
extern char *default_tz_name;
 
1734
#endif /* MYSQL_SERVER */
 
1735
#ifdef MYSQL_SERVER
709
1736
extern char *opt_logname, *opt_slow_logname;
710
1737
extern const char *log_output_str;
711
1738
 
712
 
extern DRIZZLE_BIN_LOG mysql_bin_log;
 
1739
extern MYSQL_BIN_LOG mysql_bin_log;
713
1740
extern LOGGER logger;
714
 
extern TableList general_log, slow_log;
 
1741
extern TABLE_LIST general_log, slow_log;
 
1742
extern FILE *bootstrap_file;
 
1743
extern int bootstrap_error;
715
1744
extern FILE *stderror_file;
716
1745
extern pthread_key(MEM_ROOT**,THR_MALLOC);
717
1746
extern pthread_mutex_t LOCK_mysql_create_db,LOCK_open, LOCK_lock_db,
718
 
       LOCK_thread_count,LOCK_user_locks, LOCK_status,
 
1747
       LOCK_thread_count,LOCK_mapped_file,LOCK_user_locks, LOCK_status,
719
1748
       LOCK_error_log, LOCK_uuid_generator,
720
1749
       LOCK_crypt, LOCK_timezone,
721
 
       LOCK_slave_list, LOCK_active_mi, LOCK_global_read_lock,
 
1750
       LOCK_slave_list, LOCK_active_mi, LOCK_manager, LOCK_global_read_lock,
722
1751
       LOCK_global_system_variables, LOCK_user_conn,
723
1752
       LOCK_bytes_sent, LOCK_bytes_received, LOCK_connection_count;
724
1753
extern pthread_mutex_t LOCK_server_started;
733
1762
extern String my_empty_string;
734
1763
extern const String my_null_string;
735
1764
extern SHOW_VAR status_vars[];
 
1765
#endif /* MYSQL_SERVER */
 
1766
#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
 
1767
extern struct system_variables global_system_variables;
 
1768
#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
 
1769
#ifdef MYSQL_SERVER
736
1770
extern struct system_variables max_system_variables;
737
1771
extern struct system_status_var global_status_var;
738
1772
extern struct rand_struct sql_rand;
740
1774
extern const char *opt_date_time_formats[];
741
1775
extern KNOWN_DATE_TIME_FORMAT known_date_time_formats[];
742
1776
 
 
1777
extern String null_string;
743
1778
extern HASH open_cache, lock_db_cache;
744
 
extern Table *unused_tables;
 
1779
extern TABLE *unused_tables;
745
1780
extern const char* any_db;
746
1781
extern struct my_option my_long_options[];
747
1782
extern const LEX_STRING view_type;
748
1783
extern scheduler_functions thread_scheduler;
749
1784
extern TYPELIB thread_handling_typelib;
750
 
extern uint8_t uc_update_queries[SQLCOM_END+1];
751
 
extern uint32_t sql_command_flags[];
 
1785
extern uint8 uc_update_queries[SQLCOM_END+1];
 
1786
extern uint sql_command_flags[];
752
1787
extern TYPELIB log_output_typelib;
753
1788
 
754
1789
/* optional things, have_* variables */
757
1792
extern handlerton *myisam_hton;
758
1793
extern handlerton *heap_hton;
759
1794
 
760
 
extern SHOW_COMP_OPTION have_symlink;
 
1795
extern SHOW_COMP_OPTION have_symlink, have_dlopen;
 
1796
extern SHOW_COMP_OPTION have_crypt;
761
1797
extern SHOW_COMP_OPTION have_compress;
762
1798
 
763
1799
 
764
1800
extern pthread_t signal_thread;
765
1801
 
766
 
DRIZZLE_LOCK *mysql_lock_tables(THD *thd, Table **table, uint32_t count,
767
 
                              uint32_t flags, bool *need_reopen);
 
1802
MYSQL_LOCK *mysql_lock_tables(THD *thd, TABLE **table, uint count,
 
1803
                              uint flags, bool *need_reopen);
768
1804
/* mysql_lock_tables() and open_table() flags bits */
769
 
#define DRIZZLE_LOCK_IGNORE_GLOBAL_READ_LOCK      0x0001
770
 
#define DRIZZLE_LOCK_IGNORE_FLUSH                 0x0002
771
 
#define DRIZZLE_LOCK_NOTIFY_IF_NEED_REOPEN        0x0004
772
 
#define DRIZZLE_OPEN_TEMPORARY_ONLY               0x0008
773
 
#define DRIZZLE_LOCK_IGNORE_GLOBAL_READ_ONLY      0x0010
774
 
#define DRIZZLE_LOCK_PERF_SCHEMA                  0x0020
 
1805
#define MYSQL_LOCK_IGNORE_GLOBAL_READ_LOCK      0x0001
 
1806
#define MYSQL_LOCK_IGNORE_FLUSH                 0x0002
 
1807
#define MYSQL_LOCK_NOTIFY_IF_NEED_REOPEN        0x0004
 
1808
#define MYSQL_OPEN_TEMPORARY_ONLY               0x0008
 
1809
#define MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY      0x0010
 
1810
#define MYSQL_LOCK_PERF_SCHEMA                  0x0020
775
1811
 
776
 
void mysql_unlock_tables(THD *thd, DRIZZLE_LOCK *sql_lock);
777
 
void mysql_unlock_read_tables(THD *thd, DRIZZLE_LOCK *sql_lock);
778
 
void mysql_unlock_some_tables(THD *thd, Table **table,uint32_t count);
779
 
void mysql_lock_remove(THD *thd, DRIZZLE_LOCK *locked,Table *table,
 
1812
void mysql_unlock_tables(THD *thd, MYSQL_LOCK *sql_lock);
 
1813
void mysql_unlock_read_tables(THD *thd, MYSQL_LOCK *sql_lock);
 
1814
void mysql_unlock_some_tables(THD *thd, TABLE **table,uint count);
 
1815
void mysql_lock_remove(THD *thd, MYSQL_LOCK *locked,TABLE *table,
780
1816
                       bool always_unlock);
781
 
void mysql_lock_abort(THD *thd, Table *table, bool upgrade_lock);
782
 
void mysql_lock_downgrade_write(THD *thd, Table *table,
 
1817
void mysql_lock_abort(THD *thd, TABLE *table, bool upgrade_lock);
 
1818
void mysql_lock_downgrade_write(THD *thd, TABLE *table,
783
1819
                                thr_lock_type new_lock_type);
784
 
bool mysql_lock_abort_for_thread(THD *thd, Table *table);
785
 
DRIZZLE_LOCK *mysql_lock_merge(DRIZZLE_LOCK *a,DRIZZLE_LOCK *b);
786
 
TableList *mysql_lock_have_duplicate(THD *thd, TableList *needle,
787
 
                                      TableList *haystack);
 
1820
bool mysql_lock_abort_for_thread(THD *thd, TABLE *table);
 
1821
MYSQL_LOCK *mysql_lock_merge(MYSQL_LOCK *a,MYSQL_LOCK *b);
 
1822
TABLE_LIST *mysql_lock_have_duplicate(THD *thd, TABLE_LIST *needle,
 
1823
                                      TABLE_LIST *haystack);
788
1824
bool lock_global_read_lock(THD *thd);
789
1825
void unlock_global_read_lock(THD *thd);
790
1826
bool wait_if_global_read_lock(THD *thd, bool abort_on_refresh,
794
1830
bool set_protect_against_global_read_lock(void);
795
1831
void unset_protect_against_global_read_lock(void);
796
1832
void broadcast_refresh(void);
797
 
int try_transactional_lock(THD *thd, TableList *table_list);
798
 
int check_transactional_lock(THD *thd, TableList *table_list);
799
 
int set_handler_table_locks(THD *thd, TableList *table_list,
 
1833
int try_transactional_lock(THD *thd, TABLE_LIST *table_list);
 
1834
int check_transactional_lock(THD *thd, TABLE_LIST *table_list);
 
1835
int set_handler_table_locks(THD *thd, TABLE_LIST *table_list,
800
1836
                            bool transactional);
801
1837
 
802
1838
/* Lock based on name */
803
 
int lock_and_wait_for_table_name(THD *thd, TableList *table_list);
804
 
int lock_table_name(THD *thd, TableList *table_list, bool check_in_use);
805
 
void unlock_table_name(THD *thd, TableList *table_list);
806
 
bool wait_for_locked_table_names(THD *thd, TableList *table_list);
807
 
bool lock_table_names(THD *thd, TableList *table_list);
808
 
void unlock_table_names(THD *thd, TableList *table_list,
809
 
                        TableList *last_table);
810
 
bool lock_table_names_exclusively(THD *thd, TableList *table_list);
 
1839
int lock_and_wait_for_table_name(THD *thd, TABLE_LIST *table_list);
 
1840
int lock_table_name(THD *thd, TABLE_LIST *table_list, bool check_in_use);
 
1841
void unlock_table_name(THD *thd, TABLE_LIST *table_list);
 
1842
bool wait_for_locked_table_names(THD *thd, TABLE_LIST *table_list);
 
1843
bool lock_table_names(THD *thd, TABLE_LIST *table_list);
 
1844
void unlock_table_names(THD *thd, TABLE_LIST *table_list,
 
1845
                        TABLE_LIST *last_table);
 
1846
bool lock_table_names_exclusively(THD *thd, TABLE_LIST *table_list);
811
1847
bool is_table_name_exclusively_locked_by_this_thread(THD *thd, 
812
 
                                                     TableList *table_list);
813
 
bool is_table_name_exclusively_locked_by_this_thread(THD *thd, unsigned char *key,
 
1848
                                                     TABLE_LIST *table_list);
 
1849
bool is_table_name_exclusively_locked_by_this_thread(THD *thd, uchar *key,
814
1850
                                                     int key_length);
815
1851
 
816
1852
 
822
1858
                      const char *db, const char *table,
823
1859
                      HA_CREATE_INFO *create_info,
824
1860
                      List<Create_field> &create_field,
825
 
                      uint32_t key_count,KEY *key_info,handler *db_type);
 
1861
                      uint key_count,KEY *key_info,handler *db_type);
826
1862
int rea_create_table(THD *thd, const char *path,
827
1863
                     const char *db, const char *table_name,
828
1864
                     HA_CREATE_INFO *create_info,
829
1865
                     List<Create_field> &create_field,
830
 
                     uint32_t key_count,KEY *key_info,
 
1866
                     uint key_count,KEY *key_info,
831
1867
                     handler *file);
832
 
int format_number(uint32_t inputflag,uint32_t max_length,char * pos,uint32_t length,
 
1868
int format_number(uint inputflag,uint max_length,char * pos,uint length,
833
1869
                  char * *errpos);
834
1870
 
835
1871
/* table.cc */
836
 
TABLE_SHARE *alloc_table_share(TableList *table_list, char *key,
837
 
                               uint32_t key_length);
 
1872
TABLE_SHARE *alloc_table_share(TABLE_LIST *table_list, char *key,
 
1873
                               uint key_length);
838
1874
void init_tmp_table_share(THD *thd, TABLE_SHARE *share, const char *key,
839
 
                          uint32_t key_length,
 
1875
                          uint key_length,
840
1876
                          const char *table_name, const char *path);
841
1877
void free_table_share(TABLE_SHARE *share);
842
 
int open_table_def(THD *thd, TABLE_SHARE *share, uint32_t db_flags);
 
1878
int open_table_def(THD *thd, TABLE_SHARE *share, uint db_flags);
843
1879
void open_table_error(TABLE_SHARE *share, int error, int db_errno, int errarg);
844
1880
int open_table_from_share(THD *thd, TABLE_SHARE *share, const char *alias,
845
 
                          uint32_t db_stat, uint32_t prgflag, uint32_t ha_open_flags,
846
 
                          Table *outparam, open_table_mode open_mode);
847
 
int readfrm(const char *name, unsigned char **data, size_t *length);
848
 
int writefrm(const char* name, const unsigned char* data, size_t len);
849
 
int closefrm(Table *table, bool free_share);
850
 
int read_string(File file, unsigned char* *to, size_t length);
851
 
void free_blobs(Table *table);
 
1881
                          uint db_stat, uint prgflag, uint ha_open_flags,
 
1882
                          TABLE *outparam, open_table_mode open_mode);
 
1883
int readfrm(const char *name, uchar **data, size_t *length);
 
1884
int writefrm(const char* name, const uchar* data, size_t len);
 
1885
int closefrm(TABLE *table, bool free_share);
 
1886
int read_string(File file, uchar* *to, size_t length);
 
1887
void free_blobs(TABLE *table);
852
1888
int set_zone(int nr,int min_zone,int max_zone);
853
1889
ulong convert_period_to_month(ulong period);
854
1890
ulong convert_month_to_period(ulong month);
855
 
void get_date_from_daynr(long daynr,uint32_t *year, uint32_t *month,
856
 
                         uint32_t *day);
857
 
my_time_t TIME_to_timestamp(THD *thd, const DRIZZLE_TIME *t, bool *not_exist);
858
 
bool str_to_time_with_warn(const char *str,uint32_t length,DRIZZLE_TIME *l_time);
859
 
enum enum_drizzle_timestamp_type str_to_datetime_with_warn(const char *str, uint32_t length,
860
 
                                         DRIZZLE_TIME *l_time, uint32_t flags);
861
 
void localtime_to_TIME(DRIZZLE_TIME *to, struct tm *from);
862
 
void calc_time_from_sec(DRIZZLE_TIME *to, long seconds, long microseconds);
 
1891
void get_date_from_daynr(long daynr,uint *year, uint *month,
 
1892
                         uint *day);
 
1893
my_time_t TIME_to_timestamp(THD *thd, const MYSQL_TIME *t, bool *not_exist);
 
1894
bool str_to_time_with_warn(const char *str,uint length,MYSQL_TIME *l_time);
 
1895
timestamp_type str_to_datetime_with_warn(const char *str, uint length,
 
1896
                                         MYSQL_TIME *l_time, uint flags);
 
1897
void localtime_to_TIME(MYSQL_TIME *to, struct tm *from);
 
1898
void calc_time_from_sec(MYSQL_TIME *to, long seconds, long microseconds);
863
1899
 
864
 
void make_truncated_value_warning(THD *thd, DRIZZLE_ERROR::enum_warning_level level,
 
1900
void make_truncated_value_warning(THD *thd, MYSQL_ERROR::enum_warning_level level,
865
1901
                                  const char *str_val,
866
 
                                  uint32_t str_length, enum enum_drizzle_timestamp_type time_type,
 
1902
                                  uint str_length, timestamp_type time_type,
867
1903
                                  const char *field_name);
868
1904
 
869
 
bool date_add_interval(DRIZZLE_TIME *ltime, interval_type int_type, INTERVAL interval);
870
 
bool calc_time_diff(DRIZZLE_TIME *l_time1, DRIZZLE_TIME *l_time2, int l_sign,
 
1905
bool date_add_interval(MYSQL_TIME *ltime, interval_type int_type, INTERVAL interval);
 
1906
bool calc_time_diff(MYSQL_TIME *l_time1, MYSQL_TIME *l_time2, int l_sign,
871
1907
                    int64_t *seconds_out, long *microseconds_out);
872
1908
 
873
1909
extern LEX_STRING interval_type_to_name[];
874
1910
 
875
 
extern DATE_TIME_FORMAT *date_time_format_make(enum enum_drizzle_timestamp_type format_type,
 
1911
extern DATE_TIME_FORMAT *date_time_format_make(timestamp_type format_type,
876
1912
                                               const char *format_str,
877
 
                                               uint32_t format_length);
 
1913
                                               uint format_length);
878
1914
extern DATE_TIME_FORMAT *date_time_format_copy(THD *thd,
879
1915
                                               DATE_TIME_FORMAT *format);
880
1916
const char *get_date_time_format_str(KNOWN_DATE_TIME_FORMAT *format,
881
 
                                                             enum enum_drizzle_timestamp_type type);
882
 
extern bool make_date_time(DATE_TIME_FORMAT *format, DRIZZLE_TIME *l_time,
883
 
                                             enum enum_drizzle_timestamp_type type, String *str);
884
 
void make_datetime(const DATE_TIME_FORMAT *format, const DRIZZLE_TIME *l_time,
 
1917
                                     timestamp_type type);
 
1918
extern bool make_date_time(DATE_TIME_FORMAT *format, MYSQL_TIME *l_time,
 
1919
                           timestamp_type type, String *str);
 
1920
void make_datetime(const DATE_TIME_FORMAT *format, const MYSQL_TIME *l_time,
885
1921
                   String *str);
886
 
void make_date(const DATE_TIME_FORMAT *format, const DRIZZLE_TIME *l_time,
887
 
               String *str);
888
 
void make_time(const DATE_TIME_FORMAT *format, const DRIZZLE_TIME *l_time,
889
 
               String *str);
890
 
int my_time_compare(DRIZZLE_TIME *a, DRIZZLE_TIME *b);
 
1922
void make_date(const DATE_TIME_FORMAT *format, const MYSQL_TIME *l_time,
 
1923
               String *str);
 
1924
void make_time(const DATE_TIME_FORMAT *format, const MYSQL_TIME *l_time,
 
1925
               String *str);
 
1926
int my_time_compare(MYSQL_TIME *a, MYSQL_TIME *b);
891
1927
uint64_t get_datetime_value(THD *thd, Item ***item_arg, Item **cache_arg,
892
1928
                             Item *warn_item, bool *is_null);
893
1929
 
894
1930
int test_if_number(char *str,int *res,bool allow_wildcards);
895
 
void change_byte(unsigned char *,uint,char,char);
896
 
void init_read_record(READ_RECORD *info, THD *thd, Table *reg_form,
 
1931
void change_byte(uchar *,uint,char,char);
 
1932
void init_read_record(READ_RECORD *info, THD *thd, TABLE *reg_form,
897
1933
                      SQL_SELECT *select,
898
1934
                      int use_record_cache, bool print_errors);
899
 
void init_read_record_idx(READ_RECORD *info, THD *thd, Table *table, 
900
 
                          bool print_error, uint32_t idx);
 
1935
void init_read_record_idx(READ_RECORD *info, THD *thd, TABLE *table, 
 
1936
                          bool print_error, uint idx);
901
1937
void end_read_record(READ_RECORD *info);
902
 
ha_rows filesort(THD *thd, Table *form,struct st_sort_field *sortorder,
903
 
                 uint32_t s_length, SQL_SELECT *select,
 
1938
ha_rows filesort(THD *thd, TABLE *form,struct st_sort_field *sortorder,
 
1939
                 uint s_length, SQL_SELECT *select,
904
1940
                 ha_rows max_rows, bool sort_positions,
905
1941
                 ha_rows *examined_rows);
906
 
void filesort_free_buffers(Table *table, bool full);
907
 
void change_double_for_sort(double nr,unsigned char *to);
 
1942
void filesort_free_buffers(TABLE *table, bool full);
 
1943
void change_double_for_sort(double nr,uchar *to);
908
1944
double my_double_round(double value, int64_t dec, bool dec_unsigned,
909
1945
                       bool truncate);
910
1946
int get_quick_record(SQL_SELECT *select);
911
1947
 
912
1948
int calc_weekday(long daynr,bool sunday_first_day_of_week);
913
 
uint32_t calc_week(DRIZZLE_TIME *l_time, uint32_t week_behaviour, uint32_t *year);
914
 
void find_date(char *pos,uint32_t *vek,uint32_t flag);
 
1949
uint calc_week(MYSQL_TIME *l_time, uint week_behaviour, uint *year);
 
1950
void find_date(char *pos,uint *vek,uint flag);
915
1951
TYPELIB *convert_strings_to_array_type(char * *typelibs, char * *end);
916
1952
TYPELIB *typelib(MEM_ROOT *mem_root, List<String> &strings);
917
 
ulong get_form_pos(File file, unsigned char *head, TYPELIB *save_names);
918
 
ulong make_new_entry(File file,unsigned char *fileinfo,TYPELIB *formnames,
 
1953
ulong get_form_pos(File file, uchar *head, TYPELIB *save_names);
 
1954
ulong make_new_entry(File file,uchar *fileinfo,TYPELIB *formnames,
919
1955
                     const char *newname);
920
1956
ulong next_io_size(ulong pos);
921
 
void append_unescaped(String *res, const char *pos, uint32_t length);
 
1957
void append_unescaped(String *res, const char *pos, uint length);
922
1958
int create_frm(THD *thd, const char *name, const char *db, const char *table,
923
 
               uint32_t reclength, unsigned char *fileinfo,
924
 
               HA_CREATE_INFO *create_info, uint32_t keys, KEY *key_info);
 
1959
               uint reclength, uchar *fileinfo,
 
1960
               HA_CREATE_INFO *create_info, uint keys, KEY *key_info);
 
1961
void update_create_info_from_table(HA_CREATE_INFO *info, TABLE *form);
925
1962
int rename_file_ext(const char * from,const char * to,const char * ext);
926
1963
bool check_db_name(LEX_STRING *db);
927
1964
bool check_column_name(const char *name);
928
 
bool check_table_name(const char *name, uint32_t length);
 
1965
bool check_table_name(const char *name, uint length);
929
1966
char *get_field(MEM_ROOT *mem, Field *field);
930
1967
bool get_field(MEM_ROOT *mem, Field *field, class String *res);
931
1968
char *fn_rext(char *name);
932
1969
 
933
1970
/* Conversion functions */
934
 
uint32_t build_table_filename(char *buff, size_t bufflen, const char *db,
935
 
                          const char *table, const char *ext, uint32_t flags);
 
1971
#endif /* MYSQL_SERVER */
 
1972
#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
 
1973
uint strconvert(CHARSET_INFO *from_cs, const char *from,
 
1974
                CHARSET_INFO *to_cs, char *to, uint to_length, uint *errors);
 
1975
uint filename_to_tablename(const char *from, char *to, uint to_length);
 
1976
uint tablename_to_filename(const char *from, char *to, uint to_length);
 
1977
#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
 
1978
#ifdef MYSQL_SERVER
 
1979
uint build_table_filename(char *buff, size_t bufflen, const char *db,
 
1980
                          const char *table, const char *ext, uint flags);
936
1981
 
937
1982
#define MYSQL50_TABLE_NAME_PREFIX         "#mysql50#"
938
1983
#define MYSQL50_TABLE_NAME_PREFIX_LENGTH  9
977
2022
  return thd->lex->current_select->add_group_to_list(thd, item, asc);
978
2023
}
979
2024
 
980
 
inline void mark_as_null_row(Table *table)
 
2025
inline void mark_as_null_row(TABLE *table)
981
2026
{
982
2027
  table->null_row=1;
983
2028
  table->status|=STATUS_NULL_ROW;
984
 
  memset(table->null_flags, 255, table->s->null_bytes);
 
2029
  bfill(table->null_flags,table->s->null_bytes,255);
985
2030
}
986
2031
 
987
 
inline void table_case_convert(char * name, uint32_t length)
 
2032
inline void table_case_convert(char * name, uint length)
988
2033
{
989
2034
  if (lower_case_table_names)
990
2035
    files_charset_info->cset->casedn(files_charset_info,
996
2041
  return ((lower_case_table_names == 2 && info->alias) ? info->alias : name);
997
2042
}
998
2043
 
999
 
inline ulong sql_rnd()
 
2044
inline ulong sql_rnd_with_mutex()
1000
2045
{
1001
 
  ulong tmp= (ulong) (rand() * 0xffffffff); /* make all bits random */
1002
 
 
 
2046
  pthread_mutex_lock(&LOCK_thread_count);
 
2047
  ulong tmp=(ulong) (my_rnd(&sql_rand) * 0xffffffff); /* make all bits random */
 
2048
  pthread_mutex_unlock(&LOCK_thread_count);
1003
2049
  return tmp;
1004
2050
}
1005
2051
 
1018
2064
/**
1019
2065
  clean/setup table fields and map.
1020
2066
 
1021
 
  @param table        Table structure pointer (which should be setup)
1022
 
  @param table_list   TableList structure pointer (owner of Table)
 
2067
  @param table        TABLE structure pointer (which should be setup)
 
2068
  @param table_list   TABLE_LIST structure pointer (owner of TABLE)
1023
2069
  @param tablenr     table number
1024
2070
*/
1025
 
inline void setup_table_map(Table *table, TableList *table_list, uint32_t tablenr)
 
2071
 
 
2072
 
 
2073
inline void setup_table_map(TABLE *table, TABLE_LIST *table_list, uint tablenr)
1026
2074
{
1027
2075
  table->used_fields= 0;
1028
2076
  table->const_table= 0;
1029
2077
  table->null_row= 0;
1030
2078
  table->status= STATUS_NO_RECORD;
1031
2079
  table->maybe_null= table_list->outer_join;
1032
 
  TableList *embedding= table_list->embedding;
 
2080
  TABLE_LIST *embedding= table_list->embedding;
1033
2081
  while (!table->maybe_null && embedding)
1034
2082
  {
1035
2083
    table->maybe_null= embedding->outer_join;
1042
2090
  table->merge_keys.clear_all();
1043
2091
}
1044
2092
 
1045
 
#include <drizzled/item_create.h>         /* Factory API for creating Item_* instances */
1046
2093
 
1047
2094
/**
1048
2095
  convert a hex digit into number.
1061
2108
/**
1062
2109
  return true if the table was created explicitly.
1063
2110
*/
1064
 
inline bool is_user_table(Table * table)
 
2111
inline bool is_user_table(TABLE * table)
1065
2112
{
1066
2113
  const char *name= table->s->table_name.str;
1067
2114
  return strncmp(name, tmp_file_prefix, tmp_file_prefix_length);
1087
2134
 
1088
2135
extern "C" void unireg_abort(int exit_code) __attribute__((noreturn));
1089
2136
void kill_delayed_threads(void);
1090
 
bool check_stack_overrun(THD *thd, long margin, unsigned char *dummy);
 
2137
bool check_stack_overrun(THD *thd, long margin, uchar *dummy);
1091
2138
 
1092
 
/** 
1093
 
 * Used by handlers to store things in schema tables 
1094
 
 *
1095
 
 * @TODO These should be placed in an information_schema.h header
1096
 
 * file once the new information schema design is finalized.
1097
 
 */
 
2139
/* Used by handlers to store things in schema tables */
1098
2140
#define IS_FILES_FILE_ID              0
1099
2141
#define IS_FILES_FILE_NAME            1
1100
2142
#define IS_FILES_FILE_TYPE            2
1133
2175
#define IS_FILES_CHECKSUM            35
1134
2176
#define IS_FILES_STATUS              36
1135
2177
#define IS_FILES_EXTRA               37
1136
 
 
1137
 
#endif /* DRIZZLE_SERVER_SERVER_INCLUDES_H */
 
2178
void init_fill_schema_files_row(TABLE* table);
 
2179
bool schema_table_store_record(THD *thd, TABLE *table);
 
2180
 
 
2181
/* sql/item_create.cc */
 
2182
int item_create_init();
 
2183
void item_create_cleanup();
 
2184
 
 
2185
inline void lex_string_set(LEX_STRING *lex_str, const char *c_str)
 
2186
{
 
2187
  lex_str->str= (char *) c_str;
 
2188
  lex_str->length= strlen(c_str);
 
2189
}
 
2190
 
 
2191
bool load_charset(MEM_ROOT *mem_root,
 
2192
                  Field *field,
 
2193
                  CHARSET_INFO *dflt_cs,
 
2194
                  CHARSET_INFO **cs);
 
2195
 
 
2196
bool load_collation(MEM_ROOT *mem_root,
 
2197
                    Field *field,
 
2198
                    CHARSET_INFO *dflt_cl,
 
2199
                    CHARSET_INFO **cl);
 
2200
 
 
2201
#endif /* MYSQL_SERVER */
 
2202
#endif /* MYSQL_CLIENT */
 
2203
 
 
2204
#endif /* MYSQL_PRIV_H */