MySQL 8.4.3
Source Code Documentation
sql_cursor.h
Go to the documentation of this file.
1/* Copyright (c) 2005, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef _sql_cursor_h_
25#define _sql_cursor_h_
26
27#include <stddef.h>
28#include <sys/types.h>
29#include <new>
30
31#include "sql/sql_class.h" /* Query_arena */
32
33class Query_result;
34struct MEM_ROOT;
35
36/**
37 @file
38
39 Declarations for implementation of server side cursors. Only
40 read-only non-scrollable cursors are currently implemented.
41*/
42
43/**
44 Server_side_cursor -- an interface for materialized
45 implementation of cursors. All cursors are self-contained
46 (created in their own memory root). For that reason they must
47 be deleted only using a pointer to Server_side_cursor, not to
48 its base class.
49*/
50
52 public:
53 /**
54 For allocation of Handler objects for the temporary table. The prepared
55 statement's mem_root cannot be used, since the handler may be created and
56 deleted several times. The execution mem_root cannot be used since
57 creation of and retrieval from a cursor are in different executions.
58 */
60
61 protected:
63 /** Row destination used for fetch */
65
66 public:
68 : m_arena(&mem_root, Query_arena::STMT_INITIALIZED),
69 m_result(result_arg) {}
70 virtual bool is_open() const = 0;
71
72 virtual bool open(THD *thd) = 0;
73 virtual bool fetch(ulong num_rows) = 0;
74 virtual void close() = 0;
76 static void *operator new(size_t size, MEM_ROOT *mem_root,
77 const std::nothrow_t & = std::nothrow) noexcept {
78 return mem_root->Alloc(size);
79 }
80 static void operator delete(void *, size_t) {}
81 static void operator delete(
82 void *, MEM_ROOT *, const std::nothrow_t &) noexcept { /* never called */
83 }
84};
85
87
89 Server_side_cursor **res);
90
91#endif /* _sql_cursor_h_ */
Definition: sql_class.h:348
Definition: query_result.h:58
Server_side_cursor – an interface for materialized implementation of cursors.
Definition: sql_cursor.h:51
Query_arena m_arena
Definition: sql_cursor.h:62
virtual bool fetch(ulong num_rows)=0
virtual void close()=0
Query_result * m_result
Row destination used for fetch.
Definition: sql_cursor.h:64
MEM_ROOT mem_root
For allocation of Handler objects for the temporary table.
Definition: sql_cursor.h:59
virtual bool is_open() const =0
virtual ~Server_side_cursor()
Definition: sql_cursor.h:75
virtual bool open(THD *thd)=0
Server_side_cursor(Query_result *result_arg)
Definition: sql_cursor.h:67
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
static MEM_ROOT mem_root
Definition: client_plugin.cc:114
size_t size(const char *const c)
Definition: base64.h:46
PSI_memory_key key_memory_TABLE
Definition: psi_memory_key.cc:86
bool mysql_open_cursor(THD *thd, Query_result *result, Server_side_cursor **res)
Attempt to open a materialized cursor.
Definition: sql_cursor.cc:186
Query_result * new_cursor_result(MEM_ROOT *mem_root, Query_result *result)
Definition: sql_cursor.cc:142
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83
void Clear()
Deallocate all the RAM used.
Definition: my_alloc.cc:172
void * Alloc(size_t length)
Allocate memory.
Definition: my_alloc.h:145
Definition: result.h:30