1
0
mirror of https://github.com/MariaDB/server.git synced 2025-11-30 05:23:50 +03:00
Files
mariadb/mysql-test/t/win_insert_select.test
Alexander Barkov 25ad623d64 MDEV-13240 Wrong warning with MAX(datetime_field) OVER (...)
The problem resided in Item_window_func implementation,
and it was revealed by bb-10.2-ext specific changes:

Item_window_func::save_in_field() works differently in bb-10.2-ext vs 10.2:

- 10.2 goes through val_str()
- bb-10.2-ext goes through get_date(), due to Type_handler related changes.
  get_date() tries to convert empty string to DATETIME, hence the warning.

During a discussion with Vicentiu, it was decided to fix
Item_window_func::val_xxx() to return NULL
(instead of an "empty" value, such as 0 for numbers and '' for strings)
when force_return_blank is set.
2017-07-04 14:14:30 +04:00

80 lines
1.8 KiB
Plaintext

CREATE TABLE t1 (c1 INT, c2 VARCHAR(30));
PREPARE populate_table FROM "INSERT into t1 values (1, 'manual_insert_1'),
(4, 'manual_insert_2')";
INSERT INTO t1 SELECT row_number() over(), "should_have_NULL" FROM t1;
INSERT INTO t1 SELECT 1 + row_number() over(), "should_have_2" FROM t1;
EXECUTE populate_table;
INSERT INTO t1 SELECT 10 + row_number() over(), "should repeat 4 times [11-14]" FROM t1;
SELECT c1, c2 FROM t1 ORDER BY c2, c1;
DELETE FROM t1;
EXECUTE populate_table;
INSERT INTO t1
SELECT 10 + (dense_rank() over(order by c1)), "dense_rank_insert" from t1;
SELECT c1, c2 FROM t1 ORDER BY c2, c1;
DELETE FROM t1;
EXECUTE populate_table;
INSERT INTO t1
SELECT 100 + (rank() over(order by c1)), "rank_insert" from t1;
SELECT c1, c2 FROM t1 ORDER BY c2, c1;
DELETE FROM t1;
EXECUTE populate_table;
INSERT INTO t1
SELECT 100 + (ntile(10) over(order by c1)), "ntile_insert" from t1;
SELECT c1, c2 FROM t1 ORDER BY c2, c1;
DELETE FROM t1;
EXECUTE populate_table;
INSERT INTO t1
SELECT 1000 + (percent_rank() over(order by c1)), "percent_rank_insert" from t1;
SELECT c1, c2 FROM t1 ORDER BY c2, c1;
DELETE FROM t1;
EXECUTE populate_table;
INSERT INTO t1
SELECT 1000 + (count(*) over(order by c1)), "count_insert" from t1;
SELECT c1, c2 FROM t1 ORDER BY c2, c1;
DELETE FROM t1;
EXECUTE populate_table;
--echo #
--echo # Test how avg interacts when the results need to be rounded.
--echo #
SELECT 1000 + (avg(c1) over(order by c1)) as avg_expr, c1, "This will be inserted into t1" from t1;
INSERT INTO t1
SELECT 1000 + (avg(c1) over(order by c1)), "avg_insert" from t1;
SELECT c1, c2 FROM t1 ORDER BY c2, c1;
DELETE FROM t1;
EXECUTE populate_table;
INSERT INTO t1
SELECT 1000 + (sum(c1) over(order by c1)), "sum_insert" from t1;
SELECT c1, c2
FROM t1
ORDER BY c2, c1;
DROP table t1;