mirror of
https://github.com/MariaDB/server.git
synced 2025-01-22 14:54:20 +01:00
f631b361b6
The table opening process now works the following way: - Create common TABLE_SHARE object - Read the .frm file and unpack it into the TABLE_SHARE object - Create a TABLE object based on the information in the TABLE_SHARE object and open a handler to the table object Other noteworthy changes: - In TABLE_SHARE the most common strings are now LEX_STRING's - Better error message when table is not found - Variable table_cache is now renamed 'table_open_cache' - New variable 'table_definition_cache' that is the number of table defintions that will be cached - strxnmov() calls are now fixed to avoid overflows - strxnmov() will now always add one end \0 to result - engine objects are now created with a TABLE_SHARE object instead of a TABLE object. - After creating a field object one must call field->init(table) before using it - For a busy system this change will give you: - Less memory usage for table object - Faster opening of tables (if it's has been in use or is in table definition cache) - Allow you to cache many table definitions objects - Faster drop of table mysql-test/mysql-test-run.sh: Fixed some problems with --gdb option Test both with socket and tcp/ip port that all old servers are killed mysql-test/r/flush_table.result: More tests with lock table with 2 threads + flush table mysql-test/r/information_schema.result: Removed old (now wrong) result mysql-test/r/innodb.result: Better error messages (thanks to TDC patch) mysql-test/r/merge.result: Extra flush table test mysql-test/r/ndb_bitfield.result: Better error messages (thanks to TDC patch) mysql-test/r/ndb_partition_error.result: Better error messages (thanks to TDC patch) mysql-test/r/query_cache.result: Remove tables left from old tests mysql-test/r/temp_table.result: Test truncate with temporary tables mysql-test/r/variables.result: Table_cache -> Table_open_cache mysql-test/t/flush_table.test: More tests with lock table with 2 threads + flush table mysql-test/t/merge.test: Extra flush table test mysql-test/t/multi_update.test: Added 'sleep' to make test predictable mysql-test/t/query_cache.test: Remove tables left from old tests mysql-test/t/temp_table.test: Test truncate with temporary tables mysql-test/t/variables.test: Table_cache -> Table_open_cache mysql-test/valgrind.supp: Remove warning that may happens becasue threads dies in different order mysys/hash.c: Fixed wrong DBUG_PRINT mysys/mf_dirname.c: More DBUG mysys/mf_pack.c: Better comment mysys/mf_tempdir.c: More DBUG Ensure that we call cleanup_dirname() on all temporary directory paths. If we don't do this, we will get a failure when comparing temporary table names as in some cases the temporary table name is run through convert_dirname()) mysys/my_alloc.c: Indentation fix sql/examples/ha_example.cc: We new use TABLE_SHARE instead of TABLE when creating engine handlers sql/examples/ha_example.h: We new use TABLE_SHARE instead of TABLE when creating engine handlers sql/examples/ha_tina.cc: We new use TABLE_SHARE instead of TABLE when creating engine handlers sql/examples/ha_tina.h: We new use TABLE_SHARE instead of TABLE when creating engine handlers sql/field.cc: Update for table definition cache: - Field creation now takes TABLE_SHARE instead of TABLE as argument (This is becasue field definitions are now cached in TABLE_SHARE) When a field is created, one now must call field->init(TABLE) before using it - Use s->db instead of s->table_cache_key - Added Field::clone() to create a field in TABLE from a field in TABLE_SHARE - make_field() takes TABLE_SHARE as argument instead of TABLE - move_field() -> move_field_offset() sql/field.h: Update for table definition cache: - Field creation now takes TABLE_SHARE instead of TABLE as argument (This is becasue field definitions are now cached in TABLE_SHARE) When a field is created, one now must call field->init(TABLE) before using it - Added Field::clone() to create a field in TABLE from a field in TABLE_SHARE - make_field() takes TABLE_SHARE as argument instead of TABLE - move_field() -> move_field_offset() sql/ha_archive.cc: We new use TABLE_SHARE instead of TABLE when creating engine handlers sql/ha_archive.h: We new use TABLE_SHARE instead of TABLE when creating engine handlers sql/ha_berkeley.cc: We new use TABLE_SHARE instead of TABLE when creating engine handlers Changed name of argument create() to not hide internal 'table' variable. table->s -> table_share sql/ha_berkeley.h: We new use TABLE_SHARE instead of TABLE when creating engine handlers sql/ha_blackhole.cc: We new use TABLE_SHARE instead of TABLE when creating engine handlers sql/ha_blackhole.h: We new use TABLE_SHARE instead of TABLE when creating engine handlers sql/ha_federated.cc: We new use TABLE_SHARE instead of TABLE when creating engine handlers Fixed comments Remove index variable and replace with pointers (simple optimization) move_field() -> move_field_offset() Removed some strlen() calls sql/ha_federated.h: We new use TABLE_SHARE instead of TABLE when creating engine handlers sql/ha_heap.cc: We new use TABLE_SHARE instead of TABLE when creating engine handlers Simplify delete_table() and create() as the given file names are now without extension sql/ha_heap.h: We new use TABLE_SHARE instead of TABLE when creating engine handlers sql/ha_innodb.cc: We new use TABLE_SHARE instead of TABLE when creating engine handlers sql/ha_innodb.h: We new use TABLE_SHARE instead of TABLE when creating engine handlers sql/ha_myisam.cc: We new use TABLE_SHARE instead of TABLE when creating engine handlers Remove not needed fn_format() Fixed for new table->s structure sql/ha_myisam.h: We new use TABLE_SHARE instead of TABLE when creating engine handlers sql/ha_myisammrg.cc: We new use TABLE_SHARE instead of TABLE when creating engine handlers Don't set 'is_view' for MERGE tables Use new interface to find_temporary_table() sql/ha_myisammrg.h: We new use TABLE_SHARE instead of TABLE when creating engine handlers Added flag HA_NO_COPY_ON_ALTER sql/ha_ndbcluster.cc: We new use TABLE_SHARE instead of TABLE when creating engine handlers Fixed wrong calls to strxnmov() Give error HA_ERR_TABLE_DEF_CHANGED if table definition has changed drop_table -> intern_drop_table() table->s -> table_share Move part_info to TABLE Fixed comments & DBUG print's New arguments to print_error() sql/ha_ndbcluster.h: We new use TABLE_SHARE instead of TABLE when creating engine handlers sql/ha_partition.cc: We new use TABLE_SHARE instead of TABLE when creating engine handlers We can't set up or use part_info when creating handler as there is not yet any table object New ha_intialise() to work with TDC (Done by Mikael) sql/ha_partition.h: We new use TABLE_SHARE instead of TABLE when creating engine handlers Got set_part_info() from Mikael sql/handler.cc: We new use TABLE_SHARE instead of TABLE when creating engine handlers ha_delete_table() now also takes database as an argument handler::ha_open() now takes TABLE as argument ha_open() now calls ha_allocate_read_write_set() Simplify ha_allocate_read_write_set() Remove ha_deallocate_read_write_set() Use table_share (Cached by table definition cache) sql/handler.h: New table flag: HA_NO_COPY_ON_ALTER (used by merge tables) Remove ha_deallocate_read_write_set() get_new_handler() now takes TABLE_SHARE as argument ha_delete_table() now gets database as argument sql/item.cc: table_name and db are now LEX_STRING objects When creating fields, we have now have to call field->init(table) move_field -> move_field_offset() sql/item.h: tmp_table_field_from_field_type() now takes an extra paramenter 'fixed_length' to allow one to force usage of CHAR instead of BLOB sql/item_cmpfunc.cc: Fixed call to tmp_table_field_from_field_type() sql/item_create.cc: Assert if new not handled cast type sql/item_func.cc: When creating fields, we have now have to call field->init(table) dummy_table used by 'sp' now needs a TABLE_SHARE object sql/item_subselect.cc: Trivial code cleanups sql/item_sum.cc: When creating fields, we have now have to call field->init(table) sql/item_timefunc.cc: Item_func_str_to_date::tmp_table_field() now replaced by call to tmp_table_field_from_field_type() (see item_timefunc.h) sql/item_timefunc.h: Simply tmp_table_field() sql/item_uniq.cc: When creating fields, we have now have to call field->init(table) sql/key.cc: Added 'KEY' argument to 'find_ref_key' to simplify code sql/lock.cc: More debugging Use create_table_def_key() to create key for table cache Allocate TABLE_SHARE properly when creating name lock Fix that locked_table_name doesn't test same table twice sql/mysql_priv.h: New functions for table definition cache New interfaces to a lot of functions. New faster interface to find_temporary_table() and close_temporary_table() sql/mysqld.cc: Added support for table definition cache of size 'table_def_size' Fixed som calls to strnmov() Changed name of 'table_cache' to 'table_open_cache' sql/opt_range.cc: Use new interfaces Fixed warnings from valgrind sql/parse_file.cc: Safer calls to strxnmov() Fixed typo sql/set_var.cc: Added variable 'table_definition_cache' Variable table_cache renamed to 'table_open_cache' sql/slave.cc: Use new interface sql/sp.cc: Proper use of TABLE_SHARE sql/sp_head.cc: Remove compiler warnings We have now to call field->init(table) sql/sp_head.h: Pointers to parsed strings are now const sql/sql_acl.cc: table_name is now a LEX_STRING sql/sql_base.cc: Main implementation of table definition cache (The #ifdef's are there for the future when table definition cache will replace open table cache) Now table definitions are cached indepndent of open tables, which will speed up things when a table is in use at once from several places Views are not yet cached; For the moment we only cache if a table is a view or not. Faster implementation of find_temorary_table() Replace 'wait_for_refresh()' with the more general function 'wait_for_condition()' Drop table is slightly faster as we can use the table definition cache to know the type of the table sql/sql_cache.cc: table_cache_key and table_name are now LEX_STRING 'sDBUG print fixes sql/sql_class.cc: table_cache_key is now a LEX_STRING safer strxnmov() sql/sql_class.h: Added number of open table shares (table definitions) sql/sql_db.cc: safer strxnmov() sql/sql_delete.cc: Use new interface to find_temporary_table() sql/sql_derived.cc: table_name is now a LEX_STRING sql/sql_handler.cc: TABLE_SHARE->db and TABLE_SHARE->table_name are now LEX_STRING's sql/sql_insert.cc: TABLE_SHARE->db and TABLE_SHARE->table_name are now LEX_STRING's sql/sql_lex.cc: Make parsed string a const (to quickly find out if anything is trying to change the query string) sql/sql_lex.h: Make parsed string a const (to quickly find out if anything is trying to change the query string) sql/sql_load.cc: Safer strxnmov() sql/sql_parse.cc: Better error if wrong DB name sql/sql_partition.cc: part_info moved to TABLE from TABLE_SHARE Indentation changes sql/sql_select.cc: Indentation fixes Call field->init(TABLE) for new created fields Update create_tmp_table() to use TABLE_SHARE properly sql/sql_select.h: Call field->init(TABLE) for new created fields sql/sql_show.cc: table_name is now a LEX_STRING part_info moved to TABLE sql/sql_table.cc: Use table definition cache to speed up delete of tables Fixed calls to functions with new interfaces Don't use 'share_not_to_be_used' Instead of doing openfrm() when doing repair, we now have to call get_table_share() followed by open_table_from_share(). Replace some fn_format() with faster unpack_filename(). Safer strxnmov() part_info is now in TABLE Added Mikaels patch for partition and ALTER TABLE Instead of using 'TABLE_SHARE->is_view' use 'table_flags() & HA_NO_COPY_ON_ALTER sql/sql_test.cc: table_name and table_cache_key are now LEX_STRING's sql/sql_trigger.cc: TABLE_SHARE->db and TABLE_SHARE->table_name are now LEX_STRING's safer strxnmov() Removed compiler warnings sql/sql_update.cc: Call field->init(TABLE) after field is created sql/sql_view.cc: safer strxnmov() Create common TABLE_SHARE object for views to allow us to cache if table is a view sql/structs.h: Added SHOW_TABLE_DEFINITIONS sql/table.cc: Creation and destruct of TABLE_SHARE objects that are common for many TABLE objects The table opening process now works the following way: - Create common TABLE_SHARE object - Read the .frm file and unpack it into the TABLE_SHARE object - Create a TABLE object based on the information in the TABLE_SHARE object and open a handler to the table object open_table_def() is written in such a way that it should be trival to add parsing of the .frm files in new formats sql/table.h: TABLE objects for the same database table now share a common TABLE_SHARE object In TABLE_SHARE the most common strings are now LEX_STRING's sql/unireg.cc: Changed arguments to rea_create_table() to have same order as other functions Call field->init(table) for new created fields sql/unireg.h: Added OPEN_VIEW strings/strxnmov.c: Change strxnmov() to always add end \0 This makes usage of strxnmov() safer as most of MySQL code assumes that strxnmov() will create a null terminated string
949 lines
25 KiB
C++
949 lines
25 KiB
C++
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
|
|
|
|
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
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
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.
|
|
|
|
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 */
|
|
|
|
|
|
/* Function items used by mysql */
|
|
|
|
#ifdef USE_PRAGMA_INTERFACE
|
|
#pragma interface /* gcc class implementation */
|
|
#endif
|
|
|
|
enum date_time_format_types
|
|
{
|
|
TIME_ONLY= 0, TIME_MICROSECOND, DATE_ONLY, DATE_TIME, DATE_TIME_MICROSECOND
|
|
};
|
|
|
|
class Item_func_period_add :public Item_int_func
|
|
{
|
|
public:
|
|
Item_func_period_add(Item *a,Item *b) :Item_int_func(a,b) {}
|
|
longlong val_int();
|
|
const char *func_name() const { return "period_add"; }
|
|
void fix_length_and_dec()
|
|
{
|
|
max_length=6*MY_CHARSET_BIN_MB_MAXLEN;
|
|
}
|
|
};
|
|
|
|
|
|
class Item_func_period_diff :public Item_int_func
|
|
{
|
|
public:
|
|
Item_func_period_diff(Item *a,Item *b) :Item_int_func(a,b) {}
|
|
longlong val_int();
|
|
const char *func_name() const { return "period_diff"; }
|
|
void fix_length_and_dec()
|
|
{
|
|
decimals=0;
|
|
max_length=6*MY_CHARSET_BIN_MB_MAXLEN;
|
|
}
|
|
};
|
|
|
|
|
|
class Item_func_to_days :public Item_int_func
|
|
{
|
|
public:
|
|
Item_func_to_days(Item *a) :Item_int_func(a) {}
|
|
longlong val_int();
|
|
const char *func_name() const { return "to_days"; }
|
|
void fix_length_and_dec()
|
|
{
|
|
decimals=0;
|
|
max_length=6*MY_CHARSET_BIN_MB_MAXLEN;
|
|
maybe_null=1;
|
|
}
|
|
};
|
|
|
|
|
|
class Item_func_dayofmonth :public Item_int_func
|
|
{
|
|
public:
|
|
Item_func_dayofmonth(Item *a) :Item_int_func(a) {}
|
|
longlong val_int();
|
|
const char *func_name() const { return "dayofmonth"; }
|
|
void fix_length_and_dec()
|
|
{
|
|
decimals=0;
|
|
max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
|
|
maybe_null=1;
|
|
}
|
|
};
|
|
|
|
|
|
class Item_func_month :public Item_func
|
|
{
|
|
public:
|
|
Item_func_month(Item *a) :Item_func(a) {}
|
|
longlong val_int();
|
|
double val_real()
|
|
{ DBUG_ASSERT(fixed == 1); return (double) Item_func_month::val_int(); }
|
|
String *val_str(String *str)
|
|
{
|
|
str->set(val_int(), &my_charset_bin);
|
|
return null_value ? 0 : str;
|
|
}
|
|
const char *func_name() const { return "month"; }
|
|
enum Item_result result_type () const { return INT_RESULT; }
|
|
void fix_length_and_dec()
|
|
{
|
|
collation.set(&my_charset_bin);
|
|
decimals=0;
|
|
max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
|
|
maybe_null=1;
|
|
}
|
|
};
|
|
|
|
|
|
class Item_func_monthname :public Item_func_month
|
|
{
|
|
public:
|
|
Item_func_monthname(Item *a) :Item_func_month(a) {}
|
|
const char *func_name() const { return "monthname"; }
|
|
String *val_str(String *str);
|
|
enum Item_result result_type () const { return STRING_RESULT; }
|
|
void fix_length_and_dec()
|
|
{
|
|
collation.set(&my_charset_bin);
|
|
decimals=0;
|
|
max_length=10*my_charset_bin.mbmaxlen;
|
|
maybe_null=1;
|
|
}
|
|
};
|
|
|
|
|
|
class Item_func_dayofyear :public Item_int_func
|
|
{
|
|
public:
|
|
Item_func_dayofyear(Item *a) :Item_int_func(a) {}
|
|
longlong val_int();
|
|
const char *func_name() const { return "dayofyear"; }
|
|
void fix_length_and_dec()
|
|
{
|
|
decimals=0;
|
|
max_length=3*MY_CHARSET_BIN_MB_MAXLEN;
|
|
maybe_null=1;
|
|
}
|
|
};
|
|
|
|
|
|
class Item_func_hour :public Item_int_func
|
|
{
|
|
public:
|
|
Item_func_hour(Item *a) :Item_int_func(a) {}
|
|
longlong val_int();
|
|
const char *func_name() const { return "hour"; }
|
|
void fix_length_and_dec()
|
|
{
|
|
decimals=0;
|
|
max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
|
|
maybe_null=1;
|
|
}
|
|
};
|
|
|
|
|
|
class Item_func_minute :public Item_int_func
|
|
{
|
|
public:
|
|
Item_func_minute(Item *a) :Item_int_func(a) {}
|
|
longlong val_int();
|
|
const char *func_name() const { return "minute"; }
|
|
void fix_length_and_dec()
|
|
{
|
|
decimals=0;
|
|
max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
|
|
maybe_null=1;
|
|
}
|
|
};
|
|
|
|
|
|
class Item_func_quarter :public Item_int_func
|
|
{
|
|
public:
|
|
Item_func_quarter(Item *a) :Item_int_func(a) {}
|
|
longlong val_int();
|
|
const char *func_name() const { return "quarter"; }
|
|
void fix_length_and_dec()
|
|
{
|
|
decimals=0;
|
|
max_length=1*MY_CHARSET_BIN_MB_MAXLEN;
|
|
maybe_null=1;
|
|
}
|
|
};
|
|
|
|
|
|
class Item_func_second :public Item_int_func
|
|
{
|
|
public:
|
|
Item_func_second(Item *a) :Item_int_func(a) {}
|
|
longlong val_int();
|
|
const char *func_name() const { return "second"; }
|
|
void fix_length_and_dec()
|
|
{
|
|
decimals=0;
|
|
max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
|
|
maybe_null=1;
|
|
}
|
|
};
|
|
|
|
|
|
class Item_func_week :public Item_int_func
|
|
{
|
|
public:
|
|
Item_func_week(Item *a,Item *b) :Item_int_func(a,b) {}
|
|
longlong val_int();
|
|
const char *func_name() const { return "week"; }
|
|
void fix_length_and_dec()
|
|
{
|
|
decimals=0;
|
|
max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
|
|
maybe_null=1;
|
|
}
|
|
};
|
|
|
|
class Item_func_yearweek :public Item_int_func
|
|
{
|
|
public:
|
|
Item_func_yearweek(Item *a,Item *b) :Item_int_func(a,b) {}
|
|
longlong val_int();
|
|
const char *func_name() const { return "yearweek"; }
|
|
void fix_length_and_dec()
|
|
{
|
|
decimals=0;
|
|
max_length=6*MY_CHARSET_BIN_MB_MAXLEN;
|
|
maybe_null=1;
|
|
}
|
|
};
|
|
|
|
|
|
class Item_func_year :public Item_int_func
|
|
{
|
|
public:
|
|
Item_func_year(Item *a) :Item_int_func(a) {}
|
|
longlong val_int();
|
|
const char *func_name() const { return "year"; }
|
|
void fix_length_and_dec()
|
|
{
|
|
decimals=0;
|
|
max_length=4*MY_CHARSET_BIN_MB_MAXLEN;
|
|
maybe_null=1;
|
|
}
|
|
};
|
|
|
|
|
|
class Item_func_weekday :public Item_func
|
|
{
|
|
bool odbc_type;
|
|
public:
|
|
Item_func_weekday(Item *a,bool type_arg)
|
|
:Item_func(a), odbc_type(type_arg) {}
|
|
longlong val_int();
|
|
double val_real() { DBUG_ASSERT(fixed == 1); return (double) val_int(); }
|
|
String *val_str(String *str)
|
|
{
|
|
DBUG_ASSERT(fixed == 1);
|
|
str->set(val_int(), &my_charset_bin);
|
|
return null_value ? 0 : str;
|
|
}
|
|
const char *func_name() const
|
|
{
|
|
return (odbc_type ? "dayofweek" : "weekday");
|
|
}
|
|
enum Item_result result_type () const { return INT_RESULT; }
|
|
void fix_length_and_dec()
|
|
{
|
|
collation.set(&my_charset_bin);
|
|
decimals=0;
|
|
max_length=1*MY_CHARSET_BIN_MB_MAXLEN;
|
|
maybe_null=1;
|
|
}
|
|
};
|
|
|
|
class Item_func_dayname :public Item_func_weekday
|
|
{
|
|
public:
|
|
Item_func_dayname(Item *a) :Item_func_weekday(a,0) {}
|
|
const char *func_name() const { return "dayname"; }
|
|
String *val_str(String *str);
|
|
enum Item_result result_type () const { return STRING_RESULT; }
|
|
void fix_length_and_dec()
|
|
{
|
|
collation.set(&my_charset_bin);
|
|
decimals=0;
|
|
max_length=9*MY_CHARSET_BIN_MB_MAXLEN;
|
|
maybe_null=1;
|
|
}
|
|
};
|
|
|
|
|
|
class Item_func_unix_timestamp :public Item_int_func
|
|
{
|
|
String value;
|
|
public:
|
|
Item_func_unix_timestamp() :Item_int_func() {}
|
|
Item_func_unix_timestamp(Item *a) :Item_int_func(a) {}
|
|
longlong val_int();
|
|
const char *func_name() const { return "unix_timestamp"; }
|
|
void fix_length_and_dec()
|
|
{
|
|
decimals=0;
|
|
max_length=10*MY_CHARSET_BIN_MB_MAXLEN;
|
|
}
|
|
};
|
|
|
|
|
|
class Item_func_time_to_sec :public Item_int_func
|
|
{
|
|
public:
|
|
Item_func_time_to_sec(Item *item) :Item_int_func(item) {}
|
|
longlong val_int();
|
|
const char *func_name() const { return "time_to_sec"; }
|
|
void fix_length_and_dec()
|
|
{
|
|
decimals=0;
|
|
max_length=10*MY_CHARSET_BIN_MB_MAXLEN;
|
|
}
|
|
};
|
|
|
|
|
|
/*
|
|
This can't be a Item_str_func, because the val_real() functions are special
|
|
*/
|
|
|
|
class Item_date :public Item_func
|
|
{
|
|
public:
|
|
Item_date() :Item_func() {}
|
|
Item_date(Item *a) :Item_func(a) {}
|
|
enum Item_result result_type () const { return STRING_RESULT; }
|
|
enum_field_types field_type() const { return MYSQL_TYPE_DATE; }
|
|
String *val_str(String *str);
|
|
longlong val_int();
|
|
double val_real() { DBUG_ASSERT(fixed == 1); return (double) val_int(); }
|
|
const char *func_name() const { return "date"; }
|
|
void fix_length_and_dec()
|
|
{
|
|
collation.set(&my_charset_bin);
|
|
decimals=0;
|
|
max_length=MAX_DATE_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
|
|
}
|
|
int save_in_field(Field *to, bool no_conversions);
|
|
Field *tmp_table_field(TABLE *table)
|
|
{
|
|
return tmp_table_field_from_field_type(table, 0);
|
|
}
|
|
};
|
|
|
|
|
|
class Item_date_func :public Item_str_func
|
|
{
|
|
public:
|
|
Item_date_func() :Item_str_func() {}
|
|
Item_date_func(Item *a) :Item_str_func(a) {}
|
|
Item_date_func(Item *a,Item *b) :Item_str_func(a,b) {}
|
|
Item_date_func(Item *a,Item *b, Item *c) :Item_str_func(a,b,c) {}
|
|
enum_field_types field_type() const { return MYSQL_TYPE_DATETIME; }
|
|
Field *tmp_table_field(TABLE *table)
|
|
{
|
|
return tmp_table_field_from_field_type(table, 0);
|
|
}
|
|
};
|
|
|
|
|
|
/* Abstract CURTIME function. Children should define what time zone is used */
|
|
|
|
class Item_func_curtime :public Item_func
|
|
{
|
|
longlong value;
|
|
char buff[9*2+32];
|
|
uint buff_length;
|
|
public:
|
|
Item_func_curtime() :Item_func() {}
|
|
Item_func_curtime(Item *a) :Item_func(a) {}
|
|
enum Item_result result_type () const { return STRING_RESULT; }
|
|
enum_field_types field_type() const { return MYSQL_TYPE_TIME; }
|
|
double val_real() { DBUG_ASSERT(fixed == 1); return (double) value; }
|
|
longlong val_int() { DBUG_ASSERT(fixed == 1); return value; }
|
|
String *val_str(String *str);
|
|
void fix_length_and_dec();
|
|
Field *tmp_table_field(TABLE *table)
|
|
{
|
|
return tmp_table_field_from_field_type(table, 0);
|
|
}
|
|
/*
|
|
Abstract method that defines which time zone is used for conversion.
|
|
Converts time current time in my_time_t representation to broken-down
|
|
TIME representation using UTC-SYSTEM or per-thread time zone.
|
|
*/
|
|
virtual void store_now_in_TIME(TIME *now_time)=0;
|
|
};
|
|
|
|
|
|
class Item_func_curtime_local :public Item_func_curtime
|
|
{
|
|
public:
|
|
Item_func_curtime_local() :Item_func_curtime() {}
|
|
Item_func_curtime_local(Item *a) :Item_func_curtime(a) {}
|
|
const char *func_name() const { return "curtime"; }
|
|
virtual void store_now_in_TIME(TIME *now_time);
|
|
};
|
|
|
|
|
|
class Item_func_curtime_utc :public Item_func_curtime
|
|
{
|
|
public:
|
|
Item_func_curtime_utc() :Item_func_curtime() {}
|
|
Item_func_curtime_utc(Item *a) :Item_func_curtime(a) {}
|
|
const char *func_name() const { return "utc_time"; }
|
|
virtual void store_now_in_TIME(TIME *now_time);
|
|
};
|
|
|
|
|
|
/* Abstract CURDATE function. See also Item_func_curtime. */
|
|
|
|
class Item_func_curdate :public Item_date
|
|
{
|
|
longlong value;
|
|
TIME ltime;
|
|
public:
|
|
Item_func_curdate() :Item_date() {}
|
|
longlong val_int() { DBUG_ASSERT(fixed == 1); return (value) ; }
|
|
String *val_str(String *str);
|
|
void fix_length_and_dec();
|
|
bool get_date(TIME *res, uint fuzzy_date);
|
|
virtual void store_now_in_TIME(TIME *now_time)=0;
|
|
};
|
|
|
|
|
|
class Item_func_curdate_local :public Item_func_curdate
|
|
{
|
|
public:
|
|
Item_func_curdate_local() :Item_func_curdate() {}
|
|
const char *func_name() const { return "curdate"; }
|
|
void store_now_in_TIME(TIME *now_time);
|
|
};
|
|
|
|
|
|
class Item_func_curdate_utc :public Item_func_curdate
|
|
{
|
|
public:
|
|
Item_func_curdate_utc() :Item_func_curdate() {}
|
|
const char *func_name() const { return "utc_date"; }
|
|
void store_now_in_TIME(TIME *now_time);
|
|
};
|
|
|
|
|
|
/* Abstract CURRENT_TIMESTAMP function. See also Item_func_curtime */
|
|
|
|
class Item_func_now :public Item_date_func
|
|
{
|
|
protected:
|
|
longlong value;
|
|
char buff[20*2+32]; // +32 to make my_snprintf_{8bit|ucs2} happy
|
|
uint buff_length;
|
|
TIME ltime;
|
|
public:
|
|
Item_func_now() :Item_date_func() {}
|
|
Item_func_now(Item *a) :Item_date_func(a) {}
|
|
enum Item_result result_type () const { return STRING_RESULT; }
|
|
double val_real() { DBUG_ASSERT(fixed == 1); return (double) value; }
|
|
longlong val_int() { DBUG_ASSERT(fixed == 1); return value; }
|
|
int save_in_field(Field *to, bool no_conversions);
|
|
String *val_str(String *str);
|
|
void fix_length_and_dec();
|
|
bool get_date(TIME *res, uint fuzzy_date);
|
|
virtual void store_now_in_TIME(TIME *now_time)=0;
|
|
};
|
|
|
|
|
|
class Item_func_now_local :public Item_func_now
|
|
{
|
|
public:
|
|
Item_func_now_local() :Item_func_now() {}
|
|
Item_func_now_local(Item *a) :Item_func_now(a) {}
|
|
const char *func_name() const { return "now"; }
|
|
virtual void store_now_in_TIME(TIME *now_time);
|
|
virtual enum Functype functype() const { return NOW_FUNC; }
|
|
};
|
|
|
|
|
|
class Item_func_now_utc :public Item_func_now
|
|
{
|
|
public:
|
|
Item_func_now_utc() :Item_func_now() {}
|
|
Item_func_now_utc(Item *a) :Item_func_now(a) {}
|
|
const char *func_name() const { return "utc_timestamp"; }
|
|
virtual void store_now_in_TIME(TIME *now_time);
|
|
};
|
|
|
|
|
|
/*
|
|
This is like NOW(), but always uses the real current time, not the
|
|
query_start(). This matches the Oracle behavior.
|
|
*/
|
|
class Item_func_sysdate_local :public Item_func_now
|
|
{
|
|
public:
|
|
Item_func_sysdate_local() :Item_func_now() {}
|
|
Item_func_sysdate_local(Item *a) :Item_func_now(a) {}
|
|
bool const_item() const { return 0; }
|
|
const char *func_name() const { return "sysdate"; }
|
|
void store_now_in_TIME(TIME *now_time);
|
|
double val_real();
|
|
longlong val_int();
|
|
int save_in_field(Field *to, bool no_conversions);
|
|
String *val_str(String *str);
|
|
void fix_length_and_dec();
|
|
bool get_date(TIME *res, uint fuzzy_date);
|
|
void update_used_tables()
|
|
{
|
|
Item_func_now::update_used_tables();
|
|
used_tables_cache|= RAND_TABLE_BIT;
|
|
}
|
|
};
|
|
|
|
|
|
class Item_func_from_days :public Item_date
|
|
{
|
|
public:
|
|
Item_func_from_days(Item *a) :Item_date(a) {}
|
|
const char *func_name() const { return "from_days"; }
|
|
bool get_date(TIME *res, uint fuzzy_date);
|
|
};
|
|
|
|
|
|
class Item_func_date_format :public Item_str_func
|
|
{
|
|
int fixed_length;
|
|
const bool is_time_format;
|
|
String value;
|
|
public:
|
|
Item_func_date_format(Item *a,Item *b,bool is_time_format_arg)
|
|
:Item_str_func(a,b),is_time_format(is_time_format_arg) {}
|
|
String *val_str(String *str);
|
|
const char *func_name() const
|
|
{ return is_time_format ? "time_format" : "date_format"; }
|
|
void fix_length_and_dec();
|
|
uint format_length(const String *format);
|
|
bool eq(const Item *item, bool binary_cmp) const;
|
|
};
|
|
|
|
|
|
class Item_func_from_unixtime :public Item_date_func
|
|
{
|
|
THD *thd;
|
|
public:
|
|
Item_func_from_unixtime(Item *a) :Item_date_func(a) {}
|
|
double val_real()
|
|
{
|
|
DBUG_ASSERT(fixed == 1);
|
|
return (double) Item_func_from_unixtime::val_int();
|
|
}
|
|
longlong val_int();
|
|
String *val_str(String *str);
|
|
const char *func_name() const { return "from_unixtime"; }
|
|
void fix_length_and_dec();
|
|
bool get_date(TIME *res, uint fuzzy_date);
|
|
};
|
|
|
|
|
|
/*
|
|
We need Time_zone class declaration for storing pointers in
|
|
Item_func_convert_tz.
|
|
*/
|
|
class Time_zone;
|
|
|
|
/*
|
|
This class represents CONVERT_TZ() function.
|
|
The important fact about this function that it is handled in special way.
|
|
When such function is met in expression time_zone system tables are added
|
|
to global list of tables to open, so later those already opened and locked
|
|
tables can be used during this function calculation for loading time zone
|
|
descriptions.
|
|
*/
|
|
class Item_func_convert_tz :public Item_date_func
|
|
{
|
|
/* Cached pointer to list of pre-opened time zone tables. */
|
|
TABLE_LIST *tz_tables;
|
|
/*
|
|
If time zone parameters are constants we are caching objects that
|
|
represent them (we use separate from_tz_cached/to_tz_cached members
|
|
to indicate this fact, since NULL is legal value for from_tz/to_tz
|
|
members.
|
|
*/
|
|
bool from_tz_cached, to_tz_cached;
|
|
Time_zone *from_tz, *to_tz;
|
|
public:
|
|
Item_func_convert_tz(Item *a, Item *b, Item *c):
|
|
Item_date_func(a, b, c), from_tz_cached(0), to_tz_cached(0) {}
|
|
longlong val_int();
|
|
double val_real() { return (double) val_int(); }
|
|
String *val_str(String *str);
|
|
const char *func_name() const { return "convert_tz"; }
|
|
bool fix_fields(THD *, Item **);
|
|
void fix_length_and_dec();
|
|
bool get_date(TIME *res, uint fuzzy_date);
|
|
void cleanup();
|
|
};
|
|
|
|
|
|
class Item_func_sec_to_time :public Item_str_func
|
|
{
|
|
public:
|
|
Item_func_sec_to_time(Item *item) :Item_str_func(item) {}
|
|
double val_real()
|
|
{
|
|
DBUG_ASSERT(fixed == 1);
|
|
return (double) Item_func_sec_to_time::val_int();
|
|
}
|
|
longlong val_int();
|
|
String *val_str(String *);
|
|
void fix_length_and_dec()
|
|
{
|
|
collation.set(&my_charset_bin);
|
|
maybe_null=1;
|
|
max_length=MAX_TIME_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
|
|
}
|
|
enum_field_types field_type() const { return MYSQL_TYPE_TIME; }
|
|
const char *func_name() const { return "sec_to_time"; }
|
|
Field *tmp_table_field(TABLE *table)
|
|
{
|
|
return tmp_table_field_from_field_type(table, 0);
|
|
}
|
|
};
|
|
|
|
/*
|
|
The following must be sorted so that simple intervals comes first.
|
|
(get_interval_value() depends on this)
|
|
*/
|
|
|
|
enum interval_type
|
|
{
|
|
INTERVAL_YEAR, INTERVAL_QUARTER, INTERVAL_MONTH, INTERVAL_DAY, INTERVAL_HOUR,
|
|
INTERVAL_MINUTE, INTERVAL_WEEK, INTERVAL_SECOND, INTERVAL_MICROSECOND ,
|
|
INTERVAL_YEAR_MONTH, INTERVAL_DAY_HOUR, INTERVAL_DAY_MINUTE,
|
|
INTERVAL_DAY_SECOND, INTERVAL_HOUR_MINUTE, INTERVAL_HOUR_SECOND,
|
|
INTERVAL_MINUTE_SECOND, INTERVAL_DAY_MICROSECOND, INTERVAL_HOUR_MICROSECOND,
|
|
INTERVAL_MINUTE_MICROSECOND, INTERVAL_SECOND_MICROSECOND
|
|
};
|
|
|
|
class Item_date_add_interval :public Item_date_func
|
|
{
|
|
String value;
|
|
enum_field_types cached_field_type;
|
|
|
|
public:
|
|
const interval_type int_type; // keep it public
|
|
const bool date_sub_interval; // keep it public
|
|
Item_date_add_interval(Item *a,Item *b,interval_type type_arg,bool neg_arg)
|
|
:Item_date_func(a,b),int_type(type_arg), date_sub_interval(neg_arg) {}
|
|
String *val_str(String *);
|
|
const char *func_name() const { return "date_add_interval"; }
|
|
void fix_length_and_dec();
|
|
enum_field_types field_type() const { return cached_field_type; }
|
|
double val_real() { DBUG_ASSERT(fixed == 1); return (double) val_int(); }
|
|
longlong val_int();
|
|
bool get_date(TIME *res, uint fuzzy_date);
|
|
void print(String *str);
|
|
};
|
|
|
|
|
|
class Item_extract :public Item_int_func
|
|
{
|
|
String value;
|
|
bool date_value;
|
|
public:
|
|
const interval_type int_type; // keep it public
|
|
Item_extract(interval_type type_arg, Item *a)
|
|
:Item_int_func(a), int_type(type_arg) {}
|
|
longlong val_int();
|
|
enum Functype functype() const { return EXTRACT_FUNC; }
|
|
const char *func_name() const { return "extract"; }
|
|
void fix_length_and_dec();
|
|
bool eq(const Item *item, bool binary_cmp) const;
|
|
void print(String *str);
|
|
};
|
|
|
|
|
|
class Item_typecast :public Item_str_func
|
|
{
|
|
public:
|
|
Item_typecast(Item *a) :Item_str_func(a) {}
|
|
String *val_str(String *a)
|
|
{
|
|
DBUG_ASSERT(fixed == 1);
|
|
String *tmp=args[0]->val_str(a);
|
|
null_value=args[0]->null_value;
|
|
if (tmp)
|
|
tmp->set_charset(collation.collation);
|
|
return tmp;
|
|
}
|
|
void fix_length_and_dec()
|
|
{
|
|
collation.set(&my_charset_bin);
|
|
max_length=args[0]->max_length;
|
|
}
|
|
virtual const char* cast_type() const= 0;
|
|
void print(String *str);
|
|
};
|
|
|
|
|
|
class Item_typecast_maybe_null :public Item_typecast
|
|
{
|
|
public:
|
|
Item_typecast_maybe_null(Item *a) :Item_typecast(a) {}
|
|
void fix_length_and_dec()
|
|
{
|
|
collation.set(&my_charset_bin);
|
|
max_length=args[0]->max_length;
|
|
maybe_null= 1;
|
|
}
|
|
};
|
|
|
|
|
|
class Item_char_typecast :public Item_typecast
|
|
{
|
|
int cast_length;
|
|
CHARSET_INFO *cast_cs;
|
|
bool charset_conversion;
|
|
String tmp_value;
|
|
public:
|
|
Item_char_typecast(Item *a, int length_arg, CHARSET_INFO *cs_arg)
|
|
:Item_typecast(a), cast_length(length_arg), cast_cs(cs_arg) {}
|
|
enum Functype functype() const { return CHAR_TYPECAST_FUNC; }
|
|
bool eq(const Item *item, bool binary_cmp) const;
|
|
const char *func_name() const { return "cast_as_char"; }
|
|
const char* cast_type() const { return "char"; };
|
|
String *val_str(String *a);
|
|
void fix_length_and_dec();
|
|
void print(String *str);
|
|
};
|
|
|
|
|
|
class Item_date_typecast :public Item_typecast_maybe_null
|
|
{
|
|
public:
|
|
Item_date_typecast(Item *a) :Item_typecast_maybe_null(a) {}
|
|
const char *func_name() const { return "cast_as_date"; }
|
|
String *val_str(String *str);
|
|
bool get_date(TIME *ltime, uint fuzzy_date);
|
|
const char *cast_type() const { return "date"; }
|
|
enum_field_types field_type() const { return MYSQL_TYPE_DATE; }
|
|
Field *tmp_table_field(TABLE *table)
|
|
{
|
|
return tmp_table_field_from_field_type(table, 0);
|
|
}
|
|
void fix_length_and_dec()
|
|
{
|
|
collation.set(&my_charset_bin);
|
|
max_length= 10;
|
|
maybe_null= 1;
|
|
}
|
|
};
|
|
|
|
|
|
class Item_time_typecast :public Item_typecast_maybe_null
|
|
{
|
|
public:
|
|
Item_time_typecast(Item *a) :Item_typecast_maybe_null(a) {}
|
|
const char *func_name() const { return "cast_as_time"; }
|
|
String *val_str(String *str);
|
|
bool get_time(TIME *ltime);
|
|
const char *cast_type() const { return "time"; }
|
|
enum_field_types field_type() const { return MYSQL_TYPE_TIME; }
|
|
Field *tmp_table_field(TABLE *table)
|
|
{
|
|
return tmp_table_field_from_field_type(table, 0);
|
|
}
|
|
};
|
|
|
|
|
|
class Item_datetime_typecast :public Item_typecast_maybe_null
|
|
{
|
|
public:
|
|
Item_datetime_typecast(Item *a) :Item_typecast_maybe_null(a) {}
|
|
const char *func_name() const { return "cast_as_datetime"; }
|
|
String *val_str(String *str);
|
|
const char *cast_type() const { return "datetime"; }
|
|
enum_field_types field_type() const { return MYSQL_TYPE_DATETIME; }
|
|
Field *tmp_table_field(TABLE *table)
|
|
{
|
|
return tmp_table_field_from_field_type(table, 0);
|
|
}
|
|
};
|
|
|
|
class Item_func_makedate :public Item_str_func
|
|
{
|
|
public:
|
|
Item_func_makedate(Item *a,Item *b) :Item_str_func(a,b) {}
|
|
String *val_str(String *str);
|
|
const char *func_name() const { return "makedate"; }
|
|
enum_field_types field_type() const { return MYSQL_TYPE_DATE; }
|
|
void fix_length_and_dec()
|
|
{
|
|
decimals=0;
|
|
max_length=MAX_DATE_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
|
|
}
|
|
Field *tmp_table_field(TABLE *table)
|
|
{
|
|
return tmp_table_field_from_field_type(table, 0);
|
|
}
|
|
};
|
|
|
|
|
|
class Item_func_add_time :public Item_str_func
|
|
{
|
|
const bool is_date;
|
|
int sign;
|
|
enum_field_types cached_field_type;
|
|
|
|
public:
|
|
Item_func_add_time(Item *a, Item *b, bool type_arg, bool neg_arg)
|
|
:Item_str_func(a, b), is_date(type_arg) { sign= neg_arg ? -1 : 1; }
|
|
String *val_str(String *str);
|
|
enum_field_types field_type() const { return cached_field_type; }
|
|
void fix_length_and_dec();
|
|
|
|
Field *tmp_table_field(TABLE *table)
|
|
{
|
|
return tmp_table_field_from_field_type(table, 0);
|
|
}
|
|
void print(String *str);
|
|
const char *func_name() const { return "add_time"; }
|
|
};
|
|
|
|
class Item_func_timediff :public Item_str_func
|
|
{
|
|
public:
|
|
Item_func_timediff(Item *a, Item *b)
|
|
:Item_str_func(a, b) {}
|
|
String *val_str(String *str);
|
|
const char *func_name() const { return "timediff"; }
|
|
enum_field_types field_type() const { return MYSQL_TYPE_TIME; }
|
|
void fix_length_and_dec()
|
|
{
|
|
decimals=0;
|
|
max_length=MAX_TIME_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
|
|
maybe_null= 1;
|
|
}
|
|
Field *tmp_table_field(TABLE *table)
|
|
{
|
|
return tmp_table_field_from_field_type(table, 0);
|
|
}
|
|
};
|
|
|
|
class Item_func_maketime :public Item_str_func
|
|
{
|
|
public:
|
|
Item_func_maketime(Item *a, Item *b, Item *c)
|
|
:Item_str_func(a, b ,c) {}
|
|
String *val_str(String *str);
|
|
const char *func_name() const { return "maketime"; }
|
|
enum_field_types field_type() const { return MYSQL_TYPE_TIME; }
|
|
void fix_length_and_dec()
|
|
{
|
|
decimals=0;
|
|
max_length=MAX_TIME_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
|
|
}
|
|
Field *tmp_table_field(TABLE *table)
|
|
{
|
|
return tmp_table_field_from_field_type(table, 0);
|
|
}
|
|
};
|
|
|
|
class Item_func_microsecond :public Item_int_func
|
|
{
|
|
public:
|
|
Item_func_microsecond(Item *a) :Item_int_func(a) {}
|
|
longlong val_int();
|
|
const char *func_name() const { return "microsecond"; }
|
|
void fix_length_and_dec()
|
|
{
|
|
decimals=0;
|
|
maybe_null=1;
|
|
}
|
|
};
|
|
|
|
|
|
class Item_func_timestamp_diff :public Item_int_func
|
|
{
|
|
const interval_type int_type;
|
|
public:
|
|
Item_func_timestamp_diff(Item *a,Item *b,interval_type type_arg)
|
|
:Item_int_func(a,b), int_type(type_arg) {}
|
|
const char *func_name() const { return "timestampdiff"; }
|
|
longlong val_int();
|
|
void fix_length_and_dec()
|
|
{
|
|
decimals=0;
|
|
maybe_null=1;
|
|
}
|
|
void print(String *str);
|
|
};
|
|
|
|
|
|
enum date_time_format
|
|
{
|
|
USA_FORMAT, JIS_FORMAT, ISO_FORMAT, EUR_FORMAT, INTERNAL_FORMAT
|
|
};
|
|
|
|
class Item_func_get_format :public Item_str_func
|
|
{
|
|
public:
|
|
const timestamp_type type; // keep it public
|
|
Item_func_get_format(timestamp_type type_arg, Item *a)
|
|
:Item_str_func(a), type(type_arg)
|
|
{}
|
|
String *val_str(String *str);
|
|
const char *func_name() const { return "get_format"; }
|
|
void fix_length_and_dec()
|
|
{
|
|
maybe_null= 1;
|
|
decimals=0;
|
|
max_length=17*MY_CHARSET_BIN_MB_MAXLEN;
|
|
}
|
|
void print(String *str);
|
|
};
|
|
|
|
|
|
class Item_func_str_to_date :public Item_str_func
|
|
{
|
|
enum_field_types cached_field_type;
|
|
date_time_format_types cached_format_type;
|
|
timestamp_type cached_timestamp_type;
|
|
bool const_item;
|
|
public:
|
|
Item_func_str_to_date(Item *a, Item *b)
|
|
:Item_str_func(a, b)
|
|
{}
|
|
String *val_str(String *str);
|
|
bool get_date(TIME *ltime, uint fuzzy_date);
|
|
const char *func_name() const { return "str_to_date"; }
|
|
enum_field_types field_type() const { return cached_field_type; }
|
|
void fix_length_and_dec();
|
|
Field *tmp_table_field(TABLE *table)
|
|
{
|
|
return tmp_table_field_from_field_type(table, 1);
|
|
}
|
|
};
|
|
|
|
|
|
class Item_func_last_day :public Item_date
|
|
{
|
|
public:
|
|
Item_func_last_day(Item *a) :Item_date(a) {}
|
|
const char *func_name() const { return "last_day"; }
|
|
bool get_date(TIME *res, uint fuzzy_date);
|
|
};
|