Commit graph

307 commits

Author SHA1 Message Date
Alexander Barkov
fff7fc500b MDEV-10817 CAST(MAX(DATE'2001-01-01') AS TIME) returns a wrong result 2017-11-07 15:03:58 +04:00
Vladislav Vaintroub
ccf21c9962 fix some conversion warnings 2017-09-28 17:20:46 +00:00
Marko Mäkelä
8f643e2063 Merge 10.1 into 10.2 2017-05-23 11:09:47 +03:00
Marko Mäkelä
65e1399e64 Merge 10.0 into 10.1
Significantly reduce the amount of InnoDB, XtraDB and Mariabackup
code changes by defining pfs_os_file_t as something that is
transparently compatible with os_file_t.
2017-05-20 08:41:20 +03:00
Vicențiu Ciorbaru
339a290d22 Merge remote-tracking branch 'origin/5.5' into 10.0 2017-05-17 15:42:36 +03:00
Igor Babaev
e0352fb079 Fixed the bug mdev-7599.
At some conditions the function opt_sum_query() can apply MIN/MAX
optimizations to to Item_sum objects of a select These optimizations
becomes invalid if this select is the subquery of an IN subquery
predicate that is converted to a EXISTS subquery. Thus in this case
the MIX/MAX optimizations that have been applied in opt_sum_query()
must be rolled back.
This bug appeared in 5.3 when the code for the cost base choice between
materialization and in-to-exists transformation of non-correlated
IN subqueries was introduced. Before this code in-to-exists
transformations were always performed before the call of opt_sum_query().
2017-05-15 10:00:00 -07: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
Igor Babaev
20aae56efa Fixed bug mdev-10660.
The method Item_sum::print did not print opening '(' after the name
of simple window functions (like rank, dense_rank etc).
As a result the view definitions with such window functions
were formed invalid in .frm files.
2017-02-03 15:50:25 -08:00
Igor Babaev
8481c70ede Fixed bug mdev-11867.
If a window function with aggregation is over the result
set of a grouping query then the argument of the aggregate
function from the window function is allowed to be an
aggregate function itself.
2017-02-01 19:15:28 -08:00
Sergei Golubchik
4a5d25c338 Merge branch '10.1' into 10.2 2016-12-29 13:23:18 +01: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
Alexander Barkov
ec7e0b7b30 MDEV-10556 Assertion `0' failed in virtual void Item_sum_field::set_result_field(Field*) 2016-09-21 09:13:33 +04:00
Vicențiu Ciorbaru
dfd3be928d Make cursor implementation uniform
Cursors now report their current row number as the boundary of the
partition. This is used by Frame_scan_cursor to compute aggregate
functions that do not support removal.
2016-09-09 18:33:29 +03:00
Igor Babaev
3fb4f9bb93 Merge branch '10.2-mdev9197-cons' of github.com:shagalla/server
into branch 10.2-mdev9197.
2016-08-31 16:16:54 -07:00
Galina Shalygina
eb2c147475 The consolidated patch for mdev-9197. 2016-08-23 00:39:12 +03:00
Alexander Barkov
3ccf8218bc Partial backporting of 7b50447aa6
(MDEV-9407, MDEV-9408) from 10.1

Needed to fix MDEV-10317 easier.
2016-07-03 11:20:46 +04:00
Sergei Golubchik
0a056c9b53 better ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED 2016-06-30 11:43:02 +02:00
Sergei Golubchik
ed77ee1aab cleanup: change Item::walk() to take void* not uchar*
and remove all related casts to uchar*
also remove a couple of unused methods
2016-06-30 11:43:02 +02:00
Michael Widenius
2fe8dd0f90 various cleanups 2016-06-30 11:43:02 +02:00
Michael Widenius
db7edfed17 MDEV-7563 Support CHECK constraint as in (or close to) SQL Standard
MDEV-10134 Add full support for DEFAULT

- Added support for using tables with MySQL 5.7 virtual fields,
  including MySQL 5.7 syntax
- Better error messages also for old cases
- CREATE ... SELECT now also updates timestamp columns
- Blob can now have default values
- Added new system variable "check_constraint_checks", to turn of
  CHECK constraint checking if needed.
- Removed some engine independent tests in suite vcol to only test myisam
- Moved some tests from 'include' to 't'. Should some day be done for all tests.
- FRM version increased to 11 if one uses virtual fields or constraints
- Changed to use a bitmap to check if a field has got a value, instead of
  setting HAS_EXPLICIT_VALUE bit in field flags
- Expressions can now be up to 65K in total
- Ensure we are not refering to uninitialized fields when handling virtual fields or defaults
- Changed check_vcol_func_processor() to return a bitmap of used types
- Had to change some functions that calculated cached value in fix_fields to do
  this in val() or getdate() instead.
- store_now_in_TIME() now takes a THD argument
- fill_record() now updates default values
- Add a lookahead for NOT NULL, to be able to handle DEFAULT 1+1 NOT NULL
- Automatically generate a name for constraints that doesn't have a name
- Added support for ALTER TABLE DROP CONSTRAINT
- Ensure that partition functions register virtual fields used. This fixes
  some bugs when using virtual fields in a partitioning function
2016-06-30 11:43:02 +02:00
Vicențiu Ciorbaru
be3902fceb Implement ntile window function.
The current implementation does not allow for a dynamic expression
within the sum function's parameter.
2016-04-04 22:04:18 +03:00
Sergei Petrunia
2bd4dc38e0 Merge branch '10.2' into bb-10.2-mdev9543 2016-03-28 22:18:38 +03:00
Sergei Golubchik
f67a2211ec Merge branch '10.1' into 10.2 2016-03-23 22:36:46 +01:00
Alexander Barkov
9b53d84d14 MDEV-9656 Assertion `0' failed in Item_sum_field::get_tmp_table_field().
Removing a wrong ASSERT. Item_sum_field now uses the inherited
Item::get_tmp_table_field().
2016-03-16 13:43:06 +04:00
Vicențiu Ciorbaru
21651541ce Implemented avg() window function.
It is based on the sum() function, thus much of the logic is shared.

Considering that there are 2 counters stored within the function, one
that handles the null value, while the other that handles the divisor
for the avg computation, it is possible to remove the counter from the
Item_sum_avg. I have not removed it in this patch as we may choose to
refactor the whole code into a separate class.
This remains to be dicussed.
2016-03-16 01:57:59 +02:00
Vicențiu Ciorbaru
93f2371020 Implemented a counter within Item_sum_sum
The counter keeps track of the number of items added to the sum
function. It is increased when we add a value to the sum function and
decreased when it is removed.
2016-03-14 19:12:27 +02:00
Vicențiu Ciorbaru
a0c06ba1ed Preliminary implementation for the aggregate sum function as a window function
This implementation does not deal with the case where removal of
elements from the window frame causes the item to turn to a null value.
2016-03-14 15:42:00 +02:00
Vicențiu Ciorbaru
974e65d368 Implement BIT_(AND|OR|XOR) functions as window functions. 2016-03-07 12:04:11 +02:00
Sergei Petrunia
86acf267fe Remove all comments starting with 'psergey' 2016-03-02 13:08:55 +03:00
Oleksandr Byelkin
6c414fcf89 MDEV-5542: GROUP_CONCAT truncate output to 65.536 chars when using DISTINCT or ORDER BY
port of mysql fix WL#6098
2016-03-01 21:10:59 +01:00
Sergei Petrunia
be15858245 MDEV-9526: Compute Aggregate functions as window functions
- Add temporary code: clone_read_record() clones READ_RECORD structure,
  as long as it is used for reading filesort() result that fits into
  memory.
- Add frame bounds for ROWS-type frames. ROWS n PRECEDING|FOLLOWING,
  ROWS UNBOUNDED PRECEDING|FOLLOWING, CURRENT ROW are supported.
- Add Item_sum_count::remove() which allows "streaming" computation
  of COUNT() over a moving frame.
2016-02-18 01:25:26 +03:00
Sergei Petrunia
64ab10ffff Initial implementation of RANK() window function 2016-02-14 11:30:36 +03:00
Igor Babaev
9d9c60fb12 Initial patch for the implementation of window functions (MDEV-6115):
- All parsing problems look like resolved
- Stub performing name resolution of window functions
in simplest queries has been added.
2016-02-12 20:33:56 -08:00
Alexander Barkov
7b50447aa6 MDEV-9407 Illegal mix of collation when using GROUP_CONCAT in a VIEW
MDEV-9408 CREATE TABLE SELECT MAX(int_column) creates different columns for table vs view

There were three almost identical pieces of the code:
- Field *Item_func::tmp_table_field();
- Field *Item_sum::create_tmp_field();
- Field *create_tmp_field_from_item();
with a difference in very small details (hence the bugs):
Only Item_func::tmp_table_field() was correct, the other two were not.
Removing the two incorrect pieces of the redundant code.
Joining these three functions/methods into a single virtual method
Item::create_tmp_field().
Additionally, moving Item::make_string_field() and
Item::tmp_table_field_from_field_type() from the public into the
protected section of the class declaration, as they are now not
needed outside of Item.
2016-01-16 18:45:26 +04:00
Alexander Barkov
3e471bf3e9 MDEV-9215 Detect cmp_type() and result_type() from field_type()
Part2: deriving Item_sum_sum from Type_handler_hybrid_field_type,
removing "Item_result Item_sum_sum::hybrid_type".
2015-12-01 14:20:09 +04:00
Alexander Barkov
607ef786fc MDEV-9215 Detect cmp_type() and result_type() from field_type()
(A dependency task for MDEV-4912 Add a plugin to field types)
2015-12-01 13:13:23 +04:00
Alexander Barkov
b867ade591 Removing Used_tables_and_const_cache from "class udf_handler".
It was used only temporary, during udf_handler::fix_fields() time,
and then copied to the owner Item_func_or_sum object.
Changing the code to use the Used_tables_and_const_cache part
of the owner Item_sum_or_func object directly.
2015-10-14 18:33:16 +04:00
Alexander Barkov
0b4c3ad818 Moving Used_tables_and_const_chache from Item_func to Item_func_or_sum
and thus reusing Used_tables_and_const_cache for Item_sum instead of
declaring the same members inside Item_sum.
2015-10-12 10:49:37 +04:00
Alexander Barkov
16ad1fc540 MDEV-8921 Wrong result for CAST(AVG(double_column) AS SIGNED) 2015-10-08 20:48:46 +04:00
Alexander Barkov
7091b7852d MDEV-8918 Wrong result for CAST(AVG(bigint_column) AS SIGNED)
- Moving Item_xxx_field declarations after Item_sum_xxx declarations,
  so Item_xxx_field constructors can be defined directly in item_sum.h
  rather than item_sum.cc. This removes some duplicate code, e.g.
  initialization of the following members at constructor time:
  name, decimals, max_length, unsigned_flag, field, maybe_null.
- Adding Item_sum_field as a common parent for Item_avg_field and
  Item_variance_field
- Deriving Item_sum_field directly from Item rather that Item_result_field,
  as Item_sum_field descendants do not need anything from Item_result_field.
- Removing hybrid infrastructure from Item_avg_field,
  adding Item_avg_field_decimal and Item_avg_field_double instead,
  as desired result type is already known at constructor time
  (not only at fix_fields time). This simplifies the code.
- Changing Item_avg_field_decimal::val_int() to call val_int_from_decimal()
  instead of doing { return (longlong) rint(val_real()); }
  This is the fix itself.
2015-10-08 19:19:21 +04:00
Alexander Barkov
174a0b9eb7 Clean-up: Item_sum_variance and Item_variance_field had hybrid type
infrastructure, though in fact they always return REAL result.
Removing hybrid type artifacts.
2015-10-08 12:09:05 +04:00
Alexander Barkov
cb2c799bd0 MDEV-8860 Wrong result for WHERE 2016 < SOME (SELECT CAST(time_column AS DATETIME) FROM t1)
MDEV-8875 Wrong metadata for MAX(CAST(time_column AS DATETIME))
2015-09-30 16:04:24 +04:00
Sergei Golubchik
530a6e7481 Merge branch '10.0' into 10.1
referenced_by_foreign_key2(), needed for InnoDB to compile,
was taken from 10.0-galera
2015-09-03 12:58:41 +02:00
Monty
1bae0d9e56 Stage 2 of MDEV-6152:
- Added mem_root to all calls to new Item
- Added private method operator new(size_t size) to Item to ensure that
  we always use a mem_root when creating an item.

This saves use once call to current_thd per Item creation
2015-08-21 10:40:51 +04:00
Sergey Vojtovich
31e365efae MDEV-8010 - Avoid sql_alloc() in Items (Patch #1)
Added mandatory thd parameter to Item (and all derivative classes) constructor.
Added thd parameter to all routines that may create items.
Also removed "current_thd" from Item::Item. This reduced number of
pthread_getspecific() calls from 290 to 177 per OLTP RO transaction.
2015-08-21 10:40:39 +04:00
Jan Lindström
9a5787db51 Merge commit '96badb16afcf' into 10.0
Conflicts:
	client/mysql_upgrade.c
	mysql-test/r/func_misc.result
	mysql-test/suite/binlog/r/binlog_stm_mix_innodb_myisam.result
	mysql-test/suite/innodb/r/innodb-fk.result
	mysql-test/t/subselect_sj_mat.test
	sql/item.cc
	sql/item_func.cc
	sql/log.cc
	sql/log_event.cc
	sql/rpl_utility.cc
	sql/slave.cc
	sql/sql_class.cc
	sql/sql_class.h
	sql/sql_select.cc
	storage/innobase/dict/dict0crea.c
	storage/innobase/dict/dict0dict.c
	storage/innobase/handler/ha_innodb.cc
	storage/xtradb/dict/dict0crea.c
	storage/xtradb/dict/dict0dict.c
	storage/xtradb/handler/ha_innodb.cc
	vio/viosslfactories.c
2015-08-03 23:09:43 +03:00
Sergei Golubchik
96badb16af MDEV-7821 Server crashes in Item_func_group_concat::fix_fields on 2nd execution of PS
Correct fix for this bug.

The problem was that Item_func_group_concat() was calling
setup_order(), passing args as the second argument,
ref_pointer_array. While ref_pointer_array should have free
space at the end, as setup_order() can append elements to it.

In this particular case args[] elements were overwritten when
setup_order() was pushing new elements into ref_pointer_array.
2015-07-31 22:09:46 +02:00
Alexander Barkov
be2038e3cb MDEV-7950 Item_func::type() takes 0.26% in OLTP RO
Step 4 (there will be more)
2015-05-13 17:08:24 +04:00
Alexander Barkov
499deca7fc A clean-up for c8141f5314
MDEV-7950 Item_func::type() takes 0.26% in OLTP RO (Step#2)

- Item_ref was doing unnecessary extra job after the "MDEV-7950 Step#2" patch.
  Fallback to Item::build_equal_items() if real_type() is not FIELD_ITEM.
  Note, Item_ref::build_equal_items() will most likely be further simplified.
  Waiting for Sanja and Igor to check a possibly dead code.

- Safety: Adding Item_sum::build_equal_items() with ASSERT, as Item_sum
  should never appear in build_equal_items() context.
2015-04-29 17:53:27 +04:00