Forum Moderators: coopster
Is it faster to do this in PHP then insert into MySQL or would MySQL be better for this task?
php does the work:
-loop over array matching and deleting
-dump left over strings into database
mysql does the work:
-php dumps whole array into database
-delete rows ending in pattern, something like: DELETE from FILES WHERE fname REGEXP 'tar\.gz$'
I've never used mysql regexp before so I'm not sure how well or how fast it is compared to just using PHP, would it be faster doing a delete like the above over several rows in mysql or just iterate over an array in PHP and unset the keys where it matched with preg_match and dump the remaining into the database? This table doesn't have an index.. I'm not even sure mysql regexp uses indexes.. does it?
The only way to know for sure would be to write your application both ways and time them to see which is faster. Any regular expressions require a bit more server resource as they fire up the regex engine.
My humble opinion is that I would rather scrub the data prior to writing it to the database as opposed to writing and then deleting. Remember that the time to delete individual records is exactly proportional to the number of indexes, too.