Skip to content

Commit 01c9d1c

Browse files
committed
SQL: SP idempotency fix
Fixes #52
1 parent 44e581e commit 01c9d1c

File tree

3 files changed

+66
-19
lines changed

3 files changed

+66
-19
lines changed

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,45 @@ A x y x y
9393
1 5 15 5 15
9494
1 6 16 6 16
9595
1 7 17 7 17
96+
call test_01('bigint unsigned', 'innodb', 'commit_ts(sys_end)');
97+
A x y x y
98+
1 1 11 1 11
99+
1 2 12 2 12
100+
1 3 13 3 13
101+
1 4 14 4 14
102+
1 5 15 5 15
103+
1 6 16 6 16
104+
1 7 17 7 17
105+
1 8 18 8 18
106+
1 9 19 9 19
107+
A x y x y
108+
1 1 11 1 11
109+
1 3 13 3 13
110+
1 4 14 4 14
111+
1 5 15 5 15
112+
1 6 16 6 16
113+
1 7 17 7 17
114+
1 8 18 8 18
115+
1 9 19 9 19
116+
A x y x y
117+
1 1 11 1 11
118+
1 3 13 3 13
119+
1 4 14 4 14
120+
1 5 15 5 15
121+
1 6 16 6 16
122+
1 7 17 7 17
96123
call verify_vtq;
97124
No A B C D
125+
1 1 1 1 1
126+
2 1 1 1 1
127+
3 1 1 1 1
128+
4 1 1 1 1
129+
5 1 1 1 1
130+
6 1 1 1 1
131+
7 1 1 1 1
132+
8 1 1 1 1
133+
9 1 1 1 1
134+
10 1 1 1 1
135+
11 1 1 1 1
98136
drop procedure test_01;
99137
drop procedure verify_vtq;

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ end~~
6060
delimiter ;~~
6161

6262
call test_01('timestamp(6)', 'myisam', 'sys_end');
63-
# Issue #52
64-
# call test_01('bigint unsigned', 'innodb', 'commit_ts(sys_end)');
63+
call test_01('bigint unsigned', 'innodb', 'commit_ts(sys_end)');
6564
call verify_vtq;
6665

6766
drop procedure test_01;

sql/sql_select.cc

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -701,44 +701,54 @@ setup_for_system_time(THD *thd, TABLE_LIST *tables, COND **where_expr, SELECT_LE
701701
if (select_lex->saved_where)
702702
{
703703
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);
705706
}
706707
else if (thd->stmt_arena->is_sp_execute())
707708
{
708709
if (thd->stmt_arena->is_stmt_execute()) // SP executed second time (STMT_EXECUTED)
709710
*where_expr= 0;
710711
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
712713
is modified later (and on shorter arena) */
713714
select_lex->saved_where= (*where_expr)->copy_andor_structure(thd);
714715
}
715716

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())
717720
{
718-
if (table->table && table->table->versioned())
721+
for (table= tables; table; table= table->next_local)
719722
{
720-
COND** dst_cond= where_expr;
723+
if (!table->table)
724+
continue;
725+
721726
if (table->saved_on_expr) // same logic as saved_where
722727
{
723-
DBUG_ASSERT(thd->stmt_arena->is_sp_execute());
724728
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);
729730
else
730-
{
731731
// 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,
733733
*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);
736740
}
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)
738750
{
739751
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);
742752
}
743753

744754
Field *fstart= table->table->vers_start_field();

0 commit comments

Comments
 (0)