yugabyte/yugabyte-db

[YSQL] `pg_total_relation_size` and `pg_table_size` return the same result for a table

Open

#23,181 创建于 2024年7月11日

在 GitHub 查看
 (5 评论) (0 反应) (1 负责人)C (1,003 fork)batch import
2025.1.2_blockerarea/ysqlgood first issuekind/enhancementpriority/medium

仓库指标

Star
 (8,229 star)
PR 合并指标
 (平均合并 17天 21小时) (30 天内合并 92 个 PR)

描述

Jira Link: DB-12121

Description

pg_total_relation_size should return the size including index size.

/*
 *	Compute the on-disk size of all files for the relation,
 *	including heap data, index data, toast data, FSM, VM.
 */
static int64
calculate_total_relation_size(Relation rel)
{
	int64		size;

	/*
	 * Aggregate the table size, this includes size of the heap, toast and
	 * toast index with free space and visibility map
	 */
	size = calculate_table_size(rel);

        ...

	/*
	 * Add size of all attached indexes as well
	 */
	size += calculate_indexes_size(rel);

	return size;
}

We modified calculate_table_size to work for YB in D17169 / 2e767c443d80ac1144bfe75739dff84801f763b0.

static int64
calculate_table_size(Relation rel)
{
	int64		size = 0;
	ForkNumber	forkNum;

	if (IsYBRelation(rel))
	{
		....
		HandleYBStatus(YBCPgGetTableDiskSize(YbGetRelfileNodeId(rel),
			MyDatabaseId, (int64_t *)&size, &num_missing_tablets));
		...
		return size;
	}
        ...

However, we missed modifying calculate_indexes_size, so it tries to check how much space an index is occupying on the local disk, instead of requesting the size from DocDB.

A similar fix would probably work here.

Issue Type

kind/enhancement

Warning: Please confirm that this issue does not contain any sensitive information

  • I confirm this issue does not contain any sensitive information.

贡献者指南