Skip to content

Commit fc46559

Browse files
committed
MDEV-37164 Assertion `vers_conditions.delete_history' failed upon PREPARE
Wrong assertion was added by f1f9284 (MDEV-34046) because PS parameter is applicable not only to DELETE HISTORY. Keeping value of select_lex->where for DELETE HISTORY was remade via prep_where which is read by reinit_stmt_before_use(). For SELECT prep_where is set in JOIN::optimize_inner() and that is not called for DELETE.
1 parent 39f4908 commit fc46559

File tree

3 files changed

+62
-15
lines changed

3 files changed

+62
-15
lines changed

mysql-test/suite/versioning/r/delete_history.result

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,40 @@ a row_start row_end
277277
2 2000-01-01 00:00:01.000000 2000-01-01 00:00:02.000000
278278
3 2000-01-01 00:00:02.000000 2038-01-19 03:14:07.999999
279279
100 2000-01-01 00:00:00.000000 2038-01-19 03:14:07.999999
280+
select *, row_start, row_end from t for system_time as of @ts1;
281+
a row_start row_end
282+
100 2000-01-01 00:00:00.000000 2038-01-19 03:14:07.999999
283+
2 2000-01-01 00:00:01.000000 2000-01-01 00:00:02.000000
284+
execute immediate "select *, row_start, row_end from t for system_time as of ?" using @ts1;
285+
a row_start row_end
286+
100 2000-01-01 00:00:00.000000 2038-01-19 03:14:07.999999
287+
2 2000-01-01 00:00:01.000000 2000-01-01 00:00:02.000000
288+
prepare stmt from 'select *, row_start, row_end from t for system_time as of ?';
289+
execute stmt using @ts1;
290+
a row_start row_end
291+
100 2000-01-01 00:00:00.000000 2038-01-19 03:14:07.999999
292+
2 2000-01-01 00:00:01.000000 2000-01-01 00:00:02.000000
293+
Execute stmt using @ts1;
294+
a row_start row_end
295+
100 2000-01-01 00:00:00.000000 2038-01-19 03:14:07.999999
296+
2 2000-01-01 00:00:01.000000 2000-01-01 00:00:02.000000
297+
select *, row_start, row_end from t for system_time as of @ts2;
298+
a row_start row_end
299+
3 2000-01-01 00:00:02.000000 2038-01-19 03:14:07.999999
300+
100 2000-01-01 00:00:00.000000 2038-01-19 03:14:07.999999
301+
execute immediate "select *, row_start, row_end from t for system_time as of ?" using @ts2;
302+
a row_start row_end
303+
3 2000-01-01 00:00:02.000000 2038-01-19 03:14:07.999999
304+
100 2000-01-01 00:00:00.000000 2038-01-19 03:14:07.999999
305+
execute stmt using @ts2;
306+
a row_start row_end
307+
3 2000-01-01 00:00:02.000000 2038-01-19 03:14:07.999999
308+
100 2000-01-01 00:00:00.000000 2038-01-19 03:14:07.999999
309+
Execute stmt using @ts2;
310+
a row_start row_end
311+
3 2000-01-01 00:00:02.000000 2038-01-19 03:14:07.999999
312+
100 2000-01-01 00:00:00.000000 2038-01-19 03:14:07.999999
313+
drop prepare stmt;
280314
execute immediate "delete history from t before system_time @ts1";
281315
select *, row_start, row_end from t for system_time all order by a;
282316
a row_start row_end
@@ -463,4 +497,11 @@ a row_start row_end
463497
drop prepare stmt;
464498
drop table t;
465499
set timestamp= default;
500+
#
501+
# MDEV-37164 Assertion `vers_conditions.delete_history' failed upon PREPARE
502+
#
503+
create table t (a int) with system versioning;
504+
insert into t values (1),(2);
505+
prepare stmt from 'select * from t for system_time as of timestamp ?';
506+
drop table t;
466507
# End of 10.11 tests

mysql-test/suite/versioning/t/delete_history.test

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,17 @@ set @ts2= '2000-01-01 00:00:02'; set timestamp= unix_timestamp(@ts2);
276276
update t set a= a + 1 where a < 100;
277277
set @ts3= '2000-01-01 00:00:03'; set timestamp= unix_timestamp(@ts3);
278278
select *, row_start, row_end from t for system_time all order by a;
279+
select *, row_start, row_end from t for system_time as of @ts1;
280+
execute immediate "select *, row_start, row_end from t for system_time as of ?" using @ts1;
281+
prepare stmt from 'select *, row_start, row_end from t for system_time as of ?';
282+
execute stmt using @ts1;
283+
Execute stmt using @ts1;
284+
select *, row_start, row_end from t for system_time as of @ts2;
285+
execute immediate "select *, row_start, row_end from t for system_time as of ?" using @ts2;
286+
execute stmt using @ts2;
287+
Execute stmt using @ts2;
288+
drop prepare stmt;
289+
279290
execute immediate "delete history from t before system_time @ts1";
280291
select *, row_start, row_end from t for system_time all order by a;
281292
execute immediate "delete history from t before system_time @ts2";
@@ -352,6 +363,14 @@ drop prepare stmt;
352363
drop table t;
353364
set timestamp= default;
354365

366+
--echo #
367+
--echo # MDEV-37164 Assertion `vers_conditions.delete_history' failed upon PREPARE
368+
--echo #
369+
create table t (a int) with system versioning;
370+
insert into t values (1),(2);
371+
prepare stmt from 'select * from t for system_time as of timestamp ?';
372+
drop table t;
373+
355374
--echo # End of 10.11 tests
356375

357376
--source suite/versioning/common_finish.inc

sql/sql_select.cc

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,21 +1279,7 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables)
12791279
}
12801280

12811281
if (vers_conditions.type == SYSTEM_TIME_ALL)
1282-
{
1283-
if (vers_conditions.has_param)
1284-
{
1285-
/*
1286-
Parameter substitution (set_params_from_actual_params()) works
1287-
on existing items so we don't have to reevaluate table->where
1288-
(in update_this below), we just update SELECT_LEX WHERE expression
1289-
from existing table conditions.
1290-
*/
1291-
DBUG_ASSERT(vers_conditions.delete_history);
1292-
DBUG_ASSERT(thd->stmt_arena->is_stmt_execute());
1293-
where= and_items(thd, where, table->where);
1294-
}
12951282
continue;
1296-
}
12971283
}
12981284

12991285
bool timestamps_only= table->table->versioned(VERS_TIMESTAMP);
@@ -1322,7 +1308,6 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables)
13221308
the loop, but at execution enter update_this. The second execution
13231309
is skipped on vers_conditions.type == SYSTEM_TIME_ALL condition.
13241310
*/
1325-
DBUG_ASSERT(vers_conditions.delete_history);
13261311
if (thd->stmt_arena->is_stmt_prepare())
13271312
continue;
13281313
DBUG_ASSERT(thd->stmt_arena->is_stmt_execute());
@@ -1347,6 +1332,8 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables)
13471332
else
13481333
where= and_items(thd, where, cond);
13491334
table->where= and_items(thd, table->where, cond);
1335+
if (where && vers_conditions.has_param && vers_conditions.delete_history)
1336+
prep_where= where->copy_andor_structure(thd);
13501337
}
13511338

13521339
table->vers_conditions.set_all();

0 commit comments

Comments
 (0)