@jialin.huang
FRONT-ENDBACK-ENDNETWORK, HTTPOS, COMPUTERCLOUD, AWS, Docker
To live is to risk it all Otherwise you are just an inert chunk of randomly assembled molecules drifting wherever the Universe blows you

© 2024 jialin00.com

Original content since 2022

back
RSS

MySQL — InnoDB vs. MyISAM

TL;DR

featInnoDBMyISAM
Locking Mechanismrow/record leveltable level
Transaction SupportACID compliantNo transaction support
Foreign Keys
Crash Recoveryautomanual
BufferBuffer pool for data & indexKey buffer for index only
Performance FocusWrite-intensive workloadsRead-intensive workloads
Fit forHigh concurrency, write-intensive needs; ideal for new projectsLarge-scale read operations; suitable for projects with existing large datasets

Choose InnoDB when

  1. You need transaction support
  1. High concurrency for both read/write
  1. Foreign key constraints required
  1. Automatic crash recovery important
  1. lock on specific row/record.

For example, update and insert operations:

BEGIN;
UPDATE inventory SET quantity = quantity - 1 WHERE item_id = 5;
INSERT INTO orders (item_id, user_id) VALUES (5, 101);
COMMIT;

Choose MyISAM when

  1. Read-heavy workloads
  1. Simple data structures
  1. Full-text indexing needed (in older MySQL versions)
  1. Server resources are limited
  1. lock whole table

For example, simple aggregation queries:

SELECT category, COUNT(*) 
FROM log_entries 
GROUP BY category;

Just like SSD and HDD

MyISAM does not restrict sequential or non-sequential reads, which can be advantageous for read-heavy operations. However, in scenarios with frequent write and update operations, MyISAM's performance may degrade, similar to how an HDD struggles with non-sequential reads when data becomes fragmented.

InnoDB uses a clustered index which keeps related data close together. This can improve performance for both sequential and non-sequential operations, especially in write-intensive scenarios.

https://stackoverflow.com/questions/15678406/when-to-use-myisam-and-innodb

EOF