2011-07-04 01:25:49 +02:00
|
|
|
/*
|
2015-07-10 07:52:00 +05:30
|
|
|
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
|
2001-12-06 14:10:51 +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.
|
2001-12-06 14:10:51 +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.
|
2001-12-06 14:10:51 +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
|
2011-06-30 17:46:53 +02:00
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
|
2005-05-26 12:09:14 +02:00
|
|
|
#ifdef USE_PRAGMA_IMPLEMENTATION
|
2000-07-31 21:29:14 +02:00
|
|
|
#pragma implementation // gcc: Class implementation
|
|
|
|
#endif
|
2010-04-07 13:58:40 +02:00
|
|
|
#include "my_global.h" /* NO_EMBEDDED_ACCESS_CHECKS */
|
2010-03-31 16:05:33 +02:00
|
|
|
#include "sql_priv.h"
|
|
|
|
#include "unireg.h" // REQUIRED: for other includes
|
2008-02-18 18:21:14 +02:00
|
|
|
#include <mysql.h>
|
2000-07-31 21:29:14 +02:00
|
|
|
#include <m_ctype.h>
|
|
|
|
#include "my_dir.h"
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
2002-12-08 19:59:22 +01:00
|
|
|
#include "sp_rcontext.h"
|
2004-09-07 16:29:46 +04:00
|
|
|
#include "sp_head.h"
|
|
|
|
#include "sql_trigger.h"
|
2004-10-28 17:31:26 +03:00
|
|
|
#include "sql_select.h"
|
2010-03-31 16:05:33 +02:00
|
|
|
#include "sql_show.h" // append_identifier
|
|
|
|
#include "sql_view.h" // VIEW_ANY_SQL
|
|
|
|
#include "sql_time.h" // str_to_datetime_with_warn,
|
|
|
|
// make_truncated_value_warning
|
|
|
|
#include "sql_acl.h" // get_column_grant,
|
|
|
|
// SELECT_ACL, UPDATE_ACL,
|
|
|
|
// INSERT_ACL,
|
|
|
|
// check_grant_column
|
|
|
|
#include "sql_base.h" // enum_resolution_type,
|
|
|
|
// REPORT_EXCEPT_NOT_FOUND,
|
|
|
|
// find_item_in_list,
|
|
|
|
// RESOLVED_AGAINST_ALIAS, ...
|
|
|
|
#include "log_event.h" // append_query_string
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2004-05-25 02:03:49 +04:00
|
|
|
const String my_null_string("NULL", 4, default_charset_info);
|
|
|
|
|
2005-03-13 23:50:43 +03:00
|
|
|
/****************************************************************************/
|
|
|
|
|
|
|
|
/* Hybrid_type_traits {_real} */
|
|
|
|
|
|
|
|
void Hybrid_type_traits::fix_length_and_dec(Item *item, Item *arg) const
|
|
|
|
{
|
|
|
|
item->decimals= NOT_FIXED_DEC;
|
|
|
|
item->max_length= item->float_length(arg->decimals);
|
|
|
|
}
|
|
|
|
|
2005-04-27 11:25:08 +02:00
|
|
|
static const Hybrid_type_traits real_traits_instance;
|
2005-03-13 23:50:43 +03:00
|
|
|
|
|
|
|
const Hybrid_type_traits *Hybrid_type_traits::instance()
|
|
|
|
{
|
2005-04-27 11:25:08 +02:00
|
|
|
return &real_traits_instance;
|
2005-03-13 23:50:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
my_decimal *
|
|
|
|
Hybrid_type_traits::val_decimal(Hybrid_type *val, my_decimal *to) const
|
|
|
|
{
|
|
|
|
double2my_decimal(E_DEC_FATAL_ERROR, val->real, val->dec_buf);
|
|
|
|
return val->dec_buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String *
|
|
|
|
Hybrid_type_traits::val_str(Hybrid_type *val, String *to, uint8 decimals) const
|
|
|
|
{
|
2006-06-16 12:17:20 +02:00
|
|
|
to->set_real(val->real, decimals, &my_charset_bin);
|
2005-03-13 23:50:43 +03:00
|
|
|
return to;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Hybrid_type_traits_decimal */
|
2005-04-27 11:25:08 +02:00
|
|
|
static const Hybrid_type_traits_decimal decimal_traits_instance;
|
2005-03-13 23:50:43 +03:00
|
|
|
|
|
|
|
const Hybrid_type_traits_decimal *Hybrid_type_traits_decimal::instance()
|
|
|
|
{
|
2005-04-27 11:25:08 +02:00
|
|
|
return &decimal_traits_instance;
|
2005-03-13 23:50:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
Hybrid_type_traits_decimal::fix_length_and_dec(Item *item, Item *arg) const
|
|
|
|
{
|
|
|
|
item->decimals= arg->decimals;
|
|
|
|
item->max_length= min(arg->max_length + DECIMAL_LONGLONG_DIGITS,
|
2005-05-05 20:06:49 +05:00
|
|
|
DECIMAL_MAX_STR_LENGTH);
|
2005-03-13 23:50:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Hybrid_type_traits_decimal::set_zero(Hybrid_type *val) const
|
|
|
|
{
|
|
|
|
my_decimal_set_zero(&val->dec_buf[0]);
|
|
|
|
val->used_dec_buf_no= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Hybrid_type_traits_decimal::add(Hybrid_type *val, Field *f) const
|
|
|
|
{
|
|
|
|
my_decimal_add(E_DEC_FATAL_ERROR,
|
|
|
|
&val->dec_buf[val->used_dec_buf_no ^ 1],
|
|
|
|
&val->dec_buf[val->used_dec_buf_no],
|
|
|
|
f->val_decimal(&val->dec_buf[2]));
|
|
|
|
val->used_dec_buf_no^= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
|
|
|
@todo
|
|
|
|
what is '4' for scale?
|
|
|
|
*/
|
2005-03-13 23:50:43 +03:00
|
|
|
void Hybrid_type_traits_decimal::div(Hybrid_type *val, ulonglong u) const
|
|
|
|
{
|
|
|
|
int2my_decimal(E_DEC_FATAL_ERROR, u, TRUE, &val->dec_buf[2]);
|
|
|
|
/* XXX: what is '4' for scale? */
|
|
|
|
my_decimal_div(E_DEC_FATAL_ERROR,
|
|
|
|
&val->dec_buf[val->used_dec_buf_no ^ 1],
|
|
|
|
&val->dec_buf[val->used_dec_buf_no],
|
|
|
|
&val->dec_buf[2], 4);
|
|
|
|
val->used_dec_buf_no^= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
longlong
|
|
|
|
Hybrid_type_traits_decimal::val_int(Hybrid_type *val, bool unsigned_flag) const
|
|
|
|
{
|
|
|
|
longlong result;
|
|
|
|
my_decimal2int(E_DEC_FATAL_ERROR, &val->dec_buf[val->used_dec_buf_no],
|
|
|
|
unsigned_flag, &result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double
|
|
|
|
Hybrid_type_traits_decimal::val_real(Hybrid_type *val) const
|
|
|
|
{
|
|
|
|
my_decimal2double(E_DEC_FATAL_ERROR, &val->dec_buf[val->used_dec_buf_no],
|
|
|
|
&val->real);
|
|
|
|
return val->real;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String *
|
|
|
|
Hybrid_type_traits_decimal::val_str(Hybrid_type *val, String *to,
|
|
|
|
uint8 decimals) const
|
|
|
|
{
|
|
|
|
my_decimal_round(E_DEC_FATAL_ERROR, &val->dec_buf[val->used_dec_buf_no],
|
|
|
|
decimals, FALSE, &val->dec_buf[2]);
|
|
|
|
my_decimal2string(E_DEC_FATAL_ERROR, &val->dec_buf[2], 0, 0, 0, to);
|
|
|
|
return to;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Hybrid_type_traits_integer */
|
2005-04-27 11:25:08 +02:00
|
|
|
static const Hybrid_type_traits_integer integer_traits_instance;
|
2005-03-13 23:50:43 +03:00
|
|
|
|
|
|
|
const Hybrid_type_traits_integer *Hybrid_type_traits_integer::instance()
|
|
|
|
{
|
2005-04-27 11:25:08 +02:00
|
|
|
return &integer_traits_instance;
|
2005-03-13 23:50:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Hybrid_type_traits_integer::fix_length_and_dec(Item *item, Item *arg) const
|
|
|
|
{
|
|
|
|
item->decimals= 0;
|
2007-03-09 08:05:08 +03:00
|
|
|
item->max_length= MY_INT64_NUM_DECIMAL_DIGITS;
|
2005-03-13 23:50:43 +03:00
|
|
|
item->unsigned_flag= 0;
|
|
|
|
}
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
** Item functions
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
|
|
|
Init all special items.
|
|
|
|
*/
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
void item_init(void)
|
|
|
|
{
|
|
|
|
item_user_lock_init();
|
2007-04-27 01:12:09 +03:00
|
|
|
uuid_short_init();
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2005-02-09 02:50:45 +04:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
|
|
|
@todo
|
|
|
|
Make this functions class dependent
|
2005-02-09 02:50:45 +04:00
|
|
|
*/
|
2005-02-15 16:45:00 +02:00
|
|
|
|
2005-02-09 02:50:45 +04:00
|
|
|
bool Item::val_bool()
|
|
|
|
{
|
2005-02-15 16:45:00 +02:00
|
|
|
switch(result_type()) {
|
2005-02-09 02:50:45 +04:00
|
|
|
case INT_RESULT:
|
2005-03-18 16:12:25 -08:00
|
|
|
return val_int() != 0;
|
2005-02-09 02:50:45 +04:00
|
|
|
case DECIMAL_RESULT:
|
|
|
|
{
|
|
|
|
my_decimal decimal_value;
|
|
|
|
my_decimal *val= val_decimal(&decimal_value);
|
|
|
|
if (val)
|
|
|
|
return !my_decimal_is_zero(val);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case REAL_RESULT:
|
|
|
|
case STRING_RESULT:
|
|
|
|
return val_real() != 0.0;
|
|
|
|
case ROW_RESULT:
|
|
|
|
default:
|
|
|
|
DBUG_ASSERT(0);
|
2005-02-15 16:45:00 +02:00
|
|
|
return 0; // Wrong (but safe)
|
2005-02-09 02:50:45 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
WL#2649 Number-to-string conversions
added:
include/ctype_numconv.inc
mysql-test/include/ctype_numconv.inc
mysql-test/r/ctype_binary.result
mysql-test/t/ctype_binary.test
Adding tests
modified:
mysql-test/r/bigint.result
mysql-test/r/case.result
mysql-test/r/create.result
mysql-test/r/ctype_cp1251.result
mysql-test/r/ctype_latin1.result
mysql-test/r/ctype_ucs.result
mysql-test/r/func_gconcat.result
mysql-test/r/func_str.result
mysql-test/r/metadata.result
mysql-test/r/ps_1general.result
mysql-test/r/ps_2myisam.result
mysql-test/r/ps_3innodb.result
mysql-test/r/ps_4heap.result
mysql-test/r/ps_5merge.result
mysql-test/r/show_check.result
mysql-test/r/type_datetime.result
mysql-test/r/type_ranges.result
mysql-test/r/union.result
mysql-test/suite/ndb/r/ps_7ndb.result
mysql-test/t/ctype_cp1251.test
mysql-test/t/ctype_latin1.test
mysql-test/t/ctype_ucs.test
mysql-test/t/func_str.test
Fixing tests
@ sql/field.cc
- Return str result using my_charset_numeric.
- Using real multi-byte aware str_to_XXX functions
to handle tricky charset values propely (e.g. UCS2)
@ sql/field.h
- Changing derivation of non-string field types to DERIVATION_NUMERIC.
- Changing binary() for numeric/datetime fields to always
return TRUE even if charset is not my_charset_bin. We need
this to keep ha_base_keytype() return HA_KEYTYPE_BINARY.
- Adding BINARY_FLAG into some fields, because it's not
being set automatically anymore with
"my_charset_bin to my_charset_numeric" change.
- Changing derivation for numeric/datetime datatypes to a weaker
value, to make "SELECT concat('string', field)" use character
set of the string literal for the result of the function.
@ sql/item.cc
- Implementing generic val_str_ascii().
- Using max_char_length() instead of direct read of max_length
to make "tricky" charsets like UCS2 work.
NOTE: in the future we'll possibly remove all direct reads of max_length
- Fixing Item_num::safe_charset_converter().
Previously it alligned binary string to
character string (for example by adding leading 0x00
when doing binary->UCS2 conversion). Now it just
converts from my_charset_numbner to "tocs".
- Using val_str_ascii() in Item::get_time() to make UCS2 arguments work.
- Other misc changes
@ sql/item.h
- Changing MY_COLL_CMP_CONV and MY_COLL_ALLOW_CONV to
bit operations instead of hard-coded bit masks.
- Addding new method DTCollation.set_numeric().
- Adding new methods to Item.
- Adding helper functions to make code look nicer:
agg_item_charsets_for_string_result()
agg_item_charsets_for_comparison()
- Changing charset for Item_num-derived items
from my_charset_bin to my_charset_numeric
(which is an alias for latin1).
@ sql/item_cmpfunc.cc
- Using new helper functions
- Other misc changes
@ sql/item_cmpfunc.h
- Fixing strcmp() to return max_length=2.
Previously it returned 1, which was wrong,
because it did not fit '-1'.
@ sql/item_func.cc
- Using new helper functions
- Other minor changes
@ sql/item_func.h
- Removing unused functions
- Adding helper functions
agg_arg_charsets_for_string_result()
agg_arg_charsets_for_comparison()
- Adding set_numeric() into constructors of numeric items.
- Using fix_length_and_charset() and fix_char_length()
instead of direct write to max_length.
@ sql/item_geofunc.cc
- Changing class for Item_func_geometry_type and
Item_func_as_wkt from Item_str_func to
Item_str_ascii_func, to make them return UCS2 result
properly (when character_set_connection=ucs2).
@ sql/item_geofunc.h
- Changing class for Item_func_geometry_type and
Item_func_as_wkt from Item_str_func to
Item_str_ascii_func, to make them return UCS2 result
properly (when @@character_set_connection=ucs2).
@ sql/item_strfunc.cc
- Implementing Item_str_func::val_str().
- Renaming val_str to val_str_ascii for some items,
to make them work with UCS2 properly.
- Using new helper functions
- All single-argument functions that expect string
result now call this method:
agg_arg_charsets_for_string_result(collation, args, 1);
This enables character set conversion to @@character_set_connection
in case of pure numeric input.
@ sql/item_strfunc.h
- Introducing Item_str_ascii_func - for functions
which return pure ASCII data, for performance purposes,
as well as for the cases when the old implementation
of val_str() was heavily 8-bit oriented and implementing
a UCS2-aware version is tricky.
@ sql/item_sum.cc
- Using new helper functions.
@ sql/item_timefunc.cc
- Using my_charset_numeric instead of my_charset_bin.
- Using fix_char_length(), fix_length_and_charset()
and fix_length_and_charset_datetime()
instead of direct write to max_length.
- Using tricky-charset aware function str_to_time_with_warn()
@ sql/item_timefunc.h
- Using new helper functions for charset and length initialization.
- Changing base class for Item_func_get_format() to make
it return UCS2 properly (when character_set_connection=ucs2).
@ sql/item_xmlfunc.cc
- Using new helper function
@ sql/my_decimal.cc
- Adding a new DECIMAL to CHAR converter
with real multibyte support (e.g. UCS2)
@ sql/mysql_priv.h
- Introducing a new derivation level for numeric/datetime data types.
- Adding macros for my_charset_numeric and MY_REPERTOIRE_NUMERIC.
- Adding prototypes for str_set_decimal()
- Adding prototypes for character-set aware str_to_xxx() functions.
@ sql/protocol.cc
- Changing charsetnr to "binary" client-side metadata for
numeric/datetime data types.
@ sql/time.cc
- Adding to_ascii() helper function, to convert a string
in any character set to ascii representation. In the
future can be extended to understand digits written
in various non-Latin word scripts.
- Adding real multy-byte character set aware versions for str_to_XXXX,
to make these these type of queries work correct:
INSERT INTO t1 SET datetime_column=ucs2_expression;
@ strings/ctype-ucs2.c
- endptr was not calculated correctly. INSERTing of UCS2
values into numeric columns returned warnings about
truncated wrong data.
2010-02-11 08:17:25 +04:00
|
|
|
/*
|
|
|
|
For the items which don't have its own fast val_str_ascii()
|
|
|
|
implementation we provide a generic slower version,
|
|
|
|
which converts from the Item character set to ASCII.
|
|
|
|
For better performance conversion happens only in
|
|
|
|
case of a "tricky" Item character set (e.g. UCS2).
|
|
|
|
Normally conversion does not happen.
|
|
|
|
*/
|
|
|
|
String *Item::val_str_ascii(String *str)
|
|
|
|
{
|
|
|
|
if (!(collation.collation->state & MY_CS_NONASCII))
|
|
|
|
return val_str(str);
|
|
|
|
|
|
|
|
DBUG_ASSERT(str != &str_value);
|
|
|
|
|
|
|
|
uint errors;
|
|
|
|
String *res= val_str(&str_value);
|
|
|
|
if (!res)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if ((null_value= str->copy(res->ptr(), res->length(),
|
|
|
|
collation.collation, &my_charset_latin1,
|
|
|
|
&errors)))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-19 18:58:27 +02:00
|
|
|
String *Item::val_string_from_real(String *str)
|
|
|
|
{
|
|
|
|
double nr= val_real();
|
|
|
|
if (null_value)
|
|
|
|
return 0; /* purecov: inspected */
|
2006-06-16 12:17:20 +02:00
|
|
|
str->set_real(nr,decimals, &my_charset_bin);
|
2005-02-19 18:58:27 +02:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String *Item::val_string_from_int(String *str)
|
|
|
|
{
|
|
|
|
longlong nr= val_int();
|
|
|
|
if (null_value)
|
|
|
|
return 0;
|
2006-06-16 12:17:20 +02:00
|
|
|
str->set_int(nr, unsigned_flag, &my_charset_bin);
|
2005-02-19 18:58:27 +02:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String *Item::val_string_from_decimal(String *str)
|
|
|
|
{
|
|
|
|
my_decimal dec_buf, *dec= val_decimal(&dec_buf);
|
|
|
|
if (null_value)
|
|
|
|
return 0;
|
|
|
|
my_decimal_round(E_DEC_FATAL_ERROR, dec, decimals, FALSE, &dec_buf);
|
|
|
|
my_decimal2string(E_DEC_FATAL_ERROR, &dec_buf, 0, 0, 0, str);
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
my_decimal *Item::val_decimal_from_real(my_decimal *decimal_value)
|
|
|
|
{
|
|
|
|
double nr= val_real();
|
|
|
|
if (null_value)
|
|
|
|
return 0;
|
|
|
|
double2my_decimal(E_DEC_FATAL_ERROR, nr, decimal_value);
|
|
|
|
return (decimal_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
my_decimal *Item::val_decimal_from_int(my_decimal *decimal_value)
|
|
|
|
{
|
|
|
|
longlong nr= val_int();
|
|
|
|
if (null_value)
|
|
|
|
return 0;
|
|
|
|
int2my_decimal(E_DEC_FATAL_ERROR, nr, unsigned_flag, decimal_value);
|
|
|
|
return decimal_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
my_decimal *Item::val_decimal_from_string(my_decimal *decimal_value)
|
|
|
|
{
|
|
|
|
String *res;
|
2010-07-20 15:07:36 -03:00
|
|
|
|
2005-02-19 18:58:27 +02:00
|
|
|
if (!(res= val_str(&str_value)))
|
2010-07-20 15:07:36 -03:00
|
|
|
return NULL;
|
2005-02-19 18:58:27 +02:00
|
|
|
|
2005-04-06 15:49:55 +05:00
|
|
|
if (str2my_decimal(E_DEC_FATAL_ERROR & ~E_DEC_BAD_NUM,
|
|
|
|
res->ptr(), res->length(), res->charset(),
|
|
|
|
decimal_value) & E_DEC_BAD_NUM)
|
|
|
|
{
|
2009-10-15 17:23:43 +05:00
|
|
|
ErrConvString err(res);
|
2005-04-06 15:49:55 +05:00
|
|
|
push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
|
|
|
|
ER_TRUNCATED_WRONG_VALUE,
|
|
|
|
ER(ER_TRUNCATED_WRONG_VALUE), "DECIMAL",
|
2009-10-15 17:23:43 +05:00
|
|
|
err.ptr());
|
2005-04-06 15:49:55 +05:00
|
|
|
}
|
2005-02-19 18:58:27 +02:00
|
|
|
return decimal_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-25 20:14:39 +05:00
|
|
|
my_decimal *Item::val_decimal_from_date(my_decimal *decimal_value)
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(fixed == 1);
|
2007-03-23 22:08:31 +02:00
|
|
|
MYSQL_TIME ltime;
|
2006-10-25 20:14:39 +05:00
|
|
|
if (get_date(<ime, TIME_FUZZY_DATE))
|
|
|
|
{
|
|
|
|
my_decimal_set_zero(decimal_value);
|
2007-10-05 12:08:38 +02:00
|
|
|
null_value= 1; // set NULL, stop processing
|
2006-10-25 20:14:39 +05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return date2my_decimal(<ime, decimal_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
my_decimal *Item::val_decimal_from_time(my_decimal *decimal_value)
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(fixed == 1);
|
2007-03-23 22:08:31 +02:00
|
|
|
MYSQL_TIME ltime;
|
2006-10-25 20:14:39 +05:00
|
|
|
if (get_time(<ime))
|
|
|
|
{
|
|
|
|
my_decimal_set_zero(decimal_value);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return date2my_decimal(<ime, decimal_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-19 18:58:27 +02:00
|
|
|
double Item::val_real_from_decimal()
|
|
|
|
{
|
|
|
|
/* Note that fix_fields may not be called for Item_avg_field items */
|
|
|
|
double result;
|
|
|
|
my_decimal value_buff, *dec_val= val_decimal(&value_buff);
|
|
|
|
if (null_value)
|
|
|
|
return 0.0;
|
|
|
|
my_decimal2double(E_DEC_FATAL_ERROR, dec_val, &result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
longlong Item::val_int_from_decimal()
|
|
|
|
{
|
|
|
|
/* Note that fix_fields may not be called for Item_avg_field items */
|
|
|
|
longlong result;
|
|
|
|
my_decimal value, *dec_val= val_decimal(&value);
|
|
|
|
if (null_value)
|
|
|
|
return 0;
|
|
|
|
my_decimal2int(E_DEC_FATAL_ERROR, dec_val, unsigned_flag, &result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2006-10-25 20:14:39 +05:00
|
|
|
int Item::save_time_in_field(Field *field)
|
|
|
|
{
|
2007-03-23 22:08:31 +02:00
|
|
|
MYSQL_TIME ltime;
|
2006-10-25 20:14:39 +05:00
|
|
|
if (get_time(<ime))
|
2009-01-30 17:12:24 +01:00
|
|
|
return set_field_to_null_with_conversions(field, 0);
|
2006-10-25 20:14:39 +05:00
|
|
|
field->set_notnull();
|
|
|
|
return field->store_time(<ime, MYSQL_TIMESTAMP_TIME);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Item::save_date_in_field(Field *field)
|
|
|
|
{
|
2007-03-23 22:08:31 +02:00
|
|
|
MYSQL_TIME ltime;
|
2006-10-25 20:14:39 +05:00
|
|
|
if (get_date(<ime, TIME_FUZZY_DATE))
|
2009-01-30 17:12:24 +01:00
|
|
|
return set_field_to_null_with_conversions(field, 0);
|
2006-10-25 20:14:39 +05:00
|
|
|
field->set_notnull();
|
|
|
|
return field->store_time(<ime, MYSQL_TIMESTAMP_DATETIME);
|
|
|
|
}
|
|
|
|
|
2005-02-19 18:58:27 +02:00
|
|
|
|
2007-07-27 18:42:25 +05:00
|
|
|
/*
|
|
|
|
Store the string value in field directly
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
Item::save_str_value_in_field()
|
|
|
|
field a pointer to field where to store
|
|
|
|
result the pointer to the string value to be stored
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
The method is used by Item_*::save_in_field implementations
|
|
|
|
when we don't need to calculate the value to store
|
|
|
|
See Item_string::save_in_field() implementation for example
|
|
|
|
|
|
|
|
IMPLEMENTATION
|
|
|
|
Check if the Item is null and stores the NULL or the
|
|
|
|
result value in the field accordingly.
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
Nonzero value if error
|
|
|
|
*/
|
|
|
|
|
|
|
|
int Item::save_str_value_in_field(Field *field, String *result)
|
|
|
|
{
|
|
|
|
if (null_value)
|
|
|
|
return set_field_to_null(field);
|
|
|
|
field->set_notnull();
|
|
|
|
return field->store(result->ptr(), result->length(),
|
|
|
|
collation.collation);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-21 11:01:33 +02:00
|
|
|
Item::Item():
|
2005-05-23 23:43:43 +02:00
|
|
|
rsize(0), name(0), orig_name(0), name_length(0), fixed(0),
|
2005-06-21 20:30:48 +03:00
|
|
|
is_autogenerated_name(TRUE),
|
2005-01-18 22:12:33 +04:00
|
|
|
collation(&my_charset_bin, DERIVATION_COERCIBLE)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2003-01-30 18:07:39 +02:00
|
|
|
marker= 0;
|
2002-10-25 13:58:32 +05:00
|
|
|
maybe_null=null_value=with_sum_func=unsigned_flag=0;
|
2003-01-30 18:07:39 +02:00
|
|
|
decimals= 0; max_length= 0;
|
2006-05-18 00:55:28 +04:00
|
|
|
with_subselect= 0;
|
2006-08-23 01:03:28 +04:00
|
|
|
cmp_context= (Item_result)-1;
|
2003-11-03 14:01:59 +02:00
|
|
|
|
|
|
|
/* Put item in free list so that we can free all items at end */
|
|
|
|
THD *thd= current_thd;
|
2005-05-18 17:10:48 -07:00
|
|
|
next= thd->free_list;
|
|
|
|
thd->free_list= this;
|
2003-07-02 14:45:35 +03:00
|
|
|
/*
|
2003-08-19 16:00:12 +03:00
|
|
|
Item constructor can be called during execution other then SQL_COM
|
2003-12-19 20:52:13 +03:00
|
|
|
command => we should check thd->lex->current_select on zero (thd->lex
|
2003-07-02 15:03:49 +03:00
|
|
|
can be uninitialised)
|
2003-07-02 14:45:35 +03:00
|
|
|
*/
|
2003-08-26 17:41:40 +02:00
|
|
|
if (thd->lex->current_select)
|
2003-07-29 13:00:32 +03:00
|
|
|
{
|
2004-08-13 10:01:30 +03:00
|
|
|
enum_parsing_place place=
|
2003-08-26 11:51:09 +02:00
|
|
|
thd->lex->current_select->parsing_place;
|
2004-08-13 10:01:30 +03:00
|
|
|
if (place == SELECT_LIST ||
|
|
|
|
place == IN_HAVING)
|
2003-08-26 11:51:09 +02:00
|
|
|
thd->lex->current_select->select_n_having_items++;
|
2003-07-29 13:00:32 +03:00
|
|
|
}
|
2002-11-14 00:26:18 +02:00
|
|
|
}
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
|
|
|
Constructor used by Item_field, Item_ref & aggregate (sum)
|
|
|
|
functions.
|
|
|
|
|
2003-01-30 18:07:39 +02:00
|
|
|
Used for duplicating lists in processing queries with temporary
|
2007-10-11 13:29:09 -04:00
|
|
|
tables.
|
2003-01-30 18:07:39 +02:00
|
|
|
*/
|
2004-01-19 19:53:25 +04:00
|
|
|
Item::Item(THD *thd, Item *item):
|
2005-05-23 23:43:43 +02:00
|
|
|
rsize(0),
|
2004-01-19 19:53:25 +04:00
|
|
|
str_value(item->str_value),
|
|
|
|
name(item->name),
|
2004-09-14 19:28:29 +03:00
|
|
|
orig_name(item->orig_name),
|
2004-01-19 19:53:25 +04:00
|
|
|
max_length(item->max_length),
|
2009-06-04 12:52:40 +03:00
|
|
|
name_length(item->name_length),
|
2004-01-19 19:53:25 +04:00
|
|
|
marker(item->marker),
|
|
|
|
decimals(item->decimals),
|
|
|
|
maybe_null(item->maybe_null),
|
|
|
|
null_value(item->null_value),
|
|
|
|
unsigned_flag(item->unsigned_flag),
|
|
|
|
with_sum_func(item->with_sum_func),
|
|
|
|
fixed(item->fixed),
|
2009-06-04 12:52:40 +03:00
|
|
|
is_autogenerated_name(item->is_autogenerated_name),
|
2006-08-23 01:03:28 +04:00
|
|
|
collation(item->collation),
|
Bug #11827369: ASSERTION FAILED: !THD->LEX->CONTEXT_ANALYSIS_ONLY
Some queries with the "SELECT ... FROM DUAL" nested subqueries
failed with an assertion on debug builds.
Non-debug builds were not affected.
There were a few different issues with similar assertion
failures on different queries:
1. The first problem was related to the incomplete propagation
of the "non-constant" item status from underlying subquery
items to the outer item tree: in some cases non-constants were
interpreted as constants and evaluated at the preparation stage
(val_int() calls withing fix_fields() etc).
Thus, the default implementation of Item_ref::const_item() from
the Item parent class didn't take into account the "const_item"
status of the referenced item tree -- it used the insufficient
"used_tables() == 0" check instead. This worked in most cases
since our "non-constant" functions like RAND() and SLEEP() set
the RAND_TABLE_BIT in the used table map, so they aren't
non-constant from Item_ref's "point of view". However, the
"SELECT ... FROM DUAL" subquery may have an empty map of used
tables, but at the same time subqueries are never "constant" at
the context analysis stage (preparation, view creation etc).
So, the non-contantness of such subqueries was missed.
Fix: the Item_ref::const_item() function has been overloaded to
take into account both (*ref)->const_item() status and tricky
Item_ref::used_tables() return values, since the only
(*ref)->const_item() call is not enough there.
2. In some cases instead of the const_item() call we check a
value of the Item::with_subselect field to recognize items
with nested subqueries. However, the Item_ref class didn't
propagate this value from the referenced item tree.
Fix: Item::has_subquery() and Item_ref::has_subquery()
functions have been backported from 5.6. All direct
references to the with_subselect fields of nested items have
been with the has_subquery() function call.
3. The Item_func_regex class didn't propagate with_subselect
as well, since it overloads the Item_func::fix_fields()
function with insufficient fix_fields() implementation.
Fix: the Item_func_regex::fix_fields() function has been
modified to gather "constant" statuses from inner items.
4. The Item_func_isnull::update_used_tables() function has
a special branch for the underlying item where the maybe_null
value is false: in this case it marks the Item_func_isnull
as a "const_item" and sets the cached_value to false.
However, the Item_func_isnull::val_int() was not in sync with
update_used_tables(): it didn't take into account neither
const_item_cache nor cached_value for the case of
"args[0]->maybe_null == false optimization".
As far as such an Item_func_isnull has "const_item() == true",
it's ok to call Item_func_isnull::val_int() etc from outer
items on preparation stage. In this case the server tried to
call Item_func_isnull::args[0]->isnull(), and if the args[0]
item contained a nested not-nullable subquery, it failed
with an assertion.
Fix: take the value of Item_func_isnull::const_item_cache into
account in the val_int() function.
5. The auxiliary Item_is_not_null_test class has a similar
optimization in the update_used_tables() function as the
Item_func_isnull class has, and the same issue in the val_int()
function.
In addition to that the Item_is_not_null_test::update_used_tables()
doesn't update the const_item_cache value, so the "maybe_null"
optimization is useless there. Thus, we missed some optimizations
of cases like these (before and after the fix):
< <is_not_null_test>(a),
---
> <cache>(<is_not_null_test>(a)),
or
< having (<is_not_null_test>(a) and <is_not_null_test>(a))
---
> having 1
etc.
Fix: update Item_is_not_null_test::const_item_cache in
update_used_tables() and take in into account in val_int().
2013-01-23 09:51:50 +04:00
|
|
|
with_subselect(item->has_subquery()),
|
2006-08-23 01:03:28 +04:00
|
|
|
cmp_context(item->cmp_context)
|
2003-01-25 02:25:52 +02:00
|
|
|
{
|
2005-05-18 17:10:48 -07:00
|
|
|
next= thd->free_list; // Put in free list
|
|
|
|
thd->free_list= this;
|
2003-01-25 02:25:52 +02:00
|
|
|
}
|
|
|
|
|
2003-10-16 15:54:47 +03:00
|
|
|
|
2005-05-05 20:06:49 +05:00
|
|
|
uint Item::decimal_precision() const
|
|
|
|
{
|
|
|
|
Item_result restype= result_type();
|
|
|
|
|
|
|
|
if ((restype == DECIMAL_RESULT) || (restype == INT_RESULT))
|
2009-11-02 09:21:39 -02:00
|
|
|
{
|
|
|
|
uint prec=
|
WL#2649 Number-to-string conversions
added:
include/ctype_numconv.inc
mysql-test/include/ctype_numconv.inc
mysql-test/r/ctype_binary.result
mysql-test/t/ctype_binary.test
Adding tests
modified:
mysql-test/r/bigint.result
mysql-test/r/case.result
mysql-test/r/create.result
mysql-test/r/ctype_cp1251.result
mysql-test/r/ctype_latin1.result
mysql-test/r/ctype_ucs.result
mysql-test/r/func_gconcat.result
mysql-test/r/func_str.result
mysql-test/r/metadata.result
mysql-test/r/ps_1general.result
mysql-test/r/ps_2myisam.result
mysql-test/r/ps_3innodb.result
mysql-test/r/ps_4heap.result
mysql-test/r/ps_5merge.result
mysql-test/r/show_check.result
mysql-test/r/type_datetime.result
mysql-test/r/type_ranges.result
mysql-test/r/union.result
mysql-test/suite/ndb/r/ps_7ndb.result
mysql-test/t/ctype_cp1251.test
mysql-test/t/ctype_latin1.test
mysql-test/t/ctype_ucs.test
mysql-test/t/func_str.test
Fixing tests
@ sql/field.cc
- Return str result using my_charset_numeric.
- Using real multi-byte aware str_to_XXX functions
to handle tricky charset values propely (e.g. UCS2)
@ sql/field.h
- Changing derivation of non-string field types to DERIVATION_NUMERIC.
- Changing binary() for numeric/datetime fields to always
return TRUE even if charset is not my_charset_bin. We need
this to keep ha_base_keytype() return HA_KEYTYPE_BINARY.
- Adding BINARY_FLAG into some fields, because it's not
being set automatically anymore with
"my_charset_bin to my_charset_numeric" change.
- Changing derivation for numeric/datetime datatypes to a weaker
value, to make "SELECT concat('string', field)" use character
set of the string literal for the result of the function.
@ sql/item.cc
- Implementing generic val_str_ascii().
- Using max_char_length() instead of direct read of max_length
to make "tricky" charsets like UCS2 work.
NOTE: in the future we'll possibly remove all direct reads of max_length
- Fixing Item_num::safe_charset_converter().
Previously it alligned binary string to
character string (for example by adding leading 0x00
when doing binary->UCS2 conversion). Now it just
converts from my_charset_numbner to "tocs".
- Using val_str_ascii() in Item::get_time() to make UCS2 arguments work.
- Other misc changes
@ sql/item.h
- Changing MY_COLL_CMP_CONV and MY_COLL_ALLOW_CONV to
bit operations instead of hard-coded bit masks.
- Addding new method DTCollation.set_numeric().
- Adding new methods to Item.
- Adding helper functions to make code look nicer:
agg_item_charsets_for_string_result()
agg_item_charsets_for_comparison()
- Changing charset for Item_num-derived items
from my_charset_bin to my_charset_numeric
(which is an alias for latin1).
@ sql/item_cmpfunc.cc
- Using new helper functions
- Other misc changes
@ sql/item_cmpfunc.h
- Fixing strcmp() to return max_length=2.
Previously it returned 1, which was wrong,
because it did not fit '-1'.
@ sql/item_func.cc
- Using new helper functions
- Other minor changes
@ sql/item_func.h
- Removing unused functions
- Adding helper functions
agg_arg_charsets_for_string_result()
agg_arg_charsets_for_comparison()
- Adding set_numeric() into constructors of numeric items.
- Using fix_length_and_charset() and fix_char_length()
instead of direct write to max_length.
@ sql/item_geofunc.cc
- Changing class for Item_func_geometry_type and
Item_func_as_wkt from Item_str_func to
Item_str_ascii_func, to make them return UCS2 result
properly (when character_set_connection=ucs2).
@ sql/item_geofunc.h
- Changing class for Item_func_geometry_type and
Item_func_as_wkt from Item_str_func to
Item_str_ascii_func, to make them return UCS2 result
properly (when @@character_set_connection=ucs2).
@ sql/item_strfunc.cc
- Implementing Item_str_func::val_str().
- Renaming val_str to val_str_ascii for some items,
to make them work with UCS2 properly.
- Using new helper functions
- All single-argument functions that expect string
result now call this method:
agg_arg_charsets_for_string_result(collation, args, 1);
This enables character set conversion to @@character_set_connection
in case of pure numeric input.
@ sql/item_strfunc.h
- Introducing Item_str_ascii_func - for functions
which return pure ASCII data, for performance purposes,
as well as for the cases when the old implementation
of val_str() was heavily 8-bit oriented and implementing
a UCS2-aware version is tricky.
@ sql/item_sum.cc
- Using new helper functions.
@ sql/item_timefunc.cc
- Using my_charset_numeric instead of my_charset_bin.
- Using fix_char_length(), fix_length_and_charset()
and fix_length_and_charset_datetime()
instead of direct write to max_length.
- Using tricky-charset aware function str_to_time_with_warn()
@ sql/item_timefunc.h
- Using new helper functions for charset and length initialization.
- Changing base class for Item_func_get_format() to make
it return UCS2 properly (when character_set_connection=ucs2).
@ sql/item_xmlfunc.cc
- Using new helper function
@ sql/my_decimal.cc
- Adding a new DECIMAL to CHAR converter
with real multibyte support (e.g. UCS2)
@ sql/mysql_priv.h
- Introducing a new derivation level for numeric/datetime data types.
- Adding macros for my_charset_numeric and MY_REPERTOIRE_NUMERIC.
- Adding prototypes for str_set_decimal()
- Adding prototypes for character-set aware str_to_xxx() functions.
@ sql/protocol.cc
- Changing charsetnr to "binary" client-side metadata for
numeric/datetime data types.
@ sql/time.cc
- Adding to_ascii() helper function, to convert a string
in any character set to ascii representation. In the
future can be extended to understand digits written
in various non-Latin word scripts.
- Adding real multy-byte character set aware versions for str_to_XXXX,
to make these these type of queries work correct:
INSERT INTO t1 SET datetime_column=ucs2_expression;
@ strings/ctype-ucs2.c
- endptr was not calculated correctly. INSERTing of UCS2
values into numeric columns returned warnings about
truncated wrong data.
2010-02-11 08:17:25 +04:00
|
|
|
my_decimal_length_to_precision(max_char_length(), decimals,
|
|
|
|
unsigned_flag);
|
2009-11-02 09:21:39 -02:00
|
|
|
return min(prec, DECIMAL_MAX_PRECISION);
|
|
|
|
}
|
WL#2649 Number-to-string conversions
added:
include/ctype_numconv.inc
mysql-test/include/ctype_numconv.inc
mysql-test/r/ctype_binary.result
mysql-test/t/ctype_binary.test
Adding tests
modified:
mysql-test/r/bigint.result
mysql-test/r/case.result
mysql-test/r/create.result
mysql-test/r/ctype_cp1251.result
mysql-test/r/ctype_latin1.result
mysql-test/r/ctype_ucs.result
mysql-test/r/func_gconcat.result
mysql-test/r/func_str.result
mysql-test/r/metadata.result
mysql-test/r/ps_1general.result
mysql-test/r/ps_2myisam.result
mysql-test/r/ps_3innodb.result
mysql-test/r/ps_4heap.result
mysql-test/r/ps_5merge.result
mysql-test/r/show_check.result
mysql-test/r/type_datetime.result
mysql-test/r/type_ranges.result
mysql-test/r/union.result
mysql-test/suite/ndb/r/ps_7ndb.result
mysql-test/t/ctype_cp1251.test
mysql-test/t/ctype_latin1.test
mysql-test/t/ctype_ucs.test
mysql-test/t/func_str.test
Fixing tests
@ sql/field.cc
- Return str result using my_charset_numeric.
- Using real multi-byte aware str_to_XXX functions
to handle tricky charset values propely (e.g. UCS2)
@ sql/field.h
- Changing derivation of non-string field types to DERIVATION_NUMERIC.
- Changing binary() for numeric/datetime fields to always
return TRUE even if charset is not my_charset_bin. We need
this to keep ha_base_keytype() return HA_KEYTYPE_BINARY.
- Adding BINARY_FLAG into some fields, because it's not
being set automatically anymore with
"my_charset_bin to my_charset_numeric" change.
- Changing derivation for numeric/datetime datatypes to a weaker
value, to make "SELECT concat('string', field)" use character
set of the string literal for the result of the function.
@ sql/item.cc
- Implementing generic val_str_ascii().
- Using max_char_length() instead of direct read of max_length
to make "tricky" charsets like UCS2 work.
NOTE: in the future we'll possibly remove all direct reads of max_length
- Fixing Item_num::safe_charset_converter().
Previously it alligned binary string to
character string (for example by adding leading 0x00
when doing binary->UCS2 conversion). Now it just
converts from my_charset_numbner to "tocs".
- Using val_str_ascii() in Item::get_time() to make UCS2 arguments work.
- Other misc changes
@ sql/item.h
- Changing MY_COLL_CMP_CONV and MY_COLL_ALLOW_CONV to
bit operations instead of hard-coded bit masks.
- Addding new method DTCollation.set_numeric().
- Adding new methods to Item.
- Adding helper functions to make code look nicer:
agg_item_charsets_for_string_result()
agg_item_charsets_for_comparison()
- Changing charset for Item_num-derived items
from my_charset_bin to my_charset_numeric
(which is an alias for latin1).
@ sql/item_cmpfunc.cc
- Using new helper functions
- Other misc changes
@ sql/item_cmpfunc.h
- Fixing strcmp() to return max_length=2.
Previously it returned 1, which was wrong,
because it did not fit '-1'.
@ sql/item_func.cc
- Using new helper functions
- Other minor changes
@ sql/item_func.h
- Removing unused functions
- Adding helper functions
agg_arg_charsets_for_string_result()
agg_arg_charsets_for_comparison()
- Adding set_numeric() into constructors of numeric items.
- Using fix_length_and_charset() and fix_char_length()
instead of direct write to max_length.
@ sql/item_geofunc.cc
- Changing class for Item_func_geometry_type and
Item_func_as_wkt from Item_str_func to
Item_str_ascii_func, to make them return UCS2 result
properly (when character_set_connection=ucs2).
@ sql/item_geofunc.h
- Changing class for Item_func_geometry_type and
Item_func_as_wkt from Item_str_func to
Item_str_ascii_func, to make them return UCS2 result
properly (when @@character_set_connection=ucs2).
@ sql/item_strfunc.cc
- Implementing Item_str_func::val_str().
- Renaming val_str to val_str_ascii for some items,
to make them work with UCS2 properly.
- Using new helper functions
- All single-argument functions that expect string
result now call this method:
agg_arg_charsets_for_string_result(collation, args, 1);
This enables character set conversion to @@character_set_connection
in case of pure numeric input.
@ sql/item_strfunc.h
- Introducing Item_str_ascii_func - for functions
which return pure ASCII data, for performance purposes,
as well as for the cases when the old implementation
of val_str() was heavily 8-bit oriented and implementing
a UCS2-aware version is tricky.
@ sql/item_sum.cc
- Using new helper functions.
@ sql/item_timefunc.cc
- Using my_charset_numeric instead of my_charset_bin.
- Using fix_char_length(), fix_length_and_charset()
and fix_length_and_charset_datetime()
instead of direct write to max_length.
- Using tricky-charset aware function str_to_time_with_warn()
@ sql/item_timefunc.h
- Using new helper functions for charset and length initialization.
- Changing base class for Item_func_get_format() to make
it return UCS2 properly (when character_set_connection=ucs2).
@ sql/item_xmlfunc.cc
- Using new helper function
@ sql/my_decimal.cc
- Adding a new DECIMAL to CHAR converter
with real multibyte support (e.g. UCS2)
@ sql/mysql_priv.h
- Introducing a new derivation level for numeric/datetime data types.
- Adding macros for my_charset_numeric and MY_REPERTOIRE_NUMERIC.
- Adding prototypes for str_set_decimal()
- Adding prototypes for character-set aware str_to_xxx() functions.
@ sql/protocol.cc
- Changing charsetnr to "binary" client-side metadata for
numeric/datetime data types.
@ sql/time.cc
- Adding to_ascii() helper function, to convert a string
in any character set to ascii representation. In the
future can be extended to understand digits written
in various non-Latin word scripts.
- Adding real multy-byte character set aware versions for str_to_XXXX,
to make these these type of queries work correct:
INSERT INTO t1 SET datetime_column=ucs2_expression;
@ strings/ctype-ucs2.c
- endptr was not calculated correctly. INSERTing of UCS2
values into numeric columns returned warnings about
truncated wrong data.
2010-02-11 08:17:25 +04:00
|
|
|
return min(max_char_length(), DECIMAL_MAX_PRECISION);
|
2005-05-05 20:06:49 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-22 13:30:33 +03:00
|
|
|
void Item::print_item_w_name(String *str, enum_query_type query_type)
|
2003-10-16 15:54:47 +03:00
|
|
|
{
|
2008-02-22 13:30:33 +03:00
|
|
|
print(str, query_type);
|
|
|
|
|
2003-10-16 15:54:47 +03:00
|
|
|
if (name)
|
|
|
|
{
|
2004-07-20 18:51:02 +03:00
|
|
|
THD *thd= current_thd;
|
2005-11-20 20:47:07 +02:00
|
|
|
str->append(STRING_WITH_LEN(" AS "));
|
2005-06-13 12:41:15 +02:00
|
|
|
append_identifier(thd, str, name, (uint) strlen(name));
|
2003-10-16 15:54:47 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-09-09 06:59:26 +03:00
|
|
|
void Item::cleanup()
|
|
|
|
{
|
|
|
|
DBUG_ENTER("Item::cleanup");
|
|
|
|
fixed=0;
|
2004-11-11 11:16:51 +02:00
|
|
|
marker= 0;
|
2004-09-14 19:28:29 +03:00
|
|
|
if (orig_name)
|
|
|
|
name= orig_name;
|
2004-09-09 06:59:26 +03:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
2004-11-11 11:16:51 +02:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
|
|
|
cleanup() item if it is 'fixed'.
|
2004-11-11 11:16:51 +02:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@param arg a dummy parameter, is not used here
|
2004-11-11 11:16:51 +02:00
|
|
|
*/
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
bool Item::cleanup_processor(uchar *arg)
|
2004-11-11 11:16:51 +02:00
|
|
|
{
|
|
|
|
if (fixed)
|
|
|
|
cleanup();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
|
|
|
rename item (used for views, cleanup() return original name).
|
2004-09-14 19:28:29 +03:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@param new_name new name of item;
|
2004-09-14 19:28:29 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
void Item::rename(char *new_name)
|
|
|
|
{
|
|
|
|
/*
|
2005-02-09 02:50:45 +04:00
|
|
|
we can compare pointers to names here, because if name was not changed,
|
2004-09-14 19:28:29 +03:00
|
|
|
pointer will be same
|
|
|
|
*/
|
|
|
|
if (!orig_name && new_name != name)
|
|
|
|
orig_name= name;
|
|
|
|
name= new_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
2006-08-25 11:34:13 +04:00
|
|
|
Traverse item tree possibly transforming it (replacing items).
|
2006-08-24 15:49:12 +04:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
This function is designed to ease transformation of Item trees.
|
|
|
|
Re-execution note: every such transformation is registered for
|
|
|
|
rollback by THD::change_item_tree() and is rolled back at the end
|
|
|
|
of execution by THD::rollback_item_tree_changes().
|
2006-08-24 15:49:12 +04:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
Therefore:
|
|
|
|
- this function can not be used at prepared statement prepare
|
|
|
|
(in particular, in fix_fields!), as only permanent
|
|
|
|
transformation of Item trees are allowed at prepare.
|
|
|
|
- the transformer function shall allocate new Items in execution
|
|
|
|
memory root (thd->mem_root) and not anywhere else: allocated
|
|
|
|
items will be gone in the end of execution.
|
2006-08-24 15:49:12 +04:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
If you don't need to transform an item tree, but only traverse
|
|
|
|
it, please use Item::walk() instead.
|
2006-08-24 15:49:12 +04:00
|
|
|
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@param transformer functor that performs transformation of a subtree
|
|
|
|
@param arg opaque argument passed to the functor
|
2006-08-24 15:49:12 +04:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@return
|
2006-08-24 15:49:12 +04:00
|
|
|
Returns pointer to the new subtree root. THD::change_item_tree()
|
2006-08-25 11:34:13 +04:00
|
|
|
should be called for it if transformation took place, i.e. if a
|
2006-08-24 15:49:12 +04:00
|
|
|
pointer to newly allocated item is returned.
|
|
|
|
*/
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
Item* Item::transform(Item_transformer transformer, uchar *arg)
|
2006-08-24 15:49:12 +04:00
|
|
|
{
|
2011-05-06 15:39:40 +04:00
|
|
|
DBUG_ASSERT(!current_thd->stmt_arena->is_stmt_prepare());
|
2006-08-24 15:49:12 +04:00
|
|
|
|
|
|
|
return (this->*transformer)(arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-01 07:05:42 +03:00
|
|
|
Item_ident::Item_ident(Name_resolution_context *context_arg,
|
|
|
|
const char *db_name_arg,const char *table_name_arg,
|
|
|
|
const char *field_name_arg)
|
|
|
|
:orig_db_name(db_name_arg), orig_table_name(table_name_arg),
|
|
|
|
orig_field_name(field_name_arg), context(context_arg),
|
|
|
|
db_name(db_name_arg), table_name(table_name_arg),
|
|
|
|
field_name(field_name_arg),
|
2004-12-07 15:47:00 +02:00
|
|
|
alias_name_used(FALSE), cached_field_index(NO_CACHED_FIELD_INDEX),
|
2004-03-31 21:25:55 +04:00
|
|
|
cached_table(0), depended_from(0)
|
2003-12-17 17:35:34 +02:00
|
|
|
{
|
2005-07-01 07:05:42 +03:00
|
|
|
name = (char*) field_name_arg;
|
2003-12-17 17:35:34 +02:00
|
|
|
}
|
|
|
|
|
2004-12-07 15:47:00 +02:00
|
|
|
|
2010-03-12 10:33:16 +04:00
|
|
|
Item_ident::Item_ident(TABLE_LIST *view_arg, const char *field_name_arg)
|
|
|
|
:orig_db_name(NullS), orig_table_name(view_arg->table_name),
|
|
|
|
orig_field_name(field_name_arg), context(&view_arg->view->select_lex.context),
|
|
|
|
db_name(NullS), table_name(view_arg->alias),
|
|
|
|
field_name(field_name_arg),
|
|
|
|
alias_name_used(FALSE), cached_field_index(NO_CACHED_FIELD_INDEX),
|
|
|
|
cached_table(NULL), depended_from(NULL)
|
|
|
|
{
|
|
|
|
name = (char*) field_name_arg;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
|
|
|
Constructor used by Item_field & Item_*_ref (see Item comment)
|
|
|
|
*/
|
2004-12-07 15:47:00 +02:00
|
|
|
|
2004-03-17 14:26:26 +02:00
|
|
|
Item_ident::Item_ident(THD *thd, Item_ident *item)
|
|
|
|
:Item(thd, item),
|
2004-03-31 21:25:55 +04:00
|
|
|
orig_db_name(item->orig_db_name),
|
|
|
|
orig_table_name(item->orig_table_name),
|
|
|
|
orig_field_name(item->orig_field_name),
|
2005-07-01 07:05:42 +03:00
|
|
|
context(item->context),
|
2004-03-17 14:26:26 +02:00
|
|
|
db_name(item->db_name),
|
|
|
|
table_name(item->table_name),
|
|
|
|
field_name(item->field_name),
|
2004-12-07 15:47:00 +02:00
|
|
|
alias_name_used(item->alias_name_used),
|
2004-03-28 04:11:54 +04:00
|
|
|
cached_field_index(item->cached_field_index),
|
2004-03-31 21:25:55 +04:00
|
|
|
cached_table(item->cached_table),
|
2004-03-17 14:26:26 +02:00
|
|
|
depended_from(item->depended_from)
|
2003-01-25 02:25:52 +02:00
|
|
|
{}
|
2002-12-06 21:55:53 +02:00
|
|
|
|
2004-03-17 14:26:26 +02:00
|
|
|
void Item_ident::cleanup()
|
|
|
|
{
|
2004-04-01 23:27:22 +03:00
|
|
|
DBUG_ENTER("Item_ident::cleanup");
|
2004-12-06 17:15:54 +02:00
|
|
|
#ifdef CANT_BE_USED_AS_MEMORY_IS_FREED
|
2004-11-26 16:30:20 +02:00
|
|
|
db_name ? db_name : "(null)",
|
|
|
|
orig_db_name ? orig_db_name : "(null)",
|
|
|
|
table_name ? table_name : "(null)",
|
|
|
|
orig_table_name ? orig_table_name : "(null)",
|
|
|
|
field_name ? field_name : "(null)",
|
|
|
|
orig_field_name ? orig_field_name : "(null)"));
|
2004-12-06 17:15:54 +02:00
|
|
|
#endif
|
2004-03-17 14:26:26 +02:00
|
|
|
Item::cleanup();
|
2004-03-31 21:25:55 +04:00
|
|
|
db_name= orig_db_name;
|
|
|
|
table_name= orig_table_name;
|
|
|
|
field_name= orig_field_name;
|
2005-04-29 02:43:56 +03:00
|
|
|
depended_from= 0;
|
2004-04-01 23:27:22 +03:00
|
|
|
DBUG_VOID_RETURN;
|
2004-03-17 14:26:26 +02:00
|
|
|
}
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
bool Item_ident::remove_dependence_processor(uchar * arg)
|
2003-07-02 13:12:18 +03:00
|
|
|
{
|
|
|
|
DBUG_ENTER("Item_ident::remove_dependence_processor");
|
|
|
|
if (depended_from == (st_select_lex *) arg)
|
|
|
|
depended_from= 0;
|
2009-07-18 18:09:56 +04:00
|
|
|
context= &((st_select_lex *) arg)->context;
|
2003-08-23 13:29:38 +03:00
|
|
|
DBUG_RETURN(0);
|
2003-07-02 13:12:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
2004-08-27 16:37:13 +03:00
|
|
|
Store the pointer to this item field into a list if not already there.
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
The method is used by Item::walk to collect all unique Item_field objects
|
|
|
|
from a tree of Items into a set of items represented as a list.
|
2004-08-27 16:37:13 +03:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
Item_cond::walk() and Item_func::walk() stop the evaluation of the
|
|
|
|
processor function for its arguments once the processor returns
|
|
|
|
true.Therefore in order to force this method being called for all item
|
|
|
|
arguments in a condition the method must return false.
|
2004-08-27 16:37:13 +03:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@param arg pointer to a List<Item_field>
|
2004-08-27 16:37:13 +03:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@return
|
2006-03-31 12:34:28 +03:00
|
|
|
FALSE to force the evaluation of collect_item_field_processor
|
2007-10-11 13:29:09 -04:00
|
|
|
for the subsequent items.
|
2004-08-27 16:37:13 +03:00
|
|
|
*/
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
bool Item_field::collect_item_field_processor(uchar *arg)
|
2004-08-27 16:37:13 +03:00
|
|
|
{
|
|
|
|
DBUG_ENTER("Item_field::collect_item_field_processor");
|
|
|
|
DBUG_PRINT("info", ("%s", field->field_name ? field->field_name : "noname"));
|
|
|
|
List<Item_field> *item_list= (List<Item_field>*) arg;
|
|
|
|
List_iterator<Item_field> item_list_it(*item_list);
|
|
|
|
Item_field *curr_item;
|
|
|
|
while ((curr_item= item_list_it++))
|
|
|
|
{
|
|
|
|
if (curr_item->eq(this, 1))
|
2005-05-06 11:39:30 +03:00
|
|
|
DBUG_RETURN(FALSE); /* Already in the set. */
|
2004-08-27 16:37:13 +03:00
|
|
|
}
|
|
|
|
item_list->push_back(this);
|
2005-05-06 11:39:30 +03:00
|
|
|
DBUG_RETURN(FALSE);
|
2004-08-27 16:37:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
2006-03-31 12:34:28 +03:00
|
|
|
Check if an Item_field references some field from a list of fields.
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
Check whether the Item_field represented by 'this' references any
|
|
|
|
of the fields in the keyparts passed via 'arg'. Used with the
|
|
|
|
method Item::walk() to test whether any keypart in a sequence of
|
|
|
|
keyparts is referenced in an expression.
|
2006-03-31 12:34:28 +03:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@param arg Field being compared, arg must be of type Field
|
2006-03-31 12:34:28 +03:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@retval
|
2006-03-31 12:34:28 +03:00
|
|
|
TRUE if 'this' references the field 'arg'
|
2007-10-11 13:29:09 -04:00
|
|
|
@retval
|
2006-03-31 22:54:26 +03:00
|
|
|
FALSE otherwise
|
2006-03-31 12:34:28 +03:00
|
|
|
*/
|
2006-03-31 22:54:26 +03:00
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
bool Item_field::find_item_in_field_list_processor(uchar *arg)
|
2006-03-31 12:34:28 +03:00
|
|
|
{
|
|
|
|
KEY_PART_INFO *first_non_group_part= *((KEY_PART_INFO **) arg);
|
|
|
|
KEY_PART_INFO *last_part= *(((KEY_PART_INFO **) arg) + 1);
|
|
|
|
KEY_PART_INFO *cur_part;
|
|
|
|
|
|
|
|
for (cur_part= first_non_group_part; cur_part != last_part; cur_part++)
|
|
|
|
{
|
|
|
|
if (field->eq(cur_part->field))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 18:52:22 +03:00
|
|
|
/*
|
|
|
|
Mark field in read_map
|
|
|
|
|
|
|
|
NOTES
|
|
|
|
This is used by filesort to register used fields in a a temporary
|
|
|
|
column read set or to register used fields in a view
|
|
|
|
*/
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
bool Item_field::register_field_in_read_map(uchar *arg)
|
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 18:52:22 +03:00
|
|
|
{
|
|
|
|
TABLE *table= (TABLE *) arg;
|
|
|
|
if (field->table == table || !table)
|
|
|
|
bitmap_set_bit(field->table->read_set, field->field_index);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-15 20:32:09 +02:00
|
|
|
bool Item::check_cols(uint c)
|
|
|
|
{
|
|
|
|
if (c != 1)
|
|
|
|
{
|
2003-10-06 22:35:05 +03:00
|
|
|
my_error(ER_OPERAND_COLUMNS, MYF(0), c);
|
2002-11-15 20:32:09 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-05-21 21:39:58 +03:00
|
|
|
|
|
|
|
void Item::set_name(const char *str, uint length, CHARSET_INFO *cs)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
if (!length)
|
|
|
|
{
|
2003-05-21 21:39:58 +03:00
|
|
|
/* Empty string, used by AS or internal function like last_insert_id() */
|
|
|
|
name= (char*) str;
|
2003-09-13 17:47:59 +03:00
|
|
|
name_length= 0;
|
2003-05-21 21:39:58 +03:00
|
|
|
return;
|
|
|
|
}
|
2004-08-13 11:13:56 +05:00
|
|
|
if (cs->ctype)
|
|
|
|
{
|
2006-07-16 00:45:38 +04:00
|
|
|
uint orig_len= length;
|
2004-09-06 15:14:10 +03:00
|
|
|
/*
|
|
|
|
This will probably need a better implementation in the future:
|
|
|
|
a function in CHARSET_INFO structure.
|
|
|
|
*/
|
2004-08-13 11:13:56 +05:00
|
|
|
while (length && !my_isgraph(cs,*str))
|
|
|
|
{ // Fix problem with yacc
|
|
|
|
length--;
|
|
|
|
str++;
|
|
|
|
}
|
2006-07-16 00:45:38 +04:00
|
|
|
if (orig_len != length && !is_autogenerated_name)
|
2007-09-13 18:41:50 +05:00
|
|
|
{
|
|
|
|
if (length == 0)
|
|
|
|
push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
|
|
|
|
ER_NAME_BECOMES_EMPTY, ER(ER_NAME_BECOMES_EMPTY),
|
|
|
|
str + length - orig_len);
|
|
|
|
else
|
|
|
|
push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
|
|
|
|
ER_REMOVED_SPACES, ER(ER_REMOVED_SPACES),
|
|
|
|
str + length - orig_len);
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2003-05-21 21:39:58 +03:00
|
|
|
if (!my_charset_same(cs, system_charset_info))
|
|
|
|
{
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
size_t res_length;
|
2003-09-13 17:47:59 +03:00
|
|
|
name= sql_strmake_with_convert(str, name_length= length, cs,
|
2003-05-21 21:39:58 +03:00
|
|
|
MAX_ALIAS_NAME, system_charset_info,
|
|
|
|
&res_length);
|
|
|
|
}
|
|
|
|
else
|
2003-09-13 17:47:59 +03:00
|
|
|
name= sql_strmake(str, (name_length= min(length,MAX_ALIAS_NAME)));
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2003-05-21 21:39:58 +03:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
|
|
|
@details
|
2003-06-04 18:28:51 +03:00
|
|
|
This function is called when:
|
|
|
|
- Comparing items in the WHERE clause (when doing where optimization)
|
|
|
|
- When trying to find an ORDER BY/GROUP BY item in the SELECT part
|
2002-03-22 14:03:42 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
bool Item::eq(const Item *item, bool binary_cmp) const
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2005-05-03 12:47:27 +04:00
|
|
|
/*
|
|
|
|
Note, that this is never TRUE if item is a Item_param:
|
|
|
|
for all basic constants we have special checks, and Item_param's
|
|
|
|
type() can be only among basic constant types.
|
|
|
|
*/
|
2000-07-31 21:29:14 +02:00
|
|
|
return type() == item->type() && name && item->name &&
|
2002-03-12 21:37:58 +04:00
|
|
|
!my_strcasecmp(system_charset_info,name,item->name);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2004-02-16 10:03:25 +02:00
|
|
|
|
2004-11-11 11:16:51 +02:00
|
|
|
Item *Item::safe_charset_converter(CHARSET_INFO *tocs)
|
|
|
|
{
|
2005-11-21 17:26:31 +04:00
|
|
|
Item_func_conv_charset *conv= new Item_func_conv_charset(this, tocs, 1);
|
|
|
|
return conv->safe ? conv : NULL;
|
2004-11-11 11:16:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
|
|
|
@details
|
2005-07-13 13:00:17 +05:00
|
|
|
Created mostly for mysql_prepare_table(). Important
|
|
|
|
when a string ENUM/SET column is described with a numeric default value:
|
|
|
|
|
|
|
|
CREATE TABLE t1(a SET('a') DEFAULT 1);
|
|
|
|
|
|
|
|
We cannot use generic Item::safe_charset_converter(), because
|
|
|
|
the latter returns a non-fixed Item, so val_str() crashes afterwards.
|
|
|
|
Override Item_num method, to return a fixed item.
|
|
|
|
*/
|
|
|
|
Item *Item_num::safe_charset_converter(CHARSET_INFO *tocs)
|
|
|
|
{
|
WL#2649 Number-to-string conversions
added:
include/ctype_numconv.inc
mysql-test/include/ctype_numconv.inc
mysql-test/r/ctype_binary.result
mysql-test/t/ctype_binary.test
Adding tests
modified:
mysql-test/r/bigint.result
mysql-test/r/case.result
mysql-test/r/create.result
mysql-test/r/ctype_cp1251.result
mysql-test/r/ctype_latin1.result
mysql-test/r/ctype_ucs.result
mysql-test/r/func_gconcat.result
mysql-test/r/func_str.result
mysql-test/r/metadata.result
mysql-test/r/ps_1general.result
mysql-test/r/ps_2myisam.result
mysql-test/r/ps_3innodb.result
mysql-test/r/ps_4heap.result
mysql-test/r/ps_5merge.result
mysql-test/r/show_check.result
mysql-test/r/type_datetime.result
mysql-test/r/type_ranges.result
mysql-test/r/union.result
mysql-test/suite/ndb/r/ps_7ndb.result
mysql-test/t/ctype_cp1251.test
mysql-test/t/ctype_latin1.test
mysql-test/t/ctype_ucs.test
mysql-test/t/func_str.test
Fixing tests
@ sql/field.cc
- Return str result using my_charset_numeric.
- Using real multi-byte aware str_to_XXX functions
to handle tricky charset values propely (e.g. UCS2)
@ sql/field.h
- Changing derivation of non-string field types to DERIVATION_NUMERIC.
- Changing binary() for numeric/datetime fields to always
return TRUE even if charset is not my_charset_bin. We need
this to keep ha_base_keytype() return HA_KEYTYPE_BINARY.
- Adding BINARY_FLAG into some fields, because it's not
being set automatically anymore with
"my_charset_bin to my_charset_numeric" change.
- Changing derivation for numeric/datetime datatypes to a weaker
value, to make "SELECT concat('string', field)" use character
set of the string literal for the result of the function.
@ sql/item.cc
- Implementing generic val_str_ascii().
- Using max_char_length() instead of direct read of max_length
to make "tricky" charsets like UCS2 work.
NOTE: in the future we'll possibly remove all direct reads of max_length
- Fixing Item_num::safe_charset_converter().
Previously it alligned binary string to
character string (for example by adding leading 0x00
when doing binary->UCS2 conversion). Now it just
converts from my_charset_numbner to "tocs".
- Using val_str_ascii() in Item::get_time() to make UCS2 arguments work.
- Other misc changes
@ sql/item.h
- Changing MY_COLL_CMP_CONV and MY_COLL_ALLOW_CONV to
bit operations instead of hard-coded bit masks.
- Addding new method DTCollation.set_numeric().
- Adding new methods to Item.
- Adding helper functions to make code look nicer:
agg_item_charsets_for_string_result()
agg_item_charsets_for_comparison()
- Changing charset for Item_num-derived items
from my_charset_bin to my_charset_numeric
(which is an alias for latin1).
@ sql/item_cmpfunc.cc
- Using new helper functions
- Other misc changes
@ sql/item_cmpfunc.h
- Fixing strcmp() to return max_length=2.
Previously it returned 1, which was wrong,
because it did not fit '-1'.
@ sql/item_func.cc
- Using new helper functions
- Other minor changes
@ sql/item_func.h
- Removing unused functions
- Adding helper functions
agg_arg_charsets_for_string_result()
agg_arg_charsets_for_comparison()
- Adding set_numeric() into constructors of numeric items.
- Using fix_length_and_charset() and fix_char_length()
instead of direct write to max_length.
@ sql/item_geofunc.cc
- Changing class for Item_func_geometry_type and
Item_func_as_wkt from Item_str_func to
Item_str_ascii_func, to make them return UCS2 result
properly (when character_set_connection=ucs2).
@ sql/item_geofunc.h
- Changing class for Item_func_geometry_type and
Item_func_as_wkt from Item_str_func to
Item_str_ascii_func, to make them return UCS2 result
properly (when @@character_set_connection=ucs2).
@ sql/item_strfunc.cc
- Implementing Item_str_func::val_str().
- Renaming val_str to val_str_ascii for some items,
to make them work with UCS2 properly.
- Using new helper functions
- All single-argument functions that expect string
result now call this method:
agg_arg_charsets_for_string_result(collation, args, 1);
This enables character set conversion to @@character_set_connection
in case of pure numeric input.
@ sql/item_strfunc.h
- Introducing Item_str_ascii_func - for functions
which return pure ASCII data, for performance purposes,
as well as for the cases when the old implementation
of val_str() was heavily 8-bit oriented and implementing
a UCS2-aware version is tricky.
@ sql/item_sum.cc
- Using new helper functions.
@ sql/item_timefunc.cc
- Using my_charset_numeric instead of my_charset_bin.
- Using fix_char_length(), fix_length_and_charset()
and fix_length_and_charset_datetime()
instead of direct write to max_length.
- Using tricky-charset aware function str_to_time_with_warn()
@ sql/item_timefunc.h
- Using new helper functions for charset and length initialization.
- Changing base class for Item_func_get_format() to make
it return UCS2 properly (when character_set_connection=ucs2).
@ sql/item_xmlfunc.cc
- Using new helper function
@ sql/my_decimal.cc
- Adding a new DECIMAL to CHAR converter
with real multibyte support (e.g. UCS2)
@ sql/mysql_priv.h
- Introducing a new derivation level for numeric/datetime data types.
- Adding macros for my_charset_numeric and MY_REPERTOIRE_NUMERIC.
- Adding prototypes for str_set_decimal()
- Adding prototypes for character-set aware str_to_xxx() functions.
@ sql/protocol.cc
- Changing charsetnr to "binary" client-side metadata for
numeric/datetime data types.
@ sql/time.cc
- Adding to_ascii() helper function, to convert a string
in any character set to ascii representation. In the
future can be extended to understand digits written
in various non-Latin word scripts.
- Adding real multy-byte character set aware versions for str_to_XXXX,
to make these these type of queries work correct:
INSERT INTO t1 SET datetime_column=ucs2_expression;
@ strings/ctype-ucs2.c
- endptr was not calculated correctly. INSERTing of UCS2
values into numeric columns returned warnings about
truncated wrong data.
2010-02-11 08:17:25 +04:00
|
|
|
/*
|
|
|
|
Item_num returns pure ASCII result,
|
|
|
|
so conversion is needed only in case of "tricky" character
|
|
|
|
sets like UCS2. If tocs is not "tricky", return the item itself.
|
|
|
|
*/
|
|
|
|
if (!(tocs->state & MY_CS_NONASCII))
|
|
|
|
return this;
|
|
|
|
|
2005-07-13 13:00:17 +05:00
|
|
|
Item_string *conv;
|
WL#2649 Number-to-string conversions
added:
include/ctype_numconv.inc
mysql-test/include/ctype_numconv.inc
mysql-test/r/ctype_binary.result
mysql-test/t/ctype_binary.test
Adding tests
modified:
mysql-test/r/bigint.result
mysql-test/r/case.result
mysql-test/r/create.result
mysql-test/r/ctype_cp1251.result
mysql-test/r/ctype_latin1.result
mysql-test/r/ctype_ucs.result
mysql-test/r/func_gconcat.result
mysql-test/r/func_str.result
mysql-test/r/metadata.result
mysql-test/r/ps_1general.result
mysql-test/r/ps_2myisam.result
mysql-test/r/ps_3innodb.result
mysql-test/r/ps_4heap.result
mysql-test/r/ps_5merge.result
mysql-test/r/show_check.result
mysql-test/r/type_datetime.result
mysql-test/r/type_ranges.result
mysql-test/r/union.result
mysql-test/suite/ndb/r/ps_7ndb.result
mysql-test/t/ctype_cp1251.test
mysql-test/t/ctype_latin1.test
mysql-test/t/ctype_ucs.test
mysql-test/t/func_str.test
Fixing tests
@ sql/field.cc
- Return str result using my_charset_numeric.
- Using real multi-byte aware str_to_XXX functions
to handle tricky charset values propely (e.g. UCS2)
@ sql/field.h
- Changing derivation of non-string field types to DERIVATION_NUMERIC.
- Changing binary() for numeric/datetime fields to always
return TRUE even if charset is not my_charset_bin. We need
this to keep ha_base_keytype() return HA_KEYTYPE_BINARY.
- Adding BINARY_FLAG into some fields, because it's not
being set automatically anymore with
"my_charset_bin to my_charset_numeric" change.
- Changing derivation for numeric/datetime datatypes to a weaker
value, to make "SELECT concat('string', field)" use character
set of the string literal for the result of the function.
@ sql/item.cc
- Implementing generic val_str_ascii().
- Using max_char_length() instead of direct read of max_length
to make "tricky" charsets like UCS2 work.
NOTE: in the future we'll possibly remove all direct reads of max_length
- Fixing Item_num::safe_charset_converter().
Previously it alligned binary string to
character string (for example by adding leading 0x00
when doing binary->UCS2 conversion). Now it just
converts from my_charset_numbner to "tocs".
- Using val_str_ascii() in Item::get_time() to make UCS2 arguments work.
- Other misc changes
@ sql/item.h
- Changing MY_COLL_CMP_CONV and MY_COLL_ALLOW_CONV to
bit operations instead of hard-coded bit masks.
- Addding new method DTCollation.set_numeric().
- Adding new methods to Item.
- Adding helper functions to make code look nicer:
agg_item_charsets_for_string_result()
agg_item_charsets_for_comparison()
- Changing charset for Item_num-derived items
from my_charset_bin to my_charset_numeric
(which is an alias for latin1).
@ sql/item_cmpfunc.cc
- Using new helper functions
- Other misc changes
@ sql/item_cmpfunc.h
- Fixing strcmp() to return max_length=2.
Previously it returned 1, which was wrong,
because it did not fit '-1'.
@ sql/item_func.cc
- Using new helper functions
- Other minor changes
@ sql/item_func.h
- Removing unused functions
- Adding helper functions
agg_arg_charsets_for_string_result()
agg_arg_charsets_for_comparison()
- Adding set_numeric() into constructors of numeric items.
- Using fix_length_and_charset() and fix_char_length()
instead of direct write to max_length.
@ sql/item_geofunc.cc
- Changing class for Item_func_geometry_type and
Item_func_as_wkt from Item_str_func to
Item_str_ascii_func, to make them return UCS2 result
properly (when character_set_connection=ucs2).
@ sql/item_geofunc.h
- Changing class for Item_func_geometry_type and
Item_func_as_wkt from Item_str_func to
Item_str_ascii_func, to make them return UCS2 result
properly (when @@character_set_connection=ucs2).
@ sql/item_strfunc.cc
- Implementing Item_str_func::val_str().
- Renaming val_str to val_str_ascii for some items,
to make them work with UCS2 properly.
- Using new helper functions
- All single-argument functions that expect string
result now call this method:
agg_arg_charsets_for_string_result(collation, args, 1);
This enables character set conversion to @@character_set_connection
in case of pure numeric input.
@ sql/item_strfunc.h
- Introducing Item_str_ascii_func - for functions
which return pure ASCII data, for performance purposes,
as well as for the cases when the old implementation
of val_str() was heavily 8-bit oriented and implementing
a UCS2-aware version is tricky.
@ sql/item_sum.cc
- Using new helper functions.
@ sql/item_timefunc.cc
- Using my_charset_numeric instead of my_charset_bin.
- Using fix_char_length(), fix_length_and_charset()
and fix_length_and_charset_datetime()
instead of direct write to max_length.
- Using tricky-charset aware function str_to_time_with_warn()
@ sql/item_timefunc.h
- Using new helper functions for charset and length initialization.
- Changing base class for Item_func_get_format() to make
it return UCS2 properly (when character_set_connection=ucs2).
@ sql/item_xmlfunc.cc
- Using new helper function
@ sql/my_decimal.cc
- Adding a new DECIMAL to CHAR converter
with real multibyte support (e.g. UCS2)
@ sql/mysql_priv.h
- Introducing a new derivation level for numeric/datetime data types.
- Adding macros for my_charset_numeric and MY_REPERTOIRE_NUMERIC.
- Adding prototypes for str_set_decimal()
- Adding prototypes for character-set aware str_to_xxx() functions.
@ sql/protocol.cc
- Changing charsetnr to "binary" client-side metadata for
numeric/datetime data types.
@ sql/time.cc
- Adding to_ascii() helper function, to convert a string
in any character set to ascii representation. In the
future can be extended to understand digits written
in various non-Latin word scripts.
- Adding real multy-byte character set aware versions for str_to_XXXX,
to make these these type of queries work correct:
INSERT INTO t1 SET datetime_column=ucs2_expression;
@ strings/ctype-ucs2.c
- endptr was not calculated correctly. INSERTing of UCS2
values into numeric columns returned warnings about
truncated wrong data.
2010-02-11 08:17:25 +04:00
|
|
|
uint conv_errors;
|
|
|
|
char buf[64], buf2[64];
|
|
|
|
String tmp(buf, sizeof(buf), &my_charset_bin);
|
|
|
|
String cstr(buf2, sizeof(buf2), &my_charset_bin);
|
|
|
|
String *ostr= val_str(&tmp);
|
|
|
|
char *ptr;
|
|
|
|
cstr.copy(ostr->ptr(), ostr->length(), ostr->charset(), tocs, &conv_errors);
|
|
|
|
if (conv_errors || !(conv= new Item_string(cstr.ptr(), cstr.length(),
|
|
|
|
cstr.charset(),
|
|
|
|
collation.derivation)))
|
2005-07-13 13:00:17 +05:00
|
|
|
{
|
WL#2649 Number-to-string conversions
added:
include/ctype_numconv.inc
mysql-test/include/ctype_numconv.inc
mysql-test/r/ctype_binary.result
mysql-test/t/ctype_binary.test
Adding tests
modified:
mysql-test/r/bigint.result
mysql-test/r/case.result
mysql-test/r/create.result
mysql-test/r/ctype_cp1251.result
mysql-test/r/ctype_latin1.result
mysql-test/r/ctype_ucs.result
mysql-test/r/func_gconcat.result
mysql-test/r/func_str.result
mysql-test/r/metadata.result
mysql-test/r/ps_1general.result
mysql-test/r/ps_2myisam.result
mysql-test/r/ps_3innodb.result
mysql-test/r/ps_4heap.result
mysql-test/r/ps_5merge.result
mysql-test/r/show_check.result
mysql-test/r/type_datetime.result
mysql-test/r/type_ranges.result
mysql-test/r/union.result
mysql-test/suite/ndb/r/ps_7ndb.result
mysql-test/t/ctype_cp1251.test
mysql-test/t/ctype_latin1.test
mysql-test/t/ctype_ucs.test
mysql-test/t/func_str.test
Fixing tests
@ sql/field.cc
- Return str result using my_charset_numeric.
- Using real multi-byte aware str_to_XXX functions
to handle tricky charset values propely (e.g. UCS2)
@ sql/field.h
- Changing derivation of non-string field types to DERIVATION_NUMERIC.
- Changing binary() for numeric/datetime fields to always
return TRUE even if charset is not my_charset_bin. We need
this to keep ha_base_keytype() return HA_KEYTYPE_BINARY.
- Adding BINARY_FLAG into some fields, because it's not
being set automatically anymore with
"my_charset_bin to my_charset_numeric" change.
- Changing derivation for numeric/datetime datatypes to a weaker
value, to make "SELECT concat('string', field)" use character
set of the string literal for the result of the function.
@ sql/item.cc
- Implementing generic val_str_ascii().
- Using max_char_length() instead of direct read of max_length
to make "tricky" charsets like UCS2 work.
NOTE: in the future we'll possibly remove all direct reads of max_length
- Fixing Item_num::safe_charset_converter().
Previously it alligned binary string to
character string (for example by adding leading 0x00
when doing binary->UCS2 conversion). Now it just
converts from my_charset_numbner to "tocs".
- Using val_str_ascii() in Item::get_time() to make UCS2 arguments work.
- Other misc changes
@ sql/item.h
- Changing MY_COLL_CMP_CONV and MY_COLL_ALLOW_CONV to
bit operations instead of hard-coded bit masks.
- Addding new method DTCollation.set_numeric().
- Adding new methods to Item.
- Adding helper functions to make code look nicer:
agg_item_charsets_for_string_result()
agg_item_charsets_for_comparison()
- Changing charset for Item_num-derived items
from my_charset_bin to my_charset_numeric
(which is an alias for latin1).
@ sql/item_cmpfunc.cc
- Using new helper functions
- Other misc changes
@ sql/item_cmpfunc.h
- Fixing strcmp() to return max_length=2.
Previously it returned 1, which was wrong,
because it did not fit '-1'.
@ sql/item_func.cc
- Using new helper functions
- Other minor changes
@ sql/item_func.h
- Removing unused functions
- Adding helper functions
agg_arg_charsets_for_string_result()
agg_arg_charsets_for_comparison()
- Adding set_numeric() into constructors of numeric items.
- Using fix_length_and_charset() and fix_char_length()
instead of direct write to max_length.
@ sql/item_geofunc.cc
- Changing class for Item_func_geometry_type and
Item_func_as_wkt from Item_str_func to
Item_str_ascii_func, to make them return UCS2 result
properly (when character_set_connection=ucs2).
@ sql/item_geofunc.h
- Changing class for Item_func_geometry_type and
Item_func_as_wkt from Item_str_func to
Item_str_ascii_func, to make them return UCS2 result
properly (when @@character_set_connection=ucs2).
@ sql/item_strfunc.cc
- Implementing Item_str_func::val_str().
- Renaming val_str to val_str_ascii for some items,
to make them work with UCS2 properly.
- Using new helper functions
- All single-argument functions that expect string
result now call this method:
agg_arg_charsets_for_string_result(collation, args, 1);
This enables character set conversion to @@character_set_connection
in case of pure numeric input.
@ sql/item_strfunc.h
- Introducing Item_str_ascii_func - for functions
which return pure ASCII data, for performance purposes,
as well as for the cases when the old implementation
of val_str() was heavily 8-bit oriented and implementing
a UCS2-aware version is tricky.
@ sql/item_sum.cc
- Using new helper functions.
@ sql/item_timefunc.cc
- Using my_charset_numeric instead of my_charset_bin.
- Using fix_char_length(), fix_length_and_charset()
and fix_length_and_charset_datetime()
instead of direct write to max_length.
- Using tricky-charset aware function str_to_time_with_warn()
@ sql/item_timefunc.h
- Using new helper functions for charset and length initialization.
- Changing base class for Item_func_get_format() to make
it return UCS2 properly (when character_set_connection=ucs2).
@ sql/item_xmlfunc.cc
- Using new helper function
@ sql/my_decimal.cc
- Adding a new DECIMAL to CHAR converter
with real multibyte support (e.g. UCS2)
@ sql/mysql_priv.h
- Introducing a new derivation level for numeric/datetime data types.
- Adding macros for my_charset_numeric and MY_REPERTOIRE_NUMERIC.
- Adding prototypes for str_set_decimal()
- Adding prototypes for character-set aware str_to_xxx() functions.
@ sql/protocol.cc
- Changing charsetnr to "binary" client-side metadata for
numeric/datetime data types.
@ sql/time.cc
- Adding to_ascii() helper function, to convert a string
in any character set to ascii representation. In the
future can be extended to understand digits written
in various non-Latin word scripts.
- Adding real multy-byte character set aware versions for str_to_XXXX,
to make these these type of queries work correct:
INSERT INTO t1 SET datetime_column=ucs2_expression;
@ strings/ctype-ucs2.c
- endptr was not calculated correctly. INSERTing of UCS2
values into numeric columns returned warnings about
truncated wrong data.
2010-02-11 08:17:25 +04:00
|
|
|
/*
|
|
|
|
Safe conversion is not possible (or EOM).
|
|
|
|
We could not convert a string into the requested character set
|
|
|
|
without data loss. The target charset does not cover all the
|
|
|
|
characters from the string. Operation cannot be done correctly.
|
|
|
|
*/
|
|
|
|
return NULL;
|
2005-07-13 13:00:17 +05:00
|
|
|
}
|
WL#2649 Number-to-string conversions
added:
include/ctype_numconv.inc
mysql-test/include/ctype_numconv.inc
mysql-test/r/ctype_binary.result
mysql-test/t/ctype_binary.test
Adding tests
modified:
mysql-test/r/bigint.result
mysql-test/r/case.result
mysql-test/r/create.result
mysql-test/r/ctype_cp1251.result
mysql-test/r/ctype_latin1.result
mysql-test/r/ctype_ucs.result
mysql-test/r/func_gconcat.result
mysql-test/r/func_str.result
mysql-test/r/metadata.result
mysql-test/r/ps_1general.result
mysql-test/r/ps_2myisam.result
mysql-test/r/ps_3innodb.result
mysql-test/r/ps_4heap.result
mysql-test/r/ps_5merge.result
mysql-test/r/show_check.result
mysql-test/r/type_datetime.result
mysql-test/r/type_ranges.result
mysql-test/r/union.result
mysql-test/suite/ndb/r/ps_7ndb.result
mysql-test/t/ctype_cp1251.test
mysql-test/t/ctype_latin1.test
mysql-test/t/ctype_ucs.test
mysql-test/t/func_str.test
Fixing tests
@ sql/field.cc
- Return str result using my_charset_numeric.
- Using real multi-byte aware str_to_XXX functions
to handle tricky charset values propely (e.g. UCS2)
@ sql/field.h
- Changing derivation of non-string field types to DERIVATION_NUMERIC.
- Changing binary() for numeric/datetime fields to always
return TRUE even if charset is not my_charset_bin. We need
this to keep ha_base_keytype() return HA_KEYTYPE_BINARY.
- Adding BINARY_FLAG into some fields, because it's not
being set automatically anymore with
"my_charset_bin to my_charset_numeric" change.
- Changing derivation for numeric/datetime datatypes to a weaker
value, to make "SELECT concat('string', field)" use character
set of the string literal for the result of the function.
@ sql/item.cc
- Implementing generic val_str_ascii().
- Using max_char_length() instead of direct read of max_length
to make "tricky" charsets like UCS2 work.
NOTE: in the future we'll possibly remove all direct reads of max_length
- Fixing Item_num::safe_charset_converter().
Previously it alligned binary string to
character string (for example by adding leading 0x00
when doing binary->UCS2 conversion). Now it just
converts from my_charset_numbner to "tocs".
- Using val_str_ascii() in Item::get_time() to make UCS2 arguments work.
- Other misc changes
@ sql/item.h
- Changing MY_COLL_CMP_CONV and MY_COLL_ALLOW_CONV to
bit operations instead of hard-coded bit masks.
- Addding new method DTCollation.set_numeric().
- Adding new methods to Item.
- Adding helper functions to make code look nicer:
agg_item_charsets_for_string_result()
agg_item_charsets_for_comparison()
- Changing charset for Item_num-derived items
from my_charset_bin to my_charset_numeric
(which is an alias for latin1).
@ sql/item_cmpfunc.cc
- Using new helper functions
- Other misc changes
@ sql/item_cmpfunc.h
- Fixing strcmp() to return max_length=2.
Previously it returned 1, which was wrong,
because it did not fit '-1'.
@ sql/item_func.cc
- Using new helper functions
- Other minor changes
@ sql/item_func.h
- Removing unused functions
- Adding helper functions
agg_arg_charsets_for_string_result()
agg_arg_charsets_for_comparison()
- Adding set_numeric() into constructors of numeric items.
- Using fix_length_and_charset() and fix_char_length()
instead of direct write to max_length.
@ sql/item_geofunc.cc
- Changing class for Item_func_geometry_type and
Item_func_as_wkt from Item_str_func to
Item_str_ascii_func, to make them return UCS2 result
properly (when character_set_connection=ucs2).
@ sql/item_geofunc.h
- Changing class for Item_func_geometry_type and
Item_func_as_wkt from Item_str_func to
Item_str_ascii_func, to make them return UCS2 result
properly (when @@character_set_connection=ucs2).
@ sql/item_strfunc.cc
- Implementing Item_str_func::val_str().
- Renaming val_str to val_str_ascii for some items,
to make them work with UCS2 properly.
- Using new helper functions
- All single-argument functions that expect string
result now call this method:
agg_arg_charsets_for_string_result(collation, args, 1);
This enables character set conversion to @@character_set_connection
in case of pure numeric input.
@ sql/item_strfunc.h
- Introducing Item_str_ascii_func - for functions
which return pure ASCII data, for performance purposes,
as well as for the cases when the old implementation
of val_str() was heavily 8-bit oriented and implementing
a UCS2-aware version is tricky.
@ sql/item_sum.cc
- Using new helper functions.
@ sql/item_timefunc.cc
- Using my_charset_numeric instead of my_charset_bin.
- Using fix_char_length(), fix_length_and_charset()
and fix_length_and_charset_datetime()
instead of direct write to max_length.
- Using tricky-charset aware function str_to_time_with_warn()
@ sql/item_timefunc.h
- Using new helper functions for charset and length initialization.
- Changing base class for Item_func_get_format() to make
it return UCS2 properly (when character_set_connection=ucs2).
@ sql/item_xmlfunc.cc
- Using new helper function
@ sql/my_decimal.cc
- Adding a new DECIMAL to CHAR converter
with real multibyte support (e.g. UCS2)
@ sql/mysql_priv.h
- Introducing a new derivation level for numeric/datetime data types.
- Adding macros for my_charset_numeric and MY_REPERTOIRE_NUMERIC.
- Adding prototypes for str_set_decimal()
- Adding prototypes for character-set aware str_to_xxx() functions.
@ sql/protocol.cc
- Changing charsetnr to "binary" client-side metadata for
numeric/datetime data types.
@ sql/time.cc
- Adding to_ascii() helper function, to convert a string
in any character set to ascii representation. In the
future can be extended to understand digits written
in various non-Latin word scripts.
- Adding real multy-byte character set aware versions for str_to_XXXX,
to make these these type of queries work correct:
INSERT INTO t1 SET datetime_column=ucs2_expression;
@ strings/ctype-ucs2.c
- endptr was not calculated correctly. INSERTing of UCS2
values into numeric columns returned warnings about
truncated wrong data.
2010-02-11 08:17:25 +04:00
|
|
|
if (!(ptr= current_thd->strmake(cstr.ptr(), cstr.length())))
|
|
|
|
return NULL;
|
|
|
|
conv->str_value.set(ptr, cstr.length(), cstr.charset());
|
|
|
|
/* Ensure that no one is going to change the result string */
|
|
|
|
conv->str_value.mark_as_const();
|
|
|
|
conv->fix_char_length(max_char_length());
|
2005-07-13 13:00:17 +05:00
|
|
|
return conv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-16 00:52:00 +03:00
|
|
|
Item *Item_static_float_func::safe_charset_converter(CHARSET_INFO *tocs)
|
|
|
|
{
|
|
|
|
Item_string *conv;
|
|
|
|
char buf[64];
|
|
|
|
String *s, tmp(buf, sizeof(buf), &my_charset_bin);
|
|
|
|
s= val_str(&tmp);
|
|
|
|
if ((conv= new Item_static_string_func(func_name, s->ptr(), s->length(),
|
|
|
|
s->charset())))
|
|
|
|
{
|
|
|
|
conv->str_value.copy();
|
|
|
|
conv->str_value.mark_as_const();
|
|
|
|
}
|
|
|
|
return conv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-11 11:16:51 +02:00
|
|
|
Item *Item_string::safe_charset_converter(CHARSET_INFO *tocs)
|
|
|
|
{
|
|
|
|
Item_string *conv;
|
|
|
|
uint conv_errors;
|
2006-03-20 17:41:45 +04:00
|
|
|
char *ptr;
|
2004-11-11 11:16:51 +02:00
|
|
|
String tmp, cstr, *ostr= val_str(&tmp);
|
|
|
|
cstr.copy(ostr->ptr(), ostr->length(), ostr->charset(), tocs, &conv_errors);
|
|
|
|
if (conv_errors || !(conv= new Item_string(cstr.ptr(), cstr.length(),
|
|
|
|
cstr.charset(),
|
|
|
|
collation.derivation)))
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Safe conversion is not possible (or EOM).
|
|
|
|
We could not convert a string into the requested character set
|
|
|
|
without data loss. The target charset does not cover all the
|
|
|
|
characters from the string. Operation cannot be done correctly.
|
|
|
|
*/
|
|
|
|
return NULL;
|
|
|
|
}
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
if (!(ptr= current_thd->strmake(cstr.ptr(), cstr.length())))
|
2006-03-20 17:41:45 +04:00
|
|
|
return NULL;
|
|
|
|
conv->str_value.set(ptr, cstr.length(), cstr.charset());
|
2005-03-21 23:41:28 +02:00
|
|
|
/* Ensure that no one is going to change the result string */
|
|
|
|
conv->str_value.mark_as_const();
|
2004-11-11 11:16:51 +02:00
|
|
|
return conv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-20 11:56:27 +05:00
|
|
|
Item *Item_param::safe_charset_converter(CHARSET_INFO *tocs)
|
|
|
|
{
|
|
|
|
if (const_item())
|
|
|
|
{
|
|
|
|
uint cnv_errors;
|
2005-11-28 12:41:44 +04:00
|
|
|
String *ostr= val_str(&cnvstr);
|
|
|
|
cnvitem->str_value.copy(ostr->ptr(), ostr->length(),
|
|
|
|
ostr->charset(), tocs, &cnv_errors);
|
|
|
|
if (cnv_errors)
|
|
|
|
return NULL;
|
|
|
|
cnvitem->str_value.mark_as_const();
|
|
|
|
cnvitem->max_length= cnvitem->str_value.numchars() * tocs->mbmaxlen;
|
|
|
|
return cnvitem;
|
2005-10-20 11:56:27 +05:00
|
|
|
}
|
2010-02-24 13:15:34 +04:00
|
|
|
return Item::safe_charset_converter(tocs);
|
2005-10-20 11:56:27 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-16 00:01:44 +03:00
|
|
|
Item *Item_static_string_func::safe_charset_converter(CHARSET_INFO *tocs)
|
|
|
|
{
|
|
|
|
Item_string *conv;
|
|
|
|
uint conv_errors;
|
|
|
|
String tmp, cstr, *ostr= val_str(&tmp);
|
|
|
|
cstr.copy(ostr->ptr(), ostr->length(), ostr->charset(), tocs, &conv_errors);
|
|
|
|
if (conv_errors ||
|
|
|
|
!(conv= new Item_static_string_func(func_name,
|
|
|
|
cstr.ptr(), cstr.length(),
|
|
|
|
cstr.charset(),
|
|
|
|
collation.derivation)))
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Safe conversion is not possible (or EOM).
|
|
|
|
We could not convert a string into the requested character set
|
|
|
|
without data loss. The target charset does not cover all the
|
|
|
|
characters from the string. Operation cannot be done correctly.
|
2004-11-11 11:16:51 +02:00
|
|
|
*/
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
conv->str_value.copy();
|
2005-03-21 23:41:28 +02:00
|
|
|
/* Ensure that no one is going to change the result string */
|
|
|
|
conv->str_value.mark_as_const();
|
2004-11-11 11:16:51 +02:00
|
|
|
return conv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-22 14:03:42 +02:00
|
|
|
bool Item_string::eq(const Item *item, bool binary_cmp) const
|
|
|
|
{
|
2005-05-03 12:47:27 +04:00
|
|
|
if (type() == item->type() && item->basic_const_item())
|
2002-03-22 14:03:42 +02:00
|
|
|
{
|
|
|
|
if (binary_cmp)
|
2004-02-16 10:03:25 +02:00
|
|
|
return !stringcmp(&str_value, &item->str_value);
|
2005-10-28 02:36:19 +03:00
|
|
|
return (collation.collation == item->collation.collation &&
|
|
|
|
!sortcmp(&str_value, &item->str_value, collation.collation));
|
2002-03-22 14:03:42 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
2007-03-23 22:08:31 +02:00
|
|
|
Get the value of the function as a MYSQL_TIME structure.
|
2000-07-31 21:29:14 +02:00
|
|
|
As a extra convenience the time structure is reset on error!
|
2007-10-11 13:29:09 -04:00
|
|
|
*/
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2007-03-23 22:08:31 +02:00
|
|
|
bool Item::get_date(MYSQL_TIME *ltime,uint fuzzydate)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2007-03-23 22:08:31 +02:00
|
|
|
if (result_type() == STRING_RESULT)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2007-03-23 22:08:31 +02:00
|
|
|
char buff[40];
|
|
|
|
String tmp(buff,sizeof(buff), &my_charset_bin),*res;
|
|
|
|
if (!(res=val_str(&tmp)) ||
|
WL#2649 Number-to-string conversions
added:
include/ctype_numconv.inc
mysql-test/include/ctype_numconv.inc
mysql-test/r/ctype_binary.result
mysql-test/t/ctype_binary.test
Adding tests
modified:
mysql-test/r/bigint.result
mysql-test/r/case.result
mysql-test/r/create.result
mysql-test/r/ctype_cp1251.result
mysql-test/r/ctype_latin1.result
mysql-test/r/ctype_ucs.result
mysql-test/r/func_gconcat.result
mysql-test/r/func_str.result
mysql-test/r/metadata.result
mysql-test/r/ps_1general.result
mysql-test/r/ps_2myisam.result
mysql-test/r/ps_3innodb.result
mysql-test/r/ps_4heap.result
mysql-test/r/ps_5merge.result
mysql-test/r/show_check.result
mysql-test/r/type_datetime.result
mysql-test/r/type_ranges.result
mysql-test/r/union.result
mysql-test/suite/ndb/r/ps_7ndb.result
mysql-test/t/ctype_cp1251.test
mysql-test/t/ctype_latin1.test
mysql-test/t/ctype_ucs.test
mysql-test/t/func_str.test
Fixing tests
@ sql/field.cc
- Return str result using my_charset_numeric.
- Using real multi-byte aware str_to_XXX functions
to handle tricky charset values propely (e.g. UCS2)
@ sql/field.h
- Changing derivation of non-string field types to DERIVATION_NUMERIC.
- Changing binary() for numeric/datetime fields to always
return TRUE even if charset is not my_charset_bin. We need
this to keep ha_base_keytype() return HA_KEYTYPE_BINARY.
- Adding BINARY_FLAG into some fields, because it's not
being set automatically anymore with
"my_charset_bin to my_charset_numeric" change.
- Changing derivation for numeric/datetime datatypes to a weaker
value, to make "SELECT concat('string', field)" use character
set of the string literal for the result of the function.
@ sql/item.cc
- Implementing generic val_str_ascii().
- Using max_char_length() instead of direct read of max_length
to make "tricky" charsets like UCS2 work.
NOTE: in the future we'll possibly remove all direct reads of max_length
- Fixing Item_num::safe_charset_converter().
Previously it alligned binary string to
character string (for example by adding leading 0x00
when doing binary->UCS2 conversion). Now it just
converts from my_charset_numbner to "tocs".
- Using val_str_ascii() in Item::get_time() to make UCS2 arguments work.
- Other misc changes
@ sql/item.h
- Changing MY_COLL_CMP_CONV and MY_COLL_ALLOW_CONV to
bit operations instead of hard-coded bit masks.
- Addding new method DTCollation.set_numeric().
- Adding new methods to Item.
- Adding helper functions to make code look nicer:
agg_item_charsets_for_string_result()
agg_item_charsets_for_comparison()
- Changing charset for Item_num-derived items
from my_charset_bin to my_charset_numeric
(which is an alias for latin1).
@ sql/item_cmpfunc.cc
- Using new helper functions
- Other misc changes
@ sql/item_cmpfunc.h
- Fixing strcmp() to return max_length=2.
Previously it returned 1, which was wrong,
because it did not fit '-1'.
@ sql/item_func.cc
- Using new helper functions
- Other minor changes
@ sql/item_func.h
- Removing unused functions
- Adding helper functions
agg_arg_charsets_for_string_result()
agg_arg_charsets_for_comparison()
- Adding set_numeric() into constructors of numeric items.
- Using fix_length_and_charset() and fix_char_length()
instead of direct write to max_length.
@ sql/item_geofunc.cc
- Changing class for Item_func_geometry_type and
Item_func_as_wkt from Item_str_func to
Item_str_ascii_func, to make them return UCS2 result
properly (when character_set_connection=ucs2).
@ sql/item_geofunc.h
- Changing class for Item_func_geometry_type and
Item_func_as_wkt from Item_str_func to
Item_str_ascii_func, to make them return UCS2 result
properly (when @@character_set_connection=ucs2).
@ sql/item_strfunc.cc
- Implementing Item_str_func::val_str().
- Renaming val_str to val_str_ascii for some items,
to make them work with UCS2 properly.
- Using new helper functions
- All single-argument functions that expect string
result now call this method:
agg_arg_charsets_for_string_result(collation, args, 1);
This enables character set conversion to @@character_set_connection
in case of pure numeric input.
@ sql/item_strfunc.h
- Introducing Item_str_ascii_func - for functions
which return pure ASCII data, for performance purposes,
as well as for the cases when the old implementation
of val_str() was heavily 8-bit oriented and implementing
a UCS2-aware version is tricky.
@ sql/item_sum.cc
- Using new helper functions.
@ sql/item_timefunc.cc
- Using my_charset_numeric instead of my_charset_bin.
- Using fix_char_length(), fix_length_and_charset()
and fix_length_and_charset_datetime()
instead of direct write to max_length.
- Using tricky-charset aware function str_to_time_with_warn()
@ sql/item_timefunc.h
- Using new helper functions for charset and length initialization.
- Changing base class for Item_func_get_format() to make
it return UCS2 properly (when character_set_connection=ucs2).
@ sql/item_xmlfunc.cc
- Using new helper function
@ sql/my_decimal.cc
- Adding a new DECIMAL to CHAR converter
with real multibyte support (e.g. UCS2)
@ sql/mysql_priv.h
- Introducing a new derivation level for numeric/datetime data types.
- Adding macros for my_charset_numeric and MY_REPERTOIRE_NUMERIC.
- Adding prototypes for str_set_decimal()
- Adding prototypes for character-set aware str_to_xxx() functions.
@ sql/protocol.cc
- Changing charsetnr to "binary" client-side metadata for
numeric/datetime data types.
@ sql/time.cc
- Adding to_ascii() helper function, to convert a string
in any character set to ascii representation. In the
future can be extended to understand digits written
in various non-Latin word scripts.
- Adding real multy-byte character set aware versions for str_to_XXXX,
to make these these type of queries work correct:
INSERT INTO t1 SET datetime_column=ucs2_expression;
@ strings/ctype-ucs2.c
- endptr was not calculated correctly. INSERTing of UCS2
values into numeric columns returned warnings about
truncated wrong data.
2010-02-11 08:17:25 +04:00
|
|
|
str_to_datetime_with_warn(res->charset(), res->ptr(), res->length(),
|
2007-03-23 22:08:31 +02:00
|
|
|
ltime, fuzzydate) <= MYSQL_TIMESTAMP_ERROR)
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int was_cut;
|
2011-03-30 11:08:35 +04:00
|
|
|
longlong value= val_int();
|
|
|
|
|
|
|
|
if (null_value)
|
|
|
|
goto err;
|
|
|
|
|
2007-03-23 22:08:31 +02:00
|
|
|
if (number_to_datetime(value, ltime, fuzzydate, &was_cut) == LL(-1))
|
|
|
|
{
|
|
|
|
char buff[22], *end;
|
|
|
|
end= longlong10_to_str(value, buff, -10);
|
|
|
|
make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
|
|
|
|
buff, (int) (end-buff), MYSQL_TIMESTAMP_NONE,
|
|
|
|
NullS);
|
|
|
|
goto err;
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
return 0;
|
2007-03-23 22:08:31 +02:00
|
|
|
|
|
|
|
err:
|
|
|
|
bzero((char*) ltime,sizeof(*ltime));
|
|
|
|
return 1;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
|
|
|
Get time of first argument.\
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
As a extra convenience the time structure is reset on error!
|
2007-10-11 13:29:09 -04:00
|
|
|
*/
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2007-03-23 22:08:31 +02:00
|
|
|
bool Item::get_time(MYSQL_TIME *ltime)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
char buff[40];
|
2003-01-29 17:31:20 +04:00
|
|
|
String tmp(buff,sizeof(buff),&my_charset_bin),*res;
|
WL#2649 Number-to-string conversions
added:
include/ctype_numconv.inc
mysql-test/include/ctype_numconv.inc
mysql-test/r/ctype_binary.result
mysql-test/t/ctype_binary.test
Adding tests
modified:
mysql-test/r/bigint.result
mysql-test/r/case.result
mysql-test/r/create.result
mysql-test/r/ctype_cp1251.result
mysql-test/r/ctype_latin1.result
mysql-test/r/ctype_ucs.result
mysql-test/r/func_gconcat.result
mysql-test/r/func_str.result
mysql-test/r/metadata.result
mysql-test/r/ps_1general.result
mysql-test/r/ps_2myisam.result
mysql-test/r/ps_3innodb.result
mysql-test/r/ps_4heap.result
mysql-test/r/ps_5merge.result
mysql-test/r/show_check.result
mysql-test/r/type_datetime.result
mysql-test/r/type_ranges.result
mysql-test/r/union.result
mysql-test/suite/ndb/r/ps_7ndb.result
mysql-test/t/ctype_cp1251.test
mysql-test/t/ctype_latin1.test
mysql-test/t/ctype_ucs.test
mysql-test/t/func_str.test
Fixing tests
@ sql/field.cc
- Return str result using my_charset_numeric.
- Using real multi-byte aware str_to_XXX functions
to handle tricky charset values propely (e.g. UCS2)
@ sql/field.h
- Changing derivation of non-string field types to DERIVATION_NUMERIC.
- Changing binary() for numeric/datetime fields to always
return TRUE even if charset is not my_charset_bin. We need
this to keep ha_base_keytype() return HA_KEYTYPE_BINARY.
- Adding BINARY_FLAG into some fields, because it's not
being set automatically anymore with
"my_charset_bin to my_charset_numeric" change.
- Changing derivation for numeric/datetime datatypes to a weaker
value, to make "SELECT concat('string', field)" use character
set of the string literal for the result of the function.
@ sql/item.cc
- Implementing generic val_str_ascii().
- Using max_char_length() instead of direct read of max_length
to make "tricky" charsets like UCS2 work.
NOTE: in the future we'll possibly remove all direct reads of max_length
- Fixing Item_num::safe_charset_converter().
Previously it alligned binary string to
character string (for example by adding leading 0x00
when doing binary->UCS2 conversion). Now it just
converts from my_charset_numbner to "tocs".
- Using val_str_ascii() in Item::get_time() to make UCS2 arguments work.
- Other misc changes
@ sql/item.h
- Changing MY_COLL_CMP_CONV and MY_COLL_ALLOW_CONV to
bit operations instead of hard-coded bit masks.
- Addding new method DTCollation.set_numeric().
- Adding new methods to Item.
- Adding helper functions to make code look nicer:
agg_item_charsets_for_string_result()
agg_item_charsets_for_comparison()
- Changing charset for Item_num-derived items
from my_charset_bin to my_charset_numeric
(which is an alias for latin1).
@ sql/item_cmpfunc.cc
- Using new helper functions
- Other misc changes
@ sql/item_cmpfunc.h
- Fixing strcmp() to return max_length=2.
Previously it returned 1, which was wrong,
because it did not fit '-1'.
@ sql/item_func.cc
- Using new helper functions
- Other minor changes
@ sql/item_func.h
- Removing unused functions
- Adding helper functions
agg_arg_charsets_for_string_result()
agg_arg_charsets_for_comparison()
- Adding set_numeric() into constructors of numeric items.
- Using fix_length_and_charset() and fix_char_length()
instead of direct write to max_length.
@ sql/item_geofunc.cc
- Changing class for Item_func_geometry_type and
Item_func_as_wkt from Item_str_func to
Item_str_ascii_func, to make them return UCS2 result
properly (when character_set_connection=ucs2).
@ sql/item_geofunc.h
- Changing class for Item_func_geometry_type and
Item_func_as_wkt from Item_str_func to
Item_str_ascii_func, to make them return UCS2 result
properly (when @@character_set_connection=ucs2).
@ sql/item_strfunc.cc
- Implementing Item_str_func::val_str().
- Renaming val_str to val_str_ascii for some items,
to make them work with UCS2 properly.
- Using new helper functions
- All single-argument functions that expect string
result now call this method:
agg_arg_charsets_for_string_result(collation, args, 1);
This enables character set conversion to @@character_set_connection
in case of pure numeric input.
@ sql/item_strfunc.h
- Introducing Item_str_ascii_func - for functions
which return pure ASCII data, for performance purposes,
as well as for the cases when the old implementation
of val_str() was heavily 8-bit oriented and implementing
a UCS2-aware version is tricky.
@ sql/item_sum.cc
- Using new helper functions.
@ sql/item_timefunc.cc
- Using my_charset_numeric instead of my_charset_bin.
- Using fix_char_length(), fix_length_and_charset()
and fix_length_and_charset_datetime()
instead of direct write to max_length.
- Using tricky-charset aware function str_to_time_with_warn()
@ sql/item_timefunc.h
- Using new helper functions for charset and length initialization.
- Changing base class for Item_func_get_format() to make
it return UCS2 properly (when character_set_connection=ucs2).
@ sql/item_xmlfunc.cc
- Using new helper function
@ sql/my_decimal.cc
- Adding a new DECIMAL to CHAR converter
with real multibyte support (e.g. UCS2)
@ sql/mysql_priv.h
- Introducing a new derivation level for numeric/datetime data types.
- Adding macros for my_charset_numeric and MY_REPERTOIRE_NUMERIC.
- Adding prototypes for str_set_decimal()
- Adding prototypes for character-set aware str_to_xxx() functions.
@ sql/protocol.cc
- Changing charsetnr to "binary" client-side metadata for
numeric/datetime data types.
@ sql/time.cc
- Adding to_ascii() helper function, to convert a string
in any character set to ascii representation. In the
future can be extended to understand digits written
in various non-Latin word scripts.
- Adding real multy-byte character set aware versions for str_to_XXXX,
to make these these type of queries work correct:
INSERT INTO t1 SET datetime_column=ucs2_expression;
@ strings/ctype-ucs2.c
- endptr was not calculated correctly. INSERTing of UCS2
values into numeric columns returned warnings about
truncated wrong data.
2010-02-11 08:17:25 +04:00
|
|
|
if (!(res=val_str_ascii(&tmp)) ||
|
|
|
|
str_to_time_with_warn(res->charset(), res->ptr(), res->length(), ltime))
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
bzero((char*) ltime,sizeof(*ltime));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-06-07 12:09:10 +04:00
|
|
|
CHARSET_INFO *Item::default_charset()
|
2002-11-06 15:49:53 +04:00
|
|
|
{
|
2003-04-23 18:19:22 +05:00
|
|
|
return current_thd->variables.collation_connection;
|
2002-11-06 15:49:53 +04:00
|
|
|
}
|
|
|
|
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
2002-12-08 19:59:22 +01: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 18:52:22 +03:00
|
|
|
/*
|
|
|
|
Save value in field, but don't give any warnings
|
|
|
|
|
|
|
|
NOTES
|
|
|
|
This is used to temporary store and retrieve a value in a column,
|
|
|
|
for example in opt_range to adjust the key value to fit the column.
|
|
|
|
*/
|
|
|
|
|
2004-09-17 03:08:23 +03:00
|
|
|
int Item::save_in_field_no_warnings(Field *field, bool no_conversions)
|
|
|
|
{
|
|
|
|
int res;
|
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 18:52:22 +03:00
|
|
|
TABLE *table= field->table;
|
|
|
|
THD *thd= table->in_use;
|
2004-09-17 03:08:23 +03:00
|
|
|
enum_check_fields tmp= thd->count_cuted_fields;
|
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 18:52:22 +03:00
|
|
|
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
|
2009-12-22 10:35:56 +01:00
|
|
|
ulonglong sql_mode= thd->variables.sql_mode;
|
2007-10-22 19:32:18 +03:00
|
|
|
thd->variables.sql_mode&= ~(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE);
|
2004-09-17 03:08:23 +03:00
|
|
|
thd->count_cuted_fields= CHECK_FIELD_IGNORE;
|
2011-02-17 13:41:25 +01:00
|
|
|
|
2004-09-17 03:08:23 +03:00
|
|
|
res= save_in_field(field, no_conversions);
|
2011-02-17 13:41:25 +01:00
|
|
|
|
2004-09-17 03:08:23 +03:00
|
|
|
thd->count_cuted_fields= tmp;
|
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 18:52:22 +03:00
|
|
|
dbug_tmp_restore_column_map(table->write_set, old_map);
|
2007-10-22 19:32:18 +03:00
|
|
|
thd->variables.sql_mode= sql_mode;
|
2004-09-17 03:08:23 +03:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-08-25 17:34:34 +04:00
|
|
|
/*****************************************************************************
|
2005-12-07 17:01:17 +03:00
|
|
|
Item_sp_variable methods
|
2005-08-25 17:34:34 +04:00
|
|
|
*****************************************************************************/
|
2005-12-07 17:01:17 +03:00
|
|
|
|
|
|
|
Item_sp_variable::Item_sp_variable(char *sp_var_name_str,
|
|
|
|
uint sp_var_name_length)
|
|
|
|
:m_thd(0)
|
|
|
|
#ifndef DBUG_OFF
|
|
|
|
, m_sp(0)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
m_name.str= sp_var_name_str;
|
|
|
|
m_name.length= sp_var_name_length;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Item_sp_variable::fix_fields(THD *thd, Item **)
|
|
|
|
{
|
|
|
|
Item *it;
|
|
|
|
|
|
|
|
m_thd= thd; /* NOTE: this must be set before any this_xxx() */
|
|
|
|
it= this_item();
|
|
|
|
|
|
|
|
DBUG_ASSERT(it->fixed);
|
|
|
|
|
|
|
|
max_length= it->max_length;
|
|
|
|
decimals= it->decimals;
|
|
|
|
unsigned_flag= it->unsigned_flag;
|
|
|
|
fixed= 1;
|
|
|
|
collation.set(it->collation.collation, it->collation.derivation);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double Item_sp_variable::val_real()
|
2005-02-09 02:50:45 +04:00
|
|
|
{
|
|
|
|
DBUG_ASSERT(fixed);
|
|
|
|
Item *it= this_item();
|
|
|
|
double ret= it->val_real();
|
2005-08-25 17:34:34 +04:00
|
|
|
null_value= it->null_value;
|
2005-02-09 02:50:45 +04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-12-07 17:01:17 +03:00
|
|
|
longlong Item_sp_variable::val_int()
|
2005-02-09 02:50:45 +04:00
|
|
|
{
|
|
|
|
DBUG_ASSERT(fixed);
|
|
|
|
Item *it= this_item();
|
|
|
|
longlong ret= it->val_int();
|
2005-08-25 17:34:34 +04:00
|
|
|
null_value= it->null_value;
|
2005-02-09 02:50:45 +04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-12-07 17:01:17 +03:00
|
|
|
String *Item_sp_variable::val_str(String *sp)
|
2005-02-09 02:50:45 +04:00
|
|
|
{
|
|
|
|
DBUG_ASSERT(fixed);
|
|
|
|
Item *it= this_item();
|
2005-10-06 17:54:43 +03:00
|
|
|
String *res= it->val_str(sp);
|
2005-09-13 15:15:38 +04:00
|
|
|
|
|
|
|
null_value= it->null_value;
|
2005-12-07 17:01:17 +03:00
|
|
|
|
2005-10-06 17:54:43 +03:00
|
|
|
if (!res)
|
|
|
|
return NULL;
|
|
|
|
|
2005-09-08 18:25:42 +02:00
|
|
|
/*
|
|
|
|
This way we mark returned value of val_str as const,
|
|
|
|
so that various functions (e.g. CONCAT) won't try to
|
|
|
|
modify the value of the Item. Analogous mechanism is
|
|
|
|
implemented for Item_param.
|
|
|
|
Without this trick Item_splocal could be changed as a
|
|
|
|
side-effect of expression computation. Here is an example
|
|
|
|
of what happens without it: suppose x is varchar local
|
|
|
|
variable in a SP with initial value 'ab' Then
|
|
|
|
select concat(x,'c');
|
|
|
|
would change x's value to 'abc', as Item_func_concat::val_str()
|
|
|
|
would use x's internal buffer to compute the result.
|
|
|
|
This is intended behaviour of Item_func_concat. Comments to
|
|
|
|
Item_param class contain some more details on the topic.
|
|
|
|
*/
|
2005-09-13 15:15:38 +04:00
|
|
|
|
2005-10-06 17:54:43 +03:00
|
|
|
if (res != &str_value)
|
|
|
|
str_value.set(res->ptr(), res->length(), res->charset());
|
|
|
|
else
|
|
|
|
res->mark_as_const();
|
2005-12-07 17:01:17 +03:00
|
|
|
|
2005-10-06 17:54:43 +03:00
|
|
|
return &str_value;
|
2005-02-09 02:50:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-12-07 17:01:17 +03:00
|
|
|
my_decimal *Item_sp_variable::val_decimal(my_decimal *decimal_value)
|
2005-02-09 02:50:45 +04:00
|
|
|
{
|
|
|
|
DBUG_ASSERT(fixed);
|
|
|
|
Item *it= this_item();
|
2005-04-13 17:43:53 +02:00
|
|
|
my_decimal *val= it->val_decimal(decimal_value);
|
2005-08-25 17:34:34 +04:00
|
|
|
null_value= it->null_value;
|
2005-02-09 02:50:45 +04:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-12-07 17:01:17 +03:00
|
|
|
bool Item_sp_variable::is_null()
|
2005-02-09 02:50:45 +04:00
|
|
|
{
|
2005-12-07 17:01:17 +03:00
|
|
|
return this_item()->is_null();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
Item_splocal methods
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
Item_splocal::Item_splocal(const LEX_STRING &sp_var_name,
|
|
|
|
uint sp_var_idx,
|
|
|
|
enum_field_types sp_var_type,
|
2007-07-30 04:35:16 +05:00
|
|
|
uint pos_in_q, uint len_in_q)
|
2005-12-07 17:01:17 +03:00
|
|
|
:Item_sp_variable(sp_var_name.str, sp_var_name.length),
|
2010-04-14 01:56:19 +04:00
|
|
|
m_var_idx(sp_var_idx),
|
|
|
|
limit_clause_param(FALSE),
|
|
|
|
pos_in_query(pos_in_q), len_in_query(len_in_q)
|
2005-12-07 17:01:17 +03:00
|
|
|
{
|
|
|
|
maybe_null= TRUE;
|
|
|
|
|
|
|
|
m_type= sp_map_item_type(sp_var_type);
|
2007-05-04 18:57:10 +04:00
|
|
|
m_field_type= sp_var_type;
|
2005-12-07 17:01:17 +03:00
|
|
|
m_result_type= sp_map_result_type(sp_var_type);
|
2005-02-09 02:50:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
2002-12-08 19:59:22 +01:00
|
|
|
Item *
|
|
|
|
Item_splocal::this_item()
|
|
|
|
{
|
2005-12-07 17:01:17 +03:00
|
|
|
DBUG_ASSERT(m_sp == m_thd->spcont->sp);
|
|
|
|
|
|
|
|
return m_thd->spcont->get_item(m_var_idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
const Item *
|
|
|
|
Item_splocal::this_item() const
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(m_sp == m_thd->spcont->sp);
|
|
|
|
|
|
|
|
return m_thd->spcont->get_item(m_var_idx);
|
2002-11-06 15:49:53 +04:00
|
|
|
}
|
|
|
|
|
2005-05-09 01:59:10 +03:00
|
|
|
|
|
|
|
Item **
|
2005-12-07 17:01:17 +03:00
|
|
|
Item_splocal::this_item_addr(THD *thd, Item **)
|
2005-05-09 01:59:10 +03:00
|
|
|
{
|
2005-12-07 17:01:17 +03:00
|
|
|
DBUG_ASSERT(m_sp == thd->spcont->sp);
|
|
|
|
|
|
|
|
return thd->spcont->get_item_addr(m_var_idx);
|
2005-05-09 01:59:10 +03:00
|
|
|
}
|
|
|
|
|
2005-12-07 17:01:17 +03:00
|
|
|
|
2008-02-22 13:30:33 +03:00
|
|
|
void Item_splocal::print(String *str, enum_query_type)
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
2002-12-08 19:59:22 +01:00
|
|
|
{
|
2005-12-07 17:01:17 +03:00
|
|
|
str->reserve(m_name.length+8);
|
|
|
|
str->append(m_name.str, m_name.length);
|
|
|
|
str->append('@');
|
|
|
|
str->qs_append(m_var_idx);
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
2002-12-08 19:59:22 +01:00
|
|
|
}
|
|
|
|
|
2005-12-07 17:01:17 +03:00
|
|
|
|
2006-05-15 19:57:10 +02:00
|
|
|
bool Item_splocal::set_value(THD *thd, sp_rcontext *ctx, Item **it)
|
2006-05-12 13:55:21 +04:00
|
|
|
{
|
|
|
|
return ctx->set_variable(thd, get_var_idx(), it);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-12-07 17:01:17 +03:00
|
|
|
/*****************************************************************************
|
|
|
|
Item_case_expr methods
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2007-03-26 12:32:51 +03:00
|
|
|
Item_case_expr::Item_case_expr(uint case_expr_id)
|
2006-08-17 18:13:45 +02:00
|
|
|
:Item_sp_variable( C_STRING_WITH_LEN("case_expr")),
|
2005-12-07 17:01:17 +03:00
|
|
|
m_case_expr_id(case_expr_id)
|
2003-12-04 15:17:55 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-12-07 17:01:17 +03:00
|
|
|
Item *
|
|
|
|
Item_case_expr::this_item()
|
2005-02-09 02:50:45 +04:00
|
|
|
{
|
2005-12-07 17:01:17 +03:00
|
|
|
DBUG_ASSERT(m_sp == m_thd->spcont->sp);
|
|
|
|
|
|
|
|
return m_thd->spcont->get_case_expr(m_case_expr_id);
|
2005-02-09 02:50:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-12-07 17:01:17 +03:00
|
|
|
|
|
|
|
const Item *
|
|
|
|
Item_case_expr::this_item() const
|
2005-02-09 02:50:45 +04:00
|
|
|
{
|
2005-12-07 17:01:17 +03:00
|
|
|
DBUG_ASSERT(m_sp == m_thd->spcont->sp);
|
|
|
|
|
|
|
|
return m_thd->spcont->get_case_expr(m_case_expr_id);
|
2005-02-09 02:50:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-12-07 17:01:17 +03:00
|
|
|
Item **
|
|
|
|
Item_case_expr::this_item_addr(THD *thd, Item **)
|
2005-02-09 02:50:45 +04:00
|
|
|
{
|
2005-12-07 17:01:17 +03:00
|
|
|
DBUG_ASSERT(m_sp == thd->spcont->sp);
|
|
|
|
|
|
|
|
return thd->spcont->get_case_expr_addr(m_case_expr_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-22 13:30:33 +03:00
|
|
|
void Item_case_expr::print(String *str, enum_query_type)
|
2005-12-07 17:01:17 +03:00
|
|
|
{
|
2007-03-26 12:32:51 +03:00
|
|
|
if (str->reserve(MAX_INT_WIDTH + sizeof("case_expr@")))
|
|
|
|
return; /* purecov: inspected */
|
2009-11-24 16:54:59 +03:00
|
|
|
(void) str->append(STRING_WITH_LEN("case_expr@"));
|
2005-12-07 17:01:17 +03:00
|
|
|
str->qs_append(m_case_expr_id);
|
2005-02-09 02:50:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-08-25 17:34:34 +04:00
|
|
|
/*****************************************************************************
|
|
|
|
Item_name_const methods
|
|
|
|
*****************************************************************************/
|
2005-10-06 17:54:43 +03:00
|
|
|
|
2005-08-25 17:34:34 +04:00
|
|
|
double Item_name_const::val_real()
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(fixed);
|
|
|
|
double ret= value_item->val_real();
|
|
|
|
null_value= value_item->null_value;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
longlong Item_name_const::val_int()
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(fixed);
|
|
|
|
longlong ret= value_item->val_int();
|
|
|
|
null_value= value_item->null_value;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String *Item_name_const::val_str(String *sp)
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(fixed);
|
|
|
|
String *ret= value_item->val_str(sp);
|
|
|
|
null_value= value_item->null_value;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
my_decimal *Item_name_const::val_decimal(my_decimal *decimal_value)
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(fixed);
|
|
|
|
my_decimal *val= value_item->val_decimal(decimal_value);
|
2005-08-27 02:33:06 +04:00
|
|
|
null_value= value_item->null_value;
|
2005-08-25 17:34:34 +04:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Item_name_const::is_null()
|
|
|
|
{
|
2005-10-06 17:54:43 +03:00
|
|
|
return value_item->is_null();
|
2005-08-25 17:34:34 +04:00
|
|
|
}
|
|
|
|
|
2008-02-28 14:23:22 +01:00
|
|
|
|
|
|
|
Item_name_const::Item_name_const(Item *name_arg, Item *val):
|
|
|
|
value_item(val), name_item(name_arg)
|
|
|
|
{
|
|
|
|
if (!(valid_args= name_item->basic_const_item() &&
|
|
|
|
(value_item->basic_const_item() ||
|
|
|
|
((value_item->type() == FUNC_ITEM) &&
|
2008-10-01 14:48:47 +05:00
|
|
|
((((Item_func *) value_item)->functype() ==
|
|
|
|
Item_func::COLLATE_FUNC) ||
|
|
|
|
((((Item_func *) value_item)->functype() ==
|
|
|
|
Item_func::NEG_FUNC) &&
|
2008-02-28 14:23:22 +01:00
|
|
|
(((Item_func *) value_item)->key_item()->type() !=
|
2008-10-01 14:48:47 +05:00
|
|
|
FUNC_ITEM)))))))
|
2008-02-28 14:23:22 +01:00
|
|
|
my_error(ER_WRONG_ARGUMENTS, MYF(0), "NAME_CONST");
|
|
|
|
Item::maybe_null= TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-08-25 17:34:34 +04:00
|
|
|
Item::Type Item_name_const::type() const
|
|
|
|
{
|
2007-11-27 09:36:43 +04:00
|
|
|
/*
|
|
|
|
As
|
|
|
|
1. one can try to create the Item_name_const passing non-constant
|
|
|
|
arguments, although it's incorrect and
|
|
|
|
2. the type() method can be called before the fix_fields() to get
|
|
|
|
type information for a further type cast, e.g.
|
|
|
|
if (item->type() == FIELD_ITEM)
|
|
|
|
((Item_field *) item)->...
|
|
|
|
we return NULL_ITEM in the case to avoid wrong casting.
|
2008-02-28 14:23:22 +01:00
|
|
|
|
|
|
|
valid_args guarantees value_item->basic_const_item(); if type is
|
|
|
|
FUNC_ITEM, then we have a fudged item_func_neg() on our hands
|
|
|
|
and return the underlying type.
|
2009-02-05 11:43:39 +04:00
|
|
|
For Item_func_set_collation()
|
|
|
|
e.g. NAME_CONST('name', 'value' COLLATE collation) we return its
|
|
|
|
'value' argument type.
|
2007-11-27 09:36:43 +04:00
|
|
|
*/
|
2009-02-05 11:43:39 +04:00
|
|
|
if (!valid_args)
|
|
|
|
return NULL_ITEM;
|
|
|
|
Item::Type value_type= value_item->type();
|
|
|
|
if (value_type == FUNC_ITEM)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
The second argument of NAME_CONST('name', 'value') must be
|
|
|
|
a simple constant item or a NEG_FUNC/COLLATE_FUNC.
|
|
|
|
*/
|
|
|
|
DBUG_ASSERT(((Item_func *) value_item)->functype() ==
|
|
|
|
Item_func::NEG_FUNC ||
|
|
|
|
((Item_func *) value_item)->functype() ==
|
|
|
|
Item_func::COLLATE_FUNC);
|
|
|
|
return ((Item_func *) value_item)->key_item()->type();
|
|
|
|
}
|
|
|
|
return value_type;
|
2005-08-25 17:34:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-06 17:54:43 +03:00
|
|
|
bool Item_name_const::fix_fields(THD *thd, Item **ref)
|
2005-08-25 17:34:34 +04:00
|
|
|
{
|
|
|
|
char buf[128];
|
|
|
|
String *item_name;
|
|
|
|
String s(buf, sizeof(buf), &my_charset_bin);
|
|
|
|
s.length(0);
|
|
|
|
|
|
|
|
if (value_item->fix_fields(thd, &value_item) ||
|
2007-12-07 23:36:58 -08:00
|
|
|
name_item->fix_fields(thd, &name_item) ||
|
|
|
|
!value_item->const_item() ||
|
|
|
|
!name_item->const_item() ||
|
|
|
|
!(item_name= name_item->val_str(&s))) // Can't have a NULL name
|
|
|
|
{
|
|
|
|
my_error(ER_RESERVED_SYNTAX, MYF(0), "NAME_CONST");
|
2005-08-25 17:34:34 +04:00
|
|
|
return TRUE;
|
2007-12-07 23:36:58 -08:00
|
|
|
}
|
2009-03-26 15:38:17 +08:00
|
|
|
if (is_autogenerated_name)
|
|
|
|
{
|
|
|
|
set_name(item_name->ptr(), (uint) item_name->length(), system_charset_info);
|
|
|
|
}
|
2008-02-19 18:16:17 +04:00
|
|
|
collation.set(value_item->collation.collation, DERIVATION_IMPLICIT);
|
2005-08-25 17:34:34 +04:00
|
|
|
max_length= value_item->max_length;
|
|
|
|
decimals= value_item->decimals;
|
|
|
|
fixed= 1;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-22 13:30:33 +03:00
|
|
|
void Item_name_const::print(String *str, enum_query_type query_type)
|
2005-08-25 17:34:34 +04:00
|
|
|
{
|
2005-11-20 20:47:07 +02:00
|
|
|
str->append(STRING_WITH_LEN("NAME_CONST("));
|
2008-02-22 13:30:33 +03:00
|
|
|
name_item->print(str, query_type);
|
2005-08-25 17:34:34 +04:00
|
|
|
str->append(',');
|
2008-02-22 13:30:33 +03:00
|
|
|
value_item->print(str, query_type);
|
2005-08-25 17:34:34 +04:00
|
|
|
str->append(')');
|
|
|
|
}
|
|
|
|
|
2004-11-11 11:16:51 +02:00
|
|
|
|
2006-10-24 15:26:41 +03:00
|
|
|
/*
|
|
|
|
need a special class to adjust printing : references to aggregate functions
|
|
|
|
must not be printed as refs because the aggregate functions that are added to
|
|
|
|
the front of select list are not printed as well.
|
|
|
|
*/
|
|
|
|
class Item_aggregate_ref : public Item_ref
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Item_aggregate_ref(Name_resolution_context *context_arg, Item **item,
|
|
|
|
const char *table_name_arg, const char *field_name_arg)
|
|
|
|
:Item_ref(context_arg, item, table_name_arg, field_name_arg) {}
|
|
|
|
|
2008-02-22 13:30:33 +03:00
|
|
|
virtual inline void print (String *str, enum_query_type query_type)
|
2006-10-24 15:26:41 +03:00
|
|
|
{
|
|
|
|
if (ref)
|
2008-02-22 13:30:33 +03:00
|
|
|
(*ref)->print(str, query_type);
|
2006-10-24 15:26:41 +03:00
|
|
|
else
|
2008-02-22 13:30:33 +03:00
|
|
|
Item_ident::print(str, query_type);
|
2006-10-24 15:26:41 +03:00
|
|
|
}
|
2008-10-02 17:44:49 +03:00
|
|
|
virtual Ref_Type ref_type() { return AGGREGATE_REF; }
|
2006-10-24 15:26:41 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
|
|
|
Move SUM items out from item tree and replace with reference.
|
2005-02-08 14:41:09 +02:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@param thd Thread handler
|
|
|
|
@param ref_pointer_array Pointer to array of reference fields
|
|
|
|
@param fields All fields in select
|
|
|
|
@param ref Pointer to item
|
|
|
|
@param skip_registered <=> function be must skipped for registered
|
|
|
|
SUM items
|
2005-02-08 14:41:09 +02:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@note
|
|
|
|
This is from split_sum_func2() for items that should be split
|
2005-02-08 14:41:09 +02:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
All found SUM items are added FIRST in the fields list and
|
|
|
|
we replace the item with a reference.
|
2005-02-08 14:41:09 +02:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
thd->fatal_error() may be called if we are out of memory
|
2005-02-08 14:41:09 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
void Item::split_sum_func2(THD *thd, Item **ref_pointer_array,
|
2005-10-15 14:32:37 -07:00
|
|
|
List<Item> &fields, Item **ref,
|
|
|
|
bool skip_registered)
|
2005-02-08 14:41:09 +02:00
|
|
|
{
|
2005-10-15 14:32:37 -07:00
|
|
|
/* An item of type Item_sum is registered <=> ref_by != 0 */
|
|
|
|
if (type() == SUM_FUNC_ITEM && skip_registered &&
|
|
|
|
((Item_sum *) this)->ref_by)
|
|
|
|
return;
|
2007-01-26 17:10:45 -08:00
|
|
|
if ((type() != SUM_FUNC_ITEM && with_sum_func) ||
|
|
|
|
(type() == FUNC_ITEM &&
|
|
|
|
(((Item_func *) this)->functype() == Item_func::ISNOTNULLTEST_FUNC ||
|
|
|
|
((Item_func *) this)->functype() == Item_func::TRIG_COND_FUNC)))
|
2005-02-08 14:41:09 +02:00
|
|
|
{
|
|
|
|
/* Will split complicated items and ignore simple ones */
|
|
|
|
split_sum_func(thd, ref_pointer_array, fields);
|
|
|
|
}
|
2005-09-07 22:38:36 +04:00
|
|
|
else if ((type() == SUM_FUNC_ITEM || (used_tables() & ~PARAM_TABLE_BIT)) &&
|
2006-09-25 05:24:07 -07:00
|
|
|
type() != SUBSELECT_ITEM &&
|
2005-09-07 22:38:36 +04:00
|
|
|
(type() != REF_ITEM ||
|
|
|
|
((Item_ref*)this)->ref_type() == Item_ref::VIEW_REF))
|
2005-02-08 14:41:09 +02:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
Replace item with a reference so that we can easily calculate
|
|
|
|
it (in case of sum functions) or copy it (in case of fields)
|
|
|
|
|
|
|
|
The test above is to ensure we don't do a reference for things
|
|
|
|
that are constants (PARAM_TABLE_BIT is in effect a constant)
|
|
|
|
or already referenced (for example an item in HAVING)
|
2005-09-07 22:38:36 +04:00
|
|
|
Exception is Item_direct_view_ref which we need to convert to
|
|
|
|
Item_ref to allow fields from view being stored in tmp table.
|
2005-02-08 14:41:09 +02:00
|
|
|
*/
|
2007-03-22 14:48:03 -07:00
|
|
|
Item_aggregate_ref *item_ref;
|
2005-02-08 14:41:09 +02:00
|
|
|
uint el= fields.elements;
|
2007-03-22 14:48:03 -07:00
|
|
|
Item *real_itm= real_item();
|
2005-09-07 22:38:36 +04:00
|
|
|
|
2005-09-07 23:32:39 +04:00
|
|
|
ref_pointer_array[el]= real_itm;
|
2007-03-22 14:48:03 -07:00
|
|
|
if (!(item_ref= new Item_aggregate_ref(&thd->lex->current_select->context,
|
2006-10-24 15:26:41 +03:00
|
|
|
ref_pointer_array + el, 0, name)))
|
2005-02-08 14:41:09 +02:00
|
|
|
return; // fatal_error is set
|
2007-03-22 14:48:03 -07:00
|
|
|
if (type() == SUM_FUNC_ITEM)
|
|
|
|
item_ref->depended_from= ((Item_sum *) this)->depended_from();
|
2005-09-07 23:32:39 +04:00
|
|
|
fields.push_front(real_itm);
|
2007-03-22 14:48:03 -07:00
|
|
|
thd->change_item_tree(ref, item_ref);
|
2005-02-08 14:41:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-03 15:25:23 +05:00
|
|
|
static bool
|
|
|
|
left_is_superset(DTCollation *left, DTCollation *right)
|
|
|
|
{
|
|
|
|
/* Allow convert to Unicode */
|
|
|
|
if (left->collation->state & MY_CS_UNICODE &&
|
|
|
|
(left->derivation < right->derivation ||
|
|
|
|
(left->derivation == right->derivation &&
|
2010-02-24 13:15:34 +04:00
|
|
|
(!(right->collation->state & MY_CS_UNICODE) ||
|
|
|
|
/* The code below makes 4-byte utf8 a superset over 3-byte utf8 */
|
|
|
|
(left->collation->state & MY_CS_UNICODE_SUPPLEMENT &&
|
|
|
|
!(right->collation->state & MY_CS_UNICODE_SUPPLEMENT) &&
|
|
|
|
left->collation->mbmaxlen > right->collation->mbmaxlen &&
|
|
|
|
left->collation->mbminlen == right->collation->mbminlen)))))
|
2007-08-03 15:25:23 +05:00
|
|
|
return TRUE;
|
|
|
|
/* Allow convert from ASCII */
|
|
|
|
if (right->repertoire == MY_REPERTOIRE_ASCII &&
|
|
|
|
(left->derivation < right->derivation ||
|
|
|
|
(left->derivation == right->derivation &&
|
|
|
|
!(left->repertoire == MY_REPERTOIRE_ASCII))))
|
|
|
|
return TRUE;
|
|
|
|
/* Disallow conversion otherwise */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
|
|
|
Aggregate two collations together taking
|
|
|
|
into account their coercibility (aka derivation):.
|
|
|
|
|
|
|
|
0 == DERIVATION_EXPLICIT - an explicitly written COLLATE clause @n
|
|
|
|
1 == DERIVATION_NONE - a mix of two different collations @n
|
|
|
|
2 == DERIVATION_IMPLICIT - a column @n
|
|
|
|
3 == DERIVATION_COERCIBLE - a string constant.
|
|
|
|
|
|
|
|
The most important rules are:
|
|
|
|
-# If collations are the same:
|
|
|
|
chose this collation, and the strongest derivation.
|
|
|
|
-# If collations are different:
|
|
|
|
- Character sets may differ, but only if conversion without
|
|
|
|
data loss is possible. The caller provides flags whether
|
|
|
|
character set conversion attempts should be done. If no
|
|
|
|
flags are substituted, then the character sets must be the same.
|
|
|
|
Currently processed flags are:
|
|
|
|
MY_COLL_ALLOW_SUPERSET_CONV - allow conversion to a superset
|
|
|
|
MY_COLL_ALLOW_COERCIBLE_CONV - allow conversion of a coercible value
|
|
|
|
- two EXPLICIT collations produce an error, e.g. this is wrong:
|
|
|
|
CONCAT(expr1 collate latin1_swedish_ci, expr2 collate latin1_german_ci)
|
|
|
|
- the side with smaller derivation value wins,
|
|
|
|
i.e. a column is stronger than a string constant,
|
|
|
|
an explicit COLLATE clause is stronger than a column.
|
|
|
|
- if derivations are the same, we have DERIVATION_NONE,
|
|
|
|
we'll wait for an explicit COLLATE clause which possibly can
|
|
|
|
come from another argument later: for example, this is valid,
|
|
|
|
but we don't know yet when collecting the first two arguments:
|
|
|
|
@code
|
|
|
|
CONCAT(latin1_swedish_ci_column,
|
|
|
|
latin1_german1_ci_column,
|
|
|
|
expr COLLATE latin1_german2_ci)
|
|
|
|
@endcode
|
2004-11-11 11:16:51 +02:00
|
|
|
*/
|
2007-10-11 13:29:09 -04:00
|
|
|
|
2004-11-11 11:16:51 +02:00
|
|
|
bool DTCollation::aggregate(DTCollation &dt, uint flags)
|
2003-03-19 15:55:17 +04:00
|
|
|
{
|
2003-06-24 17:12:07 +05:00
|
|
|
if (!my_charset_same(collation, dt.collation))
|
2003-03-19 15:55:17 +04:00
|
|
|
{
|
2003-06-24 17:12:07 +05:00
|
|
|
/*
|
|
|
|
We do allow to use binary strings (like BLOBS)
|
|
|
|
together with character strings.
|
2005-02-09 02:50:45 +04:00
|
|
|
Binaries have more precedence than a character
|
2003-06-27 16:09:53 +05:00
|
|
|
string of the same derivation.
|
2003-06-24 17:12:07 +05:00
|
|
|
*/
|
2003-06-27 16:08:52 +05:00
|
|
|
if (collation == &my_charset_bin)
|
2003-06-24 17:12:07 +05:00
|
|
|
{
|
2003-06-27 16:08:52 +05:00
|
|
|
if (derivation <= dt.derivation)
|
|
|
|
; // Do nothing
|
|
|
|
else
|
2004-09-01 13:56:33 +05:00
|
|
|
{
|
|
|
|
set(dt);
|
|
|
|
}
|
2003-06-24 17:12:07 +05:00
|
|
|
}
|
2003-06-27 16:08:52 +05:00
|
|
|
else if (dt.collation == &my_charset_bin)
|
2003-06-24 17:12:07 +05:00
|
|
|
{
|
2003-06-27 16:08:52 +05:00
|
|
|
if (dt.derivation <= derivation)
|
2004-09-01 13:56:33 +05:00
|
|
|
{
|
2003-06-27 16:08:52 +05:00
|
|
|
set(dt);
|
2004-09-01 13:56:33 +05:00
|
|
|
}
|
2003-06-24 17:12:07 +05:00
|
|
|
}
|
2004-11-11 11:16:51 +02:00
|
|
|
else if ((flags & MY_COLL_ALLOW_SUPERSET_CONV) &&
|
2007-08-03 15:25:23 +05:00
|
|
|
left_is_superset(this, &dt))
|
2004-09-01 13:56:33 +05:00
|
|
|
{
|
2004-11-11 11:16:51 +02:00
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
else if ((flags & MY_COLL_ALLOW_SUPERSET_CONV) &&
|
2007-08-03 15:25:23 +05:00
|
|
|
left_is_superset(&dt, this))
|
2004-11-11 11:16:51 +02:00
|
|
|
{
|
|
|
|
set(dt);
|
|
|
|
}
|
|
|
|
else if ((flags & MY_COLL_ALLOW_COERCIBLE_CONV) &&
|
|
|
|
derivation < dt.derivation &&
|
2005-03-04 14:20:49 +04:00
|
|
|
dt.derivation >= DERIVATION_SYSCONST)
|
2004-11-11 11:16:51 +02:00
|
|
|
{
|
|
|
|
// Do nothing;
|
|
|
|
}
|
|
|
|
else if ((flags & MY_COLL_ALLOW_COERCIBLE_CONV) &&
|
|
|
|
dt.derivation < derivation &&
|
2005-03-04 14:20:49 +04:00
|
|
|
derivation >= DERIVATION_SYSCONST)
|
2004-11-11 11:16:51 +02:00
|
|
|
{
|
|
|
|
set(dt);
|
2004-09-01 13:56:33 +05:00
|
|
|
}
|
2003-06-24 17:12:07 +05:00
|
|
|
else
|
|
|
|
{
|
2004-11-11 11:16:51 +02:00
|
|
|
// Cannot apply conversion
|
2009-03-19 12:20:28 +04:00
|
|
|
set(&my_charset_bin, DERIVATION_NONE,
|
|
|
|
(dt.repertoire|repertoire));
|
2004-11-11 11:16:51 +02:00
|
|
|
return 1;
|
2003-06-24 17:12:07 +05:00
|
|
|
}
|
2003-03-19 15:55:17 +04:00
|
|
|
}
|
2003-06-24 17:12:07 +05:00
|
|
|
else if (derivation < dt.derivation)
|
2003-03-19 15:55:17 +04:00
|
|
|
{
|
2003-06-24 17:12:07 +05:00
|
|
|
// Do nothing
|
2003-03-19 15:55:17 +04:00
|
|
|
}
|
2003-06-24 17:12:07 +05:00
|
|
|
else if (dt.derivation < derivation)
|
2003-03-19 15:55:17 +04:00
|
|
|
{
|
2003-06-24 17:12:07 +05:00
|
|
|
set(dt);
|
2003-03-19 15:55:17 +04:00
|
|
|
}
|
2003-06-24 17:12:07 +05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (collation == dt.collation)
|
2003-03-19 17:24:46 +04:00
|
|
|
{
|
2003-06-24 17:12:07 +05:00
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (derivation == DERIVATION_EXPLICIT)
|
2003-03-21 11:21:01 +04:00
|
|
|
{
|
2007-08-03 15:25:23 +05:00
|
|
|
set(0, DERIVATION_NONE, 0);
|
|
|
|
return 1;
|
2003-03-21 11:21:01 +04:00
|
|
|
}
|
2005-04-10 12:40:33 +05:00
|
|
|
if (collation->state & MY_CS_BINSORT)
|
|
|
|
return 0;
|
2005-05-05 20:06:49 +05:00
|
|
|
if (dt.collation->state & MY_CS_BINSORT)
|
2005-04-10 12:40:33 +05:00
|
|
|
{
|
|
|
|
set(dt);
|
|
|
|
return 0;
|
|
|
|
}
|
2003-06-24 17:12:07 +05:00
|
|
|
CHARSET_INFO *bin= get_charset_by_csname(collation->csname,
|
2005-04-10 12:40:33 +05:00
|
|
|
MY_CS_BINSORT,MYF(0));
|
2003-06-24 17:12:07 +05:00
|
|
|
set(bin, DERIVATION_NONE);
|
2003-03-19 17:24:46 +04:00
|
|
|
}
|
2003-03-19 15:55:17 +04:00
|
|
|
}
|
2007-08-03 15:25:23 +05:00
|
|
|
repertoire|= dt.repertoire;
|
2003-03-19 15:55:17 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-07-26 12:52:02 +05:00
|
|
|
/******************************/
|
|
|
|
static
|
|
|
|
void my_coll_agg_error(DTCollation &c1, DTCollation &c2, const char *fname)
|
|
|
|
{
|
|
|
|
my_error(ER_CANT_AGGREGATE_2COLLATIONS,MYF(0),
|
|
|
|
c1.collation->name,c1.derivation_name(),
|
|
|
|
c2.collation->name,c2.derivation_name(),
|
|
|
|
fname);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
void my_coll_agg_error(DTCollation &c1, DTCollation &c2, DTCollation &c3,
|
|
|
|
const char *fname)
|
|
|
|
{
|
|
|
|
my_error(ER_CANT_AGGREGATE_3COLLATIONS,MYF(0),
|
|
|
|
c1.collation->name,c1.derivation_name(),
|
|
|
|
c2.collation->name,c2.derivation_name(),
|
|
|
|
c3.collation->name,c3.derivation_name(),
|
|
|
|
fname);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static
|
2006-06-30 09:26:36 +02:00
|
|
|
void my_coll_agg_error(Item** args, uint count, const char *fname,
|
|
|
|
int item_sep)
|
2005-07-26 12:52:02 +05:00
|
|
|
{
|
|
|
|
if (count == 2)
|
2006-06-30 09:26:36 +02:00
|
|
|
my_coll_agg_error(args[0]->collation, args[item_sep]->collation, fname);
|
2005-07-26 12:52:02 +05:00
|
|
|
else if (count == 3)
|
2006-06-30 09:26:36 +02:00
|
|
|
my_coll_agg_error(args[0]->collation, args[item_sep]->collation,
|
|
|
|
args[2*item_sep]->collation, fname);
|
2005-07-26 12:52:02 +05:00
|
|
|
else
|
|
|
|
my_error(ER_CANT_AGGREGATE_NCOLLATIONS,MYF(0),fname);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool agg_item_collations(DTCollation &c, const char *fname,
|
2006-06-30 09:26:36 +02:00
|
|
|
Item **av, uint count, uint flags, int item_sep)
|
2005-07-26 12:52:02 +05:00
|
|
|
{
|
|
|
|
uint i;
|
2006-06-30 09:26:36 +02:00
|
|
|
Item **arg;
|
2009-03-19 12:20:28 +04:00
|
|
|
bool unknown_cs= 0;
|
|
|
|
|
2005-07-26 12:52:02 +05:00
|
|
|
c.set(av[0]->collation);
|
2006-06-30 09:26:36 +02:00
|
|
|
for (i= 1, arg= &av[item_sep]; i < count; i++, arg++)
|
2005-07-26 12:52:02 +05:00
|
|
|
{
|
2006-06-30 09:26:36 +02:00
|
|
|
if (c.aggregate((*arg)->collation, flags))
|
2005-07-26 12:52:02 +05:00
|
|
|
{
|
2009-03-19 12:20:28 +04:00
|
|
|
if (c.derivation == DERIVATION_NONE &&
|
|
|
|
c.collation == &my_charset_bin)
|
|
|
|
{
|
|
|
|
unknown_cs= 1;
|
|
|
|
continue;
|
|
|
|
}
|
2006-06-30 09:26:36 +02:00
|
|
|
my_coll_agg_error(av, count, fname, item_sep);
|
2005-07-26 12:52:02 +05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
2009-03-19 12:20:28 +04:00
|
|
|
|
|
|
|
if (unknown_cs &&
|
|
|
|
c.derivation != DERIVATION_EXPLICIT)
|
|
|
|
{
|
|
|
|
my_coll_agg_error(av, count, fname, item_sep);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-07-26 12:52:02 +05:00
|
|
|
if ((flags & MY_COLL_DISALLOW_NONE) &&
|
|
|
|
c.derivation == DERIVATION_NONE)
|
|
|
|
{
|
2006-06-30 09:26:36 +02:00
|
|
|
my_coll_agg_error(av, count, fname, item_sep);
|
2005-07-26 12:52:02 +05:00
|
|
|
return TRUE;
|
|
|
|
}
|
WL#2649 Number-to-string conversions
added:
include/ctype_numconv.inc
mysql-test/include/ctype_numconv.inc
mysql-test/r/ctype_binary.result
mysql-test/t/ctype_binary.test
Adding tests
modified:
mysql-test/r/bigint.result
mysql-test/r/case.result
mysql-test/r/create.result
mysql-test/r/ctype_cp1251.result
mysql-test/r/ctype_latin1.result
mysql-test/r/ctype_ucs.result
mysql-test/r/func_gconcat.result
mysql-test/r/func_str.result
mysql-test/r/metadata.result
mysql-test/r/ps_1general.result
mysql-test/r/ps_2myisam.result
mysql-test/r/ps_3innodb.result
mysql-test/r/ps_4heap.result
mysql-test/r/ps_5merge.result
mysql-test/r/show_check.result
mysql-test/r/type_datetime.result
mysql-test/r/type_ranges.result
mysql-test/r/union.result
mysql-test/suite/ndb/r/ps_7ndb.result
mysql-test/t/ctype_cp1251.test
mysql-test/t/ctype_latin1.test
mysql-test/t/ctype_ucs.test
mysql-test/t/func_str.test
Fixing tests
@ sql/field.cc
- Return str result using my_charset_numeric.
- Using real multi-byte aware str_to_XXX functions
to handle tricky charset values propely (e.g. UCS2)
@ sql/field.h
- Changing derivation of non-string field types to DERIVATION_NUMERIC.
- Changing binary() for numeric/datetime fields to always
return TRUE even if charset is not my_charset_bin. We need
this to keep ha_base_keytype() return HA_KEYTYPE_BINARY.
- Adding BINARY_FLAG into some fields, because it's not
being set automatically anymore with
"my_charset_bin to my_charset_numeric" change.
- Changing derivation for numeric/datetime datatypes to a weaker
value, to make "SELECT concat('string', field)" use character
set of the string literal for the result of the function.
@ sql/item.cc
- Implementing generic val_str_ascii().
- Using max_char_length() instead of direct read of max_length
to make "tricky" charsets like UCS2 work.
NOTE: in the future we'll possibly remove all direct reads of max_length
- Fixing Item_num::safe_charset_converter().
Previously it alligned binary string to
character string (for example by adding leading 0x00
when doing binary->UCS2 conversion). Now it just
converts from my_charset_numbner to "tocs".
- Using val_str_ascii() in Item::get_time() to make UCS2 arguments work.
- Other misc changes
@ sql/item.h
- Changing MY_COLL_CMP_CONV and MY_COLL_ALLOW_CONV to
bit operations instead of hard-coded bit masks.
- Addding new method DTCollation.set_numeric().
- Adding new methods to Item.
- Adding helper functions to make code look nicer:
agg_item_charsets_for_string_result()
agg_item_charsets_for_comparison()
- Changing charset for Item_num-derived items
from my_charset_bin to my_charset_numeric
(which is an alias for latin1).
@ sql/item_cmpfunc.cc
- Using new helper functions
- Other misc changes
@ sql/item_cmpfunc.h
- Fixing strcmp() to return max_length=2.
Previously it returned 1, which was wrong,
because it did not fit '-1'.
@ sql/item_func.cc
- Using new helper functions
- Other minor changes
@ sql/item_func.h
- Removing unused functions
- Adding helper functions
agg_arg_charsets_for_string_result()
agg_arg_charsets_for_comparison()
- Adding set_numeric() into constructors of numeric items.
- Using fix_length_and_charset() and fix_char_length()
instead of direct write to max_length.
@ sql/item_geofunc.cc
- Changing class for Item_func_geometry_type and
Item_func_as_wkt from Item_str_func to
Item_str_ascii_func, to make them return UCS2 result
properly (when character_set_connection=ucs2).
@ sql/item_geofunc.h
- Changing class for Item_func_geometry_type and
Item_func_as_wkt from Item_str_func to
Item_str_ascii_func, to make them return UCS2 result
properly (when @@character_set_connection=ucs2).
@ sql/item_strfunc.cc
- Implementing Item_str_func::val_str().
- Renaming val_str to val_str_ascii for some items,
to make them work with UCS2 properly.
- Using new helper functions
- All single-argument functions that expect string
result now call this method:
agg_arg_charsets_for_string_result(collation, args, 1);
This enables character set conversion to @@character_set_connection
in case of pure numeric input.
@ sql/item_strfunc.h
- Introducing Item_str_ascii_func - for functions
which return pure ASCII data, for performance purposes,
as well as for the cases when the old implementation
of val_str() was heavily 8-bit oriented and implementing
a UCS2-aware version is tricky.
@ sql/item_sum.cc
- Using new helper functions.
@ sql/item_timefunc.cc
- Using my_charset_numeric instead of my_charset_bin.
- Using fix_char_length(), fix_length_and_charset()
and fix_length_and_charset_datetime()
instead of direct write to max_length.
- Using tricky-charset aware function str_to_time_with_warn()
@ sql/item_timefunc.h
- Using new helper functions for charset and length initialization.
- Changing base class for Item_func_get_format() to make
it return UCS2 properly (when character_set_connection=ucs2).
@ sql/item_xmlfunc.cc
- Using new helper function
@ sql/my_decimal.cc
- Adding a new DECIMAL to CHAR converter
with real multibyte support (e.g. UCS2)
@ sql/mysql_priv.h
- Introducing a new derivation level for numeric/datetime data types.
- Adding macros for my_charset_numeric and MY_REPERTOIRE_NUMERIC.
- Adding prototypes for str_set_decimal()
- Adding prototypes for character-set aware str_to_xxx() functions.
@ sql/protocol.cc
- Changing charsetnr to "binary" client-side metadata for
numeric/datetime data types.
@ sql/time.cc
- Adding to_ascii() helper function, to convert a string
in any character set to ascii representation. In the
future can be extended to understand digits written
in various non-Latin word scripts.
- Adding real multy-byte character set aware versions for str_to_XXXX,
to make these these type of queries work correct:
INSERT INTO t1 SET datetime_column=ucs2_expression;
@ strings/ctype-ucs2.c
- endptr was not calculated correctly. INSERTing of UCS2
values into numeric columns returned warnings about
truncated wrong data.
2010-02-11 08:17:25 +04:00
|
|
|
|
|
|
|
/* If all arguments where numbers, reset to @@collation_connection */
|
2011-04-08 17:15:23 +04:00
|
|
|
if (flags & MY_COLL_ALLOW_NUMERIC_CONV &&
|
|
|
|
c.derivation == DERIVATION_NUMERIC)
|
WL#2649 Number-to-string conversions
added:
include/ctype_numconv.inc
mysql-test/include/ctype_numconv.inc
mysql-test/r/ctype_binary.result
mysql-test/t/ctype_binary.test
Adding tests
modified:
mysql-test/r/bigint.result
mysql-test/r/case.result
mysql-test/r/create.result
mysql-test/r/ctype_cp1251.result
mysql-test/r/ctype_latin1.result
mysql-test/r/ctype_ucs.result
mysql-test/r/func_gconcat.result
mysql-test/r/func_str.result
mysql-test/r/metadata.result
mysql-test/r/ps_1general.result
mysql-test/r/ps_2myisam.result
mysql-test/r/ps_3innodb.result
mysql-test/r/ps_4heap.result
mysql-test/r/ps_5merge.result
mysql-test/r/show_check.result
mysql-test/r/type_datetime.result
mysql-test/r/type_ranges.result
mysql-test/r/union.result
mysql-test/suite/ndb/r/ps_7ndb.result
mysql-test/t/ctype_cp1251.test
mysql-test/t/ctype_latin1.test
mysql-test/t/ctype_ucs.test
mysql-test/t/func_str.test
Fixing tests
@ sql/field.cc
- Return str result using my_charset_numeric.
- Using real multi-byte aware str_to_XXX functions
to handle tricky charset values propely (e.g. UCS2)
@ sql/field.h
- Changing derivation of non-string field types to DERIVATION_NUMERIC.
- Changing binary() for numeric/datetime fields to always
return TRUE even if charset is not my_charset_bin. We need
this to keep ha_base_keytype() return HA_KEYTYPE_BINARY.
- Adding BINARY_FLAG into some fields, because it's not
being set automatically anymore with
"my_charset_bin to my_charset_numeric" change.
- Changing derivation for numeric/datetime datatypes to a weaker
value, to make "SELECT concat('string', field)" use character
set of the string literal for the result of the function.
@ sql/item.cc
- Implementing generic val_str_ascii().
- Using max_char_length() instead of direct read of max_length
to make "tricky" charsets like UCS2 work.
NOTE: in the future we'll possibly remove all direct reads of max_length
- Fixing Item_num::safe_charset_converter().
Previously it alligned binary string to
character string (for example by adding leading 0x00
when doing binary->UCS2 conversion). Now it just
converts from my_charset_numbner to "tocs".
- Using val_str_ascii() in Item::get_time() to make UCS2 arguments work.
- Other misc changes
@ sql/item.h
- Changing MY_COLL_CMP_CONV and MY_COLL_ALLOW_CONV to
bit operations instead of hard-coded bit masks.
- Addding new method DTCollation.set_numeric().
- Adding new methods to Item.
- Adding helper functions to make code look nicer:
agg_item_charsets_for_string_result()
agg_item_charsets_for_comparison()
- Changing charset for Item_num-derived items
from my_charset_bin to my_charset_numeric
(which is an alias for latin1).
@ sql/item_cmpfunc.cc
- Using new helper functions
- Other misc changes
@ sql/item_cmpfunc.h
- Fixing strcmp() to return max_length=2.
Previously it returned 1, which was wrong,
because it did not fit '-1'.
@ sql/item_func.cc
- Using new helper functions
- Other minor changes
@ sql/item_func.h
- Removing unused functions
- Adding helper functions
agg_arg_charsets_for_string_result()
agg_arg_charsets_for_comparison()
- Adding set_numeric() into constructors of numeric items.
- Using fix_length_and_charset() and fix_char_length()
instead of direct write to max_length.
@ sql/item_geofunc.cc
- Changing class for Item_func_geometry_type and
Item_func_as_wkt from Item_str_func to
Item_str_ascii_func, to make them return UCS2 result
properly (when character_set_connection=ucs2).
@ sql/item_geofunc.h
- Changing class for Item_func_geometry_type and
Item_func_as_wkt from Item_str_func to
Item_str_ascii_func, to make them return UCS2 result
properly (when @@character_set_connection=ucs2).
@ sql/item_strfunc.cc
- Implementing Item_str_func::val_str().
- Renaming val_str to val_str_ascii for some items,
to make them work with UCS2 properly.
- Using new helper functions
- All single-argument functions that expect string
result now call this method:
agg_arg_charsets_for_string_result(collation, args, 1);
This enables character set conversion to @@character_set_connection
in case of pure numeric input.
@ sql/item_strfunc.h
- Introducing Item_str_ascii_func - for functions
which return pure ASCII data, for performance purposes,
as well as for the cases when the old implementation
of val_str() was heavily 8-bit oriented and implementing
a UCS2-aware version is tricky.
@ sql/item_sum.cc
- Using new helper functions.
@ sql/item_timefunc.cc
- Using my_charset_numeric instead of my_charset_bin.
- Using fix_char_length(), fix_length_and_charset()
and fix_length_and_charset_datetime()
instead of direct write to max_length.
- Using tricky-charset aware function str_to_time_with_warn()
@ sql/item_timefunc.h
- Using new helper functions for charset and length initialization.
- Changing base class for Item_func_get_format() to make
it return UCS2 properly (when character_set_connection=ucs2).
@ sql/item_xmlfunc.cc
- Using new helper function
@ sql/my_decimal.cc
- Adding a new DECIMAL to CHAR converter
with real multibyte support (e.g. UCS2)
@ sql/mysql_priv.h
- Introducing a new derivation level for numeric/datetime data types.
- Adding macros for my_charset_numeric and MY_REPERTOIRE_NUMERIC.
- Adding prototypes for str_set_decimal()
- Adding prototypes for character-set aware str_to_xxx() functions.
@ sql/protocol.cc
- Changing charsetnr to "binary" client-side metadata for
numeric/datetime data types.
@ sql/time.cc
- Adding to_ascii() helper function, to convert a string
in any character set to ascii representation. In the
future can be extended to understand digits written
in various non-Latin word scripts.
- Adding real multy-byte character set aware versions for str_to_XXXX,
to make these these type of queries work correct:
INSERT INTO t1 SET datetime_column=ucs2_expression;
@ strings/ctype-ucs2.c
- endptr was not calculated correctly. INSERTing of UCS2
values into numeric columns returned warnings about
truncated wrong data.
2010-02-11 08:17:25 +04:00
|
|
|
c.set(Item::default_charset(), DERIVATION_COERCIBLE, MY_REPERTOIRE_NUMERIC);
|
|
|
|
|
2005-07-26 12:52:02 +05:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool agg_item_collations_for_comparison(DTCollation &c, const char *fname,
|
|
|
|
Item **av, uint count, uint flags)
|
|
|
|
{
|
|
|
|
return (agg_item_collations(c, fname, av, count,
|
2006-06-30 09:26:36 +02:00
|
|
|
flags | MY_COLL_DISALLOW_NONE, 1));
|
2005-07-26 12:52:02 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-19 17:20:44 +04:00
|
|
|
bool agg_item_set_converter(DTCollation &coll, const char *fname,
|
|
|
|
Item **args, uint nargs, uint flags, int item_sep)
|
2005-07-26 12:52:02 +05:00
|
|
|
{
|
2009-08-28 17:51:31 +02:00
|
|
|
Item **arg, *safe_args[2]= {NULL, NULL};
|
2006-03-29 14:27:36 +03:00
|
|
|
|
2005-07-26 12:52:02 +05:00
|
|
|
/*
|
|
|
|
For better error reporting: save the first and the second argument.
|
|
|
|
We need this only if the the number of args is 3 or 2:
|
|
|
|
- for a longer argument list, "Illegal mix of collations"
|
|
|
|
doesn't display each argument's characteristics.
|
|
|
|
- if nargs is 1, then this error cannot happen.
|
|
|
|
*/
|
|
|
|
if (nargs >=2 && nargs <= 3)
|
|
|
|
{
|
|
|
|
safe_args[0]= args[0];
|
2006-06-30 09:26:36 +02:00
|
|
|
safe_args[1]= args[item_sep];
|
2005-07-26 12:52:02 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
THD *thd= current_thd;
|
|
|
|
bool res= FALSE;
|
2006-06-30 09:26:36 +02:00
|
|
|
uint i;
|
2011-05-06 15:41:24 +04:00
|
|
|
|
2005-07-26 12:52:02 +05:00
|
|
|
/*
|
|
|
|
In case we're in statement prepare, create conversion item
|
|
|
|
in its memory: it will be reused on each execute.
|
|
|
|
*/
|
2011-05-06 15:41:24 +04:00
|
|
|
Query_arena backup;
|
|
|
|
Query_arena *arena= thd->stmt_arena->is_stmt_prepare() ?
|
|
|
|
thd->activate_stmt_arena_if_needed(&backup) :
|
|
|
|
NULL;
|
2005-07-26 12:52:02 +05:00
|
|
|
|
2006-06-30 09:26:36 +02:00
|
|
|
for (i= 0, arg= args; i < nargs; i++, arg+= item_sep)
|
2005-07-26 12:52:02 +05:00
|
|
|
{
|
|
|
|
Item* conv;
|
|
|
|
uint32 dummy_offset;
|
2010-02-24 13:15:34 +04:00
|
|
|
if (!String::needs_conversion(1, (*arg)->collation.collation,
|
2007-08-03 15:25:23 +05:00
|
|
|
coll.collation,
|
2005-07-26 12:52:02 +05:00
|
|
|
&dummy_offset))
|
|
|
|
continue;
|
|
|
|
|
2010-05-05 13:28:37 +04:00
|
|
|
/*
|
|
|
|
No needs to add converter if an "arg" is NUMERIC or DATETIME
|
|
|
|
value (which is pure ASCII) and at the same time target DTCollation
|
|
|
|
is ASCII-compatible. For example, no needs to rewrite:
|
|
|
|
SELECT * FROM t1 WHERE datetime_field = '2010-01-01';
|
|
|
|
to
|
|
|
|
SELECT * FROM t1 WHERE CONVERT(datetime_field USING cs) = '2010-01-01';
|
|
|
|
|
|
|
|
TODO: avoid conversion of any values with
|
|
|
|
repertoire ASCII and 7bit-ASCII-compatible,
|
|
|
|
not only numeric/datetime origin.
|
|
|
|
*/
|
|
|
|
if ((*arg)->collation.derivation == DERIVATION_NUMERIC &&
|
|
|
|
(*arg)->collation.repertoire == MY_REPERTOIRE_ASCII &&
|
|
|
|
!((*arg)->collation.collation->state & MY_CS_NONASCII) &&
|
|
|
|
!(coll.collation->state & MY_CS_NONASCII))
|
|
|
|
continue;
|
|
|
|
|
2007-08-03 15:25:23 +05:00
|
|
|
if (!(conv= (*arg)->safe_charset_converter(coll.collation)) &&
|
|
|
|
((*arg)->collation.repertoire == MY_REPERTOIRE_ASCII))
|
Fixed following problems:
--Bug#52157 various crashes and assertions with multi-table update, stored function
--Bug#54475 improper error handling causes cascading crashing failures in innodb/ndb
--Bug#57703 create view cause Assertion failed: 0, file .\item_subselect.cc, line 846
--Bug#57352 valgrind warnings when creating view
--Recently discovered problem when a nested materialized derived table is used
before being populated and it leads to incorrect result
We have several modes when we should disable subquery evaluation.
The reasons for disabling are different. It could be
uselessness of the evaluation as in case of 'CREATE VIEW'
or 'PREPARE stmt', or we should disable subquery evaluation
if tables are not locked yet as it happens in bug#54475, or
too early evaluation of subqueries can lead to wrong result
as it happened in Bug#19077.
Main problem is that if subquery items are treated as const
they are evaluated in ::fix_fields(), ::fix_length_and_dec()
of the parental items as a lot of these methods have
Item::val_...() calls inside.
We have to make subqueries non-const to prevent unnecessary
subquery evaluation. At the moment we have different methods
for this. Here is a list of these modes:
1. PREPARE stmt;
We use UNCACHEABLE_PREPARE flag.
It is set during parsing in sql_parse.cc, mysql_new_select() for
each SELECT_LEX object and cleared at the end of PREPARE in
sql_prepare.cc, init_stmt_after_parse(). If this flag is set
subquery becomes non-const and evaluation does not happen.
2. CREATE|ALTER VIEW, SHOW CREATE VIEW, I_S tables which
process FRM files
We use LEX::view_prepare_mode field. We set it before
view preparation and check this flag in
::fix_fields(), ::fix_length_and_dec().
Some bugs are fixed using this approach,
some are not(Bug#57352, Bug#57703). The problem here is
that we have a lot of ::fix_fields(), ::fix_length_and_dec()
where we use Item::val_...() calls for const items.
3. Derived tables with subquery = wrong result(Bug19077)
The reason of this bug is too early subquery evaluation.
It was fixed by adding Item::with_subselect field
The check of this field in appropriate places prevents
const item evaluation if the item have subquery.
The fix for Bug19077 fixes only the problem with
convert_constant_item() function and does not cover
other places(::fix_fields(), ::fix_length_and_dec() again)
where subqueries could be evaluated.
Example:
CREATE TABLE t1 (i INT, j BIGINT);
INSERT INTO t1 VALUES (1, 2), (2, 2), (3, 2);
SELECT * FROM (SELECT MIN(i) FROM t1
WHERE j = SUBSTRING('12', (SELECT * FROM (SELECT MIN(j) FROM t1) t2))) t3;
DROP TABLE t1;
4. Derived tables with subquery where subquery
is evaluated before table locking(Bug#54475, Bug#52157)
Suggested solution is following:
-Introduce new field LEX::context_analysis_only with the following
possible flags:
#define CONTEXT_ANALYSIS_ONLY_PREPARE 1
#define CONTEXT_ANALYSIS_ONLY_VIEW 2
#define CONTEXT_ANALYSIS_ONLY_DERIVED 4
-Set/clean these flags when we perform
context analysis operation
-Item_subselect::const_item() returns
result depending on LEX::context_analysis_only.
If context_analysis_only is set then we return
FALSE that means that subquery is non-const.
As all subquery types are wrapped by Item_subselect
it allow as to make subquery non-const when
it's necessary.
2010-12-14 12:33:03 +03:00
|
|
|
conv= new Item_func_conv_charset(*arg, coll.collation, 1);
|
2007-08-03 15:25:23 +05:00
|
|
|
|
|
|
|
if (!conv)
|
2005-07-26 12:52:02 +05:00
|
|
|
{
|
|
|
|
if (nargs >=2 && nargs <= 3)
|
|
|
|
{
|
|
|
|
/* restore the original arguments for better error message */
|
|
|
|
args[0]= safe_args[0];
|
2006-06-30 09:26:36 +02:00
|
|
|
args[item_sep]= safe_args[1];
|
2005-07-26 12:52:02 +05:00
|
|
|
}
|
2006-06-30 09:26:36 +02:00
|
|
|
my_coll_agg_error(args, nargs, fname, item_sep);
|
2005-07-26 12:52:02 +05:00
|
|
|
res= TRUE;
|
|
|
|
break; // we cannot return here, we need to restore "arena".
|
|
|
|
}
|
2005-07-26 14:52:33 +05:00
|
|
|
if ((*arg)->type() == Item::FIELD_ITEM)
|
|
|
|
((Item_field *)(*arg))->no_const_subst= 1;
|
2005-07-26 12:52:02 +05:00
|
|
|
/*
|
|
|
|
If in statement prepare, then we create a converter for two
|
|
|
|
constant items, do it once and then reuse it.
|
|
|
|
If we're in execution of a prepared statement, arena is NULL,
|
|
|
|
and the conv was created in runtime memory. This can be
|
|
|
|
the case only if the argument is a parameter marker ('?'),
|
|
|
|
because for all true constants the charset converter has already
|
|
|
|
been created in prepare. In this case register the change for
|
|
|
|
rollback.
|
|
|
|
*/
|
2011-05-06 15:39:40 +04:00
|
|
|
if (thd->stmt_arena->is_stmt_prepare())
|
2005-07-26 12:52:02 +05:00
|
|
|
*arg= conv;
|
|
|
|
else
|
|
|
|
thd->change_item_tree(arg, conv);
|
2010-11-04 09:36:04 +01:00
|
|
|
|
|
|
|
if (conv->fix_fields(thd, arg))
|
|
|
|
{
|
|
|
|
res= TRUE;
|
|
|
|
break; // we cannot return here, we need to restore "arena".
|
|
|
|
}
|
2005-07-26 12:52:02 +05:00
|
|
|
}
|
|
|
|
if (arena)
|
2005-09-02 17:21:19 +04:00
|
|
|
thd->restore_active_arena(arena, &backup);
|
2005-07-26 12:52:02 +05:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-19 17:20:44 +04:00
|
|
|
/*
|
|
|
|
Collect arguments' character sets together.
|
|
|
|
We allow to apply automatic character set conversion in some cases.
|
|
|
|
The conditions when conversion is possible are:
|
|
|
|
- arguments A and B have different charsets
|
|
|
|
- A wins according to coercibility rules
|
|
|
|
(i.e. a column is stronger than a string constant,
|
|
|
|
an explicit COLLATE clause is stronger than a column)
|
|
|
|
- character set of A is either superset for character set of B,
|
|
|
|
or B is a string constant which can be converted into the
|
|
|
|
character set of A without data loss.
|
|
|
|
|
|
|
|
If all of the above is true, then it's possible to convert
|
|
|
|
B into the character set of A, and then compare according
|
|
|
|
to the collation of A.
|
|
|
|
|
|
|
|
For functions with more than two arguments:
|
|
|
|
|
|
|
|
collect(A,B,C) ::= collect(collect(A,B),C)
|
|
|
|
|
|
|
|
Since this function calls THD::change_item_tree() on the passed Item **
|
|
|
|
pointers, it is necessary to pass the original Item **'s, not copies.
|
|
|
|
Otherwise their values will not be properly restored (see BUG#20769).
|
|
|
|
If the items are not consecutive (eg. args[2] and args[5]), use the
|
|
|
|
item_sep argument, ie.
|
|
|
|
|
|
|
|
agg_item_charsets(coll, fname, &args[2], 2, flags, 3)
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool agg_item_charsets(DTCollation &coll, const char *fname,
|
|
|
|
Item **args, uint nargs, uint flags, int item_sep)
|
|
|
|
{
|
|
|
|
if (agg_item_collations(coll, fname, args, nargs, flags, item_sep))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return agg_item_set_converter(coll, fname, args, nargs, flags, item_sep);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-29 16:52:46 +05:00
|
|
|
void Item_ident_for_show::make_field(Send_field *tmp_field)
|
|
|
|
{
|
|
|
|
tmp_field->table_name= tmp_field->org_table_name= table_name;
|
|
|
|
tmp_field->db_name= db_name;
|
|
|
|
tmp_field->col_name= tmp_field->org_col_name= field->field_name;
|
|
|
|
tmp_field->charsetnr= field->charset()->number;
|
|
|
|
tmp_field->length=field->field_length;
|
|
|
|
tmp_field->type=field->type();
|
|
|
|
tmp_field->flags= field->table->maybe_null ?
|
|
|
|
(field->flags & ~NOT_NULL_FLAG) : field->flags;
|
2007-08-06 14:22:24 +04:00
|
|
|
tmp_field->decimals= field->decimals();
|
2006-06-29 16:52:46 +05:00
|
|
|
}
|
2005-07-26 12:52:02 +05:00
|
|
|
|
|
|
|
/**********************************************/
|
|
|
|
|
2004-03-20 13:36:26 +02:00
|
|
|
Item_field::Item_field(Field *f)
|
2005-07-01 07:05:42 +03:00
|
|
|
:Item_ident(0, NullS, *f->table_name, f->field_name),
|
2005-11-23 22:45:02 +02:00
|
|
|
item_equal(0), no_const_subst(0),
|
2007-04-15 08:31:34 +04:00
|
|
|
have_privileges(0), any_privileges(0)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
set_field(f);
|
2004-11-11 11:16:51 +02:00
|
|
|
/*
|
2005-11-23 22:45:02 +02:00
|
|
|
field_name and table_name should not point to garbage
|
2004-11-11 11:16:51 +02:00
|
|
|
if this item is to be reused
|
|
|
|
*/
|
|
|
|
orig_table_name= orig_field_name= "";
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2005-11-23 22:45:02 +02:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
|
|
|
Constructor used inside setup_wild().
|
|
|
|
|
|
|
|
Ensures that field, table, and database names will live as long as
|
|
|
|
Item_field (this is important in prepared statements).
|
|
|
|
*/
|
|
|
|
|
2005-07-01 07:05:42 +03:00
|
|
|
Item_field::Item_field(THD *thd, Name_resolution_context *context_arg,
|
|
|
|
Field *f)
|
2005-11-23 22:45:02 +02:00
|
|
|
:Item_ident(context_arg, f->table->s->db.str, *f->table_name, f->field_name),
|
2004-10-19 14:12:55 -07:00
|
|
|
item_equal(0), no_const_subst(0),
|
2007-04-15 08:31:34 +04:00
|
|
|
have_privileges(0), any_privileges(0)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2004-11-11 11:16:51 +02:00
|
|
|
/*
|
|
|
|
We always need to provide Item_field with a fully qualified field
|
|
|
|
name to avoid ambiguity when executing prepared statements like
|
|
|
|
SELECT * from d1.t1, d2.t1; (assuming d1.t1 and d2.t1 have columns
|
|
|
|
with same names).
|
|
|
|
This is because prepared statements never deal with wildcards in
|
|
|
|
select list ('*') and always fix fields using fully specified path
|
|
|
|
(i.e. db.table.column).
|
|
|
|
No check for OOM: if db_name is NULL, we'll just get
|
|
|
|
"Field not found" error.
|
|
|
|
We need to copy db_name, table_name and field_name because they must
|
|
|
|
be allocated in the statement memory, not in table memory (the table
|
|
|
|
structure can go away and pop up again between subsequent executions
|
2008-10-08 02:34:00 +05:00
|
|
|
of a prepared statement or after the close_tables_for_reopen() call
|
2008-10-14 11:04:36 -03:00
|
|
|
in mysql_multi_update_prepare() or due to wildcard expansion in stored
|
|
|
|
procedures).
|
2004-11-11 11:16:51 +02:00
|
|
|
*/
|
|
|
|
{
|
|
|
|
if (db_name)
|
|
|
|
orig_db_name= thd->strdup(db_name);
|
2008-10-08 02:34:00 +05:00
|
|
|
if (table_name)
|
|
|
|
orig_table_name= thd->strdup(table_name);
|
|
|
|
if (field_name)
|
|
|
|
orig_field_name= thd->strdup(field_name);
|
2004-11-11 11:16:51 +02:00
|
|
|
/*
|
|
|
|
We don't restore 'name' in cleanup because it's not changed
|
|
|
|
during execution. Still we need it to point to persistent
|
|
|
|
memory if this item is to be reused.
|
|
|
|
*/
|
|
|
|
name= (char*) orig_field_name;
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
set_field(f);
|
|
|
|
}
|
|
|
|
|
2005-07-01 07:05:42 +03:00
|
|
|
|
|
|
|
Item_field::Item_field(Name_resolution_context *context_arg,
|
|
|
|
const char *db_arg,const char *table_name_arg,
|
|
|
|
const char *field_name_arg)
|
|
|
|
:Item_ident(context_arg, db_arg,table_name_arg,field_name_arg),
|
|
|
|
field(0), result_field(0), item_equal(0), no_const_subst(0),
|
2007-04-15 08:31:34 +04:00
|
|
|
have_privileges(0), any_privileges(0)
|
2005-07-01 07:05:42 +03:00
|
|
|
{
|
2007-02-24 23:04:15 +03:00
|
|
|
SELECT_LEX *select= current_thd->lex->current_select;
|
2005-07-01 07:05:42 +03:00
|
|
|
collation.set(DERIVATION_IMPLICIT);
|
2007-02-24 23:04:15 +03:00
|
|
|
if (select && select->parsing_place != IN_HAVING)
|
|
|
|
select->select_n_where_fields++;
|
2005-07-01 07:05:42 +03:00
|
|
|
}
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
|
|
|
Constructor need to process subselect with temporary tables (see Item)
|
|
|
|
*/
|
|
|
|
|
2004-01-19 19:53:25 +04:00
|
|
|
Item_field::Item_field(THD *thd, Item_field *item)
|
2003-10-19 14:25:33 +03:00
|
|
|
:Item_ident(thd, item),
|
2004-01-19 19:53:25 +04:00
|
|
|
field(item->field),
|
2004-07-16 01:15:55 +03:00
|
|
|
result_field(item->result_field),
|
2004-10-19 14:12:55 -07:00
|
|
|
item_equal(item->item_equal),
|
|
|
|
no_const_subst(item->no_const_subst),
|
2004-07-16 01:15:55 +03:00
|
|
|
have_privileges(item->have_privileges),
|
2007-04-15 08:31:34 +04:00
|
|
|
any_privileges(item->any_privileges)
|
2003-10-19 14:25:33 +03:00
|
|
|
{
|
|
|
|
collation.set(DERIVATION_IMPLICIT);
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2011-05-11 14:11:57 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
Calculate the max column length not taking into account the
|
|
|
|
limitations over integer types.
|
|
|
|
|
|
|
|
When storing data into fields the server currently just ignores the
|
|
|
|
limits specified on integer types, e.g. 1234 can safely be stored in
|
|
|
|
an int(2) and will not cause an error.
|
|
|
|
Thus when creating temporary tables and doing transformations
|
|
|
|
we must adjust the maximum field length to reflect this fact.
|
|
|
|
We take the un-restricted maximum length and adjust it similarly to
|
|
|
|
how the declared length is adjusted wrt unsignedness etc.
|
|
|
|
TODO: this all needs to go when we disable storing 1234 in int(2).
|
|
|
|
|
|
|
|
@param field_par Original field the use to calculate the lengths
|
|
|
|
@param max_length Item's calculated explicit max length
|
|
|
|
@return The adjusted max length
|
|
|
|
*/
|
|
|
|
|
|
|
|
inline static uint32
|
|
|
|
adjust_max_effective_column_length(Field *field_par, uint32 max_length)
|
|
|
|
{
|
|
|
|
uint32 new_max_length= field_par->max_display_length();
|
|
|
|
uint32 sign_length= (field_par->flags & UNSIGNED_FLAG) ? 0 : 1;
|
|
|
|
|
|
|
|
switch (field_par->type())
|
|
|
|
{
|
|
|
|
case MYSQL_TYPE_INT24:
|
|
|
|
/*
|
|
|
|
Compensate for MAX_MEDIUMINT_WIDTH being 1 too long (8)
|
|
|
|
compared to the actual number of digits that can fit into
|
|
|
|
the column.
|
|
|
|
*/
|
|
|
|
new_max_length+= 1;
|
|
|
|
/* fall through */
|
|
|
|
case MYSQL_TYPE_LONG:
|
|
|
|
case MYSQL_TYPE_TINY:
|
|
|
|
case MYSQL_TYPE_SHORT:
|
|
|
|
|
|
|
|
/* Take out the sign and add a conditional sign */
|
|
|
|
new_max_length= new_max_length - 1 + sign_length;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* BINGINT is always 20 no matter the sign */
|
|
|
|
case MYSQL_TYPE_LONGLONG:
|
|
|
|
/* make gcc happy */
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Adjust only if the actual precision based one is bigger than specified */
|
|
|
|
return new_max_length > max_length ? new_max_length : max_length;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
void Item_field::set_field(Field *field_par)
|
|
|
|
{
|
|
|
|
field=result_field=field_par; // for easy coding with fields
|
|
|
|
maybe_null=field->maybe_null();
|
|
|
|
decimals= field->decimals();
|
2005-01-06 13:00:13 +02:00
|
|
|
table_name= *field_par->table_name;
|
|
|
|
field_name= field_par->field_name;
|
2005-11-23 22:45:02 +02:00
|
|
|
db_name= field_par->table->s->db.str;
|
2004-11-24 19:48:30 +02:00
|
|
|
alias_name_used= field_par->table->alias_name_used;
|
2001-09-27 21:45:48 +03:00
|
|
|
unsigned_flag=test(field_par->flags & UNSIGNED_FLAG);
|
WL#2649 Number-to-string conversions
added:
include/ctype_numconv.inc
mysql-test/include/ctype_numconv.inc
mysql-test/r/ctype_binary.result
mysql-test/t/ctype_binary.test
Adding tests
modified:
mysql-test/r/bigint.result
mysql-test/r/case.result
mysql-test/r/create.result
mysql-test/r/ctype_cp1251.result
mysql-test/r/ctype_latin1.result
mysql-test/r/ctype_ucs.result
mysql-test/r/func_gconcat.result
mysql-test/r/func_str.result
mysql-test/r/metadata.result
mysql-test/r/ps_1general.result
mysql-test/r/ps_2myisam.result
mysql-test/r/ps_3innodb.result
mysql-test/r/ps_4heap.result
mysql-test/r/ps_5merge.result
mysql-test/r/show_check.result
mysql-test/r/type_datetime.result
mysql-test/r/type_ranges.result
mysql-test/r/union.result
mysql-test/suite/ndb/r/ps_7ndb.result
mysql-test/t/ctype_cp1251.test
mysql-test/t/ctype_latin1.test
mysql-test/t/ctype_ucs.test
mysql-test/t/func_str.test
Fixing tests
@ sql/field.cc
- Return str result using my_charset_numeric.
- Using real multi-byte aware str_to_XXX functions
to handle tricky charset values propely (e.g. UCS2)
@ sql/field.h
- Changing derivation of non-string field types to DERIVATION_NUMERIC.
- Changing binary() for numeric/datetime fields to always
return TRUE even if charset is not my_charset_bin. We need
this to keep ha_base_keytype() return HA_KEYTYPE_BINARY.
- Adding BINARY_FLAG into some fields, because it's not
being set automatically anymore with
"my_charset_bin to my_charset_numeric" change.
- Changing derivation for numeric/datetime datatypes to a weaker
value, to make "SELECT concat('string', field)" use character
set of the string literal for the result of the function.
@ sql/item.cc
- Implementing generic val_str_ascii().
- Using max_char_length() instead of direct read of max_length
to make "tricky" charsets like UCS2 work.
NOTE: in the future we'll possibly remove all direct reads of max_length
- Fixing Item_num::safe_charset_converter().
Previously it alligned binary string to
character string (for example by adding leading 0x00
when doing binary->UCS2 conversion). Now it just
converts from my_charset_numbner to "tocs".
- Using val_str_ascii() in Item::get_time() to make UCS2 arguments work.
- Other misc changes
@ sql/item.h
- Changing MY_COLL_CMP_CONV and MY_COLL_ALLOW_CONV to
bit operations instead of hard-coded bit masks.
- Addding new method DTCollation.set_numeric().
- Adding new methods to Item.
- Adding helper functions to make code look nicer:
agg_item_charsets_for_string_result()
agg_item_charsets_for_comparison()
- Changing charset for Item_num-derived items
from my_charset_bin to my_charset_numeric
(which is an alias for latin1).
@ sql/item_cmpfunc.cc
- Using new helper functions
- Other misc changes
@ sql/item_cmpfunc.h
- Fixing strcmp() to return max_length=2.
Previously it returned 1, which was wrong,
because it did not fit '-1'.
@ sql/item_func.cc
- Using new helper functions
- Other minor changes
@ sql/item_func.h
- Removing unused functions
- Adding helper functions
agg_arg_charsets_for_string_result()
agg_arg_charsets_for_comparison()
- Adding set_numeric() into constructors of numeric items.
- Using fix_length_and_charset() and fix_char_length()
instead of direct write to max_length.
@ sql/item_geofunc.cc
- Changing class for Item_func_geometry_type and
Item_func_as_wkt from Item_str_func to
Item_str_ascii_func, to make them return UCS2 result
properly (when character_set_connection=ucs2).
@ sql/item_geofunc.h
- Changing class for Item_func_geometry_type and
Item_func_as_wkt from Item_str_func to
Item_str_ascii_func, to make them return UCS2 result
properly (when @@character_set_connection=ucs2).
@ sql/item_strfunc.cc
- Implementing Item_str_func::val_str().
- Renaming val_str to val_str_ascii for some items,
to make them work with UCS2 properly.
- Using new helper functions
- All single-argument functions that expect string
result now call this method:
agg_arg_charsets_for_string_result(collation, args, 1);
This enables character set conversion to @@character_set_connection
in case of pure numeric input.
@ sql/item_strfunc.h
- Introducing Item_str_ascii_func - for functions
which return pure ASCII data, for performance purposes,
as well as for the cases when the old implementation
of val_str() was heavily 8-bit oriented and implementing
a UCS2-aware version is tricky.
@ sql/item_sum.cc
- Using new helper functions.
@ sql/item_timefunc.cc
- Using my_charset_numeric instead of my_charset_bin.
- Using fix_char_length(), fix_length_and_charset()
and fix_length_and_charset_datetime()
instead of direct write to max_length.
- Using tricky-charset aware function str_to_time_with_warn()
@ sql/item_timefunc.h
- Using new helper functions for charset and length initialization.
- Changing base class for Item_func_get_format() to make
it return UCS2 properly (when character_set_connection=ucs2).
@ sql/item_xmlfunc.cc
- Using new helper function
@ sql/my_decimal.cc
- Adding a new DECIMAL to CHAR converter
with real multibyte support (e.g. UCS2)
@ sql/mysql_priv.h
- Introducing a new derivation level for numeric/datetime data types.
- Adding macros for my_charset_numeric and MY_REPERTOIRE_NUMERIC.
- Adding prototypes for str_set_decimal()
- Adding prototypes for character-set aware str_to_xxx() functions.
@ sql/protocol.cc
- Changing charsetnr to "binary" client-side metadata for
numeric/datetime data types.
@ sql/time.cc
- Adding to_ascii() helper function, to convert a string
in any character set to ascii representation. In the
future can be extended to understand digits written
in various non-Latin word scripts.
- Adding real multy-byte character set aware versions for str_to_XXXX,
to make these these type of queries work correct:
INSERT INTO t1 SET datetime_column=ucs2_expression;
@ strings/ctype-ucs2.c
- endptr was not calculated correctly. INSERTing of UCS2
values into numeric columns returned warnings about
truncated wrong data.
2010-02-11 08:17:25 +04:00
|
|
|
collation.set(field_par->charset(), field_par->derivation(),
|
|
|
|
field_par->repertoire());
|
|
|
|
fix_char_length(field_par->char_length());
|
2011-05-11 14:11:57 +03:00
|
|
|
|
|
|
|
max_length= adjust_max_effective_column_length(field_par, max_length);
|
|
|
|
|
2004-11-11 11:16:51 +02:00
|
|
|
fixed= 1;
|
2007-08-21 01:39:39 +05:00
|
|
|
if (field->table->s->tmp_table == SYSTEM_TMP_TABLE)
|
|
|
|
any_privileges= 0;
|
2004-11-11 11:16:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
2004-11-11 11:16:51 +02:00
|
|
|
Reset this item to point to a field from the new temporary table.
|
|
|
|
This is used when we create a new temporary table for each execution
|
|
|
|
of prepared statement.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void Item_field::reset_field(Field *f)
|
|
|
|
{
|
|
|
|
set_field(f);
|
|
|
|
/* 'name' is pointing at field->field_name of old field */
|
|
|
|
name= (char*) f->field_name;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *Item_ident::full_name() const
|
|
|
|
{
|
|
|
|
char *tmp;
|
2003-11-23 02:01:15 +02:00
|
|
|
if (!table_name || !field_name)
|
2000-07-31 21:29:14 +02:00
|
|
|
return field_name ? field_name : name ? name : "tmp_field";
|
2002-12-17 21:04:37 +02:00
|
|
|
if (db_name && db_name[0])
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2000-08-22 00:18:32 +03:00
|
|
|
tmp=(char*) sql_alloc((uint) strlen(db_name)+(uint) strlen(table_name)+
|
|
|
|
(uint) strlen(field_name)+3);
|
2000-07-31 21:29:14 +02:00
|
|
|
strxmov(tmp,db_name,".",table_name,".",field_name,NullS);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-05-06 20:40:21 +03:00
|
|
|
if (table_name[0])
|
|
|
|
{
|
|
|
|
tmp= (char*) sql_alloc((uint) strlen(table_name) +
|
|
|
|
(uint) strlen(field_name) + 2);
|
|
|
|
strxmov(tmp, table_name, ".", field_name, NullS);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
tmp= (char*) field_name;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2008-02-22 13:30:33 +03:00
|
|
|
void Item_ident::print(String *str, enum_query_type query_type)
|
2004-07-20 08:48:28 +03:00
|
|
|
{
|
2004-07-20 18:51:02 +03:00
|
|
|
THD *thd= current_thd;
|
2004-09-07 19:58:02 +03:00
|
|
|
char d_name_buff[MAX_ALIAS_NAME], t_name_buff[MAX_ALIAS_NAME];
|
|
|
|
const char *d_name= db_name, *t_name= table_name;
|
2004-11-24 19:48:30 +02:00
|
|
|
if (lower_case_table_names== 1 ||
|
|
|
|
(lower_case_table_names == 2 && !alias_name_used))
|
2004-09-07 19:58:02 +03:00
|
|
|
{
|
|
|
|
if (table_name && table_name[0])
|
|
|
|
{
|
|
|
|
strmov(t_name_buff, table_name);
|
|
|
|
my_casedn_str(files_charset_info, t_name_buff);
|
|
|
|
t_name= t_name_buff;
|
|
|
|
}
|
|
|
|
if (db_name && db_name[0])
|
|
|
|
{
|
|
|
|
strmov(d_name_buff, db_name);
|
|
|
|
my_casedn_str(files_charset_info, d_name_buff);
|
|
|
|
d_name= d_name_buff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-10 00:29:02 +03:00
|
|
|
if (!table_name || !field_name || !field_name[0])
|
2004-07-20 08:48:28 +03:00
|
|
|
{
|
2007-03-10 00:29:02 +03:00
|
|
|
const char *nm= (field_name && field_name[0]) ?
|
|
|
|
field_name : name ? name : "tmp_field";
|
2005-06-13 12:41:15 +02:00
|
|
|
append_identifier(thd, str, nm, (uint) strlen(nm));
|
2004-07-20 08:48:28 +03:00
|
|
|
return;
|
|
|
|
}
|
2004-11-24 19:48:30 +02:00
|
|
|
if (db_name && db_name[0] && !alias_name_used)
|
2004-07-20 08:48:28 +03:00
|
|
|
{
|
2005-09-01 11:36:42 +02:00
|
|
|
if (!(cached_table && cached_table->belong_to_view &&
|
|
|
|
cached_table->belong_to_view->compact_view_format))
|
|
|
|
{
|
2005-09-13 09:41:01 +02:00
|
|
|
append_identifier(thd, str, d_name, (uint)strlen(d_name));
|
2005-09-01 11:36:42 +02:00
|
|
|
str->append('.');
|
|
|
|
}
|
2005-09-13 09:41:01 +02:00
|
|
|
append_identifier(thd, str, t_name, (uint)strlen(t_name));
|
2004-07-20 18:51:02 +03:00
|
|
|
str->append('.');
|
2005-09-13 09:41:01 +02:00
|
|
|
append_identifier(thd, str, field_name, (uint)strlen(field_name));
|
2004-07-20 08:48:28 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (table_name[0])
|
|
|
|
{
|
2005-06-13 12:41:15 +02:00
|
|
|
append_identifier(thd, str, t_name, (uint) strlen(t_name));
|
2004-07-20 18:51:02 +03:00
|
|
|
str->append('.');
|
2005-06-13 12:41:15 +02:00
|
|
|
append_identifier(thd, str, field_name, (uint) strlen(field_name));
|
2004-07-20 08:48:28 +03:00
|
|
|
}
|
|
|
|
else
|
2005-06-13 12:41:15 +02:00
|
|
|
append_identifier(thd, str, field_name, (uint) strlen(field_name));
|
2004-07-20 08:48:28 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
/* ARGSUSED */
|
|
|
|
String *Item_field::val_str(String *str)
|
|
|
|
{
|
2004-03-18 15:14:36 +02:00
|
|
|
DBUG_ASSERT(fixed == 1);
|
2000-07-31 21:29:14 +02:00
|
|
|
if ((null_value=field->is_null()))
|
|
|
|
return 0;
|
2003-01-03 15:07:40 +02:00
|
|
|
str->set_charset(str_value.charset());
|
2000-07-31 21:29:14 +02:00
|
|
|
return field->val_str(str,&str_value);
|
|
|
|
}
|
|
|
|
|
2005-02-09 02:50:45 +04:00
|
|
|
|
2004-11-11 21:39:35 +03:00
|
|
|
double Item_field::val_real()
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2004-03-18 15:14:36 +02:00
|
|
|
DBUG_ASSERT(fixed == 1);
|
2000-07-31 21:29:14 +02:00
|
|
|
if ((null_value=field->is_null()))
|
|
|
|
return 0.0;
|
|
|
|
return field->val_real();
|
|
|
|
}
|
|
|
|
|
2005-02-09 02:50:45 +04:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
longlong Item_field::val_int()
|
|
|
|
{
|
2004-03-18 15:14:36 +02:00
|
|
|
DBUG_ASSERT(fixed == 1);
|
2000-07-31 21:29:14 +02:00
|
|
|
if ((null_value=field->is_null()))
|
|
|
|
return 0;
|
|
|
|
return field->val_int();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-09 02:50:45 +04:00
|
|
|
my_decimal *Item_field::val_decimal(my_decimal *decimal_value)
|
|
|
|
{
|
|
|
|
if ((null_value= field->is_null()))
|
|
|
|
return 0;
|
|
|
|
return field->val_decimal(decimal_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
String *Item_field::str_result(String *str)
|
|
|
|
{
|
|
|
|
if ((null_value=result_field->is_null()))
|
|
|
|
return 0;
|
2002-12-31 18:01:53 +02:00
|
|
|
str->set_charset(str_value.charset());
|
2000-07-31 21:29:14 +02:00
|
|
|
return result_field->val_str(str,&str_value);
|
|
|
|
}
|
|
|
|
|
2007-03-23 22:08:31 +02:00
|
|
|
bool Item_field::get_date(MYSQL_TIME *ltime,uint fuzzydate)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
if ((null_value=field->is_null()) || field->get_date(ltime,fuzzydate))
|
|
|
|
{
|
|
|
|
bzero((char*) ltime,sizeof(*ltime));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-03-23 22:08:31 +02:00
|
|
|
bool Item_field::get_date_result(MYSQL_TIME *ltime,uint fuzzydate)
|
2003-03-11 21:20:53 +01:00
|
|
|
{
|
|
|
|
if ((null_value=result_field->is_null()) ||
|
|
|
|
result_field->get_date(ltime,fuzzydate))
|
|
|
|
{
|
|
|
|
bzero((char*) ltime,sizeof(*ltime));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-03-23 22:08:31 +02:00
|
|
|
bool Item_field::get_time(MYSQL_TIME *ltime)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
if ((null_value=field->is_null()) || field->get_time(ltime))
|
|
|
|
{
|
|
|
|
bzero((char*) ltime,sizeof(*ltime));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
double Item_field::val_result()
|
|
|
|
{
|
|
|
|
if ((null_value=result_field->is_null()))
|
|
|
|
return 0.0;
|
|
|
|
return result_field->val_real();
|
|
|
|
}
|
|
|
|
|
|
|
|
longlong Item_field::val_int_result()
|
|
|
|
{
|
|
|
|
if ((null_value=result_field->is_null()))
|
|
|
|
return 0;
|
|
|
|
return result_field->val_int();
|
|
|
|
}
|
|
|
|
|
2003-06-04 18:28:51 +03:00
|
|
|
|
2005-02-09 02:50:45 +04:00
|
|
|
my_decimal *Item_field::val_decimal_result(my_decimal *decimal_value)
|
|
|
|
{
|
|
|
|
if ((null_value= result_field->is_null()))
|
|
|
|
return 0;
|
|
|
|
return result_field->val_decimal(decimal_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Item_field::val_bool_result()
|
|
|
|
{
|
|
|
|
if ((null_value= result_field->is_null()))
|
|
|
|
return FALSE;
|
2005-02-15 16:45:00 +02:00
|
|
|
switch (result_field->result_type()) {
|
2005-02-09 02:50:45 +04:00
|
|
|
case INT_RESULT:
|
2005-03-18 16:12:25 -08:00
|
|
|
return result_field->val_int() != 0;
|
2005-02-09 02:50:45 +04:00
|
|
|
case DECIMAL_RESULT:
|
|
|
|
{
|
|
|
|
my_decimal decimal_value;
|
|
|
|
my_decimal *val= result_field->val_decimal(&decimal_value);
|
|
|
|
if (val)
|
|
|
|
return !my_decimal_is_zero(val);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case REAL_RESULT:
|
|
|
|
case STRING_RESULT:
|
|
|
|
return result_field->val_real() != 0.0;
|
|
|
|
case ROW_RESULT:
|
|
|
|
default:
|
|
|
|
DBUG_ASSERT(0);
|
2005-02-25 16:53:22 +02:00
|
|
|
return 0; // Shut up compiler
|
2005-02-09 02:50:45 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-17 13:55:16 +03:00
|
|
|
bool Item_field::is_null_result()
|
|
|
|
{
|
|
|
|
return (null_value=result_field->is_null());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-22 14:03:42 +02:00
|
|
|
bool Item_field::eq(const Item *item, bool binary_cmp) const
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2007-06-20 12:43:14 -07:00
|
|
|
Item *real_item= ((Item *) item)->real_item();
|
|
|
|
if (real_item->type() != FIELD_ITEM)
|
2003-06-04 18:28:51 +03:00
|
|
|
return 0;
|
|
|
|
|
2007-06-20 12:43:14 -07:00
|
|
|
Item_field *item_field= (Item_field*) real_item;
|
2005-09-26 20:18:59 -07:00
|
|
|
if (item_field->field && field)
|
2003-06-04 18:28:51 +03:00
|
|
|
return item_field->field == field;
|
|
|
|
/*
|
|
|
|
We may come here when we are trying to find a function in a GROUP BY
|
|
|
|
clause from the select list.
|
|
|
|
In this case the '100 % correct' way to do this would be to first
|
|
|
|
run fix_fields() on the GROUP BY item and then retry this function, but
|
|
|
|
I think it's better to relax the checking a bit as we will in
|
|
|
|
most cases do the correct thing by just checking the field name.
|
|
|
|
(In cases where we would choose wrong we would have to generate a
|
|
|
|
ER_NON_UNIQ_ERROR).
|
|
|
|
*/
|
|
|
|
return (!my_strcasecmp(system_charset_info, item_field->name,
|
|
|
|
field_name) &&
|
2005-09-26 20:18:59 -07:00
|
|
|
(!item_field->table_name || !table_name ||
|
2003-06-04 18:28:51 +03:00
|
|
|
(!my_strcasecmp(table_alias_charset, item_field->table_name,
|
|
|
|
table_name) &&
|
2005-09-26 20:18:59 -07:00
|
|
|
(!item_field->db_name || !db_name ||
|
2004-03-22 15:43:13 +02:00
|
|
|
(item_field->db_name && !strcmp(item_field->db_name,
|
|
|
|
db_name))))));
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2003-10-30 12:57:26 +02:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
table_map Item_field::used_tables() const
|
|
|
|
{
|
|
|
|
if (field->table->const_table)
|
|
|
|
return 0; // const item
|
2003-05-06 01:38:38 +03:00
|
|
|
return (depended_from ? OUTER_REF_TABLE_BIT : field->table->map);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2003-10-30 12:57:26 +02:00
|
|
|
|
2003-01-30 18:07:39 +02:00
|
|
|
Item *Item_field::get_tmp_table_item(THD *thd)
|
2003-01-25 02:25:52 +02:00
|
|
|
{
|
2004-01-19 19:53:25 +04:00
|
|
|
Item_field *new_item= new Item_field(thd, this);
|
2003-01-25 02:25:52 +02:00
|
|
|
if (new_item)
|
|
|
|
new_item->field= new_item->result_field;
|
|
|
|
return new_item;
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2007-09-14 14:18:42 +04:00
|
|
|
longlong Item_field::val_int_endpoint(bool left_endp, bool *incl_endp)
|
|
|
|
{
|
|
|
|
longlong res= val_int();
|
|
|
|
return null_value? LONGLONG_MIN : res;
|
|
|
|
}
|
2003-10-30 12:57:26 +02:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
2005-02-15 16:45:00 +02:00
|
|
|
Create an item from a string we KNOW points to a valid longlong
|
2007-10-11 13:29:09 -04:00
|
|
|
end \\0 terminated number string.
|
2005-02-15 16:45:00 +02:00
|
|
|
This is always 'signed'. Unsigned values are created with Item_uint()
|
2004-05-07 01:43:17 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
Item_int::Item_int(const char *str_arg, uint length)
|
|
|
|
{
|
|
|
|
char *end_ptr= (char*) str_arg + length;
|
|
|
|
int error;
|
|
|
|
value= my_strtoll10(str_arg, &end_ptr, &error);
|
|
|
|
max_length= (uint) (end_ptr - str_arg);
|
|
|
|
name= (char*) str_arg;
|
|
|
|
fixed= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-09 02:50:45 +04:00
|
|
|
my_decimal *Item_int::val_decimal(my_decimal *decimal_value)
|
|
|
|
{
|
|
|
|
int2my_decimal(E_DEC_FATAL_ERROR, value, unsigned_flag, decimal_value);
|
|
|
|
return decimal_value;
|
|
|
|
}
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
String *Item_int::val_str(String *str)
|
|
|
|
{
|
2004-03-20 13:36:26 +02:00
|
|
|
// following assert is redundant, because fixed=1 assigned in constructor
|
2004-03-18 15:14:36 +02:00
|
|
|
DBUG_ASSERT(fixed == 1);
|
2010-03-01 13:06:11 +03:00
|
|
|
str->set_int(value, unsigned_flag, collation.collation);
|
2000-07-31 21:29:14 +02:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2008-02-22 13:30:33 +03:00
|
|
|
void Item_int::print(String *str, enum_query_type query_type)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2003-11-03 12:28:36 +02:00
|
|
|
// my_charset_bin is good enough for numbers
|
2010-02-25 23:13:11 +04:00
|
|
|
str_value.set_int(value, unsigned_flag, &my_charset_bin);
|
2003-10-16 15:54:47 +03:00
|
|
|
str->append(str_value);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2003-10-30 12:57:26 +02:00
|
|
|
|
2004-05-07 01:43:17 +03:00
|
|
|
Item_uint::Item_uint(const char *str_arg, uint length):
|
|
|
|
Item_int(str_arg, length)
|
|
|
|
{
|
|
|
|
unsigned_flag= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-05-05 12:55:09 +04:00
|
|
|
Item_uint::Item_uint(const char *str_arg, longlong i, uint length):
|
|
|
|
Item_int(str_arg, i, length)
|
|
|
|
{
|
|
|
|
unsigned_flag= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-14 02:54:33 +03:00
|
|
|
String *Item_uint::val_str(String *str)
|
|
|
|
{
|
2004-03-20 13:36:26 +02:00
|
|
|
// following assert is redundant, because fixed=1 assigned in constructor
|
2004-03-18 15:14:36 +02:00
|
|
|
DBUG_ASSERT(fixed == 1);
|
WL#2649 Number-to-string conversions
added:
include/ctype_numconv.inc
mysql-test/include/ctype_numconv.inc
mysql-test/r/ctype_binary.result
mysql-test/t/ctype_binary.test
Adding tests
modified:
mysql-test/r/bigint.result
mysql-test/r/case.result
mysql-test/r/create.result
mysql-test/r/ctype_cp1251.result
mysql-test/r/ctype_latin1.result
mysql-test/r/ctype_ucs.result
mysql-test/r/func_gconcat.result
mysql-test/r/func_str.result
mysql-test/r/metadata.result
mysql-test/r/ps_1general.result
mysql-test/r/ps_2myisam.result
mysql-test/r/ps_3innodb.result
mysql-test/r/ps_4heap.result
mysql-test/r/ps_5merge.result
mysql-test/r/show_check.result
mysql-test/r/type_datetime.result
mysql-test/r/type_ranges.result
mysql-test/r/union.result
mysql-test/suite/ndb/r/ps_7ndb.result
mysql-test/t/ctype_cp1251.test
mysql-test/t/ctype_latin1.test
mysql-test/t/ctype_ucs.test
mysql-test/t/func_str.test
Fixing tests
@ sql/field.cc
- Return str result using my_charset_numeric.
- Using real multi-byte aware str_to_XXX functions
to handle tricky charset values propely (e.g. UCS2)
@ sql/field.h
- Changing derivation of non-string field types to DERIVATION_NUMERIC.
- Changing binary() for numeric/datetime fields to always
return TRUE even if charset is not my_charset_bin. We need
this to keep ha_base_keytype() return HA_KEYTYPE_BINARY.
- Adding BINARY_FLAG into some fields, because it's not
being set automatically anymore with
"my_charset_bin to my_charset_numeric" change.
- Changing derivation for numeric/datetime datatypes to a weaker
value, to make "SELECT concat('string', field)" use character
set of the string literal for the result of the function.
@ sql/item.cc
- Implementing generic val_str_ascii().
- Using max_char_length() instead of direct read of max_length
to make "tricky" charsets like UCS2 work.
NOTE: in the future we'll possibly remove all direct reads of max_length
- Fixing Item_num::safe_charset_converter().
Previously it alligned binary string to
character string (for example by adding leading 0x00
when doing binary->UCS2 conversion). Now it just
converts from my_charset_numbner to "tocs".
- Using val_str_ascii() in Item::get_time() to make UCS2 arguments work.
- Other misc changes
@ sql/item.h
- Changing MY_COLL_CMP_CONV and MY_COLL_ALLOW_CONV to
bit operations instead of hard-coded bit masks.
- Addding new method DTCollation.set_numeric().
- Adding new methods to Item.
- Adding helper functions to make code look nicer:
agg_item_charsets_for_string_result()
agg_item_charsets_for_comparison()
- Changing charset for Item_num-derived items
from my_charset_bin to my_charset_numeric
(which is an alias for latin1).
@ sql/item_cmpfunc.cc
- Using new helper functions
- Other misc changes
@ sql/item_cmpfunc.h
- Fixing strcmp() to return max_length=2.
Previously it returned 1, which was wrong,
because it did not fit '-1'.
@ sql/item_func.cc
- Using new helper functions
- Other minor changes
@ sql/item_func.h
- Removing unused functions
- Adding helper functions
agg_arg_charsets_for_string_result()
agg_arg_charsets_for_comparison()
- Adding set_numeric() into constructors of numeric items.
- Using fix_length_and_charset() and fix_char_length()
instead of direct write to max_length.
@ sql/item_geofunc.cc
- Changing class for Item_func_geometry_type and
Item_func_as_wkt from Item_str_func to
Item_str_ascii_func, to make them return UCS2 result
properly (when character_set_connection=ucs2).
@ sql/item_geofunc.h
- Changing class for Item_func_geometry_type and
Item_func_as_wkt from Item_str_func to
Item_str_ascii_func, to make them return UCS2 result
properly (when @@character_set_connection=ucs2).
@ sql/item_strfunc.cc
- Implementing Item_str_func::val_str().
- Renaming val_str to val_str_ascii for some items,
to make them work with UCS2 properly.
- Using new helper functions
- All single-argument functions that expect string
result now call this method:
agg_arg_charsets_for_string_result(collation, args, 1);
This enables character set conversion to @@character_set_connection
in case of pure numeric input.
@ sql/item_strfunc.h
- Introducing Item_str_ascii_func - for functions
which return pure ASCII data, for performance purposes,
as well as for the cases when the old implementation
of val_str() was heavily 8-bit oriented and implementing
a UCS2-aware version is tricky.
@ sql/item_sum.cc
- Using new helper functions.
@ sql/item_timefunc.cc
- Using my_charset_numeric instead of my_charset_bin.
- Using fix_char_length(), fix_length_and_charset()
and fix_length_and_charset_datetime()
instead of direct write to max_length.
- Using tricky-charset aware function str_to_time_with_warn()
@ sql/item_timefunc.h
- Using new helper functions for charset and length initialization.
- Changing base class for Item_func_get_format() to make
it return UCS2 properly (when character_set_connection=ucs2).
@ sql/item_xmlfunc.cc
- Using new helper function
@ sql/my_decimal.cc
- Adding a new DECIMAL to CHAR converter
with real multibyte support (e.g. UCS2)
@ sql/mysql_priv.h
- Introducing a new derivation level for numeric/datetime data types.
- Adding macros for my_charset_numeric and MY_REPERTOIRE_NUMERIC.
- Adding prototypes for str_set_decimal()
- Adding prototypes for character-set aware str_to_xxx() functions.
@ sql/protocol.cc
- Changing charsetnr to "binary" client-side metadata for
numeric/datetime data types.
@ sql/time.cc
- Adding to_ascii() helper function, to convert a string
in any character set to ascii representation. In the
future can be extended to understand digits written
in various non-Latin word scripts.
- Adding real multy-byte character set aware versions for str_to_XXXX,
to make these these type of queries work correct:
INSERT INTO t1 SET datetime_column=ucs2_expression;
@ strings/ctype-ucs2.c
- endptr was not calculated correctly. INSERTing of UCS2
values into numeric columns returned warnings about
truncated wrong data.
2010-02-11 08:17:25 +04:00
|
|
|
str->set((ulonglong) value, collation.collation);
|
2001-09-14 02:54:33 +03:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2003-10-30 12:57:26 +02:00
|
|
|
|
2008-02-22 13:30:33 +03:00
|
|
|
void Item_uint::print(String *str, enum_query_type query_type)
|
2001-09-14 02:54:33 +03:00
|
|
|
{
|
2003-10-30 12:57:26 +02:00
|
|
|
// latin1 is good enough for numbers
|
2003-10-16 15:54:47 +03:00
|
|
|
str_value.set((ulonglong) value, default_charset());
|
|
|
|
str->append(str_value);
|
2001-09-14 02:54:33 +03:00
|
|
|
}
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2005-02-09 02:50:45 +04:00
|
|
|
Item_decimal::Item_decimal(const char *str_arg, uint length,
|
|
|
|
CHARSET_INFO *charset)
|
|
|
|
{
|
|
|
|
str2my_decimal(E_DEC_FATAL_ERROR, str_arg, length, charset, &decimal_value);
|
|
|
|
name= (char*) str_arg;
|
|
|
|
decimals= (uint8) decimal_value.frac;
|
|
|
|
fixed= 1;
|
2009-07-03 11:41:19 +04:00
|
|
|
max_length= my_decimal_precision_to_length_no_truncation(decimal_value.intg +
|
|
|
|
decimals,
|
|
|
|
decimals,
|
|
|
|
unsigned_flag);
|
2005-02-09 02:50:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Item_decimal::Item_decimal(longlong val, bool unsig)
|
|
|
|
{
|
|
|
|
int2my_decimal(E_DEC_FATAL_ERROR, val, unsig, &decimal_value);
|
|
|
|
decimals= (uint8) decimal_value.frac;
|
|
|
|
fixed= 1;
|
2009-07-03 11:41:19 +04:00
|
|
|
max_length= my_decimal_precision_to_length_no_truncation(decimal_value.intg +
|
|
|
|
decimals,
|
|
|
|
decimals,
|
|
|
|
unsigned_flag);
|
2005-02-09 02:50:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Item_decimal::Item_decimal(double val, int precision, int scale)
|
|
|
|
{
|
|
|
|
double2my_decimal(E_DEC_FATAL_ERROR, val, &decimal_value);
|
|
|
|
decimals= (uint8) decimal_value.frac;
|
|
|
|
fixed= 1;
|
2009-07-03 11:41:19 +04:00
|
|
|
max_length= my_decimal_precision_to_length_no_truncation(decimal_value.intg +
|
|
|
|
decimals,
|
|
|
|
decimals,
|
|
|
|
unsigned_flag);
|
2005-02-09 02:50:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Item_decimal::Item_decimal(const char *str, const my_decimal *val_arg,
|
|
|
|
uint decimal_par, uint length)
|
|
|
|
{
|
|
|
|
my_decimal2decimal(val_arg, &decimal_value);
|
|
|
|
name= (char*) str;
|
|
|
|
decimals= (uint8) decimal_par;
|
|
|
|
max_length= length;
|
|
|
|
fixed= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Item_decimal::Item_decimal(my_decimal *value_par)
|
|
|
|
{
|
|
|
|
my_decimal2decimal(value_par, &decimal_value);
|
|
|
|
decimals= (uint8) decimal_value.frac;
|
|
|
|
fixed= 1;
|
2009-07-03 11:41:19 +04:00
|
|
|
max_length= my_decimal_precision_to_length_no_truncation(decimal_value.intg +
|
|
|
|
decimals,
|
|
|
|
decimals,
|
|
|
|
unsigned_flag);
|
2005-02-09 02:50:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
Item_decimal::Item_decimal(const uchar *bin, int precision, int scale)
|
2005-02-09 02:50:45 +04:00
|
|
|
{
|
2005-05-05 20:06:49 +05:00
|
|
|
binary2my_decimal(E_DEC_FATAL_ERROR, bin,
|
|
|
|
&decimal_value, precision, scale);
|
2005-02-09 02:50:45 +04:00
|
|
|
decimals= (uint8) decimal_value.frac;
|
|
|
|
fixed= 1;
|
2009-07-03 11:41:19 +04:00
|
|
|
max_length= my_decimal_precision_to_length_no_truncation(precision, decimals,
|
|
|
|
unsigned_flag);
|
2005-02-09 02:50:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
longlong Item_decimal::val_int()
|
|
|
|
{
|
|
|
|
longlong result;
|
|
|
|
my_decimal2int(E_DEC_FATAL_ERROR, &decimal_value, unsigned_flag, &result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
double Item_decimal::val_real()
|
|
|
|
{
|
|
|
|
double result;
|
|
|
|
my_decimal2double(E_DEC_FATAL_ERROR, &decimal_value, &result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
String *Item_decimal::val_str(String *result)
|
|
|
|
{
|
WL#2649 Number-to-string conversions
added:
include/ctype_numconv.inc
mysql-test/include/ctype_numconv.inc
mysql-test/r/ctype_binary.result
mysql-test/t/ctype_binary.test
Adding tests
modified:
mysql-test/r/bigint.result
mysql-test/r/case.result
mysql-test/r/create.result
mysql-test/r/ctype_cp1251.result
mysql-test/r/ctype_latin1.result
mysql-test/r/ctype_ucs.result
mysql-test/r/func_gconcat.result
mysql-test/r/func_str.result
mysql-test/r/metadata.result
mysql-test/r/ps_1general.result
mysql-test/r/ps_2myisam.result
mysql-test/r/ps_3innodb.result
mysql-test/r/ps_4heap.result
mysql-test/r/ps_5merge.result
mysql-test/r/show_check.result
mysql-test/r/type_datetime.result
mysql-test/r/type_ranges.result
mysql-test/r/union.result
mysql-test/suite/ndb/r/ps_7ndb.result
mysql-test/t/ctype_cp1251.test
mysql-test/t/ctype_latin1.test
mysql-test/t/ctype_ucs.test
mysql-test/t/func_str.test
Fixing tests
@ sql/field.cc
- Return str result using my_charset_numeric.
- Using real multi-byte aware str_to_XXX functions
to handle tricky charset values propely (e.g. UCS2)
@ sql/field.h
- Changing derivation of non-string field types to DERIVATION_NUMERIC.
- Changing binary() for numeric/datetime fields to always
return TRUE even if charset is not my_charset_bin. We need
this to keep ha_base_keytype() return HA_KEYTYPE_BINARY.
- Adding BINARY_FLAG into some fields, because it's not
being set automatically anymore with
"my_charset_bin to my_charset_numeric" change.
- Changing derivation for numeric/datetime datatypes to a weaker
value, to make "SELECT concat('string', field)" use character
set of the string literal for the result of the function.
@ sql/item.cc
- Implementing generic val_str_ascii().
- Using max_char_length() instead of direct read of max_length
to make "tricky" charsets like UCS2 work.
NOTE: in the future we'll possibly remove all direct reads of max_length
- Fixing Item_num::safe_charset_converter().
Previously it alligned binary string to
character string (for example by adding leading 0x00
when doing binary->UCS2 conversion). Now it just
converts from my_charset_numbner to "tocs".
- Using val_str_ascii() in Item::get_time() to make UCS2 arguments work.
- Other misc changes
@ sql/item.h
- Changing MY_COLL_CMP_CONV and MY_COLL_ALLOW_CONV to
bit operations instead of hard-coded bit masks.
- Addding new method DTCollation.set_numeric().
- Adding new methods to Item.
- Adding helper functions to make code look nicer:
agg_item_charsets_for_string_result()
agg_item_charsets_for_comparison()
- Changing charset for Item_num-derived items
from my_charset_bin to my_charset_numeric
(which is an alias for latin1).
@ sql/item_cmpfunc.cc
- Using new helper functions
- Other misc changes
@ sql/item_cmpfunc.h
- Fixing strcmp() to return max_length=2.
Previously it returned 1, which was wrong,
because it did not fit '-1'.
@ sql/item_func.cc
- Using new helper functions
- Other minor changes
@ sql/item_func.h
- Removing unused functions
- Adding helper functions
agg_arg_charsets_for_string_result()
agg_arg_charsets_for_comparison()
- Adding set_numeric() into constructors of numeric items.
- Using fix_length_and_charset() and fix_char_length()
instead of direct write to max_length.
@ sql/item_geofunc.cc
- Changing class for Item_func_geometry_type and
Item_func_as_wkt from Item_str_func to
Item_str_ascii_func, to make them return UCS2 result
properly (when character_set_connection=ucs2).
@ sql/item_geofunc.h
- Changing class for Item_func_geometry_type and
Item_func_as_wkt from Item_str_func to
Item_str_ascii_func, to make them return UCS2 result
properly (when @@character_set_connection=ucs2).
@ sql/item_strfunc.cc
- Implementing Item_str_func::val_str().
- Renaming val_str to val_str_ascii for some items,
to make them work with UCS2 properly.
- Using new helper functions
- All single-argument functions that expect string
result now call this method:
agg_arg_charsets_for_string_result(collation, args, 1);
This enables character set conversion to @@character_set_connection
in case of pure numeric input.
@ sql/item_strfunc.h
- Introducing Item_str_ascii_func - for functions
which return pure ASCII data, for performance purposes,
as well as for the cases when the old implementation
of val_str() was heavily 8-bit oriented and implementing
a UCS2-aware version is tricky.
@ sql/item_sum.cc
- Using new helper functions.
@ sql/item_timefunc.cc
- Using my_charset_numeric instead of my_charset_bin.
- Using fix_char_length(), fix_length_and_charset()
and fix_length_and_charset_datetime()
instead of direct write to max_length.
- Using tricky-charset aware function str_to_time_with_warn()
@ sql/item_timefunc.h
- Using new helper functions for charset and length initialization.
- Changing base class for Item_func_get_format() to make
it return UCS2 properly (when character_set_connection=ucs2).
@ sql/item_xmlfunc.cc
- Using new helper function
@ sql/my_decimal.cc
- Adding a new DECIMAL to CHAR converter
with real multibyte support (e.g. UCS2)
@ sql/mysql_priv.h
- Introducing a new derivation level for numeric/datetime data types.
- Adding macros for my_charset_numeric and MY_REPERTOIRE_NUMERIC.
- Adding prototypes for str_set_decimal()
- Adding prototypes for character-set aware str_to_xxx() functions.
@ sql/protocol.cc
- Changing charsetnr to "binary" client-side metadata for
numeric/datetime data types.
@ sql/time.cc
- Adding to_ascii() helper function, to convert a string
in any character set to ascii representation. In the
future can be extended to understand digits written
in various non-Latin word scripts.
- Adding real multy-byte character set aware versions for str_to_XXXX,
to make these these type of queries work correct:
INSERT INTO t1 SET datetime_column=ucs2_expression;
@ strings/ctype-ucs2.c
- endptr was not calculated correctly. INSERTing of UCS2
values into numeric columns returned warnings about
truncated wrong data.
2010-02-11 08:17:25 +04:00
|
|
|
result->set_charset(&my_charset_numeric);
|
2005-02-09 02:50:45 +04:00
|
|
|
my_decimal2string(E_DEC_FATAL_ERROR, &decimal_value, 0, 0, 0, result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-02-22 13:30:33 +03:00
|
|
|
void Item_decimal::print(String *str, enum_query_type query_type)
|
2005-02-09 02:50:45 +04:00
|
|
|
{
|
|
|
|
my_decimal2string(E_DEC_FATAL_ERROR, &decimal_value, 0, 0, 0, &str_value);
|
|
|
|
str->append(str_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-05-04 16:53:10 +04:00
|
|
|
bool Item_decimal::eq(const Item *item, bool binary_cmp) const
|
|
|
|
{
|
|
|
|
if (type() == item->type() && item->basic_const_item())
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
We need to cast off const to call val_decimal(). This should
|
|
|
|
be OK for a basic constant. Additionally, we can pass 0 as
|
|
|
|
a true decimal constant will return its internal decimal
|
|
|
|
storage and ignore the argument.
|
|
|
|
*/
|
|
|
|
Item *arg= (Item*) item;
|
|
|
|
my_decimal *value= arg->val_decimal(0);
|
|
|
|
return !my_decimal_cmp(&decimal_value, value);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-25 23:33:31 +04:00
|
|
|
void Item_decimal::set_decimal_value(my_decimal *value_par)
|
|
|
|
{
|
|
|
|
my_decimal2decimal(value_par, &decimal_value);
|
|
|
|
decimals= (uint8) decimal_value.frac;
|
|
|
|
unsigned_flag= !decimal_value.sign();
|
2009-07-03 11:41:19 +04:00
|
|
|
max_length= my_decimal_precision_to_length_no_truncation(decimal_value.intg +
|
|
|
|
decimals,
|
|
|
|
decimals,
|
|
|
|
unsigned_flag);
|
2006-04-25 23:33:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-09 02:50:45 +04:00
|
|
|
String *Item_float::val_str(String *str)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2004-03-20 13:36:26 +02:00
|
|
|
// following assert is redundant, because fixed=1 assigned in constructor
|
2004-03-18 15:14:36 +02:00
|
|
|
DBUG_ASSERT(fixed == 1);
|
2006-06-16 12:17:20 +02:00
|
|
|
str->set_real(value,decimals,&my_charset_bin);
|
2000-07-31 21:29:14 +02:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2003-10-30 12:57:26 +02:00
|
|
|
|
2005-02-09 02:50:45 +04:00
|
|
|
my_decimal *Item_float::val_decimal(my_decimal *decimal_value)
|
|
|
|
{
|
|
|
|
// following assert is redundant, because fixed=1 assigned in constructor
|
|
|
|
DBUG_ASSERT(fixed == 1);
|
|
|
|
double2my_decimal(E_DEC_FATAL_ERROR, value, decimal_value);
|
|
|
|
return (decimal_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-22 13:30:33 +03:00
|
|
|
void Item_string::print(String *str, enum_query_type query_type)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2011-03-04 18:43:28 +03:00
|
|
|
const bool print_introducer=
|
|
|
|
!(query_type & QT_WITHOUT_INTRODUCERS) && is_cs_specified();
|
|
|
|
if (print_introducer)
|
2008-02-12 22:09:16 +03:00
|
|
|
{
|
|
|
|
str->append('_');
|
|
|
|
str->append(collation.collation->csname);
|
|
|
|
}
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
str->append('\'');
|
2008-02-22 13:30:33 +03:00
|
|
|
|
2011-03-04 18:43:28 +03:00
|
|
|
if (query_type & QT_TO_SYSTEM_CHARSET)
|
2008-02-22 13:30:33 +03:00
|
|
|
{
|
2011-03-04 18:43:28 +03:00
|
|
|
if (print_introducer)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Because we wrote an introducer, we must print str_value in its
|
|
|
|
charset, and the resulting bytes must not be changed until they
|
|
|
|
reach the end client.
|
|
|
|
But the caller is asking for system_charset_info, and may later
|
|
|
|
convert into character_set_results. That means two conversions: we
|
|
|
|
must ensure that they don't change our printed bytes.
|
|
|
|
So we print str_value in the least common denominator of the three
|
|
|
|
charsets involved: ASCII. Non-ASCII characters are printed as \xFF
|
|
|
|
sequences (which is ASCII too). This way, our bytes will not be
|
|
|
|
changed.
|
|
|
|
*/
|
|
|
|
ErrConvString tmp(str_value.ptr(), str_value.length(), &my_charset_bin);
|
|
|
|
str->append(tmp.ptr());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (my_charset_same(str_value.charset(), system_charset_info))
|
|
|
|
str_value.print(str); // already in system_charset_info
|
|
|
|
else // need to convert
|
|
|
|
{
|
|
|
|
THD *thd= current_thd;
|
|
|
|
LEX_STRING utf8_lex_str;
|
2008-02-22 13:30:33 +03:00
|
|
|
|
2011-03-04 18:43:28 +03:00
|
|
|
thd->convert_string(&utf8_lex_str,
|
|
|
|
system_charset_info,
|
|
|
|
str_value.c_ptr_safe(),
|
|
|
|
str_value.length(),
|
|
|
|
str_value.charset());
|
2008-02-22 13:30:33 +03:00
|
|
|
|
2011-03-04 18:43:28 +03:00
|
|
|
String utf8_str(utf8_lex_str.str,
|
|
|
|
utf8_lex_str.length,
|
|
|
|
system_charset_info);
|
2008-02-22 13:30:33 +03:00
|
|
|
|
2011-03-04 18:43:28 +03:00
|
|
|
utf8_str.print(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Caller wants a result in the charset of str_value.
|
|
|
|
str_value.print(str);
|
2008-02-22 13:30:33 +03:00
|
|
|
}
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
str->append('\'');
|
|
|
|
}
|
|
|
|
|
2005-02-09 02:50:45 +04:00
|
|
|
|
2008-10-08 14:23:53 +03:00
|
|
|
double
|
|
|
|
double_from_string_with_check (CHARSET_INFO *cs, const char *cptr, char *end)
|
2005-04-01 15:04:50 +03:00
|
|
|
{
|
|
|
|
int error;
|
2008-10-08 14:23:53 +03:00
|
|
|
char *org_end;
|
2005-04-01 15:04:50 +03:00
|
|
|
double tmp;
|
|
|
|
|
2008-10-08 14:23:53 +03:00
|
|
|
org_end= end;
|
|
|
|
tmp= my_strntod(cs, (char*) cptr, end - cptr, &end, &error);
|
2005-04-01 15:04:50 +03:00
|
|
|
if (error || (end != org_end && !check_if_only_end_space(cs, end, org_end)))
|
|
|
|
{
|
2009-10-15 17:23:43 +05:00
|
|
|
ErrConvString err(cptr, cs);
|
2005-04-04 16:43:25 +03:00
|
|
|
/*
|
|
|
|
We can use str_value.ptr() here as Item_string is gurantee to put an
|
|
|
|
end \0 here.
|
|
|
|
*/
|
2005-04-01 15:04:50 +03:00
|
|
|
push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
|
|
|
|
ER_TRUNCATED_WRONG_VALUE,
|
|
|
|
ER(ER_TRUNCATED_WRONG_VALUE), "DOUBLE",
|
2009-10-15 17:23:43 +05:00
|
|
|
err.ptr());
|
2005-04-01 15:04:50 +03:00
|
|
|
}
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-08 14:23:53 +03:00
|
|
|
double Item_string::val_real()
|
2005-04-01 15:04:50 +03:00
|
|
|
{
|
|
|
|
DBUG_ASSERT(fixed == 1);
|
2008-10-08 14:23:53 +03:00
|
|
|
return double_from_string_with_check (str_value.charset(), str_value.ptr(),
|
|
|
|
(char *) str_value.ptr() + str_value.length());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
longlong
|
|
|
|
longlong_from_string_with_check (CHARSET_INFO *cs, const char *cptr, char *end)
|
|
|
|
{
|
2005-04-01 15:04:50 +03:00
|
|
|
int err;
|
|
|
|
longlong tmp;
|
|
|
|
char *org_end= end;
|
|
|
|
|
2008-10-08 14:23:53 +03:00
|
|
|
tmp= (*(cs->cset->strtoll10))(cs, cptr, &end, &err);
|
2005-04-01 15:04:50 +03:00
|
|
|
/*
|
|
|
|
TODO: Give error if we wanted a signed integer and we got an unsigned
|
|
|
|
one
|
|
|
|
*/
|
2009-05-22 01:22:46 +05:00
|
|
|
if (!current_thd->no_errors &&
|
|
|
|
(err > 0 ||
|
|
|
|
(end != org_end && !check_if_only_end_space(cs, end, org_end))))
|
2005-04-01 15:04:50 +03:00
|
|
|
{
|
2009-10-15 17:23:43 +05:00
|
|
|
ErrConvString err(cptr, cs);
|
2005-04-01 15:04:50 +03:00
|
|
|
push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
|
|
|
|
ER_TRUNCATED_WRONG_VALUE,
|
|
|
|
ER(ER_TRUNCATED_WRONG_VALUE), "INTEGER",
|
2009-10-15 17:23:43 +05:00
|
|
|
err.ptr());
|
2005-04-01 15:04:50 +03:00
|
|
|
}
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-08 14:23:53 +03:00
|
|
|
/**
|
|
|
|
@todo
|
|
|
|
Give error if we wanted a signed integer and we got an unsigned one
|
|
|
|
*/
|
|
|
|
longlong Item_string::val_int()
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(fixed == 1);
|
|
|
|
return longlong_from_string_with_check(str_value.charset(), str_value.ptr(),
|
|
|
|
(char *) str_value.ptr()+ str_value.length());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-09 02:50:45 +04:00
|
|
|
my_decimal *Item_string::val_decimal(my_decimal *decimal_value)
|
|
|
|
{
|
2005-04-06 15:49:55 +05:00
|
|
|
return val_decimal_from_string(decimal_value);
|
2005-02-09 02:50:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-22 14:03:42 +02:00
|
|
|
bool Item_null::eq(const Item *item, bool binary_cmp) const
|
|
|
|
{ return item->type() == type(); }
|
2005-02-09 02:50:45 +04:00
|
|
|
|
|
|
|
|
2004-11-11 21:39:35 +03:00
|
|
|
double Item_null::val_real()
|
2004-03-18 15:14:36 +02:00
|
|
|
{
|
2004-03-20 13:36:26 +02:00
|
|
|
// following assert is redundant, because fixed=1 assigned in constructor
|
|
|
|
DBUG_ASSERT(fixed == 1);
|
2004-03-18 15:14:36 +02:00
|
|
|
null_value=1;
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
longlong Item_null::val_int()
|
|
|
|
{
|
2004-03-20 13:36:26 +02:00
|
|
|
// following assert is redundant, because fixed=1 assigned in constructor
|
|
|
|
DBUG_ASSERT(fixed == 1);
|
2004-03-18 15:14:36 +02:00
|
|
|
null_value=1;
|
|
|
|
return 0;
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
/* ARGSUSED */
|
|
|
|
String *Item_null::val_str(String *str)
|
2004-03-18 15:14:36 +02:00
|
|
|
{
|
2004-03-20 13:36:26 +02:00
|
|
|
// following assert is redundant, because fixed=1 assigned in constructor
|
|
|
|
DBUG_ASSERT(fixed == 1);
|
2004-03-18 15:14:36 +02:00
|
|
|
null_value=1;
|
|
|
|
return 0;
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2005-02-09 02:50:45 +04:00
|
|
|
my_decimal *Item_null::val_decimal(my_decimal *decimal_value)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2004-11-11 11:16:51 +02:00
|
|
|
Item *Item_null::safe_charset_converter(CHARSET_INFO *tocs)
|
|
|
|
{
|
|
|
|
collation.set(tocs);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2004-03-15 20:20:47 +03:00
|
|
|
/*********************** Item_param related ******************************/
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
2004-03-15 20:20:47 +03:00
|
|
|
Default function of Item_param::set_param_func, so in case
|
2007-10-11 13:29:09 -04:00
|
|
|
of malformed packet the server won't SIGSEGV.
|
2004-03-15 20:20:47 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
default_set_param_func(Item_param *param,
|
|
|
|
uchar **pos __attribute__((unused)),
|
|
|
|
ulong len __attribute__((unused)))
|
|
|
|
{
|
|
|
|
param->set_null();
|
|
|
|
}
|
|
|
|
|
2004-12-07 15:47:00 +02:00
|
|
|
|
2007-08-16 17:59:12 +04:00
|
|
|
Item_param::Item_param(uint pos_in_query_arg) :
|
2004-05-25 02:03:49 +04:00
|
|
|
state(NO_VALUE),
|
2004-03-15 20:20:47 +03:00
|
|
|
item_result_type(STRING_RESULT),
|
2004-06-18 04:16:08 +04:00
|
|
|
/* Don't pretend to be a literal unless value for this item is set. */
|
|
|
|
item_type(PARAM_ITEM),
|
2004-12-07 15:47:00 +02:00
|
|
|
param_type(MYSQL_TYPE_VARCHAR),
|
2004-05-25 02:03:49 +04:00
|
|
|
pos_in_query(pos_in_query_arg),
|
2008-02-28 20:22:11 -03:00
|
|
|
set_param_func(default_set_param_func),
|
Backport of revno 2630.28.10, 2630.28.31, 2630.28.26, 2630.33.1,
2630.39.1, 2630.28.29, 2630.34.3, 2630.34.2, 2630.34.1, 2630.29.29,
2630.29.28, 2630.31.1, 2630.28.13, 2630.28.10, 2617.23.14 and
some other minor revisions.
This patch implements:
WL#4264 "Backup: Stabilize Service Interface" -- all the
server prerequisites except si_objects.{h,cc} themselves (they can
be just copied over, when needed).
WL#4435: Support OUT-parameters in prepared statements.
(and all issues in the initial patches for these two
tasks, that were discovered in pushbuild and during testing).
Bug#39519: mysql_stmt_close() should flush all data
associated with the statement.
After execution of a prepared statement, send OUT parameters of the invoked
stored procedure, if any, to the client.
When using the binary protocol, send the parameters in an additional result
set over the wire. When using the text protocol, assign out parameters to
the user variables from the CALL(@var1, @var2, ...) specification.
The following refactoring has been made:
- Protocol::send_fields() was renamed to Protocol::send_result_set_metadata();
- A new Protocol::send_result_set_row() was introduced to incapsulate
common functionality for sending row data.
- Signature of Protocol::prepare_for_send() was changed: this operation
does not need a list of items, the number of items is fully sufficient.
The following backward incompatible changes have been made:
- CLIENT_MULTI_RESULTS is now enabled by default in the client;
- CLIENT_PS_MULTI_RESUTLS is now enabled by default in the client.
2009-10-22 00:02:06 +04:00
|
|
|
limit_clause_param(FALSE),
|
|
|
|
m_out_param_info(NULL)
|
2004-03-15 20:20:47 +03:00
|
|
|
{
|
|
|
|
name= (char*) "?";
|
2004-05-04 19:08:19 +04:00
|
|
|
/*
|
|
|
|
Since we can't say whenever this item can be NULL or cannot be NULL
|
|
|
|
before mysql_stmt_execute(), so we assuming that it can be NULL until
|
|
|
|
value is set.
|
|
|
|
*/
|
|
|
|
maybe_null= 1;
|
2005-11-28 12:41:44 +04:00
|
|
|
cnvitem= new Item_string("", 0, &my_charset_bin, DERIVATION_COERCIBLE);
|
|
|
|
cnvstr.set(cnvbuf, sizeof(cnvbuf), &my_charset_bin);
|
2004-03-15 20:20:47 +03:00
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2004-12-07 15:47:00 +02:00
|
|
|
|
2002-06-12 14:13:12 -07:00
|
|
|
void Item_param::set_null()
|
2003-09-02 14:37:06 +03:00
|
|
|
{
|
|
|
|
DBUG_ENTER("Item_param::set_null");
|
2004-05-04 19:08:19 +04:00
|
|
|
/* These are cleared after each execution by reset() method */
|
2004-05-25 02:03:49 +04:00
|
|
|
null_value= 1;
|
|
|
|
/*
|
|
|
|
Because of NULL and string values we need to set max_length for each new
|
|
|
|
placeholder value: user can submit NULL for any placeholder type, and
|
|
|
|
string length can be different in each execution.
|
|
|
|
*/
|
|
|
|
max_length= 0;
|
|
|
|
decimals= 0;
|
|
|
|
state= NULL_VALUE;
|
2005-07-13 17:38:55 +04:00
|
|
|
item_type= Item::NULL_ITEM;
|
2003-09-02 14:37:06 +03:00
|
|
|
DBUG_VOID_RETURN;
|
2002-06-12 14:13:12 -07:00
|
|
|
}
|
|
|
|
|
2004-05-25 02:03:49 +04:00
|
|
|
void Item_param::set_int(longlong i, uint32 max_length_arg)
|
2003-09-02 14:37:06 +03:00
|
|
|
{
|
|
|
|
DBUG_ENTER("Item_param::set_int");
|
2004-05-25 02:03:49 +04:00
|
|
|
value.integer= (longlong) i;
|
|
|
|
state= INT_VALUE;
|
|
|
|
max_length= max_length_arg;
|
|
|
|
decimals= 0;
|
2004-05-04 19:08:19 +04:00
|
|
|
maybe_null= 0;
|
2003-09-02 14:37:06 +03:00
|
|
|
DBUG_VOID_RETURN;
|
2002-06-12 14:13:12 -07:00
|
|
|
}
|
|
|
|
|
2004-05-25 02:03:49 +04:00
|
|
|
void Item_param::set_double(double d)
|
2003-09-02 14:37:06 +03:00
|
|
|
{
|
|
|
|
DBUG_ENTER("Item_param::set_double");
|
2004-05-25 02:03:49 +04:00
|
|
|
value.real= d;
|
|
|
|
state= REAL_VALUE;
|
|
|
|
max_length= DBL_DIG + 8;
|
2004-05-20 19:08:34 +03:00
|
|
|
decimals= NOT_FIXED_DEC;
|
2004-05-04 19:08:19 +04:00
|
|
|
maybe_null= 0;
|
2003-09-02 14:37:06 +03:00
|
|
|
DBUG_VOID_RETURN;
|
2002-06-12 14:13:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
2005-02-09 02:50:45 +04:00
|
|
|
Set decimal parameter value from string.
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@param str character string
|
|
|
|
@param length string length
|
2005-02-09 02:50:45 +04:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@note
|
|
|
|
As we use character strings to send decimal values in
|
2005-02-09 02:50:45 +04:00
|
|
|
binary protocol, we use str2my_decimal to convert it to
|
|
|
|
internal decimal value.
|
|
|
|
*/
|
2005-02-19 18:58:27 +02:00
|
|
|
|
2005-02-09 02:50:45 +04:00
|
|
|
void Item_param::set_decimal(const char *str, ulong length)
|
|
|
|
{
|
2005-02-19 18:58:27 +02:00
|
|
|
char *end;
|
2005-02-09 02:50:45 +04:00
|
|
|
DBUG_ENTER("Item_param::set_decimal");
|
|
|
|
|
2005-02-19 18:58:27 +02:00
|
|
|
end= (char*) str+length;
|
|
|
|
str2my_decimal(E_DEC_FATAL_ERROR, str, &decimal_value, &end);
|
2005-02-09 02:50:45 +04:00
|
|
|
state= DECIMAL_VALUE;
|
|
|
|
decimals= decimal_value.frac;
|
2009-07-03 11:41:19 +04:00
|
|
|
max_length=
|
|
|
|
my_decimal_precision_to_length_no_truncation(decimal_value.precision(),
|
|
|
|
decimals, unsigned_flag);
|
2005-02-09 02:50:45 +04:00
|
|
|
maybe_null= 0;
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
Backport of revno 2630.28.10, 2630.28.31, 2630.28.26, 2630.33.1,
2630.39.1, 2630.28.29, 2630.34.3, 2630.34.2, 2630.34.1, 2630.29.29,
2630.29.28, 2630.31.1, 2630.28.13, 2630.28.10, 2617.23.14 and
some other minor revisions.
This patch implements:
WL#4264 "Backup: Stabilize Service Interface" -- all the
server prerequisites except si_objects.{h,cc} themselves (they can
be just copied over, when needed).
WL#4435: Support OUT-parameters in prepared statements.
(and all issues in the initial patches for these two
tasks, that were discovered in pushbuild and during testing).
Bug#39519: mysql_stmt_close() should flush all data
associated with the statement.
After execution of a prepared statement, send OUT parameters of the invoked
stored procedure, if any, to the client.
When using the binary protocol, send the parameters in an additional result
set over the wire. When using the text protocol, assign out parameters to
the user variables from the CALL(@var1, @var2, ...) specification.
The following refactoring has been made:
- Protocol::send_fields() was renamed to Protocol::send_result_set_metadata();
- A new Protocol::send_result_set_row() was introduced to incapsulate
common functionality for sending row data.
- Signature of Protocol::prepare_for_send() was changed: this operation
does not need a list of items, the number of items is fully sufficient.
The following backward incompatible changes have been made:
- CLIENT_MULTI_RESULTS is now enabled by default in the client;
- CLIENT_PS_MULTI_RESUTLS is now enabled by default in the client.
2009-10-22 00:02:06 +04:00
|
|
|
void Item_param::set_decimal(const my_decimal *dv)
|
|
|
|
{
|
|
|
|
state= DECIMAL_VALUE;
|
|
|
|
|
|
|
|
my_decimal2decimal(dv, &decimal_value);
|
|
|
|
|
|
|
|
decimals= (uint8) decimal_value.frac;
|
|
|
|
unsigned_flag= !decimal_value.sign();
|
|
|
|
max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
|
|
|
|
decimals, unsigned_flag);
|
|
|
|
}
|
2005-02-09 02:50:45 +04:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
2007-03-23 22:08:31 +02:00
|
|
|
Set parameter value from MYSQL_TIME value.
|
2004-11-15 15:44:29 +03:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@param tm datetime value to set (time_type is ignored)
|
|
|
|
@param type type of datetime value
|
|
|
|
@param max_length_arg max length of datetime value as string
|
2004-11-15 15:44:29 +03:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@note
|
2004-11-15 15:44:29 +03:00
|
|
|
If we value to be stored is not normalized, zero value will be stored
|
|
|
|
instead and proper warning will be produced. This function relies on
|
|
|
|
the fact that even wrong value sent over binary protocol fits into
|
|
|
|
MAX_DATE_STRING_REP_LENGTH buffer.
|
|
|
|
*/
|
2007-03-23 22:08:31 +02:00
|
|
|
void Item_param::set_time(MYSQL_TIME *tm, timestamp_type time_type,
|
2006-12-15 00:51:37 +02:00
|
|
|
uint32 max_length_arg)
|
2003-01-23 22:32:39 -08:00
|
|
|
{
|
2004-05-25 02:03:49 +04:00
|
|
|
DBUG_ENTER("Item_param::set_time");
|
2003-01-23 22:32:39 -08:00
|
|
|
|
2004-05-25 02:03:49 +04:00
|
|
|
value.time= *tm;
|
2006-12-15 00:51:37 +02:00
|
|
|
value.time.time_type= time_type;
|
2003-01-23 22:32:39 -08:00
|
|
|
|
2004-11-15 15:44:29 +03:00
|
|
|
if (value.time.year > 9999 || value.time.month > 12 ||
|
|
|
|
value.time.day > 31 ||
|
2008-12-16 10:12:22 -02:00
|
|
|
(time_type != MYSQL_TIMESTAMP_TIME && value.time.hour > 23) ||
|
2004-11-15 15:44:29 +03:00
|
|
|
value.time.minute > 59 || value.time.second > 59)
|
|
|
|
{
|
|
|
|
char buff[MAX_DATE_STRING_REP_LENGTH];
|
|
|
|
uint length= my_TIME_to_str(&value.time, buff);
|
2007-03-23 22:08:31 +02:00
|
|
|
make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
|
|
|
|
buff, length, time_type, 0);
|
2004-11-15 15:44:29 +03:00
|
|
|
set_zero_time(&value.time, MYSQL_TIMESTAMP_ERROR);
|
|
|
|
}
|
|
|
|
|
2004-05-25 02:03:49 +04:00
|
|
|
state= TIME_VALUE;
|
2004-05-04 19:08:19 +04:00
|
|
|
maybe_null= 0;
|
2004-05-25 02:03:49 +04:00
|
|
|
max_length= max_length_arg;
|
|
|
|
decimals= 0;
|
2003-09-02 14:37:06 +03:00
|
|
|
DBUG_VOID_RETURN;
|
2002-06-12 14:13:12 -07:00
|
|
|
}
|
|
|
|
|
2002-10-02 13:33:08 +03:00
|
|
|
|
2004-05-25 02:03:49 +04:00
|
|
|
bool Item_param::set_str(const char *str, ulong length)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("Item_param::set_str");
|
|
|
|
/*
|
|
|
|
Assign string with no conversion: data is converted only after it's
|
|
|
|
been written to the binary log.
|
|
|
|
*/
|
2004-11-11 11:16:51 +02:00
|
|
|
uint dummy_errors;
|
|
|
|
if (str_value.copy(str, length, &my_charset_bin, &my_charset_bin,
|
|
|
|
&dummy_errors))
|
2004-05-25 02:03:49 +04:00
|
|
|
DBUG_RETURN(TRUE);
|
|
|
|
state= STRING_VALUE;
|
2005-02-09 02:50:45 +04:00
|
|
|
max_length= length;
|
2004-05-04 19:08:19 +04:00
|
|
|
maybe_null= 0;
|
2004-05-25 02:03:49 +04:00
|
|
|
/* max_length and decimals are set after charset conversion */
|
|
|
|
/* sic: str may be not null-terminated, don't add DBUG_PRINT here */
|
|
|
|
DBUG_RETURN(FALSE);
|
2003-01-23 22:32:39 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-05-25 02:03:49 +04:00
|
|
|
bool Item_param::set_longdata(const char *str, ulong length)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("Item_param::set_longdata");
|
|
|
|
|
|
|
|
/*
|
|
|
|
If client character set is multibyte, end of long data packet
|
|
|
|
may hit at the middle of a multibyte character. Additionally,
|
|
|
|
if binary log is open we must write long data value to the
|
|
|
|
binary log in character set of client. This is why we can't
|
|
|
|
convert long data to connection character set as it comes
|
|
|
|
(here), and first have to concatenate all pieces together,
|
|
|
|
write query to the binary log and only then perform conversion.
|
|
|
|
*/
|
2011-03-15 17:36:12 +06:00
|
|
|
if (str_value.length() + length > max_long_data_size)
|
|
|
|
{
|
|
|
|
my_message(ER_UNKNOWN_ERROR,
|
|
|
|
"Parameter of prepared statement which is set through "
|
|
|
|
"mysql_send_long_data() is longer than "
|
|
|
|
"'max_long_data_size' bytes",
|
|
|
|
MYF(0));
|
|
|
|
DBUG_RETURN(true);
|
|
|
|
}
|
|
|
|
|
2004-05-25 02:03:49 +04:00
|
|
|
if (str_value.append(str, length, &my_charset_bin))
|
|
|
|
DBUG_RETURN(TRUE);
|
|
|
|
state= LONG_DATA_VALUE;
|
2004-05-04 19:08:19 +04:00
|
|
|
maybe_null= 0;
|
2004-05-25 02:03:49 +04:00
|
|
|
|
|
|
|
DBUG_RETURN(FALSE);
|
2004-05-04 19:08:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
2004-06-07 12:09:10 +04:00
|
|
|
Set parameter value from user variable value.
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@param thd Current thread
|
|
|
|
@param entry User variable structure (NULL means use NULL value)
|
2004-06-07 12:09:10 +04:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@retval
|
2004-06-07 12:09:10 +04:00
|
|
|
0 OK
|
2007-10-11 13:29:09 -04:00
|
|
|
@retval
|
2005-02-09 02:50:45 +04:00
|
|
|
1 Out of memory
|
2004-06-07 12:09:10 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
bool Item_param::set_from_user_var(THD *thd, const user_var_entry *entry)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("Item_param::set_from_user_var");
|
|
|
|
if (entry && entry->value)
|
|
|
|
{
|
|
|
|
item_result_type= entry->type;
|
2008-02-08 08:55:55 -02:00
|
|
|
unsigned_flag= entry->unsigned_flag;
|
2008-02-28 11:34:08 -03:00
|
|
|
if (limit_clause_param)
|
|
|
|
{
|
|
|
|
my_bool unused;
|
|
|
|
set_int(entry->val_int(&unused), MY_INT64_NUM_DECIMAL_DIGITS);
|
|
|
|
item_type= Item::INT_ITEM;
|
|
|
|
DBUG_RETURN(!unsigned_flag && value.integer < 0 ? 1 : 0);
|
|
|
|
}
|
2007-05-18 18:16:51 +05:00
|
|
|
switch (item_result_type) {
|
2004-06-22 03:25:54 +04:00
|
|
|
case REAL_RESULT:
|
|
|
|
set_double(*(double*)entry->value);
|
2004-06-25 15:16:00 +03:00
|
|
|
item_type= Item::REAL_ITEM;
|
2004-06-22 03:25:54 +04:00
|
|
|
break;
|
|
|
|
case INT_RESULT:
|
2007-03-09 08:05:08 +03:00
|
|
|
set_int(*(longlong*)entry->value, MY_INT64_NUM_DECIMAL_DIGITS);
|
2004-06-25 15:16:00 +03:00
|
|
|
item_type= Item::INT_ITEM;
|
2004-06-22 03:25:54 +04:00
|
|
|
break;
|
|
|
|
case STRING_RESULT:
|
2004-06-07 12:09:10 +04:00
|
|
|
{
|
2004-06-22 03:25:54 +04:00
|
|
|
CHARSET_INFO *fromcs= entry->collation.collation;
|
|
|
|
CHARSET_INFO *tocs= thd->variables.collation_connection;
|
|
|
|
uint32 dummy_offset;
|
|
|
|
|
2009-06-25 11:22:39 +05:00
|
|
|
value.cs_info.character_set_of_placeholder= fromcs;
|
|
|
|
value.cs_info.character_set_client= thd->variables.character_set_client;
|
2004-06-22 03:25:54 +04:00
|
|
|
/*
|
|
|
|
Setup source and destination character sets so that they
|
|
|
|
are different only if conversion is necessary: this will
|
|
|
|
make later checks easier.
|
|
|
|
*/
|
|
|
|
value.cs_info.final_character_set_of_str_value=
|
|
|
|
String::needs_conversion(0, fromcs, tocs, &dummy_offset) ?
|
|
|
|
tocs : fromcs;
|
|
|
|
/*
|
|
|
|
Exact value of max_length is not known unless data is converted to
|
|
|
|
charset of connection, so we have to set it later.
|
|
|
|
*/
|
|
|
|
item_type= Item::STRING_ITEM;
|
|
|
|
|
|
|
|
if (set_str((const char *)entry->value, entry->length))
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
break;
|
|
|
|
}
|
2005-02-09 02:50:45 +04:00
|
|
|
case DECIMAL_RESULT:
|
|
|
|
{
|
|
|
|
const my_decimal *ent_value= (const my_decimal *)entry->value;
|
|
|
|
my_decimal2decimal(ent_value, &decimal_value);
|
|
|
|
state= DECIMAL_VALUE;
|
|
|
|
decimals= ent_value->frac;
|
2009-07-03 11:41:19 +04:00
|
|
|
max_length=
|
|
|
|
my_decimal_precision_to_length_no_truncation(ent_value->precision(),
|
|
|
|
decimals, unsigned_flag);
|
2007-05-18 18:16:51 +05:00
|
|
|
item_type= Item::DECIMAL_ITEM;
|
2005-02-09 02:50:45 +04:00
|
|
|
break;
|
|
|
|
}
|
2004-06-22 03:25:54 +04:00
|
|
|
default:
|
|
|
|
DBUG_ASSERT(0);
|
|
|
|
set_null();
|
2004-06-07 12:09:10 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
set_null();
|
|
|
|
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
|
|
|
Resets parameter after execution.
|
|
|
|
|
|
|
|
@note
|
|
|
|
We clear null_value here instead of setting it in set_* methods,
|
2004-05-04 19:08:19 +04:00
|
|
|
because we want more easily handle case for long data.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void Item_param::reset()
|
2004-05-25 02:03:49 +04:00
|
|
|
{
|
2005-07-29 05:06:35 +03:00
|
|
|
DBUG_ENTER("Item_param::reset");
|
2004-05-25 02:03:49 +04:00
|
|
|
/* Shrink string buffer if it's bigger than max possible CHAR column */
|
|
|
|
if (str_value.alloced_length() > MAX_CHAR_WIDTH)
|
|
|
|
str_value.free();
|
|
|
|
else
|
|
|
|
str_value.length(0);
|
2004-05-31 14:21:48 +04:00
|
|
|
str_value_ptr.length(0);
|
2004-05-25 02:03:49 +04:00
|
|
|
/*
|
2005-02-09 02:50:45 +04:00
|
|
|
We must prevent all charset conversions until data has been written
|
2004-05-31 14:21:48 +04:00
|
|
|
to the binary log.
|
2004-05-25 02:03:49 +04:00
|
|
|
*/
|
|
|
|
str_value.set_charset(&my_charset_bin);
|
2005-07-13 23:43:46 +04:00
|
|
|
collation.set(&my_charset_bin, DERIVATION_COERCIBLE);
|
2004-05-25 02:03:49 +04:00
|
|
|
state= NO_VALUE;
|
2004-05-04 19:08:19 +04:00
|
|
|
maybe_null= 1;
|
|
|
|
null_value= 0;
|
2004-06-18 04:16:08 +04:00
|
|
|
/*
|
|
|
|
Don't reset item_type to PARAM_ITEM: it's only needed to guard
|
|
|
|
us from item optimizations at prepare stage, when item doesn't yet
|
|
|
|
contain a literal of some kind.
|
|
|
|
In all other cases when this object is accessed its value is
|
|
|
|
set (this assumption is guarded by 'state' and
|
|
|
|
DBUG_ASSERTS(state != NO_VALUE) in all Item_param::get_*
|
|
|
|
methods).
|
|
|
|
*/
|
2005-07-29 05:06:35 +03:00
|
|
|
DBUG_VOID_RETURN;
|
2002-06-12 14:13:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-06 23:39:11 -08:00
|
|
|
int Item_param::save_in_field(Field *field, bool no_conversions)
|
2002-06-12 14:13:12 -07:00
|
|
|
{
|
|
|
|
field->set_notnull();
|
2004-05-25 02:03:49 +04:00
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case INT_VALUE:
|
2005-09-14 01:41:44 +03:00
|
|
|
return field->store(value.integer, unsigned_flag);
|
2004-05-25 02:03:49 +04:00
|
|
|
case REAL_VALUE:
|
|
|
|
return field->store(value.real);
|
2005-02-09 02:50:45 +04:00
|
|
|
case DECIMAL_VALUE:
|
|
|
|
return field->store_decimal(&decimal_value);
|
2004-05-25 02:03:49 +04:00
|
|
|
case TIME_VALUE:
|
|
|
|
field->store_time(&value.time, value.time.time_type);
|
2003-01-23 22:32:39 -08:00
|
|
|
return 0;
|
2004-05-25 02:03:49 +04:00
|
|
|
case STRING_VALUE:
|
|
|
|
case LONG_DATA_VALUE:
|
|
|
|
return field->store(str_value.ptr(), str_value.length(),
|
|
|
|
str_value.charset());
|
|
|
|
case NULL_VALUE:
|
2004-11-11 11:16:51 +02:00
|
|
|
return set_field_to_null_with_conversions(field, no_conversions);
|
2004-05-25 02:03:49 +04:00
|
|
|
case NO_VALUE:
|
|
|
|
default:
|
|
|
|
DBUG_ASSERT(0);
|
2002-06-12 14:13:12 -07:00
|
|
|
}
|
2004-05-25 02:03:49 +04:00
|
|
|
return 1;
|
2002-06-12 14:13:12 -07:00
|
|
|
}
|
|
|
|
|
2004-05-25 02:03:49 +04:00
|
|
|
|
2007-03-23 22:08:31 +02:00
|
|
|
bool Item_param::get_time(MYSQL_TIME *res)
|
2003-01-23 22:32:39 -08:00
|
|
|
{
|
2004-05-25 02:03:49 +04:00
|
|
|
if (state == TIME_VALUE)
|
|
|
|
{
|
|
|
|
*res= value.time;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
If parameter value isn't supplied assertion will fire in val_str()
|
|
|
|
which is called from Item::get_time().
|
|
|
|
*/
|
|
|
|
return Item::get_time(res);
|
2003-01-23 22:32:39 -08:00
|
|
|
}
|
2002-10-02 13:33:08 +03:00
|
|
|
|
2004-05-25 02:03:49 +04:00
|
|
|
|
2007-03-23 22:08:31 +02:00
|
|
|
bool Item_param::get_date(MYSQL_TIME *res, uint fuzzydate)
|
2004-06-09 03:21:50 +04:00
|
|
|
{
|
|
|
|
if (state == TIME_VALUE)
|
|
|
|
{
|
|
|
|
*res= value.time;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return Item::get_date(res, fuzzydate);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-11 21:39:35 +03:00
|
|
|
double Item_param::val_real()
|
2002-06-12 14:13:12 -07:00
|
|
|
{
|
2004-05-25 02:03:49 +04:00
|
|
|
switch (state) {
|
|
|
|
case REAL_VALUE:
|
|
|
|
return value.real;
|
|
|
|
case INT_VALUE:
|
|
|
|
return (double) value.integer;
|
2005-02-09 02:50:45 +04:00
|
|
|
case DECIMAL_VALUE:
|
|
|
|
{
|
|
|
|
double result;
|
|
|
|
my_decimal2double(E_DEC_FATAL_ERROR, &decimal_value, &result);
|
|
|
|
return result;
|
|
|
|
}
|
2004-05-25 02:03:49 +04:00
|
|
|
case STRING_VALUE:
|
|
|
|
case LONG_DATA_VALUE:
|
2005-01-15 12:28:38 +02:00
|
|
|
{
|
|
|
|
int dummy_err;
|
|
|
|
char *end_not_used;
|
|
|
|
return my_strntod(str_value.charset(), (char*) str_value.ptr(),
|
|
|
|
str_value.length(), &end_not_used, &dummy_err);
|
|
|
|
}
|
2004-05-25 02:03:49 +04:00
|
|
|
case TIME_VALUE:
|
|
|
|
/*
|
|
|
|
This works for example when user says SELECT ?+0.0 and supplies
|
|
|
|
time value for the placeholder.
|
|
|
|
*/
|
2004-08-24 18:00:45 +03:00
|
|
|
return ulonglong2double(TIME_to_ulonglong(&value.time));
|
2004-05-25 02:03:49 +04:00
|
|
|
case NULL_VALUE:
|
2004-05-05 20:04:25 +04:00
|
|
|
return 0.0;
|
2002-06-12 14:13:12 -07:00
|
|
|
default:
|
2004-05-25 02:03:49 +04:00
|
|
|
DBUG_ASSERT(0);
|
2002-06-12 14:13:12 -07:00
|
|
|
}
|
2004-05-25 02:03:49 +04:00
|
|
|
return 0.0;
|
2002-06-12 14:13:12 -07:00
|
|
|
}
|
|
|
|
|
2002-10-02 13:33:08 +03:00
|
|
|
|
2002-06-12 14:13:12 -07:00
|
|
|
longlong Item_param::val_int()
|
|
|
|
{
|
2004-05-25 02:03:49 +04:00
|
|
|
switch (state) {
|
|
|
|
case REAL_VALUE:
|
2005-11-30 11:17:25 +04:00
|
|
|
return (longlong) rint(value.real);
|
2004-05-25 02:03:49 +04:00
|
|
|
case INT_VALUE:
|
|
|
|
return value.integer;
|
2005-02-09 02:50:45 +04:00
|
|
|
case DECIMAL_VALUE:
|
|
|
|
{
|
|
|
|
longlong i;
|
|
|
|
my_decimal2int(E_DEC_FATAL_ERROR, &decimal_value, unsigned_flag, &i);
|
|
|
|
return i;
|
|
|
|
}
|
2004-05-25 02:03:49 +04:00
|
|
|
case STRING_VALUE:
|
|
|
|
case LONG_DATA_VALUE:
|
|
|
|
{
|
|
|
|
int dummy_err;
|
|
|
|
return my_strntoll(str_value.charset(), str_value.ptr(),
|
|
|
|
str_value.length(), 10, (char**) 0, &dummy_err);
|
|
|
|
}
|
|
|
|
case TIME_VALUE:
|
|
|
|
return (longlong) TIME_to_ulonglong(&value.time);
|
|
|
|
case NULL_VALUE:
|
|
|
|
return 0;
|
2002-06-12 14:13:12 -07:00
|
|
|
default:
|
2004-05-25 02:03:49 +04:00
|
|
|
DBUG_ASSERT(0);
|
2002-06-12 14:13:12 -07:00
|
|
|
}
|
2004-05-25 02:03:49 +04:00
|
|
|
return 0;
|
2002-06-12 14:13:12 -07:00
|
|
|
}
|
|
|
|
|
2002-10-02 13:33:08 +03:00
|
|
|
|
2005-02-09 02:50:45 +04:00
|
|
|
my_decimal *Item_param::val_decimal(my_decimal *dec)
|
|
|
|
{
|
|
|
|
switch (state) {
|
|
|
|
case DECIMAL_VALUE:
|
|
|
|
return &decimal_value;
|
|
|
|
case REAL_VALUE:
|
|
|
|
double2my_decimal(E_DEC_FATAL_ERROR, value.real, dec);
|
|
|
|
return dec;
|
|
|
|
case INT_VALUE:
|
|
|
|
int2my_decimal(E_DEC_FATAL_ERROR, value.integer, unsigned_flag, dec);
|
|
|
|
return dec;
|
|
|
|
case STRING_VALUE:
|
|
|
|
case LONG_DATA_VALUE:
|
|
|
|
string2my_decimal(E_DEC_FATAL_ERROR, &str_value, dec);
|
|
|
|
return dec;
|
|
|
|
case TIME_VALUE:
|
|
|
|
{
|
|
|
|
longlong i= (longlong) TIME_to_ulonglong(&value.time);
|
|
|
|
int2my_decimal(E_DEC_FATAL_ERROR, i, 0, dec);
|
|
|
|
return dec;
|
|
|
|
}
|
|
|
|
case NULL_VALUE:
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
DBUG_ASSERT(0);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-06-12 14:13:12 -07:00
|
|
|
String *Item_param::val_str(String* str)
|
|
|
|
{
|
2004-05-25 02:03:49 +04:00
|
|
|
switch (state) {
|
|
|
|
case STRING_VALUE:
|
|
|
|
case LONG_DATA_VALUE:
|
2004-05-31 14:21:48 +04:00
|
|
|
return &str_value_ptr;
|
2004-05-25 02:03:49 +04:00
|
|
|
case REAL_VALUE:
|
2006-06-16 12:17:20 +02:00
|
|
|
str->set_real(value.real, NOT_FIXED_DEC, &my_charset_bin);
|
2004-05-25 02:03:49 +04:00
|
|
|
return str;
|
|
|
|
case INT_VALUE:
|
|
|
|
str->set(value.integer, &my_charset_bin);
|
2002-06-12 14:13:12 -07:00
|
|
|
return str;
|
2005-02-09 02:50:45 +04:00
|
|
|
case DECIMAL_VALUE:
|
|
|
|
if (my_decimal2string(E_DEC_FATAL_ERROR, &decimal_value,
|
|
|
|
0, 0, 0, str) <= 1)
|
|
|
|
return str;
|
|
|
|
return NULL;
|
2004-05-25 02:03:49 +04:00
|
|
|
case TIME_VALUE:
|
|
|
|
{
|
2004-11-11 11:16:51 +02:00
|
|
|
if (str->reserve(MAX_DATE_STRING_REP_LENGTH))
|
2004-05-25 02:03:49 +04:00
|
|
|
break;
|
2004-11-11 11:16:51 +02:00
|
|
|
str->length((uint) my_TIME_to_str(&value.time, (char*) str->ptr()));
|
|
|
|
str->set_charset(&my_charset_bin);
|
2002-06-12 14:13:12 -07:00
|
|
|
return str;
|
2004-05-25 02:03:49 +04:00
|
|
|
}
|
|
|
|
case NULL_VALUE:
|
|
|
|
return NULL;
|
2002-06-12 14:13:12 -07:00
|
|
|
default:
|
2004-05-25 02:03:49 +04:00
|
|
|
DBUG_ASSERT(0);
|
2002-06-12 14:13:12 -07:00
|
|
|
}
|
2004-05-25 02:03:49 +04:00
|
|
|
return str;
|
2002-06-12 14:13:12 -07:00
|
|
|
}
|
2003-04-04 12:33:17 -05:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
2003-04-04 12:33:17 -05:00
|
|
|
Return Param item values in string format, for generating the dynamic
|
2007-10-11 13:29:09 -04:00
|
|
|
query used in update/binary logs.
|
|
|
|
|
|
|
|
@todo
|
|
|
|
- Change interface and implementation to fill log data in place
|
|
|
|
and avoid one more memcpy/alloc between str and log string.
|
|
|
|
- In case of error we need to notify replication
|
|
|
|
that binary log contains wrong statement
|
2003-04-04 12:33:17 -05:00
|
|
|
*/
|
|
|
|
|
Bug#12601974 - STORED PROCEDURE SQL_MODE=NO_BACKSLASH_ESCAPES IGNORED AND BREAKS REPLICATION
Analysis:
========================
sql_mode "NO_BACKSLASH_ESCAPES": When user want to use backslash as character input,
instead of escape character in a string literal then sql_mode can be set to
"NO_BACKSLASH_ESCAPES". With this mode enabled, backslash becomes an ordinary
character like any other.
SQL_MODE set applies to the current client session. And while creating the stored
procedure, MySQL stores the current sql_mode and always executes the stored
procedure in sql_mode stored with the Procedure, regardless of the server SQL
mode in effect when the routine is invoked.
In the scenario (for which bug is reported), the routine is created with
sql_mode=NO_BACKSLASH_ESCAPES. And routine is executed with the invoker sql_mode
is "" (NOT SET) by executing statement "call testp('Axel\'s')".
Since invoker sql_mode is "" (NOT_SET), the '\' in 'Axel\'s'(argument to function)
is considered as escape character and column "a" (of table "t1") values are
updated with "Axel's". The binary log generated for above update operation is as below,
set sql_mode=XXXXXX (for no_backslash_escapes)
update test.t1 set a= NAME_CONST('var',_latin1'Axel\'s' COLLATE 'latin1_swedish_ci');
While logging stored procedure statements, the local variables (params) used in
statements are replaced with the NAME_CONST(var_name, var_value) (Internal function)
(http://dev.mysql.com/doc/refman/5.6/en/miscellaneous-functions.html#function_name-const)
On slave, these logs are applied. NAME_CONST is parsed to get the variable and its
value. Since, stored procedure is created with sql_mode="NO_BACKSLASH_ESCAPES", the sql_mode
is also logged in. So that at slave this sql_mode is set before executing the statements
of routine. So at slave, sql_mode is set to "NO_BACKSLASH_ESCAPES" and then while
parsing NAME_CONST of string variable, '\' is considered as NON ESCAPE character
and parsing reported error for "'" (as we have only one "'" no backslash).
At slave, parsing was proper with sql_mode "NO_BACKSLASH_ESCAPES".
But above error reported while writing bin log, "'" (of Axel's) is escaped with
"\" character. Actually, all special characters (n, r, ', ", \, 0...) are escaped
while writing NAME_CONST for string variable(param, local variable) in bin log
Airrespective of "NO_BACKSLASH_ESCAPES" sql_mode. So, basically, the problem is
that logging string parameter does not take into account sql_mode value.
Fix:
========================
So when sql_mode is set to "NO_BACKSLASH_ESCAPES", escaping characters as
(n, r, ', ", \, 0...) should be avoided. To do so, added a check to not to
escape such characters while writing NAME_CONST for string variables in bin
log.
And when sql_mode is set to NO_BACKSLASH_ESCAPES, quote character "'" is
represented as ''.
http://dev.mysql.com/doc/refman/5.6/en/string-literals.html (There are several
ways to include quote characters within a string: )
2012-02-29 12:23:15 +05:30
|
|
|
const String *Item_param::query_val_str(THD *thd, String* str) const
|
2004-03-18 15:14:36 +02:00
|
|
|
{
|
2004-05-25 02:03:49 +04:00
|
|
|
switch (state) {
|
|
|
|
case INT_VALUE:
|
2008-02-08 10:47:25 -02:00
|
|
|
str->set_int(value.integer, unsigned_flag, &my_charset_bin);
|
2004-05-25 02:03:49 +04:00
|
|
|
break;
|
|
|
|
case REAL_VALUE:
|
2006-06-16 12:17:20 +02:00
|
|
|
str->set_real(value.real, NOT_FIXED_DEC, &my_charset_bin);
|
2004-05-25 02:03:49 +04:00
|
|
|
break;
|
2005-02-09 02:50:45 +04:00
|
|
|
case DECIMAL_VALUE:
|
|
|
|
if (my_decimal2string(E_DEC_FATAL_ERROR, &decimal_value,
|
|
|
|
0, 0, 0, str) > 1)
|
|
|
|
return &my_null_string;
|
|
|
|
break;
|
2004-05-25 02:03:49 +04:00
|
|
|
case TIME_VALUE:
|
2003-04-04 12:33:17 -05:00
|
|
|
{
|
2004-05-25 02:03:49 +04:00
|
|
|
char *buf, *ptr;
|
|
|
|
str->length(0);
|
|
|
|
/*
|
|
|
|
TODO: in case of error we need to notify replication
|
|
|
|
that binary log contains wrong statement
|
|
|
|
*/
|
2004-11-11 11:16:51 +02:00
|
|
|
if (str->reserve(MAX_DATE_STRING_REP_LENGTH+3))
|
2004-05-25 02:03:49 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* Create date string inplace */
|
|
|
|
buf= str->c_ptr_quick();
|
|
|
|
ptr= buf;
|
|
|
|
*ptr++= '\'';
|
2004-11-11 11:16:51 +02:00
|
|
|
ptr+= (uint) my_TIME_to_str(&value.time, ptr);
|
2004-05-25 02:03:49 +04:00
|
|
|
*ptr++= '\'';
|
|
|
|
str->length((uint32) (ptr - buf));
|
|
|
|
break;
|
2003-04-04 12:33:17 -05:00
|
|
|
}
|
2004-05-25 02:03:49 +04:00
|
|
|
case STRING_VALUE:
|
|
|
|
case LONG_DATA_VALUE:
|
2003-04-04 12:33:17 -05:00
|
|
|
{
|
2004-05-25 02:03:49 +04:00
|
|
|
str->length(0);
|
Bug#12601974 - STORED PROCEDURE SQL_MODE=NO_BACKSLASH_ESCAPES IGNORED AND BREAKS REPLICATION
Analysis:
========================
sql_mode "NO_BACKSLASH_ESCAPES": When user want to use backslash as character input,
instead of escape character in a string literal then sql_mode can be set to
"NO_BACKSLASH_ESCAPES". With this mode enabled, backslash becomes an ordinary
character like any other.
SQL_MODE set applies to the current client session. And while creating the stored
procedure, MySQL stores the current sql_mode and always executes the stored
procedure in sql_mode stored with the Procedure, regardless of the server SQL
mode in effect when the routine is invoked.
In the scenario (for which bug is reported), the routine is created with
sql_mode=NO_BACKSLASH_ESCAPES. And routine is executed with the invoker sql_mode
is "" (NOT SET) by executing statement "call testp('Axel\'s')".
Since invoker sql_mode is "" (NOT_SET), the '\' in 'Axel\'s'(argument to function)
is considered as escape character and column "a" (of table "t1") values are
updated with "Axel's". The binary log generated for above update operation is as below,
set sql_mode=XXXXXX (for no_backslash_escapes)
update test.t1 set a= NAME_CONST('var',_latin1'Axel\'s' COLLATE 'latin1_swedish_ci');
While logging stored procedure statements, the local variables (params) used in
statements are replaced with the NAME_CONST(var_name, var_value) (Internal function)
(http://dev.mysql.com/doc/refman/5.6/en/miscellaneous-functions.html#function_name-const)
On slave, these logs are applied. NAME_CONST is parsed to get the variable and its
value. Since, stored procedure is created with sql_mode="NO_BACKSLASH_ESCAPES", the sql_mode
is also logged in. So that at slave this sql_mode is set before executing the statements
of routine. So at slave, sql_mode is set to "NO_BACKSLASH_ESCAPES" and then while
parsing NAME_CONST of string variable, '\' is considered as NON ESCAPE character
and parsing reported error for "'" (as we have only one "'" no backslash).
At slave, parsing was proper with sql_mode "NO_BACKSLASH_ESCAPES".
But above error reported while writing bin log, "'" (of Axel's) is escaped with
"\" character. Actually, all special characters (n, r, ', ", \, 0...) are escaped
while writing NAME_CONST for string variable(param, local variable) in bin log
Airrespective of "NO_BACKSLASH_ESCAPES" sql_mode. So, basically, the problem is
that logging string parameter does not take into account sql_mode value.
Fix:
========================
So when sql_mode is set to "NO_BACKSLASH_ESCAPES", escaping characters as
(n, r, ', ", \, 0...) should be avoided. To do so, added a check to not to
escape such characters while writing NAME_CONST for string variables in bin
log.
And when sql_mode is set to NO_BACKSLASH_ESCAPES, quote character "'" is
represented as ''.
http://dev.mysql.com/doc/refman/5.6/en/string-literals.html (There are several
ways to include quote characters within a string: )
2012-02-29 12:23:15 +05:30
|
|
|
append_query_string(thd, value.cs_info.character_set_client, &str_value,
|
|
|
|
str);
|
2004-05-25 02:03:49 +04:00
|
|
|
break;
|
2003-04-04 12:33:17 -05:00
|
|
|
}
|
2004-05-25 02:03:49 +04:00
|
|
|
case NULL_VALUE:
|
|
|
|
return &my_null_string;
|
|
|
|
default:
|
|
|
|
DBUG_ASSERT(0);
|
2003-04-04 12:33:17 -05:00
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
2004-05-25 02:03:49 +04:00
|
|
|
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
2004-05-25 02:03:49 +04:00
|
|
|
Convert string from client character set to the character set of
|
|
|
|
connection.
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool Item_param::convert_str_value(THD *thd)
|
|
|
|
{
|
|
|
|
bool rc= FALSE;
|
|
|
|
if (state == STRING_VALUE || state == LONG_DATA_VALUE)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Check is so simple because all charsets were set up properly
|
|
|
|
in setup_one_conversion_function, where typecode of
|
|
|
|
placeholder was also taken into account: the variables are different
|
|
|
|
here only if conversion is really necessary.
|
|
|
|
*/
|
|
|
|
if (value.cs_info.final_character_set_of_str_value !=
|
2005-08-19 14:49:34 -04:00
|
|
|
value.cs_info.character_set_of_placeholder)
|
2004-05-25 02:03:49 +04:00
|
|
|
{
|
|
|
|
rc= thd->convert_string(&str_value,
|
2005-08-19 14:49:34 -04:00
|
|
|
value.cs_info.character_set_of_placeholder,
|
2004-05-25 02:03:49 +04:00
|
|
|
value.cs_info.final_character_set_of_str_value);
|
|
|
|
}
|
2004-11-11 11:16:51 +02:00
|
|
|
else
|
|
|
|
str_value.set_charset(value.cs_info.final_character_set_of_str_value);
|
|
|
|
/* Here str_value is guaranteed to be in final_character_set_of_str_value */
|
|
|
|
|
2009-02-19 11:49:35 +03:00
|
|
|
max_length= str_value.numchars() * str_value.charset()->mbmaxlen;
|
BUG#11753852: IF() VALUES ARE EVALUATED DIFFERENTLY IN A
REGULAR SQL VS PREPARED STATEMENT
Analysis:
---------
When passing user variables as parameters to the
prepared statements, the IF() function evaluation
turns out to be incorrect.
Consider the example:
SET @var1='0.038687';
SELECT @var1 , IF( @var1 = 0 , 1 ,@var1 ) AS sqlif ;
+----------+----------+
| @var1 | sqlif |
+----------+----------+
| 0.038687 | 0.038687 |
+----------+----------+
Executing a prepared statement where the parameters are
supplied:
PREPARE fail_stmt FROM "SELECT ? ,
IF( ? = 0 , 1 , ? ) AS ps_if_fail" ;
EXECUTE fail_stmt USING @var1 ,@var1 , @var1 ;
+----------+------------+
| ? | ps_if_fail |
+----------+------------+
| 0.038687 | 1 |
+----------+------------+
1 row in set (0.00 sec)
In the regular statement or while executing the prepared
statements without passing parameters, the decimal
precision is set for the user variable of type string.
The comparison function used for evaluation considered
the precision while comparing the values.
But while executing the prepared statement with the
parameters supplied, the decimal precision was not
set. Thus the comparison function chosen was different
which looked at the absolute values for comparison.
Fix:
----
The fix is to set 'decimals' field of Item_param to the
default value which is nothing but the maximum number of
decimals(NOT_FIXED_DEC). This is set for cases where the
strings are converted to the numeric form within certain
functions. Thus the value is not rounded off during
comparison, ensuring correct evaluation.
2013-03-28 19:11:26 +05:30
|
|
|
|
|
|
|
/* For the strings converted to numeric form within some functions */
|
|
|
|
decimals= NOT_FIXED_DEC;
|
2004-05-31 14:21:48 +04:00
|
|
|
/*
|
|
|
|
str_value_ptr is returned from val_str(). It must be not alloced
|
|
|
|
to prevent it's modification by val_str() invoker.
|
|
|
|
*/
|
|
|
|
str_value_ptr.set(str_value.ptr(), str_value.length(),
|
|
|
|
str_value.charset());
|
2005-07-13 23:43:46 +04:00
|
|
|
/* Synchronize item charset with value charset */
|
|
|
|
collation.set(str_value.charset(), DERIVATION_COERCIBLE);
|
2004-05-25 02:03:49 +04:00
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2002-06-12 14:13:12 -07:00
|
|
|
|
2005-05-03 12:47:27 +04:00
|
|
|
bool Item_param::basic_const_item() const
|
|
|
|
{
|
|
|
|
if (state == NO_VALUE || state == TIME_VALUE)
|
|
|
|
return FALSE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-05-03 19:32:29 +04:00
|
|
|
|
2005-05-03 12:47:27 +04:00
|
|
|
Item *
|
2006-12-15 00:51:37 +02:00
|
|
|
Item_param::clone_item()
|
2005-05-03 12:47:27 +04:00
|
|
|
{
|
|
|
|
/* see comments in the header file */
|
|
|
|
switch (state) {
|
|
|
|
case NULL_VALUE:
|
|
|
|
return new Item_null(name);
|
|
|
|
case INT_VALUE:
|
2005-05-05 12:55:09 +04:00
|
|
|
return (unsigned_flag ?
|
|
|
|
new Item_uint(name, value.integer, max_length) :
|
|
|
|
new Item_int(name, value.integer, max_length));
|
2005-05-03 12:47:27 +04:00
|
|
|
case REAL_VALUE:
|
2005-05-04 16:53:10 +04:00
|
|
|
return new Item_float(name, value.real, decimals, max_length);
|
2005-05-03 12:47:27 +04:00
|
|
|
case STRING_VALUE:
|
|
|
|
case LONG_DATA_VALUE:
|
|
|
|
return new Item_string(name, str_value.c_ptr_quick(), str_value.length(),
|
|
|
|
str_value.charset());
|
|
|
|
case TIME_VALUE:
|
|
|
|
break;
|
|
|
|
case NO_VALUE:
|
|
|
|
default:
|
|
|
|
DBUG_ASSERT(0);
|
|
|
|
};
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
Item_param::eq(const Item *arg, bool binary_cmp) const
|
|
|
|
{
|
|
|
|
Item *item;
|
|
|
|
if (!basic_const_item() || !arg->basic_const_item() || arg->type() != type())
|
|
|
|
return FALSE;
|
|
|
|
/*
|
|
|
|
We need to cast off const to call val_int(). This should be OK for
|
|
|
|
a basic constant.
|
|
|
|
*/
|
|
|
|
item= (Item*) arg;
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case NULL_VALUE:
|
|
|
|
return TRUE;
|
|
|
|
case INT_VALUE:
|
|
|
|
return value.integer == item->val_int() &&
|
|
|
|
unsigned_flag == item->unsigned_flag;
|
|
|
|
case REAL_VALUE:
|
2005-05-04 16:53:10 +04:00
|
|
|
return value.real == item->val_real();
|
2005-05-03 12:47:27 +04:00
|
|
|
case STRING_VALUE:
|
|
|
|
case LONG_DATA_VALUE:
|
|
|
|
if (binary_cmp)
|
|
|
|
return !stringcmp(&str_value, &item->str_value);
|
|
|
|
return !sortcmp(&str_value, &item->str_value, collation.collation);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2002-06-12 14:13:12 -07:00
|
|
|
/* End of Item_param related */
|
|
|
|
|
2008-02-22 13:30:33 +03:00
|
|
|
void Item_param::print(String *str, enum_query_type query_type)
|
2004-09-04 15:02:57 +03:00
|
|
|
{
|
|
|
|
if (state == NO_VALUE)
|
|
|
|
{
|
|
|
|
str->append('?');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-02-09 02:50:45 +04:00
|
|
|
char buffer[STRING_BUFFER_USUAL_SIZE];
|
2004-09-04 15:02:57 +03:00
|
|
|
String tmp(buffer, sizeof(buffer), &my_charset_bin);
|
|
|
|
const String *res;
|
Bug#12601974 - STORED PROCEDURE SQL_MODE=NO_BACKSLASH_ESCAPES IGNORED AND BREAKS REPLICATION
Analysis:
========================
sql_mode "NO_BACKSLASH_ESCAPES": When user want to use backslash as character input,
instead of escape character in a string literal then sql_mode can be set to
"NO_BACKSLASH_ESCAPES". With this mode enabled, backslash becomes an ordinary
character like any other.
SQL_MODE set applies to the current client session. And while creating the stored
procedure, MySQL stores the current sql_mode and always executes the stored
procedure in sql_mode stored with the Procedure, regardless of the server SQL
mode in effect when the routine is invoked.
In the scenario (for which bug is reported), the routine is created with
sql_mode=NO_BACKSLASH_ESCAPES. And routine is executed with the invoker sql_mode
is "" (NOT SET) by executing statement "call testp('Axel\'s')".
Since invoker sql_mode is "" (NOT_SET), the '\' in 'Axel\'s'(argument to function)
is considered as escape character and column "a" (of table "t1") values are
updated with "Axel's". The binary log generated for above update operation is as below,
set sql_mode=XXXXXX (for no_backslash_escapes)
update test.t1 set a= NAME_CONST('var',_latin1'Axel\'s' COLLATE 'latin1_swedish_ci');
While logging stored procedure statements, the local variables (params) used in
statements are replaced with the NAME_CONST(var_name, var_value) (Internal function)
(http://dev.mysql.com/doc/refman/5.6/en/miscellaneous-functions.html#function_name-const)
On slave, these logs are applied. NAME_CONST is parsed to get the variable and its
value. Since, stored procedure is created with sql_mode="NO_BACKSLASH_ESCAPES", the sql_mode
is also logged in. So that at slave this sql_mode is set before executing the statements
of routine. So at slave, sql_mode is set to "NO_BACKSLASH_ESCAPES" and then while
parsing NAME_CONST of string variable, '\' is considered as NON ESCAPE character
and parsing reported error for "'" (as we have only one "'" no backslash).
At slave, parsing was proper with sql_mode "NO_BACKSLASH_ESCAPES".
But above error reported while writing bin log, "'" (of Axel's) is escaped with
"\" character. Actually, all special characters (n, r, ', ", \, 0...) are escaped
while writing NAME_CONST for string variable(param, local variable) in bin log
Airrespective of "NO_BACKSLASH_ESCAPES" sql_mode. So, basically, the problem is
that logging string parameter does not take into account sql_mode value.
Fix:
========================
So when sql_mode is set to "NO_BACKSLASH_ESCAPES", escaping characters as
(n, r, ', ", \, 0...) should be avoided. To do so, added a check to not to
escape such characters while writing NAME_CONST for string variables in bin
log.
And when sql_mode is set to NO_BACKSLASH_ESCAPES, quote character "'" is
represented as ''.
http://dev.mysql.com/doc/refman/5.6/en/string-literals.html (There are several
ways to include quote characters within a string: )
2012-02-29 12:23:15 +05:30
|
|
|
res= query_val_str(current_thd, &tmp);
|
2004-09-04 15:02:57 +03:00
|
|
|
str->append(*res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-08 20:01:20 +04:00
|
|
|
/**
|
|
|
|
Preserve the original parameter types and values
|
|
|
|
when re-preparing a prepared statement.
|
|
|
|
|
2008-05-18 01:51:18 +04:00
|
|
|
@details Copy parameter type information and conversion
|
|
|
|
function pointers from a parameter of the old statement
|
|
|
|
to the corresponding parameter of the new one.
|
2008-04-08 20:01:20 +04:00
|
|
|
|
|
|
|
Move parameter values from the old parameters to the new
|
|
|
|
one. We simply "exchange" the values, which allows
|
|
|
|
to save on allocation and character set conversion in
|
|
|
|
case a parameter is a string or a blob/clob.
|
|
|
|
|
2008-05-18 01:51:18 +04:00
|
|
|
The old parameter gets the value of this one, which
|
|
|
|
ensures that all memory of this parameter is freed
|
|
|
|
correctly.
|
|
|
|
|
2008-04-08 20:01:20 +04:00
|
|
|
@param[in] src parameter item of the original
|
|
|
|
prepared statement
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
Item_param::set_param_type_and_swap_value(Item_param *src)
|
|
|
|
{
|
|
|
|
unsigned_flag= src->unsigned_flag;
|
|
|
|
param_type= src->param_type;
|
|
|
|
set_param_func= src->set_param_func;
|
|
|
|
item_type= src->item_type;
|
|
|
|
item_result_type= src->item_result_type;
|
|
|
|
|
2008-05-18 01:51:18 +04:00
|
|
|
collation.set(src->collation);
|
2008-04-08 20:01:20 +04:00
|
|
|
maybe_null= src->maybe_null;
|
|
|
|
null_value= src->null_value;
|
|
|
|
max_length= src->max_length;
|
|
|
|
decimals= src->decimals;
|
|
|
|
state= src->state;
|
|
|
|
value= src->value;
|
|
|
|
|
|
|
|
decimal_value.swap(src->decimal_value);
|
|
|
|
str_value.swap(src->str_value);
|
|
|
|
str_value_ptr.swap(src->str_value_ptr);
|
|
|
|
}
|
|
|
|
|
Backport of revno 2630.28.10, 2630.28.31, 2630.28.26, 2630.33.1,
2630.39.1, 2630.28.29, 2630.34.3, 2630.34.2, 2630.34.1, 2630.29.29,
2630.29.28, 2630.31.1, 2630.28.13, 2630.28.10, 2617.23.14 and
some other minor revisions.
This patch implements:
WL#4264 "Backup: Stabilize Service Interface" -- all the
server prerequisites except si_objects.{h,cc} themselves (they can
be just copied over, when needed).
WL#4435: Support OUT-parameters in prepared statements.
(and all issues in the initial patches for these two
tasks, that were discovered in pushbuild and during testing).
Bug#39519: mysql_stmt_close() should flush all data
associated with the statement.
After execution of a prepared statement, send OUT parameters of the invoked
stored procedure, if any, to the client.
When using the binary protocol, send the parameters in an additional result
set over the wire. When using the text protocol, assign out parameters to
the user variables from the CALL(@var1, @var2, ...) specification.
The following refactoring has been made:
- Protocol::send_fields() was renamed to Protocol::send_result_set_metadata();
- A new Protocol::send_result_set_row() was introduced to incapsulate
common functionality for sending row data.
- Signature of Protocol::prepare_for_send() was changed: this operation
does not need a list of items, the number of items is fully sufficient.
The following backward incompatible changes have been made:
- CLIENT_MULTI_RESULTS is now enabled by default in the client;
- CLIENT_PS_MULTI_RESUTLS is now enabled by default in the client.
2009-10-22 00:02:06 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
This operation is intended to store some item value in Item_param to be
|
|
|
|
used later.
|
|
|
|
|
|
|
|
@param thd thread context
|
|
|
|
@param ctx stored procedure runtime context
|
|
|
|
@param it a pointer to an item in the tree
|
|
|
|
|
|
|
|
@return Error status
|
|
|
|
@retval TRUE on error
|
|
|
|
@retval FALSE on success
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool
|
|
|
|
Item_param::set_value(THD *thd, sp_rcontext *ctx, Item **it)
|
|
|
|
{
|
2010-05-31 12:59:58 +02:00
|
|
|
Item *arg= *it;
|
Backport of revno 2630.28.10, 2630.28.31, 2630.28.26, 2630.33.1,
2630.39.1, 2630.28.29, 2630.34.3, 2630.34.2, 2630.34.1, 2630.29.29,
2630.29.28, 2630.31.1, 2630.28.13, 2630.28.10, 2617.23.14 and
some other minor revisions.
This patch implements:
WL#4264 "Backup: Stabilize Service Interface" -- all the
server prerequisites except si_objects.{h,cc} themselves (they can
be just copied over, when needed).
WL#4435: Support OUT-parameters in prepared statements.
(and all issues in the initial patches for these two
tasks, that were discovered in pushbuild and during testing).
Bug#39519: mysql_stmt_close() should flush all data
associated with the statement.
After execution of a prepared statement, send OUT parameters of the invoked
stored procedure, if any, to the client.
When using the binary protocol, send the parameters in an additional result
set over the wire. When using the text protocol, assign out parameters to
the user variables from the CALL(@var1, @var2, ...) specification.
The following refactoring has been made:
- Protocol::send_fields() was renamed to Protocol::send_result_set_metadata();
- A new Protocol::send_result_set_row() was introduced to incapsulate
common functionality for sending row data.
- Signature of Protocol::prepare_for_send() was changed: this operation
does not need a list of items, the number of items is fully sufficient.
The following backward incompatible changes have been made:
- CLIENT_MULTI_RESULTS is now enabled by default in the client;
- CLIENT_PS_MULTI_RESUTLS is now enabled by default in the client.
2009-10-22 00:02:06 +04:00
|
|
|
|
2010-05-31 12:59:58 +02:00
|
|
|
if (arg->is_null())
|
Backport of revno 2630.28.10, 2630.28.31, 2630.28.26, 2630.33.1,
2630.39.1, 2630.28.29, 2630.34.3, 2630.34.2, 2630.34.1, 2630.29.29,
2630.29.28, 2630.31.1, 2630.28.13, 2630.28.10, 2617.23.14 and
some other minor revisions.
This patch implements:
WL#4264 "Backup: Stabilize Service Interface" -- all the
server prerequisites except si_objects.{h,cc} themselves (they can
be just copied over, when needed).
WL#4435: Support OUT-parameters in prepared statements.
(and all issues in the initial patches for these two
tasks, that were discovered in pushbuild and during testing).
Bug#39519: mysql_stmt_close() should flush all data
associated with the statement.
After execution of a prepared statement, send OUT parameters of the invoked
stored procedure, if any, to the client.
When using the binary protocol, send the parameters in an additional result
set over the wire. When using the text protocol, assign out parameters to
the user variables from the CALL(@var1, @var2, ...) specification.
The following refactoring has been made:
- Protocol::send_fields() was renamed to Protocol::send_result_set_metadata();
- A new Protocol::send_result_set_row() was introduced to incapsulate
common functionality for sending row data.
- Signature of Protocol::prepare_for_send() was changed: this operation
does not need a list of items, the number of items is fully sufficient.
The following backward incompatible changes have been made:
- CLIENT_MULTI_RESULTS is now enabled by default in the client;
- CLIENT_PS_MULTI_RESUTLS is now enabled by default in the client.
2009-10-22 00:02:06 +04:00
|
|
|
{
|
|
|
|
set_null();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
null_value= FALSE;
|
|
|
|
|
2010-05-31 12:59:58 +02:00
|
|
|
switch (arg->result_type()) {
|
Backport of revno 2630.28.10, 2630.28.31, 2630.28.26, 2630.33.1,
2630.39.1, 2630.28.29, 2630.34.3, 2630.34.2, 2630.34.1, 2630.29.29,
2630.29.28, 2630.31.1, 2630.28.13, 2630.28.10, 2617.23.14 and
some other minor revisions.
This patch implements:
WL#4264 "Backup: Stabilize Service Interface" -- all the
server prerequisites except si_objects.{h,cc} themselves (they can
be just copied over, when needed).
WL#4435: Support OUT-parameters in prepared statements.
(and all issues in the initial patches for these two
tasks, that were discovered in pushbuild and during testing).
Bug#39519: mysql_stmt_close() should flush all data
associated with the statement.
After execution of a prepared statement, send OUT parameters of the invoked
stored procedure, if any, to the client.
When using the binary protocol, send the parameters in an additional result
set over the wire. When using the text protocol, assign out parameters to
the user variables from the CALL(@var1, @var2, ...) specification.
The following refactoring has been made:
- Protocol::send_fields() was renamed to Protocol::send_result_set_metadata();
- A new Protocol::send_result_set_row() was introduced to incapsulate
common functionality for sending row data.
- Signature of Protocol::prepare_for_send() was changed: this operation
does not need a list of items, the number of items is fully sufficient.
The following backward incompatible changes have been made:
- CLIENT_MULTI_RESULTS is now enabled by default in the client;
- CLIENT_PS_MULTI_RESUTLS is now enabled by default in the client.
2009-10-22 00:02:06 +04:00
|
|
|
case STRING_RESULT:
|
|
|
|
{
|
|
|
|
char str_buffer[STRING_BUFFER_USUAL_SIZE];
|
|
|
|
String sv_buffer(str_buffer, sizeof(str_buffer), &my_charset_bin);
|
2010-05-31 12:59:58 +02:00
|
|
|
String *sv= arg->val_str(&sv_buffer);
|
Backport of revno 2630.28.10, 2630.28.31, 2630.28.26, 2630.33.1,
2630.39.1, 2630.28.29, 2630.34.3, 2630.34.2, 2630.34.1, 2630.29.29,
2630.29.28, 2630.31.1, 2630.28.13, 2630.28.10, 2617.23.14 and
some other minor revisions.
This patch implements:
WL#4264 "Backup: Stabilize Service Interface" -- all the
server prerequisites except si_objects.{h,cc} themselves (they can
be just copied over, when needed).
WL#4435: Support OUT-parameters in prepared statements.
(and all issues in the initial patches for these two
tasks, that were discovered in pushbuild and during testing).
Bug#39519: mysql_stmt_close() should flush all data
associated with the statement.
After execution of a prepared statement, send OUT parameters of the invoked
stored procedure, if any, to the client.
When using the binary protocol, send the parameters in an additional result
set over the wire. When using the text protocol, assign out parameters to
the user variables from the CALL(@var1, @var2, ...) specification.
The following refactoring has been made:
- Protocol::send_fields() was renamed to Protocol::send_result_set_metadata();
- A new Protocol::send_result_set_row() was introduced to incapsulate
common functionality for sending row data.
- Signature of Protocol::prepare_for_send() was changed: this operation
does not need a list of items, the number of items is fully sufficient.
The following backward incompatible changes have been made:
- CLIENT_MULTI_RESULTS is now enabled by default in the client;
- CLIENT_PS_MULTI_RESUTLS is now enabled by default in the client.
2009-10-22 00:02:06 +04:00
|
|
|
|
|
|
|
if (!sv)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
set_str(sv->c_ptr_safe(), sv->length());
|
|
|
|
str_value_ptr.set(str_value.ptr(),
|
|
|
|
str_value.length(),
|
|
|
|
str_value.charset());
|
|
|
|
collation.set(str_value.charset(), DERIVATION_COERCIBLE);
|
|
|
|
decimals= 0;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case REAL_RESULT:
|
2010-05-31 12:59:58 +02:00
|
|
|
set_double(arg->val_real());
|
Backport of revno 2630.28.10, 2630.28.31, 2630.28.26, 2630.33.1,
2630.39.1, 2630.28.29, 2630.34.3, 2630.34.2, 2630.34.1, 2630.29.29,
2630.29.28, 2630.31.1, 2630.28.13, 2630.28.10, 2617.23.14 and
some other minor revisions.
This patch implements:
WL#4264 "Backup: Stabilize Service Interface" -- all the
server prerequisites except si_objects.{h,cc} themselves (they can
be just copied over, when needed).
WL#4435: Support OUT-parameters in prepared statements.
(and all issues in the initial patches for these two
tasks, that were discovered in pushbuild and during testing).
Bug#39519: mysql_stmt_close() should flush all data
associated with the statement.
After execution of a prepared statement, send OUT parameters of the invoked
stored procedure, if any, to the client.
When using the binary protocol, send the parameters in an additional result
set over the wire. When using the text protocol, assign out parameters to
the user variables from the CALL(@var1, @var2, ...) specification.
The following refactoring has been made:
- Protocol::send_fields() was renamed to Protocol::send_result_set_metadata();
- A new Protocol::send_result_set_row() was introduced to incapsulate
common functionality for sending row data.
- Signature of Protocol::prepare_for_send() was changed: this operation
does not need a list of items, the number of items is fully sufficient.
The following backward incompatible changes have been made:
- CLIENT_MULTI_RESULTS is now enabled by default in the client;
- CLIENT_PS_MULTI_RESUTLS is now enabled by default in the client.
2009-10-22 00:02:06 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case INT_RESULT:
|
2010-05-31 12:59:58 +02:00
|
|
|
set_int(arg->val_int(), arg->max_length);
|
Backport of revno 2630.28.10, 2630.28.31, 2630.28.26, 2630.33.1,
2630.39.1, 2630.28.29, 2630.34.3, 2630.34.2, 2630.34.1, 2630.29.29,
2630.29.28, 2630.31.1, 2630.28.13, 2630.28.10, 2617.23.14 and
some other minor revisions.
This patch implements:
WL#4264 "Backup: Stabilize Service Interface" -- all the
server prerequisites except si_objects.{h,cc} themselves (they can
be just copied over, when needed).
WL#4435: Support OUT-parameters in prepared statements.
(and all issues in the initial patches for these two
tasks, that were discovered in pushbuild and during testing).
Bug#39519: mysql_stmt_close() should flush all data
associated with the statement.
After execution of a prepared statement, send OUT parameters of the invoked
stored procedure, if any, to the client.
When using the binary protocol, send the parameters in an additional result
set over the wire. When using the text protocol, assign out parameters to
the user variables from the CALL(@var1, @var2, ...) specification.
The following refactoring has been made:
- Protocol::send_fields() was renamed to Protocol::send_result_set_metadata();
- A new Protocol::send_result_set_row() was introduced to incapsulate
common functionality for sending row data.
- Signature of Protocol::prepare_for_send() was changed: this operation
does not need a list of items, the number of items is fully sufficient.
The following backward incompatible changes have been made:
- CLIENT_MULTI_RESULTS is now enabled by default in the client;
- CLIENT_PS_MULTI_RESUTLS is now enabled by default in the client.
2009-10-22 00:02:06 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DECIMAL_RESULT:
|
|
|
|
{
|
|
|
|
my_decimal dv_buf;
|
2010-05-31 12:59:58 +02:00
|
|
|
my_decimal *dv= arg->val_decimal(&dv_buf);
|
Backport of revno 2630.28.10, 2630.28.31, 2630.28.26, 2630.33.1,
2630.39.1, 2630.28.29, 2630.34.3, 2630.34.2, 2630.34.1, 2630.29.29,
2630.29.28, 2630.31.1, 2630.28.13, 2630.28.10, 2617.23.14 and
some other minor revisions.
This patch implements:
WL#4264 "Backup: Stabilize Service Interface" -- all the
server prerequisites except si_objects.{h,cc} themselves (they can
be just copied over, when needed).
WL#4435: Support OUT-parameters in prepared statements.
(and all issues in the initial patches for these two
tasks, that were discovered in pushbuild and during testing).
Bug#39519: mysql_stmt_close() should flush all data
associated with the statement.
After execution of a prepared statement, send OUT parameters of the invoked
stored procedure, if any, to the client.
When using the binary protocol, send the parameters in an additional result
set over the wire. When using the text protocol, assign out parameters to
the user variables from the CALL(@var1, @var2, ...) specification.
The following refactoring has been made:
- Protocol::send_fields() was renamed to Protocol::send_result_set_metadata();
- A new Protocol::send_result_set_row() was introduced to incapsulate
common functionality for sending row data.
- Signature of Protocol::prepare_for_send() was changed: this operation
does not need a list of items, the number of items is fully sufficient.
The following backward incompatible changes have been made:
- CLIENT_MULTI_RESULTS is now enabled by default in the client;
- CLIENT_PS_MULTI_RESUTLS is now enabled by default in the client.
2009-10-22 00:02:06 +04:00
|
|
|
|
|
|
|
if (!dv)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
set_decimal(dv);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* That can not happen. */
|
|
|
|
|
|
|
|
DBUG_ASSERT(TRUE); // Abort in debug mode.
|
|
|
|
|
|
|
|
set_null(); // Set to NULL in release mode.
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-05-31 12:59:58 +02:00
|
|
|
item_result_type= arg->result_type();
|
|
|
|
item_type= arg->type();
|
Backport of revno 2630.28.10, 2630.28.31, 2630.28.26, 2630.33.1,
2630.39.1, 2630.28.29, 2630.34.3, 2630.34.2, 2630.34.1, 2630.29.29,
2630.29.28, 2630.31.1, 2630.28.13, 2630.28.10, 2617.23.14 and
some other minor revisions.
This patch implements:
WL#4264 "Backup: Stabilize Service Interface" -- all the
server prerequisites except si_objects.{h,cc} themselves (they can
be just copied over, when needed).
WL#4435: Support OUT-parameters in prepared statements.
(and all issues in the initial patches for these two
tasks, that were discovered in pushbuild and during testing).
Bug#39519: mysql_stmt_close() should flush all data
associated with the statement.
After execution of a prepared statement, send OUT parameters of the invoked
stored procedure, if any, to the client.
When using the binary protocol, send the parameters in an additional result
set over the wire. When using the text protocol, assign out parameters to
the user variables from the CALL(@var1, @var2, ...) specification.
The following refactoring has been made:
- Protocol::send_fields() was renamed to Protocol::send_result_set_metadata();
- A new Protocol::send_result_set_row() was introduced to incapsulate
common functionality for sending row data.
- Signature of Protocol::prepare_for_send() was changed: this operation
does not need a list of items, the number of items is fully sufficient.
The following backward incompatible changes have been made:
- CLIENT_MULTI_RESULTS is now enabled by default in the client;
- CLIENT_PS_MULTI_RESUTLS is now enabled by default in the client.
2009-10-22 00:02:06 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Setter of Item_param::m_out_param_info.
|
|
|
|
|
|
|
|
m_out_param_info is used to store information about store routine
|
|
|
|
OUT-parameters, such as stored routine name, database, stored routine
|
|
|
|
variable name. It is supposed to be set in sp_head::execute() after
|
|
|
|
Item_param::set_value() is called.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
Item_param::set_out_param_info(Send_field *info)
|
|
|
|
{
|
|
|
|
m_out_param_info= info;
|
Fix for Bug#56934 (mysql_stmt_fetch() incorrectly fills MYSQL_TIME
structure buffer).
This is a follow-up for WL#4435. The bug actually existed not only
MYSQL_TYPE_DATETIME type. The problem was that Item_param::set_value()
was written in an assumption that it's working with expressions, i.e.
with basic data types.
There are two different quick fixes here:
a) Change Item_param::make_field() -- remove setting of
Send_field::length, Send_field::charsetnr, Send_field::flags and
Send_field::type.
That would lead to marshalling all data using basic types to the client
(MYSQL_TYPE_LONGLONG, MYSQL_TYPE_DOUBLE, MYSQL_TYPE_STRING and
MYSQL_TYPE_NEWDECIMAL). In particular, that means, DATETIME would be
sent as MYSQL_TYPE_STRING, TINYINT -- as MYSQL_TYPE_LONGLONG, etc.
That could be Ok for the client, because the client library does
reverse conversion automatically (the client program would see DATETIME
as MYSQL_TIME object). However, there is a problem with metadata --
the metadata would be wrong (misleading): it would say that DATETIME is
marshaled as MYSQL_TYPE_DATETIME, not as MYSQL_TYPE_STRING.
b) Set Item_param::param_type properly to actual underlying field type.
That would lead to double conversion inside the server: for example,
MYSQL_TIME-object would be converted into STRING-object
(in Item_param::set_value()), and then converted back to MYSQL_TIME-object
(in Item_param::send()).
The data however would be marshalled more properly, and also metadata would
be correct.
This patch implements b).
There is also a possibility to avoid double conversion either by clonning
the data field, or by storing a reference to it and using it on Item::send()
time. That requires more work and might be done later.
2010-11-13 18:05:02 +03:00
|
|
|
param_type= m_out_param_info->type;
|
Backport of revno 2630.28.10, 2630.28.31, 2630.28.26, 2630.33.1,
2630.39.1, 2630.28.29, 2630.34.3, 2630.34.2, 2630.34.1, 2630.29.29,
2630.29.28, 2630.31.1, 2630.28.13, 2630.28.10, 2617.23.14 and
some other minor revisions.
This patch implements:
WL#4264 "Backup: Stabilize Service Interface" -- all the
server prerequisites except si_objects.{h,cc} themselves (they can
be just copied over, when needed).
WL#4435: Support OUT-parameters in prepared statements.
(and all issues in the initial patches for these two
tasks, that were discovered in pushbuild and during testing).
Bug#39519: mysql_stmt_close() should flush all data
associated with the statement.
After execution of a prepared statement, send OUT parameters of the invoked
stored procedure, if any, to the client.
When using the binary protocol, send the parameters in an additional result
set over the wire. When using the text protocol, assign out parameters to
the user variables from the CALL(@var1, @var2, ...) specification.
The following refactoring has been made:
- Protocol::send_fields() was renamed to Protocol::send_result_set_metadata();
- A new Protocol::send_result_set_row() was introduced to incapsulate
common functionality for sending row data.
- Signature of Protocol::prepare_for_send() was changed: this operation
does not need a list of items, the number of items is fully sufficient.
The following backward incompatible changes have been made:
- CLIENT_MULTI_RESULTS is now enabled by default in the client;
- CLIENT_PS_MULTI_RESUTLS is now enabled by default in the client.
2009-10-22 00:02:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Getter of Item_param::m_out_param_info.
|
|
|
|
|
|
|
|
m_out_param_info is used to store information about store routine
|
|
|
|
OUT-parameters, such as stored routine name, database, stored routine
|
|
|
|
variable name. It is supposed to be retrieved in
|
|
|
|
Protocol_binary::send_out_parameters() during creation of OUT-parameter
|
|
|
|
result set.
|
|
|
|
*/
|
|
|
|
|
|
|
|
const Send_field *
|
|
|
|
Item_param::get_out_param_info() const
|
|
|
|
{
|
|
|
|
return m_out_param_info;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Fill meta-data information for the corresponding column in a result set.
|
|
|
|
If this is an OUT-parameter of a stored procedure, preserve meta-data of
|
|
|
|
stored-routine variable.
|
|
|
|
|
|
|
|
@param field container for meta-data to be filled
|
|
|
|
*/
|
|
|
|
|
|
|
|
void Item_param::make_field(Send_field *field)
|
|
|
|
{
|
|
|
|
Item::make_field(field);
|
|
|
|
|
|
|
|
if (!m_out_param_info)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
This is an OUT-parameter of stored procedure. We should use
|
|
|
|
OUT-parameter info to fill out the names.
|
|
|
|
*/
|
|
|
|
|
|
|
|
field->db_name= m_out_param_info->db_name;
|
|
|
|
field->table_name= m_out_param_info->table_name;
|
|
|
|
field->org_table_name= m_out_param_info->org_table_name;
|
|
|
|
field->col_name= m_out_param_info->col_name;
|
|
|
|
field->org_col_name= m_out_param_info->org_col_name;
|
Fix for Bug#56934 (mysql_stmt_fetch() incorrectly fills MYSQL_TIME
structure buffer).
This is a follow-up for WL#4435. The bug actually existed not only
MYSQL_TYPE_DATETIME type. The problem was that Item_param::set_value()
was written in an assumption that it's working with expressions, i.e.
with basic data types.
There are two different quick fixes here:
a) Change Item_param::make_field() -- remove setting of
Send_field::length, Send_field::charsetnr, Send_field::flags and
Send_field::type.
That would lead to marshalling all data using basic types to the client
(MYSQL_TYPE_LONGLONG, MYSQL_TYPE_DOUBLE, MYSQL_TYPE_STRING and
MYSQL_TYPE_NEWDECIMAL). In particular, that means, DATETIME would be
sent as MYSQL_TYPE_STRING, TINYINT -- as MYSQL_TYPE_LONGLONG, etc.
That could be Ok for the client, because the client library does
reverse conversion automatically (the client program would see DATETIME
as MYSQL_TIME object). However, there is a problem with metadata --
the metadata would be wrong (misleading): it would say that DATETIME is
marshaled as MYSQL_TYPE_DATETIME, not as MYSQL_TYPE_STRING.
b) Set Item_param::param_type properly to actual underlying field type.
That would lead to double conversion inside the server: for example,
MYSQL_TIME-object would be converted into STRING-object
(in Item_param::set_value()), and then converted back to MYSQL_TIME-object
(in Item_param::send()).
The data however would be marshalled more properly, and also metadata would
be correct.
This patch implements b).
There is also a possibility to avoid double conversion either by clonning
the data field, or by storing a reference to it and using it on Item::send()
time. That requires more work and might be done later.
2010-11-13 18:05:02 +03:00
|
|
|
|
Backport of revno 2630.28.10, 2630.28.31, 2630.28.26, 2630.33.1,
2630.39.1, 2630.28.29, 2630.34.3, 2630.34.2, 2630.34.1, 2630.29.29,
2630.29.28, 2630.31.1, 2630.28.13, 2630.28.10, 2617.23.14 and
some other minor revisions.
This patch implements:
WL#4264 "Backup: Stabilize Service Interface" -- all the
server prerequisites except si_objects.{h,cc} themselves (they can
be just copied over, when needed).
WL#4435: Support OUT-parameters in prepared statements.
(and all issues in the initial patches for these two
tasks, that were discovered in pushbuild and during testing).
Bug#39519: mysql_stmt_close() should flush all data
associated with the statement.
After execution of a prepared statement, send OUT parameters of the invoked
stored procedure, if any, to the client.
When using the binary protocol, send the parameters in an additional result
set over the wire. When using the text protocol, assign out parameters to
the user variables from the CALL(@var1, @var2, ...) specification.
The following refactoring has been made:
- Protocol::send_fields() was renamed to Protocol::send_result_set_metadata();
- A new Protocol::send_result_set_row() was introduced to incapsulate
common functionality for sending row data.
- Signature of Protocol::prepare_for_send() was changed: this operation
does not need a list of items, the number of items is fully sufficient.
The following backward incompatible changes have been made:
- CLIENT_MULTI_RESULTS is now enabled by default in the client;
- CLIENT_PS_MULTI_RESUTLS is now enabled by default in the client.
2009-10-22 00:02:06 +04:00
|
|
|
field->length= m_out_param_info->length;
|
|
|
|
field->charsetnr= m_out_param_info->charsetnr;
|
|
|
|
field->flags= m_out_param_info->flags;
|
|
|
|
field->decimals= m_out_param_info->decimals;
|
|
|
|
field->type= m_out_param_info->type;
|
|
|
|
}
|
|
|
|
|
2009-05-25 11:00:40 +03:00
|
|
|
/****************************************************************************
|
|
|
|
Item_copy
|
|
|
|
****************************************************************************/
|
|
|
|
Item_copy *Item_copy::create (Item *item)
|
|
|
|
{
|
|
|
|
switch (item->result_type())
|
|
|
|
{
|
|
|
|
case STRING_RESULT:
|
|
|
|
return new Item_copy_string (item);
|
|
|
|
case REAL_RESULT:
|
|
|
|
return new Item_copy_float (item);
|
|
|
|
case INT_RESULT:
|
|
|
|
return item->unsigned_flag ?
|
|
|
|
new Item_copy_uint (item) : new Item_copy_int (item);
|
|
|
|
case DECIMAL_RESULT:
|
|
|
|
return new Item_copy_decimal (item);
|
2009-08-28 12:06:59 -03:00
|
|
|
default:
|
2009-05-25 11:00:40 +03:00
|
|
|
DBUG_ASSERT (0);
|
|
|
|
}
|
|
|
|
/* should not happen */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2004-09-04 15:02:57 +03:00
|
|
|
/****************************************************************************
|
|
|
|
Item_copy_string
|
|
|
|
****************************************************************************/
|
2002-10-02 13:33:08 +03:00
|
|
|
|
2009-05-25 11:00:40 +03:00
|
|
|
double Item_copy_string::val_real()
|
|
|
|
{
|
|
|
|
int err_not_used;
|
|
|
|
char *end_not_used;
|
|
|
|
return (null_value ? 0.0 :
|
|
|
|
my_strntod(str_value.charset(), (char*) str_value.ptr(),
|
|
|
|
str_value.length(), &end_not_used, &err_not_used));
|
|
|
|
}
|
|
|
|
|
|
|
|
longlong Item_copy_string::val_int()
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
return null_value ? LL(0) : my_strntoll(str_value.charset(),str_value.ptr(),
|
|
|
|
str_value.length(),10, (char**) 0,
|
|
|
|
&err);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Item_copy_string::save_in_field(Field *field, bool no_conversions)
|
|
|
|
{
|
|
|
|
return save_str_value_in_field(field, &str_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
void Item_copy_string::copy()
|
|
|
|
{
|
|
|
|
String *res=item->val_str(&str_value);
|
|
|
|
if (res && res != &str_value)
|
|
|
|
str_value.copy(*res);
|
|
|
|
null_value=item->null_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
String *Item_copy_string::val_str(String *str)
|
|
|
|
{
|
2004-03-18 15:14:36 +02:00
|
|
|
// Item_copy_string is used without fix_fields call
|
2000-07-31 21:29:14 +02:00
|
|
|
if (null_value)
|
|
|
|
return (String*) 0;
|
|
|
|
return &str_value;
|
|
|
|
}
|
|
|
|
|
2004-03-25 22:11:22 +02:00
|
|
|
|
2005-02-09 02:50:45 +04:00
|
|
|
my_decimal *Item_copy_string::val_decimal(my_decimal *decimal_value)
|
|
|
|
{
|
|
|
|
// Item_copy_string is used without fix_fields call
|
|
|
|
if (null_value)
|
2009-05-25 11:00:40 +03:00
|
|
|
return (my_decimal *) 0;
|
2005-02-09 02:50:45 +04:00
|
|
|
string2my_decimal(E_DEC_FATAL_ERROR, &str_value, decimal_value);
|
|
|
|
return (decimal_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-25 11:00:40 +03:00
|
|
|
/****************************************************************************
|
|
|
|
Item_copy_int
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void Item_copy_int::copy()
|
|
|
|
{
|
|
|
|
cached_value= item->val_int();
|
|
|
|
null_value=item->null_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int save_int_value_in_field (Field *field, longlong nr,
|
|
|
|
bool null_value, bool unsigned_flag);
|
|
|
|
|
|
|
|
int Item_copy_int::save_in_field(Field *field, bool no_conversions)
|
|
|
|
{
|
|
|
|
return save_int_value_in_field(field, cached_value,
|
|
|
|
null_value, unsigned_flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String *Item_copy_int::val_str(String *str)
|
|
|
|
{
|
|
|
|
if (null_value)
|
|
|
|
return (String *) 0;
|
|
|
|
|
|
|
|
str->set(cached_value, &my_charset_bin);
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
my_decimal *Item_copy_int::val_decimal(my_decimal *decimal_value)
|
|
|
|
{
|
|
|
|
if (null_value)
|
|
|
|
return (my_decimal *) 0;
|
|
|
|
|
|
|
|
int2my_decimal(E_DEC_FATAL_ERROR, cached_value, unsigned_flag, decimal_value);
|
|
|
|
return decimal_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
Item_copy_uint
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
String *Item_copy_uint::val_str(String *str)
|
|
|
|
{
|
|
|
|
if (null_value)
|
|
|
|
return (String *) 0;
|
|
|
|
|
|
|
|
str->set((ulonglong) cached_value, &my_charset_bin);
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
Item_copy_float
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
String *Item_copy_float::val_str(String *str)
|
|
|
|
{
|
|
|
|
if (null_value)
|
|
|
|
return (String *) 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
double nr= val_real();
|
|
|
|
str->set_real(nr,decimals, &my_charset_bin);
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
my_decimal *Item_copy_float::val_decimal(my_decimal *decimal_value)
|
|
|
|
{
|
|
|
|
if (null_value)
|
|
|
|
return (my_decimal *) 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
double nr= val_real();
|
|
|
|
double2my_decimal(E_DEC_FATAL_ERROR, nr, decimal_value);
|
|
|
|
return decimal_value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Item_copy_float::save_in_field(Field *field, bool no_conversions)
|
|
|
|
{
|
|
|
|
if (null_value)
|
|
|
|
return set_field_to_null(field);
|
|
|
|
field->set_notnull();
|
|
|
|
return field->store(cached_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
Item_copy_decimal
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int Item_copy_decimal::save_in_field(Field *field, bool no_conversions)
|
|
|
|
{
|
|
|
|
if (null_value)
|
|
|
|
return set_field_to_null(field);
|
|
|
|
field->set_notnull();
|
|
|
|
return field->store_decimal(&cached_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String *Item_copy_decimal::val_str(String *result)
|
|
|
|
{
|
|
|
|
if (null_value)
|
|
|
|
return (String *) 0;
|
|
|
|
result->set_charset(&my_charset_bin);
|
|
|
|
my_decimal2string(E_DEC_FATAL_ERROR, &cached_value, 0, 0, 0, result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double Item_copy_decimal::val_real()
|
|
|
|
{
|
|
|
|
if (null_value)
|
|
|
|
return 0.0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
double result;
|
|
|
|
my_decimal2double(E_DEC_FATAL_ERROR, &cached_value, &result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
longlong Item_copy_decimal::val_int()
|
|
|
|
{
|
|
|
|
if (null_value)
|
|
|
|
return LL(0);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
longlong result;
|
|
|
|
my_decimal2int(E_DEC_FATAL_ERROR, &cached_value, unsigned_flag, &result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Item_copy_decimal::copy()
|
|
|
|
{
|
|
|
|
my_decimal *nr= item->val_decimal(&cached_value);
|
|
|
|
if (nr && nr != &cached_value)
|
2010-04-02 01:35:36 +05:30
|
|
|
my_decimal2decimal (nr, &cached_value);
|
2009-05-25 11:00:40 +03:00
|
|
|
null_value= item->null_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
/*
|
Backport of revno 2630.28.10, 2630.28.31, 2630.28.26, 2630.33.1,
2630.39.1, 2630.28.29, 2630.34.3, 2630.34.2, 2630.34.1, 2630.29.29,
2630.29.28, 2630.31.1, 2630.28.13, 2630.28.10, 2617.23.14 and
some other minor revisions.
This patch implements:
WL#4264 "Backup: Stabilize Service Interface" -- all the
server prerequisites except si_objects.{h,cc} themselves (they can
be just copied over, when needed).
WL#4435: Support OUT-parameters in prepared statements.
(and all issues in the initial patches for these two
tasks, that were discovered in pushbuild and during testing).
Bug#39519: mysql_stmt_close() should flush all data
associated with the statement.
After execution of a prepared statement, send OUT parameters of the invoked
stored procedure, if any, to the client.
When using the binary protocol, send the parameters in an additional result
set over the wire. When using the text protocol, assign out parameters to
the user variables from the CALL(@var1, @var2, ...) specification.
The following refactoring has been made:
- Protocol::send_fields() was renamed to Protocol::send_result_set_metadata();
- A new Protocol::send_result_set_row() was introduced to incapsulate
common functionality for sending row data.
- Signature of Protocol::prepare_for_send() was changed: this operation
does not need a list of items, the number of items is fully sufficient.
The following backward incompatible changes have been made:
- CLIENT_MULTI_RESULTS is now enabled by default in the client;
- CLIENT_PS_MULTI_RESUTLS is now enabled by default in the client.
2009-10-22 00:02:06 +04:00
|
|
|
Functions to convert item to field (for send_result_set_metadata)
|
2000-07-31 21:29:14 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
2005-10-06 17:54:43 +03:00
|
|
|
bool Item::fix_fields(THD *thd, Item **ref)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2004-03-17 14:26:26 +02:00
|
|
|
|
|
|
|
// We do not check fields which are fixed during construction
|
2004-03-20 13:36:26 +02:00
|
|
|
DBUG_ASSERT(fixed == 0 || basic_const_item());
|
2002-11-21 11:01:33 +02:00
|
|
|
fixed= 1;
|
2004-10-20 04:04:37 +03:00
|
|
|
return FALSE;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2004-11-11 21:39:35 +03:00
|
|
|
double Item_ref_null_helper::val_real()
|
2002-12-06 21:55:53 +02:00
|
|
|
{
|
2004-03-18 15:14:36 +02:00
|
|
|
DBUG_ASSERT(fixed == 1);
|
2002-12-06 21:55:53 +02:00
|
|
|
double tmp= (*ref)->val_result();
|
2002-12-10 18:10:00 +02:00
|
|
|
owner->was_null|= null_value= (*ref)->null_value;
|
2002-12-06 21:55:53 +02:00
|
|
|
return tmp;
|
|
|
|
}
|
2004-03-18 15:14:36 +02:00
|
|
|
|
|
|
|
|
2002-12-06 21:55:53 +02:00
|
|
|
longlong Item_ref_null_helper::val_int()
|
|
|
|
{
|
2004-03-18 15:14:36 +02:00
|
|
|
DBUG_ASSERT(fixed == 1);
|
2002-12-06 21:55:53 +02:00
|
|
|
longlong tmp= (*ref)->val_int_result();
|
2002-12-10 18:10:00 +02:00
|
|
|
owner->was_null|= null_value= (*ref)->null_value;
|
2002-12-06 21:55:53 +02:00
|
|
|
return tmp;
|
|
|
|
}
|
2004-03-18 15:14:36 +02:00
|
|
|
|
|
|
|
|
2005-02-09 02:50:45 +04:00
|
|
|
my_decimal *Item_ref_null_helper::val_decimal(my_decimal *decimal_value)
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(fixed == 1);
|
|
|
|
my_decimal *val= (*ref)->val_decimal_result(decimal_value);
|
|
|
|
owner->was_null|= null_value= (*ref)->null_value;
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Item_ref_null_helper::val_bool()
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(fixed == 1);
|
|
|
|
bool val= (*ref)->val_bool_result();
|
|
|
|
owner->was_null|= null_value= (*ref)->null_value;
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-06 21:55:53 +02:00
|
|
|
String* Item_ref_null_helper::val_str(String* s)
|
|
|
|
{
|
2004-03-18 15:14:36 +02:00
|
|
|
DBUG_ASSERT(fixed == 1);
|
2002-12-06 21:55:53 +02:00
|
|
|
String* tmp= (*ref)->str_result(s);
|
2002-12-10 18:10:00 +02:00
|
|
|
owner->was_null|= null_value= (*ref)->null_value;
|
2002-12-06 21:55:53 +02:00
|
|
|
return tmp;
|
|
|
|
}
|
2004-03-18 15:14:36 +02:00
|
|
|
|
|
|
|
|
2007-03-23 22:08:31 +02:00
|
|
|
bool Item_ref_null_helper::get_date(MYSQL_TIME *ltime, uint fuzzydate)
|
2002-12-06 21:55:53 +02:00
|
|
|
{
|
|
|
|
return (owner->was_null|= null_value= (*ref)->get_date(ltime, fuzzydate));
|
|
|
|
}
|
2002-10-27 23:27:00 +02:00
|
|
|
|
2003-06-20 10:15:58 +03:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
|
|
|
Mark item and SELECT_LEXs as dependent if item was resolved in
|
|
|
|
outer SELECT.
|
2003-06-20 10:15:58 +03:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@param thd thread handler
|
|
|
|
@param last select from which current item depend
|
|
|
|
@param current current select
|
|
|
|
@param resolved_item item which was resolved in outer SELECT(for warning)
|
|
|
|
@param mark_item item which should be marked (can be differ in case of
|
|
|
|
substitution)
|
2003-06-20 10:15:58 +03:00
|
|
|
*/
|
|
|
|
|
2003-07-25 01:02:42 +03:00
|
|
|
static void mark_as_dependent(THD *thd, SELECT_LEX *last, SELECT_LEX *current,
|
2005-04-29 02:43:56 +03:00
|
|
|
Item_ident *resolved_item,
|
2005-02-22 12:27:08 +02:00
|
|
|
Item_ident *mark_item)
|
2003-06-20 10:15:58 +03:00
|
|
|
{
|
2005-02-22 12:27:08 +02:00
|
|
|
const char *db_name= (resolved_item->db_name ?
|
|
|
|
resolved_item->db_name : "");
|
|
|
|
const char *table_name= (resolved_item->table_name ?
|
|
|
|
resolved_item->table_name : "");
|
2005-01-06 13:00:13 +02:00
|
|
|
/* store pointer on SELECT_LEX from which item is dependent */
|
2005-02-22 12:27:08 +02:00
|
|
|
if (mark_item)
|
|
|
|
mark_item->depended_from= last;
|
2003-07-02 01:45:22 +03:00
|
|
|
current->mark_as_dependent(last);
|
2003-11-19 15:19:46 +01:00
|
|
|
if (thd->lex->describe & DESCRIBE_EXTENDED)
|
2003-07-25 01:02:42 +03:00
|
|
|
{
|
2009-05-04 22:33:23 +02:00
|
|
|
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
|
|
|
|
ER_WARN_FIELD_RESOLVED, ER(ER_WARN_FIELD_RESOLVED),
|
|
|
|
db_name, (db_name[0] ? "." : ""),
|
|
|
|
table_name, (table_name [0] ? "." : ""),
|
|
|
|
resolved_item->field_name,
|
|
|
|
current->select_number, last->select_number);
|
2003-07-25 01:02:42 +03:00
|
|
|
}
|
2003-06-20 10:15:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
|
|
|
Mark range of selects and resolved identifier (field/reference)
|
|
|
|
item as dependent.
|
2005-04-29 02:43:56 +03:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@param thd thread handler
|
|
|
|
@param last_select select where resolved_item was resolved
|
|
|
|
@param current_sel current select (select where resolved_item was placed)
|
|
|
|
@param found_field field which was found during resolving
|
|
|
|
@param found_item Item which was found during resolving (if resolved
|
|
|
|
identifier belongs to VIEW)
|
|
|
|
@param resolved_item Identifier which was resolved
|
|
|
|
|
|
|
|
@note
|
2005-04-29 02:43:56 +03:00
|
|
|
We have to mark all items between current_sel (including) and
|
|
|
|
last_select (excluding) as dependend (select before last_select should
|
|
|
|
be marked with actual table mask used by resolved item, all other with
|
|
|
|
OUTER_REF_TABLE_BIT) and also write dependence information to Item of
|
|
|
|
resolved identifier.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void mark_select_range_as_dependent(THD *thd,
|
|
|
|
SELECT_LEX *last_select,
|
2005-04-30 19:27:22 +03:00
|
|
|
SELECT_LEX *current_sel,
|
2005-04-29 02:43:56 +03:00
|
|
|
Field *found_field, Item *found_item,
|
|
|
|
Item_ident *resolved_item)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Go from current SELECT to SELECT where field was resolved (it
|
|
|
|
have to be reachable from current SELECT, because it was already
|
|
|
|
done once when we resolved this field and cached result of
|
|
|
|
resolving)
|
|
|
|
*/
|
|
|
|
SELECT_LEX *previous_select= current_sel;
|
2005-06-01 16:35:09 +03:00
|
|
|
for (; previous_select->outer_select() != last_select;
|
|
|
|
previous_select= previous_select->outer_select())
|
2005-04-29 02:43:56 +03:00
|
|
|
{
|
|
|
|
Item_subselect *prev_subselect_item=
|
|
|
|
previous_select->master_unit()->item;
|
|
|
|
prev_subselect_item->used_tables_cache|= OUTER_REF_TABLE_BIT;
|
|
|
|
prev_subselect_item->const_item_cache= 0;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
Item_subselect *prev_subselect_item=
|
|
|
|
previous_select->master_unit()->item;
|
|
|
|
Item_ident *dependent= resolved_item;
|
|
|
|
if (found_field == view_ref_found)
|
|
|
|
{
|
|
|
|
Item::Type type= found_item->type();
|
|
|
|
prev_subselect_item->used_tables_cache|=
|
|
|
|
found_item->used_tables();
|
|
|
|
dependent= ((type == Item::REF_ITEM || type == Item::FIELD_ITEM) ?
|
|
|
|
(Item_ident*) found_item :
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
prev_subselect_item->used_tables_cache|=
|
|
|
|
found_field->table->map;
|
|
|
|
prev_subselect_item->const_item_cache= 0;
|
|
|
|
mark_as_dependent(thd, last_select, current_sel, resolved_item,
|
|
|
|
dependent);
|
|
|
|
}
|
|
|
|
}
|
2004-11-11 11:16:51 +02:00
|
|
|
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
2004-11-09 17:56:33 +02:00
|
|
|
Search a GROUP BY clause for a field with a certain name.
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
Search the GROUP BY list for a column named as find_item. When searching
|
|
|
|
preference is given to columns that are qualified with the same table (and
|
|
|
|
database) name as the one being searched for.
|
2004-11-09 17:56:33 +02:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@param find_item the item being searched for
|
|
|
|
@param group_list GROUP BY clause
|
2004-11-09 17:56:33 +02:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@return
|
2004-11-09 17:56:33 +02:00
|
|
|
- the found item on success
|
|
|
|
- NULL if find_item is not in group_list
|
|
|
|
*/
|
|
|
|
|
|
|
|
static Item** find_field_in_group_list(Item *find_item, ORDER *group_list)
|
|
|
|
{
|
|
|
|
const char *db_name;
|
|
|
|
const char *table_name;
|
|
|
|
const char *field_name;
|
|
|
|
ORDER *found_group= NULL;
|
|
|
|
int found_match_degree= 0;
|
2005-10-01 09:35:30 +03:00
|
|
|
Item_ident *cur_field;
|
2004-11-09 17:56:33 +02:00
|
|
|
int cur_match_degree= 0;
|
2006-04-06 15:29:15 -07:00
|
|
|
char name_buff[NAME_LEN+1];
|
2004-11-09 17:56:33 +02:00
|
|
|
|
|
|
|
if (find_item->type() == Item::FIELD_ITEM ||
|
|
|
|
find_item->type() == Item::REF_ITEM)
|
|
|
|
{
|
|
|
|
db_name= ((Item_ident*) find_item)->db_name;
|
|
|
|
table_name= ((Item_ident*) find_item)->table_name;
|
|
|
|
field_name= ((Item_ident*) find_item)->field_name;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
|
2006-04-06 15:29:15 -07:00
|
|
|
if (db_name && lower_case_table_names)
|
|
|
|
{
|
|
|
|
/* Convert database to lower case for comparison */
|
|
|
|
strmake(name_buff, db_name, sizeof(name_buff)-1);
|
|
|
|
my_casedn_str(files_charset_info, name_buff);
|
|
|
|
db_name= name_buff;
|
|
|
|
}
|
|
|
|
|
2005-02-25 16:53:22 +02:00
|
|
|
DBUG_ASSERT(field_name != 0);
|
2004-11-09 17:56:33 +02:00
|
|
|
|
|
|
|
for (ORDER *cur_group= group_list ; cur_group ; cur_group= cur_group->next)
|
|
|
|
{
|
2005-09-26 23:29:02 -07:00
|
|
|
if ((*(cur_group->item))->real_item()->type() == Item::FIELD_ITEM)
|
2004-11-09 17:56:33 +02:00
|
|
|
{
|
2005-10-01 09:35:30 +03:00
|
|
|
cur_field= (Item_ident*) *cur_group->item;
|
2004-11-09 17:56:33 +02:00
|
|
|
cur_match_degree= 0;
|
|
|
|
|
2005-02-25 16:53:22 +02:00
|
|
|
DBUG_ASSERT(cur_field->field_name != 0);
|
2004-11-09 17:56:33 +02:00
|
|
|
|
|
|
|
if (!my_strcasecmp(system_charset_info,
|
|
|
|
cur_field->field_name, field_name))
|
|
|
|
++cur_match_degree;
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (cur_field->table_name && table_name)
|
|
|
|
{
|
|
|
|
/* If field_name is qualified by a table name. */
|
2007-11-13 11:39:52 +02:00
|
|
|
if (my_strcasecmp(table_alias_charset, cur_field->table_name, table_name))
|
2004-11-09 17:56:33 +02:00
|
|
|
/* Same field names, different tables. */
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
++cur_match_degree;
|
|
|
|
if (cur_field->db_name && db_name)
|
|
|
|
{
|
|
|
|
/* If field_name is also qualified by a database name. */
|
|
|
|
if (strcmp(cur_field->db_name, db_name))
|
|
|
|
/* Same field names, different databases. */
|
|
|
|
return NULL;
|
|
|
|
++cur_match_degree;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cur_match_degree > found_match_degree)
|
|
|
|
{
|
|
|
|
found_match_degree= cur_match_degree;
|
|
|
|
found_group= cur_group;
|
|
|
|
}
|
|
|
|
else if (found_group && (cur_match_degree == found_match_degree) &&
|
|
|
|
! (*(found_group->item))->eq(cur_field, 0))
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
If the current resolve candidate matches equally well as the current
|
|
|
|
best match, they must reference the same column, otherwise the field
|
|
|
|
is ambiguous.
|
|
|
|
*/
|
2004-11-13 19:35:51 +02:00
|
|
|
my_error(ER_NON_UNIQ_ERROR, MYF(0),
|
|
|
|
find_item->full_name(), current_thd->where);
|
2004-11-09 17:56:33 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found_group)
|
|
|
|
return found_group->item;
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
2004-11-09 17:56:33 +02:00
|
|
|
Resolve a column reference in a sub-select.
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
Resolve a column reference (usually inside a HAVING clause) against the
|
|
|
|
SELECT and GROUP BY clauses of the query described by 'select'. The name
|
|
|
|
resolution algorithm searches both the SELECT and GROUP BY clauses, and in
|
|
|
|
case of a name conflict prefers GROUP BY column names over SELECT names. If
|
|
|
|
both clauses contain different fields with the same names, a warning is
|
|
|
|
issued that name of 'ref' is ambiguous. We extend ANSI SQL in that when no
|
|
|
|
GROUP BY column is found, then a HAVING name is resolved as a possibly
|
|
|
|
derived SELECT column. This extension is allowed only if the
|
|
|
|
MODE_ONLY_FULL_GROUP_BY sql mode isn't enabled.
|
|
|
|
|
|
|
|
@param thd current thread
|
|
|
|
@param ref column reference being resolved
|
2008-01-25 10:37:29 -07:00
|
|
|
@param select the select that ref is resolved against
|
2007-10-11 13:29:09 -04:00
|
|
|
|
|
|
|
@note
|
2004-11-09 17:56:33 +02:00
|
|
|
The resolution procedure is:
|
|
|
|
- Search for a column or derived column named col_ref_i [in table T_j]
|
2007-10-11 13:29:09 -04:00
|
|
|
in the SELECT clause of Q.
|
2004-11-09 17:56:33 +02:00
|
|
|
- Search for a column named col_ref_i [in table T_j]
|
2007-10-11 13:29:09 -04:00
|
|
|
in the GROUP BY clause of Q.
|
2004-11-09 17:56:33 +02:00
|
|
|
- If found different columns with the same name in GROUP BY and SELECT
|
2007-10-11 13:29:09 -04:00
|
|
|
- issue a warning and return the GROUP BY column,
|
|
|
|
- otherwise
|
|
|
|
- if the MODE_ONLY_FULL_GROUP_BY mode is enabled return error
|
|
|
|
- else return the found SELECT column.
|
2004-11-09 17:56:33 +02:00
|
|
|
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@return
|
|
|
|
- NULL - there was an error, and the error was already reported
|
|
|
|
- not_found_item - the item was not resolved, no error was reported
|
|
|
|
- resolved item - if the item was resolved
|
2004-11-09 17:56:33 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
static Item**
|
|
|
|
resolve_ref_in_select_and_group(THD *thd, Item_ident *ref, SELECT_LEX *select)
|
|
|
|
{
|
|
|
|
Item **group_by_ref= NULL;
|
|
|
|
Item **select_ref= NULL;
|
2010-06-10 17:45:22 -03:00
|
|
|
ORDER *group_list= select->group_list.first;
|
2004-11-09 17:56:33 +02:00
|
|
|
bool ambiguous_fields= FALSE;
|
|
|
|
uint counter;
|
2007-03-04 19:54:35 -08:00
|
|
|
enum_resolution_type resolution;
|
2004-11-09 17:56:33 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Search for a column or derived column named as 'ref' in the SELECT
|
|
|
|
clause of the current select.
|
|
|
|
*/
|
2005-01-06 13:00:13 +02:00
|
|
|
if (!(select_ref= find_item_in_list(ref, *(select->get_item_list()),
|
|
|
|
&counter, REPORT_EXCEPT_NOT_FOUND,
|
2007-03-04 19:54:35 -08:00
|
|
|
&resolution)))
|
2004-11-09 17:56:33 +02:00
|
|
|
return NULL; /* Some error occurred. */
|
2007-03-04 19:54:35 -08:00
|
|
|
if (resolution == RESOLVED_AGAINST_ALIAS)
|
|
|
|
ref->alias_name_used= TRUE;
|
2004-11-09 17:56:33 +02:00
|
|
|
|
|
|
|
/* If this is a non-aggregated field inside HAVING, search in GROUP BY. */
|
|
|
|
if (select->having_fix_field && !ref->with_sum_func && group_list)
|
|
|
|
{
|
|
|
|
group_by_ref= find_field_in_group_list(ref, group_list);
|
|
|
|
|
|
|
|
/* Check if the fields found in SELECT and GROUP BY are the same field. */
|
|
|
|
if (group_by_ref && (select_ref != not_found_item) &&
|
|
|
|
!((*group_by_ref)->eq(*select_ref, 0)))
|
|
|
|
{
|
|
|
|
ambiguous_fields= TRUE;
|
|
|
|
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_NON_UNIQ_ERROR,
|
|
|
|
ER(ER_NON_UNIQ_ERROR), ref->full_name(),
|
|
|
|
current_thd->where);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-21 01:52:59 +04:00
|
|
|
if (thd->variables.sql_mode & MODE_ONLY_FULL_GROUP_BY &&
|
2008-01-11 18:50:54 +01:00
|
|
|
select->having_fix_field &&
|
2006-04-21 01:52:59 +04:00
|
|
|
select_ref != not_found_item && !group_by_ref)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Report the error if fields was found only in the SELECT item list and
|
|
|
|
the strict mode is enabled.
|
|
|
|
*/
|
|
|
|
my_error(ER_NON_GROUPING_FIELD_USED, MYF(0),
|
|
|
|
ref->name, "HAVING");
|
|
|
|
return NULL;
|
|
|
|
}
|
2004-11-09 17:56:33 +02:00
|
|
|
if (select_ref != not_found_item || group_by_ref)
|
|
|
|
{
|
|
|
|
if (select_ref != not_found_item && !ambiguous_fields)
|
|
|
|
{
|
2005-02-25 16:53:22 +02:00
|
|
|
DBUG_ASSERT(*select_ref != 0);
|
2005-02-03 18:00:50 +02:00
|
|
|
if (!select->ref_pointer_array[counter])
|
2004-11-09 17:56:33 +02:00
|
|
|
{
|
2004-11-13 19:35:51 +02:00
|
|
|
my_error(ER_ILLEGAL_REFERENCE, MYF(0),
|
|
|
|
ref->name, "forward reference in item list");
|
2004-11-09 17:56:33 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2005-02-03 13:18:30 +02:00
|
|
|
DBUG_ASSERT((*select_ref)->fixed);
|
2004-11-09 17:56:33 +02:00
|
|
|
return (select->ref_pointer_array + counter);
|
|
|
|
}
|
2004-12-22 13:54:39 +02:00
|
|
|
if (group_by_ref)
|
2004-11-09 17:56:33 +02:00
|
|
|
return group_by_ref;
|
2004-12-22 13:54:39 +02:00
|
|
|
DBUG_ASSERT(FALSE);
|
|
|
|
return NULL; /* So there is no compiler warning. */
|
2004-11-09 17:56:33 +02:00
|
|
|
}
|
2004-12-22 13:54:39 +02:00
|
|
|
|
|
|
|
return (Item**) not_found_item;
|
2004-11-09 17:56:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
2006-02-15 19:45:06 +03:00
|
|
|
Resolve the name of an outer select column reference.
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
The method resolves the column reference represented by 'this' as a column
|
|
|
|
present in outer selects that contain current select.
|
2006-02-15 19:45:06 +03:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
In prepared statements, because of cache, find_field_in_tables()
|
|
|
|
can resolve fields even if they don't belong to current context.
|
|
|
|
In this case this method only finds appropriate context and marks
|
|
|
|
current select as dependent. The found reference of field should be
|
|
|
|
provided in 'from_field'.
|
2006-02-15 19:45:06 +03:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@param[in] thd current thread
|
|
|
|
@param[in,out] from_field found field reference or (Field*)not_found_field
|
|
|
|
@param[in,out] reference view column if this item was resolved to a
|
|
|
|
view column
|
2006-02-15 19:45:06 +03:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@note
|
|
|
|
This is the inner loop of Item_field::fix_fields:
|
|
|
|
@code
|
|
|
|
for each outer query Q_k beginning from the inner-most one
|
|
|
|
{
|
|
|
|
search for a column or derived column named col_ref_i
|
|
|
|
[in table T_j] in the FROM clause of Q_k;
|
2006-02-15 19:45:06 +03:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
if such a column is not found
|
|
|
|
Search for a column or derived column named col_ref_i
|
|
|
|
[in table T_j] in the SELECT and GROUP clauses of Q_k.
|
|
|
|
}
|
|
|
|
@endcode
|
|
|
|
|
|
|
|
@retval
|
|
|
|
1 column succefully resolved and fix_fields() should continue.
|
|
|
|
@retval
|
|
|
|
0 column fully fixed and fix_fields() should return FALSE
|
|
|
|
@retval
|
|
|
|
-1 error occured
|
2006-02-15 19:45:06 +03:00
|
|
|
*/
|
2007-10-11 13:29:09 -04:00
|
|
|
|
2006-02-15 19:45:06 +03:00
|
|
|
int
|
|
|
|
Item_field::fix_outer_field(THD *thd, Field **from_field, Item **reference)
|
|
|
|
{
|
|
|
|
enum_parsing_place place= NO_MATTER;
|
|
|
|
bool field_found= (*from_field != not_found_field);
|
|
|
|
bool upward_lookup= FALSE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
If there are outer contexts (outer selects, but current select is
|
|
|
|
not derived table or view) try to resolve this reference in the
|
|
|
|
outer contexts.
|
|
|
|
|
|
|
|
We treat each subselect as a separate namespace, so that different
|
|
|
|
subselects may contain columns with the same names. The subselects
|
|
|
|
are searched starting from the innermost.
|
|
|
|
*/
|
|
|
|
Name_resolution_context *last_checked_context= context;
|
|
|
|
Item **ref= (Item **) not_found_item;
|
2007-03-09 01:45:32 -08:00
|
|
|
SELECT_LEX *current_sel= (SELECT_LEX *) thd->lex->current_select;
|
|
|
|
Name_resolution_context *outer_context= 0;
|
2007-04-15 09:54:16 +04:00
|
|
|
SELECT_LEX *select= 0;
|
2007-03-09 01:45:32 -08:00
|
|
|
/* Currently derived tables cannot be correlated */
|
|
|
|
if (current_sel->master_unit()->first_select()->linkage !=
|
|
|
|
DERIVED_TABLE_TYPE)
|
|
|
|
outer_context= context->outer_context;
|
2006-02-15 19:45:06 +03:00
|
|
|
for (;
|
|
|
|
outer_context;
|
|
|
|
outer_context= outer_context->outer_context)
|
|
|
|
{
|
2007-04-15 08:31:34 +04:00
|
|
|
select= outer_context->select_lex;
|
2006-02-15 19:45:06 +03:00
|
|
|
Item_subselect *prev_subselect_item=
|
|
|
|
last_checked_context->select_lex->master_unit()->item;
|
|
|
|
last_checked_context= outer_context;
|
|
|
|
upward_lookup= TRUE;
|
|
|
|
|
|
|
|
place= prev_subselect_item->parsing_place;
|
|
|
|
/*
|
|
|
|
If outer_field is set, field was already found by first call
|
|
|
|
to find_field_in_tables(). Only need to find appropriate context.
|
|
|
|
*/
|
|
|
|
if (field_found && outer_context->select_lex !=
|
|
|
|
cached_table->select_lex)
|
|
|
|
continue;
|
|
|
|
/*
|
|
|
|
In case of a view, find_field_in_tables() writes the pointer to
|
|
|
|
the found view field into '*reference', in other words, it
|
|
|
|
substitutes this Item_field with the found expression.
|
|
|
|
*/
|
|
|
|
if (field_found || (*from_field= find_field_in_tables(thd, this,
|
|
|
|
outer_context->
|
|
|
|
first_name_resolution_table,
|
|
|
|
outer_context->
|
|
|
|
last_name_resolution_table,
|
|
|
|
reference,
|
|
|
|
IGNORE_EXCEPT_NON_UNIQUE,
|
|
|
|
TRUE, TRUE)) !=
|
|
|
|
not_found_field)
|
|
|
|
{
|
|
|
|
if (*from_field)
|
|
|
|
{
|
2007-01-11 23:18:01 +03:00
|
|
|
if (thd->variables.sql_mode & MODE_ONLY_FULL_GROUP_BY &&
|
|
|
|
select->cur_pos_in_select_list != UNDEF_POS)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
As this is an outer field it should be added to the list of
|
|
|
|
non aggregated fields of the outer select.
|
|
|
|
*/
|
|
|
|
marker= select->cur_pos_in_select_list;
|
|
|
|
select->non_agg_fields.push_back(this);
|
|
|
|
}
|
2006-02-15 19:45:06 +03:00
|
|
|
if (*from_field != view_ref_found)
|
|
|
|
{
|
|
|
|
prev_subselect_item->used_tables_cache|= (*from_field)->table->map;
|
|
|
|
prev_subselect_item->const_item_cache= 0;
|
2007-04-15 08:31:34 +04:00
|
|
|
set_field(*from_field);
|
2007-02-21 23:00:32 +03:00
|
|
|
if (!last_checked_context->select_lex->having_fix_field &&
|
2007-05-16 23:42:10 -07:00
|
|
|
select->group_list.elements &&
|
|
|
|
(place == SELECT_LIST || place == IN_HAVING))
|
2007-02-21 23:00:32 +03:00
|
|
|
{
|
|
|
|
Item_outer_ref *rf;
|
|
|
|
/*
|
2007-04-15 08:31:34 +04:00
|
|
|
If an outer field is resolved in a grouping select then it
|
|
|
|
is replaced for an Item_outer_ref object. Otherwise an
|
|
|
|
Item_field object is used.
|
|
|
|
The new Item_outer_ref object is saved in the inner_refs_list of
|
|
|
|
the outer select. Here it is only created. It can be fixed only
|
|
|
|
after the original field has been fixed and this is done in the
|
|
|
|
fix_inner_refs() function.
|
2007-02-21 23:00:32 +03:00
|
|
|
*/
|
2007-04-15 08:31:34 +04:00
|
|
|
;
|
|
|
|
if (!(rf= new Item_outer_ref(context, this)))
|
2007-02-21 23:00:32 +03:00
|
|
|
return -1;
|
2007-04-15 08:31:34 +04:00
|
|
|
thd->change_item_tree(reference, rf);
|
2007-02-21 23:00:32 +03:00
|
|
|
select->inner_refs_list.push_back(rf);
|
2007-04-15 08:31:34 +04:00
|
|
|
rf->in_sum_func= thd->lex->in_sum_func;
|
2007-02-21 23:00:32 +03:00
|
|
|
}
|
2007-04-26 11:12:17 +03:00
|
|
|
/*
|
|
|
|
A reference is resolved to a nest level that's outer or the same as
|
|
|
|
the nest level of the enclosing set function : adjust the value of
|
|
|
|
max_arg_level for the function if it's needed.
|
|
|
|
*/
|
2006-02-15 19:45:06 +03:00
|
|
|
if (thd->lex->in_sum_func &&
|
2007-04-26 11:12:17 +03:00
|
|
|
thd->lex->in_sum_func->nest_level >= select->nest_level)
|
2006-02-15 19:45:06 +03:00
|
|
|
{
|
2006-12-15 00:51:37 +02:00
|
|
|
Item::Type ref_type= (*reference)->type();
|
2006-02-15 19:45:06 +03:00
|
|
|
set_if_bigger(thd->lex->in_sum_func->max_arg_level,
|
|
|
|
select->nest_level);
|
|
|
|
set_field(*from_field);
|
|
|
|
fixed= 1;
|
|
|
|
mark_as_dependent(thd, last_checked_context->select_lex,
|
|
|
|
context->select_lex, this,
|
2006-12-15 00:51:37 +02:00
|
|
|
((ref_type == REF_ITEM ||
|
|
|
|
ref_type == FIELD_ITEM) ?
|
2006-02-15 19:45:06 +03:00
|
|
|
(Item_ident*) (*reference) : 0));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-12-15 00:51:37 +02:00
|
|
|
Item::Type ref_type= (*reference)->type();
|
2006-02-15 19:45:06 +03:00
|
|
|
prev_subselect_item->used_tables_cache|=
|
|
|
|
(*reference)->used_tables();
|
|
|
|
prev_subselect_item->const_item_cache&=
|
|
|
|
(*reference)->const_item();
|
|
|
|
mark_as_dependent(thd, last_checked_context->select_lex,
|
|
|
|
context->select_lex, this,
|
2006-12-15 00:51:37 +02:00
|
|
|
((ref_type == REF_ITEM || ref_type == FIELD_ITEM) ?
|
2006-02-15 19:45:06 +03:00
|
|
|
(Item_ident*) (*reference) :
|
|
|
|
0));
|
|
|
|
/*
|
|
|
|
A reference to a view field had been found and we
|
|
|
|
substituted it instead of this Item (find_field_in_tables
|
|
|
|
does it by assigning the new value to *reference), so now
|
|
|
|
we can return from this function.
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Search in SELECT and GROUP lists of the outer select. */
|
2007-11-20 19:18:21 +02:00
|
|
|
if (place != IN_WHERE && place != IN_ON)
|
2006-02-15 19:45:06 +03:00
|
|
|
{
|
|
|
|
if (!(ref= resolve_ref_in_select_and_group(thd, this, select)))
|
|
|
|
return -1; /* Some error occurred (e.g. ambiguous names). */
|
|
|
|
if (ref != not_found_item)
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(*ref && (*ref)->fixed);
|
|
|
|
prev_subselect_item->used_tables_cache|= (*ref)->used_tables();
|
|
|
|
prev_subselect_item->const_item_cache&= (*ref)->const_item();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Reference is not found in this select => this subquery depend on
|
|
|
|
outer select (or we just trying to find wrong identifier, in this
|
|
|
|
case it does not matter which used tables bits we set)
|
|
|
|
*/
|
|
|
|
prev_subselect_item->used_tables_cache|= OUTER_REF_TABLE_BIT;
|
|
|
|
prev_subselect_item->const_item_cache= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
DBUG_ASSERT(ref != 0);
|
|
|
|
if (!*from_field)
|
|
|
|
return -1;
|
|
|
|
if (ref == not_found_item && *from_field == not_found_field)
|
|
|
|
{
|
|
|
|
if (upward_lookup)
|
|
|
|
{
|
|
|
|
// We can't say exactly what absent table or field
|
|
|
|
my_error(ER_BAD_FIELD_ERROR, MYF(0), full_name(), thd->where);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Call find_field_in_tables only to report the error */
|
|
|
|
find_field_in_tables(thd, this,
|
|
|
|
context->first_name_resolution_table,
|
|
|
|
context->last_name_resolution_table,
|
|
|
|
reference, REPORT_ALL_ERRORS,
|
2010-07-02 15:30:47 -03:00
|
|
|
!any_privileges, TRUE);
|
2006-02-15 19:45:06 +03:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else if (ref != not_found_item)
|
|
|
|
{
|
|
|
|
Item *save;
|
|
|
|
Item_ref *rf;
|
|
|
|
|
|
|
|
/* Should have been checked in resolve_ref_in_select_and_group(). */
|
|
|
|
DBUG_ASSERT(*ref && (*ref)->fixed);
|
|
|
|
/*
|
|
|
|
Here, a subset of actions performed by Item_ref::set_properties
|
|
|
|
is not enough. So we pass ptr to NULL into Item_[direct]_ref
|
|
|
|
constructor, so no initialization is performed, and call
|
|
|
|
fix_fields() below.
|
|
|
|
*/
|
|
|
|
save= *ref;
|
|
|
|
*ref= NULL; // Don't call set_properties()
|
|
|
|
rf= (place == IN_HAVING ?
|
|
|
|
new Item_ref(context, ref, (char*) table_name,
|
2007-03-04 19:54:35 -08:00
|
|
|
(char*) field_name, alias_name_used) :
|
2007-04-15 08:31:34 +04:00
|
|
|
(!select->group_list.elements ?
|
2006-02-15 19:45:06 +03:00
|
|
|
new Item_direct_ref(context, ref, (char*) table_name,
|
2007-04-15 08:31:34 +04:00
|
|
|
(char*) field_name, alias_name_used) :
|
|
|
|
new Item_outer_ref(context, ref, (char*) table_name,
|
|
|
|
(char*) field_name, alias_name_used)));
|
2006-02-15 19:45:06 +03:00
|
|
|
*ref= save;
|
|
|
|
if (!rf)
|
|
|
|
return -1;
|
2007-04-15 08:31:34 +04:00
|
|
|
|
|
|
|
if (place != IN_HAVING && select->group_list.elements)
|
|
|
|
{
|
|
|
|
outer_context->select_lex->inner_refs_list.push_back((Item_outer_ref*)rf);
|
|
|
|
((Item_outer_ref*)rf)->in_sum_func= thd->lex->in_sum_func;
|
|
|
|
}
|
2006-02-15 19:45:06 +03:00
|
|
|
thd->change_item_tree(reference, rf);
|
|
|
|
/*
|
|
|
|
rf is Item_ref => never substitute other items (in this case)
|
|
|
|
during fix_fields() => we can use rf after fix_fields()
|
|
|
|
*/
|
|
|
|
DBUG_ASSERT(!rf->fixed); // Assured by Item_ref()
|
|
|
|
if (rf->fix_fields(thd, reference) || rf->check_cols(1))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
mark_as_dependent(thd, last_checked_context->select_lex,
|
|
|
|
context->select_lex, this,
|
|
|
|
rf);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mark_as_dependent(thd, last_checked_context->select_lex,
|
|
|
|
context->select_lex,
|
2007-02-21 23:00:32 +03:00
|
|
|
this, (Item_ident*)*reference);
|
2006-02-15 19:45:06 +03:00
|
|
|
if (last_checked_context->select_lex->having_fix_field)
|
|
|
|
{
|
|
|
|
Item_ref *rf;
|
|
|
|
rf= new Item_ref(context,
|
|
|
|
(cached_table->db[0] ? cached_table->db : 0),
|
|
|
|
(char*) cached_table->alias, (char*) field_name);
|
|
|
|
if (!rf)
|
|
|
|
return -1;
|
|
|
|
thd->change_item_tree(reference, rf);
|
|
|
|
/*
|
|
|
|
rf is Item_ref => never substitute other items (in this case)
|
|
|
|
during fix_fields() => we can use rf after fix_fields()
|
|
|
|
*/
|
|
|
|
DBUG_ASSERT(!rf->fixed); // Assured by Item_ref()
|
|
|
|
if (rf->fix_fields(thd, reference) || rf->check_cols(1))
|
|
|
|
return -1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
2004-11-10 12:43:08 +02:00
|
|
|
Resolve the name of a column reference.
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
The method resolves the column reference represented by 'this' as a column
|
|
|
|
present in one of: FROM clause, SELECT clause, GROUP BY clause of a query
|
|
|
|
Q, or in outer queries that contain Q.
|
2004-11-10 12:43:08 +02:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
The name resolution algorithm used is (where [T_j] is an optional table
|
|
|
|
name that qualifies the column name):
|
2004-11-10 12:43:08 +02:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@code
|
|
|
|
resolve_column_reference([T_j].col_ref_i)
|
|
|
|
{
|
|
|
|
search for a column or derived column named col_ref_i
|
|
|
|
[in table T_j] in the FROM clause of Q;
|
2004-11-10 12:43:08 +02:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
if such a column is NOT found AND // Lookup in outer queries.
|
|
|
|
there are outer queries
|
2004-11-10 12:43:08 +02:00
|
|
|
{
|
2007-10-11 13:29:09 -04:00
|
|
|
for each outer query Q_k beginning from the inner-most one
|
2004-11-10 12:43:08 +02:00
|
|
|
{
|
2007-10-11 13:29:09 -04:00
|
|
|
search for a column or derived column named col_ref_i
|
|
|
|
[in table T_j] in the FROM clause of Q_k;
|
2004-11-10 12:43:08 +02:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
if such a column is not found
|
|
|
|
Search for a column or derived column named col_ref_i
|
|
|
|
[in table T_j] in the SELECT and GROUP clauses of Q_k.
|
2004-11-10 12:43:08 +02:00
|
|
|
}
|
|
|
|
}
|
2007-10-11 13:29:09 -04:00
|
|
|
}
|
|
|
|
@endcode
|
2004-11-10 12:43:08 +02:00
|
|
|
|
|
|
|
Notice that compared to Item_ref::fix_fields, here we first search the FROM
|
|
|
|
clause, and then we search the SELECT and GROUP BY clauses.
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@param[in] thd current thread
|
|
|
|
@param[in,out] reference view column if this item was resolved to a
|
|
|
|
view column
|
|
|
|
|
|
|
|
@retval
|
2004-11-10 12:43:08 +02:00
|
|
|
TRUE if error
|
2007-10-11 13:29:09 -04:00
|
|
|
@retval
|
2004-11-10 12:43:08 +02:00
|
|
|
FALSE on success
|
|
|
|
*/
|
|
|
|
|
2005-07-01 07:05:42 +03:00
|
|
|
bool Item_field::fix_fields(THD *thd, Item **reference)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2004-03-20 13:36:26 +02:00
|
|
|
DBUG_ASSERT(fixed == 0);
|
2007-01-11 23:18:01 +03:00
|
|
|
Field *from_field= (Field *)not_found_field;
|
|
|
|
bool outer_fixed= false;
|
|
|
|
|
2001-09-21 03:38:35 +03:00
|
|
|
if (!field) // If field is not checked
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2005-01-31 16:24:11 +02:00
|
|
|
/*
|
|
|
|
In case of view, find_field_in_tables() write pointer to view field
|
|
|
|
expression to 'reference', i.e. it substitute that expression instead
|
|
|
|
of this Item_field
|
|
|
|
*/
|
2005-08-12 17:57:19 +03:00
|
|
|
if ((from_field= find_field_in_tables(thd, this,
|
|
|
|
context->first_name_resolution_table,
|
|
|
|
context->last_name_resolution_table,
|
2005-07-01 07:05:42 +03:00
|
|
|
reference,
|
2007-10-09 19:16:39 +05:00
|
|
|
thd->lex->use_only_table_context ?
|
|
|
|
REPORT_ALL_ERRORS :
|
|
|
|
IGNORE_EXCEPT_NON_UNIQUE,
|
2005-10-28 00:18:23 +03:00
|
|
|
!any_privileges,
|
2005-07-03 00:51:02 +03:00
|
|
|
TRUE)) ==
|
2002-12-26 01:28:59 +02:00
|
|
|
not_found_field)
|
2002-05-26 22:50:32 +03:00
|
|
|
{
|
2006-02-15 19:45:06 +03:00
|
|
|
int ret;
|
2005-10-13 16:00:26 +04:00
|
|
|
/* Look up in current select's item_list to find aliased fields */
|
|
|
|
if (thd->lex->current_select->is_item_list_lookup)
|
|
|
|
{
|
|
|
|
uint counter;
|
2007-03-04 19:54:35 -08:00
|
|
|
enum_resolution_type resolution;
|
2005-10-13 16:00:26 +04:00
|
|
|
Item** res= find_item_in_list(this, thd->lex->current_select->item_list,
|
|
|
|
&counter, REPORT_EXCEPT_NOT_FOUND,
|
2007-03-04 19:54:35 -08:00
|
|
|
&resolution);
|
2007-01-10 08:55:55 -08:00
|
|
|
if (!res)
|
|
|
|
return 1;
|
2007-03-04 19:54:35 -08:00
|
|
|
if (resolution == RESOLVED_AGAINST_ALIAS)
|
|
|
|
alias_name_used= TRUE;
|
2006-11-03 18:48:16 +02:00
|
|
|
if (res != (Item **)not_found_item)
|
2005-10-13 16:00:26 +04:00
|
|
|
{
|
2006-11-03 18:48:16 +02:00
|
|
|
if ((*res)->type() == Item::FIELD_ITEM)
|
|
|
|
{
|
|
|
|
/*
|
2007-08-13 16:11:25 +03:00
|
|
|
It's an Item_field referencing another Item_field in the select
|
|
|
|
list.
|
|
|
|
Use the field from the Item_field in the select list and leave
|
|
|
|
the Item_field instance in place.
|
2006-11-03 18:48:16 +02:00
|
|
|
*/
|
2007-02-14 11:27:37 -05:00
|
|
|
|
2007-08-13 16:11:25 +03:00
|
|
|
Field *new_field= (*((Item_field**)res))->field;
|
2007-02-14 11:27:37 -05:00
|
|
|
|
2007-08-13 16:11:25 +03:00
|
|
|
if (new_field == NULL)
|
2007-02-09 11:05:36 +01:00
|
|
|
{
|
|
|
|
/* The column to which we link isn't valid. */
|
|
|
|
my_error(ER_BAD_FIELD_ERROR, MYF(0), (*res)->name,
|
|
|
|
current_thd->where);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
2007-08-13 16:11:25 +03:00
|
|
|
set_field(new_field);
|
2006-11-03 18:48:16 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
It's not an Item_field in the select list so we must make a new
|
|
|
|
Item_ref to point to the Item in the select list and replace the
|
|
|
|
Item_field created by the parser with the new Item_ref.
|
2010-02-06 23:54:30 +04:00
|
|
|
|
|
|
|
NOTE: If we are fixing an alias reference inside ORDER/GROUP BY
|
|
|
|
item tree, then we use new Item_ref as an intermediate value
|
|
|
|
to resolve referenced item only.
|
|
|
|
In this case the new Item_ref item is unused.
|
2006-11-03 18:48:16 +02:00
|
|
|
*/
|
2006-11-07 14:39:20 +01:00
|
|
|
Item_ref *rf= new Item_ref(context, db_name,table_name,field_name);
|
2006-11-03 18:48:16 +02:00
|
|
|
if (!rf)
|
|
|
|
return 1;
|
2010-02-06 23:54:30 +04:00
|
|
|
|
|
|
|
bool save_group_fix_field= thd->lex->current_select->group_fix_field;
|
2006-11-03 18:48:16 +02:00
|
|
|
/*
|
2010-02-06 23:54:30 +04:00
|
|
|
No need for recursive resolving of aliases.
|
|
|
|
*/
|
|
|
|
thd->lex->current_select->group_fix_field= 0;
|
|
|
|
|
|
|
|
bool ret= rf->fix_fields(thd, (Item **) &rf) || rf->check_cols(1);
|
|
|
|
thd->lex->current_select->group_fix_field= save_group_fix_field;
|
|
|
|
if (ret)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (save_group_fix_field && alias_name_used)
|
|
|
|
thd->change_item_tree(reference, *rf->ref);
|
|
|
|
else
|
|
|
|
thd->change_item_tree(reference, rf);
|
|
|
|
|
|
|
|
return FALSE;
|
2006-11-03 18:48:16 +02:00
|
|
|
}
|
2005-10-09 23:05:44 +04:00
|
|
|
}
|
|
|
|
}
|
2006-02-15 19:45:06 +03:00
|
|
|
if ((ret= fix_outer_field(thd, &from_field, reference)) < 0)
|
|
|
|
goto error;
|
|
|
|
outer_fixed= TRUE;
|
2008-03-27 19:49:32 +03:00
|
|
|
if (!ret)
|
|
|
|
goto mark_non_agg_field;
|
2003-06-04 18:28:51 +03:00
|
|
|
}
|
2004-11-09 17:56:33 +02:00
|
|
|
else if (!from_field)
|
2005-07-01 07:05:42 +03:00
|
|
|
goto error;
|
2002-10-08 14:50:12 +03:00
|
|
|
|
2008-02-12 12:43:55 +03:00
|
|
|
if (!outer_fixed && cached_table && cached_table->select_lex &&
|
2008-02-12 22:21:33 +03:00
|
|
|
context->select_lex &&
|
|
|
|
cached_table->select_lex != context->select_lex)
|
2008-02-12 12:43:55 +03:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
if ((ret= fix_outer_field(thd, &from_field, reference)) < 0)
|
|
|
|
goto error;
|
|
|
|
outer_fixed= 1;
|
2008-03-27 19:49:32 +03:00
|
|
|
if (!ret)
|
|
|
|
goto mark_non_agg_field;
|
2008-02-12 12:43:55 +03:00
|
|
|
}
|
|
|
|
|
2004-07-16 01:15:55 +03:00
|
|
|
/*
|
|
|
|
if it is not expression from merged VIEW we will set this field.
|
|
|
|
|
|
|
|
We can leave expression substituted from view for next PS/SP rexecution
|
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 18:52:22 +03:00
|
|
|
(i.e. do not register this substitution for reverting on cleanup()
|
2004-07-16 01:15:55 +03:00
|
|
|
(register_item_tree_changing())), because this subtree will be
|
2005-10-28 00:18:23 +03:00
|
|
|
fix_field'ed during setup_tables()->setup_underlying() (i.e. before
|
2004-07-16 01:15:55 +03:00
|
|
|
all other expressions of query, and references on tables which do
|
|
|
|
not present in query will not make problems.
|
|
|
|
|
|
|
|
Also we suppose that view can't be changed during PS/SP life.
|
|
|
|
*/
|
2005-02-22 12:27:08 +02:00
|
|
|
if (from_field == view_ref_found)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
set_field(from_field);
|
2005-10-15 14:32:37 -07:00
|
|
|
if (thd->lex->in_sum_func &&
|
|
|
|
thd->lex->in_sum_func->nest_level ==
|
|
|
|
thd->lex->current_select->nest_level)
|
|
|
|
set_if_bigger(thd->lex->in_sum_func->max_arg_level,
|
|
|
|
thd->lex->current_select->nest_level);
|
2000-07-31 21:29:14 +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 18:52:22 +03:00
|
|
|
else if (thd->mark_used_columns != MARK_COLUMNS_NONE)
|
2001-09-21 03:38:35 +03:00
|
|
|
{
|
2005-04-28 14:45:27 +02:00
|
|
|
TABLE *table= field->table;
|
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 18:52:22 +03:00
|
|
|
MY_BITMAP *current_bitmap, *other_bitmap;
|
|
|
|
if (thd->mark_used_columns == MARK_COLUMNS_READ)
|
2005-04-28 14:45:27 +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 18:52:22 +03:00
|
|
|
current_bitmap= table->read_set;
|
|
|
|
other_bitmap= table->write_set;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
current_bitmap= table->write_set;
|
|
|
|
other_bitmap= table->read_set;
|
|
|
|
}
|
|
|
|
if (!bitmap_fast_test_and_set(current_bitmap, field->field_index))
|
|
|
|
{
|
|
|
|
if (!bitmap_is_set(other_bitmap, field->field_index))
|
|
|
|
{
|
|
|
|
/* First usage of column */
|
|
|
|
table->used_fields++; // Used to optimize loops
|
2007-03-14 13:32:12 +02:00
|
|
|
/* purecov: begin inspected */
|
2007-03-05 19:08:41 +02:00
|
|
|
table->covering_keys.intersect(field->part_of_key);
|
2007-03-14 13:32:12 +02:00
|
|
|
/* purecov: end */
|
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 18:52:22 +03:00
|
|
|
}
|
2005-04-28 14:45:27 +02:00
|
|
|
}
|
2001-09-21 03:38:35 +03:00
|
|
|
}
|
2004-07-16 01:15:55 +03:00
|
|
|
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
|
|
|
if (any_privileges)
|
|
|
|
{
|
|
|
|
char *db, *tab;
|
2008-09-03 16:45:40 +02:00
|
|
|
db= cached_table->get_db_name();
|
|
|
|
tab= cached_table->get_table_name();
|
2004-07-16 01:15:55 +03:00
|
|
|
if (!(have_privileges= (get_column_grant(thd, &field->table->grant,
|
|
|
|
db, tab, field_name) &
|
|
|
|
VIEW_ANY_ACL)))
|
|
|
|
{
|
2004-11-13 19:35:51 +02:00
|
|
|
my_error(ER_COLUMNACCESS_DENIED_ERROR, MYF(0),
|
2005-09-15 22:29:07 +03:00
|
|
|
"ANY", thd->security_ctx->priv_user,
|
|
|
|
thd->security_ctx->host_or_ip, field_name, tab);
|
2005-07-01 07:05:42 +03:00
|
|
|
goto error;
|
2004-07-16 01:15:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2002-11-21 11:01:33 +02:00
|
|
|
fixed= 1;
|
2007-01-11 23:18:01 +03:00
|
|
|
if (thd->variables.sql_mode & MODE_ONLY_FULL_GROUP_BY &&
|
|
|
|
!outer_fixed && !thd->lex->in_sum_func &&
|
|
|
|
thd->lex->current_select->cur_pos_in_select_list != UNDEF_POS)
|
|
|
|
{
|
|
|
|
thd->lex->current_select->non_agg_fields.push_back(this);
|
|
|
|
marker= thd->lex->current_select->cur_pos_in_select_list;
|
|
|
|
}
|
2008-03-27 19:49:32 +03:00
|
|
|
mark_non_agg_field:
|
|
|
|
if (fixed && thd->variables.sql_mode & MODE_ONLY_FULL_GROUP_BY)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Mark selects according to presence of non aggregated fields.
|
|
|
|
Fields from outer selects added to the aggregate function
|
|
|
|
outer_fields list as its unknown at the moment whether it's
|
|
|
|
aggregated or not.
|
2009-07-02 17:42:00 +03:00
|
|
|
We're using either the select lex of the cached table (if present)
|
|
|
|
or the field's resolution context. context->select_lex is
|
|
|
|
safe for use because it's either the SELECT we want to use
|
|
|
|
(the current level) or a stub added by non-SELECT queries.
|
2008-03-27 19:49:32 +03:00
|
|
|
*/
|
2009-07-02 17:42:00 +03:00
|
|
|
SELECT_LEX *select_lex= cached_table ?
|
|
|
|
cached_table->select_lex : context->select_lex;
|
2008-03-27 19:49:32 +03:00
|
|
|
if (!thd->lex->in_sum_func)
|
2011-05-04 17:12:45 +02:00
|
|
|
select_lex->set_non_agg_field_used(true);
|
2008-03-27 19:49:32 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (outer_fixed)
|
|
|
|
thd->lex->in_sum_func->outer_fields.push_back(this);
|
|
|
|
else if (thd->lex->in_sum_func->nest_level !=
|
|
|
|
thd->lex->current_select->nest_level)
|
2011-05-04 17:12:45 +02:00
|
|
|
select_lex->set_non_agg_field_used(true);
|
2008-03-27 19:49:32 +03:00
|
|
|
}
|
|
|
|
}
|
2004-11-09 17:56:33 +02:00
|
|
|
return FALSE;
|
2005-07-01 07:05:42 +03:00
|
|
|
|
|
|
|
error:
|
|
|
|
context->process_error(thd);
|
|
|
|
return TRUE;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2004-11-11 11:16:51 +02:00
|
|
|
|
|
|
|
Item *Item_field::safe_charset_converter(CHARSET_INFO *tocs)
|
|
|
|
{
|
|
|
|
no_const_subst= 1;
|
|
|
|
return Item::safe_charset_converter(tocs);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-30 14:08:19 +04:00
|
|
|
void Item_field::cleanup()
|
|
|
|
{
|
2004-02-08 20:14:13 +02:00
|
|
|
DBUG_ENTER("Item_field::cleanup");
|
2003-12-30 14:08:19 +04:00
|
|
|
Item_ident::cleanup();
|
2004-03-17 14:26:26 +02:00
|
|
|
/*
|
|
|
|
Even if this object was created by direct link to field in setup_wild()
|
2005-02-09 02:50:45 +04:00
|
|
|
it will be linked correctly next time by name of field and table alias.
|
2004-03-17 14:26:26 +02:00
|
|
|
I.e. we can drop 'field'.
|
|
|
|
*/
|
2004-01-19 19:53:25 +04:00
|
|
|
field= result_field= 0;
|
2010-03-09 18:55:08 -03:00
|
|
|
item_equal= NULL;
|
2006-09-27 23:11:45 +04:00
|
|
|
null_value= FALSE;
|
2004-11-11 11:16:51 +02:00
|
|
|
DBUG_VOID_RETURN;
|
2004-02-19 12:04:46 -08:00
|
|
|
}
|
2004-02-18 22:21:37 -08:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
|
|
|
Find a field among specified multiple equalities.
|
2004-02-18 22:21:37 -08:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
The function first searches the field among multiple equalities
|
|
|
|
of the current level (in the cond_equal->current_level list).
|
|
|
|
If it fails, it continues searching in upper levels accessed
|
|
|
|
through a pointer cond_equal->upper_levels.
|
|
|
|
The search terminates as soon as a multiple equality containing
|
|
|
|
the field is found.
|
|
|
|
|
|
|
|
@param cond_equal reference to list of multiple equalities where
|
|
|
|
the field (this object) is to be looked for
|
|
|
|
|
|
|
|
@return
|
|
|
|
- First Item_equal containing the field, if success
|
|
|
|
- 0, otherwise
|
2004-02-18 22:21:37 -08:00
|
|
|
*/
|
2007-10-11 13:29:09 -04:00
|
|
|
|
2004-10-19 14:12:55 -07:00
|
|
|
Item_equal *Item_field::find_item_equal(COND_EQUAL *cond_equal)
|
|
|
|
{
|
|
|
|
Item_equal *item= 0;
|
|
|
|
while (cond_equal)
|
|
|
|
{
|
|
|
|
List_iterator_fast<Item_equal> li(cond_equal->current_level);
|
|
|
|
while ((item= li++))
|
|
|
|
{
|
|
|
|
if (item->contains(field))
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
The field is not found in any of the multiple equalities
|
|
|
|
of the current level. Look for it in upper levels
|
|
|
|
*/
|
|
|
|
cond_equal= cond_equal->upper_levels;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
|
|
|
Check whether a field can be substituted by an equal item.
|
2006-09-07 11:06:37 -07:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
The function checks whether a substitution of the field
|
|
|
|
occurrence for an equal item is valid.
|
2006-09-07 11:06:37 -07:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@param arg *arg != NULL <-> the field is in the context where
|
|
|
|
substitution for an equal item is valid
|
|
|
|
|
|
|
|
@note
|
2006-09-07 11:06:37 -07:00
|
|
|
The following statement is not always true:
|
2007-10-11 13:29:09 -04:00
|
|
|
@n
|
2006-09-07 11:06:37 -07:00
|
|
|
x=y => F(x)=F(x/y).
|
2007-10-11 13:29:09 -04:00
|
|
|
@n
|
2006-09-07 11:06:37 -07:00
|
|
|
This means substitution of an item for an equal item not always
|
2007-10-11 13:29:09 -04:00
|
|
|
yields an equavalent condition. Here's an example:
|
|
|
|
@code
|
|
|
|
'a'='a '
|
|
|
|
(LENGTH('a')=1) != (LENGTH('a ')=2)
|
|
|
|
@endcode
|
2006-09-07 11:06:37 -07:00
|
|
|
Such a substitution is surely valid if either the substituted
|
|
|
|
field is not of a STRING type or if it is an argument of
|
2007-10-11 13:29:09 -04:00
|
|
|
a comparison predicate.
|
2006-09-07 11:06:37 -07:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@retval
|
2006-09-07 11:06:37 -07:00
|
|
|
TRUE substitution is valid
|
2007-10-11 13:29:09 -04:00
|
|
|
@retval
|
2006-09-07 11:06:37 -07:00
|
|
|
FALSE otherwise
|
|
|
|
*/
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
bool Item_field::subst_argument_checker(uchar **arg)
|
2006-09-07 11:06:37 -07:00
|
|
|
{
|
|
|
|
return (result_type() != STRING_RESULT) || (*arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-15 15:47:32 +02:00
|
|
|
/**
|
|
|
|
Convert a numeric value to a zero-filled string
|
|
|
|
|
|
|
|
@param[in,out] item the item to operate on
|
|
|
|
@param field The field that this value is equated to
|
|
|
|
|
|
|
|
This function converts a numeric value to a string. In this conversion
|
|
|
|
the zero-fill flag of the field is taken into account.
|
|
|
|
This is required so the resulting string value can be used instead of
|
|
|
|
the field reference when propagating equalities.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void convert_zerofill_number_to_string(Item **item, Field_num *field)
|
|
|
|
{
|
|
|
|
char buff[MAX_FIELD_WIDTH],*pos;
|
|
|
|
String tmp(buff,sizeof(buff), field->charset()), *res;
|
|
|
|
|
|
|
|
res= (*item)->val_str(&tmp);
|
2008-04-22 02:53:12 +04:00
|
|
|
if ((*item)->is_null())
|
|
|
|
*item= new Item_null();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
field->prepend_zeros(res);
|
|
|
|
pos= (char *) sql_strmake (res->ptr(), res->length());
|
|
|
|
*item= new Item_string(pos, res->length(), field->charset());
|
|
|
|
}
|
2008-02-15 15:47:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
2004-11-11 11:16:51 +02:00
|
|
|
Set a pointer to the multiple equality the field reference belongs to
|
2007-10-11 13:29:09 -04:00
|
|
|
(if any).
|
2004-10-19 14:12:55 -07:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
The function looks for a multiple equality containing the field item
|
|
|
|
among those referenced by arg.
|
|
|
|
In the case such equality exists the function does the following.
|
|
|
|
If the found multiple equality contains a constant, then the field
|
|
|
|
reference is substituted for this constant, otherwise it sets a pointer
|
|
|
|
to the multiple equality in the field item.
|
|
|
|
|
|
|
|
|
|
|
|
@param arg reference to list of multiple equalities where
|
|
|
|
the field (this object) is to be looked for
|
|
|
|
|
|
|
|
@note
|
2004-10-19 14:12:55 -07:00
|
|
|
This function is supposed to be called as a callback parameter in calls
|
2007-10-11 13:29:09 -04:00
|
|
|
of the compile method.
|
2004-10-19 14:12:55 -07:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@return
|
|
|
|
- pointer to the replacing constant item, if the field item was substituted
|
|
|
|
- pointer to the field item, otherwise.
|
2004-10-19 14:12:55 -07:00
|
|
|
*/
|
2004-02-18 22:21:37 -08:00
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
Item *Item_field::equal_fields_propagator(uchar *arg)
|
2004-10-19 14:12:55 -07:00
|
|
|
{
|
|
|
|
if (no_const_subst)
|
|
|
|
return this;
|
|
|
|
item_equal= find_item_equal((COND_EQUAL *) arg);
|
|
|
|
Item *item= 0;
|
|
|
|
if (item_equal)
|
|
|
|
item= item_equal->get_const();
|
2006-08-21 00:23:57 +04:00
|
|
|
/*
|
|
|
|
Disable const propagation for items used in different comparison contexts.
|
|
|
|
This must be done because, for example, Item_hex_string->val_int() is not
|
|
|
|
the same as (Item_hex_string->val_str() in BINARY column)->val_int().
|
|
|
|
We cannot simply disable the replacement in a particular context (
|
|
|
|
e.g. <bin_col> = <int_col> AND <bin_col> = <hex_string>) since
|
|
|
|
Items don't know the context they are in and there are functions like
|
|
|
|
IF (<hex_string>, 'yes', 'no').
|
|
|
|
*/
|
2010-07-19 21:11:47 +04:00
|
|
|
if (!item || !has_compatible_context(item))
|
2004-10-19 14:12:55 -07:00
|
|
|
item= this;
|
2008-02-15 15:47:32 +02:00
|
|
|
else if (field && (field->flags & ZEROFILL_FLAG) && IS_NUM(field->type()))
|
|
|
|
{
|
2008-09-18 15:55:36 +03:00
|
|
|
/*
|
|
|
|
We don't need to zero-fill timestamp columns here because they will be
|
|
|
|
first converted to a string (in date/time format) and compared as such if
|
|
|
|
compared with another string.
|
|
|
|
*/
|
|
|
|
if (item && field->type() != FIELD_TYPE_TIMESTAMP && cmp_context != INT_RESULT)
|
2008-02-15 15:47:32 +02:00
|
|
|
convert_zerofill_number_to_string(&item, (Field_num *)field);
|
|
|
|
else
|
|
|
|
item= this;
|
|
|
|
}
|
2004-10-19 14:12:55 -07:00
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
|
|
|
Mark the item to not be part of substitution if it's not a binary item.
|
|
|
|
|
|
|
|
See comments in Arg_comparator::set_compare_func() for details.
|
2004-11-11 11:16:51 +02:00
|
|
|
*/
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
bool Item_field::set_no_const_sub(uchar *arg)
|
2004-11-11 11:16:51 +02:00
|
|
|
{
|
|
|
|
if (field->charset() != &my_charset_bin)
|
|
|
|
no_const_subst=1;
|
2006-08-24 15:49:12 +04:00
|
|
|
return FALSE;
|
2004-11-11 11:16:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
2005-04-15 20:43:45 -07:00
|
|
|
Replace an Item_field for an equal Item_field that evaluated earlier
|
2007-10-11 13:29:09 -04:00
|
|
|
(if any).
|
2004-10-19 14:12:55 -07:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
The function returns a pointer to an item that is taken from
|
|
|
|
the very beginning of the item_equal list which the Item_field
|
|
|
|
object refers to (belongs to) unless item_equal contains a constant
|
|
|
|
item. In this case the function returns this constant item,
|
|
|
|
(if the substitution does not require conversion).
|
|
|
|
If the Item_field object does not refer any Item_equal object
|
|
|
|
'this' is returned .
|
|
|
|
|
|
|
|
@param arg a dummy parameter, is not used here
|
|
|
|
|
|
|
|
|
|
|
|
@note
|
2004-10-19 14:12:55 -07:00
|
|
|
This function is supposed to be called as a callback parameter in calls
|
2007-10-11 13:29:09 -04:00
|
|
|
of the thransformer method.
|
2004-10-19 14:12:55 -07:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@return
|
|
|
|
- pointer to a replacement Item_field if there is a better equal item or
|
|
|
|
a pointer to a constant equal item;
|
|
|
|
- this - otherwise.
|
2004-10-19 14:12:55 -07:00
|
|
|
*/
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
Item *Item_field::replace_equal_field(uchar *arg)
|
2004-10-19 14:12:55 -07:00
|
|
|
{
|
|
|
|
if (item_equal)
|
|
|
|
{
|
2007-03-11 23:34:40 -07:00
|
|
|
Item *const_item= item_equal->get_const();
|
|
|
|
if (const_item)
|
|
|
|
{
|
2010-07-19 21:11:47 +04:00
|
|
|
if (!has_compatible_context(const_item))
|
2007-03-11 23:34:40 -07:00
|
|
|
return this;
|
|
|
|
return const_item;
|
|
|
|
}
|
2004-10-19 14:12:55 -07:00
|
|
|
Item_field *subst= item_equal->get_first();
|
2009-04-28 05:19:13 +05:00
|
|
|
if (subst && field->table != subst->field->table && !field->eq(subst->field))
|
2005-04-15 20:43:45 -07:00
|
|
|
return subst;
|
2004-10-19 14:12:55 -07:00
|
|
|
}
|
2005-04-15 20:43:45 -07:00
|
|
|
return this;
|
2003-12-30 14:08:19 +04:00
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2004-11-11 11:16:51 +02:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
void Item::init_make_field(Send_field *tmp_field,
|
2006-12-15 00:51:37 +02:00
|
|
|
enum enum_field_types field_type_arg)
|
2003-10-11 13:06:55 +02:00
|
|
|
{
|
2003-02-04 03:19:19 +02:00
|
|
|
char *empty_name= (char*) "";
|
2003-10-11 13:06:55 +02:00
|
|
|
tmp_field->db_name= empty_name;
|
2003-02-04 03:19:19 +02:00
|
|
|
tmp_field->org_table_name= empty_name;
|
|
|
|
tmp_field->org_col_name= empty_name;
|
|
|
|
tmp_field->table_name= empty_name;
|
|
|
|
tmp_field->col_name= name;
|
2003-10-11 13:06:55 +02:00
|
|
|
tmp_field->charsetnr= collation.collation->number;
|
2004-11-11 11:16:51 +02:00
|
|
|
tmp_field->flags= (maybe_null ? 0 : NOT_NULL_FLAG) |
|
WL#2649 Number-to-string conversions
added:
include/ctype_numconv.inc
mysql-test/include/ctype_numconv.inc
mysql-test/r/ctype_binary.result
mysql-test/t/ctype_binary.test
Adding tests
modified:
mysql-test/r/bigint.result
mysql-test/r/case.result
mysql-test/r/create.result
mysql-test/r/ctype_cp1251.result
mysql-test/r/ctype_latin1.result
mysql-test/r/ctype_ucs.result
mysql-test/r/func_gconcat.result
mysql-test/r/func_str.result
mysql-test/r/metadata.result
mysql-test/r/ps_1general.result
mysql-test/r/ps_2myisam.result
mysql-test/r/ps_3innodb.result
mysql-test/r/ps_4heap.result
mysql-test/r/ps_5merge.result
mysql-test/r/show_check.result
mysql-test/r/type_datetime.result
mysql-test/r/type_ranges.result
mysql-test/r/union.result
mysql-test/suite/ndb/r/ps_7ndb.result
mysql-test/t/ctype_cp1251.test
mysql-test/t/ctype_latin1.test
mysql-test/t/ctype_ucs.test
mysql-test/t/func_str.test
Fixing tests
@ sql/field.cc
- Return str result using my_charset_numeric.
- Using real multi-byte aware str_to_XXX functions
to handle tricky charset values propely (e.g. UCS2)
@ sql/field.h
- Changing derivation of non-string field types to DERIVATION_NUMERIC.
- Changing binary() for numeric/datetime fields to always
return TRUE even if charset is not my_charset_bin. We need
this to keep ha_base_keytype() return HA_KEYTYPE_BINARY.
- Adding BINARY_FLAG into some fields, because it's not
being set automatically anymore with
"my_charset_bin to my_charset_numeric" change.
- Changing derivation for numeric/datetime datatypes to a weaker
value, to make "SELECT concat('string', field)" use character
set of the string literal for the result of the function.
@ sql/item.cc
- Implementing generic val_str_ascii().
- Using max_char_length() instead of direct read of max_length
to make "tricky" charsets like UCS2 work.
NOTE: in the future we'll possibly remove all direct reads of max_length
- Fixing Item_num::safe_charset_converter().
Previously it alligned binary string to
character string (for example by adding leading 0x00
when doing binary->UCS2 conversion). Now it just
converts from my_charset_numbner to "tocs".
- Using val_str_ascii() in Item::get_time() to make UCS2 arguments work.
- Other misc changes
@ sql/item.h
- Changing MY_COLL_CMP_CONV and MY_COLL_ALLOW_CONV to
bit operations instead of hard-coded bit masks.
- Addding new method DTCollation.set_numeric().
- Adding new methods to Item.
- Adding helper functions to make code look nicer:
agg_item_charsets_for_string_result()
agg_item_charsets_for_comparison()
- Changing charset for Item_num-derived items
from my_charset_bin to my_charset_numeric
(which is an alias for latin1).
@ sql/item_cmpfunc.cc
- Using new helper functions
- Other misc changes
@ sql/item_cmpfunc.h
- Fixing strcmp() to return max_length=2.
Previously it returned 1, which was wrong,
because it did not fit '-1'.
@ sql/item_func.cc
- Using new helper functions
- Other minor changes
@ sql/item_func.h
- Removing unused functions
- Adding helper functions
agg_arg_charsets_for_string_result()
agg_arg_charsets_for_comparison()
- Adding set_numeric() into constructors of numeric items.
- Using fix_length_and_charset() and fix_char_length()
instead of direct write to max_length.
@ sql/item_geofunc.cc
- Changing class for Item_func_geometry_type and
Item_func_as_wkt from Item_str_func to
Item_str_ascii_func, to make them return UCS2 result
properly (when character_set_connection=ucs2).
@ sql/item_geofunc.h
- Changing class for Item_func_geometry_type and
Item_func_as_wkt from Item_str_func to
Item_str_ascii_func, to make them return UCS2 result
properly (when @@character_set_connection=ucs2).
@ sql/item_strfunc.cc
- Implementing Item_str_func::val_str().
- Renaming val_str to val_str_ascii for some items,
to make them work with UCS2 properly.
- Using new helper functions
- All single-argument functions that expect string
result now call this method:
agg_arg_charsets_for_string_result(collation, args, 1);
This enables character set conversion to @@character_set_connection
in case of pure numeric input.
@ sql/item_strfunc.h
- Introducing Item_str_ascii_func - for functions
which return pure ASCII data, for performance purposes,
as well as for the cases when the old implementation
of val_str() was heavily 8-bit oriented and implementing
a UCS2-aware version is tricky.
@ sql/item_sum.cc
- Using new helper functions.
@ sql/item_timefunc.cc
- Using my_charset_numeric instead of my_charset_bin.
- Using fix_char_length(), fix_length_and_charset()
and fix_length_and_charset_datetime()
instead of direct write to max_length.
- Using tricky-charset aware function str_to_time_with_warn()
@ sql/item_timefunc.h
- Using new helper functions for charset and length initialization.
- Changing base class for Item_func_get_format() to make
it return UCS2 properly (when character_set_connection=ucs2).
@ sql/item_xmlfunc.cc
- Using new helper function
@ sql/my_decimal.cc
- Adding a new DECIMAL to CHAR converter
with real multibyte support (e.g. UCS2)
@ sql/mysql_priv.h
- Introducing a new derivation level for numeric/datetime data types.
- Adding macros for my_charset_numeric and MY_REPERTOIRE_NUMERIC.
- Adding prototypes for str_set_decimal()
- Adding prototypes for character-set aware str_to_xxx() functions.
@ sql/protocol.cc
- Changing charsetnr to "binary" client-side metadata for
numeric/datetime data types.
@ sql/time.cc
- Adding to_ascii() helper function, to convert a string
in any character set to ascii representation. In the
future can be extended to understand digits written
in various non-Latin word scripts.
- Adding real multy-byte character set aware versions for str_to_XXXX,
to make these these type of queries work correct:
INSERT INTO t1 SET datetime_column=ucs2_expression;
@ strings/ctype-ucs2.c
- endptr was not calculated correctly. INSERTing of UCS2
values into numeric columns returned warnings about
truncated wrong data.
2010-02-11 08:17:25 +04:00
|
|
|
(my_binary_compare(charset_for_protocol()) ?
|
2004-11-11 11:16:51 +02:00
|
|
|
BINARY_FLAG : 0);
|
2006-12-15 00:51:37 +02:00
|
|
|
tmp_field->type= field_type_arg;
|
2000-07-31 21:29:14 +02:00
|
|
|
tmp_field->length=max_length;
|
|
|
|
tmp_field->decimals=decimals;
|
2001-09-27 21:45:48 +03:00
|
|
|
if (unsigned_flag)
|
|
|
|
tmp_field->flags |= UNSIGNED_FLAG;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2002-12-11 09:17:51 +02:00
|
|
|
void Item::make_field(Send_field *tmp_field)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2002-12-11 09:17:51 +02:00
|
|
|
init_make_field(tmp_field, field_type());
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-22 16:35:52 +03:00
|
|
|
enum_field_types Item::string_field_type() const
|
2003-08-21 20:21:07 +02:00
|
|
|
{
|
2007-01-27 03:46:45 +02:00
|
|
|
enum_field_types f_type= MYSQL_TYPE_VAR_STRING;
|
2005-07-19 11:05:49 -07:00
|
|
|
if (max_length >= 16777216)
|
2007-01-27 03:46:45 +02:00
|
|
|
f_type= MYSQL_TYPE_LONG_BLOB;
|
2005-07-19 11:05:49 -07:00
|
|
|
else if (max_length >= 65536)
|
2007-01-27 03:46:45 +02:00
|
|
|
f_type= MYSQL_TYPE_MEDIUM_BLOB;
|
2007-01-29 01:47:35 +02:00
|
|
|
return f_type;
|
2006-09-22 16:35:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Item_empty_string::make_field(Send_field *tmp_field)
|
|
|
|
{
|
|
|
|
init_make_field(tmp_field, string_field_type());
|
2003-08-21 20:21:07 +02:00
|
|
|
}
|
|
|
|
|
2002-07-25 01:00:56 +03:00
|
|
|
|
2002-12-11 09:17:51 +02:00
|
|
|
enum_field_types Item::field_type() const
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2005-02-15 16:45:00 +02:00
|
|
|
switch (result_type()) {
|
2006-09-22 16:35:52 +03:00
|
|
|
case STRING_RESULT: return string_field_type();
|
2006-12-01 17:26:52 -08:00
|
|
|
case INT_RESULT: return MYSQL_TYPE_LONGLONG;
|
|
|
|
case DECIMAL_RESULT: return MYSQL_TYPE_NEWDECIMAL;
|
|
|
|
case REAL_RESULT: return MYSQL_TYPE_DOUBLE;
|
2005-02-09 02:50:45 +04:00
|
|
|
case ROW_RESULT:
|
|
|
|
default:
|
|
|
|
DBUG_ASSERT(0);
|
2005-02-15 16:45:00 +02:00
|
|
|
return MYSQL_TYPE_VARCHAR;
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2003-11-03 14:01:59 +02:00
|
|
|
|
2014-07-07 12:05:30 +02:00
|
|
|
/**
|
|
|
|
Verifies that the input string is well-formed according to its character set.
|
|
|
|
@param send_error If true, call my_error if string is not well-formed.
|
2015-07-10 07:52:00 +05:30
|
|
|
@param truncate If true, set to null/truncate if not well-formed.
|
2014-07-07 12:05:30 +02:00
|
|
|
|
|
|
|
@return
|
|
|
|
If well-formed: input string.
|
|
|
|
If not well-formed:
|
2015-07-10 07:52:00 +05:30
|
|
|
if truncate is true and strict mode: NULL pointer and we set this
|
|
|
|
Item's value to NULL.
|
|
|
|
if truncate is true and not strict mode: input string truncated up to
|
|
|
|
last good character.
|
|
|
|
if truncate is false: input string is returned.
|
2014-07-07 12:05:30 +02:00
|
|
|
*/
|
2015-07-10 07:52:00 +05:30
|
|
|
String *Item::check_well_formed_result(String *str,
|
|
|
|
bool send_error,
|
|
|
|
bool truncate)
|
2007-10-11 16:07:10 +05:00
|
|
|
{
|
|
|
|
/* Check whether we got a well-formed string */
|
|
|
|
CHARSET_INFO *cs= str->charset();
|
2015-07-10 07:52:00 +05:30
|
|
|
|
|
|
|
size_t valid_length;
|
|
|
|
bool length_error;
|
|
|
|
|
|
|
|
if (validate_string(cs, str->ptr(), str->length(),
|
|
|
|
&valid_length, &length_error))
|
2007-10-11 16:07:10 +05:00
|
|
|
{
|
2015-07-10 07:52:00 +05:30
|
|
|
const char *str_end= str->ptr() + str->length();
|
|
|
|
const char *print_byte= str->ptr() + valid_length;
|
2007-10-11 16:07:10 +05:00
|
|
|
THD *thd= current_thd;
|
|
|
|
char hexbuf[7];
|
2015-07-10 07:52:00 +05:30
|
|
|
uint diff= str_end - print_byte;
|
2007-10-11 16:07:10 +05:00
|
|
|
set_if_smaller(diff, 3);
|
2015-07-10 07:52:00 +05:30
|
|
|
octet2hex(hexbuf, print_byte, diff);
|
|
|
|
if (send_error && length_error)
|
2007-10-15 18:40:58 +05:00
|
|
|
{
|
|
|
|
my_error(ER_INVALID_CHARACTER_STRING, MYF(0),
|
|
|
|
cs->csname, hexbuf);
|
|
|
|
return 0;
|
|
|
|
}
|
2015-07-10 07:52:00 +05:30
|
|
|
if (truncate && length_error)
|
2007-10-11 16:07:10 +05:00
|
|
|
{
|
2015-07-10 07:52:00 +05:30
|
|
|
if ((thd->variables.sql_mode &
|
|
|
|
(MODE_STRICT_TRANS_TABLES | MODE_STRICT_ALL_TABLES)))
|
|
|
|
{
|
|
|
|
null_value= 1;
|
|
|
|
str= 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
str->length(valid_length);
|
|
|
|
}
|
2007-10-11 16:07:10 +05:00
|
|
|
}
|
2009-09-10 03:18:29 -06:00
|
|
|
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_INVALID_CHARACTER_STRING,
|
2007-10-11 16:07:10 +05:00
|
|
|
ER(ER_INVALID_CHARACTER_STRING), cs->csname, hexbuf);
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2008-01-26 21:45:35 -08:00
|
|
|
/*
|
|
|
|
Compare two items using a given collation
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
eq_by_collation()
|
|
|
|
item item to compare with
|
|
|
|
binary_cmp TRUE <-> compare as binaries
|
|
|
|
cs collation to use when comparing strings
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
This method works exactly as Item::eq if the collation cs coincides with
|
|
|
|
the collation of the compared objects. Otherwise, first the collations that
|
|
|
|
differ from cs are replaced for cs and then the items are compared by
|
|
|
|
Item::eq. After the comparison the original collations of items are
|
|
|
|
restored.
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
1 compared items has been detected as equal
|
|
|
|
0 otherwise
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool Item::eq_by_collation(Item *item, bool binary_cmp, CHARSET_INFO *cs)
|
|
|
|
{
|
|
|
|
CHARSET_INFO *save_cs= 0;
|
|
|
|
CHARSET_INFO *save_item_cs= 0;
|
|
|
|
if (collation.collation != cs)
|
|
|
|
{
|
|
|
|
save_cs= collation.collation;
|
|
|
|
collation.collation= cs;
|
|
|
|
}
|
|
|
|
if (item->collation.collation != cs)
|
|
|
|
{
|
|
|
|
save_item_cs= item->collation.collation;
|
|
|
|
item->collation.collation= cs;
|
|
|
|
}
|
|
|
|
bool res= eq(item, binary_cmp);
|
|
|
|
if (save_cs)
|
|
|
|
collation.collation= save_cs;
|
|
|
|
if (save_item_cs)
|
|
|
|
item->collation.collation= save_item_cs;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2007-10-11 16:07:10 +05:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
|
|
|
Create a field to hold a string value from an item.
|
2004-12-07 15:47:00 +02:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
If max_length > CONVERT_IF_BIGGER_TO_BLOB create a blob @n
|
|
|
|
If max_length > 0 create a varchar @n
|
2014-08-21 16:42:04 +02:00
|
|
|
If max_length == 0 create a CHAR(0) (or VARCHAR(0) if we are grouping)
|
2004-12-07 15:47:00 +02:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@param table Table for which the field is created
|
2004-12-07 15:47:00 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
Field *Item::make_string_field(TABLE *table)
|
|
|
|
{
|
2005-11-23 22:45:02 +02:00
|
|
|
Field *field;
|
2005-08-31 22:06:34 +04:00
|
|
|
DBUG_ASSERT(collation.collation);
|
|
|
|
if (max_length/collation.collation->mbmaxlen > CONVERT_IF_BIGGER_TO_BLOB)
|
2005-11-23 22:45:02 +02:00
|
|
|
field= new Field_blob(max_length, maybe_null, name,
|
2009-11-21 20:31:00 +03:00
|
|
|
collation.collation, TRUE);
|
2006-07-22 02:08:00 +04:00
|
|
|
/* Item_type_holder holds the exact type, do not change it */
|
2006-07-30 00:33:24 +04:00
|
|
|
else if (max_length > 0 &&
|
2006-07-22 02:08:00 +04:00
|
|
|
(type() != Item::TYPE_HOLDER || field_type() != MYSQL_TYPE_STRING))
|
2005-11-23 22:45:02 +02:00
|
|
|
field= new Field_varstring(max_length, maybe_null, name, table->s,
|
2004-12-07 15:47:00 +02:00
|
|
|
collation.collation);
|
2005-11-23 22:45:02 +02:00
|
|
|
else
|
2014-08-21 16:42:04 +02:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
marker == 4 : see create_tmp_table()
|
|
|
|
With CHAR(0) end_update() may write garbage into the next field.
|
|
|
|
*/
|
|
|
|
if (max_length == 0 && marker == 4 && maybe_null &&
|
|
|
|
field_type() == MYSQL_TYPE_VAR_STRING && type() != Item::TYPE_HOLDER)
|
|
|
|
field= new Field_varstring(max_length, maybe_null, name, table->s,
|
|
|
|
collation.collation);
|
|
|
|
else
|
|
|
|
field= new Field_string(max_length, maybe_null, name,
|
|
|
|
collation.collation);
|
|
|
|
}
|
2005-11-23 22:45:02 +02:00
|
|
|
if (field)
|
|
|
|
field->init(table);
|
|
|
|
return field;
|
2004-12-07 15:47:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
|
|
|
Create a field based on field_type of argument.
|
2004-12-06 02:00:37 +02:00
|
|
|
|
|
|
|
For now, this is only used to create a field for
|
2005-11-23 22:45:02 +02:00
|
|
|
IFNULL(x,something) and time functions
|
2004-12-06 02:00:37 +02:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@retval
|
|
|
|
NULL error
|
|
|
|
@retval
|
|
|
|
\# Created field
|
2004-12-06 02:00:37 +02:00
|
|
|
*/
|
|
|
|
|
2005-11-23 22:45:02 +02:00
|
|
|
Field *Item::tmp_table_field_from_field_type(TABLE *table, bool fixed_length)
|
2003-08-27 19:11:54 -04:00
|
|
|
{
|
2003-12-15 17:58:15 +02:00
|
|
|
/*
|
|
|
|
The field functions defines a field to be not null if null_ptr is not 0
|
|
|
|
*/
|
|
|
|
uchar *null_ptr= maybe_null ? (uchar*) "" : 0;
|
2005-11-23 22:45:02 +02:00
|
|
|
Field *field;
|
2003-12-15 17:58:15 +02:00
|
|
|
|
|
|
|
switch (field_type()) {
|
2003-08-27 19:11:54 -04:00
|
|
|
case MYSQL_TYPE_DECIMAL:
|
2005-02-09 02:50:45 +04:00
|
|
|
case MYSQL_TYPE_NEWDECIMAL:
|
2009-11-20 12:10:47 +02:00
|
|
|
field= Field_new_decimal::create_from_item(this);
|
2005-11-23 22:45:02 +02:00
|
|
|
break;
|
2003-08-27 19:11:54 -04:00
|
|
|
case MYSQL_TYPE_TINY:
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
field= new Field_tiny((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
|
2005-11-23 22:45:02 +02:00
|
|
|
name, 0, unsigned_flag);
|
|
|
|
break;
|
2003-08-27 19:11:54 -04:00
|
|
|
case MYSQL_TYPE_SHORT:
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
field= new Field_short((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
|
2005-11-23 22:45:02 +02:00
|
|
|
name, 0, unsigned_flag);
|
|
|
|
break;
|
2003-08-27 19:11:54 -04:00
|
|
|
case MYSQL_TYPE_LONG:
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
field= new Field_long((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
|
2005-11-23 22:45:02 +02:00
|
|
|
name, 0, unsigned_flag);
|
|
|
|
break;
|
2003-08-27 19:11:54 -04:00
|
|
|
#ifdef HAVE_LONG_LONG
|
|
|
|
case MYSQL_TYPE_LONGLONG:
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
field= new Field_longlong((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
|
2005-11-23 22:45:02 +02:00
|
|
|
name, 0, unsigned_flag);
|
|
|
|
break;
|
2003-08-27 19:11:54 -04:00
|
|
|
#endif
|
2003-12-15 17:58:15 +02:00
|
|
|
case MYSQL_TYPE_FLOAT:
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
field= new Field_float((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
|
2005-11-23 22:45:02 +02:00
|
|
|
name, decimals, 0, unsigned_flag);
|
|
|
|
break;
|
2003-12-15 17:58:15 +02:00
|
|
|
case MYSQL_TYPE_DOUBLE:
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
field= new Field_double((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
|
2005-11-23 22:45:02 +02:00
|
|
|
name, decimals, 0, unsigned_flag);
|
|
|
|
break;
|
2003-12-15 17:58:15 +02:00
|
|
|
case MYSQL_TYPE_NULL:
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
field= new Field_null((uchar*) 0, max_length, Field::NONE,
|
2005-11-23 22:45:02 +02:00
|
|
|
name, &my_charset_bin);
|
|
|
|
break;
|
2003-08-27 19:11:54 -04:00
|
|
|
case MYSQL_TYPE_INT24:
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
field= new Field_medium((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
|
2005-11-23 22:45:02 +02:00
|
|
|
name, 0, unsigned_flag);
|
|
|
|
break;
|
2005-03-23 08:36:48 +02:00
|
|
|
case MYSQL_TYPE_NEWDATE:
|
2003-08-27 19:11:54 -04:00
|
|
|
case MYSQL_TYPE_DATE:
|
2008-01-08 11:49:40 +02:00
|
|
|
field= new Field_newdate(maybe_null, name, &my_charset_bin);
|
2005-11-23 22:45:02 +02:00
|
|
|
break;
|
2003-08-27 19:11:54 -04:00
|
|
|
case MYSQL_TYPE_TIME:
|
2005-11-23 22:45:02 +02:00
|
|
|
field= new Field_time(maybe_null, name, &my_charset_bin);
|
|
|
|
break;
|
2003-08-27 19:11:54 -04:00
|
|
|
case MYSQL_TYPE_TIMESTAMP:
|
2006-08-01 08:49:43 +04:00
|
|
|
field= new Field_timestamp(maybe_null, name, &my_charset_bin);
|
|
|
|
break;
|
2003-08-27 19:11:54 -04:00
|
|
|
case MYSQL_TYPE_DATETIME:
|
2005-11-23 22:45:02 +02:00
|
|
|
field= new Field_datetime(maybe_null, name, &my_charset_bin);
|
|
|
|
break;
|
2003-08-27 19:11:54 -04:00
|
|
|
case MYSQL_TYPE_YEAR:
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
field= new Field_year((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
|
2005-11-23 22:45:02 +02:00
|
|
|
name);
|
|
|
|
break;
|
2005-06-30 13:38:29 +05:00
|
|
|
case MYSQL_TYPE_BIT:
|
2006-02-02 16:57:34 +03:00
|
|
|
field= new Field_bit_as_char(NULL, max_length, null_ptr, 0,
|
2005-11-23 22:45:02 +02:00
|
|
|
Field::NONE, name);
|
|
|
|
break;
|
2003-12-15 17:58:15 +02:00
|
|
|
default:
|
2004-12-07 15:47:00 +02:00
|
|
|
/* This case should never be chosen */
|
2003-12-15 17:58:15 +02:00
|
|
|
DBUG_ASSERT(0);
|
|
|
|
/* If something goes awfully wrong, it's better to get a string than die */
|
2005-11-23 22:45:02 +02:00
|
|
|
case MYSQL_TYPE_STRING:
|
|
|
|
if (fixed_length && max_length < CONVERT_IF_BIGGER_TO_BLOB)
|
|
|
|
{
|
|
|
|
field= new Field_string(max_length, maybe_null, name,
|
|
|
|
collation.collation);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Fall through to make_string_field() */
|
2003-08-27 19:11:54 -04:00
|
|
|
case MYSQL_TYPE_ENUM:
|
|
|
|
case MYSQL_TYPE_SET:
|
2003-12-15 17:58:15 +02:00
|
|
|
case MYSQL_TYPE_VAR_STRING:
|
2004-12-06 02:00:37 +02:00
|
|
|
case MYSQL_TYPE_VARCHAR:
|
2004-12-07 15:47:00 +02:00
|
|
|
return make_string_field(table);
|
2003-08-27 19:11:54 -04:00
|
|
|
case MYSQL_TYPE_TINY_BLOB:
|
|
|
|
case MYSQL_TYPE_MEDIUM_BLOB:
|
|
|
|
case MYSQL_TYPE_LONG_BLOB:
|
|
|
|
case MYSQL_TYPE_BLOB:
|
2006-07-22 02:08:00 +04:00
|
|
|
if (this->type() == Item::TYPE_HOLDER)
|
2006-08-01 08:49:43 +04:00
|
|
|
field= new Field_blob(max_length, maybe_null, name, collation.collation,
|
|
|
|
1);
|
2006-07-22 02:08:00 +04:00
|
|
|
else
|
2006-08-01 08:49:43 +04:00
|
|
|
field= new Field_blob(max_length, maybe_null, name, collation.collation);
|
2003-12-15 17:58:15 +02:00
|
|
|
break; // Blob handled outside of case
|
2007-09-28 17:10:14 -04:00
|
|
|
#ifdef HAVE_SPATIAL
|
2007-03-28 14:35:23 +03:00
|
|
|
case MYSQL_TYPE_GEOMETRY:
|
2007-10-12 15:33:26 +05:00
|
|
|
field= new Field_geom(max_length, maybe_null,
|
|
|
|
name, table->s, get_geometry_type());
|
2007-09-28 17:10:14 -04:00
|
|
|
#endif /* HAVE_SPATIAL */
|
2003-08-27 19:11:54 -04:00
|
|
|
}
|
2005-11-23 22:45:02 +02:00
|
|
|
if (field)
|
|
|
|
field->init(table);
|
|
|
|
return field;
|
2003-08-27 19:11:54 -04:00
|
|
|
}
|
|
|
|
|
2003-12-15 17:58:15 +02:00
|
|
|
|
2002-12-11 09:17:51 +02:00
|
|
|
/* ARGSUSED */
|
|
|
|
void Item_field::make_field(Send_field *tmp_field)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2002-12-11 09:17:51 +02:00
|
|
|
field->make_field(tmp_field);
|
2005-02-25 16:53:22 +02:00
|
|
|
DBUG_ASSERT(tmp_field->table_name != 0);
|
2002-12-11 09:17:51 +02:00
|
|
|
if (name)
|
|
|
|
tmp_field->col_name=name; // Use user supplied name
|
2006-11-09 16:55:42 +02:00
|
|
|
if (table_name)
|
|
|
|
tmp_field->table_name= table_name;
|
|
|
|
if (db_name)
|
|
|
|
tmp_field->db_name= db_name;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2004-05-05 12:31:17 +03:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
|
|
|
Set a field's value from a item.
|
2000-07-31 21:29:14 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
void Item_field::save_org_in_field(Field *to)
|
|
|
|
{
|
|
|
|
if (field->is_null())
|
|
|
|
{
|
|
|
|
null_value=1;
|
2002-12-03 13:08:25 +02:00
|
|
|
set_field_to_null_with_conversions(to, 1);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
to->set_notnull();
|
|
|
|
field_conv(to,field);
|
|
|
|
null_value=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-05 19:38:42 +02:00
|
|
|
int Item_field::save_in_field(Field *to, bool no_conversions)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2007-02-06 11:08:57 +02:00
|
|
|
int res;
|
2000-07-31 21:29:14 +02:00
|
|
|
if (result_field->is_null())
|
|
|
|
{
|
|
|
|
null_value=1;
|
2010-03-23 17:07:00 +02:00
|
|
|
return set_field_to_null_with_conversions(to, no_conversions);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2010-03-23 17:07:00 +02:00
|
|
|
to->set_notnull();
|
|
|
|
|
|
|
|
/*
|
|
|
|
If we're setting the same field as the one we're reading from there's
|
|
|
|
nothing to do. This can happen in 'SET x = x' type of scenarios.
|
|
|
|
*/
|
|
|
|
if (to == result_field)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
null_value=0;
|
2010-03-23 17:07:00 +02:00
|
|
|
return 0;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2010-03-23 17:07:00 +02:00
|
|
|
|
|
|
|
res= field_conv(to,result_field);
|
|
|
|
null_value=0;
|
2007-02-06 11:08:57 +02:00
|
|
|
return res;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2002-10-16 10:32:45 +03:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
|
|
|
Store null in field.
|
2002-10-16 22:48:51 +03:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
This is used on INSERT.
|
|
|
|
Allow NULL to be inserted in timestamp and auto_increment values.
|
2002-10-16 22:48:51 +03:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@param field Field where we want to store NULL
|
2002-10-16 22:48:51 +03:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@retval
|
|
|
|
0 ok
|
|
|
|
@retval
|
|
|
|
1 Field doesn't support NULL values and can't handle 'field = NULL'
|
|
|
|
*/
|
2002-10-16 22:48:51 +03:00
|
|
|
|
2002-12-05 19:38:42 +02:00
|
|
|
int Item_null::save_in_field(Field *field, bool no_conversions)
|
2002-10-16 22:48:51 +03:00
|
|
|
{
|
2002-12-03 13:08:25 +02:00
|
|
|
return set_field_to_null_with_conversions(field, no_conversions);
|
2002-10-16 22:48:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
|
|
|
Store null in field.
|
2002-10-16 10:32:45 +03:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@param field Field where we want to store NULL
|
2002-10-16 10:32:45 +03:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@retval
|
2005-02-09 02:50:45 +04:00
|
|
|
0 OK
|
2007-10-11 13:29:09 -04:00
|
|
|
@retval
|
2002-10-16 10:32:45 +03:00
|
|
|
1 Field doesn't support NULL values
|
2007-10-11 13:29:09 -04:00
|
|
|
*/
|
2002-10-16 10:32:45 +03:00
|
|
|
|
2002-10-16 19:30:24 +03:00
|
|
|
int Item_null::save_safe_in_field(Field *field)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
return set_field_to_null(field);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-27 18:42:25 +05:00
|
|
|
/*
|
|
|
|
This implementation can lose str_value content, so if the
|
|
|
|
Item uses str_value to store something, it should
|
2009-05-21 13:06:43 +05:00
|
|
|
reimplement it's ::save_in_field() as Item_string, for example, does.
|
|
|
|
|
|
|
|
Note: all Item_XXX::val_str(str) methods must NOT rely on the fact that
|
|
|
|
str != str_value. For example, see fix for bug #44743.
|
2007-07-27 18:42:25 +05:00
|
|
|
*/
|
|
|
|
|
2002-12-05 19:38:42 +02:00
|
|
|
int Item::save_in_field(Field *field, bool no_conversions)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2002-08-24 14:49:04 +03:00
|
|
|
int error;
|
2009-12-22 19:23:13 +03:00
|
|
|
if (result_type() == STRING_RESULT)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
String *result;
|
2003-08-05 12:52:37 +05:00
|
|
|
CHARSET_INFO *cs= collation.collation;
|
2000-07-31 21:29:14 +02:00
|
|
|
char buff[MAX_FIELD_WIDTH]; // Alloc buffer for small columns
|
2004-03-25 22:11:22 +02:00
|
|
|
str_value.set_quick(buff, sizeof(buff), cs);
|
2000-07-31 21:29:14 +02:00
|
|
|
result=val_str(&str_value);
|
|
|
|
if (null_value)
|
2004-04-28 03:37:45 +03:00
|
|
|
{
|
2004-05-05 21:24:21 +03:00
|
|
|
str_value.set_quick(0, 0, cs);
|
2002-12-03 13:08:25 +02:00
|
|
|
return set_field_to_null_with_conversions(field, no_conversions);
|
2004-04-28 03:37:45 +03:00
|
|
|
}
|
2005-12-07 17:01:17 +03:00
|
|
|
|
|
|
|
/* NOTE: If null_value == FALSE, "result" must be not NULL. */
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
field->set_notnull();
|
2002-08-24 14:49:04 +03:00
|
|
|
error=field->store(result->ptr(),result->length(),cs);
|
2002-05-17 16:29:52 +05:00
|
|
|
str_value.set_quick(0, 0, cs);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2009-12-22 19:23:13 +03:00
|
|
|
else if (result_type() == REAL_RESULT &&
|
|
|
|
field->result_type() == STRING_RESULT)
|
|
|
|
{
|
|
|
|
double nr= val_real();
|
|
|
|
if (null_value)
|
|
|
|
return set_field_to_null_with_conversions(field, no_conversions);
|
|
|
|
field->set_notnull();
|
|
|
|
error= field->store(nr);
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
else if (result_type() == REAL_RESULT)
|
|
|
|
{
|
2004-11-11 21:39:35 +03:00
|
|
|
double nr= val_real();
|
2000-07-31 21:29:14 +02:00
|
|
|
if (null_value)
|
2010-05-05 15:00:59 +04:00
|
|
|
return set_field_to_null_with_conversions(field, no_conversions);
|
2000-07-31 21:29:14 +02:00
|
|
|
field->set_notnull();
|
2002-08-24 14:49:04 +03:00
|
|
|
error=field->store(nr);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2005-02-09 02:50:45 +04:00
|
|
|
else if (result_type() == DECIMAL_RESULT)
|
|
|
|
{
|
|
|
|
my_decimal decimal_value;
|
|
|
|
my_decimal *value= val_decimal(&decimal_value);
|
|
|
|
if (null_value)
|
2007-10-23 19:24:59 +04:00
|
|
|
return set_field_to_null_with_conversions(field, no_conversions);
|
2005-02-09 02:50:45 +04:00
|
|
|
field->set_notnull();
|
|
|
|
error=field->store_decimal(value);
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
longlong nr=val_int();
|
|
|
|
if (null_value)
|
2002-12-03 13:08:25 +02:00
|
|
|
return set_field_to_null_with_conversions(field, no_conversions);
|
2000-07-31 21:29:14 +02:00
|
|
|
field->set_notnull();
|
2005-09-14 01:41:44 +03:00
|
|
|
error=field->store(nr, unsigned_flag);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2010-02-11 19:41:53 +02:00
|
|
|
return error ? error : (field->table->in_use->is_error() ? 1 : 0);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2002-10-16 10:32:45 +03:00
|
|
|
|
2002-12-05 19:38:42 +02:00
|
|
|
int Item_string::save_in_field(Field *field, bool no_conversions)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
String *result;
|
|
|
|
result=val_str(&str_value);
|
2007-07-27 18:42:25 +05:00
|
|
|
return save_str_value_in_field(field, result);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2005-09-14 01:41:44 +03:00
|
|
|
|
2003-11-20 22:30:48 +02:00
|
|
|
int Item_uint::save_in_field(Field *field, bool no_conversions)
|
2003-11-16 17:37:15 +01:00
|
|
|
{
|
2005-09-14 01:41:44 +03:00
|
|
|
/* Item_int::save_in_field handles both signed and unsigned. */
|
2003-11-21 01:53:01 +02:00
|
|
|
return Item_int::save_in_field(field, no_conversions);
|
2003-11-16 17:37:15 +01:00
|
|
|
}
|
|
|
|
|
2009-05-25 11:00:40 +03:00
|
|
|
static int save_int_value_in_field (Field *field, longlong nr,
|
|
|
|
bool null_value, bool unsigned_flag)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
if (null_value)
|
|
|
|
return set_field_to_null(field);
|
|
|
|
field->set_notnull();
|
2005-09-14 01:41:44 +03:00
|
|
|
return field->store(nr, unsigned_flag);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2005-02-09 02:50:45 +04:00
|
|
|
|
2009-05-25 11:00:40 +03:00
|
|
|
int Item_int::save_in_field(Field *field, bool no_conversions)
|
|
|
|
{
|
|
|
|
return save_int_value_in_field (field, val_int(), null_value, unsigned_flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-09 02:50:45 +04:00
|
|
|
int Item_decimal::save_in_field(Field *field, bool no_conversions)
|
|
|
|
{
|
|
|
|
field->set_notnull();
|
|
|
|
return field->store_decimal(&decimal_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-05-03 12:47:27 +04:00
|
|
|
bool Item_int::eq(const Item *arg, bool binary_cmp) const
|
|
|
|
{
|
|
|
|
/* No need to check for null value as basic constant can't be NULL */
|
|
|
|
if (arg->basic_const_item() && arg->type() == type())
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
We need to cast off const to call val_int(). This should be OK for
|
|
|
|
a basic constant.
|
|
|
|
*/
|
|
|
|
Item *item= (Item*) arg;
|
|
|
|
return item->val_int() == value && item->unsigned_flag == unsigned_flag;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-15 00:51:37 +02:00
|
|
|
Item *Item_int_with_ref::clone_item()
|
2005-05-05 12:55:09 +04:00
|
|
|
{
|
2005-05-16 12:19:10 +03:00
|
|
|
DBUG_ASSERT(ref->const_item());
|
2005-05-05 12:55:09 +04:00
|
|
|
/*
|
|
|
|
We need to evaluate the constant to make sure it works with
|
|
|
|
parameter markers.
|
|
|
|
*/
|
|
|
|
return (ref->unsigned_flag ?
|
|
|
|
new Item_uint(ref->name, ref->val_int(), ref->max_length) :
|
|
|
|
new Item_int(ref->name, ref->val_int(), ref->max_length));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-20 13:36:26 +02:00
|
|
|
Item_num *Item_uint::neg()
|
|
|
|
{
|
2005-06-29 12:03:38 +05:00
|
|
|
Item_decimal *item= new Item_decimal(value, 1);
|
2005-02-09 02:50:45 +04:00
|
|
|
return item->neg();
|
2004-03-20 13:36:26 +02:00
|
|
|
}
|
2002-12-05 19:38:42 +02:00
|
|
|
|
2004-10-02 22:20:08 +03:00
|
|
|
|
2005-02-19 18:58:27 +02:00
|
|
|
static uint nr_of_decimals(const char *str, const char *end)
|
|
|
|
{
|
|
|
|
const char *decimal_point;
|
|
|
|
|
|
|
|
/* Find position for '.' */
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (str == end)
|
|
|
|
return 0;
|
|
|
|
if (*str == 'e' || *str == 'E')
|
|
|
|
return NOT_FIXED_DEC;
|
|
|
|
if (*str++ == '.')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
decimal_point= str;
|
2010-11-19 18:24:29 +03:00
|
|
|
for ( ; str < end && my_isdigit(system_charset_info, *str) ; str++)
|
2005-02-19 18:58:27 +02:00
|
|
|
;
|
2010-11-19 18:24:29 +03:00
|
|
|
if (str < end && (*str == 'e' || *str == 'E'))
|
2005-02-19 18:58:27 +02:00
|
|
|
return NOT_FIXED_DEC;
|
2010-11-19 18:24:29 +03:00
|
|
|
/*
|
|
|
|
QQ:
|
|
|
|
The number of decimal digist in fact should be (str - decimal_point - 1).
|
|
|
|
But it seems the result of nr_of_decimals() is never used!
|
|
|
|
|
|
|
|
In case of 'e' and 'E' nr_of_decimals returns NOT_FIXED_DEC.
|
|
|
|
In case if there is no 'e' or 'E' parser code in sql_yacc.yy
|
|
|
|
never calls Item_float::Item_float() - it creates Item_decimal instead.
|
|
|
|
|
|
|
|
The only piece of code where we call Item_float::Item_float(str, len)
|
|
|
|
without having 'e' or 'E' is item_xmlfunc.cc, but this Item_float
|
|
|
|
never appears in metadata itself. Changing the code to return
|
|
|
|
(str - decimal_point - 1) does not make any changes in the test results.
|
|
|
|
|
|
|
|
This should be addressed somehow.
|
|
|
|
Looks like a reminder from before real DECIMAL times.
|
|
|
|
*/
|
2005-02-19 18:58:27 +02:00
|
|
|
return (uint) (str - decimal_point);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
2010-11-18 16:11:18 +03:00
|
|
|
This function is only called during parsing:
|
|
|
|
- when parsing SQL query from sql_yacc.yy
|
|
|
|
- when parsing XPath query from item_xmlfunc.cc
|
|
|
|
We will signal an error if value is not a true double value (overflow):
|
|
|
|
eng: Illegal %s '%-.192s' value found during parsing
|
|
|
|
|
|
|
|
Note: the string is NOT null terminated when called from item_xmlfunc.cc,
|
|
|
|
so this->name will contain some SQL query tail behind the "length" bytes.
|
|
|
|
This is Ok for now, as this Item is never seen in SHOW,
|
|
|
|
or EXPLAIN, or anywhere else in metadata.
|
|
|
|
Item->name should be fixed to use LEX_STRING eventually.
|
2004-10-02 22:20:08 +03:00
|
|
|
*/
|
|
|
|
|
2005-02-09 02:50:45 +04:00
|
|
|
Item_float::Item_float(const char *str_arg, uint length)
|
2004-10-02 22:20:08 +03:00
|
|
|
{
|
|
|
|
int error;
|
2005-01-15 12:28:38 +02:00
|
|
|
char *end_not_used;
|
|
|
|
value= my_strntod(&my_charset_bin, (char*) str_arg, length, &end_not_used,
|
|
|
|
&error);
|
2004-10-02 22:20:08 +03:00
|
|
|
if (error)
|
|
|
|
{
|
2010-11-18 16:11:18 +03:00
|
|
|
char tmp[NAME_LEN + 1];
|
|
|
|
my_snprintf(tmp, sizeof(tmp), "%.*s", length, str_arg);
|
|
|
|
my_error(ER_ILLEGAL_VALUE_FOR_TYPE, MYF(0), "double", tmp);
|
2004-10-02 22:20:08 +03:00
|
|
|
}
|
|
|
|
presentation= name=(char*) str_arg;
|
2005-02-19 18:58:27 +02:00
|
|
|
decimals=(uint8) nr_of_decimals(str_arg, str_arg+length);
|
2004-10-02 22:20:08 +03:00
|
|
|
max_length=length;
|
|
|
|
fixed= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-09 02:50:45 +04:00
|
|
|
int Item_float::save_in_field(Field *field, bool no_conversions)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2004-11-11 21:39:35 +03:00
|
|
|
double nr= val_real();
|
2000-07-31 21:29:14 +02:00
|
|
|
if (null_value)
|
|
|
|
return set_field_to_null(field);
|
|
|
|
field->set_notnull();
|
2004-03-16 13:26:37 +04:00
|
|
|
return field->store(nr);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2004-09-01 20:30:48 +03:00
|
|
|
|
2008-02-22 13:30:33 +03:00
|
|
|
void Item_float::print(String *str, enum_query_type query_type)
|
2004-09-01 20:30:48 +03:00
|
|
|
{
|
|
|
|
if (presentation)
|
|
|
|
{
|
|
|
|
str->append(presentation);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
char buffer[20];
|
|
|
|
String num(buffer, sizeof(buffer), &my_charset_bin);
|
2006-06-16 12:17:20 +02:00
|
|
|
num.set_real(value, decimals, &my_charset_bin);
|
2004-09-01 20:30:48 +03:00
|
|
|
str->append(num);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-12-17 18:06:05 +04:00
|
|
|
/*
|
|
|
|
hex item
|
|
|
|
In string context this is a binary string.
|
|
|
|
In number context this is a longlong value.
|
|
|
|
*/
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2005-05-04 16:53:10 +04:00
|
|
|
bool Item_float::eq(const Item *arg, bool binary_cmp) const
|
2005-05-03 12:47:27 +04:00
|
|
|
{
|
|
|
|
if (arg->basic_const_item() && arg->type() == type())
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
We need to cast off const to call val_int(). This should be OK for
|
|
|
|
a basic constant.
|
|
|
|
*/
|
|
|
|
Item *item= (Item*) arg;
|
2005-05-04 16:53:10 +04:00
|
|
|
return item->val_real() == value;
|
2005-05-03 12:47:27 +04:00
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2001-01-25 22:38:26 +02:00
|
|
|
inline uint char_val(char X)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
return (uint) (X >= '0' && X <= '9' ? X-'0' :
|
|
|
|
X >= 'A' && X <= 'Z' ? X-'A'+10 :
|
|
|
|
X-'a'+10);
|
|
|
|
}
|
|
|
|
|
2010-05-05 11:54:52 +03:00
|
|
|
Item_hex_string::Item_hex_string()
|
|
|
|
{
|
|
|
|
hex_string_init("", 0);
|
|
|
|
}
|
2003-04-27 22:12:08 +03:00
|
|
|
|
2004-12-17 18:06:05 +04:00
|
|
|
Item_hex_string::Item_hex_string(const char *str, uint str_length)
|
2010-05-05 11:54:52 +03:00
|
|
|
{
|
|
|
|
hex_string_init(str, str_length);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Item_hex_string::hex_string_init(const char *str, uint str_length)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
max_length=(str_length+1)/2;
|
|
|
|
char *ptr=(char*) sql_alloc(max_length+1);
|
|
|
|
if (!ptr)
|
2010-05-05 11:54:52 +03:00
|
|
|
{
|
|
|
|
str_value.set("", 0, &my_charset_bin);
|
2000-07-31 21:29:14 +02:00
|
|
|
return;
|
2010-05-05 11:54:52 +03:00
|
|
|
}
|
2003-01-29 17:31:20 +04:00
|
|
|
str_value.set(ptr,max_length,&my_charset_bin);
|
2000-07-31 21:29:14 +02:00
|
|
|
char *end=ptr+max_length;
|
|
|
|
if (max_length*2 != str_length)
|
|
|
|
*ptr++=char_val(*str++); // Not even, assume 0 prefix
|
|
|
|
while (ptr != end)
|
|
|
|
{
|
|
|
|
*ptr++= (char) (char_val(str[0])*16+char_val(str[1]));
|
|
|
|
str+=2;
|
|
|
|
}
|
|
|
|
*ptr=0; // Keep purify happy
|
2003-08-05 12:52:37 +05:00
|
|
|
collation.set(&my_charset_bin, DERIVATION_COERCIBLE);
|
2004-03-20 13:36:26 +02:00
|
|
|
fixed= 1;
|
2005-05-24 17:50:17 +03:00
|
|
|
unsigned_flag= 1;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2004-12-17 18:06:05 +04:00
|
|
|
longlong Item_hex_string::val_int()
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2004-03-20 13:36:26 +02:00
|
|
|
// following assert is redundant, because fixed=1 assigned in constructor
|
2004-03-18 15:14:36 +02:00
|
|
|
DBUG_ASSERT(fixed == 1);
|
2000-07-31 21:29:14 +02:00
|
|
|
char *end=(char*) str_value.ptr()+str_value.length(),
|
|
|
|
*ptr=end-min(str_value.length(),sizeof(longlong));
|
|
|
|
|
|
|
|
ulonglong value=0;
|
|
|
|
for (; ptr != end ; ptr++)
|
|
|
|
value=(value << 8)+ (ulonglong) (uchar) *ptr;
|
|
|
|
return (longlong) value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-09 02:50:45 +04:00
|
|
|
my_decimal *Item_hex_string::val_decimal(my_decimal *decimal_value)
|
|
|
|
{
|
|
|
|
// following assert is redundant, because fixed=1 assigned in constructor
|
|
|
|
DBUG_ASSERT(fixed == 1);
|
|
|
|
ulonglong value= (ulonglong)val_int();
|
|
|
|
int2my_decimal(E_DEC_FATAL_ERROR, value, TRUE, decimal_value);
|
|
|
|
return (decimal_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-12-17 18:06:05 +04:00
|
|
|
int Item_hex_string::save_in_field(Field *field, bool no_conversions)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
field->set_notnull();
|
|
|
|
if (field->result_type() == STRING_RESULT)
|
2006-12-06 16:32:12 +04:00
|
|
|
return field->store(str_value.ptr(), str_value.length(),
|
|
|
|
collation.collation);
|
|
|
|
|
|
|
|
ulonglong nr;
|
|
|
|
uint32 length= str_value.length();
|
2008-12-09 13:53:23 +04:00
|
|
|
if (!length)
|
|
|
|
return 1;
|
|
|
|
|
2006-12-06 16:32:12 +04:00
|
|
|
if (length > 8)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2006-12-06 16:32:12 +04:00
|
|
|
nr= field->flags & UNSIGNED_FLAG ? ULONGLONG_MAX : LONGLONG_MAX;
|
|
|
|
goto warn;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2006-12-06 16:32:12 +04:00
|
|
|
nr= (ulonglong) val_int();
|
|
|
|
if ((length == 8) && !(field->flags & UNSIGNED_FLAG) && (nr > LONGLONG_MAX))
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2006-12-06 16:32:12 +04:00
|
|
|
nr= LONGLONG_MAX;
|
|
|
|
goto warn;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2007-01-18 10:51:29 +04:00
|
|
|
return field->store((longlong) nr, TRUE); // Assume hex numbers are unsigned
|
2006-12-06 16:32:12 +04:00
|
|
|
|
|
|
|
warn:
|
2007-01-18 10:51:29 +04:00
|
|
|
if (!field->store((longlong) nr, TRUE))
|
2006-12-06 16:32:12 +04:00
|
|
|
field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE,
|
|
|
|
1);
|
|
|
|
return 1;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-22 13:30:33 +03:00
|
|
|
void Item_hex_string::print(String *str, enum_query_type query_type)
|
2007-10-21 21:45:31 +04:00
|
|
|
{
|
|
|
|
char *end= (char*) str_value.ptr() + str_value.length(),
|
|
|
|
*ptr= end - min(str_value.length(), sizeof(longlong));
|
|
|
|
str->append("0x");
|
|
|
|
for (; ptr != end ; ptr++)
|
|
|
|
{
|
|
|
|
str->append(_dig_vec_lower[((uchar) *ptr) >> 4]);
|
|
|
|
str->append(_dig_vec_lower[((uchar) *ptr) & 0x0F]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-05-04 16:53:10 +04:00
|
|
|
bool Item_hex_string::eq(const Item *arg, bool binary_cmp) const
|
2005-05-03 12:47:27 +04:00
|
|
|
{
|
|
|
|
if (arg->basic_const_item() && arg->type() == type())
|
|
|
|
{
|
|
|
|
if (binary_cmp)
|
|
|
|
return !stringcmp(&str_value, &arg->str_value);
|
|
|
|
return !sortcmp(&str_value, &arg->str_value, collation.collation);
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2005-07-13 13:00:17 +05:00
|
|
|
|
2005-07-14 17:48:17 +05:00
|
|
|
Item *Item_hex_string::safe_charset_converter(CHARSET_INFO *tocs)
|
2005-07-13 13:00:17 +05:00
|
|
|
{
|
|
|
|
Item_string *conv;
|
|
|
|
String tmp, *str= val_str(&tmp);
|
|
|
|
|
|
|
|
if (!(conv= new Item_string(str->ptr(), str->length(), tocs)))
|
|
|
|
return NULL;
|
|
|
|
conv->str_value.copy();
|
2005-07-14 16:11:55 +05:00
|
|
|
conv->str_value.mark_as_const();
|
2005-07-13 13:00:17 +05:00
|
|
|
return conv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-12-17 18:06:05 +04:00
|
|
|
/*
|
|
|
|
bin item.
|
|
|
|
In string context this is a binary string.
|
|
|
|
In number context this is a longlong value.
|
|
|
|
*/
|
|
|
|
|
|
|
|
Item_bin_string::Item_bin_string(const char *str, uint str_length)
|
|
|
|
{
|
|
|
|
const char *end= str + str_length - 1;
|
|
|
|
uchar bits= 0;
|
|
|
|
uint power= 1;
|
|
|
|
|
|
|
|
max_length= (str_length + 7) >> 3;
|
|
|
|
char *ptr= (char*) sql_alloc(max_length + 1);
|
|
|
|
if (!ptr)
|
|
|
|
return;
|
|
|
|
str_value.set(ptr, max_length, &my_charset_bin);
|
2008-06-27 18:22:23 +05:00
|
|
|
|
|
|
|
if (max_length > 0)
|
2004-12-17 18:06:05 +04:00
|
|
|
{
|
2008-06-27 18:22:23 +05:00
|
|
|
ptr+= max_length - 1;
|
|
|
|
ptr[1]= 0; // Set end null for string
|
|
|
|
for (; end >= str; end--)
|
2004-12-17 18:06:05 +04:00
|
|
|
{
|
2008-06-27 18:22:23 +05:00
|
|
|
if (power == 256)
|
|
|
|
{
|
|
|
|
power= 1;
|
|
|
|
*ptr--= bits;
|
|
|
|
bits= 0;
|
|
|
|
}
|
|
|
|
if (*end == '1')
|
|
|
|
bits|= power;
|
|
|
|
power<<= 1;
|
2004-12-17 18:06:05 +04:00
|
|
|
}
|
2008-06-27 18:22:23 +05:00
|
|
|
*ptr= (char) bits;
|
2004-12-17 18:06:05 +04:00
|
|
|
}
|
2008-06-27 18:22:23 +05:00
|
|
|
else
|
|
|
|
ptr[0]= 0;
|
|
|
|
|
2004-12-17 18:06:05 +04:00
|
|
|
collation.set(&my_charset_bin, DERIVATION_COERCIBLE);
|
|
|
|
fixed= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
|
|
|
Pack data in buffer for sending.
|
2002-12-11 09:17:51 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
bool Item_null::send(Protocol *protocol, String *packet)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2002-12-11 09:17:51 +02:00
|
|
|
return protocol->store_null();
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
|
|
|
This is only called from items that is not of type item_field.
|
2000-07-31 21:29:14 +02:00
|
|
|
*/
|
|
|
|
|
2002-12-11 09:17:51 +02:00
|
|
|
bool Item::send(Protocol *protocol, String *buffer)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2009-08-28 17:51:31 +02:00
|
|
|
bool UNINIT_VAR(result); // Will be set if null_value == 0
|
2006-12-15 00:51:37 +02:00
|
|
|
enum_field_types f_type;
|
2002-12-11 09:17:51 +02:00
|
|
|
|
2006-12-15 00:51:37 +02:00
|
|
|
switch ((f_type=field_type())) {
|
2002-12-11 09:17:51 +02:00
|
|
|
default:
|
2002-12-14 17:43:01 +02:00
|
|
|
case MYSQL_TYPE_NULL:
|
|
|
|
case MYSQL_TYPE_DECIMAL:
|
|
|
|
case MYSQL_TYPE_ENUM:
|
|
|
|
case MYSQL_TYPE_SET:
|
|
|
|
case MYSQL_TYPE_TINY_BLOB:
|
|
|
|
case MYSQL_TYPE_MEDIUM_BLOB:
|
|
|
|
case MYSQL_TYPE_LONG_BLOB:
|
|
|
|
case MYSQL_TYPE_BLOB:
|
|
|
|
case MYSQL_TYPE_GEOMETRY:
|
2002-12-11 09:17:51 +02:00
|
|
|
case MYSQL_TYPE_STRING:
|
|
|
|
case MYSQL_TYPE_VAR_STRING:
|
2004-12-06 02:00:37 +02:00
|
|
|
case MYSQL_TYPE_VARCHAR:
|
2004-12-17 18:06:05 +04:00
|
|
|
case MYSQL_TYPE_BIT:
|
2005-02-09 02:50:45 +04:00
|
|
|
case MYSQL_TYPE_NEWDECIMAL:
|
2002-12-11 09:17:51 +02:00
|
|
|
{
|
|
|
|
String *res;
|
|
|
|
if ((res=val_str(buffer)))
|
2003-03-17 13:14:04 +04:00
|
|
|
result= protocol->store(res->ptr(),res->length(),res->charset());
|
2010-12-21 14:34:11 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(null_value);
|
|
|
|
}
|
2002-12-11 09:17:51 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MYSQL_TYPE_TINY:
|
|
|
|
{
|
|
|
|
longlong nr;
|
|
|
|
nr= val_int();
|
|
|
|
if (!null_value)
|
|
|
|
result= protocol->store_tiny(nr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MYSQL_TYPE_SHORT:
|
2005-04-21 15:36:10 +01:00
|
|
|
case MYSQL_TYPE_YEAR:
|
2002-12-11 09:17:51 +02:00
|
|
|
{
|
|
|
|
longlong nr;
|
|
|
|
nr= val_int();
|
|
|
|
if (!null_value)
|
|
|
|
result= protocol->store_short(nr);
|
|
|
|
break;
|
|
|
|
}
|
2002-12-14 17:43:01 +02:00
|
|
|
case MYSQL_TYPE_INT24:
|
2002-12-11 09:17:51 +02:00
|
|
|
case MYSQL_TYPE_LONG:
|
|
|
|
{
|
|
|
|
longlong nr;
|
|
|
|
nr= val_int();
|
|
|
|
if (!null_value)
|
|
|
|
result= protocol->store_long(nr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MYSQL_TYPE_LONGLONG:
|
|
|
|
{
|
|
|
|
longlong nr;
|
|
|
|
nr= val_int();
|
|
|
|
if (!null_value)
|
|
|
|
result= protocol->store_longlong(nr, unsigned_flag);
|
|
|
|
break;
|
|
|
|
}
|
2003-10-20 18:52:45 +05:00
|
|
|
case MYSQL_TYPE_FLOAT:
|
|
|
|
{
|
|
|
|
float nr;
|
2004-11-11 21:39:35 +03:00
|
|
|
nr= (float) val_real();
|
2003-10-20 18:52:45 +05:00
|
|
|
if (!null_value)
|
|
|
|
result= protocol->store(nr, decimals, buffer);
|
|
|
|
break;
|
|
|
|
}
|
2002-12-11 09:17:51 +02:00
|
|
|
case MYSQL_TYPE_DOUBLE:
|
|
|
|
{
|
2004-11-11 21:39:35 +03:00
|
|
|
double nr= val_real();
|
2002-12-11 09:17:51 +02:00
|
|
|
if (!null_value)
|
|
|
|
result= protocol->store(nr, decimals, buffer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MYSQL_TYPE_DATETIME:
|
|
|
|
case MYSQL_TYPE_DATE:
|
2002-12-14 17:43:01 +02:00
|
|
|
case MYSQL_TYPE_TIMESTAMP:
|
2002-12-11 09:17:51 +02:00
|
|
|
{
|
2007-03-23 22:08:31 +02:00
|
|
|
MYSQL_TIME tm;
|
2003-11-03 14:01:59 +02:00
|
|
|
get_date(&tm, TIME_FUZZY_DATE);
|
2002-12-11 09:17:51 +02:00
|
|
|
if (!null_value)
|
|
|
|
{
|
2006-12-15 00:51:37 +02:00
|
|
|
if (f_type == MYSQL_TYPE_DATE)
|
2002-12-11 09:17:51 +02:00
|
|
|
return protocol->store_date(&tm);
|
|
|
|
else
|
|
|
|
result= protocol->store(&tm);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MYSQL_TYPE_TIME:
|
|
|
|
{
|
2007-03-23 22:08:31 +02:00
|
|
|
MYSQL_TIME tm;
|
2002-12-11 09:17:51 +02:00
|
|
|
get_time(&tm);
|
|
|
|
if (!null_value)
|
|
|
|
result= protocol->store_time(&tm);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (null_value)
|
|
|
|
result= protocol->store_null();
|
|
|
|
return result;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2002-12-11 09:17:51 +02:00
|
|
|
|
2009-12-02 00:25:51 +03:00
|
|
|
/**
|
|
|
|
Check if an item is a constant one and can be cached.
|
|
|
|
|
|
|
|
@param arg [out] TRUE <=> Cache this item.
|
|
|
|
|
|
|
|
@return TRUE Go deeper in item tree.
|
|
|
|
@return FALSE Don't go deeper in item tree.
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool Item::cache_const_expr_analyzer(uchar **arg)
|
|
|
|
{
|
|
|
|
bool *cache_flag= (bool*)*arg;
|
|
|
|
if (!*cache_flag)
|
|
|
|
{
|
|
|
|
Item *item= real_item();
|
|
|
|
/*
|
|
|
|
Cache constant items unless it's a basic constant, constant field or
|
|
|
|
a subselect (they use their own cache).
|
|
|
|
*/
|
|
|
|
if (const_item() &&
|
2010-08-14 13:11:33 +04:00
|
|
|
!(basic_const_item() || item->basic_const_item() ||
|
|
|
|
item->type() == Item::FIELD_ITEM ||
|
2009-12-02 00:25:51 +03:00
|
|
|
item->type() == SUBSELECT_ITEM ||
|
|
|
|
/*
|
|
|
|
Do not cache GET_USER_VAR() function as its const_item() may
|
|
|
|
return TRUE for the current thread but it still may change
|
|
|
|
during the execution.
|
|
|
|
*/
|
|
|
|
(item->type() == Item::FUNC_ITEM &&
|
|
|
|
((Item_func*)item)->functype() == Item_func::GUSERVAR_FUNC)))
|
|
|
|
*cache_flag= TRUE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Cache item if needed.
|
|
|
|
|
|
|
|
@param arg TRUE <=> Cache this item.
|
|
|
|
|
|
|
|
@return cache if cache needed.
|
|
|
|
@return this otherwise.
|
|
|
|
*/
|
|
|
|
|
|
|
|
Item* Item::cache_const_expr_transformer(uchar *arg)
|
|
|
|
{
|
|
|
|
if (*(bool*)arg)
|
|
|
|
{
|
|
|
|
*((bool*)arg)= FALSE;
|
|
|
|
Item_cache *cache= Item_cache::get_cache(this);
|
|
|
|
if (!cache)
|
|
|
|
return NULL;
|
|
|
|
cache->setup(this);
|
|
|
|
cache->store(this);
|
|
|
|
return cache;
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-11 09:17:51 +02:00
|
|
|
bool Item_field::send(Protocol *protocol, String *buffer)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2002-12-11 09:17:51 +02:00
|
|
|
return protocol->store(result_field);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2004-10-28 17:31:26 +03:00
|
|
|
|
2006-11-28 15:44:11 +02:00
|
|
|
void Item_field::update_null_value()
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
need to set no_errors to prevent warnings about type conversion
|
|
|
|
popping up.
|
|
|
|
*/
|
|
|
|
THD *thd= field->table->in_use;
|
|
|
|
int no_errors;
|
|
|
|
|
|
|
|
no_errors= thd->no_errors;
|
|
|
|
thd->no_errors= 1;
|
|
|
|
Item::update_null_value();
|
|
|
|
thd->no_errors= no_errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-16 19:39:28 +03:00
|
|
|
/*
|
|
|
|
Add the field to the select list and substitute it for the reference to
|
|
|
|
the field.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
Item_field::update_value_transformer()
|
|
|
|
select_arg current select
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
If the field doesn't belong to the table being inserted into then it is
|
|
|
|
added to the select list, pointer to it is stored in the ref_pointer_array
|
|
|
|
of the select and the field itself is substituted for the Item_ref object.
|
|
|
|
This is done in order to get correct values from update fields that
|
|
|
|
belongs to the SELECT part in the INSERT .. SELECT .. ON DUPLICATE KEY
|
|
|
|
UPDATE statement.
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
0 if error occured
|
|
|
|
ref if all conditions are met
|
|
|
|
this field otherwise
|
|
|
|
*/
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
Item *Item_field::update_value_transformer(uchar *select_arg)
|
2007-02-16 19:39:28 +03:00
|
|
|
{
|
|
|
|
SELECT_LEX *select= (SELECT_LEX*)select_arg;
|
|
|
|
DBUG_ASSERT(fixed);
|
|
|
|
|
|
|
|
if (field->table != select->context.table_list->table &&
|
|
|
|
type() != Item::TRIGGER_FIELD_ITEM)
|
|
|
|
{
|
|
|
|
List<Item> *all_fields= &select->join->all_fields;
|
|
|
|
Item **ref_pointer_array= select->ref_pointer_array;
|
|
|
|
int el= all_fields->elements;
|
|
|
|
Item_ref *ref;
|
|
|
|
|
|
|
|
ref_pointer_array[el]= (Item*)this;
|
|
|
|
all_fields->push_front((Item*)this);
|
|
|
|
ref= new Item_ref(&select->context, ref_pointer_array + el,
|
|
|
|
table_name, field_name);
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-22 13:30:33 +03:00
|
|
|
void Item_field::print(String *str, enum_query_type query_type)
|
2007-03-10 00:29:02 +03:00
|
|
|
{
|
|
|
|
if (field && field->table->const_table)
|
|
|
|
{
|
|
|
|
char buff[MAX_FIELD_WIDTH];
|
|
|
|
String tmp(buff,sizeof(buff),str->charset());
|
|
|
|
field->val_str(&tmp);
|
2010-02-26 17:40:01 +04:00
|
|
|
if (field->is_null())
|
|
|
|
str->append("NULL");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
str->append('\'');
|
|
|
|
str->append(tmp);
|
|
|
|
str->append('\'');
|
|
|
|
}
|
2007-03-10 00:29:02 +03:00
|
|
|
return;
|
|
|
|
}
|
2008-02-22 13:30:33 +03:00
|
|
|
Item_ident::print(str, query_type);
|
2007-03-10 00:29:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-01 07:05:42 +03:00
|
|
|
Item_ref::Item_ref(Name_resolution_context *context_arg,
|
|
|
|
Item **item, const char *table_name_arg,
|
2007-03-04 19:54:35 -08:00
|
|
|
const char *field_name_arg,
|
|
|
|
bool alias_name_used_arg)
|
2005-07-01 07:05:42 +03:00
|
|
|
:Item_ident(context_arg, NullS, table_name_arg, field_name_arg),
|
|
|
|
result_field(0), ref(item)
|
2005-02-09 02:50:45 +04:00
|
|
|
{
|
2007-03-04 19:54:35 -08:00
|
|
|
alias_name_used= alias_name_used_arg;
|
2005-02-09 02:50:45 +04:00
|
|
|
/*
|
|
|
|
This constructor used to create some internals references over fixed items
|
|
|
|
*/
|
2007-02-21 23:00:32 +03:00
|
|
|
if (ref && *ref && (*ref)->fixed)
|
2005-02-09 02:50:45 +04:00
|
|
|
set_properties();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-12 10:33:16 +04:00
|
|
|
Item_ref::Item_ref(TABLE_LIST *view_arg, Item **item,
|
|
|
|
const char *field_name_arg, bool alias_name_used_arg)
|
|
|
|
:Item_ident(view_arg, field_name_arg),
|
|
|
|
result_field(NULL), ref(item)
|
|
|
|
{
|
|
|
|
alias_name_used= alias_name_used_arg;
|
|
|
|
/*
|
|
|
|
This constructor is used to create some internal references over fixed items
|
|
|
|
*/
|
|
|
|
if (ref && *ref && (*ref)->fixed)
|
|
|
|
set_properties();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
2004-11-10 12:43:08 +02:00
|
|
|
Resolve the name of a reference to a column reference.
|
2004-10-28 17:31:26 +03:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
The method resolves the column reference represented by 'this' as a column
|
|
|
|
present in one of: GROUP BY clause, SELECT clause, outer queries. It is
|
|
|
|
used typically for columns in the HAVING clause which are not under
|
|
|
|
aggregate functions.
|
2004-10-28 17:31:26 +03:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
POSTCONDITION @n
|
|
|
|
Item_ref::ref is 0 or points to a valid item.
|
2004-10-28 17:31:26 +03:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@note
|
2004-11-10 12:43:08 +02:00
|
|
|
The name resolution algorithm used is (where [T_j] is an optional table
|
|
|
|
name that qualifies the column name):
|
2004-11-02 18:23:15 +02:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@code
|
|
|
|
resolve_extended([T_j].col_ref_i)
|
2004-10-28 17:31:26 +03:00
|
|
|
{
|
2007-10-11 13:29:09 -04:00
|
|
|
Search for a column or derived column named col_ref_i [in table T_j]
|
|
|
|
in the SELECT and GROUP clauses of Q.
|
2004-11-05 15:48:44 +02:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
if such a column is NOT found AND // Lookup in outer queries.
|
|
|
|
there are outer queries
|
|
|
|
{
|
|
|
|
for each outer query Q_k beginning from the inner-most one
|
|
|
|
{
|
|
|
|
Search for a column or derived column named col_ref_i
|
|
|
|
[in table T_j] in the SELECT and GROUP clauses of Q_k.
|
|
|
|
|
|
|
|
if such a column is not found AND
|
|
|
|
- Q_k is not a group query AND
|
|
|
|
- Q_k is not inside an aggregate function
|
|
|
|
OR
|
|
|
|
- Q_(k-1) is not in a HAVING or SELECT clause of Q_k
|
|
|
|
{
|
|
|
|
search for a column or derived column named col_ref_i
|
|
|
|
[in table T_j] in the FROM clause of Q_k;
|
|
|
|
}
|
2004-10-28 17:31:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-10-11 13:29:09 -04:00
|
|
|
@endcode
|
|
|
|
@n
|
2004-11-02 18:23:15 +02:00
|
|
|
This procedure treats GROUP BY and SELECT clauses as one namespace for
|
2004-11-10 12:43:08 +02:00
|
|
|
column references in HAVING. Notice that compared to
|
|
|
|
Item_field::fix_fields, here we first search the SELECT and GROUP BY
|
|
|
|
clauses, and then we search the FROM clause.
|
2004-10-28 17:31:26 +03:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@param[in] thd current thread
|
|
|
|
@param[in,out] reference view column if this item was resolved to a
|
|
|
|
view column
|
2005-03-01 14:54:47 +03:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@todo
|
|
|
|
Here we could first find the field anyway, and then test this
|
|
|
|
condition, so that we can give a better error message -
|
|
|
|
ER_WRONG_FIELD_WITH_GROUP, instead of the less informative
|
|
|
|
ER_BAD_FIELD_ERROR which we produce now.
|
|
|
|
|
|
|
|
@retval
|
2004-10-28 17:31:26 +03:00
|
|
|
TRUE if error
|
2007-10-11 13:29:09 -04:00
|
|
|
@retval
|
2004-10-28 17:31:26 +03:00
|
|
|
FALSE on success
|
|
|
|
*/
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2005-07-01 07:05:42 +03:00
|
|
|
bool Item_ref::fix_fields(THD *thd, Item **reference)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2004-12-13 08:45:00 +02:00
|
|
|
enum_parsing_place place= NO_MATTER;
|
2005-07-01 07:05:42 +03:00
|
|
|
DBUG_ASSERT(fixed == 0);
|
2004-10-28 17:31:26 +03:00
|
|
|
SELECT_LEX *current_sel= thd->lex->current_select;
|
|
|
|
|
2005-03-04 21:14:35 +00:00
|
|
|
if (!ref || ref == not_found_item)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2005-07-01 07:05:42 +03:00
|
|
|
if (!(ref= resolve_ref_in_select_and_group(thd, this,
|
|
|
|
context->select_lex)))
|
|
|
|
goto error; /* Some error occurred (e.g. ambiguous names). */
|
2004-10-28 17:31:26 +03:00
|
|
|
|
2004-11-05 15:48:44 +02:00
|
|
|
if (ref == not_found_item) /* This reference was not resolved. */
|
2002-07-01 14:14:51 +03:00
|
|
|
{
|
2005-07-01 07:05:42 +03:00
|
|
|
Name_resolution_context *last_checked_context= context;
|
|
|
|
Name_resolution_context *outer_context= context->outer_context;
|
2005-03-01 14:54:47 +03:00
|
|
|
Field *from_field;
|
|
|
|
ref= 0;
|
|
|
|
|
2005-07-01 07:05:42 +03:00
|
|
|
if (!outer_context)
|
2005-03-01 14:54:47 +03:00
|
|
|
{
|
|
|
|
/* The current reference cannot be resolved in this query. */
|
|
|
|
my_error(ER_BAD_FIELD_ERROR,MYF(0),
|
|
|
|
this->full_name(), current_thd->where);
|
2005-07-01 07:05:42 +03:00
|
|
|
goto error;
|
2005-03-01 14:54:47 +03:00
|
|
|
}
|
2005-07-01 07:05:42 +03:00
|
|
|
|
2002-07-01 14:14:51 +03:00
|
|
|
/*
|
2005-07-01 07:05:42 +03:00
|
|
|
If there is an outer context (select), and it is not a derived table
|
|
|
|
(which do not support the use of outer fields for now), try to
|
|
|
|
resolve this reference in the outer select(s).
|
2005-03-01 14:54:47 +03:00
|
|
|
|
2004-11-05 15:48:44 +02:00
|
|
|
We treat each subselect as a separate namespace, so that different
|
|
|
|
subselects may contain columns with the same names. The subselects are
|
|
|
|
searched starting from the innermost.
|
2002-07-01 14:14:51 +03:00
|
|
|
*/
|
2005-03-01 14:54:47 +03:00
|
|
|
from_field= (Field*) not_found_field;
|
|
|
|
|
2005-07-01 07:05:42 +03:00
|
|
|
do
|
2002-11-24 21:10:52 +02:00
|
|
|
{
|
2005-07-01 07:05:42 +03:00
|
|
|
SELECT_LEX *select= outer_context->select_lex;
|
|
|
|
Item_subselect *prev_subselect_item=
|
|
|
|
last_checked_context->select_lex->master_unit()->item;
|
|
|
|
last_checked_context= outer_context;
|
2004-10-28 17:31:26 +03:00
|
|
|
|
2005-03-01 14:54:47 +03:00
|
|
|
/* Search in the SELECT and GROUP lists of the outer select. */
|
2005-07-01 07:05:42 +03:00
|
|
|
if (outer_context->resolve_in_select_list)
|
2004-11-05 15:48:44 +02:00
|
|
|
{
|
2005-07-01 07:05:42 +03:00
|
|
|
if (!(ref= resolve_ref_in_select_and_group(thd, this, select)))
|
|
|
|
goto error; /* Some error occurred (e.g. ambiguous names). */
|
2005-03-01 14:54:47 +03:00
|
|
|
if (ref != not_found_item)
|
2004-09-01 23:27:40 +03:00
|
|
|
{
|
2005-03-01 14:54:47 +03:00
|
|
|
DBUG_ASSERT(*ref && (*ref)->fixed);
|
|
|
|
prev_subselect_item->used_tables_cache|= (*ref)->used_tables();
|
|
|
|
prev_subselect_item->const_item_cache&= (*ref)->const_item();
|
|
|
|
break;
|
2004-11-05 15:48:44 +02:00
|
|
|
}
|
|
|
|
/*
|
2005-03-01 14:54:47 +03:00
|
|
|
Set ref to 0 to ensure that we get an error in case we replaced
|
|
|
|
this item with another item and still use this item in some
|
|
|
|
other place of the parse tree.
|
2004-11-05 15:48:44 +02:00
|
|
|
*/
|
2005-03-01 14:54:47 +03:00
|
|
|
ref= 0;
|
2004-11-05 15:48:44 +02:00
|
|
|
}
|
2002-10-08 14:50:12 +03:00
|
|
|
|
2005-03-01 14:54:47 +03:00
|
|
|
place= prev_subselect_item->parsing_place;
|
|
|
|
/*
|
|
|
|
Check table fields only if the subquery is used somewhere out of
|
|
|
|
HAVING or the outer SELECT does not use grouping (i.e. tables are
|
|
|
|
accessible).
|
2005-07-01 07:05:42 +03:00
|
|
|
TODO:
|
2005-03-01 14:54:47 +03:00
|
|
|
Here we could first find the field anyway, and then test this
|
|
|
|
condition, so that we can give a better error message -
|
|
|
|
ER_WRONG_FIELD_WITH_GROUP, instead of the less informative
|
|
|
|
ER_BAD_FIELD_ERROR which we produce now.
|
|
|
|
*/
|
|
|
|
if ((place != IN_HAVING ||
|
2005-07-01 07:05:42 +03:00
|
|
|
(!select->with_sum_func &&
|
|
|
|
select->group_list.elements == 0)))
|
2004-11-05 15:48:44 +02:00
|
|
|
{
|
2004-11-11 11:16:51 +02:00
|
|
|
/*
|
2005-03-01 14:54:47 +03:00
|
|
|
In case of view, find_field_in_tables() write pointer to view
|
|
|
|
field expression to 'reference', i.e. it substitute that
|
|
|
|
expression instead of this Item_ref
|
2004-11-11 11:16:51 +02:00
|
|
|
*/
|
2005-07-01 07:05:42 +03:00
|
|
|
from_field= find_field_in_tables(thd, this,
|
2005-08-12 17:57:19 +03:00
|
|
|
outer_context->
|
|
|
|
first_name_resolution_table,
|
|
|
|
outer_context->
|
|
|
|
last_name_resolution_table,
|
2005-03-01 14:54:47 +03:00
|
|
|
reference,
|
|
|
|
IGNORE_EXCEPT_NON_UNIQUE,
|
2005-10-28 00:18:23 +03:00
|
|
|
TRUE, TRUE);
|
2005-03-01 14:54:47 +03:00
|
|
|
if (! from_field)
|
2005-07-01 07:05:42 +03:00
|
|
|
goto error;
|
2005-03-01 14:54:47 +03:00
|
|
|
if (from_field == view_ref_found)
|
2004-11-05 15:48:44 +02:00
|
|
|
{
|
2006-12-15 00:51:37 +02:00
|
|
|
Item::Type refer_type= (*reference)->type();
|
2005-03-01 14:54:47 +03:00
|
|
|
prev_subselect_item->used_tables_cache|=
|
|
|
|
(*reference)->used_tables();
|
|
|
|
prev_subselect_item->const_item_cache&=
|
|
|
|
(*reference)->const_item();
|
|
|
|
DBUG_ASSERT((*reference)->type() == REF_ITEM);
|
2005-07-01 07:05:42 +03:00
|
|
|
mark_as_dependent(thd, last_checked_context->select_lex,
|
|
|
|
context->select_lex, this,
|
2006-12-15 00:51:37 +02:00
|
|
|
((refer_type == REF_ITEM ||
|
|
|
|
refer_type == FIELD_ITEM) ?
|
2005-03-01 14:54:47 +03:00
|
|
|
(Item_ident*) (*reference) :
|
|
|
|
0));
|
|
|
|
/*
|
|
|
|
view reference found, we substituted it instead of this
|
|
|
|
Item, so can quit
|
|
|
|
*/
|
2004-11-05 15:48:44 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2005-03-01 14:54:47 +03:00
|
|
|
if (from_field != not_found_field)
|
|
|
|
{
|
2006-02-15 19:45:06 +03:00
|
|
|
if (cached_table && cached_table->select_lex &&
|
|
|
|
outer_context->select_lex &&
|
|
|
|
cached_table->select_lex != outer_context->select_lex)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Due to cache, find_field_in_tables() can return field which
|
|
|
|
doesn't belong to provided outer_context. In this case we have
|
|
|
|
to find proper field context in order to fix field correcly.
|
|
|
|
*/
|
|
|
|
do
|
|
|
|
{
|
|
|
|
outer_context= outer_context->outer_context;
|
|
|
|
select= outer_context->select_lex;
|
|
|
|
prev_subselect_item=
|
|
|
|
last_checked_context->select_lex->master_unit()->item;
|
|
|
|
last_checked_context= outer_context;
|
|
|
|
} while (outer_context && outer_context->select_lex &&
|
|
|
|
cached_table->select_lex != outer_context->select_lex);
|
|
|
|
}
|
2005-03-01 14:54:47 +03:00
|
|
|
prev_subselect_item->used_tables_cache|= from_field->table->map;
|
|
|
|
prev_subselect_item->const_item_cache= 0;
|
|
|
|
break;
|
|
|
|
}
|
2004-11-05 15:48:44 +02:00
|
|
|
}
|
2005-03-01 14:54:47 +03:00
|
|
|
DBUG_ASSERT(from_field == not_found_field);
|
|
|
|
|
|
|
|
/* Reference is not found => depend on outer (or just error). */
|
|
|
|
prev_subselect_item->used_tables_cache|= OUTER_REF_TABLE_BIT;
|
|
|
|
prev_subselect_item->const_item_cache= 0;
|
|
|
|
|
2005-07-01 07:05:42 +03:00
|
|
|
outer_context= outer_context->outer_context;
|
|
|
|
} while (outer_context);
|
2005-03-01 14:54:47 +03:00
|
|
|
|
|
|
|
DBUG_ASSERT(from_field != 0 && from_field != view_ref_found);
|
|
|
|
if (from_field != not_found_field)
|
2003-01-25 02:25:52 +02:00
|
|
|
{
|
2005-03-01 14:54:47 +03:00
|
|
|
Item_field* fld;
|
2012-08-09 15:34:52 +04:00
|
|
|
Query_arena backup, *arena;
|
|
|
|
arena= thd->activate_stmt_arena_if_needed(&backup);
|
|
|
|
fld= new Item_field(thd, last_checked_context, from_field);
|
|
|
|
if (arena)
|
|
|
|
thd->restore_active_arena(arena, &backup);
|
|
|
|
if (!fld)
|
2005-07-01 07:05:42 +03:00
|
|
|
goto error;
|
2005-03-01 14:54:47 +03:00
|
|
|
thd->change_item_tree(reference, fld);
|
2005-07-01 07:05:42 +03:00
|
|
|
mark_as_dependent(thd, last_checked_context->select_lex,
|
|
|
|
thd->lex->current_select, this, fld);
|
2007-04-26 11:12:17 +03:00
|
|
|
/*
|
|
|
|
A reference is resolved to a nest level that's outer or the same as
|
|
|
|
the nest level of the enclosing set function : adjust the value of
|
|
|
|
max_arg_level for the function if it's needed.
|
|
|
|
*/
|
|
|
|
if (thd->lex->in_sum_func &&
|
|
|
|
thd->lex->in_sum_func->nest_level >=
|
|
|
|
last_checked_context->select_lex->nest_level)
|
|
|
|
set_if_bigger(thd->lex->in_sum_func->max_arg_level,
|
|
|
|
last_checked_context->select_lex->nest_level);
|
2005-03-01 14:54:47 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (ref == 0)
|
|
|
|
{
|
|
|
|
/* The item was not a table field and not a reference */
|
|
|
|
my_error(ER_BAD_FIELD_ERROR, MYF(0),
|
2004-11-13 19:35:51 +02:00
|
|
|
this->full_name(), current_thd->where);
|
2005-07-01 07:05:42 +03:00
|
|
|
goto error;
|
2003-01-25 02:25:52 +02:00
|
|
|
}
|
2005-03-01 14:54:47 +03:00
|
|
|
/* Should be checked in resolve_ref_in_select_and_group(). */
|
|
|
|
DBUG_ASSERT(*ref && (*ref)->fixed);
|
2005-07-01 07:05:42 +03:00
|
|
|
mark_as_dependent(thd, last_checked_context->select_lex,
|
|
|
|
context->select_lex, this, this);
|
2007-04-26 11:12:17 +03:00
|
|
|
/*
|
|
|
|
A reference is resolved to a nest level that's outer or the same as
|
|
|
|
the nest level of the enclosing set function : adjust the value of
|
|
|
|
max_arg_level for the function if it's needed.
|
|
|
|
*/
|
|
|
|
if (thd->lex->in_sum_func &&
|
|
|
|
thd->lex->in_sum_func->nest_level >=
|
|
|
|
last_checked_context->select_lex->nest_level)
|
|
|
|
set_if_bigger(thd->lex->in_sum_func->max_arg_level,
|
|
|
|
last_checked_context->select_lex->nest_level);
|
2003-01-25 02:25:52 +02:00
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2003-01-25 02:25:52 +02:00
|
|
|
|
2005-03-01 14:54:47 +03:00
|
|
|
DBUG_ASSERT(*ref);
|
2003-05-14 21:51:33 +03:00
|
|
|
/*
|
2004-11-10 12:43:08 +02:00
|
|
|
Check if this is an incorrect reference in a group function or forward
|
2008-03-14 23:11:59 +04:00
|
|
|
reference. Do not issue an error if this is:
|
|
|
|
1. outer reference (will be fixed later by the fix_inner_refs function);
|
|
|
|
2. an unnamed reference inside an aggregate function.
|
2003-05-14 21:51:33 +03:00
|
|
|
*/
|
2008-03-14 23:11:59 +04:00
|
|
|
if (!((*ref)->type() == REF_ITEM &&
|
|
|
|
((Item_ref *)(*ref))->ref_type() == OUTER_REF) &&
|
|
|
|
(((*ref)->with_sum_func && name &&
|
|
|
|
!(current_sel->linkage != GLOBAL_OPTIONS_TYPE &&
|
|
|
|
current_sel->having_fix_field)) ||
|
|
|
|
!(*ref)->fixed))
|
2002-11-21 11:01:33 +02:00
|
|
|
{
|
2004-11-13 19:35:51 +02:00
|
|
|
my_error(ER_ILLEGAL_REFERENCE, MYF(0),
|
|
|
|
name, ((*ref)->with_sum_func?
|
|
|
|
"reference to group function":
|
|
|
|
"forward reference in item list"));
|
2005-07-01 07:05:42 +03:00
|
|
|
goto error;
|
2002-11-21 11:01:33 +02:00
|
|
|
}
|
2004-12-14 01:07:06 +03:00
|
|
|
|
|
|
|
set_properties();
|
|
|
|
|
2005-03-01 14:54:47 +03:00
|
|
|
if ((*ref)->check_cols(1))
|
2005-07-01 07:05:42 +03:00
|
|
|
goto error;
|
2005-03-01 14:54:47 +03:00
|
|
|
return FALSE;
|
2005-07-01 07:05:42 +03:00
|
|
|
|
|
|
|
error:
|
|
|
|
context->process_error(thd);
|
|
|
|
return TRUE;
|
2004-12-14 01:07:06 +03:00
|
|
|
}
|
|
|
|
|
2005-03-01 14:54:47 +03:00
|
|
|
|
2004-12-14 01:07:06 +03:00
|
|
|
void Item_ref::set_properties()
|
|
|
|
{
|
2003-01-29 19:42:39 +02:00
|
|
|
max_length= (*ref)->max_length;
|
|
|
|
maybe_null= (*ref)->maybe_null;
|
|
|
|
decimals= (*ref)->decimals;
|
2003-07-30 14:15:25 +05:00
|
|
|
collation.set((*ref)->collation);
|
2005-02-07 18:24:21 +02:00
|
|
|
/*
|
|
|
|
We have to remember if we refer to a sum function, to ensure that
|
|
|
|
split_sum_func() doesn't try to change the reference.
|
|
|
|
*/
|
2003-03-26 18:37:38 +02:00
|
|
|
with_sum_func= (*ref)->with_sum_func;
|
2005-03-10 13:59:48 +02:00
|
|
|
unsigned_flag= (*ref)->unsigned_flag;
|
2007-03-04 19:54:35 -08:00
|
|
|
fixed= 1;
|
|
|
|
if (alias_name_used)
|
|
|
|
return;
|
2004-11-24 19:48:30 +02:00
|
|
|
if ((*ref)->type() == FIELD_ITEM)
|
|
|
|
alias_name_used= ((Item_ident *) (*ref))->alias_name_used;
|
|
|
|
else
|
|
|
|
alias_name_used= TRUE; // it is not field, so it is was resolved by alias
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2003-02-14 11:47:41 +02:00
|
|
|
|
2003-12-30 14:08:19 +04:00
|
|
|
void Item_ref::cleanup()
|
|
|
|
{
|
2004-02-08 20:14:13 +02:00
|
|
|
DBUG_ENTER("Item_ref::cleanup");
|
2003-12-30 14:08:19 +04:00
|
|
|
Item_ident::cleanup();
|
2004-08-26 14:34:56 +03:00
|
|
|
result_field= 0;
|
2004-02-08 20:14:13 +02:00
|
|
|
DBUG_VOID_RETURN;
|
2003-12-30 14:08:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-22 13:30:33 +03:00
|
|
|
void Item_ref::print(String *str, enum_query_type query_type)
|
2003-10-16 15:54:47 +03:00
|
|
|
{
|
2005-10-13 19:40:46 +03:00
|
|
|
if (ref)
|
2006-05-16 22:19:44 -07:00
|
|
|
{
|
|
|
|
if ((*ref)->type() != Item::CACHE_ITEM && ref_type() != VIEW_REF &&
|
2007-03-04 19:54:35 -08:00
|
|
|
!table_name && name && alias_name_used)
|
2006-05-16 22:19:44 -07:00
|
|
|
{
|
|
|
|
THD *thd= current_thd;
|
2009-05-18 23:43:06 +05:00
|
|
|
append_identifier(thd, str, (*ref)->real_item()->name,
|
2011-04-08 12:05:20 +04:00
|
|
|
strlen((*ref)->real_item()->name));
|
2006-05-16 22:19:44 -07:00
|
|
|
}
|
|
|
|
else
|
2008-02-22 13:30:33 +03:00
|
|
|
(*ref)->print(str, query_type);
|
2006-05-16 22:19:44 -07:00
|
|
|
}
|
2003-10-16 15:54:47 +03:00
|
|
|
else
|
2008-02-22 13:30:33 +03:00
|
|
|
Item_ident::print(str, query_type);
|
2003-10-16 15:54:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-08-26 13:11:06 +03:00
|
|
|
bool Item_ref::send(Protocol *prot, String *tmp)
|
|
|
|
{
|
|
|
|
if (result_field)
|
|
|
|
return prot->store(result_field);
|
|
|
|
return (*ref)->send(prot, tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-08-26 14:34:56 +03:00
|
|
|
double Item_ref::val_result()
|
|
|
|
{
|
|
|
|
if (result_field)
|
|
|
|
{
|
|
|
|
if ((null_value= result_field->is_null()))
|
|
|
|
return 0.0;
|
|
|
|
return result_field->val_real();
|
|
|
|
}
|
2004-11-11 21:39:35 +03:00
|
|
|
return val_real();
|
2004-08-26 14:34:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-17 13:55:16 +03:00
|
|
|
bool Item_ref::is_null_result()
|
|
|
|
{
|
|
|
|
if (result_field)
|
|
|
|
return (null_value=result_field->is_null());
|
|
|
|
|
|
|
|
return is_null();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-08-26 14:34:56 +03:00
|
|
|
longlong Item_ref::val_int_result()
|
|
|
|
{
|
|
|
|
if (result_field)
|
|
|
|
{
|
|
|
|
if ((null_value= result_field->is_null()))
|
2004-08-30 11:09:56 +02:00
|
|
|
return 0;
|
2004-08-26 14:34:56 +03:00
|
|
|
return result_field->val_int();
|
|
|
|
}
|
|
|
|
return val_int();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String *Item_ref::str_result(String* str)
|
|
|
|
{
|
|
|
|
if (result_field)
|
|
|
|
{
|
|
|
|
if ((null_value= result_field->is_null()))
|
|
|
|
return 0;
|
|
|
|
str->set_charset(str_value.charset());
|
|
|
|
return result_field->val_str(str, &str_value);
|
|
|
|
}
|
|
|
|
return val_str(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-09 02:50:45 +04:00
|
|
|
my_decimal *Item_ref::val_decimal_result(my_decimal *decimal_value)
|
|
|
|
{
|
|
|
|
if (result_field)
|
|
|
|
{
|
|
|
|
if ((null_value= result_field->is_null()))
|
|
|
|
return 0;
|
|
|
|
return result_field->val_decimal(decimal_value);
|
|
|
|
}
|
|
|
|
return val_decimal(decimal_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Item_ref::val_bool_result()
|
|
|
|
{
|
|
|
|
if (result_field)
|
|
|
|
{
|
|
|
|
if ((null_value= result_field->is_null()))
|
|
|
|
return 0;
|
2005-02-15 16:45:00 +02:00
|
|
|
switch (result_field->result_type()) {
|
2005-02-09 02:50:45 +04:00
|
|
|
case INT_RESULT:
|
2005-03-18 16:12:25 -08:00
|
|
|
return result_field->val_int() != 0;
|
2005-02-09 02:50:45 +04:00
|
|
|
case DECIMAL_RESULT:
|
2005-02-15 16:45:00 +02:00
|
|
|
{
|
|
|
|
my_decimal decimal_value;
|
|
|
|
my_decimal *val= result_field->val_decimal(&decimal_value);
|
|
|
|
if (val)
|
|
|
|
return !my_decimal_is_zero(val);
|
|
|
|
return 0;
|
|
|
|
}
|
2005-02-09 02:50:45 +04:00
|
|
|
case REAL_RESULT:
|
|
|
|
case STRING_RESULT:
|
|
|
|
return result_field->val_real() != 0.0;
|
|
|
|
case ROW_RESULT:
|
|
|
|
default:
|
|
|
|
DBUG_ASSERT(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return val_bool();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double Item_ref::val_real()
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(fixed);
|
|
|
|
double tmp=(*ref)->val_result();
|
|
|
|
null_value=(*ref)->null_value;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
longlong Item_ref::val_int()
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(fixed);
|
|
|
|
longlong tmp=(*ref)->val_int_result();
|
|
|
|
null_value=(*ref)->null_value;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Item_ref::val_bool()
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(fixed);
|
|
|
|
bool tmp= (*ref)->val_bool_result();
|
|
|
|
null_value= (*ref)->null_value;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String *Item_ref::val_str(String* tmp)
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(fixed);
|
|
|
|
tmp=(*ref)->str_result(tmp);
|
|
|
|
null_value=(*ref)->null_value;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Item_ref::is_null()
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(fixed);
|
2008-10-17 13:55:16 +03:00
|
|
|
bool tmp=(*ref)->is_null_result();
|
|
|
|
null_value=(*ref)->null_value;
|
|
|
|
return tmp;
|
2005-02-09 02:50:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-23 22:08:31 +02:00
|
|
|
bool Item_ref::get_date(MYSQL_TIME *ltime,uint fuzzydate)
|
2005-02-09 02:50:45 +04:00
|
|
|
{
|
|
|
|
return (null_value=(*ref)->get_date_result(ltime,fuzzydate));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
my_decimal *Item_ref::val_decimal(my_decimal *decimal_value)
|
|
|
|
{
|
2005-05-31 05:56:22 -07:00
|
|
|
my_decimal *val= (*ref)->val_decimal_result(decimal_value);
|
2005-02-09 02:50:45 +04:00
|
|
|
null_value= (*ref)->null_value;
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2005-06-22 04:45:10 +04:00
|
|
|
int Item_ref::save_in_field(Field *to, bool no_conversions)
|
|
|
|
{
|
|
|
|
int res;
|
2007-02-09 11:05:23 +02:00
|
|
|
DBUG_ASSERT(!result_field);
|
2005-06-22 04:45:10 +04:00
|
|
|
res= (*ref)->save_in_field(to, no_conversions);
|
|
|
|
null_value= (*ref)->null_value;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2005-02-09 02:50:45 +04:00
|
|
|
|
2006-01-06 00:47:49 +02:00
|
|
|
void Item_ref::save_org_in_field(Field *field)
|
|
|
|
{
|
|
|
|
(*ref)->save_org_in_field(field);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-01 07:05:42 +03:00
|
|
|
void Item_ref::make_field(Send_field *field)
|
|
|
|
{
|
|
|
|
(*ref)->make_field(field);
|
|
|
|
/* Non-zero in case of a view */
|
|
|
|
if (name)
|
|
|
|
field->col_name= name;
|
|
|
|
if (table_name)
|
|
|
|
field->table_name= table_name;
|
|
|
|
if (db_name)
|
|
|
|
field->db_name= db_name;
|
2008-08-20 14:49:28 +05:00
|
|
|
if (orig_field_name)
|
|
|
|
field->org_col_name= orig_field_name;
|
|
|
|
if (orig_table_name)
|
|
|
|
field->org_table_name= orig_table_name;
|
2005-07-01 16:23:05 +04:00
|
|
|
}
|
2005-07-01 07:05:42 +03:00
|
|
|
|
|
|
|
|
2007-06-20 12:25:07 +05:00
|
|
|
Item *Item_ref::get_tmp_table_item(THD *thd)
|
|
|
|
{
|
|
|
|
if (!result_field)
|
|
|
|
return (*ref)->get_tmp_table_item(thd);
|
|
|
|
|
|
|
|
Item_field *item= new Item_field(result_field);
|
|
|
|
if (item)
|
|
|
|
{
|
|
|
|
item->table_name= table_name;
|
|
|
|
item->db_name= db_name;
|
|
|
|
}
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-22 13:30:33 +03:00
|
|
|
void Item_ref_null_helper::print(String *str, enum_query_type query_type)
|
2003-10-16 15:54:47 +03:00
|
|
|
{
|
2005-11-20 20:47:07 +02:00
|
|
|
str->append(STRING_WITH_LEN("<ref_null_helper>("));
|
2005-10-13 19:40:46 +03:00
|
|
|
if (ref)
|
2008-02-22 13:30:33 +03:00
|
|
|
(*ref)->print(str, query_type);
|
2003-10-16 15:54:47 +03:00
|
|
|
else
|
|
|
|
str->append('?');
|
|
|
|
str->append(')');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-09 02:50:45 +04:00
|
|
|
double Item_direct_ref::val_real()
|
|
|
|
{
|
|
|
|
double tmp=(*ref)->val_real();
|
|
|
|
null_value=(*ref)->null_value;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
longlong Item_direct_ref::val_int()
|
|
|
|
{
|
|
|
|
longlong tmp=(*ref)->val_int();
|
|
|
|
null_value=(*ref)->null_value;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String *Item_direct_ref::val_str(String* tmp)
|
|
|
|
{
|
|
|
|
tmp=(*ref)->val_str(tmp);
|
|
|
|
null_value=(*ref)->null_value;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
my_decimal *Item_direct_ref::val_decimal(my_decimal *decimal_value)
|
|
|
|
{
|
|
|
|
my_decimal *tmp= (*ref)->val_decimal(decimal_value);
|
|
|
|
null_value=(*ref)->null_value;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Item_direct_ref::val_bool()
|
|
|
|
{
|
|
|
|
bool tmp= (*ref)->val_bool();
|
|
|
|
null_value=(*ref)->null_value;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Item_direct_ref::is_null()
|
|
|
|
{
|
2005-06-07 05:43:59 +03:00
|
|
|
return (*ref)->is_null();
|
2005-02-09 02:50:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-23 22:08:31 +02:00
|
|
|
bool Item_direct_ref::get_date(MYSQL_TIME *ltime,uint fuzzydate)
|
2005-02-09 02:50:45 +04:00
|
|
|
{
|
2012-01-12 13:02:51 +04:00
|
|
|
bool tmp= (*ref)->get_date(ltime, fuzzydate);
|
|
|
|
null_value= (*ref)->null_value;
|
|
|
|
return tmp;
|
2005-02-09 02:50:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
|
|
|
Prepare referenced field then call usual Item_direct_ref::fix_fields .
|
2005-07-01 07:05:42 +03:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@param thd thread handler
|
|
|
|
@param reference reference on reference where this item stored
|
2005-07-01 07:05:42 +03:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@retval
|
2005-07-01 07:05:42 +03:00
|
|
|
FALSE OK
|
2007-10-11 13:29:09 -04:00
|
|
|
@retval
|
2005-07-01 07:05:42 +03:00
|
|
|
TRUE Error
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool Item_direct_view_ref::fix_fields(THD *thd, Item **reference)
|
|
|
|
{
|
|
|
|
/* view fild reference must be defined */
|
|
|
|
DBUG_ASSERT(*ref);
|
|
|
|
/* (*ref)->check_cols() will be made in Item_direct_ref::fix_fields */
|
2009-09-29 07:23:38 +05:00
|
|
|
if ((*ref)->fixed)
|
|
|
|
{
|
|
|
|
Item *ref_item= (*ref)->real_item();
|
|
|
|
if (ref_item->type() == Item::FIELD_ITEM)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
In some cases we need to update table read set(see bug#47150).
|
|
|
|
If ref item is FIELD_ITEM and fixed then field and table
|
|
|
|
have proper values. So we can use them for update.
|
|
|
|
*/
|
|
|
|
Field *fld= ((Item_field*) ref_item)->field;
|
|
|
|
DBUG_ASSERT(fld && fld->table);
|
|
|
|
if (thd->mark_used_columns == MARK_COLUMNS_READ)
|
|
|
|
bitmap_set_bit(fld->table->read_set, fld->field_index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!(*ref)->fixed &&
|
|
|
|
((*ref)->fix_fields(thd, ref)))
|
2005-07-01 07:05:42 +03:00
|
|
|
return TRUE;
|
2009-09-29 07:23:38 +05:00
|
|
|
|
2005-07-01 07:05:42 +03:00
|
|
|
return Item_direct_ref::fix_fields(thd, reference);
|
|
|
|
}
|
|
|
|
|
2007-02-21 23:00:32 +03:00
|
|
|
/*
|
|
|
|
Prepare referenced outer field then call usual Item_direct_ref::fix_fields
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
Item_outer_ref::fix_fields()
|
|
|
|
thd thread handler
|
|
|
|
reference reference on reference where this item stored
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
FALSE OK
|
|
|
|
TRUE Error
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool Item_outer_ref::fix_fields(THD *thd, Item **reference)
|
|
|
|
{
|
2007-04-15 08:31:34 +04:00
|
|
|
bool err;
|
|
|
|
/* outer_ref->check_cols() will be made in Item_direct_ref::fix_fields */
|
|
|
|
if ((*ref) && !(*ref)->fixed && ((*ref)->fix_fields(thd, reference)))
|
2007-02-21 23:00:32 +03:00
|
|
|
return TRUE;
|
2007-04-15 08:31:34 +04:00
|
|
|
err= Item_direct_ref::fix_fields(thd, reference);
|
|
|
|
if (!outer_ref)
|
|
|
|
outer_ref= *ref;
|
|
|
|
if ((*ref)->type() == Item::FIELD_ITEM)
|
|
|
|
table_name= ((Item_field*)outer_ref)->table_name;
|
|
|
|
return err;
|
2007-02-21 23:00:32 +03:00
|
|
|
}
|
|
|
|
|
2007-04-15 08:31:34 +04:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
2005-11-11 11:40:35 +02:00
|
|
|
Compare two view column references for equality.
|
2005-07-12 23:22:08 +04:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
A view column reference is considered equal to another column
|
|
|
|
reference if the second one is a view column and if both column
|
|
|
|
references resolve to the same item. It is assumed that both
|
|
|
|
items are of the same type.
|
2005-07-12 23:22:08 +04:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@param item item to compare with
|
|
|
|
@param binary_cmp make binary comparison
|
2005-07-12 23:22:08 +04:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@retval
|
2005-07-12 23:22:08 +04:00
|
|
|
TRUE Referenced item is equal to given item
|
2007-10-11 13:29:09 -04:00
|
|
|
@retval
|
2005-07-12 23:22:08 +04:00
|
|
|
FALSE otherwise
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool Item_direct_view_ref::eq(const Item *item, bool binary_cmp) const
|
|
|
|
{
|
2005-11-11 11:40:35 +02:00
|
|
|
if (item->type() == REF_ITEM)
|
|
|
|
{
|
|
|
|
Item_ref *item_ref= (Item_ref*) item;
|
|
|
|
if (item_ref->ref_type() == VIEW_REF)
|
|
|
|
{
|
|
|
|
Item *item_ref_ref= *(item_ref->ref);
|
2006-02-22 17:07:18 +02:00
|
|
|
return ((*ref)->real_item() == item_ref_ref->real_item());
|
2005-11-11 11:40:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
2005-07-12 23:22:08 +04:00
|
|
|
}
|
2005-07-01 07:05:42 +03:00
|
|
|
|
2003-01-05 14:07:24 +04:00
|
|
|
bool Item_default_value::eq(const Item *item, bool binary_cmp) const
|
|
|
|
{
|
2003-01-22 20:08:12 +04:00
|
|
|
return item->type() == DEFAULT_VALUE_ITEM &&
|
2003-01-05 14:07:24 +04:00
|
|
|
((Item_default_value *)item)->arg->eq(arg, binary_cmp);
|
|
|
|
}
|
|
|
|
|
2003-02-14 11:47:41 +02:00
|
|
|
|
2005-07-01 07:05:42 +03:00
|
|
|
bool Item_default_value::fix_fields(THD *thd, Item **items)
|
2003-01-05 14:07:24 +04:00
|
|
|
{
|
2005-06-14 20:04:42 +05:00
|
|
|
Item *real_arg;
|
2004-10-02 22:20:08 +03:00
|
|
|
Item_field *field_arg;
|
|
|
|
Field *def_field;
|
2004-03-17 14:26:26 +02:00
|
|
|
DBUG_ASSERT(fixed == 0);
|
2004-10-02 22:20:08 +03:00
|
|
|
|
2003-01-21 20:20:46 +04:00
|
|
|
if (!arg)
|
2004-03-18 15:14:36 +02:00
|
|
|
{
|
|
|
|
fixed= 1;
|
2004-10-20 04:04:37 +03:00
|
|
|
return FALSE;
|
2004-03-18 15:14:36 +02:00
|
|
|
}
|
2005-07-01 07:05:42 +03:00
|
|
|
if (!arg->fixed && arg->fix_fields(thd, &arg))
|
|
|
|
goto error;
|
|
|
|
|
2005-06-14 17:43:51 +05:00
|
|
|
|
2005-06-14 20:04:42 +05:00
|
|
|
real_arg= arg->real_item();
|
|
|
|
if (real_arg->type() != FIELD_ITEM)
|
2003-01-05 14:07:24 +04:00
|
|
|
{
|
2005-06-14 17:43:51 +05:00
|
|
|
my_error(ER_NO_DEFAULT_FOR_FIELD, MYF(0), arg->name);
|
2005-07-01 07:05:42 +03:00
|
|
|
goto error;
|
2003-01-05 14:07:24 +04:00
|
|
|
}
|
2005-06-14 17:43:51 +05:00
|
|
|
|
2005-06-14 20:04:42 +05:00
|
|
|
field_arg= (Item_field *)real_arg;
|
2004-10-02 22:20:08 +03:00
|
|
|
if (field_arg->field->flags & NO_DEFAULT_VALUE_FLAG)
|
|
|
|
{
|
2004-11-13 19:35:51 +02:00
|
|
|
my_error(ER_NO_DEFAULT_FOR_FIELD, MYF(0), field_arg->field->field_name);
|
2005-07-01 07:05:42 +03:00
|
|
|
goto error;
|
2004-10-02 22:20:08 +03:00
|
|
|
}
|
|
|
|
if (!(def_field= (Field*) sql_alloc(field_arg->field->size_of())))
|
2005-07-01 07:05:42 +03:00
|
|
|
goto error;
|
2003-01-05 14:07:24 +04:00
|
|
|
memcpy(def_field, field_arg->field, field_arg->field->size_of());
|
2005-11-23 22:45:02 +02:00
|
|
|
def_field->move_field_offset((my_ptrdiff_t)
|
|
|
|
(def_field->table->s->default_values -
|
|
|
|
def_field->table->record[0]));
|
2003-01-05 14:07:24 +04:00
|
|
|
set_field(def_field);
|
2004-10-20 04:04:37 +03:00
|
|
|
return FALSE;
|
2005-07-01 07:05:42 +03:00
|
|
|
|
|
|
|
error:
|
|
|
|
context->process_error(thd);
|
|
|
|
return TRUE;
|
2003-01-05 14:07:24 +04:00
|
|
|
}
|
|
|
|
|
2005-01-13 18:23:34 -08:00
|
|
|
|
2008-02-22 13:30:33 +03:00
|
|
|
void Item_default_value::print(String *str, enum_query_type query_type)
|
2003-01-05 17:56:11 +04:00
|
|
|
{
|
2003-01-21 20:20:46 +04:00
|
|
|
if (!arg)
|
|
|
|
{
|
2005-11-20 20:47:07 +02:00
|
|
|
str->append(STRING_WITH_LEN("default"));
|
2003-01-22 20:08:12 +04:00
|
|
|
return;
|
2003-01-21 20:20:46 +04:00
|
|
|
}
|
2005-11-20 20:47:07 +02:00
|
|
|
str->append(STRING_WITH_LEN("default("));
|
2008-02-22 13:30:33 +03:00
|
|
|
arg->print(str, query_type);
|
2003-01-05 17:56:11 +04:00
|
|
|
str->append(')');
|
|
|
|
}
|
2002-12-03 13:08:25 +02:00
|
|
|
|
2005-01-13 18:23:34 -08:00
|
|
|
|
|
|
|
int Item_default_value::save_in_field(Field *field_arg, bool no_conversions)
|
|
|
|
{
|
|
|
|
if (!arg)
|
|
|
|
{
|
2010-02-17 16:13:42 +04:00
|
|
|
if (field_arg->flags & NO_DEFAULT_VALUE_FLAG &&
|
|
|
|
field_arg->real_type() != MYSQL_TYPE_ENUM)
|
2005-01-13 18:23:34 -08:00
|
|
|
{
|
2007-02-12 15:41:36 +04:00
|
|
|
if (field_arg->reset())
|
|
|
|
{
|
|
|
|
my_message(ER_CANT_CREATE_GEOMETRY_OBJECT,
|
|
|
|
ER(ER_CANT_CREATE_GEOMETRY_OBJECT), MYF(0));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2005-07-01 07:05:42 +03:00
|
|
|
if (context->error_processor == &view_error_processor)
|
|
|
|
{
|
2005-09-02 09:50:17 +03:00
|
|
|
TABLE_LIST *view= cached_table->top_table();
|
2005-07-01 07:05:42 +03:00
|
|
|
push_warning_printf(field_arg->table->in_use,
|
|
|
|
MYSQL_ERROR::WARN_LEVEL_WARN,
|
|
|
|
ER_NO_DEFAULT_FOR_VIEW_FIELD,
|
|
|
|
ER(ER_NO_DEFAULT_FOR_VIEW_FIELD),
|
|
|
|
view->view_db.str,
|
|
|
|
view->view_name.str);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
push_warning_printf(field_arg->table->in_use,
|
|
|
|
MYSQL_ERROR::WARN_LEVEL_WARN,
|
|
|
|
ER_NO_DEFAULT_FOR_FIELD,
|
|
|
|
ER(ER_NO_DEFAULT_FOR_FIELD),
|
|
|
|
field_arg->field_name);
|
|
|
|
}
|
2005-01-13 18:23:34 -08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
field_arg->set_default();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return Item_field::save_in_field(field_arg, no_conversions);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
2006-08-25 11:34:13 +04:00
|
|
|
This method like the walk method traverses the item tree, but at the
|
2007-10-11 13:29:09 -04:00
|
|
|
same time it can replace some nodes in the tree.
|
2006-08-24 15:49:12 +04:00
|
|
|
*/
|
2006-08-25 11:34:13 +04:00
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
Item *Item_default_value::transform(Item_transformer transformer, uchar *args)
|
2006-08-24 15:49:12 +04:00
|
|
|
{
|
2011-05-06 15:39:40 +04:00
|
|
|
DBUG_ASSERT(!current_thd->stmt_arena->is_stmt_prepare());
|
2006-08-24 15:49:12 +04:00
|
|
|
|
2008-09-03 12:32:43 +05:00
|
|
|
/*
|
|
|
|
If the value of arg is NULL, then this object represents a constant,
|
|
|
|
so further transformation is unnecessary (and impossible).
|
|
|
|
*/
|
|
|
|
if (!arg)
|
|
|
|
return 0;
|
|
|
|
|
2006-08-24 15:49:12 +04:00
|
|
|
Item *new_item= arg->transform(transformer, args);
|
|
|
|
if (!new_item)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
THD::change_item_tree() should be called only if the tree was
|
|
|
|
really transformed, i.e. when a new item has been created.
|
|
|
|
Otherwise we'll be allocating a lot of unnecessary memory for
|
|
|
|
change records at each execution.
|
|
|
|
*/
|
|
|
|
if (arg != new_item)
|
|
|
|
current_thd->change_item_tree(&arg, new_item);
|
|
|
|
return (this->*transformer)(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-03 01:16:56 +02:00
|
|
|
bool Item_insert_value::eq(const Item *item, bool binary_cmp) const
|
|
|
|
{
|
|
|
|
return item->type() == INSERT_VALUE_ITEM &&
|
|
|
|
((Item_default_value *)item)->arg->eq(arg, binary_cmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-01 07:05:42 +03:00
|
|
|
bool Item_insert_value::fix_fields(THD *thd, Item **items)
|
2003-05-03 01:16:56 +02:00
|
|
|
{
|
2004-03-17 14:26:26 +02:00
|
|
|
DBUG_ASSERT(fixed == 0);
|
2005-10-27 23:43:20 +03:00
|
|
|
/* We should only check that arg is in first table */
|
2005-11-01 15:54:30 +02:00
|
|
|
if (!arg->fixed)
|
2005-10-25 20:04:12 +04:00
|
|
|
{
|
2005-11-01 15:54:30 +02:00
|
|
|
bool res;
|
2007-07-06 16:18:49 +04:00
|
|
|
TABLE_LIST *orig_next_table= context->last_name_resolution_table;
|
2005-11-01 15:54:30 +02:00
|
|
|
context->last_name_resolution_table= context->first_name_resolution_table;
|
|
|
|
res= arg->fix_fields(thd, &arg);
|
2005-10-27 23:43:20 +03:00
|
|
|
context->last_name_resolution_table= orig_next_table;
|
2005-11-01 15:54:30 +02:00
|
|
|
if (res)
|
|
|
|
return TRUE;
|
2005-10-25 20:04:12 +04:00
|
|
|
}
|
2004-02-18 01:08:52 +02:00
|
|
|
|
2003-05-03 01:16:56 +02:00
|
|
|
if (arg->type() == REF_ITEM)
|
2012-03-12 08:56:56 +01:00
|
|
|
arg= static_cast<Item_ref *>(arg)->ref[0];
|
|
|
|
if (arg->type() != FIELD_ITEM)
|
2003-05-03 01:16:56 +02:00
|
|
|
{
|
2012-03-12 08:56:56 +01:00
|
|
|
my_error(ER_BAD_FIELD_ERROR, MYF(0), "", "VALUES() function");
|
|
|
|
return TRUE;
|
2003-05-03 01:16:56 +02:00
|
|
|
}
|
2005-12-09 00:58:59 +03:00
|
|
|
|
2003-05-03 01:16:56 +02:00
|
|
|
Item_field *field_arg= (Item_field *)arg;
|
2005-10-25 20:04:12 +04:00
|
|
|
|
2003-05-03 01:16:56 +02:00
|
|
|
if (field_arg->field->table->insert_values)
|
|
|
|
{
|
|
|
|
Field *def_field= (Field*) sql_alloc(field_arg->field->size_of());
|
|
|
|
if (!def_field)
|
2004-10-20 04:04:37 +03:00
|
|
|
return TRUE;
|
2003-05-03 01:16:56 +02:00
|
|
|
memcpy(def_field, field_arg->field, field_arg->field->size_of());
|
2005-11-23 22:45:02 +02:00
|
|
|
def_field->move_field_offset((my_ptrdiff_t)
|
|
|
|
(def_field->table->insert_values -
|
|
|
|
def_field->table->record[0]));
|
2003-05-03 01:16:56 +02:00
|
|
|
set_field(def_field);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-11-28 12:18:13 +02:00
|
|
|
Field *tmp_field= field_arg->field;
|
2003-05-03 01:16:56 +02:00
|
|
|
/* charset doesn't matter here, it's to avoid sigsegv only */
|
2005-11-23 22:45:02 +02:00
|
|
|
tmp_field= new Field_null(0, 0, Field::NONE, field_arg->field->field_name,
|
|
|
|
&my_charset_bin);
|
|
|
|
if (tmp_field)
|
|
|
|
{
|
|
|
|
tmp_field->init(field_arg->field->table);
|
|
|
|
set_field(tmp_field);
|
|
|
|
}
|
2003-05-03 01:16:56 +02:00
|
|
|
}
|
2004-10-20 04:04:37 +03:00
|
|
|
return FALSE;
|
2003-05-03 01:16:56 +02:00
|
|
|
}
|
|
|
|
|
2008-02-22 13:30:33 +03:00
|
|
|
void Item_insert_value::print(String *str, enum_query_type query_type)
|
2003-05-03 01:16:56 +02:00
|
|
|
{
|
2005-11-20 20:47:07 +02:00
|
|
|
str->append(STRING_WITH_LEN("values("));
|
2008-02-22 13:30:33 +03:00
|
|
|
arg->print(str, query_type);
|
2003-05-03 01:16:56 +02:00
|
|
|
str->append(')');
|
|
|
|
}
|
|
|
|
|
2004-09-07 16:29:46 +04:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
2005-05-24 22:19:33 +04:00
|
|
|
Find index of Field object which will be appropriate for item
|
|
|
|
representing field of row being changed in trigger.
|
2004-09-07 16:29:46 +04:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@param thd current thread context
|
|
|
|
@param table table of trigger (and where we looking for fields)
|
|
|
|
@param table_grant_info GRANT_INFO of the subject table
|
2004-09-07 16:29:46 +04:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@note
|
2004-09-07 16:29:46 +04:00
|
|
|
This function does almost the same as fix_fields() for Item_field
|
2005-05-24 22:19:33 +04:00
|
|
|
but is invoked right after trigger definition parsing. Since at
|
|
|
|
this stage we can't say exactly what Field object (corresponding
|
|
|
|
to TABLE::record[0] or TABLE::record[1]) should be bound to this
|
|
|
|
Item, we only find out index of the Field and then select concrete
|
|
|
|
Field object in fix_fields() (by that time Table_trigger_list::old_field/
|
|
|
|
new_field should point to proper array of Fields).
|
|
|
|
It also binds Item_trigger_field to Table_triggers_list object for
|
|
|
|
table of trigger which uses this item.
|
2004-09-07 16:29:46 +04:00
|
|
|
*/
|
2005-05-24 22:19:33 +04:00
|
|
|
|
2006-01-24 20:15:12 +03:00
|
|
|
void Item_trigger_field::setup_field(THD *thd, TABLE *table,
|
|
|
|
GRANT_INFO *table_grant_info)
|
2004-09-07 16:29:46 +04:00
|
|
|
{
|
2006-07-02 01:51:10 +04:00
|
|
|
/*
|
2006-07-06 13:33:23 +04:00
|
|
|
It is too early to mark fields used here, because before execution
|
|
|
|
of statement that will invoke trigger other statements may use same
|
|
|
|
TABLE object, so all such mark-up will be wiped out.
|
|
|
|
So instead we do it in Table_triggers_list::mark_fields_used()
|
|
|
|
method which is called during execution of these statements.
|
2006-07-02 01:51:10 +04: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 18:52:22 +03:00
|
|
|
enum_mark_columns save_mark_used_columns= thd->mark_used_columns;
|
|
|
|
thd->mark_used_columns= MARK_COLUMNS_NONE;
|
2005-05-24 22:19:33 +04:00
|
|
|
/*
|
|
|
|
Try to find field by its name and if it will be found
|
|
|
|
set field_idx properly.
|
|
|
|
*/
|
2005-08-12 17:57:19 +03:00
|
|
|
(void)find_field_in_table(thd, table, field_name, (uint) strlen(field_name),
|
2005-11-30 21:27:11 +02:00
|
|
|
0, &field_idx);
|
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 18:52:22 +03:00
|
|
|
thd->mark_used_columns= save_mark_used_columns;
|
2005-05-24 22:19:33 +04:00
|
|
|
triggers= table->triggers;
|
2006-01-24 20:15:12 +03:00
|
|
|
table_grants= table_grant_info;
|
2004-09-07 16:29:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Item_trigger_field::eq(const Item *item, bool binary_cmp) const
|
|
|
|
{
|
|
|
|
return item->type() == TRIGGER_FIELD_ITEM &&
|
|
|
|
row_version == ((Item_trigger_field *)item)->row_version &&
|
|
|
|
!my_strcasecmp(system_charset_info, field_name,
|
|
|
|
((Item_trigger_field *)item)->field_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-15 18:18:37 +04:00
|
|
|
void Item_trigger_field::set_required_privilege(bool rw)
|
2006-05-12 13:55:21 +04:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
Require SELECT and UPDATE privilege if this field will be read and
|
|
|
|
set, and only UPDATE privilege for setting the field.
|
|
|
|
*/
|
|
|
|
want_privilege= (rw ? SELECT_ACL | UPDATE_ACL : UPDATE_ACL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-30 03:40:42 +02:00
|
|
|
bool Item_trigger_field::set_value(THD *thd, sp_rcontext * /*ctx*/, Item **it)
|
2006-05-12 13:55:21 +04:00
|
|
|
{
|
2006-05-15 19:57:10 +02:00
|
|
|
Item *item= sp_prepare_func_item(thd, it);
|
2006-05-12 13:55:21 +04:00
|
|
|
|
2011-05-09 12:29:23 +04:00
|
|
|
if (!item)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (!fixed)
|
|
|
|
{
|
|
|
|
if (fix_fields(thd, NULL))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: field->table->copy_blobs should be false here, but let's
|
|
|
|
// remember the value at runtime to avoid subtle bugs.
|
|
|
|
bool copy_blobs_saved= field->table->copy_blobs;
|
|
|
|
|
|
|
|
field->table->copy_blobs= true;
|
|
|
|
|
|
|
|
int err_code= item->save_in_field(field, 0);
|
|
|
|
|
|
|
|
field->table->copy_blobs= copy_blobs_saved;
|
|
|
|
|
|
|
|
return err_code < 0;
|
2006-05-12 13:55:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-01 07:05:42 +03:00
|
|
|
bool Item_trigger_field::fix_fields(THD *thd, Item **items)
|
2004-09-07 16:29:46 +04:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
Since trigger is object tightly associated with TABLE object most
|
|
|
|
of its set up can be performed during trigger loading i.e. trigger
|
|
|
|
parsing! So we have little to do in fix_fields. :)
|
|
|
|
*/
|
2006-01-24 20:15:12 +03:00
|
|
|
|
2004-09-07 16:29:46 +04:00
|
|
|
DBUG_ASSERT(fixed == 0);
|
2004-11-24 12:24:02 +03:00
|
|
|
|
2006-01-24 20:15:12 +03:00
|
|
|
/* Set field. */
|
|
|
|
|
2005-05-24 22:19:33 +04:00
|
|
|
if (field_idx != (uint)-1)
|
2004-11-24 12:24:02 +03:00
|
|
|
{
|
2006-01-24 20:15:12 +03:00
|
|
|
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
|
|
|
/*
|
|
|
|
Check access privileges for the subject table. We check privileges only
|
|
|
|
in runtime.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (table_grants)
|
|
|
|
{
|
2006-05-12 13:55:21 +04:00
|
|
|
table_grants->want_privilege= want_privilege;
|
2006-01-24 20:15:12 +03:00
|
|
|
|
2007-01-27 03:46:45 +02:00
|
|
|
if (check_grant_column(thd, table_grants, triggers->trigger_table->s->db.str,
|
|
|
|
triggers->trigger_table->s->table_name.str, field_name,
|
2006-01-24 20:15:12 +03:00
|
|
|
strlen(field_name), thd->security_ctx))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#endif // NO_EMBEDDED_ACCESS_CHECKS
|
|
|
|
|
2005-05-24 22:19:33 +04:00
|
|
|
field= (row_version == OLD_ROW) ? triggers->old_field[field_idx] :
|
|
|
|
triggers->new_field[field_idx];
|
2004-11-24 12:24:02 +03:00
|
|
|
set_field(field);
|
|
|
|
fixed= 1;
|
2006-01-24 20:15:12 +03:00
|
|
|
return FALSE;
|
2004-11-24 12:24:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
my_error(ER_BAD_FIELD_ERROR, MYF(0), field_name,
|
|
|
|
(row_version == NEW_ROW) ? "NEW" : "OLD");
|
2006-01-24 20:15:12 +03:00
|
|
|
return TRUE;
|
2004-09-07 16:29:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-22 13:30:33 +03:00
|
|
|
void Item_trigger_field::print(String *str, enum_query_type query_type)
|
2004-09-07 16:29:46 +04:00
|
|
|
{
|
|
|
|
str->append((row_version == NEW_ROW) ? "NEW" : "OLD", 3);
|
|
|
|
str->append('.');
|
|
|
|
str->append(field_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Item_trigger_field::cleanup()
|
|
|
|
{
|
2006-05-12 13:55:21 +04:00
|
|
|
want_privilege= original_privilege;
|
2004-09-07 16:29:46 +04:00
|
|
|
/*
|
|
|
|
Since special nature of Item_trigger_field we should not do most of
|
|
|
|
things from Item_field::cleanup() or Item_ident::cleanup() here.
|
|
|
|
*/
|
|
|
|
Item::cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
Item_result item_cmp_type(Item_result a,Item_result b)
|
|
|
|
{
|
|
|
|
if (a == STRING_RESULT && b == STRING_RESULT)
|
|
|
|
return STRING_RESULT;
|
2003-12-10 22:26:31 +03:00
|
|
|
if (a == INT_RESULT && b == INT_RESULT)
|
2000-07-31 21:29:14 +02:00
|
|
|
return INT_RESULT;
|
2002-11-15 20:32:09 +02:00
|
|
|
else if (a == ROW_RESULT || b == ROW_RESULT)
|
|
|
|
return ROW_RESULT;
|
2005-02-09 02:50:45 +04:00
|
|
|
if ((a == INT_RESULT || a == DECIMAL_RESULT) &&
|
|
|
|
(b == INT_RESULT || b == DECIMAL_RESULT))
|
|
|
|
return DECIMAL_RESULT;
|
2003-12-10 22:26:31 +03:00
|
|
|
return REAL_RESULT;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-11 11:16:51 +02:00
|
|
|
void resolve_const_item(THD *thd, Item **ref, Item *comp_item)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2004-11-11 11:16:51 +02:00
|
|
|
Item *item= *ref;
|
2005-11-24 19:16:51 +03:00
|
|
|
Item *new_item= NULL;
|
2000-07-31 21:29:14 +02:00
|
|
|
if (item->basic_const_item())
|
2004-11-11 11:16:51 +02:00
|
|
|
return; // Can't be better
|
2000-07-31 21:29:14 +02:00
|
|
|
Item_result res_type=item_cmp_type(comp_item->result_type(),
|
|
|
|
item->result_type());
|
|
|
|
char *name=item->name; // Alloced by sql_alloc
|
|
|
|
|
2005-02-15 16:45:00 +02:00
|
|
|
switch (res_type) {
|
2005-02-09 02:50:45 +04:00
|
|
|
case STRING_RESULT:
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
char buff[MAX_FIELD_WIDTH];
|
2003-01-29 17:31:20 +04:00
|
|
|
String tmp(buff,sizeof(buff),&my_charset_bin),*result;
|
2000-07-31 21:29:14 +02:00
|
|
|
result=item->val_str(&tmp);
|
|
|
|
if (item->null_value)
|
2004-11-11 11:16:51 +02:00
|
|
|
new_item= new Item_null(name);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
uint length= result->length();
|
|
|
|
char *tmp_str= sql_strmake(result->ptr(), length);
|
|
|
|
new_item= new Item_string(name, tmp_str, length, result->charset());
|
|
|
|
}
|
2005-02-09 02:50:45 +04:00
|
|
|
break;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2005-02-09 02:50:45 +04:00
|
|
|
case INT_RESULT:
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
longlong result=item->val_int();
|
|
|
|
uint length=item->max_length;
|
|
|
|
bool null_value=item->null_value;
|
2004-11-11 11:16:51 +02:00
|
|
|
new_item= (null_value ? (Item*) new Item_null(name) :
|
|
|
|
(Item*) new Item_int(name, result, length));
|
2005-02-09 02:50:45 +04:00
|
|
|
break;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2005-09-28 15:32:05 +02:00
|
|
|
case ROW_RESULT:
|
2005-11-25 13:57:13 +03:00
|
|
|
if (item->type() == Item::ROW_ITEM && comp_item->type() == Item::ROW_ITEM)
|
2005-09-28 00:58:12 +04:00
|
|
|
{
|
2005-11-24 19:16:51 +03:00
|
|
|
/*
|
|
|
|
Substitute constants only in Item_rows. Don't affect other Items
|
|
|
|
with ROW_RESULT (eg Item_singlerow_subselect).
|
|
|
|
|
|
|
|
For such Items more optimal is to detect if it is constant and replace
|
|
|
|
it with Item_row. This would optimize queries like this:
|
|
|
|
SELECT * FROM t1 WHERE (a,b) = (SELECT a,b FROM t2 LIMIT 1);
|
|
|
|
*/
|
2005-10-07 03:12:15 +03:00
|
|
|
Item_row *item_row= (Item_row*) item;
|
|
|
|
Item_row *comp_item_row= (Item_row*) comp_item;
|
|
|
|
uint col;
|
2005-09-28 00:58:12 +04:00
|
|
|
new_item= 0;
|
|
|
|
/*
|
|
|
|
If item and comp_item are both Item_rows and have same number of cols
|
2005-10-07 03:12:15 +03:00
|
|
|
then process items in Item_row one by one.
|
|
|
|
We can't ignore NULL values here as this item may be used with <=>, in
|
|
|
|
which case NULL's are significant.
|
2005-09-28 00:58:12 +04:00
|
|
|
*/
|
2005-10-07 03:12:15 +03:00
|
|
|
DBUG_ASSERT(item->result_type() == comp_item->result_type());
|
|
|
|
DBUG_ASSERT(item_row->cols() == comp_item_row->cols());
|
|
|
|
col= item_row->cols();
|
|
|
|
while (col-- > 0)
|
2006-12-15 00:51:37 +02:00
|
|
|
resolve_const_item(thd, item_row->addr(col),
|
|
|
|
comp_item_row->element_index(col));
|
2005-09-28 21:30:10 +04:00
|
|
|
break;
|
2005-09-28 00:58:12 +04:00
|
|
|
}
|
2005-11-25 13:57:13 +03:00
|
|
|
/* Fallthrough */
|
2005-02-09 02:50:45 +04:00
|
|
|
case REAL_RESULT:
|
2000-07-31 21:29:14 +02:00
|
|
|
{ // It must REAL_RESULT
|
2004-11-11 21:39:35 +03:00
|
|
|
double result= item->val_real();
|
2000-07-31 21:29:14 +02:00
|
|
|
uint length=item->max_length,decimals=item->decimals;
|
|
|
|
bool null_value=item->null_value;
|
2004-11-11 11:16:51 +02:00
|
|
|
new_item= (null_value ? (Item*) new Item_null(name) : (Item*)
|
2005-02-09 02:50:45 +04:00
|
|
|
new Item_float(name, result, decimals, length));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DECIMAL_RESULT:
|
|
|
|
{
|
|
|
|
my_decimal decimal_value;
|
|
|
|
my_decimal *result= item->val_decimal(&decimal_value);
|
|
|
|
uint length= item->max_length, decimals= item->decimals;
|
|
|
|
bool null_value= item->null_value;
|
|
|
|
new_item= (null_value ?
|
|
|
|
(Item*) new Item_null(name) :
|
|
|
|
(Item*) new Item_decimal(name, result, length, decimals));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
DBUG_ASSERT(0);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2004-11-11 11:16:51 +02:00
|
|
|
if (new_item)
|
|
|
|
thd->change_item_tree(ref, new_item);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
2009-11-02 13:24:07 +01:00
|
|
|
Compare the value stored in field with the expression from the query.
|
2007-10-11 13:29:09 -04:00
|
|
|
|
2009-11-02 13:24:07 +01:00
|
|
|
@param field Field which the Item is stored in after conversion
|
|
|
|
@param item Original expression from query
|
2009-08-26 12:51:23 +02:00
|
|
|
|
2009-11-02 13:24:07 +01:00
|
|
|
@return Returns an integer greater than, equal to, or less than 0 if
|
|
|
|
the value stored in the field is greater than, equal to,
|
|
|
|
or less than the original Item. A 0 may also be returned if
|
|
|
|
out of memory.
|
2009-08-26 12:51:23 +02:00
|
|
|
|
2012-01-25 16:05:27 +01:00
|
|
|
@note We use this in the range optimizer/partition pruning,
|
2009-08-26 12:51:23 +02:00
|
|
|
because in some cases we can't store the value in the field
|
|
|
|
without some precision/character loss.
|
2012-01-25 16:05:27 +01:00
|
|
|
|
|
|
|
We similarly use it to verify that expressions like
|
|
|
|
BIGINT_FIELD <cmp> <literal value>
|
|
|
|
is done correctly (as int/decimal/float according to literal type).
|
2000-07-31 21:29:14 +02:00
|
|
|
*/
|
|
|
|
|
2009-11-02 13:24:07 +01:00
|
|
|
int stored_field_cmp_to_item(THD *thd, Field *field, Item *item)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
Item_result res_type=item_cmp_type(field->result_type(),
|
|
|
|
item->result_type());
|
|
|
|
if (res_type == STRING_RESULT)
|
|
|
|
{
|
|
|
|
char item_buff[MAX_FIELD_WIDTH];
|
|
|
|
char field_buff[MAX_FIELD_WIDTH];
|
2009-11-02 13:24:07 +01:00
|
|
|
|
|
|
|
String item_tmp(item_buff,sizeof(item_buff),&my_charset_bin);
|
2003-01-29 17:31:20 +04:00
|
|
|
String field_tmp(field_buff,sizeof(field_buff),&my_charset_bin);
|
2009-11-02 13:24:07 +01:00
|
|
|
String *item_result= item->val_str(&item_tmp);
|
|
|
|
/*
|
|
|
|
Some implementations of Item::val_str(String*) actually modify
|
|
|
|
the field Item::null_value, hence we can't check it earlier.
|
|
|
|
*/
|
2000-07-31 21:29:14 +02:00
|
|
|
if (item->null_value)
|
2009-08-26 12:51:23 +02:00
|
|
|
return 0;
|
2009-11-02 13:24:07 +01:00
|
|
|
String *field_result= field->val_str(&field_tmp);
|
2009-08-26 12:51:23 +02:00
|
|
|
|
2009-11-02 13:24:07 +01:00
|
|
|
enum_field_types field_type= field->type();
|
|
|
|
|
2010-09-13 11:18:35 +04:00
|
|
|
if (field_type == MYSQL_TYPE_DATE || field_type == MYSQL_TYPE_DATETIME ||
|
|
|
|
field_type == MYSQL_TYPE_TIMESTAMP)
|
2009-10-13 09:43:27 +05:00
|
|
|
{
|
2009-11-02 13:24:07 +01:00
|
|
|
enum_mysql_timestamp_type type= MYSQL_TIMESTAMP_ERROR;
|
|
|
|
|
|
|
|
if (field_type == MYSQL_TYPE_DATE)
|
|
|
|
type= MYSQL_TIMESTAMP_DATE;
|
|
|
|
|
2010-09-13 11:18:35 +04:00
|
|
|
if (field_type == MYSQL_TYPE_DATETIME ||
|
|
|
|
field_type == MYSQL_TYPE_TIMESTAMP)
|
2009-11-02 13:24:07 +01:00
|
|
|
type= MYSQL_TIMESTAMP_DATETIME;
|
|
|
|
|
|
|
|
const char *field_name= field->field_name;
|
|
|
|
MYSQL_TIME field_time, item_time;
|
|
|
|
get_mysql_time_from_str(thd, field_result, type, field_name, &field_time);
|
|
|
|
get_mysql_time_from_str(thd, item_result, type, field_name, &item_time);
|
|
|
|
|
|
|
|
return my_time_compare(&field_time, &item_time);
|
2009-10-13 09:43:27 +05:00
|
|
|
}
|
2012-01-26 10:25:23 +01:00
|
|
|
return sortcmp(field_result, item_result, field->charset());
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
if (res_type == INT_RESULT)
|
2009-08-26 12:51:23 +02:00
|
|
|
return 0; // Both are of type int
|
2005-02-09 02:50:45 +04:00
|
|
|
if (res_type == DECIMAL_RESULT)
|
|
|
|
{
|
|
|
|
my_decimal item_buf, *item_val,
|
|
|
|
field_buf, *field_val;
|
|
|
|
item_val= item->val_decimal(&item_buf);
|
|
|
|
if (item->null_value)
|
2009-08-26 12:51:23 +02:00
|
|
|
return 0;
|
2005-02-09 02:50:45 +04:00
|
|
|
field_val= field->val_decimal(&field_buf);
|
2012-01-26 10:25:23 +01:00
|
|
|
return my_decimal_cmp(field_val, item_val);
|
2005-02-09 02:50:45 +04:00
|
|
|
}
|
2012-01-25 16:05:27 +01:00
|
|
|
/*
|
|
|
|
The patch for Bug#13463415 started using this function for comparing
|
|
|
|
BIGINTs. That uncovered a bug in Visual Studio 32bit optimized mode.
|
|
|
|
Prefixing the auto variables with volatile fixes the problem....
|
|
|
|
*/
|
|
|
|
volatile double result= item->val_real();
|
2000-07-31 21:29:14 +02:00
|
|
|
if (item->null_value)
|
2009-08-26 12:51:23 +02:00
|
|
|
return 0;
|
2012-01-25 16:05:27 +01:00
|
|
|
volatile double field_result= field->val_real();
|
2009-08-26 12:51:23 +02:00
|
|
|
if (field_result < result)
|
|
|
|
return -1;
|
|
|
|
else if (field_result > result)
|
2000-07-31 21:29:14 +02:00
|
|
|
return 1;
|
2009-08-26 12:51:23 +02:00
|
|
|
return 0;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2007-11-10 23:44:48 +04:00
|
|
|
Item_cache* Item_cache::get_cache(const Item *item)
|
2002-12-19 07:38:33 +02:00
|
|
|
{
|
2009-11-06 22:34:25 +03:00
|
|
|
return get_cache(item, item->result_type());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Get a cache item of given type.
|
|
|
|
|
|
|
|
@param item value to be cached
|
|
|
|
@param type required type of cache
|
|
|
|
|
|
|
|
@return cache item
|
|
|
|
*/
|
|
|
|
|
|
|
|
Item_cache* Item_cache::get_cache(const Item *item, const Item_result type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
2002-12-19 07:38:33 +02:00
|
|
|
case INT_RESULT:
|
2009-11-17 17:06:46 +03:00
|
|
|
return new Item_cache_int(item->field_type());
|
2002-12-19 07:38:33 +02:00
|
|
|
case REAL_RESULT:
|
|
|
|
return new Item_cache_real();
|
2005-02-09 02:50:45 +04:00
|
|
|
case DECIMAL_RESULT:
|
|
|
|
return new Item_cache_decimal();
|
2002-12-19 07:38:33 +02:00
|
|
|
case STRING_RESULT:
|
2010-10-07 20:16:30 +04:00
|
|
|
/* Not all functions that return DATE/TIME are actually DATE/TIME funcs. */
|
2011-01-12 15:58:47 +03:00
|
|
|
if ((item->is_datetime() ||
|
2010-10-07 20:16:30 +04:00
|
|
|
item->field_type() == MYSQL_TYPE_TIME) &&
|
|
|
|
(const_cast<Item*>(item))->result_as_longlong())
|
2009-12-02 00:25:51 +03:00
|
|
|
return new Item_cache_datetime(item->field_type());
|
2007-11-10 23:44:48 +04:00
|
|
|
return new Item_cache_str(item);
|
2002-12-19 21:15:09 +02:00
|
|
|
case ROW_RESULT:
|
|
|
|
return new Item_cache_row();
|
2002-12-19 07:38:33 +02:00
|
|
|
default:
|
|
|
|
// should never be in real life
|
|
|
|
DBUG_ASSERT(0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-06 22:34:25 +03:00
|
|
|
void Item_cache::store(Item *item)
|
|
|
|
{
|
2009-11-24 18:26:13 +03:00
|
|
|
example= item;
|
|
|
|
if (!item)
|
|
|
|
null_value= TRUE;
|
2009-11-06 22:34:25 +03:00
|
|
|
value_cached= FALSE;
|
|
|
|
}
|
2003-10-16 15:54:47 +03:00
|
|
|
|
2008-02-22 13:30:33 +03:00
|
|
|
void Item_cache::print(String *str, enum_query_type query_type)
|
2003-10-16 15:54:47 +03:00
|
|
|
{
|
2005-11-20 20:47:07 +02:00
|
|
|
str->append(STRING_WITH_LEN("<cache>("));
|
2003-10-16 15:54:47 +03:00
|
|
|
if (example)
|
2008-02-22 13:30:33 +03:00
|
|
|
example->print(str, query_type);
|
2003-10-16 15:54:47 +03:00
|
|
|
else
|
2008-02-22 13:30:33 +03:00
|
|
|
Item::print(str, query_type);
|
2003-10-16 15:54:47 +03:00
|
|
|
str->append(')');
|
|
|
|
}
|
|
|
|
|
2009-11-24 18:26:13 +03:00
|
|
|
bool Item_cache_int::cache_value()
|
2003-10-16 15:54:47 +03:00
|
|
|
{
|
2009-11-24 18:26:13 +03:00
|
|
|
if (!example)
|
|
|
|
return FALSE;
|
2009-11-06 22:34:25 +03:00
|
|
|
value_cached= TRUE;
|
|
|
|
value= example->val_int_result();
|
|
|
|
null_value= example->null_value;
|
|
|
|
unsigned_flag= example->unsigned_flag;
|
2009-11-24 18:26:13 +03:00
|
|
|
return TRUE;
|
2005-02-09 02:50:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-27 00:12:09 +04:00
|
|
|
void Item_cache_int::store(Item *item, longlong val_arg)
|
|
|
|
{
|
2009-11-06 22:34:25 +03:00
|
|
|
/* An explicit values is given, save it. */
|
|
|
|
value_cached= TRUE;
|
2007-04-27 00:12:09 +04:00
|
|
|
value= val_arg;
|
|
|
|
null_value= item->null_value;
|
|
|
|
unsigned_flag= item->unsigned_flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-09 02:50:45 +04:00
|
|
|
String *Item_cache_int::val_str(String *str)
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(fixed == 1);
|
2010-05-28 17:30:39 +02:00
|
|
|
if (!has_value())
|
2009-11-24 18:26:13 +03:00
|
|
|
return NULL;
|
2011-03-31 22:59:11 +04:00
|
|
|
str->set_int(value, unsigned_flag, default_charset());
|
2005-02-09 02:50:45 +04:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
my_decimal *Item_cache_int::val_decimal(my_decimal *decimal_val)
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(fixed == 1);
|
2010-05-28 17:30:39 +02:00
|
|
|
if (!has_value())
|
2009-11-24 18:26:13 +03:00
|
|
|
return NULL;
|
2005-02-09 02:50:45 +04:00
|
|
|
int2my_decimal(E_DEC_FATAL_ERROR, value, unsigned_flag, decimal_val);
|
|
|
|
return decimal_val;
|
2003-10-16 15:54:47 +03:00
|
|
|
}
|
|
|
|
|
2009-11-06 22:34:25 +03:00
|
|
|
double Item_cache_int::val_real()
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(fixed == 1);
|
2010-05-28 17:30:39 +02:00
|
|
|
if (!has_value())
|
2009-11-24 18:26:13 +03:00
|
|
|
return 0.0;
|
2009-11-06 22:34:25 +03:00
|
|
|
return (double) value;
|
|
|
|
}
|
2003-10-16 15:54:47 +03:00
|
|
|
|
2009-11-06 22:34:25 +03:00
|
|
|
longlong Item_cache_int::val_int()
|
2003-10-16 15:54:47 +03:00
|
|
|
{
|
2009-11-06 22:34:25 +03:00
|
|
|
DBUG_ASSERT(fixed == 1);
|
2010-05-28 17:30:39 +02:00
|
|
|
if (!has_value())
|
2009-11-24 18:26:13 +03:00
|
|
|
return 0;
|
2009-11-06 22:34:25 +03:00
|
|
|
return value;
|
2003-10-16 15:54:47 +03:00
|
|
|
}
|
|
|
|
|
2009-12-14 17:17:41 +03:00
|
|
|
bool Item_cache_datetime::cache_value_int()
|
2009-12-02 00:25:51 +03:00
|
|
|
{
|
2009-12-12 23:38:59 +03:00
|
|
|
if (!example)
|
2011-02-17 13:41:25 +01:00
|
|
|
return false;
|
2009-12-12 23:38:59 +03:00
|
|
|
|
2011-02-17 13:41:25 +01:00
|
|
|
value_cached= true;
|
2010-07-19 21:11:47 +04:00
|
|
|
// Mark cached string value obsolete
|
2011-02-17 13:41:25 +01:00
|
|
|
str_value_cached= false;
|
|
|
|
|
|
|
|
MYSQL_TIME ltime;
|
|
|
|
const bool eval_error=
|
|
|
|
(field_type() == MYSQL_TYPE_TIME) ?
|
|
|
|
example->get_time(<ime) :
|
|
|
|
example->get_date(<ime, TIME_FUZZY_DATE);
|
|
|
|
|
|
|
|
if (eval_error)
|
|
|
|
int_value= 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch(field_type())
|
|
|
|
{
|
|
|
|
case MYSQL_TYPE_DATETIME:
|
|
|
|
case MYSQL_TYPE_TIMESTAMP:
|
|
|
|
int_value= TIME_to_ulonglong_datetime(<ime);
|
|
|
|
break;
|
|
|
|
case MYSQL_TYPE_TIME:
|
|
|
|
int_value= TIME_to_ulonglong_time(<ime);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
int_value= TIME_to_ulonglong_date(<ime);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ltime.neg)
|
|
|
|
int_value= -int_value;
|
|
|
|
}
|
|
|
|
|
2009-12-02 00:25:51 +03:00
|
|
|
null_value= example->null_value;
|
|
|
|
unsigned_flag= example->unsigned_flag;
|
2011-02-17 13:41:25 +01:00
|
|
|
|
|
|
|
return true;
|
2009-12-02 00:25:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-12 23:38:59 +03:00
|
|
|
bool Item_cache_datetime::cache_value()
|
2009-12-02 00:25:51 +03:00
|
|
|
{
|
2009-12-12 23:38:59 +03:00
|
|
|
if (!example)
|
|
|
|
return FALSE;
|
2010-07-19 21:11:47 +04:00
|
|
|
|
|
|
|
if (cmp_context == INT_RESULT)
|
|
|
|
return cache_value_int();
|
|
|
|
|
2009-12-02 00:25:51 +03:00
|
|
|
str_value_cached= TRUE;
|
2010-07-19 21:11:47 +04:00
|
|
|
// Mark cached int value obsolete
|
|
|
|
value_cached= FALSE;
|
2009-12-02 00:25:51 +03:00
|
|
|
/* Assume here that the underlying item will do correct conversion.*/
|
|
|
|
String *res= example->str_result(&str_value);
|
|
|
|
if (res && res != &str_value)
|
|
|
|
str_value.copy(*res);
|
|
|
|
null_value= example->null_value;
|
|
|
|
unsigned_flag= example->unsigned_flag;
|
Bug#13721076 CRASH WITH TIME TYPE/TIMESTAMP() AND WARNINGS IN SUBQUERY
The table contains one time value: '00:00:32'
This value is converted to timestamp by a subquery.
In convert_constant_item we call (*item)->is_null()
which triggers execution of the Item_singlerow_subselect subquery,
and the string "0000-00-00 00:00:32" is cached
by Item_cache_datetime.
We continue execution and call update_null_value, which calls val_int()
on the cached item, which converts the time value to ((longlong) 32)
Then we continue to do (*item)->save_in_field()
which ends up in Item_cache_datetime::val_str() which fails,
since (32 < 101) in number_to_datetime, and val_str() returns NULL.
Item_singlerow_subselect::val_str isnt prepared for this:
if exec() succeeds, and return !null_value, then val_str()
*must* succeed.
Solution: refuse to cache strings like "0000-00-00 00:00:32"
in Item_cache_datetime::cache_value, and return NULL instead.
This is similar to the solution for
Bug#11766860 - 60085: CRASH IN ITEM::SAVE_IN_FIELD() WITH TIME DATA TYPE
This patch is for 5.5 only.
The issue is not present after WL#946, since a time value
will be converted to a proper timestamp, with the current date
rather than "0000-00-00"
2012-03-14 13:25:14 +01:00
|
|
|
|
|
|
|
if (!null_value)
|
|
|
|
{
|
|
|
|
switch(field_type())
|
|
|
|
{
|
|
|
|
case MYSQL_TYPE_DATETIME:
|
|
|
|
case MYSQL_TYPE_TIMESTAMP:
|
|
|
|
{
|
|
|
|
MYSQL_TIME ltime;
|
|
|
|
int was_cut;
|
|
|
|
const timestamp_type tt=
|
|
|
|
str_to_datetime(str_value.charset(),
|
|
|
|
str_value.ptr(),
|
|
|
|
str_value.length(),
|
|
|
|
<ime,
|
|
|
|
TIME_DATETIME_ONLY,
|
|
|
|
&was_cut);
|
|
|
|
if (tt != MYSQL_TIMESTAMP_DATETIME || was_cut)
|
|
|
|
null_value= true;
|
|
|
|
else
|
|
|
|
my_datetime_to_str(<ime, const_cast<char*>(str_value.ptr()));
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-12 23:38:59 +03:00
|
|
|
return TRUE;
|
2009-12-02 00:25:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Item_cache_datetime::store(Item *item, longlong val_arg)
|
|
|
|
{
|
|
|
|
/* An explicit values is given, save it. */
|
|
|
|
value_cached= TRUE;
|
|
|
|
int_value= val_arg;
|
|
|
|
null_value= item->null_value;
|
|
|
|
unsigned_flag= item->unsigned_flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-04 16:18:27 +03:00
|
|
|
void Item_cache_datetime::store(Item *item)
|
|
|
|
{
|
|
|
|
Item_cache::store(item);
|
|
|
|
str_value_cached= FALSE;
|
|
|
|
}
|
|
|
|
|
2009-12-02 00:25:51 +03:00
|
|
|
String *Item_cache_datetime::val_str(String *str)
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(fixed == 1);
|
2010-11-04 16:18:27 +03:00
|
|
|
|
|
|
|
if ((value_cached || str_value_cached) && null_value)
|
|
|
|
return NULL;
|
|
|
|
|
2010-07-19 21:11:47 +04:00
|
|
|
if (!str_value_cached)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
When it's possible the Item_cache_datetime uses INT datetime
|
|
|
|
representation due to speed reasons. But still, it always has the STRING
|
|
|
|
result type and thus it can be asked to return a string value.
|
|
|
|
It is possible that at this time cached item doesn't contain correct
|
|
|
|
string value, thus we have to convert cached int value to string and
|
|
|
|
return it.
|
|
|
|
*/
|
|
|
|
if (value_cached)
|
|
|
|
{
|
|
|
|
MYSQL_TIME ltime;
|
2010-11-04 16:18:27 +03:00
|
|
|
/* Return NULL in case of OOM/conversion error. */
|
|
|
|
null_value= TRUE;
|
2010-07-19 21:11:47 +04:00
|
|
|
if (str_value.alloc(MAX_DATE_STRING_REP_LENGTH))
|
|
|
|
return NULL;
|
|
|
|
if (cached_field_type == MYSQL_TYPE_TIME)
|
|
|
|
{
|
2010-08-23 19:59:56 +04:00
|
|
|
longlong time= int_value;
|
2010-07-19 21:11:47 +04:00
|
|
|
set_zero_time(<ime, MYSQL_TIMESTAMP_TIME);
|
2010-08-23 19:59:56 +04:00
|
|
|
if (time < 0)
|
|
|
|
{
|
|
|
|
time= -time;
|
|
|
|
ltime.neg= TRUE;
|
|
|
|
}
|
|
|
|
DBUG_ASSERT(time <= TIME_MAX_VALUE);
|
2010-07-19 21:11:47 +04:00
|
|
|
ltime.second= time % 100;
|
|
|
|
time/= 100;
|
|
|
|
ltime.minute= time % 100;
|
|
|
|
time/= 100;
|
2010-08-02 16:36:41 +04:00
|
|
|
ltime.hour= time;
|
2010-07-19 21:11:47 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int was_cut;
|
|
|
|
longlong res;
|
2010-11-04 16:18:27 +03:00
|
|
|
res= number_to_datetime(int_value, <ime, TIME_FUZZY_DATE, &was_cut);
|
2010-07-19 21:11:47 +04:00
|
|
|
if (res == -1)
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
str_value.length(my_TIME_to_str(<ime,
|
|
|
|
const_cast<char*>(str_value.ptr())));
|
|
|
|
str_value_cached= TRUE;
|
2010-11-04 16:18:27 +03:00
|
|
|
null_value= FALSE;
|
2010-07-19 21:11:47 +04:00
|
|
|
}
|
|
|
|
else if (!cache_value())
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-12-02 00:25:51 +03:00
|
|
|
return &str_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
my_decimal *Item_cache_datetime::val_decimal(my_decimal *decimal_val)
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(fixed == 1);
|
2010-05-28 17:30:39 +02:00
|
|
|
if (!has_value())
|
2009-12-14 17:17:41 +03:00
|
|
|
return NULL;
|
2009-12-02 00:25:51 +03:00
|
|
|
int2my_decimal(E_DEC_FATAL_ERROR, int_value, unsigned_flag, decimal_val);
|
|
|
|
return decimal_val;
|
|
|
|
}
|
|
|
|
|
|
|
|
double Item_cache_datetime::val_real()
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(fixed == 1);
|
2010-11-04 16:18:27 +03:00
|
|
|
if ((!value_cached && !cache_value_int()) || null_value)
|
2009-12-14 17:17:41 +03:00
|
|
|
return 0.0;
|
2009-12-02 00:25:51 +03:00
|
|
|
return (double) int_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
longlong Item_cache_datetime::val_int()
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(fixed == 1);
|
2010-11-04 16:18:27 +03:00
|
|
|
if ((!value_cached && !cache_value_int()) || null_value)
|
2009-12-14 17:17:41 +03:00
|
|
|
return 0;
|
2009-12-02 00:25:51 +03:00
|
|
|
return int_value;
|
|
|
|
}
|
|
|
|
|
2009-11-24 18:26:13 +03:00
|
|
|
bool Item_cache_real::cache_value()
|
2009-11-06 22:34:25 +03:00
|
|
|
{
|
2009-11-24 18:26:13 +03:00
|
|
|
if (!example)
|
|
|
|
return FALSE;
|
2009-11-06 22:34:25 +03:00
|
|
|
value_cached= TRUE;
|
|
|
|
value= example->val_result();
|
|
|
|
null_value= example->null_value;
|
2009-11-24 18:26:13 +03:00
|
|
|
return TRUE;
|
2009-11-06 22:34:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double Item_cache_real::val_real()
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(fixed == 1);
|
2010-05-28 17:30:39 +02:00
|
|
|
if (!has_value())
|
2009-11-24 18:26:13 +03:00
|
|
|
return 0.0;
|
2009-11-06 22:34:25 +03:00
|
|
|
return value;
|
|
|
|
}
|
2003-10-16 15:54:47 +03:00
|
|
|
|
2005-02-09 02:50:45 +04:00
|
|
|
longlong Item_cache_real::val_int()
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(fixed == 1);
|
2010-05-28 17:30:39 +02:00
|
|
|
if (!has_value())
|
2009-11-24 18:26:13 +03:00
|
|
|
return 0;
|
2005-11-30 11:17:25 +04:00
|
|
|
return (longlong) rint(value);
|
2005-02-09 02:50:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String* Item_cache_real::val_str(String *str)
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(fixed == 1);
|
2010-05-28 17:30:39 +02:00
|
|
|
if (!has_value())
|
2009-11-24 18:26:13 +03:00
|
|
|
return NULL;
|
2006-06-16 12:17:20 +02:00
|
|
|
str->set_real(value, decimals, default_charset());
|
2005-02-09 02:50:45 +04:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
my_decimal *Item_cache_real::val_decimal(my_decimal *decimal_val)
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(fixed == 1);
|
2010-05-28 17:30:39 +02:00
|
|
|
if (!has_value())
|
2009-11-24 18:26:13 +03:00
|
|
|
return NULL;
|
2005-02-09 02:50:45 +04:00
|
|
|
double2my_decimal(E_DEC_FATAL_ERROR, value, decimal_val);
|
|
|
|
return decimal_val;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-24 18:26:13 +03:00
|
|
|
bool Item_cache_decimal::cache_value()
|
2005-02-09 02:50:45 +04:00
|
|
|
{
|
2009-11-24 18:26:13 +03:00
|
|
|
if (!example)
|
|
|
|
return FALSE;
|
2009-11-06 22:34:25 +03:00
|
|
|
value_cached= TRUE;
|
|
|
|
my_decimal *val= example->val_decimal_result(&decimal_value);
|
|
|
|
if (!(null_value= example->null_value) && val != &decimal_value)
|
2005-02-09 02:50:45 +04:00
|
|
|
my_decimal2decimal(val, &decimal_value);
|
2009-11-24 18:26:13 +03:00
|
|
|
return TRUE;
|
2005-02-09 02:50:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
double Item_cache_decimal::val_real()
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(fixed);
|
|
|
|
double res;
|
2010-05-28 17:30:39 +02:00
|
|
|
if (!has_value())
|
2010-03-15 09:07:16 -03:00
|
|
|
return 0.0;
|
2005-02-09 02:50:45 +04:00
|
|
|
my_decimal2double(E_DEC_FATAL_ERROR, &decimal_value, &res);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
longlong Item_cache_decimal::val_int()
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(fixed);
|
|
|
|
longlong res;
|
2010-05-28 17:30:39 +02:00
|
|
|
if (!has_value())
|
2009-11-24 18:26:13 +03:00
|
|
|
return 0;
|
2005-02-09 02:50:45 +04:00
|
|
|
my_decimal2int(E_DEC_FATAL_ERROR, &decimal_value, unsigned_flag, &res);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
String* Item_cache_decimal::val_str(String *str)
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(fixed);
|
2010-05-28 17:30:39 +02:00
|
|
|
if (!has_value())
|
2009-11-24 18:26:13 +03:00
|
|
|
return NULL;
|
2005-02-09 02:50:45 +04:00
|
|
|
my_decimal_round(E_DEC_FATAL_ERROR, &decimal_value, decimals, FALSE,
|
|
|
|
&decimal_value);
|
|
|
|
my_decimal2string(E_DEC_FATAL_ERROR, &decimal_value, 0, 0, 0, str);
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
my_decimal *Item_cache_decimal::val_decimal(my_decimal *val)
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(fixed);
|
2010-05-28 17:30:39 +02:00
|
|
|
if (!has_value())
|
2009-11-24 18:26:13 +03:00
|
|
|
return NULL;
|
2005-02-09 02:50:45 +04:00
|
|
|
return &decimal_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-24 18:26:13 +03:00
|
|
|
bool Item_cache_str::cache_value()
|
2002-12-19 07:38:33 +02:00
|
|
|
{
|
2009-11-24 18:26:13 +03:00
|
|
|
if (!example)
|
|
|
|
return FALSE;
|
2009-11-06 22:34:25 +03:00
|
|
|
value_cached= TRUE;
|
|
|
|
value_buff.set(buffer, sizeof(buffer), example->collation.collation);
|
|
|
|
value= example->str_result(&value_buff);
|
|
|
|
if ((null_value= example->null_value))
|
2002-12-19 07:38:33 +02:00
|
|
|
value= 0;
|
2003-06-26 15:07:42 +03:00
|
|
|
else if (value != &value_buff)
|
2002-12-19 07:38:33 +02:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
We copy string value to avoid changing value if 'item' is table field
|
|
|
|
in queries like following (where t1.c is varchar):
|
|
|
|
select a,
|
|
|
|
(select a,b,c from t1 where t1.a=t2.a) = ROW(a,2,'a'),
|
|
|
|
(select c from t1 where a=t2.a)
|
|
|
|
from t2;
|
|
|
|
*/
|
2003-06-26 15:07:42 +03:00
|
|
|
value_buff.copy(*value);
|
|
|
|
value= &value_buff;
|
2002-12-19 07:38:33 +02:00
|
|
|
}
|
2009-11-24 18:26:13 +03:00
|
|
|
return TRUE;
|
2002-12-19 07:38:33 +02:00
|
|
|
}
|
2003-11-23 02:01:15 +02:00
|
|
|
|
2004-11-11 21:39:35 +03:00
|
|
|
double Item_cache_str::val_real()
|
2004-03-18 15:14:36 +02:00
|
|
|
{
|
|
|
|
DBUG_ASSERT(fixed == 1);
|
2005-01-15 12:28:38 +02:00
|
|
|
int err_not_used;
|
|
|
|
char *end_not_used;
|
2010-05-28 17:30:39 +02:00
|
|
|
if (!has_value())
|
2009-11-24 18:26:13 +03:00
|
|
|
return 0.0;
|
2002-12-19 07:38:33 +02:00
|
|
|
if (value)
|
2003-01-14 14:28:36 +02:00
|
|
|
return my_strntod(value->charset(), (char*) value->ptr(),
|
2005-01-15 12:28:38 +02:00
|
|
|
value->length(), &end_not_used, &err_not_used);
|
|
|
|
return (double) 0;
|
2002-12-19 07:38:33 +02:00
|
|
|
}
|
2003-11-23 02:01:15 +02:00
|
|
|
|
|
|
|
|
2002-12-19 07:38:33 +02:00
|
|
|
longlong Item_cache_str::val_int()
|
|
|
|
{
|
2004-03-18 15:14:36 +02:00
|
|
|
DBUG_ASSERT(fixed == 1);
|
2003-01-16 17:17:07 +04:00
|
|
|
int err;
|
2010-05-28 17:30:39 +02:00
|
|
|
if (!has_value())
|
2009-11-24 18:26:13 +03:00
|
|
|
return 0;
|
2002-12-19 07:38:33 +02:00
|
|
|
if (value)
|
|
|
|
return my_strntoll(value->charset(), value->ptr(),
|
2003-01-16 17:17:07 +04:00
|
|
|
value->length(), 10, (char**) 0, &err);
|
2002-12-19 07:38:33 +02:00
|
|
|
else
|
|
|
|
return (longlong)0;
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2009-11-06 22:34:25 +03:00
|
|
|
|
|
|
|
String* Item_cache_str::val_str(String *str)
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(fixed == 1);
|
2010-05-28 17:30:39 +02:00
|
|
|
if (!has_value())
|
2009-11-24 18:26:13 +03:00
|
|
|
return 0;
|
2009-11-06 22:34:25 +03:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-09 02:50:45 +04:00
|
|
|
my_decimal *Item_cache_str::val_decimal(my_decimal *decimal_val)
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(fixed == 1);
|
2010-05-28 17:30:39 +02:00
|
|
|
if (!has_value())
|
2009-11-24 18:26:13 +03:00
|
|
|
return NULL;
|
2005-02-09 02:50:45 +04:00
|
|
|
if (value)
|
|
|
|
string2my_decimal(E_DEC_FATAL_ERROR, value, decimal_val);
|
|
|
|
else
|
|
|
|
decimal_val= 0;
|
|
|
|
return decimal_val;
|
|
|
|
}
|
|
|
|
|
2003-11-23 02:01:15 +02:00
|
|
|
|
2007-11-10 23:44:48 +04:00
|
|
|
int Item_cache_str::save_in_field(Field *field, bool no_conversions)
|
|
|
|
{
|
2011-12-05 15:42:45 +01:00
|
|
|
if (!value_cached && !cache_value())
|
|
|
|
return -1; // Fatal: couldn't cache the value
|
2007-11-10 23:44:48 +04:00
|
|
|
int res= Item_cache::save_in_field(field, no_conversions);
|
|
|
|
return (is_varbinary && field->type() == MYSQL_TYPE_STRING &&
|
|
|
|
value->length() < field->field_length) ? 1 : res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-19 21:15:09 +02:00
|
|
|
bool Item_cache_row::allocate(uint num)
|
|
|
|
{
|
2002-12-28 01:01:05 +02:00
|
|
|
item_count= num;
|
2002-12-19 21:15:09 +02:00
|
|
|
THD *thd= current_thd;
|
2002-12-28 01:01:05 +02:00
|
|
|
return (!(values=
|
|
|
|
(Item_cache **) thd->calloc(sizeof(Item_cache *)*item_count)));
|
2002-12-19 21:15:09 +02:00
|
|
|
}
|
|
|
|
|
2003-11-23 02:01:15 +02:00
|
|
|
|
2002-12-19 21:15:09 +02:00
|
|
|
bool Item_cache_row::setup(Item * item)
|
|
|
|
{
|
2003-10-16 15:54:47 +03:00
|
|
|
example= item;
|
2002-12-19 21:15:09 +02:00
|
|
|
if (!values && allocate(item->cols()))
|
|
|
|
return 1;
|
2002-12-28 01:01:05 +02:00
|
|
|
for (uint i= 0; i < item_count; i++)
|
2002-12-19 21:15:09 +02:00
|
|
|
{
|
2006-12-15 00:51:37 +02:00
|
|
|
Item *el= item->element_index(i);
|
2003-01-02 12:24:33 +02:00
|
|
|
Item_cache *tmp;
|
2007-11-10 23:44:48 +04:00
|
|
|
if (!(tmp= values[i]= Item_cache::get_cache(el)))
|
2002-12-19 21:15:09 +02:00
|
|
|
return 1;
|
2003-01-02 12:24:33 +02:00
|
|
|
tmp->setup(el);
|
2002-12-19 21:15:09 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-11-23 02:01:15 +02:00
|
|
|
|
2002-12-19 21:15:09 +02:00
|
|
|
void Item_cache_row::store(Item * item)
|
|
|
|
{
|
2009-11-24 18:26:13 +03:00
|
|
|
example= item;
|
|
|
|
if (!item)
|
|
|
|
{
|
|
|
|
null_value= TRUE;
|
|
|
|
return;
|
|
|
|
}
|
2009-11-06 22:34:25 +03:00
|
|
|
for (uint i= 0; i < item_count; i++)
|
|
|
|
values[i]->store(item->element_index(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-24 18:26:13 +03:00
|
|
|
bool Item_cache_row::cache_value()
|
2009-11-06 22:34:25 +03:00
|
|
|
{
|
2009-11-24 18:26:13 +03:00
|
|
|
if (!example)
|
|
|
|
return FALSE;
|
2009-11-06 22:34:25 +03:00
|
|
|
value_cached= TRUE;
|
2002-12-19 21:15:09 +02:00
|
|
|
null_value= 0;
|
2009-11-06 22:34:25 +03:00
|
|
|
example->bring_value();
|
2002-12-28 01:01:05 +02:00
|
|
|
for (uint i= 0; i < item_count; i++)
|
2002-12-19 21:15:09 +02:00
|
|
|
{
|
2009-11-06 22:34:25 +03:00
|
|
|
values[i]->cache_value();
|
2002-12-19 21:15:09 +02:00
|
|
|
null_value|= values[i]->null_value;
|
|
|
|
}
|
2009-11-24 18:26:13 +03:00
|
|
|
return TRUE;
|
2002-12-19 21:15:09 +02:00
|
|
|
}
|
|
|
|
|
2003-11-23 02:01:15 +02:00
|
|
|
|
2002-12-19 21:15:09 +02:00
|
|
|
void Item_cache_row::illegal_method_call(const char *method)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("Item_cache_row::illegal_method_call");
|
|
|
|
DBUG_PRINT("error", ("!!! %s method was called for row item", method));
|
|
|
|
DBUG_ASSERT(0);
|
2003-10-06 22:35:05 +03:00
|
|
|
my_error(ER_OPERAND_COLUMNS, MYF(0), 1);
|
2002-12-19 21:15:09 +02:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
2003-11-23 02:01:15 +02:00
|
|
|
|
2002-12-19 21:15:09 +02:00
|
|
|
bool Item_cache_row::check_cols(uint c)
|
|
|
|
{
|
2002-12-28 01:01:05 +02:00
|
|
|
if (c != item_count)
|
2002-12-19 21:15:09 +02:00
|
|
|
{
|
2003-10-06 22:35:05 +03:00
|
|
|
my_error(ER_OPERAND_COLUMNS, MYF(0), c);
|
2002-12-19 21:15:09 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-11-23 02:01:15 +02:00
|
|
|
|
2002-12-19 21:15:09 +02:00
|
|
|
bool Item_cache_row::null_inside()
|
|
|
|
{
|
2002-12-28 01:01:05 +02:00
|
|
|
for (uint i= 0; i < item_count; i++)
|
2002-12-19 21:15:09 +02:00
|
|
|
{
|
|
|
|
if (values[i]->cols() > 1)
|
|
|
|
{
|
|
|
|
if (values[i]->null_inside())
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-11-28 15:44:11 +02:00
|
|
|
values[i]->update_null_value();
|
2002-12-19 21:15:09 +02:00
|
|
|
if (values[i]->null_value)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-11-23 02:01:15 +02:00
|
|
|
|
2002-12-19 21:15:09 +02:00
|
|
|
void Item_cache_row::bring_value()
|
|
|
|
{
|
2010-09-09 18:44:53 +04:00
|
|
|
if (!example)
|
|
|
|
return;
|
|
|
|
example->bring_value();
|
|
|
|
null_value= example->null_value;
|
2002-12-28 01:01:05 +02:00
|
|
|
for (uint i= 0; i < item_count; i++)
|
2002-12-19 21:15:09 +02:00
|
|
|
values[i]->bring_value();
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2003-11-23 02:01:15 +02:00
|
|
|
|
2005-03-23 08:36:48 +02:00
|
|
|
Item_type_holder::Item_type_holder(THD *thd, Item *item)
|
|
|
|
:Item(thd, item), enum_set_typelib(0), fld_type(get_real_type(item))
|
2003-11-23 02:01:15 +02:00
|
|
|
{
|
|
|
|
DBUG_ASSERT(item->fixed);
|
2004-11-11 11:16:51 +02:00
|
|
|
maybe_null= item->maybe_null;
|
2003-11-25 23:52:10 +02:00
|
|
|
collation.set(item->collation);
|
2005-03-23 08:36:48 +02:00
|
|
|
get_full_info(item);
|
2005-04-01 02:14:30 +03:00
|
|
|
/* fix variable decimals which always is NOT_FIXED_DEC */
|
|
|
|
if (Field::result_merge_type(fld_type) == INT_RESULT)
|
|
|
|
decimals= 0;
|
2005-05-05 20:06:49 +05:00
|
|
|
prev_decimal_int_part= item->decimal_int_part();
|
2007-09-28 17:10:14 -04:00
|
|
|
#ifdef HAVE_SPATIAL
|
2007-06-08 00:33:03 +04:00
|
|
|
if (item->field_type() == MYSQL_TYPE_GEOMETRY)
|
2007-10-04 12:01:28 +05:00
|
|
|
geometry_type= item->get_geometry_type();
|
2007-09-28 17:10:14 -04:00
|
|
|
#endif /* HAVE_SPATIAL */
|
2003-11-23 02:01:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
|
|
|
Return expression type of Item_type_holder.
|
2005-02-04 15:31:36 +03:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@return
|
|
|
|
Item_result (type of internal MySQL expression result)
|
2005-02-04 15:31:36 +03:00
|
|
|
*/
|
|
|
|
|
2005-03-23 08:36:48 +02:00
|
|
|
Item_result Item_type_holder::result_type() const
|
2005-02-04 15:31:36 +03:00
|
|
|
{
|
2005-03-23 08:36:48 +02:00
|
|
|
return Field::result_merge_type(fld_type);
|
2004-11-11 11:16:51 +02:00
|
|
|
}
|
2005-02-04 15:31:36 +03:00
|
|
|
|
2004-11-11 11:16:51 +02:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
|
|
|
Find real field type of item.
|
2004-09-26 17:26:32 +03:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@return
|
2005-03-23 08:36:48 +02:00
|
|
|
type of field which should be created to store item value
|
2004-09-26 17:26:32 +03:00
|
|
|
*/
|
|
|
|
|
2005-03-23 08:36:48 +02:00
|
|
|
enum_field_types Item_type_holder::get_real_type(Item *item)
|
2003-11-23 02:01:15 +02:00
|
|
|
{
|
2005-03-23 08:36:48 +02:00
|
|
|
switch(item->type())
|
2003-11-23 02:01:15 +02:00
|
|
|
{
|
2005-03-23 08:36:48 +02:00
|
|
|
case FIELD_ITEM:
|
2005-02-04 15:31:36 +03:00
|
|
|
{
|
2003-11-23 21:26:43 +02:00
|
|
|
/*
|
2005-03-23 08:36:48 +02:00
|
|
|
Item_fields::field_type ask Field_type() but sometimes field return
|
|
|
|
a different type, like for enum/set, so we need to ask real type.
|
2003-11-23 21:26:43 +02:00
|
|
|
*/
|
2005-03-23 08:36:48 +02:00
|
|
|
Field *field= ((Item_field *) item)->field;
|
|
|
|
enum_field_types type= field->real_type();
|
2007-12-11 20:15:03 +01:00
|
|
|
if (field->is_created_from_null_item)
|
|
|
|
return MYSQL_TYPE_NULL;
|
2005-03-23 08:36:48 +02:00
|
|
|
/* work around about varchar type field detection */
|
|
|
|
if (type == MYSQL_TYPE_STRING && field->type() == MYSQL_TYPE_VAR_STRING)
|
|
|
|
return MYSQL_TYPE_VAR_STRING;
|
|
|
|
return type;
|
2004-11-11 11:16:51 +02:00
|
|
|
}
|
2005-03-23 08:36:48 +02:00
|
|
|
case SUM_FUNC_ITEM:
|
2004-11-11 11:16:51 +02:00
|
|
|
{
|
2005-03-23 08:36:48 +02:00
|
|
|
/*
|
|
|
|
Argument of aggregate function sometimes should be asked about field
|
|
|
|
type
|
|
|
|
*/
|
2005-02-04 15:31:36 +03:00
|
|
|
Item_sum *item_sum= (Item_sum *) item;
|
|
|
|
if (item_sum->keep_field_type())
|
2008-10-06 17:17:25 +03:00
|
|
|
return get_real_type(item_sum->get_arg(0));
|
2005-03-23 08:36:48 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case FUNC_ITEM:
|
2005-04-01 02:14:30 +03:00
|
|
|
if (((Item_func *) item)->functype() == Item_func::GUSERVAR_FUNC)
|
2005-02-04 15:31:36 +03:00
|
|
|
{
|
2004-11-11 11:16:51 +02:00
|
|
|
/*
|
2005-03-23 08:36:48 +02:00
|
|
|
There are work around of problem with changing variable type on the
|
|
|
|
fly and variable always report "string" as field type to get
|
|
|
|
acceptable information for client in send_field, so we make field
|
|
|
|
type from expression type.
|
2004-11-11 11:16:51 +02:00
|
|
|
*/
|
2005-07-04 03:42:33 +03:00
|
|
|
switch (item->result_type()) {
|
2005-03-23 08:36:48 +02:00
|
|
|
case STRING_RESULT:
|
|
|
|
return MYSQL_TYPE_VAR_STRING;
|
|
|
|
case INT_RESULT:
|
|
|
|
return MYSQL_TYPE_LONGLONG;
|
|
|
|
case REAL_RESULT:
|
|
|
|
return MYSQL_TYPE_DOUBLE;
|
2005-04-01 02:14:30 +03:00
|
|
|
case DECIMAL_RESULT:
|
|
|
|
return MYSQL_TYPE_NEWDECIMAL;
|
2005-03-23 08:36:48 +02:00
|
|
|
case ROW_RESULT:
|
|
|
|
default:
|
|
|
|
DBUG_ASSERT(0);
|
|
|
|
return MYSQL_TYPE_VAR_STRING;
|
|
|
|
}
|
2005-02-04 15:31:36 +03:00
|
|
|
}
|
2005-03-23 08:36:48 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2005-02-04 15:31:36 +03:00
|
|
|
}
|
2005-03-23 08:36:48 +02:00
|
|
|
return item->field_type();
|
2005-02-04 15:31:36 +03:00
|
|
|
}
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
2005-03-23 08:36:48 +02:00
|
|
|
Find field type which can carry current Item_type_holder type and
|
|
|
|
type of given Item.
|
2004-11-11 11:16:51 +02:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@param thd thread handler
|
|
|
|
@param item given item to join its parameters with this item ones
|
2004-11-11 11:16:51 +02:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@retval
|
2005-03-23 08:36:48 +02:00
|
|
|
TRUE error - types are incompatible
|
2007-10-11 13:29:09 -04:00
|
|
|
@retval
|
2005-03-23 08:36:48 +02:00
|
|
|
FALSE OK
|
2004-11-11 11:16:51 +02:00
|
|
|
*/
|
|
|
|
|
2005-03-23 08:36:48 +02:00
|
|
|
bool Item_type_holder::join_types(THD *thd, Item *item)
|
2004-11-11 11:16:51 +02:00
|
|
|
{
|
2005-09-27 15:11:39 +05:00
|
|
|
uint max_length_orig= max_length;
|
|
|
|
uint decimals_orig= decimals;
|
2005-04-01 02:14:30 +03:00
|
|
|
DBUG_ENTER("Item_type_holder::join_types");
|
|
|
|
DBUG_PRINT("info:", ("was type %d len %d, dec %d name %s",
|
|
|
|
fld_type, max_length, decimals,
|
|
|
|
(name ? name : "<NULL>")));
|
|
|
|
DBUG_PRINT("info:", ("in type %d len %d, dec %d",
|
|
|
|
get_real_type(item),
|
|
|
|
item->max_length, item->decimals));
|
2005-03-23 08:36:48 +02:00
|
|
|
fld_type= Field::field_type_merge(fld_type, get_real_type(item));
|
2003-11-23 02:01:15 +02:00
|
|
|
{
|
2005-04-01 02:14:30 +03:00
|
|
|
int item_decimals= item->decimals;
|
|
|
|
/* fix variable decimals which always is NOT_FIXED_DEC */
|
|
|
|
if (Field::result_merge_type(fld_type) == INT_RESULT)
|
|
|
|
item_decimals= 0;
|
|
|
|
decimals= max(decimals, item_decimals);
|
2003-11-23 02:01:15 +02:00
|
|
|
}
|
2005-04-01 02:14:30 +03:00
|
|
|
if (Field::result_merge_type(fld_type) == DECIMAL_RESULT)
|
2004-11-11 11:16:51 +02:00
|
|
|
{
|
2005-05-05 20:06:49 +05:00
|
|
|
decimals= min(max(decimals, item->decimals), DECIMAL_MAX_SCALE);
|
2008-07-30 14:07:37 +03:00
|
|
|
int item_int_part= item->decimal_int_part();
|
|
|
|
int item_prec = max(prev_decimal_int_part, item_int_part) + decimals;
|
|
|
|
int precision= min(item_prec, DECIMAL_MAX_PRECISION);
|
2005-05-05 20:06:49 +05:00
|
|
|
unsigned_flag&= item->unsigned_flag;
|
2009-07-03 11:41:19 +04:00
|
|
|
max_length= my_decimal_precision_to_length_no_truncation(precision,
|
|
|
|
decimals,
|
|
|
|
unsigned_flag);
|
2004-11-11 11:16:51 +02:00
|
|
|
}
|
2006-07-21 13:28:42 -07:00
|
|
|
|
2005-09-27 15:11:39 +05:00
|
|
|
switch (Field::result_merge_type(fld_type))
|
|
|
|
{
|
|
|
|
case STRING_RESULT:
|
2004-11-11 11:16:51 +02:00
|
|
|
{
|
2005-03-23 08:36:48 +02:00
|
|
|
const char *old_cs, *old_derivation;
|
2006-07-21 13:28:42 -07:00
|
|
|
uint32 old_max_chars= max_length / collation.collation->mbmaxlen;
|
2004-11-11 11:16:51 +02:00
|
|
|
old_cs= collation.collation->name;
|
|
|
|
old_derivation= collation.derivation_name();
|
2006-03-01 17:58:01 +04:00
|
|
|
if (collation.aggregate(item->collation, MY_COLL_ALLOW_CONV))
|
2003-11-25 23:52:10 +02:00
|
|
|
{
|
2004-11-13 19:35:51 +02:00
|
|
|
my_error(ER_CANT_AGGREGATE_2COLLATIONS, MYF(0),
|
2003-11-25 23:52:10 +02:00
|
|
|
old_cs, old_derivation,
|
|
|
|
item->collation.collation->name,
|
|
|
|
item->collation.derivation_name(),
|
|
|
|
"UNION");
|
2005-04-01 02:14:30 +03:00
|
|
|
DBUG_RETURN(TRUE);
|
2003-11-25 23:52:10 +02:00
|
|
|
}
|
2006-07-21 13:28:42 -07:00
|
|
|
/*
|
|
|
|
To figure out max_length, we have to take into account possible
|
|
|
|
expansion of the size of the values because of character set
|
|
|
|
conversions.
|
|
|
|
*/
|
2007-06-30 02:09:50 +05:00
|
|
|
if (collation.collation != &my_charset_bin)
|
|
|
|
{
|
|
|
|
max_length= max(old_max_chars * collation.collation->mbmaxlen,
|
|
|
|
display_length(item) /
|
|
|
|
item->collation.collation->mbmaxlen *
|
|
|
|
collation.collation->mbmaxlen);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
set_if_bigger(max_length, display_length(item));
|
2005-09-27 15:11:39 +05:00
|
|
|
break;
|
2003-11-23 02:01:15 +02:00
|
|
|
}
|
2005-09-27 15:11:39 +05:00
|
|
|
case REAL_RESULT:
|
|
|
|
{
|
|
|
|
if (decimals != NOT_FIXED_DEC)
|
|
|
|
{
|
2009-03-27 13:12:50 +03:00
|
|
|
/*
|
|
|
|
For FLOAT(M,D)/DOUBLE(M,D) do not change precision
|
|
|
|
if both fields have the same M and D
|
|
|
|
*/
|
|
|
|
if (item->max_length != max_length_orig ||
|
|
|
|
item->decimals != decimals_orig)
|
Bug #24791: Union with AVG-groups generates wrong results
The problem in this bug is when we create temporary tables. When
temporary tables are created for unions, there is some
inferrence being carried out regarding the type of the column.
Whenever this column type is inferred to be REAL (i.e. FLOAT or
DOUBLE), MySQL will always try to maintain exact precision, and
if that is not possible (there are hardware limits, since FLOAT
and DOUBLE are stored as approximate values) will switch to
using approximate values. The problem here is that at this point
the information about number of significant digits is not
available. Furthermore, the number of significant digits should
be increased for the AVG function, however, this was not properly
handled. There are 4 parts to the problem:
#1: DOUBLE and FLOAT fields don't display their proper display
lengths in max_display_length(). This is hard-coded as 53 for
DOUBLE and 24 for FLOAT. Now changed to instead return the
field_length.
#2: Type holders for temporary tables do not preserve the
max_length of the Item's from which they are created, and is
instead reverted to the 53 and 24 from above. This causes
*all* fields to get non-fixed significant digits.
#3: AVG function does not update max_length (display length)
when updating number of decimals.
#4: The function that switches to non-fixed number of
significant digits should use DBL_DIG + 2 or FLT_DIG + 2 as
cut-off values (Since fixed precision does not use the 'e'
notation)
Of these points, #1 is the controversial one, but this
change is preferred and has been cleared with Monty. The
function causes quite a few unit tests to blow up and they had
to b changed, but each one is annotated and motivated. We
frequently see the magical 53 and 24 give way to more relevant
numbers.
2007-03-22 10:56:47 +01:00
|
|
|
{
|
2009-03-27 13:12:50 +03:00
|
|
|
int delta1= max_length_orig - decimals_orig;
|
|
|
|
int delta2= item->max_length - item->decimals;
|
|
|
|
max_length= max(delta1, delta2) + decimals;
|
|
|
|
if (fld_type == MYSQL_TYPE_FLOAT && max_length > FLT_DIG + 2)
|
|
|
|
{
|
|
|
|
max_length= MAX_FLOAT_STR_LENGTH;
|
|
|
|
decimals= NOT_FIXED_DEC;
|
|
|
|
}
|
|
|
|
else if (fld_type == MYSQL_TYPE_DOUBLE && max_length > DBL_DIG + 2)
|
|
|
|
{
|
|
|
|
max_length= MAX_DOUBLE_STR_LENGTH;
|
|
|
|
decimals= NOT_FIXED_DEC;
|
|
|
|
}
|
Bug #24791: Union with AVG-groups generates wrong results
The problem in this bug is when we create temporary tables. When
temporary tables are created for unions, there is some
inferrence being carried out regarding the type of the column.
Whenever this column type is inferred to be REAL (i.e. FLOAT or
DOUBLE), MySQL will always try to maintain exact precision, and
if that is not possible (there are hardware limits, since FLOAT
and DOUBLE are stored as approximate values) will switch to
using approximate values. The problem here is that at this point
the information about number of significant digits is not
available. Furthermore, the number of significant digits should
be increased for the AVG function, however, this was not properly
handled. There are 4 parts to the problem:
#1: DOUBLE and FLOAT fields don't display their proper display
lengths in max_display_length(). This is hard-coded as 53 for
DOUBLE and 24 for FLOAT. Now changed to instead return the
field_length.
#2: Type holders for temporary tables do not preserve the
max_length of the Item's from which they are created, and is
instead reverted to the 53 and 24 from above. This causes
*all* fields to get non-fixed significant digits.
#3: AVG function does not update max_length (display length)
when updating number of decimals.
#4: The function that switches to non-fixed number of
significant digits should use DBL_DIG + 2 or FLT_DIG + 2 as
cut-off values (Since fixed precision does not use the 'e'
notation)
Of these points, #1 is the controversial one, but this
change is preferred and has been cleared with Monty. The
function causes quite a few unit tests to blow up and they had
to b changed, but each one is annotated and motivated. We
frequently see the magical 53 and 24 give way to more relevant
numbers.
2007-03-22 10:56:47 +01:00
|
|
|
}
|
2005-09-27 15:11:39 +05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
max_length= (fld_type == MYSQL_TYPE_FLOAT) ? FLT_DIG+6 : DBL_DIG+7;
|
|
|
|
break;
|
2003-11-23 02:01:15 +02:00
|
|
|
}
|
2006-07-21 13:28:42 -07:00
|
|
|
default:
|
|
|
|
max_length= max(max_length, display_length(item));
|
2005-09-27 15:11:39 +05:00
|
|
|
};
|
2005-03-23 08:36:48 +02:00
|
|
|
maybe_null|= item->maybe_null;
|
|
|
|
get_full_info(item);
|
2005-05-05 20:06:49 +05:00
|
|
|
|
|
|
|
/* Remember decimal integer part to be used in DECIMAL_RESULT handleng */
|
|
|
|
prev_decimal_int_part= decimal_int_part();
|
2005-04-04 16:43:25 +03:00
|
|
|
DBUG_PRINT("info", ("become type: %d len: %u dec: %u",
|
|
|
|
(int) fld_type, max_length, (uint) decimals));
|
2005-04-01 02:14:30 +03:00
|
|
|
DBUG_RETURN(FALSE);
|
2003-11-23 02:01:15 +02:00
|
|
|
}
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
|
|
|
Calculate lenth for merging result for given Item type.
|
2004-10-20 01:28:42 +03:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@param item Item for length detection
|
2004-11-11 11:16:51 +02:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@return
|
2005-03-23 08:36:48 +02:00
|
|
|
length
|
|
|
|
*/
|
2004-11-11 11:16:51 +02:00
|
|
|
|
2005-03-23 08:36:48 +02:00
|
|
|
uint32 Item_type_holder::display_length(Item *item)
|
2004-06-16 16:06:30 +03:00
|
|
|
{
|
|
|
|
if (item->type() == Item::FIELD_ITEM)
|
2004-06-17 13:48:31 +03:00
|
|
|
return ((Item_field *)item)->max_disp_length();
|
2004-11-11 11:16:51 +02:00
|
|
|
|
2005-03-23 08:36:48 +02:00
|
|
|
switch (item->field_type())
|
2004-06-16 16:06:30 +03:00
|
|
|
{
|
2005-03-23 08:36:48 +02:00
|
|
|
case MYSQL_TYPE_DECIMAL:
|
|
|
|
case MYSQL_TYPE_TIMESTAMP:
|
|
|
|
case MYSQL_TYPE_DATE:
|
|
|
|
case MYSQL_TYPE_TIME:
|
|
|
|
case MYSQL_TYPE_DATETIME:
|
|
|
|
case MYSQL_TYPE_YEAR:
|
|
|
|
case MYSQL_TYPE_NEWDATE:
|
2005-04-01 02:14:30 +03:00
|
|
|
case MYSQL_TYPE_VARCHAR:
|
|
|
|
case MYSQL_TYPE_BIT:
|
|
|
|
case MYSQL_TYPE_NEWDECIMAL:
|
2005-03-23 08:36:48 +02:00
|
|
|
case MYSQL_TYPE_ENUM:
|
|
|
|
case MYSQL_TYPE_SET:
|
|
|
|
case MYSQL_TYPE_TINY_BLOB:
|
|
|
|
case MYSQL_TYPE_MEDIUM_BLOB:
|
|
|
|
case MYSQL_TYPE_LONG_BLOB:
|
|
|
|
case MYSQL_TYPE_BLOB:
|
|
|
|
case MYSQL_TYPE_VAR_STRING:
|
|
|
|
case MYSQL_TYPE_STRING:
|
|
|
|
case MYSQL_TYPE_GEOMETRY:
|
2004-06-16 16:06:30 +03:00
|
|
|
return item->max_length;
|
2005-03-23 08:36:48 +02:00
|
|
|
case MYSQL_TYPE_TINY:
|
|
|
|
return 4;
|
|
|
|
case MYSQL_TYPE_SHORT:
|
|
|
|
return 6;
|
|
|
|
case MYSQL_TYPE_LONG:
|
2007-03-09 08:05:08 +03:00
|
|
|
return MY_INT32_NUM_DECIMAL_DIGITS;
|
2005-03-23 08:36:48 +02:00
|
|
|
case MYSQL_TYPE_FLOAT:
|
|
|
|
return 25;
|
|
|
|
case MYSQL_TYPE_DOUBLE:
|
2004-06-16 16:06:30 +03:00
|
|
|
return 53;
|
2005-03-23 08:36:48 +02:00
|
|
|
case MYSQL_TYPE_NULL:
|
2006-07-22 02:08:00 +04:00
|
|
|
return 0;
|
2005-03-23 08:36:48 +02:00
|
|
|
case MYSQL_TYPE_LONGLONG:
|
2004-06-16 16:06:30 +03:00
|
|
|
return 20;
|
2005-03-23 08:36:48 +02:00
|
|
|
case MYSQL_TYPE_INT24:
|
|
|
|
return 8;
|
2004-06-16 16:06:30 +03:00
|
|
|
default:
|
|
|
|
DBUG_ASSERT(0); // we should never go there
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2003-11-23 02:01:15 +02:00
|
|
|
|
2005-03-23 08:36:48 +02:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
2005-03-23 08:36:48 +02:00
|
|
|
Make temporary table field according collected information about type
|
2007-10-11 13:29:09 -04:00
|
|
|
of UNION result.
|
2005-03-23 08:36:48 +02:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@param table temporary table for which we create fields
|
2005-03-23 08:36:48 +02:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@return
|
2005-03-23 08:36:48 +02:00
|
|
|
created field
|
|
|
|
*/
|
|
|
|
|
|
|
|
Field *Item_type_holder::make_field_by_type(TABLE *table)
|
|
|
|
{
|
2005-03-30 23:08:03 +03:00
|
|
|
/*
|
|
|
|
The field functions defines a field to be not null if null_ptr is not 0
|
|
|
|
*/
|
|
|
|
uchar *null_ptr= maybe_null ? (uchar*) "" : 0;
|
2005-11-23 22:45:02 +02:00
|
|
|
Field *field;
|
|
|
|
|
|
|
|
switch (fld_type) {
|
2005-03-30 23:08:03 +03:00
|
|
|
case MYSQL_TYPE_ENUM:
|
2005-03-23 08:36:48 +02:00
|
|
|
DBUG_ASSERT(enum_set_typelib);
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
field= new Field_enum((uchar *) 0, max_length, null_ptr, 0,
|
2005-03-30 23:08:03 +03:00
|
|
|
Field::NONE, name,
|
2005-11-23 22:45:02 +02:00
|
|
|
get_enum_pack_length(enum_set_typelib->count),
|
2005-03-30 23:08:03 +03:00
|
|
|
enum_set_typelib, collation.collation);
|
2005-11-23 22:45:02 +02:00
|
|
|
if (field)
|
|
|
|
field->init(table);
|
|
|
|
return field;
|
2005-03-30 23:08:03 +03:00
|
|
|
case MYSQL_TYPE_SET:
|
|
|
|
DBUG_ASSERT(enum_set_typelib);
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
field= new Field_set((uchar *) 0, max_length, null_ptr, 0,
|
2005-03-30 23:08:03 +03:00
|
|
|
Field::NONE, name,
|
2005-11-23 22:45:02 +02:00
|
|
|
get_set_pack_length(enum_set_typelib->count),
|
2005-03-30 23:08:03 +03:00
|
|
|
enum_set_typelib, collation.collation);
|
2005-11-23 22:45:02 +02:00
|
|
|
if (field)
|
|
|
|
field->init(table);
|
|
|
|
return field;
|
2007-12-11 20:15:03 +01:00
|
|
|
case MYSQL_TYPE_NULL:
|
|
|
|
return make_string_field(table);
|
2005-03-30 23:08:03 +03:00
|
|
|
default:
|
|
|
|
break;
|
2005-03-23 08:36:48 +02:00
|
|
|
}
|
2005-11-23 22:45:02 +02:00
|
|
|
return tmp_table_field_from_field_type(table, 0);
|
2005-03-23 08:36:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
2005-03-23 08:36:48 +02:00
|
|
|
Get full information from Item about enum/set fields to be able to create
|
2007-10-11 13:29:09 -04:00
|
|
|
them later.
|
2005-03-23 08:36:48 +02:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@param item Item for information collection
|
2005-03-23 08:36:48 +02:00
|
|
|
*/
|
|
|
|
void Item_type_holder::get_full_info(Item *item)
|
|
|
|
{
|
|
|
|
if (fld_type == MYSQL_TYPE_ENUM ||
|
|
|
|
fld_type == MYSQL_TYPE_SET)
|
|
|
|
{
|
2005-07-12 16:30:45 +00:00
|
|
|
if (item->type() == Item::SUM_FUNC_ITEM &&
|
|
|
|
(((Item_sum*)item)->sum_func() == Item_sum::MAX_FUNC ||
|
|
|
|
((Item_sum*)item)->sum_func() == Item_sum::MIN_FUNC))
|
2008-10-06 17:17:25 +03:00
|
|
|
item = ((Item_sum*)item)->get_arg(0);
|
2005-03-23 08:36:48 +02:00
|
|
|
/*
|
2005-07-12 16:30:45 +00:00
|
|
|
We can have enum/set type after merging only if we have one enum|set
|
|
|
|
field (or MIN|MAX(enum|set field)) and number of NULL fields
|
2005-03-23 08:36:48 +02:00
|
|
|
*/
|
|
|
|
DBUG_ASSERT((enum_set_typelib &&
|
|
|
|
get_real_type(item) == MYSQL_TYPE_NULL) ||
|
|
|
|
(!enum_set_typelib &&
|
|
|
|
item->type() == Item::FIELD_ITEM &&
|
|
|
|
(get_real_type(item) == MYSQL_TYPE_ENUM ||
|
|
|
|
get_real_type(item) == MYSQL_TYPE_SET) &&
|
|
|
|
((Field_enum*)((Item_field *) item)->field)->typelib));
|
|
|
|
if (!enum_set_typelib)
|
|
|
|
{
|
|
|
|
enum_set_typelib= ((Field_enum*)((Item_field *) item)->field)->typelib;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-11 21:39:35 +03:00
|
|
|
double Item_type_holder::val_real()
|
2003-11-23 02:01:15 +02:00
|
|
|
{
|
|
|
|
DBUG_ASSERT(0); // should never be called
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
longlong Item_type_holder::val_int()
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(0); // should never be called
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-02-09 02:50:45 +04:00
|
|
|
my_decimal *Item_type_holder::val_decimal(my_decimal *)
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(0); // should never be called
|
|
|
|
return 0;
|
|
|
|
}
|
2003-11-23 02:01:15 +02:00
|
|
|
|
|
|
|
String *Item_type_holder::val_str(String*)
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(0); // should never be called
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-11-11 11:16:51 +02:00
|
|
|
void Item_result_field::cleanup()
|
|
|
|
{
|
|
|
|
DBUG_ENTER("Item_result_field::cleanup()");
|
|
|
|
Item::cleanup();
|
|
|
|
result_field= 0;
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
|
|
|
Dummy error processor used by default by Name_resolution_context.
|
2005-07-01 07:05:42 +03:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@note
|
2005-07-01 07:05:42 +03:00
|
|
|
do nothing
|
|
|
|
*/
|
|
|
|
|
|
|
|
void dummy_error_processor(THD *thd, void *data)
|
|
|
|
{}
|
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
/**
|
|
|
|
Wrapper of hide_view_error call for Name_resolution_context error
|
|
|
|
processor.
|
2005-07-01 07:05:42 +03:00
|
|
|
|
2007-10-11 13:29:09 -04:00
|
|
|
@note
|
2005-07-01 07:05:42 +03:00
|
|
|
hide view underlying tables details in error messages
|
|
|
|
*/
|
|
|
|
|
|
|
|
void view_error_processor(THD *thd, void *data)
|
|
|
|
{
|
|
|
|
((TABLE_LIST *)data)->hide_view_error(thd);
|
|
|
|
}
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
** Instantiate templates
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2005-06-22 14:08:28 +05:00
|
|
|
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
|
2000-07-31 21:29:14 +02:00
|
|
|
template class List<Item>;
|
|
|
|
template class List_iterator<Item>;
|
2001-08-02 06:29:50 +03:00
|
|
|
template class List_iterator_fast<Item>;
|
2004-11-11 11:16:51 +02:00
|
|
|
template class List_iterator_fast<Item_field>;
|
2000-07-31 21:29:14 +02:00
|
|
|
template class List<List_item>;
|
|
|
|
#endif
|