yugabyte / yugabyte-db

YugabyteDB - the cloud native distributed SQL database for mission-critical applications.
https://www.yugabyte.com
Other
9.06k stars 1.09k forks source link

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

Open timothy-e opened 4 months ago

timothy-e commented 4 months ago

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

Pedja-Djape commented 4 months ago

I'll pick this one up!

Pedja-Djape commented 3 months ago

Hey @timothy-e, I've been looking into this and am getting stuck. I took a look at calculate_table_size because you mentioned similar changes could be applied in calculate_indexes_size. I see in calculate_table_size there's methods called like, YBCPgGetTableDiskSize that make it straightforward to get the table size from DocDB, but can't seem to find a parallel for indexes.

If you have time, could you help point me in the right direction? I'm very new to this, so I apologize if there's something obvious I'm missing

alok-2024 commented 1 month ago

hey @Pedja-Djape I too glanced the issue and your comments.

Afaiu (as far as I understand) functionality similar to CatalogManager::GetTableDiskSize needs to be added in the YB catalog manager for getting index size and invoked in the calculate_indexes_size then.

@timothy-e can u help us verify our observations.