I have a PostgreSQL database and a table that consists of events. Those events have column end_time, which has a type timestamp (without timezone info). In my app I make frequent queries to the table, that try to select all events that happen in the future. So basically I'm doing this kind of SQL query:
SELECT * FROM events WHERE end_time >= ?::timestamp
I do not have an index on the end_time column currently. I fear that once my table row size grows larger (which it already has done quite much actually), the search query for future events will become slower? Because now the database search has to go through all rows to choose the ones that happen (or for more precisely, ends) in the future. I've used indexes before but can't say I'm the most familiar with them. I wonder if indexing the end_time column by creating the default Postgres index to it would increase the performance of the query? I don't have a real problem yet, but I don't want to wait for it to appear once the amount of data increases. Because then it's kind of too late, at least the user experience of the end application has decreased then.
I want to point out that I do use the timestamp without timezone, as my app always assumes local time and I should not need the timezone info. But I heard that it might have an effect with the indexing? Also my timestamps are not constrained in any way currently. So they could in theory be from now to the infinite future. I wonder if setting some constraints could make the indexing better? Something like the event time should be within 15 year or something?
One another option is that I would move events to another table that are in the past (archived_events). So that the table size of the events would not get too big. I could for example have a cron job that would do it regularly.
Also I heard that running analyze/explain to the database can actually improve it's performance? If this is the case, how often should I run those?
PostgreSQL version: 12.3