NE-Andy
05-14-2005, 10:25 PM
I'm writing a statistic tallying script right now which needs to find running totals for 10 tables with several thousand indices (as of right now, all 2000 indices or more on each table, MySQL dump gives a 54MB .sql file and will continuously grow as time proceeds). Right now, I see two viable ways to do it, but I need to know which one is more resources intensive (IE: uses more CPU/RAM) so I can avoid doing that:
First method:
Run a CREATE TABLE with TYPE=MERGE UNION with the 10 tables, and then do a SELECT * FROM the newly created table with ORDER Value1 Desc.
Second method:
Run 10 SELECT * FROM the 10 old tables with LIMIT 100 (the amount I need) and then run a selection sort through the 1000 indices.
After either of the above process is done, data is then serialized into a long string which is dumped to another mysql server for frontend presentation. So the above can be setup into a crontab and put to execute on the lowest preformance required hour of the day.
I'm looking at it now and I realized that regardless of what I do, this process will be fairly resources intensive for small bursts when its processing (~3 seconds for the second method, have not tried the first method due to certain restrictions which I can over come if proven it'd be faster/more efficient), but optimally I would like to make it least intensive as possible. Can someone tell me which one of the two above outlined methods are more efficient? Additionally, I wouldn't mind coding anything extra for as long as it works in the most efficient manner. So if you have any other methods that I've overlooked, I'm also open for suggestions.
Thanks in advance!
First method:
Run a CREATE TABLE with TYPE=MERGE UNION with the 10 tables, and then do a SELECT * FROM the newly created table with ORDER Value1 Desc.
Second method:
Run 10 SELECT * FROM the 10 old tables with LIMIT 100 (the amount I need) and then run a selection sort through the 1000 indices.
After either of the above process is done, data is then serialized into a long string which is dumped to another mysql server for frontend presentation. So the above can be setup into a crontab and put to execute on the lowest preformance required hour of the day.
I'm looking at it now and I realized that regardless of what I do, this process will be fairly resources intensive for small bursts when its processing (~3 seconds for the second method, have not tried the first method due to certain restrictions which I can over come if proven it'd be faster/more efficient), but optimally I would like to make it least intensive as possible. Can someone tell me which one of the two above outlined methods are more efficient? Additionally, I wouldn't mind coding anything extra for as long as it works in the most efficient manner. So if you have any other methods that I've overlooked, I'm also open for suggestions.
Thanks in advance!
