~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2010-06-21 15:31:05 UTC
  • mfrom: (1.1.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: james.westby@ubuntu.com-20100621153105-pbbz3t6nyrf9t2zq
Tags: upstream-5.1.48
ImportĀ upstreamĀ versionĀ 5.1.48

Show diffs side-by-side

added added

removed removed

Lines of Context:
1004
1004
        return(thd_charset((THD*) mysql_thd));
1005
1005
}
1006
1006
 
 
1007
/**********************************************************************//**
 
1008
Determines the current SQL statement.
 
1009
@return SQL statement string */
 
1010
extern "C" UNIV_INTERN
 
1011
const char*
 
1012
innobase_get_stmt(
 
1013
/*==============*/
 
1014
        void*   mysql_thd,      /*!< in: MySQL thread handle */
 
1015
        size_t* length)         /*!< out: length of the SQL statement */
 
1016
{
 
1017
#if MYSQL_VERSION_ID >= 50142
 
1018
        LEX_STRING* stmt;
 
1019
 
 
1020
        stmt = thd_query_string((THD*) mysql_thd);
 
1021
        *length = stmt->length;
 
1022
        return(stmt->str);
 
1023
#else
 
1024
        const char*     stmt_str = thd_query((THD*) mysql_thd);
 
1025
        *length = strlen(stmt_str);
 
1026
        return(stmt_str);
 
1027
#endif
 
1028
}
 
1029
 
1007
1030
#if defined (__WIN__) && defined (MYSQL_DYNAMIC_PLUGIN)
1008
1031
extern MYSQL_PLUGIN_IMPORT MY_TMPDIR mysql_tmpdir_list;
1009
1032
/*******************************************************************//**
1314
1337
        trx = trx_allocate_for_mysql();
1315
1338
 
1316
1339
        trx->mysql_thd = thd;
1317
 
        trx->mysql_query_str = thd_query(thd);
1318
1340
 
1319
1341
        innobase_trx_init(thd, trx);
1320
1342
 
6433
6455
        /* Cache the value of innodb_file_format, in case it is
6434
6456
        modified by another thread while the table is being created. */
6435
6457
        const ulint     file_format = srv_file_format;
 
6458
        const char*     stmt;
 
6459
        size_t          stmt_len;
6436
6460
 
6437
6461
        DBUG_ENTER("ha_innobase::create");
6438
6462
 
6649
6673
                         (int) form->s->primary_key :
6650
6674
                         -1);
6651
6675
 
6652
 
        /* Our function row_get_mysql_key_number_for_index assumes
 
6676
        /* Our function innobase_get_mysql_key_number_for_index assumes
6653
6677
        the primary key is always number 0, if it exists */
6654
6678
 
6655
6679
        ut_a(primary_key_no == -1 || primary_key_no == 0);
6709
6733
                }
6710
6734
        }
6711
6735
 
6712
 
        if (*trx->mysql_query_str) {
6713
 
                error = row_table_add_foreign_constraints(trx,
6714
 
                        *trx->mysql_query_str, norm_name,
 
6736
        stmt = innobase_get_stmt(thd, &stmt_len);
 
6737
 
 
6738
        if (stmt) {
 
6739
                error = row_table_add_foreign_constraints(
 
6740
                        trx, stmt, stmt_len, norm_name,
6715
6741
                        create_info->options & HA_LEX_CREATE_TMP_TABLE);
6716
6742
 
6717
6743
                error = convert_error_code_to_mysql(error, flags, NULL);
6996
7022
        /* In the Windows plugin, thd = current_thd is always NULL */
6997
7023
        trx = trx_allocate_for_mysql();
6998
7024
        trx->mysql_thd = NULL;
6999
 
        trx->mysql_query_str = NULL;
7000
7025
#else
7001
7026
        trx = innobase_trx_allocate(thd);
7002
7027
#endif
7365
7390
}
7366
7391
 
7367
7392
/*********************************************************************//**
 
7393
Calculates the key number used inside MySQL for an Innobase index. We will
 
7394
first check the "index translation table" for a match of the index to get
 
7395
the index number. If there does not exist an "index translation table",
 
7396
or not able to find the index in the translation table, then we will fall back
 
7397
to the traditional way of looping through dict_index_t list to find a
 
7398
match. In this case, we have to take into account if we generated a
 
7399
default clustered index for the table
 
7400
@return the key number used inside MySQL */
 
7401
static
 
7402
unsigned int
 
7403
innobase_get_mysql_key_number_for_index(
 
7404
/*====================================*/
 
7405
        INNOBASE_SHARE*         share,  /*!< in: share structure for index
 
7406
                                        translation table. */
 
7407
        const TABLE*            table,  /*!< in: table in MySQL data
 
7408
                                        dictionary */
 
7409
        dict_table_t*           ib_table,/*!< in: table in Innodb data
 
7410
                                        dictionary */
 
7411
        const dict_index_t*     index)  /*!< in: index */
 
7412
{
 
7413
        const dict_index_t*     ind;
 
7414
        unsigned int            i;
 
7415
 
 
7416
        ut_ad(index);
 
7417
        ut_ad(ib_table);
 
7418
        ut_ad(table);
 
7419
        ut_ad(share);
 
7420
 
 
7421
        /* If index does not belong to the table of share structure. Search
 
7422
        index->table instead */
 
7423
        if (index->table != ib_table
 
7424
            && strcmp(index->table->name, share->table_name)) {
 
7425
                i = 0;
 
7426
                ind = dict_table_get_first_index(index->table);
 
7427
 
 
7428
                while (index != ind) {
 
7429
                        ind = dict_table_get_next_index(ind);
 
7430
                        i++;
 
7431
                }
 
7432
 
 
7433
                if (row_table_got_default_clust_index(index->table)) {
 
7434
                        ut_a(i > 0);
 
7435
                        i--;
 
7436
                }
 
7437
 
 
7438
                return(i);
 
7439
        }
 
7440
 
 
7441
        /* If index translation table exists, we will first check
 
7442
        the index through index translation table for a match. */
 
7443
        if (share->idx_trans_tbl.index_mapping) {
 
7444
                for (i = 0; i < share->idx_trans_tbl.index_count; i++) {
 
7445
                        if (share->idx_trans_tbl.index_mapping[i] == index) {
 
7446
                                return(i);
 
7447
                        }
 
7448
                }
 
7449
 
 
7450
                /* Print an error message if we cannot find the index
 
7451
                ** in the "index translation table". */
 
7452
                sql_print_error("Cannot find index %s in InnoDB index "
 
7453
                                "translation table.", index->name);
 
7454
        }
 
7455
 
 
7456
        /* If we do not have an "index translation table", or not able
 
7457
        to find the index in the translation table, we'll directly find
 
7458
        matching index in the dict_index_t list */
 
7459
        for (i = 0; i < table->s->keys; i++) {
 
7460
                ind = dict_table_get_index_on_name(
 
7461
                        ib_table, table->key_info[i].name);
 
7462
 
 
7463
                if (index == ind) {
 
7464
                        return(i);
 
7465
                }
 
7466
        }
 
7467
 
 
7468
        sql_print_error("Cannot find matching index number for index %s "
 
7469
                         "in InnoDB index list.", index->name);
 
7470
 
 
7471
        return(0);
 
7472
}
 
7473
/*********************************************************************//**
7368
7474
Returns statistics information of the table to the MySQL interpreter,
7369
7475
in various fields of the handle object. */
7370
7476
UNIV_INTERN
7633
7739
                err_index = trx_get_error_info(prebuilt->trx);
7634
7740
 
7635
7741
                if (err_index) {
7636
 
                        errkey = (unsigned int)
7637
 
                                row_get_mysql_key_number_for_index(err_index);
 
7742
                        errkey = innobase_get_mysql_key_number_for_index(
 
7743
                                        share, table, ib_table, err_index);
7638
7744
                } else {
7639
7745
                        errkey = (unsigned int) prebuilt->trx->error_key_num;
7640
7746
                }
10346
10452
}
10347
10453
 
10348
10454
/*************************************************************//**
10349
 
Check if it is a valid value of innodb_change_buffering.  This function is
 
10455
Find the corresponding ibuf_use_t value that indexes into
 
10456
innobase_change_buffering_values[] array for the input
 
10457
change buffering option name.
 
10458
@return corresponding IBUF_USE_* value for the input variable
 
10459
name, or IBUF_USE_COUNT if not able to find a match */
 
10460
static
 
10461
ibuf_use_t
 
10462
innodb_find_change_buffering_value(
 
10463
/*===============================*/
 
10464
        const char*     input_name)     /*!< in: input change buffering
 
10465
                                        option name */
 
10466
{
 
10467
        ulint   use;
 
10468
 
 
10469
        for (use = 0; use < UT_ARR_SIZE(innobase_change_buffering_values);
 
10470
             use++) {
 
10471
                /* found a match */
 
10472
                if (!innobase_strcasecmp(
 
10473
                        input_name, innobase_change_buffering_values[use])) {
 
10474
                        return((ibuf_use_t)use);
 
10475
                }
 
10476
        }
 
10477
 
 
10478
        /* Did not find any match */
 
10479
        return(IBUF_USE_COUNT);
 
10480
}
 
10481
 
 
10482
/*************************************************************//**
 
10483
Check if it is a valid value of innodb_change_buffering. This function is
10350
10484
registered as a callback with MySQL.
10351
10485
@return 0 for valid innodb_change_buffering */
10352
10486
static
10370
10504
        change_buffering_input = value->val_str(value, buff, &len);
10371
10505
 
10372
10506
        if (change_buffering_input != NULL) {
10373
 
                ulint   use;
10374
 
 
10375
 
                for (use = 0; use < UT_ARR_SIZE(innobase_change_buffering_values);
10376
 
                     use++) {
10377
 
                        if (!innobase_strcasecmp(
10378
 
                                    change_buffering_input,
10379
 
                                    innobase_change_buffering_values[use])) {
10380
 
                                *(ibuf_use_t*) save = (ibuf_use_t) use;
10381
 
                                return(0);
10382
 
                        }
 
10507
                ibuf_use_t      use;
 
10508
 
 
10509
                use = innodb_find_change_buffering_value(
 
10510
                        change_buffering_input);
 
10511
 
 
10512
                if (use != IBUF_USE_COUNT) {
 
10513
                        /* Find a matching change_buffering option value. */
 
10514
                        *static_cast<const char**>(save) =
 
10515
                                innobase_change_buffering_values[use];
 
10516
 
 
10517
                        return(0);
10383
10518
                }
10384
10519
        }
10385
10520
 
 
10521
        /* No corresponding change buffering option for user supplied
 
10522
        "change_buffering_input" */
10386
10523
        return(1);
10387
10524
}
10388
10525
 
10393
10530
void
10394
10531
innodb_change_buffering_update(
10395
10532
/*===========================*/
10396
 
        THD*                            thd,            /*!< in: thread handle */
10397
 
        struct st_mysql_sys_var*        var,            /*!< in: pointer to
10398
 
                                                        system variable */
10399
 
        void*                           var_ptr,        /*!< out: where the
10400
 
                                                        formal string goes */
10401
 
        const void*                     save)           /*!< in: immediate result
10402
 
                                                        from check function */
 
10533
        THD*                            thd,    /*!< in: thread handle */
 
10534
        struct st_mysql_sys_var*        var,    /*!< in: pointer to
 
10535
                                                system variable */
 
10536
        void*                           var_ptr,/*!< out: where the
 
10537
                                                formal string goes */
 
10538
        const void*                     save)   /*!< in: immediate result
 
10539
                                                from check function */
10403
10540
{
 
10541
        ibuf_use_t      use;
 
10542
 
10404
10543
        ut_a(var_ptr != NULL);
10405
10544
        ut_a(save != NULL);
10406
 
        ut_a((*(ibuf_use_t*) save) < IBUF_USE_COUNT);
10407
 
 
10408
 
        ibuf_use = *(const ibuf_use_t*) save;
10409
 
 
10410
 
        *(const char**) var_ptr = innobase_change_buffering_values[ibuf_use];
 
10545
 
 
10546
        use = innodb_find_change_buffering_value(
 
10547
                *static_cast<const char*const*>(save));
 
10548
 
 
10549
        ut_a(use < IBUF_USE_COUNT);
 
10550
 
 
10551
        ibuf_use = use;
 
10552
        *static_cast<const char**>(var_ptr) =
 
10553
                 *static_cast<const char*const*>(save);
10411
10554
}
10412
10555
 
10413
10556
static int show_innodb_vars(THD *thd, SHOW_VAR *var, char *buff)
10735
10878
  "Buffer changes to reduce random access: "
10736
10879
  "OFF, ON, none, inserts.",
10737
10880
  innodb_change_buffering_validate,
10738
 
  innodb_change_buffering_update, NULL);
 
10881
  innodb_change_buffering_update, "inserts"); 
10739
10882
 
10740
10883
static MYSQL_SYSVAR_ULONG(read_ahead_threshold, srv_read_ahead_threshold,
10741
10884
  PLUGIN_VAR_RQCMDARG,