vladmihalcea / hypersistence-optimizer

Hypersistence Optimizer allows you to get the most out of JPA and Hibernate. By scanning your application configuration and mappings, Hypersistence Optimizer can tell you what changes you need to do to speed up your data access layer.
https://vladmihalcea.com/hypersistence-optimizer/
Apache License 2.0
306 stars 43 forks source link

Optimization of PostgreSQL ENUM Type vs. EnumType.STRING/ORDINAL #246

Closed Shanzeee closed 1 month ago

Shanzeee commented 1 month ago

I'm encountering a warning from Hypersistence Optimizer regarding the use of EnumType.STRING for an enum attribute in my entity class. Below is the warning message:

[Hypersistence Optimizer] (Test worker) MAJOR - EnumTypeStringEvent - The [defaultLanguage] enum attribute in the entity uses the EnumType.STRING strategy, which has a bigger memory footprint than EnumType.ORDINAL. For more info about this event, check out this User Guide link - https://vladmihalcea.com/hypersistence-optimizer/docs/user-guide/#EnumTypeStringEvent

I understand that using EnumType.STRING can have a larger memory footprint compared to EnumType.ORDINAL. However, I'm considering the alternative of using PostgreSQL's native ENUM type.

Would it be more efficient to use PostgreSQL's native ENUM type instead of EnumType.ORDINAL?

Enviroment: -PostgreSQL version: 16.1 -Hibernate version: 6.5

Thank you for your assistance.

vladmihalcea commented 1 month ago

Would it be more efficient to use PostgreSQL's native ENUM type instead of EnumType.ORDINAL?

According to the documentation, a PostgreSQL Enum takes 4 bytes. So, it will be more efficient than using a STRING value as most Enum names have more than 4 characters.