From 8439c2b8afee7827c7be83fb133b6d404a193eb1 Mon Sep 17 00:00:00 2001 From: Ankur Datta <64993082+ankur-arch@users.noreply.github.com> Date: Thu, 12 Dec 2024 17:55:38 +0600 Subject: [PATCH] feat: optimize recommendation for db.money (#6517) --- content/700-optimize/300-recordings.mdx | 1 + .../600-avoid-db-money.mdx | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 content/700-optimize/400-recommendations/600-avoid-db-money.mdx diff --git a/content/700-optimize/300-recordings.mdx b/content/700-optimize/300-recordings.mdx index 24f0307747..e9a9204f34 100644 --- a/content/700-optimize/300-recordings.mdx +++ b/content/700-optimize/300-recordings.mdx @@ -41,6 +41,7 @@ When a recording session ends, Optimize generates recommendations such as: - [Queries on unindexed columns](/optimize/recommendations/queries-on-unindexed-columns) - [Repeated query](/optimize/recommendations/repeated-query) - [Overfetching](/optimize/recommendations/select-returning) +- [Using `@db.Money`](/optimize/recommendations/avoid-db-money) :::info Use [Prisma AI](/optimize/prisma-ai) to ask follow-up questions about a recommendation. diff --git a/content/700-optimize/400-recommendations/600-avoid-db-money.mdx b/content/700-optimize/400-recommendations/600-avoid-db-money.mdx new file mode 100644 index 0000000000..d824c9fa82 --- /dev/null +++ b/content/700-optimize/400-recommendations/600-avoid-db-money.mdx @@ -0,0 +1,28 @@ +--- +title: 'Using @db.Money' +metaTitle: 'Optimize Recommendations: Avoid usage of `@db.Money`' +metaDescription: "Learn about the recommendation provided by Optimize for using `@db.Money` native type." +tocDepth: 3 +toc: true +--- + +Optimize provides recommendations to help you identify and resolve performance issues caused by the use of `@db.Money` type. + +The following model uses the `@db.Money` native type: + +```prisma +model Item { + // ... + price Decimal @db.Money + // ... +} +``` + +## What is the problem? + +The `@db.Money` data type in PostgreSQL is not ideal for storing monetary values. Internally, `@db.Money` is implemented as an integer, which offers speed but lacks flexibility. It handles fractional values and rounding in unexpected ways, which can lead to inaccuracies. + +Additionally, the `@db.Money` type does not store any information about the associated currency. Instead, it relies on the global `lc_monetary` locale setting, which may not be suitable for all use cases. + +For more information, refer to the [PostgreSQL documentation](https://wiki.postgresql.org/wiki/Don't_Do_This#Don.27t_use_money). +