Why does InnoDB use gap locks and next-key locks?

In MySQL 8 with InnoDB, a transaction performs a locking read over a range of values in an indexed column. Explain the differences between a record lock, a gap lock, and a next-key lock. Which inserts can these locks block? Why would the same scenario behave differently in PostgreSQL? Assume InnoDB's default isolation level, REPEATABLE READ.

ExplainTransactions and locksSeniorBackendData Engineer