56
1099 Why Use InterBase? Bill Todd The Database Group, Inc.

1099 Why Use InterBase? Bill Todd The Database Group, Inc

Embed Size (px)

Citation preview

Page 1: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

1099Why Use InterBase?

Bill Todd

The Database Group, Inc.

Page 2: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

Two Methods of Concurrency Control

Locking

Versioning

Page 3: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

Locking SchemesYour locks restrict other user’s access to the

locked object

Lock granularity– Database– Table– Page– Row– Index

Page 4: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

Pessimistic LockingRow is locked before you begin changing it.

Guarantees that you can commit your changes.

Locks can persist for a long time which reduces concurrency.

Larger number of locks increases load on database server.

Page 5: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

Optimistic LockingMost common method among database servers.

Lock is placed when row is updated and released when transaction commits.

Locks exist for a shorter time.

Another user can update the row while you are making changes.

Page 6: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

Optimistic Locking Example 1

John reads row and makes changes

Jane reads row and makes changes

John updates row causing lock

Jane attemps update & gets error

Page 7: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

Optimistic Locking Example 2

John reads row and makes changes

Jane reads row and makes changes

John updates row causing lock

John commits releasing lock

Jane updates row overwriting John’s changes

Jane commits releasing lock

Page 8: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

To Prevent Overwriting Changes

Use UPDATE statement with original value of all fields in WHERE clause– Does not work if only blob field is changed

Use UPDATE that includes timestamp or counter field in WHERE clause– Works for all field types

Page 9: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

Transactions

All changes within a transaction succeed or fail as a single unit

Page 10: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

Transaction Isolation Level

Your transaction’s isolation level controls when your transaction sees changes made by other transactions

Page 11: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

SQL Standard Isolation Levels

Read uncommitted

Read committed

Repeatable read

Serializable

Page 12: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

Locking & ConcurrencyRepeatable read isolation requires locks to stop

other users from updating rows you have read

Serializable requires locks to stop other users from updating rows you have read or inserting new rows

Page 13: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

Locking ExampleInventory valuation by warehouse

– User A starts valuation query– User B moves material from warehouse 1 to

warehouse 20 while user A’s query is reading warehouse 10’s records

– User A’s query counts the material twice.

Page 14: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

Solution

Use serializable isolation for the valuation query

Problem - User B cannot update rows until the valuation query ends

Page 15: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

Versioning

Each transaction gets a unique number

Each row version contains the number of the transaction that created it

Page 16: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

Versioning ExampleInventory valuation by warehouse

– User A starts valuation query– User B moves material from warehouse 1 to

warehouse 20 while user A’s query is reading warehouse 10’s records.

• Because there is an active transaction with a lower number new row versions are created for all rows that are updated

Page 17: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

Versioning Example (continued)

User A’s transaction only reads the rows that were committed at the time it started

The transaction gets the correct count

User B is not blocked

Page 18: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

Snapshot Isolation Level

Unique to InterBase

All the benefits of serializable

Does not place any locks

Does not block updates by others

Page 19: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

How Versioning Works

When a snapshot transaction starts it gets:– The next transaction number– A copy of the Transaction Inventory

Pages (TIP)

Page 20: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

The TIPShows the state of all transactions

– Active– Committed – Rolled back– Limbo

• Only occurs if a two-phase commit fails

Page 21: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

Which Row Version is Read?

The most recent version whose transaction was committed at the time the reading transaction started is the version that is read

Page 22: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

ExampleTransaction 90 reads a row with the following

versions

Tran 100 status = committed

Tran 80 status = active when reader started

Tran 60 status = rolled back

Tran 40 status = committed when reader started

Page 23: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

How Locking & Versioning Compare

A series of examples

What happens with no concurrency control

What happens with locking

What happens with versioning

Page 24: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

Example 1

Husband and wife go to two different ATM’s at the same time to withdraw money from their checking account.

Page 25: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

Ex 1 – No Concurrency

Page 26: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

Example 1 - Locking

Page 27: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

Example 1 - Versioning

Page 28: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

Ex 2 – No Concurrency

Page 29: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

Example 2 - Locking

Page 30: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

Example 2 - Versioning

Page 31: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

Ex 3 – No Concurrency

Page 32: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

Example 3 - locking

Page 33: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

Example 3 - Versioning

Page 34: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

Ex 4 – No ConcurrencySELECT with a WHERE clause

Another user inserts a row that satisfies the WHERE clause

Rerun the query and you see the new row

Page 35: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

Example 4 - Locking

Place a table lock to prevent the insert

Place an index range lock to prevent the insert

Page 36: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

Example 4 - Versioning

The insert is allowed

The second SELECT does not see the inserted row because its transaction number is higher than that of the reading transaction

Page 37: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

Example 5

John and Jane are told to make their salaries equal

Page 38: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

Ex 5 – No Concurrency

Page 39: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

Example 5 - Locking

Page 40: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

Example 5 - Versioning

Page 41: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

Example 5 – Versioning Fix

Page 42: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

How Do They Compare

Versioning provides better concurrency in most cases involving mixed reads and writes

Page 43: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

RecoveryDatabase server must roll back all active

transactions on restart after a crash

For locking database this means processing transaction log

For versioning only the TIP must be updated– Status bits for all active transactions changed

from Active to Rolled Back– Garbage collection cleans up rolled back row

versions

Page 44: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

Garbage CollectionRecord versions cause database to grow

Old versions are deleted each time a row is accessed

A sweep removes all row versions that are no longer needed

Page 45: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

InterBase FeaturesTransaction support

– Read committed isolation– Snapshot isolation

• Benefits of serializable isolation without blocking updaters

– SQL 92 entry level support with extnesions– User define functions– Cost base query optimizer

Page 46: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

InterBase FeaturesRow level locking

No lock escalation

No conversion deadlocks

Two phase commit

Multi-user and single user versions

SMP support

Hyperthreading support

Page 47: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

InterBase FeaturesTriggers

– Before– After– Old & new values available– Multiple triggers per event– Control of trigger firing order– Post events to clients from triggers

Make any view updateable with triggers

Page 48: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

InterBase FeaturesStored procedures

Temporary tables– ON COMMIT PRESERVE | DELETE– ALTER TABLE allows changing ON COMMIT

clause

Generators for incrementing keys

Null state for all data types

Declarative referential integrity

Page 49: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

InterBase FeaturesServer level security

Database level security

The levels can be mixed on a single server

On-line backup

On-line metadata changes

Instantaneous crash recovery

Replication

Page 50: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

InterBase FeaturesZero maintenance

Small disk footprint

Small memeory footprint

Does not require certified DBA

Does not require custom installer

Multi-platform support

Page 51: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

IB vs. Oracle & DB2Much less expensive

Less complex – easier to learn

Easier to deploy

Does not require highly trained DBA

Much lower resource requirements– Memory– Disk– CPU

Page 52: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

IB vs. Microsoft SQL ServerLess expensive

Less complex – easier to learn

Easier to deploy

No lock escalation

No conversion deadlocks

Does not require highly trained DBA

Lower resource requirements

Multi-platform support

Instant crash recovery

Page 53: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

IB vs. Advantage & DBISAMSnapshot isolation for stable view of data without

blocking updates

On-line backups

Shadowing

Transactions can span databases

Triggers can post events to clients

Complex views are updateable with triggers

Page 54: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

Applications Made For IBMixed long reads and updates

Embedded applications

Widely deployed applications

No on-site support

Multi-platform applications

Page 55: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

Questions?

Page 56: 1099 Why Use InterBase? Bill Todd The Database Group, Inc

Thank You

Please fill out the speaker evaluation

You can contact me further at …

[email protected]