Skip to content

Commit d3767f9

Browse files
MDEV-39356: Server crashes when executing UPDATE ... FOR PORTION OF with a normal table
Problem: Executing an `UPDATE ... FOR PORTION OF` statement on a table without a defined period results in assertion failure. The code in `SELECT_LEX::period_setup_conds` attempts to compare a NULL period name identifier using `streq()`, which triggers the assertion in `strnncoll` funtion. Fix: Replace `streq` with `streq_safe` in `SELECT_LEX::period_setup_conds` to handle NULL pointers safely via an early-exit.
1 parent 9f5f6b6 commit d3767f9

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

mysql-test/main/ctype_utf8mb3_geeral1400_as_ci.result

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,11 @@ DROP TABLE t1;
2929
CREATE TABLE t (c INT,c2 CHAR,c3 DATE,CHECK (c>0));
3030
ALTER TABLE t ADD INDEX (c2) USING HASH;
3131
DROP TABLE t;
32+
#
33+
# MDEV-39356: Server crashes when executing UPDATE ... FOR PORTION OF with a normal table
34+
#
35+
CREATE OR REPLACE TABLE t (id INT);
36+
UPDATE t FOR PORTION OF p FROM '2026-02-01' TO '2026-03-01' SET id = 2;
37+
ERROR HY000: Period `p` is not found in table
38+
DROP TABLE t;
3239
# End of 11.8 tests

mysql-test/main/ctype_utf8mb3_geeral1400_as_ci.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,13 @@ ALTER TABLE t ADD INDEX (c2) USING HASH;
3333

3434
DROP TABLE t;
3535

36+
--echo #
37+
--echo # MDEV-39356: Server crashes when executing UPDATE ... FOR PORTION OF with a normal table
38+
--echo #
39+
40+
CREATE OR REPLACE TABLE t (id INT);
41+
--error ER_PERIOD_NOT_FOUND
42+
UPDATE t FOR PORTION OF p FROM '2026-02-01' TO '2026-03-01' SET id = 2;
43+
DROP TABLE t;
44+
3645
--echo # End of 11.8 tests

sql/sql_select.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,7 @@ int SELECT_LEX::period_setup_conds(THD *thd, TABLE_LIST *tables)
11741174
if (!table->table)
11751175
continue;
11761176
vers_select_conds_t &conds= table->period_conditions;
1177-
if (!table->table->s->period.name.streq(conds.name))
1177+
if (!table->table->s->period.name.streq_safe(conds.name))
11781178
{
11791179
my_error(ER_PERIOD_NOT_FOUND, MYF(0), conds.name.str);
11801180
if (arena)

0 commit comments

Comments
 (0)