~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

Added code necessary for building plugins dynamically.
Merged in changes from lifeless to allow autoreconf to work.
Touching plugin.ini files now triggers a rebuid - so config/autorun.sh is no
longer required to be run after touching those.
Removed the duplicate plugin names - also removed the issue that getting them
different would silently fail weirdly later.

Show diffs side-by-side

added added

removed removed

Lines of Context:
244
244
public:
245
245
  InnobaseEngine(string name_arg)
246
246
   : drizzled::plugin::StorageEngine(name_arg,
247
 
                                     HTON_NO_FLAGS, sizeof(trx_named_savept_t))
 
247
                                     HTON_HAS_DOES_TRANSACTIONS, sizeof(trx_named_savept_t))
248
248
  {
 
249
    table_definition_ext= drizzled::plugin::DEFAULT_DEFINITION_FILE_EXT;
249
250
    addAlias("INNOBASE");
250
251
  }
251
252
 
368
369
        return(ha_innobase_exts);
369
370
  }
370
371
 
371
 
  UNIV_INTERN int createTableImplementation(Session *session, 
372
 
                                            const char *table_name,
373
 
                                            Table *form,
374
 
                                            HA_CREATE_INFO *create_info,
375
 
                                            drizzled::message::Table*);
376
 
  UNIV_INTERN int renameTableImplementation(Session* session,
377
 
                                            const char* from, 
378
 
                                            const char* to);
379
 
  UNIV_INTERN int deleteTableImplementation(Session* session, const string table_path);
 
372
  UNIV_INTERN int doCreateTable(Session *session, 
 
373
                                const char *table_name,
 
374
                                Table& form,
 
375
                                HA_CREATE_INFO& create_info,
 
376
                                drizzled::message::Table&);
 
377
  UNIV_INTERN int doRenameTable(Session* session,
 
378
                                const char* from, 
 
379
                                const char* to);
 
380
  UNIV_INTERN int doDropTable(Session& session, const string table_path);
380
381
};
381
382
 
382
383
/** @brief Initialize the default value of innodb_commit_concurrency.
936
937
innobase_mysql_print_thd(
937
938
/*=====================*/
938
939
        FILE*   f,              /*!< in: output stream */
939
 
        void*   ,               /*!< in: pointer to a Drizzle Session object */
 
940
        void * in_session,      /*!< in: pointer to a Drizzle Session object */
940
941
        uint    )               /*!< in: max query length to print, or 0 to
941
942
                                   use the default max length */
942
943
{
943
 
        fputs("Unknown thread accessing table", f);
 
944
  Session *session= reinterpret_cast<Session *>(in_session);
 
945
  fprintf(f,
 
946
          "Drizzle thread %"PRIu64", query id %"PRIu64", %s, %s, %s ",
 
947
          static_cast<uint64_t>(session_get_thread_id( session)),
 
948
          static_cast<uint64_t>(session->getQueryId()),
 
949
          glob_hostname,
 
950
          session->security_ctx.ip.c_str(),
 
951
          session->security_ctx.user.c_str()
 
952
  );
 
953
  fprintf(f,
 
954
          "\n%s", session->getQueryString()
 
955
  );
944
956
        putc('\n', f);
945
957
}
946
958
 
3139
3151
                return(DATA_FIXBINARY);
3140
3152
        case DRIZZLE_TYPE_LONG:
3141
3153
        case DRIZZLE_TYPE_LONGLONG:
3142
 
        case DRIZZLE_TYPE_TINY:
3143
3154
        case DRIZZLE_TYPE_DATETIME:
3144
3155
        case DRIZZLE_TYPE_DATE:
3145
3156
        case DRIZZLE_TYPE_TIMESTAMP:
5364
5375
create_options_are_valid(
5365
5376
/*=====================*/
5366
5377
        Session*        session,        /*!< in: connection thread. */
5367
 
        Table*          form,           /*!< in: information on table
 
5378
        Table&          form,           /*!< in: information on table
5368
5379
                                        columns and indexes */
5369
 
        HA_CREATE_INFO* create_info)    /*!< in: create info. */
 
5380
        HA_CREATE_INFO& create_info,
 
5381
        drizzled::message::Table& create_proto)
5370
5382
{
5371
5383
        ibool   kbs_specified   = FALSE;
5372
5384
        ibool   ret             = TRUE;
5379
5391
                return(TRUE);
5380
5392
        }
5381
5393
 
5382
 
        ut_ad(form != NULL);
5383
 
        ut_ad(create_info != NULL);
5384
 
 
5385
5394
        /* First check if KEY_BLOCK_SIZE was specified. */
5386
 
        if (create_info->key_block_size
5387
 
            || (create_info->used_fields & HA_CREATE_USED_KEY_BLOCK_SIZE)) {
 
5395
        if (create_proto.options().has_key_block_size()) {
5388
5396
 
5389
5397
                kbs_specified = TRUE;
5390
 
                switch (create_info->key_block_size) {
 
5398
                switch (create_proto.options().key_block_size()) {
5391
5399
                case 1:
5392
5400
                case 2:
5393
5401
                case 4:
5402
5410
                                            " KEY_BLOCK_SIZE = %lu."
5403
5411
                                            " Valid values are"
5404
5412
                                            " [1, 2, 4, 8, 16]",
5405
 
                                            create_info->key_block_size);
 
5413
                                            create_proto.options().key_block_size());
5406
5414
                        ret = FALSE;
5407
5415
                }
5408
5416
        }
5427
5435
        }
5428
5436
 
5429
5437
        /* Now check for ROW_FORMAT specifier. */
5430
 
        if (create_info->used_fields & HA_CREATE_USED_ROW_FORMAT) {
5431
 
                switch (form->s->row_type) {
 
5438
        if (create_info.used_fields & HA_CREATE_USED_ROW_FORMAT) {
 
5439
                switch (form.s->row_type) {
5432
5440
                        const char* row_format_name;
5433
5441
                case ROW_TYPE_COMPRESSED:
5434
5442
                case ROW_TYPE_DYNAMIC:
5435
5443
                        row_format_name
5436
 
                                = form->s->row_type == ROW_TYPE_COMPRESSED
 
5444
                                = form.s->row_type == ROW_TYPE_COMPRESSED
5437
5445
                                ? "COMPRESSED"
5438
5446
                                : "DYNAMIC";
5439
5447
 
5468
5476
                        However, we do allow COMPRESSED to be
5469
5477
                        specified with KEY_BLOCK_SIZE. */
5470
5478
                        if (kbs_specified
5471
 
                            && form->s->row_type == ROW_TYPE_DYNAMIC) {
 
5479
                            && form.s->row_type == ROW_TYPE_DYNAMIC) {
5472
5480
                                push_warning_printf(
5473
5481
                                        session,
5474
5482
                                        DRIZZLE_ERROR::WARN_LEVEL_ERROR,
5486
5494
                case ROW_TYPE_DEFAULT:
5487
5495
                        /* Default is COMPACT. */
5488
5496
                        row_format_name
5489
 
                                = form->s->row_type == ROW_TYPE_REDUNDANT
 
5497
                                = form.s->row_type == ROW_TYPE_REDUNDANT
5490
5498
                                ? "REDUNDANT"
5491
5499
                                : "COMPACT";
5492
5500
 
5523
5531
Creates a new table to an InnoDB database. */
5524
5532
UNIV_INTERN
5525
5533
int
5526
 
InnobaseEngine::createTableImplementation(
 
5534
InnobaseEngine::doCreateTable(
5527
5535
/*================*/
5528
5536
        Session*        session,        /*!< in: Session */
5529
5537
        const char*     table_name,     /*!< in: table name */
5530
 
        Table*          form,           /*!< in: information on table
 
5538
        Table&          form,           /*!< in: information on table
5531
5539
                                        columns and indexes */
5532
 
        HA_CREATE_INFO* create_info,    /*!< in: more information of the
 
5540
        HA_CREATE_INFO& create_info,    /*!< in: more information of the
5533
5541
                                        created table, contains also the
5534
5542
                                        create statement string */
5535
 
        drizzled::message::Table*)
 
5543
        drizzled::message::Table& create_proto)
5536
5544
{
5537
5545
        int             error;
5538
5546
        dict_table_t*   innobase_table;
5562
5570
        table. Currently InnoDB does not support symbolic link on Windows. */
5563
5571
 
5564
5572
        if (srv_file_per_table
5565
 
            && (!create_info->options & HA_LEX_CREATE_TMP_TABLE)) {
 
5573
            && (!create_info.options & HA_LEX_CREATE_TMP_TABLE)) {
5566
5574
 
5567
5575
                if ((table_name[1] == ':')
5568
5576
                    || (table_name[0] == '\\' && table_name[1] == '\\')) {
5572
5580
        }
5573
5581
#endif
5574
5582
 
5575
 
        if (form->s->fields > 1000) {
 
5583
        if (form.s->fields > 1000) {
5576
5584
                /* The limit probably should be REC_MAX_N_FIELDS - 3 = 1020,
5577
5585
                but we play safe here */
5578
5586
 
5608
5616
        iflags = 0;
5609
5617
 
5610
5618
        /* Validate create options if innodb_strict_mode is set. */
5611
 
        if (!create_options_are_valid(session, form, create_info)) {
 
5619
        if (!create_options_are_valid(session, form, create_info, create_proto)) {
5612
5620
                error = ER_ILLEGAL_HA_CREATE_OPTION;
5613
5621
                goto cleanup;
5614
5622
        }
5615
5623
 
5616
 
        if (create_info->key_block_size
5617
 
            || (create_info->used_fields & HA_CREATE_USED_KEY_BLOCK_SIZE)) {
 
5624
        if (create_proto.options().has_key_block_size()) {
5618
5625
                /* Determine the page_zip.ssize corresponding to the
5619
5626
                requested page size (key_block_size) in kilobytes. */
5620
5627
 
5621
5628
                ulint   ssize, ksize;
5622
 
                ulint   key_block_size = create_info->key_block_size;
 
5629
                ulint   key_block_size = create_proto.options().key_block_size();
5623
5630
 
5624
5631
                for (ssize = ksize = 1; ssize <= DICT_TF_ZSSIZE_MAX;
5625
5632
                     ssize++, ksize <<= 1) {
5654
5661
                                            ER_ILLEGAL_HA_CREATE_OPTION,
5655
5662
                                            "InnoDB: ignoring"
5656
5663
                                            " KEY_BLOCK_SIZE=%lu.",
5657
 
                                            create_info->key_block_size);
 
5664
                                            create_proto.options().key_block_size());
5658
5665
                }
5659
5666
        }
5660
5667
 
5661
 
        if (create_info->used_fields & HA_CREATE_USED_ROW_FORMAT) {
 
5668
        if (create_info.used_fields & HA_CREATE_USED_ROW_FORMAT) {
5662
5669
                if (iflags) {
5663
5670
                        /* KEY_BLOCK_SIZE was specified. */
5664
 
                        if (form->s->row_type != ROW_TYPE_COMPRESSED) {
 
5671
                        if (form.s->row_type != ROW_TYPE_COMPRESSED) {
5665
5672
                                /* ROW_FORMAT other than COMPRESSED
5666
5673
                                ignores KEY_BLOCK_SIZE.  It does not
5667
5674
                                make sense to reject conflicting
5674
5681
                                        ER_ILLEGAL_HA_CREATE_OPTION,
5675
5682
                                        "InnoDB: ignoring KEY_BLOCK_SIZE=%lu"
5676
5683
                                        " unless ROW_FORMAT=COMPRESSED.",
5677
 
                                        create_info->key_block_size);
 
5684
                                        create_proto.options().key_block_size());
5678
5685
                                iflags = 0;
5679
5686
                        }
5680
5687
                } else {
5681
5688
                        /* No KEY_BLOCK_SIZE */
5682
 
                        if (form->s->row_type == ROW_TYPE_COMPRESSED) {
 
5689
                        if (form.s->row_type == ROW_TYPE_COMPRESSED) {
5683
5690
                                /* ROW_FORMAT=COMPRESSED without
5684
5691
                                KEY_BLOCK_SIZE implies half the
5685
5692
                                maximum KEY_BLOCK_SIZE. */
5694
5701
                        }
5695
5702
                }
5696
5703
 
5697
 
                switch (form->s->row_type) {
 
5704
                switch (form.s->row_type) {
5698
5705
                        const char* row_format_name;
5699
5706
                case ROW_TYPE_REDUNDANT:
5700
5707
                        break;
5701
5708
                case ROW_TYPE_COMPRESSED:
5702
5709
                case ROW_TYPE_DYNAMIC:
5703
5710
                        row_format_name
5704
 
                                = form->s->row_type == ROW_TYPE_COMPRESSED
 
5711
                                = form.s->row_type == ROW_TYPE_COMPRESSED
5705
5712
                                ? "COMPRESSED"
5706
5713
                                : "DYNAMIC";
5707
5714
 
5748
5755
                iflags = DICT_TF_COMPACT;
5749
5756
        }
5750
5757
 
5751
 
        error = create_table_def(trx, form, norm_name,
5752
 
                create_info->options & HA_LEX_CREATE_TMP_TABLE ? name2 : NULL,
 
5758
        error = create_table_def(trx, &form, norm_name,
 
5759
                create_info.options & HA_LEX_CREATE_TMP_TABLE ? name2 : NULL,
5753
5760
                iflags);
5754
5761
 
5755
5762
        if (error) {
5758
5765
 
5759
5766
        /* Look for a primary key */
5760
5767
 
5761
 
        primary_key_no= (form->s->primary_key != MAX_KEY ?
5762
 
                         (int) form->s->primary_key :
 
5768
        primary_key_no= (form.s->primary_key != MAX_KEY ?
 
5769
                         (int) form.s->primary_key :
5763
5770
                         -1);
5764
5771
 
5765
5772
        /* Our function row_get_mysql_key_number_for_index assumes
5769
5776
 
5770
5777
        /* Create the keys */
5771
5778
 
5772
 
        if (form->s->keys == 0 || primary_key_no == -1) {
 
5779
        if (form.s->keys == 0 || primary_key_no == -1) {
5773
5780
                /* Create an index which is used as the clustered index;
5774
5781
                order the rows by their row id which is internally generated
5775
5782
                by InnoDB */
5784
5791
        if (primary_key_no != -1) {
5785
5792
                /* In InnoDB the clustered index must always be created
5786
5793
                first */
5787
 
                if ((error = create_index(trx, form, iflags, norm_name,
 
5794
                if ((error = create_index(trx, &form, iflags, norm_name,
5788
5795
                                          (uint) primary_key_no))) {
5789
5796
                        goto cleanup;
5790
5797
                }
5791
5798
        }
5792
5799
 
5793
 
        for (i = 0; i < form->s->keys; i++) {
 
5800
        for (i = 0; i < form.s->keys; i++) {
5794
5801
 
5795
5802
                if (i != (uint) primary_key_no) {
5796
5803
 
5797
 
                        if ((error = create_index(trx, form, iflags, norm_name,
 
5804
                        if ((error = create_index(trx, &form, iflags, norm_name,
5798
5805
                                                  i))) {
5799
5806
                                goto cleanup;
5800
5807
                        }
5804
5811
        if (*trx->mysql_query_str) {
5805
5812
                error = row_table_add_foreign_constraints(trx,
5806
5813
                        *trx->mysql_query_str, norm_name,
5807
 
                        create_info->options & HA_LEX_CREATE_TMP_TABLE);
 
5814
                        create_info.options & HA_LEX_CREATE_TMP_TABLE);
5808
5815
 
5809
5816
                error = convert_error_code_to_mysql(error, iflags, NULL);
5810
5817
 
5842
5849
        /* We need to copy the AUTOINC value from the old table if
5843
5850
        this is an ALTER TABLE. */
5844
5851
 
5845
 
        if (((create_info->used_fields & HA_CREATE_USED_AUTO)
 
5852
        if (((create_info.used_fields & HA_CREATE_USED_AUTO)
5846
5853
            || session_sql_command(session) == SQLCOM_ALTER_TABLE)
5847
 
            && create_info->auto_increment_value != 0) {
 
5854
            && create_info.auto_increment_value != 0) {
5848
5855
 
5849
5856
                /* Query was ALTER TABLE...AUTO_INCREMENT = x; or
5850
5857
                CREATE TABLE ...AUTO_INCREMENT = x; Find out a table
5853
5860
                auto increment field if the value is greater than the
5854
5861
                maximum value in the column. */
5855
5862
 
5856
 
                auto_inc_value = create_info->auto_increment_value;
 
5863
                auto_inc_value = create_info.auto_increment_value;
5857
5864
 
5858
5865
                dict_table_autoinc_lock(innobase_table);
5859
5866
                dict_table_autoinc_initialize(innobase_table, auto_inc_value);
5956
5963
@return error number */
5957
5964
UNIV_INTERN
5958
5965
int
5959
 
InnobaseEngine::deleteTableImplementation(
 
5966
InnobaseEngine::doDropTable(
5960
5967
/*======================*/
5961
 
        Session *session,
5962
 
        const string    table_path)     /* in: table name */
 
5968
        Session& session,
 
5969
        const string table_path)        /* in: table name */
5963
5970
{
5964
5971
        int     error;
5965
5972
        trx_t*  parent_trx;
5975
5982
        /* Get the transaction associated with the current session, or create one
5976
5983
        if not yet created */
5977
5984
 
5978
 
        parent_trx = check_trx_exists(session);
 
5985
        parent_trx = check_trx_exists(&session);
5979
5986
 
5980
5987
        /* In case MySQL calls this in the middle of a SELECT query, release
5981
5988
        possible adaptive hash latch to avoid deadlocks of threads */
5982
5989
 
5983
5990
        trx_search_latch_release_if_reserved(parent_trx);
5984
5991
 
5985
 
        trx = innobase_trx_allocate(session);
 
5992
        trx = innobase_trx_allocate(&session);
5986
5993
 
5987
5994
        srv_lower_case_table_names = TRUE;
5988
5995
 
5989
5996
        /* Drop the table in InnoDB */
5990
5997
 
5991
5998
        error = row_drop_table_for_mysql(norm_name, trx,
5992
 
                                         session_sql_command(session)
 
5999
                                         session_sql_command(&session)
5993
6000
                                         == SQLCOM_DROP_DB);
5994
6001
 
5995
6002
        /* Flush the log to reduce probability that the .frm files and
6153
6160
@return 0 or error code */
6154
6161
UNIV_INTERN
6155
6162
int
6156
 
InnobaseEngine::renameTableImplementation(
 
6163
InnobaseEngine::doRenameTable(
6157
6164
/*======================*/
6158
6165
        Session*        session,
6159
6166
        const char*     from,   /*!< in: old name of the table */
9076
9083
  NULL
9077
9084
};
9078
9085
 
9079
 
drizzle_declare_plugin(innobase)
 
9086
drizzle_declare_plugin
9080
9087
{
9081
9088
  innobase_engine_name,
9082
9089
  INNODB_VERSION_STR,