Unleashing the Power of Lock-Free Reservations in Oracle 23c Database

vijay balebail
3 min readOct 29, 2023

--

Introduction:

In the realm of databases, Oracle stands as a true titan, reigning supreme in sectors where data integrity, concurrency, scalability, performance, and dependability are paramount. One of Oracle’s key strengths lies in its pioneering introduction of ACID (Atomicity, Consistency, Isolation, Durability) properties through row-level locking over five decades ago. This innovation enabled Oracle to scale seamlessly, ensuring that readers wouldn’t hinder writers.

Overcoming Bottlenecks:

However, when faced with numerous writers vying to update a single row, Oracle deftly employs semaphores and mutex locks to establish efficient locking mechanisms, maintaining data consistency. While this approach proves highly effective, it still necessitates the serialization of updates on the same row. This can lead to significant bottlenecks, especially when dealing with high levels of concurrency.

A Paradigm Shift: Lock-Free Reservations

So, what if your business application could do away with row locks altogether? Consider an online store updating product quantities before finalizing a sale. As long as the product is in stock, why slow down the purchasing experience with unnecessary serialization?

Enter Lock-Free Reservations — a game-changing feature. This innovation empowers multiple concurrent updates on a numeric column value to progress unhindered by uncommitted updates to a single row. In practical terms, this means that you can designate a numeric column as lock-free reservation-enabled.

ALTER TABLE IF EXISTS products modify (items_sold reservable);

Benefits in Action:

Internally, this translates to a more streamlined process, bypassing the typical “enq: TX — row lock contention” that arises when sessions vie for the same row and column updates. This eliminates a significant application scalability hurdle.

Consider an online merchant. Concerned about overselling a product, they can implement a CHECK CONSTRAINT, ensuring that stock levels remain above zero. This way, if stocks run low or deplete, the application will promptly notify the necessary parties for restocking.

Limitations and Guidelines:

Of course, there are some constraints to be mindful of. For instance, mixing reservable and non-reservable column updates in the same statement is not allowed. For a comprehensive understanding of the rules and restrictions, consult the Database Development Guide’s section on “Guidelines and Restrictions for Lock-Free Reservation” (Section 29.5).

Performance Comparison:

To illustrate the dramatic performance enhancements, let’s conduct a simple experiment. We’ll create a table for product information, seed it with some products, and introduce a trigger to track sales and update the quantity remaining. We also will add a CHECK constraint to ensure we don’t oversell the product. For the complete script and explanation of the example, click here.

In a head-to-head comparison, the results speak for themselves. With Lock-Free Reservations, we witness a substantial improvement in performance — five times faster in our example. This demonstrates how embracing this innovative feature can revolutionize your Oracle database experience.

In Conclusion:

Embracing Lock-Free Reservations in Oracle 23c database design marks a significant leap forward in optimizing performance and concurrency. By liberating data updates from unnecessary locks, businesses can unlock new levels of efficiency and responsiveness. As with any powerful tool, it’s essential to understand its nuances and limitations, but the potential benefits make it a compelling addition to any Oracle environment.

--

--