STV_BLOCKLIST - Amazon Redshift
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

STV_BLOCKLIST

STV_BLOCKLIST 包含数据库中每个分片、表或列所使用的 1 MB 磁盘块的数目。

将聚合查询与 STV_BLOCKLIST 结合使用(如以下示例所示)可确定为每个数据库、表、分片或列分配的 1 MB 磁盘块的数目。您还可以使用 STV_PARTITIONS 查看有关磁盘利用率的摘要信息。

STV_BLOCKLIST 仅对超级用户可见。有关更多信息,请参阅系统表和视图中的数据可见性

表列

列名称 数据类型 描述
slice integer 节点分片。
col integer 列的零基索引。您创建的每个表都附加有以下三个隐藏列:INSERT_XID、DELETE_XID 和 ROW_ID (OID)。包含 3 个用户定义的列的表实际上包含 6 列,用户定义的列在内部编号为 0、1 和 2。在此示例中,INSERT_XID、DELETE_XID 和 ROW_ID 列分别编号为 3、4 和 5。
tbl integer 数据库表的表 ID。
blocknum integer 数据块的 ID。
num_values integer 数据块上包含的值的数目。
extended_limits integer 供内部使用。
minvalue bigint 块的最小数据值。将非数字数据的前八个字符存储为 64 位整数。用于磁盘扫描。
maxvalue bigint 块的最大数据值。将非数字数据的前八个字符存储为 64 位整数。用于磁盘扫描。
sb_pos integer 磁盘上的超级数据块位置的内部 Amazon Redshift 标识符。
pinned integer 是否在预加载时将数据块固定到内存中。0 = false;1 = true。默认设置为“假”。
on_disk integer 是否自动在磁盘上存储数据块。0 = false;1 = true。默认设置为“假”。
modified integer 是否已修改数据块。0 = false;1 = true。默认设置为“false”。
hdr_modified integer 是否已修改数据块标头。0 = false;1 = true。默认设置为“假”。
unsorted integer 数据块是否未排序。0 = false;1 = true。默认为“真”。
tombstone integer 供内部使用。
preferred_diskno integer 数据块应该位于的磁盘的编号(除非磁盘已出故障)。磁盘一旦修复,该数据块就将移回到该磁盘。
temporary integer 数据块是否包含临时表或中间查询结果等位置的临时数据。0 = false;1 = true。默认设置为“假”。
newblock integer 指示数据块是新数据块 (true) 还是以前从未提交到过磁盘 (false)。0 = false;1 = true。
num_readers integer 每个块上的引用数。
flags integer 块标头的内部 Amazon Redshift 标志。

示例查询

分配的每个磁盘块在 STV_BLOCKLIST 中对应一行,因此选择所有行的查询可能会返回非常多的行。建议仅将聚合查询与 STV_BLOCKLIST 结合使用。

SVV_DISKUSAGE 视图以对用户更友好的格式提供相似信息;而以下示例演示 STV_BLOCKLIST 表的一个用例。

要确定 VENUE 表中每一列所使用的 1 MB 块数,请键入以下查询:

select col, count(*) from stv_blocklist, stv_tbl_perm where stv_blocklist.tbl = stv_tbl_perm.id and stv_blocklist.slice = stv_tbl_perm.slice and stv_tbl_perm.name = 'venue' group by col order by col;

此查询返回分配到 VENUE 表中每一列的 1 MB 块的数目,如以下示例数据所示:

col | count -----+------- 0 | 4 1 | 4 2 | 4 3 | 4 4 | 4 5 | 4 7 | 4 8 | 4 (8 rows)

以下查询显示表数据是否实际分布于所有分片间:

select trim(name) as table, stv_blocklist.slice, stv_tbl_perm.rows from stv_blocklist,stv_tbl_perm where stv_blocklist.tbl=stv_tbl_perm.id and stv_tbl_perm.slice=stv_blocklist.slice and stv_blocklist.id > 10000 and name not like '%#m%' and name not like 'systable%' group by name, stv_blocklist.slice, stv_tbl_perm.rows order by 3 desc;

此查询生成以下示例输出,其中显示行数最多的表的平均数据分布:

table | slice | rows ----------+-------+------- listing | 13 | 10527 listing | 14 | 10526 listing | 8 | 10526 listing | 9 | 10526 listing | 7 | 10525 listing | 4 | 10525 listing | 17 | 10525 listing | 11 | 10525 listing | 5 | 10525 listing | 18 | 10525 listing | 12 | 10525 listing | 3 | 10525 listing | 10 | 10525 listing | 2 | 10524 listing | 15 | 10524 listing | 16 | 10524 listing | 6 | 10524 listing | 19 | 10524 listing | 1 | 10523 listing | 0 | 10521 ... (180 rows)

以下查询确定是否向磁盘提交了任何已逻辑删除的块:

select slice, col, tbl, blocknum, newblock from stv_blocklist where tombstone > 0; slice | col | tbl | blocknum | newblock -------+-----+--------+----------+---------- 4 | 0 | 101285 | 0 | 1 4 | 2 | 101285 | 0 | 1 4 | 4 | 101285 | 1 | 1 5 | 2 | 101285 | 0 | 1 5 | 0 | 101285 | 0 | 1 5 | 1 | 101285 | 0 | 1 5 | 4 | 101285 | 1 | 1 ... (24 rows)