http://database.51cto.com/art/201303/383042.htm

/******************************************************//**
The following function determines the offsets to each field in the
record.     The offsets are written to a previously allocated array of
ulint, where rec_offs_n_fields(offsets) has been initialized to the
number of fields in the record.     The rest of the array will be
initialized by this function.  rec_offs_base(offsets)[0] will be set
to the extra size (if REC_OFFS_COMPACT is set, the record is in the
new format; if REC_OFFS_EXTERNAL is set, the record contains externally
stored columns), and rec_offs_base(offsets)[1..n_fields] will be set to
offsets past the end of fields 0..n_fields, or to the beginning of
fields 1..n_fields+1.  When the high-order bit of the offset at [i+1]
is set (REC_OFFS_SQL_NULL), the field i is NULL.  When the second
high-order bit of the offset at [i+1] is set (REC_OFFS_EXTERNAL), the
field i is being stored externally. */
static
void
rec_init_offsets(
/*=============*/
    const rec_t*        rec,    /*!< in: physical record */
    const dict_index_t*    index,    /*!< in: record descriptor */
    ulint*            offsets)/*!< in/out: array of offsets;
                    in: n=rec_offs_n_fields(offsets) */
{
    ulint    i    = ;
    ulint    offs;

    rec_offs_make_valid(rec, index, offsets);

    if (dict_table_is_comp(index->table)) {
        const byte*    nulls;
        const byte*    lens;
        dict_field_t*    field;
        ulint        null_mask;
        ulint        status = rec_get_status(rec);
        ulint        n_node_ptr_field = ULINT_UNDEFINED;

        switch (UNIV_EXPECT(status, REC_STATUS_ORDINARY)) {
        case REC_STATUS_INFIMUM:
        case REC_STATUS_SUPREMUM:
            /* the field is 8 bytes long */
            rec_offs_base(offsets)[]
                = REC_N_NEW_EXTRA_BYTES | REC_OFFS_COMPACT;
            rec_offs_base(offsets)[] = ;
            return;
        case REC_STATUS_NODE_PTR:
            n_node_ptr_field
                = dict_index_get_n_unique_in_tree(index);
            break;
        case REC_STATUS_ORDINARY:
            rec_init_offsets_comp_ordinary(
                rec, FALSE, index, offsets);
            return;
        }

        nulls = rec - (REC_N_NEW_EXTRA_BYTES + );
        lens = nulls - UT_BITS_IN_BYTES(index->n_nullable);
        offs = ;
        null_mask = ;

        /* read the lengths of fields 0..n */
        do {
            ulint    len;
            if (UNIV_UNLIKELY(i == n_node_ptr_field)) {
                len = offs += REC_NODE_PTR_SIZE;
                goto resolved;
            }

            field = dict_index_get_nth_field(index, i);
            if (!(dict_field_get_col(field)->prtype
                  & DATA_NOT_NULL)) {
                /* nullable field => read the null flag */

                if (UNIV_UNLIKELY(!(byte) null_mask)) {
                    nulls--;
                    null_mask = ;
                }

                if (*nulls & null_mask) {
                    null_mask <<= ;
                    /* No length is stored for NULL fields.
                    We do not advance offs, and we set
                    the length to zero and enable the
                    SQL NULL flag in offsets[]. */
                    len = offs | REC_OFFS_SQL_NULL;
                    goto resolved;
                }
                null_mask <<= ;
            }

            if (UNIV_UNLIKELY(!field->fixed_len)) {
                /* Variable-length field: read the length */
                const dict_col_t*    col
                    = dict_field_get_col(field);
                len = *lens--;
                /* If the maximum length of the field
                is up to 255 bytes, the actual length
                is always stored in one byte. If the
                maximum length is more than 255 bytes,
                the actual length is stored in one
                byte for 0..127.  The length will be
                encoded in two bytes when it is 128 or
                more, or when the field is stored
                externally. */
                )
                    || UNIV_UNLIKELY(col->mtype
                             == DATA_BLOB)) {
                    if (len & 0x80) {
                        /* 1exxxxxxx xxxxxxxx */

                        len <<= ;
                        len |= *lens--;

                        /* B-tree node pointers
                        must not contain externally
                        stored columns.  Thus
                        the "e" flag must be 0. */
                        ut_a(!(len & 0x4000));
                        offs += len & 0x3fff;
                        len = offs;

                        goto resolved;
                    }
                }

                len = offs += len;
            } else {
                len = offs += field->fixed_len;
            }
resolved:
            rec_offs_base(offsets)[i + ] = len;
        } while (++i < rec_offs_n_fields(offsets));

        *rec_offs_base(offsets)
            = (rec - (lens + )) | REC_OFFS_COMPACT;
    } else {
        /* Old-style record: determine extra size and end offsets */
        offs = REC_N_OLD_EXTRA_BYTES;
        if (rec_get_1byte_offs_flag(rec)) {
            offs += rec_offs_n_fields(offsets);
            *rec_offs_base(offsets) = offs;
            /* Determine offsets to fields */
            do {
                offs = rec_1_get_field_end_info(rec, i);
                if (offs & REC_1BYTE_SQL_NULL_MASK) {
                    offs &= ~REC_1BYTE_SQL_NULL_MASK;
                    offs |= REC_OFFS_SQL_NULL;
                }
                rec_offs_base(offsets)[ + i] = offs;
            } while (++i < rec_offs_n_fields(offsets));
        } else {
            offs +=  * rec_offs_n_fields(offsets);
            *rec_offs_base(offsets) = offs;
            /* Determine offsets to fields */
            do {
                offs = rec_2_get_field_end_info(rec, i);
                if (offs & REC_2BYTE_SQL_NULL_MASK) {
                    offs &= ~REC_2BYTE_SQL_NULL_MASK;
                    offs |= REC_OFFS_SQL_NULL;
                }
                if (offs & REC_2BYTE_EXTERN_MASK) {
                    offs &= ~REC_2BYTE_EXTERN_MASK;
                    offs |= REC_OFFS_EXTERNAL;
                    *rec_offs_base(offsets) |= REC_OFFS_EXTERNAL;
                }
                rec_offs_base(offsets)[ + i] = offs;
            } while (++i < rec_offs_n_fields(offsets));
        }
    }
}

函数rec_init_offsets的更多相关文章

  1. Python 小而美的函数

    python提供了一些有趣且实用的函数,如any all zip,这些函数能够大幅简化我们得代码,可以更优雅的处理可迭代的对象,同时使用的时候也得注意一些情况   any any(iterable) ...

  2. 探究javascript对象和数组的异同,及函数变量缓存技巧

    javascript中最经典也最受非议的一句话就是:javascript中一切皆是对象.这篇重点要提到的,就是任何jser都不陌生的Object和Array. 有段时间曾经很诧异,到底两种数据类型用来 ...

  3. JavaScript权威指南 - 函数

    函数本身就是一段JavaScript代码,定义一次但可能被调用任意次.如果函数挂载在一个对象上,作为对象的一个属性,通常这种函数被称作对象的方法.用于初始化一个新创建的对象的函数被称作构造函数. 相对 ...

  4. C++对C的函数拓展

    一,内联函数 1.内联函数的概念 C++中的const常量可以用来代替宏常数的定义,例如:用const int a = 10来替换# define a 10.那么C++中是否有什么解决方案来替代宏代码 ...

  5. 菜鸟Python学习笔记第一天:关于一些函数库的使用

    2017年1月3日 星期二 大一学习一门新的计算机语言真的很难,有时候连函数拼写出错查错都能查半天,没办法,谁让我英语太渣. 关于计算机语言的学习我想还是从C语言学习开始为好,Python有很多语言的 ...

  6. javascript中的this与函数讲解

    前言 javascript中没有块级作用域(es6以前),javascript中作用域分为函数作用域和全局作用域.并且,大家可以认为全局作用域其实就是Window函数的函数作用域,我们编写的js代码, ...

  7. 复杂的 Hash 函数组合有意义吗?

    很久以前看到一篇文章,讲某个大网站储存用户口令时,会经过十分复杂的处理.怎么个复杂记不得了,大概就是先 Hash,结果加上一些特殊字符再 Hash,结果再加上些字符.再倒序.再怎么怎么的.再 Hash ...

  8. JS核心系列:浅谈函数的作用域

    一.作用域(scope) 所谓作用域就是:变量在声明它们的函数体以及这个函数体嵌套的任意函数体内都是有定义的. function scope(){ var foo = "global&quo ...

  9. C++中的时间函数

    C++获取时间函数众多,何时该用什么函数,拿到的是什么时间?该怎么用?很多人都会混淆. 本文是本人经历了几款游戏客户端和服务器开发后,对游戏中时间获取的一点总结. 最早学习游戏客户端时,为了获取最精确 ...

随机推荐

  1. 升级iOS10之后调用摄像头/麦克风等硬件程序崩溃闪退的问题

    在升级到iOS10之后, 开发过程中难免会遇到很多的坑, 下面是一些常见的坑, 我做了一些整理, 希望对大家开发有帮助: &1. 调用视频,摄像头, 麦克风,等硬件程序崩溃闪退的问题: 要注意 ...

  2. 获取不到app.config里面的数据库连接字符串的解决方法

    今天在自己的类库里添加了对app.config文件的数据库连接字符串的引用,但是返回的居然是Null,纳闷了.然后在网上找到了答案原来是我的app.config文件加错了地方,应该加到启动项目里面,而 ...

  3. BAT CMD 批处理文件脚本 -2

    http://checheng1988.blog.51cto.com/4725808/1090733 在很多windows程序中会见到很多用扩展名为.bat和.cmd结尾的文件,那么这些文件能干什么呢 ...

  4. html+css学习笔记 2[标签]

    img标签/a标签 <img src="图片地址" alt="图片名"/>  图片(单标签)alt属性 是图片名字,是给百度搜索引擎抓取使用:    ...

  5. NYOJ-171 聪明的kk AC 分类: NYOJ 2014-01-02 09:01 165人阅读 评论(0) 收藏

    #include<stdio.h> #define max(x,y) x>y?x:y int main(){ int num[22][22]={0}; int n,m; int x, ...

  6. SSAO

    http://blog.csdn.net/xoyojank/article/details/5734537 http://john-chapman-graphics.blogspot.com/2013 ...

  7. .bash_profile备份

    # ~/.bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User sp ...

  8. Unity3D脚本中文系列教程(六)

    http://dong2008hong.blog.163.com/blog/static/469688272014031943118/ Unity3D脚本中文系列教程(五) 变量 ◆var colli ...

  9. JSP图片上传 公共工具类

    需要jsmartcom_zh_CN.jar支持. 下载地址: http://files.cnblogs.com/simpledev/jsmartcom_zh_CN.rar <%@page imp ...

  10. ZOJ 3778 Talented Chef(找规律,模拟计算,11届ACM省赛,简单)

    题目链接 2014年浙江省赛C题,当时觉得难,现在想想这题真水.. 找规律: 若   最大的那个步骤数*m-总和>=0,那么答案就是 最大的那个步骤数 . 否则  就要另加上不够的数量,具体看代 ...