Commit graph

45 commits

Author SHA1 Message Date
Marko Mäkelä
d88c136b9f Merge 10.3 into 10.4 2018-10-17 19:11:42 +03:00
Varun Gupta
97a37edc97 MDEV-17137: Syntax errors with VIEW using MEDIAN
The syntax error happened because we had not implemented a different print for
percentile functions. The syntax is a bit different when we use percentile functions
as window functions in comparision to normal window functions.
Implemented a seperate print function for percentile functions
2018-10-16 08:11:26 -07:00
Alexander Barkov
ad8e02ac45 MDEV-17317 Add THD* parameter into Item::get_date() and stricter data type control to "fuzzydate" 2018-09-28 14:01:17 +04:00
Alexander Barkov
cb7b5fbf1c MDEV-16910 Add class VDec
Adding classes VDec and VDec2_lazy, according to the task description.
This patch removes around 250 duplicate code lines.
2018-08-07 10:48:42 +04:00
Alexander Barkov
e61568ee93 Merge remote-tracking branch 'origin/10.3' into 10.4 2018-07-03 14:02:05 +04:00
Alexander Barkov
e213b20e07 MDEV-16592 Change Item::with_sum_func from a member to a virtual method 2018-06-27 14:48:03 +04:00
Alexander Barkov
ff09512e07 MDEV-16489 when lead() returns null on a datetime field, the result is treated as the literal string '[NULL]' 2018-06-20 19:36:37 +04:00
Oleksandr Byelkin
083279f783 Merge commit '6b8802e8dd5467556a024d807a1df23940b00895' into bb-10.3-fix_len_dec 2018-06-19 14:51:50 +02:00
Marko Mäkelä
0121d5a790 Merge 10.2 into 10.3 2018-06-18 15:43:59 +03:00
Oleksandr Byelkin
6b8802e8dd MDEV-11071: Assertion `thd->transaction.stmt.is_empty()' failed in Locked_tables_list::unlock_locked_table
fix_length_and_dec now return result (error/OK)
2018-06-15 10:31:30 +02:00
Alexander Barkov
2412c15191 MDEV-15870 Using aggregate and window function in unexpected places can crash the server 2018-06-13 11:56:56 +04:00
Alexander Barkov
106f0b5798 MDEV-16385 ROW SP variable is allowed in unexpected context
The problem described in the bug report happened because the code
did not test check_cols(1) after fix_fields() in a few places.

Additionally, fix_fields() could be called multiple times for SP variables,
because they are all fixed at a early stage in append_for_log().

Solution:
1. Adding a few helper methods
   - fix_fields_if_needed()
   - fix_fields_if_needed_for_scalar()
   - fix_fields_if_needed_for_bool()
   - fix_fields_if_needed_for_order_by()
  and using it in many cases instead of fix_fields() where
  the "fixed" status is not definitely known to be "false".

2. Adding DBUG_ASSERT(!fixed) into Item_splocal*::fix_fields()
   to catch double execution.

3. Adding tests.

As a good side effect, the patch removes a lot of duplicate code (~60 lines):

   if (!item->fixed &&
       item->fix_fields(..) &&
       item->check_cols(1))
     return true;
2018-06-05 10:25:39 +04:00
Marko Mäkelä
b006d2ead4 Merge bb-10.2-ext into 10.3 2018-02-15 10:22:03 +02:00
Alexander Barkov
95d075a0e5 MDEV-15293 CAST(AS TIME) returns bad results for LAST_VALUE(),NAME_CONST(),SP variable 2018-02-13 20:37:31 +04:00
Alexander Barkov
3cad31f2a7 Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext 2018-02-08 19:06:25 +04:00
Sergei Golubchik
2eb00d1eba fix Item_window_func::print() not to crash before fix_fields()
because dbug_print_item() can be invoked any time in gdb,
also before fix_fields.

this fixes a crash of main.win in debug builds
2018-02-06 14:51:31 +01:00
Marko Mäkelä
7cb3520c06 Merge bb-10.2-ext into 10.3 2017-11-30 08:16:37 +02:00
Alexander Barkov
590400f743 MDEV-14517 Cleanup for Item::with_subselect and Item::has_subquery() 2017-11-28 06:25:14 +04:00
Varun Gupta
ab5503c8c5 Updates the tests for the percentile functions 2017-11-01 23:17:15 +05:30
Varun Gupta
0ef6127c29 Date-time fields are disabled currently for the result type of percentile function 2017-11-01 23:17:15 +05:30
Varun Gupta
58a6e43513 Tests added for percentile and median functions 2017-11-01 23:17:14 +05:30
Varun Gupta
02a4a4b512 Added fix_fields for percentile function to check the type of argument and to ensure that only numeric arguments are allowed 2017-11-01 23:17:14 +05:30
Varun Gupta
6511069e7f Added the error ER_WRONG_TYPE_FOR_PERCENTILE_CONT, which ensures that the result type for percentile_cont is always numerical 2017-11-01 23:13:01 +05:30
Varun Gupta
947ce922c9 Added the error ER_NOT_SINGLE_ELEMENT_ORDER_LIST for th percentile functions, these ensure that for the percentile
function we have the order list with exactly one element
2017-11-01 23:13:01 +05:30
Varun Gupta
3393005e95 Ensured that the the element in the order by clause should have a numerical time, if not throw an error 2017-11-01 23:13:01 +05:30
Varun Gupta
275ce39f05 Percentile class implemented, most of the functions have the same functionalite as the percentile cont class 2017-11-01 23:13:01 +05:30
Varun Gupta
01d2b6e9d9 Implemented the implementation of percentile functions using Item_cache instead of Cache_Item 2017-11-01 23:13:01 +05:30
Varun Gupta
31f1541f1e Setting handler to have the return type as that of the element by which we are ordering the partition 2017-11-01 23:13:01 +05:30
Varun Gupta
18747a4baa Added value field to Item_sum_percentile_disc
Check for single element in the order_list is added
2017-11-01 23:13:01 +05:30
Michael Widenius
4aaa38d26e Enusure that my_global.h is included first
- Added sql/mariadb.h file that should be included first by files in sql
  directory, if sql_plugin.h is not used (sql_plugin.h adds SHOW variables
  that must be done before my_global.h is included)
- Removed a lot of include my_global.h from include files
- Removed include's of some files that my_global.h automatically includes
- Removed duplicated include's of my_sys.h
- Replaced include my_config.h with my_global.h
2017-08-24 01:05:44 +02:00
Michael Widenius
b0da8897b0 Added copyright message to some files 2017-08-24 01:05:17 +02:00
Marko Mäkelä
3a7201ea92 Merge 10.2 into bb-10.2-ext 2017-06-19 16:56:13 +03:00
Igor Babaev
cf4a6abea1 Fixed the bug mdev-13064.
This is another attempt to fix the bug mdev-12992.
This patch introduces st_select_lex::context_analysis_place for
the place in SELECT where context analysis is currently performed.
It's similar to st_select_lex::parsing_place, but it is used at
the preparation stage.
2017-06-16 09:50:57 -07:00
Alexander Barkov
da63db1e3b MDEV-12719 Determine Item::result_type() from Item::type_handler() 2017-05-07 19:29:23 +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
Monty
5a759d31f7 Changing field::field_name and Item::name to LEX_CSTRING
Benefits of this patch:
- Removed a lot of calls to strlen(), especially for field_string
- Strings generated by parser are now const strings, less chance of
  accidently changing a string
- Removed a lot of calls with LEX_STRING as parameter (changed to pointer)
- More uniform code
- Item::name_length was not kept up to date. Now fixed
- Several bugs found and fixed (Access to null pointers,
  access of freed memory, wrong arguments to printf like functions)
- Removed a lot of casts from (const char*) to (char*)

Changes:
- This caused some ABI changes
  - lex_string_set now uses LEX_CSTRING
  - Some fucntions are now taking const char* instead of char*
- Create_field::change and after changed to LEX_CSTRING
- handler::connect_string, comment and engine_name() changed to LEX_CSTRING
- Checked printf() related calls to find bugs. Found and fixed several
  errors in old code.
- A lot of changes from LEX_STRING to LEX_CSTRING, especially related to
  parsing and events.
- Some changes from LEX_STRING and LEX_STRING & to LEX_CSTRING*
- Some changes for char* to const char*
- Added printf argument checking for my_snprintf()
- Introduced null_clex_str, star_clex_string, temp_lex_str to simplify
  code
- Added item_empty_name and item_used_name to be able to distingush between
  items that was given an empty name and items that was not given a name
  This is used in sql_yacc.yy to know when to give an item a name.
- select table_name."*' is not anymore same as table_name.*
- removed not used function Item::rename()
- Added comparision of item->name_length before some calls to
  my_strcasecmp() to speed up comparison
- Moved Item_sp_variable::make_field() from item.h to item.cc
- Some minimal code changes to avoid copying to const char *
- Fixed wrong error message in wsrep_mysql_parse()
- Fixed wrong code in find_field_in_natural_join() where real_item() was
  set when it shouldn't
- ER_ERROR_ON_RENAME was used with extra arguments.
- Removed some (wrong) ER_OUTOFMEMORY, as alloc_root will already
  give the error.

TODO:
- Check possible unsafe casts in plugin/auth_examples/qa_auth_interface.c
- Change code to not modify LEX_CSTRING for database name
  (as part of lower_case_table_names)
2017-04-23 22:35:46 +03:00
Alexander Barkov
47b7ffb396 Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext 2017-02-27 10:07:59 +04:00
Vicențiu Ciorbaru
57341852b5 MDEV-11746: Wrong result upon using FIRST_VALUE with a window frame
Reimplement FIRST_VALUE to act as NTH_VALUE with 0 offset. The previous
implementation was flawed when the window frame would remove values.
2017-02-14 07:46:58 +02:00
Igor Babaev
78b5e8d6ca Fixed bug mdev-11745.
Due to this bug many queries that contained a window function
with MIN/MAX aggregation returned wrong results.

Calculation of a MIN/MAX aggregate function uses cache objects
and a comparator object that are created and set up in
Item_sum_hybrid::fix_fields () by a call of Item_sum_hybrid::setup_hybrid().
The latter binds the objects to the first argument of the
MIN/MAX function. Meanwhile window function perform aggregation
over fields of a temporary table. So binding must be done rather to
these fields. The earliest moment when setup the objects used in
MIN/max functions can be done is after all calls of the method
split_sum_func().

This patch introduces this late setup, but only for aggregate
functions used in window functions.
Probably it makes sense to use this late setup for all MIN/MAX
objects.
2017-02-09 19:34:01 -08:00
Alexander Barkov
749bbb3d7b MDEV-11357 Split Item_cache::get_cache() into virtual methods in Type_handler
This patch:
- Adds a new virtual method Type_handler::Item_get_cache
- Splits moves Item_cache::get_cache() into the new method, every
  "case XXX_RESULT" to the corresponding Type_handler_xxx::Item_get_cache.
- Adds Item::get_cache as a convenience wrapper, to make the caller code
  shorter.
- Changes the last argument of Arg_comparator::cache_converted_constant()
  from Item_result to "const Type_handler *".
- Removes subselect_engine::cmp_type, subselect_engine::res_type,
  subselect_engine::res_field_type and derives subselect_engine
  from Type_handler_hybrid_field_type instead.
- Makes Type_handler_varchar public, as it's now needed as the
  default data type handler for subselect_engine.
2016-12-16 18:23:21 +04:00
Igor Babaev
903f34c7a9 Fixed bug mdev-10868.
There was no implementation of the virtual method print()
for the Item_window_func class. As a result for a view
containing window function an invalid view definition could
be written in the frm file. When a query that refers to
this view was executed a syntax error was reported.
2016-09-30 17:40:40 -07:00
Vicențiu Ciorbaru
53cf265b3b Implement LEAD and LAG and NTH_VALUE functions
Refactour out (into a copy for now) the logic of Item_sum_hybrid, to
allow for multiple arguments. It does not contain the comparator
members. The result is the class Item_sum_hybrid_simple.

LEAD and LAG make use of this Item to store previous rows in a chache.
It also helps in specifying the field type. Currently LEAD/LAG do not
support default values.

NTH_VALUE behaves identical to LEAD and LAG, except that the starting
position cursor is placed on the top of the frame instead of the current
row.
2016-09-24 15:12:34 +02:00
Vicențiu Ciorbaru
9a5930bcdf Implement first_value and last_value as window functions
Currently the implementation doesn't support removal, thus the
computation is performed by running over the window frame again.
2016-09-24 15:12:34 +02:00
Vicențiu Ciorbaru
23e8b508a0 MDEV-10059: Compute window functions with same sorting criteria simultaneously
Perform only one table scan for each window function present. We do this
by keeping keeping cursors for each window function frame bound and
running them for each function for every row.
2016-09-09 18:32:35 +03:00
Galina Shalygina
be1d06c8a5 Merge branch '10.2' into 10.2-mdev9864 2016-05-08 23:04:41 +03:00