I know this might be a basic thing for you guys in this corner of SE but I'm having some trouble figuring out the best option for designing my DB.
I am creating a custom app where the user will be entering data into a table(lets call this table "manifest") at least 1 entry every minute, each entry will have data grabbed from the input field and when adding the new row, the current date and time is also being added to a datetime
column.
This table will later be browsed by the app users on the front end at least 4 times a week when they come to do some exporting of their previously entered data.
I expect them to a lot of ordering by date, so I was planning to do an index on the date column for the first 8 characters of the MYSQL DATE = 00/00/00
(id leave out the time portion).
From what I know about indexes is that they slow down inserting and updating of data because the index needs to be rebuilt every time new data is entered.
This sounds like it would be inefficient to create an index(other than the primary key[id]) if the users will be inputting data at least once a minute for maybe 2 hours straight(per day) and the index would have to be rebuilt every minute(?) new data comes in.
I know this table would just keep growing because they need to keep track of the records for years on end, that's why I'd want to put an index on the date column to make it future proof in terms of speed. But the fact that they'd be inputting data into it so frequently and indexes would have to be rebuilt every time has me a little lost on how to proceed.
I was thinking a non-clustered index would solve the issue? I've watched several videos explaining the two and it seems that the rebuilding would still need to take place for non-clustered indexes?
Any help and performance tips would be appreciated
Best Answer
About PRIMARY KEYs:
PRIMARY KEY
.In your question:
INSERT
per minute is very slow. (So, no performance concerns here, regardless of the indexes on the table, regardless of anything else.)SELECT
) or "archive" (SELECT
, thenDELETE
)?? (More details, please.)DATE
part? If not, then make it aTIME
column. If you want to "extract" just the time (from aDATETIME
, see theTIME()
function.SELECTs
, but not others. Show us the selects so we can recommend a set of indexes that would be optimal for those selects.