~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/pbxt/src/ha_pbxt.cc

  • Committer: Brian Aker
  • Date: 2010-10-22 23:33:58 UTC
  • mfrom: (1869.1.7 refactor)
  • Revision ID: brian@tangent.org-20101022233358-kmtrpm1yvmmyaame
Merge in overhaul to how cursor and table are handled. Cursor now only knows
about table, and will always have a table and engine reference.

This cleans up a number of ownership issues, the biggest being that it now
creates the space needed for the next big refactor in locks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1482
1482
        return 0;
1483
1483
}
1484
1484
 
1485
 
Cursor *PBXTStorageEngine::create(TableShare& table)
 
1485
Cursor *PBXTStorageEngine::create(Table& table)
1486
1486
{
1487
1487
        return new ha_pbxt(*this, table);
1488
1488
}
2020
2020
 *
2021
2021
 */
2022
2022
 
2023
 
ha_pbxt::ha_pbxt(plugin::StorageEngine &engine_arg, TableShare &table_arg) : Cursor(engine_arg, table_arg)
 
2023
ha_pbxt::ha_pbxt(plugin::StorageEngine &engine_arg, Table &table_arg) : Cursor(engine_arg, table_arg)
2024
2024
{
2025
2025
        pb_share = NULL;
2026
2026
        pb_open_tab = NULL;
2351
2351
                return;
2352
2352
 
2353
2353
        xt_spinlock_lock(&tab->tab_ainc_lock);
2354
 
        if (table->found_next_number_field && !tab->tab_auto_inc) {
2355
 
                Field           *tmp_fie = table->next_number_field;
2356
 
                THD                     *tmp_thd = table->in_use;
 
2354
        if (getTable()->found_next_number_field && !tab->tab_auto_inc) {
 
2355
                Field           *tmp_fie = getTable()->next_number_field;
 
2356
                THD                     *tmp_thd = getTable()->in_use;
2357
2357
                xtBool          xn_started = FALSE;
2358
2358
                XTThreadPtr     self = pb_open_tab->ot_thread;
2359
2359
 
2381
2381
                }
2382
2382
 
2383
2383
                /* Setup the conditions for the next call! */
2384
 
                table->in_use = current_thd;
2385
 
                table->next_number_field = table->found_next_number_field;
 
2384
                getTable()->in_use = current_thd;
 
2385
                getTable()->next_number_field = getTable()->found_next_number_field;
2386
2386
 
2387
2387
                extra(HA_EXTRA_KEYREAD);
2388
 
                table->mark_columns_used_by_index_no_reset(table->getShare()->next_number_index, *table->read_set);
 
2388
                getTable()->mark_columns_used_by_index_no_reset(getTable()->getShare()->next_number_index, *getTable()->read_set);
2389
2389
                column_bitmaps_signal();
2390
 
                doStartIndexScan(table->getShare()->next_number_index, 0);
2391
 
                if (!table->getShare()->next_number_key_offset) {
 
2390
                doStartIndexScan(getTable()->getShare()->next_number_index, 0);
 
2391
                if (!getTable()->getShare()->next_number_key_offset) {
2392
2392
                        // Autoincrement at key-start
2393
 
                        err = index_last(table->getUpdateRecord());
2394
 
                        if (!err && !table->next_number_field->is_null(table->getShare()->rec_buff_length)) {
 
2393
                        err = index_last(getTable()->getUpdateRecord());
 
2394
                        if (!err && !getTable()->next_number_field->is_null(getTable()->getShare()->rec_buff_length)) {
2395
2395
                                /* {PRE-INC} */
2396
 
                                nr = (xtWord8) table->next_number_field->val_int_offset(table->getShare()->rec_buff_length);
 
2396
                                nr = (xtWord8) getTable()->next_number_field->val_int_offset(getTable()->getShare()->rec_buff_length);
2397
2397
                        }
2398
2398
                }
2399
2399
                else {
2403
2403
                         */
2404
2404
                        xtWord8 val;
2405
2405
 
2406
 
                        err = index_first(table->getUpdateRecord());
 
2406
                        err = index_first(getTable()->getUpdateRecord());
2407
2407
                        while (!err) {
2408
2408
                                /* {PRE-INC} */
2409
 
                                val = (xtWord8) table->next_number_field->val_int_offset(table->getShare()->rec_buff_length);
 
2409
                                val = (xtWord8) getTable()->next_number_field->val_int_offset(getTable()->getShare()->rec_buff_length);
2410
2410
                                if (val > nr)
2411
2411
                                        nr = val;
2412
 
                                err = index_next(table->getUpdateRecord());
 
2412
                                err = index_next(getTable()->getUpdateRecord());
2413
2413
                        }
2414
2414
                }
2415
2415
 
2444
2444
                        tab->tab_auto_inc = min_auto_inc-1;
2445
2445
 
2446
2446
                /* Restore the changed values: */
2447
 
                table->next_number_field = tmp_fie;
2448
 
                table->in_use = tmp_thd;
 
2447
                getTable()->next_number_field = tmp_fie;
 
2448
                getTable()->in_use = tmp_thd;
2449
2449
 
2450
2450
                if (xn_started) {
2451
2451
                        XT_PRINT0(self, "xt_xn_commit in init_auto_increment\n");
2480
2480
                nr += increment - ((nr - offset) % increment);
2481
2481
        else
2482
2482
                nr += increment;
2483
 
        if (table->next_number_field->cmp((const unsigned char *)&nr_less_inc, (const unsigned char *)&nr) < 0)
 
2483
        if (getTable()->next_number_field->cmp((const unsigned char *)&nr_less_inc, (const unsigned char *)&nr) < 0)
2484
2484
                tab->tab_auto_inc = (xtWord8) (nr);
2485
2485
        else
2486
2486
                nr = ~0;        /* indicate error to the caller */
2610
2610
                        pb_import_row_count++;
2611
2611
        }
2612
2612
 
2613
 
        if (table->next_number_field && buf == table->getInsertRecord()) {
 
2613
        if (getTable()->next_number_field && buf == getTable()->getInsertRecord()) {
2614
2614
                int update_err = update_auto_increment();
2615
2615
                if (update_err) {
2616
2616
                        ha_log_pbxt_thread_error_for_mysql(pb_ignore_dup_key);
2617
2617
                        err = update_err;
2618
2618
                        goto done;
2619
2619
                }
2620
 
                ha_set_auto_increment(pb_open_tab, table->next_number_field);
 
2620
                ha_set_auto_increment(pb_open_tab, getTable()->next_number_field);
2621
2621
        }
2622
2622
 
2623
2623
        if (!xt_tab_new_record(pb_open_tab, (xtWord1 *) buf)) {
2735
2735
         * update t1 set a=2 where a=1;
2736
2736
         * insert into t1 (val) values (1);
2737
2737
         */
2738
 
        if (table->found_next_number_field && new_data == table->getInsertRecord()) {
 
2738
        if (getTable()->found_next_number_field && new_data == getTable()->getInsertRecord()) {
2739
2739
                MX_LONGLONG_T   nr;
2740
 
        const boost::dynamic_bitset<>& old_bitmap= table->use_all_columns(*table->read_set);
2741
 
                nr = table->found_next_number_field->val_int();
2742
 
                ha_set_auto_increment(pb_open_tab, table->found_next_number_field);
2743
 
        table->restore_column_map(old_bitmap);
 
2740
        const boost::dynamic_bitset<>& old_bitmap= getTable()->use_all_columns(*getTable()->read_set);
 
2741
                nr = getTable()->found_next_number_field->val_int();
 
2742
                ha_set_auto_increment(pb_open_tab, getTable()->found_next_number_field);
 
2743
        getTable()->restore_column_map(old_bitmap);
2744
2744
        }
2745
2745
 
2746
2746
        if (!xt_tab_update_record(pb_open_tab, (xtWord1 *) old_data, (xtWord1 *) new_data))
3134
3134
        /* The number of columns required: */
3135
3135
        if (pb_open_tab->ot_is_modify) {
3136
3136
 
3137
 
                pb_open_tab->ot_cols_req = table->read_set->MX_BIT_SIZE();
 
3137
                pb_open_tab->ot_cols_req = getTable()->read_set->MX_BIT_SIZE();
3138
3138
#ifdef XT_PRINT_INDEX_OPT
3139
3139
                ind = (XTIndexPtr) pb_share->sh_dic_keys[idx];
3140
3140
 
3149
3149
        }
3150
3150
        else {
3151
3151
                //pb_open_tab->ot_cols_req = ha_get_max_bit(table->read_set);
3152
 
                pb_open_tab->ot_cols_req = table->read_set->MX_BIT_SIZE();
 
3152
                pb_open_tab->ot_cols_req = getTable()->read_set->MX_BIT_SIZE();
3153
3153
 
3154
3154
                /* Check for index coverage!
3155
3155
                 *
3200
3200
         */
3201
3201
        std::string bitmap_str= convert_long_to_bit_string(ind->mi_col_map, ind->mi_col_map_size);
3202
3202
        MX_BITMAP tmp(bitmap_str);
3203
 
                if (MX_BIT_IS_SUBSET(table->read_set, tmp))
 
3203
                if (MX_BIT_IS_SUBSET(getTable()->read_set, tmp))
3204
3204
#else
3205
 
                if (MX_BIT_IS_SUBSET(table->read_set, ind->mi_col_map))
 
3205
                if (MX_BIT_IS_SUBSET(getTable()->read_set, ind->mi_col_map))
3206
3206
#endif
3207
3207
                        pb_key_read = TRUE;
3208
3208
#ifdef XT_PRINT_INDEX_OPT
3347
3347
        XT_DISABLED_TRACE(("search tx=%d val=%d err=%d\n", (int) pb_open_tab->ot_thread->st_xact_data->xd_start_xn_id, (int) XT_GET_DISK_4(key), err));
3348
3348
        done:
3349
3349
        if (err)
3350
 
                table->status = STATUS_NOT_FOUND;
 
3350
                getTable()->status = STATUS_NOT_FOUND;
3351
3351
        else {
3352
3352
                pb_open_tab->ot_thread->st_statistics.st_row_select++;
3353
 
                table->status = 0;
 
3353
                getTable()->status = 0;
3354
3354
        }
3355
3355
        return err;
3356
3356
}
3408
3408
#endif
3409
3409
        done:
3410
3410
        if (err)
3411
 
                table->status = STATUS_NOT_FOUND;
 
3411
                getTable()->status = STATUS_NOT_FOUND;
3412
3412
        else {
3413
3413
                pb_open_tab->ot_thread->st_statistics.st_row_select++;
3414
 
                table->status = 0;
 
3414
                getTable()->status = 0;
3415
3415
        }
3416
3416
        XT_RETURN(err);
3417
3417
}
3462
3462
#endif
3463
3463
        done:
3464
3464
        if (err)
3465
 
                table->status = STATUS_NOT_FOUND;
 
3465
                getTable()->status = STATUS_NOT_FOUND;
3466
3466
        else {
3467
3467
                pb_open_tab->ot_thread->st_statistics.st_row_select++;
3468
 
                table->status = 0;
 
3468
                getTable()->status = 0;
3469
3469
        }
3470
3470
        XT_RETURN(err);
3471
3471
}
3500
3500
#endif
3501
3501
        done:
3502
3502
        if (err)
3503
 
                table->status = STATUS_NOT_FOUND;
 
3503
                getTable()->status = STATUS_NOT_FOUND;
3504
3504
        else {
3505
3505
                pb_open_tab->ot_thread->st_statistics.st_row_select++;
3506
 
                table->status = 0;
 
3506
                getTable()->status = 0;
3507
3507
        }
3508
3508
        XT_RETURN(err);
3509
3509
}
3553
3553
#endif
3554
3554
        done:
3555
3555
        if (err)
3556
 
                table->status = STATUS_NOT_FOUND;
 
3556
                getTable()->status = STATUS_NOT_FOUND;
3557
3557
        else {
3558
3558
                pb_open_tab->ot_thread->st_statistics.st_row_select++;
3559
 
                table->status = 0;
 
3559
                getTable()->status = 0;
3560
3560
        }
3561
3561
        XT_RETURN(err);
3562
3562
}
3599
3599
#endif
3600
3600
        done:
3601
3601
        if (err)
3602
 
                table->status = STATUS_NOT_FOUND;
 
3602
                getTable()->status = STATUS_NOT_FOUND;
3603
3603
        else {
3604
3604
                pb_open_tab->ot_thread->st_statistics.st_row_select++;
3605
 
                table->status = 0;
 
3605
                getTable()->status = 0;
3606
3606
        }
3607
3607
        XT_RETURN(err);
3608
3608
}
3646
3646
 
3647
3647
        /* The number of columns required: */
3648
3648
        if (pb_open_tab->ot_is_modify) {
3649
 
                pb_open_tab->ot_cols_req = table->read_set->MX_BIT_SIZE();
 
3649
                pb_open_tab->ot_cols_req = getTable()->read_set->MX_BIT_SIZE();
3650
3650
                /* {START-STAT-HACK} previously position of start statement hack,
3651
3651
                 * previous comment to code below: */
3652
3652
                /* Start a statement based transaction as soon
3656
3656
        }
3657
3657
        else {
3658
3658
                //pb_open_tab->ot_cols_req = ha_get_max_bit(table->read_set);
3659
 
                pb_open_tab->ot_cols_req = table->read_set->MX_BIT_SIZE();
 
3659
                pb_open_tab->ot_cols_req = getTable()->read_set->MX_BIT_SIZE();
3660
3660
 
3661
3661
                /*
3662
3662
                 * in case of queries like SELECT COUNT(*) FROM t
3726
3726
                err = HA_ERR_END_OF_FILE;
3727
3727
 
3728
3728
        if (err)
3729
 
                table->status = STATUS_NOT_FOUND;
 
3729
                getTable()->status = STATUS_NOT_FOUND;
3730
3730
        else {
3731
3731
                pb_open_tab->ot_thread->st_statistics.st_row_select++;
3732
 
                table->status = 0;
 
3732
                getTable()->status = 0;
3733
3733
        }
3734
3734
        XT_RETURN(err);
3735
3735
}
3801
3801
        }               
3802
3802
 
3803
3803
        if (err)
3804
 
                table->status = STATUS_NOT_FOUND;
 
3804
                getTable()->status = STATUS_NOT_FOUND;
3805
3805
        else {
3806
3806
                pb_open_tab->ot_thread->st_statistics.st_row_select++;
3807
 
                table->status = 0;
 
3807
                getTable()->status = 0;
3808
3808
        }
3809
3809
        XT_RETURN(err);
3810
3810
}