~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

Merge initial InnoDB+ import.

This was applied by generating a patch between MySQL 5.1.50 InnoDB plugin and
the just-merged innodb+ from mysql-trunk revision-id: vasil.dimov@oracle.com-20100422110752-1zowoqxel5xx3z2e

Then, some manual merge resolving and it worked. This should make it much
easier to merge the rest of InnoDB 1.1 and 1.2 from the mysql tree using
my bzr-reapply script.

This takes us to InnoDB 1.1.1(ish).

Show diffs side-by-side

added added

removed removed

Lines of Context:
170
170
static ulong innobase_commit_concurrency = 0;
171
171
static ulong innobase_read_io_threads;
172
172
static ulong innobase_write_io_threads;
 
173
static long innobase_buffer_pool_instances = 1;
173
174
 
174
175
/**
175
176
 * @TODO: Turn this into size_t as soon as we have a Variable<size_t>
231
232
/** Allowed values of innodb_change_buffering */
232
233
static const char* innobase_change_buffering_values[IBUF_USE_COUNT] = {
233
234
  "none",   /* IBUF_USE_NONE */
234
 
  "inserts" /* IBUF_USE_INSERT */
 
235
  "inserts",    /* IBUF_USE_INSERT */
 
236
  "deletes",    /* IBUF_USE_DELETE_MARK */
 
237
  "changes",    /* IBUF_USE_INSERT_DELETE_MARK */
 
238
  "purges",     /* IBUF_USE_DELETE */
 
239
  "all"         /* IBUF_USE_ALL */
235
240
};
236
241
 
237
242
/* "GEN_CLUST_INDEX" is the name reserved for Innodb default
1246
1251
 
1247
1252
/**********************************************************************//**
1248
1253
Determines the current SQL statement.
1249
 
@return SQL statement string */
 
1254
@return        SQL statement string */
1250
1255
extern "C" UNIV_INTERN
1251
1256
const char*
1252
1257
innobase_get_stmt(
1253
1258
/*==============*/
1254
 
        void*   session,        /*!< in: MySQL thread handle */
1255
 
        size_t* length)         /*!< out: length of the SQL statement */
 
1259
       void*   session,        /*!< in: MySQL thread handle */
 
1260
       size_t* length)         /*!< out: length of the SQL statement */
1256
1261
{
1257
1262
  *length= static_cast<Session*>(session)->query.length();
1258
1263
  return static_cast<Session*>(session)->query.c_str();
1755
1760
  return(trx && trx->mysql_thd && static_cast<Session*>(trx->mysql_thd)->getKilled());
1756
1761
}
1757
1762
 
1758
 
/**********************************************************************//**
1759
 
Determines if the currently running transaction is in strict mode.
1760
 
@return TRUE if strict */
1761
 
extern "C" UNIV_INTERN
1762
 
ibool
1763
 
trx_is_strict(
1764
 
/*==========*/
1765
 
        trx_t*  trx)    /*!< in: transaction */
1766
 
{
1767
 
  return(trx && trx->mysql_thd && true);
1768
 
}
1769
 
 
1770
1763
/**************************************************************//**
1771
1764
Resets some fields of a prebuilt struct. The template is used in fast
1772
1765
retrieval of just those column values MySQL needs in its processing. */
1922
1915
    
1923
1916
  }
1924
1917
 
 
1918
  if (vm.count("buffer-pool-instances"))
 
1919
  {
 
1920
    if (innobase_buffer_pool_instances > MAX_BUFFER_POOLS)
 
1921
    {
 
1922
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for buffer-pool-instances\n"));
 
1923
      exit(-1);
 
1924
    }
 
1925
    
 
1926
  }
 
1927
 
1925
1928
  if (vm.count("commit-concurrency"))
1926
1929
  {
1927
1930
    if (srv_replication_delay > 1000)
2191
2194
    format_id = 0;
2192
2195
  }
2193
2196
 
 
2197
  if (vm.count("purge-batch-size"))
 
2198
  {
 
2199
    srv_purge_batch_size= vm["purge-batch-size"].as<unsigned long>();
 
2200
    if (srv_purge_batch_size < 1 || srv_purge_batch_size > 5000)
 
2201
    {
 
2202
      errmsg_printf(ERRMSG_LVL_ERROR, "InnoDB: wrong purge-batch_size.");
 
2203
      goto mem_free_and_error;
 
2204
    }
 
2205
  }
 
2206
 
 
2207
  if (vm.count("n-purge-threads"))
 
2208
  {
 
2209
    srv_n_purge_threads= vm["n-purge-threads"].as<unsigned long>();
 
2210
    if (srv_n_purge_threads > 1)
 
2211
    {
 
2212
      errmsg_printf(ERRMSG_LVL_ERROR, "InnoDB: wrong n-purge-threads.");
 
2213
      goto mem_free_and_error;
 
2214
    }
 
2215
  }
 
2216
 
2194
2217
  srv_file_format = format_id;
2195
2218
 
2196
2219
  /* Given the type of innobase_file_format_name we have little
2266
2289
  srv_log_buffer_size = (ulint) innobase_log_buffer_size;
2267
2290
 
2268
2291
  srv_buf_pool_size = (ulint) innobase_buffer_pool_size;
 
2292
  srv_buf_pool_instances = (ulint) innobase_buffer_pool_instances;
2269
2293
 
2270
2294
  srv_mem_pool_size = (ulint) innobase_additional_mem_pool_size;
2271
2295
 
2296
2320
 
2297
2321
  data_mysql_default_charset_coll = (ulint)default_charset_info->number;
2298
2322
 
2299
 
  innobase_old_blocks_pct = buf_LRU_old_ratio_update(innobase_old_blocks_pct,
2300
 
                                                     FALSE);
2301
 
 
2302
2323
  innobase_commit_concurrency_init_default();
2303
2324
 
2304
2325
  /* Since we in this module access directly the fields of a trx
2313
2334
    goto mem_free_and_error;
2314
2335
  }
2315
2336
 
 
2337
  innobase_old_blocks_pct = buf_LRU_old_ratio_update(innobase_old_blocks_pct,
 
2338
                                                     TRUE);
 
2339
 
2316
2340
  innobase_open_tables = hash_create(200);
2317
2341
  pthread_mutex_init(&innobase_share_mutex, MY_MUTEX_INIT_FAST);
2318
2342
  pthread_mutex_init(&prepare_commit_mutex, MY_MUTEX_INIT_FAST);
2354
2378
 
2355
2379
  /* Get the current high water mark format. */
2356
2380
  innobase_file_format_check = (char*) trx_sys_file_format_max_get();
2357
 
  btr_search_fully_disabled = (!btr_search_enabled);
2358
2381
 
2359
2382
  return(FALSE);
2360
2383
error:
3001
3024
        dict_index_t**  index_mapping;
3002
3025
        ibool           ret = TRUE;
3003
3026
 
 
3027
        mutex_enter(&dict_sys->mutex);
 
3028
 
3004
3029
        mysql_num_index = table->getShare()->keys;
3005
3030
        ib_num_index = UT_LIST_GET_LEN(ib_table->indexes);
3006
3031
 
3030
3055
                                                         sizeof(*index_mapping));
3031
3056
 
3032
3057
                if (!index_mapping) {
 
3058
                        /* Report an error if index_mapping continues to be
 
3059
                        NULL and mysql_num_index is a non-zero value */
 
3060
                        errmsg_printf(ERRMSG_LVL_ERROR,
 
3061
                                      "InnoDB: fail to allocate memory for "
 
3062
                                        "index translation table. Number of "
 
3063
                                        "Index:%lu, array size:%lu",
 
3064
                                        mysql_num_index,
 
3065
                                        share->idx_trans_tbl.array_size);
3033
3066
                        ret = FALSE;
3034
3067
                        goto func_exit;
3035
3068
                }
3037
3070
                share->idx_trans_tbl.array_size = mysql_num_index;
3038
3071
        }
3039
3072
 
3040
 
 
3041
3073
        /* For each index in the mysql key_info array, fetch its
3042
3074
        corresponding InnoDB index pointer into index_mapping
3043
3075
        array. */
3083
3115
 
3084
3116
        share->idx_trans_tbl.index_mapping = index_mapping;
3085
3117
 
 
3118
        mutex_exit(&dict_sys->mutex);
 
3119
 
3086
3120
        return(ret);
3087
3121
}
3088
3122
 
3723
3757
    return(DATA_DOUBLE);
3724
3758
  case DRIZZLE_TYPE_BLOB:
3725
3759
    return(DATA_BLOB);
3726
 
  case DRIZZLE_TYPE_NULL:
3727
 
    /* MySQL currently accepts "NULL" datatype, but will
3728
 
       reject such datatype in the next release. We will cope
3729
 
       with it and not trigger assertion failure in 5.1 */
3730
 
    break;
3731
3760
  default:
3732
3761
    ut_error;
3733
3762
  }
6200
6229
    }
6201
6230
 
6202
6231
    error = row_table_add_foreign_constraints(trx,
6203
 
                                              query, strlen(query),
 
6232
                                              query,
6204
6233
                                              norm_name,
6205
6234
                                              lex_identified_temp_table);
6206
6235
 
7187
7216
          break;
7188
7217
        }
7189
7218
 
7190
 
        dict_index_stat_mutex_enter(index);
7191
 
 
7192
7219
        if (index->stat_n_diff_key_vals[j + 1] == 0) {
7193
7220
 
7194
7221
          rec_per_key = stats.records;
7197
7224
           index->stat_n_diff_key_vals[j + 1]);
7198
7225
        }
7199
7226
 
7200
 
        dict_index_stat_mutex_exit(index);
7201
 
 
7202
7227
        /* Since MySQL seems to favor table scans
7203
7228
        too much over index searches, we pretend
7204
7229
        index selectivity is 2 times better than
9392
9417
  "Number of IOPs the server can do. Tunes the background IO rate",
9393
9418
  NULL, NULL, 200, 100, ~0L, 0);
9394
9419
 
 
9420
static DRIZZLE_SYSVAR_ULONG(purge_batch_size, srv_purge_batch_size,
 
9421
  PLUGIN_VAR_OPCMDARG,
 
9422
  "Number of UNDO logs to purge in one batch from the history list. "
 
9423
  "Default is 20",
 
9424
  NULL, NULL,
 
9425
  20,                   /* Default setting */
 
9426
  1,                    /* Minimum value */
 
9427
  5000, 0);             /* Maximum value */
 
9428
 
 
9429
static DRIZZLE_SYSVAR_ULONG(purge_threads, srv_n_purge_threads,
 
9430
  PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_READONLY,
 
9431
  "Purge threads can be either 0 or 1. Default is 0.",
 
9432
  NULL, NULL,
 
9433
  0,                    /* Default setting */
 
9434
  0,                    /* Minimum value */
 
9435
  1, 0);                /* Maximum value */
 
9436
 
9395
9437
static DRIZZLE_SYSVAR_ULONG(fast_shutdown, innobase_fast_shutdown,
9396
9438
  PLUGIN_VAR_OPCMDARG,
9397
9439
  "Speeds up the shutdown process of the InnoDB storage engine. Possible "
9498
9540
  "The size of the memory buffer InnoDB uses to cache data and indexes of its tables.",
9499
9541
  NULL, NULL, 128*1024*1024L, 5*1024*1024L, INT64_MAX, 1024*1024L);
9500
9542
 
 
9543
static DRIZZLE_SYSVAR_LONG(buffer_pool_instances, innobase_buffer_pool_instances,
 
9544
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
 
9545
  "Number of buffer pool instances, set to higher value on high-end machines to increase scalability",
 
9546
  NULL, NULL, 1L, 1L, MAX_BUFFER_POOLS, 1L);
 
9547
 
9501
9548
static DRIZZLE_SYSVAR_ULONG(commit_concurrency, innobase_commit_concurrency,
9502
9549
  PLUGIN_VAR_RQCMDARG,
9503
9550
  "Helps in performance tuning in heavily concurrent environments.",
9594
9641
  "Use OS memory allocator instead of InnoDB's internal memory allocator",
9595
9642
  NULL, NULL, TRUE);
9596
9643
 
 
9644
static DRIZZLE_SYSVAR_BOOL(use_native_aio, srv_use_native_aio,
 
9645
  PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
 
9646
  "Use native AIO if supported on this platform.",
 
9647
  NULL, NULL, TRUE);
 
9648
 
9597
9649
static DRIZZLE_SYSVAR_STR(change_buffering, innobase_change_buffering,
9598
9650
  PLUGIN_VAR_RQCMDARG,
9599
9651
  "Buffer changes to reduce random access: "
9600
 
  "OFF, ON, none, inserts.",
 
9652
  "OFF, ON, inserting, deleting, changing or purging..",
9601
9653
  innodb_change_buffering_validate,
9602
 
  innodb_change_buffering_update, "inserts"); 
 
9654
  innodb_change_buffering_update, NULL);
9603
9655
 
9604
9656
static DRIZZLE_SYSVAR_ULONG(read_ahead_threshold, srv_read_ahead_threshold,
9605
9657
  PLUGIN_VAR_RQCMDARG,
9622
9674
  context("fast-shutdown",
9623
9675
          po::value<unsigned long>(&innobase_fast_shutdown)->default_value(1), 
9624
9676
          "Speeds up the shutdown process of the InnoDB storage engine. Possible values are 0, 1 (faster) or 2 (fastest - crash-like).");
 
9677
  context("purge-batch-size",
 
9678
          po::value<unsigned long>(&srv_purge_batch_size)->default_value(20),
 
9679
          "Number of UNDO logs to purge in one batch from the history list. "
 
9680
          "Default is 20.");
 
9681
  context("purge-threads",
 
9682
          po::value<unsigned long>(&srv_n_purge_threads)->default_value(0),
 
9683
          "Purge threads can be either 0 or 1. Defalut is 0.");
9625
9684
  context("file-per-table",
9626
9685
          po::value<bool>(&srv_file_per_table)->default_value(false)->zero_tokens(),
9627
9686
          "Stores each InnoDB table to an .ibd file in the database dir.");
9678
9737
  context("buffer-pool-size",
9679
9738
          po::value<int64_t>(&innobase_buffer_pool_size)->default_value(128*1024*1024L),
9680
9739
          "The size of the memory buffer InnoDB uses to cache data and indexes of its tables.");
 
9740
  context("buffer-pool-instances",
 
9741
          po::value<int64_t>(&innobase_buffer_pool_instances)->default_value(1),
 
9742
          "Number of buffer pool instances, set to higher value on high-end machines to increase scalability");
 
9743
 
9681
9744
  context("commit-concurrency",
9682
9745
          po::value<unsigned long>(&innobase_commit_concurrency)->default_value(0),
9683
9746
          "Helps in performance tuning in heavily concurrent environments.");
9750
9813
  DRIZZLE_SYSVAR(additional_mem_pool_size),
9751
9814
  DRIZZLE_SYSVAR(autoextend_increment),
9752
9815
  DRIZZLE_SYSVAR(buffer_pool_size),
 
9816
  DRIZZLE_SYSVAR(buffer_pool_instances),
9753
9817
  DRIZZLE_SYSVAR(checksums),
9754
9818
  DRIZZLE_SYSVAR(commit_concurrency),
9755
9819
  DRIZZLE_SYSVAR(concurrency_tickets),
9794
9858
  DRIZZLE_SYSVAR(thread_sleep_delay),
9795
9859
  DRIZZLE_SYSVAR(version),
9796
9860
  DRIZZLE_SYSVAR(use_sys_malloc),
 
9861
  DRIZZLE_SYSVAR(use_native_aio),
9797
9862
  DRIZZLE_SYSVAR(change_buffering),
9798
9863
  DRIZZLE_SYSVAR(read_ahead_threshold),
9799
9864
  DRIZZLE_SYSVAR(io_capacity),
 
9865
  DRIZZLE_SYSVAR(purge_threads),
 
9866
  DRIZZLE_SYSVAR(purge_batch_size),
9800
9867
  NULL
9801
9868
};
9802
9869