Re: What should be my PK?
Posted by: Rick James
Date: June 08, 2016 09:03PM

For a MyISAM-only system, key_buffer_size should be set to about 20% of available RAM.

In MyISAM, the PRIMARY KEY is no different than a UNIQUE KEY.

You have provided one query "SELECT ... WHERE URI_CM = 'constant'" -- That needs INDEX(uri_cm). If you would care to provide the other SELECTs, UPDATEs, and DELETEs, we can advise on what other indexes you might need.

That particular query operates as follows:

1. Drill down the BTree index for URI_CM (in the file book_tbl.MYI). (It might be about 5 levels deep.)
2. At the bottom will be a pointer to the row.
3. Seek into book_tbl.MYD, using that pointer as a byte offset into the file.
4. Read the record.

9 billion rows is a lot, probably a few terabytes? Much more than can be cached in RAM? So, unless you have touched that particular row 'recently', some of those 6 (5 in index + 1 in data) disk hits won't be cached. I suspect the query for some random URI_CM will take a few tens of milliseconds.

Note that I did not mention the PK in this discussion of how MySQL will find the row.

There are lots of differences if we are talking about InnoDB. The short answer is to make URI_CM the first column in the PK, and add enough columns to make the combination unique. (Then do not have INDEX(URI_CM).) I would expect 'similar' speed. The my.cnf settings would need to be different.

Options: ReplyQuote


Subject
Written By
Posted
May 18, 2016 07:39AM
May 18, 2016 09:42AM
May 18, 2016 09:50AM
May 23, 2016 04:13PM
June 04, 2016 08:53PM
June 05, 2016 11:40AM
June 07, 2016 03:52PM
June 08, 2016 08:10AM
Re: What should be my PK?
June 08, 2016 09:03PM
June 09, 2016 07:55AM
June 13, 2016 01:51AM
June 16, 2016 09:38AM
June 20, 2016 12:45AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.