Skip to content

Commit

Permalink
forsøk på optimalisering av sql
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Kroken committed Nov 21, 2023
1 parent e20dffa commit 4bc23be
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,24 @@ class PersongrunnlagRepo(
fun finnNesteUprosesserte(): PersongrunnlagMelding.Mottatt? {
return jdbcTemplate.query(
// """select m.*, ms.statushistorikk from melding m join melding_status ms on m.id = ms.id where (ms.status->>'type' = 'Klar') or (ms.status->>'type' = 'Retry' and (ms.status->>'karanteneTil')::timestamptz < (:now)::timestamptz) fetch first row only for no key update of m skip locked""",
/*
"""select m.*, ms.statushistorikk
| from melding m
| join (select * from melding_status
| where (status->>'type' = 'Klar') or (status->>'type' = 'Retry')) ms on m.id = ms.id
| where (ms.status->>'type' = 'Klar')
| or (ms.status->>'type' = 'Retry' and (ms.status->>'karanteneTil')::timestamptz < (:now)::timestamptz)
| fetch first row only for no key update of m skip locked""".trimMargin(),
*/
""" SELECT mms.*, m.id as m_id2
| FROM (SELECT *, ms.statushistorikk, ms.status as ms_status, (ms.status->>'karanteneTil') as karanteneTil, m.id as m_id1
| FROM melding m,
| (SELECT * FROM melding_status WHERE (status->>'type' = 'Klar') OR (status->>'type' = 'Retry')) ms
| WHERE ms.id = m.id) mms,
| melding m
| WHERE karanteneTil is null or (karanteneTil)::timestamptz < (:now)::timestamptz
| AND m.id = mms.m_id1
| FETCH FIRST ROW ONLY FOR NO KEY UPDATE OF m SKIP LOCKED""".trimMargin(),
mapOf(
"now" to Instant.now(clock).toString()
),
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/db/migration/V12__indekser.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
create index godskriv_opptjening_status_1 on godskriv_opptjening_status ((status->>'type'),(status->>'karanteneTil'));

0 comments on commit 4bc23be

Please sign in to comment.