mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
MDEV-16230: Server crashes when Analyze format=json is run with a window function with empty PARTITION BY and ORDER BY clauses
Currently when both PARTITION BY and ORDER BY clauses are empty then we create a Item with the first field in the select list and sort with that field. It should be created as an Item_temptable_field instead of Item_field because the print() function continues to work even if the table has been dropped.
This commit is contained in:
@ -3743,5 +3743,50 @@ a ROW_NUMBER() OVER v2
|
||||
1 1
|
||||
drop table t0;
|
||||
#
|
||||
# MDEV-16230:Server crashes when Analyze format=json is run with a window function with
|
||||
# empty PARTITION BY and ORDER BY clauses
|
||||
#
|
||||
CREATE TABLE t1(a INT, b INT);
|
||||
INSERT INTO t1 VALUES (1,1),(2,2),(3,3);
|
||||
ANALYZE FORMAT=JSON SELECT row_number() OVER() FROM t1;
|
||||
ANALYZE
|
||||
{
|
||||
"query_block": {
|
||||
"select_id": 1,
|
||||
"r_loops": 1,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"window_functions_computation": {
|
||||
"sorts": {
|
||||
"filesort": {
|
||||
"sort_key": "`row_number() OVER()`",
|
||||
"r_loops": 1,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"r_used_priority_queue": false,
|
||||
"r_output_rows": 3,
|
||||
"r_buffer_size": "REPLACED"
|
||||
}
|
||||
},
|
||||
"temporary_table": {
|
||||
"table": {
|
||||
"table_name": "t1",
|
||||
"access_type": "ALL",
|
||||
"r_loops": 1,
|
||||
"rows": 3,
|
||||
"r_rows": 3,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"filtered": 100,
|
||||
"r_filtered": 100
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
SELECT row_number() OVER() FROM t1;
|
||||
row_number() OVER()
|
||||
1
|
||||
2
|
||||
3
|
||||
DROP TABLE t1;
|
||||
#
|
||||
# End of 10.2 tests
|
||||
#
|
||||
|
@ -2446,6 +2446,19 @@ WINDOW v2 AS ( PARTITION BY a ORDER BY a DESC );
|
||||
|
||||
drop table t0;
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-16230:Server crashes when Analyze format=json is run with a window function with
|
||||
--echo # empty PARTITION BY and ORDER BY clauses
|
||||
--echo #
|
||||
|
||||
CREATE TABLE t1(a INT, b INT);
|
||||
INSERT INTO t1 VALUES (1,1),(2,2),(3,3);
|
||||
|
||||
--source include/analyze-format.inc
|
||||
ANALYZE FORMAT=JSON SELECT row_number() OVER() FROM t1;
|
||||
SELECT row_number() OVER() FROM t1;
|
||||
DROP TABLE t1;
|
||||
|
||||
--echo #
|
||||
--echo # End of 10.2 tests
|
||||
--echo #
|
||||
|
@ -2872,7 +2872,8 @@ bool Window_funcs_sort::setup(THD *thd, SQL_SELECT *sel,
|
||||
*/
|
||||
ORDER *order= (ORDER *)alloc_root(thd->mem_root, sizeof(ORDER));
|
||||
memset(order, 0, sizeof(*order));
|
||||
Item *item= new (thd->mem_root) Item_field(thd, join_tab->table->field[0]);
|
||||
Item *item= new (thd->mem_root) Item_temptable_field(thd,
|
||||
join_tab->table->field[0]);
|
||||
order->item= (Item **)alloc_root(thd->mem_root, 2 * sizeof(Item *));
|
||||
order->item[1]= NULL;
|
||||
order->item[0]= item;
|
||||
|
Reference in New Issue
Block a user