Missing Index on diagnosis_key.submission_timestamp
See original GitHub issueDisclaimer: I assume, since this application is not complete, there will change a couple of things and maybe this was already planned. This issues it at least meant as a reminder.
Current Implementation
The current Flyway migration script db/migration/postgres/V1__createTables.sql
creates only the table diagnosis_key
itself.
There are already two data base accesses to the column submission_timestamp
in DiagnosisKeyService
:
public List<DiagnosisKey> getDiagnosisKeys() {
return keyRepository.findAll(Sort.by(Sort.Direction.ASC, "submissionTimestamp"));
}
and
public void applyRetentionPolicy(int daysToRetain) {
long threshold = LocalDateTime
.ofInstant(Instant.now(), UTC)
.minusDays(daysToRetain)
.toEpochSecond(UTC) / 3600L;
keyRepository.deleteBySubmissionTimestampIsLessThanEqual(threshold);
}
Suggested Enhancement
Depending on the expected number of entries in this table (I assume it will be a lot), this will result in very slow full table scans. There should be an index added to the column submission_timestamp
.
Expected Benefits
- Much faster data base access on high load and high number of db entries.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:8 (8 by maintainers)
Top Results From Across the Web
Tune nonclustered indexes with missing index suggestions
The missing indexes feature is a lightweight tool for finding missing indexes that might significantly improve query performance.
Read more >SQL Compare reports missing index when index exists on ...
Schema Compare is reporting a missing index on table when index already exists on the database. CREATE NONCLUSTERED INDEX [IX_PaymentGateWayLog_OrderID_Created]
Read more >Show Missing Indexes when rendering query plan · Issue #3491
When rendering a SQL Server query plan the Plan visualizer does not show information about missing indexes, even if it is included in...
Read more >Do Disabled Indexes Affect Missing Index Recommendations?
It does! SQL Server asks for the index. Sure, the index exists – it even has the same name – but it's currently...
Read more >Index Analysis (including Missing Indexes) - Feature Requests
Since databasses report missing index data, it would be nice to see this in DPA so we can associate the largest wait time...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yeah, the
TestDataGeneration
class would need to be changed accordingly.I just ran the retention for ~250k keys and I guess we should add the index:
The first logging statement is misleading, as it is actually not reporting the end of the deletion task - so the actual deletion happens between both statements. That delete took 5 minutes on my machine, which is far too long.
Hi Jan!
I also agree that the index will most likely make sense here.
As for the anticipated performance gains wrt full table scans I am not 100% sure whether the optimizer would care much for the index. See Postgres Documentation - 11.4. Indexes and ORDER BY: …For a query that requires scanning a large fraction of the table, the explicit sort is likely to be faster because it requires less disk I/O due to a better-ordered access pattern. Indexes are more useful when only a few rows need be fetched…