2003-02-04 20:52:14 +01:00
|
|
|
/* Copyright (C) 2000-2003 MySQL AB
|
2000-10-10 21:31:00 +02:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2006-12-23 20:17:15 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2000-10-10 21:31:00 +02:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2000-10-10 21:31:00 +02:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
|
This will be pushed only after I fix the testsuite.
This is the main commit for Worklog tasks:
* A more dynamic binlog format which allows small changes (1064)
* Log session variables in Query_log_event (1063)
Below 5.0 means 5.0.0.
MySQL 5.0 is able to replicate FOREIGN_KEY_CHECKS, UNIQUE_KEY_CHECKS (for speed),
SQL_AUTO_IS_NULL, SQL_MODE. Not charsets (WL#1062), not some vars (I can only think
of SQL_SELECT_LIMIT, which deserves a special treatment). Note that this
works for queries, except LOAD DATA INFILE (for this it would have to wait
for Dmitri's push of WL#874, which in turns waits for the present push, so...
the deadlock must be broken!). Note that when Dmitri pushes WL#874 in 5.0.1,
5.0.0 won't be able to replicate a LOAD DATA INFILE from 5.0.1.
Apart from that, the new binlog format is designed so that it can tolerate
a little variation in the events (so that a 5.0.0 slave could replicate a
5.0.1 master, except for LOAD DATA INFILE unfortunately); that is, when I
later add replication of charsets it should break nothing. And when I later
add a UID to every event, it should break nothing.
The main change brought by this patch is a new type of event, Format_description_log_event,
which describes some lengthes in other event types. This event is needed for
the master/slave/mysqlbinlog to understand a 5.0 log. Thanks to this event,
we can later add more bytes to the header of every event without breaking compatibility.
Inside Query_log_event, we have some additional dynamic format, as every Query_log_event
can have a different number of status variables, stored as pairs (code, value); that's
how SQL_MODE and session variables and catalog are stored. Like this, we can later
add count of affected rows, charsets... and we can have options --don't-log-count-affected-rows
if we want.
MySQL 5.0 is able to run on 4.x relay logs, 4.x binlogs.
Upgrading a 4.x master to 5.0 is ok (no need to delete binlogs),
upgrading a 4.x slave to 5.0 is ok (no need to delete relay logs);
so both can be "hot" upgrades.
Upgrading a 3.23 master to 5.0 requires as much as upgrading it to 4.0.
3.23 and 4.x can't be slaves of 5.0.
So downgrading from 5.0 to 4.x may be complicated.
Log_event::log_pos is now the position of the end of the event, which is
more useful than the position of the beginning. We take care about compatibility
with <5.0 (in which log_pos is the beginning).
I added a short test for replication of SQL_MODE and some other variables.
TODO:
- after committing this, merge the latest 5.0 into it
- fix all tests
- update the manual with upgrade notes.
2003-12-18 01:09:05 +01:00
|
|
|
/*
|
|
|
|
Mostly this file is used in the server. But a little part of it is used in
|
|
|
|
mysqlbinlog too (definition of SELECT_DISTINCT and others).
|
|
|
|
The consequence is that 90% of the file is wrapped in #ifndef MYSQL_CLIENT,
|
|
|
|
except the part which must be in the server and in the client.
|
|
|
|
*/
|
|
|
|
|
2006-05-03 15:00:38 +02:00
|
|
|
#ifndef MYSQL_PRIV_H
|
|
|
|
#define MYSQL_PRIV_H
|
|
|
|
|
This will be pushed only after I fix the testsuite.
This is the main commit for Worklog tasks:
* A more dynamic binlog format which allows small changes (1064)
* Log session variables in Query_log_event (1063)
Below 5.0 means 5.0.0.
MySQL 5.0 is able to replicate FOREIGN_KEY_CHECKS, UNIQUE_KEY_CHECKS (for speed),
SQL_AUTO_IS_NULL, SQL_MODE. Not charsets (WL#1062), not some vars (I can only think
of SQL_SELECT_LIMIT, which deserves a special treatment). Note that this
works for queries, except LOAD DATA INFILE (for this it would have to wait
for Dmitri's push of WL#874, which in turns waits for the present push, so...
the deadlock must be broken!). Note that when Dmitri pushes WL#874 in 5.0.1,
5.0.0 won't be able to replicate a LOAD DATA INFILE from 5.0.1.
Apart from that, the new binlog format is designed so that it can tolerate
a little variation in the events (so that a 5.0.0 slave could replicate a
5.0.1 master, except for LOAD DATA INFILE unfortunately); that is, when I
later add replication of charsets it should break nothing. And when I later
add a UID to every event, it should break nothing.
The main change brought by this patch is a new type of event, Format_description_log_event,
which describes some lengthes in other event types. This event is needed for
the master/slave/mysqlbinlog to understand a 5.0 log. Thanks to this event,
we can later add more bytes to the header of every event without breaking compatibility.
Inside Query_log_event, we have some additional dynamic format, as every Query_log_event
can have a different number of status variables, stored as pairs (code, value); that's
how SQL_MODE and session variables and catalog are stored. Like this, we can later
add count of affected rows, charsets... and we can have options --don't-log-count-affected-rows
if we want.
MySQL 5.0 is able to run on 4.x relay logs, 4.x binlogs.
Upgrading a 4.x master to 5.0 is ok (no need to delete binlogs),
upgrading a 4.x slave to 5.0 is ok (no need to delete relay logs);
so both can be "hot" upgrades.
Upgrading a 3.23 master to 5.0 requires as much as upgrading it to 4.0.
3.23 and 4.x can't be slaves of 5.0.
So downgrading from 5.0 to 4.x may be complicated.
Log_event::log_pos is now the position of the end of the event, which is
more useful than the position of the beginning. We take care about compatibility
with <5.0 (in which log_pos is the beginning).
I added a short test for replication of SQL_MODE and some other variables.
TODO:
- after committing this, merge the latest 5.0 into it
- fix all tests
- update the manual with upgrade notes.
2003-12-18 01:09:05 +01:00
|
|
|
#ifndef MYSQL_CLIENT
|
|
|
|
|
2001-09-14 01:54:33 +02:00
|
|
|
#include <my_global.h>
|
2002-07-23 17:31:22 +02:00
|
|
|
#include <mysql_version.h>
|
|
|
|
#include <mysql_embed.h>
|
2000-07-31 21:29:14 +02:00
|
|
|
#include <my_sys.h>
|
2004-06-24 17:08:36 +02:00
|
|
|
#include <my_time.h>
|
2000-07-31 21:29:14 +02:00
|
|
|
#include <m_string.h>
|
|
|
|
#include <hash.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <thr_lock.h>
|
|
|
|
#include <my_base.h> /* Needed by field.h */
|
Bug#22687 (Functions UNIQUE_USERS, GROUP_UNIQUE_USERS)
According to some internal communication, these two functions are place
holders for future enhancements. Because they use a variable number of
parameters, the implementation defined a reserved keyword for them in the
parser grammar.
Unfortunately, doing so creates a bug similar to Bug 21114 reported for the
function FORMAT.
In the 5.1 code base, due to improvements in the code implemented with bug
21114, having a reserved keyword for functions with a variable number of
arguments is not needed any more by the implementation.
As a result, this fix removes the place-holder implementation, and removes
the unnecessary reserved keywords. Should the functions UNIQUE_USERS and
GROUP_UNIQUE_USERS be finally implemented in a later release, the
implementation should sub class Create_native_func in sql/item_create.cc.
For example, see the class Create_func_concat.
2007-01-11 22:58:05 +01:00
|
|
|
#include <queues.h>
|
2003-11-12 09:38:46 +01:00
|
|
|
#include "sql_bitmap.h"
|
2005-08-25 15:34:34 +02:00
|
|
|
#include "sql_array.h"
|
2007-04-02 20:38:58 +02:00
|
|
|
#include "sql_plugin.h"
|
2007-02-23 12:13:55 +01:00
|
|
|
#include "scheduler.h"
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2003-10-11 13:06:55 +02:00
|
|
|
/* TODO convert all these three maps to Bitmap classes */
|
|
|
|
typedef ulonglong table_map; /* Used for table bits in join */
|
Bug#10932 - Building server with key limit of 128, makes test cases fail
Allow for configuration of the maximum number of indexes per table.
Added and used a configure.in macro.
Replaced fixed limits by the configurable limit.
Limited MyISAM indexes to its hard limit.
Fixed a bug in opt_range.cc for many indexes with InnoDB.
Tested for 2, 63, 64, 65, 127, 128, 129, 255, 256, and 257 indexes.
Testing this part of the bugfix requires rebuilding of the server
with different options. This cannot be done with our test suite.
Therefore I added the necessary test files to the bug report.
If you repeat the tests, please note that the ps_* tests fail for
everything but 64 indexes. This is because of differences in the
meta data, namely field lengths for index names etc.
2005-12-02 16:27:18 +01:00
|
|
|
#if MAX_INDEXES <= 64
|
|
|
|
typedef Bitmap<64> key_map; /* Used for finding keys */
|
|
|
|
#else
|
|
|
|
typedef Bitmap<((MAX_INDEXES+7)/8*8)> key_map; /* Used for finding keys */
|
|
|
|
#endif
|
2005-10-15 23:32:37 +02:00
|
|
|
typedef ulong nesting_map; /* Used for flags of nesting constructs */
|
2005-10-25 17:28:27 +02:00
|
|
|
/*
|
2005-11-01 06:36:49 +01:00
|
|
|
Used to identify NESTED_JOIN structures within a join (applicable only to
|
|
|
|
structures that have not been simplified away and embed more the one
|
|
|
|
element)
|
2005-10-25 17:28:27 +02:00
|
|
|
*/
|
|
|
|
typedef ulonglong nested_join_map;
|
2003-10-11 13:06:55 +02:00
|
|
|
|
2005-03-19 01:12:25 +01:00
|
|
|
/* query_id */
|
|
|
|
typedef ulonglong query_id_t;
|
2006-12-14 23:51:37 +01:00
|
|
|
extern query_id_t global_query_id;
|
2005-03-19 01:12:25 +01:00
|
|
|
|
|
|
|
/* increment query_id and return it. */
|
2006-12-14 23:51:37 +01:00
|
|
|
inline query_id_t next_query_id() { return global_query_id++; }
|
2005-03-19 01:12:25 +01:00
|
|
|
|
2003-10-11 13:06:55 +02:00
|
|
|
/* useful constants */
|
|
|
|
extern const key_map key_map_empty;
|
2005-06-03 22:46:03 +02:00
|
|
|
extern key_map key_map_full; /* Should be threaded as const */
|
2004-01-14 13:01:55 +01:00
|
|
|
extern const char *primary_key_name;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
#include "mysql_com.h"
|
2001-05-31 16:42:37 +02:00
|
|
|
#include <violite.h>
|
2000-07-31 21:29:14 +02:00
|
|
|
#include "unireg.h"
|
|
|
|
|
2000-09-12 02:02:33 +02:00
|
|
|
void init_sql_alloc(MEM_ROOT *root, uint block_size, uint pre_alloc_size);
|
2000-07-31 21:29:14 +02:00
|
|
|
gptr sql_alloc(unsigned size);
|
|
|
|
gptr sql_calloc(unsigned size);
|
|
|
|
char *sql_strdup(const char *str);
|
|
|
|
char *sql_strmake(const char *str,uint len);
|
|
|
|
gptr sql_memdup(const void * ptr,unsigned size);
|
|
|
|
void sql_element_free(void *ptr);
|
2003-05-21 20:39:58 +02:00
|
|
|
char *sql_strmake_with_convert(const char *str, uint32 arg_length,
|
|
|
|
CHARSET_INFO *from_cs,
|
|
|
|
uint32 max_res_length,
|
|
|
|
CHARSET_INFO *to_cs, uint32 *result_length);
|
2006-05-22 20:46:13 +02:00
|
|
|
uint kill_one_thread(THD *thd, ulong id, bool only_kill_query);
|
|
|
|
void sql_kill(THD *thd, ulong id, bool only_kill_query);
|
2002-06-11 10:20:31 +02:00
|
|
|
bool net_request_file(NET* net, const char* fname);
|
2001-07-08 03:15:41 +02:00
|
|
|
char* query_table_status(THD *thd,const char *db,const char *table_name);
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2007-01-29 14:31:48 +01:00
|
|
|
void net_set_write_timeout(NET *net, uint timeout);
|
|
|
|
void net_set_read_timeout(NET *net, uint timeout);
|
2005-09-14 14:31:38 +02:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
#define x_free(A) { my_free((gptr) (A),MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR)); }
|
|
|
|
#define safeFree(x) { if(x) { my_free((gptr) x,MYF(0)); x = NULL; } }
|
|
|
|
#define PREV_BITS(type,A) ((type) (((type) 1 << (A)) -1))
|
|
|
|
#define all_bits_set(A,B) ((A) & (B) != (B))
|
|
|
|
|
BUG#21490 - No warning issued for deprecated replication parameters
This patch deprecates the replication startup options in the configuration
file and on the command line. The options deprecated include:
MASTER_HOST, MASTER_USER, MASTER_PASSWORD, MASTER_PORT, MASTER_CONNECT_RETRY,
MASTER_SSL, MASTER_SSL_CA, MASTER_SSL_CAPATH, MASTER_SSL_CERT, MASTER_SSL_KEY,
and MASTER_SSL_CIPHER
The code is designed to print the warning message once.
2007-01-18 19:20:38 +01:00
|
|
|
#define WARN_DEPRECATED(Thd,Ver,Old,New) \
|
|
|
|
do { \
|
|
|
|
DBUG_ASSERT(strncmp(Ver, MYSQL_SERVER_VERSION, sizeof(Ver)-1) > 0); \
|
2007-03-01 08:41:13 +01:00
|
|
|
if (((gptr)Thd) != NULL) \
|
BUG#21490 - No warning issued for deprecated replication parameters
This patch deprecates the replication startup options in the configuration
file and on the command line. The options deprecated include:
MASTER_HOST, MASTER_USER, MASTER_PASSWORD, MASTER_PORT, MASTER_CONNECT_RETRY,
MASTER_SSL, MASTER_SSL_CA, MASTER_SSL_CAPATH, MASTER_SSL_CERT, MASTER_SSL_KEY,
and MASTER_SSL_CIPHER
The code is designed to print the warning message once.
2007-01-18 19:20:38 +01:00
|
|
|
push_warning_printf(((THD *)Thd), MYSQL_ERROR::WARN_LEVEL_WARN, \
|
|
|
|
ER_WARN_DEPRECATED_SYNTAX, ER(ER_WARN_DEPRECATED_SYNTAX), \
|
|
|
|
(Old), (Ver), (New)); \
|
|
|
|
else \
|
|
|
|
sql_print_warning("The syntax %s is deprecated and will be removed " \
|
|
|
|
"in MySQL %s. Please use %s instead.", (Old), (Ver), (New)); \
|
2006-03-01 21:36:05 +01:00
|
|
|
} while(0)
|
|
|
|
|
2003-06-04 17:28:51 +02:00
|
|
|
extern CHARSET_INFO *system_charset_info, *files_charset_info ;
|
|
|
|
extern CHARSET_INFO *national_charset_info, *table_alias_charset;
|
2002-10-30 13:19:43 +01:00
|
|
|
|
2006-07-04 14:40:40 +02:00
|
|
|
|
2006-11-09 11:41:34 +01:00
|
|
|
enum Derivation
|
|
|
|
{
|
|
|
|
DERIVATION_IGNORABLE= 5,
|
|
|
|
DERIVATION_COERCIBLE= 4,
|
|
|
|
DERIVATION_SYSCONST= 3,
|
|
|
|
DERIVATION_IMPLICIT= 2,
|
|
|
|
DERIVATION_NONE= 1,
|
|
|
|
DERIVATION_EXPLICIT= 0
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-07-04 14:40:40 +02:00
|
|
|
typedef struct my_locale_st
|
|
|
|
{
|
2006-12-05 10:45:21 +01:00
|
|
|
uint number;
|
2006-07-04 14:40:40 +02:00
|
|
|
const char *name;
|
|
|
|
const char *description;
|
|
|
|
const bool is_ascii;
|
|
|
|
TYPELIB *month_names;
|
|
|
|
TYPELIB *ab_month_names;
|
|
|
|
TYPELIB *day_names;
|
|
|
|
TYPELIB *ab_day_names;
|
2006-08-21 14:21:48 +02:00
|
|
|
#ifdef __cplusplus
|
2006-12-05 13:01:21 +01:00
|
|
|
my_locale_st(uint number_par,
|
|
|
|
const char *name_par, const char *descr_par, bool is_ascii_par,
|
2006-08-21 14:21:48 +02:00
|
|
|
TYPELIB *month_names_par, TYPELIB *ab_month_names_par,
|
|
|
|
TYPELIB *day_names_par, TYPELIB *ab_day_names_par) :
|
2006-12-05 13:01:21 +01:00
|
|
|
number(number_par),
|
2006-08-21 14:21:48 +02:00
|
|
|
name(name_par), description(descr_par), is_ascii(is_ascii_par),
|
2006-08-22 13:03:13 +02:00
|
|
|
month_names(month_names_par), ab_month_names(ab_month_names_par),
|
2006-08-21 14:21:48 +02:00
|
|
|
day_names(day_names_par), ab_day_names(ab_day_names_par)
|
|
|
|
{}
|
|
|
|
#endif
|
2006-07-04 14:40:40 +02:00
|
|
|
} MY_LOCALE;
|
|
|
|
|
|
|
|
extern MY_LOCALE my_locale_en_US;
|
|
|
|
extern MY_LOCALE *my_locales[];
|
2007-04-09 14:58:56 +02:00
|
|
|
extern MY_LOCALE *my_default_lc_time_names;
|
2006-07-04 14:40:40 +02:00
|
|
|
|
|
|
|
MY_LOCALE *my_locale_by_name(const char *name);
|
2006-12-05 10:45:21 +01:00
|
|
|
MY_LOCALE *my_locale_by_number(uint number);
|
2006-07-04 14:40:40 +02:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
/***************************************************************************
|
2000-10-10 21:31:00 +02:00
|
|
|
Configuration parameters
|
2000-07-31 21:29:14 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#define ACL_CACHE_SIZE 256
|
2003-07-04 02:18:15 +02:00
|
|
|
#define MAX_PASSWORD_LENGTH 32
|
2000-07-31 21:29:14 +02:00
|
|
|
#define HOST_CACHE_SIZE 128
|
|
|
|
#define MAX_ACCEPT_RETRY 10 // Test accept this many times
|
|
|
|
#define MAX_FIELDS_BEFORE_HASH 32
|
|
|
|
#define USER_VARS_HASH_SIZE 16
|
2006-10-30 15:47:02 +01:00
|
|
|
#define TABLE_OPEN_CACHE_MIN 64
|
|
|
|
#define TABLE_OPEN_CACHE_DEFAULT 64
|
2006-09-27 20:42:56 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Value of 9236 discovered through binary search 2006-09-26 on Ubuntu Dapper
|
|
|
|
Drake, libc6 2.3.6-0ubuntu2, Linux kernel 2.6.15-27-686, on x86. (Added
|
|
|
|
100 bytes as reasonable buffer against growth and other environments'
|
|
|
|
requirements.)
|
|
|
|
|
|
|
|
Feel free to raise this by the smallest amount you can to get the
|
|
|
|
"execution_constants" test to pass.
|
|
|
|
*/
|
2006-12-14 23:51:37 +01:00
|
|
|
#define STACK_MIN_SIZE 12000 // Abort if less stack during eval.
|
2006-09-27 20:42:56 +02:00
|
|
|
|
2005-11-24 01:36:28 +01:00
|
|
|
#define STACK_MIN_SIZE_FOR_OPEN 1024*80
|
2005-06-05 16:01:20 +02:00
|
|
|
#define STACK_BUFF_ALLOC 256 // For stack overrun checks
|
2000-07-31 21:29:14 +02:00
|
|
|
#ifndef MYSQLD_NET_RETRY_COUNT
|
|
|
|
#define MYSQLD_NET_RETRY_COUNT 10 // Abort read after this many int.
|
|
|
|
#endif
|
2001-01-27 10:24:05 +01:00
|
|
|
#define TEMP_POOL_SIZE 128
|
2003-10-11 21:00:24 +02:00
|
|
|
|
|
|
|
#define QUERY_ALLOC_BLOCK_SIZE 8192
|
|
|
|
#define QUERY_ALLOC_PREALLOC_SIZE 8192
|
|
|
|
#define TRANS_ALLOC_BLOCK_SIZE 4096
|
|
|
|
#define TRANS_ALLOC_PREALLOC_SIZE 4096
|
|
|
|
#define RANGE_ALLOC_BLOCK_SIZE 2048
|
|
|
|
#define ACL_ALLOC_BLOCK_SIZE 1024
|
|
|
|
#define UDF_ALLOC_BLOCK_SIZE 1024
|
|
|
|
#define TABLE_ALLOC_BLOCK_SIZE 1024
|
2003-10-15 21:40:36 +02:00
|
|
|
#define BDB_LOG_ALLOC_BLOCK_SIZE 1024
|
|
|
|
#define WARN_ALLOC_BLOCK_SIZE 2048
|
|
|
|
#define WARN_ALLOC_PREALLOC_SIZE 1024
|
2003-10-11 21:00:24 +02:00
|
|
|
|
2002-04-18 17:24:14 +02:00
|
|
|
/*
|
|
|
|
The following parameters is to decide when to use an extra cache to
|
2002-06-12 14:04:18 +02:00
|
|
|
optimise seeks when reading a big table in sorted order
|
2002-04-18 17:24:14 +02:00
|
|
|
*/
|
2005-04-07 18:24:14 +02:00
|
|
|
#define MIN_FILE_LENGTH_TO_USE_ROW_CACHE (10L*1024*1024)
|
2000-07-31 21:29:14 +02:00
|
|
|
#define MIN_ROWS_TO_USE_TABLE_CACHE 100
|
2002-11-20 21:56:57 +01:00
|
|
|
#define MIN_ROWS_TO_USE_BULK_INSERT 100
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2002-04-18 17:24:14 +02:00
|
|
|
/*
|
|
|
|
The following is used to decide if MySQL should use table scanning
|
|
|
|
instead of reading with keys. The number says how many evaluation of the
|
|
|
|
WHERE clause is comparable to reading one extra row from a table.
|
|
|
|
*/
|
2000-09-14 01:39:07 +02:00
|
|
|
#define TIME_FOR_COMPARE 5 // 5 compares == one read
|
2002-04-18 17:24:14 +02:00
|
|
|
|
2003-12-18 04:08:00 +01:00
|
|
|
/*
|
|
|
|
Number of comparisons of table rowids equivalent to reading one row from a
|
|
|
|
table.
|
|
|
|
*/
|
|
|
|
#define TIME_FOR_COMPARE_ROWID (TIME_FOR_COMPARE*2)
|
|
|
|
|
|
|
|
/*
|
|
|
|
For sequential disk seeks the cost formula is:
|
|
|
|
DISK_SEEK_BASE_COST + DISK_SEEK_PROP_COST * #blocks_to_skip
|
|
|
|
|
|
|
|
The cost of average seek
|
|
|
|
DISK_SEEK_BASE_COST + DISK_SEEK_PROP_COST*BLOCKS_IN_AVG_SEEK =1.0.
|
|
|
|
*/
|
|
|
|
#define DISK_SEEK_BASE_COST ((double)0.5)
|
|
|
|
|
|
|
|
#define BLOCKS_IN_AVG_SEEK 128
|
|
|
|
|
|
|
|
#define DISK_SEEK_PROP_COST ((double)0.5/BLOCKS_IN_AVG_SEEK)
|
|
|
|
|
|
|
|
|
2002-04-18 17:24:14 +02:00
|
|
|
/*
|
|
|
|
Number of rows in a reference table when refereed through a not unique key.
|
|
|
|
This value is only used when we don't know anything about the key
|
|
|
|
distribution.
|
|
|
|
*/
|
2000-10-10 21:31:00 +02:00
|
|
|
#define MATCHING_ROWS_IN_OTHER_TABLE 10
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
/* Don't pack string keys shorter than this (if PACK_KEYS=1 isn't used) */
|
|
|
|
#define KEY_DEFAULT_PACK_LENGTH 8
|
|
|
|
|
|
|
|
/* Characters shown for the command in 'show processlist' */
|
|
|
|
#define PROCESS_LIST_WIDTH 100
|
2006-05-02 21:08:22 +02:00
|
|
|
/* Characters shown for the command in 'information_schema.processlist' */
|
|
|
|
#define PROCESS_LIST_INFO_WIDTH 65535
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
#define PRECISION_FOR_DOUBLE 53
|
|
|
|
#define PRECISION_FOR_FLOAT 24
|
|
|
|
|
|
|
|
/* The following can also be changed from the command line */
|
|
|
|
#define CONNECT_TIMEOUT 5 // Do not wait long for connect
|
|
|
|
#define DEFAULT_CONCURRENCY 10
|
|
|
|
#define DELAYED_LIMIT 100 /* pause after xxx inserts */
|
|
|
|
#define DELAYED_QUEUE_SIZE 1000
|
|
|
|
#define DELAYED_WAIT_TIMEOUT 5*60 /* Wait for delayed insert */
|
|
|
|
#define FLUSH_TIME 0 /* Don't flush tables */
|
|
|
|
#define MAX_CONNECT_ERRORS 10 // errors before disabling host
|
|
|
|
|
2005-05-06 10:39:30 +02:00
|
|
|
#ifdef __NETWARE__
|
|
|
|
#define IF_NETWARE(A,B) (A)
|
|
|
|
#else
|
|
|
|
#define IF_NETWARE(A,B) (B)
|
|
|
|
#endif
|
2005-02-24 17:55:20 +01:00
|
|
|
|
2006-04-16 03:17:32 +02:00
|
|
|
#if defined(__WIN__)
|
2000-07-31 21:29:14 +02:00
|
|
|
#undef FLUSH_TIME
|
|
|
|
#define FLUSH_TIME 1800 /* Flush every half hour */
|
|
|
|
|
|
|
|
#define INTERRUPT_PRIOR -2
|
|
|
|
#define CONNECT_PRIOR -1
|
|
|
|
#define WAIT_PRIOR 0
|
|
|
|
#define QUERY_PRIOR 2
|
|
|
|
#else
|
|
|
|
#define INTERRUPT_PRIOR 10
|
|
|
|
#define CONNECT_PRIOR 9
|
|
|
|
#define WAIT_PRIOR 8
|
|
|
|
#define QUERY_PRIOR 6
|
|
|
|
#endif /* __WIN92__ */
|
|
|
|
|
2000-12-24 14:19:00 +01:00
|
|
|
/* Bits from testflag */
|
2000-07-31 21:29:14 +02:00
|
|
|
#define TEST_PRINT_CACHED_TABLES 1
|
|
|
|
#define TEST_NO_KEY_GROUP 2
|
|
|
|
#define TEST_MIT_THREAD 4
|
|
|
|
#define TEST_BLOCKING 8
|
|
|
|
#define TEST_KEEP_TMP_TABLES 16
|
|
|
|
#define TEST_READCHECK 64 /* Force use of readcheck */
|
|
|
|
#define TEST_NO_EXTRA 128
|
2000-08-30 05:05:12 +02:00
|
|
|
#define TEST_CORE_ON_SIGNAL 256 /* Give core if signal */
|
2001-03-07 22:50:44 +01:00
|
|
|
#define TEST_NO_STACKTRACE 512
|
2003-06-10 20:42:29 +02:00
|
|
|
#define TEST_SIGINT 1024 /* Allow sigint on threads */
|
2005-06-09 15:48:57 +02:00
|
|
|
#define TEST_SYNCHRONIZATION 2048 /* get server to do sleep in
|
|
|
|
some places */
|
This will be pushed only after I fix the testsuite.
This is the main commit for Worklog tasks:
* A more dynamic binlog format which allows small changes (1064)
* Log session variables in Query_log_event (1063)
Below 5.0 means 5.0.0.
MySQL 5.0 is able to replicate FOREIGN_KEY_CHECKS, UNIQUE_KEY_CHECKS (for speed),
SQL_AUTO_IS_NULL, SQL_MODE. Not charsets (WL#1062), not some vars (I can only think
of SQL_SELECT_LIMIT, which deserves a special treatment). Note that this
works for queries, except LOAD DATA INFILE (for this it would have to wait
for Dmitri's push of WL#874, which in turns waits for the present push, so...
the deadlock must be broken!). Note that when Dmitri pushes WL#874 in 5.0.1,
5.0.0 won't be able to replicate a LOAD DATA INFILE from 5.0.1.
Apart from that, the new binlog format is designed so that it can tolerate
a little variation in the events (so that a 5.0.0 slave could replicate a
5.0.1 master, except for LOAD DATA INFILE unfortunately); that is, when I
later add replication of charsets it should break nothing. And when I later
add a UID to every event, it should break nothing.
The main change brought by this patch is a new type of event, Format_description_log_event,
which describes some lengthes in other event types. This event is needed for
the master/slave/mysqlbinlog to understand a 5.0 log. Thanks to this event,
we can later add more bytes to the header of every event without breaking compatibility.
Inside Query_log_event, we have some additional dynamic format, as every Query_log_event
can have a different number of status variables, stored as pairs (code, value); that's
how SQL_MODE and session variables and catalog are stored. Like this, we can later
add count of affected rows, charsets... and we can have options --don't-log-count-affected-rows
if we want.
MySQL 5.0 is able to run on 4.x relay logs, 4.x binlogs.
Upgrading a 4.x master to 5.0 is ok (no need to delete binlogs),
upgrading a 4.x slave to 5.0 is ok (no need to delete relay logs);
so both can be "hot" upgrades.
Upgrading a 3.23 master to 5.0 requires as much as upgrading it to 4.0.
3.23 and 4.x can't be slaves of 5.0.
So downgrading from 5.0 to 4.x may be complicated.
Log_event::log_pos is now the position of the end of the event, which is
more useful than the position of the beginning. We take care about compatibility
with <5.0 (in which log_pos is the beginning).
I added a short test for replication of SQL_MODE and some other variables.
TODO:
- after committing this, merge the latest 5.0 into it
- fix all tests
- update the manual with upgrade notes.
2003-12-18 01:09:05 +01:00
|
|
|
#endif
|
|
|
|
|
2005-06-09 15:48:57 +02:00
|
|
|
/*
|
This will be pushed only after I fix the testsuite.
This is the main commit for Worklog tasks:
* A more dynamic binlog format which allows small changes (1064)
* Log session variables in Query_log_event (1063)
Below 5.0 means 5.0.0.
MySQL 5.0 is able to replicate FOREIGN_KEY_CHECKS, UNIQUE_KEY_CHECKS (for speed),
SQL_AUTO_IS_NULL, SQL_MODE. Not charsets (WL#1062), not some vars (I can only think
of SQL_SELECT_LIMIT, which deserves a special treatment). Note that this
works for queries, except LOAD DATA INFILE (for this it would have to wait
for Dmitri's push of WL#874, which in turns waits for the present push, so...
the deadlock must be broken!). Note that when Dmitri pushes WL#874 in 5.0.1,
5.0.0 won't be able to replicate a LOAD DATA INFILE from 5.0.1.
Apart from that, the new binlog format is designed so that it can tolerate
a little variation in the events (so that a 5.0.0 slave could replicate a
5.0.1 master, except for LOAD DATA INFILE unfortunately); that is, when I
later add replication of charsets it should break nothing. And when I later
add a UID to every event, it should break nothing.
The main change brought by this patch is a new type of event, Format_description_log_event,
which describes some lengthes in other event types. This event is needed for
the master/slave/mysqlbinlog to understand a 5.0 log. Thanks to this event,
we can later add more bytes to the header of every event without breaking compatibility.
Inside Query_log_event, we have some additional dynamic format, as every Query_log_event
can have a different number of status variables, stored as pairs (code, value); that's
how SQL_MODE and session variables and catalog are stored. Like this, we can later
add count of affected rows, charsets... and we can have options --don't-log-count-affected-rows
if we want.
MySQL 5.0 is able to run on 4.x relay logs, 4.x binlogs.
Upgrading a 4.x master to 5.0 is ok (no need to delete binlogs),
upgrading a 4.x slave to 5.0 is ok (no need to delete relay logs);
so both can be "hot" upgrades.
Upgrading a 3.23 master to 5.0 requires as much as upgrading it to 4.0.
3.23 and 4.x can't be slaves of 5.0.
So downgrading from 5.0 to 4.x may be complicated.
Log_event::log_pos is now the position of the end of the event, which is
more useful than the position of the beginning. We take care about compatibility
with <5.0 (in which log_pos is the beginning).
I added a short test for replication of SQL_MODE and some other variables.
TODO:
- after committing this, merge the latest 5.0 into it
- fix all tests
- update the manual with upgrade notes.
2003-12-18 01:09:05 +01:00
|
|
|
This is included in the server and in the client.
|
|
|
|
Options for select set by the yacc parser (stored in lex->options).
|
2005-06-09 15:48:57 +02:00
|
|
|
|
|
|
|
XXX:
|
|
|
|
log_event.h defines OPTIONS_WRITTEN_TO_BIN_LOG to specify what THD
|
|
|
|
options list are written into binlog. These options can NOT change their
|
|
|
|
values, or it will break replication between version.
|
|
|
|
|
|
|
|
context is encoded as following:
|
|
|
|
SELECT - SELECT_LEX_NODE::options
|
|
|
|
THD - THD::options
|
|
|
|
intern - neither. used only as
|
|
|
|
func(..., select_node->options | thd->options | OPTION_XXX, ...)
|
|
|
|
|
|
|
|
TODO: separate three contexts above, move them to separate bitfields.
|
This will be pushed only after I fix the testsuite.
This is the main commit for Worklog tasks:
* A more dynamic binlog format which allows small changes (1064)
* Log session variables in Query_log_event (1063)
Below 5.0 means 5.0.0.
MySQL 5.0 is able to replicate FOREIGN_KEY_CHECKS, UNIQUE_KEY_CHECKS (for speed),
SQL_AUTO_IS_NULL, SQL_MODE. Not charsets (WL#1062), not some vars (I can only think
of SQL_SELECT_LIMIT, which deserves a special treatment). Note that this
works for queries, except LOAD DATA INFILE (for this it would have to wait
for Dmitri's push of WL#874, which in turns waits for the present push, so...
the deadlock must be broken!). Note that when Dmitri pushes WL#874 in 5.0.1,
5.0.0 won't be able to replicate a LOAD DATA INFILE from 5.0.1.
Apart from that, the new binlog format is designed so that it can tolerate
a little variation in the events (so that a 5.0.0 slave could replicate a
5.0.1 master, except for LOAD DATA INFILE unfortunately); that is, when I
later add replication of charsets it should break nothing. And when I later
add a UID to every event, it should break nothing.
The main change brought by this patch is a new type of event, Format_description_log_event,
which describes some lengthes in other event types. This event is needed for
the master/slave/mysqlbinlog to understand a 5.0 log. Thanks to this event,
we can later add more bytes to the header of every event without breaking compatibility.
Inside Query_log_event, we have some additional dynamic format, as every Query_log_event
can have a different number of status variables, stored as pairs (code, value); that's
how SQL_MODE and session variables and catalog are stored. Like this, we can later
add count of affected rows, charsets... and we can have options --don't-log-count-affected-rows
if we want.
MySQL 5.0 is able to run on 4.x relay logs, 4.x binlogs.
Upgrading a 4.x master to 5.0 is ok (no need to delete binlogs),
upgrading a 4.x slave to 5.0 is ok (no need to delete relay logs);
so both can be "hot" upgrades.
Upgrading a 3.23 master to 5.0 requires as much as upgrading it to 4.0.
3.23 and 4.x can't be slaves of 5.0.
So downgrading from 5.0 to 4.x may be complicated.
Log_event::log_pos is now the position of the end of the event, which is
more useful than the position of the beginning. We take care about compatibility
with <5.0 (in which log_pos is the beginning).
I added a short test for replication of SQL_MODE and some other variables.
TODO:
- after committing this, merge the latest 5.0 into it
- fix all tests
- update the manual with upgrade notes.
2003-12-18 01:09:05 +01:00
|
|
|
*/
|
|
|
|
|
2007-02-02 19:11:44 +01:00
|
|
|
#define SELECT_DISTINCT (ULL(1) << 0) // SELECT, user
|
|
|
|
#define SELECT_STRAIGHT_JOIN (ULL(1) << 1) // SELECT, user
|
|
|
|
#define SELECT_DESCRIBE (ULL(1) << 2) // SELECT, user
|
|
|
|
#define SELECT_SMALL_RESULT (ULL(1) << 3) // SELECT, user
|
|
|
|
#define SELECT_BIG_RESULT (ULL(1) << 4) // SELECT, user
|
|
|
|
#define OPTION_FOUND_ROWS (ULL(1) << 5) // SELECT, user
|
|
|
|
#define OPTION_TO_QUERY_CACHE (ULL(1) << 6) // SELECT, user
|
|
|
|
#define SELECT_NO_JOIN_CACHE (ULL(1) << 7) // intern
|
|
|
|
#define OPTION_BIG_TABLES (ULL(1) << 8) // THD, user
|
|
|
|
#define OPTION_BIG_SELECTS (ULL(1) << 9) // THD, user
|
|
|
|
#define OPTION_LOG_OFF (ULL(1) << 10) // THD, user
|
2007-02-13 16:23:32 +01:00
|
|
|
#define OPTION_QUOTE_SHOW_CREATE (ULL(1) << 11) // THD, user, unused
|
2007-02-02 19:11:44 +01:00
|
|
|
#define TMP_TABLE_ALL_COLUMNS (ULL(1) << 12) // SELECT, intern
|
|
|
|
#define OPTION_WARNINGS (ULL(1) << 13) // THD, user
|
|
|
|
#define OPTION_AUTO_IS_NULL (ULL(1) << 14) // THD, user, binlog
|
|
|
|
#define OPTION_FOUND_COMMENT (ULL(1) << 15) // SELECT, intern, parser
|
|
|
|
#define OPTION_SAFE_UPDATES (ULL(1) << 16) // THD, user
|
|
|
|
#define OPTION_BUFFER_RESULT (ULL(1) << 17) // SELECT, user
|
|
|
|
#define OPTION_BIN_LOG (ULL(1) << 18) // THD, user
|
|
|
|
#define OPTION_NOT_AUTOCOMMIT (ULL(1) << 19) // THD, user
|
|
|
|
#define OPTION_BEGIN (ULL(1) << 20) // THD, intern
|
|
|
|
#define OPTION_TABLE_LOCK (ULL(1) << 21) // THD, intern
|
|
|
|
#define OPTION_QUICK (ULL(1) << 22) // SELECT (for DELETE)
|
2007-02-13 16:23:32 +01:00
|
|
|
#define OPTION_KEEP_LOG (ULL(1) << 23) // THD, user
|
2005-06-09 15:48:57 +02:00
|
|
|
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
/* The following is used to detect a conflict with DISTINCT */
|
2007-02-02 19:11:44 +01:00
|
|
|
#define SELECT_ALL (ULL(1) << 24) // SELECT, user, parser
|
2003-10-16 14:54:47 +02:00
|
|
|
|
2002-06-22 19:23:53 +02:00
|
|
|
/* The following can be set when importing tables in a 'wrong order'
|
|
|
|
to suppress foreign key checks */
|
2007-02-02 19:11:44 +01:00
|
|
|
#define OPTION_NO_FOREIGN_KEY_CHECKS (ULL(1) << 26) // THD, user, binlog
|
2002-06-22 19:23:53 +02:00
|
|
|
/* The following speeds up inserts to InnoDB tables by suppressing unique
|
|
|
|
key checks in some cases */
|
2007-02-02 19:11:44 +01:00
|
|
|
#define OPTION_RELAXED_UNIQUE_CHECKS (ULL(1) << 27) // THD, user, binlog
|
|
|
|
#define SELECT_NO_UNLOCK (ULL(1) << 28) // SELECT, intern
|
|
|
|
#define OPTION_SCHEMA_TABLE (ULL(1) << 29) // SELECT, intern
|
2005-01-03 20:04:33 +01:00
|
|
|
/* Flag set if setup_tables already done */
|
2007-02-02 19:11:44 +01:00
|
|
|
#define OPTION_SETUP_TABLES_DONE (ULL(1) << 30) // intern
|
2005-06-09 15:48:57 +02:00
|
|
|
/* If not set then the thread will ignore all warnings with level notes. */
|
2007-02-02 19:11:44 +01:00
|
|
|
#define OPTION_SQL_NOTES (ULL(1) << 31) // THD, user
|
2005-08-12 12:54:42 +02:00
|
|
|
/*
|
|
|
|
Force the used temporary table to be a MyISAM table (because we will use
|
|
|
|
fulltext functions when reading from it.
|
|
|
|
*/
|
2007-02-02 19:11:44 +01:00
|
|
|
#define TMP_TABLE_FORCE_MYISAM (ULL(1) << 32)
|
2007-01-26 20:47:12 +01:00
|
|
|
|
2003-12-06 23:21:09 +01:00
|
|
|
|
2005-06-09 15:48:57 +02:00
|
|
|
/*
|
|
|
|
Maximum length of time zone name that we support
|
2005-03-22 00:26:12 +01:00
|
|
|
(Time zone name is char(64) in db). mysqlbinlog needs it.
|
|
|
|
*/
|
2007-04-03 16:40:55 +02:00
|
|
|
#define MAX_TIME_ZONE_NAME_LENGTH (NAME_LEN + 1)
|
2005-03-22 00:26:12 +01:00
|
|
|
|
This will be pushed only after I fix the testsuite.
This is the main commit for Worklog tasks:
* A more dynamic binlog format which allows small changes (1064)
* Log session variables in Query_log_event (1063)
Below 5.0 means 5.0.0.
MySQL 5.0 is able to replicate FOREIGN_KEY_CHECKS, UNIQUE_KEY_CHECKS (for speed),
SQL_AUTO_IS_NULL, SQL_MODE. Not charsets (WL#1062), not some vars (I can only think
of SQL_SELECT_LIMIT, which deserves a special treatment). Note that this
works for queries, except LOAD DATA INFILE (for this it would have to wait
for Dmitri's push of WL#874, which in turns waits for the present push, so...
the deadlock must be broken!). Note that when Dmitri pushes WL#874 in 5.0.1,
5.0.0 won't be able to replicate a LOAD DATA INFILE from 5.0.1.
Apart from that, the new binlog format is designed so that it can tolerate
a little variation in the events (so that a 5.0.0 slave could replicate a
5.0.1 master, except for LOAD DATA INFILE unfortunately); that is, when I
later add replication of charsets it should break nothing. And when I later
add a UID to every event, it should break nothing.
The main change brought by this patch is a new type of event, Format_description_log_event,
which describes some lengthes in other event types. This event is needed for
the master/slave/mysqlbinlog to understand a 5.0 log. Thanks to this event,
we can later add more bytes to the header of every event without breaking compatibility.
Inside Query_log_event, we have some additional dynamic format, as every Query_log_event
can have a different number of status variables, stored as pairs (code, value); that's
how SQL_MODE and session variables and catalog are stored. Like this, we can later
add count of affected rows, charsets... and we can have options --don't-log-count-affected-rows
if we want.
MySQL 5.0 is able to run on 4.x relay logs, 4.x binlogs.
Upgrading a 4.x master to 5.0 is ok (no need to delete binlogs),
upgrading a 4.x slave to 5.0 is ok (no need to delete relay logs);
so both can be "hot" upgrades.
Upgrading a 3.23 master to 5.0 requires as much as upgrading it to 4.0.
3.23 and 4.x can't be slaves of 5.0.
So downgrading from 5.0 to 4.x may be complicated.
Log_event::log_pos is now the position of the end of the event, which is
more useful than the position of the beginning. We take care about compatibility
with <5.0 (in which log_pos is the beginning).
I added a short test for replication of SQL_MODE and some other variables.
TODO:
- after committing this, merge the latest 5.0 into it
- fix all tests
- update the manual with upgrade notes.
2003-12-18 01:09:05 +01:00
|
|
|
/* The rest of the file is included in the server only */
|
|
|
|
#ifndef MYSQL_CLIENT
|
|
|
|
|
2002-02-14 17:10:44 +01:00
|
|
|
/* Bits for different SQL modes modes (including ANSI mode) */
|
2005-06-09 15:48:57 +02:00
|
|
|
#define MODE_REAL_AS_FLOAT 1
|
|
|
|
#define MODE_PIPES_AS_CONCAT 2
|
|
|
|
#define MODE_ANSI_QUOTES 4
|
2002-01-30 14:32:48 +01:00
|
|
|
#define MODE_IGNORE_SPACE 8
|
2003-06-04 17:28:51 +02:00
|
|
|
#define MODE_NOT_USED 16
|
2002-01-30 14:32:48 +01:00
|
|
|
#define MODE_ONLY_FULL_GROUP_BY 32
|
|
|
|
#define MODE_NO_UNSIGNED_SUBTRACTION 64
|
2003-08-23 11:25:39 +02:00
|
|
|
#define MODE_NO_DIR_IN_CREATE 128
|
2003-08-29 12:44:35 +02:00
|
|
|
#define MODE_POSTGRESQL 256
|
|
|
|
#define MODE_ORACLE 512
|
|
|
|
#define MODE_MSSQL 1024
|
|
|
|
#define MODE_DB2 2048
|
2003-10-15 11:50:36 +02:00
|
|
|
#define MODE_MAXDB 4096
|
2003-08-29 12:44:35 +02:00
|
|
|
#define MODE_NO_KEY_OPTIONS 8192
|
2006-01-07 14:41:57 +01:00
|
|
|
#define MODE_NO_TABLE_OPTIONS 16384
|
2004-09-28 19:08:00 +02:00
|
|
|
#define MODE_NO_FIELD_OPTIONS 32768
|
|
|
|
#define MODE_MYSQL323 65536
|
|
|
|
#define MODE_MYSQL40 (MODE_MYSQL323*2)
|
|
|
|
#define MODE_ANSI (MODE_MYSQL40*2)
|
|
|
|
#define MODE_NO_AUTO_VALUE_ON_ZERO (MODE_ANSI*2)
|
|
|
|
#define MODE_NO_BACKSLASH_ESCAPES (MODE_NO_AUTO_VALUE_ON_ZERO*2)
|
|
|
|
#define MODE_STRICT_TRANS_TABLES (MODE_NO_BACKSLASH_ESCAPES*2)
|
|
|
|
#define MODE_STRICT_ALL_TABLES (MODE_STRICT_TRANS_TABLES*2)
|
|
|
|
#define MODE_NO_ZERO_IN_DATE (MODE_STRICT_ALL_TABLES*2)
|
|
|
|
#define MODE_NO_ZERO_DATE (MODE_NO_ZERO_IN_DATE*2)
|
|
|
|
#define MODE_INVALID_DATES (MODE_NO_ZERO_DATE*2)
|
|
|
|
#define MODE_ERROR_FOR_DIVISION_BY_ZERO (MODE_INVALID_DATES*2)
|
|
|
|
#define MODE_TRADITIONAL (MODE_ERROR_FOR_DIVISION_BY_ZERO*2)
|
2004-11-02 15:45:26 +01:00
|
|
|
#define MODE_NO_AUTO_CREATE_USER (MODE_TRADITIONAL*2)
|
2004-11-27 20:26:46 +01:00
|
|
|
#define MODE_HIGH_NOT_PRECEDENCE (MODE_NO_AUTO_CREATE_USER*2)
|
2005-06-17 23:14:44 +02:00
|
|
|
#define MODE_NO_ENGINE_SUBSTITUTION (MODE_HIGH_NOT_PRECEDENCE*2)
|
2005-02-03 16:22:16 +01:00
|
|
|
/*
|
|
|
|
Replication uses 8 bytes to store SQL_MODE in the binary log. The day you
|
|
|
|
use strictly more than 64 bits by adding one more define above, you should
|
|
|
|
contact the replication team because the replication code should then be
|
|
|
|
updated (to store more bytes on disk).
|
2005-03-09 02:40:43 +01:00
|
|
|
|
|
|
|
NOTE: When adding new SQL_MODE types, make sure to also add them to
|
2007-03-16 20:56:16 +01:00
|
|
|
the scripts used for creating the MySQL system tables
|
|
|
|
in scripts/mysql_system_tables.sql and scripts/mysql_system_tables_fix.sql
|
|
|
|
|
2005-02-03 16:22:16 +01:00
|
|
|
*/
|
2001-08-09 17:51:38 +02:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
#define RAID_BLOCK_SIZE 1024
|
|
|
|
|
2003-07-08 12:06:05 +02:00
|
|
|
#define MY_CHARSET_BIN_MB_MAXLEN 1
|
|
|
|
|
2003-11-17 19:53:40 +01:00
|
|
|
// uncachable cause
|
|
|
|
#define UNCACHEABLE_DEPENDENT 1
|
|
|
|
#define UNCACHEABLE_RAND 2
|
2004-02-01 19:07:44 +01:00
|
|
|
#define UNCACHEABLE_SIDEEFFECT 4
|
|
|
|
// forcing to save JOIN for explain
|
|
|
|
#define UNCACHEABLE_EXPLAIN 8
|
2005-06-07 22:34:53 +02:00
|
|
|
/* Don't evaluate subqueries in prepare even if they're not correlated */
|
|
|
|
#define UNCACHEABLE_PREPARE 16
|
2007-01-19 09:17:28 +01:00
|
|
|
/* For uncorrelated SELECT in an UNION with some correlated SELECTs */
|
|
|
|
#define UNCACHEABLE_UNITED 32
|
2003-11-17 19:53:40 +01:00
|
|
|
|
2007-01-19 09:17:28 +01:00
|
|
|
/* Used to check GROUP BY list in the MODE_ONLY_FULL_GROUP_BY mode */
|
2007-01-11 21:18:01 +01:00
|
|
|
#define UNDEF_POS (-1)
|
2001-10-03 21:55:31 +02:00
|
|
|
#ifdef EXTRA_DEBUG
|
2002-06-11 10:20:31 +02:00
|
|
|
/*
|
|
|
|
Sync points allow us to force the server to reach a certain line of code
|
|
|
|
and block there until the client tells the server it is ok to go on.
|
|
|
|
The client tells the server to block with SELECT GET_LOCK()
|
|
|
|
and unblocks it with SELECT RELEASE_LOCK(). Used for debugging difficult
|
|
|
|
concurrency problems
|
|
|
|
*/
|
2001-10-03 21:55:31 +02:00
|
|
|
#define DBUG_SYNC_POINT(lock_name,lock_timeout) \
|
|
|
|
debug_sync_point(lock_name,lock_timeout)
|
|
|
|
void debug_sync_point(const char* lock_name, uint lock_timeout);
|
|
|
|
#else
|
|
|
|
#define DBUG_SYNC_POINT(lock_name,lock_timeout)
|
2002-06-11 10:20:31 +02:00
|
|
|
#endif /* EXTRA_DEBUG */
|
2001-10-03 21:55:31 +02:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
/* BINLOG_DUMP options */
|
|
|
|
|
|
|
|
#define BINLOG_DUMP_NON_BLOCK 1
|
|
|
|
|
2000-12-15 12:18:52 +01:00
|
|
|
/* sql_show.cc:show_log_files() */
|
|
|
|
#define SHOW_LOG_STATUS_FREE "FREE"
|
|
|
|
#define SHOW_LOG_STATUS_INUSE "IN USE"
|
|
|
|
|
2005-09-14 09:53:09 +02:00
|
|
|
struct st_table_list;
|
|
|
|
class String;
|
|
|
|
void view_store_options(THD *thd, st_table_list *table, String *buff);
|
|
|
|
|
2003-01-09 01:19:14 +01:00
|
|
|
/* Options to add_table_to_list() */
|
|
|
|
#define TL_OPTION_UPDATING 1
|
|
|
|
#define TL_OPTION_FORCE_INDEX 2
|
2003-06-12 13:29:02 +02:00
|
|
|
#define TL_OPTION_IGNORE_LEAVES 4
|
2006-09-04 17:40:30 +02:00
|
|
|
#define TL_OPTION_ALIAS 8
|
2003-01-09 01:19:14 +01:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
/* Some portable defines */
|
|
|
|
|
|
|
|
#define portable_sizeof_char_ptr 8
|
|
|
|
|
|
|
|
#define tmp_file_prefix "#sql" /* Prefix for tmp tables */
|
|
|
|
#define tmp_file_prefix_length 4
|
|
|
|
|
2003-12-07 12:10:21 +01:00
|
|
|
/* Flags for calc_week() function. */
|
|
|
|
#define WEEK_MONDAY_FIRST 1
|
|
|
|
#define WEEK_YEAR 2
|
|
|
|
#define WEEK_FIRST_WEEKDAY 4
|
|
|
|
|
2005-02-08 23:50:45 +01:00
|
|
|
#define STRING_BUFFER_USUAL_SIZE 80
|
|
|
|
|
2005-07-22 22:43:59 +02:00
|
|
|
/*
|
|
|
|
Some defines for exit codes for ::is_equal class functions.
|
|
|
|
*/
|
|
|
|
#define IS_EQUAL_NO 0
|
|
|
|
#define IS_EQUAL_YES 1
|
|
|
|
#define IS_EQUAL_PACK_LENGTH 2
|
|
|
|
|
2004-08-13 09:01:30 +02:00
|
|
|
enum enum_parsing_place
|
|
|
|
{
|
|
|
|
NO_MATTER,
|
|
|
|
IN_HAVING,
|
2004-08-31 20:10:57 +02:00
|
|
|
SELECT_LIST,
|
2006-09-25 15:15:14 +02:00
|
|
|
IN_WHERE,
|
|
|
|
IN_ON
|
2004-08-13 09:01:30 +02:00
|
|
|
};
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
struct st_table;
|
|
|
|
class THD;
|
|
|
|
|
|
|
|
/* Struct to handle simple linked lists */
|
|
|
|
|
|
|
|
typedef struct st_sql_list {
|
|
|
|
uint elements;
|
|
|
|
byte *first;
|
|
|
|
byte **next;
|
2002-11-29 15:40:18 +01:00
|
|
|
|
2006-02-25 16:46:30 +01:00
|
|
|
st_sql_list() {} /* Remove gcc warning */
|
2002-11-29 15:40:18 +01:00
|
|
|
inline void empty()
|
|
|
|
{
|
|
|
|
elements=0;
|
|
|
|
first=0;
|
|
|
|
next= &first;
|
|
|
|
}
|
|
|
|
inline void link_in_list(byte *element,byte **next_ptr)
|
|
|
|
{
|
|
|
|
elements++;
|
|
|
|
(*next)=element;
|
|
|
|
next= next_ptr;
|
|
|
|
*next=0;
|
|
|
|
}
|
2003-07-03 10:55:36 +02:00
|
|
|
inline void save_and_clear(struct st_sql_list *save)
|
|
|
|
{
|
|
|
|
*save= *this;
|
|
|
|
empty();
|
|
|
|
}
|
|
|
|
inline void push_front(struct st_sql_list *save)
|
|
|
|
{
|
|
|
|
*save->next= first; /* link current list last */
|
|
|
|
first= save->first;
|
|
|
|
elements+= save->elements;
|
|
|
|
}
|
2004-11-24 10:24:02 +01:00
|
|
|
inline void push_back(struct st_sql_list *save)
|
|
|
|
{
|
|
|
|
if (save->first)
|
|
|
|
{
|
|
|
|
*next= save->first;
|
|
|
|
next= save->next;
|
|
|
|
elements+= save->elements;
|
|
|
|
}
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
} SQL_LIST;
|
|
|
|
|
|
|
|
|
|
|
|
extern pthread_key(THD*, THR_THD);
|
|
|
|
inline THD *_current_thd(void)
|
|
|
|
{
|
|
|
|
return my_pthread_getspecific_ptr(THD*,THR_THD);
|
|
|
|
}
|
|
|
|
#define current_thd _current_thd()
|
|
|
|
|
2006-01-19 22:40:56 +01:00
|
|
|
|
2005-01-16 13:16:23 +01:00
|
|
|
/*
|
|
|
|
External variables
|
|
|
|
*/
|
|
|
|
extern ulong server_id, concurrency;
|
|
|
|
|
2005-02-14 21:50:09 +01:00
|
|
|
|
2004-11-24 12:56:51 +01:00
|
|
|
typedef my_bool (*qc_engine_callback)(THD *thd, char *table_key,
|
|
|
|
uint key_length,
|
|
|
|
ulonglong *engine_data);
|
2000-07-31 21:29:14 +02:00
|
|
|
#include "sql_string.h"
|
|
|
|
#include "sql_list.h"
|
|
|
|
#include "sql_map.h"
|
2005-02-08 23:50:45 +01:00
|
|
|
#include "my_decimal.h"
|
2000-07-31 21:29:14 +02:00
|
|
|
#include "handler.h"
|
2004-05-11 22:23:49 +02:00
|
|
|
#include "parse_file.h"
|
2000-07-31 21:29:14 +02:00
|
|
|
#include "table.h"
|
2005-04-01 14:04:50 +02:00
|
|
|
#include "sql_error.h"
|
2000-07-31 21:29:14 +02:00
|
|
|
#include "field.h" /* Field definitions */
|
2002-12-11 08:17:51 +01:00
|
|
|
#include "protocol.h"
|
2000-07-31 21:29:14 +02:00
|
|
|
#include "sql_udf.h"
|
2006-02-16 17:38:33 +01:00
|
|
|
#include "sql_partition.h"
|
|
|
|
|
2004-06-07 10:09:10 +02:00
|
|
|
class user_var_entry;
|
2005-09-20 20:20:38 +02:00
|
|
|
class Security_context;
|
2005-07-16 01:29:13 +02:00
|
|
|
enum enum_var_type
|
|
|
|
{
|
2005-07-16 14:10:42 +02:00
|
|
|
OPT_DEFAULT= 0, OPT_SESSION, OPT_GLOBAL
|
2005-07-16 01:29:13 +02:00
|
|
|
};
|
|
|
|
class sys_var;
|
2006-01-19 22:40:56 +01:00
|
|
|
#ifdef MYSQL_SERVER
|
2006-07-21 01:04:04 +02:00
|
|
|
class Comp_creator;
|
2003-11-03 11:28:36 +01:00
|
|
|
typedef Comp_creator* (*chooser_compare_func_creator)(bool invert);
|
2006-01-19 22:40:56 +01:00
|
|
|
#endif
|
2006-07-21 01:04:04 +02:00
|
|
|
#include "item.h"
|
2006-07-22 14:18:28 +02:00
|
|
|
extern my_decimal decimal_zero;
|
|
|
|
|
2004-02-12 02:10:26 +01:00
|
|
|
/* sql_parse.cc */
|
|
|
|
void free_items(Item *item);
|
|
|
|
void cleanup_items(Item *item);
|
2004-02-12 17:50:00 +01:00
|
|
|
class THD;
|
2005-08-08 15:46:06 +02:00
|
|
|
void close_thread_tables(THD *thd, bool locked=0, bool skip_derived=0);
|
2006-01-07 14:41:57 +01:00
|
|
|
bool check_one_table_access(THD *thd, ulong privilege, TABLE_LIST *tables);
|
2006-06-21 11:12:46 +02:00
|
|
|
bool check_single_table_access(THD *thd, ulong privilege,
|
2007-04-04 11:01:47 +02:00
|
|
|
TABLE_LIST *tables, bool no_errors);
|
2005-05-17 20:54:20 +02:00
|
|
|
bool check_routine_access(THD *thd,ulong want_access,char *db,char *name,
|
|
|
|
bool is_proc, bool no_errors);
|
2004-09-03 20:43:04 +02:00
|
|
|
bool check_some_access(THD *thd, ulong want_access, TABLE_LIST *table);
|
2006-01-07 14:41:57 +01:00
|
|
|
bool check_merge_table_access(THD *thd, char *db, TABLE_LIST *table_list);
|
2005-05-17 20:54:20 +02:00
|
|
|
bool check_some_routine_access(THD *thd, const char *db, const char *name, bool is_proc);
|
2004-10-20 03:04:37 +02:00
|
|
|
bool multi_update_precheck(THD *thd, TABLE_LIST *tables);
|
2005-06-08 23:07:52 +02:00
|
|
|
bool multi_delete_precheck(THD *thd, TABLE_LIST *tables);
|
2004-10-20 03:04:37 +02:00
|
|
|
bool mysql_multi_update_prepare(THD *thd);
|
|
|
|
bool mysql_multi_delete_prepare(THD *thd);
|
|
|
|
bool mysql_insert_select_prepare(THD *thd);
|
|
|
|
bool update_precheck(THD *thd, TABLE_LIST *tables);
|
|
|
|
bool delete_precheck(THD *thd, TABLE_LIST *tables);
|
2004-11-12 14:36:31 +01:00
|
|
|
bool insert_precheck(THD *thd, TABLE_LIST *tables);
|
2004-10-20 03:04:37 +02:00
|
|
|
bool create_table_precheck(THD *thd, TABLE_LIST *tables,
|
|
|
|
TABLE_LIST *create_table);
|
2006-03-21 14:35:49 +01:00
|
|
|
int append_query_string(CHARSET_INFO *csinfo,
|
|
|
|
String const *from, String *to);
|
2005-09-14 09:53:09 +02:00
|
|
|
|
2006-03-02 12:17:13 +01:00
|
|
|
void get_default_definer(THD *thd, LEX_USER *definer);
|
2006-03-01 12:13:07 +01:00
|
|
|
LEX_USER *create_default_definer(THD *thd);
|
2005-11-10 20:25:03 +01:00
|
|
|
LEX_USER *create_definer(THD *thd, LEX_STRING *user_name, LEX_STRING *host_name);
|
2006-06-29 12:50:44 +02:00
|
|
|
LEX_USER *get_current_user(THD *thd, LEX_USER *user);
|
2007-04-03 13:13:27 +02:00
|
|
|
bool check_string_byte_length(LEX_STRING *str, const char *err_msg,
|
|
|
|
uint max_byte_length);
|
|
|
|
bool check_string_char_length(LEX_STRING *str, const char *err_msg,
|
|
|
|
uint max_char_length, CHARSET_INFO *cs,
|
|
|
|
bool no_error);
|
2005-02-17 13:52:16 +01:00
|
|
|
|
|
|
|
enum enum_mysql_completiontype {
|
|
|
|
ROLLBACK_RELEASE=-2, ROLLBACK=1, ROLLBACK_AND_CHAIN=7,
|
|
|
|
COMMIT_RELEASE=-1, COMMIT=0, COMMIT_AND_CHAIN=6
|
|
|
|
};
|
|
|
|
|
2006-01-12 19:51:02 +01:00
|
|
|
bool begin_trans(THD *thd);
|
2006-05-05 19:08:40 +02:00
|
|
|
bool end_active_trans(THD *thd);
|
2005-02-17 13:52:16 +01:00
|
|
|
int end_trans(THD *thd, enum enum_mysql_completiontype completion);
|
|
|
|
|
2004-08-31 20:10:57 +02:00
|
|
|
Item *negate_expression(THD *thd, Item *expr);
|
2000-07-31 21:29:14 +02:00
|
|
|
#include "sql_class.h"
|
2004-12-09 11:31:46 +01:00
|
|
|
#include "sql_acl.h"
|
|
|
|
#include "tztime.h"
|
2006-01-19 22:40:56 +01:00
|
|
|
#ifdef MYSQL_SERVER
|
2006-12-02 01:47:45 +01:00
|
|
|
#include "sql_servers.h"
|
2000-07-31 21:29:14 +02:00
|
|
|
#include "opt_range.h"
|
2002-03-22 21:55:08 +01:00
|
|
|
|
|
|
|
#ifdef HAVE_QUERY_CACHE
|
2003-10-02 11:02:05 +02:00
|
|
|
struct Query_cache_query_flags
|
|
|
|
{
|
|
|
|
unsigned int client_long_flag:1;
|
2005-01-19 00:59:39 +01:00
|
|
|
unsigned int client_protocol_41:1;
|
Fix for BUG#735 "Prepared Statements: there is no support for Query
Cache".
WL#1569 "Prepared Statements: implement support of Query Cache".
Prepared SELECTs did not look up in the query cache, and their results
were not stored in the query cache. This made them slower than
non-prepared SELECTs in some cases.
The fix is to re-use the expanded query (the prepared query where
"?" placeholders are replaced by their values, at execution time)
for searching/storing in the query cache.
It works fine for statements prepared via mysql_stmt_prepare(), which
are the most commonly used and were the scope of this bugfix and WL.
It works less fine for statements prepared via the SQL command
PREPARE...FROM, which are still not using the query cache if they
have at least one parameter (because then the expanded query contains
names of user variables, and user variables don't work with the
query cache, even in non-prepared queries).
Note that results from prepared SELECTs, which are in the binary
protocol, and results from normal SELECTs, which are in the text
protocol, ignore each other in the query cache, because a result in the
binary protocol should never be served to a SELECT expecting the text
protocol and vice-versa.
Note, after this patch, bug 25843 starts applying to query cache
("changing default database between PREPARE and EXECUTE of statement
breaks binlog"), we need to fix it.
2007-03-09 18:09:57 +01:00
|
|
|
unsigned int result_in_binary_protocol:1;
|
2005-07-23 06:51:25 +02:00
|
|
|
unsigned int more_results_exists:1;
|
2005-09-29 10:25:44 +02:00
|
|
|
unsigned int pkt_nr;
|
2003-10-03 14:09:54 +02:00
|
|
|
uint character_set_client_num;
|
|
|
|
uint character_set_results_num;
|
|
|
|
uint collation_connection_num;
|
2003-10-02 11:02:05 +02:00
|
|
|
ha_rows limit;
|
2004-06-18 08:11:31 +02:00
|
|
|
Time_zone *time_zone;
|
2004-09-10 15:28:18 +02:00
|
|
|
ulong sql_mode;
|
|
|
|
ulong max_sort_length;
|
|
|
|
ulong group_concat_max_len;
|
2006-07-04 14:40:40 +02:00
|
|
|
MY_LOCALE *lc_time_names;
|
2003-10-02 11:02:05 +02:00
|
|
|
};
|
|
|
|
#define QUERY_CACHE_FLAGS_SIZE sizeof(Query_cache_query_flags)
|
2001-12-02 13:34:01 +01:00
|
|
|
#include "sql_cache.h"
|
2002-03-22 21:55:08 +01:00
|
|
|
#define query_cache_store_query(A, B) query_cache.store_query(A, B)
|
|
|
|
#define query_cache_destroy() query_cache.destroy()
|
|
|
|
#define query_cache_result_size_limit(A) query_cache.result_size_limit(A)
|
2005-09-06 10:16:53 +02:00
|
|
|
#define query_cache_init() query_cache.init()
|
2002-03-22 21:55:08 +01:00
|
|
|
#define query_cache_resize(A) query_cache.resize(A)
|
2003-03-02 20:39:03 +01:00
|
|
|
#define query_cache_set_min_res_unit(A) query_cache.set_min_res_unit(A)
|
2002-03-22 21:55:08 +01:00
|
|
|
#define query_cache_invalidate3(A, B, C) query_cache.invalidate(A, B, C)
|
|
|
|
#define query_cache_invalidate1(A) query_cache.invalidate(A)
|
|
|
|
#define query_cache_send_result_to_client(A, B, C) \
|
|
|
|
query_cache.send_result_to_client(A, B, C)
|
|
|
|
#define query_cache_invalidate_by_MyISAM_filename_ref \
|
|
|
|
&query_cache_invalidate_by_MyISAM_filename
|
Fix for BUG#735 "Prepared Statements: there is no support for Query
Cache".
WL#1569 "Prepared Statements: implement support of Query Cache".
Prepared SELECTs did not look up in the query cache, and their results
were not stored in the query cache. This made them slower than
non-prepared SELECTs in some cases.
The fix is to re-use the expanded query (the prepared query where
"?" placeholders are replaced by their values, at execution time)
for searching/storing in the query cache.
It works fine for statements prepared via mysql_stmt_prepare(), which
are the most commonly used and were the scope of this bugfix and WL.
It works less fine for statements prepared via the SQL command
PREPARE...FROM, which are still not using the query cache if they
have at least one parameter (because then the expanded query contains
names of user variables, and user variables don't work with the
query cache, even in non-prepared queries).
Note that results from prepared SELECTs, which are in the binary
protocol, and results from normal SELECTs, which are in the text
protocol, ignore each other in the query cache, because a result in the
binary protocol should never be served to a SELECT expecting the text
protocol and vice-versa.
Note, after this patch, bug 25843 starts applying to query cache
("changing default database between PREPARE and EXECUTE of statement
breaks binlog"), we need to fix it.
2007-03-09 18:09:57 +01:00
|
|
|
/* note the "maybe": it's a read without mutex */
|
|
|
|
#define query_cache_maybe_disabled(T) \
|
|
|
|
(T->variables.query_cache_type == 0 || query_cache.query_cache_size == 0)
|
|
|
|
#define query_cache_is_cacheable_query(L) \
|
|
|
|
(((L)->sql_command == SQLCOM_SELECT) && (L)->safe_to_cache_query)
|
2002-03-22 21:55:08 +01:00
|
|
|
#else
|
2003-10-02 11:02:05 +02:00
|
|
|
#define QUERY_CACHE_FLAGS_SIZE 0
|
2002-03-22 21:55:08 +01:00
|
|
|
#define query_cache_store_query(A, B)
|
|
|
|
#define query_cache_destroy()
|
|
|
|
#define query_cache_result_size_limit(A)
|
2005-09-06 10:16:53 +02:00
|
|
|
#define query_cache_init()
|
2002-03-22 21:55:08 +01:00
|
|
|
#define query_cache_resize(A)
|
2003-03-02 20:39:03 +01:00
|
|
|
#define query_cache_set_min_res_unit(A)
|
2002-03-22 21:55:08 +01:00
|
|
|
#define query_cache_invalidate3(A, B, C)
|
|
|
|
#define query_cache_invalidate1(A)
|
|
|
|
#define query_cache_send_result_to_client(A, B, C) 0
|
|
|
|
#define query_cache_invalidate_by_MyISAM_filename_ref NULL
|
|
|
|
|
|
|
|
#define query_cache_abort(A)
|
|
|
|
#define query_cache_end_of_result(A)
|
|
|
|
#define query_cache_invalidate_by_MyISAM_filename_ref NULL
|
Fix for BUG#735 "Prepared Statements: there is no support for Query
Cache".
WL#1569 "Prepared Statements: implement support of Query Cache".
Prepared SELECTs did not look up in the query cache, and their results
were not stored in the query cache. This made them slower than
non-prepared SELECTs in some cases.
The fix is to re-use the expanded query (the prepared query where
"?" placeholders are replaced by their values, at execution time)
for searching/storing in the query cache.
It works fine for statements prepared via mysql_stmt_prepare(), which
are the most commonly used and were the scope of this bugfix and WL.
It works less fine for statements prepared via the SQL command
PREPARE...FROM, which are still not using the query cache if they
have at least one parameter (because then the expanded query contains
names of user variables, and user variables don't work with the
query cache, even in non-prepared queries).
Note that results from prepared SELECTs, which are in the binary
protocol, and results from normal SELECTs, which are in the text
protocol, ignore each other in the query cache, because a result in the
binary protocol should never be served to a SELECT expecting the text
protocol and vice-versa.
Note, after this patch, bug 25843 starts applying to query cache
("changing default database between PREPARE and EXECUTE of statement
breaks binlog"), we need to fix it.
2007-03-09 18:09:57 +01:00
|
|
|
#define query_cache_maybe_disabled(T) 1
|
|
|
|
#define query_cache_is_cacheable_query(L) 0
|
2002-03-22 21:55:08 +01:00
|
|
|
#endif /*HAVE_QUERY_CACHE*/
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2006-02-01 10:06:07 +01:00
|
|
|
/*
|
|
|
|
Error injector Macros to enable easy testing of recovery after failures
|
|
|
|
in various error cases.
|
|
|
|
*/
|
|
|
|
#ifndef ERROR_INJECT_SUPPORT
|
2006-02-03 18:05:30 +01:00
|
|
|
|
2006-02-03 18:05:29 +01:00
|
|
|
#define ERROR_INJECT(x) 0
|
2006-02-03 18:05:30 +01:00
|
|
|
#define ERROR_INJECT_ACTION(x,action) 0
|
2006-02-03 18:05:29 +01:00
|
|
|
#define ERROR_INJECT_CRASH(x) 0
|
2006-02-03 18:05:30 +01:00
|
|
|
#define ERROR_INJECT_VALUE(x) 0
|
|
|
|
#define ERROR_INJECT_VALUE_ACTION(x,action) 0
|
|
|
|
#define ERROR_INJECT_VALUE_CRASH(x) 0
|
2006-02-01 16:38:08 +01:00
|
|
|
#define SET_ERROR_INJECT_VALUE(x)
|
2006-02-03 18:05:30 +01:00
|
|
|
|
2006-02-01 10:06:07 +01:00
|
|
|
#else
|
|
|
|
|
2006-04-16 03:49:13 +02:00
|
|
|
inline bool check_and_unset_keyword(const char *dbug_str)
|
2006-02-04 13:03:35 +01:00
|
|
|
{
|
2006-02-21 03:50:44 +01:00
|
|
|
const char *extra_str= "-d,";
|
|
|
|
char total_str[200];
|
|
|
|
if (_db_strict_keyword_ (dbug_str))
|
2006-02-04 13:03:35 +01:00
|
|
|
{
|
2006-02-21 03:50:44 +01:00
|
|
|
strxmov(total_str, extra_str, dbug_str, NullS);
|
|
|
|
DBUG_SET(total_str);
|
2006-02-04 13:03:35 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-01 10:06:07 +01:00
|
|
|
inline bool
|
2006-04-16 03:49:13 +02:00
|
|
|
check_and_unset_inject_value(int value)
|
2006-02-01 10:06:07 +01:00
|
|
|
{
|
2006-02-01 14:00:00 +01:00
|
|
|
THD *thd= current_thd;
|
2006-02-03 18:05:30 +01:00
|
|
|
if (thd->error_inject_value == (uint)value)
|
2006-02-01 14:00:00 +01:00
|
|
|
{
|
2006-02-03 18:05:30 +01:00
|
|
|
thd->error_inject_value= 0;
|
2006-02-01 14:00:00 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
2006-02-01 10:06:07 +01:00
|
|
|
}
|
|
|
|
|
2006-03-25 00:19:13 +01:00
|
|
|
/*
|
|
|
|
ERROR INJECT MODULE:
|
|
|
|
--------------------
|
|
|
|
These macros are used to insert macros from the application code.
|
|
|
|
The event that activates those error injections can be activated
|
|
|
|
from SQL by using:
|
|
|
|
SET SESSION dbug=+d,code;
|
|
|
|
|
|
|
|
After the error has been injected, the macros will automatically
|
|
|
|
remove the debug code, thus similar to using:
|
|
|
|
SET SESSION dbug=-d,code
|
|
|
|
from SQL.
|
|
|
|
|
|
|
|
ERROR_INJECT_CRASH will inject a crash of the MySQL Server if code
|
|
|
|
is set when macro is called. ERROR_INJECT_CRASH can be used in
|
|
|
|
if-statements, it will always return FALSE unless of course it
|
|
|
|
crashes in which case it doesn't return at all.
|
|
|
|
|
|
|
|
ERROR_INJECT_ACTION will inject the action specified in the action
|
|
|
|
parameter of the macro, before performing the action the code will
|
|
|
|
be removed such that no more events occur. ERROR_INJECT_ACTION
|
|
|
|
can also be used in if-statements and always returns FALSE.
|
|
|
|
ERROR_INJECT can be used in a normal if-statement, where the action
|
|
|
|
part is performed in the if-block. The macro returns TRUE if the
|
|
|
|
error was activated and otherwise returns FALSE. If activated the
|
|
|
|
code is removed.
|
|
|
|
|
|
|
|
Sometimes it is necessary to perform error inject actions as a serie
|
|
|
|
of events. In this case one can use one variable on the THD object.
|
|
|
|
Thus one sets this value by using e.g. SET_ERROR_INJECT_VALUE(100).
|
|
|
|
Then one can later test for it by using ERROR_INJECT_CRASH_VALUE,
|
|
|
|
ERROR_INJECT_ACTION_VALUE and ERROR_INJECT_VALUE. This have the same
|
|
|
|
behaviour as the above described macros except that they use the
|
|
|
|
error inject value instead of a code used by DBUG macros.
|
|
|
|
*/
|
|
|
|
#define SET_ERROR_INJECT_VALUE(x) \
|
|
|
|
current_thd->error_inject_value= (x)
|
2006-02-03 18:05:29 +01:00
|
|
|
#define ERROR_INJECT_CRASH(code) \
|
2006-02-21 03:50:44 +01:00
|
|
|
DBUG_EVALUATE_IF(code, (abort(), 0), 0)
|
2006-02-03 18:05:29 +01:00
|
|
|
#define ERROR_INJECT_ACTION(code, action) \
|
2006-04-16 03:49:13 +02:00
|
|
|
(check_and_unset_keyword(code) ? ((action), 0) : 0)
|
2006-02-01 10:06:07 +01:00
|
|
|
#define ERROR_INJECT(code) \
|
2006-04-16 03:49:13 +02:00
|
|
|
check_and_unset_keyword(code)
|
2006-02-03 18:05:30 +01:00
|
|
|
#define ERROR_INJECT_VALUE(value) \
|
2006-04-16 03:49:13 +02:00
|
|
|
check_and_unset_inject_value(value)
|
2006-02-03 18:05:30 +01:00
|
|
|
#define ERROR_INJECT_VALUE_ACTION(value,action) \
|
2006-04-16 03:49:13 +02:00
|
|
|
(check_and_unset_inject_value(value) ? (action) : 0)
|
2006-02-03 18:05:30 +01:00
|
|
|
#define ERROR_INJECT_VALUE_CRASH(value) \
|
2006-04-16 03:49:13 +02:00
|
|
|
ERROR_INJECT_VALUE_ACTION(value, (abort(), 0))
|
2006-02-03 18:05:30 +01:00
|
|
|
|
2006-02-01 10:06:07 +01:00
|
|
|
#endif
|
2006-02-01 16:38:08 +01:00
|
|
|
|
2006-01-17 08:40:00 +01:00
|
|
|
uint build_table_path(char *buff, size_t bufflen, const char *db,
|
|
|
|
const char *table, const char *ext);
|
|
|
|
void write_bin_log(THD *thd, bool clear_error,
|
|
|
|
char const *query, ulong query_length);
|
|
|
|
|
2007-02-23 12:13:55 +01:00
|
|
|
/* sql_connect.cc */
|
|
|
|
int check_user(THD *thd, enum enum_server_command command,
|
|
|
|
const char *passwd, uint passwd_len, const char *db,
|
|
|
|
bool check_count);
|
|
|
|
pthread_handler_t handle_one_connection(void *arg);
|
|
|
|
bool init_new_connection_handler_thread();
|
|
|
|
void reset_mqh(LEX_USER *lu, bool get_them);
|
|
|
|
bool check_mqh(THD *thd, uint check_command);
|
|
|
|
void time_out_user_resource_limits(THD *thd, USER_CONN *uc);
|
|
|
|
int check_for_max_user_connections(THD *thd, USER_CONN *uc);
|
|
|
|
void decrease_user_connections(USER_CONN *uc);
|
|
|
|
void thd_init_client_charset(THD *thd, uint cs_number);
|
|
|
|
bool setup_connection_thread_globals(THD *thd);
|
|
|
|
bool login_connection(THD *thd);
|
|
|
|
void prepare_new_connection_state(THD* thd);
|
|
|
|
void end_connection(THD *thd);
|
|
|
|
|
2004-10-20 03:04:37 +02:00
|
|
|
bool mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create, bool silent);
|
|
|
|
bool mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create);
|
|
|
|
bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent);
|
2006-02-13 08:49:28 +01:00
|
|
|
bool mysql_rename_db(THD *thd, LEX_STRING *old_db, LEX_STRING *new_db);
|
2002-08-21 21:04:22 +02:00
|
|
|
void mysql_binlog_send(THD* thd, char* log_ident, my_off_t pos, ushort flags);
|
2005-12-22 06:39:02 +01:00
|
|
|
void mysql_client_binlog_statement(THD *thd);
|
2004-10-20 03:04:37 +02:00
|
|
|
bool mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists,
|
|
|
|
my_bool drop_temporary);
|
2001-09-02 12:47:00 +02:00
|
|
|
int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
|
2004-07-16 00:15:55 +02:00
|
|
|
bool drop_temporary, bool drop_view, bool log_query);
|
2002-07-23 17:31:22 +02:00
|
|
|
int mysql_rm_table_part2_with_lock(THD *thd, TABLE_LIST *tables,
|
2003-01-04 14:37:20 +01:00
|
|
|
bool if_exists, bool drop_temporary,
|
2002-07-23 17:31:22 +02:00
|
|
|
bool log_query);
|
2005-12-21 19:18:40 +01:00
|
|
|
bool quick_rm_table(handlerton *base,const char *db,
|
2006-08-02 17:57:06 +02:00
|
|
|
const char *table_name, uint flags);
|
2004-09-07 14:29:46 +02:00
|
|
|
void close_cached_table(THD *thd, TABLE *table);
|
2006-02-13 08:49:28 +01:00
|
|
|
bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list, bool silent);
|
2006-10-13 19:59:52 +02:00
|
|
|
bool do_rename(THD *thd, TABLE_LIST *ren_table, char *new_db,
|
|
|
|
char *new_table_name, char *new_table_alias,
|
|
|
|
bool skip_error);
|
2007-03-27 19:55:01 +02:00
|
|
|
bool mysql_change_db(THD *thd, const LEX_STRING *new_db_name,
|
|
|
|
bool force_switch);
|
2000-07-31 21:29:14 +02:00
|
|
|
void mysql_parse(THD *thd,char *inBuf,uint length);
|
2004-03-11 17:38:19 +01:00
|
|
|
bool mysql_test_parse_for_slave(THD *thd,char *inBuf,uint length);
|
2003-02-14 10:47:41 +01:00
|
|
|
bool is_update_query(enum enum_sql_command command);
|
Implement WL#2661 "Prepared Statements: Dynamic SQL in Stored Procedures".
The idea of the patch is to separate statement processing logic,
such as parsing, validation of the parsed tree, execution and cleanup,
from global query processing logic, such as logging, resetting
priorities of a thread, resetting stored procedure cache, resetting
thread count of errors and warnings.
This makes PREPARE and EXECUTE behave similarly to the rest of SQL
statements and allows their use in stored procedures.
This patch contains a change in behaviour:
until recently for each SQL prepared statement command, 2 queries
were written to the general log, e.g.
[Query] prepare stmt from @stmt_text;
[Prepare] select * from t1 <-- contents of @stmt_text
The chagne was necessary to prevent [Prepare] commands from being written
to the general log when executing a stored procedure with Dynamic SQL.
We should consider whether the old behavior is preferrable and probably
restore it.
This patch refixes Bug#7115, Bug#10975 (partially), Bug#10605 (various bugs
in Dynamic SQL reported before it was disabled).
2005-09-03 01:13:18 +02:00
|
|
|
bool alloc_query(THD *thd, const char *packet, uint packet_length);
|
2000-08-15 19:09:37 +02:00
|
|
|
void mysql_init_select(LEX *lex);
|
2004-10-14 00:53:59 +02:00
|
|
|
void mysql_reset_thd_for_next_command(THD *thd);
|
2007-03-27 19:09:56 +02:00
|
|
|
void mysql_init_query(THD *thd, const char *buf, uint length);
|
2002-05-06 23:04:16 +02:00
|
|
|
bool mysql_new_select(LEX *lex, bool move_down);
|
2002-10-02 12:33:08 +02:00
|
|
|
void create_select_for_variable(const char *var_name);
|
2002-01-02 23:46:43 +01:00
|
|
|
void mysql_init_multi_delete(LEX *lex);
|
2005-06-08 23:07:52 +02:00
|
|
|
bool multi_delete_set_locks_and_link_aux_tables(LEX *lex);
|
2001-02-20 21:34:47 +01:00
|
|
|
void init_max_user_conn(void);
|
2002-09-16 14:55:19 +02:00
|
|
|
void init_update_queries(void);
|
2001-02-20 21:34:47 +01:00
|
|
|
void free_max_user_conn(void);
|
2005-10-08 16:39:55 +02:00
|
|
|
pthread_handler_t handle_bootstrap(void *arg);
|
2004-10-20 03:04:37 +02:00
|
|
|
bool mysql_execute_command(THD *thd);
|
2000-07-31 21:29:14 +02:00
|
|
|
bool do_command(THD *thd);
|
2001-04-11 13:04:03 +02:00
|
|
|
bool dispatch_command(enum enum_server_command command, THD *thd,
|
|
|
|
char* packet, uint packet_length);
|
2005-06-16 23:58:36 +02:00
|
|
|
void log_slow_statement(THD *thd);
|
2003-12-12 21:26:58 +01:00
|
|
|
bool check_dup(const char *db, const char *name, TABLE_LIST *tables);
|
2007-02-13 22:15:23 +01:00
|
|
|
bool compare_record(TABLE *table);
|
2006-01-24 06:20:23 +01:00
|
|
|
bool append_file_to_dir(THD *thd, const char **filename_ptr,
|
|
|
|
const char *table_name);
|
2003-04-08 07:35:13 +02:00
|
|
|
|
2004-03-12 00:10:22 +01:00
|
|
|
bool table_cache_init(void);
|
2000-07-31 21:29:14 +02:00
|
|
|
void table_cache_free(void);
|
2005-11-23 21:45:02 +01:00
|
|
|
bool table_def_init(void);
|
|
|
|
void table_def_free(void);
|
2006-02-23 13:34:03 +01:00
|
|
|
void assign_new_table_id(TABLE_SHARE *share);
|
2005-11-23 21:45:02 +01:00
|
|
|
uint cached_open_tables(void);
|
|
|
|
uint cached_table_definitions(void);
|
2000-07-31 21:29:14 +02:00
|
|
|
void kill_mysql(void);
|
2003-05-26 18:01:20 +02:00
|
|
|
void close_connection(THD *thd, uint errcode, bool lock);
|
2003-09-26 12:33:13 +02:00
|
|
|
bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables,
|
|
|
|
bool *write_to_binlog);
|
|
|
|
bool check_access(THD *thd, ulong access, const char *db, ulong *save_priv,
|
2005-09-13 13:07:38 +02:00
|
|
|
bool no_grant, bool no_errors, bool schema_db);
|
2002-06-12 14:04:18 +02:00
|
|
|
bool check_table_access(THD *thd, ulong want_access, TABLE_LIST *tables,
|
2003-09-26 12:33:13 +02:00
|
|
|
bool no_errors);
|
2002-06-12 14:04:18 +02:00
|
|
|
bool check_global_access(THD *thd, ulong want_access);
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2005-08-19 16:26:05 +02:00
|
|
|
/*
|
|
|
|
Support routine for SQL parser on partitioning syntax
|
|
|
|
*/
|
|
|
|
my_bool is_partition_management(LEX *lex);
|
2005-07-18 13:31:02 +02:00
|
|
|
/*
|
|
|
|
General routine to change field->ptr of a NULL-terminated array of Field
|
|
|
|
objects. Useful when needed to call val_int, val_str or similar and the
|
|
|
|
field data is not in table->record[0] but in some other structure.
|
|
|
|
set_key_field_ptr changes all fields of an index using a key_info object.
|
|
|
|
All methods presume that there is at least one field to change.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void set_field_ptr(Field **ptr, const byte *new_buf, const byte *old_buf);
|
|
|
|
void set_key_field_ptr(KEY *key_info, const byte *new_buf,
|
|
|
|
const byte *old_buf);
|
|
|
|
|
2004-10-20 03:04:37 +02:00
|
|
|
bool mysql_backup_table(THD* thd, TABLE_LIST* table_list);
|
|
|
|
bool mysql_restore_table(THD* thd, TABLE_LIST* table_list);
|
|
|
|
|
|
|
|
bool mysql_checksum_table(THD* thd, TABLE_LIST* table_list,
|
|
|
|
HA_CHECK_OPT* check_opt);
|
|
|
|
bool mysql_check_table(THD* thd, TABLE_LIST* table_list,
|
|
|
|
HA_CHECK_OPT* check_opt);
|
|
|
|
bool mysql_repair_table(THD* thd, TABLE_LIST* table_list,
|
|
|
|
HA_CHECK_OPT* check_opt);
|
|
|
|
bool mysql_analyze_table(THD* thd, TABLE_LIST* table_list,
|
|
|
|
HA_CHECK_OPT* check_opt);
|
|
|
|
bool mysql_optimize_table(THD* thd, TABLE_LIST* table_list,
|
|
|
|
HA_CHECK_OPT* check_opt);
|
|
|
|
bool mysql_assign_to_keycache(THD* thd, TABLE_LIST* table_list,
|
|
|
|
LEX_STRING *key_cache_name);
|
|
|
|
bool mysql_preload_keys(THD* thd, TABLE_LIST* table_list);
|
2003-11-20 21:06:25 +01:00
|
|
|
int reassign_keycache_tables(THD* thd, KEY_CACHE *src_cache,
|
|
|
|
KEY_CACHE *dst_cache);
|
2005-12-07 15:01:17 +01:00
|
|
|
TABLE *create_virtual_tmp_table(THD *thd, List<create_field> &field_list);
|
2003-06-12 13:29:02 +02:00
|
|
|
|
2005-01-16 13:16:23 +01:00
|
|
|
bool mysql_xa_recover(THD *thd);
|
|
|
|
|
2002-07-24 18:55:08 +02:00
|
|
|
bool check_simple_select();
|
2006-01-11 11:35:25 +01:00
|
|
|
int mysql_alter_tablespace(THD* thd, st_alter_tablespace *ts_info);
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2006-10-17 15:20:26 +02:00
|
|
|
SORT_FIELD * make_unireg_sortorder(ORDER *order, uint *length,
|
|
|
|
SORT_FIELD *sortorder);
|
2003-01-25 01:25:52 +01:00
|
|
|
int setup_order(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
|
|
|
|
List<Item> &fields, List <Item> &all_fields, ORDER *order);
|
|
|
|
int setup_group(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
|
|
|
|
List<Item> &fields, List<Item> &all_fields, ORDER *order,
|
2002-08-30 11:40:40 +02:00
|
|
|
bool *hidden_group_fields);
|
2007-02-21 21:00:32 +01:00
|
|
|
bool fix_inner_refs(THD *thd, List<Item> &all_fields, SELECT_LEX *select,
|
|
|
|
Item **ref_pointer_array);
|
2000-11-11 19:27:34 +01:00
|
|
|
|
2005-01-03 20:04:33 +01:00
|
|
|
bool handle_select(THD *thd, LEX *lex, select_result *result,
|
|
|
|
ulong setup_tables_done_option);
|
2004-10-20 03:04:37 +02:00
|
|
|
bool mysql_select(THD *thd, Item ***rref_pointer_array,
|
|
|
|
TABLE_LIST *tables, uint wild_num, List<Item> &list,
|
|
|
|
COND *conds, uint og_num, ORDER *order, ORDER *group,
|
2006-11-30 02:40:42 +01:00
|
|
|
Item *having, ORDER *proc_param, ulonglong select_type,
|
2004-10-20 03:04:37 +02:00
|
|
|
select_result *result, SELECT_LEX_UNIT *unit,
|
|
|
|
SELECT_LEX *select_lex);
|
2003-02-02 22:30:01 +01:00
|
|
|
void free_underlaid_joins(THD *thd, SELECT_LEX *select);
|
2004-10-20 03:04:37 +02:00
|
|
|
bool mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit,
|
|
|
|
select_result *result);
|
2002-09-26 22:08:22 +02:00
|
|
|
int mysql_explain_select(THD *thd, SELECT_LEX *sl, char const *type,
|
|
|
|
select_result *result);
|
2004-10-20 03:04:37 +02:00
|
|
|
bool mysql_union(THD *thd, LEX *lex, select_result *result,
|
2005-01-03 20:04:33 +01:00
|
|
|
SELECT_LEX_UNIT *unit, ulong setup_tables_done_option);
|
2005-10-27 23:18:23 +02:00
|
|
|
bool mysql_handle_derived(LEX *lex, bool (*processor)(THD *thd,
|
|
|
|
LEX *lex,
|
|
|
|
TABLE_LIST *table));
|
|
|
|
bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *t);
|
|
|
|
bool mysql_derived_filling(THD *thd, LEX *lex, TABLE_LIST *t);
|
2001-12-05 12:03:00 +01:00
|
|
|
Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
|
2003-01-28 07:38:28 +01:00
|
|
|
Item ***copy_func, Field **from_field,
|
2006-05-24 10:56:59 +02:00
|
|
|
Field **def_field,
|
2005-03-16 15:11:01 +01:00
|
|
|
bool group, bool modify_item,
|
2005-06-30 10:38:29 +02:00
|
|
|
bool table_cant_handle_bit_fields,
|
2006-03-30 15:14:55 +02:00
|
|
|
bool make_copy_field,
|
2005-03-16 15:11:01 +01:00
|
|
|
uint convert_blob_length);
|
2005-04-19 10:09:25 +02:00
|
|
|
void sp_prepare_create_field(THD *thd, create_field *sql_field);
|
2005-03-04 22:14:35 +01:00
|
|
|
int prepare_create_field(create_field *sql_field,
|
2005-03-16 15:11:01 +01:00
|
|
|
uint *blob_columns,
|
|
|
|
int *timestamps, int *timestamps_with_niladic,
|
2006-11-30 02:40:42 +01:00
|
|
|
longlong table_flags);
|
2004-10-20 03:04:37 +02:00
|
|
|
bool mysql_create_table(THD *thd,const char *db, const char *table_name,
|
|
|
|
HA_CREATE_INFO *create_info,
|
|
|
|
List<create_field> &fields, List<Key> &keys,
|
2006-06-21 16:57:30 +02:00
|
|
|
bool tmp_table, uint select_field_count,
|
|
|
|
bool use_copy_create_info);
|
2004-08-20 00:52:43 +02:00
|
|
|
|
2004-10-20 03:04:37 +02:00
|
|
|
bool mysql_alter_table(THD *thd, char *new_db, char *new_name,
|
|
|
|
HA_CREATE_INFO *create_info,
|
|
|
|
TABLE_LIST *table_list,
|
|
|
|
List<create_field> &fields,
|
|
|
|
List<Key> &keys,
|
2006-07-01 23:51:10 +02:00
|
|
|
uint order_num, ORDER *order, bool ignore,
|
2005-03-16 15:11:01 +01:00
|
|
|
ALTER_INFO *alter_info, bool do_send_ok);
|
2004-10-20 03:04:37 +02:00
|
|
|
bool mysql_recreate_table(THD *thd, TABLE_LIST *table_list, bool do_send_ok);
|
|
|
|
bool mysql_create_like_table(THD *thd, TABLE_LIST *table,
|
|
|
|
HA_CREATE_INFO *create_info,
|
|
|
|
Table_ident *src_table);
|
2006-08-02 17:57:06 +02:00
|
|
|
bool mysql_rename_table(handlerton *base, const char *old_db,
|
|
|
|
const char * old_name, const char *new_db,
|
|
|
|
const char * new_name, uint flags);
|
2004-10-20 03:04:37 +02:00
|
|
|
bool mysql_create_index(THD *thd, TABLE_LIST *table_list, List<Key> &keys);
|
|
|
|
bool mysql_drop_index(THD *thd, TABLE_LIST *table_list,
|
|
|
|
ALTER_INFO *alter_info);
|
2004-11-12 13:34:00 +01:00
|
|
|
bool mysql_prepare_update(THD *thd, TABLE_LIST *table_list,
|
|
|
|
Item **conds, uint order_num, ORDER *order);
|
2004-11-25 01:23:13 +01:00
|
|
|
int mysql_update(THD *thd,TABLE_LIST *tables,List<Item> &fields,
|
|
|
|
List<Item> &values,COND *conds,
|
|
|
|
uint order_num, ORDER *order, ha_rows limit,
|
2004-12-31 11:04:35 +01:00
|
|
|
enum enum_duplicates handle_duplicates, bool ignore);
|
2004-10-20 03:04:37 +02:00
|
|
|
bool mysql_multi_update(THD *thd, TABLE_LIST *table_list,
|
|
|
|
List<Item> *fields, List<Item> *values,
|
2005-08-12 12:54:42 +02:00
|
|
|
COND *conds, ulonglong options,
|
2005-01-03 22:04:52 +01:00
|
|
|
enum enum_duplicates handle_duplicates, bool ignore,
|
2004-10-20 03:04:37 +02:00
|
|
|
SELECT_LEX_UNIT *unit, SELECT_LEX *select_lex);
|
|
|
|
bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list, TABLE *table,
|
|
|
|
List<Item> &fields, List_item *values,
|
|
|
|
List<Item> &update_fields,
|
2004-12-30 23:44:00 +01:00
|
|
|
List<Item> &update_values, enum_duplicates duplic,
|
2007-03-16 09:35:39 +01:00
|
|
|
COND **where, bool select_insert,
|
|
|
|
bool check_fields, bool abort_on_warning);
|
2004-10-20 03:04:37 +02:00
|
|
|
bool mysql_insert(THD *thd,TABLE_LIST *table,List<Item> &fields,
|
|
|
|
List<List_item> &values, List<Item> &update_fields,
|
2005-01-03 22:04:52 +01:00
|
|
|
List<Item> &update_values, enum_duplicates flag,
|
|
|
|
bool ignore);
|
2005-07-01 06:05:42 +02:00
|
|
|
int check_that_all_fields_are_given_values(THD *thd, TABLE *entry,
|
|
|
|
TABLE_LIST *table_list);
|
2007-04-04 16:58:25 +02:00
|
|
|
void prepare_triggers_for_insert_stmt(TABLE *table);
|
2004-10-20 03:04:37 +02:00
|
|
|
bool mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds);
|
2005-08-30 11:39:20 +02:00
|
|
|
bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
|
|
|
|
SQL_LIST *order, ha_rows rows, ulonglong options,
|
|
|
|
bool reset_auto_increment);
|
2004-10-20 03:04:37 +02:00
|
|
|
bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok);
|
|
|
|
bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create);
|
2005-11-29 09:07:21 +01:00
|
|
|
uint create_table_def_key(THD *thd, char *key, TABLE_LIST *table_list,
|
2005-11-23 21:45:02 +01:00
|
|
|
bool tmp_table);
|
2005-11-29 09:07:21 +01:00
|
|
|
TABLE_SHARE *get_table_share(THD *thd, TABLE_LIST *table_list, char *key,
|
2005-11-23 21:45:02 +01:00
|
|
|
uint key_length, uint db_flags, int *error);
|
|
|
|
void release_table_share(TABLE_SHARE *share, enum release_type type);
|
|
|
|
TABLE_SHARE *get_cached_table_share(const char *db, const char *table_name);
|
2000-07-31 21:29:14 +02:00
|
|
|
TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type update);
|
2004-07-16 00:15:55 +02:00
|
|
|
TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT* mem,
|
2005-07-13 11:48:13 +02:00
|
|
|
bool *refresh, uint flags);
|
2005-10-17 20:37:24 +02:00
|
|
|
bool reopen_name_locked_table(THD* thd, TABLE_LIST* table);
|
2000-07-31 21:29:14 +02:00
|
|
|
TABLE *find_locked_table(THD *thd, const char *db,const char *table_name);
|
|
|
|
bool reopen_tables(THD *thd,bool get_locks,bool in_refresh);
|
|
|
|
bool close_data_tables(THD *thd,const char *db, const char *table_name);
|
|
|
|
bool wait_for_tables(THD *thd);
|
2000-08-29 11:31:01 +02:00
|
|
|
bool table_is_used(TABLE *table, bool wait_for_name_lock);
|
2006-03-29 13:27:36 +02:00
|
|
|
TABLE *drop_locked_tables(THD *thd,const char *db, const char *table_name);
|
2000-07-31 21:29:14 +02:00
|
|
|
void abort_locked_tables(THD *thd,const char *db, const char *table_name);
|
2003-12-08 06:13:14 +01:00
|
|
|
void execute_init_command(THD *thd, sys_var_str *init_command_var,
|
|
|
|
rw_lock_t *var_mutex);
|
2004-11-12 20:24:16 +01:00
|
|
|
extern Field *not_found_field;
|
|
|
|
extern Field *view_ref_found;
|
2004-11-02 17:23:15 +01:00
|
|
|
|
|
|
|
enum find_item_error_report_type {REPORT_ALL_ERRORS, REPORT_EXCEPT_NOT_FOUND,
|
|
|
|
IGNORE_ERRORS, REPORT_EXCEPT_NON_UNIQUE,
|
|
|
|
IGNORE_EXCEPT_NON_UNIQUE};
|
2004-08-26 23:08:59 +02:00
|
|
|
Field *
|
2005-08-12 16:57:19 +02:00
|
|
|
find_field_in_tables(THD *thd, Item_ident *item,
|
|
|
|
TABLE_LIST *first_table, TABLE_LIST *last_table,
|
|
|
|
Item **ref, find_item_error_report_type report_error,
|
|
|
|
bool check_privileges, bool register_tree_change);
|
2004-09-08 11:29:21 +02:00
|
|
|
Field *
|
2005-08-12 16:57:19 +02:00
|
|
|
find_field_in_table_ref(THD *thd, TABLE_LIST *table_list,
|
2005-11-28 20:57:50 +01:00
|
|
|
const char *name, uint length,
|
|
|
|
const char *item_name, const char *db_name,
|
|
|
|
const char *table_name, Item **ref,
|
2005-11-30 20:27:11 +01:00
|
|
|
bool check_privileges, bool allow_rowid,
|
2005-08-12 16:57:19 +02:00
|
|
|
uint *cached_field_index_ptr,
|
|
|
|
bool register_tree_change, TABLE_LIST **actual_table);
|
2004-09-08 11:29:21 +02:00
|
|
|
Field *
|
2005-11-30 20:27:11 +01:00
|
|
|
find_field_in_table(THD *thd, TABLE *table, const char *name, uint length,
|
|
|
|
bool allow_rowid, uint *cached_field_index_ptr);
|
2005-07-18 13:31:02 +02:00
|
|
|
Field *
|
|
|
|
find_field_in_table_sef(TABLE *table, const char *name);
|
|
|
|
|
2006-01-19 22:40:56 +01:00
|
|
|
#endif /* MYSQL_SERVER */
|
|
|
|
|
2001-12-10 10:02:26 +01:00
|
|
|
#ifdef HAVE_OPENSSL
|
2003-05-30 15:41:19 +02:00
|
|
|
#include <openssl/des.h>
|
2002-12-04 23:14:51 +01:00
|
|
|
struct st_des_keyblock
|
|
|
|
{
|
2003-10-07 14:42:26 +02:00
|
|
|
DES_cblock key1, key2, key3;
|
2001-12-10 10:02:26 +01:00
|
|
|
};
|
|
|
|
struct st_des_keyschedule
|
|
|
|
{
|
2003-09-12 20:33:43 +02:00
|
|
|
DES_key_schedule ks1, ks2, ks3;
|
2001-12-10 10:02:26 +01:00
|
|
|
};
|
2001-12-13 14:53:18 +01:00
|
|
|
extern char *des_key_file;
|
2001-12-13 02:36:36 +01:00
|
|
|
extern struct st_des_keyschedule des_keyschedule[10];
|
2001-12-13 01:31:19 +01:00
|
|
|
extern uint des_default_key;
|
2001-12-13 14:53:18 +01:00
|
|
|
extern pthread_mutex_t LOCK_des_key_file;
|
|
|
|
bool load_des_key_file(const char *file_name);
|
2001-12-10 10:02:26 +01:00
|
|
|
#endif /* HAVE_OPENSSL */
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2006-01-19 22:40:56 +01:00
|
|
|
#ifdef MYSQL_SERVER
|
2001-12-17 18:59:20 +01:00
|
|
|
/* sql_do.cc */
|
2004-10-20 03:04:37 +02:00
|
|
|
bool mysql_do(THD *thd, List<Item> &values);
|
2001-12-17 18:59:20 +01:00
|
|
|
|
2005-01-21 03:36:40 +01:00
|
|
|
/* sql_analyse.h */
|
|
|
|
bool append_escaped(String *to_str, String *from_str);
|
|
|
|
|
2002-06-13 00:47:05 +02:00
|
|
|
/* sql_show.cc */
|
2004-10-20 03:04:37 +02:00
|
|
|
bool mysqld_show_open_tables(THD *thd,const char *wild);
|
|
|
|
bool mysqld_show_logs(THD *thd);
|
2003-06-27 15:29:10 +02:00
|
|
|
void append_identifier(THD *thd, String *packet, const char *name,
|
|
|
|
uint length);
|
2004-10-01 10:51:59 +02:00
|
|
|
int get_quote_char_for_identifier(THD *thd, const char *name, uint length);
|
2000-07-31 21:29:14 +02:00
|
|
|
void mysqld_list_fields(THD *thd,TABLE_LIST *table, const char *wild);
|
2005-03-16 15:11:01 +01:00
|
|
|
int mysqld_dump_create_info(THD *thd, TABLE_LIST *table_list, int fd);
|
2004-10-20 03:04:37 +02:00
|
|
|
bool mysqld_show_create(THD *thd, TABLE_LIST *table_list);
|
|
|
|
bool mysqld_show_create_db(THD *thd, char *dbname, HA_CREATE_INFO *create);
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
void mysqld_list_processes(THD *thd,const char *user,bool verbose);
|
|
|
|
int mysqld_show_status(THD *thd);
|
|
|
|
int mysqld_show_variables(THD *thd,const char *wild);
|
2004-10-20 03:04:37 +02:00
|
|
|
bool mysqld_show_storage_engines(THD *thd);
|
2005-11-10 18:43:17 +01:00
|
|
|
bool mysqld_show_authors(THD *thd);
|
2006-05-03 02:53:26 +02:00
|
|
|
bool mysqld_show_contributors(THD *thd);
|
2004-10-20 03:04:37 +02:00
|
|
|
bool mysqld_show_privileges(THD *thd);
|
|
|
|
bool mysqld_show_column_types(THD *thd);
|
|
|
|
bool mysqld_help (THD *thd, const char *text);
|
2004-09-13 15:48:01 +02:00
|
|
|
void calc_sum_of_all_status(STATUS_VAR *to);
|
2002-06-12 23:13:12 +02:00
|
|
|
|
2005-11-10 20:25:03 +01:00
|
|
|
void append_definer(THD *thd, String *buffer, const LEX_STRING *definer_user,
|
|
|
|
const LEX_STRING *definer_host);
|
|
|
|
|
2006-01-07 14:41:57 +01:00
|
|
|
int add_status_vars(SHOW_VAR *list);
|
|
|
|
void remove_status_vars(SHOW_VAR *list);
|
|
|
|
void init_status_vars();
|
|
|
|
void free_status_vars();
|
2007-03-02 17:43:45 +01:00
|
|
|
void reset_status_vars();
|
2005-11-10 20:25:03 +01:00
|
|
|
|
2004-11-13 11:56:39 +01:00
|
|
|
/* information schema */
|
2007-03-27 19:55:01 +02:00
|
|
|
extern LEX_STRING INFORMATION_SCHEMA_NAME;
|
2006-01-18 10:56:07 +01:00
|
|
|
extern const LEX_STRING partition_keywords[];
|
2004-11-13 11:56:39 +01:00
|
|
|
LEX_STRING *make_lex_string(THD *thd, LEX_STRING *lex_str,
|
|
|
|
const char* str, uint length,
|
2005-03-16 15:11:01 +01:00
|
|
|
bool allocate_lex_string);
|
2004-11-13 11:56:39 +01:00
|
|
|
ST_SCHEMA_TABLE *find_schema_table(THD *thd, const char* table_name);
|
|
|
|
ST_SCHEMA_TABLE *get_schema_table(enum enum_schema_tables schema_table_idx);
|
|
|
|
int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident,
|
|
|
|
enum enum_schema_tables schema_table_idx);
|
|
|
|
int make_schema_select(THD *thd, SELECT_LEX *sel,
|
|
|
|
enum enum_schema_tables schema_table_idx);
|
|
|
|
int mysql_schema_table(THD *thd, LEX *lex, TABLE_LIST *table_list);
|
|
|
|
int fill_schema_user_privileges(THD *thd, TABLE_LIST *tables, COND *cond);
|
|
|
|
int fill_schema_schema_privileges(THD *thd, TABLE_LIST *tables, COND *cond);
|
|
|
|
int fill_schema_table_privileges(THD *thd, TABLE_LIST *tables, COND *cond);
|
|
|
|
int fill_schema_column_privileges(THD *thd, TABLE_LIST *tables, COND *cond);
|
2007-02-12 13:06:14 +01:00
|
|
|
bool get_schema_tables_result(JOIN *join,
|
|
|
|
enum enum_schema_table_state executed_place);
|
2007-04-03 13:11:34 +02:00
|
|
|
enum enum_schema_tables get_schema_table_idx(ST_SCHEMA_TABLE *schema_table);
|
|
|
|
|
2005-09-13 13:07:38 +02:00
|
|
|
#define is_schema_db(X) \
|
2007-03-27 19:55:01 +02:00
|
|
|
!my_strcasecmp(system_charset_info, INFORMATION_SCHEMA_NAME.str, (X))
|
2004-11-13 11:56:39 +01:00
|
|
|
|
2002-06-12 23:13:12 +02:00
|
|
|
/* sql_prepare.cc */
|
Implement WL#2661 "Prepared Statements: Dynamic SQL in Stored Procedures".
The idea of the patch is to separate statement processing logic,
such as parsing, validation of the parsed tree, execution and cleanup,
from global query processing logic, such as logging, resetting
priorities of a thread, resetting stored procedure cache, resetting
thread count of errors and warnings.
This makes PREPARE and EXECUTE behave similarly to the rest of SQL
statements and allows their use in stored procedures.
This patch contains a change in behaviour:
until recently for each SQL prepared statement command, 2 queries
were written to the general log, e.g.
[Query] prepare stmt from @stmt_text;
[Prepare] select * from t1 <-- contents of @stmt_text
The chagne was necessary to prevent [Prepare] commands from being written
to the general log when executing a stored procedure with Dynamic SQL.
We should consider whether the old behavior is preferrable and probably
restore it.
This patch refixes Bug#7115, Bug#10975 (partially), Bug#10605 (various bugs
in Dynamic SQL reported before it was disabled).
2005-09-03 01:13:18 +02:00
|
|
|
|
|
|
|
void mysql_stmt_prepare(THD *thd, const char *packet, uint packet_length);
|
2004-03-15 18:20:47 +01:00
|
|
|
void mysql_stmt_execute(THD *thd, char *packet, uint packet_length);
|
2005-06-17 21:26:25 +02:00
|
|
|
void mysql_stmt_close(THD *thd, char *packet);
|
Implement WL#2661 "Prepared Statements: Dynamic SQL in Stored Procedures".
The idea of the patch is to separate statement processing logic,
such as parsing, validation of the parsed tree, execution and cleanup,
from global query processing logic, such as logging, resetting
priorities of a thread, resetting stored procedure cache, resetting
thread count of errors and warnings.
This makes PREPARE and EXECUTE behave similarly to the rest of SQL
statements and allows their use in stored procedures.
This patch contains a change in behaviour:
until recently for each SQL prepared statement command, 2 queries
were written to the general log, e.g.
[Query] prepare stmt from @stmt_text;
[Prepare] select * from t1 <-- contents of @stmt_text
The chagne was necessary to prevent [Prepare] commands from being written
to the general log when executing a stored procedure with Dynamic SQL.
We should consider whether the old behavior is preferrable and probably
restore it.
This patch refixes Bug#7115, Bug#10975 (partially), Bug#10605 (various bugs
in Dynamic SQL reported before it was disabled).
2005-09-03 01:13:18 +02:00
|
|
|
void mysql_sql_stmt_prepare(THD *thd);
|
|
|
|
void mysql_sql_stmt_execute(THD *thd);
|
|
|
|
void mysql_sql_stmt_close(THD *thd);
|
|
|
|
void mysql_stmt_fetch(THD *thd, char *packet, uint packet_length);
|
2003-07-08 11:27:21 +02:00
|
|
|
void mysql_stmt_reset(THD *thd, char *packet);
|
2002-10-02 12:33:08 +02:00
|
|
|
void mysql_stmt_get_longdata(THD *thd, char *pos, ulong packet_length);
|
2005-06-09 16:17:45 +02:00
|
|
|
void reinit_stmt_before_use(THD *thd, LEX *lex);
|
2002-06-12 23:13:12 +02:00
|
|
|
|
2001-04-07 00:18:33 +02:00
|
|
|
/* sql_handler.cc */
|
2005-03-16 15:11:01 +01:00
|
|
|
bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen);
|
2004-11-12 14:36:31 +01:00
|
|
|
bool mysql_ha_close(THD *thd, TABLE_LIST *tables);
|
2004-10-20 03:04:37 +02:00
|
|
|
bool mysql_ha_read(THD *, TABLE_LIST *,enum enum_ha_read_modes,char *,
|
|
|
|
List<Item> *,enum ha_rkey_function,Item *,ha_rows,ha_rows);
|
2005-11-15 21:57:02 +01:00
|
|
|
int mysql_ha_flush(THD *thd, TABLE_LIST *tables, uint mode_flags,
|
|
|
|
bool is_locked);
|
2006-11-27 10:24:24 +01:00
|
|
|
void mysql_ha_mark_tables_for_reopen(THD *thd, TABLE *table);
|
2004-09-24 18:39:25 +02:00
|
|
|
/* mysql_ha_flush mode_flags bits */
|
|
|
|
#define MYSQL_HA_CLOSE_FINAL 0x00
|
|
|
|
#define MYSQL_HA_REOPEN_ON_USAGE 0x01
|
|
|
|
#define MYSQL_HA_FLUSH_ALL 0x02
|
2001-04-07 00:18:33 +02:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
/* sql_base.cc */
|
2004-10-22 21:51:04 +02:00
|
|
|
#define TMP_TABLE_KEY_EXTRA 8
|
2000-07-31 21:29:14 +02:00
|
|
|
void set_item_name(Item *item,char *pos,uint length);
|
2007-04-03 13:13:27 +02:00
|
|
|
bool add_field_to_list(THD *thd, LEX_STRING *field_name, enum enum_field_types type,
|
2000-07-31 21:29:14 +02:00
|
|
|
char *length, char *decimal,
|
2002-06-02 20:22:20 +02:00
|
|
|
uint type_modifier,
|
2004-04-02 08:12:53 +02:00
|
|
|
Item *default_value, Item *on_update_value,
|
2003-09-16 09:14:40 +02:00
|
|
|
LEX_STRING *comment,
|
2004-12-02 09:48:43 +01:00
|
|
|
char *change, List<String> *interval_list,
|
|
|
|
CHARSET_INFO *cs,
|
2003-03-27 10:09:09 +01:00
|
|
|
uint uint_geom_type);
|
2005-03-04 22:14:35 +01:00
|
|
|
create_field * new_create_field(THD *thd, char *field_name, enum_field_types type,
|
|
|
|
char *length, char *decimals,
|
|
|
|
uint type_modifier,
|
|
|
|
Item *default_value, Item *on_update_value,
|
|
|
|
LEX_STRING *comment, char *change,
|
|
|
|
List<String> *interval_list, CHARSET_INFO *cs,
|
|
|
|
uint uint_geom_type);
|
2000-07-31 21:29:14 +02:00
|
|
|
void store_position_for_column(const char *name);
|
2005-03-16 15:11:01 +01:00
|
|
|
bool add_to_list(THD *thd, SQL_LIST &list,Item *group,bool asc);
|
2005-11-28 20:57:50 +01:00
|
|
|
bool push_new_name_resolution_context(THD *thd,
|
|
|
|
TABLE_LIST *left_op,
|
|
|
|
TABLE_LIST *right_op);
|
2000-07-31 21:29:14 +02:00
|
|
|
void add_join_on(TABLE_LIST *b,Item *expr);
|
2007-01-31 15:04:38 +01:00
|
|
|
void add_join_natural(TABLE_LIST *a,TABLE_LIST *b,List<String> *using_fields,
|
|
|
|
SELECT_LEX *lex);
|
2002-11-29 15:40:18 +01:00
|
|
|
bool add_proc_to_list(THD *thd, Item *item);
|
2000-07-31 21:29:14 +02:00
|
|
|
TABLE *unlink_open_table(THD *thd,TABLE *list,TABLE *find);
|
2005-08-02 21:54:49 +02:00
|
|
|
void update_non_unique_table_error(TABLE_LIST *update,
|
|
|
|
const char *operation,
|
|
|
|
TABLE_LIST *duplicate);
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
SQL_SELECT *make_select(TABLE *head, table_map const_tables,
|
2005-03-16 15:11:01 +01:00
|
|
|
table_map read_tables, COND *conds,
|
|
|
|
bool allow_null_cond, int *error);
|
2004-11-12 20:24:16 +01:00
|
|
|
extern Item **not_found_item;
|
2007-03-05 04:54:35 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
This enumeration type is used only by the function find_item_in_list
|
|
|
|
to return the info on how an item has been resolved against a list
|
|
|
|
of possibly aliased items.
|
|
|
|
The item can be resolved:
|
|
|
|
- against an alias name of the list's element (RESOLVED_AGAINST_ALIAS)
|
|
|
|
- against non-aliased field name of the list (RESOLVED_WITH_NO_ALIAS)
|
|
|
|
- against an aliased field name of the list (RESOLVED_BEHIND_ALIAS)
|
|
|
|
- ignoring the alias name in cases when SQL requires to ignore aliases
|
|
|
|
(e.g. when the resolved field reference contains a table name or
|
|
|
|
when the resolved item is an expression) (RESOLVED_IGNORING_ALIAS)
|
|
|
|
*/
|
|
|
|
enum enum_resolution_type {
|
|
|
|
NOT_RESOLVED=0,
|
|
|
|
RESOLVED_IGNORING_ALIAS,
|
|
|
|
RESOLVED_BEHIND_ALIAS,
|
|
|
|
RESOLVED_WITH_NO_ALIAS,
|
|
|
|
RESOLVED_AGAINST_ALIAS
|
|
|
|
};
|
2003-01-25 01:25:52 +01:00
|
|
|
Item ** find_item_in_list(Item *item, List<Item> &items, uint *counter,
|
2004-09-30 14:28:17 +02:00
|
|
|
find_item_error_report_type report_error,
|
2007-03-05 04:54:35 +01:00
|
|
|
enum_resolution_type *resolution);
|
2003-11-18 12:47:27 +01:00
|
|
|
bool get_key_map_from_key_list(key_map *map, TABLE *table,
|
2003-10-11 13:06:55 +02:00
|
|
|
List<String> *index_list);
|
2005-07-01 06:05:42 +02:00
|
|
|
bool insert_fields(THD *thd, Name_resolution_context *context,
|
2001-05-20 15:08:09 +02:00
|
|
|
const char *db_name, const char *table_name,
|
2005-07-01 06:05:42 +02:00
|
|
|
List_iterator<Item> *it, bool any_privileges);
|
|
|
|
bool setup_tables(THD *thd, Name_resolution_context *context,
|
2005-08-12 16:57:19 +02:00
|
|
|
List<TABLE_LIST> *from_clause, TABLE_LIST *tables,
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
TABLE_LIST **leaves, bool select_insert);
|
2006-06-04 20:05:22 +02:00
|
|
|
bool setup_tables_and_check_access(THD *thd,
|
|
|
|
Name_resolution_context *context,
|
|
|
|
List<TABLE_LIST> *from_clause,
|
|
|
|
TABLE_LIST *tables,
|
|
|
|
TABLE_LIST **leaves,
|
|
|
|
bool select_insert,
|
2006-08-29 16:58:50 +02:00
|
|
|
ulong want_access_first,
|
2006-06-04 20:05:22 +02:00
|
|
|
ulong want_access);
|
2003-01-25 01:25:52 +01:00
|
|
|
int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields,
|
|
|
|
List<Item> *sum_func_list, uint wild_num);
|
2005-07-01 06:05:42 +02:00
|
|
|
bool setup_fields(THD *thd, Item** ref_pointer_array,
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
List<Item> &item, enum_mark_columns mark_used_columns,
|
2004-10-20 03:04:37 +02:00
|
|
|
List<Item> *sum_func_list, bool allow_sum_func);
|
2005-07-01 06:05:42 +02:00
|
|
|
inline bool setup_fields_with_no_wrap(THD *thd, Item **ref_pointer_array,
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
List<Item> &item,
|
|
|
|
enum_mark_columns mark_used_columns,
|
|
|
|
List<Item> *sum_func_list,
|
|
|
|
bool allow_sum_func)
|
2005-07-01 06:05:42 +02:00
|
|
|
{
|
|
|
|
bool res;
|
|
|
|
thd->lex->select_lex.no_wrap_view_item= TRUE;
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
res= setup_fields(thd, ref_pointer_array, item, mark_used_columns, sum_func_list,
|
2005-07-01 06:05:42 +02:00
|
|
|
allow_sum_func);
|
|
|
|
thd->lex->select_lex.no_wrap_view_item= FALSE;
|
|
|
|
return res;
|
|
|
|
}
|
2004-09-14 18:28:29 +02:00
|
|
|
int setup_conds(THD *thd, TABLE_LIST *tables, TABLE_LIST *leaves,
|
|
|
|
COND **conds);
|
2002-10-30 12:18:52 +01:00
|
|
|
int setup_ftfuncs(SELECT_LEX* select);
|
|
|
|
int init_ftfuncs(THD *thd, SELECT_LEX* select, bool no_order);
|
2005-11-23 21:45:02 +01:00
|
|
|
void wait_for_condition(THD *thd, pthread_mutex_t *mutex,
|
|
|
|
pthread_cond_t *cond);
|
2005-08-08 15:46:06 +02:00
|
|
|
int open_tables(THD *thd, TABLE_LIST **tables, uint *counter, uint flags);
|
2004-02-01 14:30:32 +01:00
|
|
|
int simple_open_n_lock_tables(THD *thd,TABLE_LIST *tables);
|
2004-10-20 03:04:37 +02:00
|
|
|
bool open_and_lock_tables(THD *thd,TABLE_LIST *tables);
|
2005-08-08 15:46:06 +02:00
|
|
|
bool open_normal_and_derived_tables(THD *thd, TABLE_LIST *tables, uint flags);
|
2005-09-15 01:56:09 +02:00
|
|
|
int lock_tables(THD *thd, TABLE_LIST *tables, uint counter, bool *need_reopen);
|
2000-07-31 21:29:14 +02:00
|
|
|
TABLE *open_temporary_table(THD *thd, const char *path, const char *db,
|
|
|
|
const char *table_name, bool link_in_list);
|
2005-12-21 19:18:40 +01:00
|
|
|
bool rm_temporary_table(handlerton *base, char *path);
|
2000-07-31 21:29:14 +02:00
|
|
|
void free_io_cache(TABLE *entry);
|
|
|
|
void intern_close_table(TABLE *entry);
|
2002-09-03 15:28:01 +02:00
|
|
|
bool close_thread_table(THD *thd, TABLE **table_ptr);
|
2000-07-31 21:29:14 +02:00
|
|
|
void close_temporary_tables(THD *thd);
|
2006-02-16 14:19:24 +01:00
|
|
|
void close_tables_for_reopen(THD *thd, TABLE_LIST **tables);
|
2004-09-03 20:43:04 +02:00
|
|
|
TABLE_LIST *find_table_in_list(TABLE_LIST *table,
|
2006-02-25 16:46:30 +01:00
|
|
|
st_table_list *TABLE_LIST::*link,
|
2004-09-03 20:43:04 +02:00
|
|
|
const char *db_name,
|
|
|
|
const char *table_name);
|
2007-03-01 22:09:22 +01:00
|
|
|
TABLE_LIST *unique_table(THD *thd, TABLE_LIST *table, TABLE_LIST *table_list,
|
|
|
|
bool check_alias);
|
2005-11-23 21:45:02 +01:00
|
|
|
TABLE *find_temporary_table(THD *thd, const char *db, const char *table_name);
|
|
|
|
TABLE *find_temporary_table(THD *thd, TABLE_LIST *table_list);
|
|
|
|
bool close_temporary_table(THD *thd, TABLE_LIST *table_list);
|
|
|
|
void close_temporary_table(THD *thd, TABLE *table, bool free_share,
|
|
|
|
bool delete_table);
|
|
|
|
void close_temporary(TABLE *table, bool free_share, bool delete_table);
|
2000-11-26 07:29:01 +01:00
|
|
|
bool rename_temporary_table(THD* thd, TABLE *table, const char *new_db,
|
2000-07-31 21:29:14 +02:00
|
|
|
const char *table_name);
|
2005-02-09 00:14:14 +01:00
|
|
|
void remove_db_from_cache(const char *db);
|
2000-07-31 21:29:14 +02:00
|
|
|
void flush_tables();
|
2005-07-31 11:49:55 +02:00
|
|
|
bool is_equal(const LEX_STRING *a, const LEX_STRING *b);
|
2006-06-19 15:30:55 +02:00
|
|
|
char *make_default_log_name(char *buff,const char* log_ext);
|
2005-07-26 16:55:58 +02:00
|
|
|
|
2006-01-17 08:40:00 +01:00
|
|
|
#ifdef WITH_PARTITION_STORAGE_ENGINE
|
|
|
|
uint fast_alter_partition_table(THD *thd, TABLE *table,
|
|
|
|
ALTER_INFO *alter_info,
|
|
|
|
HA_CREATE_INFO *create_info,
|
|
|
|
TABLE_LIST *table_list,
|
|
|
|
List<create_field> *create_list,
|
2006-05-27 00:44:52 +02:00
|
|
|
List<Key> *key_list, char *db,
|
2006-01-17 08:40:00 +01:00
|
|
|
const char *table_name,
|
|
|
|
uint fast_alter_partition);
|
|
|
|
uint prep_alter_part_table(THD *thd, TABLE *table, ALTER_INFO *alter_info,
|
|
|
|
HA_CREATE_INFO *create_info,
|
|
|
|
handlerton *old_db_type,
|
|
|
|
bool *partition_changed,
|
|
|
|
uint *fast_alter_partition);
|
|
|
|
#endif
|
|
|
|
|
2005-07-26 16:55:58 +02:00
|
|
|
/* bits for last argument to remove_table_from_cache() */
|
2005-07-20 21:19:01 +02:00
|
|
|
#define RTFC_NO_FLAG 0x0000
|
|
|
|
#define RTFC_OWNED_BY_THD_FLAG 0x0001
|
|
|
|
#define RTFC_WAIT_OTHER_THREAD_FLAG 0x0002
|
|
|
|
#define RTFC_CHECK_KILLED_FLAG 0x0004
|
2000-11-28 03:47:47 +01:00
|
|
|
bool remove_table_from_cache(THD *thd, const char *db, const char *table,
|
2005-07-19 00:29:19 +02:00
|
|
|
uint flags);
|
2005-07-26 16:55:58 +02:00
|
|
|
|
2006-02-09 11:05:05 +01:00
|
|
|
#define NORMAL_PART_NAME 0
|
|
|
|
#define TEMP_PART_NAME 1
|
|
|
|
#define RENAMED_PART_NAME 2
|
|
|
|
void create_partition_name(char *out, const char *in1,
|
|
|
|
const char *in2, uint name_variant,
|
|
|
|
bool translate);
|
|
|
|
void create_subpartition_name(char *out, const char *in1,
|
|
|
|
const char *in2, const char *in3,
|
|
|
|
uint name_variant);
|
|
|
|
|
2006-01-17 08:40:00 +01:00
|
|
|
typedef struct st_lock_param_type
|
|
|
|
{
|
2006-05-27 00:44:52 +02:00
|
|
|
TABLE_LIST table_list;
|
2006-01-17 08:40:00 +01:00
|
|
|
ulonglong copied;
|
|
|
|
ulonglong deleted;
|
|
|
|
THD *thd;
|
|
|
|
HA_CREATE_INFO *create_info;
|
2006-05-27 22:34:13 +02:00
|
|
|
ALTER_INFO *alter_info;
|
2006-01-17 08:40:00 +01:00
|
|
|
List<create_field> *create_list;
|
|
|
|
List<create_field> new_create_list;
|
|
|
|
List<Key> *key_list;
|
|
|
|
List<Key> new_key_list;
|
|
|
|
TABLE *table;
|
|
|
|
KEY *key_info_buffer;
|
|
|
|
const char *db;
|
|
|
|
const char *table_name;
|
|
|
|
const void *pack_frm_data;
|
|
|
|
enum thr_lock_type old_lock_type;
|
|
|
|
uint key_count;
|
|
|
|
uint db_options;
|
|
|
|
uint pack_frm_len;
|
2006-02-09 20:13:22 +01:00
|
|
|
partition_info *part_info;
|
2006-01-17 08:40:00 +01:00
|
|
|
} ALTER_PARTITION_PARAM_TYPE;
|
|
|
|
|
|
|
|
void mem_alloc_error(size_t size);
|
2006-02-01 16:38:08 +01:00
|
|
|
|
2006-03-25 00:19:13 +01:00
|
|
|
enum ddl_log_entry_code
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
DDL_LOG_EXECUTE_CODE:
|
|
|
|
This is a code that indicates that this is a log entry to
|
|
|
|
be executed, from this entry a linked list of log entries
|
|
|
|
can be found and executed.
|
|
|
|
DDL_LOG_ENTRY_CODE:
|
|
|
|
An entry to be executed in a linked list from an execute log
|
|
|
|
entry.
|
|
|
|
DDL_IGNORE_LOG_ENTRY_CODE:
|
|
|
|
An entry that is to be ignored
|
|
|
|
*/
|
|
|
|
DDL_LOG_EXECUTE_CODE = 'e',
|
|
|
|
DDL_LOG_ENTRY_CODE = 'l',
|
|
|
|
DDL_IGNORE_LOG_ENTRY_CODE = 'i'
|
|
|
|
};
|
|
|
|
|
|
|
|
enum ddl_log_action_code
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
The type of action that a DDL_LOG_ENTRY_CODE entry is to
|
|
|
|
perform.
|
|
|
|
DDL_LOG_DELETE_ACTION:
|
|
|
|
Delete an entity
|
|
|
|
DDL_LOG_RENAME_ACTION:
|
|
|
|
Rename an entity
|
|
|
|
DDL_LOG_REPLACE_ACTION:
|
|
|
|
Rename an entity after removing the previous entry with the
|
|
|
|
new name, that is replace this entry.
|
|
|
|
*/
|
|
|
|
DDL_LOG_DELETE_ACTION = 'd',
|
|
|
|
DDL_LOG_RENAME_ACTION = 'r',
|
|
|
|
DDL_LOG_REPLACE_ACTION = 's'
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct st_ddl_log_entry
|
2006-02-06 21:47:03 +01:00
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
const char *from_name;
|
2006-03-25 00:19:13 +01:00
|
|
|
const char *handler_name;
|
2006-02-07 10:45:07 +01:00
|
|
|
uint next_entry;
|
2006-02-14 11:08:58 +01:00
|
|
|
uint entry_pos;
|
2006-03-25 00:19:13 +01:00
|
|
|
enum ddl_log_entry_code entry_type;
|
|
|
|
enum ddl_log_action_code action_type;
|
2006-04-01 16:37:36 +02:00
|
|
|
/*
|
|
|
|
Most actions have only one phase. REPLACE does however have two
|
|
|
|
phases. The first phase removes the file with the new name if
|
|
|
|
there was one there before and the second phase renames the
|
|
|
|
old name to the new name.
|
|
|
|
*/
|
2006-02-10 22:36:01 +01:00
|
|
|
char phase;
|
2006-03-25 00:19:13 +01:00
|
|
|
} DDL_LOG_ENTRY;
|
2006-02-06 21:47:03 +01:00
|
|
|
|
2006-03-25 00:19:13 +01:00
|
|
|
typedef struct st_ddl_log_memory_entry
|
2006-02-08 15:14:15 +01:00
|
|
|
{
|
|
|
|
uint entry_pos;
|
2006-03-25 00:19:13 +01:00
|
|
|
struct st_ddl_log_memory_entry *next_log_entry;
|
|
|
|
struct st_ddl_log_memory_entry *prev_log_entry;
|
|
|
|
struct st_ddl_log_memory_entry *next_active_log_entry;
|
|
|
|
} DDL_LOG_MEMORY_ENTRY;
|
2006-02-06 21:47:03 +01:00
|
|
|
|
2006-02-10 22:36:01 +01:00
|
|
|
|
2006-03-25 00:19:13 +01:00
|
|
|
bool write_ddl_log_entry(DDL_LOG_ENTRY *ddl_log_entry,
|
|
|
|
DDL_LOG_MEMORY_ENTRY **active_entry);
|
|
|
|
bool write_execute_ddl_log_entry(uint first_entry,
|
2006-02-09 20:20:21 +01:00
|
|
|
bool complete,
|
2006-03-25 00:19:13 +01:00
|
|
|
DDL_LOG_MEMORY_ENTRY **active_entry);
|
|
|
|
bool deactivate_ddl_log_entry(uint entry_no);
|
|
|
|
void release_ddl_log_memory_entry(DDL_LOG_MEMORY_ENTRY *log_entry);
|
|
|
|
bool sync_ddl_log();
|
|
|
|
void release_ddl_log();
|
|
|
|
void execute_ddl_log_recovery();
|
2006-04-03 18:26:35 +02:00
|
|
|
bool execute_ddl_log_entry(THD *thd, uint first_entry);
|
2006-04-16 03:49:13 +02:00
|
|
|
|
|
|
|
extern pthread_mutex_t LOCK_gdl;
|
2006-02-06 21:47:03 +01:00
|
|
|
|
2006-02-01 10:06:07 +01:00
|
|
|
#define WFRM_WRITE_SHADOW 1
|
|
|
|
#define WFRM_INSTALL_SHADOW 2
|
2006-01-17 08:40:00 +01:00
|
|
|
#define WFRM_PACK_FRM 4
|
|
|
|
bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags);
|
2006-04-16 03:49:13 +02:00
|
|
|
int abort_and_upgrade_lock(ALTER_PARTITION_PARAM_TYPE *lpt);
|
2006-01-17 08:40:00 +01:00
|
|
|
void close_open_tables_and_downgrade(ALTER_PARTITION_PARAM_TYPE *lpt);
|
|
|
|
void mysql_wait_completed_table(ALTER_PARTITION_PARAM_TYPE *lpt, TABLE *my_table);
|
|
|
|
|
BUG#9953: CONVERT_TZ requires mysql.time_zone_name to be locked
The problem was that some facilities (like CONVERT_TZ() function or
server HELP statement) may require implicit access to some tables in
'mysql' database. This access was done by ordinary means of adding
such tables to the list of tables the query is going to open.
However, if we issued LOCK TABLES before that, we would get "table
was not locked" error trying to open such implicit tables.
The solution is to treat certain tables as MySQL system tables, like
we already do for mysql.proc. Such tables may be opened for reading
at any moment regardless of any locks in effect. The cost of this is
that system table may be locked for writing only together with other
system tables, it is disallowed to lock system tables for writing and
have any other lock on any other table.
After this patch the following tables are treated as MySQL system
tables:
mysql.help_category
mysql.help_keyword
mysql.help_relation
mysql.help_topic
mysql.proc (it already was)
mysql.time_zone
mysql.time_zone_leap_second
mysql.time_zone_name
mysql.time_zone_transition
mysql.time_zone_transition_type
These tables are now opened with open_system_tables_for_read() and
closed with close_system_tables(), or one table may be opened with
open_system_table_for_update() and closed with close_thread_tables()
(the latter is used for mysql.proc table, which is updated as part of
normal MySQL server operation). These functions may be used when
some tables were opened and locked already.
NOTE: online update of time zone tables is not possible during
replication, because there's no time zone cache flush neither on LOCK
TABLES, nor on FLUSH TABLES, so the master may serve stale time zone
data from cache, while on slave updated data will be loaded from the
time zone tables.
2007-03-09 11:12:31 +01:00
|
|
|
/* Functions to work with system tables. */
|
|
|
|
bool open_system_tables_for_read(THD *thd, TABLE_LIST *table_list,
|
|
|
|
Open_tables_state *backup);
|
|
|
|
void close_system_tables(THD *thd, Open_tables_state *backup);
|
|
|
|
TABLE *open_system_table_for_update(THD *thd, TABLE_LIST *one_table);
|
|
|
|
|
2006-01-12 19:51:02 +01:00
|
|
|
bool close_cached_tables(THD *thd, bool wait_for_refresh, TABLE_LIST *tables, bool have_lock = FALSE);
|
2007-03-24 09:18:19 +01:00
|
|
|
bool close_cached_connection_tables(THD *thd, bool wait_for_refresh,
|
|
|
|
LEX_STRING *connect_string,
|
|
|
|
bool have_lock = FALSE);
|
2000-07-31 21:29:14 +02:00
|
|
|
void copy_field_from_tmp_record(Field *field,int offset);
|
2004-11-12 13:34:00 +01:00
|
|
|
bool fill_record(THD *thd, Field **field, List<Item> &values,
|
|
|
|
bool ignore_errors);
|
2005-05-24 20:19:33 +02:00
|
|
|
bool fill_record_n_invoke_before_triggers(THD *thd, List<Item> &fields,
|
|
|
|
List<Item> &values,
|
|
|
|
bool ignore_errors,
|
|
|
|
Table_triggers_list *triggers,
|
|
|
|
enum trg_event_type event);
|
|
|
|
bool fill_record_n_invoke_before_triggers(THD *thd, Field **field,
|
|
|
|
List<Item> &values,
|
|
|
|
bool ignore_errors,
|
|
|
|
Table_triggers_list *triggers,
|
|
|
|
enum trg_event_type event);
|
2005-08-16 11:18:35 +02:00
|
|
|
OPEN_TABLE_LIST *list_open_tables(THD *thd, const char *db, const char *wild);
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2004-09-03 20:43:04 +02:00
|
|
|
inline TABLE_LIST *find_table_in_global_list(TABLE_LIST *table,
|
|
|
|
const char *db_name,
|
|
|
|
const char *table_name)
|
|
|
|
{
|
2006-02-25 16:46:30 +01:00
|
|
|
return find_table_in_list(table, &TABLE_LIST::next_global,
|
2004-09-03 20:43:04 +02:00
|
|
|
db_name, table_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline TABLE_LIST *find_table_in_local_list(TABLE_LIST *table,
|
|
|
|
const char *db_name,
|
|
|
|
const char *table_name)
|
|
|
|
{
|
2006-02-25 16:46:30 +01:00
|
|
|
return find_table_in_list(table, &TABLE_LIST::next_local,
|
2004-09-03 20:43:04 +02:00
|
|
|
db_name, table_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
/* sql_calc.cc */
|
|
|
|
bool eval_const_cond(COND *cond);
|
|
|
|
|
|
|
|
/* sql_load.cc */
|
2004-10-28 10:02:48 +02:00
|
|
|
bool mysql_load(THD *thd, sql_exchange *ex, TABLE_LIST *table_list,
|
2005-03-16 02:32:47 +01:00
|
|
|
List<Item> &fields_vars, List<Item> &set_fields,
|
|
|
|
List<Item> &set_values_list,
|
|
|
|
enum enum_duplicates handle_duplicates, bool ignore,
|
2005-03-16 10:13:35 +01:00
|
|
|
bool local_file);
|
2004-09-28 19:08:00 +02:00
|
|
|
int write_record(THD *thd, TABLE *table, COPY_INFO *info);
|
2000-11-28 00:14:49 +01:00
|
|
|
|
|
|
|
/* sql_manager.cc */
|
2000-11-28 21:59:46 +01:00
|
|
|
extern ulong volatile manager_status;
|
2001-12-26 15:49:10 +01:00
|
|
|
extern bool volatile manager_thread_in_use, mqh_used;
|
2000-11-28 00:14:49 +01:00
|
|
|
extern pthread_t manager_thread;
|
2005-10-08 16:39:55 +02:00
|
|
|
pthread_handler_t handle_manager(void *arg);
|
2005-11-07 16:25:06 +01:00
|
|
|
bool mysql_manager_submit(void (*action)());
|
|
|
|
|
2000-11-28 00:14:49 +01:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
/* sql_test.cc */
|
|
|
|
#ifndef DBUG_OFF
|
|
|
|
void print_where(COND *cond,const char *info);
|
|
|
|
void print_cached_tables(void);
|
2002-10-16 16:21:47 +02:00
|
|
|
void TEST_filesort(SORT_FIELD *sortorder,uint s_length);
|
2006-05-03 03:31:20 +02:00
|
|
|
void print_plan(JOIN* join,uint idx, double record_count, double read_time,
|
|
|
|
double current_read_time, const char *info);
|
2000-07-31 21:29:14 +02:00
|
|
|
#endif
|
2005-02-17 13:07:28 +01:00
|
|
|
void mysql_print_status();
|
2000-07-31 21:29:14 +02:00
|
|
|
/* key.cc */
|
2006-11-21 21:32:58 +01:00
|
|
|
int find_ref_key(KEY *key, uint key_count, byte *record, Field *field,
|
2007-01-29 10:40:26 +01:00
|
|
|
uint *key_length, uint *keypart);
|
2004-08-27 15:37:13 +02:00
|
|
|
void key_copy(byte *to_key, byte *from_record, KEY *key_info, uint key_length);
|
|
|
|
void key_restore(byte *to_record, byte *from_key, KEY *key_info,
|
|
|
|
uint key_length);
|
2004-05-16 13:48:32 +02:00
|
|
|
bool key_cmp_if_same(TABLE *form,const byte *key,uint index,uint key_length);
|
2000-07-31 21:29:14 +02:00
|
|
|
void key_unpack(String *to,TABLE *form,uint index);
|
2006-09-21 11:39:29 +02:00
|
|
|
bool is_key_used(TABLE *table, uint idx, const MY_BITMAP *fields);
|
2004-05-16 13:48:32 +02:00
|
|
|
int key_cmp(KEY_PART_INFO *key_part, const byte *key, uint key_length);
|
2005-07-18 13:31:02 +02:00
|
|
|
int key_rec_cmp(void *key_info, byte *a, byte *b);
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2004-05-16 13:48:32 +02:00
|
|
|
bool init_errmessage(void);
|
2006-01-19 22:40:56 +01:00
|
|
|
#endif /* MYSQL_SERVER */
|
2000-07-31 21:29:14 +02:00
|
|
|
void sql_perror(const char *message);
|
2004-08-14 03:38:37 +02:00
|
|
|
|
2006-05-22 20:46:13 +02:00
|
|
|
|
2006-01-19 03:56:06 +01:00
|
|
|
int vprint_msg_to_log(enum loglevel level, const char *format, va_list args);
|
2006-08-17 21:25:40 +02:00
|
|
|
void sql_print_error(const char *format, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
|
|
|
|
void sql_print_warning(const char *format, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
|
|
|
|
void sql_print_information(const char *format, ...)
|
|
|
|
ATTRIBUTE_FORMAT(printf, 1, 2);
|
2006-09-29 05:20:33 +02:00
|
|
|
typedef void (*sql_print_message_func)(const char *format, ...)
|
|
|
|
ATTRIBUTE_FORMAT(printf, 1, 2);
|
2006-05-22 20:46:13 +02:00
|
|
|
extern sql_print_message_func sql_print_message_handlers[];
|
2004-08-14 03:38:37 +02:00
|
|
|
|
2006-01-19 03:56:06 +01:00
|
|
|
int error_log_print(enum loglevel level, const char *format,
|
|
|
|
va_list args);
|
|
|
|
|
|
|
|
bool slow_log_print(THD *thd, const char *query, uint query_length,
|
|
|
|
time_t query_start_arg);
|
|
|
|
|
|
|
|
bool general_log_print(THD *thd, enum enum_server_command command,
|
|
|
|
const char *format,...);
|
2004-08-14 03:38:37 +02:00
|
|
|
|
2001-10-08 03:58:07 +02:00
|
|
|
bool fn_format_relative_to_data_home(my_string to, const char *name,
|
|
|
|
const char *dir, const char *extension);
|
2006-01-19 22:40:56 +01:00
|
|
|
#ifdef MYSQL_SERVER
|
2005-01-16 13:16:23 +01:00
|
|
|
File open_binlog(IO_CACHE *log, const char *log_file_name,
|
|
|
|
const char **errmsg);
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2003-09-13 10:35:29 +02:00
|
|
|
/* mysqld.cc */
|
2006-03-10 01:44:08 +01:00
|
|
|
extern void MYSQLerror(const char*);
|
2006-04-07 13:30:40 +02:00
|
|
|
void refresh_status(THD *thd);
|
2007-01-10 09:57:03 +01:00
|
|
|
my_bool mysql_rm_tmp_tables(void);
|
2007-02-23 12:13:55 +01:00
|
|
|
void handle_connection_in_main_thread(THD *thd);
|
|
|
|
void create_thread_to_handle_connection(THD *thd);
|
|
|
|
void unlink_thd(THD *thd);
|
|
|
|
bool one_thread_per_connection_end(THD *thd, bool put_in_cache);
|
|
|
|
void flush_thread_cache();
|
2003-09-13 10:35:29 +02:00
|
|
|
|
2004-03-16 11:01:05 +01:00
|
|
|
/* item_func.cc */
|
|
|
|
extern bool check_reserved_words(LEX_STRING *name);
|
|
|
|
|
2003-11-03 13:01:59 +01:00
|
|
|
/* strfunc.cc */
|
2004-10-26 10:17:37 +02:00
|
|
|
ulonglong find_set(TYPELIB *lib, const char *x, uint length, CHARSET_INFO *cs,
|
2003-11-03 13:01:59 +01:00
|
|
|
char **err_pos, uint *err_len, bool *set_warning);
|
2007-03-27 18:27:58 +02:00
|
|
|
uint find_type(const TYPELIB *lib, const char *find, uint length,
|
|
|
|
bool part_match);
|
|
|
|
uint find_type2(const TYPELIB *lib, const char *find, uint length,
|
|
|
|
CHARSET_INFO *cs);
|
2004-12-21 14:12:27 +01:00
|
|
|
void unhex_type2(TYPELIB *lib);
|
2003-11-03 13:01:59 +01:00
|
|
|
uint check_word(TYPELIB *lib, const char *val, const char *end,
|
|
|
|
const char **end_of_word);
|
2006-10-10 17:59:46 +02:00
|
|
|
int find_string_in_array(LEX_STRING * const haystack, LEX_STRING * const needle,
|
2006-10-10 21:19:34 +02:00
|
|
|
CHARSET_INFO * const cs);
|
2003-11-03 13:01:59 +01:00
|
|
|
|
2004-02-06 21:57:22 +01:00
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
bool is_keyword(const char *name, uint len);
|
2003-12-30 11:08:19 +01:00
|
|
|
|
2004-01-30 07:32:35 +01:00
|
|
|
#define MY_DB_OPT_FILE "db.opt"
|
2006-02-13 08:49:28 +01:00
|
|
|
bool my_database_names_init(void);
|
|
|
|
void my_database_names_free(void);
|
2006-07-27 15:57:43 +02:00
|
|
|
bool check_db_dir_existence(const char *db_name);
|
2004-01-30 07:32:35 +01:00
|
|
|
bool load_db_opt(THD *thd, const char *path, HA_CREATE_INFO *create);
|
2006-07-27 15:57:43 +02:00
|
|
|
bool load_db_opt_by_name(THD *thd, const char *db_name,
|
|
|
|
HA_CREATE_INFO *db_create_info);
|
2004-07-09 09:55:16 +02:00
|
|
|
bool my_dbopt_init(void);
|
|
|
|
void my_dbopt_cleanup(void);
|
2006-02-13 08:49:28 +01:00
|
|
|
extern int creating_database; // How many database locks are made
|
|
|
|
extern int creating_table; // How many mysql_create_table() are running
|
2003-12-30 11:08:19 +01:00
|
|
|
|
2002-07-23 17:31:22 +02:00
|
|
|
/*
|
|
|
|
External variables
|
|
|
|
*/
|
|
|
|
|
2006-12-14 23:51:37 +01:00
|
|
|
extern time_t server_start_time;
|
2001-10-02 04:53:00 +02:00
|
|
|
extern char *mysql_data_home,server_version[SERVER_VERSION_LENGTH],
|
2004-02-16 18:53:00 +01:00
|
|
|
mysql_real_data_home[], *opt_mysql_tmpdir, mysql_charsets_dir[],
|
2004-04-07 20:58:33 +02:00
|
|
|
def_ft_boolean_syntax[sizeof(ft_boolean_syntax)];
|
2002-10-08 14:39:37 +02:00
|
|
|
#define mysql_tmpdir (my_tmpdir(&mysql_tmpdir_list))
|
|
|
|
extern MY_TMPDIR mysql_tmpdir_list;
|
2006-08-17 18:13:45 +02:00
|
|
|
extern const LEX_STRING command_name[];
|
2003-09-26 12:33:13 +02:00
|
|
|
extern const char *first_keyword, *my_localhost, *delayed_user, *binary_keyword;
|
2002-07-23 17:31:22 +02:00
|
|
|
extern const char **errmesg; /* Error messages */
|
|
|
|
extern const char *myisam_recover_options_str;
|
2007-01-12 21:22:41 +01:00
|
|
|
extern const char *in_left_expr_name, *in_additional_cond, *in_having_cond;
|
2005-03-27 14:15:21 +02:00
|
|
|
extern const char * const triggers_file_ext;
|
2005-07-19 18:06:49 +02:00
|
|
|
extern const char * const trigname_file_ext;
|
2003-11-03 11:28:36 +01:00
|
|
|
extern Eq_creator eq_creator;
|
|
|
|
extern Ne_creator ne_creator;
|
|
|
|
extern Gt_creator gt_creator;
|
|
|
|
extern Lt_creator lt_creator;
|
|
|
|
extern Ge_creator ge_creator;
|
|
|
|
extern Le_creator le_creator;
|
2005-01-21 14:51:24 +01:00
|
|
|
extern char language[FN_REFLEN], reg_ext[FN_EXTLEN];
|
2005-12-31 06:01:26 +01:00
|
|
|
extern uint reg_ext_length;
|
2002-07-23 17:31:22 +02:00
|
|
|
extern char glob_hostname[FN_REFLEN], mysql_home[FN_REFLEN];
|
2004-06-18 08:11:31 +02:00
|
|
|
extern char pidfile_name[FN_REFLEN], system_time_zone[30], *opt_init_file;
|
2005-03-12 20:09:54 +01:00
|
|
|
extern char log_error_file[FN_REFLEN], *opt_tc_log_file;
|
2002-07-23 17:31:22 +02:00
|
|
|
extern double log_10[32];
|
2007-01-31 06:51:05 +01:00
|
|
|
extern double log_01[32];
|
2004-03-15 15:28:21 +01:00
|
|
|
extern ulonglong log_10_int[20];
|
2002-12-05 15:38:49 +01:00
|
|
|
extern ulonglong keybuff_size;
|
2005-08-12 12:54:42 +02:00
|
|
|
extern ulonglong thd_startup_options;
|
2007-02-28 22:25:50 +01:00
|
|
|
extern ulong refresh_version, thread_id;
|
2004-04-01 22:47:20 +02:00
|
|
|
extern ulong binlog_cache_use, binlog_cache_disk_use;
|
2002-07-23 17:31:22 +02:00
|
|
|
extern ulong aborted_threads,aborted_connects;
|
|
|
|
extern ulong delayed_insert_timeout;
|
|
|
|
extern ulong delayed_insert_limit, delayed_queue_size;
|
|
|
|
extern ulong delayed_insert_threads, delayed_insert_writes;
|
|
|
|
extern ulong delayed_rows_in_use,delayed_insert_errors;
|
2003-03-02 20:39:03 +01:00
|
|
|
extern ulong slave_open_temp_tables;
|
|
|
|
extern ulong query_cache_size, query_cache_min_res_unit;
|
2005-08-12 12:54:42 +02:00
|
|
|
extern ulong slow_launch_threads, slow_launch_time;
|
2005-11-23 21:45:02 +01:00
|
|
|
extern ulong table_cache_size, table_def_size;
|
2002-07-23 17:31:22 +02:00
|
|
|
extern ulong max_connections,max_connect_errors, connect_timeout;
|
2005-03-02 11:29:48 +01:00
|
|
|
extern ulong slave_net_timeout, slave_trans_retries;
|
2005-01-19 22:54:01 +01:00
|
|
|
extern uint max_user_connections;
|
2004-09-13 15:48:01 +02:00
|
|
|
extern ulong what_to_log,flush_time;
|
2005-05-26 20:36:14 +02:00
|
|
|
extern ulong query_buff_size, thread_stack;
|
2006-04-07 21:37:06 +02:00
|
|
|
extern ulong max_prepared_stmt_count, prepared_stmt_count;
|
2002-07-23 17:31:22 +02:00
|
|
|
extern ulong binlog_cache_size, max_binlog_cache_size, open_files_limit;
|
2003-07-06 17:59:54 +02:00
|
|
|
extern ulong max_binlog_size, max_relay_log_size;
|
2005-12-22 06:39:02 +01:00
|
|
|
extern ulong opt_binlog_rows_event_max_size;
|
2007-02-23 12:13:55 +01:00
|
|
|
extern ulong rpl_recovery_rank, thread_cache_size, thread_pool_size;
|
2004-09-13 15:48:01 +02:00
|
|
|
extern ulong back_log;
|
2002-07-23 17:31:22 +02:00
|
|
|
extern ulong specialflag, current_pid;
|
2004-06-10 15:56:13 +02:00
|
|
|
extern ulong expire_logs_days, sync_binlog_period, sync_binlog_counter;
|
2005-06-07 10:30:09 +02:00
|
|
|
extern ulong opt_tc_log_size, tc_log_max_pages_used, tc_log_page_size;
|
|
|
|
extern ulong tc_log_page_waits;
|
2004-11-18 11:00:42 +01:00
|
|
|
extern my_bool relay_log_purge, opt_innodb_safe_binlog, opt_innodb;
|
2002-07-23 17:31:22 +02:00
|
|
|
extern uint test_flags,select_errors,ha_open_options;
|
2003-06-14 10:37:42 +02:00
|
|
|
extern uint protocol_version, mysqld_port, dropping_tables;
|
2003-12-30 12:14:21 +01:00
|
|
|
extern uint delay_key_write_options, lower_case_table_names;
|
2005-10-04 18:52:12 +02:00
|
|
|
extern bool opt_endinfo, using_udf_functions;
|
|
|
|
extern my_bool locked_in_memory;
|
2004-10-20 00:28:42 +02:00
|
|
|
extern bool opt_using_transactions, mysqld_embedded;
|
2004-05-19 15:03:32 +02:00
|
|
|
extern bool using_update_log, opt_large_files, server_id_supplied;
|
2006-06-19 15:30:55 +02:00
|
|
|
extern bool opt_update_log, opt_bin_log, opt_error_log;
|
|
|
|
extern my_bool opt_log, opt_slow_log;
|
2006-06-23 01:49:19 +02:00
|
|
|
extern ulong log_output_options;
|
Bug #1039: tmpdir and datadir not available via @@ system variable syntax
Bug #19606: ssl variables are not displayed in show variables
Bug #19616: log_queries_not_using_indexes is not listed in show variables
Make basedir, datadir, tmpdir, log_queries_not_using_indexes, ssl_ca,
ssl_capath, ssl_cert, ssl_cipher, and ssl_key all available both from
SHOW VARIABLES and as @@variables.
As a side-effect of this change, log_queries_not_using_indexes can
be changed at runtime (but only globally, not per-connection).
2006-05-09 01:38:45 +02:00
|
|
|
extern my_bool opt_log_queries_not_using_indexes;
|
2002-08-22 15:50:58 +02:00
|
|
|
extern bool opt_disable_networking, opt_skip_show_db;
|
2005-10-04 18:52:12 +02:00
|
|
|
extern my_bool opt_character_set_client_handshake;
|
2002-07-23 17:31:22 +02:00
|
|
|
extern bool volatile abort_loop, shutdown_in_progress, grant_option;
|
|
|
|
extern uint volatile thread_count, thread_running, global_read_lock;
|
2002-08-22 15:50:58 +02:00
|
|
|
extern my_bool opt_sql_bin_update, opt_safe_user_create, opt_no_mix_types;
|
2005-12-01 13:34:48 +01:00
|
|
|
extern my_bool opt_safe_show_db, opt_local_infile, opt_myisam_use_mmap;
|
2002-08-22 15:50:58 +02:00
|
|
|
extern my_bool opt_slave_compressed_protocol, use_temp_pool;
|
2004-03-06 09:43:35 +01:00
|
|
|
extern my_bool opt_readonly, lower_case_file_system;
|
2005-03-03 19:51:29 +01:00
|
|
|
extern my_bool opt_enable_named_pipe, opt_sync_frm, opt_allow_suspicious_udfs;
|
2003-07-08 00:36:14 +02:00
|
|
|
extern my_bool opt_secure_auth;
|
2007-02-14 14:44:34 +01:00
|
|
|
extern char* opt_secure_file_priv;
|
2005-06-16 23:58:36 +02:00
|
|
|
extern my_bool opt_log_slow_admin_statements;
|
2005-05-26 16:44:46 +02:00
|
|
|
extern my_bool sp_automatic_privileges, opt_noacl;
|
2005-11-10 17:50:51 +01:00
|
|
|
extern my_bool opt_old_style_user_limits, trust_function_creators;
|
2004-06-20 19:11:02 +02:00
|
|
|
extern uint opt_crash_binlog_innodb;
|
2003-06-14 10:37:42 +02:00
|
|
|
extern char *shared_memory_base_name, *mysqld_unix_port;
|
2005-10-06 03:49:14 +02:00
|
|
|
extern my_bool opt_enable_shared_memory;
|
2004-06-18 08:11:31 +02:00
|
|
|
extern char *default_tz_name;
|
2004-12-14 20:26:31 +01:00
|
|
|
extern my_bool opt_large_pages;
|
|
|
|
extern uint opt_large_page_size;
|
2006-06-19 15:30:55 +02:00
|
|
|
extern char *opt_logname, *opt_slow_logname;
|
|
|
|
extern const char *log_output_str;
|
2002-07-23 17:31:22 +02:00
|
|
|
|
2006-05-05 08:45:58 +02:00
|
|
|
extern MYSQL_BIN_LOG mysql_bin_log;
|
2006-01-19 03:56:06 +01:00
|
|
|
extern LOGGER logger;
|
|
|
|
extern TABLE_LIST general_log, slow_log;
|
2000-11-28 03:47:47 +01:00
|
|
|
extern FILE *bootstrap_file;
|
2005-01-16 13:16:23 +01:00
|
|
|
extern int bootstrap_error;
|
2005-08-04 12:23:21 +02:00
|
|
|
extern FILE *stderror_file;
|
2004-11-08 00:13:54 +01:00
|
|
|
extern pthread_key(MEM_ROOT**,THR_MALLOC);
|
2006-02-13 08:49:28 +01:00
|
|
|
extern pthread_mutex_t LOCK_mysql_create_db,LOCK_Acl,LOCK_open, LOCK_lock_db,
|
2000-07-31 21:29:14 +02:00
|
|
|
LOCK_thread_count,LOCK_mapped_file,LOCK_user_locks, LOCK_status,
|
2004-02-27 20:30:08 +01:00
|
|
|
LOCK_error_log, LOCK_delayed_insert, LOCK_uuid_generator,
|
2000-07-31 21:29:14 +02:00
|
|
|
LOCK_delayed_status, LOCK_delayed_create, LOCK_crypt, LOCK_timezone,
|
2005-03-16 08:40:19 +01:00
|
|
|
LOCK_slave_list, LOCK_active_mi, LOCK_manager, LOCK_global_read_lock,
|
2005-07-19 20:05:49 +02:00
|
|
|
LOCK_global_system_variables, LOCK_user_conn,
|
2006-04-12 16:30:54 +02:00
|
|
|
LOCK_prepared_stmt_count,
|
2005-05-18 18:00:21 +02:00
|
|
|
LOCK_bytes_sent, LOCK_bytes_received;
|
2005-07-19 18:25:05 +02:00
|
|
|
#ifdef HAVE_OPENSSL
|
|
|
|
extern pthread_mutex_t LOCK_des_key_file;
|
|
|
|
#endif
|
2005-11-06 00:20:37 +01:00
|
|
|
extern pthread_mutex_t LOCK_server_started;
|
|
|
|
extern pthread_cond_t COND_server_started;
|
|
|
|
extern int mysqld_server_started;
|
2003-07-18 11:11:01 +02:00
|
|
|
extern rw_lock_t LOCK_grant, LOCK_sys_init_connect, LOCK_sys_init_slave;
|
2007-03-02 17:43:45 +01:00
|
|
|
extern rw_lock_t LOCK_system_variables_hash;
|
2002-06-28 18:30:09 +02:00
|
|
|
extern pthread_cond_t COND_refresh, COND_thread_count, COND_manager;
|
2006-05-24 16:21:35 +02:00
|
|
|
extern pthread_cond_t COND_global_read_lock;
|
2000-07-31 21:29:14 +02:00
|
|
|
extern pthread_attr_t connection_attrib;
|
2002-07-23 17:31:22 +02:00
|
|
|
extern I_List<THD> threads;
|
2003-07-06 18:09:57 +02:00
|
|
|
extern I_List<NAMED_LIST> key_caches;
|
2001-02-07 22:27:19 +01:00
|
|
|
extern MY_BITMAP temp_pool;
|
2003-09-18 15:58:02 +02:00
|
|
|
extern String my_empty_string;
|
2003-12-20 00:16:10 +01:00
|
|
|
extern const String my_null_string;
|
2007-03-02 17:43:45 +01:00
|
|
|
extern SHOW_VAR status_vars[];
|
2002-06-28 18:30:09 +02:00
|
|
|
extern struct system_variables global_system_variables;
|
2002-07-23 17:31:22 +02:00
|
|
|
extern struct system_variables max_system_variables;
|
2004-09-13 15:48:01 +02:00
|
|
|
extern struct system_status_var global_status_var;
|
2002-12-05 02:40:33 +01:00
|
|
|
extern struct rand_struct sql_rand;
|
2002-07-23 17:31:22 +02:00
|
|
|
|
2003-11-03 13:01:59 +01:00
|
|
|
extern const char *opt_date_time_formats[];
|
|
|
|
extern KNOWN_DATE_TIME_FORMAT known_date_time_formats[];
|
2003-10-20 10:24:18 +02:00
|
|
|
|
2003-09-29 21:06:31 +02:00
|
|
|
extern String null_string;
|
2006-02-13 08:49:28 +01:00
|
|
|
extern HASH open_cache, lock_db_cache;
|
2003-09-13 10:35:29 +02:00
|
|
|
extern TABLE *unused_tables;
|
|
|
|
extern const char* any_db;
|
|
|
|
extern struct my_option my_long_options[];
|
2005-07-31 11:49:55 +02:00
|
|
|
extern const LEX_STRING view_type;
|
2007-02-23 12:13:55 +01:00
|
|
|
extern scheduler_functions thread_scheduler;
|
|
|
|
extern TYPELIB thread_handling_typelib;
|
|
|
|
extern uint8 uc_update_queries[SQLCOM_END+1];
|
2006-06-20 12:20:32 +02:00
|
|
|
extern uint sql_command_flags[];
|
2006-06-19 15:30:55 +02:00
|
|
|
extern TYPELIB log_output_typelib;
|
2002-07-23 17:31:22 +02:00
|
|
|
|
2002-07-25 07:12:42 +02:00
|
|
|
/* optional things, have_* variables */
|
|
|
|
|
2006-09-15 19:28:00 +02:00
|
|
|
extern handlerton *partition_hton;
|
|
|
|
extern handlerton *myisam_hton;
|
|
|
|
extern handlerton *heap_hton;
|
2005-12-21 19:18:40 +01:00
|
|
|
|
2007-03-05 10:30:05 +01:00
|
|
|
extern SHOW_COMP_OPTION have_ssl, have_symlink, have_dlopen;
|
2005-04-05 13:17:49 +02:00
|
|
|
extern SHOW_COMP_OPTION have_query_cache;
|
2004-05-27 17:31:30 +02:00
|
|
|
extern SHOW_COMP_OPTION have_geometry, have_rtree_keys;
|
2003-01-28 07:38:28 +01:00
|
|
|
extern SHOW_COMP_OPTION have_crypt;
|
2003-04-10 02:50:30 +02:00
|
|
|
extern SHOW_COMP_OPTION have_compress;
|
2002-08-08 02:12:02 +02:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
#ifndef __WIN__
|
|
|
|
extern pthread_t signal_thread;
|
|
|
|
#endif
|
|
|
|
|
2002-09-16 14:55:19 +02:00
|
|
|
#ifdef HAVE_OPENSSL
|
2006-03-10 16:41:14 +01:00
|
|
|
extern struct st_VioSSLFd * ssl_acceptor_fd;
|
2002-09-16 14:55:19 +02:00
|
|
|
#endif /* HAVE_OPENSSL */
|
|
|
|
|
2005-09-15 01:56:09 +02:00
|
|
|
MYSQL_LOCK *mysql_lock_tables(THD *thd, TABLE **table, uint count,
|
|
|
|
uint flags, bool *need_reopen);
|
2006-05-09 14:39:11 +02:00
|
|
|
/* mysql_lock_tables() and open_table() flags bits */
|
2005-05-31 11:08:14 +02:00
|
|
|
#define MYSQL_LOCK_IGNORE_GLOBAL_READ_LOCK 0x0001
|
|
|
|
#define MYSQL_LOCK_IGNORE_FLUSH 0x0002
|
2005-09-15 01:56:09 +02:00
|
|
|
#define MYSQL_LOCK_NOTIFY_IF_NEED_REOPEN 0x0004
|
2006-05-09 14:39:11 +02:00
|
|
|
#define MYSQL_OPEN_IGNORE_LOCKED_TABLES 0x0008
|
2005-05-31 11:08:14 +02:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
void mysql_unlock_tables(THD *thd, MYSQL_LOCK *sql_lock);
|
|
|
|
void mysql_unlock_read_tables(THD *thd, MYSQL_LOCK *sql_lock);
|
|
|
|
void mysql_unlock_some_tables(THD *thd, TABLE **table,uint count);
|
|
|
|
void mysql_lock_remove(THD *thd, MYSQL_LOCK *locked,TABLE *table);
|
2006-01-17 08:40:00 +01:00
|
|
|
void mysql_lock_abort(THD *thd, TABLE *table, bool upgrade_lock);
|
|
|
|
void mysql_lock_downgrade_write(THD *thd, TABLE *table,
|
|
|
|
thr_lock_type new_lock_type);
|
2005-07-19 00:29:19 +02:00
|
|
|
bool mysql_lock_abort_for_thread(THD *thd, TABLE *table);
|
2000-07-31 21:29:14 +02:00
|
|
|
MYSQL_LOCK *mysql_lock_merge(MYSQL_LOCK *a,MYSQL_LOCK *b);
|
2005-12-22 13:48:00 +01:00
|
|
|
TABLE_LIST *mysql_lock_have_duplicate(THD *thd, TABLE_LIST *needle,
|
|
|
|
TABLE_LIST *haystack);
|
2001-08-14 19:33:49 +02:00
|
|
|
bool lock_global_read_lock(THD *thd);
|
|
|
|
void unlock_global_read_lock(THD *thd);
|
2004-09-09 05:59:26 +02:00
|
|
|
bool wait_if_global_read_lock(THD *thd, bool abort_on_refresh,
|
|
|
|
bool is_not_commit);
|
2001-08-14 19:33:49 +02:00
|
|
|
void start_waiting_global_read_lock(THD *thd);
|
2004-12-02 23:02:38 +01:00
|
|
|
bool make_global_read_lock_block_commit(THD *thd);
|
2005-04-27 22:58:11 +02:00
|
|
|
bool set_protect_against_global_read_lock(void);
|
|
|
|
void unset_protect_against_global_read_lock(void);
|
2006-06-26 19:14:35 +02:00
|
|
|
void broadcast_refresh(void);
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2000-08-21 02:07:54 +02:00
|
|
|
/* Lock based on name */
|
2001-09-02 12:47:00 +02:00
|
|
|
int lock_and_wait_for_table_name(THD *thd, TABLE_LIST *table_list);
|
2006-05-27 00:44:52 +02:00
|
|
|
int lock_table_name(THD *thd, TABLE_LIST *table_list, bool check_in_use);
|
2000-08-21 02:07:54 +02:00
|
|
|
void unlock_table_name(THD *thd, TABLE_LIST *table_list);
|
|
|
|
bool wait_for_locked_table_names(THD *thd, TABLE_LIST *table_list);
|
2003-03-03 19:42:49 +01:00
|
|
|
bool lock_table_names(THD *thd, TABLE_LIST *table_list);
|
|
|
|
void unlock_table_names(THD *thd, TABLE_LIST *table_list,
|
2005-03-16 15:11:01 +01:00
|
|
|
TABLE_LIST *last_table);
|
2000-08-21 02:07:54 +02:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
/* old unireg functions */
|
|
|
|
|
|
|
|
void unireg_init(ulong options);
|
2006-11-30 22:23:23 +01:00
|
|
|
void unireg_end(void) __attribute__((noreturn));
|
2005-11-23 21:45:02 +01:00
|
|
|
bool mysql_create_frm(THD *thd, const char *file_name,
|
2005-07-27 12:05:30 +02:00
|
|
|
const char *db, const char *table,
|
2004-04-08 16:56:45 +02:00
|
|
|
HA_CREATE_INFO *create_info,
|
|
|
|
List<create_field> &create_field,
|
|
|
|
uint key_count,KEY *key_info,handler *db_type);
|
2005-11-23 21:45:02 +01:00
|
|
|
int rea_create_table(THD *thd, const char *path,
|
|
|
|
const char *db, const char *table_name,
|
2005-07-22 05:08:54 +02:00
|
|
|
HA_CREATE_INFO *create_info,
|
2005-11-23 21:45:02 +01:00
|
|
|
List<create_field> &create_field,
|
|
|
|
uint key_count,KEY *key_info,
|
|
|
|
handler *file);
|
2000-07-31 21:29:14 +02:00
|
|
|
int format_number(uint inputflag,uint max_length,my_string pos,uint length,
|
|
|
|
my_string *errpos);
|
2005-11-23 21:45:02 +01:00
|
|
|
|
|
|
|
/* table.cc */
|
2005-11-29 09:07:21 +01:00
|
|
|
TABLE_SHARE *alloc_table_share(TABLE_LIST *table_list, char *key,
|
2005-11-23 21:45:02 +01:00
|
|
|
uint key_length);
|
|
|
|
void init_tmp_table_share(TABLE_SHARE *share, const char *key, uint key_length,
|
|
|
|
const char *table_name, const char *path);
|
|
|
|
void free_table_share(TABLE_SHARE *share);
|
|
|
|
int open_table_def(THD *thd, TABLE_SHARE *share, uint db_flags);
|
|
|
|
void open_table_error(TABLE_SHARE *share, int error, int db_errno, int errarg);
|
|
|
|
int open_table_from_share(THD *thd, TABLE_SHARE *share, const char *alias,
|
|
|
|
uint db_stat, uint prgflag, uint ha_open_flags,
|
2006-01-17 08:40:00 +01:00
|
|
|
TABLE *outparam, bool is_create_table);
|
2004-04-15 09:14:14 +02:00
|
|
|
int readfrm(const char *name, const void** data, uint* length);
|
|
|
|
int writefrm(const char* name, const void* data, uint len);
|
2005-11-23 21:45:02 +01:00
|
|
|
int closefrm(TABLE *table, bool free_share);
|
2000-07-31 21:29:14 +02:00
|
|
|
int read_string(File file, gptr *to, uint length);
|
|
|
|
void free_blobs(TABLE *table);
|
|
|
|
int set_zone(int nr,int min_zone,int max_zone);
|
|
|
|
ulong convert_period_to_month(ulong period);
|
|
|
|
ulong convert_month_to_period(ulong month);
|
|
|
|
void get_date_from_daynr(long daynr,uint *year, uint *month,
|
|
|
|
uint *day);
|
2007-03-23 21:08:31 +01:00
|
|
|
my_time_t TIME_to_timestamp(THD *thd, const MYSQL_TIME *t, my_bool *not_exist);
|
|
|
|
bool str_to_time_with_warn(const char *str,uint length,MYSQL_TIME *l_time);
|
2004-06-24 17:08:36 +02:00
|
|
|
timestamp_type str_to_datetime_with_warn(const char *str, uint length,
|
2007-03-23 21:08:31 +01:00
|
|
|
MYSQL_TIME *l_time, uint flags);
|
|
|
|
void localtime_to_TIME(MYSQL_TIME *to, struct tm *from);
|
|
|
|
void calc_time_from_sec(MYSQL_TIME *to, long seconds, long microseconds);
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2007-03-23 21:08:31 +01:00
|
|
|
void make_truncated_value_warning(THD *thd, MYSQL_ERROR::enum_warning_level level,
|
|
|
|
const char *str_val,
|
2004-09-28 19:08:00 +02:00
|
|
|
uint str_length, timestamp_type time_type,
|
|
|
|
const char *field_name);
|
2006-01-18 20:41:22 +01:00
|
|
|
|
2007-03-23 21:08:31 +01:00
|
|
|
bool date_add_interval(MYSQL_TIME *ltime, interval_type int_type, INTERVAL interval);
|
|
|
|
bool calc_time_diff(MYSQL_TIME *l_time1, MYSQL_TIME *l_time2, int l_sign,
|
2006-04-07 09:08:58 +02:00
|
|
|
longlong *seconds_out, long *microseconds_out);
|
2006-01-18 20:41:22 +01:00
|
|
|
|
2006-06-08 23:07:11 +02:00
|
|
|
extern LEX_STRING interval_type_to_name[];
|
|
|
|
|
2003-11-03 13:01:59 +01:00
|
|
|
extern DATE_TIME_FORMAT *date_time_format_make(timestamp_type format_type,
|
|
|
|
const char *format_str,
|
|
|
|
uint format_length);
|
|
|
|
extern DATE_TIME_FORMAT *date_time_format_copy(THD *thd,
|
|
|
|
DATE_TIME_FORMAT *format);
|
|
|
|
const char *get_date_time_format_str(KNOWN_DATE_TIME_FORMAT *format,
|
|
|
|
timestamp_type type);
|
2007-03-23 21:08:31 +01:00
|
|
|
extern bool make_date_time(DATE_TIME_FORMAT *format, MYSQL_TIME *l_time,
|
2003-11-03 13:01:59 +01:00
|
|
|
timestamp_type type, String *str);
|
2007-03-23 21:08:31 +01:00
|
|
|
void make_datetime(const DATE_TIME_FORMAT *format, const MYSQL_TIME *l_time,
|
2004-05-25 00:03:49 +02:00
|
|
|
String *str);
|
2007-03-23 21:08:31 +01:00
|
|
|
void make_date(const DATE_TIME_FORMAT *format, const MYSQL_TIME *l_time,
|
2004-05-25 00:03:49 +02:00
|
|
|
String *str);
|
2007-03-23 21:08:31 +01:00
|
|
|
void make_time(const DATE_TIME_FORMAT *format, const MYSQL_TIME *l_time,
|
2004-05-25 00:03:49 +02:00
|
|
|
String *str);
|
2007-03-23 21:08:31 +01:00
|
|
|
int my_time_compare(MYSQL_TIME *a, MYSQL_TIME *b);
|
2003-10-20 10:24:18 +02:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
int test_if_number(char *str,int *res,bool allow_wildcards);
|
|
|
|
void change_byte(byte *,uint,char,char);
|
|
|
|
void init_read_record(READ_RECORD *info, THD *thd, TABLE *reg_form,
|
|
|
|
SQL_SELECT *select,
|
2001-03-11 22:09:09 +01:00
|
|
|
int use_record_cache, bool print_errors);
|
2005-09-30 13:21:37 +02:00
|
|
|
void init_read_record_idx(READ_RECORD *info, THD *thd, TABLE *table,
|
|
|
|
bool print_error, uint idx);
|
2000-07-31 21:29:14 +02:00
|
|
|
void end_read_record(READ_RECORD *info);
|
2002-10-16 16:21:47 +02:00
|
|
|
ha_rows filesort(THD *thd, TABLE *form,struct st_sort_field *sortorder,
|
|
|
|
uint s_length, SQL_SELECT *select,
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
ha_rows max_rows, bool sort_positions,
|
|
|
|
ha_rows *examined_rows);
|
2006-11-01 02:31:56 +01:00
|
|
|
void filesort_free_buffers(TABLE *table, bool full);
|
2000-07-31 21:29:14 +02:00
|
|
|
void change_double_for_sort(double nr,byte *to);
|
2005-05-19 22:04:08 +02:00
|
|
|
double my_double_round(double value, int dec, bool truncate);
|
2000-07-31 21:29:14 +02:00
|
|
|
int get_quick_record(SQL_SELECT *select);
|
2006-06-08 23:07:11 +02:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
int calc_weekday(long daynr,bool sunday_first_day_of_week);
|
2007-03-23 21:08:31 +01:00
|
|
|
uint calc_week(MYSQL_TIME *l_time, uint week_behaviour, uint *year);
|
2000-07-31 21:29:14 +02:00
|
|
|
void find_date(char *pos,uint *vek,uint flag);
|
|
|
|
TYPELIB *convert_strings_to_array_type(my_string *typelibs, my_string *end);
|
2005-11-25 11:25:31 +01:00
|
|
|
TYPELIB *typelib(MEM_ROOT *mem_root, List<String> &strings);
|
2000-07-31 21:29:14 +02:00
|
|
|
ulong get_form_pos(File file, uchar *head, TYPELIB *save_names);
|
|
|
|
ulong make_new_entry(File file,uchar *fileinfo,TYPELIB *formnames,
|
|
|
|
const char *newname);
|
|
|
|
ulong next_io_size(ulong pos);
|
2002-06-02 20:22:20 +02:00
|
|
|
void append_unescaped(String *res, const char *pos, uint length);
|
2005-11-23 21:45:02 +01:00
|
|
|
int create_frm(THD *thd, const char *name, const char *db, const char *table,
|
|
|
|
uint reclength, uchar *fileinfo,
|
2000-07-31 21:29:14 +02:00
|
|
|
HA_CREATE_INFO *create_info, uint keys);
|
|
|
|
void update_create_info_from_table(HA_CREATE_INFO *info, TABLE *form);
|
|
|
|
int rename_file_ext(const char * from,const char * to,const char * ext);
|
2006-10-16 18:57:33 +02:00
|
|
|
bool check_db_name(LEX_STRING *db);
|
2000-07-31 21:29:14 +02:00
|
|
|
bool check_column_name(const char *name);
|
|
|
|
bool check_table_name(const char *name, uint length);
|
2003-02-12 20:55:37 +01:00
|
|
|
char *get_field(MEM_ROOT *mem, Field *field);
|
2003-05-29 23:47:31 +02:00
|
|
|
bool get_field(MEM_ROOT *mem, Field *field, class String *res);
|
2002-03-12 18:37:58 +01:00
|
|
|
int wild_case_compare(CHARSET_INFO *cs, const char *str,const char *wildstr);
|
2005-12-31 06:01:26 +01:00
|
|
|
char *fn_rext(char *name);
|
|
|
|
|
|
|
|
/* Conversion functions */
|
|
|
|
uint strconvert(CHARSET_INFO *from_cs, const char *from,
|
2005-12-31 09:34:39 +01:00
|
|
|
CHARSET_INFO *to_cs, char *to, uint to_length, uint *errors);
|
|
|
|
uint filename_to_tablename(const char *from, char *to, uint to_length);
|
|
|
|
uint tablename_to_filename(const char *from, char *to, uint to_length);
|
2005-12-31 06:01:26 +01:00
|
|
|
uint build_table_filename(char *buff, size_t bufflen, const char *db,
|
2006-08-02 17:57:06 +02:00
|
|
|
const char *table, const char *ext, uint flags);
|
|
|
|
/* Flags for conversion functions. */
|
|
|
|
#define FN_FROM_IS_TMP (1 << 0)
|
|
|
|
#define FN_TO_IS_TMP (1 << 1)
|
|
|
|
#define FN_IS_TMP (FN_FROM_IS_TMP | FN_TO_IS_TMP)
|
2006-12-04 18:22:38 +01:00
|
|
|
#define NO_FRM_RENAME (1 << 2)
|
2006-08-02 17:57:06 +02:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
/* from hostname.cc */
|
|
|
|
struct in_addr;
|
|
|
|
my_string ip_to_hostname(struct in_addr *in,uint *errors);
|
|
|
|
void inc_host_errors(struct in_addr *in);
|
|
|
|
void reset_host_errors(struct in_addr *in);
|
|
|
|
bool hostname_cache_init();
|
|
|
|
void hostname_cache_free();
|
|
|
|
void hostname_cache_refresh(void);
|
2004-04-28 16:45:08 +02:00
|
|
|
|
2002-07-23 17:31:22 +02:00
|
|
|
/* sql_cache.cc */
|
2000-07-31 21:29:14 +02:00
|
|
|
extern bool sql_cache_init();
|
|
|
|
extern void sql_cache_free();
|
|
|
|
extern int sql_cache_hit(THD *thd, char *inBuf, uint length);
|
|
|
|
|
2005-07-16 01:29:13 +02:00
|
|
|
/* item_func.cc */
|
2003-07-06 18:09:57 +02:00
|
|
|
Item *get_system_var(THD *thd, enum_var_type var_type, LEX_STRING name,
|
|
|
|
LEX_STRING component);
|
Implement WL#2661 "Prepared Statements: Dynamic SQL in Stored Procedures".
The idea of the patch is to separate statement processing logic,
such as parsing, validation of the parsed tree, execution and cleanup,
from global query processing logic, such as logging, resetting
priorities of a thread, resetting stored procedure cache, resetting
thread count of errors and warnings.
This makes PREPARE and EXECUTE behave similarly to the rest of SQL
statements and allows their use in stored procedures.
This patch contains a change in behaviour:
until recently for each SQL prepared statement command, 2 queries
were written to the general log, e.g.
[Query] prepare stmt from @stmt_text;
[Prepare] select * from t1 <-- contents of @stmt_text
The chagne was necessary to prevent [Prepare] commands from being written
to the general log when executing a stored procedure with Dynamic SQL.
We should consider whether the old behavior is preferrable and probably
restore it.
This patch refixes Bug#7115, Bug#10975 (partially), Bug#10605 (various bugs
in Dynamic SQL reported before it was disabled).
2005-09-03 01:13:18 +02:00
|
|
|
int get_var_with_binlog(THD *thd, enum_sql_command sql_command,
|
|
|
|
LEX_STRING &name, user_var_entry **out_entry);
|
2003-01-27 18:37:25 +01:00
|
|
|
/* log.cc */
|
|
|
|
bool flush_error_log(void);
|
2002-07-23 17:31:22 +02:00
|
|
|
|
2003-06-10 20:42:29 +02:00
|
|
|
/* sql_list.cc */
|
|
|
|
void free_list(I_List <i_string_pair> *list);
|
|
|
|
void free_list(I_List <i_string> *list);
|
|
|
|
|
2003-09-13 10:35:29 +02:00
|
|
|
/* sql_yacc.cc */
|
2006-03-10 01:44:08 +01:00
|
|
|
extern int MYSQLparse(void *thd);
|
2006-08-19 04:16:07 +02:00
|
|
|
#ifndef DBUG_OFF
|
|
|
|
extern void turn_parser_debug_on();
|
|
|
|
#endif
|
2003-09-13 10:35:29 +02:00
|
|
|
|
|
|
|
/* frm_crypt.cc */
|
|
|
|
#ifdef HAVE_CRYPTED_FRM
|
|
|
|
SQL_CRYPT *get_crypt_for_frm(void);
|
|
|
|
#endif
|
|
|
|
|
2004-07-16 00:15:55 +02:00
|
|
|
#include "sql_view.h"
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
/* Some inline functions for more speed */
|
|
|
|
|
2002-12-06 20:11:27 +01:00
|
|
|
inline bool add_item_to_list(THD *thd, Item *item)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2003-05-05 20:54:37 +02:00
|
|
|
return thd->lex->current_select->add_item_to_list(thd, item);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2002-12-06 20:11:27 +01:00
|
|
|
|
|
|
|
inline bool add_value_to_list(THD *thd, Item *value)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2003-05-05 20:54:37 +02:00
|
|
|
return thd->lex->value_list.push_back(value);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2002-12-06 20:11:27 +01:00
|
|
|
|
|
|
|
inline bool add_order_to_list(THD *thd, Item *item, bool asc)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2003-05-05 20:54:37 +02:00
|
|
|
return thd->lex->current_select->add_order_to_list(thd, item, asc);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2002-12-06 20:11:27 +01:00
|
|
|
|
|
|
|
inline bool add_group_to_list(THD *thd, Item *item, bool asc)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2003-05-05 20:54:37 +02:00
|
|
|
return thd->lex->current_select->add_group_to_list(thd, item, asc);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2002-12-06 20:11:27 +01:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
inline void mark_as_null_row(TABLE *table)
|
|
|
|
{
|
|
|
|
table->null_row=1;
|
2000-11-20 01:57:02 +01:00
|
|
|
table->status|=STATUS_NULL_ROW;
|
2005-01-06 12:00:13 +01:00
|
|
|
bfill(table->null_flags,table->s->null_bytes,255);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2002-11-07 22:45:19 +01:00
|
|
|
|
2003-07-23 16:36:56 +02:00
|
|
|
inline void table_case_convert(char * name, uint length)
|
|
|
|
{
|
|
|
|
if (lower_case_table_names)
|
2005-06-06 13:54:15 +02:00
|
|
|
files_charset_info->cset->casedn(files_charset_info,
|
|
|
|
name, length, name, length);
|
2003-08-29 12:44:35 +02:00
|
|
|
}
|
|
|
|
|
2003-12-30 12:14:21 +01:00
|
|
|
inline const char *table_case_name(HA_CREATE_INFO *info, const char *name)
|
|
|
|
{
|
|
|
|
return ((lower_case_table_names == 2 && info->alias) ? info->alias : name);
|
|
|
|
}
|
2004-02-11 00:06:46 +01:00
|
|
|
|
2004-02-27 20:30:08 +01:00
|
|
|
inline ulong sql_rnd_with_mutex()
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&LOCK_thread_count);
|
|
|
|
ulong tmp=(ulong) (my_rnd(&sql_rand) * 0xffffffff); /* make all bits random */
|
|
|
|
pthread_mutex_unlock(&LOCK_thread_count);
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2003-11-03 11:28:36 +01:00
|
|
|
Comp_creator *comp_eq_creator(bool invert);
|
|
|
|
Comp_creator *comp_ge_creator(bool invert);
|
|
|
|
Comp_creator *comp_gt_creator(bool invert);
|
|
|
|
Comp_creator *comp_le_creator(bool invert);
|
|
|
|
Comp_creator *comp_lt_creator(bool invert);
|
|
|
|
Comp_creator *comp_ne_creator(bool invert);
|
2002-11-07 22:45:19 +01:00
|
|
|
|
2003-10-08 16:40:54 +02:00
|
|
|
Item * all_any_subquery_creator(Item *left_expr,
|
|
|
|
chooser_compare_func_creator cmp,
|
|
|
|
bool all,
|
|
|
|
SELECT_LEX *select_lex);
|
|
|
|
|
2003-07-02 00:45:22 +02:00
|
|
|
/*
|
|
|
|
clean/setup table fields and map
|
|
|
|
|
|
|
|
SYNOPSYS
|
|
|
|
setup_table_map()
|
|
|
|
table - TABLE structure pointer (which should be setup)
|
|
|
|
table_list TABLE_LIST structure pointer (owner of TABLE)
|
|
|
|
tablenr - table number
|
|
|
|
*/
|
2003-08-29 12:44:35 +02:00
|
|
|
|
2003-07-02 00:45:22 +02:00
|
|
|
inline void setup_table_map(TABLE *table, TABLE_LIST *table_list, uint tablenr)
|
|
|
|
{
|
|
|
|
table->used_fields= 0;
|
|
|
|
table->const_table= 0;
|
2003-08-20 16:35:12 +02:00
|
|
|
table->null_row= 0;
|
2003-07-02 00:45:22 +02:00
|
|
|
table->status= STATUS_NO_RECORD;
|
2005-02-05 16:16:29 +01:00
|
|
|
table->maybe_null= table_list->outer_join;
|
2005-08-06 01:43:35 +02:00
|
|
|
TABLE_LIST *embedding= table_list->embedding;
|
|
|
|
while (!table->maybe_null && embedding)
|
|
|
|
{
|
|
|
|
table->maybe_null= embedding->outer_join;
|
|
|
|
embedding= embedding->embedding;
|
|
|
|
}
|
2003-07-02 00:45:22 +02:00
|
|
|
table->tablenr= tablenr;
|
|
|
|
table->map= (table_map) 1 << tablenr;
|
|
|
|
table->force_index= table_list->force_index;
|
2007-03-05 18:08:41 +01:00
|
|
|
table->covering_keys= table->s->keys_for_keyread;
|
|
|
|
table->merge_keys.clear_all();
|
2003-07-02 00:45:22 +02:00
|
|
|
}
|
This will be pushed only after I fix the testsuite.
This is the main commit for Worklog tasks:
* A more dynamic binlog format which allows small changes (1064)
* Log session variables in Query_log_event (1063)
Below 5.0 means 5.0.0.
MySQL 5.0 is able to replicate FOREIGN_KEY_CHECKS, UNIQUE_KEY_CHECKS (for speed),
SQL_AUTO_IS_NULL, SQL_MODE. Not charsets (WL#1062), not some vars (I can only think
of SQL_SELECT_LIMIT, which deserves a special treatment). Note that this
works for queries, except LOAD DATA INFILE (for this it would have to wait
for Dmitri's push of WL#874, which in turns waits for the present push, so...
the deadlock must be broken!). Note that when Dmitri pushes WL#874 in 5.0.1,
5.0.0 won't be able to replicate a LOAD DATA INFILE from 5.0.1.
Apart from that, the new binlog format is designed so that it can tolerate
a little variation in the events (so that a 5.0.0 slave could replicate a
5.0.1 master, except for LOAD DATA INFILE unfortunately); that is, when I
later add replication of charsets it should break nothing. And when I later
add a UID to every event, it should break nothing.
The main change brought by this patch is a new type of event, Format_description_log_event,
which describes some lengthes in other event types. This event is needed for
the master/slave/mysqlbinlog to understand a 5.0 log. Thanks to this event,
we can later add more bytes to the header of every event without breaking compatibility.
Inside Query_log_event, we have some additional dynamic format, as every Query_log_event
can have a different number of status variables, stored as pairs (code, value); that's
how SQL_MODE and session variables and catalog are stored. Like this, we can later
add count of affected rows, charsets... and we can have options --don't-log-count-affected-rows
if we want.
MySQL 5.0 is able to run on 4.x relay logs, 4.x binlogs.
Upgrading a 4.x master to 5.0 is ok (no need to delete binlogs),
upgrading a 4.x slave to 5.0 is ok (no need to delete relay logs);
so both can be "hot" upgrades.
Upgrading a 3.23 master to 5.0 requires as much as upgrading it to 4.0.
3.23 and 4.x can't be slaves of 5.0.
So downgrading from 5.0 to 4.x may be complicated.
Log_event::log_pos is now the position of the end of the event, which is
more useful than the position of the beginning. We take care about compatibility
with <5.0 (in which log_pos is the beginning).
I added a short test for replication of SQL_MODE and some other variables.
TODO:
- after committing this, merge the latest 5.0 into it
- fix all tests
- update the manual with upgrade notes.
2003-12-18 01:09:05 +01:00
|
|
|
|
2004-01-23 13:02:57 +01:00
|
|
|
|
2004-12-06 17:45:32 +01:00
|
|
|
/*
|
|
|
|
SYNOPSYS
|
|
|
|
hexchar_to_int()
|
|
|
|
convert a hex digit into number
|
|
|
|
*/
|
|
|
|
|
|
|
|
inline int hexchar_to_int(char c)
|
|
|
|
{
|
|
|
|
if (c <= '9' && c >= '0')
|
|
|
|
return c-'0';
|
|
|
|
c|=32;
|
|
|
|
if (c <= 'f' && c >= 'a')
|
|
|
|
return c-'a'+10;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-05-29 17:01:58 +02:00
|
|
|
/*
|
|
|
|
is_user_table()
|
|
|
|
return true if the table was created explicitly
|
|
|
|
*/
|
|
|
|
|
|
|
|
inline bool is_user_table(TABLE * table)
|
|
|
|
{
|
|
|
|
const char *name= table->s->table_name.str;
|
|
|
|
return strncmp(name, tmp_file_prefix, tmp_file_prefix_length);
|
|
|
|
}
|
2004-12-06 17:45:32 +01:00
|
|
|
|
2004-03-29 16:57:07 +02:00
|
|
|
/*
|
|
|
|
Some functions that are different in the embedded library and the normal
|
|
|
|
server
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef EMBEDDED_LIBRARY
|
2006-11-30 22:23:23 +01:00
|
|
|
extern "C" void unireg_abort(int exit_code) __attribute__((noreturn));
|
2004-03-29 16:57:07 +02:00
|
|
|
void kill_delayed_threads(void);
|
2005-05-31 12:06:15 +02:00
|
|
|
bool check_stack_overrun(THD *thd, long margin, char *dummy);
|
2004-03-29 16:57:07 +02:00
|
|
|
#else
|
|
|
|
#define unireg_abort(exit_code) DBUG_RETURN(exit_code)
|
|
|
|
inline void kill_delayed_threads(void) {}
|
2005-05-31 12:06:15 +02:00
|
|
|
#define check_stack_overrun(A, B, C) 0
|
2004-03-29 16:57:07 +02:00
|
|
|
#endif
|
2004-02-10 18:44:02 +01:00
|
|
|
|
2006-01-28 04:16:23 +01:00
|
|
|
/* Used by handlers to store things in schema tables */
|
2006-10-05 16:39:22 +02:00
|
|
|
#define IS_FILES_FILE_ID 0
|
|
|
|
#define IS_FILES_FILE_NAME 1
|
|
|
|
#define IS_FILES_FILE_TYPE 2
|
|
|
|
#define IS_FILES_TABLESPACE_NAME 3
|
|
|
|
#define IS_FILES_TABLE_CATALOG 4
|
|
|
|
#define IS_FILES_TABLE_SCHEMA 5
|
|
|
|
#define IS_FILES_TABLE_NAME 6
|
|
|
|
#define IS_FILES_LOGFILE_GROUP_NAME 7
|
|
|
|
#define IS_FILES_LOGFILE_GROUP_NUMBER 8
|
|
|
|
#define IS_FILES_ENGINE 9
|
|
|
|
#define IS_FILES_FULLTEXT_KEYS 10
|
|
|
|
#define IS_FILES_DELETED_ROWS 11
|
|
|
|
#define IS_FILES_UPDATE_COUNT 12
|
|
|
|
#define IS_FILES_FREE_EXTENTS 13
|
|
|
|
#define IS_FILES_TOTAL_EXTENTS 14
|
|
|
|
#define IS_FILES_EXTENT_SIZE 15
|
|
|
|
#define IS_FILES_INITIAL_SIZE 16
|
|
|
|
#define IS_FILES_MAXIMUM_SIZE 17
|
|
|
|
#define IS_FILES_AUTOEXTEND_SIZE 18
|
|
|
|
#define IS_FILES_CREATION_TIME 19
|
|
|
|
#define IS_FILES_LAST_UPDATE_TIME 20
|
|
|
|
#define IS_FILES_LAST_ACCESS_TIME 21
|
|
|
|
#define IS_FILES_RECOVER_TIME 22
|
|
|
|
#define IS_FILES_TRANSACTION_COUNTER 23
|
|
|
|
#define IS_FILES_VERSION 24
|
|
|
|
#define IS_FILES_ROW_FORMAT 25
|
|
|
|
#define IS_FILES_TABLE_ROWS 26
|
|
|
|
#define IS_FILES_AVG_ROW_LENGTH 27
|
|
|
|
#define IS_FILES_DATA_LENGTH 28
|
|
|
|
#define IS_FILES_MAX_DATA_LENGTH 29
|
|
|
|
#define IS_FILES_INDEX_LENGTH 30
|
|
|
|
#define IS_FILES_DATA_FREE 31
|
|
|
|
#define IS_FILES_CREATE_TIME 32
|
|
|
|
#define IS_FILES_UPDATE_TIME 33
|
|
|
|
#define IS_FILES_CHECK_TIME 34
|
|
|
|
#define IS_FILES_CHECKSUM 35
|
|
|
|
#define IS_FILES_STATUS 36
|
|
|
|
#define IS_FILES_EXTRA 37
|
|
|
|
void init_fill_schema_files_row(TABLE* table);
|
2006-01-28 04:16:23 +01:00
|
|
|
bool schema_table_store_record(THD *thd, TABLE *table);
|
|
|
|
|
2006-11-02 19:01:53 +01:00
|
|
|
/* sql/item_create.cc */
|
|
|
|
int item_create_init();
|
|
|
|
void item_create_cleanup();
|
|
|
|
|
2006-01-19 22:40:56 +01:00
|
|
|
#endif /* MYSQL_SERVER */
|
This will be pushed only after I fix the testsuite.
This is the main commit for Worklog tasks:
* A more dynamic binlog format which allows small changes (1064)
* Log session variables in Query_log_event (1063)
Below 5.0 means 5.0.0.
MySQL 5.0 is able to replicate FOREIGN_KEY_CHECKS, UNIQUE_KEY_CHECKS (for speed),
SQL_AUTO_IS_NULL, SQL_MODE. Not charsets (WL#1062), not some vars (I can only think
of SQL_SELECT_LIMIT, which deserves a special treatment). Note that this
works for queries, except LOAD DATA INFILE (for this it would have to wait
for Dmitri's push of WL#874, which in turns waits for the present push, so...
the deadlock must be broken!). Note that when Dmitri pushes WL#874 in 5.0.1,
5.0.0 won't be able to replicate a LOAD DATA INFILE from 5.0.1.
Apart from that, the new binlog format is designed so that it can tolerate
a little variation in the events (so that a 5.0.0 slave could replicate a
5.0.1 master, except for LOAD DATA INFILE unfortunately); that is, when I
later add replication of charsets it should break nothing. And when I later
add a UID to every event, it should break nothing.
The main change brought by this patch is a new type of event, Format_description_log_event,
which describes some lengthes in other event types. This event is needed for
the master/slave/mysqlbinlog to understand a 5.0 log. Thanks to this event,
we can later add more bytes to the header of every event without breaking compatibility.
Inside Query_log_event, we have some additional dynamic format, as every Query_log_event
can have a different number of status variables, stored as pairs (code, value); that's
how SQL_MODE and session variables and catalog are stored. Like this, we can later
add count of affected rows, charsets... and we can have options --don't-log-count-affected-rows
if we want.
MySQL 5.0 is able to run on 4.x relay logs, 4.x binlogs.
Upgrading a 4.x master to 5.0 is ok (no need to delete binlogs),
upgrading a 4.x slave to 5.0 is ok (no need to delete relay logs);
so both can be "hot" upgrades.
Upgrading a 3.23 master to 5.0 requires as much as upgrading it to 4.0.
3.23 and 4.x can't be slaves of 5.0.
So downgrading from 5.0 to 4.x may be complicated.
Log_event::log_pos is now the position of the end of the event, which is
more useful than the position of the beginning. We take care about compatibility
with <5.0 (in which log_pos is the beginning).
I added a short test for replication of SQL_MODE and some other variables.
TODO:
- after committing this, merge the latest 5.0 into it
- fix all tests
- update the manual with upgrade notes.
2003-12-18 01:09:05 +01:00
|
|
|
#endif /* MYSQL_CLIENT */
|
2006-05-03 15:00:38 +02:00
|
|
|
|
|
|
|
#endif /* MYSQL_PRIV_H */
|