文档主页
MySQL 8.4 参考手册
相关文档 下载本手册
PDF (US Ltr) - 39.9 MB
PDF (A4) - 40.0 MB
手册页 (TGZ) - 258.5 KB
手册页 (Zip) - 365.5 KB
信息 (Gzip) - 4.0 MB
信息 (Zip) - 4.0 MB


MySQL 8.4 参考手册  /  ...  /  ndbinfo memory_per_fragment 表

25.6.17.47 ndbinfo memory_per_fragment 表

memory_per_fragment 表提供了各个片段的内存使用信息。请参阅本节后面的注释,了解如何使用此表找出NDB表使用了多少内存。

memory_per_fragment 表包含以下列:

  • fq_name

    此片段的名称

  • parent_fq_name

    此片段的父级的名称

  • type

    用于此片段的字典对象类型(NDB API 中的Object::Type);以下类型之一:系统表用户表唯一哈希索引哈希索引唯一有序索引有序索引哈希索引触发器订阅触发器只读约束索引触发器重组触发器表空间日志文件组数据文件撤消文件哈希映射外键定义外键父触发器外键子触发器架构事务

    您还可以通过在 mysql 客户端中执行 TABLE ndbinfo.dict_obj_types 来获取此列表。

  • table_id

    此表的表 ID

  • node_id

    此节点的节点 ID

  • block_instance

    NDB 内核块实例 ID;您可以使用此编号从 threadblocks 表获取有关特定线程的信息。

  • fragment_num

    片段 ID(编号)

  • fixed_elem_alloc_bytes

    为固定大小元素分配的字节数

  • fixed_elem_free_bytes

    分配给固定大小元素的页面中剩余的可用字节数

  • fixed_elem_size_bytes

    每个固定大小元素的长度(以字节为单位)

  • fixed_elem_count

    固定大小元素的数量

  • fixed_elem_free_count

    固定大小元素的可用行数

  • var_elem_alloc_bytes

    为可变大小元素分配的字节数

  • var_elem_free_bytes

    分配给可变大小元素的页面中剩余的可用字节数

  • var_elem_count

    可变大小元素的数量

  • hash_index_alloc_bytes

    分配给哈希索引的字节数

memory_per_fragment 表:注释

memory_per_fragment 表为系统中的每个表片段副本和每个索引片段副本包含一行;这意味着,例如,当 NoOfReplicas=2 时,每个片段通常有两个片段副本。只要所有数据节点都在运行并连接到集群,这就是正确的;对于缺少的数据节点,它托管的片段副本没有行。

memory_per_fragment 表的列可以根据其功能或用途进行分组,如下所示:

  • 关键列fq_nametypetable_idnode_idblock_instancefragment_num

  • 关系列parent_fq_name

  • 固定大小存储列fixed_elem_alloc_bytesfixed_elem_free_bytesfixed_elem_size_bytesfixed_elem_countfixed_elem_free_count

  • 可变大小存储列var_elem_alloc_bytesvar_elem_free_bytesvar_elem_count

  • 哈希索引列hash_index_alloc_bytes

parent_fq_namefq_name 列可用于标识与表关联的索引。类似的架构对象层次结构信息可在其他 ndbinfo 表中找到。

表和索引片段副本在 32KB 页面中分配 DataMemory。这些内存页面的管理方式如下:

  • 固定大小页面:这些页面存储存储在给定片段中的行的固定大小部分。每行都有一个固定大小的部分。

  • 可变大小页面:这些页面存储片段中行的可变大小部分。每个具有一列或多列可变大小的动态列(或两者兼有)的行都具有一个可变大小的部分。

  • 哈希索引页面:这些页面分配为 8 KB 子页面,并存储主键哈希索引结构。

NDB 表中的每一行都有一个固定大小的部分,该部分由一个行标题和一个或多个固定大小的列组成。该行还可能包含一个或多个可变大小部分引用、一个或多个磁盘部分引用,或两者兼有。每一行还有一个主键哈希索引条目(对应于每个 NDB 表的一部分隐藏主键)。

从 foregoing 中我们可以看到,每个表片段和索引片段一起分配的 DataMemory 量计算如下:

DataMemory =
  (number_of_fixed_pages + number_of_var_pages) * 32KB
    + number_of_hash_pages * 8KB

由于 fixed_elem_alloc_bytesvar_elem_alloc_bytes 始终是 32768 字节的倍数,因此我们可以进一步确定 number_of_fixed_pages = fixed_elem_alloc_bytes / 32768number_of_var_pages = var_elem_alloc_bytes / 32768hash_index_alloc_bytes 始终是 8192 字节的倍数,因此 number_of_hash_pages = hash_index_alloc_bytes / 8192

固定大小页面有一个内部标题和许多固定大小的插槽,每个插槽可以包含一行的固定大小部分。给定行的固定大小部分的大小取决于架构,并由 fixed_elem_size_bytes 列提供;可以通过计算插槽总数和页面总数来确定每个页面的固定大小插槽数量,如下所示:

fixed_slots = fixed_elem_count + fixed_elem_free_count

fixed_pages = fixed_elem_alloc_bytes / 32768

slots_per_page = total_slots / total_pages

fixed_elem_count 实际上是给定表片段的行计数,因为每行都有 1 个固定元素,fixed_elem_free_count 是分配的页面中可用固定大小插槽的总数。fixed_elem_free_bytes 等于 fixed_elem_free_count * fixed_elem_size_bytes

片段可以有任意数量的固定大小页面;当删除固定大小页面上的最后一行时,该页面将释放到 DataMemory 页面池。固定大小页面可能会碎片化,分配的页面数量超过正在使用的固定大小插槽数量所需的页面数量。您可以通过将所需页面与分配的页面进行比较来检查是否存在这种情况,您可以按如下方式计算:

fixed_pages_required = 1 + (fixed_elem_count / slots_per_page)

fixed_page_utilization = fixed_pages_required / fixed_pages

可变大小页面有一个内部标题,并使用剩余空间存储一个或多个可变大小的行部分;存储的部分数量取决于架构和存储的实际数据。由于并非所有架构或行都具有可变大小的部分,因此 var_elem_count 可能小于 fixed_elem_count。片段中所有可变大小页面上的可用总空间由 var_elem_free_bytes 列显示;因为此空间可能分布在多个页面上,所以它不一定能用于存储特定大小的条目。每个可变大小页面都会根据需要进行重新组织,以适应可变大小行部分在插入、更新和删除时不断变化的大小;如果给定的行部分对于它所在的页面来说太大,则可以将其移动到不同的页面。

可变大小页面的利用率可以按如下方式计算:

var_page_used_bytes =  var_elem_alloc_bytes - var_elem_free_bytes

var_page_utilisation = var_page_used_bytes / var_elem_alloc_bytes

avg_row_var_part_size = var_page_used_bytes / fixed_elem_count

我们可以获得每行的平均可变部分大小,如下所示:

avg_row_var_part_size = var_page_used_bytes / fixed_elem_count

辅助唯一索引在内部实现为具有以下架构的独立表:

  • 主键:基表中的索引列。

  • :基表中的主键列。

这些表像往常一样分布和分片。这意味着它们的片段副本像使用任何其他 NDB 表一样使用固定、可变和哈希索引页面。

辅助有序索引的分片和分布方式与基表相同。有序索引片段是 T 树结构,它维护一个平衡树,其中包含按索引列隐含的顺序排列的行引用。由于树包含引用而不是实际数据,因此 T 树存储成本不取决于索引列的大小或数量,而是行数的函数。该树是使用固定大小的节点结构构建的,每个节点结构可以包含许多行引用;所需的节点数量取决于表中的行数以及表示顺序所需的树结构。在 memory_per_fragment 表中,我们可以看到有序索引仅分配固定大小的页面,因此与往常一样,此表中的相关列如下所示:

  • fixed_elem_alloc_bytes:这等于固定大小页面数量的 32768 倍。

  • fixed_elem_count:正在使用的 T 树节点的数量。

  • fixed_elem_size_bytes:每个 T 树节点的字节数。

  • fixed_elem_free_count:分配的页面中可用的 T 树节点插槽的数量。

  • fixed_elem_free_bytes:这等于 fixed_elem_free_count * fixed_elem_size_bytes

如果页面中的可用空间碎片化,则对该页面进行碎片整理。可以使用 OPTIMIZE TABLE 对表的可变大小页面进行碎片整理;这会在页面之间移动行的可变大小部分,以便可以释放一些完整的页面以供重复使用。

memory_per_fragment 表:示例

在以下示例中,我们创建一个包含三个整数列的简单表,其中一列具有主键,一列具有唯一索引,一列没有索引,以及一个没有索引的 VARCHAR 列,如下所示

mysql> CREATE DATABASE IF NOT EXISTS test;
Query OK, 1 row affected (0.06 sec)

mysql> USE test;
Database changed

mysql> CREATE TABLE t1 (
    ->    c1 BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    ->    c2 INT,
    ->    c3 INT UNIQUE,
    -> )  ENGINE=NDBCLUSTER;
Query OK, 0 rows affected (0.27 sec)

创建表后,我们插入 50,000 行包含随机数据;生成和插入这些行的精确方法没有实际区别,我们将完成该方法留给用户作为练习。

获取有关片段和内存使用情况的一般信息

此查询显示有关每个片段的内存使用情况的一般信息

mysql> SELECT
    ->   fq_name, node_id, block_instance, fragment_num, fixed_elem_alloc_bytes,
    ->   fixed_elem_free_bytes, fixed_elem_size_bytes, fixed_elem_count,
    ->   fixed_elem_free_count, var_elem_alloc_bytes, var_elem_free_bytes,
    ->   var_elem_count
    -> FROM ndbinfo.memory_per_fragment
    -> WHERE fq_name = "test/def/t1"\G
*************************** 1. row ***************************
               fq_name: test/def/t1
               node_id: 5
        block_instance: 1
          fragment_num: 0
fixed_elem_alloc_bytes: 1114112
 fixed_elem_free_bytes: 11836
 fixed_elem_size_bytes: 44
      fixed_elem_count: 24925
 fixed_elem_free_count: 269
  var_elem_alloc_bytes: 1245184
   var_elem_free_bytes: 32552
        var_elem_count: 24925
*************************** 2. row ***************************
               fq_name: test/def/t1
               node_id: 5
        block_instance: 1
          fragment_num: 1
fixed_elem_alloc_bytes: 1114112
 fixed_elem_free_bytes: 5236
 fixed_elem_size_bytes: 44
      fixed_elem_count: 25075
 fixed_elem_free_count: 119
  var_elem_alloc_bytes: 1277952
   var_elem_free_bytes: 54232
        var_elem_count: 25075
*************************** 3. row ***************************
               fq_name: test/def/t1
               node_id: 6
        block_instance: 1
          fragment_num: 0
fixed_elem_alloc_bytes: 1114112
 fixed_elem_free_bytes: 11836
 fixed_elem_size_bytes: 44
      fixed_elem_count: 24925
 fixed_elem_free_count: 269
  var_elem_alloc_bytes: 1245184
   var_elem_free_bytes: 32552
        var_elem_count: 24925
*************************** 4. row ***************************
               fq_name: test/def/t1
               node_id: 6
        block_instance: 1
          fragment_num: 1
fixed_elem_alloc_bytes: 1114112
 fixed_elem_free_bytes: 5236
 fixed_elem_size_bytes: 44
      fixed_elem_count: 25075
 fixed_elem_free_count: 119
  var_elem_alloc_bytes: 1277952
   var_elem_free_bytes: 54232
        var_elem_count: 25075
4 rows in set (0.12 sec)
查找表及其索引

此查询可用于查找特定表及其索引

mysql> SELECT fq_name
    -> FROM ndbinfo.memory_per_fragment
    -> WHERE fq_name = 'test/def/t1' OR parent_fq_name='test/def/t1'
    -> GROUP BY fq_name;
+----------------------+
| fq_name              |
+----------------------+
| test/def/t1          |
| sys/def/13/PRIMARY   |
| sys/def/13/c3        |
| sys/def/13/c3$unique |
+----------------------+
4 rows in set (0.13 sec)

mysql> SELECT COUNT(*) FROM t1;
+----------+
| COUNT(*) |
+----------+
|    50000 |
+----------+
1 row in set (0.00 sec)
查找架构元素分配的内存

此查询显示每个架构元素分配的内存(所有副本的总和)

mysql> SELECT
    ->   fq_name AS Name,
    ->   SUM(fixed_elem_alloc_bytes) AS Fixed,
    ->   SUM(var_elem_alloc_bytes) AS Var,
    ->   SUM(hash_index_alloc_bytes) AS Hash,
    ->   SUM(fixed_elem_alloc_bytes+var_elem_alloc_bytes+hash_index_alloc_bytes) AS Total
    -> FROM ndbinfo.memory_per_fragment
    -> WHERE fq_name = 'test/def/t1' OR parent_fq_name='test/def/t1'
    -> GROUP BY fq_name;
+----------------------+---------+---------+---------+----------+
| Name                 | Fixed   | Var     | Hash    | Total    |
+----------------------+---------+---------+---------+----------+
| test/def/t1          | 4456448 | 5046272 | 1425408 | 10928128 |
| sys/def/13/PRIMARY   | 1966080 |       0 |       0 |  1966080 |
| sys/def/13/c3        | 1441792 |       0 |       0 |  1441792 |
| sys/def/13/c3$unique | 3276800 |       0 | 1425408 |  4702208 |
+----------------------+---------+---------+---------+----------+
4 rows in set (0.11 sec)
查找为表及其所有索引分配的内存

可以使用此处显示的查询获得为表及其所有索引分配的内存总和(所有副本的总和)

mysql> SELECT
    ->   SUM(fixed_elem_alloc_bytes) AS Fixed,
    ->   SUM(var_elem_alloc_bytes) AS Var,
    ->   SUM(hash_index_alloc_bytes) AS Hash,
    ->   SUM(fixed_elem_alloc_bytes+var_elem_alloc_bytes+hash_index_alloc_bytes) AS Total
    -> FROM ndbinfo.memory_per_fragment
    -> WHERE fq_name = 'test/def/t1' OR parent_fq_name='test/def/t1';
+----------+---------+---------+----------+
| Fixed    | Var     | Hash    | Total    |
+----------+---------+---------+----------+
| 11141120 | 5046272 | 2850816 | 19038208 |
+----------+---------+---------+----------+
1 row in set (0.12 sec)

这是先前查询的缩写版本,仅显示表使用的总内存

mysql> SELECT
    ->   SUM(fixed_elem_alloc_bytes+var_elem_alloc_bytes+hash_index_alloc_bytes) AS Total
    -> FROM ndbinfo.memory_per_fragment
    -> WHERE fq_name = 'test/def/t1' OR parent_fq_name='test/def/t1';
+----------+
| Total    |
+----------+
| 19038208 |
+----------+
1 row in set (0.12 sec)
查找每行分配的内存

以下查询显示每行分配的总内存(所有副本)

mysql> SELECT
    ->   SUM(fixed_elem_alloc_bytes+var_elem_alloc_bytes+hash_index_alloc_bytes)
    ->   /
    ->   SUM(fixed_elem_count) AS Total_alloc_per_row
    -> FROM ndbinfo.memory_per_fragment
    -> WHERE fq_name = 'test/def/t1';
+---------------------+
| Total_alloc_per_row |
+---------------------+
|            109.2813 |
+---------------------+
1 row in set (0.12 sec)
查找每行使用的总内存

要获取每行使用的总内存(所有副本),我们需要使用的总内存除以行数,即基表的 fixed_elem_count,如下所示

mysql> SELECT
    ->   SUM(
    ->     (fixed_elem_alloc_bytes - fixed_elem_free_bytes)
    ->     + (var_elem_alloc_bytes - var_elem_free_bytes)
    ->     + hash_index_alloc_bytes
    ->   )
    ->   /
    ->   SUM(fixed_elem_count)
    ->   AS total_in_use_per_row
    -> FROM ndbinfo.memory_per_fragment
    -> WHERE fq_name = 'test/def/t1';
+----------------------+
| total_in_use_per_row |
+----------------------+
|             107.2042 |
+----------------------+
1 row in set (0.12 sec)
查找每个元素分配的内存

可以使用以下查询找到每个架构元素分配的内存(所有副本的总和)

mysql> SELECT
    ->   fq_name AS Name,
    ->   SUM(fixed_elem_alloc_bytes) AS Fixed,
    ->   SUM(var_elem_alloc_bytes) AS Var,
    ->   SUM(hash_index_alloc_bytes) AS Hash,
    ->   SUM(fixed_elem_alloc_bytes + var_elem_alloc_bytes + hash_index_alloc_bytes)
    ->     AS Total_alloc
    -> FROM ndbinfo.memory_per_fragment
    -> WHERE fq_name = 'test/def/t1' OR parent_fq_name='test/def/t1'
    -> GROUP BY fq_name;
+----------------------+---------+---------+---------+-------------+
| Name                 | Fixed   | Var     | Hash    | Total_alloc |
+----------------------+---------+---------+---------+-------------+
| test/def/t1          | 4456448 | 5046272 | 1425408 |    10928128 |
| sys/def/13/PRIMARY   | 1966080 |       0 |       0 |     1966080 |
| sys/def/13/c3        | 1441792 |       0 |       0 |     1441792 |
| sys/def/13/c3$unique | 3276800 |       0 | 1425408 |     4702208 |
+----------------------+---------+---------+---------+-------------+
4 rows in set (0.11 sec)
查找每个元素每行分配的平均内存

要获取每个架构元素每行分配的平均内存(所有副本的总和),我们使用子查询每次获取基表固定元素计数,以获取每行的平均值,因为索引的 fixed_elem_count 不一定与基表相同,如下所示

mysql> SELECT
    ->   fq_name AS Name,
    ->   ( SELECT SUM(fixed_elem_count)
    ->     FROM ndbinfo.memory_per_fragment
    ->     WHERE fq_name='test/def/t1') AS Table_rows,
    ->
    ->   SUM(fixed_elem_alloc_bytes)
    ->   /
    ->   ( SELECT SUM(fixed_elem_count)
    ->     FROM ndbinfo.memory_per_fragment
    ->     WHERE fq_name='test/def/t1') AS Avg_fixed_alloc,
    ->
    ->   SUM(var_elem_alloc_bytes)
    ->   /
    ->   ( SELECT SUM(fixed_elem_count)
    ->     FROM ndbinfo.memory_per_fragment
    ->     WHERE fq_name='test/def/t1') as Avg_var_alloc,
    ->
    ->   SUM(hash_index_alloc_bytes)
    ->   /
    ->   ( SELECT SUM(fixed_elem_count)
    ->     FROM ndbinfo.memory_per_fragment
    ->     WHERE fq_name='test/def/t1') as Avg_hash_alloc,
    ->
    ->   SUM(fixed_elem_alloc_bytes+var_elem_alloc_bytes+hash_index_alloc_bytes)
    ->   /
    ->   ( SELECT SUM(fixed_elem_count)
    ->     FROM ndbinfo.memory_per_fragment
    ->     WHERE fq_name='test/def/t1') as Avg_total_alloc
    ->
    -> FROM ndbinfo.memory_per_fragment
    -> WHERE fq_name = 'test/def/t1' or parent_fq_name='test/def/t1'
    -> GROUP BY fq_name;
+----------------------+------------+-----------------+---------------+----------------+-----------------+
| Name                 | Table_rows | Avg_fixed_alloc | Avg_var_alloc | Avg_hash_alloc | Avg_total_alloc |
+----------------------+------------+-----------------+---------------+----------------+-----------------+
| test/def/t1          |     100000 |         44.5645 |       50.4627 |        14.2541 |        109.2813 |
| sys/def/13/PRIMARY   |     100000 |         19.6608 |        0.0000 |         0.0000 |         19.6608 |
| sys/def/13/c3        |     100000 |         14.4179 |        0.0000 |         0.0000 |         14.4179 |
| sys/def/13/c3$unique |     100000 |         32.7680 |        0.0000 |        14.2541 |         47.0221 |
+----------------------+------------+-----------------+---------------+----------------+-----------------+
4 rows in set (0.70 sec)
查找每行分配的平均内存

每行分配的平均内存(所有副本的总和)

mysql> SELECT
    ->   ( SELECT SUM(fixed_elem_count)
    ->     FROM ndbinfo.memory_per_fragment
    ->     WHERE fq_name='test/def/t1') AS Table_rows,
    ->
    ->   SUM(fixed_elem_alloc_bytes)
    ->   /
    ->   ( SELECT SUM(fixed_elem_count)
    ->     FROM ndbinfo.memory_per_fragment
    ->     WHERE fq_name='test/def/t1') AS Avg_fixed_alloc,
    ->
    ->   SUM(var_elem_alloc_bytes)
    ->   /
    ->   ( SELECT SUM(fixed_elem_count)
    ->     FROM ndbinfo.memory_per_fragment
    ->     WHERE fq_name='test/def/t1') AS Avg_var_alloc,
    ->
    ->   SUM(hash_index_alloc_bytes)
    ->   /
    ->   ( SELECT SUM(fixed_elem_count)
    ->     FROM ndbinfo.memory_per_fragment
    ->     WHERE fq_name='test/def/t1') AS Avg_hash_alloc,
    ->
    ->   SUM(fixed_elem_alloc_bytes + var_elem_alloc_bytes + hash_index_alloc_bytes)
    ->   /
    ->   ( SELECT SUM(fixed_elem_count)
    ->     FROM ndbinfo.memory_per_fragment
    ->     WHERE fq_name='test/def/t1') AS Avg_total_alloc
    ->
    -> FROM ndbinfo.memory_per_fragment
    -> WHERE fq_name = 'test/def/t1' OR parent_fq_name='test/def/t1';
+------------+-----------------+---------------+----------------+-----------------+
| Table_rows | Avg_fixed_alloc | Avg_var_alloc | Avg_hash_alloc | Avg_total_alloc |
+------------+-----------------+---------------+----------------+-----------------+
|     100000 |        111.4112 |       50.4627 |        28.5082 |        190.3821 |
+------------+-----------------+---------------+----------------+-----------------+
1 row in set (0.71 sec)
查找表中每行分配的平均内存

要获取整个表中所有副本的每行分配的平均内存量,我们可以使用此处显示的查询

mysql> SELECT
    ->   ( SELECT SUM(fixed_elem_count)
    ->     FROM ndbinfo.memory_per_fragment
    ->     WHERE fq_name='test/def/t1') AS table_rows,
    ->
    ->   SUM(fixed_elem_alloc_bytes + var_elem_alloc_bytes + hash_index_alloc_bytes)
    ->   /
    ->   ( SELECT SUM(fixed_elem_count)
    ->     FROM ndbinfo.memory_per_fragment
    ->     WHERE fq_name='test/def/t1') AS avg_total_alloc
    ->
    -> FROM ndbinfo.memory_per_fragment
    -> WHERE fq_name = 'test/def/t1' OR parent_fq_name='test/def/t1';
+------------+-----------------+
| table_rows | avg_total_alloc |
+------------+-----------------+
|     100000 |        190.3821 |
+------------+-----------------+
1 row in set (0.33 sec)
查找每个架构元素使用的内存

要获取所有副本中每个架构元素使用的内存,我们需要对每个元素的已分配内存和空闲内存之间的差值求和,如下所示

mysql> SELECT
    ->   fq_name AS Name,
    ->   SUM(fixed_elem_alloc_bytes - fixed_elem_free_bytes) AS fixed_inuse,
    ->   SUM(var_elem_alloc_bytes-var_elem_free_bytes) AS var_inuse,
    ->   SUM(hash_index_alloc_bytes) AS hash_memory,
    ->   SUM(  (fixed_elem_alloc_bytes - fixed_elem_free_bytes)
    ->       + (var_elem_alloc_bytes - var_elem_free_bytes)
    ->       + hash_index_alloc_bytes) AS total_alloc
    -> FROM ndbinfo.memory_per_fragment
    -> WHERE fq_name = 'test/def/t1' OR parent_fq_name='test/def/t1'
    -> GROUP BY fq_name;
+----------------------+-------------+-----------+---------+-------------+
| fq_name              | fixed_inuse | var_inuse | hash    | total_alloc |
+----------------------+-------------+-----------+---------+-------------+
| test/def/t1          |     4422304 |   4872704 | 1425408 |    10720416 |
| sys/def/13/PRIMARY   |     1950848 |         0 |       0 |     1950848 |
| sys/def/13/c3        |     1428736 |         0 |       0 |     1428736 |
| sys/def/13/c3$unique |     3212800 |         0 | 1425408 |     4638208 |
+----------------------+-------------+-----------+---------+-------------+
4 rows in set (0.13 sec)
查找每个架构元素使用的平均内存

此查询获取所有副本中每个架构元素使用的平均内存

mysql> SELECT
    ->   fq_name AS Name,
    ->
    ->   ( SELECT SUM(fixed_elem_count)
    ->     FROM ndbinfo.memory_per_fragment
    ->     WHERE fq_name='test/def/t1') AS table_rows,
    ->
    ->   SUM(fixed_elem_alloc_bytes - fixed_elem_free_bytes)
    ->   /
    ->   ( SELECT SUM(fixed_elem_count)
    ->     FROM ndbinfo.memory_per_fragment
    ->     WHERE fq_name='test/def/t1') AS avg_fixed_inuse,
    ->
    ->   SUM(var_elem_alloc_bytes - var_elem_free_bytes)
    ->   /
    ->   ( SELECT SUM(fixed_elem_count)
    ->     FROM ndbinfo.memory_per_fragment
    ->     WHERE fq_name='test/def/t1') AS avg_var_inuse,
    ->
    ->   SUM(hash_index_alloc_bytes)
    ->   /
    ->   ( SELECT SUM(fixed_elem_count)
    ->     FROM ndbinfo.memory_per_fragment
    ->     WHERE fq_name='test/def/t1') AS avg_hash,
    ->
    ->   SUM(
    ->       (fixed_elem_alloc_bytes - fixed_elem_free_bytes)
    ->     + (var_elem_alloc_bytes - var_elem_free_bytes) + hash_index_alloc_bytes)
    ->   /
    ->   ( SELECT SUM(fixed_elem_count)
    ->     FROM ndbinfo.memory_per_fragment
    ->     WHERE fq_name='test/def/t1') AS avg_total_inuse
    ->
    -> FROM ndbinfo.memory_per_fragment
    -> WHERE fq_name = 'test/def/t1' OR parent_fq_name='test/def/t1'
    -> GROUP BY fq_name;
+----------------------+------------+-----------------+---------------+----------+-----------------+
| Name                 | table_rows | avg_fixed_inuse | avg_var_inuse | avg_hash | avg_total_inuse |
+----------------------+------------+-----------------+---------------+----------+-----------------+
| test/def/t1          |     100000 |         44.2230 |       48.7270 |  14.2541 |        107.2042 |
| sys/def/13/PRIMARY   |     100000 |         19.5085 |        0.0000 |   0.0000 |         19.5085 |
| sys/def/13/c3        |     100000 |         14.2874 |        0.0000 |   0.0000 |         14.2874 |
| sys/def/13/c3$unique |     100000 |         32.1280 |        0.0000 |  14.2541 |         46.3821 |
+----------------------+------------+-----------------+---------------+----------+-----------------+
4 rows in set (0.72 sec)
查找每个元素每行使用的平均内存

此查询获取所有副本中每个元素每行使用的平均内存

mysql> SELECT
    ->   ( SELECT SUM(fixed_elem_count)
    ->     FROM ndbinfo.memory_per_fragment
    ->     WHERE fq_name='test/def/t1') AS table_rows,
    ->
    ->   SUM(fixed_elem_alloc_bytes - fixed_elem_free_bytes)
    ->   /
    ->   ( SELECT SUM(fixed_elem_count)
    ->     FROM ndbinfo.memory_per_fragment
    ->     WHERE fq_name='test/def/t1') AS avg_fixed_inuse,
    ->
    ->   SUM(var_elem_alloc_bytes - var_elem_free_bytes)
    ->   /
    ->   ( SELECT SUM(fixed_elem_count)
    ->     FROM ndbinfo.memory_per_fragment
    ->     WHERE fq_name='test/def/t1') AS avg_var_inuse,
    ->
    ->   SUM(hash_index_alloc_bytes)
    ->   /
    ->   ( SELECT SUM(fixed_elem_count)
    ->     FROM ndbinfo.memory_per_fragment
    ->     WHERE fq_name='test/def/t1') AS avg_hash,
    ->
    ->   SUM(
    ->     (fixed_elem_alloc_bytes - fixed_elem_free_bytes)
    ->     + (var_elem_alloc_bytes - var_elem_free_bytes)
    ->     + hash_index_alloc_bytes)
    ->   /
    ->   ( SELECT SUM(fixed_elem_count)
    ->     FROM ndbinfo.memory_per_fragment
    ->     WHERE fq_name='test/def/t1') AS avg_total_inuse
    ->
    -> FROM ndbinfo.memory_per_fragment
    -> WHERE fq_name = 'test/def/t1' OR parent_fq_name='test/def/t1';
+------------+-----------------+---------------+----------+-----------------+
| table_rows | avg_fixed_inuse | avg_var_inuse | avg_hash | avg_total_inuse |
+------------+-----------------+---------------+----------+-----------------+
|     100000 |        110.1469 |       48.7270 |  28.5082 |        187.3821 |
+------------+-----------------+---------------+----------+-----------------+
1 row in set (0.68 sec)
查找每行使用的总平均内存

此查询获取每行使用的总平均内存

mysql> SELECT
    ->   SUM(
    ->     (fixed_elem_alloc_bytes - fixed_elem_free_bytes)
    ->     + (var_elem_alloc_bytes - var_elem_free_bytes)
    ->     + hash_index_alloc_bytes)
    ->   /
    ->   ( SELECT
    ->       SUM(fixed_elem_count)
    ->       FROM ndbinfo.memory_per_fragment
    ->       WHERE fq_name='test/def/t1') AS avg_total_in_use
    -> FROM ndbinfo.memory_per_fragment
    -> WHERE fq_name = 'test/def/t1' OR parent_fq_name='test/def/t1';
+------------------+
| avg_total_in_use |
+------------------+
|         187.3821 |
+------------------+
1 row in set (0.24 sec)