mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 12:02:42 +01:00
f429b5a834
Implementing cursor%ROWTYPE variables, according to the task description. This patch includes a refactoring in how sp_instr_cpush and sp_instr_copen work. This is needed to implement MDEV-10598 later easier, to allow variable declarations go after cursor declarations (which is currently not allowed). Before this patch, sp_instr_cpush worked as a Query_arena associated with the cursor. sp_instr_copen::execute() switched to the sp_instr_cpush's Query_arena when executing the cursor SELECT statement. Now the Query_arena associated with the cursor is stored inside an instance of a new class sp_lex_cursor (a LEX descendand) that contains the cursor SELECT statement. This simplifies the implementation, because: - It's easier to follow the code when everything related to execution of the cursor SELECT statement is stored inside the same sp_lex_cursor object (rather than distributed between LEX and sp_instr_cpush). - It's easier to link an sp_instr_cursor_copy_struct to sp_lex_cursor rather than to sp_instr_cpush. - Also, it allows to perform sp_instr_cursor_copy_struct::exec_core() without having a pointer to sp_instr_cpush, using a pointer to sp_lex_cursor instead. This will be important for MDEV-10598, because sp_instr_cpush will happen *after* sp_instr_cursor_copy_struct. After MDEV-10598 is done, this declaration: DECLARE CURSOR cur IS SELECT * FROM t1; rec cur%ROWTYPE; BEGIN OPEN cur; FETCH cur INTO rec; CLOSE cur; END; will generate about this code: +-----+--------------------------+ | Pos | Instruction | +-----+--------------------------+ | 0 | cursor_copy_struct rec@0 | Points to sp_cursor_lex through m_lex_keeper | 1 | set rec@0 NULL | | 2 | cpush cur@0 | Points to sp_cursor_lex through m_lex_keeper | 3 | copen cur@0 | Points to sp_cursor_lex through m_cursor | 4 | cfetch cur@0 rec@0 | | 5 | cclose cur@0 | | 6 | cpop 1 | +-----+--------------------------+ Notice, "cursor_copy_struct" and "set" will go before "cpush". Instructions at positions 0, 2, 3 point to the same sp_cursor_lex instance.
71 lines
2.1 KiB
C++
71 lines
2.1 KiB
C++
/* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
|
|
|
|
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
|
|
the Free Software Foundation; version 2 of the License.
|
|
|
|
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
|
|
|
#ifndef _sql_cursor_h_
|
|
#define _sql_cursor_h_
|
|
|
|
#ifdef USE_PRAGMA_INTERFACE
|
|
#pragma interface /* gcc class interface */
|
|
#endif
|
|
|
|
#include "sql_class.h" /* Query_arena */
|
|
|
|
class JOIN;
|
|
|
|
/**
|
|
@file
|
|
|
|
Declarations for implementation of server side cursors. Only
|
|
read-only non-scrollable cursors are currently implemented.
|
|
*/
|
|
|
|
/**
|
|
Server_side_cursor -- an interface for materialized
|
|
implementation of cursors. All cursors are self-contained
|
|
(created in their own memory root). For that reason they must
|
|
be deleted only using a pointer to Server_side_cursor, not to
|
|
its base class.
|
|
*/
|
|
|
|
class Server_side_cursor: protected Query_arena, public Sql_alloc
|
|
{
|
|
protected:
|
|
/** Row destination used for fetch */
|
|
select_result *result;
|
|
public:
|
|
Server_side_cursor(MEM_ROOT *mem_root_arg, select_result *result_arg)
|
|
:Query_arena(mem_root_arg, STMT_INITIALIZED), result(result_arg)
|
|
{}
|
|
|
|
virtual bool is_open() const= 0;
|
|
|
|
virtual int open(JOIN *top_level_join)= 0;
|
|
virtual void fetch(ulong num_rows)= 0;
|
|
virtual void close()= 0;
|
|
virtual bool export_structure(THD *thd, Row_definition_list *defs)
|
|
{
|
|
DBUG_ASSERT(0);
|
|
return true;
|
|
}
|
|
virtual ~Server_side_cursor();
|
|
|
|
static void operator delete(void *ptr, size_t size);
|
|
};
|
|
|
|
|
|
int mysql_open_cursor(THD *thd, select_result *result,
|
|
Server_side_cursor **res);
|
|
|
|
#endif /* _sql_cusor_h_ */
|