Mysql. You should never neglect creating additional indexes in table.

Since I’m making statistics engine for Internet-radio ct.fm I have opportunity to play about huge selections and table optiomization.

So, here is a table where all information about channel connections is gathered: ip-address, time of connection, disconnection, conjectural geographical location of user, etc.

  1. create table ctfmstat_log(
  2. lid bigint unsigned primary key auto_increment,
  3. ip int,
  4. start int,
  5. end int,
  6. countrycode varchar(20),
  7. countryname varchar(40),
  8. region varchar(40),
  9. city varchar(40),
  10. latitude float,
  11. longitude float
  12. ) DEFAULT CHARSET=utf8;

Typical query to such table is something like “how many users has connected to channel at day n”.

  1. SELECT DATE_FORMAT(FROM_UNIXTIME(start),"%Y%m%d") as day, count(*) as counter
  2. FROM ctfmstat_log
  3. WHERE start>1257026400 AND start<1262296800
  4. GROUP BY day ORDER BY day;

I’ve used simple php-code(I don’t bring it here, not so important) that run such query cyclically 10 seconds.

Result: 80-90 fetches

So, let’s change table a little…

  1. create table ctfmstat_log(
  2. lid bigint unsigned primary key auto_increment,
  3. ip int,
  4. start int,
  5. end int,
  6. countrycode varchar(20),
  7. countryname varchar(40),
  8. region varchar(40),
  9. city varchar(40),
  10. latitude float,
  11. longitude float,
  12. index (start)
  13. ) DEFAULT CHARSET=utf8;

And here is a result: 8000-8500 fetches!

Fill the difference!

Comments

Hi there, I dont know if I am writing in a proper board but I have got a problem with activation, link i receive in email is not working... http://iflamberg.net/?b416723904a2e2cabf5c5197d36,

Post new comment

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.