MySQL 8.0.33
Source Code Documentation
ha_tina.h
Go to the documentation of this file.
1/* Copyright (c) 2003, 2023, 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 also distributed 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 included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#include <sys/stat.h>
24#include <sys/types.h>
25
26#include "my_dir.h"
27#include "my_inttypes.h"
28#include "my_io.h"
29#include "sql/handler.h"
30#include "sql_string.h"
32
33#define DEFAULT_CHAIN_LENGTH 512
34/*
35 Version for file format.
36 1 - Initial Version. That is, the version when the metafile was introduced.
37*/
38
39#define TINA_VERSION 1
40
41struct TINA_SHARE {
45 /*
46 Below flag is needed to make log tables work with concurrent insert.
47 For more details see comment to ha_tina::update_status.
48 */
50 /*
51 Here we save the length of the file for readers. This is updated by
52 inserts, updates and deletes. The var is initialized along with the
53 share initialization.
54 */
60 File meta_file; /* Meta file we use */
61 File tina_write_filedes; /* File handler for readers */
62 bool crashed; /* Meta file is crashed */
63 ha_rows rows_recorded; /* Number of rows in tables */
64 uint data_file_version; /* Version of the data file used */
65};
66
67struct tina_set {
70};
71
72class ha_tina : public handler {
73 THR_LOCK_DATA lock; /* MySQL lock */
74 TINA_SHARE *share; /* Shared lock info */
76 current_position; /* Current position in the file during a file scan */
77 my_off_t next_position; /* Next position in the file scan */
78 my_off_t local_saved_data_file_length; /* save position for reads */
82 File data_file; /* File handler for readers */
85 /*
86 The chain contains "holes" in the file, occurred because of
87 deletes/updates. It is used in rnd_end() to get rid of them
88 in the end of the query.
89 */
95 uint local_data_file_version; /* Saved version of the data file used */
98
99 private:
100 bool get_write_pos(my_off_t *end_pos, tina_set *closest_hole);
102 int init_tina_writer();
103 int init_data_file();
104
105 public:
106 ha_tina(handlerton *hton, TABLE_SHARE *table_arg);
107 ~ha_tina() override {
109 if (file_buff) delete file_buff;
110 blobroot.Clear();
111 }
112 const char *table_type() const override { return "CSV"; }
113 ulonglong table_flags() const override {
116 }
117 ulong index_flags(uint, uint, bool) const override {
118 /*
119 We will never have indexes so this will never be called(AKA we return
120 zero)
121 */
122 return 0;
123 }
125 uint max_keys() const { return 0; }
126 uint max_key_parts() const { return 0; }
127 uint max_key_length() const { return 0; }
128 /*
129 Called in test_quick_select to determine if indexes should be used.
130 */
131 double scan_time() override {
132 return (double)(stats.records + stats.deleted) / 20.0 + 10;
133 }
134 /* The next method will never be called */
135 virtual bool fast_key_read() { return true; }
136 /*
137 TODO: return actual upper bound of number of records in the table.
138 (e.g. save number of records seen on full table scan and/or use file size
139 as upper bound)
140 */
142
143 int open(const char *name, int mode, uint open_options,
144 const dd::Table *table_def) override;
145 int close(void) override;
146 int write_row(uchar *buf) override;
147 int update_row(const uchar *old_data, uchar *new_data) override;
148 int delete_row(const uchar *buf) override;
149 int rnd_init(bool scan = true) override;
150 int rnd_next(uchar *buf) override;
151 int rnd_pos(uchar *buf, uchar *pos) override;
152 bool check_and_repair(THD *thd) override;
153 int check(THD *thd, HA_CHECK_OPT *check_opt) override;
154 bool is_crashed() const override;
155 int rnd_end() override;
156 int repair(THD *thd, HA_CHECK_OPT *check_opt) override;
157 /* This is required for SQL layer to know that we support autorepair */
158 bool auto_repair() const override { return true; }
159 void position(const uchar *record) override;
160 int info(uint) override;
161 int extra(enum ha_extra_function operation) override;
162 int delete_all_rows(void) override;
163 int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info,
164 dd::Table *table_def) override;
166 uint table_changes) override;
167
169 enum thr_lock_type lock_type) override;
170
171 /*
172 These functions used to get/update status of the handler.
173 Needed to enable concurrent inserts.
174 */
175 void get_status();
176 void update_status();
177
178 /* The following methods were added just for TINA */
179 int encode_quote(uchar *buf);
181 int chain_append();
182};
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:166
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:33
Definition: transparent_file.h:34
Definition: table.h:46
Definition: ha_tina.h:72
int delete_row(const uchar *buf) override
Definition: ha_tina.cc:1035
ha_tina(handlerton *hton, TABLE_SHARE *table_arg)
Definition: ha_tina.cc:509
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:1377
bool get_write_pos(my_off_t *end_pos, tina_set *closest_hole)
Definition: ha_tina.cc:1223
int write_row(uchar *buf) override
Write a row.
Definition: ha_tina.cc:934
int chain_append()
Definition: ha_tina.cc:603
tina_set * chain_ptr
Definition: ha_tina.h:92
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:1623
my_off_t local_saved_data_file_length
Definition: ha_tina.h:78
bool is_crashed() const override
Check if the table is crashed.
Definition: ha_tina.cc:405
int init_tina_writer()
Definition: ha_tina.cc:383
int open_update_temp_file_if_needed()
Definition: ha_tina.cc:967
int rnd_pos(uchar *buf, uchar *pos) override
Definition: ha_tina.cc:1182
uchar byte_buffer[IO_SIZE]
Definition: ha_tina.h:80
THR_LOCK_DATA lock
Definition: ha_tina.h:73
const char * table_type() const override
The following can be called without an open handler.
Definition: ha_tina.h:112
MEM_ROOT blobroot
Definition: ha_tina.h:97
int close(void) override
Definition: ha_tina.cc:922
bool records_is_known
Definition: ha_tina.h:96
int info(uint) override
General method to gather info from handler.
Definition: ha_tina.cc:1196
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:1108
int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info, dd::Table *table_def) override
Create table (implementation).
Definition: ha_tina.cc:1541
int encode_quote(uchar *buf)
Definition: ha_tina.cc:534
my_off_t next_position
Definition: ha_tina.h:77
int find_current_row(uchar *buf)
Definition: ha_tina.cc:638
double scan_time() override
Definition: ha_tina.h:131
TINA_SHARE * share
Definition: ha_tina.h:74
bool auto_repair() const override
Check if the table can be automatically repaired.
Definition: ha_tina.h:158
String buffer
Definition: ha_tina.h:84
void get_status()
Definition: ha_tina.cc:841
tina_set * chain
Definition: ha_tina.h:91
int rnd_next(uchar *buf) override
Definition: ha_tina.cc:1136
int rnd_end() override
Definition: ha_tina.cc:1237
int delete_all_rows(void) override
Delete all rows in a table.
Definition: ha_tina.cc:1501
int open(const char *name, int mode, uint open_options, const dd::Table *table_def) override
Definition: ha_tina.cc:886
int update_row(const uchar *old_data, uchar *new_data) override
Update a single row.
Definition: ha_tina.cc:991
my_off_t current_position
Definition: ha_tina.h:76
File update_temp_file
Definition: ha_tina.h:83
virtual bool fast_key_read()
Definition: ha_tina.h:135
~ha_tina() override
Definition: ha_tina.h:107
uint max_key_length() const
Definition: ha_tina.h:127
tina_set chain_buffer[DEFAULT_CHAIN_LENGTH]
Definition: ha_tina.h:90
uint max_keys() const
Definition: ha_tina.h:125
int check(THD *thd, HA_CHECK_OPT *check_opt) override
Definition: ha_tina.cc:1579
Transparent_file * file_buff
Definition: ha_tina.h:81
ha_rows estimate_rows_upper_bound() override
Return upper bound of current number of records in the table (max.
Definition: ha_tina.h:141
uint32 chain_size
Definition: ha_tina.h:94
ulong index_flags(uint, uint, bool) const override
Definition: ha_tina.h:117
uint max_key_parts() const
Definition: ha_tina.h:126
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:1529
File data_file
Definition: ha_tina.h:82
int init_data_file()
Initialize the data file.
Definition: ha_tina.cc:1067
void position(const uchar *record) override
Definition: ha_tina.cc:1172
uint max_record_length() const
Definition: ha_tina.h:124
uint local_data_file_version
Definition: ha_tina.h:95
my_off_t temp_file_length
Definition: ha_tina.h:79
ulonglong table_flags() const override
Definition: ha_tina.h:113
void update_status()
Definition: ha_tina.cc:876
int extra(enum ha_extra_function operation) override
Storage engine specific implementation of ha_extra()
Definition: ha_tina.cc:1208
uchar chain_alloced
Definition: ha_tina.h:93
bool check_and_repair(THD *thd) override
Check and repair the table if necessary.
Definition: ha_tina.cc:376
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:4365
A table definition from the master.
Definition: rpl_utility.h:247
#define DEFAULT_CHAIN_LENGTH
Definition: ha_tina.h:33
my_off_t ha_rows
Definition: my_base.h:1139
ha_extra_function
Definition: my_base.h:183
#define HA_POS_ERROR
Definition: my_base.h:1141
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:55
ulonglong my_off_t
Definition: my_inttypes.h:71
unsigned char uchar
Definition: my_inttypes.h:51
uint32_t uint32
Definition: my_inttypes.h:66
Common #defines and includes for file and socket I/O.
#define FN_REFLEN
Definition: my_io.h:82
constexpr const size_t IO_SIZE
Definition: my_io.h:158
int File
Definition: my_io_bits.h:50
void my_free(void *ptr)
Frees the memory pointed by the ptr.
Definition: my_memory.cc:80
static int record
Definition: mysqltest.cc:187
Definition: buf0block_hint.cc:29
mode
Definition: file_handle.h:59
#define HA_BINLOG_ROW_CAPABLE
Definition: handler.h:338
#define HA_MAX_REC_LENGTH
Definition: handler.h:616
#define HA_CAN_REPAIR
Definition: handler.h:368
#define HA_BINLOG_STMT_CAPABLE
Definition: handler.h:339
#define HA_NO_TRANSACTIONS
Definition: handler.h:209
#define HA_NO_AUTO_INCREMENT
Definition: handler.h:313
Our own string classes, used pervasively throughout the executor.
case opt name
Definition: sslopt-case.h:32
Definition: handler.h:3583
Definition: handler.h:2998
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:82
void Clear()
Deallocate all the RAM used.
Definition: my_alloc.cc:168
This structure is shared between different table objects.
Definition: table.h:688
Definition: table.h:1395
Definition: thr_lock.h:123
Definition: thr_lock.h:138
Definition: ha_tina.h:41
bool crashed
Definition: ha_tina.h:62
bool is_log_table
Definition: ha_tina.h:49
File meta_file
Definition: ha_tina.h:60
mysql_mutex_t mutex
Definition: ha_tina.h:56
File tina_write_filedes
Definition: ha_tina.h:61
THR_LOCK lock
Definition: ha_tina.h:57
char * table_name
Definition: ha_tina.h:42
bool tina_write_opened
Definition: ha_tina.h:59
uint table_name_length
Definition: ha_tina.h:44
char data_file_name[FN_REFLEN]
Definition: ha_tina.h:43
bool update_file_opened
Definition: ha_tina.h:58
my_off_t saved_data_file_length
Definition: ha_tina.h:55
uint use_count
Definition: ha_tina.h:44
uint data_file_version
Definition: ha_tina.h:64
ha_rows rows_recorded
Definition: ha_tina.h:63
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2594
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:49
Definition: mysqlslap.cc:237
Definition: ha_tina.h:67
my_off_t begin
Definition: ha_tina.h:68
my_off_t end
Definition: ha_tina.h:69
thr_lock_type
Definition: thr_lock.h:50
unsigned int uint
Definition: uca9-dump.cc:74