Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Index size metric with correct values #57

Merged
merged 1 commit into from
Jun 11, 2021

Conversation

iserko
Copy link
Contributor

@iserko iserko commented May 6, 2021

At my company we just used this to check a specific table in our database and noticed that the index_size was wrong.
Turns out the query used to pull that information is slightly off.

According to PostgreSQL docs https://www.postgresql.org/docs/current/catalog-pg-index.html
indrelid is The OID of the pg_class entry for the table this index is for
since the indexoid is used to calculate size by giving it as the parameter to pg_relation_size, that returns the size of the whole table and not just the index.

The fix is to use indexrelid which is The OID of the pg_class entry for this index.

At my company we just used this to check a specific table in our database and noticed that the index_size was wrong.
Turns out the query used to pull that information is slightly off.

According to PostgreSQL docs https://www.postgresql.org/docs/current/catalog-pg-index.html
`indrelid` is `The OID of the pg_class entry for the table this index is for`
since the `indexoid` is used to calculate size by giving it as the parameter to `pg_relation_size`, that returns the size of the whole table and not just the index.

The fix is to use `indexrelid` which is `The OID of the pg_class entry for this index`.
@CLAassistant
Copy link

CLAassistant commented May 6, 2021

CLA assistant check
All committers have signed the CLA.

@gsanchezgavier gsanchezgavier added design Categorizes issue or PR as related to design. triage/pending Issue or PR is pending for triage and prioritization. labels May 31, 2021
@carlossscastro carlossscastro self-assigned this Jun 4, 2021
@carlossscastro carlossscastro removed the triage/pending Issue or PR is pending for triage and prioritization. label Jun 9, 2021
@nadiamoe nadiamoe added bug Categorizes issue or PR as related to a bug. triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed design Categorizes issue or PR as related to design. labels Jun 11, 2021
@carlossscastro
Copy link
Contributor

This has been tested on both versions to validate index size values

Output of both integration versions:
currentversion_output.txt
fixedversion_output.txt

Output from Postgres DB:
postgresdb_output.txt

Compare example:

Validation Version:

      "metrics": [
        {
          "database": "demo",
          "displayName": "pg_attribute_relid_attnam_index",
          "entityName": "index:pg_attribute_relid_attnam_index",
          "event_type": "PostgresqlIndexSample",
          "index.sizeInBytes": 442368,
          "schema": "pg_catalog",
          "table": "pg_attribute"
        }
      ],

Fixed Version:

      "metrics": [
        {
          "database": "demo",
          "displayName": "pg_attribute_relid_attnam_index",
          "entityName": "index:pg_attribute_relid_attnam_index",
          "event_type": "PostgresqlIndexSample",
          "index.sizeInBytes": 131072,
          "schema": "pg_catalog",
          "table": "pg_attribute"
        }
      ],

Output From Postgres:

|                Name                 | Type  |  Owner   |      Table      | Persistence |    Size    |
| pg_attribute_relid_attnam_index     | index | postgres | pg_attribute    | permanent   | 128 kB     |

@carlossscastro
Copy link
Contributor

@iserko
Thanks a lot for spotting this and for your contribution
We will be releasing this in the next few days.

@carlossscastro carlossscastro self-requested a review June 11, 2021 14:04
@carlossscastro carlossscastro merged commit 7900876 into newrelic:master Jun 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Categorizes issue or PR as related to a bug. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants