Commit graph

66226 commits

Author SHA1 Message Date
Alexander Barkov
705fc43eaa MDEV-12775 Reuse data type aggregation code for hybrid functions and UNION
Introducing a new class Type_holder (used internally in sql_union.cc),
to reuse exactly the same data type attribute aggregation Type_handler API
for hybrid functions and UNION.

This fixes a number of bugs in UNION:

- MDEV-9495 Wrong field type for a UNION of a signed and an unsigned INT expression
- MDEV-9497 UNION and COALESCE produce different field types for DECIMAL+INT
- MDEV-12594 UNION between fixed length double columns does not always preserve scale
- MDEV-12595 UNION converts INT to BIGINT
- MDEV-12599 UNION is not symmetric when mixing INT and CHAR

Details:

- sql_union.cc: Reusing attribute aggregation for UNION.
  Adding new methods:
  * st_select_lex_unit::join_union_type_handlers()
  * st_select_lex_unit::join_union_type_attributes()
  * st_select_lex_unit::join_union_item_types()
  Removing the old join_types()-based code.

- Changing Type_handler::Item_hybrid_func_fix_attributes()
  to accept "name", Type_handler_hybrid_field_type, Type_all_attributes
  as three separate parameters instead of a single Item_hybrid_func parameter,
  to make it possible to pass both Item_hybrid_func and Type_holder.

- Moving the former special GEOMETRY and ENUM/SET attribute aggregation code
  from Item_type_holder::join_types() to
  * Type_handler_typelib::Item_hybrid_func_fix_attributes().
  * Type_handler_geometry::Item_hybrid_func_fix_attrubutes().
  This makes GEOMETRY/ENUM/SET symmetric with all other data types
  (from the UNION point of view).
  Removing Item_type_holder::join_types() and Item_type_holder::get_full_info().

- Adding new methods into Type_all_attributes:
  * Type_all_attributes::set_geometry_type() and
    Item_hybrid_func::set_geometry_type().
  * Adding Type_all_attributes::get_typelib().
  * Adding Type_all_attributes::set_typelib().

- Adding Type_handler_typelib as a common parent for
  Type_handler_enum and Type_handler_set, to avoid code duplication: they have
  already had two common methods, and we're adding one more shared method.

- Adding Type_all_attributes::set_maybe_null(), as some type handlers
  may want to set maybe_null (e.g. Type_handler_geometry) during data type
  attribute aggregation.

- Changing Type_geometry_attributes() to accept Type_handler
  and Type_all_attributes as two separate parameters, instead
  of a single Item parameter, to make it possible to pass Type_holder.

- Adding Item_args::add_argument().

- Moving Item_args::alloc_arguments() from "protected" to "public".

- Moving Item_type_holder::Item_type_holder() from item.cc to item.h, as
  now it's very simple.
  Btw, this constructor should probably be eventually removed.
  It's now used only in sql_show.cc, which could be modified to use
  Item_return_decimal (for symmetry with Item_return_xxx created for all
  other data types). Or, another option: remove all Item_return_xxx and
  use Item_type_holder for all data types instead.

- storage/tokudb/mysql-test/tokudb/r/type_float.result
  Recording new results (MDEV-12594).

- mysql-test/r/cte_recursive.result
  Recording new results (MDEV-9497)

- mysql-test/r/subselect*.result
  Recording new results (MDEV-12595)

- mysql-test/r/metadata.result
  Recording new results (MDEV-9495)

- mysql-test/r/temp_table.result
  Recording new results (MDEV-12594)

- mysql-test/r/type_float.result
  Recording new results (MDEV-12594)
2017-05-15 23:45:31 +04:00
Alexander Barkov
7c44b8afb7 MDEV-12798 Item_param does not preserve exact field type in EXECUTE IMMEDIATE 'CREATE TABLE AS SELECT ?' USING POINT(1,1) 2017-05-15 14:58:05 +04:00
Alexander Barkov
238eb41005 MDEV-12784 Change Item_func_length::print() to display octet_length() rather than length() 2017-05-11 19:39:49 +04:00
Alexander Barkov
7beb8ff274 A --ps cleanup for MDEV-12658 Make the third parameter to LPAD and RPAD optional
"mtr --ps func_str" failed:
pad_str was erroneously appended with a new space on every PS execution.

Adding pad_str.length(0) into fix_length_and_dec() to avoid this.
2017-05-11 07:29:43 +04:00
Alexander Barkov
533506b4ed MDEV-12777 Change Lex_field_type_st::m_type from enum_field_types to Type_handler pointer 2017-05-10 18:14:08 +04:00
Alexander Barkov
191638416b MDEV-12772 Add Field::get_typelib() and Item::get_typelib() 2017-05-10 11:02:02 +04:00
Alexander Barkov
0f642188cc MDEV-12771 Remove Item_func_xxx::decimal_precision() for case and abbreviations 2017-05-10 09:27:15 +04:00
Alexander Barkov
cd32f84214 MDEV-12770 Add Type_handler::decimal_precision() + MDEV-12769
This patch for MDEV-12770 is also fixing:

MDEV-12769 Arithmetic operators with temporal types create excessive column types
2017-05-10 08:30:56 +04:00
halfspawn
18ad176809 MDEV-12685 Oracle-compatible function CHR() 2017-05-08 15:51:53 +04:00
Monty
71fa413c16 MDEV-10139 Support for SEQUENCE objects
- SETVAL(sequence_name, next_value, is_used, round)
- ALTER SEQUENCE, including RESTART WITH

Other things:
- Added handler::extra() option HA_EXTRA_PREPARE_FOR_ALTER_TABLE to signal
  ha_sequence() that it should allow write_row statments.
- ALTER ONLINE TABLE now works with SEQUENCE:s
2017-05-08 02:44:55 +03:00
Monty
1e04ad284c Fixed compiler warnings and warnings from build.tags
Other things
- Ensure that ut_d() is set to EXPR if ut_ad() is DEBUG_ASSERT()
  If not, we will get a crash in purge_sys_t::~purge_sys_t() as
  this ut_ad() code expect's that the ut_d() codes has been executed
2017-05-08 02:33:35 +03:00
Monty
276b0c8ef0 Fixed crash with SEQUENCE when using REPAIR 2017-05-08 02:33:34 +03:00
Alexander Barkov
c619fbeafe Adding MYSQL_PLUGIN_IMPORT to type_handler_xxx declarations (fixing compilation failure on Windows) 2017-05-07 19:41:19 +04:00
Alexander Barkov
da63db1e3b MDEV-12719 Determine Item::result_type() from Item::type_handler() 2017-05-07 19:29:23 +04:00
Alexander Barkov
02ada41744 MDEV-12721 Wrong execution plan for WHERE (date_field <=> timestamp_expr AND TRUE) 2017-05-07 17:44:27 +04:00
Alexander Barkov
4e9022b48b MDEV-12718 Determine Item::cmp_type() from Item::type_handler() 2017-05-07 09:12:54 +04:00
Alexander Barkov
cc694792c9 MDEV-12717 Change Item_equal to operate Type_handler rather than Item_result 2017-05-07 01:02:37 +04:00
Alexander Barkov
aea54a11a6 MDEV-12716 Change Value_source::Context to operate Type_handler rather than Item_result 2017-05-06 23:06:18 +04:00
Alexander Barkov
c898de84b7 MDEV-12714 Determine Item::field_type() from Item::type_handler() 2017-05-06 20:44:05 +04:00
Alexander Barkov
46239f29c6 MDEV-12713 Define virtual type_handler() for all Item classes 2017-05-06 19:12:59 +04:00
Alexander Barkov
5a644e177f Adding "const" qualifier to Item::cols(), and to the "Item *cmp" parameter to Type_handler::make_const_item_for_comparison() 2017-05-06 15:05:59 +04:00
Alexander Barkov
9a360e97a2 Cleanup: changing set_handler_by_field_type(field_type()) to set_handler(type_handler()).
This gives better performance, as excludes handler-by-type lookup.
2017-05-06 14:52:18 +04:00
Alexander Barkov
380ec90905 MDEV-12710 Fix Item_cache constructors to accept Type_handler instead of enum_field_types 2017-05-06 13:34:16 +04:00
Alexander Barkov
26fa7232cf MDEV-12707 Split resolve_const_item() into virtual methods in Type_handler 2017-05-06 00:04:15 +04:00
Alexander Barkov
ac53b49b1b Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext 2017-05-05 16:12:54 +04:00
Alexander Barkov
db0917f68f MDEV-12696 Crash with LOAD XML and non-updatable VIEW column 2017-05-05 11:05:55 +04:00
Alexander Barkov
583b68e899 MDEV-12560, MDEV-12665 - geometry type not preserved in hybrid functions and UNION
This is a join patch fixing these two bugs:
MDEV-12560 Wrong data type for SELECT NULL UNION SELECT Point(1,1)
MDEV-12665 Hybrid functions do not preserve geometry type
2017-05-05 07:23:16 +04:00
Alexander Barkov
aacb4d57ca MDEV-12695 Add Column_definition::type_handler() 2017-05-05 07:00:18 +04:00
Alexander Barkov
1ff79562b8 MDEV-12692 Split Item_func_between::fix_length_and_dec 2017-05-04 18:30:11 +04:00
Alexander Barkov
fe127562e2 MDEV-12687 Split Item::send() into virtual method in Type_handler 2017-05-04 16:05:21 +04:00
Alexander Barkov
ae5b31fe52 A cleanup for MDEV-12619 UNION creates excessive integer column types for integer literals
Fixing result set metadata for Item_int to match type_handler(),
i.e. MYSQL_TYPE_LONG for small numbers and MYSQL_TYPE_LONGLONG for big numbers.
2017-05-04 13:17:12 +04:00
Vladislav Vaintroub
ba824b66c1 MDEV-12597 Do not print warning about inconsistent slow-log variables
The new 10.2 has log-slow-admin-statements ON but log-slow-queries OFF,
thus  there is no reason for a warning about it(the change was "by design")
2017-05-04 09:10:55 +00:00
Alexander Barkov
01b308c39c MDEV-12617 CASE and CASE-alike hybrid functions do not preserve exact data types 2017-05-04 11:38:55 +04:00
Alexander Barkov
78a891c87b A partial patch for MDEV-12518 Unify sql_yacc.yy and sql_yacc_ora.yy
Making sql_yacc.yy close to sql_yacc_ora.yy:

1. Adding struct sp_cursor_name_and_offset into %union
2. Adding field_type_numeric, field_type_string,  field_type_lob,
   field_type_temporal, field_type_misc
3. Adding keyword_sp_data_type and keyword_sp_not_data_type
4. Removing "opt_savepoint". Moving this grammar to "rollback" instead.
   This fixes one shift/reduce conflict.
5. Minor indentation cleanup.
2017-05-04 09:56:09 +04:00
Igor Babaev
ce8ee7d90b Fixed the bug mdev-11990.
The usage of windows functions when all tables were optimized away
by min/max optimization were not supported. As result a result,
the queries that used window functions with min/max aggregation
over the whole table returned wrong result sets.
The patch fixed this problem.
2017-05-03 13:50:35 -07:00
halfspawn
850d3bafca MDEV-12658 Make the third parameter to LPAD and RPAD optional 2017-05-03 17:39:45 +02:00
Alexander Barkov
736a1d29bc Adding Item_func_pad as a common parent for Item_func_lpad and Item_func_rpad
Removing duplication:
- fix_length_and_dec()
- tmp_value
- lpad_str, rpad_str -> pad_str
2017-05-03 13:43:22 +04:00
Alexey Botchkov
a60bdcba64 MDEV-12462 SPATIAL index fails to work with CONTAINS.
Flags are wrongly set for MBR_CONTAINS/MBR_WITHIN functions.
2017-05-02 16:24:42 +04:00
Alexander Barkov
8bc88a4940 Fixing a warning: ‘class Type_all_attributes’ has ... non-virtual destructor 2017-05-02 15:58:26 +04:00
Alexey Botchkov
3ea9d3e59e MDEV-12363 Assertion `0' failed in Type_handler_string_result::make_sort_key(uchar*, Item*, const SORT_FIELD_ATTR*, Sort_param*).
maybe_null wasn't properly set for Item_json_func_keys.
2017-05-02 15:47:43 +04:00
Alexey Botchkov
42ad4f2821 MDEV-12364 Server crashes in __memcpy_sse2_unaligned / String::copy on
JSON_SEARCH with variables.

        Wrong index for the tmp_paths array in
        Item_func_json_search::val_str.
2017-05-02 14:28:57 +04:00
Alexander Barkov
746f794c43 MDEV-12657 A few tests fail in build-bot on Windows after changing Field::field_name and Item::name to LEX_CSTRING 2017-05-02 13:51:35 +04:00
Alexander Barkov
07143a7393 MDEV-12659 Add THD::make_string_literal() 2017-05-02 12:58:25 +04:00
Alexander Barkov
85b73e2254 MDEV-12656 Crash in CREATE..SELECT..UNION with a ENUM column and NULL 2017-05-02 11:39:20 +04:00
Alexander Barkov
50b70e765b MDEV-12655 Move Item_func::count_xxx_length() to Type_std_attributes 2017-05-02 07:49:06 +04:00
Alexander Barkov
c67971a8a3 MDEV-12649 Add Type_handler::Item_save_in_value 2017-04-30 22:50:37 +04:00
Sergei Golubchik
5ccaabe962 MDEV-10355 Weird error message upon CREATE TABLE with DEFAULT
post-fix for 0b52b28b91

* restore EXPLAIN output
* remove redundant code
2017-04-30 14:58:11 +02:00
Sergei Golubchik
d17093b2ed MDEV-12293 Assertion `table->no_keyread || !table->covering_keys.is_set(tab->index) || table->file->keyread == tab->index' failed
sometimes the optimizer starts a keyread on some index
and later (but before any actual index accesses) changes
it to a keyread on a different index
2017-04-30 14:58:11 +02:00
Alexander Barkov
7a19c59c00 MDEV-9395 Add Type_handler::Item_decimal_scale() and Item_divisor_precision_increment() 2017-04-29 21:34:57 +04:00
Igor Babaev
7a29ca2776 Fixed the bug mdev-12563.
The bug happened when the specification of a recursive CTE had
no recursive references at the top level of the specification.
In this case the regular processing of derived table references
of the select containing a non-recursive reference to this
recursive CTE misses handling the specification unit.
At the preparation stage any non-recursive reference to a
recursive CTE must be handled after the preparation of the
specification unit for this CTE. So we have to force this
preparation when regular handling of derived tables does not
do it.
2017-04-28 21:59:11 -07:00