I'm trying to design a database schema which needs to operate on a set of data that looks like this:
Events
event_id|time|key1|key2|data
And it needs to perform queries like this efficiently:
Get all events where key1/key2 = ... and time is between ... and ...
One schema I thought of would be
Events
primary_key=event_id|key1|key2|data
Key1Lookup
primary_key=key1|sortkey=time|event_id
Key2Lookup
primary_key=key2|sortkey=time|event_id
So that my query might look like
SELECT data FROM Events, Key1Lookup WHERE key1=... AND time BETWEEN ... AND ... AND Events.event_id = Key1Lookup.event_id
or
SELECT data FROM Events, Key2Lookup WHERE key2=... AND time BETWEEN ... AND ... AND Events.event_id = Key2Lookup.event_id
Does this seem like the right key selection/query design? I'm completely new to redshift, so I really need guidance here.
Additional information: The event_id is unique. In Key1Lookup, key1 is not unique, but there are only a few repeats in Key1Lookup (think of it like a user_id in a comments table). In Key2Lookup, key2 is not unique, but there are only a few repeats in Key2Lookup (think of it like a location_id in a comments table). There are a huge number of distinct key1s, and there are a huge number of distinct key2s. I expect the distinct number of key1s to increase a lot, and I expect the distinct number of key2s to increase a lot.