@@ -701,44 +701,54 @@ setup_for_system_time(THD *thd, TABLE_LIST *tables, COND **where_expr, SELECT_LE
701
701
if (select_lex->saved_where)
702
702
{
703
703
DBUG_ASSERT(thd->stmt_arena->is_sp_execute());
704
- *where_expr= select_lex->saved_where;
704
+ /* 2. this copy_andor_structure() is also required by the same reason */
705
+ *where_expr= select_lex->saved_where->copy_andor_structure(thd);
705
706
}
706
707
else if (thd->stmt_arena->is_sp_execute())
707
708
{
708
709
if (thd->stmt_arena->is_stmt_execute()) // SP executed second time (STMT_EXECUTED)
709
710
*where_expr= 0;
710
711
else if (*where_expr) // SP executed first time (STMT_INITIALIZED_FOR_SP)
711
- /* copy_andor_structure() is required since this andor tree
712
+ /* 1. copy_andor_structure() is required since this andor tree
712
713
is modified later (and on shorter arena) */
713
714
select_lex->saved_where= (*where_expr)->copy_andor_structure(thd);
714
715
}
715
716
716
- for (table= tables; table; table= table->next_local)
717
+ /* We have to save also non-versioned on_expr since we may have
718
+ conjuction of versioned + non-versioned */
719
+ if (thd->stmt_arena->is_sp_execute())
717
720
{
718
- if (table-> table && table->table->versioned() )
721
+ for (table= tables; table; table= table->next_local )
719
722
{
720
- COND** dst_cond= where_expr;
723
+ if (!table->table)
724
+ continue;
725
+
721
726
if (table->saved_on_expr) // same logic as saved_where
722
727
{
723
- DBUG_ASSERT(thd->stmt_arena->is_sp_execute());
724
728
if (table->on_expr)
725
- {
726
- table->on_expr= table->saved_on_expr;
727
- dst_cond= &table->on_expr;
728
- }
729
+ table->on_expr= table->saved_on_expr->copy_andor_structure(thd);
729
730
else
730
- {
731
731
// on_expr was moved to WHERE (see below: Add ON expression to the WHERE)
732
- *dst_cond = and_items(thd,
732
+ *where_expr = and_items(thd,
733
733
*where_expr,
734
- table->saved_on_expr);
735
- }
734
+ table->saved_on_expr->copy_andor_structure(thd));
735
+ }
736
+ else if (table->on_expr &&
737
+ thd->stmt_arena->state == Query_arena::STMT_INITIALIZED_FOR_SP)
738
+ {
739
+ table->saved_on_expr= table->on_expr->copy_andor_structure(thd);
736
740
}
737
- else if (table->on_expr)
741
+ }
742
+ }
743
+
744
+ for (table= tables; table; table= table->next_local)
745
+ {
746
+ if (table->table && table->table->versioned())
747
+ {
748
+ COND** dst_cond= where_expr;
749
+ if (table->on_expr)
738
750
{
739
751
dst_cond= &table->on_expr;
740
- if (thd->stmt_arena->state == Query_arena::STMT_INITIALIZED_FOR_SP)
741
- table->saved_on_expr= table->on_expr->copy_andor_structure(thd);
742
752
}
743
753
744
754
Field *fstart= table->table->vers_start_field();
0 commit comments