博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
函数page_cur_search_with_match
阅读量:5061 次
发布时间:2019-06-12

本文共 8007 字,大约阅读时间需要 26 分钟。

 

/****************************************************************//**Searches the right position for a page cursor. */UNIV_INTERNvoidpage_cur_search_with_match(/*=======================*/    const buf_block_t*    block,    /*!< in: buffer block */    const dict_index_t*    index,    /*!< in: record descriptor */    const dtuple_t*        tuple,    /*!< in: data tuple */    ulint            mode,    /*!< in: PAGE_CUR_L,                    PAGE_CUR_LE, PAGE_CUR_G, or                    PAGE_CUR_GE */    ulint*            iup_matched_fields,                    /*!< in/out: already matched                    fields in upper limit record */    ulint*            iup_matched_bytes,                    /*!< in/out: already matched                    bytes in a field not yet                    completely matched */    ulint*            ilow_matched_fields,                    /*!< in/out: already matched                    fields in lower limit record */    ulint*            ilow_matched_bytes,                    /*!< in/out: already matched                    bytes in a field not yet                    completely matched */    page_cur_t*        cursor)    /*!< out: page cursor */{    ulint        up;    ulint        low;    ulint        mid;    const page_t*    page;    const page_dir_slot_t* slot;    const rec_t*    up_rec;    const rec_t*    low_rec;    const rec_t*    mid_rec;    ulint        up_matched_fields;    ulint        up_matched_bytes;    ulint        low_matched_fields;    ulint        low_matched_bytes;    ulint        cur_matched_fields;    ulint        cur_matched_bytes;    int        cmp;    mem_heap_t*    heap        = NULL;    ulint        offsets_[REC_OFFS_NORMAL_SIZE];    ulint*        offsets        = offsets_;    rec_offs_init(offsets_);    page = buf_block_get_frame(block);    page_check_dir(page);    /* If mode PAGE_CUR_G is specified, we are trying to position the    cursor to answer a query of the form "tuple < X", where tuple is    the input parameter, and X denotes an arbitrary physical record on    the page. We want to position the cursor on the first X which    satisfies the condition. */    up_matched_fields  = *iup_matched_fields;    up_matched_bytes   = *iup_matched_bytes;    low_matched_fields = *ilow_matched_fields;    low_matched_bytes  = *ilow_matched_bytes;    /* Perform binary search. First the search is done through the page    directory, after that as a linear search in the list of records    owned by the upper limit directory slot. */    low = 0;    up = page_dir_get_n_slots(page) - 1; //槽数    /* Perform binary search until the lower and upper limit directory    slots come to the distance 1 of each other */    /**      *二分查找,while循环,直至找到up与low相邻近      *      * slot为中间槽      * mid_rec为中间槽中的中间一条记录      *      *cmp_dtuple_rec_with_match:将tuple中每一列与mid_red中每一列做比较,如果相等继续其他列      */    while (up - low > 1) {        mid = (low + up) / 2;        slot = page_dir_get_nth_slot(page, mid);        mid_rec = page_dir_slot_get_rec(slot);         offsets = rec_get_offsets(mid_rec, index, offsets,                      dtuple_get_n_fields_cmp(tuple),                      &heap);        cmp = cmp_dtuple_rec_with_match(tuple, mid_rec, offsets,                        &cur_matched_fields,                        &cur_matched_bytes);        if (UNIV_LIKELY(cmp > 0)) {low_slot_match:            low = mid;            low_matched_fields = cur_matched_fields;            low_matched_bytes = cur_matched_bytes;        } else if (UNIV_EXPECT(cmp, -1)) {#ifdef PAGE_CUR_LE_OR_EXTENDS            if (mode == PAGE_CUR_LE_OR_EXTENDS                && page_cur_rec_field_extends(                    tuple, mid_rec, offsets,                    cur_matched_fields)) {                goto low_slot_match;            }#endif /* PAGE_CUR_LE_OR_EXTENDS */up_slot_match:            up = mid;            up_matched_fields = cur_matched_fields;            up_matched_bytes = cur_matched_bytes;        } else if (mode == PAGE_CUR_G || mode == PAGE_CUR_LE#ifdef PAGE_CUR_LE_OR_EXTENDS               || mode == PAGE_CUR_LE_OR_EXTENDS#endif /* PAGE_CUR_LE_OR_EXTENDS */               ) {            goto low_slot_match;        } else {            goto up_slot_match;        }    }    slot = page_dir_get_nth_slot(page, low);    low_rec = page_dir_slot_get_rec(slot);    slot = page_dir_get_nth_slot(page, up);    up_rec = page_dir_slot_get_rec(slot);    /* Perform linear search until the upper and lower records come to    distance 1 of each other. */    while (page_rec_get_next_const(low_rec) != up_rec) {        mid_rec = page_rec_get_next_const(low_rec);        ut_pair_min(&cur_matched_fields, &cur_matched_bytes,                low_matched_fields, low_matched_bytes,                up_matched_fields, up_matched_bytes);        offsets = rec_get_offsets(mid_rec, index, offsets,                      dtuple_get_n_fields_cmp(tuple),                      &heap);        cmp = cmp_dtuple_rec_with_match(tuple, mid_rec, offsets,                        &cur_matched_fields,                        &cur_matched_bytes);        if (UNIV_LIKELY(cmp > 0)) {low_rec_match:            low_rec = mid_rec;            low_matched_fields = cur_matched_fields;            low_matched_bytes = cur_matched_bytes;        } else if (UNIV_EXPECT(cmp, -1)) {#ifdef PAGE_CUR_LE_OR_EXTENDS            if (mode == PAGE_CUR_LE_OR_EXTENDS                && page_cur_rec_field_extends(                    tuple, mid_rec, offsets,                    cur_matched_fields)) {                goto low_rec_match;            }#endif /* PAGE_CUR_LE_OR_EXTENDS */up_rec_match:            up_rec = mid_rec;            up_matched_fields = cur_matched_fields;            up_matched_bytes = cur_matched_bytes;        } else if (mode == PAGE_CUR_G || mode == PAGE_CUR_LE#ifdef PAGE_CUR_LE_OR_EXTENDS               || mode == PAGE_CUR_LE_OR_EXTENDS#endif /* PAGE_CUR_LE_OR_EXTENDS */               ) {            goto low_rec_match;        } else {            goto up_rec_match;        }    }#ifdef UNIV_SEARCH_DEBUG    /* Check that the lower and upper limit records have the    right alphabetical order compared to tuple. */    dbg_matched_fields = 0;    dbg_matched_bytes = 0;    offsets = rec_get_offsets(low_rec, index, offsets,                  ULINT_UNDEFINED, &heap);    dbg_cmp = page_cmp_dtuple_rec_with_match(tuple, low_rec, offsets,                         &dbg_matched_fields,                         &dbg_matched_bytes);    if (mode == PAGE_CUR_G) {        ut_a(dbg_cmp >= 0);    } else if (mode == PAGE_CUR_GE) {        ut_a(dbg_cmp == 1);    } else if (mode == PAGE_CUR_L) {        ut_a(dbg_cmp == 1);    } else if (mode == PAGE_CUR_LE) {        ut_a(dbg_cmp >= 0);    }    if (!page_rec_is_infimum(low_rec)) {        ut_a(low_matched_fields == dbg_matched_fields);        ut_a(low_matched_bytes == dbg_matched_bytes);    }    dbg_matched_fields = 0;    dbg_matched_bytes = 0;    offsets = rec_get_offsets(up_rec, index, offsets,                  ULINT_UNDEFINED, &heap);    dbg_cmp = page_cmp_dtuple_rec_with_match(tuple, up_rec, offsets,                         &dbg_matched_fields,                         &dbg_matched_bytes);    if (mode == PAGE_CUR_G) {        ut_a(dbg_cmp == -1);    } else if (mode == PAGE_CUR_GE) {        ut_a(dbg_cmp <= 0);    } else if (mode == PAGE_CUR_L) {        ut_a(dbg_cmp <= 0);    } else if (mode == PAGE_CUR_LE) {        ut_a(dbg_cmp == -1);    }    if (!page_rec_is_supremum(up_rec)) {        ut_a(up_matched_fields == dbg_matched_fields);        ut_a(up_matched_bytes == dbg_matched_bytes);    }#endif    if (mode <= PAGE_CUR_GE) {        page_cur_position(up_rec, block, cursor);    } else {        page_cur_position(low_rec, block, cursor);    }    *iup_matched_fields  = up_matched_fields;    *iup_matched_bytes   = up_matched_bytes;    *ilow_matched_fields = low_matched_fields;    *ilow_matched_bytes  = low_matched_bytes;    if (UNIV_LIKELY_NULL(heap)) {        mem_heap_free(heap);    }}

 

转载于:https://www.cnblogs.com/taek/p/4953612.html

你可能感兴趣的文章
__all__有趣的属性
查看>>
BZOJ 5180 [Baltic2016]Cities(斯坦纳树)
查看>>
写博客
查看>>
利用循环播放dataurl的视频来防止锁屏:NoSleep.js
查看>>
python3 生成器与迭代器
查看>>
java编写提升性能的代码
查看>>
ios封装静态库技巧两则
查看>>
Educational Codeforces Round 46 (Rated for Div. 2)
查看>>
Abstract Factory Pattern
查看>>
C# 实现Bresenham算法(vs2010)
查看>>
基于iSCSI的SQL Server 2012群集测试(一)--SQL群集安装
查看>>
list 容器 排序函数.xml
查看>>
存储开头结尾使用begin tran,rollback tran作用?
查看>>
Activity启动过程中获取组件宽高的五种方式
查看>>
java导出Excel表格简单的方法
查看>>
SQLite数据库简介
查看>>
利用堆实现堆排序&amp;优先队列
查看>>
Mono源码学习笔记:Console类(四)
查看>>
Android学习路线(十二)Activity生命周期——启动一个Activity
查看>>
《Genesis-3D开源游戏引擎完整实例教程-跑酷游戏篇03:暂停游戏》
查看>>