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. python学习小结2:if和while控制语句

    if语句 if语句中,代码块是按缩进的空格数量来判断的,也就是说空格数量一致的相邻行会被当作一个代码块,当if的条件成立的时候它就会得到执行. x = 100 if x > 50: print ...

  2. 我只知道一点非常简单的关于MVC的验证

    我只知道一些非常简单的关于MVC的验证 如题,我只知道一点非常简单的关于MVC的验证,所以如果您接触过MVC的验证,相信也就不用看了,这个且当作是学习笔记吧. 先小讲解一下他基本的五个从Model里打 ...

  3. RabbitMQ学习(1):安装

    1.安装 Erlang,官网:https://www.erlang.org/ 2.安装RabbitMQ服务器,rabbitMQ server,官网http://www.rabbitmq.com/ 注: ...

  4. 【BZOJ】【2818】Gcd

    欧拉函数/莫比乌斯函数 嗯……跟2190很像的一道题,在上道题的基础上我们很容易就想到先求出gcd(x,y)==1的组,然后再让x*=prime[i],y*=prime[i]这样它们的最大公约数就是p ...

  5. MySQL之重设密码(忘记密码)讲解

    Windows下的实际操作如下: 1.关闭正在运行的MySQL. 2.打开DOS窗口,转到mysql\bin目录. 3.输入mysqld(或mysqld-nt) --skip-grant-tables ...

  6. linux故障救援

    今天手贱,误操作将/usr/lib整个文件夹都删了.但是系统内还有很多重要的文件和数据,不敢贸然重装系统. 弄了个u盘启动. 一开始整个系统只有一个分区,原系统装在这个分区里,我用u盘启动后,用分区管 ...

  7. linux源代码阅读笔记 fork和execve的区别

    1. man exec就可以知到: The exec() family of functions replaces the current process image with a new proce ...

  8. [C++]默认构造函数

    默认构造函数(default constructor)就是在没有显示提供初始化式时调用的构造函数.它由不带参数的构造函数,或者为所有的形参提供默认实参的构造函数定义.若个定义某个类的变量时没有提供初始 ...

  9. LOGSTASH再入门第一发

    慢慢弄起来... 前年搞过,现在生疏了,再慢慢拾起来吧. 一些URL: https://www.elastic.co/downloads/logstash https://www.elastic.co ...

  10. redis、memcache、mongoDB有哪些区别(转载)

    转载: http://leandre.cn/database/64.html Memcached Memcached的优点: Memcached可以利用多核优势,单实例吞吐量极高,可以达到几十万QPS ...