質問

Trying to learn mysql and having tons of other material to learn, I'm considering skipping memory tables, since they have many special characteristics to consider especially that they vanish, after server restart.
In production environments, what are they used for?

役に立ちましたか?

解決

If you are learning MySQL, skipping MEMORY storage engine is not a bad idea. InnoDB is the default storage engine and it is suitable for most cases. Only in edge cases it makes sense to use another one, and you probably shouldn't consider this option before knowing InnoDB quite well.

However, to answer your question, first let's check pro's and con's of MEMORY.

Cons:

  • You could lose your data (except for table definition).
  • No transactions, no consistency of any kind.
  • Only supports HASH indexes, so there is no optimisation for queries like WHERE col > n, ORDER BY or GROUP BY.
  • Massive usage consumes memory. No trivial way to monitor how much memory you are using for these tables.

Pros:

  • Not dramatically faster than InnoDB (in terms of latency), but still generally faster when used properly.
  • Better throughput because you don't talk to storage devices.

So the question becomes, which use cases don't suffer because of the cons and take advantage of the pro's? Well, a first obvious generic answer is, avoid all use cases where data loss is a problem. More specifically, you could consider MEMORY for:

  • Caches: all queries are point searches, data can always be reconstructed.
  • Speed up some massive insertion. You put data into a MEMORY table temporarily, do your transformations, and copy the rows to a "regular" table. But if your transformations require BTREE indexes, this is not a good option.
  • TEMPORARY tables, when you don't need BTREE indexes.
ライセンス: CC-BY-SA帰属
所属していません dba.stackexchange
scroll top