~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

Refactor

Show diffs side-by-side

added added

removed removed

Lines of Context:
104
104
        ulint   len;
105
105
        byte    buf[DICT_MAX_INDEX_COL_LEN];
106
106
 
 
107
        ut_a(clust_len >= BTR_EXTERN_FIELD_REF_SIZE);
 
108
 
 
109
        if (UNIV_UNLIKELY
 
110
            (!memcmp(clust_field + clust_len - BTR_EXTERN_FIELD_REF_SIZE,
 
111
                     field_ref_zero, BTR_EXTERN_FIELD_REF_SIZE))) {
 
112
                /* The externally stored field was not written yet.
 
113
                This record should only be seen by
 
114
                recv_recovery_rollback_active() or any
 
115
                TRX_ISO_READ_UNCOMMITTED transactions. */
 
116
                return(FALSE);
 
117
        }
 
118
 
107
119
        len = btr_copy_externally_stored_field_prefix(buf, sizeof buf,
108
120
                                                      zip_size,
109
121
                                                      clust_field, clust_len);
246
258
{
247
259
        sel_node_t*     node;
248
260
 
249
 
        node = mem_heap_alloc(heap, sizeof(sel_node_t));
 
261
        node = static_cast<sel_node_t *>(mem_heap_alloc(heap, sizeof(sel_node_t)));
250
262
        node->common.type = QUE_NODE_SELECT;
251
263
        node->state = SEL_NODE_OPEN;
252
264
 
326
338
                eval_node_copy_val(var->alias, exp);
327
339
 
328
340
                exp = que_node_get_next(exp);
329
 
                var = que_node_get_next(var);
 
341
                var = static_cast<sym_node_t *>(que_node_get_next(var));
330
342
        }
331
343
}
332
344
 
343
355
 
344
356
        ut_ad(node->is_aggregate);
345
357
 
346
 
        func_node = node->select_list;
 
358
        func_node = static_cast<func_node_t *>(node->select_list);
347
359
 
348
360
        while (func_node) {
349
361
                eval_node_set_int_val(func_node, 0);
350
362
 
351
 
                func_node = que_node_get_next(func_node);
 
363
                func_node = static_cast<func_node_t *>(que_node_get_next(func_node));
352
364
        }
353
365
 
354
366
        node->aggregate_already_fetched = FALSE;
474
486
 
475
487
        ut_ad(que_node_get_type(column) == QUE_NODE_SYMBOL);
476
488
 
477
 
        column->prefetch_buf = mem_alloc(SEL_MAX_N_PREFETCH
478
 
                                         * sizeof(sel_buf_t));
 
489
        column->prefetch_buf = static_cast<sel_buf_t *>(mem_alloc(SEL_MAX_N_PREFETCH
 
490
                                                                  * sizeof(sel_buf_t)));
479
491
        for (i = 0; i < SEL_MAX_N_PREFETCH; i++) {
480
492
                sel_buf = column->prefetch_buf + i;
481
493
 
554
566
                column values to be able to free it later: therefore
555
567
                we swap the values for sel_buf and val */
556
568
 
557
 
                sel_buf->data = dfield_get_data(val);
 
569
                sel_buf->data = static_cast<byte *>(dfield_get_data(val));
558
570
                sel_buf->len = dfield_get_len(val);
559
571
                sel_buf->val_buf_size = que_node_get_val_buf_size(column);
560
572
 
622
634
 
623
635
                val = que_node_get_val(column);
624
636
 
625
 
                data = dfield_get_data(val);
 
637
                data = static_cast<byte *>(dfield_get_data(val));
626
638
                len = dfield_get_len(val);
627
639
                val_buf_size = que_node_get_val_buf_size(column);
628
640
 
734
746
                /* Evaluate the left side of the comparison, i.e., get the
735
747
                column value if there is an indirection */
736
748
 
737
 
                eval_sym(cond->args);
 
749
          eval_sym(static_cast<sym_node_t *>(cond->args));
738
750
 
739
751
                /* Do the comparison */
740
752
 
870
882
                err = lock_clust_rec_read_check_and_lock(
871
883
                        0, btr_pcur_get_block(&plan->clust_pcur),
872
884
                        clust_rec, index, offsets,
873
 
                        node->row_lock_mode, lock_type, thr);
 
885
                        static_cast<lock_mode>(node->row_lock_mode), lock_type, thr);
874
886
 
875
887
                switch (err) {
876
888
                case DB_SUCCESS:
977
989
        }
978
990
 
979
991
        if (dict_index_is_clust(index)) {
980
 
                err = lock_clust_rec_read_check_and_lock(
981
 
                        0, block, rec, index, offsets, mode, type, thr);
 
992
                err = lock_clust_rec_read_check_and_lock(0, block, rec, index,
 
993
                                                         offsets, static_cast<lock_mode>(mode), type, thr);
982
994
        } else {
983
 
                err = lock_sec_rec_read_check_and_lock(
984
 
                        0, block, rec, index, offsets, mode, type, thr);
 
995
                err = lock_sec_rec_read_check_and_lock(0, block, rec, index,
 
996
                                                       offsets, static_cast<lock_mode>(mode), type, thr);
985
997
        }
986
998
 
987
999
        return(err);
2011
2023
 
2012
2024
        ut_ad(thr);
2013
2025
 
2014
 
        node = thr->run_node;
 
2026
        node = static_cast<sel_node_t *>(thr->run_node);
2015
2027
 
2016
2028
        ut_ad(que_node_get_type(node) == QUE_NODE_SELECT);
2017
2029
 
2048
2060
 
2049
2061
                        while (table_node) {
2050
2062
                                err = lock_table(0, table_node->table,
2051
 
                                                 i_lock_mode, thr);
 
2063
                                                 static_cast<lock_mode>(i_lock_mode), thr);
2052
2064
                                if (err != DB_SUCCESS) {
2053
2065
                                        thr_get_trx(thr)->error_state = err;
2054
2066
 
2055
2067
                                        return(NULL);
2056
2068
                                }
2057
2069
 
2058
 
                                table_node = que_node_get_next(table_node);
 
2070
                                table_node = static_cast<sym_node_t *>(que_node_get_next(table_node));
2059
2071
                        }
2060
2072
                }
2061
2073
 
2112
2124
 
2113
2125
        ut_ad(thr);
2114
2126
 
2115
 
        node = thr->run_node;
 
2127
        node = static_cast<fetch_node_t *>(thr->run_node);
2116
2128
        sel_node = node->cursor_def;
2117
2129
 
2118
2130
        ut_ad(que_node_get_type(node) == QUE_NODE_FETCH);
2171
2183
        void*   row,            /*!< in:  sel_node_t* */
2172
2184
        void*   user_arg)       /*!< in:  not used */
2173
2185
{
2174
 
        sel_node_t*     node = row;
 
2186
        sel_node_t *node = static_cast<sel_node_t *>(row);
2175
2187
        que_node_t*     exp;
2176
2188
        ulint           i = 0;
2177
2189
 
2220
2232
 
2221
2233
        ut_ad(thr);
2222
2234
 
2223
 
        node = thr->run_node;
 
2235
        node = static_cast<row_printf_node_t *>(thr->run_node);
2224
2236
 
2225
2237
        sel_node = node->sel_node;
2226
2238
 
2677
2689
        row_prebuilt_t* prebuilt,       /*!< in: prebuilt struct */
2678
2690
        const rec_t*    rec,            /*!< in: Innobase record in the index
2679
2691
                                        which was described in prebuilt's
2680
 
                                        template; must be protected by
2681
 
                                        a page latch */
 
2692
                                        template, or in the clustered index;
 
2693
                                        must be protected by a page latch */
 
2694
        ibool           rec_clust,      /*!< in: TRUE if rec is in the
 
2695
                                        clustered index instead of
 
2696
                                        prebuilt->index */
2682
2697
        const ulint*    offsets)        /*!< in: array returned by
2683
 
                                        rec_get_offsets() */
 
2698
                                        rec_get_offsets(rec) */
2684
2699
{
2685
 
        mysql_row_templ_t*      templ;
2686
 
        mem_heap_t*             extern_field_heap       = NULL;
2687
 
        mem_heap_t*             heap;
2688
 
        const byte*             data;
2689
 
        ulint                   len;
2690
 
        ulint                   i;
 
2700
        mem_heap_t*     extern_field_heap       = NULL;
 
2701
        mem_heap_t*     heap;
 
2702
        ulint           i;
2691
2703
 
2692
2704
        ut_ad(prebuilt->mysql_template);
2693
2705
        ut_ad(prebuilt->default_rec);
2694
2706
        ut_ad(rec_offs_validate(rec, NULL, offsets));
 
2707
        ut_ad(!rec_get_deleted_flag(rec, rec_offs_comp(offsets)));
2695
2708
 
2696
2709
        if (UNIV_LIKELY_NULL(prebuilt->blob_heap)) {
2697
2710
                mem_heap_free(prebuilt->blob_heap);
2700
2713
 
2701
2714
        for (i = 0; i < prebuilt->n_template ; i++) {
2702
2715
 
2703
 
                templ = prebuilt->mysql_template + i;
2704
 
 
2705
 
                if (UNIV_UNLIKELY(rec_offs_nth_extern(offsets,
2706
 
                                                      templ->rec_field_no))) {
 
2716
                const mysql_row_templ_t*templ = prebuilt->mysql_template + i;
 
2717
                const byte*             data;
 
2718
                ulint                   len;
 
2719
                ulint                   field_no;
 
2720
 
 
2721
                field_no = rec_clust
 
2722
                        ? templ->clust_rec_field_no : templ->rec_field_no;
 
2723
 
 
2724
                if (UNIV_UNLIKELY(rec_offs_nth_extern(offsets, field_no))) {
2707
2725
 
2708
2726
                        /* Copy an externally stored field to the temporary
2709
2727
                        heap */
2731
2749
                        data = btr_rec_copy_externally_stored_field(
2732
2750
                                rec, offsets,
2733
2751
                                dict_table_zip_size(prebuilt->table),
2734
 
                                templ->rec_field_no, &len, heap);
 
2752
                                field_no, &len, heap);
2735
2753
 
2736
2754
                        if (UNIV_UNLIKELY(!data)) {
2737
2755
                                /* The externally stored field
2767
2785
                } else {
2768
2786
                        /* Field is stored in the row. */
2769
2787
 
2770
 
                        data = rec_get_nth_field(rec, offsets,
2771
 
                                                 templ->rec_field_no, &len);
 
2788
                        data = rec_get_nth_field(rec, offsets, field_no, &len);
2772
2789
 
2773
2790
                        if (UNIV_UNLIKELY(templ->type == DATA_BLOB)
2774
2791
                            && len != UNIV_SQL_NULL) {
2784
2801
                                                UNIV_PAGE_SIZE);
2785
2802
                                }
2786
2803
 
2787
 
                                data = memcpy(mem_heap_alloc(
 
2804
                                data = static_cast<byte *>(memcpy(mem_heap_alloc(
2788
2805
                                                prebuilt->blob_heap, len),
2789
 
                                                data, len);
 
2806
                                                                  data, len));
2790
2807
                        }
2791
2808
                }
2792
2809
 
2968
2985
                err = lock_clust_rec_read_check_and_lock(
2969
2986
                        0, btr_pcur_get_block(prebuilt->clust_pcur),
2970
2987
                        clust_rec, clust_index, *offsets,
2971
 
                        prebuilt->select_lock_type, LOCK_REC_NOT_GAP, thr);
 
2988
                        static_cast<lock_mode>(prebuilt->select_lock_type),
 
2989
                        LOCK_REC_NOT_GAP, thr);
2972
2990
                switch (err) {
2973
2991
                case DB_SUCCESS:
2974
2992
                case DB_SUCCESS_LOCKED_REC:
2992
3010
 
2993
3011
                        /* The following call returns 'offsets' associated with
2994
3012
                        'old_vers' */
2995
 
                        err = row_sel_build_prev_vers_for_mysql(
 
3013
                  err = static_cast<db_err>(row_sel_build_prev_vers_for_mysql(
2996
3014
                                trx->read_view, clust_index, prebuilt,
2997
3015
                                clust_rec, offsets, offset_heap, &old_vers,
2998
 
                                mtr);
 
3016
                                mtr));
2999
3017
 
3000
3018
                        if (err != DB_SUCCESS || old_vers == NULL) {
3001
3019
 
3130
3148
        row_prebuilt_t* prebuilt)       /*!< in: prebuilt struct */
3131
3149
{
3132
3150
        ulint                   i;
3133
 
        mysql_row_templ_t*      templ;
 
3151
        const mysql_row_templ_t*templ;
3134
3152
        byte*                   cached_rec;
3135
3153
        ut_ad(prebuilt->n_fetch_cached > 0);
3136
3154
        ut_ad(prebuilt->mysql_prefix_len <= prebuilt->mysql_row_len);
3190
3208
row_sel_push_cache_row_for_mysql(
3191
3209
/*=============================*/
3192
3210
        row_prebuilt_t* prebuilt,       /*!< in: prebuilt struct */
3193
 
        const rec_t*    rec,            /*!< in: record to push; must
3194
 
                                        be protected by a page latch */
3195
 
        const ulint*    offsets)        /*!<in: rec_get_offsets() */
 
3211
        const rec_t*    rec,            /*!< in: record to push, in the index
 
3212
                                        which was described in prebuilt's
 
3213
                                        template, or in the clustered index;
 
3214
                                        must be protected by a page latch */
 
3215
        ibool           rec_clust,      /*!< in: TRUE if rec is in the
 
3216
                                        clustered index instead of
 
3217
                                        prebuilt->index */
 
3218
        const ulint*    offsets)        /*!< in: rec_get_offsets(rec) */
3196
3219
{
3197
3220
        byte*   buf;
3198
3221
        ulint   i;
3199
3222
 
3200
3223
        ut_ad(prebuilt->n_fetch_cached < MYSQL_FETCH_CACHE_SIZE);
3201
3224
        ut_ad(rec_offs_validate(rec, NULL, offsets));
 
3225
        ut_ad(!rec_get_deleted_flag(rec, rec_offs_comp(offsets)));
3202
3226
        ut_a(!prebuilt->templ_contains_blob);
3203
3227
 
3204
3228
        if (prebuilt->fetch_cache[0] == NULL) {
3210
3234
                        buffers in Linux. Put magic numbers there to help
3211
3235
                        to track a possible bug. */
3212
3236
 
3213
 
                        buf = mem_alloc(prebuilt->mysql_row_len + 8);
 
3237
                        buf = static_cast<byte *>(mem_alloc(prebuilt->mysql_row_len + 8));
3214
3238
 
3215
3239
                        prebuilt->fetch_cache[i] = buf + 4;
3216
3240
 
3227
3251
        if (UNIV_UNLIKELY(!row_sel_store_mysql_rec(
3228
3252
                                  prebuilt->fetch_cache[
3229
3253
                                          prebuilt->n_fetch_cached],
3230
 
                                  prebuilt, rec, offsets))) {
 
3254
                                  prebuilt, rec, rec_clust, offsets))) {
3231
3255
                return(FALSE);
3232
3256
        }
3233
3257
 
3604
3628
                                ut_ad(!rec_get_deleted_flag(rec, comp));
3605
3629
 
3606
3630
                                if (!row_sel_store_mysql_rec(buf, prebuilt,
3607
 
                                                             rec, offsets)) {
 
3631
                                                             rec, FALSE,
 
3632
                                                             offsets)) {
3608
3633
                                        /* Only fresh inserts may contain
3609
3634
                                        incomplete externally stored
3610
3635
                                        columns. Pretend that such
4252
4277
                        is necessary, because we can only get the undo
4253
4278
                        information via the clustered index record. */
4254
4279
 
4255
 
                        ut_ad(index != clust_index);
4256
4280
                        ut_ad(!dict_index_is_clust(index));
4257
4281
                        if (!lock_sec_rec_cons_read_sees(
4258
4282
                                    rec, trx->read_view)) {
4367
4391
                        goto next_rec;
4368
4392
                }
4369
4393
 
4370
 
                if (prebuilt->need_to_access_clustered) {
4371
 
 
4372
 
                        result_rec = clust_rec;
4373
 
 
4374
 
                        ut_ad(rec_offs_validate(result_rec, clust_index,
4375
 
                                                offsets));
4376
 
                } else {
4377
 
                        /* We used 'offsets' for the clust rec, recalculate
4378
 
                        them for 'rec' */
4379
 
                        offsets = rec_get_offsets(rec, index, offsets,
4380
 
                                                  ULINT_UNDEFINED, &heap);
4381
 
                        result_rec = rec;
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. */
 
4394
                result_rec = clust_rec;
 
4395
                ut_ad(rec_offs_validate(result_rec, clust_index, offsets));
4387
4396
        } else {
4388
4397
                result_rec = rec;
4389
 
                ut_ad(!rec_get_deleted_flag(rec, comp));
4390
4398
        }
4391
4399
 
4392
4400
        /* We found a qualifying record 'result_rec'. At this point,
4395
4403
        ut_ad(rec_offs_validate(result_rec,
4396
4404
                                result_rec != rec ? clust_index : index,
4397
4405
                                offsets));
 
4406
        ut_ad(!rec_get_deleted_flag(result_rec, comp));
4398
4407
 
4399
4408
        /* At this point, the clustered index record is protected
4400
4409
        by a page latch that was acquired when pcur was positioned.
4418
4427
                cursor. */
4419
4428
 
4420
4429
                if (!row_sel_push_cache_row_for_mysql(prebuilt, result_rec,
 
4430
                                                      result_rec != rec,
4421
4431
                                                      offsets)) {
4422
4432
                        /* Only fresh inserts may contain incomplete
4423
4433
                        externally stored columns. Pretend that such
4435
4445
 
4436
4446
                goto next_rec;
4437
4447
        } else {
4438
 
                if (prebuilt->template_type == ROW_MYSQL_DUMMY_TEMPLATE) {
 
4448
                if (UNIV_UNLIKELY
 
4449
                    (prebuilt->template_type == ROW_MYSQL_DUMMY_TEMPLATE)) {
 
4450
                        /* CHECK TABLE: fetch the row */
 
4451
 
 
4452
                        if (result_rec != rec
 
4453
                            && !prebuilt->need_to_access_clustered) {
 
4454
                                /* We used 'offsets' for the clust
 
4455
                                rec, recalculate them for 'rec' */
 
4456
                                offsets = rec_get_offsets(rec, index, offsets,
 
4457
                                                          ULINT_UNDEFINED,
 
4458
                                                          &heap);
 
4459
                                result_rec = rec;
 
4460
                        }
 
4461
 
4439
4462
                        memcpy(buf + 4, result_rec
4440
4463
                               - rec_offs_extra_size(offsets),
4441
4464
                               rec_offs_size(offsets));
4442
4465
                        mach_write_to_4(buf,
4443
4466
                                        rec_offs_extra_size(offsets) + 4);
4444
4467
                } else {
4445
 
                        if (!row_sel_store_mysql_rec(buf, prebuilt,
4446
 
                                                     result_rec, offsets)) {
 
4468
                        /* Returning a row to MySQL */
 
4469
 
 
4470
                        if (!row_sel_store_mysql_rec(buf, prebuilt, result_rec,
 
4471
                                                     result_rec != rec,
 
4472
                                                     offsets)) {
4447
4473
                                /* Only fresh inserts may contain
4448
4474
                                incomplete externally stored
4449
4475
                                columns. Pretend that such records do