Commit 21f90d19 authored by unknown's avatar unknown

Fix the client_test failure (due to failing cursors tests after the merge).


sql/sql_select.cc:
  Fix the client_test failure (due to failing cursors tests after the merge):
  move some code around, use set_n_backup calls instead of by-hand
  setup.
parent 714fc4b7
...@@ -1898,7 +1898,7 @@ void mysql_stmt_execute(THD *thd, char *packet, uint packet_length) ...@@ -1898,7 +1898,7 @@ void mysql_stmt_execute(THD *thd, char *packet, uint packet_length)
{ {
if (stmt->cursor->is_open()) if (stmt->cursor->is_open())
stmt->cursor->init_from_thd(thd); stmt->cursor->init_from_thd(thd);
thd->set_item_arena(&thd->stmt_backup); stmt->cursor->state= stmt->state;
} }
else else
{ {
...@@ -2044,6 +2044,7 @@ void mysql_stmt_fetch(THD *thd, char *packet, uint packet_length) ...@@ -2044,6 +2044,7 @@ void mysql_stmt_fetch(THD *thd, char *packet, uint packet_length)
DBUG_ENTER("mysql_stmt_fetch"); DBUG_ENTER("mysql_stmt_fetch");
thd->current_arena= stmt;
if (!(stmt= thd->stmt_map.find(stmt_id)) || if (!(stmt= thd->stmt_map.find(stmt_id)) ||
!stmt->cursor || !stmt->cursor ||
!stmt->cursor->is_open()) !stmt->cursor->is_open())
...@@ -2053,9 +2054,7 @@ void mysql_stmt_fetch(THD *thd, char *packet, uint packet_length) ...@@ -2053,9 +2054,7 @@ void mysql_stmt_fetch(THD *thd, char *packet, uint packet_length)
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
thd->stmt_backup.set_statement(thd); thd->set_n_backup_statement(stmt, &thd->stmt_backup);
thd->stmt_backup.set_item_arena(thd);
thd->set_statement(stmt);
stmt->cursor->init_thd(thd); stmt->cursor->init_thd(thd);
if (!(specialflag & SPECIAL_NO_PRIOR)) if (!(specialflag & SPECIAL_NO_PRIOR))
...@@ -2070,11 +2069,8 @@ void mysql_stmt_fetch(THD *thd, char *packet, uint packet_length) ...@@ -2070,11 +2069,8 @@ void mysql_stmt_fetch(THD *thd, char *packet, uint packet_length)
/* Restore THD state */ /* Restore THD state */
stmt->cursor->reset_thd(thd); stmt->cursor->reset_thd(thd);
thd->set_statement(&thd->stmt_backup); thd->restore_backup_statement(stmt, &thd->stmt_backup);
thd->set_item_arena(&thd->stmt_backup); thd->current_arena= thd;
if (error && error != -4)
send_error(thd, ER_OUT_OF_RESOURCES);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
......
...@@ -1683,8 +1683,6 @@ Cursor::init_from_thd(THD *thd) ...@@ -1683,8 +1683,6 @@ Cursor::init_from_thd(THD *thd)
void void
Cursor::init_thd(THD *thd) Cursor::init_thd(THD *thd)
{ {
thd->mem_root= mem_root;
DBUG_ASSERT(thd->derived_tables == 0); DBUG_ASSERT(thd->derived_tables == 0);
thd->derived_tables= derived_tables; thd->derived_tables= derived_tables;
...@@ -1694,7 +1692,6 @@ Cursor::init_thd(THD *thd) ...@@ -1694,7 +1692,6 @@ Cursor::init_thd(THD *thd)
DBUG_ASSERT(thd->lock== 0); DBUG_ASSERT(thd->lock== 0);
thd->lock= lock; thd->lock= lock;
thd->query_id= query_id; thd->query_id= query_id;
thd->free_list= free_list;
} }
...@@ -1779,6 +1776,8 @@ Cursor::fetch(ulong num_rows) ...@@ -1779,6 +1776,8 @@ Cursor::fetch(ulong num_rows)
int error= 0; int error= 0;
/* save references to memory, allocated during fetch */
thd->set_n_backup_item_arena(this, &thd->stmt_backup);
join->fetch_limit+= num_rows; join->fetch_limit+= num_rows;
/* /*
...@@ -1842,54 +1841,37 @@ Cursor::fetch(ulong num_rows) ...@@ -1842,54 +1841,37 @@ Cursor::fetch(ulong num_rows)
if (thd->net.report_error) if (thd->net.report_error)
error= -1; error= -1;
if (error == -3) /* LIMIT clause worked */
error= 0;
switch (error) { #ifdef USING_TRANSACTIONS
/* Fetch limit worked, possibly more rows are there */
case -4:
if (thd->transaction.all.innobase_tid) if (thd->transaction.all.innobase_tid)
ha_release_temporary_latches(thd); ha_release_temporary_latches(thd);
#endif
thd->restore_backup_item_arena(this, &thd->stmt_backup);
if (error == -4)
{
/* Fetch limit worked, possibly more rows are there */
thd->server_status|= SERVER_STATUS_CURSOR_EXISTS; thd->server_status|= SERVER_STATUS_CURSOR_EXISTS;
::send_eof(thd); ::send_eof(thd);
thd->server_status&= ~SERVER_STATUS_CURSOR_EXISTS; thd->server_status&= ~SERVER_STATUS_CURSOR_EXISTS;
/* save references to memory, allocated during fetch */ }
mem_root= thd->mem_root; else
free_list= thd->free_list; {
break;
/* Limit clause worked: this is the same as 'no more rows' */
case -3: /* LIMIT clause worked */
error= 0;
/* fallthrough */
case 0: /* No more rows */
if (thd->transaction.all.innobase_tid)
ha_release_temporary_latches(thd);
close(); close();
if (error == 0)
{
thd->server_status|= SERVER_STATUS_LAST_ROW_SENT; thd->server_status|= SERVER_STATUS_LAST_ROW_SENT;
::send_eof(thd); ::send_eof(thd);
thd->server_status&= ~SERVER_STATUS_LAST_ROW_SENT; thd->server_status&= ~SERVER_STATUS_LAST_ROW_SENT;
join= 0; }
unit= 0; else
free_items(thd->free_list); send_error(thd, ER_OUT_OF_RESOURCES);
thd->free_list= free_list= 0; /* free cursor memory */
/* free_items(free_list);
Must be last, as some memory might be allocated for free purposes, free_list= 0;
like in free_tmp_table() (TODO: fix this issue)
*/
mem_root= thd->mem_root;
free_root(&mem_root, MYF(0));
break;
default:
close();
join= 0;
unit= 0;
free_items(thd->free_list);
thd->free_list= free_list= 0;
/*
Must be last, as some memory might be allocated for free purposes,
like in free_tmp_table() (TODO: fix this issue)
*/
mem_root= thd->mem_root;
free_root(&mem_root, MYF(0)); free_root(&mem_root, MYF(0));
break;
} }
return error; return error;
} }
...@@ -1927,6 +1909,8 @@ Cursor::close() ...@@ -1927,6 +1909,8 @@ Cursor::close()
thd->derived_tables= tmp_derived_tables; thd->derived_tables= tmp_derived_tables;
thd->lock= tmp_lock; thd->lock= tmp_lock;
} }
join= 0;
unit= 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment