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. linux 删除某种规则命名的文件

    由于android开发需要删除以IMG_开头命名的图片文件,因此用到此命令 命令格式: rm IMG_*

  2. 一个SQL Server 2008 R2 死锁的问题解决

    问题场景:在客户那碰到一个操作卡死的现象 问题解决: 1.如何挂钩是死锁问题:通过代码跟踪,发现是指执行一个SQL语句超时,因此猜想可能是表锁住了 2.如果确认是思索问题:通过SQL发现死锁,以下是相 ...

  3. 【BZOJ】【2588】COT(Count On a Tree)

    可持久化线段树 maya……树么……转化成序列……所以就写了个树链剖分……然后每个点保存的是从它到根的可持久化线段树. 然后就像序列一样查询……注意是多个左端点和多个右端点,处理方法类似BZOJ 19 ...

  4. 剑指offer--面试题11

    题目:求数值的整数次方,不考虑大数值情况 即实现函数:double Power(double base, int exponent) 自己所写代码如下: #include "stdafx.h ...

  5. [转载]DateTime TryParse

    今天被Architect问住了,说你光用一个TryParse就判断人家是不是时间日期型的,是不完整的.所以我花点时间看了下TryParse的用法. MSDN:http://msdn.microsoft ...

  6. 关闭VS时, 每次都 会弹出 保存以下各项的更改吗?

    如果是添加项目, 或修改了解决方案的配置, 会弹出这个是正常的.  如果在没有修改的情况下还这样就是有问题的.   原因:  在Vs中安装了PowerDesigner插件, 并在VS中点了该插件的东西 ...

  7. Win 7怎样拒绝所有可移动存储设备的所有权限

    在Windows 7中,我们可拒绝对任何可移动存储类的权限.下面让我来教大家怎样在组策略中启用“所有可移动存储类:拒绝所有权限”策略,具体操作步骤如下所述: 步骤/方法 在开始搜索框中键入“gpedi ...

  8. Unity3D–Texture图片空间和内存占用分析(转载)

    原地址:http://www.unity蛮牛.com/home.php?mod=space&uid=1801&do=blog&id=756 Texture图片空间和内存占用分析 ...

  9. linux服务器重启服务命令说明文档

    (前提是电脑上面已经安装好了ssh软件~!)输入ip,用户名,端口(默认22) 输入密码,登陆成功之后, 转入到/usr/local/tomcat/bin 目录,输入命令行: [root@yangch ...

  10. HDU 2544 最短路(模板题)

    求1到N的最短路径,模板题,以1为源点,用dijkstra算法(可以用优先级队列优化) #include <iostream> #include <algorithm> #in ...