fix: improve performance on db insert (#1649)

This commit is contained in:
Livio Amstutz 2021-04-22 17:06:23 +02:00 committed by GitHub
parent 9d778fa67c
commit 06281b5ccb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 3 deletions

View File

@ -37,10 +37,9 @@ const (
//previous_data selects the needed data of the latest event of the aggregate
// and buffers it (crdb inmemory)
" WITH previous_data AS (" +
" SELECT MAX(event_sequence) AS seq, resource_owner " +
" SELECT event_sequence AS seq, resource_owner " +
" FROM eventstore.events " +
//TODO: remove LIMIT 1 / order by as soon as data cleaned up (only 1 resource_owner per aggregate)
" WHERE aggregate_type = $2 AND aggregate_id = $3 GROUP BY resource_owner order by seq desc LIMIT 1" +
" WHERE aggregate_type = $2 AND aggregate_id = $3 ORDER BY seq DESC LIMIT 1" +
" )" +
// defines the data to be inserted
" SELECT " +

View File

@ -0,0 +1,2 @@
use eventstore;
CREATE INDEX IF NOT EXISTS max_sequence on eventstore.events (aggregate_type, aggregate_id, event_sequence DESC);