DBDB.io The Encyclopedia of Database Systems · Est. 2017
Database of Databases

Database Entry

Derby


Derby is a lightweight embedded relational database implemented completely in Java. It is an embedded database for any Java applications.[05][06]

Source Code
https://github.com/apache/derby[02]
Country of Origin
US
Start Year
1997 [07]
Former Names
JBMS, Cloudscape, Java DB
Project Type
Open Source
Written in
Java
Supported Languages
Java
Operating System
All OS with Java VM
License
Apache v2

Database Entry

Derby


Derby is a lightweight embedded relational database implemented completely in Java. It is an embedded database for any Java applications.[05][06]

History[07][08][09]


In 1997, Cloudscape Inc., a start-up in Oakland, California, developed a database engine called JBMS, which was later renamed as Cloudscape. From 1999 to 2001, Cloudscape was acquired first by Informix Software, and by IBM, and its name was changed to IBM Cloudscape. In 2004, IBM contributed the code to the Apache Software Foundation as Derby. The Apache DB project, supported by Apache Software Foundation, aims at creating and maintaining open-sourced, high-quality databases. In 2005, Derby exited the incubator and became a Apache DB subproject.

Checkpoints[10]


Derby supports fuzzy checkpointing, with slight variances from the ARIES implementation. Instead of storing active transaction table and dirty page table in checkpoint, it instead stores a few timestamps, which include the checkpoint start time and the earliest start time of ongoing transaction when the checkpoint starts. For example, if transaction T1, T2 and T3 are not finished when the checkpoint starts, then the earliest start time of the three will be recorded in the checkpoint.

When it comes to recovery, the system will first find the nearest checkpoint. Using the earliest start time of ongoing transactions, it will iterate through the log and find all the active transactions and dirty pages at the checkpoint, and redo or undo accordingly.

Compression[11]


Derby does not support data compression, but it supports the function "syscs_util.syscs_compress_table" which is used to claim unused space after there is deletion of large amount of data.

Concurrency Control[12][13]


There are two scopes of locking (table-level and row-level), three types of locks (exclusive, shared and update) and four different types of transaction isolation levels. The locking strategies for different combination of scopes, lock types and isolation levels are different.

In general, although not explicitly stated, Derby implements strict two-phase locking. Exclusive locks will be held until a transaction aborts or commits; shared lock, instead, will be released after the reading of the rows finish (except for specific isolation levels) Derby also supports deadlock detection. When a deadlock is detected, the transaction that holds the least number of locks will be aborted.

Data Model[09][14][01]


Derby is a relational database that supports SQL syntax.

Foreign Keys[15]


Foreign key is implemented as one of the CONSTAINT clauses. There are two levels of CONSTAINTS, column level and table level. Foreign key constraint in a column level enforces that the values in the column must corresponds to the values in the referenced column marked as primary key or unique key. Table level constraint works similarly, but it is for multiple columns.

Insert, update or delete instructions will be rejected with a statement exception if the foreign key constraint is violated. The constraint check can be at statement execution or commit depending on the constraint mode. (IMMEDIATE or DEFERRED).

Indexes[16]


Derby implements standard B+ Tree algorithms. It stores keys in leaf pages only. The B+ Tree supports page-level latching. Derby uses only exclusive latches, not shared latches in B+ tree implementation.

Isolation Levels[17]


It supports all four level of isolations. Isolation levels only differ for SELECT statements. They behave the same for other operations.

Joins[18]


Derby provides two types of join strategies -- nested loop and hash join. Nested loop join is more preferable in most cases. Hash join is preferred when inner table values are unique and outer table have many qualifying rows. Also, when the system estimates that the amount of memory required for hash join exceeds the amount available, nested loop will be used.

Logging[19][16]


Derby implements a combination of physical and logical logging. For actions on the same page, it uses physical logging. For BTree operations, which might affect several pages, it uses physical redo and logical undo.

Query Compilation[20][21]


Derby parses the prepared statement using Javacc and generates the Java binary code directly. JIT complier is supported, so that after several executions, JIT compiler will compile it to native code for performance improvement.

Query Execution[22]


Subqueries can only be materialized if they not correlate with outer queries, and return one row. For subqueries that cannot be flattened (DISTINCT), optimization can be made on subqueries such as using Hash Join.

Query Interface[06]


SQL

Storage Architecture[23][24]


Derby mainly support on-disk database. It also provides in-memory database for testing and developing applications.

Storage Model[25]


Derby implements row-based storage model. Rows corresponds to records in data pages.

Storage Organization[26]


Derby stores data and index in containers, which has a one-to-one mapping with files. Within each container, there will be three types of pages -- header page, data page and allocation page. Data pages hold data in row order.

Stored Procedures[27]


Derby support Java stored procedures.

Views[28]


Derivative Systems
Splice Machine Splice Machine

Citations

28 sources
  1. Apache Derby apache.org
  2. GitHub - apache/derby: Mirror of Apache Derby · GitHub github.com
  3. Apache Derby: Documentation apache.org
  4. Apache Derby - Wikipedia wikipedia.org
  5. https://wiki.apache.org/db-derby/ apache.org Dead — Check Archive
  6. Apache Derby apache.org
  7. Apache Derby Project Charter apache.org
  8. Welcome to the Apache DB Project! apache.org
  9. Proposal for Derby: an Apache Database Sub-Project apache.org
  10. Derby Logging and Recovery apache.org
  11. SYSCS_UTIL.SYSCS_COMPRESS_TABLE system procedure apache.org
  12. Types and Scope of Locks in Derby Systems apache.org
  13. Derby Developer's Guide apache.org
  14. https://builds.apache.org/job/Derby-docs/lastSuccessfulBuild/artifact/trunk/out/ref/refderby.pdf apache.org Dead — Check Archive
  15. CONSTRAINT clause apache.org
  16. org.apache.derby.impl.store.access.btree apache.org
  17. Isolation levels and concurrency apache.org
  18. Join strategies apache.org
  19. Derby Logging and Recovery apache.org
  20. https://db.apache.org/derby/binaries/ApacheDerbyInternals_1_1.pdf apache.org
  21. Derby Engine Architecture Overview apache.org
  22. Tuning Derby apache.org
  23. https://builds.apache.org/job/Derby-docs/lastSuccessfulBuild/artifact/trunk/out/getstart/getstartderby.pdf apache.org Dead — Check Archive
  24. https://builds.apache.org/job/Derby-docs/lastSuccessfulBuild/artifact/trunk/out/devguide/derbydev.pdf apache.org Dead — Check Archive
  25. Derby On Disk Page Format apache.org
  26. Derby On Disk Page Format apache.org
  27. CREATE PROCEDURE statement apache.org
  28. CREATE VIEW statement apache.org
Revision #44 Last Updated: