1
0
mirror of https://github.com/MariaDB/server.git synced 2026-10-23 18:49:29 +03:00

MDEV-40821 SIGSEGV in Window_funcs_sort::setup

Window_funcs_sort failed accessing win_func->window_spec as window
spec was not defined in the query. Usually this is checked by fixing
item win_func, but it was not done by vers_setup_conds().

Actually, earlier check by vers_setup_conds() must fail on DELETE
HISTORY from non-versioned table, but TABLE_LIST for t1 has no
versioning conditions.

The cause was the parser assigning versioning conditions to wrong
table pointed by last_table() which was already switched to another
table from SYSTEM_TIME expression (cs1). It is fixed by the 10.11
commit of MDEV-40821, this commit adds the tests.

DELETE ... FOR PORTION OF with index hints is converted to
multi-table, same as with a subquery on the target table, which is
prohibited by the 11.4 commit of MDEV-40821. Tests added for index
hints.

Warning WARN_INDEX_HINTS_IGNORED now names the clause the index hints
are incompatible with: RETURNING or FOR PORTION OF.
This commit is contained in:
Aleksey Midenkov
2026-09-21 19:23:26 +03:00
parent 498fdb44e2
commit 525db0b508
6 changed files with 101 additions and 3 deletions

View File

@@ -451,3 +451,35 @@ id s e
1 2000-01-01 2000-01-05
drop table t1;
# End of 11.4 tests
#
# MDEV-40821 SIGSEGV in Window_funcs_sort::setup
#
create table t1 (c1 int key);
create sequence cs1 engine myisam;
delete from t1 ignore index (primary) for portion of app from setval(cs1,1) to sum(1) over w1;
ERROR HY000: Period `app` is not found in table
create or replace table t1 (c1 int key, s date, e date, period for app(s,e));
delete from t1 ignore index (primary) for portion of app from setval(cs1,1) to sum(1) over w1;
ERROR HY000: Window function is allowed only in SELECT list and ORDER BY clause
drop sequence cs1;
drop table t1;
create table t1 (id int, s date, e date, period for app(s,e), key(id));
# Index hint: row must be split, not deleted
insert into t1 values (1, '2000-01-01', '2000-01-10');
delete from t1 ignore index (id)
for portion of app from '2000-01-05' to '2000-01-20';
Warnings:
Warning 4207 Index hints are ignored because they are incompatible with FOR PORTION OF clause
select * from t1;
id s e
1 2000-01-01 2000-01-05
# Index hint: non-constant bounds must be rejected
delete from t1;
insert into t1 values (1, '2000-01-01', '2000-01-10');
delete from t1 ignore index (id) for portion of app from s to e;
ERROR HY000: Expression in FOR PORTION OF must be constant
select * from t1;
id s e
1 2000-01-01 2000-01-10
drop table t1;
# End of 11.8 tests

View File

@@ -1,6 +1,7 @@
source suite/period/engines.inc;
source include/have_log_bin.inc;
source include/have_partition.inc;
source include/have_sequence.inc;
create table t (id int, s date, e date, period for apptime(s,e));
@@ -298,3 +299,36 @@ select * from t1;
drop table t1;
--echo # End of 11.4 tests
--echo #
--echo # MDEV-40821 SIGSEGV in Window_funcs_sort::setup
--echo #
create table t1 (c1 int key);
create sequence cs1 engine myisam;
--error ER_PERIOD_NOT_FOUND
delete from t1 ignore index (primary) for portion of app from setval(cs1,1) to sum(1) over w1;
create or replace table t1 (c1 int key, s date, e date, period for app(s,e));
--error ER_WRONG_PLACEMENT_OF_WINDOW_FUNCTION
delete from t1 ignore index (primary) for portion of app from setval(cs1,1) to sum(1) over w1;
# Cleanup
drop sequence cs1;
drop table t1;
create table t1 (id int, s date, e date, period for app(s,e), key(id));
--echo # Index hint: row must be split, not deleted
insert into t1 values (1, '2000-01-01', '2000-01-10');
delete from t1 ignore index (id)
for portion of app from '2000-01-05' to '2000-01-20';
select * from t1;
--echo # Index hint: non-constant bounds must be rejected
delete from t1;
insert into t1 values (1, '2000-01-01', '2000-01-10');
--error ER_NOT_CONSTANT_EXPRESSION
delete from t1 ignore index (id) for portion of app from s to e;
select * from t1;
drop table t1;
--echo # End of 11.8 tests

View File

@@ -602,3 +602,16 @@ x
1
drop table t1, t2, t3, t4;
# End of 10.11 tests
#
# MDEV-40821 SIGSEGV in Window_funcs_sort::setup
#
create table t1 (c1 int key);
create sequence cs1 engine myisam;
delete history from t1 ignore index (primary) before system_time timestamp(setval(cs1,1),sum(1) over w1);
ERROR HY000: Table `t1` is not system-versioned
create or replace table t1 (c1 int key) with system versioning;
delete history from t1 ignore index (primary) before system_time timestamp(setval(cs1,1),sum(1) over w1);
ERROR HY000: Window function is allowed only in SELECT list and ORDER BY clause
drop sequence cs1;
drop table t1;
# End of 11.8 tests

View File

@@ -2,6 +2,7 @@
--source include/have_partition.inc
--source suite/versioning/engines.inc
--source include/word_size.inc
--source include/have_sequence.inc
call mtr.add_suppression("need more HISTORY partitions");
@@ -456,4 +457,20 @@ drop table t1, t2, t3, t4;
--echo # End of 10.11 tests
--echo #
--echo # MDEV-40821 SIGSEGV in Window_funcs_sort::setup
--echo #
create table t1 (c1 int key);
create sequence cs1 engine myisam;
--error ER_VERS_NOT_VERSIONED
delete history from t1 ignore index (primary) before system_time timestamp(setval(cs1,1),sum(1) over w1);
create or replace table t1 (c1 int key) with system versioning;
--error ER_WRONG_PLACEMENT_OF_WINDOW_FUNCTION
delete history from t1 ignore index (primary) before system_time timestamp(setval(cs1,1),sum(1) over w1);
# Cleanup
drop sequence cs1;
drop table t1;
--echo # End of 11.8 tests
--source suite/versioning/common_finish.inc

View File

@@ -12293,7 +12293,7 @@ ER_PSEUDO_THREAD_ID_OVERWRITE
ER_VEC_DISTANCE_TYPE
eng "Cannot determine distance type for VEC_DISTANCE, index is not found"
WARN_INDEX_HINTS_IGNORED
eng "Index hints are ignored because they are incompatible with RETURNING clause"
ukr "Підказки по використанню индексів ігноруются тому що вони несумісні з RETURNING"
eng "Index hints are ignored because they are incompatible with %s clause"
ukr "Підказки по використанню индексів ігноруются тому що вони несумісні з %s"
ER_SIGNAL_SKIP_ROW_FROM_TRIGGER
eng "The row is skipped by a trigger implementation"

View File

@@ -1967,7 +1967,9 @@ bool Sql_cmd_delete::prepare_inner(THD *thd)
{
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
WARN_INDEX_HINTS_IGNORED,
"%s", ER_THD(thd, WARN_INDEX_HINTS_IGNORED));
ER_THD(thd, WARN_INDEX_HINTS_IGNORED),
thd->lex->has_returning() ?
"RETURNING" : "FOR PORTION OF");
}
}
if (table_list->vers_conditions.is_set() && table_list->is_view_or_derived())