~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to plugin/innobase/row/row0sel.c

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-12-21 16:39:40 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20101221163940-c1pfo1jjvx7909xq
Tags: 2010.12.06-0ubuntu1
* New upstream release.
* Added libaio-dev build depend for InnoDB.
* Removed libpcre patch - applied upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************************
2
2
 
3
 
Copyright (c) 1997, 2010, Innobase Oy. All Rights Reserved.
4
 
Copyright (c) 2008, Google Inc.
 
3
Copyright (C) 1997, 2010, Innobase Oy. All Rights Reserved.
 
4
Copyright (C) 2008, Google Inc.
5
5
 
6
6
Portions of this file contain modifications contributed and copyrighted by
7
7
Google, Inc. Those modifications are gratefully acknowledged and are described
2692
2692
        ut_ad(prebuilt->mysql_template);
2693
2693
        ut_ad(prebuilt->default_rec);
2694
2694
        ut_ad(rec_offs_validate(rec, NULL, offsets));
2695
 
        ut_ad(!rec_get_deleted_flag(rec, rec_offs_comp(offsets)));
2696
2695
 
2697
2696
        if (UNIV_LIKELY_NULL(prebuilt->blob_heap)) {
2698
2697
                mem_heap_free(prebuilt->blob_heap);
2699
2698
                prebuilt->blob_heap = NULL;
2700
2699
        }
2701
2700
 
2702
 
        /* init null bytes with default values as they might be
2703
 
        left uninitialized in some cases and these uninited bytes
2704
 
        might be copied into mysql record buffer that leads to
2705
 
        valgrind warnings */
2706
 
        memcpy(mysql_rec, prebuilt->default_rec, prebuilt->null_bitmap_len);
2707
 
 
2708
2701
        for (i = 0; i < prebuilt->n_template ; i++) {
2709
2702
 
2710
2703
                templ = prebuilt->mysql_template + i;
3377
3370
        mem_heap_t*     heap                            = NULL;
3378
3371
        ulint           offsets_[REC_OFFS_NORMAL_SIZE];
3379
3372
        ulint*          offsets                         = offsets_;
 
3373
        ibool           table_lock_waited               = FALSE;
3380
3374
 
3381
3375
        rec_offs_init(offsets_);
3382
3376
 
3607
3601
                                row_sel_try_search_shortcut_for_mysql().
3608
3602
                                The latch will not be released until
3609
3603
                                mtr_commit(&mtr). */
 
3604
                                ut_ad(!rec_get_deleted_flag(rec, comp));
3610
3605
 
3611
3606
                                if (!row_sel_store_mysql_rec(buf, prebuilt,
3612
3607
                                                             rec, offsets)) {
3722
3717
 
3723
3718
        clust_index = dict_table_get_first_index(index->table);
3724
3719
 
 
3720
        /* Do some start-of-statement preparations */
 
3721
 
 
3722
        if (!prebuilt->sql_stat_start) {
 
3723
                /* No need to set an intention lock or assign a read view */
 
3724
 
 
3725
                if (trx->read_view == NULL
 
3726
                    && prebuilt->select_lock_type == LOCK_NONE) {
 
3727
 
 
3728
                        fputs("InnoDB: Error: MySQL is trying to"
 
3729
                              " perform a consistent read\n"
 
3730
                              "InnoDB: but the read view is not assigned!\n",
 
3731
                              stderr);
 
3732
                        trx_print(stderr, trx, 600);
 
3733
                        fputc('\n', stderr);
 
3734
                        ut_error;
 
3735
                }
 
3736
        } else if (prebuilt->select_lock_type == LOCK_NONE) {
 
3737
                /* This is a consistent read */
 
3738
                /* Assign a read view for the query */
 
3739
 
 
3740
                trx_assign_read_view(trx);
 
3741
                prebuilt->sql_stat_start = FALSE;
 
3742
        } else {
 
3743
wait_table_again:
 
3744
                err = lock_table(0, index->table,
 
3745
                                 prebuilt->select_lock_type == LOCK_S
 
3746
                                 ? LOCK_IS : LOCK_IX, thr);
 
3747
 
 
3748
                if (err != DB_SUCCESS) {
 
3749
 
 
3750
                        table_lock_waited = TRUE;
 
3751
                        goto lock_table_wait;
 
3752
                }
 
3753
                prebuilt->sql_stat_start = FALSE;
 
3754
        }
 
3755
 
 
3756
        /* Open or restore index cursor position */
 
3757
 
3725
3758
        if (UNIV_LIKELY(direction != 0)) {
3726
3759
                ibool   need_to_process = sel_restore_position_for_mysql(
3727
3760
                        &same_user_rec, BTR_SEARCH_LEAF,
3797
3830
                }
3798
3831
        }
3799
3832
 
3800
 
        if (!prebuilt->sql_stat_start) {
3801
 
                /* No need to set an intention lock or assign a read view */
3802
 
 
3803
 
                if (trx->read_view == NULL
3804
 
                    && prebuilt->select_lock_type == LOCK_NONE) {
3805
 
 
3806
 
                        fputs("InnoDB: Error: MySQL is trying to"
3807
 
                              " perform a consistent read\n"
3808
 
                              "InnoDB: but the read view is not assigned!\n",
3809
 
                              stderr);
3810
 
                        trx_print(stderr, trx, 600);
3811
 
                        fputc('\n', stderr);
3812
 
                        ut_a(0);
3813
 
                }
3814
 
        } else if (prebuilt->select_lock_type == LOCK_NONE) {
3815
 
                /* This is a consistent read */
3816
 
                /* Assign a read view for the query */
3817
 
 
3818
 
                trx_assign_read_view(trx);
3819
 
                prebuilt->sql_stat_start = FALSE;
3820
 
        } else {
3821
 
                ulint   lock_mode;
3822
 
                if (prebuilt->select_lock_type == LOCK_S) {
3823
 
                        lock_mode = LOCK_IS;
3824
 
                } else {
3825
 
                        lock_mode = LOCK_IX;
3826
 
                }
3827
 
                err = lock_table(0, index->table, lock_mode, thr);
3828
 
 
3829
 
                if (err != DB_SUCCESS) {
3830
 
 
3831
 
                        goto lock_wait_or_error;
3832
 
                }
3833
 
                prebuilt->sql_stat_start = FALSE;
3834
 
        }
3835
 
 
3836
3833
rec_loop:
3837
3834
        /*-------------------------------------------------------------*/
3838
3835
        /* PHASE 4: Look for matching records in a loop */
4248
4245
 
4249
4246
                                rec = old_vers;
4250
4247
                        }
4251
 
                } else if (!lock_sec_rec_cons_read_sees(rec, trx->read_view)) {
 
4248
                } else {
4252
4249
                        /* We are looking into a non-clustered index,
4253
4250
                        and to get the right version of the record we
4254
4251
                        have to look also into the clustered index: this
4256
4253
                        information via the clustered index record. */
4257
4254
 
4258
4255
                        ut_ad(index != clust_index);
4259
 
                        goto requires_clust_rec;
 
4256
                        ut_ad(!dict_index_is_clust(index));
 
4257
                        if (!lock_sec_rec_cons_read_sees(
 
4258
                                    rec, trx->read_view)) {
 
4259
                                goto requires_clust_rec;
 
4260
                        }
4260
4261
                }
4261
4262
        }
4262
4263
 
4379
4380
                                                  ULINT_UNDEFINED, &heap);
4380
4381
                        result_rec = rec;
4381
4382
                }
 
4383
 
 
4384
                /* result_rec can legitimately be delete-marked
 
4385
                now that it has been established that it points to a
 
4386
                clustered index record that exists in the read view. */
4382
4387
        } else {
4383
4388
                result_rec = rec;
 
4389
                ut_ad(!rec_get_deleted_flag(rec, comp));
4384
4390
        }
4385
4391
 
4386
4392
        /* We found a qualifying record 'result_rec'. At this point,
4557
4563
 
4558
4564
        btr_pcur_store_position(pcur, &mtr);
4559
4565
 
 
4566
lock_table_wait:
4560
4567
        mtr_commit(&mtr);
4561
4568
        mtr_has_extra_clust_latch = FALSE;
4562
4569
 
4574
4581
                thr->lock_state = QUE_THR_LOCK_NOLOCK;
4575
4582
                mtr_start(&mtr);
4576
4583
 
 
4584
                /* Table lock waited, go try to obtain table lock
 
4585
                again */
 
4586
                if (table_lock_waited) {
 
4587
                        table_lock_waited = FALSE;
 
4588
 
 
4589
                        goto wait_table_again;
 
4590
                }
 
4591
 
4577
4592
                sel_restore_position_for_mysql(&same_user_rec,
4578
4593
                                               BTR_SEARCH_LEAF, pcur,
4579
4594
                                               moves_up, &mtr);