~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/mysql_priv.h

  • Committer: Monty Taylor
  • Date: 2008-07-01 14:33:36 UTC
  • mto: (28.1.12 backport_patch)
  • mto: This revision was merged to the branch mainline in revision 34.
  • Revision ID: monty@inaugust.com-20080701143336-8uihm7dhpu92rt0q
Somehow missed moving password.c. Duh.

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