MySQL 8.0.39
Source Code Documentation
ha_tina.h
Go to the documentation of this file.
1/* Copyright (c) 2003, 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#include <sys/stat.h>
25#include <sys/types.h>
26
27#include "my_dir.h"
28#include "my_inttypes.h"
29#include "my_io.h"
30#include "sql/handler.h"
31#include "sql_string.h"
33
34#define DEFAULT_CHAIN_LENGTH 512
35/*
36 Version for file format.
37 1 - Initial Version. That is, the version when the metafile was introduced.
38*/
39
40#define TINA_VERSION 1
41
42struct TINA_SHARE {
46 /*
47 Below flag is needed to make log tables work with concurrent insert.
48 For more details see comment to ha_tina::update_status.
49 */
51 /*
52 Here we save the length of the file for readers. This is updated by
53 inserts, updates and deletes. The var is initialized along with the
54 share initialization.
55 */
61 File meta_file; /* Meta file we use */
62 File tina_write_filedes; /* File handler for readers */
63 bool crashed; /* Meta file is crashed */
64 ha_rows rows_recorded; /* Number of rows in tables */
65 uint data_file_version; /* Version of the data file used */
66};
67
68struct tina_set {
71};
72
73class ha_tina : public handler {
74 THR_LOCK_DATA lock; /* MySQL lock */
75 TINA_SHARE *share; /* Shared lock info */
77 current_position; /* Current position in the file during a file scan */
78 my_off_t next_position; /* Next position in the file scan */
79 my_off_t local_saved_data_file_length; /* save position for reads */
83 File data_file; /* File handler for readers */
86 /*
87 The chain contains "holes" in the file, occurred because of
88 deletes/updates. It is used in rnd_end() to get rid of them
89 in the end of the query.
90 */
96 uint local_data_file_version; /* Saved version of the data file used */
99
100 private:
101 bool get_write_pos(my_off_t *end_pos, tina_set *closest_hole);
103 int init_tina_writer();
104 int init_data_file();
105
106 public:
107 ha_tina(handlerton *hton, TABLE_SHARE *table_arg);
108 ~ha_tina() override {
110 if (file_buff) delete file_buff;
111 blobroot.Clear();
112 }
113 const char *table_type() const override { return "CSV"; }
114 ulonglong table_flags() const override {
117 }
118 ulong index_flags(uint, uint, bool) const override {
119 /*
120 We will never have indexes so this will never be called(AKA we return
121 zero)
122 */
123 return 0;
124 }
126 uint max_keys() const { return 0; }
127 uint max_key_parts() const { return 0; }
128 uint max_key_length() const { return 0; }
129 /*
130 Called in test_quick_select to determine if indexes should be used.
131 */
132 double scan_time() override {
133 return (double)(stats.records + stats.deleted) / 20.0 + 10;
134 }
135 /* The next method will never be called */
136 virtual bool fast_key_read() { return true; }
137 /*
138 TODO: return actual upper bound of number of records in the table.
139 (e.g. save number of records seen on full table scan and/or use file size
140 as upper bound)
141 */
143
144 int open(const char *name, int mode, uint open_options,
145 const dd::Table *table_def) override;
146 int close(void) override;
147 int write_row(uchar *buf) override;
148 int update_row(const uchar *old_data, uchar *new_data) override;
149 int delete_row(const uchar *buf) override;
150 int rnd_init(bool scan = true) override;
151 int rnd_next(uchar *buf) override;
152 int rnd_pos(uchar *buf, uchar *pos) override;
153 bool check_and_repair(THD *thd) override;
154 int check(THD *thd, HA_CHECK_OPT *check_opt) override;
155 bool is_crashed() const override;
156 int rnd_end() override;
157 int repair(THD *thd, HA_CHECK_OPT *check_opt) override;
158 /* This is required for SQL layer to know that we support autorepair */
159 bool auto_repair() const override { return true; }
160 void position(const uchar *record) override;
161 int info(uint) override;
162 int extra(enum ha_extra_function operation) override;
163 int delete_all_rows(void) override;
164 int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info,
165 dd::Table *table_def) override;
167 uint table_changes) override;
168
170 enum thr_lock_type lock_type) override;
171
172 /*
173 These functions used to get/update status of the handler.
174 Needed to enable concurrent inserts.
175 */
176 void get_status();
177 void update_status();
178
179 /* The following methods were added just for TINA */
180 int encode_quote(uchar *buf);
182 int chain_append();
183};
app_data_ptr new_data(u_int n, char *val, cons_type consensus)
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:168
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:34
Definition: transparent_file.h:35
Definition: table.h:47
Definition: ha_tina.h:73
int delete_row(const uchar *buf) override
Definition: ha_tina.cc:1036
ha_tina(handlerton *hton, TABLE_SHARE *table_arg)
Definition: ha_tina.cc:510
int repair(THD *thd, HA_CHECK_OPT *check_opt) override
In this method check_opt can be modified to specify CHECK option to use to call check() upon the tabl...
Definition: ha_tina.cc:1378
bool get_write_pos(my_off_t *end_pos, tina_set *closest_hole)
Definition: ha_tina.cc:1224
int write_row(uchar *buf) override
Write a row.
Definition: ha_tina.cc:935
int chain_append()
Definition: ha_tina.cc:604
tina_set * chain_ptr
Definition: ha_tina.h:93
bool check_if_incompatible_data(HA_CREATE_INFO *info, uint table_changes) override
Part of old, deprecated in-place ALTER API.
Definition: ha_tina.cc:1624
my_off_t local_saved_data_file_length
Definition: ha_tina.h:79
bool is_crashed() const override
Check if the table is crashed.
Definition: ha_tina.cc:406
int init_tina_writer()
Definition: ha_tina.cc:384
int open_update_temp_file_if_needed()
Definition: ha_tina.cc:968
int rnd_pos(uchar *buf, uchar *pos) override
Definition: ha_tina.cc:1183
uchar byte_buffer[IO_SIZE]
Definition: ha_tina.h:81
THR_LOCK_DATA lock
Definition: ha_tina.h:74
const char * table_type() const override
The following can be called without an open handler.
Definition: ha_tina.h:113
MEM_ROOT blobroot
Definition: ha_tina.h:98
int close(void) override
Definition: ha_tina.cc:923
bool records_is_known
Definition: ha_tina.h:97
int info(uint) override
General method to gather info from handler.
Definition: ha_tina.cc:1197
int rnd_init(bool scan=true) override
rnd_init() can be called two times without rnd_end() in between (it only makes sense if scan=1).
Definition: ha_tina.cc:1109
int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info, dd::Table *table_def) override
Create table (implementation).
Definition: ha_tina.cc:1542
int encode_quote(uchar *buf)
Definition: ha_tina.cc:535
my_off_t next_position
Definition: ha_tina.h:78
int find_current_row(uchar *buf)
Definition: ha_tina.cc:639
double scan_time() override
Definition: ha_tina.h:132
TINA_SHARE * share
Definition: ha_tina.h:75
bool auto_repair() const override
Check if the table can be automatically repaired.
Definition: ha_tina.h:159
String buffer
Definition: ha_tina.h:85
void get_status()
Definition: ha_tina.cc:842
tina_set * chain
Definition: ha_tina.h:92
int rnd_next(uchar *buf) override
Definition: ha_tina.cc:1137
int rnd_end() override
Definition: ha_tina.cc:1238
int delete_all_rows(void) override
Delete all rows in a table.
Definition: ha_tina.cc:1502
int open(const char *name, int mode, uint open_options, const dd::Table *table_def) override
Definition: ha_tina.cc:887
int update_row(const uchar *old_data, uchar *new_data) override
Update a single row.
Definition: ha_tina.cc:992
my_off_t current_position
Definition: ha_tina.h:77
File update_temp_file
Definition: ha_tina.h:84
virtual bool fast_key_read()
Definition: ha_tina.h:136
~ha_tina() override
Definition: ha_tina.h:108
uint max_key_length() const
Definition: ha_tina.h:128
tina_set chain_buffer[DEFAULT_CHAIN_LENGTH]
Definition: ha_tina.h:91
uint max_keys() const
Definition: ha_tina.h:126
int check(THD *thd, HA_CHECK_OPT *check_opt) override
Definition: ha_tina.cc:1580
Transparent_file * file_buff
Definition: ha_tina.h:82
ha_rows estimate_rows_upper_bound() override
Return upper bound of current number of records in the table (max.
Definition: ha_tina.h:142
uint32 chain_size
Definition: ha_tina.h:95
ulong index_flags(uint, uint, bool) const override
Definition: ha_tina.h:118
uint max_key_parts() const
Definition: ha_tina.h:127
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_tina.cc:1530
File data_file
Definition: ha_tina.h:83
int init_data_file()
Initialize the data file.
Definition: ha_tina.cc:1068
void position(const uchar *record) override
Definition: ha_tina.cc:1173
uint max_record_length() const
Definition: ha_tina.h:125
uint local_data_file_version
Definition: ha_tina.h:96
my_off_t temp_file_length
Definition: ha_tina.h:80
ulonglong table_flags() const override
Definition: ha_tina.h:114
void update_status()
Definition: ha_tina.cc:877
int extra(enum ha_extra_function operation) override
Storage engine specific implementation of ha_extra()
Definition: ha_tina.cc:1209
uchar chain_alloced
Definition: ha_tina.h:94
bool check_and_repair(THD *thd) override
Check and repair the table if necessary.
Definition: ha_tina.cc:377
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:4414
A table definition from the master.
Definition: rpl_utility.h:248
#define DEFAULT_CHAIN_LENGTH
Definition: ha_tina.h:34
my_off_t ha_rows
Definition: my_base.h:1140
ha_extra_function
Definition: my_base.h:184
#define HA_POS_ERROR
Definition: my_base.h:1142
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:56
ulonglong my_off_t
Definition: my_inttypes.h:72
unsigned char uchar
Definition: my_inttypes.h:52
uint32_t uint32
Definition: my_inttypes.h:67
Common #defines and includes for file and socket I/O.
#define FN_REFLEN
Definition: my_io.h:83
constexpr const size_t IO_SIZE
Definition: my_io.h:159
int File
Definition: my_io_bits.h:51
void my_free(void *ptr)
Frees the memory pointed by the ptr.
Definition: my_memory.cc:81
static int record
Definition: mysqltest.cc:188
Definition: buf0block_hint.cc:30
mode
Definition: file_handle.h:60
#define HA_BINLOG_ROW_CAPABLE
Definition: handler.h:339
#define HA_MAX_REC_LENGTH
Definition: handler.h:617
#define HA_CAN_REPAIR
Definition: handler.h:369
#define HA_BINLOG_STMT_CAPABLE
Definition: handler.h:340
#define HA_NO_TRANSACTIONS
Definition: handler.h:210
#define HA_NO_AUTO_INCREMENT
Definition: handler.h:314
Our own string classes, used pervasively throughout the executor.
case opt name
Definition: sslopt-case.h:33
Definition: handler.h:3632
Struct to hold information about the table that should be created.
Definition: handler.h:3045
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:171
This structure is shared between different table objects.
Definition: table.h:690
Definition: table.h:1399
Definition: thr_lock.h:124
Definition: thr_lock.h:139
Definition: ha_tina.h:42
bool crashed
Definition: ha_tina.h:63
bool is_log_table
Definition: ha_tina.h:50
File meta_file
Definition: ha_tina.h:61
mysql_mutex_t mutex
Definition: ha_tina.h:57
File tina_write_filedes
Definition: ha_tina.h:62
THR_LOCK lock
Definition: ha_tina.h:58
char * table_name
Definition: ha_tina.h:43
bool tina_write_opened
Definition: ha_tina.h:60
uint table_name_length
Definition: ha_tina.h:45
char data_file_name[FN_REFLEN]
Definition: ha_tina.h:44
bool update_file_opened
Definition: ha_tina.h:59
my_off_t saved_data_file_length
Definition: ha_tina.h:56
uint use_count
Definition: ha_tina.h:45
uint data_file_version
Definition: ha_tina.h:65
ha_rows rows_recorded
Definition: ha_tina.h:64
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2622
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:50
Definition: mysqlslap.cc:238
Definition: ha_tina.h:68
my_off_t begin
Definition: ha_tina.h:69
my_off_t end
Definition: ha_tina.h:70
thr_lock_type
Definition: thr_lock.h:51
unsigned int uint
Definition: uca9-dump.cc:75