~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

Merged vcol stuff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2227
2227
        }
2228
2228
 
2229
2229
        /* Create buffers for packing the fields of a record. Why
2230
 
        table->reclength did not work here? Obviously, because char
 
2230
        table->stored_rec_length did not work here? Obviously, because char
2231
2231
        fields when packed actually became 1 byte longer, when we also
2232
2232
        stored the string length as the first byte. */
2233
2233
 
2234
2234
        upd_and_key_val_buff_len =
2235
 
                                table->s->reclength + table->s->max_key_length
2236
 
                                                        + MAX_REF_PARTS * 3;
 
2235
                                table->s->stored_rec_length
 
2236
                                + table->s->max_key_length
 
2237
                                + MAX_REF_PARTS * 3;
2237
2238
        if (!(unsigned char*) my_multi_malloc(MYF(MY_WME),
2238
2239
                        &upd_buff, upd_and_key_val_buff_len,
2239
2240
                        &key_val_buff, upd_and_key_val_buff_len,
2289
2290
 
2290
2291
        prebuilt = row_create_prebuilt(ib_table);
2291
2292
 
2292
 
        prebuilt->mysql_row_len = table->s->reclength;
 
2293
        prebuilt->mysql_row_len = table->s->stored_rec_length;
2293
2294
        prebuilt->idx_cond_func= NULL;
2294
2295
 
2295
2296
        /* Looks like MySQL-3.23 sometimes has primary key number != 0 */
2899
2900
        dict_index_t*   clust_index;
2900
2901
        mysql_row_templ_t* templ;
2901
2902
        Field*          field;
2902
 
        ulint           n_fields;
 
2903
        ulint           n_fields, n_stored_fields;
2903
2904
        ulint           n_requested_fields      = 0;
2904
2905
        ibool           fetch_all_in_key        = FALSE;
2905
2906
        ibool           fetch_primary_key_cols  = FALSE;
2906
 
        ulint           i;
 
2907
        ulint           i, sql_idx, innodb_idx  = 0;
2907
2908
        /* byte offset of the end of last requested column */
2908
2909
        ulint           mysql_prefix_len        = 0;
2909
2910
        ibool           do_idx_cond_push= FALSE;
2966
2967
        }
2967
2968
 
2968
2969
        n_fields = (ulint)table->s->fields; /* number of columns */
 
2970
        n_stored_fields= (ulint)table->s->stored_fields; /* number of stored columns */
2969
2971
 
2970
2972
        if (!prebuilt->mysql_template) {
2971
2973
                prebuilt->mysql_template = (mysql_row_templ_t*)
2972
2974
                                                mem_alloc_noninline(
2973
 
                                        n_fields * sizeof(mysql_row_templ_t));
 
2975
                                        n_stored_fields * sizeof(mysql_row_templ_t));
2974
2976
        }
2975
2977
 
2976
2978
        prebuilt->template_type = templ_type;
2992
2994
          If index condition pushdown is used, the array is split into two
2993
2995
          parts: first go index fields, then go table fields.
2994
2996
          
2995
 
          Note that in InnoDB, i is the column number. MySQL calls columns
2996
 
          'fields'.
 
2997
          Note that in InnoDB, innodb_idx is the column number. MySQL calls columns
 
2998
          'fields' associated with index sql_idx.
2997
2999
        */
2998
 
        for (i = 0; i < n_fields; i++) {
 
3000
        for (sql_idx = 0; sql_idx < n_fields; sql_idx++) {
2999
3001
                templ = prebuilt->mysql_template + n_requested_fields;
3000
 
                field = table->field[i];
 
3002
                field = table->field[sql_idx];
 
3003
                if (!field->is_stored)
 
3004
                       goto skip_field;
3001
3005
 
3002
3006
                if (UNIV_LIKELY(templ_type == ROW_DRIZZLE_REC_FIELDS)) {
3003
3007
                        /* Decide which columns we should fetch
3004
3008
                        and which we can skip. */
3005
3009
                        register const ibool    index_contains_field =
3006
 
                                dict_index_contains_col_or_prefix(index, i);
 
3010
                                dict_index_contains_col_or_prefix(index, innodb_idx);
3007
3011
                        register const ibool    index_covers_field = 
3008
3012
                                field->part_of_key.is_set(file->active_index);
3009
3013
 
3020
3024
                                goto include_field;
3021
3025
                        }
3022
3026
 
3023
 
                        if (bitmap_is_set(table->read_set, i) ||
3024
 
                            bitmap_is_set(table->write_set, i)) {
 
3027
                        if (bitmap_is_set(table->read_set, sql_idx) ||
 
3028
                            bitmap_is_set(table->write_set, sql_idx)) {
3025
3029
                                /* This field is needed in the query */
3026
3030
 
3027
3031
                                goto include_field;
3029
3033
 
3030
3034
                        if (fetch_primary_key_cols
3031
3035
                                && dict_table_col_in_clustered_key(
3032
 
                                        index->table, i)) {
 
3036
                                        index->table, innodb_idx)) {
3033
3037
                                /* This field is needed in the query */
3034
3038
 
3035
3039
                                goto include_field;
3046
3050
                }
3047
3051
                n_requested_fields++;
3048
3052
 
3049
 
                templ->col_no = i;
 
3053
                templ->col_no = innodb_idx;
3050
3054
 
3051
3055
                if (index == clust_index) {
3052
3056
                        templ->rec_field_no = dict_col_get_clust_pos_noninline(
3053
 
                                &index->table->cols[i], index);
 
3057
                                &index->table->cols[innodb_idx], index);
3054
3058
                } else {
3055
3059
                        templ->rec_field_no = dict_index_get_nth_col_pos(
3056
 
                                                                index, i);
 
3060
                                                                index, innodb_idx);
3057
3061
                }
3058
3062
 
3059
3063
                if (templ->rec_field_no == ULINT_UNDEFINED) {
3079
3083
                        mysql_prefix_len = templ->mysql_col_offset
3080
3084
                                + templ->mysql_col_len;
3081
3085
                }
3082
 
                templ->type = index->table->cols[i].mtype;
 
3086
                templ->type = index->table->cols[innodb_idx].mtype;
3083
3087
                templ->mysql_type = (ulint)field->type();
3084
3088
 
3085
3089
                if (templ->mysql_type == DATA_DRIZZLE_TRUE_VARCHAR) {
3088
3092
                }
3089
3093
 
3090
3094
                templ->charset = dtype_get_charset_coll_noninline(
3091
 
                                index->table->cols[i].prtype);
3092
 
                templ->mbminlen = index->table->cols[i].mbminlen;
3093
 
                templ->mbmaxlen = index->table->cols[i].mbmaxlen;
3094
 
                templ->is_unsigned = index->table->cols[i].prtype
 
3095
                                index->table->cols[innodb_idx].prtype);
 
3096
                templ->mbminlen = index->table->cols[innodb_idx].mbminlen;
 
3097
                templ->mbmaxlen = index->table->cols[innodb_idx].mbmaxlen;
 
3098
                templ->is_unsigned = index->table->cols[innodb_idx].prtype
3095
3099
                                                        & DATA_UNSIGNED;
3096
3100
                if (templ->type == DATA_BLOB) {
3097
3101
                        prebuilt->templ_contains_blob = TRUE;
3098
3102
                }
3099
3103
skip_field:
3100
 
                if (need_second_pass && (i+1 == n_fields))
 
3104
                if (field->is_stored)
 
3105
                {
 
3106
                  innodb_idx++;
 
3107
                }
 
3108
                if (need_second_pass && (sql_idx+1 == n_fields))
3101
3109
                {
3102
3110
                  prebuilt->n_index_fields= n_requested_fields;
3103
3111
                  need_second_pass= FALSE;
3104
 
                  i= (~(ulint)0); /* to start from 0 */
 
3112
                  sql_idx= (~(ulint)0); /* to start from 0 */
 
3113
                  innodb_idx= 0;
3105
3114
                }
3106
3115
        }
3107
3116
 
3484
3493
        ulint           n_changed = 0;
3485
3494
        dfield_t        dfield;
3486
3495
        dict_index_t*   clust_index;
3487
 
        uint            i;
 
3496
        uint            sql_idx, innodb_idx= 0;
3488
3497
 
3489
3498
        n_fields = table->s->fields;
3490
3499
        clust_index = dict_table_get_first_index_noninline(prebuilt->table);
3492
3501
        /* We use upd_buff to convert changed fields */
3493
3502
        buf = (byte*) upd_buff;
3494
3503
 
3495
 
        for (i = 0; i < n_fields; i++) {
3496
 
                field = table->field[i];
 
3504
        for (sql_idx = 0; sql_idx < n_fields; sql_idx++) {
 
3505
                field = table->field[sql_idx];
 
3506
                if (!field->is_stored)
 
3507
                  continue;
3497
3508
 
3498
3509
                o_ptr = (byte*) old_row + get_field_offset(table, field);
3499
3510
                n_ptr = (byte*) new_row + get_field_offset(table, field);
3511
3522
 
3512
3523
                field_mysql_type = field->type();
3513
3524
 
3514
 
                col_type = prebuilt->table->cols[i].mtype;
 
3525
                col_type = prebuilt->table->cols[innodb_idx].mtype;
3515
3526
 
3516
3527
                switch (col_type) {
3517
3528
 
3566
3577
                        /* Let us use a dummy dfield to make the conversion
3567
3578
                        from the MySQL column format to the InnoDB format */
3568
3579
 
3569
 
                        dict_col_copy_type_noninline(prebuilt->table->cols + i,
 
3580
                        dict_col_copy_type_noninline(prebuilt->table->cols + innodb_idx,
3570
3581
                                                     &dfield.type);
3571
3582
 
3572
3583
                        if (n_len != UNIV_SQL_NULL) {
3587
3598
 
3588
3599
                        ufield->exp = NULL;
3589
3600
                        ufield->field_no = dict_col_get_clust_pos_noninline(
3590
 
                                &prebuilt->table->cols[i], clust_index);
 
3601
                                &prebuilt->table->cols[innodb_idx], clust_index);
3591
3602
                        n_changed++;
3592
3603
                }
 
3604
                if (field->is_stored)
 
3605
                  innodb_idx++;
3593
3606
        }
3594
3607
 
3595
3608
        uvect->n_fields = n_changed;
4519
4532
        /* We pass 0 as the space id, and determine at a lower level the space
4520
4533
        id where to store the table */
4521
4534
 
4522
 
        table = dict_mem_table_create(table_name, 0, n_cols, flags);
 
4535
        table = dict_mem_table_create(table_name, 0, form->s->stored_fields, flags);
4523
4536
 
4524
4537
        if (path_of_temp_table) {
4525
4538
                table->dir_path_of_temp_table =
4528
4541
 
4529
4542
        for (i = 0; i < n_cols; i++) {
4530
4543
                field = form->field[i];
 
4544
                if (!field->is_stored)
 
4545
                  continue;
4531
4546
 
4532
4547
                col_type = get_innobase_type_from_mysql_type(&unsigned_type,
4533
4548
                                                                        field);
4789
4804
 
4790
4805
        assert(thd != NULL);
4791
4806
 
4792
 
        if (form->s->fields > 1000) {
 
4807
        if (form->s->stored_fields > 1000) {
4793
4808
                /* The limit probably should be REC_MAX_N_FIELDS - 3 = 1020,
4794
4809
                but we play safe here */
4795
4810
 
5280
5295
        KEY*            key;
5281
5296
        dict_index_t*   index;
5282
5297
        unsigned char*          key_val_buff2   = (unsigned char*) my_malloc(
5283
 
                                                  table->s->reclength
 
5298
                                                  table->s->stored_rec_length
5284
5299
                                        + table->s->max_key_length + 100,
5285
5300
                                                                MYF(MY_FAE));
5286
 
        ulint           buff2_len = table->s->reclength
 
5301
        ulint           buff2_len = table->s->stored_rec_length
5287
5302
                                        + table->s->max_key_length + 100;
5288
5303
        dtuple_t*       range_start;
5289
5304
        dtuple_t*       range_end;