From bd38a40d83c1e7c63a651890dc87ad97542c0d43 Mon Sep 17 00:00:00 2001 From: mmvpm Date: Fri, 10 May 2024 21:44:42 +0300 Subject: [PATCH] Add some sql indices --- README.md | 8 ++++++++ .../resources/db.migration/V7__photos_offer_id_index.sql | 1 + .../resources/db.migration/V8__offers_status_index.sql | 1 + .../mmvpm/service/dao/offer/OfferDaoPostgresql.scala | 2 +- 4 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 service/src/main/resources/db.migration/V7__photos_offer_id_index.sql create mode 100644 service/src/main/resources/db.migration/V8__offers_status_index.sql diff --git a/README.md b/README.md index abb4562..5e3c29c 100644 --- a/README.md +++ b/README.md @@ -130,6 +130,14 @@ create index offers_name_description_idx on offers using gin (to_tsvector('russian', name || ' ' || description)); ``` +Indices for internal needs: + +```sql +create index photos_offer_id on offer_photos (offer_id); + +create index offers_status_idx on offers (status); +``` + ### REST API #### Authorization diff --git a/service/src/main/resources/db.migration/V7__photos_offer_id_index.sql b/service/src/main/resources/db.migration/V7__photos_offer_id_index.sql new file mode 100644 index 0000000..4cb6f94 --- /dev/null +++ b/service/src/main/resources/db.migration/V7__photos_offer_id_index.sql @@ -0,0 +1 @@ +create index photos_offer_id on offer_photos (offer_id); diff --git a/service/src/main/resources/db.migration/V8__offers_status_index.sql b/service/src/main/resources/db.migration/V8__offers_status_index.sql new file mode 100644 index 0000000..5f928d0 --- /dev/null +++ b/service/src/main/resources/db.migration/V8__offers_status_index.sql @@ -0,0 +1 @@ +create index offers_status_idx on offers (status); diff --git a/service/src/main/scala/com/github/mmvpm/service/dao/offer/OfferDaoPostgresql.scala b/service/src/main/scala/com/github/mmvpm/service/dao/offer/OfferDaoPostgresql.scala index 13754b0..422e4b5 100644 --- a/service/src/main/scala/com/github/mmvpm/service/dao/offer/OfferDaoPostgresql.scala +++ b/service/src/main/scala/com/github/mmvpm/service/dao/offer/OfferDaoPostgresql.scala @@ -245,7 +245,7 @@ class OfferDaoPostgresql[F[_]: MonadCancelThrow](implicit val tr: Transactor[F]) select id, url, blob, telegram_id from photos join offer_photos op on photos.id = op.photo_id - where op.offer_id = $offerId + where offer_id = $offerId """ .query[PhotosEntry] .to[List]