22
22
Place, Suite 330, Boston, MA 02111-1307 USA
24
24
*****************************************************************************/
25
/***********************************************************************
27
Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
28
Copyright (c) 2009, Percona Inc.
30
Portions of this file contain modifications contributed and copyrighted
31
by Percona Inc.. Those modifications are
32
gratefully acknowledged and are described briefly in the InnoDB
33
documentation. The contributions by Percona Inc. are incorporated with
34
their permission, and subject to the conditions contained in the file
37
This program is free software; you can redistribute it and/or modify it
38
under the terms of the GNU General Public License as published by the
39
Free Software Foundation; version 2 of the License.
41
This program is distributed in the hope that it will be useful, but
42
WITHOUT ANY WARRANTY; without even the implied warranty of
43
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
44
Public License for more details.
46
You should have received a copy of the GNU General Public License along
47
with this program; if not, write to the Free Software Foundation, Inc.,
48
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
50
***********************************************************************/
26
52
/* TODO list for the InnoDB handler in 5.0:
27
53
- Remove the flag trx->active_trans and look at trx->conc_state
41
67
#include <mysys_err.h>
42
68
#include <mysql/plugin.h>
70
/** @file ha_innodb.cc */
44
72
/* Include necessary InnoDB headers */
46
#include "../storage/innobase/include/univ.i"
47
#include "../storage/innobase/include/btr0sea.h"
48
#include "../storage/innobase/include/os0file.h"
49
#include "../storage/innobase/include/os0thread.h"
50
#include "../storage/innobase/include/srv0start.h"
51
#include "../storage/innobase/include/srv0srv.h"
52
#include "../storage/innobase/include/trx0roll.h"
53
#include "../storage/innobase/include/trx0trx.h"
54
#include "../storage/innobase/include/trx0sys.h"
55
#include "../storage/innobase/include/mtr0mtr.h"
56
#include "../storage/innobase/include/row0ins.h"
57
#include "../storage/innobase/include/row0mysql.h"
58
#include "../storage/innobase/include/row0sel.h"
59
#include "../storage/innobase/include/row0upd.h"
60
#include "../storage/innobase/include/log0log.h"
61
#include "../storage/innobase/include/lock0lock.h"
62
#include "../storage/innobase/include/dict0crea.h"
63
#include "../storage/innobase/include/btr0cur.h"
64
#include "../storage/innobase/include/btr0btr.h"
65
#include "../storage/innobase/include/fsp0fsp.h"
66
#include "../storage/innobase/include/sync0sync.h"
67
#include "../storage/innobase/include/fil0fil.h"
68
#include "../storage/innobase/include/trx0xa.h"
69
#include "../storage/innobase/include/row0merge.h"
70
#include "../storage/innobase/include/thr0loc.h"
71
#include "../storage/innobase/include/dict0boot.h"
72
#include "../storage/innobase/include/ha_prototypes.h"
73
#include "../storage/innobase/include/ut0mem.h"
74
#include "../storage/innobase/include/ibuf0ibuf.h"
77
#include "os0thread.h"
78
#include "srv0start.h"
85
#include "row0mysql.h"
89
#include "lock0lock.h"
90
#include "dict0crea.h"
94
#include "sync0sync.h"
97
#include "row0merge.h"
99
#include "dict0boot.h"
100
#include "ha_prototypes.h"
102
#include "ibuf0ibuf.h"
77
105
#include "ha_innodb.h"
112
140
# define EQ_CURRENT_THD(thd) ((thd) == current_thd)
113
141
#endif /* MYSQL_DYNAMIC_PLUGIN && __WIN__ */
115
#ifdef MYSQL_DYNAMIC_PLUGIN
116
/* These must be weak global variables in the dynamic plugin. */
117
struct handlerton* innodb_hton_ptr;
119
struct st_mysql_plugin* builtin_innobase_plugin_ptr;
121
int builtin_innobase_plugin;
123
/********************************************************************
124
Copy InnoDB system variables from the static InnoDB to the dynamic
128
innodb_plugin_init(void);
129
/*====================*/
130
/* out: TRUE if the dynamic InnoDB plugin should start */
131
#else /* MYSQL_DYNAMIC_PLUGIN */
132
/* This must be a global variable in the statically linked InnoDB. */
133
struct handlerton* innodb_hton_ptr = NULL;
134
#endif /* MYSQL_DYNAMIC_PLUGIN */
143
static struct handlerton* innodb_hton_ptr;
136
145
static const long AUTOINC_OLD_STYLE_LOCKING = 0;
137
146
static const long AUTOINC_NEW_STYLE_LOCKING = 1;
216
228
TABLE_SHARE *table,
217
229
MEM_ROOT *mem_root);
219
/****************************************************************
220
Validate the file format name and return its corresponding id. */
231
/** @brief Initialize the default value of innodb_commit_concurrency.
233
Once InnoDB is running, the innodb_commit_concurrency must not change
234
from zero to nonzero. (Bug #42101)
236
The initial default value is 0, and without this extra initialization,
237
SET GLOBAL innodb_commit_concurrency=DEFAULT would set the parameter
238
to 0, even if it was initially set to nonzero at the command line
239
or configuration file. */
242
innobase_commit_concurrency_init_default(void);
243
/*==========================================*/
245
/************************************************************//**
246
Validate the file format name and return its corresponding id.
247
@return valid file format id */
223
250
innobase_file_format_name_lookup(
224
251
/*=============================*/
225
/* out: valid file format id */
226
const char* format_name); /* in: pointer to file format
252
const char* format_name); /*!< in: pointer to file format
228
/****************************************************************
254
/************************************************************//**
229
255
Validate the file format check config parameters, as a side effect it
230
sets the srv_check_file_format_at_startup variable. */
256
sets the srv_check_file_format_at_startup variable.
257
@return true if one of "on" or "off" */
233
260
innobase_file_format_check_on_off(
234
261
/*==============================*/
235
/* out: true if one of
237
const char* format_check); /* in: parameter value */
238
/****************************************************************
262
const char* format_check); /*!< in: parameter value */
263
/************************************************************//**
239
264
Validate the file format check config parameters, as a side effect it
240
sets the srv_check_file_format_at_startup variable. */
265
sets the srv_check_file_format_at_startup variable.
266
@return true if valid config value */
243
269
innobase_file_format_check_validate(
244
270
/*================================*/
245
/* out: true if valid
247
const char* format_check); /* in: parameter value */
248
/********************************************************************
271
const char* format_check); /*!< in: parameter value */
272
/****************************************************************//**
249
273
Return alter table flags supported in an InnoDB database. */
256
280
static const char innobase_hton_name[]= "InnoDB";
282
/*************************************************************//**
283
Check for a valid value of innobase_commit_concurrency.
284
@return 0 for valid innodb_commit_concurrency */
287
innobase_commit_concurrency_validate(
288
/*=================================*/
289
THD* thd, /*!< in: thread handle */
290
struct st_mysql_sys_var* var, /*!< in: pointer to system
292
void* save, /*!< out: immediate result
293
for update function */
294
struct st_mysql_value* value) /*!< in: incoming string */
297
ulong commit_concurrency;
299
DBUG_ENTER("innobase_commit_concurrency_validate");
301
if (value->val_int(value, &intbuf)) {
302
/* The value is NULL. That is invalid. */
306
*reinterpret_cast<ulong*>(save) = commit_concurrency
307
= static_cast<ulong>(intbuf);
309
/* Allow the value to be updated, as long as it remains zero
311
DBUG_RETURN(!(!commit_concurrency == !innobase_commit_concurrency));
258
314
static MYSQL_THDVAR_BOOL(support_xa, PLUGIN_VAR_OPCMDARG,
259
315
"Enable InnoDB support for the XA two-phase commit",
260
316
/* check_func */ NULL, /* update_func */ NULL,
281
337
return new (mem_root) ha_innobase(hton, table);
284
/***********************************************************************
285
This function is used to prepare X/Open XA distributed transaction */
340
/*******************************************************************//**
341
This function is used to prepare an X/Open XA distributed transaction.
342
@return 0 or error number */
288
345
innobase_xa_prepare(
289
346
/*================*/
290
/* out: 0 or error number */
292
THD* thd, /* in: handle to the MySQL thread of the user
293
whose XA transaction should be prepared */
294
bool all); /* in: TRUE - commit transaction
295
FALSE - the current SQL statement ended */
296
/***********************************************************************
297
This function is used to recover X/Open XA distributed transactions */
347
handlerton* hton, /*!< in: InnoDB handlerton */
348
THD* thd, /*!< in: handle to the MySQL thread of
349
the user whose XA transaction should
351
bool all); /*!< in: TRUE - commit transaction
352
FALSE - the current SQL statement
354
/*******************************************************************//**
355
This function is used to recover X/Open XA distributed transactions.
356
@return number of prepared transactions stored in xid_list */
300
359
innobase_xa_recover(
301
360
/*================*/
302
/* out: number of prepared transactions
303
stored in xid_list */
305
XID* xid_list, /* in/out: prepared transactions */
306
uint len); /* in: number of slots in xid_list */
307
/***********************************************************************
361
handlerton* hton, /*!< in: InnoDB handlerton */
362
XID* xid_list,/*!< in/out: prepared transactions */
363
uint len); /*!< in: number of slots in xid_list */
364
/*******************************************************************//**
308
365
This function is used to commit one X/Open XA distributed transaction
309
which is in the prepared state */
366
which is in the prepared state
367
@return 0 or error number */
312
370
innobase_commit_by_xid(
313
371
/*===================*/
314
/* out: 0 or error number */
315
372
handlerton* hton,
316
XID* xid); /* in: X/Open XA transaction identification */
317
/***********************************************************************
373
XID* xid); /*!< in: X/Open XA transaction identification */
374
/*******************************************************************//**
318
375
This function is used to rollback one X/Open XA distributed transaction
319
which is in the prepared state */
376
which is in the prepared state
377
@return 0 or error number */
322
380
innobase_rollback_by_xid(
323
381
/*=====================*/
324
/* out: 0 or error number */
326
XID *xid); /* in: X/Open XA transaction identification */
327
/***********************************************************************
382
handlerton* hton, /*!< in: InnoDB handlerton */
383
XID* xid); /*!< in: X/Open XA transaction
385
/*******************************************************************//**
328
386
Create a consistent view for a cursor based on current transaction
329
387
which is created if the corresponding MySQL thread still lacks one.
330
388
This consistent view is then used inside of MySQL when accessing records
390
@return pointer to cursor view or NULL */
334
393
innobase_create_cursor_view(
335
394
/*========================*/
336
/* out: pointer to cursor view or NULL */
337
handlerton* hton, /* in: innobase hton */
338
THD* thd); /* in: user thread handle */
339
/***********************************************************************
395
handlerton* hton, /*!< in: innobase hton */
396
THD* thd); /*!< in: user thread handle */
397
/*******************************************************************//**
340
398
Set the given consistent cursor view to a transaction which is created
341
399
if the corresponding MySQL thread still lacks one. If the given
342
400
consistent cursor view is NULL global read view of a transaction is
357
415
innobase_close_cursor_view(
358
416
/*=======================*/
359
417
handlerton* hton,
360
THD* thd, /* in: user thread handle */
361
void* curview);/* in: Consistent read view to be closed */
362
/*********************************************************************
418
THD* thd, /*!< in: user thread handle */
419
void* curview);/*!< in: Consistent read view to be closed */
420
/*****************************************************************//**
363
421
Removes all tables in the named database inside InnoDB. */
366
424
innobase_drop_database(
367
425
/*===================*/
368
/* out: error number */
369
handlerton* hton, /* in: handlerton of Innodb */
370
char* path); /* in: database path; inside InnoDB the name
426
handlerton* hton, /*!< in: handlerton of Innodb */
427
char* path); /*!< in: database path; inside InnoDB the name
371
428
of the last directory in the path is used as
372
429
the database name: for example, in 'mysql/data/test'
373
430
the database name is 'test' */
374
/***********************************************************************
431
/*******************************************************************//**
375
432
Closes an InnoDB database. */
378
435
innobase_end(handlerton *hton, ha_panic_function type);
380
/*********************************************************************
437
/*****************************************************************//**
381
438
Creates an InnoDB transaction struct for the thd if it does not yet have one.
382
439
Starts a new InnoDB transaction if a transaction is not yet started. And
383
440
assigns a new snapshot for a consistent read if the transaction does not yet
387
445
innobase_start_trx_and_assign_read_view(
388
446
/*====================================*/
390
handlerton* hton, /* in: Innodb handlerton */
391
THD* thd); /* in: MySQL thread handle of the user for whom
447
handlerton* hton, /*!< in: Innodb handlerton */
448
THD* thd); /*!< in: MySQL thread handle of the user for whom
392
449
the transaction should be committed */
393
/********************************************************************
450
/****************************************************************//**
394
451
Flushes InnoDB logs to disk and makes a checkpoint. Really, a commit flushes
395
the logs, and the name of this function should be innobase_checkpoint. */
452
the logs, and the name of this function should be innobase_checkpoint.
453
@return TRUE if error */
398
456
innobase_flush_logs(
399
457
/*================*/
400
/* out: TRUE if error */
401
handlerton* hton); /* in: InnoDB handlerton */
458
handlerton* hton); /*!< in: InnoDB handlerton */
403
/****************************************************************************
460
/************************************************************************//**
404
461
Implements the SHOW INNODB STATUS command. Sends the output of the InnoDB
405
462
Monitor to the client. */
408
465
innodb_show_status(
409
466
/*===============*/
410
handlerton* hton, /* in: the innodb handlerton */
411
THD* thd, /* in: the MySQL query thread of the caller */
467
handlerton* hton, /*!< in: the innodb handlerton */
468
THD* thd, /*!< in: the MySQL query thread of the caller */
412
469
stat_print_fn *stat_print);
414
471
bool innobase_show_status(handlerton *hton, THD* thd,
415
472
stat_print_fn* stat_print,
416
473
enum ha_stat_type stat_type);
418
/*********************************************************************
475
/*****************************************************************//**
419
476
Commits a transaction in an InnoDB database. */
422
479
innobase_commit_low(
423
480
/*================*/
424
trx_t* trx); /* in: transaction handle */
481
trx_t* trx); /*!< in: transaction handle */
426
483
static SHOW_VAR innodb_status_variables[]= {
427
484
{"buffer_pool_pages_data",
520
577
/* General functions */
522
/**********************************************************************
579
/******************************************************************//**
523
580
Returns true if the thread is the replication thread on the slave
524
581
server. Used in srv_conc_enter_innodb() to determine if the thread
525
582
should be allowed to enter InnoDB - the replication thread is treated
526
583
differently than other threads. Also used in
527
srv_conc_force_exit_innodb(). */
584
srv_conc_force_exit_innodb().
585
@return true if thd is the replication thread */
528
586
extern "C" UNIV_INTERN
530
588
thd_is_replication_slave_thread(
531
589
/*============================*/
532
/* out: true if thd is the replication thread */
533
void* thd) /* in: thread handle (THD*) */
590
void* thd) /*!< in: thread handle (THD*) */
535
592
return((ibool) thd_slave_thread((THD*) thd));
538
/**********************************************************************
595
/******************************************************************//**
539
596
Save some CPU by testing the value of srv_thread_concurrency in inline
543
600
innodb_srv_conc_enter_innodb(
544
601
/*=========================*/
545
trx_t* trx) /* in: transaction handle */
602
trx_t* trx) /*!< in: transaction handle */
547
604
if (UNIV_LIKELY(!srv_thread_concurrency)) {
594
/**********************************************************************
651
/******************************************************************//**
595
652
Returns true if the transaction this thread is processing has edited
596
653
non-transactional tables. Used by the deadlock detector when deciding
597
654
which transaction to rollback in case of a deadlock - we try to avoid
598
rolling back transactions that have edited non-transactional tables. */
655
rolling back transactions that have edited non-transactional tables.
656
@return true if non-transactional tables have been edited */
599
657
extern "C" UNIV_INTERN
601
659
thd_has_edited_nontrans_tables(
602
660
/*===========================*/
603
/* out: true if non-transactional tables have
605
void* thd) /* in: thread handle (THD*) */
661
void* thd) /*!< in: thread handle (THD*) */
607
663
return((ibool) thd_non_transactional_update((THD*) thd));
610
/**********************************************************************
611
Returns true if the thread is executing a SELECT statement. */
666
/******************************************************************//**
667
Returns true if the thread is executing a SELECT statement.
668
@return true if thd is executing SELECT */
612
669
extern "C" UNIV_INTERN
616
/* out: true if thd is executing SELECT */
617
const void* thd) /* in: thread handle (THD*) */
673
const void* thd) /*!< in: thread handle (THD*) */
619
675
return(thd_sql_command((const THD*) thd) == SQLCOM_SELECT);
622
/**********************************************************************
678
/******************************************************************//**
623
679
Returns true if the thread supports XA,
624
global value of innodb_supports_xa if thd is NULL. */
680
global value of innodb_supports_xa if thd is NULL.
681
@return true if thd has XA support */
625
682
extern "C" UNIV_INTERN
629
/* out: true if thd has XA support */
630
void* thd) /* in: thread handle (THD*), or NULL to query
686
void* thd) /*!< in: thread handle (THD*), or NULL to query
631
687
the global innodb_supports_xa */
633
689
return(THDVAR((THD*) thd, support_xa));
636
/**********************************************************************
637
Returns the lock wait timeout for the current connection. */
692
/******************************************************************//**
693
Returns the lock wait timeout for the current connection.
694
@return the lock wait timeout, in seconds */
638
695
extern "C" UNIV_INTERN
640
697
thd_lock_wait_timeout(
641
698
/*==================*/
642
/* out: the lock wait timeout, in seconds */
643
void* thd) /* in: thread handle (THD*), or NULL to query
699
void* thd) /*!< in: thread handle (THD*), or NULL to query
644
700
the global innodb_lock_wait_timeout */
646
702
/* According to <mysql/plugin.h>, passing thd == NULL
648
704
return(THDVAR((THD*) thd, lock_wait_timeout));
651
/************************************************************************
652
Obtain the InnoDB transaction of a MySQL thread. */
707
/********************************************************************//**
708
Obtain the InnoDB transaction of a MySQL thread.
709
@return reference to transaction pointer */
657
/* out: reference to transaction pointer */
658
THD* thd) /* in: MySQL thread */
714
THD* thd) /*!< in: MySQL thread */
660
716
return(*(trx_t**) thd_ha_data(thd, innodb_hton_ptr));
663
/************************************************************************
719
/********************************************************************//**
664
720
Call this function when mysqld passes control to the client. That is to
665
721
avoid deadlocks on the adaptive hash S-latch possibly held by thd. For more
666
documentation, see handler.cc. */
722
documentation, see handler.cc.
669
726
innobase_release_temporary_latches(
670
727
/*===============================*/
672
handlerton* hton, /* in: handlerton */
673
THD* thd) /* in: MySQL thread */
728
handlerton* hton, /*!< in: handlerton */
729
THD* thd) /*!< in: MySQL thread */
709
/************************************************************************
765
/********************************************************************//**
710
766
Converts an InnoDB error code to a MySQL error code and also tells to MySQL
711
767
about a possible transaction rollback inside InnoDB caused by a lock wait
712
timeout or a deadlock. */
768
timeout or a deadlock.
769
@return MySQL error code */
713
770
extern "C" UNIV_INTERN
715
772
convert_error_code_to_mysql(
716
773
/*========================*/
717
/* out: MySQL error code */
718
int error, /* in: InnoDB error code */
719
ulint flags, /* in: InnoDB table flags, or 0 */
720
THD* thd) /* in: user thread handle or NULL */
774
int error, /*!< in: InnoDB error code */
775
ulint flags, /*!< in: InnoDB table flags, or 0 */
776
THD* thd) /*!< in: user thread handle or NULL */
857
916
VOID(pthread_mutex_unlock(&LOCK_thread_count));
860
/*****************************************************************
919
/*************************************************************//**
861
920
Prints info of a THD object (== user session thread) to the given file. */
862
921
extern "C" UNIV_INTERN
864
923
innobase_mysql_print_thd(
865
924
/*=====================*/
866
FILE* f, /* in: output stream */
867
void* thd, /* in: pointer to a MySQL THD object */
868
uint max_query_len) /* in: max query length to print, or 0 to
925
FILE* f, /*!< in: output stream */
926
void* thd, /*!< in: pointer to a MySQL THD object */
927
uint max_query_len) /*!< in: max query length to print, or 0 to
869
928
use the default max length */
871
930
char buffer[1024];
903
/**********************************************************************
962
/******************************************************************//**
904
963
Converts an identifier to a table name. */
905
964
extern "C" UNIV_INTERN
907
966
innobase_convert_from_table_id(
908
967
/*===========================*/
909
struct charset_info_st* cs, /* in: the 'from' character set */
910
char* to, /* out: converted identifier */
911
const char* from, /* in: identifier to convert */
912
ulint len) /* in: length of 'to', in bytes */
968
struct charset_info_st* cs, /*!< in: the 'from' character set */
969
char* to, /*!< out: converted identifier */
970
const char* from, /*!< in: identifier to convert */
971
ulint len) /*!< in: length of 'to', in bytes */
916
975
strconvert(cs, from, &my_charset_filename, to, (uint) len, &errors);
919
/**********************************************************************
978
/******************************************************************//**
920
979
Converts an identifier to UTF-8. */
921
980
extern "C" UNIV_INTERN
923
982
innobase_convert_from_id(
924
983
/*=====================*/
925
struct charset_info_st* cs, /* in: the 'from' character set */
926
char* to, /* out: converted identifier */
927
const char* from, /* in: identifier to convert */
928
ulint len) /* in: length of 'to', in bytes */
984
struct charset_info_st* cs, /*!< in: the 'from' character set */
985
char* to, /*!< out: converted identifier */
986
const char* from, /*!< in: identifier to convert */
987
ulint len) /*!< in: length of 'to', in bytes */
932
991
strconvert(cs, from, system_charset_info, to, (uint) len, &errors);
935
/**********************************************************************
936
Compares NUL-terminated UTF-8 strings case insensitively. */
994
/******************************************************************//**
995
Compares NUL-terminated UTF-8 strings case insensitively.
996
@return 0 if a=b, <0 if a<b, >1 if a>b */
937
997
extern "C" UNIV_INTERN
939
999
innobase_strcasecmp(
940
1000
/*================*/
941
/* out: 0 if a=b, <0 if a<b, >1 if a>b */
942
const char* a, /* in: first string to compare */
943
const char* b) /* in: second string to compare */
1001
const char* a, /*!< in: first string to compare */
1002
const char* b) /*!< in: second string to compare */
945
1004
return(my_strcasecmp(system_charset_info, a, b));
948
/**********************************************************************
1007
/******************************************************************//**
949
1008
Makes all characters in a NUL-terminated UTF-8 string lower case. */
950
1009
extern "C" UNIV_INTERN
952
1011
innobase_casedn_str(
953
1012
/*================*/
954
char* a) /* in/out: string to put in lower case */
1013
char* a) /*!< in/out: string to put in lower case */
956
1015
my_casedn_str(system_charset_info, a);
959
/**************************************************************************
960
Determines the connection character set. */
1018
/**********************************************************************//**
1019
Determines the connection character set.
1020
@return connection character set */
961
1021
extern "C" UNIV_INTERN
962
1022
struct charset_info_st*
963
1023
innobase_get_charset(
964
1024
/*=================*/
965
/* out: connection character set */
966
void* mysql_thd) /* in: MySQL thread handle */
1025
void* mysql_thd) /*!< in: MySQL thread handle */
968
1027
return(thd_charset((THD*) mysql_thd));
971
1030
#if defined (__WIN__) && defined (MYSQL_DYNAMIC_PLUGIN)
972
/***********************************************************************
1031
/*******************************************************************//**
973
1032
Map an OS error to an errno value. The OS error number is stored in
974
1033
_doserrno and the mapped value is stored in errno) */
978
unsigned long); /* in: OS error value */
1037
unsigned long); /*!< in: OS error value */
980
/*************************************************************************
981
Creates a temporary file. */
1039
/*********************************************************************//**
1040
Creates a temporary file.
1041
@return temporary file descriptor, or < 0 on error */
982
1042
extern "C" UNIV_INTERN
984
1044
innobase_mysql_tmpfile(void)
985
1045
/*========================*/
986
/* out: temporary file descriptor, or < 0 on error */
988
1047
int fd; /* handle of opened file */
989
1048
HANDLE osfh; /* OS handle of opened file */
1095
1154
#endif /* defined (__WIN__) && defined (MYSQL_DYNAMIC_PLUGIN) */
1097
/*************************************************************************
1098
Wrapper around MySQL's copy_and_convert function, see it for
1156
/*********************************************************************//**
1157
Wrapper around MySQL's copy_and_convert function.
1158
@return number of bytes copied to 'to' */
1100
1159
extern "C" UNIV_INTERN
1102
1161
innobase_convert_string(
1103
1162
/*====================*/
1106
CHARSET_INFO* to_cs,
1109
CHARSET_INFO* from_cs,
1163
void* to, /*!< out: converted string */
1164
ulint to_length, /*!< in: number of bytes reserved
1165
for the converted string */
1166
CHARSET_INFO* to_cs, /*!< in: character set to convert to */
1167
const void* from, /*!< in: string to convert */
1168
ulint from_length, /*!< in: number of bytes to convert */
1169
CHARSET_INFO* from_cs, /*!< in: character set to convert from */
1170
uint* errors) /*!< out: number of errors encountered
1171
during the conversion */
1112
1173
return(copy_and_convert((char*)to, (uint32) to_length, to_cs,
1113
1174
(const char*)from, (uint32) from_length, from_cs,
1117
/***********************************************************************
1178
/*******************************************************************//**
1118
1179
Formats the raw data in "data" (in InnoDB on-disk format) that is of
1119
1180
type DATA_(CHAR|VARCHAR|MYSQL|VARMYSQL) using "charset_coll" and writes
1120
1181
the result to "buf". The result is converted to "system_charset_info".
1121
1182
Not more than "buf_size" bytes are written to "buf".
1122
The result is always '\0'-terminated (provided buf_size > 0) and the
1183
The result is always NUL-terminated (provided buf_size > 0) and the
1123
1184
number of bytes that were written to "buf" is returned (including the
1124
terminating '\0'). */
1186
@return number of bytes that were written */
1125
1187
extern "C" UNIV_INTERN
1127
1189
innobase_raw_format(
1128
1190
/*================*/
1129
/* out: number of bytes
1130
that were written */
1131
const char* data, /* in: raw data */
1132
ulint data_len, /* in: raw data length
1191
const char* data, /*!< in: raw data */
1192
ulint data_len, /*!< in: raw data length
1134
ulint charset_coll, /* in: charset collation */
1135
char* buf, /* out: output buffer */
1136
ulint buf_size) /* in: output buffer size
1194
ulint charset_coll, /*!< in: charset collation */
1195
char* buf, /*!< out: output buffer */
1196
ulint buf_size) /*!< in: output buffer size
1139
1199
/* XXX we use a hard limit instead of allocating
1170
1230
innobase_next_autoinc() will be called with increment set to
1171
1231
n * 3 where autoinc_lock_mode != TRADITIONAL because we want
1172
to reserve 3 values for the multi-value INSERT above. */
1232
to reserve 3 values for the multi-value INSERT above.
1233
@return the next value */
1175
1236
innobase_next_autoinc(
1176
1237
/*==================*/
1177
/* out: the next value */
1178
ulonglong current, /* in: Current value */
1179
ulonglong increment, /* in: increment current by */
1180
ulonglong offset, /* in: AUTOINC offset */
1181
ulonglong max_value) /* in: max value for type */
1238
ulonglong current, /*!< in: Current value */
1239
ulonglong increment, /*!< in: increment current by */
1240
ulonglong offset, /*!< in: AUTOINC offset */
1241
ulonglong max_value) /*!< in: max value for type */
1183
1243
ulonglong next_value;
1382
1442
innobase_register_stmt(
1383
1443
/*===================*/
1384
handlerton* hton, /* in: Innobase hton */
1385
THD* thd) /* in: MySQL thd (connection) object */
1444
handlerton* hton, /*!< in: Innobase hton */
1445
THD* thd) /*!< in: MySQL thd (connection) object */
1387
1447
DBUG_ASSERT(hton == innodb_hton_ptr);
1388
1448
/* Register the statement */
1389
1449
trans_register_ha(thd, FALSE, hton);
1392
/*************************************************************************
1452
/*********************************************************************//**
1393
1453
Registers an InnoDB transaction in MySQL, so that the MySQL XA code knows
1394
1454
to call the InnoDB prepare and commit, or rollback for the transaction. This
1395
1455
MUST be called for every transaction for which the user may call commit or
1475
1535
holding any InnoDB semaphores. The calling thread is holding the
1476
1536
query cache mutex, and this function will reserver the InnoDB kernel mutex.
1477
1537
Thus, the 'rank' in sync0sync.h of the MySQL query cache mutex is above
1478
the InnoDB kernel mutex. */
1538
the InnoDB kernel mutex.
1539
@return TRUE if permitted, FALSE if not; note that the value FALSE
1540
does not mean we should invalidate the query cache: invalidation is
1541
called explicitly */
1481
1544
innobase_query_caching_of_table_permitted(
1482
1545
/*======================================*/
1483
/* out: TRUE if permitted, FALSE if not;
1484
note that the value FALSE does not mean
1485
we should invalidate the query cache:
1486
invalidation is called explicitly */
1487
THD* thd, /* in: thd of the user who is trying to
1546
THD* thd, /*!< in: thd of the user who is trying to
1488
1547
store a result to the query cache or
1490
char* full_name, /* in: concatenation of database name,
1491
the null character '\0', and the table
1549
char* full_name, /*!< in: concatenation of database name,
1550
the null character NUL, and the table
1493
uint full_name_len, /* in: length of the full name, i.e.
1552
uint full_name_len, /*!< in: length of the full name, i.e.
1494
1553
len(dbname) + len(tablename) + 1 */
1495
ulonglong *unused) /* unused for this engine */
1554
ulonglong *unused) /*!< unused for this engine */
1497
1556
ibool is_autocommit;
1582
1641
return((my_bool)FALSE);
1585
/*********************************************************************
1586
Invalidates the MySQL query cache for the table.
1587
NOTE that the exact prototype of this function has to be in
1588
/innobase/row/row0ins.c! */
1644
/*****************************************************************//**
1645
Invalidates the MySQL query cache for the table. */
1589
1646
extern "C" UNIV_INTERN
1591
1648
innobase_invalidate_query_cache(
1592
1649
/*============================*/
1593
trx_t* trx, /* in: transaction which modifies the table */
1594
char* full_name, /* in: concatenation of database name, null
1595
char '\0', table name, null char'\0';
1596
NOTE that in Windows this is always
1598
ulint full_name_len) /* in: full name length where also the null
1650
trx_t* trx, /*!< in: transaction which
1651
modifies the table */
1652
const char* full_name, /*!< in: concatenation of
1653
database name, null char NUL,
1654
table name, null char NUL;
1655
NOTE that in Windows this is
1656
always in LOWER CASE! */
1657
ulint full_name_len) /*!< in: full name length where
1658
also the null chars count */
1601
1660
/* Note that the sync0sync.h rank of the query cache mutex is just
1602
1661
above the InnoDB kernel mutex. The caller of this function must not
1605
1664
/* Argument TRUE below means we are using transactions */
1606
1665
#ifdef HAVE_QUERY_CACHE
1607
1666
mysql_query_cache_invalidate4((THD*) trx->mysql_thd,
1608
(const char*) full_name,
1609
1668
(uint32) full_name_len,
1614
/*********************************************************************
1673
/*****************************************************************//**
1615
1674
Convert an SQL identifier to the MySQL system_charset_info (UTF-8)
1616
and quote it if needed. */
1675
and quote it if needed.
1676
@return pointer to the end of buf */
1619
1679
innobase_convert_identifier(
1620
1680
/*========================*/
1621
/* out: pointer to the end of buf */
1622
char* buf, /* out: buffer for converted identifier */
1623
ulint buflen, /* in: length of buf, in bytes */
1624
const char* id, /* in: identifier to convert */
1625
ulint idlen, /* in: length of id, in bytes */
1626
void* thd, /* in: MySQL connection thread, or NULL */
1627
ibool file_id)/* in: TRUE=id is a table or database name;
1681
char* buf, /*!< out: buffer for converted identifier */
1682
ulint buflen, /*!< in: length of buf, in bytes */
1683
const char* id, /*!< in: identifier to convert */
1684
ulint idlen, /*!< in: length of id, in bytes */
1685
void* thd, /*!< in: MySQL connection thread, or NULL */
1686
ibool file_id)/*!< in: TRUE=id is a table or database name;
1628
1687
FALSE=id is an UTF-8 string */
1630
1689
char nz[NAME_LEN + 1];
1699
/*********************************************************************
1758
/*****************************************************************//**
1700
1759
Convert a table or index name to the MySQL system_charset_info (UTF-8)
1701
and quote it if needed. */
1760
and quote it if needed.
1761
@return pointer to the end of buf */
1702
1762
extern "C" UNIV_INTERN
1704
1764
innobase_convert_name(
1705
1765
/*==================*/
1706
/* out: pointer to the end of buf */
1707
char* buf, /* out: buffer for converted identifier */
1708
ulint buflen, /* in: length of buf, in bytes */
1709
const char* id, /* in: identifier to convert */
1710
ulint idlen, /* in: length of id, in bytes */
1711
void* thd, /* in: MySQL connection thread, or NULL */
1712
ibool table_id)/* in: TRUE=id is a table or database name;
1766
char* buf, /*!< out: buffer for converted identifier */
1767
ulint buflen, /*!< in: length of buf, in bytes */
1768
const char* id, /*!< in: identifier to convert */
1769
ulint idlen, /*!< in: length of id, in bytes */
1770
void* thd, /*!< in: MySQL connection thread, or NULL */
1771
ibool table_id)/*!< in: TRUE=id is a table or database name;
1713
1772
FALSE=id is an index name */
1756
/**************************************************************************
1757
Determines if the currently running transaction has been interrupted. */
1815
/**********************************************************************//**
1816
Determines if the currently running transaction has been interrupted.
1817
@return TRUE if interrupted */
1758
1818
extern "C" UNIV_INTERN
1760
1820
trx_is_interrupted(
1761
1821
/*===============*/
1762
/* out: TRUE if interrupted */
1763
trx_t* trx) /* in: transaction */
1822
trx_t* trx) /*!< in: transaction */
1765
1824
return(trx && trx->mysql_thd && thd_killed((THD*) trx->mysql_thd));
1768
/******************************************************************
1827
/**************************************************************//**
1769
1828
Resets some fields of a prebuilt struct. The template is used in fast
1770
1829
retrieval of just those column values MySQL needs in its processing. */
1773
1832
reset_template(
1774
1833
/*===========*/
1775
row_prebuilt_t* prebuilt) /* in/out: prebuilt struct */
1834
row_prebuilt_t* prebuilt) /*!< in/out: prebuilt struct */
1777
1836
prebuilt->keep_other_fields_on_keyread = 0;
1778
1837
prebuilt->read_just_key = 0;
1781
/*********************************************************************
1840
/*****************************************************************//**
1782
1841
Call this when you have opened a new table handle in HANDLER, before you
1783
1842
call index_read_idx() etc. Actually, we can let the cursor stay open even
1784
1843
over a transaction commit! Then you should call this before every operation,
2131
if (innobase_change_buffering) {
2135
use < UT_ARR_SIZE(innobase_change_buffering_values);
2137
if (!innobase_strcasecmp(
2138
innobase_change_buffering,
2139
innobase_change_buffering_values[use])) {
2140
ibuf_use = (ibuf_use_t) use;
2141
goto innobase_change_buffering_inited_ok;
2145
sql_print_error("InnoDB: invalid value "
2146
"innodb_file_format_check=%s",
2147
innobase_change_buffering);
2148
goto mem_free_and_error;
2151
innobase_change_buffering_inited_ok:
2085
2152
ut_a((ulint) ibuf_use < UT_ARR_SIZE(innobase_change_buffering_values));
2086
2153
innobase_change_buffering = (char*)
2087
2154
innobase_change_buffering_values[ibuf_use];
2265
2340
trx_commit_for_mysql(trx);
2268
/*********************************************************************
2343
/*****************************************************************//**
2269
2344
Creates an InnoDB transaction struct for the thd if it does not yet have one.
2270
2345
Starts a new InnoDB transaction if a transaction is not yet started. And
2271
2346
assigns a new snapshot for a consistent read if the transaction does not yet
2275
2351
innobase_start_trx_and_assign_read_view(
2276
2352
/*====================================*/
2278
handlerton *hton, /* in: Innodb handlerton */
2279
THD* thd) /* in: MySQL thread handle of the user for whom
2353
handlerton *hton, /*!< in: Innodb handlerton */
2354
THD* thd) /*!< in: MySQL thread handle of the user for whom
2280
2355
the transaction should be committed */
2438
2520
DBUG_RETURN(0);
2441
/*********************************************************************
2442
Rolls back a transaction or the latest SQL statement. */
2523
/*****************************************************************//**
2524
Rolls back a transaction or the latest SQL statement.
2525
@return 0 or error number */
2445
2528
innobase_rollback(
2446
2529
/*==============*/
2447
/* out: 0 or error number */
2448
handlerton *hton, /* in: Innodb handlerton */
2449
THD* thd, /* in: handle to the MySQL thread of the user
2530
handlerton *hton, /*!< in: Innodb handlerton */
2531
THD* thd, /*!< in: handle to the MySQL thread of the user
2450
2532
whose transaction should be rolled back */
2451
bool all) /* in: TRUE - commit transaction
2533
bool all) /*!< in: TRUE - commit transaction
2452
2534
FALSE - the current SQL statement ended */
2515
2597
DBUG_RETURN(convert_error_code_to_mysql(error, 0, NULL));
2518
/*********************************************************************
2519
Rolls back a transaction to a savepoint. */
2600
/*****************************************************************//**
2601
Rolls back a transaction to a savepoint.
2602
@return 0 if success, HA_ERR_NO_SAVEPOINT if no savepoint with the
2522
2606
innobase_rollback_to_savepoint(
2523
2607
/*===========================*/
2524
/* out: 0 if success, HA_ERR_NO_SAVEPOINT if
2525
no savepoint with the given name */
2526
handlerton *hton, /* in: Innodb handlerton */
2527
THD* thd, /* in: handle to the MySQL thread of the user
2608
handlerton *hton, /*!< in: Innodb handlerton */
2609
THD* thd, /*!< in: handle to the MySQL thread of the user
2528
2610
whose transaction should be rolled back */
2529
void* savepoint) /* in: savepoint data */
2611
void* savepoint) /*!< in: savepoint data */
2531
2613
ib_int64_t mysql_binlog_cache_pos;
2553
2635
DBUG_RETURN(convert_error_code_to_mysql(error, 0, NULL));
2556
/*********************************************************************
2557
Release transaction savepoint name. */
2638
/*****************************************************************//**
2639
Release transaction savepoint name.
2640
@return 0 if success, HA_ERR_NO_SAVEPOINT if no savepoint with the
2560
2644
innobase_release_savepoint(
2561
2645
/*=======================*/
2562
/* out: 0 if success, HA_ERR_NO_SAVEPOINT if
2563
no savepoint with the given name */
2564
handlerton* hton, /* in: handlerton for Innodb */
2565
THD* thd, /* in: handle to the MySQL thread of the user
2646
handlerton* hton, /*!< in: handlerton for Innodb */
2647
THD* thd, /*!< in: handle to the MySQL thread of the user
2566
2648
whose transaction should be rolled back */
2567
void* savepoint) /* in: savepoint data */
2649
void* savepoint) /*!< in: savepoint data */
2584
2666
DBUG_RETURN(convert_error_code_to_mysql(error, 0, NULL));
2587
/*********************************************************************
2588
Sets a transaction savepoint. */
2669
/*****************************************************************//**
2670
Sets a transaction savepoint.
2671
@return always 0, that is, always succeeds */
2591
2674
innobase_savepoint(
2592
2675
/*===============*/
2593
/* out: always 0, that is, always succeeds */
2594
handlerton* hton, /* in: handle to the Innodb handlerton */
2595
THD* thd, /* in: handle to the MySQL thread */
2596
void* savepoint) /* in: savepoint data */
2676
handlerton* hton, /*!< in: handle to the Innodb handlerton */
2677
THD* thd, /*!< in: handle to the MySQL thread */
2678
void* savepoint) /*!< in: savepoint data */
2631
2713
DBUG_RETURN(convert_error_code_to_mysql(error, 0, NULL));
2634
/*********************************************************************
2635
Frees a possible InnoDB trx object associated with the current THD. */
2716
/*****************************************************************//**
2717
Frees a possible InnoDB trx object associated with the current THD.
2718
@return 0 or error number */
2638
2721
innobase_close_connection(
2639
2722
/*======================*/
2640
/* out: 0 or error number */
2641
handlerton* hton, /* in: innobase handlerton */
2642
THD* thd) /* in: handle to the MySQL thread of the user
2723
handlerton* hton, /*!< in: innobase handlerton */
2724
THD* thd) /*!< in: handle to the MySQL thread of the user
2643
2725
whose resources should be free'd */
2679
/*****************************************************************************
2761
/*************************************************************************//**
2680
2762
** InnoDB database tables
2681
2763
*****************************************************************************/
2683
/********************************************************************
2684
Get the record format from the data dictionary. */
2765
/****************************************************************//**
2766
Get the record format from the data dictionary.
2767
@return one of ROW_TYPE_REDUNDANT, ROW_TYPE_COMPACT,
2768
ROW_TYPE_COMPRESSED, ROW_TYPE_DYNAMIC */
2687
2771
ha_innobase::get_row_type() const
2688
2772
/*=============================*/
2692
ROW_TYPE_COMPRESSED,
2695
2774
if (prebuilt && prebuilt->table) {
2696
2775
const ulint flags = prebuilt->table->flags;
2735
2816
return int_table_flags | HA_BINLOG_STMT_CAPABLE;
2738
/********************************************************************
2819
/****************************************************************//**
2739
2820
Gives the file extension of an InnoDB single-table tablespace. */
2740
2821
static const char* ha_innobase_exts[] = {
2826
/****************************************************************//**
2827
Returns the table type (storage engine name).
2828
@return table type */
2747
2831
ha_innobase::table_type() const
2748
2832
/*===========================*/
2749
/* out: table type */
2751
2834
return(innobase_hton_name);
2837
/****************************************************************//**
2838
Returns the index type. */
2756
ha_innobase::index_type(uint)
2757
/*=========================*/
2758
/* out: index type */
2841
ha_innobase::index_type(
2842
/*====================*/
2844
/*!< out: index type */
2760
2846
return("BTREE");
2849
/****************************************************************//**
2850
Returns the table file name extension.
2851
@return file extension string */
2765
2854
ha_innobase::bas_ext() const
2766
2855
/*========================*/
2767
/* out: file extension string */
2769
2857
return(ha_innobase_exts);
2860
/****************************************************************//**
2861
Returns the operations supported for indexes.
2862
@return flags of supported operations */
2774
ha_innobase::index_flags(uint, uint, bool) const
2865
ha_innobase::index_flags(
2866
/*=====================*/
2776
2872
return(HA_READ_NEXT | HA_READ_PREV | HA_READ_ORDER
2777
2873
| HA_READ_RANGE | HA_KEYREAD_ONLY);
2876
/****************************************************************//**
2877
Returns the maximum number of keys.
2782
2881
ha_innobase::max_supported_keys() const
2882
/*===================================*/
2784
2884
return(MAX_KEY);
2887
/****************************************************************//**
2888
Returns the maximum key length.
2889
@return maximum supported key length, in bytes */
2789
2892
ha_innobase::max_supported_key_length() const
2893
/*=========================================*/
2791
2895
/* An InnoDB page must store >= 2 keys; a secondary key record
2792
2896
must also contain the primary key value: max key length is
2883
2996
/* Execute SELECT MAX(col_name) FROM TABLE; */
2884
2997
error = row_search_max_autoinc(index, col_name, &auto_inc);
2886
if (error == DB_SUCCESS) {
2888
/* At the this stage we dont' know the increment
3002
/* At the this stage we don't know the increment
2889
3003
or the offset, so use default inrement of 1. */
2892
dict_table_autoinc_initialize(innodb_table, auto_inc);
3007
case DB_RECORD_NOT_FOUND:
2895
3008
ut_print_timestamp(stderr);
2896
fprintf(stderr, " InnoDB: Error: (%lu) Couldn't read "
2897
"the MAX(%s) autoinc value from the "
2898
"index (%s).\n", error, col_name, index->name);
3009
fprintf(stderr, " InnoDB: MySQL and InnoDB data "
3010
"dictionaries are out of sync.\n"
3011
"InnoDB: Unable to find the AUTOINC column %s in the "
3012
"InnoDB table %s.\n"
3013
"InnoDB: We set the next AUTOINC column value to the "
3014
"maximum possible value,\n"
3015
"InnoDB: in effect disabling the AUTOINC next value "
3017
"InnoDB: You can either set the next AUTOINC value "
3018
"explicitly using ALTER TABLE\n"
3019
"InnoDB: or fix the data dictionary by recreating "
3021
col_name, index->table->name);
3023
auto_inc = 0xFFFFFFFFFFFFFFFFULL;
3030
dict_table_autoinc_initialize(prebuilt->table, auto_inc);
2904
/*********************************************************************
3035
/*****************************************************************//**
2905
3036
Creates and opens a handle to a table which already exists in an InnoDB
3038
@return 1 if error, 0 if success */
2909
3041
ha_innobase::open(
2910
3042
/*==============*/
2911
/* out: 1 if error, 0 if success */
2912
const char* name, /* in: table name */
2913
int mode, /* in: not used */
2914
uint test_if_locked) /* in: not used */
3043
const char* name, /*!< in: table name */
3044
int mode, /*!< in: not used */
3045
uint test_if_locked) /*!< in: not used */
2916
3047
dict_table_t* ib_table;
2917
3048
char norm_name[1000];
3166
3296
/* The following accessor functions should really be inside MySQL code! */
3168
/******************************************************************
3169
Gets field offset for a field in a table. */
3298
/**************************************************************//**
3299
Gets field offset for a field in a table.
3172
3303
get_field_offset(
3173
3304
/*=============*/
3175
TABLE* table, /* in: MySQL table object */
3176
Field* field) /* in: MySQL field object */
3305
TABLE* table, /*!< in: MySQL table object */
3306
Field* field) /*!< in: MySQL field object */
3178
3308
return((uint) (field->ptr - table->record[0]));
3181
/******************************************************************
3311
/**************************************************************//**
3182
3312
Checks if a field in a record is SQL NULL. Uses the record format
3183
information in table to track the null bit in record. */
3313
information in table to track the null bit in record.
3314
@return 1 if NULL, 0 otherwise */
3186
3317
field_in_record_is_null(
3187
3318
/*====================*/
3188
/* out: 1 if NULL, 0 otherwise */
3189
TABLE* table, /* in: MySQL table object */
3190
Field* field, /* in: MySQL field object */
3191
char* record) /* in: a row in MySQL format */
3319
TABLE* table, /*!< in: MySQL table object */
3320
Field* field, /*!< in: MySQL field object */
3321
char* record) /*!< in: a row in MySQL format */
3193
3323
int null_offset;
3227
3357
record[null_offset] = record[null_offset] | field->null_bit;
3230
/*****************************************************************
3360
/*************************************************************//**
3231
3361
InnoDB uses this function to compare two data fields for which the data type
3232
3362
is such that we must use MySQL code to compare them. NOTE that the prototype
3233
3363
of this function is in rem0cmp.c in InnoDB source code! If you change this
3234
function, remember to update the prototype there! */
3364
function, remember to update the prototype there!
3365
@return 1, 0, -1, if a is greater, equal, less than b, respectively */
3235
3366
extern "C" UNIV_INTERN
3237
3368
innobase_mysql_cmp(
3238
3369
/*===============*/
3239
/* out: 1, 0, -1, if a is greater,
3240
equal, less than b, respectively */
3241
int mysql_type, /* in: MySQL type */
3242
uint charset_number, /* in: number of the charset */
3243
const unsigned char* a, /* in: data field */
3244
unsigned int a_length, /* in: data field length,
3370
int mysql_type, /*!< in: MySQL type */
3371
uint charset_number, /*!< in: number of the charset */
3372
const unsigned char* a, /*!< in: data field */
3373
unsigned int a_length, /*!< in: data field length,
3245
3374
not UNIV_SQL_NULL */
3246
const unsigned char* b, /* in: data field */
3247
unsigned int b_length) /* in: data field length,
3375
const unsigned char* b, /*!< in: data field */
3376
unsigned int b_length) /*!< in: data field length,
3248
3377
not UNIV_SQL_NULL */
3250
3379
CHARSET_INFO* charset;
3312
/******************************************************************
3441
/**************************************************************//**
3313
3442
Converts a MySQL type to an InnoDB type. Note that this function returns
3314
3443
the 'mtype' of InnoDB. InnoDB differentiates between MySQL's old <= 4.1
3315
VARCHAR and the new true VARCHAR in >= 5.0.3 by the 'prtype'. */
3444
VARCHAR and the new true VARCHAR in >= 5.0.3 by the 'prtype'.
3445
@return DATA_BINARY, DATA_VARCHAR, ... */
3316
3446
extern "C" UNIV_INTERN
3318
3448
get_innobase_type_from_mysql_type(
3319
3449
/*==============================*/
3320
/* out: DATA_BINARY,
3321
DATA_VARCHAR, ... */
3322
ulint* unsigned_flag, /* out: DATA_UNSIGNED if an
3450
ulint* unsigned_flag, /*!< out: DATA_UNSIGNED if an
3323
3451
'unsigned type';
3324
3452
at least ENUM and SET,
3325
3453
and unsigned integer
3326
3454
types are 'unsigned types' */
3327
const void* f) /* in: MySQL Field */
3455
const void* f) /*!< in: MySQL Field */
3329
3457
const class Field* field = reinterpret_cast<const class Field*>(f);
3433
3561
buf[1] = (byte)(val / 256);
3436
/***********************************************************************
3564
/*******************************************************************//**
3437
3565
Reads an unsigned integer value < 64k from 2 bytes, in the little-endian
3441
3570
innobase_read_from_2_little_endian(
3442
3571
/*===============================*/
3444
const uchar* buf) /* in: from where to read */
3572
const uchar* buf) /*!< in: from where to read */
3446
3574
return (uint) ((ulint)(buf[0]) + 256 * ((ulint)(buf[1])));
3449
/***********************************************************************
3450
Stores a key value for a row to a buffer. */
3577
/*******************************************************************//**
3578
Stores a key value for a row to a buffer.
3579
@return key value length as stored in buff */
3453
3582
ha_innobase::store_key_val_for_row(
3454
3583
/*===============================*/
3455
/* out: key value length as stored in buff */
3456
uint keynr, /* in: key number */
3457
char* buff, /* in/out: buffer for the key value (in MySQL
3584
uint keynr, /*!< in: key number */
3585
char* buff, /*!< in/out: buffer for the key value (in MySQL
3459
uint buff_len,/* in: buffer length */
3460
const uchar* record)/* in: row in MySQL format */
3587
uint buff_len,/*!< in: buffer length */
3588
const uchar* record)/*!< in: row in MySQL format */
3462
3590
KEY* key_info = table->key_info + keynr;
3463
3591
KEY_PART_INFO* key_part = key_info->key_part;
3720
3848
DBUG_RETURN((uint)(buff - buff_start));
3723
/******************************************************************
3851
/**************************************************************//**
3724
3852
Builds a 'template' to the prebuilt struct. The template is used in fast
3725
3853
retrieval of just those column values MySQL needs in its processing. */
3728
3856
build_template(
3729
3857
/*===========*/
3730
row_prebuilt_t* prebuilt, /* in/out: prebuilt struct */
3731
THD* thd, /* in: current user thread, used
3858
row_prebuilt_t* prebuilt, /*!< in/out: prebuilt struct */
3859
THD* thd, /*!< in: current user thread, used
3732
3860
only if templ_type is
3733
3861
ROW_MYSQL_REC_FIELDS */
3734
TABLE* table, /* in: MySQL table */
3735
uint templ_type) /* in: ROW_MYSQL_WHOLE_ROW or
3862
TABLE* table, /*!< in: MySQL table */
3863
uint templ_type) /*!< in: ROW_MYSQL_WHOLE_ROW or
3736
3864
ROW_MYSQL_REC_FIELDS */
3738
3866
dict_index_t* index;
4343
4468
DBUG_RETURN(error_result);
4346
/**************************************************************************
4471
/**********************************************************************//**
4347
4472
Checks which fields have changed in a row and stores information
4348
of them to an update vector. */
4473
of them to an update vector.
4474
@return error number or 0 */
4351
4477
calc_row_difference(
4352
4478
/*================*/
4353
/* out: error number or 0 */
4354
upd_t* uvect, /* in/out: update vector */
4355
uchar* old_row, /* in: old row in MySQL format */
4356
uchar* new_row, /* in: new row in MySQL format */
4357
struct st_table* table, /* in: table in MySQL data
4479
upd_t* uvect, /*!< in/out: update vector */
4480
uchar* old_row, /*!< in: old row in MySQL format */
4481
uchar* new_row, /*!< in: new row in MySQL format */
4482
struct st_table* table, /*!< in: table in MySQL data
4359
uchar* upd_buff, /* in: buffer to use */
4360
ulint buff_len, /* in: buffer length */
4361
row_prebuilt_t* prebuilt, /* in: InnoDB prebuilt struct */
4362
THD* thd) /* in: user thread */
4484
uchar* upd_buff, /*!< in: buffer to use */
4485
ulint buff_len, /*!< in: buffer length */
4486
row_prebuilt_t* prebuilt, /*!< in: InnoDB prebuilt struct */
4487
THD* thd) /*!< in: user thread */
4364
4489
uchar* original_upd_buff = upd_buff;
4494
/**************************************************************************
4619
/**********************************************************************//**
4495
4620
Updates a row given as a parameter to a new value. Note that we are given
4496
4621
whole rows, not just the fields which are updated: this incurs some
4497
4622
overhead for CPU when we check which fields are actually updated.
4498
4623
TODO: currently InnoDB does not prevent the 'Halloween problem':
4499
4624
in a searched update a single row can get updated several times
4500
if its index columns are updated! */
4625
if its index columns are updated!
4626
@return error number or 0 */
4503
4629
ha_innobase::update_row(
4504
4630
/*====================*/
4505
/* out: error number or 0 */
4506
const uchar* old_row, /* in: old row in MySQL format */
4507
uchar* new_row) /* in: new row in MySQL format */
4631
const uchar* old_row, /*!< in: old row in MySQL format */
4632
uchar* new_row) /*!< in: new row in MySQL format */
4718
#ifdef ROW_MERGE_IS_INDEX_USABLE
4719
/**********************************************************************
4720
Check if an index can be used by the optimizer. */
4723
ha_innobase::is_index_available(
4724
/*============================*/
4725
/* out: true if available else false*/
4726
uint keynr) /* in: index number to check */
4728
DBUG_ENTER("ha_innobase::is_index_available");
4730
if (table && keynr != MAX_KEY && table->s->keys > 0) {
4731
const dict_index_t* index;
4732
const KEY* key = table->key_info + keynr;
4734
ut_ad(user_thd == ha_thd());
4735
ut_a(prebuilt->trx == thd_to_trx(user_thd));
4737
index = dict_table_get_index_on_name(
4738
prebuilt->table, key->name);
4740
if (!row_merge_is_index_usable(prebuilt->trx, index)) {
4748
#endif /* ROW_MERGE_IS_INDEX_USABLE */
4750
/**********************************************************************
4751
Initializes a handle to use an index. */
4843
/******************************************************************//**
4844
Initializes a handle to use an index.
4845
@return 0 or error number */
4754
4848
ha_innobase::index_init(
4755
4849
/*====================*/
4756
/* out: 0 or error number */
4757
uint keynr, /* in: key (index) number */
4758
bool sorted) /* in: 1 if result MUST be sorted according to index */
4850
uint keynr, /*!< in: key (index) number */
4851
bool sorted) /*!< in: 1 if result MUST be sorted according to index */
4760
4853
DBUG_ENTER("index_init");
4762
4855
DBUG_RETURN(change_active_index(keynr));
4765
/**********************************************************************
4766
Currently does nothing. */
4858
/******************************************************************//**
4859
Currently does nothing.
4769
4863
ha_innobase::index_end(void)
4881
4974
start of a new SQL statement. */
4884
/**************************************************************************
4977
/**********************************************************************//**
4885
4978
Positions an index cursor to the index specified in the handle. Fetches the
4980
@return 0, HA_ERR_KEY_NOT_FOUND, or error number */
4889
4983
ha_innobase::index_read(
4890
4984
/*====================*/
4891
/* out: 0, HA_ERR_KEY_NOT_FOUND,
4893
uchar* buf, /* in/out: buffer for the returned
4985
uchar* buf, /*!< in/out: buffer for the returned
4895
const uchar* key_ptr, /* in: key value; if this is NULL
4987
const uchar* key_ptr, /*!< in: key value; if this is NULL
4896
4988
we position the cursor at the
4897
4989
start or end of index; this can
4898
4990
also contain an InnoDB row id, in
4997
5089
DBUG_RETURN(error);
5000
/***********************************************************************
5092
/*******************************************************************//**
5001
5093
The following functions works like index_read, but it find the last
5002
row with the current key value or prefix. */
5094
row with the current key value or prefix.
5095
@return 0, HA_ERR_KEY_NOT_FOUND, or an error code */
5005
5098
ha_innobase::index_read_last(
5006
5099
/*=========================*/
5007
/* out: 0, HA_ERR_KEY_NOT_FOUND, or an
5009
uchar* buf, /* out: fetched row */
5010
const uchar* key_ptr,/* in: key value, or a prefix of a full
5100
uchar* buf, /*!< out: fetched row */
5101
const uchar* key_ptr,/*!< in: key value, or a prefix of a full
5012
uint key_len)/* in: length of the key val or prefix
5103
uint key_len)/*!< in: length of the key val or prefix
5015
5106
return(index_read(buf, key_ptr, key_len, HA_READ_PREFIX_LAST));
5018
/************************************************************************
5019
Get the index for a handle. Does not change active index.*/
5109
/********************************************************************//**
5110
Get the index for a handle. Does not change active index.
5111
@return NULL or index instance. */
5022
5114
ha_innobase::innobase_get_index(
5023
5115
/*============================*/
5024
/* out: NULL or index instance. */
5025
uint keynr) /* in: use this index; MAX_KEY means always
5116
uint keynr) /*!< in: use this index; MAX_KEY means always
5026
5117
clustered index, even if it was internally
5027
5118
generated by InnoDB */
5099
5201
DBUG_RETURN(0);
5102
/**************************************************************************
5204
/**********************************************************************//**
5103
5205
Positions an index cursor to the index specified in keynr. Fetches the
5105
/* ??? This is only used to read whole keys ??? */
5207
??? This is only used to read whole keys ???
5208
@return error number or 0 */
5108
5211
ha_innobase::index_read_idx(
5109
5212
/*========================*/
5110
/* out: error number or 0 */
5111
uchar* buf, /* in/out: buffer for the returned
5213
uchar* buf, /*!< in/out: buffer for the returned
5113
uint keynr, /* in: use this index */
5114
const uchar* key, /* in: key value; if this is NULL
5215
uint keynr, /*!< in: use this index */
5216
const uchar* key, /*!< in: key value; if this is NULL
5115
5217
we position the cursor at the
5116
5218
start or end of index */
5117
uint key_len, /* in: key value length */
5118
enum ha_rkey_function find_flag)/* in: search flags from my_base.h */
5219
uint key_len, /*!< in: key value length */
5220
enum ha_rkey_function find_flag)/*!< in: search flags from my_base.h */
5120
5222
if (change_active_index(keynr)) {
5125
5227
return(index_read(buf, key, key_len, find_flag));
5128
/***************************************************************************
5230
/***********************************************************************//**
5129
5231
Reads the next or previous row from a cursor, which must have previously been
5130
positioned using index_read. */
5232
positioned using index_read.
5233
@return 0, HA_ERR_END_OF_FILE, or error number */
5133
5236
ha_innobase::general_fetch(
5134
5237
/*=======================*/
5135
/* out: 0, HA_ERR_END_OF_FILE, or error
5137
uchar* buf, /* in/out: buffer for next row in MySQL
5238
uchar* buf, /*!< in/out: buffer for next row in MySQL
5139
uint direction, /* in: ROW_SEL_NEXT or ROW_SEL_PREV */
5140
uint match_mode) /* in: 0, ROW_SEL_EXACT, or
5240
uint direction, /*!< in: ROW_SEL_NEXT or ROW_SEL_PREV */
5241
uint match_mode) /*!< in: 0, ROW_SEL_EXACT, or
5141
5242
ROW_SEL_EXACT_PREFIX */
5194
5294
return(general_fetch(buf, ROW_SEL_NEXT, 0));
5197
/***********************************************************************
5198
Reads the next row matching to the key value given as the parameter. */
5297
/*******************************************************************//**
5298
Reads the next row matching to the key value given as the parameter.
5299
@return 0, HA_ERR_END_OF_FILE, or error number */
5201
5302
ha_innobase::index_next_same(
5202
5303
/*=========================*/
5203
/* out: 0, HA_ERR_END_OF_FILE, or error
5205
uchar* buf, /* in/out: buffer for the row */
5206
const uchar* key, /* in: key value */
5207
uint keylen) /* in: key value length */
5304
uchar* buf, /*!< in/out: buffer for the row */
5305
const uchar* key, /*!< in: key value */
5306
uint keylen) /*!< in: key value length */
5209
5308
ha_statistic_increment(&SSV::ha_read_next_count);
5211
5310
return(general_fetch(buf, ROW_SEL_NEXT, last_match_mode));
5214
/***************************************************************************
5313
/***********************************************************************//**
5215
5314
Reads the previous row from a cursor, which must have previously been
5216
positioned using index_read. */
5315
positioned using index_read.
5316
@return 0, HA_ERR_END_OF_FILE, or error number */
5219
5319
ha_innobase::index_prev(
5220
5320
/*====================*/
5221
/* out: 0, HA_ERR_END_OF_FILE, or error number */
5222
uchar* buf) /* in/out: buffer for previous row in MySQL format */
5321
uchar* buf) /*!< in/out: buffer for previous row in MySQL format */
5224
5323
ha_statistic_increment(&SSV::ha_read_prev_count);
5226
5325
return(general_fetch(buf, ROW_SEL_PREV, 0));
5229
/************************************************************************
5328
/********************************************************************//**
5230
5329
Positions a cursor on the first record in an index and reads the
5231
corresponding row to buf. */
5330
corresponding row to buf.
5331
@return 0, HA_ERR_END_OF_FILE, or error code */
5234
5334
ha_innobase::index_first(
5235
5335
/*=====================*/
5236
/* out: 0, HA_ERR_END_OF_FILE, or error code */
5237
uchar* buf) /* in/out: buffer for the row */
5336
uchar* buf) /*!< in/out: buffer for the row */
5313
/*********************************************************************
5314
Ends a table scan. */
5412
/*****************************************************************//**
5414
@return 0 or error number */
5317
5417
ha_innobase::rnd_end(void)
5318
5418
/*======================*/
5319
/* out: 0 or error number */
5321
5420
return(index_end());
5324
/*********************************************************************
5423
/*****************************************************************//**
5325
5424
Reads the next row in a table scan (also used to read the FIRST row
5326
in a table scan). */
5426
@return 0, HA_ERR_END_OF_FILE, or error number */
5329
5429
ha_innobase::rnd_next(
5330
5430
/*==================*/
5331
/* out: 0, HA_ERR_END_OF_FILE, or error number */
5332
uchar* buf) /* in/out: returns the row in this buffer,
5431
uchar* buf) /*!< in/out: returns the row in this buffer,
5333
5432
in MySQL format */
5352
5451
DBUG_RETURN(error);
5355
/**************************************************************************
5356
Fetches a row from the table based on a row reference. */
5454
/**********************************************************************//**
5455
Fetches a row from the table based on a row reference.
5456
@return 0, HA_ERR_KEY_NOT_FOUND, or error code */
5359
5459
ha_innobase::rnd_pos(
5360
5460
/*=================*/
5361
/* out: 0, HA_ERR_KEY_NOT_FOUND, or error code */
5362
uchar* buf, /* in/out: buffer for the row */
5363
uchar* pos) /* in: primary key value of the row in the
5461
uchar* buf, /*!< in/out: buffer for the row */
5462
uchar* pos) /*!< in: primary key value of the row in the
5364
5463
MySQL format, or the row id if the clustered
5365
5464
index was internally generated by InnoDB; the
5366
5465
length of data in pos has to be ref_length */
5451
5550
(row_is_magic_monitor_table(table_name) \
5452
5551
&& check_global_access(thd, PROCESS_ACL))
5454
/*********************************************************************
5553
/*****************************************************************//**
5455
5554
Creates a table definition to an InnoDB database. */
5458
5557
create_table_def(
5459
5558
/*=============*/
5460
trx_t* trx, /* in: InnoDB transaction handle */
5461
TABLE* form, /* in: information on table
5559
trx_t* trx, /*!< in: InnoDB transaction handle */
5560
TABLE* form, /*!< in: information on table
5462
5561
columns and indexes */
5463
const char* table_name, /* in: table name */
5464
const char* path_of_temp_table,/* in: if this is a table explicitly
5562
const char* table_name, /*!< in: table name */
5563
const char* path_of_temp_table,/*!< in: if this is a table explicitly
5465
5564
created by the user with the
5466
5565
TEMPORARY keyword, then this
5467
5566
parameter is the dir path where the
5580
5679
DBUG_RETURN(error);
5583
/*********************************************************************
5682
/*****************************************************************//**
5584
5683
Creates an index in an InnoDB database. */
5589
trx_t* trx, /* in: InnoDB transaction handle */
5590
TABLE* form, /* in: information on table
5688
trx_t* trx, /*!< in: InnoDB transaction handle */
5689
TABLE* form, /*!< in: information on table
5591
5690
columns and indexes */
5592
ulint flags, /* in: InnoDB table flags */
5593
const char* table_name, /* in: table name */
5594
uint key_num) /* in: index number */
5691
ulint flags, /*!< in: InnoDB table flags */
5692
const char* table_name, /*!< in: table name */
5693
uint key_num) /*!< in: index number */
5597
5696
dict_index_t* index;
5735
/*********************************************************************
5834
/*****************************************************************//**
5736
5835
Validates the create options. We may build on this function
5737
5836
in future. For now, it checks two specifiers:
5738
5837
KEY_BLOCK_SIZE and ROW_FORMAT
5739
If innodb_strict_mode is not set then this function is a no-op */
5838
If innodb_strict_mode is not set then this function is a no-op
5839
@return TRUE if valid. */
5742
5842
create_options_are_valid(
5743
5843
/*=====================*/
5744
/* out: TRUE if valid. */
5745
THD* thd, /* in: connection thread. */
5746
TABLE* form, /* in: information on table
5844
THD* thd, /*!< in: connection thread. */
5845
TABLE* form, /*!< in: information on table
5747
5846
columns and indexes */
5748
HA_CREATE_INFO* create_info) /* in: create info. */
5847
HA_CREATE_INFO* create_info) /*!< in: create info. */
5750
5849
ibool kbs_specified = FALSE;
5751
5850
ibool ret = TRUE;
6506
6604
innobase_commit_low(trx);
6507
6605
trx_free_for_mysql(trx);
6509
/*************************************************************************
6510
Renames an InnoDB table. */
6607
/*********************************************************************//**
6608
Renames an InnoDB table.
6609
@return 0 or error code */
6513
6612
innobase_rename_table(
6514
6613
/*==================*/
6515
/* out: 0 or error code */
6516
trx_t* trx, /* in: transaction */
6517
const char* from, /* in: old name of the table */
6518
const char* to, /* in: new name of the table */
6614
trx_t* trx, /*!< in: transaction */
6615
const char* from, /*!< in: old name of the table */
6616
const char* to, /*!< in: new name of the table */
6519
6617
ibool lock_and_commit)
6520
/* in: TRUE=lock data dictionary and commit */
6618
/*!< in: TRUE=lock data dictionary and commit */
6615
6713
DBUG_RETURN(error);
6618
/*************************************************************************
6619
Estimates the number of index records in a range. */
6716
/*********************************************************************//**
6717
Estimates the number of index records in a range.
6718
@return estimated number of rows */
6622
6721
ha_innobase::records_in_range(
6623
6722
/*==========================*/
6624
/* out: estimated number of
6626
uint keynr, /* in: index number */
6627
key_range *min_key, /* in: start key value of the
6723
uint keynr, /*!< in: index number */
6724
key_range *min_key, /*!< in: start key value of the
6628
6725
range, may also be 0 */
6629
key_range *max_key) /* in: range end key val, may
6726
key_range *max_key) /*!< in: range end key val, may
6792
6889
return((double) (prebuilt->table->stat_clustered_index_size));
6795
/**********************************************************************
6892
/******************************************************************//**
6796
6893
Calculate the time it takes to read a set of ranges through an index
6797
This enables us to optimise reads for clustered indexes. */
6894
This enables us to optimise reads for clustered indexes.
6895
@return estimated time measured in disk seeks */
6800
6898
ha_innobase::read_time(
6801
6899
/*===================*/
6802
/* out: estimated time measured in disk seeks */
6803
uint index, /* in: key number */
6804
uint ranges, /* in: how many ranges */
6805
ha_rows rows) /* in: estimated number of rows in the ranges */
6900
uint index, /*!< in: key number */
6901
uint ranges, /*!< in: how many ranges */
6902
ha_rows rows) /*!< in: estimated number of rows in the ranges */
6807
6904
ha_rows total_rows;
6808
6905
double time_for_scan;
7096
7193
DBUG_RETURN(0);
7099
/**************************************************************************
7196
/**********************************************************************//**
7100
7197
Updates index cardinalities of the table, based on 8 random dives into
7101
each index tree. This does NOT calculate exact statistics on the table. */
7198
each index tree. This does NOT calculate exact statistics on the table.
7199
@return returns always 0 (success) */
7104
7202
ha_innobase::analyze(
7105
7203
/*=================*/
7106
/* out: returns always 0 (success) */
7107
THD* thd, /* in: connection thread handle */
7108
HA_CHECK_OPT* check_opt) /* in: currently ignored */
7204
THD* thd, /*!< in: connection thread handle */
7205
HA_CHECK_OPT* check_opt) /*!< in: currently ignored */
7110
7207
/* Simply call ::info() with all the flags */
7111
7208
info(HA_STATUS_TIME | HA_STATUS_CONST | HA_STATUS_VARIABLE);
7116
/**************************************************************************
7213
/**********************************************************************//**
7117
7214
This is mapped to "ALTER TABLE tablename ENGINE=InnoDB", which rebuilds
7118
7215
the table in MySQL. */
7121
7218
ha_innobase::optimize(
7122
7219
/*==================*/
7123
THD* thd, /* in: connection thread handle */
7124
HA_CHECK_OPT* check_opt) /* in: currently ignored */
7220
THD* thd, /*!< in: connection thread handle */
7221
HA_CHECK_OPT* check_opt) /*!< in: currently ignored */
7126
7223
return(HA_ADMIN_TRY_ALTER);
7129
/***********************************************************************
7226
/*******************************************************************//**
7130
7227
Tries to check that an InnoDB table is not corrupted. If corruption is
7131
7228
noticed, prints to stderr information about it. In case of corruption
7132
may also assert a failure and crash the server. */
7229
may also assert a failure and crash the server.
7230
@return HA_ADMIN_CORRUPT or HA_ADMIN_OK */
7135
7233
ha_innobase::check(
7136
7234
/*===============*/
7137
/* out: HA_ADMIN_CORRUPT or
7139
THD* thd, /* in: user thread handle */
7140
HA_CHECK_OPT* check_opt) /* in: check options, currently
7235
THD* thd, /*!< in: user thread handle */
7236
HA_CHECK_OPT* check_opt) /*!< in: check options, currently
7239
7334
return(str ? str : (char*) comment);
7242
/***********************************************************************
7243
Gets the foreign key create info for a table stored in InnoDB. */
7337
/*******************************************************************//**
7338
Gets the foreign key create info for a table stored in InnoDB.
7339
@return own: character string in the form which can be inserted to the
7340
CREATE TABLE statement, MUST be freed with
7341
ha_innobase::free_foreign_key_create_info */
7246
7344
ha_innobase::get_foreign_key_create_info(void)
7247
7345
/*==========================================*/
7248
/* out, own: character string in the form which
7249
can be inserted to the CREATE TABLE statement,
7250
MUST be freed with ::free_foreign_key_create_info */
7482
/***********************************************************************
7578
/*******************************************************************//**
7483
7579
Frees the foreign key create info for a table stored in InnoDB, if it is
7487
7583
ha_innobase::free_foreign_key_create_info(
7488
7584
/*======================================*/
7489
char* str) /* in, own: create info string to free */
7585
char* str) /*!< in, own: create info string to free */
7492
7588
my_free(str, MYF(0));
7496
/***********************************************************************
7497
Tells something additional to the handler about how to do things. */
7592
/*******************************************************************//**
7593
Tells something additional to the handler about how to do things.
7594
@return 0 or error number */
7500
7597
ha_innobase::extra(
7501
7598
/*===============*/
7502
/* out: 0 or error number */
7503
7599
enum ha_extra_function operation)
7504
/* in: HA_EXTRA_FLUSH or some other flag */
7600
/*!< in: HA_EXTRA_FLUSH or some other flag */
7506
7602
/* Warning: since it is not sure that MySQL calls external_lock
7507
7603
before calling this function, the trx field in prebuilt can be
7677
/**********************************************************************
7773
/******************************************************************//**
7678
7774
As MySQL will execute an external lock for every new table it uses when it
7679
7775
starts to process an SQL statement (an exception is when MySQL calls
7680
7776
start_stmt for the handle) we can use this function to store the pointer to
7681
7777
the THD in the handle. We will also use this function to communicate
7682
7778
to InnoDB that a new SQL statement has started and that we must store a
7683
7779
savepoint to our transaction handle, so that we are able to roll back
7684
the SQL statement in case of an error. */
7780
the SQL statement in case of an error.
7687
7784
ha_innobase::external_lock(
7688
7785
/*=======================*/
7690
THD* thd, /* in: handle to the user thread */
7691
int lock_type) /* in: lock type */
7786
THD* thd, /*!< in: handle to the user thread */
7787
int lock_type) /*!< in: lock type */
7935
8031
DBUG_RETURN(0);
7938
/****************************************************************************
7939
Here we export InnoDB status variables to MySQL. */
8034
/************************************************************************//**
8035
Here we export InnoDB status variables to MySQL. */
7942
innodb_export_status()
7943
/*==================*/
8038
innodb_export_status(void)
8039
/*======================*/
7945
8041
if (innodb_inited) {
7946
8042
srv_export_innodb_status();
7952
/****************************************************************************
8046
/************************************************************************//**
7953
8047
Implements the SHOW INNODB STATUS command. Sends the output of the InnoDB
7954
8048
Monitor to the client. */
7957
8051
innodb_show_status(
7958
8052
/*===============*/
7959
handlerton* hton, /* in: the innodb handlerton */
7960
THD* thd, /* in: the MySQL query thread of the caller */
8053
handlerton* hton, /*!< in: the innodb handlerton */
8054
THD* thd, /*!< in: the MySQL query thread of the caller */
7961
8055
stat_print_fn *stat_print)
8255
8353
pthread_mutex_unlock(&innobase_share_mutex);
8258
/*********************************************************************
8356
/*****************************************************************//**
8259
8357
Converts a MySQL table lock stored in the 'lock' field of the handle to
8260
8358
a proper type before storing pointer to the lock into an array of pointers.
8261
8359
MySQL also calls this if it wants to reset some table locks to a not-locked
8262
8360
state during the processing of an SQL query. An example is that during a
8263
8361
SELECT the read lock is released early on the 'const' tables where we only
8264
8362
fetch one row. MySQL does not call this when it releases all locks at the
8265
end of an SQL statement. */
8363
end of an SQL statement.
8364
@return pointer to the next element in the 'to' array */
8267
8366
THR_LOCK_DATA**
8268
8367
ha_innobase::store_lock(
8269
8368
/*====================*/
8270
/* out: pointer to the next
8271
element in the 'to' array */
8272
THD* thd, /* in: user thread handle */
8273
THR_LOCK_DATA** to, /* in: pointer to an array
8369
THD* thd, /*!< in: user thread handle */
8370
THR_LOCK_DATA** to, /*!< in: pointer to an array
8274
8371
of pointers to lock structs;
8275
8372
pointer to the 'lock' field
8276
8373
of current handle is stored
8277
8374
next to this array */
8278
enum thr_lock_type lock_type) /* in: lock type to store in
8375
enum thr_lock_type lock_type) /*!< in: lock type to store in
8279
8376
'lock'; this may also be
8525
8622
ha_innobase::get_auto_increment(
8526
8623
/*============================*/
8527
ulonglong offset, /* in: */
8528
ulonglong increment, /* in: table autoinc increment */
8529
ulonglong nb_desired_values, /* in: number of values reqd */
8530
ulonglong *first_value, /* out: the autoinc value */
8531
ulonglong *nb_reserved_values) /* out: count of reserved values */
8624
ulonglong offset, /*!< in: table autoinc offset */
8625
ulonglong increment, /*!< in: table autoinc increment */
8626
ulonglong nb_desired_values, /*!< in: number of values reqd */
8627
ulonglong *first_value, /*!< out: the autoinc value */
8628
ulonglong *nb_reserved_values) /*!< out: count of reserved values */
8663
8765
trx_t* trx = check_trx_exists(ha_thd());
8665
buf->copy(trx->detailed_error, strlen(trx->detailed_error),
8767
buf->copy(trx->detailed_error, (uint) strlen(trx->detailed_error),
8666
8768
system_charset_info);
8671
/***********************************************************************
8773
/*******************************************************************//**
8672
8774
Compares two 'refs'. A 'ref' is the (internal) primary key value of the row.
8673
8775
If there is no explicitly declared non-null unique key or a primary key, then
8674
InnoDB internally uses the row id as the primary key. */
8776
InnoDB internally uses the row id as the primary key.
8777
@return < 0 if ref1 < ref2, 0 if equal, else > 0 */
8677
8780
ha_innobase::cmp_ref(
8678
8781
/*=================*/
8679
/* out: < 0 if ref1 < ref2, 0 if equal, else
8681
const uchar* ref1, /* in: an (internal) primary key value in the
8782
const uchar* ref1, /*!< in: an (internal) primary key value in the
8682
8783
MySQL key value format */
8683
const uchar* ref2) /* in: an (internal) primary key value in the
8784
const uchar* ref2) /*!< in: an (internal) primary key value in the
8684
8785
MySQL key value format */
8686
8787
enum_field_types mysql_type;
8743
/***********************************************************************
8744
Ask InnoDB if a query to a table can be cached. */
8844
/*******************************************************************//**
8845
Ask InnoDB if a query to a table can be cached.
8846
@return TRUE if query caching of the table is permitted */
8747
8849
ha_innobase::register_query_cache_table(
8748
8850
/*====================================*/
8749
/* out: TRUE if query caching
8750
of the table is permitted */
8751
THD* thd, /* in: user thread handle */
8752
char* table_key, /* in: concatenation of database name,
8753
the null character '\0',
8851
THD* thd, /*!< in: user thread handle */
8852
char* table_key, /*!< in: concatenation of database name,
8853
the null character NUL,
8754
8854
and the table name */
8755
uint key_length, /* in: length of the full name, i.e.
8855
uint key_length, /*!< in: length of the full name, i.e.
8756
8856
len(dbname) + len(tablename) + 1 */
8757
8857
qc_engine_callback*
8758
call_back, /* out: pointer to function for
8858
call_back, /*!< out: pointer to function for
8759
8859
checking if query caching
8760
8860
is permitted */
8761
ulonglong *engine_data) /* in/out: data to call_back */
8861
ulonglong *engine_data) /*!< in/out: data to call_back */
8763
8863
*call_back = innobase_query_caching_of_table_permitted;
8764
8864
*engine_data = 0;
8784
8884
return(trx_sys_mysql_bin_log_pos);
8787
/**********************************************************************
8887
/******************************************************************//**
8788
8888
This function is used to find the storage length in bytes of the first n
8789
8889
characters for prefix indexes using a multibyte character set. The function
8790
8890
finds charset information and returns length of prefix_len characters in the
8791
8891
index field in bytes.
8793
NOTE: the prototype of this function is copied to data0type.c! If you change
8794
this function, you MUST change also data0type.c! */
8892
@return number of bytes occupied by the first n characters */
8795
8893
extern "C" UNIV_INTERN
8797
8895
innobase_get_at_most_n_mbchars(
8798
8896
/*===========================*/
8799
/* out: number of bytes occupied by the first
8801
ulint charset_id, /* in: character set id */
8802
ulint prefix_len, /* in: prefix length in bytes of the index
8897
ulint charset_id, /*!< in: character set id */
8898
ulint prefix_len, /*!< in: prefix length in bytes of the index
8803
8899
(this has to be divided by mbmaxlen to get the
8804
8900
number of CHARACTERS n in the prefix) */
8805
ulint data_len, /* in: length of the string in bytes */
8806
const char* str) /* in: character string */
8901
ulint data_len, /*!< in: length of the string in bytes */
8902
const char* str) /*!< in: character string */
8808
ulint char_length; /* character length in bytes */
8809
ulint n_chars; /* number of characters in prefix */
8810
CHARSET_INFO* charset; /* charset used in the field */
8904
ulint char_length; /*!< character length in bytes */
8905
ulint n_chars; /*!< number of characters in prefix */
8906
CHARSET_INFO* charset; /*!< charset used in the field */
8812
8908
charset = get_charset((uint) charset_id, MYF(MY_WME));
8858
8954
return(char_length);
8861
/***********************************************************************
8862
This function is used to prepare X/Open XA distributed transaction */
8957
/*******************************************************************//**
8958
This function is used to prepare an X/Open XA distributed transaction.
8959
@return 0 or error number */
8865
8962
innobase_xa_prepare(
8866
8963
/*================*/
8867
/* out: 0 or error number */
8869
THD* thd, /* in: handle to the MySQL thread of the user
8870
whose XA transaction should be prepared */
8871
bool all) /* in: TRUE - commit transaction
8872
FALSE - the current SQL statement ended */
8964
handlerton* hton, /*!< in: InnoDB handlerton */
8965
THD* thd, /*!< in: handle to the MySQL thread of
8966
the user whose XA transaction should
8968
bool all) /*!< in: TRUE - commit transaction
8969
FALSE - the current SQL statement
8875
8973
trx_t* trx = check_trx_exists(thd);
8877
8975
DBUG_ASSERT(hton == innodb_hton_ptr);
8977
/* we use support_xa value as it was seen at transaction start
8978
time, not the current session variable value. Any possible changes
8979
to the session variable take effect only in the next transaction */
8980
if (!trx->support_xa) {
8985
thd_get_xid(thd, (MYSQL_XID*) &trx->xid);
8987
/* Release a possible FIFO ticket and search latch. Since we will
8988
reserve the kernel mutex, we have to release the search system latch
8989
first to obey the latching order. */
8991
innobase_release_stat_resources(trx);
8993
if (trx->active_trans == 0 && trx->conc_state != TRX_NOT_STARTED) {
8995
sql_print_error("trx->active_trans == 0, but trx->conc_state != "
9000
|| (!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))) {
9002
/* We were instructed to prepare the whole transaction, or
9003
this is an SQL statement end and autocommit is on */
9005
ut_ad(trx->active_trans);
9007
error = (int) trx_prepare_for_mysql(trx);
9009
/* We just mark the SQL statement ended and do not do a
9010
transaction prepare */
9012
/* If we had reserved the auto-inc lock for some
9013
table in this SQL statement we release it now */
9015
row_unlock_table_autoinc_for_mysql(trx);
9017
/* Store the current undo_no of the transaction so that we
9018
know where to roll back if we have to roll back the next
9021
trx_mark_sql_stat_end(trx);
9024
/* Tell the InnoDB server that there might be work for utility
9027
srv_active_wake_master_thread();
8879
9029
if (thd_sql_command(thd) != SQLCOM_XA_PREPARE &&
8880
9030
(all || !thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))
8903
9053
trx->active_trans = 2;
8906
/* we use support_xa value as it was seen at transaction start
8907
time, not the current session variable value. Any possible changes
8908
to the session variable take effect only in the next transaction */
8909
if (!trx->support_xa) {
8914
thd_get_xid(thd, (MYSQL_XID*) &trx->xid);
8916
/* Release a possible FIFO ticket and search latch. Since we will
8917
reserve the kernel mutex, we have to release the search system latch
8918
first to obey the latching order. */
8920
innobase_release_stat_resources(trx);
8922
if (trx->active_trans == 0 && trx->conc_state != TRX_NOT_STARTED) {
8924
sql_print_error("trx->active_trans == 0, but trx->conc_state != "
8929
|| (!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))) {
8931
/* We were instructed to prepare the whole transaction, or
8932
this is an SQL statement end and autocommit is on */
8934
ut_ad(trx->active_trans);
8936
error = (int) trx_prepare_for_mysql(trx);
8938
/* We just mark the SQL statement ended and do not do a
8939
transaction prepare */
8941
/* If we had reserved the auto-inc lock for some
8942
table in this SQL statement we release it now */
8944
row_unlock_table_autoinc_for_mysql(trx);
8946
/* Store the current undo_no of the transaction so that we
8947
know where to roll back if we have to roll back the next
8950
trx_mark_sql_stat_end(trx);
8953
/* Tell the InnoDB server that there might be work for utility
8956
srv_active_wake_master_thread();
8961
/***********************************************************************
8962
This function is used to recover X/Open XA distributed transactions */
9059
/*******************************************************************//**
9060
This function is used to recover X/Open XA distributed transactions.
9061
@return number of prepared transactions stored in xid_list */
8965
9064
innobase_xa_recover(
8966
9065
/*================*/
8967
/* out: number of prepared transactions
8968
stored in xid_list */
8970
XID* xid_list, /* in/out: prepared transactions */
8971
uint len) /* in: number of slots in xid_list */
9066
handlerton* hton, /*!< in: InnoDB handlerton */
9067
XID* xid_list,/*!< in/out: prepared transactions */
9068
uint len) /*!< in: number of slots in xid_list */
8973
9070
DBUG_ASSERT(hton == innodb_hton_ptr);
9033
/***********************************************************************
9131
/*******************************************************************//**
9034
9132
Create a consistent view for a cursor based on current transaction
9035
9133
which is created if the corresponding MySQL thread still lacks one.
9036
9134
This consistent view is then used inside of MySQL when accessing records
9136
@return pointer to cursor view or NULL */
9040
9139
innobase_create_cursor_view(
9041
9140
/*========================*/
9042
/* out: pointer to cursor view or NULL */
9043
handlerton *hton, /* in: innobase hton */
9044
THD* thd) /* in: user thread handle */
9141
handlerton *hton, /*!< in: innobase hton */
9142
THD* thd) /*!< in: user thread handle */
9046
9144
DBUG_ASSERT(hton == innodb_hton_ptr);
9048
9146
return(read_cursor_view_create_for_mysql(check_trx_exists(thd)));
9051
/***********************************************************************
9149
/*******************************************************************//**
9052
9150
Close the given consistent cursor view of a transaction and restore
9053
9151
global read view to a transaction read view. Transaction is created if the
9054
9152
corresponding MySQL thread still lacks one. */
9187
/***********************************************************************
9188
Check whether any of the given columns is being renamed in the table. */
9191
column_is_being_renamed(
9192
/*====================*/
9193
/* out: true if any of col_names is
9194
being renamed in table */
9195
TABLE* table, /* in: MySQL table */
9196
uint n_cols, /* in: number of columns */
9197
const char** col_names) /* in: names of the columns */
9202
const char* col_name;
9204
for (j = 0; j < n_cols; j++) {
9205
col_name = col_names[j];
9206
for (k = 0; k < table->s->fields; k++) {
9207
field = table->field[k];
9208
if ((field->flags & FIELD_IS_RENAMED)
9209
&& innobase_strcasecmp(field->field_name,
9219
/***********************************************************************
9220
Check whether a column in table "table" is being renamed and if this column
9221
is part of a foreign key, either part of another table, referencing this
9222
table or part of this table, referencing another table. */
9225
foreign_key_column_is_being_renamed(
9226
/*================================*/
9227
/* out: true if a column that
9228
participates in a foreign key definition
9230
row_prebuilt_t* prebuilt, /* in: InnoDB prebuilt struct */
9231
TABLE* table) /* in: MySQL table */
9233
dict_foreign_t* foreign;
9235
/* check whether there are foreign keys at all */
9236
if (UT_LIST_GET_LEN(prebuilt->table->foreign_list) == 0
9237
&& UT_LIST_GET_LEN(prebuilt->table->referenced_list) == 0) {
9238
/* no foreign keys involved with prebuilt->table */
9243
row_mysql_lock_data_dictionary(prebuilt->trx);
9245
/* Check whether any column in the foreign key constraints which refer
9246
to this table is being renamed. */
9247
for (foreign = UT_LIST_GET_FIRST(prebuilt->table->referenced_list);
9249
foreign = UT_LIST_GET_NEXT(referenced_list, foreign)) {
9251
if (column_is_being_renamed(table, foreign->n_fields,
9252
foreign->referenced_col_names)) {
9254
row_mysql_unlock_data_dictionary(prebuilt->trx);
9259
/* Check whether any column in the foreign key constraints in the
9260
table is being renamed. */
9261
for (foreign = UT_LIST_GET_FIRST(prebuilt->table->foreign_list);
9263
foreign = UT_LIST_GET_NEXT(foreign_list, foreign)) {
9265
if (column_is_being_renamed(table, foreign->n_fields,
9266
foreign->foreign_col_names)) {
9268
row_mysql_unlock_data_dictionary(prebuilt->trx);
9273
row_mysql_unlock_data_dictionary(prebuilt->trx);
9091
9280
ha_innobase::check_if_incompatible_data(
9218
/*****************************************************************
9414
/*************************************************************//**
9219
9415
Check if it is a valid file format. This function is registered as
9220
a callback with MySQL. */
9416
a callback with MySQL.
9417
@return 0 for valid file format */
9223
9420
innodb_file_format_name_validate(
9224
9421
/*=============================*/
9225
/* out: 0 for valid file
9227
THD* thd, /* in: thread handle */
9228
struct st_mysql_sys_var* var, /* in: pointer to system
9422
THD* thd, /*!< in: thread handle */
9423
struct st_mysql_sys_var* var, /*!< in: pointer to system
9230
void* save, /* out: immediate result
9425
void* save, /*!< out: immediate result
9231
9426
for update function */
9232
struct st_mysql_value* value) /* in: incoming string */
9427
struct st_mysql_value* value) /*!< in: incoming string */
9234
9429
const char* file_format_input;
9235
9430
char buff[STRING_BUFFER_USUAL_SIZE];
9249
9444
if (format_id <= DICT_TF_FORMAT_MAX) {
9251
*(uint*) save = format_id;
9446
*static_cast<const char**>(save) = file_format_input;
9451
*static_cast<const char**>(save) = NULL;
9259
/********************************************************************
9455
/****************************************************************//**
9260
9456
Update the system variable innodb_file_format using the "saved"
9261
9457
value. This function is registered as a callback with MySQL. */
9264
9460
innodb_file_format_name_update(
9265
9461
/*===========================*/
9266
THD* thd, /* in: thread handle */
9267
struct st_mysql_sys_var* var, /* in: pointer to
9462
THD* thd, /*!< in: thread handle */
9463
struct st_mysql_sys_var* var, /*!< in: pointer to
9268
9464
system variable */
9269
void* var_ptr, /* out: where the
9465
void* var_ptr, /*!< out: where the
9270
9466
formal string goes */
9271
const void* save) /* in: immediate result
9467
const void* save) /*!< in: immediate result
9272
9468
from check function */
9470
const char* format_name;
9274
9472
ut_a(var_ptr != NULL);
9275
9473
ut_a(save != NULL);
9276
ut_a((*(const uint*) save) <= DICT_TF_FORMAT_MAX);
9278
srv_file_format = *(const uint*) save;
9280
*(const char**) var_ptr
9475
format_name = *static_cast<const char*const*>(save);
9480
format_id = innobase_file_format_name_lookup(format_name);
9482
if (format_id <= DICT_TF_FORMAT_MAX) {
9483
srv_file_format = format_id;
9487
*static_cast<const char**>(var_ptr)
9281
9488
= trx_sys_file_format_id_to_name(srv_file_format);
9284
/*****************************************************************
9491
/*************************************************************//**
9285
9492
Check if valid argument to innodb_file_format_check. This
9286
function is registered as a callback with MySQL. */
9493
function is registered as a callback with MySQL.
9494
@return 0 for valid file format */
9289
9497
innodb_file_format_check_validate(
9290
9498
/*==============================*/
9291
/* out: 0 for valid file
9293
THD* thd, /* in: thread handle */
9294
struct st_mysql_sys_var* var, /* in: pointer to system
9499
THD* thd, /*!< in: thread handle */
9500
struct st_mysql_sys_var* var, /*!< in: pointer to system
9296
void* save, /* out: immediate result
9502
void* save, /*!< out: immediate result
9297
9503
for update function */
9298
struct st_mysql_value* value) /* in: incoming string */
9504
struct st_mysql_value* value) /*!< in: incoming string */
9300
9506
const char* file_format_input;
9301
9507
char buff[STRING_BUFFER_USUAL_SIZE];
9542
*static_cast<const char**>(save) = NULL;
9346
/********************************************************************
9546
/****************************************************************//**
9347
9547
Update the system variable innodb_file_format_check using the "saved"
9348
9548
value. This function is registered as a callback with MySQL. */
9351
9551
innodb_file_format_check_update(
9352
9552
/*============================*/
9353
THD* thd, /* in: thread handle */
9354
struct st_mysql_sys_var* var, /* in: pointer to
9553
THD* thd, /*!< in: thread handle */
9554
struct st_mysql_sys_var* var, /*!< in: pointer to
9355
9555
system variable */
9356
void* var_ptr, /* out: where the
9556
void* var_ptr, /*!< out: where the
9357
9557
formal string goes */
9358
const void* save) /* in: immediate result
9558
const void* save) /*!< in: immediate result
9359
9559
from check function */
9561
const char* format_name_in;
9562
const char** format_name_out;
9363
9565
ut_a(save != NULL);
9364
9566
ut_a(var_ptr != NULL);
9366
format_id = *(const uint*) save;
9568
format_name_in = *static_cast<const char*const*>(save);
9570
if (!format_name_in) {
9575
format_id = innobase_file_format_name_lookup(format_name_in);
9577
if (format_id > DICT_TF_FORMAT_MAX) {
9578
/* DEFAULT is "on", which is invalid at runtime. */
9579
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
9581
"Ignoring SET innodb_file_format=%s",
9586
format_name_out = static_cast<const char**>(var_ptr);
9368
9588
/* Update the max format id in the system tablespace. */
9369
if (trx_sys_file_format_max_set(format_id, (const char**) var_ptr)) {
9589
if (trx_sys_file_format_max_set(format_id, format_name_out)) {
9370
9590
ut_print_timestamp(stderr);
9371
9591
fprintf(stderr,
9372
9592
" [Info] InnoDB: the file format in the system "
9373
"tablespace is now set to %s.\n", *(char**) var_ptr);
9593
"tablespace is now set to %s.\n", *format_name_out);
9377
/********************************************************************
9597
/****************************************************************//**
9378
9598
Update the system variable innodb_adaptive_hash_index using the "saved"
9379
9599
value. This function is registered as a callback with MySQL. */
9382
9602
innodb_adaptive_hash_index_update(
9383
9603
/*==============================*/
9384
THD* thd, /* in: thread handle */
9385
struct st_mysql_sys_var* var, /* in: pointer to
9604
THD* thd, /*!< in: thread handle */
9605
struct st_mysql_sys_var* var, /*!< in: pointer to
9386
9606
system variable */
9387
void* var_ptr, /* out: where the
9607
void* var_ptr, /*!< out: where the
9388
9608
formal string goes */
9389
const void* save) /* in: immediate result
9609
const void* save) /*!< in: immediate result
9390
9610
from check function */
9392
9612
if (*(my_bool*) save) {
9399
/*****************************************************************
9619
/*************************************************************//**
9400
9620
Check if it is a valid value of innodb_change_buffering. This function is
9401
registered as a callback with MySQL. */
9621
registered as a callback with MySQL.
9622
@return 0 for valid innodb_change_buffering */
9404
9625
innodb_change_buffering_validate(
9405
9626
/*=============================*/
9407
innodb_change_buffering */
9408
THD* thd, /* in: thread handle */
9409
struct st_mysql_sys_var* var, /* in: pointer to system
9627
THD* thd, /*!< in: thread handle */
9628
struct st_mysql_sys_var* var, /*!< in: pointer to system
9411
void* save, /* out: immediate result
9630
void* save, /*!< out: immediate result
9412
9631
for update function */
9413
struct st_mysql_value* value) /* in: incoming string */
9632
struct st_mysql_value* value) /*!< in: incoming string */
9415
9634
const char* change_buffering_input;
9416
9635
char buff[STRING_BUFFER_USUAL_SIZE];
9441
/********************************************************************
9660
/****************************************************************//**
9442
9661
Update the system variable innodb_change_buffering using the "saved"
9443
9662
value. This function is registered as a callback with MySQL. */
9446
9665
innodb_change_buffering_update(
9447
9666
/*===========================*/
9448
THD* thd, /* in: thread handle */
9449
struct st_mysql_sys_var* var, /* in: pointer to
9667
THD* thd, /*!< in: thread handle */
9668
struct st_mysql_sys_var* var, /*!< in: pointer to
9450
9669
system variable */
9451
void* var_ptr, /* out: where the
9670
void* var_ptr, /*!< out: where the
9452
9671
formal string goes */
9453
const void* save) /* in: immediate result
9672
const void* save) /*!< in: immediate result
9454
9673
from check function */
9456
9675
ut_a(var_ptr != NULL);
9559
9783
static MYSQL_SYSVAR_ULONG(max_dirty_pages_pct, srv_max_buf_pool_modified_pct,
9560
9784
PLUGIN_VAR_RQCMDARG,
9561
9785
"Percentage of dirty pages allowed in bufferpool.",
9562
NULL, NULL, 90, 0, 100, 0);
9786
NULL, NULL, 75, 0, 99, 0);
9788
static MYSQL_SYSVAR_BOOL(adaptive_flushing, srv_adaptive_flushing,
9789
PLUGIN_VAR_NOCMDARG,
9790
"Attempt flushing dirty pages to avoid IO bursts at checkpoints.",
9564
9793
static MYSQL_SYSVAR_ULONG(max_purge_lag, srv_max_purge_lag,
9565
9794
PLUGIN_VAR_RQCMDARG,
9611
9840
static MYSQL_SYSVAR_LONGLONG(buffer_pool_size, innobase_buffer_pool_size,
9612
9841
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
9613
9842
"The size of the memory buffer InnoDB uses to cache data and indexes of its tables.",
9614
NULL, NULL, 8*1024*1024L, 5*1024*1024L, LONGLONG_MAX, 1024*1024L);
9843
NULL, NULL, 128*1024*1024L, 5*1024*1024L, LONGLONG_MAX, 1024*1024L);
9616
static MYSQL_SYSVAR_ULONG(commit_concurrency, srv_commit_concurrency,
9845
static MYSQL_SYSVAR_ULONG(commit_concurrency, innobase_commit_concurrency,
9617
9846
PLUGIN_VAR_RQCMDARG,
9618
9847
"Helps in performance tuning in heavily concurrent environments.",
9619
NULL, NULL, 0, 0, 1000, 0);
9848
innobase_commit_concurrency_validate, NULL, 0, 0, 1000, 0);
9621
9850
static MYSQL_SYSVAR_ULONG(concurrency_tickets, srv_n_free_tickets_to_enter,
9622
9851
PLUGIN_VAR_RQCMDARG,
9628
9857
"Number of file I/O threads in InnoDB.",
9629
9858
NULL, NULL, 4, 4, 64, 0);
9860
static MYSQL_SYSVAR_ULONG(read_io_threads, innobase_read_io_threads,
9861
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
9862
"Number of background read I/O threads in InnoDB.",
9863
NULL, NULL, 4, 1, 64, 0);
9865
static MYSQL_SYSVAR_ULONG(write_io_threads, innobase_write_io_threads,
9866
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
9867
"Number of background write I/O threads in InnoDB.",
9868
NULL, NULL, 4, 1, 64, 0);
9631
9870
static MYSQL_SYSVAR_LONG(force_recovery, innobase_force_recovery,
9632
9871
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
9633
9872
"Helps to save your data in case the disk image of the database becomes corrupt.",
9661
9900
static MYSQL_SYSVAR_ULONG(sync_spin_loops, srv_n_spin_wait_rounds,
9662
9901
PLUGIN_VAR_RQCMDARG,
9663
"Count of spin-loop rounds in InnoDB mutexes",
9664
NULL, NULL, 20L, 0L, ~0L, 0);
9902
"Count of spin-loop rounds in InnoDB mutexes (30 by default)",
9903
NULL, NULL, 30L, 0L, ~0L, 0);
9905
static MYSQL_SYSVAR_ULONG(spin_wait_delay, srv_spin_wait_delay,
9906
PLUGIN_VAR_OPCMDARG,
9907
"Maximum delay between polling for a spin lock (6 by default)",
9908
NULL, NULL, 6L, 0L, ~0L, 0);
9666
9910
static MYSQL_SYSVAR_ULONG(thread_concurrency, srv_thread_concurrency,
9667
9911
PLUGIN_VAR_RQCMDARG,
9754
10008
MYSQL_SYSVAR(version),
9755
10009
MYSQL_SYSVAR(use_sys_malloc),
9756
10010
MYSQL_SYSVAR(change_buffering),
10011
MYSQL_SYSVAR(read_ahead_threshold),
10012
MYSQL_SYSVAR(io_capacity),
9760
#ifdef MYSQL_DYNAMIC_PLUGIN
9761
struct st_mysql_sys_var
9763
MYSQL_PLUGIN_VAR_HEADER;
9767
struct param_mapping
9769
const char* server; /* Parameter name in the server. */
9770
const char* plugin; /* Paramater name in the plugin. */
9773
/********************************************************************
9774
Match the parameters from the static and dynamic versions. */
9777
innobase_match_parameter(
9778
/*=====================*/
9779
/* out: true if names match */
9780
const char* from_server, /* in: variable name from server */
9781
const char* from_plugin) /* in: variable name from plugin */
9783
static const param_mapping param_map[] = {
9784
{"use_adaptive_hash_indexes", "adaptive_hash_index"}
9787
if (strcmp(from_server, from_plugin) == 0) {
9791
const param_mapping* param = param_map;
9792
int n_elems = sizeof(param_map) / sizeof(param_map[0]);
9794
for (int i = 0; i < n_elems; ++i, ++param) {
9796
if (strcmp(param->server, from_server) == 0
9797
&& strcmp(param->plugin, from_plugin) == 0) {
9806
/********************************************************************
9807
Copy InnoDB system variables from the static InnoDB to the dynamic
9811
innodb_plugin_init(void)
9812
/*====================*/
9813
/* out: TRUE if the dynamic InnoDB plugin should start */
9815
#if !MYSQL_STORAGE_ENGINE_PLUGIN
9816
#error "MYSQL_STORAGE_ENGINE_PLUGIN must be nonzero."
9819
/* Copy the system variables. */
9821
struct st_mysql_plugin* builtin;
9822
struct st_mysql_sys_var** sta; /* static parameters */
9823
struct st_mysql_sys_var** dyn; /* dynamic parameters */
9826
if (!builtin_innobase_plugin_ptr) {
9831
builtin = builtin_innobase_plugin_ptr;
9833
switch (builtin_innobase_plugin) {
9836
case MYSQL_STORAGE_ENGINE_PLUGIN:
9842
builtin = (struct st_mysql_plugin*) &builtin_innobase_plugin;
9845
for (sta = builtin->system_vars; *sta != NULL; sta++) {
9847
for (dyn = innobase_system_variables; *dyn != NULL; dyn++) {
9849
/* do not copy session variables */
9850
if (((*sta)->flags | (*dyn)->flags)
9851
& PLUGIN_VAR_THDLOCAL) {
9855
if (innobase_match_parameter((*sta)->name,
9858
/* found the corresponding parameter */
9860
/* check if the flags are the same,
9861
ignoring differences in the READONLY or
9863
e.g. we are not copying string variable to
9864
an integer one, but we do not care if it is
9865
readonly in the static and not in the
9867
if (((*sta)->flags ^ (*dyn)->flags)
9868
& ~(PLUGIN_VAR_READONLY
9869
| PLUGIN_VAR_NOSYSVAR)) {
9872
"InnoDB: %s in static InnoDB "
9873
"(flags=0x%x) differs from "
9874
"%s in dynamic InnoDB "
9876
(*sta)->name, (*sta)->flags,
9877
(*dyn)->name, (*dyn)->flags);
9879
/* we could break; here leaving this
9880
parameter uncopied */
9884
/* assign the value of the static parameter
9885
to the dynamic one, according to their type */
9887
#define COPY_VAR(label, type) \
9889
*(type*)(*dyn)->value = *(type*)(*sta)->value; \
9892
switch ((*sta)->flags
9894
| PLUGIN_VAR_UNSIGNED)) {
9896
COPY_VAR(PLUGIN_VAR_BOOL, char);
9897
COPY_VAR(PLUGIN_VAR_INT, int);
9898
COPY_VAR(PLUGIN_VAR_LONG, long);
9899
COPY_VAR(PLUGIN_VAR_LONGLONG, long long);
9900
COPY_VAR(PLUGIN_VAR_STR, char*);
9904
"InnoDB: unknown flags "
9906
(*sta)->flags, (*sta)->name);
9909
/* Make the static InnoDB variable point to
9911
(*sta)->value = (*dyn)->value;
9920
#endif /* MYSQL_DYNAMIC_PLUGIN */
9922
10016
mysql_declare_plugin(innobase)
9924
10018
MYSQL_STORAGE_ENGINE_PLUGIN,
9943
10037
i_s_innodb_cmpmem_reset
9944
10038
mysql_declare_plugin_end;
10040
/** @brief Initialize the default value of innodb_commit_concurrency.
10042
Once InnoDB is running, the innodb_commit_concurrency must not change
10043
from zero to nonzero. (Bug #42101)
10045
The initial default value is 0, and without this extra initialization,
10046
SET GLOBAL innodb_commit_concurrency=DEFAULT would set the parameter
10047
to 0, even if it was initially set to nonzero at the command line
10048
or configuration file. */
10051
innobase_commit_concurrency_init_default(void)
10052
/*==========================================*/
10054
MYSQL_SYSVAR_NAME(commit_concurrency).def_val
10055
= innobase_commit_concurrency;
9946
10058
#ifdef UNIV_COMPILE_TEST_FUNCS
9948
10060
typedef struct innobase_convert_name_test_struct {