There's more than one way to do things | |
PerlMonks |
Re^3: CGI Program To Delete Old Data From MySQL Table?by erix (Prior) |
on Oct 01, 2013 at 11:19 UTC ( [id://1056466]=note: print w/replies, xml ) | Need Help?? |
I did think of including that optimization but I thought it was better (because conceptually easier) to show what I did show (the idea was to show the ease of use of the postgres interval datatype). And remember that index-retrieval is not always faster. SeqScan is better than Index-retrieval when hitting a large part of the table (like when deleting 40 out of 100 rows (or keeping 60 days out of 'hundreds' of rows as the OP mentions)). Of course there is no way to know what the distribution in the OP's table is. Indeed, for my example, it turns out seq scan is still preferred over index, with my original date data. Only if the number of deleted rows becomes small compared to the total rowcount, does Pg use the index. So yes, PostgreSQL /is/ extremely clever ;-) The index-usable statement for postgres could be:
I tweaked my little program to accept an arg1=number of created rows and an arg2=number of rows to keep.
In Section
Seekers of Perl Wisdom
|
|