1 /* Copyright (c) 2005, 2011, 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 "thr_lock.h"                           /* THR_LOCK */
24 #include "handler.h"                            /* handler */
25 #include "table.h"                              /* TABLE_SHARE */
26 #include "sql_const.h"                          /* MAX_KEY */
27 
28 /*
29   Shared structure for correct LOCK operation
30 */
31 struct st_blackhole_share {
32   THR_LOCK lock;
33   uint use_count;
34   uint table_name_length;
35   char table_name[1];
36 };
37 
38 
39 /*
40   Class definition for the blackhole storage engine
41   "Dumbest named feature ever"
42 */
43 class ha_blackhole: public handler
44 {
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   {
52   }
53   /* The name that will be used for display purposes */
table_type()54   const char *table_type() const { return "BLACKHOLE"; }
55   /*
56     The name of the index type that will be used for display
57     don't implement this method unless you really have indexes
58   */
59   const char *index_type(uint key_number);
60   const char **bas_ext() const;
table_flags()61   ulonglong table_flags() const
62   {
63     return(HA_NULL_IN_KEY | HA_CAN_FULLTEXT | HA_CAN_SQL_HANDLER |
64            HA_BINLOG_STMT_CAPABLE | HA_BINLOG_ROW_CAPABLE |
65            HA_CAN_INDEX_BLOBS | HA_AUTO_PART_KEY | HA_READ_OUT_OF_SYNC |
66            HA_FILE_BASED | HA_CAN_GEOMETRY | HA_CAN_INSERT_DELAYED);
67   }
index_flags(uint inx,uint part,bool all_parts)68   ulong index_flags(uint inx, uint part, bool all_parts) const
69   {
70     return ((table_share->key_info[inx].algorithm == HA_KEY_ALG_FULLTEXT) ?
71             0 : HA_READ_NEXT | HA_READ_PREV | HA_READ_RANGE |
72             HA_READ_ORDER | HA_KEYREAD_ONLY);
73   }
74   /* The following defines can be increased if necessary */
75 #define BLACKHOLE_MAX_KEY	MAX_KEY		/* Max allowed keys */
76 #define BLACKHOLE_MAX_KEY_SEG	16		/* Max segments for key */
77 #define BLACKHOLE_MAX_KEY_LENGTH	3500		/* Like in InnoDB */
max_supported_keys()78   uint max_supported_keys()          const { return BLACKHOLE_MAX_KEY; }
max_supported_key_length()79   uint max_supported_key_length()    const { return BLACKHOLE_MAX_KEY_LENGTH; }
max_supported_key_part_length()80   uint max_supported_key_part_length() const { return BLACKHOLE_MAX_KEY_LENGTH; }
81   int open(const char *name, int mode, uint test_if_locked);
82   int close(void);
83   int truncate();
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, key_part_map keypart_map);
93   int index_next(uchar * buf);
94   int index_prev(uchar * buf);
95   int index_first(uchar * buf);
96   int index_last(uchar * buf);
97   void position(const uchar *record);
98   int info(uint flag);
99   int external_lock(THD *thd, int lock_type);
100   int create(const char *name, TABLE *table_arg,
101              HA_CREATE_INFO *create_info);
102   THR_LOCK_DATA **store_lock(THD *thd,
103                              THR_LOCK_DATA **to,
104                              enum thr_lock_type lock_type);
has_gap_locks()105   bool has_gap_locks() const { return true; }
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