I have a MySQL 5.7 table that holds activities that users can search through. It will end up holding less than 100,000 rows and inserts will be less than 50/day. This activities
table has a structure of:
CREATE TABLE activities (
activityID int AUTO_INCREMENT,
createdBy char, -- a unique AWS ID. eg: "us-east-1:128d0a74-c82f-4553-916d-90053e4a8b0f"
active bool,
city varchar,
length int,
price decimal,
latitude decimal,
longitude decimal,
CONSTRAINT Activities_PK PRIMARY KEY (activityID)
);
The queries I will be making are constructed depending on the query string sent to the API endpoint. There are 3 'paths' the API can be searched by to return activities.
- If
createdBY
is included the query string,Select ... where createdBy = ~some id~
- If
city
is included, Select bycity
, andlength
if included, and mininmumprice
if included, and maximumprice
if included - If
latitude
andlongitude
are included, search between the 2 points
Indexes I have come up with so far:
createdBy
, as a B-Tree. Should this be a HASH index because it's a unique identifier?(city, length, price)
. Since this is a covering index, if the constructed Select query is only searching bycity
, would it still use the index even though it containslength
andprice
?Also, since covering indexes start on the left, should I also include a
(city, price, length)
index?(latitude, longitude)
Are these acceptable indexes? Should I include an index for the active column? All queries should only return active activities. My guess will be ~90% of rows would be active, while ~10% would be inactive. This answer suggests no.
Thanks so much! Any other suggestions are welcome!