~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/handler/ha_innodb.cc

  • Committer: Monty Taylor
  • Date: 2009-08-12 06:25:19 UTC
  • mto: (1114.1.1 innodb-plugin-merge)
  • mto: This revision was merged to the branch mainline in revision 1183.
  • Revision ID: mordred@inaugust.com-20090812062519-cij02mrrunvnxblt
Tags: innodb-plugin-1.0.4
InnoDB Plugin 1.0.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************************
2
2
 
3
3
Copyright (c) 2000, 2009, MySQL AB & Innobase Oy. All Rights Reserved.
4
 
Copyright (c) 2008, Google Inc.
 
4
Copyright (c) 2008, 2009 Google Inc.
5
5
 
6
6
Portions of this file contain modifications contributed and copyrighted by
7
7
Google, Inc. Those modifications are gratefully acknowledged and are described
22
22
Place, Suite 330, Boston, MA 02111-1307 USA
23
23
 
24
24
*****************************************************************************/
 
25
/***********************************************************************
 
26
 
 
27
Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
 
28
Copyright (c) 2009, Percona Inc.
 
29
 
 
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
 
35
COPYING.Percona.
 
36
 
 
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.
 
40
 
 
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.
 
45
 
 
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
 
49
 
 
50
***********************************************************************/
25
51
 
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>
43
69
 
 
70
/** @file ha_innodb.cc */
 
71
 
44
72
/* Include necessary InnoDB headers */
45
73
extern "C" {
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"
 
74
#include "univ.i"
 
75
#include "btr0sea.h"
 
76
#include "os0file.h"
 
77
#include "os0thread.h"
 
78
#include "srv0start.h"
 
79
#include "srv0srv.h"
 
80
#include "trx0roll.h"
 
81
#include "trx0trx.h"
 
82
#include "trx0sys.h"
 
83
#include "mtr0mtr.h"
 
84
#include "row0ins.h"
 
85
#include "row0mysql.h"
 
86
#include "row0sel.h"
 
87
#include "row0upd.h"
 
88
#include "log0log.h"
 
89
#include "lock0lock.h"
 
90
#include "dict0crea.h"
 
91
#include "btr0cur.h"
 
92
#include "btr0btr.h"
 
93
#include "fsp0fsp.h"
 
94
#include "sync0sync.h"
 
95
#include "fil0fil.h"
 
96
#include "trx0xa.h"
 
97
#include "row0merge.h"
 
98
#include "thr0loc.h"
 
99
#include "dict0boot.h"
 
100
#include "ha_prototypes.h"
 
101
#include "ut0mem.h"
 
102
#include "ibuf0ibuf.h"
75
103
}
76
104
 
77
105
#include "ha_innodb.h"
112
140
# define EQ_CURRENT_THD(thd) ((thd) == current_thd)
113
141
#endif /* MYSQL_DYNAMIC_PLUGIN && __WIN__ */
114
142
 
115
 
#ifdef MYSQL_DYNAMIC_PLUGIN
116
 
/* These must be weak global variables in the dynamic plugin. */
117
 
struct handlerton* innodb_hton_ptr;
118
 
#ifdef __WIN__
119
 
struct st_mysql_plugin* builtin_innobase_plugin_ptr;
120
 
#else
121
 
int builtin_innobase_plugin;
122
 
#endif /* __WIN__ */
123
 
/********************************************************************
124
 
Copy InnoDB system variables from the static InnoDB to the dynamic
125
 
plugin. */
126
 
static
127
 
bool
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;
135
144
 
136
145
static const long AUTOINC_OLD_STYLE_LOCKING = 0;
137
146
static const long AUTOINC_NEW_STYLE_LOCKING = 1;
142
151
        innobase_additional_mem_pool_size, innobase_file_io_threads,
143
152
        innobase_force_recovery, innobase_open_files,
144
153
        innobase_autoinc_lock_mode;
 
154
static ulong innobase_commit_concurrency = 0;
 
155
static ulong innobase_read_io_threads;
 
156
static ulong innobase_write_io_threads;
145
157
 
146
158
static long long innobase_buffer_pool_size, innobase_log_file_size;
147
159
 
216
228
                                        TABLE_SHARE *table,
217
229
                                        MEM_ROOT *mem_root);
218
230
 
219
 
/****************************************************************
220
 
Validate the file format name and return its corresponding id. */
 
231
/** @brief Initialize the default value of innodb_commit_concurrency.
 
232
 
 
233
Once InnoDB is running, the innodb_commit_concurrency must not change
 
234
from zero to nonzero. (Bug #42101)
 
235
 
 
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. */
 
240
static
 
241
void
 
242
innobase_commit_concurrency_init_default(void);
 
243
/*==========================================*/
 
244
 
 
245
/************************************************************//**
 
246
Validate the file format name and return its corresponding id.
 
247
@return valid file format id */
221
248
static
222
249
uint
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
227
253
                                                name */
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" */
231
258
static
232
259
bool
233
260
innobase_file_format_check_on_off(
234
261
/*==============================*/
235
 
                                                /* out: true if one of 
236
 
                                                "on" or "off" */
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 */
241
267
static
242
268
bool
243
269
innobase_file_format_check_validate(
244
270
/*================================*/
245
 
                                                /* out: true if valid
246
 
                                                config value */
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. */
250
274
static
251
275
uint
255
279
 
256
280
static const char innobase_hton_name[]= "InnoDB";
257
281
 
 
282
/*************************************************************//**
 
283
Check for a valid value of innobase_commit_concurrency.
 
284
@return 0 for valid innodb_commit_concurrency */
 
285
static
 
286
int
 
287
innobase_commit_concurrency_validate(
 
288
/*=================================*/
 
289
        THD*                            thd,    /*!< in: thread handle */
 
290
        struct st_mysql_sys_var*        var,    /*!< in: pointer to system
 
291
                                                variable */
 
292
        void*                           save,   /*!< out: immediate result
 
293
                                                for update function */
 
294
        struct st_mysql_value*          value)  /*!< in: incoming string */
 
295
{
 
296
        long long       intbuf;
 
297
        ulong           commit_concurrency;
 
298
 
 
299
        DBUG_ENTER("innobase_commit_concurrency_validate");
 
300
 
 
301
        if (value->val_int(value, &intbuf)) {
 
302
                /* The value is NULL. That is invalid. */
 
303
                DBUG_RETURN(1);
 
304
        }
 
305
 
 
306
        *reinterpret_cast<ulong*>(save) = commit_concurrency
 
307
                = static_cast<ulong>(intbuf);
 
308
 
 
309
        /* Allow the value to be updated, as long as it remains zero
 
310
        or nonzero. */
 
311
        DBUG_RETURN(!(!commit_concurrency == !innobase_commit_concurrency));
 
312
}
 
313
 
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);
282
338
}
283
339
 
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 */
286
343
static
287
344
int
288
345
innobase_xa_prepare(
289
346
/*================*/
290
 
                        /* out: 0 or error number */
291
 
        handlerton* hton,
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
 
350
                                be prepared */
 
351
        bool            all);   /*!< in: TRUE - commit transaction
 
352
                                FALSE - the current SQL statement
 
353
                                ended */
 
354
/*******************************************************************//**
 
355
This function is used to recover X/Open XA distributed transactions.
 
356
@return number of prepared transactions stored in xid_list */
298
357
static
299
358
int
300
359
innobase_xa_recover(
301
360
/*================*/
302
 
                                /* out: number of prepared transactions
303
 
                                stored in xid_list */
304
 
        handlerton* hton,
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 */
310
368
static
311
369
int
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 */
320
378
static
321
379
int
322
380
innobase_rollback_by_xid(
323
381
/*=====================*/
324
 
                        /* out: 0 or error number */
325
 
        handlerton* hton,
326
 
        XID     *xid);  /* in: X/Open XA transaction identification */
327
 
/***********************************************************************
 
382
        handlerton*     hton,   /*!< in: InnoDB handlerton */
 
383
        XID*            xid);   /*!< in: X/Open XA transaction
 
384
                                identification */
 
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
331
 
using a cursor. */
 
389
using a cursor.
 
390
@return pointer to cursor view or NULL */
332
391
static
333
392
void*
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
346
404
innobase_set_cursor_view(
347
405
/*=====================*/
348
406
        handlerton* hton,
349
 
        THD*    thd,    /* in: user thread handle */
350
 
        void*   curview);/* in: Consistent cursor view to be set */
351
 
/***********************************************************************
 
407
        THD*    thd,    /*!< in: user thread handle */
 
408
        void*   curview);/*!< in: Consistent cursor view to be set */
 
409
/*******************************************************************//**
352
410
Close the given consistent cursor view of a transaction and restore
353
411
global read view to a transaction read view. Transaction is created if the
354
412
corresponding MySQL thread still lacks one. */
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. */
364
422
static
365
423
void
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. */
376
433
static
377
434
int
378
435
innobase_end(handlerton *hton, ha_panic_function type);
379
436
 
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
384
 
have one. */
 
441
have one.
 
442
@return 0 */
385
443
static
386
444
int
387
445
innobase_start_trx_and_assign_read_view(
388
446
/*====================================*/
389
 
                        /* out: 0 */
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 */
396
454
static
397
455
bool
398
456
innobase_flush_logs(
399
457
/*================*/
400
 
                                /* out: TRUE if error */
401
 
        handlerton*     hton);  /* in: InnoDB handlerton */
 
458
        handlerton*     hton);  /*!< in: InnoDB handlerton */
402
459
 
403
 
/****************************************************************************
 
460
/************************************************************************//**
404
461
Implements the SHOW INNODB STATUS command. Sends the output of the InnoDB
405
462
Monitor to the client. */
406
463
static
407
464
bool
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);
413
470
static
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);
417
474
 
418
 
/*********************************************************************
 
475
/*****************************************************************//**
419
476
Commits a transaction in an InnoDB database. */
420
477
static
421
478
void
422
479
innobase_commit_low(
423
480
/*================*/
424
 
        trx_t*  trx);   /* in: transaction handle */
 
481
        trx_t*  trx);   /*!< in: transaction handle */
425
482
 
426
483
static SHOW_VAR innodb_status_variables[]= {
427
484
  {"buffer_pool_pages_data",
519
576
 
520
577
/* General functions */
521
578
 
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
529
587
ibool
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*) */
534
591
{
535
592
        return((ibool) thd_slave_thread((THD*) thd));
536
593
}
537
594
 
538
 
/**********************************************************************
 
595
/******************************************************************//**
539
596
Save some CPU by testing the value of srv_thread_concurrency in inline
540
597
functions. */
541
598
static inline
542
599
void
543
600
innodb_srv_conc_enter_innodb(
544
601
/*=========================*/
545
 
        trx_t*  trx)    /* in: transaction handle */
 
602
        trx_t*  trx)    /*!< in: transaction handle */
546
603
{
547
604
        if (UNIV_LIKELY(!srv_thread_concurrency)) {
548
605
 
552
609
        srv_conc_enter_innodb(trx);
553
610
}
554
611
 
555
 
/**********************************************************************
 
612
/******************************************************************//**
556
613
Save some CPU by testing the value of srv_thread_concurrency in inline
557
614
functions. */
558
615
static inline
559
616
void
560
617
innodb_srv_conc_exit_innodb(
561
618
/*========================*/
562
 
        trx_t*  trx)    /* in: transaction handle */
 
619
        trx_t*  trx)    /*!< in: transaction handle */
563
620
{
564
621
        if (UNIV_LIKELY(!trx->declared_to_be_inside_innodb)) {
565
622
 
569
626
        srv_conc_exit_innodb(trx);
570
627
}
571
628
 
572
 
/**********************************************************************
 
629
/******************************************************************//**
573
630
Releases possible search latch and InnoDB thread FIFO ticket. These should
574
631
be released at each SQL statement end, and also when mysqld passes the
575
632
control to the client. It does no harm to release these also in the middle
578
635
void
579
636
innobase_release_stat_resources(
580
637
/*============================*/
581
 
        trx_t*  trx)    /* in: transaction object */
 
638
        trx_t*  trx)    /*!< in: transaction object */
582
639
{
583
640
        if (trx->has_search_latch) {
584
641
                trx_search_latch_release_if_reserved(trx);
591
648
        }
592
649
}
593
650
 
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
600
658
ibool
601
659
thd_has_edited_nontrans_tables(
602
660
/*===========================*/
603
 
                        /* out: true if non-transactional tables have
604
 
                        been edited */
605
 
        void*   thd)    /* in: thread handle (THD*) */
 
661
        void*   thd)    /*!< in: thread handle (THD*) */
606
662
{
607
663
        return((ibool) thd_non_transactional_update((THD*) thd));
608
664
}
609
665
 
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
613
670
ibool
614
671
thd_is_select(
615
672
/*==========*/
616
 
                                /* out: true if thd is executing SELECT */
617
 
        const void*     thd)    /* in: thread handle (THD*) */
 
673
        const void*     thd)    /*!< in: thread handle (THD*) */
618
674
{
619
675
        return(thd_sql_command((const THD*) thd) == SQLCOM_SELECT);
620
676
}
621
677
 
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
626
683
ibool
627
684
thd_supports_xa(
628
685
/*============*/
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 */
632
688
{
633
689
        return(THDVAR((THD*) thd, support_xa));
634
690
}
635
691
 
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
639
696
ulong
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 */
645
701
{
646
702
        /* According to <mysql/plugin.h>, passing thd == NULL
648
704
        return(THDVAR((THD*) thd, lock_wait_timeout));
649
705
}
650
706
 
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 */
653
710
static inline
654
711
trx_t*&
655
712
thd_to_trx(
656
713
/*=======*/
657
 
                        /* out: reference to transaction pointer */
658
 
        THD*    thd)    /* in: MySQL thread */
 
714
        THD*    thd)    /*!< in: MySQL thread */
659
715
{
660
716
        return(*(trx_t**) thd_ha_data(thd, innodb_hton_ptr));
661
717
}
662
718
 
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.
 
723
@return 0 */
667
724
static
668
725
int
669
726
innobase_release_temporary_latches(
670
727
/*===============================*/
671
 
                                /* out: 0 */
672
 
        handlerton*     hton,   /* in: handlerton */
673
 
        THD*            thd)    /* in: MySQL thread */
 
728
        handlerton*     hton,   /*!< in: handlerton */
 
729
        THD*            thd)    /*!< in: MySQL thread */
674
730
{
675
731
        trx_t*  trx;
676
732
 
689
745
        return(0);
690
746
}
691
747
 
692
 
/************************************************************************
 
748
/********************************************************************//**
693
749
Increments innobase_active_counter and every INNOBASE_WAKE_INTERVALth
694
750
time calls srv_active_wake_master_thread. This function should be used
695
751
when a single database operation may introduce a small need for
706
762
        }
707
763
}
708
764
 
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
714
771
int
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 */
721
777
{
722
778
        switch (error) {
723
779
        case DB_SUCCESS:
733
789
        case DB_FOREIGN_DUPLICATE_KEY:
734
790
                return(HA_ERR_FOREIGN_DUPLICATE_KEY);
735
791
 
 
792
        case DB_MISSING_HISTORY:
 
793
                return(HA_ERR_TABLE_DEF_CHANGED);
 
794
 
736
795
        case DB_RECORD_NOT_FOUND:
737
796
                return(HA_ERR_NO_ACTIVE_RECORD);
738
797
 
827
886
        }
828
887
}
829
888
 
830
 
/*****************************************************************
 
889
/*************************************************************//**
831
890
If you want to print a thd that is not associated with the current thread,
832
891
you must call this function before reserving the InnoDB kernel_mutex, to
833
892
protect MySQL from setting thd->query NULL. If you print a thd of the current
843
902
        VOID(pthread_mutex_lock(&LOCK_thread_count));
844
903
}
845
904
 
846
 
/*****************************************************************
 
905
/*************************************************************//**
847
906
Releases the mutex reserved by innobase_mysql_prepare_print_arbitrary_thd().
848
907
In the InnoDB latching order, the mutex sits right above the
849
908
kernel_mutex.  In debug builds, we assert that the kernel_mutex is
857
916
        VOID(pthread_mutex_unlock(&LOCK_thread_count));
858
917
}
859
918
 
860
 
/*****************************************************************
 
919
/*************************************************************//**
861
920
Prints info of a THD object (== user session thread) to the given file. */
862
921
extern "C" UNIV_INTERN
863
922
void
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 */
870
929
{
871
930
        char    buffer[1024];
875
934
        putc('\n', f);
876
935
}
877
936
 
878
 
/**********************************************************************
 
937
/******************************************************************//**
879
938
Get the variable length bounds of the given character set. */
880
939
extern "C" UNIV_INTERN
881
940
void
882
941
innobase_get_cset_width(
883
942
/*====================*/
884
 
        ulint   cset,           /* in: MySQL charset-collation code */
885
 
        ulint*  mbminlen,       /* out: minimum length of a char (in bytes) */
886
 
        ulint*  mbmaxlen)       /* out: maximum length of a char (in bytes) */
 
943
        ulint   cset,           /*!< in: MySQL charset-collation code */
 
944
        ulint*  mbminlen,       /*!< out: minimum length of a char (in bytes) */
 
945
        ulint*  mbmaxlen)       /*!< out: maximum length of a char (in bytes) */
887
946
{
888
947
        CHARSET_INFO*   cs;
889
948
        ut_ad(cset < 256);
900
959
        }
901
960
}
902
961
 
903
 
/**********************************************************************
 
962
/******************************************************************//**
904
963
Converts an identifier to a table name. */
905
964
extern "C" UNIV_INTERN
906
965
void
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 */
913
972
{
914
973
        uint    errors;
915
974
 
916
975
        strconvert(cs, from, &my_charset_filename, to, (uint) len, &errors);
917
976
}
918
977
 
919
 
/**********************************************************************
 
978
/******************************************************************//**
920
979
Converts an identifier to UTF-8. */
921
980
extern "C" UNIV_INTERN
922
981
void
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 */
929
988
{
930
989
        uint    errors;
931
990
 
932
991
        strconvert(cs, from, system_charset_info, to, (uint) len, &errors);
933
992
}
934
993
 
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
938
998
int
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 */
944
1003
{
945
1004
        return(my_strcasecmp(system_charset_info, a, b));
946
1005
}
947
1006
 
948
 
/**********************************************************************
 
1007
/******************************************************************//**
949
1008
Makes all characters in a NUL-terminated UTF-8 string lower case. */
950
1009
extern "C" UNIV_INTERN
951
1010
void
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 */
955
1014
{
956
1015
        my_casedn_str(system_charset_info, a);
957
1016
}
958
1017
 
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 */
967
1026
{
968
1027
        return(thd_charset((THD*) mysql_thd));
969
1028
}
970
1029
 
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) */
975
1034
extern "C"
976
1035
void __cdecl
977
1036
_dosmaperr(
978
 
        unsigned long); /* in: OS error value */
 
1037
        unsigned long); /*!< in: OS error value */
979
1038
 
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
983
1043
int
984
1044
innobase_mysql_tmpfile(void)
985
1045
/*========================*/
986
 
                        /* out: temporary file descriptor, or < 0 on error */
987
1046
{
988
1047
        int     fd;                             /* handle of opened file */
989
1048
        HANDLE  osfh;                           /* OS handle of opened file */
1061
1120
        DBUG_RETURN(fd);
1062
1121
}
1063
1122
#else
1064
 
/*************************************************************************
1065
 
Creates a temporary file. */
 
1123
/*********************************************************************//**
 
1124
Creates a temporary file.
 
1125
@return temporary file descriptor, or < 0 on error */
1066
1126
extern "C" UNIV_INTERN
1067
1127
int
1068
1128
innobase_mysql_tmpfile(void)
1069
1129
/*========================*/
1070
 
                        /* out: temporary file descriptor, or < 0 on error */
1071
1130
{
1072
1131
        int     fd2 = -1;
1073
1132
        File    fd = mysql_tmpfile("ib");
1094
1153
}
1095
1154
#endif /* defined (__WIN__) && defined (MYSQL_DYNAMIC_PLUGIN) */
1096
1155
 
1097
 
/*************************************************************************
1098
 
Wrapper around MySQL's copy_and_convert function, see it for
1099
 
documentation. */
 
1156
/*********************************************************************//**
 
1157
Wrapper around MySQL's copy_and_convert function.
 
1158
@return number of bytes copied to 'to' */
1100
1159
extern "C" UNIV_INTERN
1101
1160
ulint
1102
1161
innobase_convert_string(
1103
1162
/*====================*/
1104
 
        void*           to,
1105
 
        ulint           to_length,
1106
 
        CHARSET_INFO*   to_cs,
1107
 
        const void*     from,
1108
 
        ulint           from_length,
1109
 
        CHARSET_INFO*   from_cs,
1110
 
        uint*           errors)
 
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 */
1111
1172
{
1112
1173
  return(copy_and_convert((char*)to, (uint32) to_length, to_cs,
1113
1174
                          (const char*)from, (uint32) from_length, from_cs,
1114
1175
                          errors));
1115
1176
}
1116
1177
 
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'). */
 
1185
terminating NUL).
 
1186
@return number of bytes that were written */
1125
1187
extern "C" UNIV_INTERN
1126
1188
ulint
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
1133
1193
                                        in bytes */
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
1137
1197
                                        in bytes */
1138
1198
{
1139
1199
        /* XXX we use a hard limit instead of allocating
1153
1213
        return(ut_str_sql_format(buf_tmp, buf_tmp_used, buf, buf_size));
1154
1214
}
1155
1215
 
1156
 
/*************************************************************************
 
1216
/*********************************************************************//**
1157
1217
Compute the next autoinc value.
1158
1218
 
1159
1219
For MySQL replication the autoincrement values can be partitioned among
1169
1229
 
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 */
1173
1234
static
1174
1235
ulonglong
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 */
1182
1242
{
1183
1243
        ulonglong       next_value;
1184
1244
 
1236
1296
        return(next_value);
1237
1297
}
1238
1298
 
1239
 
/*************************************************************************
 
1299
/*********************************************************************//**
1240
1300
Initializes some fields in an InnoDB transaction object. */
1241
1301
static
1242
1302
void
1243
1303
innobase_trx_init(
1244
1304
/*==============*/
1245
 
        THD*    thd,    /* in: user thread handle */
1246
 
        trx_t*  trx)    /* in/out: InnoDB transaction handle */
 
1305
        THD*    thd,    /*!< in: user thread handle */
 
1306
        trx_t*  trx)    /*!< in/out: InnoDB transaction handle */
1247
1307
{
1248
1308
        DBUG_ENTER("innobase_trx_init");
1249
1309
        DBUG_ASSERT(EQ_CURRENT_THD(thd));
1258
1318
        DBUG_VOID_RETURN;
1259
1319
}
1260
1320
 
1261
 
/*************************************************************************
1262
 
Allocates an InnoDB transaction for a MySQL handler object. */
 
1321
/*********************************************************************//**
 
1322
Allocates an InnoDB transaction for a MySQL handler object.
 
1323
@return InnoDB transaction handle */
1263
1324
extern "C" UNIV_INTERN
1264
1325
trx_t*
1265
1326
innobase_trx_allocate(
1266
1327
/*==================*/
1267
 
                        /* out: InnoDB transaction handle */
1268
 
        THD*    thd)    /* in: user thread handle */
 
1328
        THD*    thd)    /*!< in: user thread handle */
1269
1329
{
1270
1330
        trx_t*  trx;
1271
1331
 
1283
1343
        DBUG_RETURN(trx);
1284
1344
}
1285
1345
 
1286
 
/*************************************************************************
 
1346
/*********************************************************************//**
1287
1347
Gets the InnoDB transaction handle for a MySQL handler object, creates
1288
1348
an InnoDB transaction struct if the corresponding MySQL thread struct still
1289
 
lacks one. */
 
1349
lacks one.
 
1350
@return InnoDB transaction handle */
1290
1351
static
1291
1352
trx_t*
1292
1353
check_trx_exists(
1293
1354
/*=============*/
1294
 
                        /* out: InnoDB transaction handle */
1295
 
        THD*    thd)    /* in: user thread handle */
 
1355
        THD*    thd)    /*!< in: user thread handle */
1296
1356
{
1297
1357
        trx_t*& trx = thd_to_trx(thd);
1298
1358
 
1311
1371
}
1312
1372
 
1313
1373
 
1314
 
/*************************************************************************
 
1374
/*********************************************************************//**
1315
1375
Construct ha_innobase handler. */
1316
1376
UNIV_INTERN
1317
1377
ha_innobase::ha_innobase(handlerton *hton, TABLE_SHARE *table_arg)
1329
1389
  num_write_row(0)
1330
1390
{}
1331
1391
 
1332
 
/*************************************************************************
 
1392
/*********************************************************************//**
1333
1393
Destruct ha_innobase handler. */
1334
1394
UNIV_INTERN
1335
1395
ha_innobase::~ha_innobase()
1336
1396
{
1337
1397
}
1338
1398
 
1339
 
/*************************************************************************
 
1399
/*********************************************************************//**
1340
1400
Updates the user_thd field in a handle and also allocates a new InnoDB
1341
1401
transaction handle if needed, and updates the transaction fields in the
1342
1402
prebuilt struct. */
1344
1404
void
1345
1405
ha_innobase::update_thd(
1346
1406
/*====================*/
1347
 
        THD*    thd)    /* in: thd to use the handle */
 
1407
        THD*    thd)    /*!< in: thd to use the handle */
1348
1408
{
1349
1409
        trx_t*          trx;
1350
1410
 
1358
1418
        user_thd = thd;
1359
1419
}
1360
1420
 
1361
 
/*************************************************************************
 
1421
/*********************************************************************//**
1362
1422
Updates the user_thd field in a handle and also allocates a new InnoDB
1363
1423
transaction handle if needed, and updates the transaction fields in the
1364
1424
prebuilt struct. */
1372
1432
        update_thd(thd);
1373
1433
}
1374
1434
 
1375
 
/*************************************************************************
 
1435
/*********************************************************************//**
1376
1436
Registers that InnoDB takes part in an SQL statement, so that MySQL knows to
1377
1437
roll back the statement if the statement results in an error. This MUST be
1378
1438
called for every SQL statement that may be rolled back by MySQL. Calling this
1381
1441
void
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 */
1386
1446
{
1387
1447
        DBUG_ASSERT(hton == innodb_hton_ptr);
1388
1448
        /* Register the statement */
1389
1449
        trans_register_ha(thd, FALSE, hton);
1390
1450
}
1391
1451
 
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
1400
1460
void
1401
1461
innobase_register_trx_and_stmt(
1402
1462
/*===========================*/
1403
 
        handlerton *hton, /* in: Innobase handlerton */
1404
 
        THD*    thd)    /* in: MySQL thd (connection) object */
 
1463
        handlerton *hton, /*!< in: Innobase handlerton */
 
1464
        THD*    thd)    /*!< in: MySQL thd (connection) object */
1405
1465
{
1406
1466
        /* NOTE that actually innobase_register_stmt() registers also
1407
1467
        the transaction in the AUTOCOMMIT=1 mode. */
1458
1518
put restrictions on the use of the query cache.
1459
1519
*/
1460
1520
 
1461
 
/**********************************************************************
 
1521
/******************************************************************//**
1462
1522
The MySQL query cache uses this to check from InnoDB if the query cache at
1463
1523
the moment is allowed to operate on an InnoDB table. The SQL query must
1464
1524
be a non-locking SELECT.
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 */
1479
1542
static
1480
1543
my_bool
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
1489
1548
                                retrieve it */
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
1492
1551
                                name */
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 */
1496
1555
{
1497
1556
        ibool   is_autocommit;
1498
1557
        trx_t*  trx;
1582
1641
        return((my_bool)FALSE);
1583
1642
}
1584
1643
 
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
1590
1647
void
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
1597
 
                                in LOWER CASE! */
1598
 
        ulint   full_name_len)  /* in: full name length where also the null
1599
 
                                chars count */
 
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 */
1600
1659
{
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,
 
1667
                                      full_name,
1609
1668
                                      (uint32) full_name_len,
1610
1669
                                      TRUE);
1611
1670
#endif
1612
1671
}
1613
1672
 
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 */
1617
1677
static
1618
1678
char*
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 */
1629
1688
{
1630
1689
        char nz[NAME_LEN + 1];
1696
1755
        return(buf);
1697
1756
}
1698
1757
 
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
1703
1763
char*
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 */
1714
1773
{
1715
1774
        char*           s       = buf;
1753
1812
 
1754
1813
}
1755
1814
 
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
1759
1819
ibool
1760
1820
trx_is_interrupted(
1761
1821
/*===============*/
1762
 
                        /* out: TRUE if interrupted */
1763
 
        trx_t*  trx)    /* in: transaction */
 
1822
        trx_t*  trx)    /*!< in: transaction */
1764
1823
{
1765
1824
        return(trx && trx->mysql_thd && thd_killed((THD*) trx->mysql_thd));
1766
1825
}
1767
1826
 
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. */
1771
1830
static
1772
1831
void
1773
1832
reset_template(
1774
1833
/*===========*/
1775
 
        row_prebuilt_t* prebuilt)       /* in/out: prebuilt struct */
 
1834
        row_prebuilt_t* prebuilt)       /*!< in/out: prebuilt struct */
1776
1835
{
1777
1836
        prebuilt->keep_other_fields_on_keyread = 0;
1778
1837
        prebuilt->read_just_key = 0;
1779
1838
}
1780
1839
 
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,
1840
1899
        reset_template(prebuilt);
1841
1900
}
1842
1901
 
1843
 
/*************************************************************************
1844
 
Opens an InnoDB database. */
 
1902
/*********************************************************************//**
 
1903
Opens an InnoDB database.
 
1904
@return 0 on success, error code on failure */
1845
1905
static
1846
1906
int
1847
1907
innobase_init(
1848
1908
/*==========*/
1849
 
                        /* out: 0 on success, error code on failure */
1850
 
        void    *p)     /* in: InnoDB handlerton */
 
1909
        void    *p)     /*!< in: InnoDB handlerton */
1851
1910
{
1852
 
        static char     current_dir[3];         /* Set if using current lib */
 
1911
        static char     current_dir[3];         /*!< Set if using current lib */
1853
1912
        int             err;
1854
1913
        bool            ret;
1855
1914
        char            *default_path;
1857
1916
 
1858
1917
        DBUG_ENTER("innobase_init");
1859
1918
        handlerton *innobase_hton= (handlerton *)p;
1860
 
 
1861
 
#ifdef MYSQL_DYNAMIC_PLUGIN
1862
 
        if (!innodb_plugin_init()) {
1863
 
                sql_print_error("InnoDB plugin init failed.");
1864
 
                DBUG_RETURN(-1);
1865
 
        }
1866
 
 
1867
 
        if (innodb_hton_ptr) {
1868
 
                /* Patch the statically linked handlerton and variables */
1869
 
                innobase_hton = innodb_hton_ptr;
1870
 
        }
1871
 
#endif /* MYSQL_DYNAMIC_PLUGIN */
1872
 
 
1873
1919
        innodb_hton_ptr = innobase_hton;
1874
1920
 
1875
1921
        innobase_hton->state = SHOW_OPTION_YES;
2082
2128
                }
2083
2129
        }
2084
2130
 
 
2131
        if (innobase_change_buffering) {
 
2132
                ulint   use;
 
2133
 
 
2134
                for (use = 0;
 
2135
                     use < UT_ARR_SIZE(innobase_change_buffering_values);
 
2136
                     use++) {
 
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;
 
2142
                        }
 
2143
                }
 
2144
 
 
2145
                sql_print_error("InnoDB: invalid value "
 
2146
                                "innodb_file_format_check=%s",
 
2147
                                innobase_change_buffering);
 
2148
                goto mem_free_and_error;
 
2149
        }
 
2150
 
 
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];
2104
2171
        srv_mem_pool_size = (ulint) innobase_additional_mem_pool_size;
2105
2172
 
2106
2173
        srv_n_file_io_threads = (ulint) innobase_file_io_threads;
 
2174
        srv_n_read_io_threads = (ulint) innobase_read_io_threads;
 
2175
        srv_n_write_io_threads = (ulint) innobase_write_io_threads;
2107
2176
 
2108
2177
        srv_force_recovery = (ulint) innobase_force_recovery;
2109
2178
 
2141
2210
        ut_a(0 == strcmp(my_charset_latin1.name, "latin1_swedish_ci"));
2142
2211
        srv_latin1_ordering = my_charset_latin1.sort_order;
2143
2212
 
 
2213
        innobase_commit_concurrency_init_default();
 
2214
 
2144
2215
        /* Since we in this module access directly the fields of a trx
2145
2216
        struct, and due to different headers and flags it might happen that
2146
2217
        mutex_t has a different size in this module and in InnoDB
2175
2246
        DBUG_RETURN(TRUE);
2176
2247
}
2177
2248
 
2178
 
/***********************************************************************
2179
 
Closes an InnoDB database. */
 
2249
/*******************************************************************//**
 
2250
Closes an InnoDB database.
 
2251
@return TRUE if error */
2180
2252
static
2181
2253
int
2182
 
innobase_end(handlerton *hton, ha_panic_function type)
2183
 
/*==============*/
2184
 
                                /* out: TRUE if error */
 
2254
innobase_end(
 
2255
/*=========*/
 
2256
        handlerton*             hton,   /*!< in/out: InnoDB handlerton */
 
2257
        ha_panic_function       type __attribute__((unused)))
 
2258
                                        /*!< in: ha_panic() parameter */
2185
2259
{
2186
2260
        int     err= 0;
2187
2261
 
2215
2289
        DBUG_RETURN(err);
2216
2290
}
2217
2291
 
2218
 
/********************************************************************
 
2292
/****************************************************************//**
2219
2293
Flushes InnoDB logs to disk and makes a checkpoint. Really, a commit flushes
2220
 
the logs, and the name of this function should be innobase_checkpoint. */
 
2294
the logs, and the name of this function should be innobase_checkpoint.
 
2295
@return TRUE if error */
2221
2296
static
2222
2297
bool
2223
 
innobase_flush_logs(handlerton *hton)
2224
 
/*=====================*/
2225
 
                                /* out: TRUE if error */
 
2298
innobase_flush_logs(
 
2299
/*================*/
 
2300
        handlerton*     hton)   /*!< in/out: InnoDB handlerton */
2226
2301
{
2227
2302
        bool    result = 0;
2228
2303
 
2234
2309
        DBUG_RETURN(result);
2235
2310
}
2236
2311
 
2237
 
/********************************************************************
 
2312
/****************************************************************//**
2238
2313
Return alter table flags supported in an InnoDB database. */
2239
2314
static
2240
2315
uint
2249
2324
                | HA_ONLINE_ADD_PK_INDEX_NO_WRITES);
2250
2325
}
2251
2326
 
2252
 
/*********************************************************************
 
2327
/*****************************************************************//**
2253
2328
Commits a transaction in an InnoDB database. */
2254
2329
static
2255
2330
void
2256
2331
innobase_commit_low(
2257
2332
/*================*/
2258
 
        trx_t*  trx)    /* in: transaction handle */
 
2333
        trx_t*  trx)    /*!< in: transaction handle */
2259
2334
{
2260
2335
        if (trx->conc_state == TRX_NOT_STARTED) {
2261
2336
 
2265
2340
        trx_commit_for_mysql(trx);
2266
2341
}
2267
2342
 
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
2272
 
have one. */
 
2347
have one.
 
2348
@return 0 */
2273
2349
static
2274
2350
int
2275
2351
innobase_start_trx_and_assign_read_view(
2276
2352
/*====================================*/
2277
 
                        /* out: 0 */
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 */
2281
2356
{
2282
2357
        trx_t*  trx;
2312
2387
        DBUG_RETURN(0);
2313
2388
}
2314
2389
 
2315
 
/*********************************************************************
 
2390
/*****************************************************************//**
2316
2391
Commits a transaction in an InnoDB database or marks an SQL statement
2317
 
ended. */
 
2392
ended.
 
2393
@return 0 */
2318
2394
static
2319
2395
int
2320
2396
innobase_commit(
2321
2397
/*============*/
2322
 
                        /* out: 0 */
2323
 
        handlerton *hton, /* in: Innodb handlerton */ 
2324
 
        THD*    thd,    /* in: MySQL thread handle of the user for whom
 
2398
        handlerton *hton, /*!< in: Innodb handlerton */ 
 
2399
        THD*    thd,    /*!< in: MySQL thread handle of the user for whom
2325
2400
                        the transaction should be committed */
2326
 
        bool    all)    /* in:  TRUE - commit transaction
 
2401
        bool    all)    /*!< in:        TRUE - commit transaction
2327
2402
                                FALSE - the current SQL statement ended */
2328
2403
{
2329
2404
        trx_t*          trx;
2372
2447
                Note, the position is current because of
2373
2448
                prepare_commit_mutex */
2374
2449
retry:
2375
 
                if (srv_commit_concurrency > 0) {
 
2450
                if (innobase_commit_concurrency > 0) {
2376
2451
                        pthread_mutex_lock(&commit_cond_m);
2377
2452
                        commit_threads++;
2378
2453
 
2379
 
                        if (commit_threads > srv_commit_concurrency) {
 
2454
                        if (commit_threads > innobase_commit_concurrency) {
2380
2455
                                commit_threads--;
2381
2456
                                pthread_cond_wait(&commit_cond,
2382
2457
                                        &commit_cond_m);
2391
2466
                trx->mysql_log_file_name = mysql_bin_log_file_name();
2392
2467
                trx->mysql_log_offset = (ib_int64_t) mysql_bin_log_file_pos();
2393
2468
 
 
2469
                /* Don't do write + flush right now. For group commit
 
2470
                to work we want to do the flush after releasing the
 
2471
                prepare_commit_mutex. */
 
2472
                trx->flush_log_later = TRUE;
2394
2473
                innobase_commit_low(trx);
 
2474
                trx->flush_log_later = FALSE;
2395
2475
 
2396
 
                if (srv_commit_concurrency > 0) {
 
2476
                if (innobase_commit_concurrency > 0) {
2397
2477
                        pthread_mutex_lock(&commit_cond_m);
2398
2478
                        commit_threads--;
2399
2479
                        pthread_cond_signal(&commit_cond);
2405
2485
                        pthread_mutex_unlock(&prepare_commit_mutex);
2406
2486
                }
2407
2487
 
 
2488
                /* Now do a write + flush of logs. */
 
2489
                trx_commit_complete_for_mysql(trx);
2408
2490
                trx->active_trans = 0;
2409
2491
 
2410
2492
        } else {
2438
2520
        DBUG_RETURN(0);
2439
2521
}
2440
2522
 
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 */
2443
2526
static
2444
2527
int
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 */
2453
2535
{
2454
2536
        int     error = 0;
2484
2566
        DBUG_RETURN(convert_error_code_to_mysql(error, 0, NULL));
2485
2567
}
2486
2568
 
2487
 
/*********************************************************************
2488
 
Rolls back a transaction */
 
2569
/*****************************************************************//**
 
2570
Rolls back a transaction
 
2571
@return 0 or error number */
2489
2572
static
2490
2573
int
2491
2574
innobase_rollback_trx(
2492
2575
/*==================*/
2493
 
                        /* out: 0 or error number */
2494
 
        trx_t*  trx)    /*  in: transaction */
 
2576
        trx_t*  trx)    /*!< in: transaction */
2495
2577
{
2496
2578
        int     error = 0;
2497
2579
 
2515
2597
        DBUG_RETURN(convert_error_code_to_mysql(error, 0, NULL));
2516
2598
}
2517
2599
 
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
 
2603
given name */
2520
2604
static
2521
2605
int
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 */
2530
2612
{
2531
2613
        ib_int64_t      mysql_binlog_cache_pos;
2532
2614
        int             error = 0;
2553
2635
        DBUG_RETURN(convert_error_code_to_mysql(error, 0, NULL));
2554
2636
}
2555
2637
 
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
 
2641
given name */
2558
2642
static
2559
2643
int
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 */
2568
2650
{
2569
2651
        int             error = 0;
2570
2652
        trx_t*          trx;
2584
2666
        DBUG_RETURN(convert_error_code_to_mysql(error, 0, NULL));
2585
2667
}
2586
2668
 
2587
 
/*********************************************************************
2588
 
Sets a transaction savepoint. */
 
2669
/*****************************************************************//**
 
2670
Sets a transaction savepoint.
 
2671
@return always 0, that is, always succeeds */
2589
2672
static
2590
2673
int
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 */
2597
2679
{
2598
2680
        int     error = 0;
2599
2681
        trx_t*  trx;
2631
2713
        DBUG_RETURN(convert_error_code_to_mysql(error, 0, NULL));
2632
2714
}
2633
2715
 
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 */
2636
2719
static
2637
2720
int
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 */
2644
2726
{
2645
2727
        trx_t*  trx;
2676
2758
}
2677
2759
 
2678
2760
 
2679
 
/*****************************************************************************
 
2761
/*************************************************************************//**
2680
2762
** InnoDB database tables
2681
2763
*****************************************************************************/
2682
2764
 
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 */
2685
2769
UNIV_INTERN
2686
2770
enum row_type
2687
2771
ha_innobase::get_row_type() const
2688
2772
/*=============================*/
2689
 
                        /* out: one of
2690
 
                        ROW_TYPE_REDUNDANT,
2691
 
                        ROW_TYPE_COMPACT,
2692
 
                        ROW_TYPE_COMPRESSED,
2693
 
                        ROW_TYPE_DYNAMIC */
2694
2773
{
2695
2774
        if (prebuilt && prebuilt->table) {
2696
2775
                const ulint     flags = prebuilt->table->flags;
2721
2800
 
2722
2801
 
2723
2802
 
2724
 
/********************************************************************
2725
 
Get the table flags to use for the statement. */
 
2803
/****************************************************************//**
 
2804
Get the table flags to use for the statement.
 
2805
@return table flags */
2726
2806
UNIV_INTERN
2727
2807
handler::Table_flags
2728
2808
ha_innobase::table_flags() const
 
2809
/*============================*/
2729
2810
{
2730
2811
       /* Need to use tx_isolation here since table flags is (also)
2731
2812
          called before prebuilt is inited. */
2735
2816
        return int_table_flags | HA_BINLOG_STMT_CAPABLE;
2736
2817
}
2737
2818
 
2738
 
/********************************************************************
 
2819
/****************************************************************//**
2739
2820
Gives the file extension of an InnoDB single-table tablespace. */
2740
2821
static const char* ha_innobase_exts[] = {
2741
2822
  ".ibd",
2742
2823
  NullS
2743
2824
};
2744
2825
 
 
2826
/****************************************************************//**
 
2827
Returns the table type (storage engine name).
 
2828
@return table type */
2745
2829
UNIV_INTERN
2746
2830
const char*
2747
2831
ha_innobase::table_type() const
2748
2832
/*===========================*/
2749
 
                                /* out: table type */
2750
2833
{
2751
2834
        return(innobase_hton_name);
2752
2835
}
2753
2836
 
 
2837
/****************************************************************//**
 
2838
Returns the index type. */
2754
2839
UNIV_INTERN
2755
2840
const char*
2756
 
ha_innobase::index_type(uint)
2757
 
/*=========================*/
2758
 
                                /* out: index type */
 
2841
ha_innobase::index_type(
 
2842
/*====================*/
 
2843
        uint)
 
2844
                                /*!< out: index type */
2759
2845
{
2760
2846
        return("BTREE");
2761
2847
}
2762
2848
 
 
2849
/****************************************************************//**
 
2850
Returns the table file name extension.
 
2851
@return file extension string */
2763
2852
UNIV_INTERN
2764
2853
const char**
2765
2854
ha_innobase::bas_ext() const
2766
2855
/*========================*/
2767
 
                                /* out: file extension string */
2768
2856
{
2769
2857
        return(ha_innobase_exts);
2770
2858
}
2771
2859
 
 
2860
/****************************************************************//**
 
2861
Returns the operations supported for indexes.
 
2862
@return flags of supported operations */
2772
2863
UNIV_INTERN
2773
2864
ulong
2774
 
ha_innobase::index_flags(uint, uint, bool) const
 
2865
ha_innobase::index_flags(
 
2866
/*=====================*/
 
2867
        uint,
 
2868
        uint,
 
2869
        bool)
 
2870
const
2775
2871
{
2776
2872
        return(HA_READ_NEXT | HA_READ_PREV | HA_READ_ORDER
2777
2873
               | HA_READ_RANGE | HA_KEYREAD_ONLY);
2778
2874
}
2779
2875
 
 
2876
/****************************************************************//**
 
2877
Returns the maximum number of keys.
 
2878
@return MAX_KEY */
2780
2879
UNIV_INTERN
2781
2880
uint
2782
2881
ha_innobase::max_supported_keys() const
 
2882
/*===================================*/
2783
2883
{
2784
2884
        return(MAX_KEY);
2785
2885
}
2786
2886
 
 
2887
/****************************************************************//**
 
2888
Returns the maximum key length.
 
2889
@return maximum supported key length, in bytes */
2787
2890
UNIV_INTERN
2788
2891
uint
2789
2892
ha_innobase::max_supported_key_length() const
 
2893
/*=========================================*/
2790
2894
{
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
2796
2900
        return(3500);
2797
2901
}
2798
2902
 
 
2903
/****************************************************************//**
 
2904
Returns the key map of keys that are usable for scanning.
 
2905
@return key_map_full */
2799
2906
UNIV_INTERN
2800
2907
const key_map*
2801
2908
ha_innobase::keys_to_use_for_scanning()
2803
2910
        return(&key_map_full);
2804
2911
}
2805
2912
 
 
2913
/****************************************************************//**
 
2914
Determines if table caching is supported.
 
2915
@return HA_CACHE_TBL_ASKTRANSACT */
2806
2916
UNIV_INTERN
2807
2917
uint8
2808
2918
ha_innobase::table_cache_type()
2810
2920
        return(HA_CACHE_TBL_ASKTRANSACT);
2811
2921
}
2812
2922
 
 
2923
/****************************************************************//**
 
2924
Determines if the primary key is clustered index.
 
2925
@return true */
2813
2926
UNIV_INTERN
2814
2927
bool
2815
2928
ha_innobase::primary_key_is_clustered()
2817
2930
        return(true);
2818
2931
}
2819
2932
 
2820
 
/*********************************************************************
 
2933
/*****************************************************************//**
2821
2934
Normalizes a table name string. A normalized name consists of the
2822
2935
database name catenated to '/' and table name. An example:
2823
2936
test/mytable. On Windows normalization puts both the database name and the
2826
2939
void
2827
2940
normalize_table_name(
2828
2941
/*=================*/
2829
 
        char*           norm_name,      /* out: normalized name as a
 
2942
        char*           norm_name,      /*!< out: normalized name as a
2830
2943
                                        null-terminated string */
2831
 
        const char*     name)           /* in: table name string */
 
2944
        const char*     name)           /*!< in: table name string */
2832
2945
{
2833
2946
        char*   name_ptr;
2834
2947
        char*   db_ptr;
2863
2976
#endif
2864
2977
}
2865
2978
 
2866
 
/************************************************************************
 
2979
/********************************************************************//**
2867
2980
Set the autoinc column max value. This should only be called once from
2868
 
ha_innobase::open(). Therefore there's no need for a covering lock. */
 
2981
ha_innobase::open(). Therefore there's no need for a covering lock.
 
2982
@return DB_SUCCESS or error code */
2869
2983
UNIV_INTERN
2870
2984
ulint
2871
2985
ha_innobase::innobase_initialize_autoinc()
2874
2988
        dict_index_t*   index;
2875
2989
        ulonglong       auto_inc;
2876
2990
        const char*     col_name;
2877
 
        ulint           error = DB_SUCCESS;
2878
 
        dict_table_t*   innodb_table = prebuilt->table;
 
2991
        ulint           error;
2879
2992
 
2880
2993
        col_name = table->found_next_number_field->field_name;
2881
2994
        index = innobase_get_index(table->s->next_number_index);
2883
2996
        /* Execute SELECT MAX(col_name) FROM TABLE; */
2884
2997
        error = row_search_max_autoinc(index, col_name, &auto_inc);
2885
2998
 
2886
 
        if (error == DB_SUCCESS) {
 
2999
        switch (error) {
 
3000
        case DB_SUCCESS:
2887
3001
 
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. */
2890
3004
                ++auto_inc;
2891
 
 
2892
 
                dict_table_autoinc_initialize(innodb_table, auto_inc);
2893
 
 
2894
 
        } else {
 
3005
                break;
 
3006
 
 
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 "
 
3016
                        "generation.\n"
 
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 "
 
3020
                        "the table.\n",
 
3021
                        col_name, index->table->name);
 
3022
 
 
3023
                auto_inc = 0xFFFFFFFFFFFFFFFFULL;
 
3024
                break;
 
3025
 
 
3026
        default:
 
3027
                return(error);
2899
3028
        }
2900
3029
 
2901
 
        return(error);
 
3030
        dict_table_autoinc_initialize(prebuilt->table, auto_inc);
 
3031
 
 
3032
        return(DB_SUCCESS);
2902
3033
}
2903
3034
 
2904
 
/*********************************************************************
 
3035
/*****************************************************************//**
2905
3036
Creates and opens a handle to a table which already exists in an InnoDB
2906
 
database. */
 
3037
database.
 
3038
@return 1 if error, 0 if success */
2907
3039
UNIV_INTERN
2908
3040
int
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 */
2915
3046
{
2916
3047
        dict_table_t*   ib_table;
2917
3048
        char            norm_name[1000];
2994
3125
                                "or, the table contains indexes that this "
2995
3126
                                "version of the engine\n"
2996
3127
                                "doesn't support.\n"
2997
 
                                "See http://dev.mysql.com/doc/refman/5.1/en/innodb-troubleshooting.html\n"
 
3128
                                "See " REFMAN "innodb-troubleshooting.html\n"
2998
3129
                                "how you can resolve the problem.\n",
2999
3130
                                norm_name);
3000
3131
                free_share(share);
3010
3141
                                "Have you deleted the .ibd file from the "
3011
3142
                                "database directory under\nthe MySQL datadir, "
3012
3143
                                "or have you used DISCARD TABLESPACE?\n"
3013
 
                                "See http://dev.mysql.com/doc/refman/5.1/en/innodb-troubleshooting.html\n"
 
3144
                                "See " REFMAN "innodb-troubleshooting.html\n"
3014
3145
                                "how you can resolve the problem.\n",
3015
3146
                                norm_name);
3016
3147
                free_share(share);
3116
3247
                if (dict_table_autoinc_read(prebuilt->table) == 0) {
3117
3248
 
3118
3249
                        error = innobase_initialize_autoinc();
3119
 
                        /* Should always succeed! */
3120
3250
                        ut_a(error == DB_SUCCESS);
3121
3251
                }
3122
3252
 
3133
3263
        return(DICT_MAX_INDEX_COL_LEN - 1);
3134
3264
}
3135
3265
 
3136
 
/**********************************************************************
3137
 
Closes a handle to an InnoDB table. */
 
3266
/******************************************************************//**
 
3267
Closes a handle to an InnoDB table.
 
3268
@return 0 */
3138
3269
UNIV_INTERN
3139
3270
int
3140
3271
ha_innobase::close(void)
3141
3272
/*====================*/
3142
 
                                /* out: 0 */
3143
3273
{
3144
3274
        THD*    thd;
3145
3275
 
3165
3295
 
3166
3296
/* The following accessor functions should really be inside MySQL code! */
3167
3297
 
3168
 
/******************************************************************
3169
 
Gets field offset for a field in a table. */
 
3298
/**************************************************************//**
 
3299
Gets field offset for a field in a table.
 
3300
@return offset */
3170
3301
static inline
3171
3302
uint
3172
3303
get_field_offset(
3173
3304
/*=============*/
3174
 
                        /* out: offset */
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 */
3177
3307
{
3178
3308
        return((uint) (field->ptr - table->record[0]));
3179
3309
}
3180
3310
 
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 */
3184
3315
static inline
3185
3316
uint
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 */
3192
3322
{
3193
3323
        int     null_offset;
3194
3324
 
3208
3338
        return(0);
3209
3339
}
3210
3340
 
3211
 
/******************************************************************
 
3341
/**************************************************************//**
3212
3342
Sets a field in a record to SQL NULL. Uses the record format
3213
3343
information in table to track the null bit in record. */
3214
3344
static inline
3215
3345
void
3216
3346
set_field_in_record_to_null(
3217
3347
/*========================*/
3218
 
        TABLE*  table,  /* in: MySQL table object */
3219
 
        Field*  field,  /* in: MySQL field object */
3220
 
        char*   record) /* in: a row in MySQL format */
 
3348
        TABLE*  table,  /*!< in: MySQL table object */
 
3349
        Field*  field,  /*!< in: MySQL field object */
 
3350
        char*   record) /*!< in: a row in MySQL format */
3221
3351
{
3222
3352
        int     null_offset;
3223
3353
 
3227
3357
        record[null_offset] = record[null_offset] | field->null_bit;
3228
3358
}
3229
3359
 
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
3236
3367
int
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 */
3249
3378
{
3250
3379
        CHARSET_INFO*           charset;
3309
3438
        return(0);
3310
3439
}
3311
3440
 
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
3317
3447
ulint
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 */
3328
3456
{
3329
3457
        const class Field* field = reinterpret_cast<const class Field*>(f);
3330
3458
 
3417
3545
        return(0);
3418
3546
}
3419
3547
 
3420
 
/***********************************************************************
 
3548
/*******************************************************************//**
3421
3549
Writes an unsigned integer value < 64k to 2 bytes, in the little-endian
3422
3550
storage format. */
3423
3551
static inline
3424
3552
void
3425
3553
innobase_write_to_2_little_endian(
3426
3554
/*==============================*/
3427
 
        byte*   buf,    /* in: where to store */
3428
 
        ulint   val)    /* in: value to write, must be < 64k */
 
3555
        byte*   buf,    /*!< in: where to store */
 
3556
        ulint   val)    /*!< in: value to write, must be < 64k */
3429
3557
{
3430
3558
        ut_a(val < 256 * 256);
3431
3559
 
3433
3561
        buf[1] = (byte)(val / 256);
3434
3562
}
3435
3563
 
3436
 
/***********************************************************************
 
3564
/*******************************************************************//**
3437
3565
Reads an unsigned integer value < 64k from 2 bytes, in the little-endian
3438
 
storage format. */
 
3566
storage format.
 
3567
@return value */
3439
3568
static inline
3440
3569
uint
3441
3570
innobase_read_from_2_little_endian(
3442
3571
/*===============================*/
3443
 
                                /* out: value */
3444
 
        const uchar*    buf)    /* in: from where to read */
 
3572
        const uchar*    buf)    /*!< in: from where to read */
3445
3573
{
3446
3574
        return (uint) ((ulint)(buf[0]) + 256 * ((ulint)(buf[1])));
3447
3575
}
3448
3576
 
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 */
3451
3580
UNIV_INTERN
3452
3581
uint
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
3458
3586
                                format) */
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 */
3461
3589
{
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));
3721
3849
}
3722
3850
 
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. */
3726
3854
static
3727
3855
void
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 */
3737
3865
{
3738
3866
        dict_index_t*   index;
3932
4060
        }
3933
4061
}
3934
4062
 
3935
 
/************************************************************************
 
4063
/********************************************************************//**
3936
4064
Get the upper limit of the MySQL integral and floating-point type. */
3937
4065
UNIV_INTERN
3938
4066
ulonglong
3993
4121
        return(max_value);
3994
4122
}
3995
4123
 
3996
 
/************************************************************************
 
4124
/********************************************************************//**
3997
4125
This special handling is really to overcome the limitations of MySQL's
3998
4126
binlogging. We need to eliminate the non-determinism that will arise in
3999
4127
INSERT ... SELECT type of statements, since MySQL binlog only stores the
4000
4128
min value of the autoinc interval. Once that is fixed we can get rid of
4001
 
the special lock handling.*/
 
4129
the special lock handling.
 
4130
@return DB_SUCCESS if all OK else error code */
4002
4131
UNIV_INTERN
4003
4132
ulint
4004
4133
ha_innobase::innobase_lock_autoinc(void)
4005
4134
/*====================================*/
4006
 
                                        /* out: DB_SUCCESS if all OK else
4007
 
                                        error code */
4008
4135
{
4009
4136
        ulint           error = DB_SUCCESS;
4010
4137
 
4054
4181
        return(ulong(error));
4055
4182
}
4056
4183
 
4057
 
/************************************************************************
4058
 
Reset the autoinc value in the table.*/
 
4184
/********************************************************************//**
 
4185
Reset the autoinc value in the table.
 
4186
@return DB_SUCCESS if all went well else error code */
4059
4187
UNIV_INTERN
4060
4188
ulint
4061
4189
ha_innobase::innobase_reset_autoinc(
4062
4190
/*================================*/
4063
 
                                        /* out: DB_SUCCESS if all went well
4064
 
                                        else error code */
4065
 
        ulonglong       autoinc)        /* in: value to store */
 
4191
        ulonglong       autoinc)        /*!< in: value to store */
4066
4192
{
4067
4193
        ulint           error;
4068
4194
 
4078
4204
        return(ulong(error));
4079
4205
}
4080
4206
 
4081
 
/************************************************************************
 
4207
/********************************************************************//**
4082
4208
Store the autoinc value in the table. The autoinc value is only set if
4083
 
it's greater than the existing autoinc value in the table.*/
 
4209
it's greater than the existing autoinc value in the table.
 
4210
@return DB_SUCCESS if all went well else error code */
4084
4211
UNIV_INTERN
4085
4212
ulint
4086
4213
ha_innobase::innobase_set_max_autoinc(
4087
4214
/*==================================*/
4088
 
                                        /* out: DB_SUCCES if all went well
4089
 
                                        else error code */
4090
 
        ulonglong       auto_inc)       /* in: value to store */
 
4215
        ulonglong       auto_inc)       /*!< in: value to store */
4091
4216
{
4092
4217
        ulint           error;
4093
4218
 
4103
4228
        return(ulong(error));
4104
4229
}
4105
4230
 
4106
 
/************************************************************************
 
4231
/********************************************************************//**
4107
4232
Stores a row in an InnoDB database, to the table specified in this
4108
 
handle. */
 
4233
handle.
 
4234
@return error code */
4109
4235
UNIV_INTERN
4110
4236
int
4111
4237
ha_innobase::write_row(
4112
4238
/*===================*/
4113
 
                        /* out: error code */
4114
 
        uchar*  record) /* in: a row in MySQL format */
 
4239
        uchar*  record) /*!< in: a row in MySQL format */
4115
4240
{
4116
4241
        ulint           error = 0;
4117
4242
        int             error_result= 0;
4343
4468
        DBUG_RETURN(error_result);
4344
4469
}
4345
4470
 
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 */
4349
4475
static
4350
4476
int
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
4358
4483
                                        dictionary */
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 */
4363
4488
{
4364
4489
        uchar*          original_upd_buff = upd_buff;
4365
4490
        Field*          field;
4491
4616
        return(0);
4492
4617
}
4493
4618
 
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 */
4501
4627
UNIV_INTERN
4502
4628
int
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 */
4508
4633
{
4509
4634
        upd_t*          uvect;
4510
4635
        int             error = 0;
4604
4729
        DBUG_RETURN(error);
4605
4730
}
4606
4731
 
4607
 
/**************************************************************************
4608
 
Deletes a row given as the parameter. */
 
4732
/**********************************************************************//**
 
4733
Deletes a row given as the parameter.
 
4734
@return error number or 0 */
4609
4735
UNIV_INTERN
4610
4736
int
4611
4737
ha_innobase::delete_row(
4612
4738
/*====================*/
4613
 
                                /* out: error number or 0 */
4614
 
        const uchar*    record) /* in: a row in MySQL format */
 
4739
        const uchar*    record) /*!< in: a row in MySQL format */
4615
4740
{
4616
4741
        int             error = 0;
4617
4742
        trx_t*          trx = thd_to_trx(user_thd);
4647
4772
        DBUG_RETURN(error);
4648
4773
}
4649
4774
 
4650
 
/**************************************************************************
 
4775
/**********************************************************************//**
4651
4776
Removes a new lock set on a row, if it was not read optimistically. This can
4652
4777
be called after a row has been read in the processing of an UPDATE or a DELETE
4653
4778
query, if the option innodb_locks_unsafe_for_binlog is set. */
4715
4840
        }
4716
4841
}
4717
4842
 
4718
 
#ifdef ROW_MERGE_IS_INDEX_USABLE
4719
 
/**********************************************************************
4720
 
Check if an index can be used by the optimizer. */
4721
 
UNIV_INTERN
4722
 
bool
4723
 
ha_innobase::is_index_available(
4724
 
/*============================*/
4725
 
                                        /* out: true if available else false*/
4726
 
        uint            keynr)          /* in: index number to check */
4727
 
{
4728
 
        DBUG_ENTER("ha_innobase::is_index_available");
4729
 
 
4730
 
        if (table && keynr != MAX_KEY && table->s->keys > 0) {
4731
 
                const dict_index_t*     index;
4732
 
                const KEY*              key = table->key_info + keynr;
4733
 
 
4734
 
                ut_ad(user_thd == ha_thd());
4735
 
                ut_a(prebuilt->trx == thd_to_trx(user_thd));
4736
 
 
4737
 
                index = dict_table_get_index_on_name(
4738
 
                        prebuilt->table, key->name);
4739
 
 
4740
 
                if (!row_merge_is_index_usable(prebuilt->trx, index)) {
4741
 
 
4742
 
                        DBUG_RETURN(false);
4743
 
                }
4744
 
        }
4745
 
 
4746
 
        DBUG_RETURN(true);
4747
 
}
4748
 
#endif /* ROW_MERGE_IS_INDEX_USABLE */
4749
 
 
4750
 
/**********************************************************************
4751
 
Initializes a handle to use an index. */
 
4843
/******************************************************************//**
 
4844
Initializes a handle to use an index.
 
4845
@return 0 or error number */
4752
4846
UNIV_INTERN
4753
4847
int
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 */
4759
4852
{
4760
4853
        DBUG_ENTER("index_init");
4761
4854
 
4762
4855
        DBUG_RETURN(change_active_index(keynr));
4763
4856
}
4764
4857
 
4765
 
/**********************************************************************
4766
 
Currently does nothing. */
 
4858
/******************************************************************//**
 
4859
Currently does nothing.
 
4860
@return 0 */
4767
4861
UNIV_INTERN
4768
4862
int
4769
4863
ha_innobase::index_end(void)
4775
4869
        DBUG_RETURN(error);
4776
4870
}
4777
4871
 
4778
 
/*************************************************************************
 
4872
/*********************************************************************//**
4779
4873
Converts a search mode flag understood by MySQL to a flag understood
4780
4874
by InnoDB. */
4781
4875
static inline
4820
4914
        case HA_READ_MBR_WITHIN:
4821
4915
        case HA_READ_MBR_DISJOINT:
4822
4916
        case HA_READ_MBR_EQUAL:
4823
 
                my_error(ER_TABLE_CANT_HANDLE_SPKEYS, MYF(0));
4824
4917
                return(PAGE_CUR_UNSUPP);
4825
4918
        /* do not use "default:" in order to produce a gcc warning:
4826
4919
        enumeration value '...' not handled in switch
4881
4974
start of a new SQL statement. */
4882
4975
 
4883
4976
 
4884
 
/**************************************************************************
 
4977
/**********************************************************************//**
4885
4978
Positions an index cursor to the index specified in the handle. Fetches the
4886
 
row if any. */
 
4979
row if any.
 
4980
@return 0, HA_ERR_KEY_NOT_FOUND, or error number */
4887
4981
UNIV_INTERN
4888
4982
int
4889
4983
ha_innobase::index_read(
4890
4984
/*====================*/
4891
 
                                        /* out: 0, HA_ERR_KEY_NOT_FOUND,
4892
 
                                        or error number */
4893
 
        uchar*          buf,            /* in/out: buffer for the returned
 
4985
        uchar*          buf,            /*!< in/out: buffer for the returned
4894
4986
                                        row */
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
4901
4993
                                        also be a prefix of a full key value,
4902
4994
                                        and the last column can be a prefix
4903
4995
                                        of a full column */
4904
 
        uint                    key_len,/* in: key value length */
4905
 
        enum ha_rkey_function find_flag)/* in: search flags from my_base.h */
 
4996
        uint                    key_len,/*!< in: key value length */
 
4997
        enum ha_rkey_function find_flag)/*!< in: search flags from my_base.h */
4906
4998
{
4907
4999
        ulint           mode;
4908
5000
        dict_index_t*   index;
4997
5089
        DBUG_RETURN(error);
4998
5090
}
4999
5091
 
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 */
5003
5096
UNIV_INTERN
5004
5097
int
5005
5098
ha_innobase::index_read_last(
5006
5099
/*=========================*/
5007
 
                                /* out: 0, HA_ERR_KEY_NOT_FOUND, or an
5008
 
                                error code */
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
5011
5102
                                key value */
5012
 
        uint            key_len)/* in: length of the key val or prefix
 
5103
        uint            key_len)/*!< in: length of the key val or prefix
5013
5104
                                in bytes */
5014
5105
{
5015
5106
        return(index_read(buf, key_ptr, key_len, HA_READ_PREFIX_LAST));
5016
5107
}
5017
5108
 
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. */
5020
5112
UNIV_INTERN
5021
5113
dict_index_t*
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 */
5028
5119
{
5055
5146
        DBUG_RETURN(index);
5056
5147
}
5057
5148
 
5058
 
/************************************************************************
5059
 
Changes the active index of a handle. */
 
5149
/********************************************************************//**
 
5150
Changes the active index of a handle.
 
5151
@return 0 or error code */
5060
5152
UNIV_INTERN
5061
5153
int
5062
5154
ha_innobase::change_active_index(
5063
5155
/*=============================*/
5064
 
                        /* out: 0 or error code */
5065
 
        uint    keynr)  /* in: use this index; MAX_KEY means always clustered
 
5156
        uint    keynr)  /*!< in: use this index; MAX_KEY means always clustered
5066
5157
                        index, even if it was internally generated by
5067
5158
                        InnoDB */
5068
5159
{
5081
5172
                DBUG_RETURN(1);
5082
5173
        }
5083
5174
 
 
5175
        prebuilt->index_usable = row_merge_is_index_usable(prebuilt->trx,
 
5176
                                                           prebuilt->index);
 
5177
 
 
5178
        if (UNIV_UNLIKELY(!prebuilt->index_usable)) {
 
5179
                sql_print_warning("InnoDB: insufficient history for index %u",
 
5180
                                  keynr);
 
5181
                /* The caller seems to ignore this.  Thus, we must check
 
5182
                this again in row_search_for_mysql(). */
 
5183
                DBUG_RETURN(2);
 
5184
        }
 
5185
 
5084
5186
        ut_a(prebuilt->search_tuple != 0);
5085
5187
 
5086
5188
        dtuple_set_n_fields(prebuilt->search_tuple, prebuilt->index->n_fields);
5099
5201
        DBUG_RETURN(0);
5100
5202
}
5101
5203
 
5102
 
/**************************************************************************
 
5204
/**********************************************************************//**
5103
5205
Positions an index cursor to the index specified in keynr. Fetches the
5104
 
row if any. */
5105
 
/* ??? This is only used to read whole keys ??? */
 
5206
row if any.
 
5207
??? This is only used to read whole keys ???
 
5208
@return error number or 0 */
5106
5209
UNIV_INTERN
5107
5210
int
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
5112
5214
                                        row */
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 */
5119
5221
{
5120
5222
        if (change_active_index(keynr)) {
5121
5223
 
5125
5227
        return(index_read(buf, key, key_len, find_flag));
5126
5228
}
5127
5229
 
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 */
5131
5234
UNIV_INTERN
5132
5235
int
5133
5236
ha_innobase::general_fetch(
5134
5237
/*=======================*/
5135
 
                                /* out: 0, HA_ERR_END_OF_FILE, or error
5136
 
                                number */
5137
 
        uchar*  buf,            /* in/out: buffer for next row in MySQL
 
5238
        uchar*  buf,            /*!< in/out: buffer for next row in MySQL
5138
5239
                                format */
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 */
5142
5243
{
5143
5244
        ulint           ret;
5177
5278
        DBUG_RETURN(error);
5178
5279
}
5179
5280
 
5180
 
/***************************************************************************
 
5281
/***********************************************************************//**
5181
5282
Reads the next row from a cursor, which must have previously been
5182
 
positioned using index_read. */
 
5283
positioned using index_read.
 
5284
@return 0, HA_ERR_END_OF_FILE, or error number */
5183
5285
UNIV_INTERN
5184
5286
int
5185
5287
ha_innobase::index_next(
5186
5288
/*====================*/
5187
 
                                /* out: 0, HA_ERR_END_OF_FILE, or error
5188
 
                                number */
5189
 
        uchar*          buf)    /* in/out: buffer for next row in MySQL
 
5289
        uchar*          buf)    /*!< in/out: buffer for next row in MySQL
5190
5290
                                format */
5191
5291
{
5192
5292
        ha_statistic_increment(&SSV::ha_read_next_count);
5194
5294
        return(general_fetch(buf, ROW_SEL_NEXT, 0));
5195
5295
}
5196
5296
 
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 */
5199
5300
UNIV_INTERN
5200
5301
int
5201
5302
ha_innobase::index_next_same(
5202
5303
/*=========================*/
5203
 
                                /* out: 0, HA_ERR_END_OF_FILE, or error
5204
 
                                number */
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 */
5208
5307
{
5209
5308
        ha_statistic_increment(&SSV::ha_read_next_count);
5210
5309
 
5211
5310
        return(general_fetch(buf, ROW_SEL_NEXT, last_match_mode));
5212
5311
}
5213
5312
 
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 */
5217
5317
UNIV_INTERN
5218
5318
int
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 */
5223
5322
{
5224
5323
        ha_statistic_increment(&SSV::ha_read_prev_count);
5225
5324
 
5226
5325
        return(general_fetch(buf, ROW_SEL_PREV, 0));
5227
5326
}
5228
5327
 
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 */
5232
5332
UNIV_INTERN
5233
5333
int
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 */
5238
5337
{
5239
5338
        int     error;
5240
5339
 
5252
5351
        DBUG_RETURN(error);
5253
5352
}
5254
5353
 
5255
 
/************************************************************************
 
5354
/********************************************************************//**
5256
5355
Positions a cursor on the last record in an index and reads the
5257
 
corresponding row to buf. */
 
5356
corresponding row to buf.
 
5357
@return 0, HA_ERR_END_OF_FILE, or error code */
5258
5358
UNIV_INTERN
5259
5359
int
5260
5360
ha_innobase::index_last(
5261
5361
/*====================*/
5262
 
                        /* out: 0, HA_ERR_END_OF_FILE, or error code */
5263
 
        uchar*  buf)    /* in/out: buffer for the row */
 
5362
        uchar*  buf)    /*!< in/out: buffer for the row */
5264
5363
{
5265
5364
        int     error;
5266
5365
 
5278
5377
        DBUG_RETURN(error);
5279
5378
}
5280
5379
 
5281
 
/********************************************************************
5282
 
Initialize a table scan. */
 
5380
/****************************************************************//**
 
5381
Initialize a table scan.
 
5382
@return 0 or error number */
5283
5383
UNIV_INTERN
5284
5384
int
5285
5385
ha_innobase::rnd_init(
5286
5386
/*==================*/
5287
 
                        /* out: 0 or error number */
5288
 
        bool    scan)   /* in: TRUE if table/index scan FALSE otherwise */
 
5387
        bool    scan)   /*!< in: TRUE if table/index scan FALSE otherwise */
5289
5388
{
5290
5389
        int     err;
5291
5390
 
5310
5409
        return(err);
5311
5410
}
5312
5411
 
5313
 
/*********************************************************************
5314
 
Ends a table scan. */
 
5412
/*****************************************************************//**
 
5413
Ends a table scan.
 
5414
@return 0 or error number */
5315
5415
UNIV_INTERN
5316
5416
int
5317
5417
ha_innobase::rnd_end(void)
5318
5418
/*======================*/
5319
 
                                /* out: 0 or error number */
5320
5419
{
5321
5420
        return(index_end());
5322
5421
}
5323
5422
 
5324
 
/*********************************************************************
 
5423
/*****************************************************************//**
5325
5424
Reads the next row in a table scan (also used to read the FIRST row
5326
 
in a table scan). */
 
5425
in a table scan).
 
5426
@return 0, HA_ERR_END_OF_FILE, or error number */
5327
5427
UNIV_INTERN
5328
5428
int
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 */
5334
5433
{
5335
5434
        int     error;
5352
5451
        DBUG_RETURN(error);
5353
5452
}
5354
5453
 
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 */
5357
5457
UNIV_INTERN
5358
5458
int
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 */
5404
5503
        DBUG_RETURN(error);
5405
5504
}
5406
5505
 
5407
 
/*************************************************************************
 
5506
/*********************************************************************//**
5408
5507
Stores a reference to the current row to 'ref' field of the handle. Note
5409
5508
that in the case where we have generated the clustered index for the
5410
5509
table, the function parameter is illogical: we MUST ASSUME that 'record'
5416
5515
void
5417
5516
ha_innobase::position(
5418
5517
/*==================*/
5419
 
        const uchar*    record) /* in: row in MySQL format */
 
5518
        const uchar*    record) /*!< in: row in MySQL format */
5420
5519
{
5421
5520
        uint            len;
5422
5521
 
5451
5550
        (row_is_magic_monitor_table(table_name) \
5452
5551
         && check_global_access(thd, PROCESS_ACL))
5453
5552
 
5454
 
/*********************************************************************
 
5553
/*****************************************************************//**
5455
5554
Creates a table definition to an InnoDB database. */
5456
5555
static
5457
5556
int
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
5469
5568
                                        an .ibd file for it (no .ibd extension
5470
5569
                                        in the path, though); otherwise this
5471
5570
                                        is NULL */
5472
 
        ulint           flags)          /* in: table flags */
 
5571
        ulint           flags)          /*!< in: table flags */
5473
5572
{
5474
5573
        Field*          field;
5475
5574
        dict_table_t*   table;
5580
5679
        DBUG_RETURN(error);
5581
5680
}
5582
5681
 
5583
 
/*********************************************************************
 
5682
/*****************************************************************//**
5584
5683
Creates an index in an InnoDB database. */
5585
5684
static
5586
5685
int
5587
5686
create_index(
5588
5687
/*=========*/
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 */
5595
5694
{
5596
5695
        Field*          field;
5597
5696
        dict_index_t*   index;
5705
5804
        DBUG_RETURN(error);
5706
5805
}
5707
5806
 
5708
 
/*********************************************************************
 
5807
/*****************************************************************//**
5709
5808
Creates an index to an InnoDB table when the user has defined no
5710
5809
primary index. */
5711
5810
static
5712
5811
int
5713
5812
create_clustered_index_when_no_primary(
5714
5813
/*===================================*/
5715
 
        trx_t*          trx,            /* in: InnoDB transaction handle */
5716
 
        ulint           flags,          /* in: InnoDB table flags */
5717
 
        const char*     table_name)     /* in: table name */
 
5814
        trx_t*          trx,            /*!< in: InnoDB transaction handle */
 
5815
        ulint           flags,          /*!< in: InnoDB table flags */
 
5816
        const char*     table_name)     /*!< in: table name */
5718
5817
{
5719
5818
        dict_index_t*   index;
5720
5819
        int             error;
5732
5831
        return(error);
5733
5832
}
5734
5833
 
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. */
5740
5840
static
5741
5841
ibool
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. */
5749
5848
{
5750
5849
        ibool   kbs_specified   = FALSE;
5751
5850
        ibool   ret             = TRUE;
5898
5997
        return(ret);
5899
5998
}
5900
5999
 
5901
 
/*********************************************************************
 
6000
/*****************************************************************//**
5902
6001
Update create_info.  Used in SHOW CREATE TABLE et al. */
5903
6002
UNIV_INTERN
5904
6003
void
5905
6004
ha_innobase::update_create_info(
5906
6005
/*============================*/
5907
 
        HA_CREATE_INFO* create_info)    /* in/out: create info */
 
6006
        HA_CREATE_INFO* create_info)    /*!< in/out: create info */
5908
6007
{
5909
6008
  if (!(create_info->used_fields & HA_CREATE_USED_AUTO)) {
5910
6009
    ha_innobase::info(HA_STATUS_AUTO);
5912
6011
  }
5913
6012
}
5914
6013
 
5915
 
/*********************************************************************
5916
 
Creates a new table to an InnoDB database. */
 
6014
/*****************************************************************//**
 
6015
Creates a new table to an InnoDB database.
 
6016
@return error number */
5917
6017
UNIV_INTERN
5918
6018
int
5919
6019
ha_innobase::create(
5920
6020
/*================*/
5921
 
                                        /* out: error number */
5922
 
        const char*     name,           /* in: table name */
5923
 
        TABLE*          form,           /* in: information on table
 
6021
        const char*     name,           /*!< in: table name */
 
6022
        TABLE*          form,           /*!< in: information on table
5924
6023
                                        columns and indexes */
5925
 
        HA_CREATE_INFO* create_info)    /* in: more information of the
 
6024
        HA_CREATE_INFO* create_info)    /*!< in: more information of the
5926
6025
                                        created table, contains also the
5927
6026
                                        create statement string */
5928
6027
{
6165
6264
        /* Our function row_get_mysql_key_number_for_index assumes
6166
6265
        the primary key is always number 0, if it exists */
6167
6266
 
6168
 
        DBUG_ASSERT(primary_key_no == -1 || primary_key_no == 0);
 
6267
        ut_a(primary_key_no == -1 || primary_key_no == 0);
6169
6268
 
6170
6269
        /* Create the keys */
6171
6270
 
6279
6378
        DBUG_RETURN(error);
6280
6379
}
6281
6380
 
6282
 
/*********************************************************************
6283
 
Discards or imports an InnoDB tablespace. */
 
6381
/*****************************************************************//**
 
6382
Discards or imports an InnoDB tablespace.
 
6383
@return 0 == success, -1 == error */
6284
6384
UNIV_INTERN
6285
6385
int
6286
6386
ha_innobase::discard_or_import_tablespace(
6287
6387
/*======================================*/
6288
 
                                /* out: 0 == success, -1 == error */
6289
 
        my_bool discard)        /* in: TRUE if discard, else import */
 
6388
        my_bool discard)        /*!< in: TRUE if discard, else import */
6290
6389
{
6291
6390
        dict_table_t*   dict_table;
6292
6391
        trx_t*          trx;
6312
6411
        DBUG_RETURN(err);
6313
6412
}
6314
6413
 
6315
 
/*********************************************************************
6316
 
Deletes all rows of an InnoDB table. */
 
6414
/*****************************************************************//**
 
6415
Deletes all rows of an InnoDB table.
 
6416
@return error number */
6317
6417
UNIV_INTERN
6318
6418
int
6319
6419
ha_innobase::delete_all_rows(void)
6320
6420
/*==============================*/
6321
 
                                /* out: error number */
6322
6421
{
6323
6422
        int             error;
6324
6423
 
6351
6450
        DBUG_RETURN(error);
6352
6451
}
6353
6452
 
6354
 
/*********************************************************************
 
6453
/*****************************************************************//**
6355
6454
Drops a table from an InnoDB database. Before calling this function,
6356
6455
MySQL calls innobase_commit to commit the transaction of the current user.
6357
6456
Then the current user cannot have locks set on the table. Drop table
6358
6457
operation inside InnoDB will remove all locks any user has on the table
6359
 
inside InnoDB. */
 
6458
inside InnoDB.
 
6459
@return error number */
6360
6460
UNIV_INTERN
6361
6461
int
6362
6462
ha_innobase::delete_table(
6363
6463
/*======================*/
6364
 
                                /* out: error number */
6365
 
        const char*     name)   /* in: table name */
 
6464
        const char*     name)   /*!< in: table name */
6366
6465
{
6367
6466
        ulint   name_len;
6368
6467
        int     error;
6429
6528
        DBUG_RETURN(error);
6430
6529
}
6431
6530
 
6432
 
/*********************************************************************
 
6531
/*****************************************************************//**
6433
6532
Removes all tables in the named database inside InnoDB. */
6434
6533
static
6435
6534
void
6436
6535
innobase_drop_database(
6437
6536
/*===================*/
6438
 
                        /* out: error number */
6439
 
        handlerton *hton, /* in: handlerton of Innodb */
6440
 
        char*   path)   /* in: database path; inside InnoDB the name
 
6537
        handlerton *hton, /*!< in: handlerton of Innodb */
 
6538
        char*   path)   /*!< in: database path; inside InnoDB the name
6441
6539
                        of the last directory in the path is used as
6442
6540
                        the database name: for example, in 'mysql/data/test'
6443
6541
                        the database name is 'test' */
6506
6604
        innobase_commit_low(trx);
6507
6605
        trx_free_for_mysql(trx);
6508
6606
}
6509
 
/*************************************************************************
6510
 
Renames an InnoDB table. */
 
6607
/*********************************************************************//**
 
6608
Renames an InnoDB table.
 
6609
@return 0 or error code */
6511
6610
static
6512
6611
int
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 */
6521
6619
{
6522
6620
        int     error;
6523
6621
        char*   norm_to;
6571
6669
 
6572
6670
        return error;
6573
6671
}
6574
 
/*************************************************************************
6575
 
Renames an InnoDB table. */
 
6672
/*********************************************************************//**
 
6673
Renames an InnoDB table.
 
6674
@return 0 or error code */
6576
6675
UNIV_INTERN
6577
6676
int
6578
6677
ha_innobase::rename_table(
6579
6678
/*======================*/
6580
 
                                /* out: 0 or error code */
6581
 
        const char*     from,   /* in: old name of the table */
6582
 
        const char*     to)     /* in: new name of the table */
 
6679
        const char*     from,   /*!< in: old name of the table */
 
6680
        const char*     to)     /*!< in: new name of the table */
6583
6681
{
6584
6682
        trx_t*  trx;
6585
6683
        int     error;
6615
6713
        DBUG_RETURN(error);
6616
6714
}
6617
6715
 
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 */
6620
6719
UNIV_INTERN
6621
6720
ha_rows
6622
6721
ha_innobase::records_in_range(
6623
6722
/*==========================*/
6624
 
                                                /* out: estimated number of
6625
 
                                                rows */
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
6630
6727
                                                   also be 0 */
6631
6728
{
6632
6729
        KEY*            key;
6702
6799
                                                      mode2);
6703
6800
        } else {
6704
6801
 
6705
 
                n_rows = 0;
 
6802
                n_rows = HA_POS_ERROR;
6706
6803
        }
6707
6804
 
6708
6805
        mem_heap_free(heap);
6724
6821
        DBUG_RETURN((ha_rows) n_rows);
6725
6822
}
6726
6823
 
6727
 
/*************************************************************************
 
6824
/*********************************************************************//**
6728
6825
Gives an UPPER BOUND to the number of rows in a table. This is used in
6729
 
filesort.cc. */
 
6826
filesort.cc.
 
6827
@return upper bound of rows */
6730
6828
UNIV_INTERN
6731
6829
ha_rows
6732
6830
ha_innobase::estimate_rows_upper_bound(void)
6733
6831
/*======================================*/
6734
 
                        /* out: upper bound of rows */
6735
6832
{
6736
6833
        dict_index_t*   index;
6737
6834
        ulonglong       estimate;
6774
6871
        DBUG_RETURN((ha_rows) estimate);
6775
6872
}
6776
6873
 
6777
 
/*************************************************************************
 
6874
/*********************************************************************//**
6778
6875
How many seeks it will take to read through the table. This is to be
6779
6876
comparable to the number returned by records_in_range so that we can
6780
 
decide if we should scan the table or use keys. */
 
6877
decide if we should scan the table or use keys.
 
6878
@return estimated time measured in disk seeks */
6781
6879
UNIV_INTERN
6782
6880
double
6783
6881
ha_innobase::scan_time()
6784
6882
/*====================*/
6785
 
                        /* out: estimated time measured in disk seeks */
6786
6883
{
6787
6884
        /* Since MySQL seems to favor table scans too much over index
6788
6885
        searches, we pretend that a sequential read takes the same time
6792
6889
        return((double) (prebuilt->table->stat_clustered_index_size));
6793
6890
}
6794
6891
 
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 */
6798
6896
UNIV_INTERN
6799
6897
double
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 */
6806
6903
{
6807
6904
        ha_rows total_rows;
6808
6905
        double  time_for_scan;
6830
6927
        return(ranges + (double) rows / (double) total_rows * time_for_scan);
6831
6928
}
6832
6929
 
6833
 
/*************************************************************************
 
6930
/*********************************************************************//**
6834
6931
Returns statistics information of the table to the MySQL interpreter,
6835
6932
in various fields of the handle object. */
6836
6933
UNIV_INTERN
6837
6934
int
6838
6935
ha_innobase::info(
6839
6936
/*==============*/
6840
 
        uint flag)      /* in: what information MySQL requests */
 
6937
        uint flag)      /*!< in: what information MySQL requests */
6841
6938
{
6842
6939
        dict_table_t*   ib_table;
6843
6940
        dict_index_t*   index;
6900
6997
                nor the CHECK TABLE time, nor the UPDATE or INSERT time. */
6901
6998
 
6902
6999
                if (os_file_get_status(path,&stat_info)) {
6903
 
                        stats.create_time = stat_info.ctime;
 
7000
                        stats.create_time = (ulong) stat_info.ctime;
6904
7001
                }
6905
7002
        }
6906
7003
 
7022
7119
                                                ".frm file. Have you mixed up "
7023
7120
                                                ".frm files from different "
7024
7121
                                                "installations? See "
7025
 
"http://dev.mysql.com/doc/refman/5.1/en/innodb-troubleshooting.html\n",
7026
 
 
 
7122
                                                REFMAN
 
7123
                                                "innodb-troubleshooting.html\n",
7027
7124
                                                ib_table->name);
7028
7125
                                break;
7029
7126
                        }
7035
7132
"Index %s of %s has %lu columns unique inside InnoDB, but MySQL is asking "
7036
7133
"statistics for %lu columns. Have you mixed up .frm files from different "
7037
7134
"installations? "
7038
 
"See http://dev.mysql.com/doc/refman/5.1/en/innodb-troubleshooting.html\n",
 
7135
"See " REFMAN "innodb-troubleshooting.html\n",
7039
7136
                                                        index->name,
7040
7137
                                                        ib_table->name,
7041
7138
                                                        (unsigned long)
7096
7193
        DBUG_RETURN(0);
7097
7194
}
7098
7195
 
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) */
7102
7200
UNIV_INTERN
7103
7201
int
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 */
7109
7206
{
7110
7207
        /* Simply call ::info() with all the flags */
7111
7208
        info(HA_STATUS_TIME | HA_STATUS_CONST | HA_STATUS_VARIABLE);
7113
7210
        return(0);
7114
7211
}
7115
7212
 
7116
 
/**************************************************************************
 
7213
/**********************************************************************//**
7117
7214
This is mapped to "ALTER TABLE tablename ENGINE=InnoDB", which rebuilds
7118
7215
the table in MySQL. */
7119
7216
UNIV_INTERN
7120
7217
int
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 */
7125
7222
{
7126
7223
        return(HA_ADMIN_TRY_ALTER);
7127
7224
}
7128
7225
 
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 */
7133
7231
UNIV_INTERN
7134
7232
int
7135
7233
ha_innobase::check(
7136
7234
/*===============*/
7137
 
                                        /* out: HA_ADMIN_CORRUPT or
7138
 
                                        HA_ADMIN_OK */
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
7141
7237
                                        ignored */
7142
7238
{
7143
7239
        ulint           ret;
7163
7259
        return(HA_ADMIN_CORRUPT);
7164
7260
}
7165
7261
 
7166
 
/*****************************************************************
 
7262
/*************************************************************//**
7167
7263
Adds information about free space in the InnoDB tablespace to a table comment
7168
7264
which is printed out when a user calls SHOW TABLE STATUS. Adds also info on
7169
 
foreign keys. */
 
7265
foreign keys.
 
7266
@return table comment + InnoDB free space + info on foreign keys */
7170
7267
UNIV_INTERN
7171
7268
char*
7172
7269
ha_innobase::update_table_comment(
7173
7270
/*==============================*/
7174
 
                                /* out: table comment + InnoDB free space +
7175
 
                                info on foreign keys */
7176
 
        const char*     comment)/* in: table comment defined by user */
 
7271
        const char*     comment)/*!< in: table comment defined by user */
7177
7272
{
7178
7273
        uint    length = (uint) strlen(comment);
7179
7274
        char*   str;
7239
7334
        return(str ? str : (char*) comment);
7240
7335
}
7241
7336
 
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 */
7244
7342
UNIV_INTERN
7245
7343
char*
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 */
7251
7346
{
7252
7347
        char*   str     = 0;
7253
7348
        long    flen;
7416
7511
            f_key_info.referenced_key_name = thd_make_lex_string(
7417
7512
                    thd, f_key_info.referenced_key_name,
7418
7513
                    foreign->referenced_index->name,
7419
 
                    strlen(foreign->referenced_index->name), 1);
 
7514
                    (uint) strlen(foreign->referenced_index->name), 1);
7420
7515
          }
7421
7516
          else
7422
7517
            f_key_info.referenced_key_name= 0;
7432
7527
  DBUG_RETURN(0);
7433
7528
}
7434
7529
 
7435
 
/*********************************************************************
 
7530
/*****************************************************************//**
7436
7531
Checks if ALTER TABLE may change the storage engine of the table.
7437
7532
Changing storage engines is not allowed for tables for which there
7438
 
are foreign key constraints (parent or child tables). */
 
7533
are foreign key constraints (parent or child tables).
 
7534
@return TRUE if can switch engines */
7439
7535
UNIV_INTERN
7440
7536
bool
7441
7537
ha_innobase::can_switch_engines(void)
7460
7556
        DBUG_RETURN(can_switch);
7461
7557
}
7462
7558
 
7463
 
/***********************************************************************
 
7559
/*******************************************************************//**
7464
7560
Checks if a table is referenced by a foreign key. The MySQL manual states that
7465
7561
a REPLACE is either equivalent to an INSERT, or DELETE(s) + INSERT. Only a
7466
7562
delete is then allowed internally to resolve a duplicate key conflict in
7467
 
REPLACE, not an update. */
 
7563
REPLACE, not an update.
 
7564
@return > 0 if referenced by a FOREIGN KEY */
7468
7565
UNIV_INTERN
7469
7566
uint
7470
7567
ha_innobase::referenced_by_foreign_key(void)
7471
7568
/*========================================*/
7472
 
                        /* out: > 0 if referenced by a FOREIGN KEY */
7473
7569
{
7474
7570
        if (dict_table_is_referenced_by_foreign_key(prebuilt->table)) {
7475
7571
 
7479
7575
        return(0);
7480
7576
}
7481
7577
 
7482
 
/***********************************************************************
 
7578
/*******************************************************************//**
7483
7579
Frees the foreign key create info for a table stored in InnoDB, if it is
7484
7580
non-NULL. */
7485
7581
UNIV_INTERN
7486
7582
void
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 */
7490
7586
{
7491
7587
        if (str) {
7492
7588
                my_free(str, MYF(0));
7493
7589
        }
7494
7590
}
7495
7591
 
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 */
7498
7595
UNIV_INTERN
7499
7596
int
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 */
7505
7601
{
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
7571
7667
        return(0);
7572
7668
}
7573
7669
 
7574
 
/**********************************************************************
 
7670
/******************************************************************//**
7575
7671
MySQL calls this function at the start of each SQL statement inside LOCK
7576
7672
TABLES. Inside LOCK TABLES the ::external_lock method does not work to
7577
7673
mark SQL statement borders. Note also a special case: if a temporary table
7581
7677
procedure. To make the execution more deterministic for binlogging, MySQL-5.0
7582
7678
locks all tables involved in a stored procedure with full explicit table
7583
7679
locks (thd_in_lock_tables(thd) holds in store_lock()) before executing the
7584
 
procedure. */
 
7680
procedure.
 
7681
@return 0 or error code */
7585
7682
UNIV_INTERN
7586
7683
int
7587
7684
ha_innobase::start_stmt(
7588
7685
/*====================*/
7589
 
                                /* out: 0 or error code */
7590
 
        THD*            thd,    /* in: handle to the user thread */
 
7686
        THD*            thd,    /*!< in: handle to the user thread */
7591
7687
        thr_lock_type   lock_type)
7592
7688
{
7593
7689
        trx_t*          trx;
7656
7752
        return(0);
7657
7753
}
7658
7754
 
7659
 
/**********************************************************************
7660
 
Maps a MySQL trx isolation level code to the InnoDB isolation level code */
 
7755
/******************************************************************//**
 
7756
Maps a MySQL trx isolation level code to the InnoDB isolation level code
 
7757
@return InnoDB isolation level */
7661
7758
static inline
7662
7759
ulint
7663
7760
innobase_map_isolation_level(
7664
7761
/*=========================*/
7665
 
                                        /* out: InnoDB isolation level */
7666
 
        enum_tx_isolation       iso)    /* in: MySQL isolation level code */
 
7762
        enum_tx_isolation       iso)    /*!< in: MySQL isolation level code */
7667
7763
{
7668
7764
        switch(iso) {
7669
7765
                case ISO_REPEATABLE_READ: return(TRX_ISO_REPEATABLE_READ);
7674
7770
        }
7675
7771
}
7676
7772
 
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.
 
7781
@return 0 */
7685
7782
UNIV_INTERN
7686
7783
int
7687
7784
ha_innobase::external_lock(
7688
7785
/*=======================*/
7689
 
                                /* out: 0 */
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 */
7692
7788
{
7693
7789
        trx_t*          trx;
7694
7790
 
7842
7938
        DBUG_RETURN(0);
7843
7939
}
7844
7940
 
7845
 
/**********************************************************************
 
7941
/******************************************************************//**
7846
7942
With this function MySQL request a transactional lock to a table when
7847
 
user issued query LOCK TABLES..WHERE ENGINE = InnoDB. */
 
7943
user issued query LOCK TABLES..WHERE ENGINE = InnoDB.
 
7944
@return error code */
7848
7945
UNIV_INTERN
7849
7946
int
7850
7947
ha_innobase::transactional_table_lock(
7851
7948
/*==================================*/
7852
 
                                /* out: error code */
7853
 
        THD*    thd,            /* in: handle to the user thread */
7854
 
        int     lock_type)      /* in: lock type */
 
7949
        THD*    thd,            /*!< in: handle to the user thread */
 
7950
        int     lock_type)      /*!< in: lock type */
7855
7951
{
7856
7952
        trx_t*          trx;
7857
7953
 
7873
7969
                        "InnoDB: Have you deleted the .ibd file"
7874
7970
                        " from the database directory under\n"
7875
7971
                        "InnoDB: the MySQL datadir?"
7876
 
                        "InnoDB: See"
7877
 
                        " http://dev.mysql.com/doc/refman/5.1/en/innodb-troubleshooting.html\n"
 
7972
                        "InnoDB: See " REFMAN
 
7973
                        "innodb-troubleshooting.html\n"
7878
7974
                        "InnoDB: how you can resolve the problem.\n",
7879
7975
                        prebuilt->table->name);
7880
7976
                DBUG_RETURN(HA_ERR_CRASHED);
7935
8031
        DBUG_RETURN(0);
7936
8032
}
7937
8033
 
7938
 
/****************************************************************************
7939
 
Here we export InnoDB status variables to MySQL.  */
 
8034
/************************************************************************//**
 
8035
Here we export InnoDB status variables to MySQL. */
7940
8036
static
7941
 
int
7942
 
innodb_export_status()
7943
 
/*==================*/
 
8037
void
 
8038
innodb_export_status(void)
 
8039
/*======================*/
7944
8040
{
7945
8041
        if (innodb_inited) {
7946
8042
                srv_export_innodb_status();
7947
8043
        }
7948
 
 
7949
 
        return(0);
7950
8044
}
7951
8045
 
7952
 
/****************************************************************************
 
8046
/************************************************************************//**
7953
8047
Implements the SHOW INNODB STATUS command. Sends the output of the InnoDB
7954
8048
Monitor to the client. */
7955
8049
static
7956
8050
bool
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)
7962
8056
{
7963
8057
        trx_t*                  trx;
8029
8123
 
8030
8124
        bool result = FALSE;
8031
8125
 
8032
 
        if (stat_print(thd, innobase_hton_name, strlen(innobase_hton_name),
 
8126
        if (stat_print(thd, innobase_hton_name, (uint) strlen(innobase_hton_name),
8033
8127
                        STRING_WITH_LEN(""), str, flen)) {
8034
8128
                result= TRUE;
8035
8129
        }
8038
8132
        DBUG_RETURN(FALSE);
8039
8133
}
8040
8134
 
8041
 
/****************************************************************************
 
8135
/************************************************************************//**
8042
8136
Implements the SHOW MUTEX STATUS command. . */
8043
8137
static
8044
8138
bool
8045
8139
innodb_mutex_show_status(
8046
8140
/*=====================*/
8047
 
        handlerton*     hton,   /* in: the innodb handlerton */
8048
 
        THD*            thd,            /* in: the MySQL query thread of the
 
8141
        handlerton*     hton,   /*!< in: the innodb handlerton */
 
8142
        THD*            thd,            /*!< in: the MySQL query thread of the
8049
8143
                                        caller */
8050
8144
        stat_print_fn*  stat_print)
8051
8145
{
8060
8154
        ulint     rw_lock_count_os_yield= 0;
8061
8155
        ulonglong rw_lock_wait_time= 0;
8062
8156
#endif /* UNIV_DEBUG */
8063
 
        uint      hton_name_len= strlen(innobase_hton_name), buf1len, buf2len;
 
8157
        uint      hton_name_len= (uint) strlen(innobase_hton_name), buf1len, buf2len;
8064
8158
        DBUG_ENTER("innodb_mutex_show_status");
8065
8159
        DBUG_ASSERT(hton == innodb_hton_ptr);
8066
8160
 
8069
8163
        mutex = UT_LIST_GET_FIRST(mutex_list);
8070
8164
 
8071
8165
        while (mutex != NULL) {
 
8166
                if (mutex->count_os_wait == 0
 
8167
                    || buf_pool_is_block_mutex(mutex)) {
 
8168
                        goto next_mutex;
 
8169
                }
8072
8170
#ifdef UNIV_DEBUG
8073
8171
                if (mutex->mutex_type != 1) {
8074
8172
                        if (mutex->count_using > 0) {
8104
8202
                        rw_lock_wait_time += mutex->lspent_time;
8105
8203
                }
8106
8204
#else /* UNIV_DEBUG */
8107
 
                buf1len= my_snprintf(buf1, sizeof(buf1), "%s:%lu",
 
8205
                buf1len= (uint) my_snprintf(buf1, sizeof(buf1), "%s:%lu",
8108
8206
                                     mutex->cfile_name, (ulong) mutex->cline);
8109
 
                buf2len= my_snprintf(buf2, sizeof(buf2), "os_waits=%lu",
 
8207
                buf2len= (uint) my_snprintf(buf2, sizeof(buf2), "os_waits=%lu",
8110
8208
                                     mutex->count_os_wait);
8111
8209
 
8112
8210
                if (stat_print(thd, innobase_hton_name,
8117
8215
                }
8118
8216
#endif /* UNIV_DEBUG */
8119
8217
 
 
8218
next_mutex:
8120
8219
                mutex = UT_LIST_GET_NEXT(list, mutex);
8121
8220
        }
8122
8221
 
8127
8226
        lock = UT_LIST_GET_FIRST(rw_lock_list);
8128
8227
 
8129
8228
        while (lock != NULL) {
8130
 
                if (lock->count_os_wait) {
 
8229
                if (lock->count_os_wait
 
8230
                    && !buf_pool_is_block_lock(lock)) {
8131
8231
                        buf1len= my_snprintf(buf1, sizeof(buf1), "%s:%lu",
8132
8232
                                    lock->cfile_name, (ulong) lock->cline);
8133
8233
                        buf2len= my_snprintf(buf2, sizeof(buf2),
8180
8280
        }
8181
8281
}
8182
8282
 
8183
 
/****************************************************************************
 
8283
/************************************************************************//**
8184
8284
 Handling the shared INNOBASE_SHARE structure that is needed to provide table
8185
8285
 locking.
8186
8286
****************************************************************************/
8214
8314
                            innobase_open_tables, fold, share);
8215
8315
 
8216
8316
                thr_lock_init(&share->lock);
8217
 
                pthread_mutex_init(&share->mutex,MY_MUTEX_INIT_FAST);
8218
8317
        }
8219
8318
 
8220
8319
        share->use_count++;
8245
8344
                HASH_DELETE(INNOBASE_SHARE, table_name_hash,
8246
8345
                            innobase_open_tables, fold, share);
8247
8346
                thr_lock_delete(&share->lock);
8248
 
                pthread_mutex_destroy(&share->mutex);
8249
8347
                my_free(share, MYF(0));
8250
8348
 
8251
8349
                /* TODO: invoke HASH_MIGRATE if innobase_open_tables
8255
8353
        pthread_mutex_unlock(&innobase_share_mutex);
8256
8354
}
8257
8355
 
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 */
8266
8365
UNIV_INTERN
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
8280
8377
                                                TL_IGNORE */
8281
8378
{
8458
8555
        return(to);
8459
8556
}
8460
8557
 
8461
 
/*******************************************************************************
 
8558
/*********************************************************************//**
8462
8559
Read the next autoinc value. Acquire the relevant locks before reading
8463
8560
the AUTOINC value. If SUCCESS then the table AUTOINC mutex will be locked
8464
 
on return and all relevant locks acquired. */
 
8561
on return and all relevant locks acquired.
 
8562
@return DB_SUCCESS or error code */
8465
8563
UNIV_INTERN
8466
8564
ulint
8467
8565
ha_innobase::innobase_get_autoinc(
8468
8566
/*==============================*/
8469
 
                                        /* out: DB_SUCCESS or error code */
8470
 
        ulonglong*      value)          /* out: autoinc value */
 
8567
        ulonglong*      value)          /*!< out: autoinc value */
8471
8568
{
8472
8569
        *value = 0;
8473
8570
 
8485
8582
        return(prebuilt->autoinc_error);
8486
8583
}
8487
8584
 
8488
 
/***********************************************************************
 
8585
/*******************************************************************//**
8489
8586
This function reads the global auto-inc counter. It doesn't use the 
8490
 
AUTOINC lock even if the lock mode is set to TRADITIONAL. */
 
8587
AUTOINC lock even if the lock mode is set to TRADITIONAL.
 
8588
@return the autoinc value */
8491
8589
UNIV_INTERN
8492
8590
ulonglong
8493
8591
ha_innobase::innobase_peek_autoinc(void)
8494
8592
/*====================================*/
8495
 
                                        /* out: the autoinc value */
8496
8593
{
8497
8594
        ulonglong       auto_inc;
8498
8595
        dict_table_t*   innodb_table;
8509
8606
        ut_a(auto_inc > 0);
8510
8607
 
8511
8608
        dict_table_autoinc_unlock(innodb_table);
8512
 
 
 
8609
 
8513
8610
        return(auto_inc);
8514
8611
}
8515
 
  
8516
 
/*******************************************************************************
 
8612
 
 
8613
/*********************************************************************//**
8517
8614
This function initializes the auto-inc counter if it has not been
8518
8615
initialized yet. This function does not change the value of the auto-inc
8519
8616
counter if it already has been initialized. Returns the value of the
8524
8621
void
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 */
8532
8629
{
8533
8630
        trx_t*          trx;
8534
8631
        ulint           error;
8622
8719
        dict_table_autoinc_unlock(prebuilt->table);
8623
8720
}
8624
8721
 
8625
 
/* See comment in handler.h */
 
8722
/*******************************************************************//**
 
8723
Reset the auto-increment counter to the given value, i.e. the next row
 
8724
inserted will get the given value. This is called e.g. after TRUNCATE
 
8725
is emulated by doing a 'DELETE FROM t'. HA_ERR_WRONG_COMMAND is
 
8726
returned by storage engines that don't support this operation.
 
8727
@return 0 or error code */
8626
8728
UNIV_INTERN
8627
8729
int
8628
8730
ha_innobase::reset_auto_increment(
8629
8731
/*==============================*/
8630
 
        ulonglong       value)          /* in: new value for table autoinc */
 
8732
        ulonglong       value)          /*!< in: new value for table autoinc */
8631
8733
{
8632
8734
        DBUG_ENTER("ha_innobase::reset_auto_increment");
8633
8735
 
8662
8764
{
8663
8765
        trx_t*  trx = check_trx_exists(ha_thd());
8664
8766
 
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);
8667
8769
 
8668
8770
        return(FALSE);
8669
8771
}
8670
8772
 
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 */
8675
8778
UNIV_INTERN
8676
8779
int
8677
8780
ha_innobase::cmp_ref(
8678
8781
/*=================*/
8679
 
                                /* out: < 0 if ref1 < ref2, 0 if equal, else
8680
 
                                > 0 */
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 */
8685
8786
{
8686
8787
        enum_field_types mysql_type;
8740
8841
        return(0);
8741
8842
}
8742
8843
 
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 */
8745
8847
UNIV_INTERN
8746
8848
my_bool
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 */
8762
8862
{
8763
8863
        *call_back = innobase_query_caching_of_table_permitted;
8764
8864
        *engine_data = 0;
8784
8884
        return(trx_sys_mysql_bin_log_pos);
8785
8885
}
8786
8886
 
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.
8792
 
 
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
8796
8894
ulint
8797
8895
innobase_get_at_most_n_mbchars(
8798
8896
/*===========================*/
8799
 
                                /* out: number of bytes occupied by the first
8800
 
                                n characters */
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 */
8807
8903
{
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 */
8811
8907
 
8812
8908
        charset = get_charset((uint) charset_id, MYF(MY_WME));
8813
8909
 
8858
8954
        return(char_length);
8859
8955
}
8860
8956
 
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 */
8863
8960
static
8864
8961
int
8865
8962
innobase_xa_prepare(
8866
8963
/*================*/
8867
 
                        /* out: 0 or error number */
8868
 
        handlerton *hton,
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
 
8967
                                be prepared */
 
8968
        bool            all)    /*!< in: TRUE - commit transaction
 
8969
                                FALSE - the current SQL statement
 
8970
                                ended */
8873
8971
{
8874
8972
        int error = 0;
8875
8973
        trx_t* trx = check_trx_exists(thd);
8876
8974
 
8877
8975
        DBUG_ASSERT(hton == innodb_hton_ptr);
8878
8976
 
 
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) {
 
8981
 
 
8982
                return(0);
 
8983
        }
 
8984
 
 
8985
        thd_get_xid(thd, (MYSQL_XID*) &trx->xid);
 
8986
 
 
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. */
 
8990
 
 
8991
        innobase_release_stat_resources(trx);
 
8992
 
 
8993
        if (trx->active_trans == 0 && trx->conc_state != TRX_NOT_STARTED) {
 
8994
 
 
8995
          sql_print_error("trx->active_trans == 0, but trx->conc_state != "
 
8996
                          "TRX_NOT_STARTED");
 
8997
        }
 
8998
 
 
8999
        if (all
 
9000
                || (!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))) {
 
9001
 
 
9002
                /* We were instructed to prepare the whole transaction, or
 
9003
                this is an SQL statement end and autocommit is on */
 
9004
 
 
9005
                ut_ad(trx->active_trans);
 
9006
 
 
9007
                error = (int) trx_prepare_for_mysql(trx);
 
9008
        } else {
 
9009
                /* We just mark the SQL statement ended and do not do a
 
9010
                transaction prepare */
 
9011
 
 
9012
                /* If we had reserved the auto-inc lock for some
 
9013
                table in this SQL statement we release it now */
 
9014
 
 
9015
                row_unlock_table_autoinc_for_mysql(trx);
 
9016
 
 
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
 
9019
                SQL statement */
 
9020
 
 
9021
                trx_mark_sql_stat_end(trx);
 
9022
        }
 
9023
 
 
9024
        /* Tell the InnoDB server that there might be work for utility
 
9025
        threads: */
 
9026
 
 
9027
        srv_active_wake_master_thread();
 
9028
 
8879
9029
        if (thd_sql_command(thd) != SQLCOM_XA_PREPARE &&
8880
9030
            (all || !thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))
8881
9031
        {
8903
9053
                trx->active_trans = 2;
8904
9054
        }
8905
9055
 
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) {
8910
 
 
8911
 
                return(0);
8912
 
        }
8913
 
 
8914
 
        thd_get_xid(thd, (MYSQL_XID*) &trx->xid);
8915
 
 
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. */
8919
 
 
8920
 
        innobase_release_stat_resources(trx);
8921
 
 
8922
 
        if (trx->active_trans == 0 && trx->conc_state != TRX_NOT_STARTED) {
8923
 
 
8924
 
          sql_print_error("trx->active_trans == 0, but trx->conc_state != "
8925
 
                          "TRX_NOT_STARTED");
8926
 
        }
8927
 
 
8928
 
        if (all
8929
 
                || (!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))) {
8930
 
 
8931
 
                /* We were instructed to prepare the whole transaction, or
8932
 
                this is an SQL statement end and autocommit is on */
8933
 
 
8934
 
                ut_ad(trx->active_trans);
8935
 
 
8936
 
                error = (int) trx_prepare_for_mysql(trx);
8937
 
        } else {
8938
 
                /* We just mark the SQL statement ended and do not do a
8939
 
                transaction prepare */
8940
 
 
8941
 
                /* If we had reserved the auto-inc lock for some
8942
 
                table in this SQL statement we release it now */
8943
 
 
8944
 
                row_unlock_table_autoinc_for_mysql(trx);
8945
 
 
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
8948
 
                SQL statement */
8949
 
 
8950
 
                trx_mark_sql_stat_end(trx);
8951
 
        }
8952
 
 
8953
 
        /* Tell the InnoDB server that there might be work for utility
8954
 
        threads: */
8955
 
 
8956
 
        srv_active_wake_master_thread();
8957
 
 
8958
9056
        return(error);
8959
9057
}
8960
9058
 
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 */
8963
9062
static
8964
9063
int
8965
9064
innobase_xa_recover(
8966
9065
/*================*/
8967
 
                                /* out: number of prepared transactions
8968
 
                                stored in xid_list */
8969
 
        handlerton *hton,
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 */
8972
9069
{
8973
9070
        DBUG_ASSERT(hton == innodb_hton_ptr);
8974
9071
 
8980
9077
        return(trx_recover_for_mysql(xid_list, len));
8981
9078
}
8982
9079
 
8983
 
/***********************************************************************
 
9080
/*******************************************************************//**
8984
9081
This function is used to commit one X/Open XA distributed transaction
8985
 
which is in the prepared state */
 
9082
which is in the prepared state
 
9083
@return 0 or error number */
8986
9084
static
8987
9085
int
8988
9086
innobase_commit_by_xid(
8989
9087
/*===================*/
8990
 
                        /* out: 0 or error number */
8991
9088
        handlerton *hton,
8992
 
        XID*    xid)    /* in: X/Open XA transaction identification */
 
9089
        XID*    xid)    /*!< in: X/Open XA transaction identification */
8993
9090
{
8994
9091
        trx_t*  trx;
8995
9092
 
9006
9103
        }
9007
9104
}
9008
9105
 
9009
 
/***********************************************************************
 
9106
/*******************************************************************//**
9010
9107
This function is used to rollback one X/Open XA distributed transaction
9011
 
which is in the prepared state */
 
9108
which is in the prepared state
 
9109
@return 0 or error number */
9012
9110
static
9013
9111
int
9014
9112
innobase_rollback_by_xid(
9015
9113
/*=====================*/
9016
 
                        /* out: 0 or error number */
9017
 
        handlerton *hton,
9018
 
        XID     *xid)   /* in: X/Open XA transaction identification */
 
9114
        handlerton*     hton,   /*!< in: InnoDB handlerton */
 
9115
        XID*            xid)    /*!< in: X/Open XA transaction
 
9116
                                identification */
9019
9117
{
9020
9118
        trx_t*  trx;
9021
9119
 
9030
9128
        }
9031
9129
}
9032
9130
 
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
9037
 
using a cursor. */
 
9135
using a cursor.
 
9136
@return pointer to cursor view or NULL */
9038
9137
static
9039
9138
void*
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 */
9045
9143
{
9046
9144
        DBUG_ASSERT(hton == innodb_hton_ptr);
9047
9145
 
9048
9146
        return(read_cursor_view_create_for_mysql(check_trx_exists(thd)));
9049
9147
}
9050
9148
 
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. */
9057
9155
innobase_close_cursor_view(
9058
9156
/*=======================*/
9059
9157
        handlerton *hton,
9060
 
        THD*    thd,    /* in: user thread handle */
9061
 
        void*   curview)/* in: Consistent read view to be closed */
 
9158
        THD*    thd,    /*!< in: user thread handle */
 
9159
        void*   curview)/*!< in: Consistent read view to be closed */
9062
9160
{
9063
9161
        DBUG_ASSERT(hton == innodb_hton_ptr);
9064
9162
 
9066
9164
                                         (cursor_view_t*) curview);
9067
9165
}
9068
9166
 
9069
 
/***********************************************************************
 
9167
/*******************************************************************//**
9070
9168
Set the given consistent cursor view to a transaction which is created
9071
9169
if the corresponding MySQL thread still lacks one. If the given
9072
9170
consistent cursor view is NULL global read view of a transaction is
9076
9174
innobase_set_cursor_view(
9077
9175
/*=====================*/
9078
9176
        handlerton *hton,
9079
 
        THD*    thd,    /* in: user thread handle */
9080
 
        void*   curview)/* in: Consistent cursor view to be set */
 
9177
        THD*    thd,    /*!< in: user thread handle */
 
9178
        void*   curview)/*!< in: Consistent cursor view to be set */
9081
9179
{
9082
9180
        DBUG_ASSERT(hton == innodb_hton_ptr);
9083
9181
 
9086
9184
}
9087
9185
 
9088
9186
 
 
9187
/***********************************************************************
 
9188
Check whether any of the given columns is being renamed in the table. */
 
9189
static
 
9190
bool
 
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 */
 
9198
{
 
9199
        uint            j;
 
9200
        uint            k;
 
9201
        Field*          field;
 
9202
        const char*     col_name;
 
9203
 
 
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,
 
9210
                                                   col_name) == 0) {
 
9211
                                return(true);
 
9212
                        }
 
9213
                }
 
9214
        }
 
9215
 
 
9216
        return(false);
 
9217
}
 
9218
 
 
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. */
 
9223
static
 
9224
bool
 
9225
foreign_key_column_is_being_renamed(
 
9226
/*================================*/
 
9227
                                        /* out: true if a column that
 
9228
                                        participates in a foreign key definition
 
9229
                                        is being renamed */
 
9230
        row_prebuilt_t* prebuilt,       /* in: InnoDB prebuilt struct */
 
9231
        TABLE*          table)          /* in: MySQL table */
 
9232
{
 
9233
        dict_foreign_t* foreign;
 
9234
 
 
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 */
 
9239
 
 
9240
                return(false);
 
9241
        }
 
9242
 
 
9243
        row_mysql_lock_data_dictionary(prebuilt->trx);
 
9244
 
 
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);
 
9248
             foreign != NULL;
 
9249
             foreign = UT_LIST_GET_NEXT(referenced_list, foreign)) {
 
9250
 
 
9251
                if (column_is_being_renamed(table, foreign->n_fields,
 
9252
                                            foreign->referenced_col_names)) {
 
9253
 
 
9254
                        row_mysql_unlock_data_dictionary(prebuilt->trx);
 
9255
                        return(true);
 
9256
                }
 
9257
        }
 
9258
 
 
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);
 
9262
             foreign != NULL;
 
9263
             foreign = UT_LIST_GET_NEXT(foreign_list, foreign)) {
 
9264
 
 
9265
                if (column_is_being_renamed(table, foreign->n_fields,
 
9266
                                            foreign->foreign_col_names)) {
 
9267
 
 
9268
                        row_mysql_unlock_data_dictionary(prebuilt->trx);
 
9269
                        return(true);
 
9270
                }
 
9271
        }
 
9272
 
 
9273
        row_mysql_unlock_data_dictionary(prebuilt->trx);
 
9274
 
 
9275
        return(false);
 
9276
}
 
9277
 
9089
9278
UNIV_INTERN
9090
9279
bool
9091
9280
ha_innobase::check_if_incompatible_data(
9104
9293
                return(COMPATIBLE_DATA_NO);
9105
9294
        }
9106
9295
 
 
9296
        /* Check if a column participating in a foreign key is being renamed.
 
9297
        There is no mechanism for updating InnoDB foreign key definitions. */
 
9298
        if (foreign_key_column_is_being_renamed(prebuilt, table)) {
 
9299
 
 
9300
                return COMPATIBLE_DATA_NO;
 
9301
        }
 
9302
 
9107
9303
        /* Check that row format didn't change */
9108
 
        if ((info->used_fields & HA_CREATE_USED_ROW_FORMAT) &&
9109
 
            get_row_type() != info->row_type) {
 
9304
        if ((info->used_fields & HA_CREATE_USED_ROW_FORMAT)
 
9305
            && info->row_type != ROW_TYPE_DEFAULT
 
9306
            && info->row_type != get_row_type()) {
9110
9307
 
9111
9308
                return(COMPATIBLE_DATA_NO);
9112
9309
        }
9119
9316
        return(COMPATIBLE_DATA_YES);
9120
9317
}
9121
9318
 
9122
 
/****************************************************************
9123
 
Validate the file format name and return its corresponding id. */
 
9319
/************************************************************//**
 
9320
Validate the file format name and return its corresponding id.
 
9321
@return valid file format id */
9124
9322
static
9125
9323
uint
9126
9324
innobase_file_format_name_lookup(
9127
9325
/*=============================*/
9128
 
                                        /* out: valid file format id*/
9129
 
        const char*     format_name)    /* in: pointer to file format name */
 
9326
        const char*     format_name)    /*!< in: pointer to file format name */
9130
9327
{
9131
9328
        char*   endp;
9132
9329
        uint    format_id;
9162
9359
        return(DICT_TF_FORMAT_MAX + 1);
9163
9360
}
9164
9361
 
9165
 
/****************************************************************
 
9362
/************************************************************//**
9166
9363
Validate the file format check value, is it one of "on" or "off",
9167
 
as a side effect it sets the srv_check_file_format_at_startup variable. */
 
9364
as a side effect it sets the srv_check_file_format_at_startup variable.
 
9365
@return true if config value one of "on" or  "off" */
9168
9366
static
9169
9367
bool
9170
9368
innobase_file_format_check_on_off(
9171
9369
/*==============================*/
9172
 
                                        /* out: true if config value one
9173
 
                                        of "on" or  "off" */
9174
 
        const char*     format_check)   /* in: parameter value */
 
9370
        const char*     format_check)   /*!< in: parameter value */
9175
9371
{
9176
9372
        bool            ret = true;
9177
9373
 
9191
9387
        return(ret);
9192
9388
}
9193
9389
 
9194
 
/****************************************************************
 
9390
/************************************************************//**
9195
9391
Validate the file format check config parameters, as a side effect it
9196
 
sets the srv_check_file_format_at_startup variable. */
 
9392
sets the srv_check_file_format_at_startup variable.
 
9393
@return true if valid config value */
9197
9394
static
9198
9395
bool
9199
9396
innobase_file_format_check_validate(
9200
9397
/*================================*/
9201
 
                                        /* out: true if valid config value */
9202
 
        const char*     format_check)   /* in: parameter value */
 
9398
        const char*     format_check)   /*!< in: parameter value */
9203
9399
{
9204
9400
        uint            format_id;
9205
9401
        bool            ret = true;
9215
9411
        return(ret);
9216
9412
}
9217
9413
 
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 */
9221
9418
static
9222
9419
int
9223
9420
innodb_file_format_name_validate(
9224
9421
/*=============================*/
9225
 
                                                /* out: 0 for valid file
9226
 
                                                format */
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
9229
9424
                                                variable */
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 */
9233
9428
{
9234
9429
        const char*     file_format_input;
9235
9430
        char            buff[STRING_BUFFER_USUAL_SIZE];
9248
9443
 
9249
9444
                if (format_id <= DICT_TF_FORMAT_MAX) {
9250
9445
 
9251
 
                        *(uint*) save = format_id;
 
9446
                        *static_cast<const char**>(save) = file_format_input;
9252
9447
                        return(0);
9253
9448
                }
9254
9449
        }
9255
9450
 
 
9451
        *static_cast<const char**>(save) = NULL;
9256
9452
        return(1);
9257
9453
}
9258
9454
 
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. */
9262
9458
static
9263
9459
void
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 */
9273
9469
{
 
9470
        const char* format_name;
 
9471
 
9274
9472
        ut_a(var_ptr != NULL);
9275
9473
        ut_a(save != NULL);
9276
 
        ut_a((*(const uint*) save) <= DICT_TF_FORMAT_MAX);
9277
 
 
9278
 
        srv_file_format = *(const uint*) save;
9279
 
 
9280
 
        *(const char**) var_ptr
 
9474
 
 
9475
        format_name = *static_cast<const char*const*>(save);
 
9476
 
 
9477
        if (format_name) {
 
9478
                uint    format_id;
 
9479
 
 
9480
                format_id = innobase_file_format_name_lookup(format_name);
 
9481
 
 
9482
                if (format_id <= DICT_TF_FORMAT_MAX) {
 
9483
                        srv_file_format = format_id;
 
9484
                }
 
9485
        }
 
9486
 
 
9487
        *static_cast<const char**>(var_ptr)
9281
9488
                = trx_sys_file_format_id_to_name(srv_file_format);
9282
9489
}
9283
9490
 
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 */
9287
9495
static
9288
9496
int
9289
9497
innodb_file_format_check_validate(
9290
9498
/*==============================*/
9291
 
                                                /* out: 0 for valid file
9292
 
                                                format */
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
9295
9501
                                                variable */
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 */
9299
9505
{
9300
9506
        const char*     file_format_input;
9301
9507
        char            buff[STRING_BUFFER_USUAL_SIZE];
9319
9525
                } else if (innobase_file_format_check_validate(
9320
9526
                                file_format_input)) {
9321
9527
 
9322
 
                        uint    format_id;
9323
 
 
9324
 
                        format_id = innobase_file_format_name_lookup(
9325
 
                                file_format_input);
9326
 
 
9327
 
                        ut_a(format_id <= DICT_TF_FORMAT_MAX);
9328
 
 
9329
 
                        *(uint*) save = format_id;
 
9528
                        *static_cast<const char**>(save) = file_format_input;
9330
9529
 
9331
9530
                        return(0);
9332
9531
 
9340
9539
                }
9341
9540
        }
9342
9541
 
 
9542
        *static_cast<const char**>(save) = NULL;
9343
9543
        return(1);
9344
9544
}
9345
9545
 
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. */
9349
9549
static
9350
9550
void
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 */
9360
9560
{
9361
 
        uint    format_id;
 
9561
        const char*     format_name_in;
 
9562
        const char**    format_name_out;
 
9563
        uint            format_id;
9362
9564
 
9363
9565
        ut_a(save != NULL);
9364
9566
        ut_a(var_ptr != NULL);
9365
9567
 
9366
 
        format_id = *(const uint*) save;
 
9568
        format_name_in = *static_cast<const char*const*>(save);
 
9569
 
 
9570
        if (!format_name_in) {
 
9571
 
 
9572
                return;
 
9573
        }
 
9574
 
 
9575
        format_id = innobase_file_format_name_lookup(format_name_in);
 
9576
 
 
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,
 
9580
                                    ER_WRONG_ARGUMENTS,
 
9581
                                    "Ignoring SET innodb_file_format=%s",
 
9582
                                    format_name_in);
 
9583
                return;
 
9584
        }
 
9585
 
 
9586
        format_name_out = static_cast<const char**>(var_ptr);
9367
9587
 
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);
9374
9594
        }
9375
9595
}
9376
9596
 
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. */
9380
9600
static
9381
9601
void
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 */
9391
9611
{
9392
9612
        if (*(my_bool*) save) {
9396
9616
        }
9397
9617
}
9398
9618
 
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 */
9402
9623
static
9403
9624
int
9404
9625
innodb_change_buffering_validate(
9405
9626
/*=============================*/
9406
 
                                                /* out: 0 for valid
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
9410
9629
                                                variable */
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 */
9414
9633
{
9415
9634
        const char*     change_buffering_input;
9416
9635
        char            buff[STRING_BUFFER_USUAL_SIZE];
9438
9657
        return(1);
9439
9658
}
9440
9659
 
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. */
9444
9663
static
9445
9664
void
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 */
9455
9674
{
9456
9675
        ut_a(var_ptr != NULL);
9496
9715
  "Disable with --skip-innodb-doublewrite.",
9497
9716
  NULL, NULL, TRUE);
9498
9717
 
 
9718
static MYSQL_SYSVAR_ULONG(io_capacity, srv_io_capacity,
 
9719
  PLUGIN_VAR_RQCMDARG,
 
9720
  "Number of IOPs the server can do. Tunes the background IO rate",
 
9721
  NULL, NULL, 200, 100, ~0L, 0);
 
9722
 
9499
9723
static MYSQL_SYSVAR_ULONG(fast_shutdown, innobase_fast_shutdown,
9500
9724
  PLUGIN_VAR_OPCMDARG,
9501
9725
  "Speeds up the shutdown process of the InnoDB storage engine. Possible "
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);
 
9787
 
 
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.",
 
9791
  NULL, NULL, TRUE);
9563
9792
 
9564
9793
static MYSQL_SYSVAR_ULONG(max_purge_lag, srv_max_purge_lag,
9565
9794
  PLUGIN_VAR_RQCMDARG,
9601
9830
static MYSQL_SYSVAR_LONG(additional_mem_pool_size, innobase_additional_mem_pool_size,
9602
9831
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
9603
9832
  "Size of a memory pool InnoDB uses to store data dictionary information and other internal data structures.",
9604
 
  NULL, NULL, 1*1024*1024L, 512*1024L, LONG_MAX, 1024);
 
9833
  NULL, NULL, 8*1024*1024L, 512*1024L, LONG_MAX, 1024);
9605
9834
 
9606
9835
static MYSQL_SYSVAR_ULONG(autoextend_increment, srv_auto_extend_increment,
9607
9836
  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);
9615
9844
 
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);
9620
9849
 
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);
9630
9859
 
 
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);
 
9864
 
 
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);
 
9869
 
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.",
9636
9875
static MYSQL_SYSVAR_LONG(log_buffer_size, innobase_log_buffer_size,
9637
9876
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
9638
9877
  "The size of the buffer which InnoDB uses to write log to the log files on disk.",
9639
 
  NULL, NULL, 1024*1024L, 256*1024L, LONG_MAX, 1024);
 
9878
  NULL, NULL, 8*1024*1024L, 256*1024L, LONG_MAX, 1024);
9640
9879
 
9641
9880
static MYSQL_SYSVAR_LONGLONG(log_file_size, innobase_log_file_size,
9642
9881
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
9660
9899
 
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);
 
9904
 
 
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);
9665
9909
 
9666
9910
static MYSQL_SYSVAR_ULONG(thread_concurrency, srv_thread_concurrency,
9667
9911
  PLUGIN_VAR_RQCMDARG,
9706
9950
  innodb_change_buffering_validate,
9707
9951
  innodb_change_buffering_update, NULL);
9708
9952
 
 
9953
static MYSQL_SYSVAR_ULONG(read_ahead_threshold, srv_read_ahead_threshold,
 
9954
  PLUGIN_VAR_RQCMDARG,
 
9955
  "Number of pages that must be accessed sequentially for InnoDB to"
 
9956
  "trigger a readahead.",
 
9957
  NULL, NULL, 56, 0, 64, 0);
 
9958
 
9709
9959
static struct st_mysql_sys_var* innobase_system_variables[]= {
9710
9960
  MYSQL_SYSVAR(additional_mem_pool_size),
9711
9961
  MYSQL_SYSVAR(autoextend_increment),
9718
9968
  MYSQL_SYSVAR(doublewrite),
9719
9969
  MYSQL_SYSVAR(fast_shutdown),
9720
9970
  MYSQL_SYSVAR(file_io_threads),
 
9971
  MYSQL_SYSVAR(read_io_threads),
 
9972
  MYSQL_SYSVAR(write_io_threads),
9721
9973
  MYSQL_SYSVAR(file_per_table),
9722
9974
  MYSQL_SYSVAR(file_format),
9723
9975
  MYSQL_SYSVAR(file_format_check),
9735
9987
  MYSQL_SYSVAR(log_files_in_group),
9736
9988
  MYSQL_SYSVAR(log_group_home_dir),
9737
9989
  MYSQL_SYSVAR(max_dirty_pages_pct),
 
9990
  MYSQL_SYSVAR(adaptive_flushing),
9738
9991
  MYSQL_SYSVAR(max_purge_lag),
9739
9992
  MYSQL_SYSVAR(mirrored_log_groups),
9740
9993
  MYSQL_SYSVAR(open_files),
9747
10000
  MYSQL_SYSVAR(strict_mode),
9748
10001
  MYSQL_SYSVAR(support_xa),
9749
10002
  MYSQL_SYSVAR(sync_spin_loops),
 
10003
  MYSQL_SYSVAR(spin_wait_delay),
9750
10004
  MYSQL_SYSVAR(table_locks),
9751
10005
  MYSQL_SYSVAR(thread_concurrency),
9752
10006
  MYSQL_SYSVAR(thread_sleep_delay),
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),
9757
10013
  NULL
9758
10014
};
9759
10015
 
9760
 
#ifdef MYSQL_DYNAMIC_PLUGIN
9761
 
struct st_mysql_sys_var
9762
 
{
9763
 
        MYSQL_PLUGIN_VAR_HEADER;
9764
 
        void* value;
9765
 
};
9766
 
 
9767
 
struct param_mapping
9768
 
{
9769
 
        const char*     server;         /* Parameter name in the server. */
9770
 
        const char*     plugin;         /* Paramater name in the plugin. */
9771
 
};
9772
 
 
9773
 
/********************************************************************
9774
 
Match the parameters from the static and dynamic versions. */
9775
 
static
9776
 
bool
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 */
9782
 
{
9783
 
        static const param_mapping param_map[] = {
9784
 
                {"use_adaptive_hash_indexes", "adaptive_hash_index"}
9785
 
        };
9786
 
 
9787
 
        if (strcmp(from_server, from_plugin) == 0) {
9788
 
                return(true);
9789
 
        }
9790
 
 
9791
 
        const param_mapping*    param = param_map;
9792
 
        int     n_elems = sizeof(param_map) / sizeof(param_map[0]);
9793
 
 
9794
 
        for (int i = 0; i < n_elems; ++i, ++param) {
9795
 
 
9796
 
                if (strcmp(param->server, from_server) == 0
9797
 
                    && strcmp(param->plugin, from_plugin) == 0) {
9798
 
 
9799
 
                        return(true);
9800
 
                }
9801
 
        }
9802
 
 
9803
 
        return(false);
9804
 
}
9805
 
 
9806
 
/********************************************************************
9807
 
Copy InnoDB system variables from the static InnoDB to the dynamic
9808
 
plugin. */
9809
 
static
9810
 
bool
9811
 
innodb_plugin_init(void)
9812
 
/*====================*/
9813
 
                /* out: TRUE if the dynamic InnoDB plugin should start */
9814
 
{
9815
 
#if !MYSQL_STORAGE_ENGINE_PLUGIN
9816
 
#error "MYSQL_STORAGE_ENGINE_PLUGIN must be nonzero."
9817
 
#endif
9818
 
 
9819
 
        /* Copy the system variables. */
9820
 
 
9821
 
        struct st_mysql_plugin*         builtin;
9822
 
        struct st_mysql_sys_var**       sta; /* static parameters */
9823
 
        struct st_mysql_sys_var**       dyn; /* dynamic parameters */
9824
 
 
9825
 
#ifdef __WIN__
9826
 
        if (!builtin_innobase_plugin_ptr) {
9827
 
 
9828
 
                return(true);
9829
 
        }
9830
 
 
9831
 
        builtin = builtin_innobase_plugin_ptr;
9832
 
#else
9833
 
        switch (builtin_innobase_plugin) {
9834
 
        case 0:
9835
 
                return(true);
9836
 
        case MYSQL_STORAGE_ENGINE_PLUGIN:
9837
 
                break;
9838
 
        default:
9839
 
                return(false);
9840
 
        }
9841
 
 
9842
 
        builtin = (struct st_mysql_plugin*) &builtin_innobase_plugin;
9843
 
#endif
9844
 
 
9845
 
        for (sta = builtin->system_vars; *sta != NULL; sta++) {
9846
 
 
9847
 
                for (dyn = innobase_system_variables; *dyn != NULL; dyn++) {
9848
 
 
9849
 
                        /* do not copy session variables */
9850
 
                        if (((*sta)->flags | (*dyn)->flags)
9851
 
                            & PLUGIN_VAR_THDLOCAL) {
9852
 
                                continue;
9853
 
                        }
9854
 
 
9855
 
                        if (innobase_match_parameter((*sta)->name,
9856
 
                                                     (*dyn)->name)) {
9857
 
 
9858
 
                                /* found the corresponding parameter */
9859
 
 
9860
 
                                /* check if the flags are the same,
9861
 
                                ignoring differences in the READONLY or
9862
 
                                NOSYSVAR flags;
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
9866
 
                                dynamic */
9867
 
                                if (((*sta)->flags ^ (*dyn)->flags)
9868
 
                                    & ~(PLUGIN_VAR_READONLY
9869
 
                                        | PLUGIN_VAR_NOSYSVAR)) {
9870
 
 
9871
 
                                        fprintf(stderr,
9872
 
                                                "InnoDB: %s in static InnoDB "
9873
 
                                                "(flags=0x%x) differs from "
9874
 
                                                "%s in dynamic InnoDB "
9875
 
                                                "(flags=0x%x)\n",
9876
 
                                                (*sta)->name, (*sta)->flags,
9877
 
                                                (*dyn)->name, (*dyn)->flags);
9878
 
 
9879
 
                                        /* we could break; here leaving this
9880
 
                                        parameter uncopied */
9881
 
                                        return(false);
9882
 
                                }
9883
 
 
9884
 
                                /* assign the value of the static parameter
9885
 
                                to the dynamic one, according to their type */
9886
 
 
9887
 
#define COPY_VAR(label, type)                                   \
9888
 
        case label:                                             \
9889
 
                *(type*)(*dyn)->value = *(type*)(*sta)->value;  \
9890
 
                break;
9891
 
 
9892
 
                                switch ((*sta)->flags
9893
 
                                        & ~(PLUGIN_VAR_MASK
9894
 
                                            | PLUGIN_VAR_UNSIGNED)) {
9895
 
 
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*);
9901
 
 
9902
 
                                default:
9903
 
                                        fprintf(stderr,
9904
 
                                                "InnoDB: unknown flags "
9905
 
                                                "0x%x for %s\n",
9906
 
                                                (*sta)->flags, (*sta)->name);
9907
 
                                }
9908
 
 
9909
 
                                /* Make the static InnoDB variable point to
9910
 
                                the dynamic one */
9911
 
                                (*sta)->value = (*dyn)->value;
9912
 
 
9913
 
                                break;
9914
 
                        }
9915
 
                }
9916
 
        }
9917
 
 
9918
 
        return(true);
9919
 
}
9920
 
#endif /* MYSQL_DYNAMIC_PLUGIN */
9921
 
 
9922
10016
mysql_declare_plugin(innobase)
9923
10017
{
9924
10018
  MYSQL_STORAGE_ENGINE_PLUGIN,
9943
10037
i_s_innodb_cmpmem_reset
9944
10038
mysql_declare_plugin_end;
9945
10039
 
 
10040
/** @brief Initialize the default value of innodb_commit_concurrency.
 
10041
 
 
10042
Once InnoDB is running, the innodb_commit_concurrency must not change
 
10043
from zero to nonzero. (Bug #42101)
 
10044
 
 
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. */
 
10049
static
 
10050
void
 
10051
innobase_commit_concurrency_init_default(void)
 
10052
/*==========================================*/
 
10053
{
 
10054
        MYSQL_SYSVAR_NAME(commit_concurrency).def_val
 
10055
                = innobase_commit_concurrency;
 
10056
}
 
10057
 
9946
10058
#ifdef UNIV_COMPILE_TEST_FUNCS
9947
10059
 
9948
10060
typedef struct innobase_convert_name_test_struct {