MySQL 8.0.40
Source Code Documentation
ha_heap.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2000, 2024, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License, version 2.0, for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
24
25/* class for the the heap handler */
26
27#include <sys/types.h>
28
29#include "heap.h"
30#include "my_inttypes.h"
31#include "sql/handler.h"
32#include "sql/table.h"
33
34class ha_heap : public handler {
35 HP_INFO *file{nullptr};
37 /* number of records changed since last statistics update */
40 /// True if only one ha_heap is to exist for the table.
41 bool single_instance{false};
42
43 public:
45 ~ha_heap() override = default;
46 handler *clone(const char *name, MEM_ROOT *mem_root) override;
47 const char *table_type() const override;
49 return HA_KEY_ALG_HASH;
50 }
51 bool is_index_algorithm_supported(enum ha_key_alg key_alg) const override {
52 return key_alg == HA_KEY_ALG_BTREE || key_alg == HA_KEY_ALG_HASH;
53 }
54 /* Rows also use a fixed-size format */
55 enum row_type get_real_row_type(const HA_CREATE_INFO *) const override {
56 return ROW_TYPE_FIXED;
57 }
58 ulonglong table_flags() const override {
63 }
64 ulong index_flags(uint inx, uint, bool) const override {
65 return ((table_share->key_info[inx].algorithm == HA_KEY_ALG_BTREE)
68 }
69 uint max_supported_keys() const override { return MAX_KEY; }
71 [[maybe_unused]]) const override {
72 return MAX_KEY_LENGTH;
73 }
74 double scan_time() override {
75 return (double)(stats.records + stats.deleted) / 20.0 + 10;
76 }
77 double read_time(uint, uint, ha_rows rows) override {
78 return (double)rows / 20.0 + 1;
79 }
80
81 int open(const char *name, int mode, uint test_if_locked,
82 const dd::Table *table_def) override;
83 int close(void) override;
85 int write_row(uchar *buf) override;
86 int update_row(const uchar *old_data, uchar *new_data) override;
87 int delete_row(const uchar *buf) override;
88 void get_auto_increment(ulonglong offset, ulonglong increment,
89 ulonglong nb_desired_values, ulonglong *first_value,
90 ulonglong *nb_reserved_values) override;
91 int index_read_map(uchar *buf, const uchar *key, key_part_map keypart_map,
92 enum ha_rkey_function find_flag) override;
94 key_part_map keypart_map) override;
95 int index_read_idx_map(uchar *buf, uint index, const uchar *key,
96 key_part_map keypart_map,
97 enum ha_rkey_function find_flag) override;
98 int index_next(uchar *buf) override;
99 int index_prev(uchar *buf) override;
100 int index_first(uchar *buf) override;
101 int index_last(uchar *buf) override;
102 int rnd_init(bool scan) override;
103 int rnd_next(uchar *buf) override;
104 int rnd_pos(uchar *buf, uchar *pos) override;
105 void position(const uchar *record) override;
106 int info(uint) override;
107 int extra(enum ha_extra_function operation) override;
108 int reset() override;
109 int external_lock(THD *thd, int lock_type) override;
110 int delete_all_rows(void) override;
111 int disable_indexes(uint mode) override;
112 int enable_indexes(uint mode) override;
113 int indexes_are_disabled(void) override;
115 key_range *max_key) override;
116 int delete_table(const char *from, const dd::Table *table_def) override;
117 void drop_table(const char *name) override;
118 int rename_table(const char *from, const char *to,
119 const dd::Table *from_table_def,
120 dd::Table *to_table_def) override;
121 int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info,
122 dd::Table *table_def) override;
123 void update_create_info(HA_CREATE_INFO *create_info) override;
124
126 enum thr_lock_type lock_type) override;
127 int cmp_ref(const uchar *ref1, const uchar *ref2) const override {
128 return memcmp(ref1, ref2, sizeof(HEAP_PTR));
129 }
131 uint table_changes) override;
132
133 private:
134 void update_key_stats();
135};
app_data_ptr new_data(u_int n, char *val, cons_type consensus)
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:34
Definition: table.h:47
Definition: ha_heap.h:34
int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info, dd::Table *table_def) override
Create table (implementation).
Definition: ha_heap.cc:633
int index_first(uchar *buf) override
Definition: ha_heap.cc:295
int rnd_pos(uchar *buf, uchar *pos) override
Definition: ha_heap.cc:318
int disable_indexes(uint mode) override
Disable indexes for a while.
Definition: ha_heap.cc:403
int index_read_idx_map(uchar *buf, uint index, const uchar *key, key_part_map keypart_map, enum ha_rkey_function find_flag) override
Positions an index cursor to the index specified in argument.
Definition: ha_heap.cc:273
void drop_table(const char *name) override
Definition: ha_heap.cc:497
bool is_index_algorithm_supported(enum ha_key_alg key_alg) const override
Check if SE supports specific key algorithm.
Definition: ha_heap.h:51
int external_lock(THD *thd, int lock_type) override
Is not invoked for non-transactional temporary tables.
Definition: ha_heap.cc:375
int rnd_next(uchar *buf) override
Definition: ha_heap.cc:311
int index_next(uchar *buf) override
Definition: ha_heap.cc:281
bool single_instance
True if only one ha_heap is to exist for the table.
Definition: ha_heap.h:41
int close(void) override
Definition: ha_heap.cc:148
enum ha_key_alg get_default_index_algorithm() const override
Get default key algorithm for SE.
Definition: ha_heap.h:48
bool check_if_incompatible_data(HA_CREATE_INFO *info, uint table_changes) override
Part of old, deprecated in-place ALTER API.
Definition: ha_heap.cc:668
int write_row(uchar *buf) override
Write a row.
Definition: ha_heap.cc:205
THR_LOCK_DATA ** store_lock(THD *thd, THR_LOCK_DATA **to, enum thr_lock_type lock_type) override
Is not invoked for non-transactional temporary tables.
Definition: ha_heap.cc:473
int index_last(uchar *buf) override
Definition: ha_heap.cc:302
int enable_indexes(uint mode) override
Enable indexes again.
Definition: ha_heap.cc:444
int open(const char *name, int mode, uint test_if_locked, const dd::Table *table_def) override
Definition: ha_heap.cc:97
void set_keys_for_scanning(void)
int delete_row(const uchar *buf) override
Definition: ha_heap.cc:239
handler * clone(const char *name, MEM_ROOT *mem_root) override
Definition: ha_heap.cc:164
int cmp_ref(const uchar *ref1, const uchar *ref2) const override
Compare two positions.
Definition: ha_heap.h:127
~ha_heap() override=default
double read_time(uint, uint, ha_rows rows) override
The cost of reading a set of ranges from the table using an index to access it.
Definition: ha_heap.h:77
int extra(enum ha_extra_function operation) override
Storage engine specific implementation of ha_extra()
Definition: ha_heap.cc:357
enum row_type get_real_row_type(const HA_CREATE_INFO *) const override
Get real row type for the table created based on one specified by user, CREATE TABLE options and SE c...
Definition: ha_heap.h:55
void position(const uchar *record) override
Definition: ha_heap.cc:327
ulong index_flags(uint inx, uint, bool) const override
Definition: ha_heap.h:64
HP_SHARE * internal_share
Definition: ha_heap.h:36
int update_row(const uchar *old_data, uchar *new_data) override
Update a single row.
Definition: ha_heap.cc:224
const char * table_type() const override
The following can be called without an open handler.
Definition: ha_heap.cc:173
ha_heap(handlerton *hton, TABLE_SHARE *table)
Definition: ha_heap.cc:79
double scan_time() override
Definition: ha_heap.h:74
int info(uint) override
General method to gather info from handler.
Definition: ha_heap.cc:332
int delete_table(const char *from, const dd::Table *table_def) override
Delete a table.
Definition: ha_heap.cc:492
int index_read_last_map(uchar *buf, const uchar *key, key_part_map keypart_map) override
The following functions works like index_read, but it find the last row with the current key value or...
Definition: ha_heap.cc:264
int reset() override
Reset state of file to after 'open'.
Definition: ha_heap.cc:361
uint key_stat_version
Definition: ha_heap.h:39
void update_key_stats()
Update index statistics for the table.
Definition: ha_heap.cc:179
void get_auto_increment(ulonglong offset, ulonglong increment, ulonglong nb_desired_values, ulonglong *first_value, ulonglong *nb_reserved_values) override
Reserves an interval of auto_increment values from the handler.
Definition: ha_heap.cc:659
uint max_supported_key_part_length(HA_CREATE_INFO *create_info) const override
Definition: ha_heap.h:70
int rename_table(const char *from, const char *to, const dd::Table *from_table_def, dd::Table *to_table_def) override
Default rename_table() and delete_table() rename/delete files with a given name and extensions from h...
Definition: ha_heap.cc:502
int rnd_init(bool scan) override
rnd_init() can be called two times without rnd_end() in between (it only makes sense if scan=1).
Definition: ha_heap.cc:309
int index_read_map(uchar *buf, const uchar *key, key_part_map keypart_map, enum ha_rkey_function find_flag) override
Positions an index cursor to the index specified in the handle ('active_index').
Definition: ha_heap.cc:254
ulonglong table_flags() const override
Definition: ha_heap.h:58
ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key) override
Find number of records in a range.
Definition: ha_heap.cc:507
uint max_supported_keys() const override
Definition: ha_heap.h:69
int delete_all_rows(void) override
Delete all rows in a table.
Definition: ha_heap.cc:363
int index_prev(uchar *buf) override
Definition: ha_heap.cc:288
int indexes_are_disabled(void) override
Check if indexes are disabled.
Definition: ha_heap.cc:469
uint records_changed
Definition: ha_heap.h:38
void update_create_info(HA_CREATE_INFO *create_info) override
Update create info as part of ALTER TABLE.
Definition: ha_heap.cc:653
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:4412
TABLE_SHARE * table_share
Definition: handler.h:4419
TABLE * table
Definition: handler.h:4420
A table definition from the master.
Definition: rpl_utility.h:248
static MEM_ROOT mem_root
Definition: client_plugin.cc:110
uchar * HEAP_PTR
Definition: heap.h:187
ha_key_alg
Definition: my_base.h:97
@ HA_KEY_ALG_HASH
Definition: my_base.h:109
@ HA_KEY_ALG_BTREE
Definition: my_base.h:107
ha_rkey_function
Definition: my_base.h:78
ulong key_part_map
Definition: my_base.h:1007
my_off_t ha_rows
Definition: my_base.h:1140
ha_extra_function
Definition: my_base.h:184
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:56
unsigned char uchar
Definition: my_inttypes.h:52
static int record
Definition: mysqltest.cc:188
Definition: buf0block_hint.cc:30
Definition: os0file.h:86
mode
Definition: file_handle.h:60
required string key
Definition: replication_asynchronous_connection_failover.proto:60
#define HA_COUNT_ROWS_INSTANT
Definition: handler.h:332
#define HA_BINLOG_ROW_CAPABLE
Definition: handler.h:339
#define HA_READ_NEXT
Definition: handler.h:526
#define HA_NO_BLOBS
Definition: handler.h:252
#define HA_KEY_SCAN_NOT_ROR
Definition: handler.h:576
row_type
Definition: handler.h:676
@ ROW_TYPE_FIXED
Definition: handler.h:679
#define HA_BINLOG_STMT_CAPABLE
Definition: handler.h:340
#define HA_READ_ORDER
Definition: handler.h:542
#define HA_FAST_KEY_READ
Definition: handler.h:234
#define HA_READ_RANGE
Definition: handler.h:549
#define HA_NO_TRANSACTIONS
Definition: handler.h:210
#define HA_STATS_RECORDS_IS_EXACT
Definition: handler.h:272
#define HA_NULL_IN_KEY
Definition: handler.h:245
#define HA_ONLY_WHOLE_INDEX
Definition: handler.h:554
#define HA_READ_PREV
Definition: handler.h:530
constexpr const unsigned int MAX_KEY
Definition: sql_const.h:45
constexpr const unsigned int MAX_KEY_LENGTH
Definition: sql_const.h:47
case opt name
Definition: sslopt-case.h:33
Struct to hold information about the table that should be created.
Definition: handler.h:3045
Definition: heap.h:168
Definition: heap.h:141
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83
This structure is shared between different table objects.
Definition: table.h:690
KEY * key_info
Definition: table.h:746
Definition: table.h:1399
Definition: thr_lock.h:124
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2622
Definition: my_base.h:1124
Definition: mysqlslap.cc:238
thr_lock_type
Definition: thr_lock.h:51
unsigned int uint
Definition: uca9-dump.cc:75