23 #include <drizzled/error_t.h>
24 #include <drizzled/handler_structs.h>
25 #include <drizzled/message.h>
26 #include <drizzled/message/cache.h>
27 #include <drizzled/plugin.h>
28 #include <drizzled/plugin/monitored_in_transaction.h>
29 #include <drizzled/plugin/plugin.h>
30 #include <drizzled/sql_string.h>
43 typedef bool (stat_print_fn)(Session *session,
const char *type, uint32_t type_len,
44 const char *file, uint32_t file_len,
45 const char *status, uint32_t status_len);
48 enum engine_flag_bits {
49 HTON_BIT_ALTER_NOT_SUPPORTED,
51 HTON_BIT_NOT_USER_SELECTABLE,
52 HTON_BIT_TEMPORARY_NOT_SUPPORTED,
53 HTON_BIT_TEMPORARY_ONLY,
54 HTON_BIT_DOES_TRANSACTIONS,
55 HTON_BIT_STATS_RECORDS_IS_EXACT,
57 HTON_BIT_CAN_INDEX_BLOBS,
58 HTON_BIT_PRIMARY_KEY_IN_READ_INDEX,
59 HTON_BIT_PARTIAL_COLUMN_READ,
60 HTON_BIT_TABLE_SCAN_ON_INDEX,
61 HTON_BIT_FAST_KEY_READ,
64 HTON_BIT_NO_AUTO_INCREMENT,
65 HTON_BIT_DUPLICATE_POS,
66 HTON_BIT_AUTO_PART_KEY,
67 HTON_BIT_REQUIRE_PRIMARY_KEY,
68 HTON_BIT_REQUIRES_KEY_COLUMNS_FOR_DELETE,
69 HTON_BIT_PRIMARY_KEY_REQUIRED_FOR_DELETE,
70 HTON_BIT_NO_PREFIX_CHAR_KEYS,
71 HTON_BIT_HAS_CHECKSUM,
72 HTON_BIT_SKIP_STORE_LOCK,
73 HTON_BIT_SCHEMA_DICTIONARY,
74 HTON_BIT_FOREIGN_KEYS,
78 static const std::bitset<HTON_BIT_SIZE> HTON_NO_FLAGS(0);
79 static const std::bitset<HTON_BIT_SIZE> HTON_ALTER_NOT_SUPPORTED(1 << HTON_BIT_ALTER_NOT_SUPPORTED);
80 static const std::bitset<HTON_BIT_SIZE> HTON_HIDDEN(1 << HTON_BIT_HIDDEN);
81 static const std::bitset<HTON_BIT_SIZE> HTON_NOT_USER_SELECTABLE(1 << HTON_BIT_NOT_USER_SELECTABLE);
82 static const std::bitset<HTON_BIT_SIZE> HTON_TEMPORARY_NOT_SUPPORTED(1 << HTON_BIT_TEMPORARY_NOT_SUPPORTED);
83 static const std::bitset<HTON_BIT_SIZE> HTON_TEMPORARY_ONLY(1 << HTON_BIT_TEMPORARY_ONLY);
84 static const std::bitset<HTON_BIT_SIZE> HTON_HAS_DOES_TRANSACTIONS(1 << HTON_BIT_DOES_TRANSACTIONS);
85 static const std::bitset<HTON_BIT_SIZE> HTON_STATS_RECORDS_IS_EXACT(1 << HTON_BIT_STATS_RECORDS_IS_EXACT);
86 static const std::bitset<HTON_BIT_SIZE> HTON_NULL_IN_KEY(1 << HTON_BIT_NULL_IN_KEY);
87 static const std::bitset<HTON_BIT_SIZE> HTON_CAN_INDEX_BLOBS(1 << HTON_BIT_CAN_INDEX_BLOBS);
88 static const std::bitset<HTON_BIT_SIZE> HTON_PRIMARY_KEY_IN_READ_INDEX(1 << HTON_BIT_PRIMARY_KEY_IN_READ_INDEX);
89 static const std::bitset<HTON_BIT_SIZE> HTON_PARTIAL_COLUMN_READ(1 << HTON_BIT_PARTIAL_COLUMN_READ);
90 static const std::bitset<HTON_BIT_SIZE> HTON_TABLE_SCAN_ON_INDEX(1 << HTON_BIT_TABLE_SCAN_ON_INDEX);
91 static const std::bitset<HTON_BIT_SIZE> HTON_FAST_KEY_READ(1 << HTON_BIT_FAST_KEY_READ);
92 static const std::bitset<HTON_BIT_SIZE> HTON_NO_BLOBS(1 << HTON_BIT_NO_BLOBS);
93 static const std::bitset<HTON_BIT_SIZE> HTON_HAS_RECORDS(1 << HTON_BIT_HAS_RECORDS);
94 static const std::bitset<HTON_BIT_SIZE> HTON_NO_AUTO_INCREMENT(1 << HTON_BIT_NO_AUTO_INCREMENT);
95 static const std::bitset<HTON_BIT_SIZE> HTON_DUPLICATE_POS(1 << HTON_BIT_DUPLICATE_POS);
96 static const std::bitset<HTON_BIT_SIZE> HTON_AUTO_PART_KEY(1 << HTON_BIT_AUTO_PART_KEY);
97 static const std::bitset<HTON_BIT_SIZE> HTON_REQUIRE_PRIMARY_KEY(1 << HTON_BIT_REQUIRE_PRIMARY_KEY);
98 static const std::bitset<HTON_BIT_SIZE> HTON_REQUIRES_KEY_COLUMNS_FOR_DELETE(1 << HTON_BIT_REQUIRES_KEY_COLUMNS_FOR_DELETE);
99 static const std::bitset<HTON_BIT_SIZE> HTON_PRIMARY_KEY_REQUIRED_FOR_DELETE(1 << HTON_BIT_PRIMARY_KEY_REQUIRED_FOR_DELETE);
100 static const std::bitset<HTON_BIT_SIZE> HTON_NO_PREFIX_CHAR_KEYS(1 << HTON_BIT_NO_PREFIX_CHAR_KEYS);
101 static const std::bitset<HTON_BIT_SIZE> HTON_HAS_CHECKSUM(1 << HTON_BIT_HAS_CHECKSUM);
102 static const std::bitset<HTON_BIT_SIZE> HTON_SKIP_STORE_LOCK(1 << HTON_BIT_SKIP_STORE_LOCK);
103 static const std::bitset<HTON_BIT_SIZE> HTON_HAS_SCHEMA_DICTIONARY(1 << HTON_BIT_SCHEMA_DICTIONARY);
104 static const std::bitset<HTON_BIT_SIZE> HTON_HAS_FOREIGN_KEYS(1 << HTON_BIT_FOREIGN_KEYS);
109 typedef std::vector<StorageEngine *> EngineVector;
111 typedef std::set<std::string> TableNameList;
113 extern const std::string UNKNOWN_STRING;
114 extern DRIZZLED_API const std::string DEFAULT_DEFINITION_FILE_EXT;
132 typedef uint64_t Table_flags;
135 static EngineVector &getSchemaEngines();
136 const std::bitset<HTON_BIT_SIZE> flags;
139 virtual void setTransactionReadWrite(
Session& session);
145 virtual void doStartStatement(
Session *session)
155 virtual void doEndStatement(
Session *session)
161 std::string table_definition_ext;
164 const std::string& getTableDefinitionFileExtension()
166 return table_definition_ext;
169 virtual message::Table::Index::IndexType default_index_type()
const
171 return message::Table::Index::BTREE;
175 std::vector<std::string> aliases;
178 const std::vector<std::string>& getAliases()
const
183 void addAlias(std::string alias)
185 aliases.push_back(alias);
196 pthread_mutex_t proto_cache_mutex;
200 const std::bitset<HTON_BIT_SIZE> &flags_arg= HTON_NO_FLAGS);
205 virtual int doGetTableDefinition(
Session &session,
217 void print_keydup_error(uint32_t key_nr,
const char *msg,
const Table &table)
const;
218 virtual bool get_error_message(
int error,
String *buf)
const;
221 virtual void print_error(
int error, myf errflag,
const Table& table)
const;
223 bool is_user_selectable()
const
225 return not flags.test(HTON_BIT_NOT_USER_SELECTABLE);
228 bool check_flag(
const engine_flag_bits flag)
const
230 return flags.test(flag);
234 virtual uint32_t index_flags(
enum ha_key_alg)
const {
return 0; }
235 virtual void startStatement(Session *session)
237 doStartStatement(session);
239 virtual void endStatement(Session *session)
241 doEndStatement(session);
247 virtual int close_connection(Session *)
252 virtual Cursor *create(Table &)= 0;
254 virtual bool flush_logs() {
return false; }
255 virtual bool show_status(Session *, stat_print_fn *,
enum ha_stat_type)
271 virtual const char **bas_ext()
const =0;
274 virtual int doCreateTable(Session &session,
277 const message::Table &message)= 0;
279 virtual int doRenameTable(Session &session,
282 virtual int doDropTable(Session &session,
285 virtual void doGetTableIdentifiers(CachedDirectory &directory,
287 identifier::table::vector &set_of_identifiers)= 0;
292 { (void)identifier;
return true; }
296 friend class AddSchemaNames;
297 friend class AddTableIdentifier;
298 friend class AlterSchema;
299 friend class CanCreateTable;
300 friend class CreateSchema;
301 friend class DropSchema;
302 friend class DropTable;
303 friend class DropTables;
304 friend class FindEngineByName;
305 friend class Ha_delete_table_error_handler;
306 friend class StorageEngineCloseConnection;
307 friend class StorageEngineDoesTableExist;
308 friend class StorageEngineGetSchemaDefinition;
309 friend class StorageEngineGetTableDefinition;
310 friend class DropTableByIdentifier;
315 static bool addPlugin(plugin::StorageEngine *engine);
316 static void removePlugin(plugin::StorageEngine *engine);
318 static message::table::shared_ptr getTableMessage(Session& session,
320 bool include_temporary_tables=
true);
321 static bool doesTableExist(Session &session,
323 bool include_temporary_tables=
true);
325 static plugin::StorageEngine *findByName(
const std::string &find_str);
326 static plugin::StorageEngine *findByName(Session& session,
const std::string &find_str);
328 static void closeConnection(Session&);
329 static void dropDatabase(
char* path);
330 static bool flushLogs(plugin::StorageEngine *db_type);
332 static bool dropTable(Session& session,
334 static bool dropTable(Session& session,
336 drizzled::error_t &error);
338 static bool dropTable(Session& session,
339 StorageEngine &engine,
340 const identifier::Table& identifier,
341 drizzled::error_t &error);
343 static void getIdentifiers(Session &session,
344 const identifier::Schema &schema_identifier,
345 identifier::table::vector &set_of_identifiers);
351 static void getIdentifiers(Session &session, identifier::schema::vector &schemas);
357 static bool dropSchema(Session &session,
358 const identifier::Schema& identifier,
359 message::schema::const_reference schema_message);
364 virtual void doGetSchemaIdentifiers(identifier::schema::vector&)
369 return drizzled::message::schema::shared_ptr();
382 static inline const std::string &resolveName(
const StorageEngine *engine)
384 return engine == NULL ? UNKNOWN_STRING : engine->getName();
387 static bool createTable(Session &session,
388 const identifier::Table &identifier,
389 message::Table& table_message);
391 static void removeLostTemporaryTables(Session &session,
const char *directory);
393 Cursor *getCursor(Table &share);
395 uint32_t max_record_length()
const
396 {
return std::min(HA_MAX_REC_LENGTH, max_supported_record_length()); }
397 uint32_t max_keys()
const
398 {
return std::min(MAX_KEY, max_supported_keys()); }
399 uint32_t max_key_parts()
const
400 {
return std::min(MAX_REF_PARTS, max_supported_key_parts()); }
401 uint32_t max_key_length()
const
402 {
return std::min(MAX_KEY_LENGTH, max_supported_key_length()); }
403 uint32_t max_key_part_length(
void)
const
404 {
return std::min(MAX_KEY_LENGTH, max_supported_key_part_length()); }
406 virtual uint32_t max_supported_record_length(
void)
const
407 {
return HA_MAX_REC_LENGTH; }
408 virtual uint32_t max_supported_keys(
void)
const {
return 0; }
409 virtual uint32_t max_supported_key_parts(
void)
const {
return MAX_REF_PARTS; }
410 virtual uint32_t max_supported_key_length(
void)
const {
return MAX_KEY_LENGTH; }
411 virtual uint32_t max_supported_key_part_length(
void)
const {
return 255; }
418 static bool readTableFile(
const std::string &path, message::Table &table_message);
438 virtual bool validateCreateTableOption(
const std::string &key,
const std::string &state)
446 virtual bool validateCreateSchemaOption(
const std::string &key,
const std::string &state)
455 std::ostream& operator<<(std::ostream& output,
const StorageEngine &engine);