Re: Implementing an history with a limited number of entries with MySQL
Salvatore Sanfilippo wrote:
> On May 12, 11:32 am, "Paul Lautman" <paul.laut...@btinternet.com>
> wrote:
>
>> Here's another way to think about it. Once you have 10000 rows, then
>> every time you insert a new row, you can just delete the oldest one.
>> So, if you're using MyISAM, you can check the result of SHOW TABLE
>> STATUS and if it is 10000 then insert your row and delete the oldest
>> one.
>
> Hello Paul,
>
> yes this can work as far as there is a way to make "delete the oldest
> one"
> very fast. AFAIK the faster I can get is:
>
> row = SELECT MIN(time) FROM history WHERE customer_id=$mycustomer
> DELETE FROM row WHERE time=row[0];
>
> I wonder if there are faster ways.
>
> Regards,
> Salvatore
I find the "Strawberry Query" for finding the row with the minimum value
(LEFT (self)JOIN and NULL test), many times faster than the MIN() approach.
|