Posted By

Eloi on 05/05/09


Tagged

mysql sessions performance ip inetaton inetntoa


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

Eloi
kubaitis
virendrakryadav


Create Table Sessions


 / Published in: MySQL
 

Saving the IP as Int we save a lot of space and permit do beautibul selects

  1. CREATE TABLE Sessions (
  2. session_id INT UNSIGNED NOT NULL AUTOINCREMENT,
  3. ip_address INT UNSIGNED NOT NULL,
  4. session_data TEXT NOT NULL,
  5. PRIMARY KEY (session_id),
  6. INDEX (ip_address)
  7. ) ENGINE=INNODB
  8.  
  9. // INSERT a new dummy record
  10. INSERT INTO Sessions VALUES (NULL, INET_ATON('192.168.0.2'), 'some session data');
  11.  
  12. //Find all sessions coming FROM a local subnet
  13. SELECT
  14. sessin_id,
  15. ip_address as ip_raw,
  16. INET_NTOA(ip_address) as ip,
  17. session_data
  18. FROM Sessions
  19. WHERE ip_address
  20. BETWEEN INET_ATON('192.168.0.1')
  21. AND INET_ATON('192.168.0.255')

Report this snippet  

You need to login to post a comment.