Mysql optimization

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
CarmeloLabadie

Mysql optimization

Post by CarmeloLabadie » 02 Jun 2021, 04:04

I have this mysql table called comments which looks like this:

commentID parentID type userID date comment
The commentID is set as Primary key, but most of the time I fetch the data using the parentID. How should I set my indexes?

Should I just add an index on parentID and let commentID be the primary key?

Edit: Would it be bad to have 3 indexes? For example on a forum table which has a categoryID boardID and topicID?

User avatar
aimeos
Administrator
Posts: 8606
Joined: 01 Jan 1970, 00:00

Re: Mysql optimization

Post by aimeos » 03 Jun 2021, 08:55

CarmeloLabadie wrote: 02 Jun 2021, 04:04 Should I just add an index on parentID and let commentID be the primary key?
Yes, this should be the first step.
CarmeloLabadie wrote: 02 Jun 2021, 04:04 Edit: Would it be bad to have 3 indexes? For example on a forum table which has a categoryID boardID and topicID?
That depend on what queries you perform. If they contain categoryID, boardID and/or topicID in the WHERE clause, then it makes sense to add a multi-column index for the used columns too.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply