yugabyte/yugabyte-db

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

Open

#23,181 opened on Jul 11, 2024

View on GitHub
 (5 comments) (0 reactions) (1 assignee)C (1,003 forks)batch import
2025.1.2_blockerarea/ysqlgood first issuekind/enhancementpriority/medium

Repository metrics

Stars
 (8,229 stars)
PR merge metrics
 (Avg merge 17d 21h) (92 merged PRs in 30d)

Description

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.

Contributor guide