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. C#中使用SelectionStart属性指定输入框光标位置

    今天工作中遇到一个小BUG需要修改,需求为在文本框输入的过程中,如果数字是以0开头则自动消除0 如输入012,则显示12 很容易想到在textbox的text changed事件中判断,如果text是 ...

  2. jquery-2.0.3.js和jquery-2.0.3.min.js的区别

    两个文件的作用是完全一样的. jquery-2.0.3.js里的代码是没有进行处理的原代码,适合于人们阅读与研究. jquery-2.0.3.min.js里的代码进行过特殊的处理, 如变量的名称基本都 ...

  3. 如何解决Mac与iPhone之间handoff连接问题

    首先账户以及设备handoff开关问题不再赘述.主要是昨天发现的一个小技巧 当确认所有设备的iCloud账号统一.蓝牙打开.处在同一WiFi下的前提下,我的iPhone和Mac仍然handoff连接有 ...

  4. .NET操作JSON

    http://www.cnblogs.com/txw1958/archive/2012/08/01/csharp-json.html JSON文件读入到内存中就是字符串,.NET操作JSON就是生成与 ...

  5. 一个有趣的 SQL 查询(查询7天连续登陆)

    一个有趣的 SQL 查询 一个朋友有这样一个SQL查询需求: 有一个登录表(tmp_test),包含用户ID(uid)和登录时间(login_time).表结构如下: . row ********** ...

  6. Wmware桥接网络虚拟机无法上网的问题

    之前装好的一个虚拟机,安装到本地的Wmware workstation的时候,发现无法上网. 虚拟机使用的是桥接模式:一开始怀疑IP被占用,修改后发现不起作用.    排查所有的网络配置,发现都没有问 ...

  7. 【BZOJ】【2154】Crash的数字表格

    莫比乌斯反演 PoPoQQQ讲义第4题 题解:http://www.cnblogs.com/jianglangcaijin/archive/2013/11/27/3446169.html 感觉两次sq ...

  8. javamail邮件发送报错解决方案

    如果你用myEclipse进行开发的话,运行时可能会出现以下的错误:Exception in thread "main" java.lang.NoClassDefFoundErro ...

  9. PHP输出中文乱码的问题

    用echo输出的中文显示成乱码, 其实应该是各种服务器脚本都会遇到这个问题, 根本还是编码问题, 一般来说出于编码兼容考虑大多的页面都将页面字符集定义为utf-8 <meta http-equi ...

  10. POJ1222 高斯消元法解抑或方程

    第一次学怎么用高斯消元法解抑或方程组,思想其实很简单,方法可以看下面的链接:http://blog.csdn.net/zhuichao001/article/details/5440843 有了这种思 ...