开发者

Delete MySql Records older than a half hour or 1800 seconds?

The current MYSQL Is

DELETE FROM `sessions` WHERE `expires` < UNIX_TIMESTAMP();

Not sure how i would make it do what i want to do. I was thinking of using php and doing unixtime-1800 and then using that in the MySQL, which would be okay for my app. Not sure if you can do it all in MySQ开发者_StackOverflowL becuase i'm just wondering.

The PHP i had would be somthing like this

<?Php
$time = time() - 1800;
mysql_query("DELETE FROM `sessions` WHERE `expires` < $time;")
?>


Just substract the number of seconds you want

DELETE FROM `sessions` WHERE `expires` < (UNIX_TIMESTAMP() - 1800);

How often do you plan on running this query ?


You can simply do :

DELETE FROM `sessions` WHERE `expires` < (UNIX_TIMESTAMP() - 1800);


That approach will cause huge performance degradations on the high-loaded system. The very first proposal is to create a new table every half an hour and flush older tables by some logic.

Edit: OK, maybe not so huge degradations with half-an-hour GC, but it's a bad design generally.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜