mbari-org / vars-annotation

Video Annotation Application for MBARI's Media Management (M3) software stack
https://docs.mbari.org/vars-annotation/
Apache License 2.0
16 stars 6 forks source link

Add indexes to deepsea-ai/M3_EVENT_TRACKS database. #145

Closed hohonuuli closed 1 year ago

hohonuuli commented 1 year ago

Currently there are only indices on the primary keys. The Event table had 91 million rows, so definitely needed.

cc: @danellecline

danellecline commented 1 year ago

Whoa. Thanks for looking into that. Fingers crossed this will help

hohonuuli commented 1 year ago

Attempting to add the following but it's running slooooooooow (Edit. It took 3 minutes to add the index)

CREATE INDEX Event_track_uuid_index
   ON dbo.Event (track_uuid)
GO
hohonuuli commented 1 year ago

@danellecline The indexes will make a huge difference. I'll add them to any column that is used for search (e.g. Event.media_id, Event.class_id, etc).

hohonuuli commented 1 year ago

Adding

create index Event_media_id_index
    on dbo.Event (media_id)
go
hohonuuli commented 1 year ago

Media table:

create index Media_job_id_index
    on dbo.Media (job_id)
go

create index Media_uuid_index
    on dbo.Media (uuid)
go
hohonuuli commented 1 year ago

Running the following still took 45 seconds. Look at views to see how they are constructed ...

select
    *
from
    Track
where
    media_id = 44
hohonuuli commented 1 year ago

Running SELECT * FROM Event WHERE media_id = 44 returns 53100 records in 741ms

hohonuuli commented 1 year ago

Additional indices could be created on Job and User but they're so small I'm skipping.