1 /* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
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/types.h>
24 
25 #include "my_inttypes.h"
26 #include "sql/handler.h" /* handler */
27 #include "sql/table.h"   /* TABLE_SHARE */
28 #include "thr_lock.h"    /* THR_LOCK */
29 
30 /*
31   Shared structure for correct LOCK operation
32 */
33 struct st_blackhole_share {
34   THR_LOCK lock;
35   uint use_count;
36   uint table_name_length;
37   char table_name[1];
38 };
39 
40 /*
41   Class definition for the blackhole storage engine
42   "Dumbest named feature ever"
43 */
44 class ha_blackhole : public handler {
45   THR_LOCK_DATA lock; /* MySQL lock */
46   st_blackhole_share *share;
47 
48  public:
49   ha_blackhole(handlerton *hton, TABLE_SHARE *table_arg);
~ha_blackhole()50   ~ha_blackhole() {}
51   /* The name that will be used for display purposes */
table_type()52   const char *table_type() const { return "BLACKHOLE"; }
get_default_index_algorithm()53   virtual enum ha_key_alg get_default_index_algorithm() const {
54     return HA_KEY_ALG_BTREE;
55   }
is_index_algorithm_supported(enum ha_key_alg key_alg)56   virtual bool is_index_algorithm_supported(enum ha_key_alg key_alg) const {
57     return key_alg == HA_KEY_ALG_BTREE || key_alg == HA_KEY_ALG_RTREE;
58   }
table_flags()59   ulonglong table_flags() const {
60     return (HA_NULL_IN_KEY | HA_CAN_FULLTEXT | HA_CAN_SQL_HANDLER |
61             HA_BINLOG_STMT_CAPABLE | HA_BINLOG_ROW_CAPABLE |
62             HA_CAN_INDEX_BLOBS | HA_AUTO_PART_KEY | HA_READ_OUT_OF_SYNC |
63             HA_FILE_BASED | HA_CAN_GEOMETRY);
64   }
index_flags(uint inx,uint,bool)65   ulong index_flags(uint inx, uint, bool) const {
66     return ((table_share->key_info[inx].algorithm == HA_KEY_ALG_FULLTEXT)
67                 ? 0
68                 : HA_READ_NEXT | HA_READ_PREV | HA_READ_RANGE | HA_READ_ORDER |
69                       HA_KEYREAD_ONLY);
70   }
71   /* The following defines can be increased if necessary */
72 #define BLACKHOLE_MAX_KEY 64     /* Max allowed keys */
73 #define BLACKHOLE_MAX_KEY_SEG 16 /* Max segments for key */
74 #define BLACKHOLE_MAX_KEY_LENGTH 1000
max_supported_keys()75   uint max_supported_keys() const { return BLACKHOLE_MAX_KEY; }
max_supported_key_length()76   uint max_supported_key_length() const { return BLACKHOLE_MAX_KEY_LENGTH; }
max_supported_key_part_length(HA_CREATE_INFO * create_info MY_ATTRIBUTE ((unused)))77   uint max_supported_key_part_length(
78       HA_CREATE_INFO *create_info MY_ATTRIBUTE((unused))) const {
79     return BLACKHOLE_MAX_KEY_LENGTH;
80   }
81   int open(const char *name, int mode, uint test_if_locked,
82            const dd::Table *table_def);
83   int close(void);
84   int rnd_init(bool scan);
85   int rnd_next(uchar *buf);
86   int rnd_pos(uchar *buf, uchar *pos);
87   int index_read_map(uchar *buf, const uchar *key, key_part_map keypart_map,
88                      enum ha_rkey_function find_flag);
89   int index_read_idx_map(uchar *buf, uint idx, const uchar *key,
90                          key_part_map keypart_map,
91                          enum ha_rkey_function find_flag);
92   int index_read_last_map(uchar *buf, const uchar *key,
93                           key_part_map keypart_map);
94   int index_next(uchar *buf);
95   int index_prev(uchar *buf);
96   int index_first(uchar *buf);
97   int index_last(uchar *buf);
98   void position(const uchar *record);
99   int info(uint flag);
100   int external_lock(THD *thd, int lock_type);
101   int create(const char *name, TABLE *table_arg, HA_CREATE_INFO *create_info,
102              dd::Table *table_def);
103   THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to,
104                              enum thr_lock_type lock_type);
105 
106  private:
107   virtual int write_row(uchar *buf);
108   virtual int update_row(const uchar *old_data, uchar *new_data);
109   virtual int delete_row(const uchar *buf);
110 };
111