drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
ha_innodb.cc
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (C) 2000, 2010, MySQL AB & Innobase Oy. All Rights Reserved.
4Copyright (C) 2008, 2009 Google Inc.
5Copyright (C) 2009, Percona Inc.
6Copyright (C) 2011, Stewart Smith
7
8Portions of this file contain modifications contributed and copyrighted by
9Google, Inc. Those modifications are gratefully acknowledged and are described
10briefly in the InnoDB documentation. The contributions by Google are
11incorporated with their permission, and subject to the conditions contained in
12the file COPYING.Google.
13
14Portions of this file contain modifications contributed and copyrighted
15by Percona Inc.. Those modifications are
16gratefully acknowledged and are described briefly in the InnoDB
17documentation. The contributions by Percona Inc. are incorporated with
18their permission, and subject to the conditions contained in the file
19COPYING.Percona.
20
21This program is free software; you can redistribute it and/or modify it under
22the terms of the GNU General Public License as published by the Free Software
23Foundation; version 2 of the License.
24
25This program is distributed in the hope that it will be useful, but WITHOUT
26ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
27FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
28
29You should have received a copy of the GNU General Public License along with
30this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
31St, Fifth Floor, Boston, MA 02110-1301 USA
32
33*****************************************************************************/
34
35/* TODO list for the InnoDB Cursor in 5.0:
36 - fix savepoint functions to use savepoint storage area
37 - Find out what kind of problems the OS X case-insensitivity causes to
38 table and database names; should we 'normalize' the names like we do
39 in Windows?
40*/
41
42#include <config.h>
43
44#include <limits.h>
45#include <fcntl.h>
46
47#include <drizzled/error.h>
48#include <drizzled/errmsg_print.h>
49#include <drizzled/internal/m_string.h>
50#include <drizzled/internal/my_sys.h>
51#include <drizzled/plugin.h>
52#include <drizzled/show.h>
53#include <drizzled/data_home.h>
54#include <drizzled/catalog/local.h>
55#include <drizzled/error.h>
56#include <drizzled/field.h>
57#include <drizzled/charset.h>
58#include <drizzled/session.h>
59#include <drizzled/current_session.h>
60#include <drizzled/table.h>
61#include <drizzled/field/blob.h>
62#include <drizzled/field/varstring.h>
63#include <drizzled/plugin/xa_storage_engine.h>
64#include <drizzled/plugin/daemon.h>
65#include <drizzled/memory/multi_malloc.h>
66#include <drizzled/pthread_globals.h>
67#include <drizzled/named_savepoint.h>
68#include <drizzled/session/table_messages.h>
69#include <drizzled/transaction_services.h>
72#include <drizzled/statistics_variables.h>
73#include <drizzled/system_variables.h>
74#include <drizzled/session/times.h>
75#include <drizzled/session/transactions.h>
76#include <drizzled/typelib.h>
77#include <drizzled/key_part_info.h>
78
79#include <boost/algorithm/string.hpp>
80#include <boost/program_options.hpp>
81#include <boost/scoped_array.hpp>
82#include <boost/filesystem.hpp>
84#include <iostream>
85#include <drizzled/internal/my_sys.h>
86
87namespace po= boost::program_options;
88namespace fs=boost::filesystem;
89
91
92/* Include necessary InnoDB headers */
93#include "univ.i"
94#include "buf0lru.h"
95#include "btr0sea.h"
96#include "os0file.h"
97#include "os0thread.h"
98#include "srv0start.h"
99#include "srv0srv.h"
100#include "trx0roll.h"
101#include "trx0trx.h"
102#include "trx0sys.h"
103#include "mtr0mtr.h"
104#include "row0ins.h"
105#include "row0mysql.h"
106#include "row0sel.h"
107#include "row0upd.h"
108#include "log0log.h"
109#include "lock0lock.h"
110#include "dict0crea.h"
111#include "create_replication.h"
112#include "btr0cur.h"
113#include "btr0btr.h"
114#include "fsp0fsp.h"
115#include "sync0sync.h"
116#include "fil0fil.h"
117#include "trx0xa.h"
118#include "row0merge.h"
119#include "dict0boot.h"
120#include "ha_prototypes.h"
121#include "ut0mem.h"
122#include "ibuf0ibuf.h"
123
124#include "ha_innodb.h"
125#include "data_dictionary.h"
126#include "replication_dictionary.h"
127#include "internal_dictionary.h"
128#include "handler0vars.h"
129
130#include <iostream>
131#include <sstream>
132#include <string>
133
134#include <plugin/innobase/handler/status_function.h>
135#include <plugin/innobase/handler/replication_log.h>
136
137#include <google/protobuf/io/zero_copy_stream.h>
138#include <google/protobuf/io/zero_copy_stream_impl.h>
139#include <google/protobuf/io/coded_stream.h>
140#include <google/protobuf/text_format.h>
141
142#include <boost/thread/mutex.hpp>
143
144using std::string;
145using namespace drizzled;
146
148static boost::mutex innobase_share_mutex;
149
151static ulong commit_threads = 0;
152static boost::condition_variable commit_cond;
153static boost::mutex commit_cond_m;
154static bool innodb_inited = 0;
155
156#define INSIDE_HA_INNOBASE_CC
157
158/* In the Windows plugin, the return value of current_session is
159undefined. Map it to NULL. */
160#if defined MYSQL_DYNAMIC_PLUGIN && defined __WIN__
161# undef current_session
162# define current_session NULL
163# define EQ_CURRENT_SESSION(session) TRUE
164#else /* MYSQL_DYNAMIC_PLUGIN && __WIN__ */
165# define EQ_CURRENT_SESSION(session) ((session) == current_session)
166#endif /* MYSQL_DYNAMIC_PLUGIN && __WIN__ */
167
168static plugin::XaStorageEngine* innodb_engine_ptr= NULL;
169
170typedef constrained_check<uint32_t, UINT32_MAX, 10> open_files_constraint;
171static open_files_constraint innobase_open_files;
172typedef constrained_check<uint32_t, 10, 1> mirrored_log_groups_constraint;
173static mirrored_log_groups_constraint innobase_mirrored_log_groups;
174typedef constrained_check<uint32_t, 100, 2> log_files_in_group_constraint;
175static log_files_in_group_constraint innobase_log_files_in_group;
176typedef constrained_check<uint32_t, 6, 0> force_recovery_constraint;
177force_recovery_constraint innobase_force_recovery;
178typedef constrained_check<size_t, SIZE_MAX, 256*1024, 1024> log_buffer_constraint;
179static log_buffer_constraint innobase_log_buffer_size;
180typedef constrained_check<size_t, SIZE_MAX, 512*1024, 1024> additional_mem_pool_constraint;
181static additional_mem_pool_constraint innobase_additional_mem_pool_size;
182typedef constrained_check<unsigned int, 1000, 1> autoextend_constraint;
183static autoextend_constraint innodb_auto_extend_increment;
184typedef constrained_check<size_t, SIZE_MAX, 33554432, 1048576> buffer_pool_constraint;
185static buffer_pool_constraint innobase_buffer_pool_size;
186typedef constrained_check<uint32_t, MAX_BUFFER_POOLS, 1> buffer_pool_instances_constraint;
187static buffer_pool_instances_constraint innobase_buffer_pool_instances;
188typedef constrained_check<uint32_t,
189 (1 << UNIV_PAGE_SIZE_SHIFT_MAX),
190 (1 << 12)> page_size_constraint;
191static page_size_constraint innobase_page_size;
192typedef constrained_check<uint32_t,
193 (1 << UNIV_PAGE_SIZE_SHIFT_MAX),
194 (1 << 9)> log_block_size_constraint;
195static log_block_size_constraint innobase_log_block_size;
196typedef constrained_check<uint32_t, UINT32_MAX, 100> io_capacity_constraint;
197static io_capacity_constraint innodb_io_capacity;
198typedef constrained_check<uint32_t, 5000, 1> purge_batch_constraint;
199static purge_batch_constraint innodb_purge_batch_size;
200typedef constrained_check<uint32_t, 1, 0> purge_threads_constraint;
201static purge_threads_constraint innodb_n_purge_threads;
202typedef constrained_check<uint32_t, 2, 0> trinary_constraint;
203static trinary_constraint innodb_flush_log_at_trx_commit;
204typedef constrained_check<unsigned int, 99, 0> max_dirty_pages_constraint;
205static max_dirty_pages_constraint innodb_max_dirty_pages_pct;
206static uint64_constraint innodb_max_purge_lag;
207static uint64_nonzero_constraint innodb_stats_sample_pages;
208typedef constrained_check<uint32_t, 64, 1> io_threads_constraint;
209static io_threads_constraint innobase_read_io_threads;
210static io_threads_constraint innobase_write_io_threads;
211
212typedef constrained_check<uint32_t, 1000, 0> concurrency_constraint;
213static concurrency_constraint innobase_commit_concurrency;
214static concurrency_constraint innobase_thread_concurrency;
215static uint32_nonzero_constraint innodb_concurrency_tickets;
216
218static log_file_constraint innobase_log_file_size;
219
220static uint64_constraint innodb_replication_delay;
221
222static uint32_constraint buffer_pool_restore_at_startup;
223
227static old_blocks_constraint innobase_old_blocks_pct;
228
229static uint32_constraint innodb_sync_spin_loops;
230static uint32_constraint innodb_spin_wait_delay;
231static uint32_constraint innodb_thread_sleep_delay;
232
233typedef constrained_check<uint32_t, 64, 0> read_ahead_threshold_constraint;
234static read_ahead_threshold_constraint innodb_read_ahead_threshold;
235
236static uint64_constraint ibuf_max_size;
237
238typedef constrained_check<uint32_t, 1, 0> binary_constraint;
239static binary_constraint ibuf_active_contract;
240
241typedef constrained_check<uint32_t, 999999999, 100> ibuf_accel_rate_constraint;
242static ibuf_accel_rate_constraint ibuf_accel_rate;
243static uint32_constraint checkpoint_age_target;
244static binary_constraint flush_neighbor_pages;
245
246static string sysvar_transaction_log_use_replicator;
247
248typedef constrained_check<uint32_t, TRX_SYS_N_RSEGS, 1> rollback_segments_constraint;
249static rollback_segments_constraint innobase_rollback_segments;
250
251
252/* The default values for the following char* start-up parameters
253are determined in innobase_init below: */
254
255std::string innobase_data_home_dir;
256std::string innobase_data_file_path;
257std::string innobase_log_group_home_dir;
258static string innobase_file_format_name;
259static string innobase_change_buffering;
260
261static string read_ahead;
262static string adaptive_flushing_method;
263
264/* The highest file format being used in the database. The value can be
265set by user, however, it will be adjusted to the newer file format if
266a table of such format is created/opened. */
267static string innobase_file_format_max;
268
269/* Below we have boolean-valued start-up parameters, and their default
270values */
271
272static trinary_constraint innobase_fast_shutdown;
273
274/* "innobase_file_format_check" decides whether we would continue
275booting the server if the file format stamped on the system
276table space exceeds the maximum file format supported
277by the server. Can be set during server startup at command
278line or configure file, and a read only variable after
279server startup */
280
281/* If a new file format is introduced, the file format
282name needs to be updated accordingly. Please refer to
283file_format_name_map[] defined in trx0sys.c for the next
284file format name. */
285
286static my_bool innobase_file_format_check = TRUE;
287static my_bool innobase_use_doublewrite = TRUE;
288static my_bool innobase_use_checksums = TRUE;
289static my_bool innobase_rollback_on_timeout = FALSE;
290static my_bool innobase_create_status_file = FALSE;
291static bool innobase_use_replication_log;
292static bool support_xa;
293static bool strict_mode;
294typedef constrained_check<uint32_t, 1024*1024*1024, 1> lock_wait_constraint;
295static lock_wait_constraint lock_wait_timeout;
296
297static char* internal_innobase_data_file_path = NULL;
298
302static const char* innodb_stats_method_names[] = {
303 "nulls_equal",
304 "nulls_unequal",
305 "nulls_ignored",
306 NULL
307};
308
309static string innodb_stats_method;
310
311/* The following counter is used to convey information to InnoDB
312about server activity: in selects it is not sensible to call
313srv_active_wake_master_thread after each fetch or search, we only do
314it every INNOBASE_WAKE_INTERVAL'th step. */
315
316#define INNOBASE_WAKE_INTERVAL 32
317static ulong innobase_active_counter = 0;
318
319static hash_table_t* innobase_open_tables;
320
321#ifdef __NETWARE__ /* some special cleanup for NetWare */
322bool nw_panic = FALSE;
323#endif
324
326static const char* innobase_change_buffering_values[IBUF_USE_COUNT] = {
327 "none", /* IBUF_USE_NONE */
328 "inserts", /* IBUF_USE_INSERT */
329 "deletes", /* IBUF_USE_DELETE_MARK */
330 "changes", /* IBUF_USE_INSERT_DELETE_MARK */
331 "purges", /* IBUF_USE_DELETE */
332 "all" /* IBUF_USE_ALL */
333};
334
336static const char* read_ahead_names[] = {
337 "none", /* 0 */
338 "random",
339 "linear",
340 "both", /* 3 */
341 /* For compatibility with the older Percona patch */
342 "0", /* 4 ("none" + 4) */
343 "1",
344 "2",
345 "3", /* 7 ("both" + 4) */
346 NULL
347};
348
349static TYPELIB read_ahead_typelib = {
350 array_elements(read_ahead_names) - 1, "read_ahead_typelib",
351 read_ahead_names, NULL
352};
353
355static const char* adaptive_flushing_method_names[] = {
356 "native", /* 0 */
357 "estimate", /* 1 */
358 "keep_average", /* 2 */
359 /* For compatibility with the older Percona patch */
360 "0", /* 3 ("native" + 3) */
361 "1", /* 4 ("estimate" + 3) */
362 "2", /* 5 ("keep_average" + 3) */
363 NULL
364};
365
366static TYPELIB adaptive_flushing_method_typelib = {
367 array_elements(adaptive_flushing_method_names) - 1,
368 "adaptive_flushing_method_typelib",
370};
371
372/* "GEN_CLUST_INDEX" is the name reserved for Innodb default
373system primary index. */
374static const char innobase_index_reserve_name[]= "GEN_CLUST_INDEX";
375
376/********************************************************************
377Gives the file extension of an InnoDB single-table tablespace. */
378static const char* ha_innobase_exts[] = {
379 ".ibd",
380 NULL
381};
382
383static INNOBASE_SHARE *get_share(const char *table_name);
384static void free_share(INNOBASE_SHARE *share);
385
386class InnobaseEngine : public plugin::XaStorageEngine
387{
388public:
389 explicit InnobaseEngine(string name_arg) :
390 plugin::XaStorageEngine(name_arg,
391 HTON_NULL_IN_KEY |
392 HTON_CAN_INDEX_BLOBS |
393 HTON_PRIMARY_KEY_IN_READ_INDEX |
394 HTON_PARTIAL_COLUMN_READ |
395 HTON_TABLE_SCAN_ON_INDEX |
396 HTON_HAS_FOREIGN_KEYS)
397 {
398 table_definition_ext= plugin::defaultTableDefinitionFileExt();
399 addAlias("INNOBASE");
400 }
401
402 virtual ~InnobaseEngine()
403 {
404 if (innodb_inited) {
405 srv_fast_shutdown = (ulint) innobase_fast_shutdown;
406 innodb_inited = 0;
407 hash_table_free(innobase_open_tables);
408 innobase_open_tables = NULL;
409 if (innobase_shutdown_for_mysql() != DB_SUCCESS) {
410 // Throw here?
411 }
413 free(internal_innobase_data_file_path);
414 }
415
416 /* These get strdup'd from vm variables */
417
418 }
419
420private:
421 virtual int doStartTransaction(Session *session, start_transaction_option_t options);
422 virtual void doStartStatement(Session *session);
423 virtual void doEndStatement(Session *session);
424public:
425 virtual
426 int
428/*======================*/
429 /* out: 0 or error number */
430 Session* session); /* in: handle to the MySQL thread of the user
431 whose resources should be free'd */
432
433 virtual int doSetSavepoint(Session* session,
434 drizzled::NamedSavepoint &savepoint);
435 virtual int doRollbackToSavepoint(Session* session,
436 drizzled::NamedSavepoint &savepoint);
437 virtual int doReleaseSavepoint(Session* session,
438 drizzled::NamedSavepoint &savepoint);
439 virtual int doXaCommit(Session* session, bool all)
440 {
441 return doCommit(session, all); /* XA commit just does a SQL COMMIT */
442 }
443 virtual int doXaRollback(Session *session, bool all)
444 {
445 return doRollback(session, all); /* XA rollback just does a SQL ROLLBACK */
446 }
447 virtual uint64_t doGetCurrentTransactionId(Session *session);
448 virtual uint64_t doGetNewTransactionId(Session *session);
449 virtual int doCommit(Session* session, bool all);
450 virtual int doRollback(Session* session, bool all);
451
452 /***********************************************************************
453 This function is used to prepare X/Open XA distributed transaction */
454 virtual
455 int
457 /*================*/
458 /* out: 0 or error number */
459 Session* session, /* in: handle to the MySQL thread of the user
460 whose XA transaction should be prepared */
461 bool all); /* in: TRUE - commit transaction
462 FALSE - the current SQL statement ended */
463 /***********************************************************************
464 This function is used to recover X/Open XA distributed transactions */
465 virtual
466 int
468 /*================*/
469 /* out: number of prepared transactions
470 stored in xid_list */
471 ::drizzled::XID* xid_list, /* in/out: prepared transactions */
472 size_t len); /* in: number of slots in xid_list */
473 /***********************************************************************
474 This function is used to commit one X/Open XA distributed transaction
475 which is in the prepared state */
476 virtual
477 int
479 /*===================*/
480 /* out: 0 or error number */
481 ::drizzled::XID* xid); /* in: X/Open XA transaction identification */
482 /***********************************************************************
483 This function is used to rollback one X/Open XA distributed transaction
484 which is in the prepared state */
485 virtual
486 int
488 /*=====================*/
489 /* out: 0 or error number */
490 ::drizzled::XID *xid); /* in: X/Open XA transaction identification */
491
492 virtual Cursor *create(Table &table)
493 {
494 return new ha_innobase(*this, table);
495 }
496
497 /*********************************************************************
498 Removes all tables in the named database inside InnoDB. */
499 bool
501 /*===================*/
502 /* out: error number */
503 const identifier::Schema &identifier); /* in: database path; inside InnoDB the name
504 of the last directory in the path is used as
505 the database name: for example, in 'mysql/data/test'
506 the database name is 'test' */
507
508 /********************************************************************
509 Flushes InnoDB logs to disk and makes a checkpoint. Really, a commit flushes
510 the logs, and the name of this function should be innobase_checkpoint. */
511 virtual
512 bool
513 flush_logs();
514 /*================*/
515 /* out: TRUE if error */
516
517 /****************************************************************************
518 Implements the SHOW INNODB STATUS command. Sends the output of the InnoDB
519 Monitor to the client. */
520 virtual
521 bool
522 show_status(
523 /*===============*/
524 Session* session, /* in: the MySQL query thread of the caller */
525 stat_print_fn *stat_print,
526 enum ha_stat_type stat_type);
527
528 virtual
529 int
531 /*===============================*/
532 /* out: 0 */
533 Session* session); /* in: MySQL thread */
534
535
536 const char** bas_ext() const {
537 return(ha_innobase_exts);
538 }
539
540 UNIV_INTERN int doCreateTable(Session &session,
541 Table &form,
542 const identifier::Table &identifier,
543 const message::Table&);
544 UNIV_INTERN int doRenameTable(Session&, const identifier::Table &from, const identifier::Table &to);
545 UNIV_INTERN int doDropTable(Session &session, const identifier::Table &identifier);
546
547 UNIV_INTERN virtual bool get_error_message(int error, String *buf) const;
548
549 UNIV_INTERN uint32_t max_supported_keys() const;
550 UNIV_INTERN uint32_t max_supported_key_length() const;
551 UNIV_INTERN uint32_t max_supported_key_part_length() const;
552
553
554 UNIV_INTERN uint32_t index_flags(drizzled::message::Table::Index::IndexType) const
555 {
556 return (HA_READ_NEXT |
557 HA_READ_PREV |
558 HA_READ_ORDER |
559 HA_READ_RANGE |
560 HA_KEYREAD_ONLY);
561 }
562
563 int doGetTableDefinition(drizzled::Session& session,
564 const identifier::Table &identifier,
565 drizzled::message::Table &table_proto);
566
567 bool doDoesTableExist(drizzled::Session& session, const identifier::Table &identifier);
568
569 void doGetTableIdentifiers(drizzled::CachedDirectory &directory,
570 const drizzled::identifier::Schema &schema_identifier,
571 drizzled::identifier::table::vector &set_of_identifiers);
572 bool validateCreateTableOption(const std::string &key, const std::string &state);
573 void dropTemporarySchema();
574
575};
576
577
578bool InnobaseEngine::validateCreateTableOption(const std::string &key, const std::string &state)
579{
580 if (boost::iequals(key, "ROW_FORMAT"))
581 {
582 if (boost::iequals(state, "COMPRESSED"))
583 return true;
584
585 if (boost::iequals(state, "COMPACT"))
586 return true;
587
588 if (boost::iequals(state, "DYNAMIC"))
589 return true;
590
591 if (boost::iequals(state, "REDUNDANT"))
592 return true;
593 }
594
595 return false;
596}
597
598void InnobaseEngine::doGetTableIdentifiers(drizzled::CachedDirectory &directory,
599 const drizzled::identifier::Schema &schema_identifier,
600 drizzled::identifier::table::vector &set_of_identifiers)
601{
602 CachedDirectory::Entries entries= directory.getEntries();
603
604 std::string search_string(schema_identifier.getSchemaName());
605
606 boost::algorithm::to_lower(search_string);
607
608 if (search_string.compare("data_dictionary") == 0)
609 {
610 set_of_identifiers.push_back(identifier::Table(
611 catalog::local_identifier(),
612 schema_identifier.getSchemaName(),
613 "SYS_REPLICATION_LOG"));
614 }
615
616 for (CachedDirectory::Entries::iterator entry_iter= entries.begin();
617 entry_iter != entries.end(); ++entry_iter)
618 {
619 CachedDirectory::Entry *entry= *entry_iter;
620 const string *filename= &entry->filename;
621
622 assert(filename->size());
623
624 const char *ext= strchr(filename->c_str(), '.');
625
626 if (ext == NULL || system_charset_info->strcasecmp(ext, plugin::defaultTableDefinitionFileExt().c_str()) ||
627 (filename->compare(0, strlen(TMP_FILE_PREFIX), TMP_FILE_PREFIX) == 0))
628 { }
629 else
630 {
631 std::string path;
632 path+= directory.getPath();
633 path+= FN_LIBCHAR;
634 path+= entry->filename;
635
636 message::Table definition;
637 if (StorageEngine::readTableFile(path, definition))
638 {
639 /*
640 Using schema_identifier here to stop unused warning, could use
641 definition.schema() instead
642 */
643 identifier::Table identifier(schema_identifier, definition.name());
644 set_of_identifiers.push_back(identifier);
645 }
646 }
647 }
648}
649
650bool InnobaseEngine::doDoesTableExist(Session &session, const identifier::Table &identifier)
651{
652 string proto_path(identifier.getPath());
653 proto_path.append(plugin::defaultTableDefinitionFileExt());
654
655 if (session.getMessageCache().doesTableMessageExist(identifier))
656 return true;
657
658 std::string search_string(identifier.getPath());
659 boost::algorithm::to_lower(search_string);
660
661 if (search_string.compare("data_dictionary/sys_replication_log") == 0)
662 return true;
663
664 if (access(proto_path.c_str(), F_OK))
665 {
666 return false;
667 }
668
669 return true;
670}
671
672int InnobaseEngine::doGetTableDefinition(Session &session,
673 const identifier::Table &identifier,
674 message::Table &table_proto)
675{
676 string proto_path(identifier.getPath());
677 proto_path.append(plugin::defaultTableDefinitionFileExt());
678
679 // First we check the temporary tables.
680 if (session.getMessageCache().getTableMessage(identifier, table_proto))
681 return EEXIST;
682
683 if (read_replication_log_table_message(identifier.getTableName().c_str(), &table_proto) == 0)
684 return EEXIST;
685
686 if (access(proto_path.c_str(), F_OK))
687 {
688 return errno;
689 }
690
691 if (StorageEngine::readTableFile(proto_path, table_proto))
692 return EEXIST;
693
694 return ENOENT;
695}
696
697
698/************************************************************/
701static
702uint
704/*=============================*/
705 const char* format_name);
707/************************************************************/
711static
712int
714/*================================*/
715 const char* format_max);
716
717static const char innobase_engine_name[]= "InnoDB";
718
719
720/*****************************************************************/
722static
723void
725/*================*/
726 trx_t* trx);
727
728static drizzle_show_var innodb_status_variables[]= {
729 {"buffer_pool_pages_data",
730 (char*) &export_vars.innodb_buffer_pool_pages_data, SHOW_LONG},
731 {"buffer_pool_pages_dirty",
732 (char*) &export_vars.innodb_buffer_pool_pages_dirty, SHOW_LONG},
733 {"buffer_pool_pages_flushed",
734 (char*) &export_vars.innodb_buffer_pool_pages_flushed, SHOW_LONG},
735 {"buffer_pool_pages_free",
736 (char*) &export_vars.innodb_buffer_pool_pages_free, SHOW_LONG},
737#ifdef UNIV_DEBUG
738 {"buffer_pool_pages_latched",
739 (char*) &export_vars.innodb_buffer_pool_pages_latched, SHOW_LONG},
740#endif /* UNIV_DEBUG */
741 {"buffer_pool_pages_misc",
742 (char*) &export_vars.innodb_buffer_pool_pages_misc, SHOW_LONG},
743 {"buffer_pool_pages_total",
744 (char*) &export_vars.innodb_buffer_pool_pages_total, SHOW_LONG},
745 {"buffer_pool_read_ahead",
746 (char*) &export_vars.innodb_buffer_pool_read_ahead, SHOW_LONG},
747 {"buffer_pool_read_ahead_evicted",
748 (char*) &export_vars.innodb_buffer_pool_read_ahead_evicted, SHOW_LONG},
749 {"buffer_pool_read_requests",
750 (char*) &export_vars.innodb_buffer_pool_read_requests, SHOW_LONG},
751 {"buffer_pool_reads",
752 (char*) &export_vars.innodb_buffer_pool_reads, SHOW_LONG},
753 {"buffer_pool_wait_free",
754 (char*) &export_vars.innodb_buffer_pool_wait_free, SHOW_LONG},
755 {"buffer_pool_write_requests",
756 (char*) &export_vars.innodb_buffer_pool_write_requests, SHOW_LONG},
757 {"data_fsyncs",
758 (char*) &export_vars.innodb_data_fsyncs, SHOW_LONG},
759 {"data_pending_fsyncs",
760 (char*) &export_vars.innodb_data_pending_fsyncs, SHOW_LONG},
761 {"data_pending_reads",
762 (char*) &export_vars.innodb_data_pending_reads, SHOW_LONG},
763 {"data_pending_writes",
764 (char*) &export_vars.innodb_data_pending_writes, SHOW_LONG},
765 {"data_read",
766 (char*) &export_vars.innodb_data_read, SHOW_LONG},
767 {"data_reads",
768 (char*) &export_vars.innodb_data_reads, SHOW_LONG},
769 {"data_writes",
770 (char*) &export_vars.innodb_data_writes, SHOW_LONG},
771 {"data_written",
772 (char*) &export_vars.innodb_data_written, SHOW_LONG},
773 {"dblwr_pages_written",
774 (char*) &export_vars.innodb_dblwr_pages_written, SHOW_LONG},
775 {"dblwr_writes",
776 (char*) &export_vars.innodb_dblwr_writes, SHOW_LONG},
777 {"have_atomic_builtins",
778 (char*) &export_vars.innodb_have_atomic_builtins, SHOW_BOOL},
779 {"log_waits",
780 (char*) &export_vars.innodb_log_waits, SHOW_LONG},
781 {"log_write_requests",
782 (char*) &export_vars.innodb_log_write_requests, SHOW_LONG},
783 {"log_writes",
784 (char*) &export_vars.innodb_log_writes, SHOW_LONG},
785 {"os_log_fsyncs",
786 (char*) &export_vars.innodb_os_log_fsyncs, SHOW_LONG},
787 {"os_log_pending_fsyncs",
788 (char*) &export_vars.innodb_os_log_pending_fsyncs, SHOW_LONG},
789 {"os_log_pending_writes",
790 (char*) &export_vars.innodb_os_log_pending_writes, SHOW_LONG},
791 {"os_log_written",
792 (char*) &export_vars.innodb_os_log_written, SHOW_LONG},
793 {"page_size",
794 (char*) &export_vars.innodb_page_size, SHOW_LONG},
795 {"pages_created",
796 (char*) &export_vars.innodb_pages_created, SHOW_LONG},
797 {"pages_read",
798 (char*) &export_vars.innodb_pages_read, SHOW_LONG},
799 {"pages_written",
800 (char*) &export_vars.innodb_pages_written, SHOW_LONG},
801 {"row_lock_current_waits",
802 (char*) &export_vars.innodb_row_lock_current_waits, SHOW_LONG},
803 {"row_lock_time",
804 (char*) &export_vars.innodb_row_lock_time, SHOW_LONGLONG},
805 {"row_lock_time_avg",
806 (char*) &export_vars.innodb_row_lock_time_avg, SHOW_LONG},
807 {"row_lock_time_max",
808 (char*) &export_vars.innodb_row_lock_time_max, SHOW_LONG},
809 {"row_lock_waits",
810 (char*) &export_vars.innodb_row_lock_waits, SHOW_LONG},
811 {"rows_deleted",
812 (char*) &export_vars.innodb_rows_deleted, SHOW_LONG},
813 {"rows_inserted",
814 (char*) &export_vars.innodb_rows_inserted, SHOW_LONG},
815 {"rows_read",
816 (char*) &export_vars.innodb_rows_read, SHOW_LONG},
817 {"rows_updated",
818 (char*) &export_vars.innodb_rows_updated, SHOW_LONG},
819 {NULL, NULL, SHOW_LONG}
820};
821
822InnodbStatusTool::Generator::Generator(drizzled::Field **fields) :
823 plugin::TableFunction::Generator(fields)
824{
826 status_var_ptr= innodb_status_variables;
827}
828
829bool InnodbStatusTool::Generator::populate()
830{
831 if (status_var_ptr->name)
832 {
833 std::ostringstream oss;
834 string return_value;
835 const char *value= status_var_ptr->value;
836
837 /* VARIABLE_NAME */
838 push(status_var_ptr->name);
839
840 switch (status_var_ptr->type)
841 {
842 case SHOW_LONG:
843 oss << *(int64_t*) value;
844 return_value= oss.str();
845 break;
846 case SHOW_LONGLONG:
847 oss << *(int64_t*) value;
848 return_value= oss.str();
849 break;
850 case SHOW_BOOL:
851 return_value= *(bool*) value ? "ON" : "OFF";
852 break;
853 default:
854 assert(0);
855 }
856
857 /* VARIABLE_VALUE */
858 if (return_value.length())
859 push(return_value);
860 else
861 push(" ");
862
863 status_var_ptr++;
864
865 return true;
866 }
867 return false;
868}
869
870/* General functions */
871
872/******************************************************************/
882UNIV_INTERN
883ibool
885/*============================*/
887{
888 return false;
889}
890
891/******************************************************************/
894static inline
895void
897/*=========================*/
898 trx_t* trx)
899{
900 if (UNIV_LIKELY(!srv_thread_concurrency)) {
901
902 return;
903 }
904
906}
907
908/******************************************************************/
911static inline
912void
914/*========================*/
915 trx_t* trx)
916{
917 if (UNIV_LIKELY(!trx->declared_to_be_inside_innodb)) {
918
919 return;
920 }
921
923}
924
925/******************************************************************/
930static inline
931void
933/*============================*/
934 trx_t* trx)
935{
936 if (trx->has_search_latch) {
938 }
939
940 if (trx->declared_to_be_inside_innodb) {
941 /* Release our possible ticket in the FIFO */
942
944 }
945}
946
947/******************************************************************/
956UNIV_INTERN
957ibool
959/*===========================*/
960 drizzled::Session *session)
961{
962 return((ibool)session->transaction.all.hasModifiedNonTransData());
963}
964
965/******************************************************************/
968UNIV_INTERN
969ibool
971/*==========*/
972 const drizzled::Session *session)
973{
974 return(session->getSqlCommand() == SQLCOM_SELECT);
975}
976
977/******************************************************************/
981UNIV_INTERN
982ibool
984/*============*/
987{
988 /* TODO: Add support here for per-session value */
989 return(support_xa);
990}
991
992/******************************************************************/
995UNIV_INTERN
996ulong
998/*==================*/
1001{
1002 /* TODO: Add support here for per-session value */
1003 /* According to <drizzle/plugin.h>, passing session == NULL
1004 returns the global value of the session variable. */
1005 return((ulong)lock_wait_timeout.get());
1006}
1007
1008/******************************************************************/
1010UNIV_INTERN
1011void
1013/*===================*/
1014 drizzled::Session* in_session,
1015 ulint value)
1016{
1017 if (in_session)
1018 in_session->times.utime_after_lock+= value;
1019}
1020
1021/********************************************************************/
1024static inline
1025trx_t*&
1027/*=======*/
1028 Session* session)
1029{
1030 return *(trx_t**) session->getEngineData(innodb_engine_ptr);
1031}
1032
1033
1034plugin::ReplicationReturnCode ReplicationLog::apply(Session &session,
1035 const message::Transaction &message)
1036{
1037 size_t message_byte_length= message.ByteSizeLong();
1038 char *data= new char[message_byte_length];
1039
1040 message.SerializeToArray(data, static_cast<int>(message_byte_length));
1041
1042 trx_t *trx= session_to_trx(&session);
1043
1044 uint64_t trx_id= message.transaction_context().transaction_id();
1045 uint32_t seg_id= message.segment_id();
1046 uint64_t end_timestamp= message.transaction_context().end_timestamp();
1047 bool is_end_segment= message.end_segment();
1048 trx->log_commit_id= TRUE;
1049
1050 string server_uuid= session.getServerUUID();
1051 string originating_server_uuid= session.getOriginatingServerUUID();
1052 uint64_t originating_commit_id= session.getOriginatingCommitID();
1053 bool use_originating_server_uuid= session.isOriginatingServerUUIDSet();
1054
1055 ulint error= insert_replication_message(data, message_byte_length, trx, trx_id,
1056 end_timestamp, is_end_segment, seg_id, server_uuid.c_str(),
1057 use_originating_server_uuid, originating_server_uuid.c_str(),
1058 originating_commit_id);
1059
1060 (void)error;
1061
1062 delete[] data;
1063
1064 return plugin::SUCCESS;
1065}
1066
1067/********************************************************************/
1072int
1074/*===============================*/
1075 Session* session)
1076{
1077 trx_t* trx;
1078
1079 assert(this == innodb_engine_ptr);
1080
1081 if (!innodb_inited) {
1082
1083 return(0);
1084 }
1085
1086 trx = session_to_trx(session);
1087
1088 if (trx) {
1090 }
1091 return(0);
1092}
1093
1094/********************************************************************/
1099static inline
1100void
1102/*=======================*/
1103{
1104 innobase_active_counter++;
1105
1106 if ((innobase_active_counter % INNOBASE_WAKE_INTERVAL) == 0) {
1108 }
1109}
1110
1111/********************************************************************/
1116UNIV_INTERN
1117int
1119/*========================*/
1120 int error,
1121 ulint flags,
1122 Session* session)
1123{
1124 switch (error) {
1125 case DB_SUCCESS:
1126 return(0);
1127
1128 case DB_INTERRUPTED:
1129 my_error(ER_QUERY_INTERRUPTED, MYF(0));
1130 /* fall through */
1131
1132 case DB_FOREIGN_EXCEED_MAX_CASCADE:
1133 push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1134 HA_ERR_ROW_IS_REFERENCED,
1135 "InnoDB: Cannot delete/update "
1136 "rows with cascading foreign key "
1137 "constraints that exceed max "
1138 "depth of %d. Please "
1139 "drop extra constraints and try "
1141 /* fall through */
1142
1143 case DB_ERROR:
1144 default:
1145 return(-1); /* unspecified error */
1146
1147 case DB_DUPLICATE_KEY:
1148 /* Be cautious with returning this error, since
1149 mysql could re-enter the storage layer to get
1150 duplicated key info, the operation requires a
1151 valid table handle and/or transaction information,
1152 which might not always be available in the error
1153 handling stage. */
1154 return(HA_ERR_FOUND_DUPP_KEY);
1155
1156 case DB_FOREIGN_DUPLICATE_KEY:
1157 return(HA_ERR_FOREIGN_DUPLICATE_KEY);
1158
1159 case DB_MISSING_HISTORY:
1160 return(HA_ERR_TABLE_DEF_CHANGED);
1161
1162 case DB_RECORD_NOT_FOUND:
1163 return(HA_ERR_NO_ACTIVE_RECORD);
1164
1165 case DB_DEADLOCK:
1166 /* Since we rolled back the whole transaction, we must
1167 tell it also to MySQL so that MySQL knows to empty the
1168 cached binlog for this transaction */
1169
1170 session->markTransactionForRollback(TRUE);
1171
1172 return(HA_ERR_LOCK_DEADLOCK);
1173
1174 case DB_LOCK_WAIT_TIMEOUT:
1175 /* Starting from 5.0.13, we let MySQL just roll back the
1176 latest SQL statement in a lock wait timeout. Previously, we
1177 rolled back the whole transaction. */
1178
1179 session->markTransactionForRollback((bool)row_rollback_on_timeout);
1180
1181 return(HA_ERR_LOCK_WAIT_TIMEOUT);
1182
1183 case DB_NO_REFERENCED_ROW:
1184 return(HA_ERR_NO_REFERENCED_ROW);
1185
1186 case DB_ROW_IS_REFERENCED:
1187 return(HA_ERR_ROW_IS_REFERENCED);
1188
1189 case DB_CANNOT_ADD_CONSTRAINT:
1190 case DB_CHILD_NO_INDEX:
1191 case DB_PARENT_NO_INDEX:
1192 return(HA_ERR_CANNOT_ADD_FOREIGN);
1193
1194 case DB_CANNOT_DROP_CONSTRAINT:
1195
1196 return(HA_ERR_ROW_IS_REFERENCED); /* TODO: This is a bit
1197 misleading, a new MySQL error
1198 code should be introduced */
1199
1200 case DB_COL_APPEARS_TWICE_IN_INDEX:
1201 case DB_CORRUPTION:
1202 return(HA_ERR_CRASHED);
1203
1204 case DB_OUT_OF_FILE_SPACE:
1205 return(HA_ERR_RECORD_FILE_FULL);
1206
1207 case DB_TABLE_IS_BEING_USED:
1208 return(HA_ERR_WRONG_COMMAND);
1209
1210 case DB_TABLE_NOT_FOUND:
1211 return(HA_ERR_NO_SUCH_TABLE);
1212
1213 case DB_TOO_BIG_RECORD:
1214 my_error(ER_TOO_BIG_ROWSIZE, MYF(0),
1216 return(HA_ERR_TO_BIG_ROW);
1217
1218 case DB_NO_SAVEPOINT:
1219 return(HA_ERR_NO_SAVEPOINT);
1220
1221 case DB_LOCK_TABLE_FULL:
1222 /* Since we rolled back the whole transaction, we must
1223 tell it also to MySQL so that MySQL knows to empty the
1224 cached binlog for this transaction */
1225
1226 session->markTransactionForRollback(TRUE);
1227
1228 return(HA_ERR_LOCK_TABLE_FULL);
1229
1230 case DB_PRIMARY_KEY_IS_NULL:
1231 return(ER_PRIMARY_CANT_HAVE_NULL);
1232
1233 case DB_TOO_MANY_CONCURRENT_TRXS:
1234
1235 /* Once MySQL add the appropriate code to errmsg.txt then
1236 we can get rid of this #ifdef. NOTE: The code checked by
1237 the #ifdef is the suggested name for the error condition
1238 and the actual error code name could very well be different.
1239 This will require some monitoring, ie. the status
1240 of this request on our part.*/
1241
1242 /* New error code HA_ERR_TOO_MANY_CONCURRENT_TRXS is only
1243 available in 5.1.38 and later, but the plugin should still
1244 work with previous versions of MySQL.
1245 In Drizzle we seem to not have this yet.
1246 */
1247#ifdef HA_ERR_TOO_MANY_CONCURRENT_TRXS
1248 return(HA_ERR_TOO_MANY_CONCURRENT_TRXS);
1249#else /* HA_ERR_TOO_MANY_CONCURRENT_TRXS */
1250 return(HA_ERR_RECORD_FILE_FULL);
1251#endif /* HA_ERR_TOO_MANY_CONCURRENT_TRXS */
1252 case DB_UNSUPPORTED:
1253 return(HA_ERR_UNSUPPORTED);
1254 }
1255}
1256
1257
1258/*************************************************************/
1260UNIV_INTERN
1261void
1263/*=====================*/
1264 FILE* f,
1265 drizzled::Session *in_session,
1266 uint )
1268{
1269 drizzled::identifier::user::ptr user_identifier(in_session->user());
1270
1271 fprintf(f,
1272 "Drizzle thread %" PRIu64 ", query id %" PRIu64 ", %s, %s, %s ",
1273 static_cast<uint64_t>(in_session->getSessionId()),
1274 static_cast<uint64_t>(in_session->getQueryId()),
1275 getServerHostname().c_str(),
1276 user_identifier->address().c_str(),
1277 user_identifier->username().c_str()
1278 );
1279 fprintf(f, "\n%s", in_session->getQueryString()->c_str());
1280 putc('\n', f);
1281}
1282
1283/******************************************************************/
1285UNIV_INTERN
1286void
1288/*====================*/
1289 ulint cset,
1290 ulint* mbminlen,
1291 ulint* mbmaxlen)
1292{
1293 charset_info_st* cs;
1294 ut_ad(cset < 256);
1295 ut_ad(mbminlen);
1296 ut_ad(mbmaxlen);
1297
1298 cs = all_charsets[cset];
1299 if (cs) {
1300 *mbminlen = cs->mbminlen;
1301 *mbmaxlen = cs->mbmaxlen;
1302 ut_ad(*mbminlen < DATA_MBMAX);
1303 ut_ad(*mbmaxlen < DATA_MBMAX);
1304 } else {
1305 ut_a(cset == 0);
1306 *mbminlen = *mbmaxlen = 0;
1307 }
1308}
1309
1310/******************************************************************/
1312UNIV_INTERN
1313void
1315/*===========================*/
1316 const void*,
1317 char* to,
1318 const char* from,
1319 ulint len)
1320{
1321 strncpy(to, from, len);
1322}
1323
1324/******************************************************************/
1326UNIV_INTERN
1327void
1329/*=====================*/
1330 const void*,
1331 char* to,
1332 const char* from,
1333 ulint len)
1334{
1335 strncpy(to, from, len);
1336}
1337
1338/******************************************************************/
1341UNIV_INTERN
1342int
1344/*================*/
1345 const char* a,
1346 const char* b)
1347{
1348 return(system_charset_info->strcasecmp(a, b));
1349}
1350
1351/******************************************************************/
1354const char*
1356/*==============*/
1357 const char* path_name)
1358{
1359 const char* name = path_name + drizzled::internal::dirname_length(path_name);
1360
1361 return((name) ? name : "null");
1362}
1363
1364/******************************************************************/
1366UNIV_INTERN
1367void
1369/*================*/
1370 char* a)
1371{
1372 system_charset_info->casedn_str(a);
1373}
1374
1375UNIV_INTERN
1376bool
1377innobase_isspace(
1378 const void* cs,
1379 char char_to_test)
1380{
1381 return static_cast<const charset_info_st*>(cs)->isspace(char_to_test);
1382}
1383
1384#if defined (__WIN__) && defined (MYSQL_DYNAMIC_PLUGIN)
1385/*******************************************************************/
1388void __cdecl
1389_dosmaperr(
1390 unsigned long);
1391
1392/*********************************************************************/
1395UNIV_INTERN
1396int
1398/*========================*/
1399{
1400 int fd; /* handle of opened file */
1401 HANDLE osfh; /* OS handle of opened file */
1402 char* tmpdir; /* point to the directory
1403 where to create file */
1404 TCHAR path_buf[MAX_PATH - 14]; /* buffer for tmp file path.
1405 The length cannot be longer
1406 than MAX_PATH - 14, or
1407 GetTempFileName will fail. */
1408 char filename[MAX_PATH]; /* name of the tmpfile */
1409 DWORD fileaccess = GENERIC_READ /* OS file access */
1410 | GENERIC_WRITE
1411 | DELETE;
1412 DWORD fileshare = FILE_SHARE_READ /* OS file sharing mode */
1413 | FILE_SHARE_WRITE
1414 | FILE_SHARE_DELETE;
1415 DWORD filecreate = CREATE_ALWAYS; /* OS method of open/create */
1416 DWORD fileattrib = /* OS file attribute flags */
1417 FILE_ATTRIBUTE_NORMAL
1418 | FILE_FLAG_DELETE_ON_CLOSE
1419 | FILE_ATTRIBUTE_TEMPORARY
1420 | FILE_FLAG_SEQUENTIAL_SCAN;
1421
1422 tmpdir = my_tmpdir(&mysql_tmpdir_list);
1423
1424 /* The tmpdir parameter can not be NULL for GetTempFileName. */
1425 if (!tmpdir) {
1426 uint ret;
1427
1428 /* Use GetTempPath to determine path for temporary files. */
1429 ret = GetTempPath(sizeof(path_buf), path_buf);
1430 if (ret > sizeof(path_buf) || (ret == 0)) {
1431
1432 _dosmaperr(GetLastError()); /* map error */
1433 return(-1);
1434 }
1435
1436 tmpdir = path_buf;
1437 }
1438
1439 /* Use GetTempFileName to generate a unique filename. */
1440 if (!GetTempFileName(tmpdir, "ib", 0, filename)) {
1441
1442 _dosmaperr(GetLastError()); /* map error */
1443 return(-1);
1444 }
1445
1446 /* Open/Create the file. */
1447 osfh = CreateFile(filename, fileaccess, fileshare, NULL,
1448 filecreate, fileattrib, NULL);
1449 if (osfh == INVALID_HANDLE_VALUE) {
1450
1451 /* open/create file failed! */
1452 _dosmaperr(GetLastError()); /* map error */
1453 return(-1);
1454 }
1455
1456 do {
1457 /* Associates a CRT file descriptor with the OS file handle. */
1458 fd = _open_osfhandle((intptr_t) osfh, 0);
1459 } while (fd == -1 && errno == EINTR);
1460
1461 if (fd == -1) {
1462 /* Open failed, close the file handle. */
1463
1464 _dosmaperr(GetLastError()); /* map error */
1465 CloseHandle(osfh); /* no need to check if
1466 CloseHandle fails */
1467 }
1468
1469 return(fd);
1470}
1471#else
1472/*********************************************************************/
1475UNIV_INTERN
1476int
1478/*========================*/
1479{
1480 int fd2 = -1;
1481 int fd = ::drizzled::tmpfile("ib");
1482 if (fd >= 0) {
1483 /* Copy the file descriptor, so that the additional resources
1484 allocated by create_temp_file() can be freed by invoking
1485 internal::my_close().
1486
1487 Because the file descriptor returned by this function
1488 will be passed to fdopen(), it will be closed by invoking
1489 fclose(), which in turn will invoke close() instead of
1490 internal::my_close(). */
1491 fd2 = dup(fd);
1492 if (fd2 < 0) {
1493 errno=errno;
1494 my_error(EE_OUT_OF_FILERESOURCES,
1495 MYF(ME_BELL+ME_WAITTANG),
1496 "ib*", errno);
1497 }
1498 internal::my_close(fd, MYF(MY_WME));
1499 }
1500 return(fd2);
1501}
1502#endif /* defined (__WIN__) && defined (MYSQL_DYNAMIC_PLUGIN) */
1503
1504
1505/*******************************************************************/
1514UNIV_INTERN
1515ulint
1517/*================*/
1518 const char* data,
1519 ulint data_len,
1521 ulint ,
1522 char* buf,
1523 ulint buf_size)
1525{
1526 return(ut_str_sql_format(data, data_len, buf, buf_size));
1527}
1528
1529/*********************************************************************/
1546static
1547uint64_t
1549/*==================*/
1550 uint64_t current,
1551 uint64_t increment,
1552 uint64_t offset,
1553 uint64_t max_value)
1554{
1555 uint64_t next_value;
1556
1557 /* Should never be 0. */
1558 ut_a(increment > 0);
1559
1560 /* According to MySQL documentation, if the offset is greater than
1561 the increment then the offset is ignored. */
1562 if (offset > increment) {
1563 offset = 0;
1564 }
1565
1566 if (max_value <= current) {
1567 next_value = max_value;
1568 } else if (offset <= 1) {
1569 /* Offset 0 and 1 are the same, because there must be at
1570 least one node in the system. */
1571 if (max_value - current <= increment) {
1572 next_value = max_value;
1573 } else {
1574 next_value = current + increment;
1575 }
1576 } else if (max_value > current) {
1577 if (current > offset) {
1578 next_value = ((current - offset) / increment) + 1;
1579 } else {
1580 next_value = ((offset - current) / increment) + 1;
1581 }
1582
1583 ut_a(increment > 0);
1584 ut_a(next_value > 0);
1585
1586 /* Check for multiplication overflow. */
1587 if (increment > (max_value / next_value)) {
1588
1589 next_value = max_value;
1590 } else {
1591 next_value *= increment;
1592
1593 ut_a(max_value >= next_value);
1594
1595 /* Check for overflow. */
1596 if (max_value - next_value <= offset) {
1597 next_value = max_value;
1598 } else {
1599 next_value += offset;
1600 }
1601 }
1602 } else {
1603 next_value = max_value;
1604 }
1605
1606 ut_a(next_value <= max_value);
1607
1608 return(next_value);
1609}
1610
1611/*********************************************************************/
1613static
1614void
1616/*==============*/
1617 Session* session,
1618 trx_t* trx)
1619{
1620 assert(session == trx->mysql_thd);
1621
1622 trx->check_foreigns = !session_test_options(
1623 session, OPTION_NO_FOREIGN_KEY_CHECKS);
1624
1625 trx->check_unique_secondary = !session_test_options(
1626 session, OPTION_RELAXED_UNIQUE_CHECKS);
1627
1628 return;
1629}
1630
1631/*********************************************************************/
1634UNIV_INTERN
1635trx_t*
1637/*==================*/
1638 Session* session)
1639{
1640 trx_t* trx;
1641
1642 assert(session != NULL);
1643 assert(EQ_CURRENT_SESSION(session));
1644
1645 trx = trx_allocate_for_mysql();
1646
1647 trx->mysql_thd = session;
1648
1649 innobase_trx_init(session, trx);
1650
1651 return(trx);
1652}
1653
1654/*********************************************************************/
1659static
1660trx_t*
1662/*=============*/
1663 Session* session)
1664{
1665 trx_t*& trx = session_to_trx(session);
1666
1667 ut_ad(EQ_CURRENT_SESSION(session));
1668
1669 if (trx == NULL) {
1670 trx = innobase_trx_allocate(session);
1671 } else if (UNIV_UNLIKELY(trx->magic_n != TRX_MAGIC_N)) {
1673 ut_error;
1674 }
1675
1676 innobase_trx_init(session, trx);
1677
1678 return(trx);
1679}
1680
1681
1682/*********************************************************************/
1684UNIV_INTERN
1685ha_innobase::ha_innobase(plugin::StorageEngine &engine_arg,
1686 Table &table_arg)
1687 :Cursor(engine_arg, table_arg),
1688 primary_key(0), /* needs initialization because index_flags() may be called
1689 before this is set to the real value. It's ok to have any
1690 value here because it doesn't matter if we return the
1691 HA_DO_INDEX_COND_PUSHDOWN bit from those "early" calls */
1692 start_of_scan(0),
1693 num_write_row(0)
1694{}
1695
1696/*********************************************************************/
1698UNIV_INTERN
1702
1703/*********************************************************************/
1707UNIV_INTERN inline
1708void
1710/*====================*/
1711 Session* session)
1712{
1713 trx_t* trx;
1714
1715 assert(session);
1716 trx = check_trx_exists(session);
1717
1718 if (prebuilt->trx != trx) {
1719
1721 }
1722
1723 user_session = session;
1724}
1725
1726/*****************************************************************/
1730static
1731char*
1733/*========================*/
1734 char* buf,
1735 ulint buflen,
1736 const char* id,
1737 ulint idlen,
1738 drizzled::Session *session,
1739 ibool file_id)
1741{
1742 char nz[NAME_LEN + 1];
1743 const size_t nz2_size= NAME_LEN + 1 + srv_mysql50_table_name_prefix.size();
1744 boost::scoped_array<char> nz2(new char[nz2_size]);
1745
1746 const char* s = id;
1747 int q;
1748
1749 if (file_id) {
1750 /* Decode the table name. The filename_to_tablename()
1751 function expects a NUL-terminated string. The input and
1752 output strings buffers must not be shared. */
1753
1754 if (UNIV_UNLIKELY(idlen > (sizeof nz) - 1)) {
1755 idlen = (sizeof nz) - 1;
1756 }
1757
1758 memcpy(nz, id, idlen);
1759 nz[idlen] = 0;
1760
1761 s = nz2.get();
1762 idlen = identifier::Table::filename_to_tablename(nz, nz2.get(), nz2_size);
1763 }
1764
1765 /* See if the identifier needs to be quoted. */
1766 if (UNIV_UNLIKELY(!session)) {
1767 q = '"';
1768 } else {
1769 q = get_quote_char_for_identifier();
1770 }
1771
1772 if (q == EOF) {
1773 if (UNIV_UNLIKELY(idlen > buflen)) {
1774 idlen = buflen;
1775 }
1776 memcpy(buf, s, idlen);
1777 return(buf + idlen);
1778 }
1779
1780 /* Quote the identifier. */
1781 if (buflen < 2) {
1782 return(buf);
1783 }
1784
1785 *buf++ = q;
1786 buflen--;
1787
1788 for (; idlen; idlen--) {
1789 int c = *s++;
1790 if (UNIV_UNLIKELY(c == q)) {
1791 if (UNIV_UNLIKELY(buflen < 3)) {
1792 break;
1793 }
1794
1795 *buf++ = c;
1796 *buf++ = c;
1797 buflen -= 2;
1798 } else {
1799 if (UNIV_UNLIKELY(buflen < 2)) {
1800 break;
1801 }
1802
1803 *buf++ = c;
1804 buflen--;
1805 }
1806 }
1807
1808 *buf++ = q;
1809 return(buf);
1810}
1811
1812/*****************************************************************/
1816UNIV_INTERN
1817char*
1819/*==================*/
1820 char* buf,
1821 ulint buflen,
1822 const char* id,
1823 ulint idlen,
1824 drizzled::Session *session,
1825 ibool table_id)
1827{
1828 char* s = buf;
1829 const char* bufend = buf + buflen;
1830
1831 if (table_id) {
1832 const char* catalog_skip= (const char*) memchr(id, '/', idlen);
1833 if (catalog_skip)
1834 {
1835 idlen = idlen - (catalog_skip - id);
1836 id = catalog_skip + 1;
1837 }
1838 const char* slash = (const char*) memchr(id, '/', idlen);
1839 if (!slash) {
1840
1841 goto no_db_name;
1842 }
1843
1844 /* Print the database name and table name separately. */
1845 s = innobase_convert_identifier(s, bufend - s, id, slash - id,
1846 session, TRUE);
1847 if (UNIV_LIKELY(s < bufend)) {
1848 *s++ = '.';
1849 s = innobase_convert_identifier(s, bufend - s,
1850 slash + 1, idlen
1851 - (slash - id) - 1,
1852 session, TRUE);
1853 }
1854 } else if (UNIV_UNLIKELY(*id == TEMP_INDEX_PREFIX)) {
1855 /* Temporary index name (smart ALTER TABLE) */
1856 const char temp_index_suffix[]= "--temporary--";
1857
1858 s = innobase_convert_identifier(buf, buflen, id + 1, idlen - 1,
1859 session, FALSE);
1860 if (s - buf + (sizeof temp_index_suffix - 1) < buflen) {
1861 memcpy(s, temp_index_suffix,
1862 sizeof temp_index_suffix - 1);
1863 s += sizeof temp_index_suffix - 1;
1864 }
1865 } else {
1866no_db_name:
1867 s = innobase_convert_identifier(buf, buflen, id, idlen,
1868 session, table_id);
1869 }
1870
1871 return(s);
1872
1873}
1874
1875/**********************************************************************/
1878UNIV_INTERN
1879ibool
1881/*===============*/
1882 trx_t* trx)
1883{
1884 return(trx && trx->mysql_thd && trx->mysql_thd->getKilled());
1885}
1886
1887/**********************************************************************/
1890UNIV_INTERN
1891ibool
1893/*==========*/
1894 trx_t* trx)
1895{
1896 return(trx && trx->mysql_thd
1897 && true);
1898}
1899
1900/**************************************************************/
1903static
1904void
1906/*===========*/
1907 row_prebuilt_t* prebuilt)
1908{
1909 prebuilt->keep_other_fields_on_keyread = 0;
1910 prebuilt->read_just_key = 0;
1911}
1912
1913template<class T>
1914void align_value(T& value, size_t align_val= 1024)
1915{
1916 value= value - (value % align_val);
1917}
1918
1919static void auto_extend_update(Session *, sql_var_t)
1920{
1921 srv_auto_extend_increment= innodb_auto_extend_increment.get();
1922}
1923
1924static void io_capacity_update(Session *, sql_var_t)
1925{
1926 srv_io_capacity= innodb_io_capacity.get();
1927}
1928
1929static void purge_batch_update(Session *, sql_var_t)
1930{
1931 srv_purge_batch_size= innodb_purge_batch_size.get();
1932}
1933
1934static void purge_threads_update(Session *, sql_var_t)
1935{
1936 srv_n_purge_threads= innodb_n_purge_threads.get();
1937}
1938
1939static void innodb_adaptive_hash_index_update(Session *, sql_var_t)
1940{
1941 if (btr_search_enabled)
1942 {
1944 } else {
1946 }
1947}
1948
1949static void innodb_old_blocks_pct_update(Session *, sql_var_t)
1950{
1951 innobase_old_blocks_pct= buf_LRU_old_ratio_update(innobase_old_blocks_pct.get(), TRUE);
1952}
1953
1954static void innodb_thread_concurrency_update(Session *, sql_var_t)
1955{
1956 srv_thread_concurrency= innobase_thread_concurrency.get();
1957}
1958
1959static void innodb_rollback_segments_update(Session *, sql_var_t)
1960{
1961 srv_rollback_segments= innobase_rollback_segments.get();
1962}
1963
1964
1965static void innodb_sync_spin_loops_update(Session *, sql_var_t)
1966{
1967 srv_n_spin_wait_rounds= innodb_sync_spin_loops.get();
1968}
1969
1970static void innodb_spin_wait_delay_update(Session *, sql_var_t)
1971{
1972 srv_spin_wait_delay= innodb_spin_wait_delay.get();
1973}
1974
1975static void innodb_thread_sleep_delay_update(Session *, sql_var_t)
1976{
1977 srv_thread_sleep_delay= innodb_thread_sleep_delay.get();
1978}
1979
1980static void innodb_read_ahead_threshold_update(Session *, sql_var_t)
1981{
1982 srv_read_ahead_threshold= innodb_read_ahead_threshold.get();
1983}
1984
1985static void auto_lru_dump_update(Session *, sql_var_t)
1986{
1987 srv_auto_lru_dump= buffer_pool_restore_at_startup.get();
1988}
1989
1990static void ibuf_active_contract_update(Session *, sql_var_t)
1991{
1992 srv_ibuf_active_contract= ibuf_active_contract.get();
1993}
1994
1995static void ibuf_accel_rate_update(Session *, sql_var_t)
1996{
1997 srv_ibuf_accel_rate= ibuf_accel_rate.get();
1998}
1999
2000static void checkpoint_age_target_update(Session *, sql_var_t)
2001{
2002 srv_checkpoint_age_target= checkpoint_age_target.get();
2003}
2004
2005static void flush_neighbor_pages_update(Session *, sql_var_t)
2006{
2007 srv_flush_neighbor_pages= flush_neighbor_pages.get();
2008}
2009
2010static int innodb_commit_concurrency_validate(Session *session, set_var *var)
2011{
2012 uint64_t new_value= var->getInteger();
2013
2014 if ((innobase_commit_concurrency.get() == 0 && new_value != 0) ||
2015 (innobase_commit_concurrency.get() != 0 && new_value == 0))
2016 {
2017 push_warning_printf(session,
2018 DRIZZLE_ERROR::WARN_LEVEL_WARN,
2019 ER_WRONG_ARGUMENTS,
2020 _("Once InnoDB is running, innodb_commit_concurrency "
2021 "must not change between zero and nonzero."));
2022 return 1;
2023 }
2024 return 0;
2025}
2026
2027/*************************************************************/
2031static
2032int
2034/*=============================*/
2035 Session* ,
2036 set_var *var)
2037{
2038 const char *file_format_input = var->value->str_value.ptr();
2039 if (file_format_input == NULL)
2040 return 1;
2041
2042 if (file_format_input != NULL) {
2043 uint format_id;
2044
2046 file_format_input);
2047
2048 if (format_id <= DICT_TF_FORMAT_MAX) {
2049 innobase_file_format_name =
2051
2052 return(0);
2053 }
2054 }
2055
2056 return(1);
2057}
2058
2059static
2060int
2061innodb_stats_method_validate(
2062/*=============================*/
2063 Session* ,
2064 set_var *var)
2065{
2066 const char *stats_method_input = var->value->str_value.ptr();
2067
2068 if (stats_method_input == NULL)
2069 return 1;
2070
2071 ulint use;
2072
2073 for (use = 0;
2074 use < UT_ARR_SIZE(innodb_stats_method_names);
2075 ++use) {
2076 if (!innobase_strcasecmp(stats_method_input,
2078 {
2079 srv_innodb_stats_method= use;
2080 innodb_stats_method= innodb_stats_method_names[use];
2081 return 0;
2082 }
2083 }
2084
2085 return 1;
2086}
2087
2088
2089/*************************************************************/
2093static
2094int
2096/*=============================*/
2097 Session* ,
2098 set_var *var)
2099{
2100 const char *change_buffering_input = var->value->str_value.ptr();
2101
2102 if (change_buffering_input == NULL)
2103 return 1;
2104
2105 ulint use;
2106
2107 for (use = 0;
2108 use < UT_ARR_SIZE(innobase_change_buffering_values);
2109 ++use) {
2110 if (!innobase_strcasecmp(change_buffering_input,
2112 {
2113 ibuf_use= static_cast<ibuf_use_t>(use);
2114 return 0;
2115 }
2116 }
2117
2118 return 1;
2119}
2120
2121
2122/*************************************************************/
2126static
2127int
2129/*==============================*/
2130 Session* session,
2131 set_var *var)
2132{
2133 const char *file_format_input = var->value->str_value.ptr();
2134 if (file_format_input == NULL)
2135 return 1;
2136
2137 if (file_format_input != NULL) {
2138 int format_id = innobase_file_format_validate_and_set(file_format_input);
2139
2140 if (format_id > DICT_TF_FORMAT_MAX) {
2141 /* DEFAULT is "on", which is invalid at runtime. */
2142 return 1;
2143 }
2144
2145 if (format_id >= 0) {
2146 innobase_file_format_max.assign(
2147 trx_sys_file_format_id_to_name((uint)format_id));
2148
2149 /* Update the max format id in the system tablespace. */
2150 const char *name_buff;
2151
2152 if (trx_sys_file_format_max_set(format_id, &name_buff))
2153 {
2154 errmsg_printf(error::WARN,
2155 " [Info] InnoDB: the file format in the system "
2156 "tablespace is now set to %s.\n", name_buff);
2157 innobase_file_format_max= name_buff;
2158 }
2159 return(0);
2160
2161 } else {
2162 push_warning_printf(session,
2163 DRIZZLE_ERROR::WARN_LEVEL_WARN,
2164 ER_WRONG_ARGUMENTS,
2165 "InnoDB: invalid innodb_file_format_max "
2166 "value; can be any format up to %s "
2167 "or equivalent id of %d",
2170 }
2171 }
2172
2173 return(1);
2174}
2175
2176/*********************************************************************/
2180static
2181int
2183/*================*/
2184 Session*,
2185 set_var* var)
2186{
2187 const char *read_ahead_input = var->value->str_value.ptr();
2188 int res = read_ahead_typelib.find_type(read_ahead_input, TYPELIB::e_none); // e_none is wrong
2189
2190 if (res > 0) {
2191 srv_read_ahead = res - 1;
2192 return 0;
2193 }
2194
2195 return 1;
2196}
2197
2198/*********************************************************************/
2202static
2203int
2205/*==============================*/
2206 Session*,
2207 set_var* var)
2208{
2209 const char *adaptive_flushing_method_input = var->value->str_value.ptr();
2210 int res = adaptive_flushing_method_typelib.find_type(adaptive_flushing_method_input, TYPELIB::e_none); // e_none is wrong
2211
2212 if (res > 0) {
2213 srv_adaptive_flushing_method = res - 1;
2214 return 0;
2215 }
2216 return 1;
2217}
2218
2219
2220/*********************************************************************/
2223static
2224int
2226/*==========*/
2227 module::Context &context)
2228{
2229 int err;
2230 bool ret;
2231 uint format_id;
2232 InnobaseEngine *actuall_engine_ptr;
2233 const module::option_map &vm= context.getOptions();
2234
2235 srv_auto_extend_increment= innodb_auto_extend_increment.get();
2236 srv_io_capacity= innodb_io_capacity.get();
2237 srv_purge_batch_size= innodb_purge_batch_size.get();
2238 srv_n_purge_threads= innodb_n_purge_threads.get();
2239 srv_flush_log_at_trx_commit= innodb_flush_log_at_trx_commit.get();
2240 srv_max_buf_pool_modified_pct= innodb_max_dirty_pages_pct.get();
2241 srv_max_purge_lag= innodb_max_purge_lag.get();
2242 srv_stats_sample_pages= innodb_stats_sample_pages.get();
2243 srv_n_free_tickets_to_enter= innodb_concurrency_tickets.get();
2244 srv_replication_delay= innodb_replication_delay.get();
2245 srv_thread_concurrency= innobase_thread_concurrency.get();
2246 srv_n_spin_wait_rounds= innodb_sync_spin_loops.get();
2247 srv_spin_wait_delay= innodb_spin_wait_delay.get();
2248 srv_thread_sleep_delay= innodb_thread_sleep_delay.get();
2249 srv_read_ahead_threshold= innodb_read_ahead_threshold.get();
2250 srv_auto_lru_dump= buffer_pool_restore_at_startup.get();
2251 srv_ibuf_max_size= ibuf_max_size.get();
2252 srv_ibuf_active_contract= ibuf_active_contract.get();
2253 srv_ibuf_accel_rate= ibuf_accel_rate.get();
2254 srv_checkpoint_age_target= checkpoint_age_target.get();
2255 srv_flush_neighbor_pages= flush_neighbor_pages.get();
2256 srv_rollback_segments= innobase_rollback_segments.get();
2257
2258 srv_read_ahead = read_ahead_typelib.find_type_or_exit(vm["read-ahead"].as<string>().c_str(),
2259 "read_ahead_typelib") + 1;
2260
2261 srv_adaptive_flushing_method = adaptive_flushing_method_typelib.find_type_or_exit(vm["adaptive-flushing-method"].as<string>().c_str(),
2262 "adaptive_flushing_method_typelib") + 1;
2263
2264 /* Inverted Booleans */
2265
2266 innobase_use_checksums= not vm.count("disable-checksums");
2267 innobase_use_doublewrite= not vm.count("disable-doublewrite");
2268 srv_adaptive_flushing= not vm.count("disable-adaptive-flushing");
2269 srv_use_sys_malloc= not vm.count("use-internal-malloc");
2270 srv_use_native_aio= not vm.count("disable-native-aio");
2271 support_xa= not vm.count("disable-xa");
2272 btr_search_enabled= not vm.count("disable-adaptive-hash-index");
2273
2274 /* Hafta do this here because we need to late-bind the default value */
2275 innobase_data_home_dir= vm.count("data-home-dir") ? vm["data-home-dir"].as<string>() : getDataHome().string();
2276
2277 if (vm.count("data-file-path"))
2278 {
2279 innobase_data_file_path= vm["data-file-path"].as<string>();
2280 }
2281
2282
2283 innodb_engine_ptr= actuall_engine_ptr= new InnobaseEngine(innobase_engine_name);
2284
2285 ut_a(DATA_MYSQL_TRUE_VARCHAR == (ulint)DRIZZLE_TYPE_VARCHAR);
2286
2287#ifdef UNIV_DEBUG
2288 static const char test_filename[] = "-@";
2289 const size_t test_tablename_size= sizeof test_filename
2291 boost::scoped_array test_tablename(new char[test_tablename_size]);
2292 if ((test_tablename_size) - 1
2293 != filename_to_tablename(test_filename, test_tablename.get(),
2294 test_tablename_size)
2295 || strncmp(test_tablename.get(),
2298 || strcmp(test_tablename.get()
2300 test_filename)) {
2301 errmsg_printf(error::ERROR, "tablename encoding has been changed");
2302 goto error;
2303 }
2304#endif /* UNIV_DEBUG */
2305
2306 srv_page_size = 0;
2307 srv_page_size_shift = 0;
2308
2309 uint32_t page_size = innobase_page_size.get();
2310 uint32_t log_block_size = innobase_log_block_size.get();
2311
2312 if (innobase_page_size != (1 << 14)) {
2313 uint n_shift;
2314
2315 errmsg_printf(error::WARN,
2316 "InnoDB: Warning: innodb_page_size has been changed from default value 16384. (###EXPERIMENTAL### operation)\n");
2317 for (n_shift = 12; n_shift <= UNIV_PAGE_SIZE_SHIFT_MAX; n_shift++) {
2318 if (innobase_page_size == (1UL << n_shift)) {
2319 srv_page_size_shift = n_shift;
2320 srv_page_size = (1 << srv_page_size_shift);
2321 errmsg_printf(error::WARN,
2322 "InnoDB: The universal page size of the database is set to %lu.\n",
2323 srv_page_size);
2324 break;
2325 }
2326 }
2327 } else {
2328 srv_page_size_shift = 14;
2329 srv_page_size = (1 << srv_page_size_shift);
2330 }
2331
2332 if (!srv_page_size_shift) {
2333 errmsg_printf(error::ERROR,
2334 "InnoDB: Error: %" PRIu32 " is not a valid value for innodb_page_size.\n"
2335 "InnoDB: Error: Valid values are 4096, 8192, and 16384 (default=16384).\n",
2336 page_size);
2337 goto error;
2338 }
2339
2340 srv_log_block_size = 0;
2341 if (log_block_size != (1 << 9)) {
2342 uint n_shift;
2343
2344 errmsg_printf(error::WARN,
2345 "InnoDB: Warning: innodb_log_block_size has been changed from default value 512. (###EXPERIMENTAL### operation)\n");
2346 for (n_shift = 9; n_shift <= UNIV_PAGE_SIZE_SHIFT_MAX; n_shift++) {
2347 if (log_block_size == (1UL << n_shift)) {
2348 srv_log_block_size = (1 << n_shift);
2349 errmsg_printf(error::WARN, "InnoDB: The log block size is set to %" PRIu32 ".\n",
2350 srv_log_block_size);
2351 break;
2352 }
2353 }
2354 } else {
2355 srv_log_block_size = 512;
2356 }
2357
2358 if (!srv_log_block_size) {
2359 errmsg_printf(error::ERROR,
2360 "InnoDB: Error: %" PRIu32 " is not a valid value for innodb_log_block_size.\n"
2361 "InnoDB: Error: A valid value for innodb_log_block_size is\n"
2362 "InnoDB: Error: a power of 2 from 512 to 16384.\n",
2363 log_block_size);
2364 goto error;
2365 }
2366
2367 os_innodb_umask = (ulint)internal::get_my_umask();
2368
2369
2370 /* Set InnoDB initialization parameters according to the values
2371 read from MySQL .cnf file */
2372
2373 /*--------------- Data files -------------------------*/
2374
2375 /* The default dir for data files is the datadir of MySQL */
2376
2377 srv_data_home = (char *)innobase_data_home_dir.c_str();
2378
2379 /* Set default InnoDB data file size to 10 MB and let it be
2380 auto-extending. Thus users can use InnoDB in >= 4.0 without having
2381 to specify any startup options. */
2382
2383 if (innobase_data_file_path.empty())
2384 {
2385 innobase_data_file_path= std::string("ibdata1:10M:autoextend");
2386 }
2387
2388 /* Since InnoDB edits the argument in the next call, we make another
2389 copy of it: */
2390
2391 internal_innobase_data_file_path = strdup(innobase_data_file_path.c_str());
2392
2394 internal_innobase_data_file_path);
2395 if (ret == FALSE) {
2396 errmsg_printf(error::ERROR, "InnoDB: syntax error in innodb_data_file_path");
2397
2398mem_free_and_error:
2400 free(internal_innobase_data_file_path);
2401 goto error;
2402 }
2403
2404 /* -------------- Log files ---------------------------*/
2405
2406 /* The default dir for log files is the datadir of MySQL */
2407
2408 if (vm.count("log-group-home-dir"))
2409 {
2410 innobase_log_group_home_dir= vm["log-group-home-dir"].as<string>();
2411 }
2412 else
2413 {
2414 innobase_log_group_home_dir= getDataHome().string();
2415 }
2416
2417 ret = (bool)
2418 srv_parse_log_group_home_dirs((char *)innobase_log_group_home_dir.c_str());
2419
2420 if (ret == FALSE || innobase_mirrored_log_groups.get() != 1) {
2421 errmsg_printf(error::ERROR, _("syntax error in innodb_log_group_home_dir, or a "
2422 "wrong number of mirrored log groups"));
2423
2424 goto mem_free_and_error;
2425 }
2426
2427
2428 /* Validate the file format by animal name */
2429 if (vm.count("file-format"))
2430 {
2432 vm["file-format"].as<string>().c_str());
2433
2434 if (format_id > DICT_TF_FORMAT_MAX) {
2435
2436 errmsg_printf(error::ERROR, "InnoDB: wrong innodb_file_format.");
2437
2438 goto mem_free_and_error;
2439 }
2440 } else {
2441 /* Set it to the default file format id.*/
2442 format_id = 0;
2443 }
2444
2445 srv_file_format = format_id;
2446
2447 innobase_file_format_name =
2449
2450 /* Check innobase_file_format_check variable */
2451 if (!innobase_file_format_check)
2452 {
2453 /* Set the value to disable checking. */
2455 } else {
2456 /* Set the value to the lowest supported format. */
2458 }
2459
2460 /* Did the user specify a format name that we support?
2461 As a side effect it will update the variable
2462 srv_max_file_format_at_startup */
2463 if (innobase_file_format_validate_and_set(innobase_file_format_max.c_str()) < 0)
2464 {
2465 errmsg_printf(error::ERROR, _("InnoDB: invalid innodb_file_format_max value: "
2466 "should be any value up to %s or its equivalent numeric id"),
2468 goto mem_free_and_error;
2469 }
2470
2471 if (vm.count("change-buffering"))
2472 {
2473 ulint use;
2474
2475 for (use = 0;
2476 use < UT_ARR_SIZE(innobase_change_buffering_values);
2477 use++) {
2479 innobase_change_buffering.c_str(),
2481 ibuf_use = static_cast<ibuf_use_t>(use);
2482 goto innobase_change_buffering_inited_ok;
2483 }
2484 }
2485
2486 errmsg_printf(error::ERROR, "InnoDB: invalid value innodb_change_buffering=%s",
2487 vm["change-buffering"].as<string>().c_str());
2488 goto mem_free_and_error;
2489 }
2490
2491innobase_change_buffering_inited_ok:
2492 ut_a((ulint) ibuf_use < UT_ARR_SIZE(innobase_change_buffering_values));
2493 innobase_change_buffering = innobase_change_buffering_values[ibuf_use];
2494
2495 /* --------------------------------------------------*/
2496
2497 if (vm.count("flush-method") != 0)
2498 {
2499 srv_file_flush_method_str = (char *)vm["flush-method"].as<string>().c_str();
2500 }
2501
2502 srv_n_log_groups = (ulint) innobase_mirrored_log_groups;
2503 srv_n_log_files = (ulint) innobase_log_files_in_group;
2504 srv_log_file_size = (ulint) innobase_log_file_size;
2505
2506 srv_log_buffer_size = (ulint) innobase_log_buffer_size;
2507
2508 srv_buf_pool_size = (ulint) innobase_buffer_pool_size;
2509 srv_buf_pool_instances = (ulint) innobase_buffer_pool_instances;
2510
2511 srv_mem_pool_size = (ulint) innobase_additional_mem_pool_size;
2512
2513 srv_n_read_io_threads = (ulint) innobase_read_io_threads;
2514 srv_n_write_io_threads = (ulint) innobase_write_io_threads;
2515
2516 srv_read_ahead &= 3;
2517 srv_adaptive_flushing_method %= 3;
2518
2519 srv_force_recovery = (ulint) innobase_force_recovery;
2520
2521 srv_use_doublewrite_buf = (ibool) innobase_use_doublewrite;
2522 srv_use_checksums = (ibool) innobase_use_checksums;
2523
2524#ifdef HAVE_LARGE_PAGES
2525 if ((os_use_large_pages = (ibool) my_use_large_pages))
2526 os_large_page_size = (ulint) opt_large_page_size;
2527#endif
2528
2529 row_rollback_on_timeout = (ibool) innobase_rollback_on_timeout;
2530
2531 srv_locks_unsafe_for_binlog = (ibool) TRUE;
2532
2533 srv_max_n_open_files = (ulint) innobase_open_files;
2534 srv_innodb_status = (ibool) innobase_create_status_file;
2535
2536 srv_print_verbose_log = true;
2537
2538 /* Store the default charset-collation number of this MySQL
2539 installation */
2540
2541 data_mysql_default_charset_coll = (ulint)default_charset_info->number;
2542
2543 /* Since we in this module access directly the fields of a trx
2544 struct, and due to different headers and flags it might happen that
2545 mutex_t has a different size in this module and in InnoDB
2546 modules, we check at run time that the size is the same in
2547 these compilation modules. */
2548
2550
2551 if (err != DB_SUCCESS)
2552 {
2553 goto mem_free_and_error;
2554 }
2555
2556 err = dict_create_sys_replication_log();
2557
2558 if (err != DB_SUCCESS) {
2559 goto mem_free_and_error;
2560 }
2561
2562
2563 innobase_old_blocks_pct = buf_LRU_old_ratio_update(innobase_old_blocks_pct.get(),
2564 TRUE);
2565
2566 innobase_open_tables = hash_create(200);
2567 innodb_inited= 1;
2568
2569 actuall_engine_ptr->dropTemporarySchema();
2570
2571 context.add(new InnodbStatusTool);
2572 context.add(innodb_engine_ptr);
2573 context.add(new CmpTool(false));
2574 context.add(new CmpTool(true));
2575 context.add(new CmpmemTool(false));
2576 context.add(new CmpmemTool(true));
2577 context.add(new InnodbTrxTool("INNODB_TRX"));
2578 context.add(new InnodbTrxTool("INNODB_LOCKS"));
2579 context.add(new InnodbTrxTool("INNODB_LOCK_WAITS"));
2580 context.add(new InnodbSysTablesTool());
2581 context.add(new InnodbSysTableStatsTool());
2582 context.add(new InnodbSysIndexesTool());
2583 context.add(new InnodbSysColumnsTool());
2584 context.add(new InnodbSysFieldsTool());
2585 context.add(new InnodbSysForeignTool());
2586 context.add(new InnodbSysForeignColsTool());
2587 context.add(new InnodbInternalTables());
2588 context.add(new InnodbReplicationTable());
2589
2590 if (innobase_use_replication_log)
2591 {
2592 ReplicationLog *replication_logger= new ReplicationLog();
2593 context.add(replication_logger);
2594 ReplicationLog::setup(replication_logger, sysvar_transaction_log_use_replicator);
2595 }
2596
2597 context.registerVariable(new sys_var_const_string_val("data-home-dir", innobase_data_home_dir));
2598 context.registerVariable(new sys_var_const_string_val("flush-method",
2599 vm.count("flush-method") ? vm["flush-method"].as<string>() : ""));
2600 context.registerVariable(new sys_var_const_string_val("log-group-home-dir", innobase_log_group_home_dir));
2601 context.registerVariable(new sys_var_const_string_val("data-file-path", innobase_data_file_path));
2602 context.registerVariable(new sys_var_const_string_val("version", vm["version"].as<string>()));
2603
2604
2605 context.registerVariable(new sys_var_bool_ptr_readonly("replication_log", &innobase_use_replication_log));
2606 context.registerVariable(new sys_var_bool_ptr_readonly("checksums", &innobase_use_checksums));
2607 context.registerVariable(new sys_var_bool_ptr_readonly("doublewrite", &innobase_use_doublewrite));
2608 context.registerVariable(new sys_var_bool_ptr("file-per-table", &srv_file_per_table));
2609 context.registerVariable(new sys_var_bool_ptr_readonly("file-format-check", &innobase_file_format_check));
2610 context.registerVariable(new sys_var_bool_ptr("adaptive-flushing", &srv_adaptive_flushing));
2611 context.registerVariable(new sys_var_bool_ptr("status-file", &innobase_create_status_file));
2612 context.registerVariable(new sys_var_bool_ptr_readonly("use-sys-malloc", &srv_use_sys_malloc));
2613 context.registerVariable(new sys_var_bool_ptr_readonly("use-native-aio", &srv_use_native_aio));
2614
2615 context.registerVariable(new sys_var_bool_ptr("support-xa", &support_xa));
2616 context.registerVariable(new sys_var_bool_ptr("strict_mode", &strict_mode));
2617 context.registerVariable(new sys_var_constrained_value<uint32_t>("lock_wait_timeout", lock_wait_timeout));
2618
2619 context.registerVariable(new sys_var_constrained_value_readonly<size_t>("additional_mem_pool_size",innobase_additional_mem_pool_size));
2620 context.registerVariable(new sys_var_constrained_value<uint32_t>("autoextend_increment",
2621 innodb_auto_extend_increment,
2622 auto_extend_update));
2623 context.registerVariable(new sys_var_constrained_value<uint32_t>("io_capacity",
2624 innodb_io_capacity,
2625 io_capacity_update));
2626 context.registerVariable(new sys_var_constrained_value<uint32_t>("purge_batch_size",
2627 innodb_purge_batch_size,
2628 purge_batch_update));
2629 context.registerVariable(new sys_var_constrained_value<uint32_t>("purge_threads",
2630 innodb_n_purge_threads,
2631 purge_threads_update));
2632 context.registerVariable(new sys_var_constrained_value<uint32_t>("fast_shutdown", innobase_fast_shutdown));
2633 context.registerVariable(new sys_var_std_string("file_format",
2634 innobase_file_format_name,
2636 context.registerVariable(new sys_var_std_string("change_buffering",
2637 innobase_change_buffering,
2639 context.registerVariable(new sys_var_std_string("file_format_max",
2640 innobase_file_format_max,
2642 context.registerVariable(new sys_var_constrained_value_readonly<size_t>("buffer_pool_size", innobase_buffer_pool_size));
2643 context.registerVariable(new sys_var_constrained_value_readonly<int64_t>("log_file_size", innobase_log_file_size));
2644 context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("page_size", innobase_page_size));
2645 context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("log_block_size", innobase_log_block_size));
2646 context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("flush_log_at_trx_commit",
2647 innodb_flush_log_at_trx_commit));
2648 context.registerVariable(new sys_var_constrained_value_readonly<unsigned int>("max_dirty_pages_pct",
2649 innodb_max_dirty_pages_pct));
2650 context.registerVariable(new sys_var_constrained_value_readonly<uint64_t>("max_purge_lag", innodb_max_purge_lag));
2651 context.registerVariable(new sys_var_constrained_value_readonly<uint64_t>("stats_sample_pages", innodb_stats_sample_pages));
2652 context.registerVariable(new sys_var_bool_ptr("adaptive_hash_index", &btr_search_enabled, innodb_adaptive_hash_index_update));
2653 context.registerVariable(new sys_var_std_string("stats_method",
2654 innodb_stats_method,
2655 innodb_stats_method_validate));
2656
2657 context.registerVariable(new sys_var_constrained_value<uint32_t>("commit_concurrency",
2658 innobase_commit_concurrency,
2659 innodb_commit_concurrency_validate));
2660 context.registerVariable(new sys_var_constrained_value<uint32_t>("concurrency_tickets",
2661 innodb_concurrency_tickets));
2662 context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("read_io_threads", innobase_read_io_threads));
2663 context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("write_io_threads", innobase_write_io_threads));
2664 context.registerVariable(new sys_var_constrained_value_readonly<uint64_t>("replication_delay", innodb_replication_delay));
2665 context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("force_recovery", innobase_force_recovery));
2666 context.registerVariable(new sys_var_constrained_value_readonly<size_t>("log_buffer_size", innobase_log_buffer_size));
2667 context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("log_files_in_group", innobase_log_files_in_group));
2668 context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("mirrored_log_groups", innobase_mirrored_log_groups));
2669 context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("open_files", innobase_open_files));
2670 context.registerVariable(new sys_var_constrained_value<uint32_t>("old_blocks_pct",
2671 innobase_old_blocks_pct,
2672 innodb_old_blocks_pct_update));
2673 context.registerVariable(new sys_var_uint32_t_ptr("old_blocks_time", &buf_LRU_old_threshold_ms));
2674 context.registerVariable(new sys_var_constrained_value<uint32_t>("sync_spin_loops", innodb_sync_spin_loops, innodb_sync_spin_loops_update));
2675 context.registerVariable(new sys_var_constrained_value<uint32_t>("spin_wait_delay", innodb_spin_wait_delay, innodb_spin_wait_delay_update));
2676 context.registerVariable(new sys_var_constrained_value<uint32_t>("thread_sleep_delay", innodb_thread_sleep_delay, innodb_thread_sleep_delay_update));
2677 context.registerVariable(new sys_var_constrained_value<uint32_t>("thread_concurrency",
2678 innobase_thread_concurrency,
2679 innodb_thread_concurrency_update));
2680 context.registerVariable(new sys_var_constrained_value<uint32_t>("read_ahead_threshold",
2681 innodb_read_ahead_threshold,
2682 innodb_read_ahead_threshold_update));
2683 context.registerVariable(new sys_var_constrained_value<uint32_t>("auto_lru_dump",
2684 buffer_pool_restore_at_startup,
2685 auto_lru_dump_update));
2686 context.registerVariable(new sys_var_constrained_value_readonly<uint64_t>("ibuf_max_size",
2687 ibuf_max_size));
2688 context.registerVariable(new sys_var_constrained_value<uint32_t>("ibuf_active_contract",
2689 ibuf_active_contract,
2690 ibuf_active_contract_update));
2691 context.registerVariable(new sys_var_constrained_value<uint32_t>("ibuf_accel_rate",
2692 ibuf_accel_rate,
2693 ibuf_accel_rate_update));
2694 context.registerVariable(new sys_var_constrained_value<uint32_t>("checkpoint_age_target",
2695 checkpoint_age_target,
2696 checkpoint_age_target_update));
2697 context.registerVariable(new sys_var_constrained_value<uint32_t>("flush_neighbor_pages",
2698 flush_neighbor_pages,
2699 flush_neighbor_pages_update));
2700 context.registerVariable(new sys_var_std_string("read_ahead",
2701 read_ahead,
2703 context.registerVariable(new sys_var_std_string("adaptive_flushing_method",
2704 adaptive_flushing_method,
2706 /* Get the current high water mark format. */
2707 innobase_file_format_max = trx_sys_file_format_max_get();
2708 btr_search_fully_disabled = (!btr_search_enabled);
2709
2710 context.registerVariable(new sys_var_const_string("use-replicator",
2711 sysvar_transaction_log_use_replicator));
2712
2713 context.registerVariable(new sys_var_constrained_value<uint32_t>("rollback_segments",
2714 innobase_rollback_segments,
2715 innodb_rollback_segments_update));
2716
2717#if defined(UNIV_DEBUG) && !defined(UNIV_HOTBACKUP)
2718 context.registerVariable(new sys_var_bool_ptr("timed-mutexes", &timed_mutexes));
2719#endif /* UNIV_DEBUG && !UNIV_HOTBACKUP */
2720
2721
2722 return(FALSE);
2723
2724error:
2725 return(TRUE);
2726}
2727
2728
2729/****************************************************************/
2733bool
2735/*=====================*/
2736{
2737 bool result = 0;
2738
2739 assert(this == innodb_engine_ptr);
2740
2742
2743 return(result);
2744}
2745
2746/*****************************************************************/
2748static
2749void
2751/*================*/
2752 trx_t* trx)
2753{
2754 if (trx->conc_state == TRX_NOT_STARTED) {
2755
2756 return;
2757 }
2758
2760}
2761
2762/*****************************************************************/
2768int
2770/*====================================*/
2771 Session* session,
2773 start_transaction_option_t options)
2774{
2775 assert(this == innodb_engine_ptr);
2776
2777 /* Create a new trx struct for session, if it does not yet have one */
2778 trx_t *trx = check_trx_exists(session);
2779
2780 /* This is just to play safe: release a possible FIFO ticket and
2781 search latch. Since we will reserve the kernel mutex, we have to
2782 release the search system latch first to obey the latching order. */
2784
2785 /* If the transaction is not started yet, start it */
2787
2788 /* Assign a read view if the transaction does not have it yet */
2789 if (options == START_TRANS_OPT_WITH_CONS_SNAPSHOT)
2791
2792 return 0;
2793}
2794
2795/*****************************************************************/
2799int
2801/*============*/
2802 Session* session,
2804 bool all)
2806{
2807 trx_t* trx;
2808
2809 assert(this == innodb_engine_ptr);
2810
2811 trx = check_trx_exists(session);
2812
2813 /* Since we will reserve the kernel mutex, we have to release
2814 the search system latch first to obey the latching order. */
2815
2816 if (trx->has_search_latch) {
2818 }
2819
2820 if (all)
2821 {
2822 /* We were instructed to commit the whole transaction, or
2823 this is an SQL statement end and autocommit is on */
2824
2825 /* We need current binlog position for ibbackup to work.
2826 Note, the position is current because of
2827 prepare_commit_mutex */
2828 const uint32_t commit_concurrency= innobase_commit_concurrency.get();
2829 if (commit_concurrency)
2830 {
2831 do
2832 {
2833 boost::mutex::scoped_lock scopedLock(commit_cond_m);
2835
2836 if (commit_threads <= commit_concurrency)
2837 break;
2838
2840 commit_cond.wait(scopedLock);
2841 } while (1);
2842 }
2843
2844 trx->mysql_log_file_name = NULL;
2845 trx->mysql_log_offset = 0;
2846
2847 /* Don't do write + flush right now. For group commit
2848 to work we want to do the flush after releasing the
2849 prepare_commit_mutex. */
2850 trx->flush_log_later = TRUE;
2852 trx->flush_log_later = FALSE;
2853
2854 if (commit_concurrency)
2855 {
2856 boost::mutex::scoped_lock scopedLock(commit_cond_m);
2858 commit_cond.notify_one();
2859 }
2860
2861 /* Now do a write + flush of logs. */
2863
2864 } else {
2865 /* We just mark the SQL statement ended and do not do a
2866 transaction commit */
2867
2868 /* If we had reserved the auto-inc lock for some
2869 table in this SQL statement we release it now */
2870
2872
2873 /* Store the current undo_no of the transaction so that we
2874 know where to roll back if we have to roll back the next
2875 SQL statement */
2876
2878
2879 if (! session_test_options(session, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
2880 {
2881 if (trx->conc_state != TRX_NOT_STARTED)
2882 {
2883 commit(session, TRUE);
2884 }
2885 }
2886 }
2887
2888 trx->n_autoinc_rows = 0; /* Reset the number AUTO-INC rows required */
2889
2890 if (trx->declared_to_be_inside_innodb) {
2891 /* Release our possible ticket in the FIFO */
2892
2894 }
2895
2896 /* Tell the InnoDB server that there might be work for utility
2897 threads: */
2899
2900 if (trx->isolation_level <= TRX_ISO_READ_COMMITTED &&
2901 trx->global_read_view)
2902 {
2903 /* At low transaction isolation levels we let
2904 each consistent read set its own snapshot */
2906 }
2907
2908 return(0);
2909}
2910
2911/*****************************************************************/
2914int
2916/*==============*/
2917 Session* session,
2919 bool all)
2921{
2922 int error = 0;
2923 trx_t* trx;
2924
2925 assert(this == innodb_engine_ptr);
2926
2927 trx = check_trx_exists(session);
2928
2929 /* Release a possible FIFO ticket and search latch. Since we will
2930 reserve the kernel mutex, we have to release the search system latch
2931 first to obey the latching order. */
2932
2934
2935 trx->n_autoinc_rows = 0;
2936
2937 /* If we had reserved the auto-inc lock for some table (if
2938 we come here to roll back the latest SQL statement) we
2939 release it now before a possibly lengthy rollback */
2940
2942
2943 if (all)
2944 {
2945 error = trx_rollback_for_mysql(trx);
2946 } else {
2948 }
2949
2950 if (trx->isolation_level <= TRX_ISO_READ_COMMITTED &&
2951 trx->global_read_view)
2952 {
2953 /* At low transaction isolation levels we let
2954 each consistent read set its own snapshot */
2956 }
2957
2958 return(convert_error_code_to_mysql(error, 0, NULL));
2959}
2960
2961/*****************************************************************/
2964static
2965int
2967/*==================*/
2968 trx_t* trx)
2969{
2970 int error = 0;
2971
2972 /* Release a possible FIFO ticket and search latch. Since we will
2973 reserve the kernel mutex, we have to release the search system latch
2974 first to obey the latching order. */
2975
2977
2978 /* If we had reserved the auto-inc lock for some table (if
2979 we come here to roll back the latest SQL statement) we
2980 release it now before a possibly lengthy rollback */
2981
2983
2984 error = trx_rollback_for_mysql(trx);
2985
2986 return(convert_error_code_to_mysql(error, 0, NULL));
2987}
2988
2989/*****************************************************************/
2993int
2995/*===========================*/
2996 Session* session,
2998 drizzled::NamedSavepoint &named_savepoint)
2999{
3000 ib_int64_t mysql_binlog_cache_pos;
3001 int error = 0;
3002 trx_t* trx;
3003
3004 assert(this == innodb_engine_ptr);
3005
3006 trx = check_trx_exists(session);
3007
3008 /* Release a possible FIFO ticket and search latch. Since we will
3009 reserve the kernel mutex, we have to release the search system latch
3010 first to obey the latching order. */
3011
3013
3014 error= (int)trx_rollback_to_savepoint_for_mysql(trx, named_savepoint.getName().c_str(),
3015 &mysql_binlog_cache_pos);
3016 return(convert_error_code_to_mysql(error, 0, NULL));
3017}
3018
3019/*****************************************************************/
3023int
3025/*=======================*/
3026 Session* session,
3028 drizzled::NamedSavepoint &named_savepoint)
3029{
3030 int error = 0;
3031 trx_t* trx;
3032
3033 assert(this == innodb_engine_ptr);
3034
3035 trx = check_trx_exists(session);
3036
3037 error = (int) trx_release_savepoint_for_mysql(trx, named_savepoint.getName().c_str());
3038
3039 return(convert_error_code_to_mysql(error, 0, NULL));
3040}
3041
3042/*****************************************************************/
3045int
3047/*===============*/
3048 Session* session,
3049 drizzled::NamedSavepoint &named_savepoint)
3050{
3051 int error = 0;
3052 trx_t* trx;
3053
3054 assert(this == innodb_engine_ptr);
3055
3056 /*
3057 In the autocommit mode there is no sense to set a savepoint
3058 (unless we are in sub-statement), so SQL layer ensures that
3059 this method is never called in such situation.
3060 */
3061
3062 trx = check_trx_exists(session);
3063
3064 /* Release a possible FIFO ticket and search latch. Since we will
3065 reserve the kernel mutex, we have to release the search system latch
3066 first to obey the latching order. */
3067
3069
3070 /* cannot happen outside of transaction */
3071 assert(trx->conc_state != TRX_NOT_STARTED);
3072
3073 error = (int) trx_savepoint_for_mysql(trx, named_savepoint.getName().c_str(), (ib_int64_t)0);
3074
3075 return(convert_error_code_to_mysql(error, 0, NULL));
3076}
3077
3078/*****************************************************************/
3081int
3083/*======================*/
3084 Session* session)
3086{
3087 trx_t* trx;
3088
3089 assert(this == innodb_engine_ptr);
3090 trx = session_to_trx(session);
3091
3092 ut_a(trx);
3093
3094 assert(session->getKilled() != Session::NOT_KILLED ||
3095 trx->conc_state == TRX_NOT_STARTED);
3096
3097 /* Warn if rolling back some things... */
3098 if (session->getKilled() != Session::NOT_KILLED &&
3099 trx->conc_state != TRX_NOT_STARTED &&
3100 trx->undo_no > 0 &&
3101 global_system_variables.log_warnings)
3102 {
3103 errmsg_printf(error::WARN,
3104 "Drizzle is closing a connection during a KILL operation\n"
3105 "that has an active InnoDB transaction. %llu row modifications will "
3106 "roll back.\n",
3107 (ullint) trx->undo_no);
3108 }
3109
3111
3112 trx_free_for_mysql(trx);
3113
3114 return(0);
3115}
3116
3117
3118/*************************************************************************/
3121
3122/****************************************************************/
3124UNIV_INTERN
3125const char*
3127/*====================*/
3128 uint)
3130{
3131 return("BTREE");
3132}
3133
3134/****************************************************************/
3137UNIV_INTERN
3138uint
3140/*===================================*/
3141{
3142 return(MAX_KEY);
3143}
3144
3145/****************************************************************/
3148UNIV_INTERN
3149uint32_t
3151/*=========================================*/
3152{
3153 /* An InnoDB page must store >= 2 keys; a secondary key record
3154 must also contain the primary key value: max key length is
3155 therefore set to slightly less than 1 / 4 of page size which
3156 is 16 kB; but currently MySQL does not work with keys whose
3157 size is > MAX_KEY_LENGTH */
3158 return(3500);
3159}
3160
3161/****************************************************************/
3164UNIV_INTERN
3165const key_map*
3167{
3168 return(&key_map_full);
3169}
3170
3171
3172/****************************************************************/
3175UNIV_INTERN
3176bool
3178{
3179 return(true);
3180}
3181
3182/********************************************************************/
3185static
3186uint64_t
3188/*===========================*/
3189 const Field* field)
3190{
3191 uint64_t max_value = 0;
3192
3193 switch(field->key_type()) {
3194 /* TINY */
3195 case HA_KEYTYPE_BINARY:
3196 max_value = 0xFFULL;
3197 break;
3198 /* LONG */
3199 case HA_KEYTYPE_ULONG_INT:
3200 max_value = 0xFFFFFFFFULL;
3201 break;
3202 case HA_KEYTYPE_LONG_INT:
3203 max_value = 0x7FFFFFFFULL;
3204 break;
3205 /* BIG */
3206 case HA_KEYTYPE_ULONGLONG:
3207 max_value = 0xFFFFFFFFFFFFFFFFULL;
3208 break;
3209 case HA_KEYTYPE_LONGLONG:
3210 max_value = 0x7FFFFFFFFFFFFFFFULL;
3211 break;
3212 case HA_KEYTYPE_DOUBLE:
3213 /* We use the maximum as per IEEE754-2008 standard, 2^53 */
3214 max_value = 0x20000000000000ULL;
3215 break;
3216 default:
3217 ut_error;
3218 }
3219
3220 return(max_value);
3221}
3222
3223/*******************************************************************/
3227static
3228ibool
3230/*=========================*/
3231 const KeyInfo* key_info,
3233 const dict_index_t* index_info)
3235{
3236 const KeyPartInfo* key_part;
3237 const KeyPartInfo* key_end;
3238 const dict_field_t* innodb_idx_fld;
3239 const dict_field_t* innodb_idx_fld_end;
3240
3241 /* Check whether user defined index column count matches */
3242 if (key_info->key_parts != index_info->n_user_defined_cols) {
3243 return(FALSE);
3244 }
3245
3246 key_part = key_info->key_part;
3247 key_end = key_part + key_info->key_parts;
3248 innodb_idx_fld = index_info->fields;
3249 innodb_idx_fld_end = index_info->fields + index_info->n_fields;
3250
3251 /* Check each index column's datatype. We do not check
3252 column name because there exists case that index
3253 column name got modified in mysql but such change does not
3254 propagate to InnoDB.
3255 One hidden assumption here is that the index column sequences
3256 are matched up between those in mysql and Innodb. */
3257 for (; key_part != key_end; ++key_part) {
3258 ulint col_type;
3259 ibool is_unsigned;
3260 ulint mtype = innodb_idx_fld->col->mtype;
3261
3262 /* Need to translate to InnoDB column type before
3263 comparison. */
3264 col_type = get_innobase_type_from_mysql_type(&is_unsigned,
3265 key_part->field);
3266
3267 /* Ignore Innodb specific system columns. */
3268 while (mtype == DATA_SYS) {
3269 innodb_idx_fld++;
3270
3271 if (innodb_idx_fld >= innodb_idx_fld_end) {
3272 return(FALSE);
3273 }
3274 }
3275
3276 if (col_type != mtype) {
3277 /* Column Type mismatches */
3278 return(FALSE);
3279 }
3280
3281 innodb_idx_fld++;
3282 }
3283
3284 return(TRUE);
3285}
3286
3287/*******************************************************************/
3298static
3299ibool
3301/*=============================*/
3302 const Table* table,
3304 dict_table_t* ib_table,
3306 INNOBASE_SHARE* share)
3309{
3310 ulint mysql_num_index;
3311 ulint ib_num_index;
3312 dict_index_t** index_mapping;
3313 ibool ret = TRUE;
3314
3315 mutex_enter(&dict_sys->mutex);
3316
3317 mysql_num_index = table->getShare()->keys;
3318 ib_num_index = UT_LIST_GET_LEN(ib_table->indexes);
3319
3320 index_mapping = share->idx_trans_tbl.index_mapping;
3321
3322 /* If there exists inconsistency between MySQL and InnoDB dictionary
3323 (metadata) information, the number of index defined in MySQL
3324 could exceed that in InnoDB, do not build index translation
3325 table in such case */
3326 if (UNIV_UNLIKELY(ib_num_index < mysql_num_index)) {
3327 ret = FALSE;
3328 goto func_exit;
3329 }
3330
3331 /* If index entry count is non-zero, nothing has
3332 changed since last update, directly return TRUE */
3333 if (share->idx_trans_tbl.index_count) {
3334 /* Index entry count should still match mysql_num_index */
3335 ut_a(share->idx_trans_tbl.index_count == mysql_num_index);
3336 goto func_exit;
3337 }
3338
3339 /* The number of index increased, rebuild the mapping table */
3340 if (mysql_num_index > share->idx_trans_tbl.array_size) {
3341 index_mapping = (dict_index_t**) realloc(index_mapping,
3342 mysql_num_index *
3343 sizeof(*index_mapping));
3344
3345 if (!index_mapping) {
3346 /* Report an error if index_mapping continues to be
3347 NULL and mysql_num_index is a non-zero value */
3348 errmsg_printf(error::ERROR, "InnoDB: fail to allocate memory for "
3349 "index translation table. Number of Index:%lu, array size:%lu",
3350 mysql_num_index,
3351 share->idx_trans_tbl.array_size);
3352 ret = FALSE;
3353 goto func_exit;
3354 }
3355
3356 share->idx_trans_tbl.array_size = mysql_num_index;
3357 }
3358
3359 /* For each index in the mysql key_info array, fetch its
3360 corresponding InnoDB index pointer into index_mapping
3361 array. */
3362 for (ulint count = 0; count < mysql_num_index; count++) {
3363
3364 /* Fetch index pointers into index_mapping according to mysql
3365 index sequence */
3366 index_mapping[count] = dict_table_get_index_on_name(
3367 ib_table, table->key_info[count].name);
3368
3369 if (!index_mapping[count]) {
3370 errmsg_printf(error::ERROR, "Cannot find index %s in InnoDB index dictionary.",
3371 table->key_info[count].name);
3372 ret = FALSE;
3373 goto func_exit;
3374 }
3375
3376 /* Double check fetched index has the same
3377 column info as those in mysql key_info. */
3378 if (!innobase_match_index_columns(&table->key_info[count], index_mapping[count])) {
3379 errmsg_printf(error::ERROR, "Found index %s whose column info does not match that of MySQL.",
3380 table->key_info[count].name);
3381 ret = FALSE;
3382 goto func_exit;
3383 }
3384 }
3385
3386 /* Successfully built the translation table */
3387 share->idx_trans_tbl.index_count = mysql_num_index;
3388
3389func_exit:
3390 if (!ret) {
3391 /* Build translation table failed. */
3392 free(index_mapping);
3393
3394 share->idx_trans_tbl.array_size = 0;
3395 share->idx_trans_tbl.index_count = 0;
3396 index_mapping = NULL;
3397 }
3398
3399 share->idx_trans_tbl.index_mapping = index_mapping;
3400
3401 mutex_exit(&dict_sys->mutex);
3402
3403 return(ret);
3404}
3405
3406/*******************************************************************/
3415static
3416dict_index_t*
3418/*==================*/
3419 INNOBASE_SHARE* share,
3421 uint keynr)
3423{
3424 if (!share->idx_trans_tbl.index_mapping
3425 || keynr >= share->idx_trans_tbl.index_count) {
3426 return(NULL);
3427 }
3428
3429 return(share->idx_trans_tbl.index_mapping[keynr]);
3430}
3431
3432/********************************************************************/
3435UNIV_INTERN
3436void
3438/*======================================*/
3439{
3440 uint64_t auto_inc;
3441 const Field* field = getTable()->found_next_number_field;
3442
3443 if (field != NULL) {
3444 auto_inc = innobase_get_int_col_max_value(field);
3445 } else {
3446 /* We have no idea what's been passed in to us as the
3447 autoinc column. We set it to the 0, effectively disabling
3448 updates to the table. */
3449 auto_inc = 0;
3450
3451 ut_print_timestamp(stderr);
3452 errmsg_printf(error::ERROR, "InnoDB: Unable to determine the AUTOINC column name");
3453 }
3454
3455 if (srv_force_recovery >= SRV_FORCE_NO_IBUF_MERGE) {
3456 /* If the recovery level is set so high that writes
3457 are disabled we force the AUTOINC counter to 0
3458 value effectively disabling writes to the table.
3459 Secondly, we avoid reading the table in case the read
3460 results in failure due to a corrupted table/index.
3461
3462 We will not return an error to the client, so that the
3463 tables can be dumped with minimal hassle. If an error
3464 were returned in this case, the first attempt to read
3465 the table would fail and subsequent SELECTs would succeed. */
3466 auto_inc = 0;
3467 } else if (field == NULL) {
3468 /* This is a far more serious error, best to avoid
3469 opening the table and return failure. */
3470 my_error(ER_AUTOINC_READ_FAILED, MYF(0));
3471 } else {
3472 dict_index_t* index;
3473 const char* col_name;
3474 uint64_t read_auto_inc;
3475 ulint err;
3476
3477 update_session(getTable()->in_use);
3478 col_name = field->field_name;
3479
3481
3482 index = innobase_get_index(getTable()->getShare()->next_number_index);
3483
3484 /* Execute SELECT MAX(col_name) FROM TABLE; */
3485 err = row_search_max_autoinc(index, col_name, &read_auto_inc);
3486
3487 switch (err) {
3488 case DB_SUCCESS: {
3489 uint64_t col_max_value;
3490
3491 col_max_value = innobase_get_int_col_max_value(field);
3492
3493 /* At the this stage we do not know the increment
3494 nor the offset, so use a default increment of 1. */
3495
3496 auto_inc = innobase_next_autoinc(read_auto_inc, 1, 1, col_max_value);
3497
3498 break;
3499 }
3500 case DB_RECORD_NOT_FOUND:
3501 ut_print_timestamp(stderr);
3502 errmsg_printf(error::ERROR, "InnoDB: MySQL and InnoDB data dictionaries are out of sync.\n"
3503 "InnoDB: Unable to find the AUTOINC column %s in the InnoDB table %s.\n"
3504 "InnoDB: We set the next AUTOINC column value to 0,\n"
3505 "InnoDB: in effect disabling the AUTOINC next value generation.\n"
3506 "InnoDB: You can either set the next AUTOINC value explicitly using ALTER TABLE\n"
3507 "InnoDB: or fix the data dictionary by recreating the table.\n",
3508 col_name, index->table->name);
3509
3510 /* This will disable the AUTOINC generation. */
3511 auto_inc = 0;
3512
3513 /* We want the open to succeed, so that the user can
3514 take corrective action. ie. reads should succeed but
3515 updates should fail. */
3516 err = DB_SUCCESS;
3517 break;
3518 default:
3519 /* row_search_max_autoinc() should only return
3520 one of DB_SUCCESS or DB_RECORD_NOT_FOUND. */
3521 ut_error;
3522 }
3523 }
3524
3525 dict_table_autoinc_initialize(prebuilt->table, auto_inc);
3526}
3527
3528/*****************************************************************/
3532UNIV_INTERN
3533int
3535 int mode,
3536 uint test_if_locked)
3537{
3538 dict_table_t* ib_table;
3539 Session* session;
3540
3541 UT_NOT_USED(mode);
3542 UT_NOT_USED(test_if_locked);
3543
3544 session= getTable()->in_use;
3545
3546 /* Under some cases Drizzle seems to call this function while
3547 holding btr_search_latch. This breaks the latching order as
3548 we acquire dict_sys->mutex below and leads to a deadlock. */
3549 if (session != NULL) {
3550 getTransactionalEngine()->releaseTemporaryLatches(session);
3551 }
3552
3553 user_session = NULL;
3554
3555 std::string search_string(identifier.getSchemaName());
3556 boost::algorithm::to_lower(search_string);
3557
3558 if (search_string.compare("data_dictionary") == 0)
3559 {
3560 std::string table_name(identifier.getTableName());
3561 boost::algorithm::to_upper(table_name);
3562 if (!(share=get_share(table_name.c_str())))
3563 {
3564 return 1;
3565 }
3566 }
3567 else
3568 {
3569 if (!(share=get_share(identifier.getKeyPath().c_str())))
3570 {
3571 return(1);
3572 }
3573 }
3574
3575 /* Create buffers for packing the fields of a record. Why
3576 table->stored_rec_length did not work here? Obviously, because char
3577 fields when packed actually became 1 byte longer, when we also
3578 stored the string length as the first byte. */
3579
3580 upd_and_key_val_buff_len =
3581 getTable()->getShare()->sizeStoredRecord()
3582 + getTable()->getShare()->max_key_length
3583 + MAX_REF_PARTS * 3;
3584
3585 upd_buff.resize(upd_and_key_val_buff_len);
3586
3587 if (upd_buff.size() < upd_and_key_val_buff_len)
3588 {
3589 free_share(share);
3590 }
3591
3592 key_val_buff.resize(upd_and_key_val_buff_len);
3593 if (key_val_buff.size() < upd_and_key_val_buff_len)
3594 {
3595 return(1);
3596 }
3597
3598 /* Get pointer to a table object in InnoDB dictionary cache */
3599 if (search_string.compare("data_dictionary") == 0)
3600 {
3601 std::string table_name(identifier.getTableName());
3602 boost::algorithm::to_upper(table_name);
3603 ib_table = dict_table_get(table_name.c_str(), TRUE);
3604 }
3605 else
3606 {
3607 ib_table = dict_table_get(identifier.getKeyPath().c_str(), TRUE);
3608 if (ib_table == NULL
3609 && drizzled::identifier::Catalog(identifier.getCatalogName())==drizzled::catalog::local_identifier())
3610 {
3611 std::string table_path_no_catalog(identifier.getKeyPath());
3612 table_path_no_catalog.erase(0, drizzled::catalog::local_identifier().getPath().length()+1);
3613 /* We try without local/ as old InnoDB data dictionary (pre CATALOG)
3614 did not have local/ in data dict, just in filesystem path */
3615 ib_table = dict_table_get(table_path_no_catalog.c_str(), TRUE);
3616 }
3617 }
3618
3619 if (NULL == ib_table) {
3620 errmsg_printf(error::ERROR, "Cannot find or open table %s from\n"
3621 "the internal data dictionary of InnoDB "
3622 "though the .frm file for the\n"
3623 "table exists. Maybe you have deleted and "
3624 "recreated InnoDB data\n"
3625 "files but have forgotten to delete the "
3626 "corresponding .frm files\n"
3627 "of InnoDB tables, or you have moved .frm "
3628 "files to another database?\n"
3629 "or, the table contains indexes that this "
3630 "version of the engine\n"
3631 "doesn't support.\n"
3632 "See " REFMAN "innodb-troubleshooting.html\n"
3633 "how you can resolve the problem.\n",
3634 identifier.getKeyPath().c_str());
3635 free_share(share);
3636 upd_buff.resize(0);
3637 key_val_buff.resize(0);
3638 errno = ENOENT;
3639
3640 return(HA_ERR_NO_SUCH_TABLE);
3641 }
3642
3643 if (ib_table->ibd_file_missing && ! session->doing_tablespace_operation()) {
3644 errmsg_printf(error::ERROR, "MySQL is trying to open a table handle but "
3645 "the .ibd file for\ntable %s does not exist.\n"
3646 "Have you deleted the .ibd file from the "
3647 "database directory under\nthe MySQL datadir, "
3648 "or have you used DISCARD TABLESPACE?\n"
3649 "See " REFMAN "innodb-troubleshooting.html\n"
3650 "how you can resolve the problem.\n",
3651 identifier.getKeyPath().c_str());
3652 free_share(share);
3653 upd_buff.resize(0);
3654 key_val_buff.resize(0);
3655 errno = ENOENT;
3656
3657 dict_table_decrement_handle_count(ib_table, FALSE);
3658 return(HA_ERR_NO_SUCH_TABLE);
3659 }
3660
3661 prebuilt = row_create_prebuilt(ib_table);
3662
3663 prebuilt->mysql_row_len = getTable()->getShare()->sizeStoredRecord();
3664 prebuilt->default_rec = getTable()->getDefaultValues();
3665 ut_ad(prebuilt->default_rec);
3666
3667 /* Looks like MySQL-3.23 sometimes has primary key number != 0 */
3668
3669 primary_key = getTable()->getShare()->getPrimaryKey();
3670 key_used_on_scan = primary_key;
3671
3672 if (!innobase_build_index_translation(getTable(), ib_table, share)) {
3673 errmsg_printf(error::ERROR, "Build InnoDB index translation table for"
3674 " Table %s failed", identifier.getKeyPath().c_str());
3675 }
3676
3677 /* Allocate a buffer for a 'row reference'. A row reference is
3678 a string of bytes of length ref_length which uniquely specifies
3679 a row in our table. Note that MySQL may also compare two row
3680 references for equality by doing a simple memcmp on the strings
3681 of length ref_length! */
3682
3683 if (!row_table_got_default_clust_index(ib_table)) {
3684
3685 prebuilt->clust_index_was_generated = FALSE;
3686
3687 if (UNIV_UNLIKELY(primary_key >= MAX_KEY)) {
3688 errmsg_printf(error::ERROR, "Table %s has a primary key in "
3689 "InnoDB data dictionary, but not "
3690 "in MySQL!", identifier.getTableName().c_str());
3691
3692 /* This mismatch could cause further problems
3693 if not attended, bring this to the user's attention
3694 by printing a warning in addition to log a message
3695 in the errorlog */
3696 push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3697 ER_NO_SUCH_INDEX,
3698 "InnoDB: Table %s has a "
3699 "primary key in InnoDB data "
3700 "dictionary, but not in "
3701 "MySQL!", identifier.getTableName().c_str());
3702
3703 /* If primary_key >= MAX_KEY, its (primary_key)
3704 value could be out of bound if continue to index
3705 into key_info[] array. Find InnoDB primary index,
3706 and assign its key_length to ref_length.
3707 In addition, since MySQL indexes are sorted starting
3708 with primary index, unique index etc., initialize
3709 ref_length to the first index key length in
3710 case we fail to find InnoDB cluster index.
3711
3712 Please note, this will not resolve the primary
3713 index mismatch problem, other side effects are
3714 possible if users continue to use the table.
3715 However, we allow this table to be opened so
3716 that user can adopt necessary measures for the
3717 mismatch while still being accessible to the table
3718 date. */
3719 ref_length = getTable()->key_info[0].key_length;
3720
3721 /* Find correspoinding cluster index
3722 key length in MySQL's key_info[] array */
3723 for (ulint i = 0; i < getTable()->getShare()->keys; i++) {
3724 dict_index_t* index;
3725 index = innobase_get_index(i);
3726 if (dict_index_is_clust(index)) {
3727 ref_length =
3728 getTable()->key_info[i].key_length;
3729 }
3730 }
3731 } else {
3732 /* MySQL allocates the buffer for ref.
3733 key_info->key_length includes space for all key
3734 columns + one byte for each column that may be
3735 NULL. ref_length must be as exact as possible to
3736 save space, because all row reference buffers are
3737 allocated based on ref_length. */
3738
3739 ref_length = getTable()->key_info[primary_key].key_length;
3740 }
3741 } else {
3742 if (primary_key != MAX_KEY) {
3743 errmsg_printf(error::ERROR,
3744 "Table %s has no primary key in InnoDB data "
3745 "dictionary, but has one in MySQL! If you "
3746 "created the table with a MySQL version < "
3747 "3.23.54 and did not define a primary key, "
3748 "but defined a unique key with all non-NULL "
3749 "columns, then MySQL internally treats that "
3750 "key as the primary key. You can fix this "
3751 "error by dump + DROP + CREATE + reimport "
3752 "of the table.", identifier.getTableName().c_str());
3753
3754 /* This mismatch could cause further problems
3755 if not attended, bring this to the user attention
3756 by printing a warning in addition to log a message
3757 in the errorlog */
3758 push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3759 ER_NO_SUCH_INDEX,
3760 "InnoDB: Table %s has no "
3761 "primary key in InnoDB data "
3762 "dictionary, but has one in "
3763 "MySQL!", identifier.getTableName().c_str());
3764 }
3765
3766 prebuilt->clust_index_was_generated = TRUE;
3767
3768 ref_length = DATA_ROW_ID_LEN;
3769
3770 /* If we automatically created the clustered index, then
3771 MySQL does not know about it, and MySQL must NOT be aware
3772 of the index used on scan, to make it avoid checking if we
3773 update the column of the index. That is why we assert below
3774 that key_used_on_scan is the undefined value MAX_KEY.
3775 The column is the row id in the automatical generation case,
3776 and it will never be updated anyway. */
3777
3778 if (key_used_on_scan != MAX_KEY) {
3779 errmsg_printf(error::WARN,
3780 "Table %s key_used_on_scan is %lu even "
3781 "though there is no primary key inside "
3782 "InnoDB.", identifier.getTableName().c_str(), (ulong) key_used_on_scan);
3783 }
3784 }
3785
3786 /* Index block size in InnoDB: used by MySQL in query optimization */
3787 stats.block_size = 16 * 1024;
3788
3789 /* Init table lock structure */
3790 lock.init(&share->lock);
3791
3792 if (prebuilt->table) {
3793 /* We update the highest file format in the system table
3794 space, if this table has higher file format setting. */
3795
3796 char changed_file_format_max[100];
3797 strcpy(changed_file_format_max, innobase_file_format_max.c_str());
3798 trx_sys_file_format_max_upgrade((const char **)&changed_file_format_max,
3800 innobase_file_format_max= changed_file_format_max;
3801 }
3802
3803 /* Only if the table has an AUTOINC column. */
3804 if (prebuilt->table != NULL && getTable()->found_next_number_field != NULL) {
3805
3806 dict_table_autoinc_lock(prebuilt->table);
3807
3808 /* Since a table can already be "open" in InnoDB's internal
3809 data dictionary, we only init the autoinc counter once, the
3810 first time the table is loaded. We can safely reuse the
3811 autoinc value from a previous Drizzle open. */
3812 if (dict_table_autoinc_read(prebuilt->table) == 0) {
3813
3815 }
3816
3817 dict_table_autoinc_unlock(prebuilt->table);
3818 }
3819
3820 info(HA_STATUS_NO_LOCK | HA_STATUS_VARIABLE | HA_STATUS_CONST);
3821
3822 return(0);
3823}
3824
3825UNIV_INTERN
3826uint32_t
3827InnobaseEngine::max_supported_key_part_length() const
3828{
3829 return(DICT_MAX_INDEX_COL_LEN - 1);
3830}
3831
3832/******************************************************************/
3835UNIV_INTERN
3836int
3838/*====================*/
3839{
3840 Session* session;
3841
3842 session= getTable()->in_use;
3843 if (session != NULL) {
3844 getTransactionalEngine()->releaseTemporaryLatches(session);
3845 }
3846
3848
3849 upd_buff.clear();
3850 key_val_buff.clear();
3851 free_share(share);
3852
3853 /* Tell InnoDB server that there might be work for
3854 utility threads: */
3855
3857
3858 return(0);
3859}
3860
3861/* The following accessor functions should really be inside MySQL code! */
3862
3863/**************************************************************/
3866static inline
3867uint
3869/*=============*/
3870 Table* table,
3871 Field* field)
3872{
3873 return((uint) (field->ptr - table->getInsertRecord()));
3874}
3875
3876/**************************************************************/
3880static inline
3881uint
3883/*====================*/
3884 Table* table,
3885 Field* field,
3886 char* record)
3887{
3888 int null_offset;
3889
3890 if (!field->null_ptr) {
3891
3892 return(0);
3893 }
3894
3895 null_offset = (uint) ((char*) field->null_ptr
3896 - (char*) table->getInsertRecord());
3897
3898 if (record[null_offset] & field->null_bit) {
3899
3900 return(1);
3901 }
3902
3903 return(0);
3904}
3905
3906/**************************************************************/
3909static inline
3910void
3912/*========================*/
3913 Table* table,
3914 Field* field,
3915 char* record)
3916{
3917 int null_offset;
3918
3919 null_offset = (uint) ((char*) field->null_ptr
3920 - (char*) table->getInsertRecord());
3921
3922 record[null_offset] = record[null_offset] | field->null_bit;
3923}
3924
3925/*************************************************************/
3931UNIV_INTERN int
3933/*===============*/
3934 int mysql_type,
3935 uint charset_number,
3936 const unsigned char* a,
3937 unsigned int a_length,
3939 const unsigned char* b, /* in: data field */
3940 unsigned int b_length); /* in: data field length,
3941 not UNIV_SQL_NULL */
3942
3943int
3945/*===============*/
3946 /* out: 1, 0, -1, if a is greater, equal, less than b, respectively */
3947 int mysql_type, /* in: MySQL type */
3948 uint charset_number, /* in: number of the charset */
3949 const unsigned char* a, /* in: data field */
3950 unsigned int a_length, /* in: data field length, not UNIV_SQL_NULL */
3951 const unsigned char* b, /* in: data field */
3952 unsigned int b_length) /* in: data field length, not UNIV_SQL_NULL */
3953{
3954 const charset_info_st* charset;
3955 enum_field_types mysql_tp;
3956 int ret;
3957
3958 assert(a_length != UNIV_SQL_NULL);
3959 assert(b_length != UNIV_SQL_NULL);
3960
3961 mysql_tp = (enum_field_types) mysql_type;
3962
3963 switch (mysql_tp) {
3964
3965 case DRIZZLE_TYPE_BLOB:
3966 case DRIZZLE_TYPE_VARCHAR:
3967 /* Use the charset number to pick the right charset struct for
3968 the comparison. Since the MySQL function get_charset may be
3969 slow before Bar removes the mutex operation there, we first
3970 look at 2 common charsets directly. */
3971
3972 if (charset_number == default_charset_info->number) {
3973 charset = default_charset_info;
3974 } else {
3975 charset = get_charset(charset_number);
3976
3977 if (charset == NULL) {
3978 errmsg_printf(error::ERROR, "InnoDB needs charset %lu for doing "
3979 "a comparison, but MySQL cannot "
3980 "find that charset.",
3981 (ulong) charset_number);
3982 ut_a(0);
3983 }
3984 }
3985
3986 /* Starting from 4.1.3, we use strnncollsp() in comparisons of
3987 non-latin1_swedish_ci strings. NOTE that the collation order
3988 changes then: 'b\0\0...' is ordered BEFORE 'b ...'. Users
3989 having indexes on such data need to rebuild their tables! */
3990
3991 ret = charset->coll->strnncollsp(charset,
3992 a, a_length,
3993 b, b_length, 0);
3994 if (ret < 0) {
3995 return(-1);
3996 } else if (ret > 0) {
3997 return(1);
3998 } else {
3999 return(0);
4000 }
4001 default:
4002 ut_error;
4003 }
4004
4005 return(0);
4006}
4007
4008/**************************************************************/
4013UNIV_INTERN
4014ulint
4016/*==============================*/
4017 ulint* unsigned_flag,
4022 const void* f)
4023{
4024 const class Field* field = reinterpret_cast<const class Field*>(f);
4025
4026 /* The following asserts try to check that the MySQL type code fits in
4027 8 bits: this is used in ibuf and also when DATA_NOT_NULL is ORed to
4028 the type */
4029
4030 assert((ulint)DRIZZLE_TYPE_DOUBLE < 256);
4031
4032 if (field->flags & UNSIGNED_FLAG) {
4033
4034 *unsigned_flag = DATA_UNSIGNED;
4035 } else {
4036 *unsigned_flag = 0;
4037 }
4038
4039 if (field->real_type() == DRIZZLE_TYPE_ENUM)
4040 {
4041 /* MySQL has field->type() a string type for these, but the
4042 data is actually internally stored as an unsigned integer
4043 code! */
4044
4045 *unsigned_flag = DATA_UNSIGNED; /* MySQL has its own unsigned
4046 flag set to zero, even though
4047 internally this is an unsigned
4048 integer type */
4049 return(DATA_INT);
4050 }
4051
4052 switch (field->type()) {
4053 /* NOTE that we only allow string types in DATA_DRIZZLE and
4054 DATA_VARDRIZZLE */
4055 case DRIZZLE_TYPE_VARCHAR: /* new >= 5.0.3 true VARCHAR */
4056 if (field->binary()) {
4057 return(DATA_BINARY);
4058 } else {
4059 return(DATA_VARMYSQL);
4060 }
4061 case DRIZZLE_TYPE_DECIMAL:
4062 case DRIZZLE_TYPE_MICROTIME:
4063 return(DATA_FIXBINARY);
4064 case DRIZZLE_TYPE_LONG:
4065 case DRIZZLE_TYPE_LONGLONG:
4066 case DRIZZLE_TYPE_DATETIME:
4067 case DRIZZLE_TYPE_TIME:
4068 case DRIZZLE_TYPE_DATE:
4069 case DRIZZLE_TYPE_TIMESTAMP:
4070 case DRIZZLE_TYPE_ENUM:
4071 return(DATA_INT);
4072 case DRIZZLE_TYPE_DOUBLE:
4073 return(DATA_DOUBLE);
4074 case DRIZZLE_TYPE_BLOB:
4075 return(DATA_BLOB);
4076 case DRIZZLE_TYPE_BOOLEAN:
4077 case DRIZZLE_TYPE_UUID:
4078 return(DATA_FIXBINARY);
4079 case DRIZZLE_TYPE_IPV6:
4080 return(DATA_FIXBINARY);
4081 case DRIZZLE_TYPE_NULL:
4082 ut_error;
4083 }
4084
4085 return(0);
4086}
4087
4088/*******************************************************************/
4091static inline
4092void
4094/*==============================*/
4095 byte* buf,
4096 ulint val)
4097{
4098 ut_a(val < 256 * 256);
4099
4100 buf[0] = (byte)(val & 0xFF);
4101 buf[1] = (byte)(val / 256);
4102}
4103
4104/*******************************************************************/
4108static inline
4109uint
4111/*===============================*/
4112 const unsigned char* buf)
4113{
4114 return (uint) ((ulint)(buf[0]) + 256 * ((ulint)(buf[1])));
4115}
4116
4117/*******************************************************************/
4120UNIV_INTERN
4121uint
4123/*===============================*/
4124 uint keynr,
4125 char* buff,
4127 uint buff_len,
4128 const unsigned char* record)
4129{
4130 KeyInfo* key_info = &getTable()->key_info[keynr];
4131 KeyPartInfo* key_part = key_info->key_part;
4132 KeyPartInfo* end = key_part + key_info->key_parts;
4133 char* buff_start = buff;
4134 enum_field_types mysql_type;
4135 Field* field;
4136 ibool is_null;
4137
4138 /* The format for storing a key field in MySQL is the following:
4139
4140 1. If the column can be NULL, then in the first byte we put 1 if the
4141 field value is NULL, 0 otherwise.
4142
4143 2. If the column is of a BLOB type (it must be a column prefix field
4144 in this case), then we put the length of the data in the field to the
4145 next 2 bytes, in the little-endian format. If the field is SQL NULL,
4146 then these 2 bytes are set to 0. Note that the length of data in the
4147 field is <= column prefix length.
4148
4149 3. In a column prefix field, prefix_len next bytes are reserved for
4150 data. In a normal field the max field length next bytes are reserved
4151 for data. For a VARCHAR(n) the max field length is n. If the stored
4152 value is the SQL NULL then these data bytes are set to 0.
4153
4154 4. We always use a 2 byte length for a true >= 5.0.3 VARCHAR. Note that
4155 in the MySQL row format, the length is stored in 1 or 2 bytes,
4156 depending on the maximum allowed length. But in the MySQL key value
4157 format, the length always takes 2 bytes.
4158
4159 We have to zero-fill the buffer so that MySQL is able to use a
4160 simple memcmp to compare two key values to determine if they are
4161 equal. MySQL does this to compare contents of two 'ref' values. */
4162
4163 bzero(buff, buff_len);
4164
4165 for (; key_part != end; key_part++) {
4166 is_null = FALSE;
4167
4168 if (key_part->null_bit) {
4169 if (record[key_part->null_offset]
4170 & key_part->null_bit) {
4171 *buff = 1;
4172 is_null = TRUE;
4173 } else {
4174 *buff = 0;
4175 }
4176 buff++;
4177 }
4178
4179 field = key_part->field;
4180 mysql_type = field->type();
4181
4182 if (mysql_type == DRIZZLE_TYPE_VARCHAR) {
4183 /* >= 5.0.3 true VARCHAR */
4184 ulint lenlen;
4185 ulint len;
4186 const byte* data;
4187 ulint key_len;
4188 ulint true_len;
4189 const charset_info_st* cs;
4190 int error=0;
4191
4192 key_len = key_part->length;
4193
4194 if (is_null) {
4195 buff += key_len + 2;
4196
4197 continue;
4198 }
4199 cs = field->charset();
4200
4201 lenlen = (ulint)
4202 (((Field_varstring*)field)->pack_length_no_ptr());
4203
4204 data = row_mysql_read_true_varchar(&len,
4205 (byte*) (record
4206 + (ulint)get_field_offset(getTable(), field)),
4207 lenlen);
4208
4209 true_len = len;
4210
4211 /* For multi byte character sets we need to calculate
4212 the true length of the key */
4213
4214 if (len > 0 && cs->mbmaxlen > 1) {
4215 true_len = (ulint) cs->cset->well_formed_len(*cs, str_ref(data, len), (uint) (key_len / cs->mbmaxlen), &error);
4216 }
4217
4218 /* In a column prefix index, we may need to truncate
4219 the stored value: */
4220
4221 if (true_len > key_len) {
4222 true_len = key_len;
4223 }
4224
4225 /* The length in a key value is always stored in 2
4226 bytes */
4227
4228 row_mysql_store_true_var_len((byte*)buff, true_len, 2);
4229 buff += 2;
4230
4231 memcpy(buff, data, true_len);
4232
4233 /* Note that we always reserve the maximum possible
4234 length of the true VARCHAR in the key value, though
4235 only len first bytes after the 2 length bytes contain
4236 actual data. The rest of the space was reset to zero
4237 in the bzero() call above. */
4238
4239 buff += key_len;
4240
4241 } else if (mysql_type == DRIZZLE_TYPE_BLOB) {
4242
4243 const charset_info_st* cs;
4244 ulint key_len;
4245 ulint true_len;
4246 int error=0;
4247 ulint blob_len;
4248 const byte* blob_data;
4249
4250 ut_a(key_part->key_part_flag & HA_PART_KEY_SEG);
4251
4252 key_len = key_part->length;
4253
4254 if (is_null) {
4255 buff += key_len + 2;
4256
4257 continue;
4258 }
4259
4260 cs = field->charset();
4261
4262 blob_data = row_mysql_read_blob_ref(&blob_len,
4263 (byte*) (record
4264 + (ulint)get_field_offset(getTable(), field)),
4265 (ulint) field->pack_length());
4266
4267 true_len = blob_len;
4268
4269 ut_a(get_field_offset(getTable(), field)
4270 == key_part->offset);
4271
4272 /* For multi byte character sets we need to calculate
4273 the true length of the key */
4274
4275 if (blob_len > 0 && cs->mbmaxlen > 1) {
4276 true_len = (ulint) cs->cset->well_formed_len(*cs, str_ref(blob_data, blob_len), (uint) (key_len / cs->mbmaxlen), &error);
4277 }
4278
4279 /* All indexes on BLOB and TEXT are column prefix
4280 indexes, and we may need to truncate the data to be
4281 stored in the key value: */
4282
4283 if (true_len > key_len) {
4284 true_len = key_len;
4285 }
4286
4287 /* MySQL reserves 2 bytes for the length and the
4288 storage of the number is little-endian */
4289
4291 (byte*)buff, true_len);
4292 buff += 2;
4293
4294 memcpy(buff, blob_data, true_len);
4295
4296 /* Note that we always reserve the maximum possible
4297 length of the BLOB prefix in the key value. */
4298
4299 buff += key_len;
4300 } else {
4301 /* Here we handle all other data types except the
4302 true VARCHAR, BLOB and TEXT. Note that the column
4303 value we store may be also in a column prefix
4304 index. */
4305
4306 ulint true_len;
4307 ulint key_len;
4308 const unsigned char* src_start;
4309 const charset_info_st* cs= field->charset();
4310
4311 key_len = key_part->length;
4312
4313 if (is_null) {
4314 buff += key_len;
4315
4316 continue;
4317 }
4318
4319 src_start = record + key_part->offset;
4320 true_len = key_len;
4321
4322 /* Character set for the field is defined only
4323 to fields whose type is string and real field
4324 type is not enum or set. For these fields check
4325 if character set is multi byte. */
4326
4327 memcpy(buff, src_start, true_len);
4328 buff += true_len;
4329
4330 /* Pad the unused space with spaces. */
4331
4332 if (true_len < key_len) {
4333 ulint pad_len = key_len - true_len;
4334 ut_a(!(pad_len % cs->mbminlen));
4335
4336 cs->cset->fill(cs, buff, pad_len,
4337 0x20 /* space */);
4338 buff += pad_len;
4339 }
4340 }
4341 }
4342
4343 ut_a(buff <= buff_start + buff_len);
4344
4345 return((uint)(buff - buff_start));
4346}
4347
4348/**************************************************************/
4351static
4352void
4354/*===========*/
4355 row_prebuilt_t* prebuilt,
4356 Session* ,
4359 Table* table,
4360 uint templ_type)
4362{
4363 dict_index_t* index;
4364 dict_index_t* clust_index;
4365 mysql_row_templ_t* templ;
4366 Field* field;
4367 ulint n_fields;
4368 ulint n_requested_fields = 0;
4369 ibool fetch_all_in_key = FALSE;
4370 ibool fetch_primary_key_cols = FALSE;
4371 ulint i= 0;
4372 /* byte offset of the end of last requested column */
4373 ulint mysql_prefix_len = 0;
4374
4375 if (prebuilt->select_lock_type == LOCK_X) {
4376 /* We always retrieve the whole clustered index record if we
4377 use exclusive row level locks, for example, if the read is
4378 done in an UPDATE statement. */
4379
4380 templ_type = ROW_MYSQL_WHOLE_ROW;
4381 }
4382
4383 if (templ_type == ROW_MYSQL_REC_FIELDS) {
4384 if (prebuilt->hint_need_to_fetch_extra_cols
4385 == ROW_RETRIEVE_ALL_COLS) {
4386
4387 /* We know we must at least fetch all columns in the
4388 key, or all columns in the table */
4389
4390 if (prebuilt->read_just_key) {
4391 /* MySQL has instructed us that it is enough
4392 to fetch the columns in the key; looks like
4393 MySQL can set this flag also when there is
4394 only a prefix of the column in the key: in
4395 that case we retrieve the whole column from
4396 the clustered index */
4397
4398 fetch_all_in_key = TRUE;
4399 } else {
4400 templ_type = ROW_MYSQL_WHOLE_ROW;
4401 }
4402 } else if (prebuilt->hint_need_to_fetch_extra_cols
4403 == ROW_RETRIEVE_PRIMARY_KEY) {
4404 /* We must at least fetch all primary key cols. Note
4405 that if the clustered index was internally generated
4406 by InnoDB on the row id (no primary key was
4407 defined), then row_search_for_mysql() will always
4408 retrieve the row id to a special buffer in the
4409 prebuilt struct. */
4410
4411 fetch_primary_key_cols = TRUE;
4412 }
4413 }
4414
4415 clust_index = dict_table_get_first_index(prebuilt->table);
4416
4417 if (templ_type == ROW_MYSQL_REC_FIELDS) {
4418 index = prebuilt->index;
4419 } else {
4420 index = clust_index;
4421 }
4422
4423 if (index == clust_index) {
4424 prebuilt->need_to_access_clustered = TRUE;
4425 } else {
4426 prebuilt->need_to_access_clustered = FALSE;
4427 /* Below we check column by column if we need to access
4428 the clustered index */
4429 }
4430
4431 n_fields = (ulint)table->getShare()->sizeFields(); /* number of columns */
4432
4433 if (!prebuilt->mysql_template) {
4434 prebuilt->mysql_template = (mysql_row_templ_t*)
4435 mem_alloc(n_fields * sizeof(mysql_row_templ_t));
4436 }
4437
4438 prebuilt->template_type = templ_type;
4439 prebuilt->null_bitmap_len = table->getShare()->null_bytes;
4440
4441 prebuilt->templ_contains_blob = FALSE;
4442
4443 /* Note that in InnoDB, i is the column number. MySQL calls columns
4444 'fields'. */
4445 for (i = 0; i < n_fields; i++)
4446 {
4447 const dict_col_t *col= &index->table->cols[i];
4448 templ = prebuilt->mysql_template + n_requested_fields;
4449 field = table->getField(i);
4450
4451 if (UNIV_LIKELY(templ_type == ROW_MYSQL_REC_FIELDS)) {
4452 /* Decide which columns we should fetch
4453 and which we can skip. */
4454 const ibool index_contains_field =
4455 dict_index_contains_col_or_prefix(index, i);
4456
4457 if (!index_contains_field && prebuilt->read_just_key) {
4458 /* If this is a 'key read', we do not need
4459 columns that are not in the key */
4460
4461 goto skip_field;
4462 }
4463
4464 if (index_contains_field && fetch_all_in_key) {
4465 /* This field is needed in the query */
4466
4467 goto include_field;
4468 }
4469
4470 if (field->isReadSet() || field->isWriteSet())
4471 /* This field is needed in the query */
4472 goto include_field;
4473
4474 assert(table->isReadSet(i) == field->isReadSet());
4475 assert(table->isWriteSet(i) == field->isWriteSet());
4476
4477 if (fetch_primary_key_cols
4478 && dict_table_col_in_clustered_key(
4479 index->table, i)) {
4480 /* This field is needed in the query */
4481
4482 goto include_field;
4483 }
4484
4485 /* This field is not needed in the query, skip it */
4486
4487 goto skip_field;
4488 }
4489include_field:
4490 n_requested_fields++;
4491
4492 templ->col_no = i;
4493 templ->clust_rec_field_no = dict_col_get_clust_pos(col, clust_index);
4494 ut_ad(templ->clust_rec_field_no != ULINT_UNDEFINED);
4495
4496 if (index == clust_index) {
4497 templ->rec_field_no = templ->clust_rec_field_no;
4498 } else {
4499 templ->rec_field_no = dict_index_get_nth_col_pos(
4500 index, i);
4501 if (templ->rec_field_no == ULINT_UNDEFINED) {
4502 prebuilt->need_to_access_clustered = TRUE;
4503 }
4504 }
4505
4506 if (field->null_ptr) {
4507 templ->mysql_null_byte_offset =
4508 (ulint) ((char*) field->null_ptr
4509 - (char*) table->getInsertRecord());
4510
4511 templ->mysql_null_bit_mask = (ulint) field->null_bit;
4512 } else {
4513 templ->mysql_null_bit_mask = 0;
4514 }
4515
4516 templ->mysql_col_offset = (ulint)
4517 get_field_offset(table, field);
4518
4519 templ->mysql_col_len = (ulint) field->pack_length();
4520 if (mysql_prefix_len < templ->mysql_col_offset
4521 + templ->mysql_col_len) {
4522 mysql_prefix_len = templ->mysql_col_offset
4523 + templ->mysql_col_len;
4524 }
4525 templ->type = col->mtype;
4526 templ->mysql_type = (ulint)field->type();
4527
4528 if (templ->mysql_type == DATA_MYSQL_TRUE_VARCHAR) {
4529 templ->mysql_length_bytes = (ulint)
4530 (((Field_varstring*)field)->pack_length_no_ptr());
4531 }
4532
4533 templ->charset = dtype_get_charset_coll(col->prtype);
4534 templ->mbminlen = dict_col_get_mbminlen(col);
4535 templ->mbmaxlen = dict_col_get_mbmaxlen(col);
4536 templ->is_unsigned = col->prtype & DATA_UNSIGNED;
4537 if (templ->type == DATA_BLOB) {
4538 prebuilt->templ_contains_blob = TRUE;
4539 }
4540skip_field:
4541 ;
4542 }
4543
4544 prebuilt->n_template = n_requested_fields;
4545 prebuilt->mysql_prefix_len = mysql_prefix_len;
4546
4547 if (index != clust_index && prebuilt->need_to_access_clustered) {
4548 /* Change rec_field_no's to correspond to the clustered index
4549 record */
4550 for (i = 0; i < n_requested_fields; i++) {
4551 templ = prebuilt->mysql_template + i;
4552
4553 templ->rec_field_no = templ->clust_rec_field_no;
4554 }
4555 }
4556}
4557
4558/********************************************************************/
4565UNIV_INTERN
4566ulint
4568/*====================================*/
4569{
4570 ulint error = DB_SUCCESS;
4571
4572 dict_table_autoinc_lock(prebuilt->table);
4573
4574 return(ulong(error));
4575}
4576
4577/********************************************************************/
4580UNIV_INTERN
4581ulint
4583/*================================*/
4584 uint64_t autoinc)
4585{
4586 dict_table_autoinc_lock(prebuilt->table);
4587 dict_table_autoinc_initialize(prebuilt->table, autoinc);
4588 dict_table_autoinc_unlock(prebuilt->table);
4589
4590 return(ulong(DB_SUCCESS));
4591}
4592
4593/********************************************************************/
4597UNIV_INTERN
4598ulint
4600/*==================================*/
4601 uint64_t auto_inc)
4602{
4603 dict_table_autoinc_lock(prebuilt->table);
4604 dict_table_autoinc_update_if_greater(prebuilt->table, auto_inc);
4605 dict_table_autoinc_unlock(prebuilt->table);
4606
4607 return(ulong(DB_SUCCESS));
4608}
4609
4610/********************************************************************/
4614UNIV_INTERN
4615int
4617/*===================*/
4618 unsigned char* record)
4619{
4620 ulint error = 0;
4621 int error_result= 0;
4622 ibool auto_inc_used= FALSE;
4623 ulint sql_command;
4624 trx_t* trx = session_to_trx(user_session);
4625
4626 if (prebuilt->trx != trx) {
4627 errmsg_printf(error::ERROR, "The transaction object for the table handle is at "
4628 "%p, but for the current thread it is at %p",
4629 (const void*) prebuilt->trx, (const void*) trx);
4630
4631 fputs("InnoDB: Dump of 200 bytes around prebuilt: ", stderr);
4632 ut_print_buf(stderr, ((const byte*)prebuilt) - 100, 200);
4633 fputs("\n"
4634 "InnoDB: Dump of 200 bytes around ha_data: ",
4635 stderr);
4636 ut_print_buf(stderr, ((const byte*) trx) - 100, 200);
4637 putc('\n', stderr);
4638 ut_error;
4639 }
4640
4641 sql_command = user_session->getSqlCommand();
4642
4643 if ((sql_command == SQLCOM_ALTER_TABLE
4644 || sql_command == SQLCOM_CREATE_INDEX
4645 || sql_command == SQLCOM_DROP_INDEX)
4646 && num_write_row >= 10000) {
4647 /* ALTER TABLE is COMMITted at every 10000 copied rows.
4648 The IX table lock for the original table has to be re-issued.
4649 As this method will be called on a temporary table where the
4650 contents of the original table is being copied to, it is
4651 a bit tricky to determine the source table. The cursor
4652 position in the source table need not be adjusted after the
4653 intermediate COMMIT, since writes by other transactions are
4654 being blocked by a MySQL table lock TL_WRITE_ALLOW_READ. */
4655
4656 dict_table_t* src_table;
4657 enum lock_mode mode;
4658
4659 num_write_row = 0;
4660
4661 /* Commit the transaction. This will release the table
4662 locks, so they have to be acquired again. */
4663
4664 /* Altering an InnoDB table */
4665 /* Get the source table. */
4666 src_table = lock_get_src_table(
4667 prebuilt->trx, prebuilt->table, &mode);
4668 if (!src_table) {
4669no_commit:
4670 /* Unknown situation: do not commit */
4671 /*
4672 ut_print_timestamp(stderr);
4673 fprintf(stderr,
4674 " InnoDB: ALTER TABLE is holding lock"
4675 " on %lu tables!\n",
4676 prebuilt->trx->mysql_n_tables_locked);
4677 */
4678 ;
4679 } else if (src_table == prebuilt->table) {
4680 /* Source table is not in InnoDB format:
4681 no need to re-acquire locks on it. */
4682
4683 /* Altering to InnoDB format */
4685 /* We will need an IX lock on the destination table. */
4686 prebuilt->sql_stat_start = TRUE;
4687 } else {
4688 /* Ensure that there are no other table locks than
4689 LOCK_IX and LOCK_AUTO_INC on the destination table. */
4690
4692 prebuilt->trx)) {
4693 goto no_commit;
4694 }
4695
4696 /* Commit the transaction. This will release the table
4697 locks, so they have to be acquired again. */
4699 /* Re-acquire the table lock on the source table. */
4700 row_lock_table_for_mysql(prebuilt, src_table, mode);
4701 /* We will need an IX lock on the destination table. */
4702 prebuilt->sql_stat_start = TRUE;
4703 }
4704 }
4705
4706 num_write_row++;
4707
4708 /* This is the case where the table has an auto-increment column */
4709 if (getTable()->next_number_field && record == getTable()->getInsertRecord()) {
4710
4711 /* Reset the error code before calling
4712 innobase_get_auto_increment(). */
4713 prebuilt->autoinc_error = DB_SUCCESS;
4714
4715 if ((error = update_auto_increment())) {
4716 /* We don't want to mask autoinc overflow errors. */
4717
4718 /* Handle the case where the AUTOINC sub-system
4719 failed during initialization. */
4720 if (prebuilt->autoinc_error == DB_UNSUPPORTED) {
4721 error_result = ER_AUTOINC_READ_FAILED;
4722 /* Set the error message to report too. */
4723 my_error(ER_AUTOINC_READ_FAILED, MYF(0));
4724 goto func_exit;
4725 } else if (prebuilt->autoinc_error != DB_SUCCESS) {
4726 error = (int) prebuilt->autoinc_error;
4727
4728 goto report_error;
4729 }
4730
4731 /* MySQL errors are passed straight back. */
4732 error_result = (int) error;
4733 goto func_exit;
4734 }
4735
4736 auto_inc_used = TRUE;
4737 }
4738
4739 if (prebuilt->mysql_template == NULL
4740 || prebuilt->template_type != ROW_MYSQL_WHOLE_ROW) {
4741
4742 /* Build the template used in converting quickly between
4743 the two database formats */
4744
4745 build_template(prebuilt, NULL, getTable(), ROW_MYSQL_WHOLE_ROW);
4746 }
4747
4749
4750 error = row_insert_for_mysql((byte*) record, prebuilt);
4751
4752 user_session->setXaId(trx->id);
4753
4754 /* Handle duplicate key errors */
4755 if (auto_inc_used) {
4756 ulint err;
4757 uint64_t auto_inc;
4758 uint64_t col_max_value;
4759
4760 /* Note the number of rows processed for this statement, used
4761 by get_auto_increment() to determine the number of AUTO-INC
4762 values to reserve. This is only useful for a mult-value INSERT
4763 and is a statement level counter.*/
4764 if (trx->n_autoinc_rows > 0) {
4765 --trx->n_autoinc_rows;
4766 }
4767
4768 /* We need the upper limit of the col type to check for
4769 whether we update the table autoinc counter or not. */
4770 col_max_value = innobase_get_int_col_max_value(
4771 getTable()->next_number_field);
4772 /* Get the value that MySQL attempted to store in the table.*/
4773 auto_inc = getTable()->next_number_field->val_int();
4774
4775 switch (error) {
4776 case DB_DUPLICATE_KEY:
4777
4778 /* A REPLACE command and LOAD DATA INFILE REPLACE
4779 handle a duplicate key error themselves, but we
4780 must update the autoinc counter if we are performing
4781 those statements. */
4782
4783 switch (sql_command) {
4784 case SQLCOM_LOAD:
4785 if ((trx->duplicates
4786 & (TRX_DUP_IGNORE | TRX_DUP_REPLACE))) {
4787
4788 goto set_max_autoinc;
4789 }
4790 break;
4791
4792 case SQLCOM_REPLACE:
4793 case SQLCOM_INSERT_SELECT:
4794 case SQLCOM_REPLACE_SELECT:
4795 goto set_max_autoinc;
4796
4797 default:
4798 break;
4799 }
4800
4801 break;
4802
4803 case DB_SUCCESS:
4804 /* If the actual value inserted is greater than
4805 the upper limit of the interval, then we try and
4806 update the table upper limit. Note: last_value
4807 will be 0 if get_auto_increment() was not called.*/
4808
4809 if (auto_inc >= prebuilt->autoinc_last_value) {
4810set_max_autoinc:
4811 /* This should filter out the negative
4812 values set explicitly by the user. */
4813 if (auto_inc <= col_max_value) {
4814 ut_a(prebuilt->autoinc_increment > 0);
4815
4816 uint64_t need;
4817 uint64_t offset;
4818
4819 offset = prebuilt->autoinc_offset;
4820 need = prebuilt->autoinc_increment;
4821
4822 auto_inc = innobase_next_autoinc(
4823 auto_inc,
4824 need, offset, col_max_value);
4825
4827 auto_inc);
4828
4829 if (err != DB_SUCCESS) {
4830 error = err;
4831 }
4832 }
4833 }
4834 break;
4835 }
4836 }
4837
4839
4840report_error:
4841 error_result = convert_error_code_to_mysql((int) error,
4842 prebuilt->table->flags,
4843 user_session);
4844
4845func_exit:
4847
4848 return(error_result);
4849}
4850
4851/**********************************************************************/
4855static
4856int
4858/*================*/
4859 upd_t* uvect,
4860 unsigned char* old_row,
4861 unsigned char* new_row,
4862 Table* table,
4864 unsigned char* upd_buff,
4865 ulint buff_len,
4866 row_prebuilt_t* prebuilt,
4867 Session* )
4868{
4869 unsigned char* original_upd_buff = upd_buff;
4870 enum_field_types field_mysql_type;
4871 uint n_fields;
4872 ulint o_len;
4873 ulint n_len;
4874 ulint col_pack_len;
4875 const byte* new_mysql_row_col;
4876 const byte* o_ptr;
4877 const byte* n_ptr;
4878 byte* buf;
4879 upd_field_t* ufield;
4880 ulint col_type;
4881 ulint n_changed = 0;
4882 dfield_t dfield;
4883 dict_index_t* clust_index;
4884 uint i= 0;
4885
4886 n_fields = table->getShare()->sizeFields();
4887 clust_index = dict_table_get_first_index(prebuilt->table);
4888
4889 /* We use upd_buff to convert changed fields */
4890 buf = (byte*) upd_buff;
4891
4892 for (i = 0; i < n_fields; i++) {
4893 Field *field= table->getField(i);
4894
4895 o_ptr = (const byte*) old_row + get_field_offset(table, field);
4896 n_ptr = (const byte*) new_row + get_field_offset(table, field);
4897
4898 /* Use new_mysql_row_col and col_pack_len save the values */
4899
4900 new_mysql_row_col = n_ptr;
4901 col_pack_len = field->pack_length();
4902
4903 o_len = col_pack_len;
4904 n_len = col_pack_len;
4905
4906 /* We use o_ptr and n_ptr to dig up the actual data for
4907 comparison. */
4908
4909 field_mysql_type = field->type();
4910
4911 col_type = prebuilt->table->cols[i].mtype;
4912
4913 switch (col_type) {
4914
4915 case DATA_BLOB:
4916 o_ptr = row_mysql_read_blob_ref(&o_len, o_ptr, o_len);
4917 n_ptr = row_mysql_read_blob_ref(&n_len, n_ptr, n_len);
4918
4919 break;
4920
4921 case DATA_VARCHAR:
4922 case DATA_BINARY:
4923 case DATA_VARMYSQL:
4924 if (field_mysql_type == DRIZZLE_TYPE_VARCHAR) {
4925 /* This is a >= 5.0.3 type true VARCHAR where
4926 the real payload data length is stored in
4927 1 or 2 bytes */
4928
4930 &o_len, o_ptr,
4931 (ulint)
4932 (((Field_varstring*)field)->pack_length_no_ptr()));
4933
4935 &n_len, n_ptr,
4936 (ulint)
4937 (((Field_varstring*)field)->pack_length_no_ptr()));
4938 }
4939
4940 break;
4941 default:
4942 ;
4943 }
4944
4945 if (field->null_ptr) {
4946 if (field_in_record_is_null(table, field,
4947 (char*) old_row)) {
4948 o_len = UNIV_SQL_NULL;
4949 }
4950
4951 if (field_in_record_is_null(table, field,
4952 (char*) new_row)) {
4953 n_len = UNIV_SQL_NULL;
4954 }
4955 }
4956
4957 if (o_len != n_len || (o_len != UNIV_SQL_NULL &&
4958 0 != memcmp(o_ptr, n_ptr, o_len))) {
4959 /* The field has changed */
4960
4961 ufield = uvect->fields + n_changed;
4962
4963 /* Let us use a dummy dfield to make the conversion
4964 from the MySQL column format to the InnoDB format */
4965
4966 dict_col_copy_type(prebuilt->table->cols + i,
4967 &dfield.type);
4968
4969 if (n_len != UNIV_SQL_NULL) {
4971 &dfield,
4972 (byte*)buf,
4973 TRUE,
4974 new_mysql_row_col,
4975 col_pack_len,
4976 dict_table_is_comp(prebuilt->table));
4977 dfield_copy_data(&ufield->new_val, &dfield);
4978 } else {
4979 dfield_set_null(&ufield->new_val);
4980 }
4981
4982 ufield->exp = NULL;
4983 ufield->orig_len = 0;
4985 &prebuilt->table->cols[i], clust_index);
4986 n_changed++;
4987 }
4988 }
4989
4990 uvect->n_fields = n_changed;
4991 uvect->info_bits = 0;
4992
4993 ut_a(buf <= (byte*)original_upd_buff + buff_len);
4994
4995 return(0);
4996}
4997
4998/**********************************************************************/
5006UNIV_INTERN
5007int
5009/*====================*/
5010 const unsigned char* old_row,
5011 unsigned char* new_row)
5012{
5013 upd_t* uvect;
5014 int error = 0;
5015 trx_t* trx = session_to_trx(user_session);
5016
5017 ut_a(prebuilt->trx == trx);
5018
5019 if (prebuilt->upd_node) {
5020 uvect = prebuilt->upd_node->update;
5021 } else {
5023 }
5024
5025 /* Build an update vector from the modified fields in the rows
5026 (uses upd_buff of the handle) */
5027
5028 calc_row_difference(uvect, (unsigned char*) old_row, new_row, getTable(),
5029 &upd_buff[0], (ulint)upd_and_key_val_buff_len,
5031
5032 /* This is not a delete */
5033 prebuilt->upd_node->is_delete = FALSE;
5034
5035 ut_a(prebuilt->template_type == ROW_MYSQL_WHOLE_ROW);
5036
5037 if (getTable()->found_next_number_field)
5038 {
5039 uint64_t auto_inc;
5040 uint64_t col_max_value;
5041
5042 auto_inc = getTable()->found_next_number_field->val_int();
5043
5044 /* We need the upper limit of the col type to check for
5045 whether we update the table autoinc counter or not. */
5046 col_max_value = innobase_get_int_col_max_value(
5047 getTable()->found_next_number_field);
5048
5049 uint64_t current_autoinc;
5050 ulint autoinc_error= innobase_get_autoinc(&current_autoinc);
5051 if (autoinc_error == DB_SUCCESS
5052 && auto_inc <= col_max_value && auto_inc != 0
5053 && auto_inc >= current_autoinc)
5054 {
5055
5056 uint64_t need;
5057 uint64_t offset;
5058
5059 offset = prebuilt->autoinc_offset;
5060 need = prebuilt->autoinc_increment;
5061
5062 auto_inc = innobase_next_autoinc(
5063 auto_inc, need, offset, col_max_value);
5064
5065 dict_table_autoinc_update_if_greater(prebuilt->table, auto_inc);
5066 }
5067
5068 dict_table_autoinc_unlock(prebuilt->table);
5069 }
5070
5072
5073 error = row_update_for_mysql((byte*) old_row, prebuilt);
5074
5075 user_session->setXaId(trx->id);
5076
5077 /* We need to do some special AUTOINC handling for the following case:
5078
5079 INSERT INTO t (c1,c2) VALUES(x,y) ON DUPLICATE KEY UPDATE ...
5080
5081 We need to use the AUTOINC counter that was actually used by
5082 MySQL in the UPDATE statement, which can be different from the
5083 value used in the INSERT statement.*/
5084
5085 if (error == DB_SUCCESS
5086 && getTable()->next_number_field
5087 && new_row == getTable()->getInsertRecord()
5088 && user_session->getSqlCommand() == SQLCOM_INSERT
5089 && (trx->duplicates & (TRX_DUP_IGNORE | TRX_DUP_REPLACE))
5090 == TRX_DUP_IGNORE) {
5091
5092 uint64_t auto_inc;
5093 uint64_t col_max_value;
5094
5095 auto_inc = getTable()->next_number_field->val_int();
5096
5097 /* We need the upper limit of the col type to check for
5098 whether we update the table autoinc counter or not. */
5099 col_max_value = innobase_get_int_col_max_value(
5100 getTable()->next_number_field);
5101
5102 if (auto_inc <= col_max_value && auto_inc != 0) {
5103
5104 uint64_t need;
5105 uint64_t offset;
5106
5107 offset = prebuilt->autoinc_offset;
5108 need = prebuilt->autoinc_increment;
5109
5110 auto_inc = innobase_next_autoinc(
5111 auto_inc, need, offset, col_max_value);
5112
5113 error = innobase_set_max_autoinc(auto_inc);
5114 }
5115 }
5116
5118
5119 error = convert_error_code_to_mysql(error,
5120 prebuilt->table->flags,
5121 user_session);
5122
5123 if (error == 0 /* success */
5124 && uvect->n_fields == 0 /* no columns were updated */) {
5125
5126 /* This is the same as success, but instructs
5127 MySQL that the row is not really updated and it
5128 should not increase the count of updated rows.
5129 This is fix for http://bugs.mysql.com/29157 */
5130 error = HA_ERR_RECORD_IS_THE_SAME;
5131 }
5132
5133 /* Tell InnoDB server that there might be work for
5134 utility threads: */
5135
5137
5138 return(error);
5139}
5140
5141/**********************************************************************/
5144UNIV_INTERN
5145int
5147/*====================*/
5148 const unsigned char* record)
5149{
5150 int error = 0;
5151 trx_t* trx = session_to_trx(user_session);
5152
5153 ut_a(prebuilt->trx == trx);
5154
5155 if (!prebuilt->upd_node) {
5157 }
5158
5159 /* This is a delete */
5160
5161 prebuilt->upd_node->is_delete = TRUE;
5162
5164
5165 error = row_update_for_mysql((byte*) record, prebuilt);
5166
5167 user_session->setXaId(trx->id);
5168
5170
5172 error, prebuilt->table->flags, user_session);
5173
5174 /* Tell the InnoDB server that there might be work for
5175 utility threads: */
5176
5178
5179 return(error);
5180}
5181
5182/**********************************************************************/
5186UNIV_INTERN
5187void
5189/*=========================*/
5190{
5191 /* Consistent read does not take any locks, thus there is
5192 nothing to unlock. */
5193
5194 if (prebuilt->select_lock_type == LOCK_NONE) {
5195 return;
5196 }
5197
5198 switch (prebuilt->row_read_type) {
5199 case ROW_READ_WITH_LOCKS:
5201 && prebuilt->trx->isolation_level
5202 > TRX_ISO_READ_COMMITTED) {
5203 break;
5204 }
5205 /* fall through */
5206 case ROW_READ_TRY_SEMI_CONSISTENT:
5208 break;
5209 case ROW_READ_DID_SEMI_CONSISTENT:
5210 prebuilt->row_read_type = ROW_READ_TRY_SEMI_CONSISTENT;
5211 break;
5212 }
5213
5214 return;
5215}
5216
5217/* See Cursor.h and row0mysql.h for docs on this function. */
5218UNIV_INTERN
5219bool
5221/*=======================================*/
5222{
5223 return(prebuilt->row_read_type == ROW_READ_DID_SEMI_CONSISTENT);
5224}
5225
5226/* See Cursor.h and row0mysql.h for docs on this function. */
5227UNIV_INTERN
5228void
5230/*===========================================*/
5231{
5232 ut_a(prebuilt->trx == session_to_trx(getTable()->in_use));
5233
5234 /* Row read type is set to semi consistent read if this was
5235 requested by the MySQL and either innodb_locks_unsafe_for_binlog
5236 option is used or this session is using READ COMMITTED isolation
5237 level. */
5238
5239 if (yes
5241 || prebuilt->trx->isolation_level <= TRX_ISO_READ_COMMITTED)) {
5242 prebuilt->row_read_type = ROW_READ_TRY_SEMI_CONSISTENT;
5243 } else {
5244 prebuilt->row_read_type = ROW_READ_WITH_LOCKS;
5245 }
5246}
5247
5248/******************************************************************/
5251UNIV_INTERN
5252int
5254/*====================*/
5255 uint keynr,
5256 bool )
5257{
5258 return(change_active_index(keynr));
5259}
5260
5261/******************************************************************/
5264UNIV_INTERN
5265int
5267/*========================*/
5268{
5269 int error = 0;
5270 active_index=MAX_KEY;
5271 return(error);
5272}
5273
5274/*********************************************************************/
5277static inline
5278ulint
5280/*============================*/
5281 enum ha_rkey_function find_flag)
5282{
5283 switch (find_flag) {
5284 case HA_READ_KEY_EXACT:
5285 /* this does not require the index to be UNIQUE */
5286 return(PAGE_CUR_GE);
5287 case HA_READ_KEY_OR_NEXT:
5288 return(PAGE_CUR_GE);
5289 case HA_READ_KEY_OR_PREV:
5290 return(PAGE_CUR_LE);
5291 case HA_READ_AFTER_KEY:
5292 return(PAGE_CUR_G);
5293 case HA_READ_BEFORE_KEY:
5294 return(PAGE_CUR_L);
5295 case HA_READ_PREFIX:
5296 return(PAGE_CUR_GE);
5297 case HA_READ_PREFIX_LAST:
5298 return(PAGE_CUR_LE);
5299 case HA_READ_PREFIX_LAST_OR_PREV:
5300 return(PAGE_CUR_LE);
5301 /* In MySQL-4.0 HA_READ_PREFIX and HA_READ_PREFIX_LAST always
5302 pass a complete-field prefix of a key value as the search
5303 tuple. I.e., it is not allowed that the last field would
5304 just contain n first bytes of the full field value.
5305 MySQL uses a 'padding' trick to convert LIKE 'abc%'
5306 type queries so that it can use as a search tuple
5307 a complete-field-prefix of a key value. Thus, the InnoDB
5308 search mode PAGE_CUR_LE_OR_EXTENDS is never used.
5309 TODO: when/if MySQL starts to use also partial-field
5310 prefixes, we have to deal with stripping of spaces
5311 and comparison of non-latin1 char type fields in
5312 innobase_mysql_cmp() to get PAGE_CUR_LE_OR_EXTENDS to
5313 work correctly. */
5314 case HA_READ_MBR_CONTAIN:
5315 case HA_READ_MBR_INTERSECT:
5316 case HA_READ_MBR_WITHIN:
5317 case HA_READ_MBR_DISJOINT:
5318 case HA_READ_MBR_EQUAL:
5319 return(PAGE_CUR_UNSUPP);
5320 /* do not use "default:" in order to produce a gcc warning:
5321 enumeration value '...' not handled in switch
5322 (if -Wswitch or -Wall is used) */
5323 }
5324
5325 my_error(ER_CHECK_NOT_IMPLEMENTED, MYF(0), "this functionality");
5326
5327 return(PAGE_CUR_UNSUPP);
5328}
5329
5330/*
5331 BACKGROUND INFO: HOW A SELECT SQL QUERY IS EXECUTED
5332 ---------------------------------------------------
5333The following does not cover all the details, but explains how we determine
5334the start of a new SQL statement, and what is associated with it.
5335
5336For each table in the database the MySQL interpreter may have several
5337table handle instances in use, also in a single SQL query. For each table
5338handle instance there is an InnoDB 'prebuilt' struct which contains most
5339of the InnoDB data associated with this table handle instance.
5340
5341 A) if the user has not explicitly set any MySQL table level locks:
5342
5343 1) Drizzle calls StorageEngine::doStartStatement(), indicating to
5344 InnoDB that a new SQL statement has begun.
5345
5346 2a) For each InnoDB-managed table in the SELECT, Drizzle calls ::external_lock
5347 to set an 'intention' table level lock on the table of the Cursor instance.
5348 There we set prebuilt->sql_stat_start = TRUE. The flag sql_stat_start should
5349 be set true if we are taking this table handle instance to use in a new SQL
5350 statement issued by the user.
5351
5352 2b) If prebuilt->sql_stat_start == TRUE we 'pre-compile' the MySQL search
5353instructions to prebuilt->template of the table handle instance in
5354::index_read. The template is used to save CPU time in large joins.
5355
5356 3) In row_search_for_mysql, if prebuilt->sql_stat_start is true, we
5357allocate a new consistent read view for the trx if it does not yet have one,
5358or in the case of a locking read, set an InnoDB 'intention' table level
5359lock on the table.
5360
5361 4) We do the SELECT. MySQL may repeatedly call ::index_read for the
5362same table handle instance, if it is a join.
5363
53645) When the SELECT ends, the Drizzle kernel calls doEndStatement()
5365
5366 (a) we execute a COMMIT there if the autocommit is on. The Drizzle interpreter
5367 does NOT execute autocommit for pure read transactions, though it should.
5368 That is why we must execute the COMMIT in ::doEndStatement().
5369 (b) we also release possible 'SQL statement level resources' InnoDB may
5370 have for this SQL statement.
5371
5372 @todo
5373
5374 Remove need for InnoDB to call autocommit for read-only trx
5375
5376 @todo Check the below is still valid (I don't think it is...)
5377
5378 B) If the user has explicitly set MySQL table level locks, then MySQL
5379does NOT call ::external_lock at the start of the statement. To determine
5380when we are at the start of a new SQL statement we at the start of
5381::index_read also compare the query id to the latest query id where the
5382table handle instance was used. If it has changed, we know we are at the
5383start of a new SQL statement. Since the query id can theoretically
5384overwrap, we use this test only as a secondary way of determining the
5385start of a new SQL statement. */
5386
5387
5388/**********************************************************************/
5392UNIV_INTERN
5393int
5395/*====================*/
5396 unsigned char* buf,
5398 const unsigned char* key_ptr,
5407 uint key_len,
5408 enum ha_rkey_function find_flag)
5409{
5410 ulint mode;
5411 dict_index_t* index;
5412 ulint match_mode = 0;
5413 int error;
5414 ulint ret;
5415
5417
5418 ha_statistic_increment(&system_status_var::ha_read_key_count);
5419
5420 index = prebuilt->index;
5421
5422 if (UNIV_UNLIKELY(index == NULL)) {
5423 prebuilt->index_usable = FALSE;
5424 return(HA_ERR_CRASHED);
5425 }
5426
5427 if (UNIV_UNLIKELY(!prebuilt->index_usable)) {
5428 return(HA_ERR_TABLE_DEF_CHANGED);
5429 }
5430
5431 /* Note that if the index for which the search template is built is not
5432 necessarily prebuilt->index, but can also be the clustered index */
5433
5434 if (prebuilt->sql_stat_start) {
5436 ROW_MYSQL_REC_FIELDS);
5437 }
5438
5439 if (key_ptr) {
5440 /* Convert the search key value to InnoDB format into
5441 prebuilt->search_tuple */
5442
5444 prebuilt->search_tuple,
5445 (byte*) &key_val_buff[0],
5446 (ulint)upd_and_key_val_buff_len,
5447 index,
5448 (byte*) key_ptr,
5449 (ulint) key_len,
5450 prebuilt->trx);
5451 } else {
5452 /* We position the cursor to the last or the first entry
5453 in the index */
5454
5455 dtuple_set_n_fields(prebuilt->search_tuple, 0);
5456 }
5457
5458 mode = convert_search_mode_to_innobase(find_flag);
5459
5460 match_mode = 0;
5461
5462 if (find_flag == HA_READ_KEY_EXACT) {
5463
5464 match_mode = ROW_SEL_EXACT;
5465
5466 } else if (find_flag == HA_READ_PREFIX
5467 || find_flag == HA_READ_PREFIX_LAST) {
5468
5469 match_mode = ROW_SEL_EXACT_PREFIX;
5470 }
5471
5472 last_match_mode = (uint) match_mode;
5473
5474 if (mode != PAGE_CUR_UNSUPP) {
5475
5477
5478 ret = row_search_for_mysql((byte*) buf, mode, prebuilt,
5479 match_mode, 0);
5480
5482 } else {
5483
5484 ret = DB_UNSUPPORTED;
5485 }
5486
5487 switch (ret) {
5488 case DB_SUCCESS:
5489 error = 0;
5490 getTable()->status = 0;
5491 break;
5492 case DB_RECORD_NOT_FOUND:
5493 error = HA_ERR_KEY_NOT_FOUND;
5494 getTable()->status = STATUS_NOT_FOUND;
5495 break;
5496 case DB_END_OF_INDEX:
5497 error = HA_ERR_KEY_NOT_FOUND;
5498 getTable()->status = STATUS_NOT_FOUND;
5499 break;
5500 default:
5501 error = convert_error_code_to_mysql((int) ret,
5502 prebuilt->table->flags,
5503 user_session);
5504 getTable()->status = STATUS_NOT_FOUND;
5505 break;
5506 }
5507
5508 return(error);
5509}
5510
5511/*******************************************************************/
5515UNIV_INTERN
5516int
5518/*=========================*/
5519 unsigned char* buf,
5520 const unsigned char* key_ptr,
5522 uint key_len)
5524{
5525 return(index_read(buf, key_ptr, key_len, HA_READ_PREFIX_LAST));
5526}
5527
5528/********************************************************************/
5531UNIV_INTERN
5532dict_index_t*
5534/*============================*/
5535 uint keynr)
5538{
5539 dict_index_t* index = 0;
5540
5541 ha_statistic_increment(&system_status_var::ha_read_key_count);
5542
5543 if (keynr != MAX_KEY && getTable()->getShare()->sizeKeys() > 0)
5544 {
5545 KeyInfo *key = getTable()->key_info + keynr;
5546 index = innobase_index_lookup(share, keynr);
5547
5548 if (index) {
5549 ut_a(ut_strcmp(index->name, key->name) == 0);
5550 } else {
5551 /* Can't find index with keynr in the translation
5552 table. Only print message if the index translation
5553 table exists */
5554 if (share->idx_trans_tbl.index_mapping) {
5555 errmsg_printf(error::ERROR,
5556 "InnoDB could not find "
5557 "index %s key no %u for "
5558 "table %s through its "
5559 "index translation table",
5560 key ? key->name : "NULL",
5561 keynr,
5562 prebuilt->table->name);
5563 }
5564
5565 index = dict_table_get_index_on_name(prebuilt->table,
5566 key->name);
5567 }
5568 } else {
5569 index = dict_table_get_first_index(prebuilt->table);
5570 }
5571
5572 if (!index) {
5573 errmsg_printf(error::ERROR,
5574 "Innodb could not find key n:o %u with name %s "
5575 "from dict cache for table %s",
5576 keynr, getTable()->getShare()->getTableMessage()->indexes(keynr).name().c_str(),
5577 prebuilt->table->name);
5578 }
5579
5580 return(index);
5581}
5582
5583/********************************************************************/
5586UNIV_INTERN
5587int
5589/*=============================*/
5590 uint keynr)
5593{
5594 ut_ad(user_session == table->in_use);
5596
5597 active_index = keynr;
5598
5599 prebuilt->index = innobase_get_index(keynr);
5600
5601 if (UNIV_UNLIKELY(!prebuilt->index)) {
5602 errmsg_printf(error::WARN, "InnoDB: change_active_index(%u) failed",
5603 keynr);
5604 prebuilt->index_usable = FALSE;
5605 return(1);
5606 }
5607
5608 prebuilt->index_usable = row_merge_is_index_usable(prebuilt->trx,
5609 prebuilt->index);
5610
5611 if (UNIV_UNLIKELY(!prebuilt->index_usable)) {
5612 push_warning_printf(user_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
5613 HA_ERR_TABLE_DEF_CHANGED,
5614 "InnoDB: insufficient history for index %u",
5615 keynr);
5616 /* The caller seems to ignore this. Thus, we must check
5617 this again in row_search_for_mysql(). */
5618 return(2);
5619 }
5620
5621 ut_a(prebuilt->search_tuple != 0);
5622
5623 dtuple_set_n_fields(prebuilt->search_tuple, prebuilt->index->n_fields);
5624
5625 dict_index_copy_types(prebuilt->search_tuple, prebuilt->index,
5626 prebuilt->index->n_fields);
5627
5628 /* MySQL changes the active index for a handle also during some
5629 queries, for example SELECT MAX(a), SUM(a) first retrieves the MAX()
5630 and then calculates the sum. Previously we played safe and used
5631 the flag ROW_MYSQL_WHOLE_ROW below, but that caused unnecessary
5632 copying. Starting from MySQL-4.1 we use a more efficient flag here. */
5633
5634 build_template(prebuilt, user_session, getTable(), ROW_MYSQL_REC_FIELDS);
5635
5636 return(0);
5637}
5638
5639/**********************************************************************/
5644UNIV_INTERN
5645int
5647/*========================*/
5648 unsigned char* buf,
5650 uint keynr,
5651 const unsigned char* key,
5654 uint key_len,
5655 enum ha_rkey_function find_flag)
5656{
5657 if (change_active_index(keynr)) {
5658
5659 return(1);
5660 }
5661
5662 return(index_read(buf, key, key_len, find_flag));
5663}
5664
5665/***********************************************************************/
5669UNIV_INTERN
5670int
5672/*=======================*/
5673 unsigned char* buf,
5675 uint direction,
5676 uint match_mode)
5678{
5679 ulint ret;
5680 int error = 0;
5681
5683
5685
5687 (byte*)buf, 0, prebuilt, match_mode, direction);
5688
5690
5691 switch (ret) {
5692 case DB_SUCCESS:
5693 error = 0;
5694 getTable()->status = 0;
5695 break;
5696 case DB_RECORD_NOT_FOUND:
5697 error = HA_ERR_END_OF_FILE;
5698 getTable()->status = STATUS_NOT_FOUND;
5699 break;
5700 case DB_END_OF_INDEX:
5701 error = HA_ERR_END_OF_FILE;
5702 getTable()->status = STATUS_NOT_FOUND;
5703 break;
5704 default:
5706 (int) ret, prebuilt->table->flags, user_session);
5707 getTable()->status = STATUS_NOT_FOUND;
5708 break;
5709 }
5710
5711 return(error);
5712}
5713
5714/***********************************************************************/
5718UNIV_INTERN
5719int
5721/*====================*/
5722 unsigned char* buf)
5724{
5725 ha_statistic_increment(&system_status_var::ha_read_next_count);
5726
5727 return(general_fetch(buf, ROW_SEL_NEXT, 0));
5728}
5729
5730/*******************************************************************/
5733UNIV_INTERN
5734int
5736/*=========================*/
5737 unsigned char* buf,
5738 const unsigned char* ,
5739 uint )
5740{
5741 ha_statistic_increment(&system_status_var::ha_read_next_count);
5742
5743 return(general_fetch(buf, ROW_SEL_NEXT, last_match_mode));
5744}
5745
5746/***********************************************************************/
5750UNIV_INTERN
5751int
5753/*====================*/
5754 unsigned char* buf)
5755{
5756 ha_statistic_increment(&system_status_var::ha_read_prev_count);
5757
5758 return(general_fetch(buf, ROW_SEL_PREV, 0));
5759}
5760
5761/********************************************************************/
5765UNIV_INTERN
5766int
5768/*=====================*/
5769 unsigned char* buf)
5770{
5771 int error;
5772
5773 ha_statistic_increment(&system_status_var::ha_read_first_count);
5774
5775 error = index_read(buf, NULL, 0, HA_READ_AFTER_KEY);
5776
5777 /* MySQL does not seem to allow this to return HA_ERR_KEY_NOT_FOUND */
5778
5779 if (error == HA_ERR_KEY_NOT_FOUND) {
5780 error = HA_ERR_END_OF_FILE;
5781 }
5782
5783 return(error);
5784}
5785
5786/********************************************************************/
5790UNIV_INTERN
5791int
5793/*====================*/
5794 unsigned char* buf)
5795{
5796 int error;
5797
5798 ha_statistic_increment(&system_status_var::ha_read_last_count);
5799
5800 error = index_read(buf, NULL, 0, HA_READ_BEFORE_KEY);
5801
5802 /* MySQL does not seem to allow this to return HA_ERR_KEY_NOT_FOUND */
5803
5804 if (error == HA_ERR_KEY_NOT_FOUND) {
5805 error = HA_ERR_END_OF_FILE;
5806 }
5807
5808 return(error);
5809}
5810
5811/****************************************************************/
5814UNIV_INTERN
5815int
5817/*==================*/
5818 bool scan)
5819{
5820 int err;
5821
5822 /* Store the active index value so that we can restore the original
5823 value after a scan */
5824
5825 if (prebuilt->clust_index_was_generated) {
5826 err = change_active_index(MAX_KEY);
5827 } else {
5828 err = change_active_index(primary_key);
5829 }
5830
5831 /* Don't use semi-consistent read in random row reads (by position).
5832 This means we must disable semi_consistent_read if scan is false */
5833
5834 if (!scan) {
5836 }
5837
5838 start_of_scan = 1;
5839
5840 return(err);
5841}
5842
5843/*****************************************************************/
5846UNIV_INTERN
5847int
5849/*======================*/
5850{
5851 return(doEndIndexScan());
5852}
5853
5854/*****************************************************************/
5858UNIV_INTERN
5859int
5861/*==================*/
5862 unsigned char* buf)
5864{
5865 int error;
5866
5867 ha_statistic_increment(&system_status_var::ha_read_rnd_next_count);
5868
5869 if (start_of_scan) {
5870 error = index_first(buf);
5871
5872 if (error == HA_ERR_KEY_NOT_FOUND) {
5873 error = HA_ERR_END_OF_FILE;
5874 }
5875
5876 start_of_scan = 0;
5877 } else {
5878 error = general_fetch(buf, ROW_SEL_NEXT, 0);
5879 }
5880
5881 return(error);
5882}
5883
5884/**********************************************************************/
5887UNIV_INTERN
5888int
5890/*=================*/
5891 unsigned char* buf,
5892 unsigned char* pos)
5896{
5897 int error;
5898 uint keynr = active_index;
5899
5900 ha_statistic_increment(&system_status_var::ha_read_rnd_count);
5901
5902 ut_a(prebuilt->trx == session_to_trx(getTable()->in_use));
5903
5904 if (prebuilt->clust_index_was_generated) {
5905 /* No primary key was defined for the table and we
5906 generated the clustered index from the row id: the
5907 row reference is the row id, not any key value
5908 that MySQL knows of */
5909
5910 error = change_active_index(MAX_KEY);
5911 } else {
5912 error = change_active_index(primary_key);
5913 }
5914
5915 if (error) {
5916 return(error);
5917 }
5918
5919 /* Note that we assume the length of the row reference is fixed
5920 for the table, and it is == ref_length */
5921
5922 error = index_read(buf, pos, ref_length, HA_READ_KEY_EXACT);
5923
5924 if (error) {
5925 }
5926
5927 change_active_index(keynr);
5928
5929 return(error);
5930}
5931
5932/*********************************************************************/
5940UNIV_INTERN
5941void
5943/*==================*/
5944 const unsigned char* record)
5945{
5946 uint len;
5947
5948 ut_a(prebuilt->trx == session_to_trx(getTable()->in_use));
5949
5950 if (prebuilt->clust_index_was_generated) {
5951 /* No primary key was defined for the table and we
5952 generated the clustered index from row id: the
5953 row reference will be the row id, not any key value
5954 that MySQL knows of */
5955
5956 len = DATA_ROW_ID_LEN;
5957
5958 memcpy(ref, prebuilt->row_id, len);
5959 } else {
5960 len = store_key_val_for_row(primary_key, (char*)ref,
5961 ref_length, record);
5962 }
5963
5964 /* We assume that the 'ref' value len is always fixed for the same
5965 table. */
5966
5967 if (len != ref_length) {
5968 errmsg_printf(error::ERROR, "Stored ref len is %lu, but table ref len is %lu",
5969 (ulong) len, (ulong) ref_length);
5970 }
5971}
5972
5973
5974/*****************************************************************/
5976static
5977int
5979/*=============*/
5980 trx_t* trx,
5981 Table* form,
5983 const char* table_name,
5984 const char* path_of_temp_table,
5992 ulint flags)
5993{
5994 Field* field;
5995 dict_table_t* table;
5996 ulint n_cols;
5997 int error;
5998 ulint col_type;
5999 ulint col_len;
6000 ulint nulls_allowed;
6001 ulint unsigned_type;
6002 ulint binary_type;
6003 ulint long_true_varchar;
6004 ulint charset_no;
6005 ulint i;
6006
6007 n_cols = form->getShare()->sizeFields();
6008
6009 /* We pass 0 as the space id, and determine at a lower level the space
6010 id where to store the table */
6011
6012 table = dict_mem_table_create(table_name, 0, n_cols, flags);
6013
6014 if (path_of_temp_table) {
6015 table->dir_path_of_temp_table =
6016 mem_heap_strdup(table->heap, path_of_temp_table);
6017 }
6018
6019 for (i = 0; i < n_cols; i++) {
6020 field = form->getField(i);
6021
6022 col_type = get_innobase_type_from_mysql_type(&unsigned_type,
6023 field);
6024
6025 if (!col_type) {
6026 push_warning_printf(
6027 trx->mysql_thd,
6028 DRIZZLE_ERROR::WARN_LEVEL_WARN,
6029 ER_CANT_CREATE_TABLE,
6030 "Error creating table '%s' with "
6031 "column '%s'. Please check its "
6032 "column type and try to re-create "
6033 "the table with an appropriate "
6034 "column type.",
6035 table->name, (char*) field->field_name);
6036 goto err_col;
6037 }
6038
6039 if (field->null_ptr) {
6040 nulls_allowed = 0;
6041 } else {
6042 nulls_allowed = DATA_NOT_NULL;
6043 }
6044
6045 if (field->binary()) {
6046 binary_type = DATA_BINARY_TYPE;
6047 } else {
6048 binary_type = 0;
6049 }
6050
6051 charset_no = 0;
6052
6053 if (dtype_is_string_type(col_type)) {
6054
6055 charset_no = (ulint)field->charset()->number;
6056
6057 if (UNIV_UNLIKELY(charset_no >= 256)) {
6058 /* in data0type.h we assume that the
6059 number fits in one byte in prtype */
6060 push_warning_printf(
6061 trx->mysql_thd,
6062 DRIZZLE_ERROR::WARN_LEVEL_ERROR,
6063 ER_CANT_CREATE_TABLE,
6064 "In InnoDB, charset-collation codes"
6065 " must be below 256."
6066 " Unsupported code %lu.",
6067 (ulong) charset_no);
6068 return(ER_CANT_CREATE_TABLE);
6069 }
6070 }
6071
6072 ut_a(field->type() < 256); /* we assume in dtype_form_prtype()
6073 that this fits in one byte */
6074 col_len = field->pack_length();
6075
6076 /* The MySQL pack length contains 1 or 2 bytes length field
6077 for a true VARCHAR. Let us subtract that, so that the InnoDB
6078 column length in the InnoDB data dictionary is the real
6079 maximum byte length of the actual data. */
6080
6081 long_true_varchar = 0;
6082
6083 if (field->type() == DRIZZLE_TYPE_VARCHAR) {
6084 col_len -= ((Field_varstring*)field)->pack_length_no_ptr();
6085
6086 if (((Field_varstring*)field)->pack_length_no_ptr() == 2) {
6087 long_true_varchar = DATA_LONG_TRUE_VARCHAR;
6088 }
6089 }
6090
6091 /* First check whether the column to be added has a
6092 system reserved name. */
6093 if (dict_col_name_is_reserved(field->field_name)){
6094 my_error(ER_WRONG_COLUMN_NAME, MYF(0), field->field_name);
6095
6096 err_col:
6097 dict_mem_table_free(table);
6099
6100 error = DB_ERROR;
6101 goto error_ret;
6102 }
6103
6104 dict_mem_table_add_col(table, table->heap,
6105 (char*) field->field_name,
6106 col_type,
6107 dtype_form_prtype(
6108 (ulint)field->type()
6109 | nulls_allowed | unsigned_type
6110 | binary_type | long_true_varchar,
6111 charset_no),
6112 col_len);
6113 }
6114
6115 error = row_create_table_for_mysql(table, trx);
6116
6117 if (error == DB_DUPLICATE_KEY) {
6118 char buf[100];
6119 char* buf_end = innobase_convert_identifier(
6120 buf, sizeof buf - 1, table_name, strlen(table_name),
6121 trx->mysql_thd, TRUE);
6122
6123 *buf_end = '\0';
6124 my_error(ER_TABLE_EXISTS_ERROR, MYF(0), buf);
6125 }
6126
6127error_ret:
6128 error = convert_error_code_to_mysql(error, flags, NULL);
6129
6130 return(error);
6131}
6132
6133/*****************************************************************/
6135static
6136int
6138/*=========*/
6139 trx_t* trx,
6140 Table* form,
6142 ulint flags,
6143 const char* table_name,
6144 uint key_num)
6145{
6146 Field* field;
6147 dict_index_t* index;
6148 int error;
6149 ulint n_fields;
6150 KeyInfo* key;
6151 KeyPartInfo* key_part;
6152 ulint ind_type;
6153 ulint col_type;
6154 ulint prefix_len;
6155 ulint is_unsigned;
6156 ulint i;
6157 ulint j;
6158 ulint* field_lengths;
6159
6160 key = &form->key_info[key_num];
6161
6162 n_fields = key->key_parts;
6163
6164 /* Assert that "GEN_CLUST_INDEX" cannot be used as non-primary index */
6165 ut_a(innobase_strcasecmp(key->name, innobase_index_reserve_name) != 0);
6166
6167 ind_type = 0;
6168
6169 if (key_num == form->getShare()->getPrimaryKey()) {
6170 ind_type = ind_type | DICT_CLUSTERED;
6171 }
6172
6173 if (key->flags & HA_NOSAME ) {
6174 ind_type = ind_type | DICT_UNIQUE;
6175 }
6176
6177 /* We pass 0 as the space id, and determine at a lower level the space
6178 id where to store the table */
6179
6180 index = dict_mem_index_create(table_name, key->name, 0,
6181 ind_type, n_fields);
6182
6183 field_lengths = (ulint*) malloc(sizeof(ulint) * n_fields);
6184
6185 for (i = 0; i < n_fields; i++) {
6186 key_part = key->key_part + i;
6187
6188 /* (The flag HA_PART_KEY_SEG denotes in MySQL a column prefix
6189 field in an index: we only store a specified number of first
6190 bytes of the column to the index field.) The flag does not
6191 seem to be properly set by MySQL. Let us fall back on testing
6192 the length of the key part versus the column. */
6193
6194 field = NULL;
6195 for (j = 0; j < form->getShare()->sizeFields(); j++)
6196 {
6197
6198 field = form->getField(j);
6199
6200 if (0 == innobase_strcasecmp(
6201 field->field_name,
6202 key_part->field->field_name)) {
6203 /* Found the corresponding column */
6204
6205 break;
6206 }
6207 }
6208
6209 ut_a(j < form->getShare()->sizeFields());
6210
6212 &is_unsigned, key_part->field);
6213
6214 if (DATA_BLOB == col_type
6215 || (key_part->length < field->pack_length()
6216 && field->type() != DRIZZLE_TYPE_VARCHAR)
6217 || (field->type() == DRIZZLE_TYPE_VARCHAR
6218 && key_part->length < field->pack_length()
6219 - ((Field_varstring*)field)->pack_length_no_ptr())) {
6220
6221 prefix_len = key_part->length;
6222
6223 if (col_type == DATA_INT
6224 || col_type == DATA_FLOAT
6225 || col_type == DATA_DOUBLE
6226 || col_type == DATA_DECIMAL) {
6227 errmsg_printf(error::ERROR,
6228 "MySQL is trying to create a column "
6229 "prefix index field, on an "
6230 "inappropriate data type. Table "
6231 "name %s, column name %s.",
6232 table_name,
6233 key_part->field->field_name);
6234
6235 prefix_len = 0;
6236 }
6237 } else {
6238 prefix_len = 0;
6239 }
6240
6241 field_lengths[i] = key_part->length;
6242
6243 dict_mem_index_add_field(index,
6244 (char*) key_part->field->field_name, prefix_len);
6245 }
6246
6247 /* Even though we've defined max_supported_key_part_length, we
6248 still do our own checking using field_lengths to be absolutely
6249 sure we don't create too long indexes. */
6250 error = row_create_index_for_mysql(index, trx, field_lengths);
6251
6252 error = convert_error_code_to_mysql(error, flags, NULL);
6253
6254 free(field_lengths);
6255
6256 return(error);
6257}
6258
6259/*****************************************************************/
6262static
6263int
6265/*===================================*/
6266 trx_t* trx,
6267 ulint flags,
6268 const char* table_name)
6269{
6270 dict_index_t* index;
6271 int error;
6272
6273 /* We pass 0 as the space id, and determine at a lower level the space
6274 id where to store the table */
6275
6276 index = dict_mem_index_create(table_name,
6277 innobase_index_reserve_name,
6278 0, DICT_CLUSTERED, 0);
6279
6280 error = row_create_index_for_mysql(index, trx, NULL);
6281
6282 error = convert_error_code_to_mysql(error, flags, NULL);
6283
6284 return(error);
6285}
6286
6287/*****************************************************************/
6293#if 0
6294static
6295ibool
6296create_options_are_valid(
6297/*=====================*/
6298 Session* session,
6299 Table& form,
6301 message::Table& create_proto)
6302{
6303 ibool kbs_specified = FALSE;
6304 ibool ret = TRUE;
6305
6306
6307 ut_ad(session != NULL);
6308
6309 /* If innodb_strict_mode is not set don't do any validation. */
6310 if (!(SessionVAR(session, strict_mode))) {
6311 return(TRUE);
6312 }
6313
6314 /* Now check for ROW_FORMAT specifier. */
6315 return(ret);
6316}
6317#endif
6318
6319/*********************************************************************
6320Creates a new table to an InnoDB database. */
6321UNIV_INTERN
6322int
6324 /*================*/
6325 Session &session,
6326 Table& form,
6327 const identifier::Table &identifier,
6328 const message::Table& create_proto)
6329{
6330 int error;
6331 dict_table_t* innobase_table;
6332 trx_t* parent_trx;
6333 trx_t* trx;
6334 int primary_key_no;
6335 uint i;
6336 ib_int64_t auto_inc_value;
6337 ulint iflags;
6338 /* Cache the value of innodb_file_format, in case it is
6339 modified by another thread while the table is being created. */
6340 const ulint file_format = srv_file_format;
6341 bool lex_identified_temp_table= (create_proto.type() == message::Table::TEMPORARY);
6342 const char* stmt;
6343 size_t stmt_len;
6344
6345 std::string search_string(identifier.getSchemaName());
6346 boost::algorithm::to_lower(search_string);
6347
6348 if (search_string.compare("data_dictionary") == 0)
6349 {
6350 return HA_WRONG_CREATE_OPTION;
6351 }
6352
6353 if (form.getShare()->sizeFields() > 1000) {
6354 /* The limit probably should be REC_MAX_N_FIELDS - 3 = 1020,
6355 but we play safe here */
6356
6357 return(HA_ERR_TO_BIG_ROW);
6358 }
6359
6360 /* Get the transaction associated with the current session, or create one
6361 if not yet created */
6362
6363 parent_trx = check_trx_exists(&session);
6364
6365 /* In case MySQL calls this in the middle of a SELECT query, release
6366 possible adaptive hash latch to avoid deadlocks of threads */
6367
6369
6370 trx = innobase_trx_allocate(&session);
6371
6372 srv_lower_case_table_names = TRUE;
6373
6374 /* Latch the InnoDB data dictionary exclusively so that no deadlocks
6375 or lock waits can happen in it during a table create operation.
6376 Drop table etc. do this latching in row0mysql.c. */
6377
6378 row_mysql_lock_data_dictionary(trx);
6379
6380 /* Create the table definition in InnoDB */
6381
6382 iflags = 0;
6383
6384#if 0 // Since we validate the options before this stage, we no longer need to do this.
6385 /* Validate create options if innodb_strict_mode is set. */
6386 if (! create_options_are_valid(&session, form, create_proto)) {
6387 error = ER_ILLEGAL_HA_CREATE_OPTION;
6388 goto cleanup;
6389 }
6390#endif
6391
6392 // We assume compact format by default
6393 iflags= DICT_TF_COMPACT;
6394
6395 size_t num_engine_options= create_proto.engine().options_size();
6396 for (size_t x= 0; x < num_engine_options; ++x)
6397 {
6398 if (boost::iequals(create_proto.engine().options(x).name(), "ROW_FORMAT"))
6399 {
6400 if (boost::iequals(create_proto.engine().options(x).state(), "COMPRESSED"))
6401 {
6402 iflags= DICT_TF_FORMAT_ZIP;
6403 }
6404 else if (boost::iequals(create_proto.engine().options(x).state(), "COMPACT"))
6405 {
6406 iflags= DICT_TF_FORMAT_ZIP;
6407 }
6408 else if (boost::iequals(create_proto.engine().options(x).state(), "DYNAMIC"))
6409 {
6410 iflags= DICT_TF_COMPACT;
6411 }
6412 else if (boost::iequals(create_proto.engine().options(x).state(), "REDUNDANT"))
6413 {
6414 iflags= DICT_TF_COMPACT;
6415 }
6416 }
6417 else
6418 {
6419 assert(0); // This should never happen since we have already validated the options.
6420 }
6421 }
6422
6423 if (iflags == DICT_TF_FORMAT_ZIP)
6424 {
6425 /*
6426 ROW_FORMAT=COMPRESSED without KEY_BLOCK_SIZE implies half the maximum KEY_BLOCK_SIZE.
6427 @todo implement KEY_BLOCK_SIZE
6428 */
6429 iflags= (DICT_TF_ZSSIZE_MAX - 1)
6434
6435 if (strict_mode)
6436 {
6437 if (! srv_file_per_table)
6438 {
6439 push_warning_printf(
6440 &session,
6441 DRIZZLE_ERROR::WARN_LEVEL_WARN,
6442 ER_ILLEGAL_HA_CREATE_OPTION,
6443 "InnoDB: ROW_FORMAT=COMPRESSED requires innodb_file_per_table.");
6444 }
6445 else if (file_format < DICT_TF_FORMAT_ZIP)
6446 {
6447 push_warning_printf(
6448 &session,
6449 DRIZZLE_ERROR::WARN_LEVEL_WARN,
6450 ER_ILLEGAL_HA_CREATE_OPTION,
6451 "InnoDB: ROW_FORMAT=compressed requires innodb_file_format > Antelope.");
6452 }
6453 }
6454 }
6455
6456 /* Look for a primary key */
6457
6458 primary_key_no= (form.getShare()->hasPrimaryKey() ?
6459 (int) form.getShare()->getPrimaryKey() :
6460 -1);
6461
6462 /* Our function innobase_get_mysql_key_number_for_index assumes
6463 the primary key is always number 0, if it exists */
6464
6465 assert(primary_key_no == -1 || primary_key_no == 0);
6466
6467 /* Check for name conflicts (with reserved name) for
6468 any user indices to be created. */
6469 if (innobase_index_name_is_reserved(trx, form.key_info,
6470 form.getShare()->keys)) {
6471 error = -1;
6472 goto cleanup;
6473 }
6474
6475 if (lex_identified_temp_table)
6477
6478 error= create_table_def(trx, &form, identifier.getKeyPath().c_str(),
6479 lex_identified_temp_table ? identifier.getKeyPath().c_str() : NULL,
6480 iflags);
6481
6482 session.setXaId(trx->id);
6483
6484 if (error) {
6485 goto cleanup;
6486 }
6487
6488 /* Create the keys */
6489
6490 if (form.getShare()->sizeKeys() == 0 || primary_key_no == -1) {
6491 /* Create an index which is used as the clustered index;
6492 order the rows by their row id which is internally generated
6493 by InnoDB */
6494
6495 error = create_clustered_index_when_no_primary(trx, iflags, identifier.getKeyPath().c_str());
6496 if (error) {
6497 goto cleanup;
6498 }
6499 }
6500
6501 if (primary_key_no != -1) {
6502 /* In InnoDB the clustered index must always be created first */
6503 if ((error = create_index(trx, &form, iflags, identifier.getKeyPath().c_str(),
6504 (uint) primary_key_no))) {
6505 goto cleanup;
6506 }
6507 }
6508
6509 for (i = 0; i < form.getShare()->sizeKeys(); i++) {
6510 if (i != (uint) primary_key_no) {
6511
6512 if ((error = create_index(trx, &form, iflags, identifier.getKeyPath().c_str(),
6513 i))) {
6514 goto cleanup;
6515 }
6516 }
6517 }
6518
6519 stmt= session.getQueryStringCopy(stmt_len);
6520
6521 if (stmt) {
6522 string generated_create_table;
6523 const char *query= stmt;
6524
6525 if (session.getSqlCommand() == SQLCOM_CREATE_TABLE)
6526 {
6528 generated_create_table,
6529 message::DRIZZLE, true);
6530 query= generated_create_table.c_str();
6531 }
6532
6534 query, strlen(query),
6535 identifier.getKeyPath().c_str(),
6536 lex_identified_temp_table);
6537 switch (error) {
6538
6539 case DB_PARENT_NO_INDEX:
6540 push_warning_printf(
6541 &session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
6542 HA_ERR_CANNOT_ADD_FOREIGN,
6543 "Create table '%s' with foreign key constraint"
6544 " failed. There is no index in the referenced"
6545 " table where the referenced columns appear"
6546 " as the first columns.\n", identifier.getKeyPath().c_str());
6547 break;
6548
6549 case DB_CHILD_NO_INDEX:
6550 push_warning_printf(
6551 &session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
6552 HA_ERR_CANNOT_ADD_FOREIGN,
6553 "Create table '%s' with foreign key constraint"
6554 " failed. There is no index in the referencing"
6555 " table where referencing columns appear"
6556 " as the first columns.\n", identifier.getKeyPath().c_str());
6557 break;
6558 }
6559
6560 error = convert_error_code_to_mysql(error, iflags, NULL);
6561
6562 if (error) {
6563 goto cleanup;
6564 }
6565 }
6566
6568
6570
6571 /* Flush the log to reduce probability that the .frm files and
6572 the InnoDB data dictionary get out-of-sync if the user runs
6573 with innodb_flush_log_at_trx_commit = 0 */
6574
6576
6577 innobase_table = dict_table_get(identifier.getKeyPath().c_str(), FALSE);
6578
6579 assert(innobase_table != 0);
6580
6581 if (innobase_table) {
6582 /* We update the highest file format in the system table
6583 space, if this table has higher file format setting. */
6584
6585 char changed_file_format_max[100];
6586 strcpy(changed_file_format_max, innobase_file_format_max.c_str());
6587 trx_sys_file_format_max_upgrade((const char **)&changed_file_format_max,
6588 dict_table_get_format(innobase_table));
6589 innobase_file_format_max= changed_file_format_max;
6590 }
6591
6592 /* Note: We can't call update_session() as prebuilt will not be
6593 setup at this stage and so we use session. */
6594
6595 /* We need to copy the AUTOINC value from the old table if
6596 this is an ALTER TABLE or CREATE INDEX because CREATE INDEX
6597 does a table copy too. */
6598
6599 if ((create_proto.options().has_auto_increment_value()
6600 || session.getSqlCommand() == SQLCOM_ALTER_TABLE
6601 || session.getSqlCommand() == SQLCOM_CREATE_INDEX)
6602 && create_proto.options().auto_increment_value() != 0) {
6603
6604 /* Query was one of :
6605 CREATE TABLE ...AUTO_INCREMENT = x; or
6606 ALTER TABLE...AUTO_INCREMENT = x; or
6607 CREATE INDEX x on t(...);
6608 Find out a table definition from the dictionary and get
6609 the current value of the auto increment field. Set a new
6610 value to the auto increment field if the value is greater
6611 than the maximum value in the column. */
6612
6613 auto_inc_value = create_proto.options().auto_increment_value();
6614
6615 dict_table_autoinc_lock(innobase_table);
6616 dict_table_autoinc_initialize(innobase_table, auto_inc_value);
6617 dict_table_autoinc_unlock(innobase_table);
6618 }
6619
6620 /* Tell the InnoDB server that there might be work for
6621 utility threads: */
6622
6624
6625 trx_free_for_mysql(trx);
6626
6627 if (lex_identified_temp_table)
6628 {
6629 session.getMessageCache().storeTableMessage(identifier, create_proto);
6630 }
6631 else
6632 {
6633 StorageEngine::writeDefinitionFromPath(identifier, create_proto);
6634 }
6635
6636 return(0);
6637
6638cleanup:
6640
6642
6643 trx_free_for_mysql(trx);
6644
6645 return(error);
6646}
6647
6648/*****************************************************************/
6651UNIV_INTERN
6652int
6654/*======================================*/
6655 my_bool discard)
6656{
6657 dict_table_t* dict_table;
6658 trx_t* trx;
6659 int err;
6660
6661 ut_a(prebuilt->trx);
6662 ut_a(prebuilt->trx->magic_n == TRX_MAGIC_N);
6663 ut_a(prebuilt->trx == session_to_trx(getTable()->in_use));
6664
6665 dict_table = prebuilt->table;
6666 trx = prebuilt->trx;
6667
6668 if (discard) {
6669 err = row_discard_tablespace_for_mysql(dict_table->name, trx);
6670 } else {
6671 err = row_import_tablespace_for_mysql(dict_table->name, trx);
6672 }
6673
6674 err = convert_error_code_to_mysql(err, dict_table->flags, NULL);
6675
6676 return(err);
6677}
6678
6679/*****************************************************************/
6682UNIV_INTERN
6683int
6685/*==============================*/
6686{
6687 int error;
6688
6689 /* Get the transaction associated with the current session, or create one
6690 if not yet created, and update prebuilt->trx */
6691
6692 update_session(getTable()->in_use);
6693
6694 if (user_session->getSqlCommand() != SQLCOM_TRUNCATE) {
6695 fallback:
6696 /* We only handle TRUNCATE TABLE t as a special case.
6697 DELETE FROM t will have to use ha_innobase::doDeleteRecord(),
6698 because DELETE is transactional while TRUNCATE is not. */
6699 return(errno=HA_ERR_WRONG_COMMAND);
6700 }
6701
6702 /* Truncate the table in InnoDB */
6703
6704 error = row_truncate_table_for_mysql(prebuilt->table, prebuilt->trx);
6705 if (error == DB_ERROR) {
6706 /* Cannot truncate; resort to ha_innobase::doDeleteRecord() */
6707 goto fallback;
6708 }
6709
6710 error = convert_error_code_to_mysql(error, prebuilt->table->flags,
6711 NULL);
6712
6713 return(error);
6714}
6715
6716/*****************************************************************/
6723UNIV_INTERN
6724int
6726/*======================*/
6727 Session &session,
6728 const identifier::Table &identifier)
6729{
6730 int error;
6731 trx_t* parent_trx;
6732 trx_t* trx;
6733
6734 ut_a(identifier.getPath().length() < 1000);
6735
6736 std::string search_string(identifier.getSchemaName());
6737 boost::algorithm::to_lower(search_string);
6738
6739 if (search_string.compare("data_dictionary") == 0)
6740 {
6741 return HA_ERR_TABLE_READONLY;
6742 }
6743
6744 /* Get the transaction associated with the current session, or create one
6745 if not yet created */
6746
6747 parent_trx = check_trx_exists(&session);
6748
6749 /* In case MySQL calls this in the middle of a SELECT query, release
6750 possible adaptive hash latch to avoid deadlocks of threads */
6751
6753
6754 trx = innobase_trx_allocate(&session);
6755
6756 srv_lower_case_table_names = TRUE;
6757
6758 /* Drop the table in InnoDB */
6759
6760 error = row_drop_table_for_mysql(identifier.getKeyPath().c_str(), trx,
6761 session.getSqlCommand()
6762 == SQLCOM_DROP_DB);
6763
6764 if (error == ENOENT
6765 && drizzled::identifier::Catalog(identifier.getCatalogName())==drizzled::catalog::local_identifier())
6766 {
6767 std::string table_path_no_catalog(identifier.getKeyPath());
6768 table_path_no_catalog.erase(0, drizzled::catalog::local_identifier().getPath().length()+1);
6769 error = row_drop_table_for_mysql(table_path_no_catalog.c_str(), trx,
6770 session.getSqlCommand()
6771 == SQLCOM_DROP_DB);
6772 }
6773
6774 session.setXaId(trx->id);
6775
6776 /* Flush the log to reduce probability that the .frm files and
6777 the InnoDB data dictionary get out-of-sync if the user runs
6778 with innodb_flush_log_at_trx_commit = 0 */
6779
6781
6782 /* Tell the InnoDB server that there might be work for
6783 utility threads: */
6784
6786
6788
6789 trx_free_for_mysql(trx);
6790
6791 if (error != ENOENT)
6792 error = convert_error_code_to_mysql(error, 0, NULL);
6793
6794 if (error == 0 || error == ENOENT)
6795 {
6796 if (identifier.getType() == message::Table::TEMPORARY)
6797 {
6798 session.getMessageCache().removeTableMessage(identifier);
6799 ulint sql_command = session.getSqlCommand();
6800
6801 // If this was the final removal to an alter table then we will need
6802 // to remove the .dfe that was left behind.
6803 if ((sql_command == SQLCOM_ALTER_TABLE
6804 || sql_command == SQLCOM_CREATE_INDEX
6805 || sql_command == SQLCOM_DROP_INDEX))
6806 {
6807 string path(identifier.getPath());
6808
6809 path.append(plugin::defaultTableDefinitionFileExt());
6810
6811 (void)internal::my_delete(path.c_str(), MYF(0));
6812 }
6813 }
6814 else
6815 {
6816 string path(identifier.getPath());
6817
6818 path.append(plugin::defaultTableDefinitionFileExt());
6819
6820 (void)internal::my_delete(path.c_str(), MYF(0));
6821 }
6822 }
6823
6824 return(error);
6825}
6826
6827/*****************************************************************/
6829bool
6831/*===================*/
6832 const identifier::Schema &identifier)
6837{
6838 trx_t* trx;
6839 int error;
6840 string schema_path(identifier.getPath());
6841 Session* session = current_session;
6842
6843 /* Get the transaction associated with the current session, or create one
6844 if not yet created */
6845
6846 assert(this == innodb_engine_ptr);
6847
6848 /* In the Windows plugin, session = current_session is always NULL */
6849 if (session) {
6850 trx_t* parent_trx = check_trx_exists(session);
6851
6852 /* In case Drizzle calls this in the middle of a SELECT
6853 query, release possible adaptive hash latch to avoid
6854 deadlocks of threads */
6855
6857 }
6858
6859 schema_path.append("/");
6860 trx = innobase_trx_allocate(session);
6861 error = row_drop_database_for_mysql(schema_path.c_str(), trx);
6862
6863 /* Flush the log to reduce probability that the .frm files and
6864 the InnoDB data dictionary get out-of-sync if the user runs
6865 with innodb_flush_log_at_trx_commit = 0 */
6866
6868
6869 /* Tell the InnoDB server that there might be work for
6870 utility threads: */
6871
6873
6875 trx_free_for_mysql(trx);
6876
6877 if (error) {
6878 // What do we do here?
6879 }
6880
6881 return false; // We are just a listener since we lack control over DDL, so we give no positive acknowledgement.
6882}
6883
6884void InnobaseEngine::dropTemporarySchema()
6885{
6886 string schema_path(GLOBAL_TEMPORARY_EXT);
6887 schema_path += "/";
6888
6889 trx_t* trx = trx_allocate_for_mysql();
6890
6891 trx->mysql_thd = NULL;
6892
6893 trx->check_foreigns = false;
6894 trx->check_unique_secondary = false;
6895
6896 (void)row_drop_database_for_mysql(schema_path.c_str(), trx);
6897
6898 /* Flush the log to reduce probability that the .frm files and
6899 the InnoDB data dictionary get out-of-sync if the user runs
6900 with innodb_flush_log_at_trx_commit = 0 */
6901
6903
6904 /* Tell the InnoDB server that there might be work for
6905 utility threads: */
6906
6908
6910 trx_free_for_mysql(trx);
6911}
6912/*********************************************************************/
6915static
6916int
6918/*==================*/
6919 trx_t* trx,
6920 const identifier::Table &from,
6921 const identifier::Table &to,
6922 ibool lock_and_commit)
6924{
6925 int error;
6926
6927 srv_lower_case_table_names = TRUE;
6928
6929 /* Serialize data dictionary operations with dictionary mutex:
6930 no deadlocks can occur then in these operations */
6931
6932 if (lock_and_commit) {
6933 row_mysql_lock_data_dictionary(trx);
6934 }
6935
6936 error = row_rename_table_for_mysql(from.getKeyPath().c_str(), to.getKeyPath().c_str(), trx, lock_and_commit);
6937
6938 if (error != DB_SUCCESS) {
6939 FILE* ef = dict_foreign_err_file;
6940
6941 fputs("InnoDB: Renaming table ", ef);
6942 ut_print_name(ef, trx, TRUE, from.getKeyPath().c_str());
6943 fputs(" to ", ef);
6944 ut_print_name(ef, trx, TRUE, to.getKeyPath().c_str());
6945 fputs(" failed!\n", ef);
6946 }
6947
6948 if (lock_and_commit) {
6950
6951 /* Flush the log to reduce probability that the .frm
6952 files and the InnoDB data dictionary get out-of-sync
6953 if the user runs with innodb_flush_log_at_trx_commit = 0 */
6954
6956 }
6957
6958 return error;
6959}
6960/*********************************************************************/
6963UNIV_INTERN int InnobaseEngine::doRenameTable(Session &session, const identifier::Table &from, const identifier::Table &to)
6964{
6965 // A temp table alter table/rename is a shallow rename and only the
6966 // definition needs to be updated.
6967 if (to.getType() == message::Table::TEMPORARY && from.getType() == message::Table::TEMPORARY)
6968 {
6969 session.getMessageCache().renameTableMessage(from, to);
6970 return 0;
6971 }
6972
6973 trx_t* trx;
6974 int error;
6975 trx_t* parent_trx;
6976
6977 /* Get the transaction associated with the current session, or create one
6978 if not yet created */
6979
6980 parent_trx = check_trx_exists(&session);
6981
6982 /* In case MySQL calls this in the middle of a SELECT query, release
6983 possible adaptive hash latch to avoid deadlocks of threads */
6984
6986
6987 trx = innobase_trx_allocate(&session);
6988
6989 error = innobase_rename_table(trx, from, to, TRUE);
6990
6991 session.setXaId(trx->id);
6992
6993 /* Tell the InnoDB server that there might be work for
6994 utility threads: */
6995
6997
6999 trx_free_for_mysql(trx);
7000
7001 /* Add a special case to handle the Duplicated Key error
7002 and return DB_ERROR instead.
7003 This is to avoid a possible SIGSEGV error from mysql error
7004 handling code. Currently, mysql handles the Duplicated Key
7005 error by re-entering the storage layer and getting dup key
7006 info by calling get_dup_key(). This operation requires a valid
7007 table handle ('row_prebuilt_t' structure) which could no
7008 longer be available in the error handling stage. The suggested
7009 solution is to report a 'table exists' error message (since
7010 the dup key error here is due to an existing table whose name
7011 is the one we are trying to rename to) and return the generic
7012 error code. */
7013 if (error == (int) DB_DUPLICATE_KEY) {
7014 my_error(ER_TABLE_EXISTS_ERROR, to);
7015 error = DB_ERROR;
7016 }
7017
7018 error = convert_error_code_to_mysql(error, 0, NULL);
7019
7020 if (not error)
7021 {
7022 // If this fails, we are in trouble
7023 plugin::StorageEngine::renameDefinitionFromPath(to, from);
7024 }
7025
7026 return(error);
7027}
7028
7029/*********************************************************************/
7032UNIV_INTERN
7033ha_rows
7035/*==========================*/
7036 uint keynr,
7037 key_range *min_key,
7039 key_range *max_key)
7041{
7042 KeyInfo* key;
7043 dict_index_t* index;
7044 unsigned char* key_val_buff2 = (unsigned char*) malloc(
7045 getTable()->getShare()->sizeStoredRecord()
7046 + getTable()->getShare()->max_key_length + 100);
7047 ulint buff2_len = getTable()->getShare()->sizeStoredRecord()
7048 + getTable()->getShare()->max_key_length + 100;
7049 dtuple_t* range_start;
7050 dtuple_t* range_end;
7051 ib_int64_t n_rows;
7052 ulint mode1;
7053 ulint mode2;
7054 mem_heap_t* heap;
7055
7056 ut_a(prebuilt->trx == session_to_trx(getTable()->in_use));
7057
7058 prebuilt->trx->op_info = "estimating records in index range";
7059
7060 /* In case MySQL calls this in the middle of a SELECT query, release
7061 possible adaptive hash latch to avoid deadlocks of threads */
7062
7064
7065 active_index = keynr;
7066
7067 key = &getTable()->key_info[active_index];
7068
7069 index = innobase_get_index(keynr);
7070
7071 /* There exists possibility of not being able to find requested
7072 index due to inconsistency between MySQL and InoDB dictionary info.
7073 Necessary message should have been printed in innobase_get_index() */
7074 if (UNIV_UNLIKELY(!index)) {
7075 n_rows = HA_POS_ERROR;
7076 goto func_exit;
7077 }
7078
7079 if (UNIV_UNLIKELY(!row_merge_is_index_usable(prebuilt->trx, index))) {
7080 n_rows = HA_ERR_TABLE_DEF_CHANGED;
7081 goto func_exit;
7082 }
7083
7084 heap = mem_heap_create(2 * (key->key_parts * sizeof(dfield_t)
7085 + sizeof(dtuple_t)));
7086
7087 range_start = dtuple_create(heap, key->key_parts);
7088 dict_index_copy_types(range_start, index, key->key_parts);
7089
7090 range_end = dtuple_create(heap, key->key_parts);
7091 dict_index_copy_types(range_end, index, key->key_parts);
7092
7094 range_start, (byte*) &key_val_buff[0],
7095 (ulint)upd_and_key_val_buff_len,
7096 index,
7097 (byte*) (min_key ? min_key->key :
7098 (const unsigned char*) 0),
7099 (ulint) (min_key ? min_key->length : 0),
7100 prebuilt->trx);
7101
7103 range_end, (byte*) key_val_buff2,
7104 buff2_len, index,
7105 (byte*) (max_key ? max_key->key :
7106 (const unsigned char*) 0),
7107 (ulint) (max_key ? max_key->length : 0),
7108 prebuilt->trx);
7109
7110 mode1 = convert_search_mode_to_innobase(min_key ? min_key->flag :
7111 HA_READ_KEY_EXACT);
7112 mode2 = convert_search_mode_to_innobase(max_key ? max_key->flag :
7113 HA_READ_KEY_EXACT);
7114
7115 if (mode1 != PAGE_CUR_UNSUPP && mode2 != PAGE_CUR_UNSUPP) {
7116
7117 n_rows = btr_estimate_n_rows_in_range(index, range_start,
7118 mode1, range_end,
7119 mode2);
7120 } else {
7121
7122 n_rows = HA_POS_ERROR;
7123 }
7124
7125 mem_heap_free(heap);
7126
7127func_exit:
7128 free(key_val_buff2);
7129
7130 prebuilt->trx->op_info = "";
7131
7132 /* The MySQL optimizer seems to believe an estimate of 0 rows is
7133 always accurate and may return the result 'Empty set' based on that.
7134 The accuracy is not guaranteed, and even if it were, for a locking
7135 read we should anyway perform the search to set the next-key lock.
7136 Add 1 to the value to make sure MySQL does not make the assumption! */
7137
7138 if (n_rows == 0) {
7139 n_rows = 1;
7140 }
7141
7142 return((ha_rows) n_rows);
7143}
7144
7145/*********************************************************************/
7149UNIV_INTERN
7150ha_rows
7152/*======================================*/
7153{
7154 dict_index_t* index;
7155 uint64_t estimate;
7156 uint64_t local_data_file_length;
7157 ulint stat_n_leaf_pages;
7158
7159 /* We do not know if MySQL can call this function before calling
7160 external_lock(). To be safe, update the session of the current table
7161 handle. */
7162
7163 update_session(getTable()->in_use);
7164
7165 prebuilt->trx->op_info = (char*)
7166 "calculating upper bound for table rows";
7167
7168 /* In case MySQL calls this in the middle of a SELECT query, release
7169 possible adaptive hash latch to avoid deadlocks of threads */
7170
7172
7173 index = dict_table_get_first_index(prebuilt->table);
7174
7175 stat_n_leaf_pages = index->stat_n_leaf_pages;
7176
7177 ut_a(stat_n_leaf_pages > 0);
7178
7179 local_data_file_length =
7180 ((uint64_t) stat_n_leaf_pages) * UNIV_PAGE_SIZE;
7181
7182
7183 /* Calculate a minimum length for a clustered index record and from
7184 that an upper bound for the number of rows. Since we only calculate
7185 new statistics in row0mysql.c when a table has grown by a threshold
7186 factor, we must add a safety factor 2 in front of the formula below. */
7187
7188 estimate = 2 * local_data_file_length /
7189 dict_index_calc_min_rec_len(index);
7190
7191 prebuilt->trx->op_info = "";
7192
7193 return((ha_rows) estimate);
7194}
7195
7196/*********************************************************************/
7201UNIV_INTERN
7202double
7204/*====================*/
7205{
7206 /* Since MySQL seems to favor table scans too much over index
7207 searches, we pretend that a sequential read takes the same time
7208 as a random disk read, that is, we do not divide the following
7209 by 10, which would be physically realistic. */
7210
7211 return((double) (prebuilt->table->stat_clustered_index_size));
7212}
7213
7214/******************************************************************/
7218UNIV_INTERN
7219double
7221/*===================*/
7222 uint index,
7223 uint ranges,
7224 ha_rows rows)
7225{
7226 ha_rows total_rows;
7227 double time_for_scan;
7228
7229 if (index != getTable()->getShare()->getPrimaryKey()) {
7230 /* Not clustered */
7231 return(Cursor::read_time(index, ranges, rows));
7232 }
7233
7234 if (rows <= 2) {
7235
7236 return((double) rows);
7237 }
7238
7239 /* Assume that the read time is proportional to the scan time for all
7240 rows + at most one seek per range. */
7241
7242 time_for_scan = scan_time();
7243
7244 if ((total_rows = estimate_rows_upper_bound()) < rows) {
7245
7246 return(time_for_scan);
7247 }
7248
7249 return(ranges + (double) rows / (double) total_rows * time_for_scan);
7250}
7251
7252/*********************************************************************/
7261static
7262unsigned int
7264/*====================================*/
7265 INNOBASE_SHARE* share,
7267 const drizzled::Table* table,
7269 dict_table_t* ib_table,
7271 const dict_index_t* index)
7272{
7273 const dict_index_t* ind;
7274 unsigned int i;
7275
7276 ut_ad(index);
7277 ut_ad(ib_table);
7278 ut_ad(table);
7279 ut_ad(share);
7280
7281 /* If index does not belong to the table of share structure. Search
7282 index->table instead */
7283 if (index->table != ib_table) {
7284 i = 0;
7285 ind = dict_table_get_first_index(index->table);
7286
7287 while (index != ind) {
7288 ind = dict_table_get_next_index(ind);
7289 i++;
7290 }
7291
7292 if (row_table_got_default_clust_index(index->table)) {
7293 ut_a(i > 0);
7294 i--;
7295 }
7296
7297 return(i);
7298 }
7299
7300 /* If index does not belong to the table of share structure. Search
7301 index->table instead */
7302 if (index->table != ib_table) {
7303 i = 0;
7304 ind = dict_table_get_first_index(index->table);
7305
7306 while (index != ind) {
7307 ind = dict_table_get_next_index(ind);
7308 i++;
7309 }
7310
7311 if (row_table_got_default_clust_index(index->table)) {
7312 ut_a(i > 0);
7313 i--;
7314 }
7315
7316 return(i);
7317 }
7318
7319 /* If index translation table exists, we will first check
7320 the index through index translation table for a match. */
7321 if (share->idx_trans_tbl.index_mapping) {
7322 for (i = 0; i < share->idx_trans_tbl.index_count; i++) {
7323 if (share->idx_trans_tbl.index_mapping[i] == index) {
7324 return(i);
7325 }
7326 }
7327
7328 /* Print an error message if we cannot find the index
7329 ** in the "index translation table". */
7330 errmsg_printf(error::ERROR,
7331 "Cannot find index %s in InnoDB index "
7332 "translation table.", index->name);
7333 }
7334
7335 /* If we do not have an "index translation table", or not able
7336 to find the index in the translation table, we'll directly find
7337 matching index in the dict_index_t list */
7338 for (i = 0; i < table->getShare()->keys; i++) {
7339 ind = dict_table_get_index_on_name(
7340 ib_table, table->key_info[i].name);
7341
7342 if (index == ind) {
7343 return(i);
7344 }
7345 }
7346
7347 errmsg_printf(error::ERROR,
7348 "Cannot find matching index number for index %s "
7349 "in InnoDB index list.", index->name);
7350
7351 return(0);
7352}
7353
7354/*********************************************************************/
7358static
7359ha_rows
7361/*===============*/
7362 dict_index_t* index,
7363 ulint i,
7365 ha_rows records)
7366{
7367 ha_rows rec_per_key;
7368
7369 ut_ad(i < dict_index_get_n_unique(index));
7370
7371 /* Note the stat_n_diff_key_vals[] stores the diff value with
7372 n-prefix indexing, so it is always stat_n_diff_key_vals[i + 1] */
7373 if (index->stat_n_diff_key_vals[i + 1] == 0) {
7374
7375 rec_per_key = records;
7376 } else if (srv_innodb_stats_method == SRV_STATS_NULLS_IGNORED) {
7377 ib_int64_t num_null;
7378
7379 /* Number of rows with NULL value in this
7380 field */
7381 num_null = records - index->stat_n_non_null_key_vals[i];
7382
7383 /* In theory, index->stat_n_non_null_key_vals[i]
7384 should always be less than the number of records.
7385 Since this is statistics value, the value could
7386 have slight discrepancy. But we will make sure
7387 the number of null values is not a negative number. */
7388 num_null = (num_null < 0) ? 0 : num_null;
7389
7390 /* If the number of NULL values is the same as or
7391 large than that of the distinct values, we could
7392 consider that the table consists mostly of NULL value.
7393 Set rec_per_key to 1. */
7394 if (index->stat_n_diff_key_vals[i + 1] <= num_null) {
7395 rec_per_key = 1;
7396 } else {
7397 /* Need to exclude rows with NULL values from
7398 rec_per_key calculation */
7399 rec_per_key = (ha_rows)(
7400 (records - num_null)
7401 / (index->stat_n_diff_key_vals[i + 1]
7402 - num_null));
7403 }
7404 } else {
7405 rec_per_key = (ha_rows)
7406 (records / index->stat_n_diff_key_vals[i + 1]);
7407 }
7408
7409 return(rec_per_key);
7410}
7411
7412/*********************************************************************/
7415UNIV_INTERN
7416int
7418/*==============*/
7419 uint flag)
7420{
7421 dict_table_t* ib_table;
7422 dict_index_t* index;
7423 ha_rows rec_per_key;
7424 ib_int64_t n_rows;
7425 os_file_stat_t stat_info;
7426
7427 /* If we are forcing recovery at a high level, we will suppress
7428 statistics calculation on tables, because that may crash the
7429 server if an index is badly corrupted. */
7430
7431 /* We do not know if MySQL can call this function before calling
7432 external_lock(). To be safe, update the session of the current table
7433 handle. */
7434
7435 update_session(getTable()->in_use);
7436
7437 /* In case MySQL calls this in the middle of a SELECT query, release
7438 possible adaptive hash latch to avoid deadlocks of threads */
7439
7440 prebuilt->trx->op_info = "returning various info to MySQL";
7441
7443
7444 ib_table = prebuilt->table;
7445
7446 if (flag & HA_STATUS_TIME) {
7447 /* In Analyze we call with this flag: update
7448 then statistics so that they are up-to-date */
7449
7450 prebuilt->trx->op_info = "updating table statistics";
7451
7452 dict_update_statistics(ib_table,
7453 FALSE /* update even if stats
7454 are initialized */);
7455
7456
7457 prebuilt->trx->op_info = "returning various info to MySQL";
7458
7459 fs::path get_status_path(catalog::local_identifier().getPath());
7460 get_status_path /= ib_table->name;
7461 get_status_path.replace_extension("dfe");
7462
7463 /* Note that we do not know the access time of the table,
7464 nor the CHECK TABLE time, nor the UPDATE or INSERT time. */
7465
7466 if (os_file_get_status(get_status_path.string().c_str(), &stat_info)) {
7467 stats.create_time = (ulong) stat_info.ctime;
7468 }
7469 }
7470
7471 if (flag & HA_STATUS_VARIABLE) {
7472
7473 dict_table_stats_lock(ib_table, RW_S_LATCH);
7474
7475 n_rows = ib_table->stat_n_rows;
7476
7477 /* Because we do not protect stat_n_rows by any mutex in a
7478 delete, it is theoretically possible that the value can be
7479 smaller than zero! TODO: fix this race.
7480
7481 The MySQL optimizer seems to assume in a left join that n_rows
7482 is an accurate estimate if it is zero. Of course, it is not,
7483 since we do not have any locks on the rows yet at this phase.
7484 Since SHOW TABLE STATUS seems to call this function with the
7485 HA_STATUS_TIME flag set, while the left join optimizer does not
7486 set that flag, we add one to a zero value if the flag is not
7487 set. That way SHOW TABLE STATUS will show the best estimate,
7488 while the optimizer never sees the table empty. */
7489
7490 if (n_rows < 0) {
7491 n_rows = 0;
7492 }
7493
7494 if (n_rows == 0 && !(flag & HA_STATUS_TIME)) {
7495 n_rows++;
7496 }
7497
7498 /* Fix bug#40386: Not flushing query cache after truncate.
7499 n_rows can not be 0 unless the table is empty, set to 1
7500 instead. The original problem of bug#29507 is actually
7501 fixed in the server code. */
7502 if (user_session->getSqlCommand() == SQLCOM_TRUNCATE) {
7503
7504 n_rows = 1;
7505
7506 /* We need to reset the prebuilt value too, otherwise
7507 checks for values greater than the last value written
7508 to the table will fail and the autoinc counter will
7509 not be updated. This will force doInsertRecord() into
7510 attempting an update of the table's AUTOINC counter. */
7511
7512 prebuilt->autoinc_last_value = 0;
7513 }
7514
7515 stats.records = (ha_rows)n_rows;
7516 stats.deleted = 0;
7517 stats.data_file_length = ((uint64_t)
7518 ib_table->stat_clustered_index_size)
7519 * UNIV_PAGE_SIZE;
7520 stats.index_file_length = ((uint64_t)
7522 * UNIV_PAGE_SIZE;
7523
7524 dict_table_stats_unlock(ib_table, RW_S_LATCH);
7525
7526 /* Since fsp_get_available_space_in_free_extents() is
7527 acquiring latches inside InnoDB, we do not call it if we
7528 are asked by MySQL to avoid locking. Another reason to
7529 avoid the call is that it uses quite a lot of CPU.
7530 See Bug#38185. */
7531 if (flag & HA_STATUS_NO_LOCK) {
7532 /* We do not update delete_length if no
7533 locking is requested so the "old" value can
7534 remain. delete_length is initialized to 0 in
7535 the ha_statistics' constructor.*/
7536 } else if (UNIV_UNLIKELY
7537 (srv_force_recovery >= SRV_FORCE_NO_IBUF_MERGE)) {
7538 /* Avoid accessing the tablespace if
7539 innodb_crash_recovery is set to a high value. */
7540 stats.delete_length = 0;
7541 } else {
7542 ullint avail_space;
7543
7544 avail_space = fsp_get_available_space_in_free_extents(ib_table->space);
7545
7546 if (avail_space == ULLINT_UNDEFINED) {
7547 Session* session;
7548
7549 session= getTable()->in_use;
7550 assert(session);
7551
7552 push_warning_printf(
7553 session,
7554 DRIZZLE_ERROR::WARN_LEVEL_WARN,
7555 ER_CANT_GET_STAT,
7556 "InnoDB: Trying to get the free "
7557 "space for table %s but its "
7558 "tablespace has been discarded or "
7559 "the .ibd file is missing. Setting "
7560 "the free space to zero.",
7561 ib_table->name);
7562
7563 stats.delete_length = 0;
7564 } else {
7565 stats.delete_length = avail_space * 1024;
7566 }
7567 }
7568
7569 stats.check_time = 0;
7570
7571 if (stats.records == 0) {
7572 stats.mean_rec_length = 0;
7573 } else {
7574 stats.mean_rec_length = (ulong) (stats.data_file_length / stats.records);
7575 }
7576 }
7577
7578 if (flag & HA_STATUS_CONST) {
7579 ulong i;
7580 /* Verify the number of index in InnoDB and MySQL
7581 matches up. If prebuilt->clust_index_was_generated
7582 holds, InnoDB defines GEN_CLUST_INDEX internally */
7583 ulint num_innodb_index = UT_LIST_GET_LEN(ib_table->indexes) - prebuilt->clust_index_was_generated;
7584
7585 if (getTable()->getShare()->keys != num_innodb_index) {
7586 errmsg_printf(error::ERROR, "Table %s contains %lu "
7587 "indexes inside InnoDB, which "
7588 "is different from the number of "
7589 "indexes %u defined in the MySQL ",
7590 ib_table->name, num_innodb_index,
7591 getTable()->getShare()->keys);
7592 }
7593
7594 dict_table_stats_lock(ib_table, RW_S_LATCH);
7595
7596 for (i = 0; i < getTable()->getShare()->sizeKeys(); i++) {
7597 ulong j;
7598 /* We could get index quickly through internal
7599 index mapping with the index translation table.
7600 The identity of index (match up index name with
7601 that of table->key_info[i]) is already verified in
7602 innobase_get_index(). */
7603 index = innobase_get_index(i);
7604
7605 if (index == NULL) {
7606 errmsg_printf(error::ERROR, "Table %s contains fewer "
7607 "indexes inside InnoDB than "
7608 "are defined in the MySQL "
7609 ".frm file. Have you mixed up "
7610 ".frm files from different "
7611 "installations? See "
7612 REFMAN
7613 "innodb-troubleshooting.html\n",
7614 ib_table->name);
7615 break;
7616 }
7617
7618 for (j = 0; j < getTable()->key_info[i].key_parts; j++) {
7619
7620 if (j + 1 > index->n_uniq) {
7621 errmsg_printf(error::ERROR,
7622"Index %s of %s has %lu columns unique inside InnoDB, but MySQL is asking "
7623"statistics for %lu columns. Have you mixed up .frm files from different "
7624"installations? "
7625"See " REFMAN "innodb-troubleshooting.html\n",
7626 index->name,
7627 ib_table->name,
7628 (unsigned long)
7629 index->n_uniq, j + 1);
7630 break;
7631 }
7632
7633 rec_per_key = innodb_rec_per_key(index, j, stats.records);
7634
7635 /* Since MySQL seems to favor table scans
7636 too much over index searches, we pretend
7637 index selectivity is 2 times better than
7638 our estimate: */
7639
7640 rec_per_key = rec_per_key / 2;
7641
7642 if (rec_per_key == 0) {
7643 rec_per_key = 1;
7644 }
7645
7646 getTable()->key_info[i].rec_per_key[j]=
7647 rec_per_key >= ~(ulong) 0 ? ~(ulong) 0 :
7648 (ulong) rec_per_key;
7649 }
7650 }
7651
7652 dict_table_stats_unlock(ib_table, RW_S_LATCH);
7653 }
7654
7655 if (srv_force_recovery >= SRV_FORCE_NO_IBUF_MERGE) {
7656 goto func_exit;
7657 }
7658
7659 if (flag & HA_STATUS_ERRKEY) {
7660 const dict_index_t* err_index;
7661
7662 ut_a(prebuilt->trx);
7663 ut_a(prebuilt->trx->magic_n == TRX_MAGIC_N);
7664
7665 err_index = trx_get_error_info(prebuilt->trx);
7666
7667 if (err_index) {
7668 errkey = (unsigned int)
7669 innobase_get_mysql_key_number_for_index(share, getTable(), ib_table,
7670 err_index);
7671 } else {
7672 errkey = (unsigned int) prebuilt->trx->error_key_num;
7673 }
7674 }
7675
7676 if ((flag & HA_STATUS_AUTO) && getTable()->found_next_number_field) {
7677 stats.auto_increment_value = innobase_peek_autoinc();
7678 }
7679
7680func_exit:
7681 prebuilt->trx->op_info = "";
7682
7683 return(0);
7684}
7685
7686/**********************************************************************/
7690UNIV_INTERN
7691int
7693/*=================*/
7694 Session*)
7695{
7696 /* Simply call ::info() with all the flags */
7697 info(HA_STATUS_TIME | HA_STATUS_CONST | HA_STATUS_VARIABLE);
7698
7699 return(0);
7700}
7701
7702/*******************************************************************/
7707UNIV_INTERN
7708int
7710/*===============*/
7711 Session* session)
7712{
7713 dict_index_t* index;
7714 ulint n_rows;
7715 ulint n_rows_in_table = ULINT_UNDEFINED;
7716 ibool is_ok = TRUE;
7717 ulint old_isolation_level;
7718
7719 assert(session == getTable()->in_use);
7720 ut_a(prebuilt->trx);
7721 ut_a(prebuilt->trx->magic_n == TRX_MAGIC_N);
7722 ut_a(prebuilt->trx == session_to_trx(session));
7723
7724 if (prebuilt->mysql_template == NULL) {
7725 /* Build the template; we will use a dummy template
7726 in index scans done in checking */
7727
7728 build_template(prebuilt, NULL, getTable(), ROW_MYSQL_WHOLE_ROW);
7729 }
7730
7731 if (prebuilt->table->ibd_file_missing) {
7732 errmsg_printf(error::ERROR, "InnoDB: Error:\n"
7733 "InnoDB: MySQL is trying to use a table handle"
7734 " but the .ibd file for\n"
7735 "InnoDB: table %s does not exist.\n"
7736 "InnoDB: Have you deleted the .ibd file"
7737 " from the database directory under\n"
7738 "InnoDB: the MySQL datadir, or have you"
7739 " used DISCARD TABLESPACE?\n"
7740 "InnoDB: Please refer to\n"
7741 "InnoDB: " REFMAN "innodb-troubleshooting.html\n"
7742 "InnoDB: how you can resolve the problem.\n",
7743 prebuilt->table->name);
7744 return(HA_ADMIN_CORRUPT);
7745 }
7746
7747 prebuilt->trx->op_info = "checking table";
7748
7749 old_isolation_level = prebuilt->trx->isolation_level;
7750
7751 /* We must run the index record counts at an isolation level
7752 >= READ COMMITTED, because a dirty read can see a wrong number
7753 of records in some index; to play safe, we use always
7754 REPEATABLE READ here */
7755
7756 prebuilt->trx->isolation_level = TRX_ISO_REPEATABLE_READ;
7757
7758 /* Enlarge the fatal lock wait timeout during CHECK TABLE. */
7759 mutex_enter(&kernel_mutex);
7760 srv_fatal_semaphore_wait_threshold += 7200; /* 2 hours */
7761 mutex_exit(&kernel_mutex);
7762
7763 for (index = dict_table_get_first_index(prebuilt->table);
7764 index != NULL;
7765 index = dict_table_get_next_index(index)) {
7766#if 0
7767 fputs("Validating index ", stderr);
7768 ut_print_name(stderr, trx, FALSE, index->name);
7769 putc('\n', stderr);
7770#endif
7771
7772 if (!btr_validate_index(index, prebuilt->trx)) {
7773 is_ok = FALSE;
7774 push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
7775 ER_NOT_KEYFILE,
7776 "InnoDB: The B-tree of"
7777 " index '%-.200s' is corrupted.",
7778 index->name);
7779 continue;
7780 }
7781
7782 /* Instead of invoking change_active_index(), set up
7783 a dummy template for non-locking reads, disabling
7784 access to the clustered index. */
7785 prebuilt->index = index;
7786
7787 prebuilt->index_usable = row_merge_is_index_usable(
7788 prebuilt->trx, prebuilt->index);
7789
7790 if (UNIV_UNLIKELY(!prebuilt->index_usable)) {
7791 push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
7792 HA_ERR_TABLE_DEF_CHANGED,
7793 "InnoDB: Insufficient history for"
7794 " index '%-.200s'",
7795 index->name);
7796 continue;
7797 }
7798
7799 prebuilt->sql_stat_start = TRUE;
7800 prebuilt->template_type = ROW_MYSQL_DUMMY_TEMPLATE;
7801 prebuilt->n_template = 0;
7802 prebuilt->need_to_access_clustered = FALSE;
7803
7804 dtuple_set_n_fields(prebuilt->search_tuple, 0);
7805
7806 prebuilt->select_lock_type = LOCK_NONE;
7807
7808 if (!row_check_index_for_mysql(prebuilt, index, &n_rows)) {
7809 push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
7810 ER_NOT_KEYFILE,
7811 "InnoDB: The B-tree of"
7812 " index '%-.200s' is corrupted.",
7813 index->name);
7814 is_ok = FALSE;
7815 }
7816
7817 if (user_session->getKilled()) {
7818 break;
7819 }
7820
7821#if 0
7822 fprintf(stderr, "%lu entries in index %s\n", n_rows,
7823 index->name);
7824#endif
7825
7826 if (index == dict_table_get_first_index(prebuilt->table)) {
7827 n_rows_in_table = n_rows;
7828 } else if (n_rows != n_rows_in_table) {
7829 push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
7830 ER_NOT_KEYFILE,
7831 "InnoDB: Index '%-.200s'"
7832 " contains %lu entries,"
7833 " should be %lu.",
7834 index->name,
7835 (ulong) n_rows,
7836 (ulong) n_rows_in_table);
7837 is_ok = FALSE;
7838 }
7839 }
7840
7841 /* Restore the original isolation level */
7842 prebuilt->trx->isolation_level = old_isolation_level;
7843
7844 /* We validate also the whole adaptive hash index for all tables
7845 at every CHECK TABLE */
7846
7847 if (!btr_search_validate()) {
7848 push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
7849 ER_NOT_KEYFILE,
7850 "InnoDB: The adaptive hash index is corrupted.");
7851 is_ok = FALSE;
7852 }
7853
7854 /* Restore the fatal lock wait timeout after CHECK TABLE. */
7855 mutex_enter(&kernel_mutex);
7856 srv_fatal_semaphore_wait_threshold -= 7200; /* 2 hours */
7857 mutex_exit(&kernel_mutex);
7858
7859 prebuilt->trx->op_info = "";
7860 if (user_session->getKilled()) {
7861 my_error(ER_QUERY_INTERRUPTED, MYF(0));
7862 }
7863
7864 return(is_ok ? HA_ADMIN_OK : HA_ADMIN_CORRUPT);
7865}
7866
7867/*************************************************************/
7872UNIV_INTERN
7873char*
7875/*==============================*/
7876 const char* comment)
7877{
7878 uint length = (uint) strlen(comment);
7879 char* str;
7880 long flen;
7881
7882 /* We do not know if MySQL can call this function before calling
7883 external_lock(). To be safe, update the session of the current table
7884 handle. */
7885
7886 if (length > 64000 - 3) {
7887 return((char*)comment); /* string too long */
7888 }
7889
7890 update_session(getTable()->in_use);
7891
7892 prebuilt->trx->op_info = "returning table comment";
7893
7894 /* In case MySQL calls this in the middle of a SELECT query, release
7895 possible adaptive hash latch to avoid deadlocks of threads */
7896
7898 str = NULL;
7899
7900 /* output the data to a temporary file */
7901
7902 mutex_enter(&srv_dict_tmpfile_mutex);
7903 rewind(srv_dict_tmpfile);
7904
7905 fprintf(srv_dict_tmpfile, "InnoDB free: %llu kB",
7906 fsp_get_available_space_in_free_extents(
7907 prebuilt->table->space));
7908
7909 dict_print_info_on_foreign_keys(FALSE, srv_dict_tmpfile,
7910 prebuilt->trx, prebuilt->table);
7911 flen = ftell(srv_dict_tmpfile);
7912 if (flen < 0) {
7913 flen = 0;
7914 } else if (length + flen + 3 > 64000) {
7915 flen = 64000 - 3 - length;
7916 }
7917
7918 /* allocate buffer for the full string, and
7919 read the contents of the temporary file */
7920
7921 str = (char*) malloc(length + flen + 3);
7922
7923 if (str) {
7924 char* pos = str + length;
7925 if (length) {
7926 memcpy(str, comment, length);
7927 *pos++ = ';';
7928 *pos++ = ' ';
7929 }
7930 rewind(srv_dict_tmpfile);
7931 flen = (uint) fread(pos, 1, flen, srv_dict_tmpfile);
7932 pos[flen] = 0;
7933 }
7934
7935 mutex_exit(&srv_dict_tmpfile_mutex);
7936
7937 prebuilt->trx->op_info = "";
7938
7939 return(str ? str : (char*) comment);
7940}
7941
7942/*******************************************************************/
7947UNIV_INTERN
7948char*
7950/*==========================================*/
7951{
7952 char* str = 0;
7953 long flen;
7954
7955 ut_a(prebuilt != NULL);
7956
7957 /* We do not know if MySQL can call this function before calling
7958 external_lock(). To be safe, update the session of the current table
7959 handle. */
7960
7961 update_session(getTable()->in_use);
7962
7963 prebuilt->trx->op_info = "getting info on foreign keys";
7964
7965 /* In case MySQL calls this in the middle of a SELECT query,
7966 release possible adaptive hash latch to avoid
7967 deadlocks of threads */
7968
7970
7971 mutex_enter(&srv_dict_tmpfile_mutex);
7972 rewind(srv_dict_tmpfile);
7973
7974 /* output the data to a temporary file */
7975 dict_print_info_on_foreign_keys(TRUE, srv_dict_tmpfile,
7976 prebuilt->trx, prebuilt->table);
7977 prebuilt->trx->op_info = "";
7978
7979 flen = ftell(srv_dict_tmpfile);
7980 if (flen < 0) {
7981 flen = 0;
7982 }
7983
7984 /* allocate buffer for the string, and
7985 read the contents of the temporary file */
7986
7987 str = (char*) malloc(flen + 1);
7988
7989 if (str) {
7990 rewind(srv_dict_tmpfile);
7991 flen = (uint) fread(str, 1, flen, srv_dict_tmpfile);
7992 str[flen] = 0;
7993 }
7994
7995 mutex_exit(&srv_dict_tmpfile_mutex);
7996
7997 return(str);
7998}
7999
8000
8001UNIV_INTERN
8002int
8004{
8005 ut_a(prebuilt != NULL);
8006 update_session(getTable()->in_use);
8007 prebuilt->trx->op_info = "getting list of foreign keys";
8009 mutex_enter(&(dict_sys->mutex));
8010 dict_foreign_t* foreign = UT_LIST_GET_FIRST(prebuilt->table->foreign_list);
8011
8012 while (foreign != NULL)
8013 {
8014 uint ulen;
8015 char uname[NAME_LEN + 1]; /* Unencoded name */
8016 char db_name[NAME_LEN + 1];
8017 const char *tmp_buff;
8018
8020 tmp_buff = foreign->id;
8021 uint i = 0;
8022 while (tmp_buff[i] != '/')
8023 i++;
8024 tmp_buff += i + 1;
8025 lex_string_t *tmp_foreign_id = session->make_lex_string(NULL, str_ref(tmp_buff));
8026
8027 /* Database name */
8028 tmp_buff = foreign->referenced_table_name;
8029
8030 i= 0;
8031 while (tmp_buff[i] != '/')
8032 {
8033 db_name[i]= tmp_buff[i];
8034 i++;
8035 }
8036 db_name[i] = 0;
8037 ulen= identifier::Table::filename_to_tablename(db_name, uname, sizeof(uname));
8038 lex_string_t *tmp_referenced_db = session->make_lex_string(NULL, str_ref(uname, ulen));
8039
8040 /* Table name */
8041 tmp_buff += i + 1;
8042 ulen= identifier::Table::filename_to_tablename(tmp_buff, uname, sizeof(uname));
8043 lex_string_t *tmp_referenced_table = session->make_lex_string(NULL, str_ref(uname, ulen));
8044
8046 List<lex_string_t> tmp_foreign_fields;
8047 List<lex_string_t> tmp_referenced_fields;
8048 for (i= 0;;)
8049 {
8050 tmp_foreign_fields.push_back(session->make_lex_string(NULL, str_ref(foreign->foreign_col_names[i])));
8051 tmp_referenced_fields.push_back(session->make_lex_string(NULL, str_ref(foreign->referenced_col_names[i])));
8052 if (++i >= foreign->n_fields)
8053 break;
8054 }
8055
8056 if (foreign->type & DICT_FOREIGN_ON_DELETE_CASCADE)
8057 tmp_buff= "CASCADE";
8058 else if (foreign->type & DICT_FOREIGN_ON_DELETE_SET_NULL)
8059 tmp_buff= "SET NULL";
8060 else if (foreign->type & DICT_FOREIGN_ON_DELETE_NO_ACTION)
8061 tmp_buff= "NO ACTION";
8062 else
8063 tmp_buff= "RESTRICT";
8064 lex_string_t *tmp_delete_method = session->make_lex_string(NULL, str_ref(tmp_buff));
8065
8066 if (foreign->type & DICT_FOREIGN_ON_UPDATE_CASCADE)
8067 tmp_buff= "CASCADE";
8068 else if (foreign->type & DICT_FOREIGN_ON_UPDATE_SET_NULL)
8069 tmp_buff= "SET NULL";
8070 else if (foreign->type & DICT_FOREIGN_ON_UPDATE_NO_ACTION)
8071 tmp_buff= "NO ACTION";
8072 else
8073 tmp_buff= "RESTRICT";
8074 lex_string_t *tmp_update_method = session->make_lex_string(NULL, str_ref(tmp_buff));
8075
8076 lex_string_t *tmp_referenced_key_name = foreign->referenced_index && foreign->referenced_index->name
8077 ? session->make_lex_string(NULL, str_ref(foreign->referenced_index->name))
8078 : NULL;
8079
8080 ForeignKeyInfo f_key_info(
8081 tmp_foreign_id, tmp_referenced_db, tmp_referenced_table,
8082 tmp_update_method, tmp_delete_method, tmp_referenced_key_name,
8083 tmp_foreign_fields, tmp_referenced_fields);
8084
8085 f_key_list->push_back((ForeignKeyInfo*)session->mem.memdup(&f_key_info, sizeof(ForeignKeyInfo)));
8086 foreign = UT_LIST_GET_NEXT(foreign_list, foreign);
8087 }
8088 mutex_exit(&(dict_sys->mutex));
8089 prebuilt->trx->op_info = "";
8090
8091 return 0;
8092}
8093
8094/*****************************************************************/
8099UNIV_INTERN
8100bool
8102/*=================================*/
8103{
8104 bool can_switch;
8105
8106 ut_a(prebuilt->trx == session_to_trx(getTable()->in_use));
8107
8108 prebuilt->trx->op_info =
8109 "determining if there are foreign key constraints";
8110 row_mysql_lock_data_dictionary(prebuilt->trx);
8111
8112 can_switch = !UT_LIST_GET_FIRST(prebuilt->table->referenced_list)
8113 && !UT_LIST_GET_FIRST(prebuilt->table->foreign_list);
8114
8116 prebuilt->trx->op_info = "";
8117
8118 return(can_switch);
8119}
8120
8121/*******************************************************************/
8127UNIV_INTERN
8128uint
8130/*========================================*/
8131{
8132 if (dict_table_is_referenced_by_foreign_key(prebuilt->table)) {
8133
8134 return(1);
8135 }
8136
8137 return(0);
8138}
8139
8140/*******************************************************************/
8143UNIV_INTERN
8144void
8146/*======================================*/
8147 char* str)
8148{
8149 free(str);
8150}
8151
8152/*******************************************************************/
8155UNIV_INTERN
8156int
8158/*===============*/
8159 enum ha_extra_function operation)
8161{
8162 /* Warning: since it is not sure that MySQL calls external_lock
8163 before calling this function, the trx field in prebuilt can be
8164 obsolete! */
8165
8166 switch (operation) {
8167 case HA_EXTRA_FLUSH:
8168 if (prebuilt->blob_heap) {
8170 }
8171 break;
8172 case HA_EXTRA_RESET_STATE:
8174 break;
8175 case HA_EXTRA_NO_KEYREAD:
8176 prebuilt->read_just_key = 0;
8177 break;
8178 case HA_EXTRA_KEYREAD:
8179 prebuilt->read_just_key = 1;
8180 break;
8181 case HA_EXTRA_KEYREAD_PRESERVE_FIELDS:
8182 prebuilt->keep_other_fields_on_keyread = 1;
8183 break;
8184
8185 /* IMPORTANT: prebuilt->trx can be obsolete in
8186 this method, because it is not sure that MySQL
8187 calls external_lock before this method with the
8188 parameters below. We must not invoke update_session()
8189 either, because the calling threads may change.
8190 CAREFUL HERE, OR MEMORY CORRUPTION MAY OCCUR! */
8191 case HA_EXTRA_IGNORE_DUP_KEY:
8192 session_to_trx(getTable()->in_use)->duplicates |= TRX_DUP_IGNORE;
8193 break;
8194 case HA_EXTRA_WRITE_CAN_REPLACE:
8195 session_to_trx(getTable()->in_use)->duplicates |= TRX_DUP_REPLACE;
8196 break;
8197 case HA_EXTRA_WRITE_CANNOT_REPLACE:
8198 session_to_trx(getTable()->in_use)->duplicates &= ~TRX_DUP_REPLACE;
8199 break;
8200 case HA_EXTRA_NO_IGNORE_DUP_KEY:
8201 session_to_trx(getTable()->in_use)->duplicates &=
8202 ~(TRX_DUP_IGNORE | TRX_DUP_REPLACE);
8203 break;
8204 default:/* Do nothing */
8205 ;
8206 }
8207
8208 return(0);
8209}
8210
8211UNIV_INTERN
8212int
8214{
8215 if (prebuilt->blob_heap) {
8217 }
8218
8220
8221 /* TODO: This should really be reset in reset_template() but for now
8222 it's safer to do it explicitly here. */
8223
8224 /* This is a statement level counter. */
8225 prebuilt->autoinc_last_value = 0;
8226
8227 return(0);
8228}
8229
8230/******************************************************************/
8233static inline
8234ulint
8236/*=========================*/
8237 enum_tx_isolation iso)
8238{
8239 switch(iso) {
8240 case ISO_REPEATABLE_READ: return(TRX_ISO_REPEATABLE_READ);
8241 case ISO_READ_COMMITTED: return(TRX_ISO_READ_COMMITTED);
8242 case ISO_SERIALIZABLE: return(TRX_ISO_SERIALIZABLE);
8243 case ISO_READ_UNCOMMITTED: return(TRX_ISO_READ_UNCOMMITTED);
8244 default: ut_a(0); return(0);
8245 }
8246}
8247
8248/******************************************************************/
8253UNIV_INTERN
8254int
8256/*=======================*/
8257 Session* session,
8258 int lock_type)
8259{
8260 update_session(session);
8261
8262 trx_t *trx= prebuilt->trx;
8263
8264 prebuilt->sql_stat_start = TRUE;
8265 prebuilt->hint_need_to_fetch_extra_cols = 0;
8266
8268
8269 if (lock_type == F_WRLCK) {
8270
8271 /* If this is a SELECT, then it is in UPDATE TABLE ...
8272 or SELECT ... FOR UPDATE */
8273 prebuilt->select_lock_type = LOCK_X;
8274 prebuilt->stored_select_lock_type = LOCK_X;
8275 }
8276
8277 if (lock_type != F_UNLCK) {
8278 /* MySQL is setting a new table lock */
8279
8280 if (trx->isolation_level == TRX_ISO_SERIALIZABLE
8281 && prebuilt->select_lock_type == LOCK_NONE
8282 && session_test_options(session,
8283 OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) {
8284
8285 /* To get serializable execution, we let InnoDB
8286 conceptually add 'LOCK IN SHARE MODE' to all SELECTs
8287 which otherwise would have been consistent reads. An
8288 exception is consistent reads in the AUTOCOMMIT=1 mode:
8289 we know that they are read-only transactions, and they
8290 can be serialized also if performed as consistent
8291 reads. */
8292
8293 prebuilt->select_lock_type = LOCK_S;
8294 prebuilt->stored_select_lock_type = LOCK_S;
8295 }
8296
8297 /* Starting from 4.1.9, no InnoDB table lock is taken in LOCK
8298 TABLES if AUTOCOMMIT=1. It does not make much sense to acquire
8299 an InnoDB table lock if it is released immediately at the end
8300 of LOCK TABLES, and InnoDB's table locks in that case cause
8301 VERY easily deadlocks.
8302
8303 We do not set InnoDB table locks if user has not explicitly
8304 requested a table lock. Note that session_in_lock_tables(session)
8305 can hold in some cases, e.g., at the start of a stored
8306 procedure call (SQLCOM_CALL). */
8307
8308 if (prebuilt->select_lock_type != LOCK_NONE) {
8309 trx->mysql_n_tables_locked++;
8310 }
8311
8312 prebuilt->mysql_has_locked = TRUE;
8313
8314 return(0);
8315 }
8316
8317 /* MySQL is releasing a table lock */
8318 prebuilt->mysql_has_locked = FALSE;
8319 trx->mysql_n_tables_locked= 0;
8320
8321 return(0);
8322}
8323
8324/************************************************************************/
8327static
8328bool
8330/*===============*/
8331 plugin::StorageEngine* engine,
8332 Session* session,
8333 stat_print_fn *stat_print)
8334{
8335 trx_t* trx;
8336 static const char truncated_msg[] = "... truncated...\n";
8337 const long MAX_STATUS_SIZE = 1048576;
8338 ulint trx_list_start = ULINT_UNDEFINED;
8339 ulint trx_list_end = ULINT_UNDEFINED;
8340
8341 assert(engine == innodb_engine_ptr);
8342
8343 trx = check_trx_exists(session);
8344
8346
8347 /* We let the InnoDB Monitor to output at most MAX_STATUS_SIZE
8348 bytes of text. */
8349
8350 long flen, usable_len;
8351 char* str;
8352
8353 mutex_enter(&srv_monitor_file_mutex);
8354 rewind(srv_monitor_file);
8355 srv_printf_innodb_monitor(srv_monitor_file, FALSE,
8356 &trx_list_start, &trx_list_end);
8357 flen = ftell(srv_monitor_file);
8358 os_file_set_eof(srv_monitor_file);
8359
8360 if (flen < 0) {
8361 flen = 0;
8362 }
8363
8364 if (flen > MAX_STATUS_SIZE) {
8365 usable_len = MAX_STATUS_SIZE;
8366 srv_truncated_status_writes++;
8367 } else {
8368 usable_len = flen;
8369 }
8370
8371 /* allocate buffer for the string, and
8372 read the contents of the temporary file */
8373
8374 if (!(str = (char*) malloc(usable_len + 1))) {
8375 mutex_exit(&srv_monitor_file_mutex);
8376 return(TRUE);
8377 }
8378
8379 rewind(srv_monitor_file);
8380 if (flen < MAX_STATUS_SIZE) {
8381 /* Display the entire output. */
8382 flen = (long) fread(str, 1, flen, srv_monitor_file);
8383 } else if (trx_list_end < (ulint) flen
8384 && trx_list_start < trx_list_end
8385 && trx_list_start + (flen - trx_list_end)
8386 < MAX_STATUS_SIZE - sizeof truncated_msg - 1) {
8387 /* Omit the beginning of the list of active transactions. */
8388 long len = (long) fread(str, 1, trx_list_start, srv_monitor_file);
8389 memcpy(str + len, truncated_msg, sizeof truncated_msg - 1);
8390 len += sizeof truncated_msg - 1;
8391 usable_len = (MAX_STATUS_SIZE - 1) - len;
8392 fseek(srv_monitor_file, flen - usable_len, SEEK_SET);
8393 len += (long) fread(str + len, 1, usable_len, srv_monitor_file);
8394 flen = len;
8395 } else {
8396 /* Omit the end of the output. */
8397 flen = (long) fread(str, 1, MAX_STATUS_SIZE - 1, srv_monitor_file);
8398 }
8399
8400 mutex_exit(&srv_monitor_file_mutex);
8401
8402 stat_print(session, innobase_engine_name, strlen(innobase_engine_name),
8403 STRING_WITH_LEN(""), str, flen);
8404
8405 free(str);
8406
8407 return(FALSE);
8408}
8409
8410/************************************************************************/
8413static
8414bool
8416/*=====================*/
8417 plugin::StorageEngine* engine,
8418 Session* session,
8420 stat_print_fn* stat_print)
8422{
8423 char buf1[IO_SIZE], buf2[IO_SIZE];
8424 mutex_t* mutex;
8425 rw_lock_t* lock;
8426 ulint block_mutex_oswait_count = 0;
8427 ulint block_lock_oswait_count = 0;
8428 mutex_t* block_mutex = NULL;
8429 rw_lock_t* block_lock = NULL;
8430#ifdef UNIV_DEBUG
8431 ulint rw_lock_count= 0;
8432 ulint rw_lock_count_spin_loop= 0;
8433 ulint rw_lock_count_spin_rounds= 0;
8434 ulint rw_lock_count_os_wait= 0;
8435 ulint rw_lock_count_os_yield= 0;
8436 uint64_t rw_lock_wait_time= 0;
8437#endif /* UNIV_DEBUG */
8438 uint engine_name_len= strlen(innobase_engine_name), buf1len, buf2len;
8439 assert(engine == innodb_engine_ptr);
8440
8441 mutex_enter(&mutex_list_mutex);
8442
8443 for (mutex = UT_LIST_GET_FIRST(mutex_list); mutex != NULL;
8444 mutex = UT_LIST_GET_NEXT(list, mutex)) {
8445 if (mutex->count_os_wait == 0) {
8446 continue;
8447 }
8448
8449
8450 if (buf_pool_is_block_mutex(mutex)) {
8451 block_mutex = mutex;
8452 block_mutex_oswait_count += mutex->count_os_wait;
8453 continue;
8454 }
8455#ifdef UNIV_DEBUG
8456 if (mutex->mutex_type != 1) {
8457 if (mutex->count_using > 0) {
8458 buf1len= my_snprintf(buf1, sizeof(buf1),
8459 "%s:%s", mutex->cmutex_name, innobase_basename(mutex->cfile_name));
8460 buf2len= my_snprintf(buf2, sizeof(buf2),
8461 "count=%lu, spin_waits=%lu,"
8462 " spin_rounds=%lu, "
8463 "os_waits=%lu, os_yields=%lu,"
8464 " os_wait_times=%lu",
8465 mutex->count_using,
8466 mutex->count_spin_loop,
8467 mutex->count_spin_rounds,
8468 mutex->count_os_wait,
8469 mutex->count_os_yield,
8470 (ulong) (mutex->lspent_time/1000));
8471
8472 if (stat_print(session, innobase_engine_name,
8473 engine_name_len, buf1, buf1len,
8474 buf2, buf2len)) {
8475 mutex_exit(&mutex_list_mutex);
8476 return(1);
8477 }
8478 }
8479 } else {
8480 rw_lock_count += mutex->count_using;
8481 rw_lock_count_spin_loop += mutex->count_spin_loop;
8482 rw_lock_count_spin_rounds += mutex->count_spin_rounds;
8483 rw_lock_count_os_wait += mutex->count_os_wait;
8484 rw_lock_count_os_yield += mutex->count_os_yield;
8485 rw_lock_wait_time += mutex->lspent_time;
8486 }
8487#else /* UNIV_DEBUG */
8488 buf1len= snprintf(buf1, sizeof(buf1), "%s:%lu",
8489 innobase_basename(mutex->cfile_name),
8490 (ulong) mutex->cline);
8491 buf2len= snprintf(buf2, sizeof(buf2), "os_waits=%lu",
8492 (ulong) mutex->count_os_wait);
8493
8494 if (stat_print(session, innobase_engine_name,
8495 engine_name_len, buf1, buf1len,
8496 buf2, buf2len)) {
8497 mutex_exit(&mutex_list_mutex);
8498 return(1);
8499 }
8500#endif /* UNIV_DEBUG */
8501 }
8502
8503 if (block_mutex) {
8504 buf1len = snprintf(buf1, sizeof buf1,
8505 "combined %s:%lu",
8506 innobase_basename(block_mutex->cfile_name),
8507 (ulong) block_mutex->cline);
8508 buf2len = snprintf(buf2, sizeof buf2,
8509 "os_waits=%lu",
8510 (ulong) block_mutex_oswait_count);
8511
8512 if (stat_print(session, innobase_engine_name,
8513 strlen(innobase_engine_name), buf1, buf1len,
8514 buf2, buf2len)) {
8515 mutex_exit(&mutex_list_mutex);
8516 return(1);
8517 }
8518 }
8519
8520 mutex_exit(&mutex_list_mutex);
8521
8522 mutex_enter(&rw_lock_list_mutex);
8523
8524 for (lock = UT_LIST_GET_FIRST(rw_lock_list); lock != NULL;
8525 lock = UT_LIST_GET_NEXT(list, lock)) {
8526 if (lock->count_os_wait == 0) {
8527 continue;
8528 }
8529
8530 if (buf_pool_is_block_lock(lock)) {
8531 block_lock = lock;
8532 block_lock_oswait_count += lock->count_os_wait;
8533 continue;
8534 }
8535
8536 buf1len = snprintf(buf1, sizeof buf1, "%s:%lu",
8538 (ulong) lock->cline);
8539 buf2len = snprintf(buf2, sizeof buf2, "os_waits=%lu",
8540 (ulong) lock->count_os_wait);
8541
8542 if (stat_print(session, innobase_engine_name,
8543 strlen(innobase_engine_name), buf1, buf1len,
8544 buf2, buf2len)) {
8545 mutex_exit(&rw_lock_list_mutex);
8546 return(1);
8547 }
8548 }
8549
8550 if (block_lock) {
8551 buf1len = snprintf(buf1, sizeof buf1,
8552 "combined %s:%lu",
8553 innobase_basename(block_lock->cfile_name),
8554 (ulong) block_lock->cline);
8555 buf2len = snprintf(buf2, sizeof buf2,
8556 "os_waits=%lu",
8557 (ulong) block_lock_oswait_count);
8558
8559 if (stat_print(session, innobase_engine_name,
8560 strlen(innobase_engine_name), buf1, buf1len,
8561 buf2, buf2len)) {
8562 mutex_exit(&rw_lock_list_mutex);
8563 return(1);
8564 }
8565 }
8566
8567 mutex_exit(&rw_lock_list_mutex);
8568
8569#ifdef UNIV_DEBUG
8570 buf2len = snprintf(buf2, sizeof buf2,
8571 "count=%lu, spin_waits=%lu, spin_rounds=%lu, "
8572 "os_waits=%lu, os_yields=%lu, os_wait_times=%lu",
8573 (ulong) rw_lock_count,
8574 (ulong) rw_lock_count_spin_loop,
8575 (ulong) rw_lock_count_spin_rounds,
8576 (ulong) rw_lock_count_os_wait,
8577 (ulong) rw_lock_count_os_yield,
8578 (ulong) (rw_lock_wait_time / 1000));
8579
8580 if (stat_print(session, innobase_engine_name, engine_name_len,
8581 STRING_WITH_LEN("rw_lock_mutexes"), buf2, buf2len)) {
8582 return(1);
8583 }
8584#endif /* UNIV_DEBUG */
8585
8586 return(FALSE);
8587}
8588
8589bool InnobaseEngine::show_status(Session* session,
8590 stat_print_fn* stat_print,
8591 enum ha_stat_type stat_type)
8592{
8593 assert(this == innodb_engine_ptr);
8594
8595 switch (stat_type) {
8596 case HA_ENGINE_STATUS:
8597 return innodb_show_status(this, session, stat_print);
8598 case HA_ENGINE_MUTEX:
8599 return innodb_mutex_show_status(this, session, stat_print);
8600 default:
8601 return(FALSE);
8602 }
8603}
8604
8605/************************************************************************/
8609
8610static INNOBASE_SHARE* get_share(const char* table_name)
8611{
8612 INNOBASE_SHARE *share;
8613 boost::mutex::scoped_lock scopedLock(innobase_share_mutex);
8614
8615 ulint fold = ut_fold_string(table_name);
8616
8617 HASH_SEARCH(table_name_hash, innobase_open_tables, fold,
8618 INNOBASE_SHARE*, share,
8619 ut_ad(share->use_count > 0),
8620 !strcmp(share->table_name, table_name));
8621
8622 if (!share) {
8623 /* TODO: invoke HASH_MIGRATE if innobase_open_tables
8624 grows too big */
8625
8626 share= new INNOBASE_SHARE(table_name);
8627
8628 HASH_INSERT(INNOBASE_SHARE, table_name_hash,
8629 innobase_open_tables, fold, share);
8630
8631 thr_lock_init(&share->lock);
8632
8633 /* Index translation table initialization */
8634 share->idx_trans_tbl.index_mapping = NULL;
8635 share->idx_trans_tbl.index_count = 0;
8636 share->idx_trans_tbl.array_size = 0;
8637 }
8638
8639 share->use_count++;
8640
8641 return(share);
8642}
8643
8644static void free_share(INNOBASE_SHARE* share)
8645{
8646 boost::mutex::scoped_lock scopedLock(innobase_share_mutex);
8647
8648#ifdef UNIV_DEBUG
8649 INNOBASE_SHARE* share2;
8650 ulint fold = ut_fold_string(share->table_name);
8651
8652 HASH_SEARCH(table_name_hash, innobase_open_tables, fold,
8653 INNOBASE_SHARE*, share2,
8654 ut_ad(share->use_count > 0),
8655 !strcmp(share->table_name, share2->table_name));
8656
8657 ut_a(share2 == share);
8658#endif /* UNIV_DEBUG */
8659
8660 if (!--share->use_count) {
8661 ulint fold = ut_fold_string(share->table_name);
8662
8663 HASH_DELETE(INNOBASE_SHARE, table_name_hash,
8664 innobase_open_tables, fold, share);
8665
8666 /* Free any memory from index translation table */
8667 free(share->idx_trans_tbl.index_mapping);
8668
8669 delete share;
8670
8671 /* TODO: invoke HASH_MIGRATE if innobase_open_tables
8672 shrinks too much */
8673 }
8674}
8675
8676/*****************************************************************/
8685UNIV_INTERN
8688/*====================*/
8689 Session* session,
8690 THR_LOCK_DATA** to,
8695 enum thr_lock_type lock_type)
8698{
8699 trx_t* trx;
8700
8701 /* Note that trx in this function is NOT necessarily prebuilt->trx
8702 because we call update_session() later, in ::external_lock()! Failure to
8703 understand this caused a serious memory corruption bug in 5.1.11. */
8704
8705 trx = check_trx_exists(session);
8706
8707 assert(EQ_CURRENT_SESSION(session));
8708 const uint32_t sql_command = session->getSqlCommand();
8709
8710 if (sql_command == SQLCOM_DROP_TABLE) {
8711
8712 /* MySQL calls this function in DROP Table though this table
8713 handle may belong to another session that is running a query.
8714 Let us in that case skip any changes to the prebuilt struct. */
8715
8716 } else if (lock_type == TL_READ_WITH_SHARED_LOCKS
8717 || lock_type == TL_READ_NO_INSERT
8718 || (lock_type != TL_IGNORE
8719 && sql_command != SQLCOM_SELECT)) {
8720
8721 /* The OR cases above are in this order:
8722 1) MySQL is doing LOCK TABLES ... READ LOCAL, or we
8723 are processing a stored procedure or function, or
8724 2) (we do not know when TL_READ_HIGH_PRIORITY is used), or
8725 3) this is a SELECT ... IN SHARE MODE, or
8726 4) we are doing a complex SQL statement like
8727 INSERT INTO ... SELECT ... and the logical logging (MySQL
8728 binlog) requires the use of a locking read, or
8729 MySQL is doing LOCK TABLES ... READ.
8730 5) we let InnoDB do locking reads for all SQL statements that
8731 are not simple SELECTs; note that select_lock_type in this
8732 case may get strengthened in ::external_lock() to LOCK_X.
8733 Note that we MUST use a locking read in all data modifying
8734 SQL statements, because otherwise the execution would not be
8735 serializable, and also the results from the update could be
8736 unexpected if an obsolete consistent read view would be
8737 used. */
8738
8739 ulint isolation_level;
8740
8741 isolation_level = trx->isolation_level;
8742
8744 || isolation_level <= TRX_ISO_READ_COMMITTED)
8745 && isolation_level != TRX_ISO_SERIALIZABLE
8746 && (lock_type == TL_READ || lock_type == TL_READ_NO_INSERT)
8747 && (sql_command == SQLCOM_INSERT_SELECT
8748 || sql_command == SQLCOM_REPLACE_SELECT
8749 || sql_command == SQLCOM_UPDATE
8750 || sql_command == SQLCOM_CREATE_TABLE
8751 || sql_command == SQLCOM_SET_OPTION)) {
8752
8753 /* If we either have innobase_locks_unsafe_for_binlog
8754 option set or this session is using READ COMMITTED
8755 isolation level and isolation level of the transaction
8756 is not set to serializable and MySQL is doing
8757 INSERT INTO...SELECT or REPLACE INTO...SELECT
8758 or UPDATE ... = (SELECT ...) or CREATE ...
8759 SELECT... or SET ... = (SELECT ...) without
8760 FOR UPDATE or IN SHARE MODE in select,
8761 then we use consistent read for select. */
8762
8763 prebuilt->select_lock_type = LOCK_NONE;
8764 prebuilt->stored_select_lock_type = LOCK_NONE;
8765 } else if (sql_command == SQLCOM_CHECKSUM) {
8766 /* Use consistent read for checksum table */
8767
8768 prebuilt->select_lock_type = LOCK_NONE;
8769 prebuilt->stored_select_lock_type = LOCK_NONE;
8770 } else {
8771 prebuilt->select_lock_type = LOCK_S;
8772 prebuilt->stored_select_lock_type = LOCK_S;
8773 }
8774
8775 } else if (lock_type != TL_IGNORE) {
8776
8777 /* We set possible LOCK_X value in external_lock, not yet
8778 here even if this would be SELECT ... FOR UPDATE */
8779
8780 prebuilt->select_lock_type = LOCK_NONE;
8781 prebuilt->stored_select_lock_type = LOCK_NONE;
8782 }
8783
8784 if (lock_type != TL_IGNORE && lock.type == TL_UNLOCK) {
8785
8786 /* If we are not doing a LOCK TABLE, DISCARD/IMPORT
8787 TABLESPACE or TRUNCATE TABLE then allow multiple
8788 writers. Note that ALTER TABLE uses a TL_WRITE_ALLOW_READ
8789 < TL_WRITE_CONCURRENT_INSERT.
8790 */
8791
8792 if ((lock_type >= TL_WRITE_CONCURRENT_INSERT
8793 && lock_type <= TL_WRITE)
8794 && ! session->doing_tablespace_operation()
8795 && sql_command != SQLCOM_TRUNCATE
8796 && sql_command != SQLCOM_CREATE_TABLE) {
8797
8798 lock_type = TL_WRITE_ALLOW_WRITE;
8799 }
8800
8801 /* In queries of type INSERT INTO t1 SELECT ... FROM t2 ...
8802 MySQL would use the lock TL_READ_NO_INSERT on t2, and that
8803 would conflict with TL_WRITE_ALLOW_WRITE, blocking all inserts
8804 to t2. Convert the lock to a normal read lock to allow
8805 concurrent inserts to t2.
8806 */
8807
8808 if (lock_type == TL_READ_NO_INSERT) {
8809
8810 lock_type = TL_READ;
8811 }
8812
8813 lock.type = lock_type;
8814 }
8815
8816 *to++= &lock;
8817
8818 return(to);
8819}
8820
8821/*********************************************************************/
8826UNIV_INTERN
8827ulint
8829/*==============================*/
8830 uint64_t* value)
8831{
8832 *value = 0;
8833
8834 dict_table_autoinc_lock(prebuilt->table);
8835 prebuilt->autoinc_error= DB_SUCCESS;
8836 /* Determine the first value of the interval */
8837 *value = dict_table_autoinc_read(prebuilt->table);
8838
8839 /* It should have been initialized during open. */
8840 if (*value == 0) {
8841 prebuilt->autoinc_error = DB_UNSUPPORTED;
8842 dict_table_autoinc_unlock(prebuilt->table);
8843 }
8844
8845 return(DB_SUCCESS);
8846}
8847
8848/*******************************************************************/
8852UNIV_INTERN
8853uint64_t
8855/*====================================*/
8856{
8857 uint64_t auto_inc;
8858 dict_table_t* innodb_table;
8859
8860 ut_a(prebuilt != NULL);
8861 ut_a(prebuilt->table != NULL);
8862
8863 innodb_table = prebuilt->table;
8864
8865 dict_table_autoinc_lock(innodb_table);
8866
8867 auto_inc = dict_table_autoinc_read(innodb_table);
8868
8869 if (auto_inc == 0) {
8870 ut_print_timestamp(stderr);
8871 errmsg_printf(error::ERROR, " InnoDB: AUTOINC next value generation is disabled for '%s'\n", innodb_table->name);
8872 }
8873
8874 dict_table_autoinc_unlock(innodb_table);
8875
8876 return(auto_inc);
8877}
8878
8879/*********************************************************************/
8886UNIV_INTERN
8887void
8889/*============================*/
8890 uint64_t offset,
8891 uint64_t increment,
8892 uint64_t nb_desired_values,
8893 uint64_t *first_value,
8894 uint64_t *nb_reserved_values)
8895{
8896 trx_t* trx;
8897 ulint error;
8898 uint64_t autoinc = 0;
8899
8900 /* Prepare prebuilt->trx in the table handle */
8901 update_session(getTable()->in_use);
8902
8903 error = innobase_get_autoinc(&autoinc);
8904
8905 if (error != DB_SUCCESS) {
8906 *first_value = (~(uint64_t) 0);
8907 return;
8908 }
8909
8910 /* This is a hack, since nb_desired_values seems to be accurate only
8911 for the first call to get_auto_increment() for multi-row INSERT and
8912 meaningless for other statements e.g, LOAD etc. Subsequent calls to
8913 this method for the same statement results in different values which
8914 don't make sense. Therefore we store the value the first time we are
8915 called and count down from that as rows are written (see doInsertRecord()).
8916 */
8917
8918 trx = prebuilt->trx;
8919
8920 /* Note: We can't rely on *first_value since some MySQL engines,
8921 in particular the partition engine, don't initialize it to 0 when
8922 invoking this method. So we are not sure if it's guaranteed to
8923 be 0 or not. */
8924
8925 /* We need the upper limit of the col type to check for
8926 whether we update the table autoinc counter or not. */
8927 uint64_t col_max_value = innobase_get_int_col_max_value(getTable()->next_number_field);
8928
8929 /* Called for the first time ? */
8930 if (trx->n_autoinc_rows == 0) {
8931
8932 trx->n_autoinc_rows = (ulint) nb_desired_values;
8933
8934 /* It's possible for nb_desired_values to be 0:
8935 e.g., INSERT INTO T1(C) SELECT C FROM T2; */
8936 if (nb_desired_values == 0) {
8937
8938 trx->n_autoinc_rows = 1;
8939 }
8940
8941 set_if_bigger(*first_value, autoinc);
8942 /* Not in the middle of a mult-row INSERT. */
8943 } else if (prebuilt->autoinc_last_value == 0) {
8944 set_if_bigger(*first_value, autoinc);
8945 /* Check for -ve values. */
8946 } else if (*first_value > col_max_value && trx->n_autoinc_rows > 0) {
8947 /* Set to next logical value. */
8948 ut_a(autoinc > trx->n_autoinc_rows);
8949 *first_value = (autoinc - trx->n_autoinc_rows) - 1;
8950 }
8951
8952 *nb_reserved_values = trx->n_autoinc_rows;
8953
8954 /* This all current style autoinc. */
8955 {
8956 uint64_t need;
8957 uint64_t current;
8958 uint64_t next_value;
8959
8960 current = *first_value > col_max_value ? autoinc : *first_value;
8961 need = *nb_reserved_values * increment;
8962
8963 /* Compute the last value in the interval */
8964 next_value = innobase_next_autoinc(current, need, offset, col_max_value);
8965
8966 prebuilt->autoinc_last_value = next_value;
8967
8968 if (prebuilt->autoinc_last_value < *first_value) {
8969 *first_value = (~(unsigned long long) 0);
8970 } else {
8971 /* Update the table autoinc variable */
8972 dict_table_autoinc_update_if_greater(
8973 prebuilt->table, prebuilt->autoinc_last_value);
8974 }
8975 }
8976
8977 /* The increment to be used to increase the AUTOINC value, we use
8978 this in doInsertRecord() and doUpdateRecord() to increase the autoinc counter
8979 for columns that are filled by the user. We need the offset and
8980 the increment. */
8981 prebuilt->autoinc_offset = offset;
8982 prebuilt->autoinc_increment = increment;
8983
8984 dict_table_autoinc_unlock(prebuilt->table);
8985}
8986
8987/*******************************************************************/
8993UNIV_INTERN
8994int
8996/*==============================*/
8997 uint64_t value)
8998{
8999 int error;
9000
9001 update_session(getTable()->in_use);
9002
9004
9005 if (error != DB_SUCCESS) {
9006 error = convert_error_code_to_mysql(error,
9007 prebuilt->table->flags,
9008 user_session);
9009
9010 return(error);
9011 }
9012
9013 /* The next value can never be 0. */
9014 if (value == 0) {
9015 value = 1;
9016 }
9017
9019
9020 return 0;
9021}
9022
9023/* See comment in Cursor.cc */
9024UNIV_INTERN
9025bool
9026InnobaseEngine::get_error_message(int, String *buf) const
9027{
9028 trx_t* trx = check_trx_exists(current_session);
9029
9030 buf->copy(trx->detailed_error, (uint) strlen(trx->detailed_error),
9031 system_charset_info);
9032
9033 return(FALSE);
9034}
9035
9036/*******************************************************************/
9041UNIV_INTERN
9042int
9044/*=================*/
9045 const unsigned char* ref1,
9047 const unsigned char* ref2)
9049{
9050 enum_field_types mysql_type;
9051 Field* field;
9052 KeyPartInfo* key_part;
9053 KeyPartInfo* key_part_end;
9054 uint len1;
9055 uint len2;
9056 int result;
9057
9058 if (prebuilt->clust_index_was_generated) {
9059 /* The 'ref' is an InnoDB row id */
9060
9061 return(memcmp(ref1, ref2, DATA_ROW_ID_LEN));
9062 }
9063
9064 /* Do a type-aware comparison of primary key fields. PK fields
9065 are always NOT NULL, so no checks for NULL are performed. */
9066
9067 key_part = getTable()->key_info[getTable()->getShare()->getPrimaryKey()].key_part;
9068
9069 key_part_end = key_part
9070 + getTable()->key_info[getTable()->getShare()->getPrimaryKey()].key_parts;
9071
9072 for (; key_part != key_part_end; ++key_part) {
9073 field = key_part->field;
9074 mysql_type = field->type();
9075
9076 if (mysql_type == DRIZZLE_TYPE_BLOB) {
9077
9078 /* In the MySQL key value format, a column prefix of
9079 a BLOB is preceded by a 2-byte length field */
9080
9083
9084 ref1 += 2;
9085 ref2 += 2;
9086 result = ((Field_blob*)field)->cmp( ref1, len1,
9087 ref2, len2);
9088 } else {
9089 result = field->key_cmp(ref1, ref2);
9090 }
9091
9092 if (result) {
9093
9094 return(result);
9095 }
9096
9097 ref1 += key_part->store_length;
9098 ref2 += key_part->store_length;
9099 }
9100
9101 return(0);
9102}
9103
9104/**********************************************************************
9105This function is used to find the storage length in bytes of the first n
9106characters for prefix indexes using a multibyte character set. The function
9107finds charset information and returns length of prefix_len characters in the
9108index field in bytes.
9109@return number of bytes occupied by the first n characters */
9110
9111ulint
9113/*===========================*/
9114 ulint charset_id,
9115 ulint prefix_len,
9118 ulint data_len,
9119 const char* str)
9120{
9121 ulint char_length;
9122 ulint n_chars;
9123 const charset_info_st* charset;
9124
9125 charset = get_charset((uint) charset_id);
9126
9127 ut_ad(charset);
9128 ut_ad(charset->mbmaxlen);
9129
9130 /* Calculate how many characters at most the prefix index contains */
9131
9132 n_chars = prefix_len / charset->mbmaxlen;
9133
9134 /* If the charset is multi-byte, then we must find the length of the
9135 first at most n chars in the string. If the string contains less
9136 characters than n, then we return the length to the end of the last
9137 character. */
9138
9139 if (charset->mbmaxlen > 1) {
9140 /* my_charpos() returns the byte length of the first n_chars
9141 characters, or a value bigger than the length of str, if
9142 there were not enough full characters in str.
9143
9144 Why does the code below work:
9145 Suppose that we are looking for n UTF-8 characters.
9146
9147 1) If the string is long enough, then the prefix contains at
9148 least n complete UTF-8 characters + maybe some extra
9149 characters + an incomplete UTF-8 character. No problem in
9150 this case. The function returns the pointer to the
9151 end of the nth character.
9152
9153 2) If the string is not long enough, then the string contains
9154 the complete value of a column, that is, only complete UTF-8
9155 characters, and we can store in the column prefix index the
9156 whole string. */
9157
9158 char_length = my_charpos(charset, str,
9159 str + data_len, (int) n_chars);
9160 if (char_length > data_len) {
9161 char_length = data_len;
9162 }
9163 } else {
9164 if (data_len < prefix_len) {
9165 char_length = data_len;
9166 } else {
9167 char_length = prefix_len;
9168 }
9169 }
9170
9171 return(char_length);
9172}
9173
9179void
9181 Session *session)
9182{
9183 /*
9184 * Create the InnoDB transaction structure
9185 * for the session
9186 */
9187 trx_t *trx= check_trx_exists(session);
9188
9189 /* "reset" the error message for the transaction */
9190 trx->detailed_error[0]= '\0';
9191
9192 /* Set the isolation level of the transaction. */
9193 trx->isolation_level= innobase_map_isolation_level(session->getTxIsolation());
9194}
9195
9196void
9197InnobaseEngine::doEndStatement(
9198 Session *session)
9199{
9200 trx_t *trx= check_trx_exists(session);
9201
9202 /* Release a possible FIFO ticket and search latch. Since we
9203 may reserve the kernel mutex, we have to release the search
9204 system latch first to obey the latching order. */
9205
9207
9208}
9209
9210/*******************************************************************/
9213int
9215/*================*/
9216 Session* session,
9219 bool all)
9222{
9223 int error = 0;
9224 trx_t* trx = check_trx_exists(session);
9225
9226 assert(this == innodb_engine_ptr);
9227
9228 /* we use support_xa value as it was seen at transaction start
9229 time, not the current session variable value. Any possible changes
9230 to the session variable take effect only in the next transaction */
9231 if (!trx->support_xa) {
9232
9233 return(0);
9234 }
9235
9236 session->get_xid(reinterpret_cast<DrizzleXid*>(&trx->xid));
9237
9238 /* Release a possible FIFO ticket and search latch. Since we will
9239 reserve the kernel mutex, we have to release the search system latch
9240 first to obey the latching order. */
9241
9243
9244 if (all
9245 || (!session_test_options(session, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))) {
9246
9247 /* We were instructed to prepare the whole transaction, or
9248 this is an SQL statement end and autocommit is on */
9249
9250 ut_ad(trx->conc_state != TRX_NOT_STARTED);
9251
9252 error = (int) trx_prepare_for_mysql(trx);
9253 } else {
9254 /* We just mark the SQL statement ended and do not do a
9255 transaction prepare */
9256
9257 /* If we had reserved the auto-inc lock for some
9258 table in this SQL statement we release it now */
9259
9261
9262 /* Store the current undo_no of the transaction so that we
9263 know where to roll back if we have to roll back the next
9264 SQL statement */
9265
9267 }
9268
9269 /* Tell the InnoDB server that there might be work for utility
9270 threads: */
9271
9273
9274 return(error);
9275}
9276
9277uint64_t InnobaseEngine::doGetCurrentTransactionId(Session *session)
9278{
9279 trx_t *trx= session_to_trx(session);
9280 return (trx->id);
9281}
9282
9283uint64_t InnobaseEngine::doGetNewTransactionId(Session *session)
9284{
9285 trx_t*& trx = session_to_trx(session);
9286
9287 if (trx == NULL)
9288 {
9289 trx = innobase_trx_allocate(session);
9290
9291 innobase_trx_init(session, trx);
9292 }
9293
9294 mutex_enter(&kernel_mutex);
9295 trx->id= trx_sys_get_new_trx_id();
9296 mutex_exit(&kernel_mutex);
9297
9298 uint64_t transaction_id= trx->id;
9299
9300 return transaction_id;
9301}
9302
9303/*******************************************************************/
9306int
9308/*================*/
9309 ::drizzled::XID* xid_list,
9310 size_t len)
9311{
9312 assert(this == innodb_engine_ptr);
9313
9314 if (len == 0 || xid_list == NULL) {
9315
9316 return(0);
9317 }
9318
9319 return(trx_recover_for_mysql((::XID *)xid_list, len));
9320}
9321
9322/*******************************************************************/
9326int
9328/*===================*/
9329 ::drizzled::XID* xid)
9330{
9331 trx_t* trx;
9332
9333 assert(this == innodb_engine_ptr);
9334
9335 trx = trx_get_trx_by_xid((::XID *)xid);
9336
9337 if (trx) {
9339
9340 return(XA_OK);
9341 } else {
9342 return(XAER_NOTA);
9343 }
9344}
9345
9346/*******************************************************************/
9350int
9352/*=====================*/
9353 ::drizzled::XID* xid)
9355{
9356 trx_t* trx;
9357
9358 assert(this == innodb_engine_ptr);
9359
9360 trx = trx_get_trx_by_xid((::XID *)xid);
9361
9362 if (trx) {
9363 return(innobase_rollback_trx(trx));
9364 } else {
9365 return(XAER_NOTA);
9366 }
9367}
9368
9369
9370/************************************************************/
9373static
9374uint
9376/*=============================*/
9377 const char* format_name)
9378{
9379 char* endp;
9380 uint format_id;
9381
9382 ut_a(format_name != NULL);
9383
9384 /* The format name can contain the format id itself instead of
9385 the name and we check for that. */
9386 format_id = (uint) strtoul(format_name, &endp, 10);
9387
9388 /* Check for valid parse. */
9389 if (*endp == '\0' && *format_name != '\0') {
9390
9391 if (format_id <= DICT_TF_FORMAT_MAX) {
9392
9393 return(format_id);
9394 }
9395 } else {
9396
9397 for (format_id = 0; format_id <= DICT_TF_FORMAT_MAX;
9398 format_id++) {
9399 const char* name;
9400
9401 name = trx_sys_file_format_id_to_name(format_id);
9402
9403 if (!innobase_strcasecmp(format_name, name)) {
9404
9405 return(format_id);
9406 }
9407 }
9408 }
9409
9410 return(DICT_TF_FORMAT_MAX + 1);
9411}
9412
9413/************************************************************/
9417static
9418int
9420/*================================*/
9421 const char* format_max)
9422{
9423 uint format_id;
9424
9425 format_id = innobase_file_format_name_lookup(format_max);
9426
9427 if (format_id < DICT_TF_FORMAT_MAX + 1) {
9429 return((int) format_id);
9430 } else {
9431 return(-1);
9432 }
9433}
9434
9435
9436
9437static void init_options(drizzled::module::option_context &context)
9438{
9439 context("disable-checksums",
9440 "Disable InnoDB checksums validation.");
9441 context("data-home-dir",
9442 po::value<string>(),
9443 "The common part for InnoDB table spaces.");
9444 context("disable-doublewrite",
9445 "Disable InnoDB doublewrite buffer.");
9446 context("io-capacity",
9447 po::value<io_capacity_constraint>(&innodb_io_capacity)->default_value(200),
9448 "Number of IOPs the server can do. Tunes the background IO rate");
9449 context("fast-shutdown",
9450 po::value<trinary_constraint>(&innobase_fast_shutdown)->default_value(1),
9451 "Speeds up the shutdown process of the InnoDB storage engine. Possible values are 0, 1 (faster) or 2 (fastest - crash-like).");
9452 context("purge-batch-size",
9453 po::value<purge_batch_constraint>(&innodb_purge_batch_size)->default_value(20),
9454 "Number of UNDO log pages to purge in one batch from the history list.");
9455 context("purge-threads",
9456 po::value<purge_threads_constraint>(&innodb_n_purge_threads)->default_value(1),
9457 "Purge threads can be either 0 or 1. Default is 1.");
9458 context("file-per-table",
9459 po::value<bool>(&srv_file_per_table)->default_value(false)->zero_tokens(),
9460 "Stores each InnoDB table to an .ibd file in the database dir.");
9461 context("file-format-max",
9462 po::value<string>(&innobase_file_format_max)->default_value("Antelope"),
9463 "The highest file format in the tablespace.");
9464 context("file-format-check",
9465 po::value<bool>(&innobase_file_format_check)->default_value(true)->zero_tokens(),
9466 "Whether to perform system file format check.");
9467 context("file-format",
9468 po::value<string>(&innobase_file_format_name)->default_value("Antelope"),
9469 "File format to use for new tables in .ibd files.");
9470 context("flush-log-at-trx-commit",
9471 po::value<trinary_constraint>(&innodb_flush_log_at_trx_commit)->default_value(1),
9472 "Set to 0 (write and flush once per second), 1 (write and flush at each commit) or 2 (write at commit, flush once per second).");
9473 context("flush-method",
9474 po::value<string>(),
9475 "With which method to flush data.");
9476 context("log-group-home-dir",
9477 po::value<string>(),
9478 "Path to InnoDB log files.");
9479 context("max-dirty-pages-pct",
9480 po::value<max_dirty_pages_constraint>(&innodb_max_dirty_pages_pct)->default_value(75),
9481 "Percentage of dirty pages allowed in bufferpool.");
9482 context("disable-adaptive-flushing",
9483 "Do not attempt flushing dirty pages to avoid IO bursts at checkpoints.");
9484 context("max-purge-lag",
9485 po::value<uint64_constraint>(&innodb_max_purge_lag)->default_value(0),
9486 "Desired maximum length of the purge queue (0 = no limit)");
9487 context("status-file",
9488 po::value<bool>(&innobase_create_status_file)->default_value(false)->zero_tokens(),
9489 "Enable SHOW INNODB STATUS output in the innodb_status.<pid> file");
9490 context("disable-stats-on-metadata",
9491 "Disable statistics gathering for metadata commands such as SHOW TABLE STATUS (on by default)");
9492 context("stats-sample-pages",
9493 po::value<uint64_nonzero_constraint>(&innodb_stats_sample_pages)->default_value(8),
9494 "The number of index pages to sample when calculating statistics (default 8)");
9495 context("disable-adaptive-hash-index",
9496 "Enable InnoDB adaptive hash index (enabled by default)");
9497 context("replication-delay",
9498 po::value<uint64_constraint>(&innodb_replication_delay)->default_value(0),
9499 "Replication thread delay (ms) on the slave server if innodb_thread_concurrency is reached (0 by default)");
9500 context("additional-mem-pool-size",
9501 po::value<additional_mem_pool_constraint>(&innobase_additional_mem_pool_size)->default_value(8*1024*1024L),
9502 "Size of a memory pool InnoDB uses to store data dictionary information and other internal data structures.");
9503 context("autoextend-increment",
9504 po::value<autoextend_constraint>(&innodb_auto_extend_increment)->default_value(64L),
9505 "Data file autoextend increment in megabytes");
9506 context("buffer-pool-size",
9507 po::value<buffer_pool_constraint>(&innobase_buffer_pool_size)->default_value(128*1024*1024L),
9508 "The size of the memory buffer InnoDB uses to cache data and indexes of its tables.");
9509 context("buffer-pool-instances",
9510 po::value<buffer_pool_instances_constraint>(&innobase_buffer_pool_instances)->default_value(1),
9511 "Number of buffer pool instances, set to higher value on high-end machines to increase scalability");
9512
9513 context("commit-concurrency",
9514 po::value<concurrency_constraint>(&innobase_commit_concurrency)->default_value(0),
9515 "Helps in performance tuning in heavily concurrent environments.");
9516 context("concurrency-tickets",
9517 po::value<uint32_nonzero_constraint>(&innodb_concurrency_tickets)->default_value(500L),
9518 "Number of times a thread is allowed to enter InnoDB within the same SQL query after it has once got the ticket");
9519 context("read-io-threads",
9520 po::value<io_threads_constraint>(&innobase_read_io_threads)->default_value(4),
9521 "Number of background read I/O threads in InnoDB.");
9522 context("write-io-threads",
9523 po::value<io_threads_constraint>(&innobase_write_io_threads)->default_value(4),
9524 "Number of background write I/O threads in InnoDB.");
9525 context("force-recovery",
9526 po::value<force_recovery_constraint>(&innobase_force_recovery)->default_value(0),
9527 "Helps to save your data in case the disk image of the database becomes corrupt.");
9528 context("log-buffer-size",
9529 po::value<log_buffer_constraint>(&innobase_log_buffer_size)->default_value(8*1024*1024L),
9530 "The size of the buffer which InnoDB uses to write log to the log files on disk.");
9531 context("log-file-size",
9532 po::value<log_file_constraint>(&innobase_log_file_size)->default_value(20*1024*1024L),
9533 "The size of the buffer which InnoDB uses to write log to the log files on disk.");
9534 context("page-size",
9535 po::value<page_size_constraint>(&innobase_page_size)->default_value(1 << 14),
9536 "###EXPERIMENTAL###: The universal page size of the database. Changing for created database is not supported. Use on your own risk!");
9537 context("log-block-size",
9538 po::value<log_block_size_constraint>(&innobase_log_block_size)->default_value(1 << 9),
9539 "###EXPERIMENTAL###: The log block size of the transaction log file. Changing for created log file is not supported. Use on your own risk!");
9540 context("log-files-in-group",
9541 po::value<log_files_in_group_constraint>(&innobase_log_files_in_group)->default_value(2),
9542 "Number of log files in the log group. InnoDB writes to the files in a circular fashion.");
9543 context("mirrored-log-groups",
9544 po::value<mirrored_log_groups_constraint>(&innobase_mirrored_log_groups)->default_value(1),
9545 "Number of identical copies of log groups we keep for the database. Currently this should be set to 1.");
9546 context("open-files",
9547 po::value<open_files_constraint>(&innobase_open_files)->default_value(300L),
9548 "How many files at the maximum InnoDB keeps open at the same time.");
9549 context("sync-spin-loops",
9550 po::value<uint32_constraint>(&innodb_sync_spin_loops)->default_value(30L),
9551 "Count of spin-loop rounds in InnoDB mutexes (30 by default)");
9552 context("spin-wait-delay",
9553 po::value<uint32_constraint>(&innodb_spin_wait_delay)->default_value(6L),
9554 "Maximum delay between polling for a spin lock (6 by default)");
9555 context("thread-concurrency",
9556 po::value<concurrency_constraint>(&innobase_thread_concurrency)->default_value(0),
9557 "Helps in performance tuning in heavily concurrent environments. Sets the maximum number of threads allowed inside InnoDB. Value 0 will disable the thread throttling.");
9558 context("thread-sleep-delay",
9559 po::value<uint32_constraint>(&innodb_thread_sleep_delay)->default_value(10000L),
9560 "Time of innodb thread sleeping before joining InnoDB queue (usec). Value 0 disable a sleep");
9561 context("data-file-path",
9562 po::value<string>(),
9563 "Path to individual files and their sizes.");
9564 context("version",
9565 po::value<string>()->default_value(INNODB_VERSION_STR),
9566 "InnoDB version");
9567 context("use-internal-malloc",
9568 "Use InnoDB's internal memory allocator instal of the OS memory allocator.");
9569 context("disable-native-aio",
9570 _("Do not use Native AIO library for IO, even if available"));
9571 context("change-buffering",
9572 po::value<string>(&innobase_change_buffering),
9573 "Buffer changes to reduce random access: OFF, ON, inserting, deleting, changing, or purging.");
9574 context("read-ahead-threshold",
9575 po::value<read_ahead_threshold_constraint>(&innodb_read_ahead_threshold)->default_value(56),
9576 "Number of pages that must be accessed sequentially for InnoDB to trigger a readahead.");
9577 context("auto-lru-dump",
9578 po::value<uint32_constraint>(&buffer_pool_restore_at_startup)->default_value(0),
9579 "Time in seconds between automatic buffer pool dumps. "
9580 "0 (the default) disables automatic dumps.");
9581 context("ibuf-max-size",
9582 po::value<uint64_constraint>(&ibuf_max_size)->default_value(UINT64_MAX),
9583 "The maximum size of the insert buffer (in bytes).");
9584 context("ibuf-active-contract",
9585 po::value<binary_constraint>(&ibuf_active_contract)->default_value(1),
9586 "Enable/Disable active_contract of insert buffer. 0:disable 1:enable");
9587 context("ibuf-accel-rate",
9588 po::value<ibuf_accel_rate_constraint>(&ibuf_accel_rate)->default_value(100),
9589 "Tunes amount of insert buffer processing of background, in addition to innodb_io_capacity. (in percentage)");
9590 context("checkpoint-age-target",
9591 po::value<uint32_constraint>(&checkpoint_age_target)->default_value(0),
9592 "Control soft limit of checkpoint age. (0 : not control)");
9593 context("flush-neighbor-pages",
9594 po::value<binary_constraint>(&flush_neighbor_pages)->default_value(1),
9595 "Enable/Disable flushing also neighbor pages. 0:disable 1:enable");
9596 context("read-ahead",
9597 po::value<string>(&read_ahead)->default_value("linear"),
9598 "Control read ahead activity (none, random, [linear], both). [from 1.0.5: random read ahead is ignored]");
9599 context("adaptive-flushing-method",
9600 po::value<string>(&adaptive_flushing_method)->default_value("estimate"),
9601 "Choose method of innodb_adaptive_flushing. (native, [estimate], keep_average)");
9602 context("disable-xa",
9603 "Disable InnoDB support for the XA two-phase commit");
9604 context("disable-table-locks",
9605 "Disable InnoDB locking in LOCK TABLES");
9606 context("strict-mode",
9607 po::value<bool>(&strict_mode)->default_value(false)->zero_tokens(),
9608 "Use strict mode when evaluating create options.");
9609 context("replication-log",
9610 po::value<bool>(&innobase_use_replication_log)->default_value(false)->zero_tokens(),
9611 _("Enable internal replication log."));
9612 context("use-replicator",
9613 po::value<string>(&sysvar_transaction_log_use_replicator)->default_value(DEFAULT_USE_REPLICATOR),
9614 _("Name of the replicator plugin to use (default='default_replicator')"));
9615 context("lock-wait-timeout",
9616 po::value<lock_wait_constraint>(&lock_wait_timeout)->default_value(50),
9617 _("Timeout in seconds an InnoDB transaction may wait for a lock before being rolled back. Values above 100000000 disable the timeout."));
9618 context("old-blocks-pct",
9619 po::value<old_blocks_constraint>(&innobase_old_blocks_pct)->default_value(100 * 3 / 8),
9620 _("Percentage of the buffer pool to reserve for 'old' blocks."));
9621 context("old-blocks-time",
9622 po::value<uint32_t>(&buf_LRU_old_threshold_ms)->default_value(0),
9623 _("ove blocks to the 'new' end of the buffer pool if the first access"
9624 " was at least this many milliseconds ago."
9625 " The timeout is disabled if 0 (the default)."));
9626 context("stats-method",
9627 po::value<string>(&innodb_stats_method),
9628 "Specifies how InnoDB index statistics collection code should "
9629 "treat NULLs. Possible values are NULLS_EQUAL (default), "
9630 "NULLS_UNEQUAL and NULLS_IGNORED");
9631 context("rollback-segments",
9632 po::value<rollback_segments_constraint>(&innobase_rollback_segments)->default_value(128),
9633 "Number of UNDO logs to use");
9634#if defined(UNIV_DEBUG) && !defined(UNIV_HOTBACKUP)
9635 context(("timed-mutexes",
9636 po::value<bool>(&timed_mutexes)->default_value(false)->zero_tokens(),
9637 _("Specify whether to time mutexes (only InnoDB mutexes are currently "
9638 "supported)"));
9639#endif /* UNIV_DEBUG && !UNIV_HOTBACKUP */
9640
9641}
9642
9643
9644
9645DRIZZLE_DECLARE_PLUGIN
9646{
9647 DRIZZLE_VERSION_ID,
9648 "innodb",
9649 INNODB_VERSION_STR,
9650 "Innobase Oy",
9651 "InnoDB storage engine: transactional, row-level locking, foreign keys",
9652 PLUGIN_LICENSE_GPL,
9653 innobase_init, /* Plugin Init */
9654 NULL, /* depends */
9655 init_options /* reserved */
9656}
9657DRIZZLE_DECLARE_PLUGIN_END;
9658
9660 const key_range *end_key,
9661 bool eq_range_arg,
9662 bool sorted)
9663{
9664 int res;
9665 //if (!eq_range_arg)
9666 //in_range_read= TRUE;
9667 res= Cursor::read_range_first(start_key, end_key, eq_range_arg, sorted);
9668 //if (res)
9669 // in_range_read= FALSE;
9670 return res;
9671}
9672
9673
9675{
9676 int res= Cursor::read_range_next();
9677 //if (res)
9678 // in_range_read= FALSE;
9679 return res;
9680}
9681
9682/***********************************************************************
9683This function checks each index name for a table against reserved
9684system default primary index name 'GEN_CLUST_INDEX'. If a name matches,
9685this function pushes an warning message to the client, and returns true. */
9686UNIV_INTERN
9687bool
9688innobase_index_name_is_reserved(
9689/*============================*/
9690 /* out: true if an index name
9691 matches the reserved name */
9692 const trx_t* trx, /* in: InnoDB transaction handle */
9693 const KeyInfo* key_info, /* in: Indexes to be created */
9694 ulint num_of_keys) /* in: Number of indexes to
9695 be created. */
9696{
9697 const KeyInfo* key;
9698 uint key_num; /* index number */
9699
9700 for (key_num = 0; key_num < num_of_keys; key_num++) {
9701 key = &key_info[key_num];
9702
9703 if (innobase_strcasecmp(key->name,
9704 innobase_index_reserve_name) == 0) {
9705 /* Push warning to drizzle */
9706 push_warning_printf(trx->mysql_thd,
9707 DRIZZLE_ERROR::WARN_LEVEL_WARN,
9708 ER_WRONG_NAME_FOR_INDEX,
9709 "Cannot Create Index with name "
9710 "'%s'. The name is reserved "
9711 "for the system default primary "
9712 "index.",
9713 innobase_index_reserve_name);
9714
9715 my_error(ER_WRONG_NAME_FOR_INDEX, MYF(0),
9716 innobase_index_reserve_name);
9717
9718 return(true);
9719 }
9720 }
9721
9722 return(false);
9723}
9724
9725#ifdef UNIV_COMPILE_TEST_FUNCS
9726
9727typedef struct innobase_convert_name_test_struct {
9728 char* buf;
9729 ulint buflen;
9730 const char* id;
9731 ulint idlen;
9732 drizzled::Session *session;
9733 ibool file_id;
9734
9735 const char* expected;
9736} innobase_convert_name_test_t;
9737
9738void
9739test_innobase_convert_name()
9740{
9741 char buf[1024];
9742 ulint i;
9743
9744 innobase_convert_name_test_t test_input[] = {
9745 {buf, sizeof(buf), "abcd", 4, NULL, TRUE, "\"abcd\""},
9746 {buf, 7, "abcd", 4, NULL, TRUE, "\"abcd\""},
9747 {buf, 6, "abcd", 4, NULL, TRUE, "\"abcd\""},
9748 {buf, 5, "abcd", 4, NULL, TRUE, "\"abc\""},
9749 {buf, 4, "abcd", 4, NULL, TRUE, "\"ab\""},
9750
9751 {buf, sizeof(buf), "ab@0060cd", 9, NULL, TRUE, "\"ab`cd\""},
9752 {buf, 9, "ab@0060cd", 9, NULL, TRUE, "\"ab`cd\""},
9753 {buf, 8, "ab@0060cd", 9, NULL, TRUE, "\"ab`cd\""},
9754 {buf, 7, "ab@0060cd", 9, NULL, TRUE, "\"ab`cd\""},
9755 {buf, 6, "ab@0060cd", 9, NULL, TRUE, "\"ab`c\""},
9756 {buf, 5, "ab@0060cd", 9, NULL, TRUE, "\"ab`\""},
9757 {buf, 4, "ab@0060cd", 9, NULL, TRUE, "\"ab\""},
9758
9759 {buf, sizeof(buf), "ab\"cd", 5, NULL, TRUE,
9760 "\"#mysql50#ab\"\"cd\""},
9761 {buf, 17, "ab\"cd", 5, NULL, TRUE,
9762 "\"#mysql50#ab\"\"cd\""},
9763 {buf, 16, "ab\"cd", 5, NULL, TRUE,
9764 "\"#mysql50#ab\"\"c\""},
9765 {buf, 15, "ab\"cd", 5, NULL, TRUE,
9766 "\"#mysql50#ab\"\"\""},
9767 {buf, 14, "ab\"cd", 5, NULL, TRUE,
9768 "\"#mysql50#ab\""},
9769 {buf, 13, "ab\"cd", 5, NULL, TRUE,
9770 "\"#mysql50#ab\""},
9771 {buf, 12, "ab\"cd", 5, NULL, TRUE,
9772 "\"#mysql50#a\""},
9773 {buf, 11, "ab\"cd", 5, NULL, TRUE,
9774 "\"#mysql50#\""},
9775 {buf, 10, "ab\"cd", 5, NULL, TRUE,
9776 "\"#mysql50\""},
9777
9778 {buf, sizeof(buf), "ab/cd", 5, NULL, TRUE, "\"ab\".\"cd\""},
9779 {buf, 9, "ab/cd", 5, NULL, TRUE, "\"ab\".\"cd\""},
9780 {buf, 8, "ab/cd", 5, NULL, TRUE, "\"ab\".\"c\""},
9781 {buf, 7, "ab/cd", 5, NULL, TRUE, "\"ab\".\"\""},
9782 {buf, 6, "ab/cd", 5, NULL, TRUE, "\"ab\"."},
9783 {buf, 5, "ab/cd", 5, NULL, TRUE, "\"ab\"."},
9784 {buf, 4, "ab/cd", 5, NULL, TRUE, "\"ab\""},
9785 {buf, 3, "ab/cd", 5, NULL, TRUE, "\"a\""},
9786 {buf, 2, "ab/cd", 5, NULL, TRUE, "\"\""},
9787 /* XXX probably "" is a better result in this case
9788 {buf, 1, "ab/cd", 5, NULL, TRUE, "."},
9789 */
9790 {buf, 0, "ab/cd", 5, NULL, TRUE, ""},
9791 };
9792
9793 for (i = 0; i < sizeof(test_input) / sizeof(test_input[0]); i++) {
9794
9795 char* end;
9796 ibool ok = TRUE;
9797 size_t res_len;
9798
9799 fprintf(stderr, "TESTING %lu, %s, %lu, %s\n",
9800 test_input[i].buflen,
9801 test_input[i].id,
9802 test_input[i].idlen,
9803 test_input[i].expected);
9804
9806 test_input[i].buf,
9807 test_input[i].buflen,
9808 test_input[i].id,
9809 test_input[i].idlen,
9810 test_input[i].session,
9811 test_input[i].file_id);
9812
9813 res_len = (size_t) (end - test_input[i].buf);
9814
9815 if (res_len != strlen(test_input[i].expected)) {
9816
9817 fprintf(stderr, "unexpected len of the result: %u, "
9818 "expected: %u\n", (unsigned) res_len,
9819 (unsigned) strlen(test_input[i].expected));
9820 ok = FALSE;
9821 }
9822
9823 if (memcmp(test_input[i].buf,
9824 test_input[i].expected,
9825 strlen(test_input[i].expected)) != 0
9826 || !ok) {
9827
9828 fprintf(stderr, "unexpected result: %.*s, "
9829 "expected: %s\n", (int) res_len,
9830 test_input[i].buf,
9831 test_input[i].expected);
9832 ok = FALSE;
9833 }
9834
9835 if (ok) {
9836 fprintf(stderr, "OK: res: %.*s\n\n", (int) res_len,
9837 buf);
9838 } else {
9839 fprintf(stderr, "FAILED\n\n");
9840 return;
9841 }
9842 }
9843}
9844
9845#endif /* UNIV_COMPILE_TEST_FUNCS */
UNIV_INTERN void btr_search_enable(void)
Definition btr0sea.cc:236
UNIV_INTERN void btr_search_disable(void)
Definition btr0sea.cc:206
#define buf_pool_is_block_mutex(m)
Definition buf0buf.h:1045
#define buf_pool_is_block_lock(l)
Definition buf0buf.h:1050
Defines the interface to the CachedDirectory class.
virtual int doCommit(Session *session, bool all)
virtual bool flush_logs()
virtual int doReleaseTemporaryLatches(Session *session)
virtual int doXaCommitXid(::drizzled::XID *xid)
virtual int doXaRecover(::drizzled::XID *xid_list, size_t len)
virtual int close_connection(Session *session)
virtual int doXaRollbackXid(::drizzled::XID *xid)
UNIV_INTERN int doCreateTable(Session &session, Table &form, const identifier::Table &identifier, const message::Table &)
UNIV_INTERN uint32_t max_supported_key_length() const
virtual int doSetSavepoint(Session *session, drizzled::NamedSavepoint &savepoint)
virtual int doRollbackToSavepoint(Session *session, drizzled::NamedSavepoint &savepoint)
virtual int doXaPrepare(Session *session, bool all)
virtual int doReleaseSavepoint(Session *session, drizzled::NamedSavepoint &savepoint)
bool doDropSchema(const identifier::Schema &identifier)
virtual void doStartStatement(Session *session)
virtual int doStartTransaction(Session *session, start_transaction_option_t options)
UNIV_INTERN uint32_t max_supported_keys() const
UNIV_INTERN int doRenameTable(Session &, const identifier::Table &from, const identifier::Table &to)
UNIV_INTERN int doDropTable(Session &session, const identifier::Table &identifier)
virtual int doRollback(Session *session, bool all)
const Entries & getEntries() const
const char * getPath() const
virtual int read_range_first(const key_range *start_key, const key_range *end_key, bool eq_range, bool sorted)
virtual int read_range_next()
str_ref comment
Definition field.h:105
virtual uint32_t pack_length() const
Definition field.cc:707
const char * field_name
Definition field.h:104
This class defines the information for foreign keys.
query_id_t getQueryId() const
Definition session.h:621
session_id_t getSessionId() const
Definition session.h:640
std::vector< unsigned char > upd_buff
Definition ha_innodb.h:92
row_prebuilt_t * prebuilt
Definition ha_innodb.h:82
UNIV_INTERN ulint innobase_get_autoinc(uint64_t *value)
int read_range_next()
UNIV_INTERN ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key)
UNIV_INTERN ulint innobase_set_max_autoinc(uint64_t auto_inc)
UNIV_INTERN void update_session(Session *session)
UNIV_INTERN double scan_time()
UNIV_INTERN int discard_or_import_tablespace(bool discard)
UNIV_INTERN int check(Session *session)
UNIV_INTERN int doOpen(const drizzled::identifier::Table &identifier, int mode, uint test_if_locked)
UNIV_INTERN int external_lock(Session *session, int lock_type)
UNIV_INTERN const char * index_type(uint key_number)
UNIV_INTERN void position(const unsigned char *record)
UNIV_INTERN const key_map * keys_to_use_for_scanning()
UNIV_INTERN int rnd_next(unsigned char *buf)
UNIV_INTERN int get_foreign_key_list(Session *session, List< ForeignKeyInfo > *f_key_list)
UNIV_INTERN int cmp_ref(const unsigned char *ref1, const unsigned char *ref2)
UNIV_INTERN int index_next(unsigned char *buf)
UNIV_INTERN int index_next_same(unsigned char *buf, const unsigned char *key, uint keylen)
UNIV_INTERN dict_index_t * innobase_get_index(uint keynr)
UNIV_INTERN int extra(enum ha_extra_function operation)
INNOBASE_SHARE * share
Definition ha_innodb.h:89
UNIV_INTERN double read_time(uint index, uint ranges, ha_rows rows)
UNIV_INTERN int reset()
UNIV_INTERN int close(void)
UNIV_INTERN void innobase_initialize_autoinc()
UNIV_INTERN int reset_auto_increment(uint64_t value)
UNIV_INTERN int analyze(Session *session)
uint num_write_row
Definition ha_innodb.h:106
UNIV_INTERN ha_innobase(plugin::StorageEngine &engine, Table &table_arg)
UNIV_INTERN int doStartIndexScan(uint index, bool sorted)
UNIV_INTERN ha_rows estimate_rows_upper_bound()
UNIV_INTERN int index_last(unsigned char *buf)
UNIV_INTERN int index_prev(unsigned char *buf)
int read_range_first(const key_range *start_key, const key_range *end_key, bool eq_range_arg, bool sorted)
UNIV_INTERN char * update_table_comment(const char *comment)
UNIV_INTERN bool primary_key_is_clustered()
UNIV_INTERN int doInsertRecord(unsigned char *buf)
std::vector< unsigned char > key_val_buff
Definition ha_innodb.h:93
UNIV_INTERN int index_first(unsigned char *buf)
Session * user_session
Definition ha_innodb.h:85
UNIV_INTERN ulint innobase_lock_autoinc()
UNIV_INTERN int doEndIndexScan()
UNIV_INTERN int delete_all_rows()
UNIV_INTERN int info(uint)
UNIV_INTERN int doDeleteRecord(const unsigned char *buf)
UNIV_INTERN THR_LOCK_DATA ** store_lock(Session *session, THR_LOCK_DATA **to, enum thr_lock_type lock_type)
UNIV_INTERN uint referenced_by_foreign_key()
UNIV_INTERN ulint innobase_reset_autoinc(uint64_t auto_inc)
UNIV_INTERN int rnd_pos(unsigned char *buf, unsigned char *pos)
virtual UNIV_INTERN void get_auto_increment(uint64_t offset, uint64_t increment, uint64_t nb_desired_values, uint64_t *first_value, uint64_t *nb_reserved_values)
UNIV_INTERN void free_foreign_key_create_info(char *str)
UNIV_INTERN int doEndTableScan()
UNIV_INTERN int doUpdateRecord(const unsigned char *old_data, unsigned char *new_data)
UNIV_INTERN plugin::TransactionalStorageEngine * getTransactionalEngine()
Definition ha_innodb.h:135
UNIV_INTERN uint64_t innobase_peek_autoinc()
UNIV_INTERN int doStartTableScan(bool scan)
UNIV_INTERN void try_semi_consistent_read(bool yes)
ulong start_of_scan
Definition ha_innodb.h:100
UNIV_INTERN int general_fetch(unsigned char *buf, uint32_t direction, uint32_t match_mode)
UNIV_INTERN int index_read(unsigned char *buf, const unsigned char *key, uint key_len, enum ha_rkey_function find_flag)
UNIV_INTERN int index_read_idx(unsigned char *buf, uint index, const unsigned char *key, uint key_len, enum ha_rkey_function find_flag)
UNIV_INTERN bool was_semi_consistent_read()
UNIV_INTERN int index_read_last(unsigned char *buf, const unsigned char *key, uint key_len)
UNIV_INTERN uint store_key_val_for_row(uint keynr, char *buff, uint buff_len, const unsigned char *record)
UNIV_INTERN char * get_foreign_key_create_info()
UNIV_INTERN void unlock_row()
UNIV_INTERN int change_active_index(uint32_t keynr)
UNIV_INTERN bool can_switch_engines()
UNIV_INTERN ~ha_innobase()
UNIV_INLINE dtuple_t * dtuple_create(mem_heap_t *heap, ulint n_fields)
UNIV_INLINE void dfield_copy_data(dfield_t *field1, const dfield_t *field2)
UNIV_INLINE void dfield_set_null(dfield_t *field)
UNIV_INLINE ulint dtype_get_charset_coll(ulint prtype)
#define TMP_FILE_PREFIX
UNIV_INLINE ulint dict_index_get_n_unique(const dict_index_t *index)
UNIV_INLINE ulint dict_col_get_clust_pos(const dict_col_t *col, const dict_index_t *clust_index)
UNIV_INLINE ulint dict_index_is_clust(const dict_index_t *index) __attribute__((pure))
UNIV_INLINE void dict_col_copy_type(const dict_col_t *col, dtype_t *type)
UNIV_INLINE ulint dict_table_get_format(const dict_table_t *table)
UNIV_INLINE ulint dict_col_get_mbminlen(const dict_col_t *col)
UNIV_INLINE ulint dict_col_get_mbmaxlen(const dict_col_t *col)
UNIV_INLINE ibool dict_table_is_comp(const dict_table_t *table)
#define DICT_TF2_TEMPORARY
Definition dict0mem.h:109
#define DICT_FOREIGN_ON_DELETE_SET_NULL
Definition dict0mem.h:458
#define DICT_TF_FORMAT_ZIP
Definition dict0mem.h:83
#define DICT_FK_MAX_RECURSIVE_LOAD
Definition dict0mem.h:122
#define DICT_TF_COMPACT
Definition dict0mem.h:68
#define DICT_FOREIGN_ON_UPDATE_NO_ACTION
Definition dict0mem.h:462
#define DICT_TF_FORMAT_SHIFT
Definition dict0mem.h:79
#define DICT_TF_FORMAT_MIN
Definition dict0mem.h:90
#define DICT_FOREIGN_ON_UPDATE_SET_NULL
Definition dict0mem.h:460
#define DICT_UNIQUE
Definition dict0mem.h:52
#define DICT_CLUSTERED
Definition dict0mem.h:51
#define DICT_MAX_INDEX_COL_LEN
DICT_MAX_INDEX_COL_LEN is measured in bytes and is the maximum indexed column length (or indexed pref...
Definition dict0mem.h:308
#define DICT_TF_ZSSIZE_SHIFT
Definition dict0mem.h:72
#define DICT_TF2_SHIFT
Additional table flags.
Definition dict0mem.h:106
#define DICT_FOREIGN_ON_UPDATE_CASCADE
Definition dict0mem.h:459
#define DICT_FOREIGN_ON_DELETE_NO_ACTION
Definition dict0mem.h:461
#define DICT_FOREIGN_ON_DELETE_CASCADE
Definition dict0mem.h:457
#define DICT_TF_FORMAT_MAX
Definition dict0mem.h:87
static int innodb_file_format_name_validate(Session *, set_var *var)
static int innobase_rollback_trx(trx_t *trx)
static int innodb_file_format_max_validate(Session *session, set_var *var)
constrained_check< uint32_t, 95, 5 > old_blocks_constraint
Definition ha_innodb.cc:226
UNIV_INTERN void thd_set_lock_wait_time(drizzled::Session *in_session, ulint value)
UNIV_INTERN void innobase_casedn_str(char *a)
UNIV_INTERN trx_t * innobase_trx_allocate(Session *session)
static INNOBASE_SHARE * get_share(const char *table_name)
static ha_rows innodb_rec_per_key(dict_index_t *index, ulint i, ha_rows records)
static void innodb_srv_conc_exit_innodb(trx_t *trx)
Definition ha_innodb.cc:913
static void reset_template(row_prebuilt_t *prebuilt)
static int adaptive_flushing_method_validate(Session *, set_var *var)
static bool innodb_show_status(plugin::StorageEngine *engine, Session *session, stat_print_fn *stat_print)
UNIV_INTERN ulong thd_lock_wait_timeout(drizzled::Session *)
Definition ha_innodb.cc:997
static trx_t *& session_to_trx(Session *session)
static void innobase_trx_init(Session *session, trx_t *trx)
static bool innodb_mutex_show_status(plugin::StorageEngine *engine, Session *session, stat_print_fn *stat_print)
UNIV_INTERN ulint get_innobase_type_from_mysql_type(ulint *unsigned_flag, const void *f)
static int calc_row_difference(upd_t *uvect, unsigned char *old_row, unsigned char *new_row, Table *table, unsigned char *upd_buff, ulint buff_len, row_prebuilt_t *prebuilt, Session *)
static void innobase_commit_low(trx_t *trx)
ulint innobase_get_at_most_n_mbchars(ulint charset_id, ulint prefix_len, ulint data_len, const char *str)
static ulint convert_search_mode_to_innobase(enum ha_rkey_function find_flag)
static int innobase_file_format_validate_and_set(const char *format_max)
UNIV_INTERN ibool thd_has_edited_nontrans_tables(drizzled::Session *session)
Definition ha_innodb.cc:958
static trx_t * check_trx_exists(Session *session)
static uint innobase_read_from_2_little_endian(const unsigned char *buf)
UNIV_INTERN int innobase_mysql_cmp(int mysql_type, uint charset_number, const unsigned char *a, unsigned int a_length, const unsigned char *b, unsigned int b_length)
UNIV_INTERN ibool trx_is_interrupted(trx_t *trx)
static dict_index_t * innobase_index_lookup(INNOBASE_SHARE *share, uint keynr)
UNIV_INTERN void innobase_convert_from_table_id(const void *, char *to, const char *from, ulint len)
UNIV_INTERN int convert_error_code_to_mysql(int error, ulint flags, Session *session)
static int create_index(trx_t *trx, Table *form, ulint flags, const char *table_name, uint key_num)
static ibool innobase_match_index_columns(const KeyInfo *key_info, const dict_index_t *index_info)
static uint field_in_record_is_null(Table *table, Field *field, char *record)
static void build_template(row_prebuilt_t *prebuilt, Session *, Table *table, uint templ_type)
static void innobase_release_stat_resources(trx_t *trx)
Definition ha_innodb.cc:932
static void innobase_active_small(void)
static unsigned int innobase_get_mysql_key_number_for_index(INNOBASE_SHARE *share, const drizzled::Table *table, dict_table_t *ib_table, const dict_index_t *index)
UNIV_INTERN char * innobase_convert_name(char *buf, ulint buflen, const char *id, ulint idlen, drizzled::Session *session, ibool table_id)
UNIV_INTERN ibool thd_is_select(const drizzled::Session *session)
Definition ha_innodb.cc:970
UNIV_INTERN void innobase_get_cset_width(ulint cset, ulint *mbminlen, ulint *mbmaxlen)
UNIV_INTERN ibool trx_is_strict(trx_t *trx)
UNIV_INTERN void innobase_mysql_print_thd(FILE *f, drizzled::Session *in_session, uint)
static void set_field_in_record_to_null(Table *table, Field *field, char *record)
static int innobase_rename_table(trx_t *trx, const identifier::Table &from, const identifier::Table &to, ibool lock_and_commit)
static uint innobase_file_format_name_lookup(const char *format_name)
static void innodb_srv_conc_enter_innodb(trx_t *trx)
Definition ha_innodb.cc:896
static void innobase_write_to_2_little_endian(byte *buf, ulint val)
static int read_ahead_validate(Session *, set_var *var)
UNIV_INTERN int innobase_mysql_tmpfile(void)
UNIV_INTERN ibool thd_is_replication_slave_thread(drizzled::Session *)
Definition ha_innodb.cc:884
static char * innobase_convert_identifier(char *buf, ulint buflen, const char *id, ulint idlen, drizzled::Session *session, ibool file_id)
static int innobase_init(module::Context &context)
UNIV_INTERN void innobase_convert_from_id(const void *, char *to, const char *from, ulint len)
static ibool innobase_build_index_translation(const Table *table, dict_table_t *ib_table, INNOBASE_SHARE *share)
static const char * adaptive_flushing_method_names[]
Definition ha_innodb.cc:355
static uint64_t innobase_get_int_col_max_value(const Field *field)
UNIV_INTERN int innobase_strcasecmp(const char *a, const char *b)
static uint64_t innobase_next_autoinc(uint64_t current, uint64_t increment, uint64_t offset, uint64_t max_value)
UNIV_INTERN ulint innobase_raw_format(const char *data, ulint data_len, ulint, char *buf, ulint buf_size)
static const char * innobase_change_buffering_values[IBUF_USE_COUNT]
Definition ha_innodb.cc:326
static ulong commit_threads
Definition ha_innodb.cc:151
static int innodb_change_buffering_validate(Session *, set_var *var)
UNIV_INTERN ibool thd_supports_xa(drizzled::Session *)
Definition ha_innodb.cc:983
static boost::mutex innobase_share_mutex
Definition ha_innodb.cc:148
static uint get_field_offset(Table *table, Field *field)
static int create_clustered_index_when_no_primary(trx_t *trx, ulint flags, const char *table_name)
static const char * read_ahead_names[]
Definition ha_innodb.cc:336
static const char * innodb_stats_method_names[]
Definition ha_innodb.cc:302
const char * innobase_basename(const char *path_name)
static ulint innobase_map_isolation_level(enum_tx_isolation iso)
static int create_table_def(trx_t *trx, Table *form, const char *table_name, const char *path_of_temp_table, ulint flags)
#define HASH_INSERT(TYPE, NAME, TABLE, FOLD, DATA)
Definition hash0hash.h:101
#define HASH_SEARCH(NAME, TABLE, FOLD, TYPE, DATA, ASSERTION, TEST)
Definition hash0hash.h:176
#define HASH_DELETE(TYPE, NAME, TABLE, FOLD, DATA)
Definition hash0hash.h:137
ibuf_use_t
Definition ibuf0ibuf.h:53
UNIV_INTERN dict_table_t * lock_get_src_table(trx_t *trx, dict_table_t *dest, enum lock_mode *mode)
Definition lock0lock.cc:649
UNIV_INTERN ibool lock_is_table_exclusive(dict_table_t *table, trx_t *trx)
Definition lock0lock.cc:717
UNIV_INTERN void log_buffer_flush_to_disk(void)
Definition log0log.cc:1601
UNIV_INTERN void mem_analyze_corruption(void *ptr)
Definition mem0dbg.cc:822
UNIV_INTERN char * mem_heap_strdup(mem_heap_t *heap, const char *str)
Definition mem0mem.cc:104
#define mem_heap_create(N)
Definition mem0mem.h:91
#define mem_heap_free(heap)
Definition mem0mem.h:111
TODO: Rename this file - func.h is stupid.
DRIZZLED_API int tmpfile(const char *prefix)
Definition session.cc:121
An Proxy Wrapper around boost::program_options::variables_map.
UNIV_INTERN ibool os_file_set_eof(FILE *file)
Definition os0file.cc:2042
UNIV_INTERN ibool os_file_get_status(const char *path, os_file_stat_t *stat_info)
Definition os0file.cc:2962
ulint os_innodb_umask
Definition os0file.cc:71
UNIV_INLINE ulint page_get_free_space_of_empty(ulint comp) __attribute__((const))
UNIV_INTERN void read_view_close_for_mysql(trx_t *trx)
Definition read0read.cc:336
UNIV_INTERN ibool row_merge_is_index_usable(const trx_t *trx, const dict_index_t *index)
UNIV_INTERN int row_table_add_foreign_constraints(trx_t *trx, const char *sql_string, size_t sql_length, const char *name, ibool reject_fks)
UNIV_INTERN int row_import_tablespace_for_mysql(const char *name, trx_t *trx)
UNIV_INTERN const byte * row_mysql_read_true_varchar(ulint *len, const byte *field, ulint lenlen)
Definition row0mysql.cc:172
UNIV_INTERN int row_update_for_mysql(byte *mysql_rec, row_prebuilt_t *prebuilt)
UNIV_INTERN int row_discard_tablespace_for_mysql(const char *name, trx_t *trx)
UNIV_INTERN int row_create_table_for_mysql(dict_table_t *table, trx_t *trx)
UNIV_INTERN int row_lock_table_for_mysql(row_prebuilt_t *prebuilt, dict_table_t *table, ulint mode)
UNIV_INTERN const byte * row_mysql_read_blob_ref(ulint *len, const byte *ref, ulint col_len)
Definition row0mysql.cc:234
UNIV_INTERN void row_update_prebuilt_trx(row_prebuilt_t *prebuilt, trx_t *trx)
Definition row0mysql.cc:798
UNIV_INTERN int row_insert_for_mysql(byte *mysql_rec, row_prebuilt_t *prebuilt)
UNIV_INTERN void row_prebuilt_free(row_prebuilt_t *prebuilt, ibool dict_locked)
Definition row0mysql.cc:712
UNIV_INTERN ulint row_rename_table_for_mysql(const char *old_name, const char *new_name, trx_t *trx, ibool commit)
ibool row_rollback_on_timeout
Definition row0mysql.cc:58
UNIV_INTERN void row_unlock_table_autoinc_for_mysql(trx_t *trx)
Definition row0mysql.cc:928
UNIV_INTERN ibool row_table_got_default_clust_index(const dict_table_t *table)
UNIV_INTERN int row_lock_table_autoinc_for_mysql(row_prebuilt_t *prebuilt)
Definition row0mysql.cc:950
UNIV_INTERN row_prebuilt_t * row_create_prebuilt(dict_table_t *table)
Definition row0mysql.cc:650
UNIV_INTERN int row_drop_database_for_mysql(const char *name, trx_t *trx)
UNIV_INTERN int row_truncate_table_for_mysql(dict_table_t *table, trx_t *trx)
UNIV_INTERN byte * row_mysql_store_true_var_len(byte *dest, ulint len, ulint lenlen)
Definition row0mysql.cc:143
UNIV_INTERN ulint row_check_index_for_mysql(row_prebuilt_t *prebuilt, const dict_index_t *index, ulint *n_rows)
UNIV_INTERN int row_drop_table_for_mysql(const char *name, trx_t *trx, ibool drop_db)
UNIV_INTERN byte * row_mysql_store_col_in_innobase_format(dfield_t *dfield, byte *buf, ibool row_format_col, const byte *mysql_data, ulint col_len, ulint comp)
Definition row0mysql.cc:301
UNIV_INTERN upd_t * row_get_prebuilt_update_vector(row_prebuilt_t *prebuilt)
UNIV_INTERN int row_create_index_for_mysql(dict_index_t *index, trx_t *trx, const ulint *field_lengths)
UNIV_INTERN void row_mysql_unlock_data_dictionary(trx_t *trx)
UNIV_INTERN int row_unlock_for_mysql(row_prebuilt_t *prebuilt, ibool has_latches_on_recs)
UNIV_INTERN void row_mysql_prebuilt_free_blob_heap(row_prebuilt_t *prebuilt)
Definition row0mysql.cc:127
UNIV_INTERN ulint row_search_for_mysql(byte *buf, ulint mode, row_prebuilt_t *prebuilt, ulint match_mode, ulint direction)
Definition row0sel.cc:3346
@ ROW_SEL_PREV
Definition row0sel.h:386
@ ROW_SEL_NEXT
Definition row0sel.h:385
UNIV_INTERN void row_sel_convert_mysql_key_to_innobase(dtuple_t *tuple, byte *buf, ulint buf_len, dict_index_t *index, const byte *key_ptr, ulint key_len, trx_t *trx)
Definition row0sel.cc:2292
@ ROW_SEL_EXACT_PREFIX
Definition row0sel.h:392
@ ROW_SEL_EXACT
Definition row0sel.h:391
UNIV_INTERN ulint row_search_max_autoinc(dict_index_t *index, const char *col_name, ib_uint64_t *value)
Definition row0sel.cc:4844
ulint srv_buf_pool_size
Definition srv0srv.cc:253
UNIV_INTERN void srv_active_wake_master_thread(void)
Definition srv0srv.cc:2617
ibool srv_locks_unsafe_for_binlog
Definition srv0srv.cc:138
@ SRV_FORCE_NO_IBUF_MERGE
Definition srv0srv.h:445
static const std::string srv_mysql50_table_name_prefix("#mysql50#")
ulint srv_buf_pool_instances
Definition srv0srv.cc:255
my_bool srv_file_per_table
Definition srv0srv.cc:125
UNIV_INTERN void srv_conc_exit_innodb(trx_t *trx)
Definition srv0srv.cc:1455
uint32_t srv_auto_lru_dump
Definition srv0srv.cc:375
UNIV_INTERN void srv_export_innodb_status(void)
Definition srv0srv.cc:2061
ulint srv_file_format
Definition srv0srv.cc:127
UNIV_INTERN void srv_conc_force_exit_innodb(trx_t *trx)
Definition srv0srv.cc:1399
UNIV_INTERN void srv_conc_enter_innodb(trx_t *trx)
Definition srv0srv.cc:1213
ulint srv_max_file_format_at_startup
Definition srv0srv.cc:131
UNIV_INTERN ibool srv_printf_innodb_monitor(FILE *file, ibool nowait, ulint *trx_start, ulint *trx_end)
Definition srv0srv.cc:1869
export_struc export_vars
Definition srv0srv.cc:378
UNIV_INTERN void srv_free_paths_and_sizes(void)
Definition srv0start.cc:450
UNIV_INTERN int innobase_shutdown_for_mysql(void)
UNIV_INTERN ibool srv_parse_data_file_paths_and_sizes(char *str)
Definition srv0start.cc:195
UNIV_INTERN int innobase_start_or_create_for_mysql(void)
Definition srv0start.cc:971
UNIV_INTERN ibool srv_parse_log_group_home_dirs(char *str)
Definition srv0start.cc:379
enum TransformSqlError transformTableDefinitionToSql(const Table &table, string &destination, enum TransformSqlVariant sql_variant, bool with_schema)
dtype_t type
Definition data0data.h:438
unsigned prtype
Definition dict0mem.h:265
unsigned mtype
Definition dict0mem.h:264
dict_col_t * col
Definition dict0mem.h:312
char * referenced_table_name
Definition dict0mem.h:433
dict_index_t * referenced_index
Definition dict0mem.h:445
const char ** foreign_col_names
Definition dict0mem.h:431
const char ** referenced_col_names
Definition dict0mem.h:438
unsigned n_user_defined_cols
Definition dict0mem.h:345
const char * name
Definition dict0mem.h:331
unsigned n_fields
Definition dict0mem.h:353
dict_field_t * fields
Definition dict0mem.h:363
dict_col_t * cols
Definition dict0mem.h:498
ulint stat_clustered_index_size
Definition dict0mem.h:574
ib_int64_t stat_n_rows
Definition dict0mem.h:571
ulint stat_sum_of_other_index_sizes
Definition dict0mem.h:577
unsigned ibd_file_missing
Definition dict0mem.h:482
dict_index_t ** index_mapping
Definition ha_innodb.h:42
const char * cfile_name
Definition sync0sync.h:699
ulong count_os_wait
Definition sync0sync.h:708
mysql_row_templ_t * mysql_template
Definition row0mysql.h:639
unsigned templ_contains_blob
Definition row0mysql.h:633
dict_table_t * table
Definition row0mysql.h:592
unsigned template_type
Definition row0mysql.h:619
dict_index_t * index
Definition row0mysql.h:593
ibool keep_other_fields_on_keyread
Definition row0mysql.h:745
unsigned read_just_key
Definition row0mysql.h:613
unsigned null_bitmap_len
Definition row0mysql.h:625
ulint hint_need_to_fetch_extra_cols
Definition row0mysql.h:654
unsigned need_to_access_clustered
Definition row0mysql.h:628
unsigned cline
Definition sync0rw.h:625
const char * cfile_name
Definition sync0rw.h:614
ulint count_os_wait
Definition sync0rw.h:613
char table_name[FN_REFLEN]
Definition ha_innodb.h:51
innodb_idx_translate_t idx_trans_tbl
Definition ha_innodb.h:56
ibool log_commit_id
Definition trx0trx.h:720
unsigned support_xa
Definition trx0trx.h:496
drizzled::Session * mysql_thd
Definition trx0trx.h:559
char detailed_error[256]
Definition trx0trx.h:717
undo_no_t undo_no
Definition trx0trx.h:681
ulint n_autoinc_rows
Definition trx0trx.h:708
trx_id_t id
Definition trx0trx.h:548
ulint conc_state
Definition trx0trx.h:480
ulint duplicates
Definition trx0trx.h:513
unsigned field_no
Definition row0upd.h:371
unsigned orig_len
Definition row0upd.h:377
dfield_t new_val
Definition row0upd.h:385
que_node_t * exp
Definition row0upd.h:380
upd_field_t * fields
Definition row0upd.h:393
ulint info_bits
Definition row0upd.h:390
ulint n_fields
Definition row0upd.h:392
mutex_t mutex_list_mutex
Definition sync0sync.cc:218
ut_list_base_node_t mutex_list
Definition sync0sync.cc:215
#define mutex_t
Definition sync0types.h:31
UNIV_INTERN ulint trx_rollback_to_savepoint_for_mysql(trx_t *trx, const char *savepoint_name, ib_int64_t *mysql_binlog_cache_pos)
Definition trx0roll.cc:237
UNIV_INTERN ulint trx_release_savepoint_for_mysql(trx_t *trx, const char *savepoint_name)
Definition trx0roll.cc:359
UNIV_INTERN ulint trx_savepoint_for_mysql(trx_t *trx, const char *savepoint_name, ib_int64_t binlog_cache_pos)
Definition trx0roll.cc:302
UNIV_INTERN int trx_rollback_last_sql_stat_for_mysql(trx_t *trx)
Definition trx0roll.cc:158
UNIV_INTERN int trx_rollback_for_mysql(trx_t *trx)
Definition trx0roll.cc:129
UNIV_INTERN ibool trx_sys_file_format_max_set(ulint format_id, const char **name)
Definition trx0sys.cc:1102
UNIV_INLINE trx_id_t trx_sys_get_new_trx_id(void)
UNIV_INTERN const char * trx_sys_file_format_max_get(void)
Definition trx0sys.cc:1179
UNIV_INTERN const char * trx_sys_file_format_id_to_name(const ulint id)
Definition trx0sys.cc:1036
UNIV_INTERN ibool trx_sys_file_format_max_upgrade(const char **name, ulint format_id)
Definition trx0sys.cc:1151
UNIV_INTERN void trx_mark_sql_stat_end(trx_t *trx)
Definition trx0trx.cc:1672
UNIV_INLINE void trx_start_if_not_started(trx_t *trx)
UNIV_INTERN read_view_t * trx_assign_read_view(trx_t *trx)
Definition trx0trx.cc:1028
UNIV_INTERN void trx_search_latch_release_if_reserved(trx_t *trx)
Definition trx0trx.cc:244
UNIV_INTERN ulint trx_prepare_for_mysql(trx_t *trx)
Definition trx0trx.cc:1955
UNIV_INTERN trx_t * trx_allocate_for_mysql(void)
Definition trx0trx.cc:199
UNIV_INTERN int trx_recover_for_mysql(XID *xid_list, ulint len)
Definition trx0trx.cc:1986
UNIV_INTERN ulint trx_commit_for_mysql(trx_t *trx)
Definition trx0trx.cc:1596
UNIV_INTERN trx_t * trx_get_trx_by_xid(const XID *xid)
Definition trx0trx.cc:2056
UNIV_INTERN ulint trx_commit_complete_for_mysql(trx_t *trx)
Definition trx0trx.cc:1627
UNIV_INLINE const dict_index_t * trx_get_error_info(const trx_t *trx)
UNIV_INTERN void trx_free_for_mysql(trx_t *trx)
Definition trx0trx.cc:342
#define ut_error
Definition ut0dbg.h:115
#define ut_ad(EXPR)
Definition ut0dbg.h:127
#define ut_a(EXPR)
Definition ut0dbg.h:105
#define UT_NOT_USED(A)
Definition ut0dbg.h:134
#define UT_LIST_GET_LEN(BASE)
Definition ut0lst.h:216
#define UT_LIST_GET_FIRST(BASE)
Definition ut0lst.h:223
#define UT_LIST_GET_NEXT(NAME, N)
Definition ut0lst.h:200
UNIV_INLINE int ut_strcmp(const char *str1, const char *str2)
UNIV_INLINE ulint ut_str_sql_format(const char *str, ulint str_len, char *buf, ulint buf_size)
UNIV_INLINE ulint ut_fold_string(const char *str) __attribute__((pure))
UNIV_INTERN void ut_print_buf(FILE *file, const void *buf, ulint len)
Definition ut0ut.cc:436
#define TEMP_INDEX_PREFIX
Definition ut0ut.h:51
UNIV_INTERN void ut_print_timestamp(FILE *file)
Definition ut0ut.cc:239
UNIV_INTERN void ut_print_name(FILE *f, struct trx_struct *trx, ibool table_id, const char *name)
Definition ut0ut.cc:520