开发者

Oracle Transaction - Count table

开发者 https://www.devze.com 2023-04-05 05:28 出处:网络
I have a table where I need to constrain by category and then find all overlapping dates against some date range.This takes about 2 seconds, which is unacceptable to do on every transaction which occu

I have a table where I need to constrain by category and then find all overlapping dates against some date range. This takes about 2 seconds, which is unacceptable to do on every transaction which occurs at roughly 50/s. The alternative is to create some tally table -- then again, I don't know how great of an idea this is because things can get out of sync.

Date on Rent   # Rented   Category
9/5/2011       5          CATEGORY1

In Oracle (PL/SQL, if it matters), how can I maintain this performance, but ensure that concurrent transactions don't screw up the increment / decrement by making it one less or one more than it really is?

I have two types of transactions, kind of like a search and a rent. Only rents will be updating this tally table (and searches just reading from it). I don't mind if rents slow down, but do not want se开发者_如何转开发arch performance impacted. Rents can occur as frequently as 5-10 / second.


Oracle uses locks to ensure data consistency during a query. The details of how they work can get complex, but the effect is that it guarantees that an update/insert to your tally table will only use the data in the main table as it was when the query began. If there is another update or insert to your main table while you are doing an update/insert to the tally table, it won't affect it.

You'll have to experiment with your data to see if keeping a summary/tally table helps or hurts you. It really depends on how quickly the main table is getting updated, how much time you spend updating your tally table vs how much time you save by being able to select on it, and how up-to-date you need selects to be.

0

精彩评论

暂无评论...
验证码 换一张
取 消