# Calculate PK usage for tables with composite key as Primary key

**URL:** <https://forums.percona.com/t/calculate-pk-usage-for-tables-with-composite-key-as-primary-key/25612>\
**Category:** Percona Server for MySQL 5.7\
**Created:** [October 3, 2023, 5:07am UTC](https://forums.percona.com/t/calculate-pk-usage-for-tables-with-composite-key-as-primary-key/25612 "2023-10-03T05:07:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![virin\_t](https://avatars.discourse-cdn.com/v4/letter/v/b38774/32.png) [@virin\_t](https://forums.percona.com/u/virin_t)\
**Post date:** [October 3, 2023, 5:07am UTC](https://forums.percona.com/t/calculate-pk-usage-for-tables-with-composite-key-as-primary-key/25612/1 "2023-10-03T05:07:11Z")

</div>

Hi, I am trying to get primary % used on table in percona mysql 5.7 version db, it is straight when there a only one column as Primary Key.  
but, what is correct approach when ,  
I have table where primary is on two columns and each column have different datatypes.  
PRIMARY KEY ( ‘column A’,‘column B’)  
column A mediumint(5) unsigned  
column B varchar(25)

In this case , what is correct way to calculate PK space usage for this table

---

<div class="post-metadata">

**Author:** ![kedarpercona](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/kedarpercona/32/809_2.png) [@kedarpercona](https://forums.percona.com/u/kedarpercona)\
**Post date:** [October 3, 2023, 5:26am UTC](https://forums.percona.com/t/calculate-pk-usage-for-tables-with-composite-key-as-primary-key/25612/2 "2023-10-03T05:26:57Z")

</div>

Hi Virin,  
Imagine InnoDB table as a PK arranged B-tree… it is clustered index storing all the data in sorted order… So your table size is your primary index size. If you add secondary indexes, you will see the size of the other indexes in the index\_length column of “show table status” output.  
I wonder though why would you try to find the PK space usage?

Thanks,  
K

---

<div class="post-metadata">

**Author:** ![matthewb](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/matthewb/32/34_2.png) [@matthewb](https://forums.percona.com/u/matthewb)\
**Post date:** [October 3, 2023, 12:05pm UTC](https://forums.percona.com/t/calculate-pk-usage-for-tables-with-composite-key-as-primary-key/25612/3 "2023-10-03T12:05:06Z")

</div>

> [@virin\_t](#):
>
> column B varchar(25)

It depends on which character set you are using. latin1 uses 1 byte per character. utf8/utf8mb3 can use 1-3 bytes, and utf8mb4 uses up to 4 bytes.

---

<div class="post-metadata">

**Author:** ![virin\_t](https://avatars.discourse-cdn.com/v4/letter/v/b38774/32.png) [@virin\_t](https://forums.percona.com/u/virin_t)\
**Post date:** [October 11, 2023, 5:34am UTC](https://forums.percona.com/t/calculate-pk-usage-for-tables-with-composite-key-as-primary-key/25612/4 "2023-10-11T05:34:12Z")

</div>

Hi Kedar,  
Just trying to know the usage to see if any tables have more usage and might run to issue related to PK usage (if auto increment is not set etc)  
beside that, just curious to find how to get usage estimation on tables with a composite key as primary key (more than one column with different datatypes)

---

<div class="post-metadata">

**Author:** ![virin\_t](https://avatars.discourse-cdn.com/v4/letter/v/b38774/32.png) [@virin\_t](https://forums.percona.com/u/virin_t)\
**Post date:** [October 11, 2023, 5:35am UTC](https://forums.percona.com/t/calculate-pk-usage-for-tables-with-composite-key-as-primary-key/25612/5 "2023-10-11T05:35:19Z")

</div>

using utf8 here mat, just trying to know usage depending on number of rows

---

<div class="post-metadata">

**Author:** ![kedarpercona](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/kedarpercona/32/809_2.png) [@kedarpercona](https://forums.percona.com/u/kedarpercona)\
**Post date:** [October 11, 2023, 1:22pm UTC](https://forums.percona.com/t/calculate-pk-usage-for-tables-with-composite-key-as-primary-key/25612/6 "2023-10-11T13:22:34Z")

</div>

Hi Virin,

If it is auto-increment or integer type, you call still find the fill factor you may query OR use [PMM](https://docs.percona.com/percona-monitoring-and-management/details/dashboards/dashboard-mysql-table-details.html#pie).

In your case where auto-increment is not set BUT you have a composite primary key with a varchar column. I really see no way to identify a limit or range for it’s usage. Even if it is two integers the domain for that primary key will become really large: say `n! / (m!(n - m)!)` assuming that’s the range of those two columns respectively!  
Best is to monitor (pmm) and routinely check the auto-increment fill depending on how much is your data growth…

Thanks,  
K.
