How's it going. I'm hoping that this isn't considered to be a duplicate of... mysql two column primary key with auto-increment
My question is a little different though as I am not trying to reference a different database.
I would just like to know the most 'performant' way to go about this...
I want to have a comments table that has say page_id as the primary key
, but I still want to have an auto increment id associated with each row so I can address them by id when updating or deleting them. As of now my table is structured as follows
id INT(8) NOT NULL AUTO_INCREMENT,
page_id INT(5) NOT NULL,
comment VARCHAR(2500) NOT NULL,
PRIMARY KEY (id)
And my queries look like....
SELECT comment FROM comments WHERE page_id = '$page_id' AND id >= $start_at_id
I've been watching a bunch of MySQL optimization videos and I keep hearing index on the left, but my problem is that I am most of the way blind so I can't see their code examples. Here my screen reader will make all of that possible. My question is this. Would it be better to set my table up like...
page_id INT(5) NOT NULL,
id INT(8) NOT NULL AUTO_INCREMENT,
comment VARCHAR(2500) NOT NULL,
PRIMARY KEY (page_id)
And if so... What would be a better way to structure the query. Keep in mind that "start_at_id" is 0 unless it's a pagination page. I'm using the default engine for mysql 5.6 which I believe is my (pardon my spelling) isam???
Thanks in advance.