2006-12-31 01:02:27 +01:00
|
|
|
/* Copyright (C) 2005-2006 MySQL AB
|
2005-09-22 00:11:21 +02:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2006-12-23 20:17:15 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2005-09-22 00:11:21 +02:00
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
#ifdef USE_PRAGMA_IMPLEMENTATION
|
|
|
|
#pragma implementation /* gcc class implementation */
|
|
|
|
#endif
|
|
|
|
|
2010-03-31 16:05:33 +02:00
|
|
|
#include "sql_priv.h"
|
|
|
|
#include "unireg.h"
|
2005-09-22 00:11:21 +02:00
|
|
|
#include "sql_cursor.h"
|
2008-12-20 11:01:41 +01:00
|
|
|
#include "probes_mysql.h"
|
2010-03-31 16:05:33 +02:00
|
|
|
#include "sql_parse.h" // mysql_execute_command
|
2005-09-22 00:11:21 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
Declarations.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2007-10-16 21:37:31 +02:00
|
|
|
/**
|
2005-09-22 00:11:21 +02:00
|
|
|
Materialized_cursor -- an insensitive materialized server-side
|
|
|
|
cursor. The result set of this cursor is saved in a temporary
|
|
|
|
table at open. The cursor itself is simply an interface for the
|
|
|
|
handler of the temporary table.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class Materialized_cursor: public Server_side_cursor
|
|
|
|
{
|
|
|
|
MEM_ROOT main_mem_root;
|
|
|
|
/* A fake unit to supply to select_send when fetching */
|
|
|
|
SELECT_LEX_UNIT fake_unit;
|
|
|
|
TABLE *table;
|
|
|
|
List<Item> item_list;
|
|
|
|
ulong fetch_limit;
|
|
|
|
ulong fetch_count;
|
2008-12-10 15:13:11 +01:00
|
|
|
bool is_rnd_inited;
|
2005-09-22 00:11:21 +02:00
|
|
|
public:
|
|
|
|
Materialized_cursor(select_result *result, TABLE *table);
|
|
|
|
|
Backport of revno 2630.28.10, 2630.28.31, 2630.28.26, 2630.33.1,
2630.39.1, 2630.28.29, 2630.34.3, 2630.34.2, 2630.34.1, 2630.29.29,
2630.29.28, 2630.31.1, 2630.28.13, 2630.28.10, 2617.23.14 and
some other minor revisions.
This patch implements:
WL#4264 "Backup: Stabilize Service Interface" -- all the
server prerequisites except si_objects.{h,cc} themselves (they can
be just copied over, when needed).
WL#4435: Support OUT-parameters in prepared statements.
(and all issues in the initial patches for these two
tasks, that were discovered in pushbuild and during testing).
Bug#39519: mysql_stmt_close() should flush all data
associated with the statement.
After execution of a prepared statement, send OUT parameters of the invoked
stored procedure, if any, to the client.
When using the binary protocol, send the parameters in an additional result
set over the wire. When using the text protocol, assign out parameters to
the user variables from the CALL(@var1, @var2, ...) specification.
The following refactoring has been made:
- Protocol::send_fields() was renamed to Protocol::send_result_set_metadata();
- A new Protocol::send_result_set_row() was introduced to incapsulate
common functionality for sending row data.
- Signature of Protocol::prepare_for_send() was changed: this operation
does not need a list of items, the number of items is fully sufficient.
The following backward incompatible changes have been made:
- CLIENT_MULTI_RESULTS is now enabled by default in the client;
- CLIENT_PS_MULTI_RESUTLS is now enabled by default in the client.
2009-10-21 22:02:06 +02:00
|
|
|
int fill_item_list(THD *thd, List<Item> &send_result_set_metadata);
|
2005-09-22 00:11:21 +02:00
|
|
|
virtual bool is_open() const { return table != 0; }
|
|
|
|
virtual int open(JOIN *join __attribute__((unused)));
|
|
|
|
virtual void fetch(ulong num_rows);
|
|
|
|
virtual void close();
|
|
|
|
virtual ~Materialized_cursor();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-10-16 21:37:31 +02:00
|
|
|
/**
|
2005-09-22 00:11:21 +02:00
|
|
|
Select_materialize -- a mediator between a cursor query and the
|
|
|
|
protocol. In case we were not able to open a non-materialzed
|
|
|
|
cursor, it creates an internal temporary HEAP table, and insert
|
|
|
|
all rows into it. When the table reaches max_heap_table_size,
|
|
|
|
it's converted to a MyISAM table. Later this table is used to
|
|
|
|
create a Materialized_cursor.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class Select_materialize: public select_union
|
|
|
|
{
|
2007-10-16 21:37:31 +02:00
|
|
|
select_result *result; /**< the result object of the caller (PS or SP) */
|
2005-09-22 00:11:21 +02:00
|
|
|
public:
|
2008-02-20 20:45:24 +01:00
|
|
|
Materialized_cursor *materialized_cursor;
|
2008-04-17 21:02:01 +02:00
|
|
|
Select_materialize(select_result *result_arg)
|
|
|
|
:result(result_arg), materialized_cursor(0) {}
|
Backport of revno 2630.28.10, 2630.28.31, 2630.28.26, 2630.33.1,
2630.39.1, 2630.28.29, 2630.34.3, 2630.34.2, 2630.34.1, 2630.29.29,
2630.29.28, 2630.31.1, 2630.28.13, 2630.28.10, 2617.23.14 and
some other minor revisions.
This patch implements:
WL#4264 "Backup: Stabilize Service Interface" -- all the
server prerequisites except si_objects.{h,cc} themselves (they can
be just copied over, when needed).
WL#4435: Support OUT-parameters in prepared statements.
(and all issues in the initial patches for these two
tasks, that were discovered in pushbuild and during testing).
Bug#39519: mysql_stmt_close() should flush all data
associated with the statement.
After execution of a prepared statement, send OUT parameters of the invoked
stored procedure, if any, to the client.
When using the binary protocol, send the parameters in an additional result
set over the wire. When using the text protocol, assign out parameters to
the user variables from the CALL(@var1, @var2, ...) specification.
The following refactoring has been made:
- Protocol::send_fields() was renamed to Protocol::send_result_set_metadata();
- A new Protocol::send_result_set_row() was introduced to incapsulate
common functionality for sending row data.
- Signature of Protocol::prepare_for_send() was changed: this operation
does not need a list of items, the number of items is fully sufficient.
The following backward incompatible changes have been made:
- CLIENT_MULTI_RESULTS is now enabled by default in the client;
- CLIENT_PS_MULTI_RESUTLS is now enabled by default in the client.
2009-10-21 22:02:06 +02:00
|
|
|
virtual bool send_result_set_metadata(List<Item> &list, uint flags);
|
2005-09-22 00:11:21 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
2007-10-16 21:37:31 +02:00
|
|
|
/**
|
2010-07-27 14:42:36 +02:00
|
|
|
Attempt to open a materialized cursor.
|
2005-09-22 00:11:21 +02:00
|
|
|
|
2007-10-16 21:37:31 +02:00
|
|
|
@param thd thread handle
|
|
|
|
@param[in] result result class of the caller used as a destination
|
|
|
|
for the rows fetched from the cursor
|
|
|
|
@param[out] pcursor a pointer to store a pointer to cursor in
|
|
|
|
|
|
|
|
@retval
|
|
|
|
0 the query has been successfully executed; in this
|
|
|
|
case pcursor may or may not contain
|
|
|
|
a pointer to an open cursor.
|
|
|
|
@retval
|
|
|
|
non-zero an error, 'pcursor' has been left intact.
|
2005-09-22 00:11:21 +02:00
|
|
|
*/
|
|
|
|
|
2010-07-27 14:42:36 +02:00
|
|
|
int mysql_open_cursor(THD *thd, select_result *result,
|
2005-09-22 00:11:21 +02:00
|
|
|
Server_side_cursor **pcursor)
|
|
|
|
{
|
|
|
|
select_result *save_result;
|
|
|
|
Select_materialize *result_materialize;
|
|
|
|
LEX *lex= thd->lex;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (! (result_materialize= new (thd->mem_root) Select_materialize(result)))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
save_result= lex->result;
|
|
|
|
|
|
|
|
lex->result= result_materialize;
|
2010-07-27 14:42:36 +02:00
|
|
|
|
2009-11-05 15:51:00 +01:00
|
|
|
MYSQL_QUERY_EXEC_START(thd->query(),
|
2008-12-20 11:01:41 +01:00
|
|
|
thd->thread_id,
|
|
|
|
(char *) (thd->db ? thd->db : ""),
|
2010-12-08 17:47:21 +01:00
|
|
|
&thd->security_ctx->priv_user[0],
|
2008-12-20 11:01:41 +01:00
|
|
|
(char *) thd->security_ctx->host_or_ip,
|
|
|
|
2);
|
2005-09-22 00:11:21 +02:00
|
|
|
rc= mysql_execute_command(thd);
|
2008-12-20 11:01:41 +01:00
|
|
|
MYSQL_QUERY_EXEC_DONE(rc);
|
2005-09-22 00:11:21 +02:00
|
|
|
|
|
|
|
lex->result= save_result;
|
|
|
|
/*
|
|
|
|
Possible options here:
|
|
|
|
- a materialized cursor is open. In this case rc is 0 and
|
2008-02-20 20:45:24 +01:00
|
|
|
result_materialize->materialized is not NULL
|
|
|
|
- an error occurred during materialization.
|
|
|
|
result_materialize->materialized_cursor is not NULL, but rc != 0
|
2005-09-22 00:11:21 +02:00
|
|
|
- successful completion of mysql_execute_command without
|
2010-07-27 14:42:36 +02:00
|
|
|
a cursor: rc is 0, result_materialize->materialized_cursor is NULL.
|
2005-09-22 00:11:21 +02:00
|
|
|
This is possible if some command writes directly to the
|
|
|
|
network, bypassing select_result mechanism. An example of
|
|
|
|
such command is SHOW VARIABLES or SHOW STATUS.
|
|
|
|
*/
|
|
|
|
if (rc)
|
2008-12-10 15:13:11 +01:00
|
|
|
{
|
|
|
|
if (result_materialize->materialized_cursor)
|
|
|
|
delete result_materialize->materialized_cursor;
|
2005-09-22 00:11:21 +02:00
|
|
|
goto end;
|
|
|
|
}
|
2010-07-27 14:42:36 +02:00
|
|
|
|
|
|
|
if (result_materialize->materialized_cursor)
|
2005-09-22 00:11:21 +02:00
|
|
|
{
|
2008-02-20 20:45:24 +01:00
|
|
|
Materialized_cursor *materialized_cursor=
|
|
|
|
result_materialize->materialized_cursor;
|
2005-09-22 00:11:21 +02:00
|
|
|
|
|
|
|
if ((rc= materialized_cursor->open(0)))
|
|
|
|
{
|
|
|
|
delete materialized_cursor;
|
2010-07-27 14:42:36 +02:00
|
|
|
goto end;
|
2005-09-22 00:11:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
*pcursor= materialized_cursor;
|
|
|
|
thd->stmt_arena->cleanup_stmt();
|
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
|
|
|
delete result_materialize;
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
Server_side_cursor
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
Server_side_cursor::~Server_side_cursor()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Server_side_cursor::operator delete(void *ptr, size_t size)
|
|
|
|
{
|
|
|
|
Server_side_cursor *cursor= (Server_side_cursor*) ptr;
|
|
|
|
MEM_ROOT own_root= *cursor->mem_root;
|
|
|
|
|
|
|
|
DBUG_ENTER("Server_side_cursor::operator delete");
|
|
|
|
TRASH(ptr, size);
|
|
|
|
/*
|
|
|
|
If this cursor has never been opened mem_root is empty. Otherwise
|
|
|
|
mem_root points to the memory the cursor object was allocated in.
|
|
|
|
In this case it's important to call free_root last, and free a copy
|
|
|
|
instead of *mem_root to avoid writing into freed memory.
|
|
|
|
*/
|
|
|
|
free_root(&own_root, MYF(0));
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
Materialized_cursor
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
Materialized_cursor::Materialized_cursor(select_result *result_arg,
|
|
|
|
TABLE *table_arg)
|
|
|
|
:Server_side_cursor(&table_arg->mem_root, result_arg),
|
|
|
|
table(table_arg),
|
|
|
|
fetch_limit(0),
|
2008-12-10 15:13:11 +01:00
|
|
|
fetch_count(0),
|
|
|
|
is_rnd_inited(0)
|
2005-09-22 00:11:21 +02:00
|
|
|
{
|
|
|
|
fake_unit.init_query();
|
|
|
|
fake_unit.thd= table->in_use;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-20 20:45:24 +01:00
|
|
|
/**
|
|
|
|
Preserve the original metadata that would be sent to the client.
|
|
|
|
|
|
|
|
@param thd Thread identifier.
|
Backport of revno 2630.28.10, 2630.28.31, 2630.28.26, 2630.33.1,
2630.39.1, 2630.28.29, 2630.34.3, 2630.34.2, 2630.34.1, 2630.29.29,
2630.29.28, 2630.31.1, 2630.28.13, 2630.28.10, 2617.23.14 and
some other minor revisions.
This patch implements:
WL#4264 "Backup: Stabilize Service Interface" -- all the
server prerequisites except si_objects.{h,cc} themselves (they can
be just copied over, when needed).
WL#4435: Support OUT-parameters in prepared statements.
(and all issues in the initial patches for these two
tasks, that were discovered in pushbuild and during testing).
Bug#39519: mysql_stmt_close() should flush all data
associated with the statement.
After execution of a prepared statement, send OUT parameters of the invoked
stored procedure, if any, to the client.
When using the binary protocol, send the parameters in an additional result
set over the wire. When using the text protocol, assign out parameters to
the user variables from the CALL(@var1, @var2, ...) specification.
The following refactoring has been made:
- Protocol::send_fields() was renamed to Protocol::send_result_set_metadata();
- A new Protocol::send_result_set_row() was introduced to incapsulate
common functionality for sending row data.
- Signature of Protocol::prepare_for_send() was changed: this operation
does not need a list of items, the number of items is fully sufficient.
The following backward incompatible changes have been made:
- CLIENT_MULTI_RESULTS is now enabled by default in the client;
- CLIENT_PS_MULTI_RESUTLS is now enabled by default in the client.
2009-10-21 22:02:06 +02:00
|
|
|
@param send_result_set_metadata List of fields that would be sent.
|
2008-02-20 20:45:24 +01:00
|
|
|
*/
|
|
|
|
|
2010-07-27 14:42:36 +02:00
|
|
|
int Materialized_cursor::fill_item_list(THD *thd,
|
|
|
|
List<Item> &send_result_set_metadata)
|
2008-02-20 20:45:24 +01:00
|
|
|
{
|
|
|
|
Query_arena backup_arena;
|
|
|
|
int rc;
|
Backport of revno 2630.28.10, 2630.28.31, 2630.28.26, 2630.33.1,
2630.39.1, 2630.28.29, 2630.34.3, 2630.34.2, 2630.34.1, 2630.29.29,
2630.29.28, 2630.31.1, 2630.28.13, 2630.28.10, 2617.23.14 and
some other minor revisions.
This patch implements:
WL#4264 "Backup: Stabilize Service Interface" -- all the
server prerequisites except si_objects.{h,cc} themselves (they can
be just copied over, when needed).
WL#4435: Support OUT-parameters in prepared statements.
(and all issues in the initial patches for these two
tasks, that were discovered in pushbuild and during testing).
Bug#39519: mysql_stmt_close() should flush all data
associated with the statement.
After execution of a prepared statement, send OUT parameters of the invoked
stored procedure, if any, to the client.
When using the binary protocol, send the parameters in an additional result
set over the wire. When using the text protocol, assign out parameters to
the user variables from the CALL(@var1, @var2, ...) specification.
The following refactoring has been made:
- Protocol::send_fields() was renamed to Protocol::send_result_set_metadata();
- A new Protocol::send_result_set_row() was introduced to incapsulate
common functionality for sending row data.
- Signature of Protocol::prepare_for_send() was changed: this operation
does not need a list of items, the number of items is fully sufficient.
The following backward incompatible changes have been made:
- CLIENT_MULTI_RESULTS is now enabled by default in the client;
- CLIENT_PS_MULTI_RESUTLS is now enabled by default in the client.
2009-10-21 22:02:06 +02:00
|
|
|
List_iterator_fast<Item> it_org(send_result_set_metadata);
|
2008-02-20 20:45:24 +01:00
|
|
|
List_iterator_fast<Item> it_dst(item_list);
|
|
|
|
Item *item_org;
|
|
|
|
Item *item_dst;
|
|
|
|
|
|
|
|
thd->set_n_backup_active_arena(this, &backup_arena);
|
|
|
|
|
|
|
|
if ((rc= table->fill_item_list(&item_list)))
|
|
|
|
goto end;
|
|
|
|
|
Backport of revno 2630.28.10, 2630.28.31, 2630.28.26, 2630.33.1,
2630.39.1, 2630.28.29, 2630.34.3, 2630.34.2, 2630.34.1, 2630.29.29,
2630.29.28, 2630.31.1, 2630.28.13, 2630.28.10, 2617.23.14 and
some other minor revisions.
This patch implements:
WL#4264 "Backup: Stabilize Service Interface" -- all the
server prerequisites except si_objects.{h,cc} themselves (they can
be just copied over, when needed).
WL#4435: Support OUT-parameters in prepared statements.
(and all issues in the initial patches for these two
tasks, that were discovered in pushbuild and during testing).
Bug#39519: mysql_stmt_close() should flush all data
associated with the statement.
After execution of a prepared statement, send OUT parameters of the invoked
stored procedure, if any, to the client.
When using the binary protocol, send the parameters in an additional result
set over the wire. When using the text protocol, assign out parameters to
the user variables from the CALL(@var1, @var2, ...) specification.
The following refactoring has been made:
- Protocol::send_fields() was renamed to Protocol::send_result_set_metadata();
- A new Protocol::send_result_set_row() was introduced to incapsulate
common functionality for sending row data.
- Signature of Protocol::prepare_for_send() was changed: this operation
does not need a list of items, the number of items is fully sufficient.
The following backward incompatible changes have been made:
- CLIENT_MULTI_RESULTS is now enabled by default in the client;
- CLIENT_PS_MULTI_RESUTLS is now enabled by default in the client.
2009-10-21 22:02:06 +02:00
|
|
|
DBUG_ASSERT(send_result_set_metadata.elements == item_list.elements);
|
2008-02-20 20:45:24 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
Unless we preserve the original metadata, it will be lost,
|
|
|
|
since new fields describe columns of the temporary table.
|
|
|
|
Allocate a copy of the name for safety only. Currently
|
|
|
|
items with original names are always kept in memory,
|
|
|
|
but in case this changes a memory leak may be hard to notice.
|
|
|
|
*/
|
|
|
|
while ((item_dst= it_dst++, item_org= it_org++))
|
|
|
|
{
|
|
|
|
Send_field send_field;
|
|
|
|
Item_ident *ident= static_cast<Item_ident *>(item_dst);
|
|
|
|
item_org->make_field(&send_field);
|
|
|
|
|
|
|
|
ident->db_name= thd->strdup(send_field.db_name);
|
|
|
|
ident->table_name= thd->strdup(send_field.table_name);
|
|
|
|
}
|
|
|
|
end:
|
|
|
|
thd->restore_active_arena(this, &backup_arena);
|
|
|
|
/* Check for thd->is_error() in case of OOM */
|
2008-02-21 02:30:29 +01:00
|
|
|
return rc || thd->is_error();
|
2008-02-20 20:45:24 +01:00
|
|
|
}
|
|
|
|
|
2010-07-27 14:42:36 +02:00
|
|
|
|
2005-09-22 00:11:21 +02:00
|
|
|
int Materialized_cursor::open(JOIN *join __attribute__((unused)))
|
|
|
|
{
|
|
|
|
THD *thd= fake_unit.thd;
|
|
|
|
int rc;
|
|
|
|
Query_arena backup_arena;
|
|
|
|
thd->set_n_backup_active_arena(this, &backup_arena);
|
|
|
|
/* Create a list of fields and start sequential scan */
|
2008-12-10 15:13:11 +01:00
|
|
|
rc= result->prepare(item_list, &fake_unit);
|
|
|
|
if (!rc && !(rc= table->file->ha_rnd_init(TRUE)))
|
|
|
|
is_rnd_inited= 1;
|
|
|
|
|
2005-09-22 00:11:21 +02:00
|
|
|
thd->restore_active_arena(this, &backup_arena);
|
2005-11-09 18:31:01 +01:00
|
|
|
if (rc == 0)
|
|
|
|
{
|
|
|
|
/*
|
2005-11-10 15:05:19 +01:00
|
|
|
Now send the result set metadata to the client. We need to
|
Backport of revno 2630.28.10, 2630.28.31, 2630.28.26, 2630.33.1,
2630.39.1, 2630.28.29, 2630.34.3, 2630.34.2, 2630.34.1, 2630.29.29,
2630.29.28, 2630.31.1, 2630.28.13, 2630.28.10, 2617.23.14 and
some other minor revisions.
This patch implements:
WL#4264 "Backup: Stabilize Service Interface" -- all the
server prerequisites except si_objects.{h,cc} themselves (they can
be just copied over, when needed).
WL#4435: Support OUT-parameters in prepared statements.
(and all issues in the initial patches for these two
tasks, that were discovered in pushbuild and during testing).
Bug#39519: mysql_stmt_close() should flush all data
associated with the statement.
After execution of a prepared statement, send OUT parameters of the invoked
stored procedure, if any, to the client.
When using the binary protocol, send the parameters in an additional result
set over the wire. When using the text protocol, assign out parameters to
the user variables from the CALL(@var1, @var2, ...) specification.
The following refactoring has been made:
- Protocol::send_fields() was renamed to Protocol::send_result_set_metadata();
- A new Protocol::send_result_set_row() was introduced to incapsulate
common functionality for sending row data.
- Signature of Protocol::prepare_for_send() was changed: this operation
does not need a list of items, the number of items is fully sufficient.
The following backward incompatible changes have been made:
- CLIENT_MULTI_RESULTS is now enabled by default in the client;
- CLIENT_PS_MULTI_RESUTLS is now enabled by default in the client.
2009-10-21 22:02:06 +02:00
|
|
|
do it here, as in Select_materialize::send_result_set_metadata the items
|
|
|
|
for column types are not yet created (send_result_set_metadata requires
|
2005-11-10 15:05:19 +01:00
|
|
|
a list of items). The new types may differ from the original
|
|
|
|
ones sent at prepare if some of them were altered by MySQL
|
|
|
|
HEAP tables mechanism -- used when create_tmp_field_from_item
|
|
|
|
may alter the original column type.
|
2005-11-09 18:31:01 +01:00
|
|
|
|
Backport of revno 2630.28.10, 2630.28.31, 2630.28.26, 2630.33.1,
2630.39.1, 2630.28.29, 2630.34.3, 2630.34.2, 2630.34.1, 2630.29.29,
2630.29.28, 2630.31.1, 2630.28.13, 2630.28.10, 2617.23.14 and
some other minor revisions.
This patch implements:
WL#4264 "Backup: Stabilize Service Interface" -- all the
server prerequisites except si_objects.{h,cc} themselves (they can
be just copied over, when needed).
WL#4435: Support OUT-parameters in prepared statements.
(and all issues in the initial patches for these two
tasks, that were discovered in pushbuild and during testing).
Bug#39519: mysql_stmt_close() should flush all data
associated with the statement.
After execution of a prepared statement, send OUT parameters of the invoked
stored procedure, if any, to the client.
When using the binary protocol, send the parameters in an additional result
set over the wire. When using the text protocol, assign out parameters to
the user variables from the CALL(@var1, @var2, ...) specification.
The following refactoring has been made:
- Protocol::send_fields() was renamed to Protocol::send_result_set_metadata();
- A new Protocol::send_result_set_row() was introduced to incapsulate
common functionality for sending row data.
- Signature of Protocol::prepare_for_send() was changed: this operation
does not need a list of items, the number of items is fully sufficient.
The following backward incompatible changes have been made:
- CLIENT_MULTI_RESULTS is now enabled by default in the client;
- CLIENT_PS_MULTI_RESUTLS is now enabled by default in the client.
2009-10-21 22:02:06 +02:00
|
|
|
We can't simply supply SEND_EOF flag to send_result_set_metadata, because
|
|
|
|
send_result_set_metadata doesn't flush the network buffer.
|
2005-11-09 18:31:01 +01:00
|
|
|
*/
|
Backport of revno 2630.28.10, 2630.28.31, 2630.28.26, 2630.33.1,
2630.39.1, 2630.28.29, 2630.34.3, 2630.34.2, 2630.34.1, 2630.29.29,
2630.29.28, 2630.31.1, 2630.28.13, 2630.28.10, 2617.23.14 and
some other minor revisions.
This patch implements:
WL#4264 "Backup: Stabilize Service Interface" -- all the
server prerequisites except si_objects.{h,cc} themselves (they can
be just copied over, when needed).
WL#4435: Support OUT-parameters in prepared statements.
(and all issues in the initial patches for these two
tasks, that were discovered in pushbuild and during testing).
Bug#39519: mysql_stmt_close() should flush all data
associated with the statement.
After execution of a prepared statement, send OUT parameters of the invoked
stored procedure, if any, to the client.
When using the binary protocol, send the parameters in an additional result
set over the wire. When using the text protocol, assign out parameters to
the user variables from the CALL(@var1, @var2, ...) specification.
The following refactoring has been made:
- Protocol::send_fields() was renamed to Protocol::send_result_set_metadata();
- A new Protocol::send_result_set_row() was introduced to incapsulate
common functionality for sending row data.
- Signature of Protocol::prepare_for_send() was changed: this operation
does not need a list of items, the number of items is fully sufficient.
The following backward incompatible changes have been made:
- CLIENT_MULTI_RESULTS is now enabled by default in the client;
- CLIENT_PS_MULTI_RESUTLS is now enabled by default in the client.
2009-10-21 22:02:06 +02:00
|
|
|
rc= result->send_result_set_metadata(item_list, Protocol::SEND_NUM_ROWS);
|
2005-11-09 18:31:01 +01:00
|
|
|
thd->server_status|= SERVER_STATUS_CURSOR_EXISTS;
|
|
|
|
result->send_eof();
|
|
|
|
}
|
2005-09-22 00:11:21 +02:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-16 21:37:31 +02:00
|
|
|
/**
|
2005-09-22 00:11:21 +02:00
|
|
|
Fetch up to the given number of rows from a materialized cursor.
|
|
|
|
|
|
|
|
Precondition: the cursor is open.
|
|
|
|
|
|
|
|
If the cursor points after the last row, the fetch will automatically
|
|
|
|
close the cursor and not send any data (except the 'EOF' packet
|
|
|
|
with SERVER_STATUS_LAST_ROW_SENT). This is an extra round trip
|
|
|
|
and probably should be improved to return
|
|
|
|
SERVER_STATUS_LAST_ROW_SENT along with the last row.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void Materialized_cursor::fetch(ulong num_rows)
|
|
|
|
{
|
|
|
|
THD *thd= table->in_use;
|
|
|
|
|
|
|
|
int res= 0;
|
2006-02-24 17:34:15 +01:00
|
|
|
result->begin_dataset();
|
2005-09-22 00:11:21 +02:00
|
|
|
for (fetch_limit+= num_rows; fetch_count < fetch_limit; fetch_count++)
|
|
|
|
{
|
|
|
|
if ((res= table->file->rnd_next(table->record[0])))
|
|
|
|
break;
|
|
|
|
/* Send data only if the read was successful. */
|
2010-07-21 09:56:43 +02:00
|
|
|
/*
|
|
|
|
If network write failed (i.e. due to a closed socked),
|
|
|
|
the error has already been set. Just return.
|
|
|
|
*/
|
|
|
|
if (result->send_data(item_list))
|
|
|
|
return;
|
2005-09-22 00:11:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (res) {
|
|
|
|
case 0:
|
|
|
|
thd->server_status|= SERVER_STATUS_CURSOR_EXISTS;
|
|
|
|
result->send_eof();
|
|
|
|
break;
|
|
|
|
case HA_ERR_END_OF_FILE:
|
|
|
|
thd->server_status|= SERVER_STATUS_LAST_ROW_SENT;
|
|
|
|
result->send_eof();
|
|
|
|
close();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
table->file->print_error(res, MYF(0));
|
|
|
|
close();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Materialized_cursor::close()
|
|
|
|
{
|
|
|
|
/* Free item_list items */
|
|
|
|
free_items();
|
2008-12-10 15:13:11 +01:00
|
|
|
if (is_rnd_inited)
|
|
|
|
(void) table->file->ha_rnd_end();
|
2005-09-22 00:11:21 +02:00
|
|
|
/*
|
|
|
|
We need to grab table->mem_root to prevent free_tmp_table from freeing:
|
|
|
|
the cursor object was allocated in this memory.
|
|
|
|
*/
|
|
|
|
main_mem_root= table->mem_root;
|
|
|
|
mem_root= &main_mem_root;
|
|
|
|
clear_alloc_root(&table->mem_root);
|
|
|
|
free_tmp_table(table->in_use, table);
|
|
|
|
table= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Materialized_cursor::~Materialized_cursor()
|
|
|
|
{
|
|
|
|
if (is_open())
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
Select_materialize
|
|
|
|
****************************************************************************/
|
|
|
|
|
Backport of revno 2630.28.10, 2630.28.31, 2630.28.26, 2630.33.1,
2630.39.1, 2630.28.29, 2630.34.3, 2630.34.2, 2630.34.1, 2630.29.29,
2630.29.28, 2630.31.1, 2630.28.13, 2630.28.10, 2617.23.14 and
some other minor revisions.
This patch implements:
WL#4264 "Backup: Stabilize Service Interface" -- all the
server prerequisites except si_objects.{h,cc} themselves (they can
be just copied over, when needed).
WL#4435: Support OUT-parameters in prepared statements.
(and all issues in the initial patches for these two
tasks, that were discovered in pushbuild and during testing).
Bug#39519: mysql_stmt_close() should flush all data
associated with the statement.
After execution of a prepared statement, send OUT parameters of the invoked
stored procedure, if any, to the client.
When using the binary protocol, send the parameters in an additional result
set over the wire. When using the text protocol, assign out parameters to
the user variables from the CALL(@var1, @var2, ...) specification.
The following refactoring has been made:
- Protocol::send_fields() was renamed to Protocol::send_result_set_metadata();
- A new Protocol::send_result_set_row() was introduced to incapsulate
common functionality for sending row data.
- Signature of Protocol::prepare_for_send() was changed: this operation
does not need a list of items, the number of items is fully sufficient.
The following backward incompatible changes have been made:
- CLIENT_MULTI_RESULTS is now enabled by default in the client;
- CLIENT_PS_MULTI_RESUTLS is now enabled by default in the client.
2009-10-21 22:02:06 +02:00
|
|
|
bool Select_materialize::send_result_set_metadata(List<Item> &list, uint flags)
|
2005-09-22 00:11:21 +02:00
|
|
|
{
|
|
|
|
DBUG_ASSERT(table == 0);
|
|
|
|
if (create_result_table(unit->thd, unit->get_unit_column_types(),
|
2009-12-22 10:35:56 +01:00
|
|
|
FALSE, thd->variables.option_bits | TMP_TABLE_ALL_COLUMNS, ""))
|
2005-09-22 00:11:21 +02:00
|
|
|
return TRUE;
|
2008-02-20 20:45:24 +01:00
|
|
|
|
|
|
|
materialized_cursor= new (&table->mem_root)
|
|
|
|
Materialized_cursor(result, table);
|
|
|
|
|
|
|
|
if (! materialized_cursor)
|
|
|
|
{
|
|
|
|
free_tmp_table(table->in_use, table);
|
|
|
|
table= 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
if (materialized_cursor->fill_item_list(unit->thd, list))
|
|
|
|
{
|
|
|
|
delete materialized_cursor;
|
|
|
|
table= 0;
|
|
|
|
materialized_cursor= 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-11-19 17:00:02 +01:00
|
|
|
return FALSE;
|
2005-09-22 00:11:21 +02:00
|
|
|
}
|
|
|
|
|