When it comes to writing custom MySQL database-driven PHP session management for a VERY dynamic website, what is the best (fastest read/write access) structure for your session table?
Bad Example (Not Optimized):
CREATE TABLE `session` ( `session_id` VARCHAR(32) NOT NULL, `session_data` TEXT NOT NULL, `t_created` DATETIME NOT NULL, `t_updated` DATETIME NOT NULL, PRIMARY KEY (`session_id`) ) ENGINE=INNODB DEFAULT CHARSET=utf8;
I assume that using the Memory Engine would be better/faster, but I'm not sure. I can't think of a good way to explain everything in English, so I've made a list of requirements/details that I think are important:
Details:
- Category: Optimization
- Sub Category: MySQL Query Performance
- Goal: Fastest Random Access Table Schema and Single Row Query
- Common Uses: Custom Session Management, Temporary Storage
- Operating System: *nix, more specifically: Centos 5+ (on x86_64)
- Database: MySQL Version: 5+ (Community Version)
Outcomes:
- SQL Query: Create Table
- SQL Query: Select Single Row by Random Key (e.g. PHP session id)
- SQL Query: Insert Single Row with Random Key (e.g. PHP session id)
- SQL Query: Update Single Row by Random Key (e.g. session id)
- SQL Query: Delete Multiple Rows by Timestamp (garbage collection, e.g. expired sessions)
Expected Row Lifespan (e.g. session durations):
- 30%: 0s-30s
- 20%: 30s-5m
- 30%: 5m-1h
- 20%: 1h-8h
Expected Row Count (e.g. active sessions):
- Low: 128
- Medium: 1024
- High: 100000
If anyone can think of a better way to phrase all this, please feel free to edit.