Skip to content

Instantly share code, notes, and snippets.

@rponte
Last active December 13, 2021 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rponte/e8950fa6ff1989b360a093e0d30548cb to your computer and use it in GitHub Desktop.
Save rponte/e8950fa6ff1989b360a093e0d30548cb to your computer and use it in GitHub Desktop.
Hibernate Tip when working with Oracle: favor dynamic update (@DynamicUpdate annotation)

Full page logging in Postgres and Oracle (Oracle: sparse update)

The volume of undo and redo generated is only 15 MB here, including 6 MB of undo vectors. This is really optimized and this is one reason why you should update only the columns changed (and not use the default non-dynamic update of Hibernate for example).

A feature @DynamicUpdate do Hibernate pode ser útil e interessante em alguns cenários especificos! Os cenários que me vem a cabeça agora:

Com relação a performance, o foco maior é na pressão colocada no banco de dados, pois é aqui onde pode-se colher melhores frutos ao configurar o Hibernate. Por exemplo, se você tem uma tabela com várias colunas indexadas usar a conf padrão do Hibernate pode se tornar um gargalo:

https://use-the-index-luke.com/sql/dml/update

E alguns bancos de dados, como Oracle, atualizar somente as colunas necessárias faz diferença no volume de logging gerado (UNDO e REDO) pelo banco. Ou seja, quanto mais log gerado mais escrita em disco, o que pode ser crítico em cenários de alto-throughput:

https://blog.dbi-services.com/full-page-logging-in-postgres-and-oracle/?source=post_page-----e3a04d6a8bd2----------------------

Na minha opinião, como regra geral, favoreça o padrão do Hibernate devido ao cache de statements. Ou seja, use somente @DynamicUpdate onde de fato for necessário e após um bom benchmarking com métricas e tudo mais!

@rponte
Copy link
Author

rponte commented Dec 13, 2021

Boost Secondary Index Queries with Index Only Scan

This also means that “SELECT *” is almost always a bad idea. You should only select the columns that you will need in order to benefit from Index Only Scan. And this recommendation is not only for SELECT. An UPDATE that lists all the table columns will be inefficient. This is why you need to set dynamic-update=true in Hibernate, which is unfortunately not the default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment