Re: Optimize multiple writes on the same row
Posted by:
Rick James
Date: March 15, 2012 10:41AM
One thought...
Write an "UPDATE" TRIGGER on the 'fact' (million-row) table. It would add NEW.val - OLD.val to a sum column in another table (perhaps only 1 row). (Do all of the updates in a single UPDATE in the TRIGGER.)
Then your 'report' SQL would hit only this new table.
Write an "INSERT" TRIGGER also. It would do similar things, but also modify the 'count' field in the secondary table.
Note: Do not keep an 'average' field; instead, always recompute it (sum/count). Standard deviation can be done if you keep three totals: count, sum, and sum of squares.
Median is actually possible, but tricky.
I am assuming that the complexity of this scheme would be less costly (on performance) than repeatedly scanning a million rows.
How often do UPDATEs come in? How often for INSERTs? And DELETEs?
Subject
Views
Written By
Posted
2879
March 14, 2012 02:16PM
Re: Optimize multiple writes on the same row
1041
March 15, 2012 10:41AM
1143
March 16, 2012 05:31AM
943
March 18, 2012 10:06AM
1195
March 19, 2012 08:33AM
1181
March 20, 2012 11:32AM
1086
March 22, 2012 11:49AM
1179
March 23, 2012 11:35AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.