com.quadcap.sql |
SQL Database engine. Various design related information follows.
Tuples and Columns
public interface Tuple {
public int numColumns();
public Column getColumn(int i);
}
public interface Column {
public String getName();
public Type getType();
public boolean isFixed();
public int getOffset();
public int getLength();
public Enumeration getConstraints();
}
public interface Table extends Tuple {
public int numRows();
public Row getRow(int i);
public Enumeration getConstraints();
public Constraint getPrimaryKeyConstraint();
}
public interface Row extends Tuple {
public Row(Tuple def, byte[] bytes);
}
public interface Index {
public Tuple getBaseType();
/**
* Return an enumeration of the keys of this index, in order, starting
* with the first index value not less than first
*/
public Enumeration enumerate(TupleValue first);
/**
* Return an enumeration of the keys of this index, in reverse order,
* starting with the first index value not greater than last
*/
public Enumeration reverseEnumerate(TupleValue last);
}
public interface Type {
public String getTypeName();
public int compare(Type other);
public void setBytes(byte[] buf, int offset, int cnt);
public byte[] getBytes();
public Object getObject();
public void setObject(Object obj);
}
public interface Constraint {
public Tuple get
}
public interface PrimaryKeyConstraint extends Constraint {
}
public interface ForeignKeyConstraint extends Constraint {
}
public interface UniqueConstraint extends Constraint {
}
Inheritance Tree for Tuple and Cursor
interface Tuple // columns, qualifier
class TupleImpl
interface Cursor extends Tuple // rows and movement
abstract class CursorImpl extends TupleImpl implements Cursor
class JoinCursor extends CursorImpl
interface Relation extends Tuple // constraints, cursor mgmt
class View extends TupleImpl implements Relation
class Table extends TupleImpl implements Relation
Cursor
CursorImpl
Filter
Aggregate
Distinct
GroupBy
Having
Predicate
Index
Items
JoinCross
JoinInner
Merge
OrderBy
Static
View
Table Expressions:
Updatable
SelectFromTable
NonUpdatable
JoinedTable
MergeExpression
VectorExpression (table value constructor)
Possibly updatable
SelectFromItem
TreeNode
ClassOrInterfaceDef
ClassDef
interfaceDef
Decl
VariableDecl
MethodDecl
InnerClassDecl
StaticBlockDecl
Literal
Logging and recovery
Write-ahead logging
Log entries:
redo
undo
redo/undo
CLR written when performing partial rollback
begintransaction
commit
checkpoint
Recovery: redo, then undo
Restore from last checkpoint.
Redo all records from that point to the end of the log.
Undo all loser transactions.
Checkpoint:
Periodically, or at connection close, take checkpoint.
Copy entire datafile
Can optimize with 'modified pages' bitmap
Compress log.
Only save log records for pending uncommited transactions.
Join operations:
Break where clause down into "exp AND exp AND ..." form.
For each expression, classify it as one of:
- table vs table (t1.fld == t2.fld)
- table vs const (t1.fld == val)
All tables that don't appear in table vs table expressions go first in
the join order.
Tables that don't have any constant expressions go last in the join order.
All tables are joined using nested loops joins.
Join over columns
Natural (inner, left, right, full), Union
Using : inner, left, right, full
Join on expression
Cross
On : inner, left, right, full
Stmt.execute(Session)
- SelectStmt
- StmtAddColumn
- StmtAddConstraint
- StmtAlterColumn
- StmtCreateIndex
- StmtCreateSchema
- StmtCreateTable
- StmtCreateView
- StmtDelete
- StmtDropConstraint
- StmtDropIndex
- StmtDropTable
- StmtInsert
- StmtNull
- StmtUpdate
Session.doStep(LogStep)
- AddColumn
- AddConstraint
- AddTable
- AlterColumn
- DeleteConstraint
- DeleteRow
- DropTable
- InsertBlob
- InsertRow
- ModIndexEntry
- UpdateRow
- StmtCreateView
LogStep.redo(Session)
Random stress testing
Dimensions
1. Number of tables
2. Number of columns
3. Datatypes
4. Field sizes
5. Integrity violations, statement rollback
6. Transaction rollback
7. Views
8. Join, union, intersection, subquery,
|
Java Source File Name | Type | Comment |
AddColumn.java | Class | Log step to add a column to a table, supplying default values as necessary. |
AddConstraint.java | Class | Log step to add a constraint to a table. |
AddIndexEntry.java | Class | Log step to add a entry to an index. |
AddTable.java | Class | Log step to add a table to a database. |
AggregateCursor.java | Class | Used in conjunction with a GroupByCursor to handle
aggregate functions (e.g., SUM, AVG, etc.) with
a GROUP BY clause. |
AggregateExpression.java | Class | Expression implementing one of AVG, SUM,
MIN, or MAX. |
AlterColumn.java | Class | Log Step to alter the definition of a table column. |
Analyze.java | Class | Join planner. |
AutoNumberConstraint.java | Class | Constraint class for SQL AUTO_NUMBER constraints. |
AutoNumberStep.java | Class | Log step to record allocations of auto numbers... |
Backup.java | Interface | The "Back me up" hook, implemented external to this package. |
BC_Cursor.java | Class | Cursor that implements the DISTINCT modifier by creating
temporary table, where the entire row is used as the index key. |
BinaryExpression.java | Class | Expression class for all binary ops. |
CheckConstraint.java | Class | Constraint class for SQL CHECK constraints. |
Column.java | Class | A column lives in a tuple, has a name, a type, and a default value. |
Connection.java | Class | Analagous (and mapped onto) a JDBC Connection , this class
maintains state and locks on behalf of a single session. |
Constraint.java | Class | A constraint is a condition which must be satisfied relative to
the rows of a table. |
Cursor.java | Interface | The base cursor interface. |
CursorImpl.java | Class | Base cursor implementation class. |
Database.java | Class | This class implements the QED SQL database outer API. |
DatabaseRoot.java | Class | The persistent root block of the database. |
DbException.java | Class | |
DbRuntimeException.java | Class | A kind of runtime exception that we can throw. |
DefaultTableConstraint.java | Class | If a table has no other constraints (e.g., primary key, unique), we
synthesize this constraint to force the creation of an index, since
the table traversal code depends on having an index to iterate. |
DeleteConstraint.java | Class | Log step to remove a table constraint. |
DeletedRows.java | Class | StatementContext which manages delete operations generated by a
statement, defers those operations so consistency can be checked,
and at the end of the statement's execution, performs all of the
deletes. |
DeleteIndexEntry.java | Class | Log step to delete an index entry. |
DeleteRow.java | Class | Log step to delete a row from a table. |
DistinctCursor.java | Class | Cursor that implements the DISTINCT modifier by creating
temporary table, where the entire row is used as the index key. |
DropColumn.java | Class | Log step to add a column to a table, supplying default values as necessary. |
DropTable.java | Class | Log step to remove a table from a database. |
ExportedKeyConstraint.java | Class | A hidden 'ExportedKeyConstraint' is created for tables that
are referenced as foreign keys by other tables. |
ExportedKeys.java | Class | A statement context which keeps track of the set of changes to the
keys in a foreign-key constraint during the statement execution. |
Expression.java | Class | Base class for all expression types. |
ExpressionVisitor.java | Interface | Expression tree visitor. |
FilterCursor.java | Class | Base class for all filter cursor types. |
ForeignKeyConstraint.java | Class | Abstract base class for imported and exported key constraints. |
Function.java | Interface | An SQL function, defined as the value resulting from some function on
a row. |
FunctionExpression.java | Class | Implement function expressions. |
GroupByCursor.java | Class | Cursor to support SQL GROUP BY. |
HavingCursor.java | Class | Cursor to support HAVING clause. |
ImportedKeyConstraint.java | Class | |
IndexConstraint.java | Class | Base class for all index constraints. |
IndexCursor.java | Class | Cursor for iterating an index. |
InExpression.java | Class | Expression implementing IN (list). |
InsertBlob.java | Class | Log step to insert a BLOB value into the database. |
InsertRow.java | Class | Log step to insert a row into a table. |
ItemsCursor.java | Class | This cursor performs the name-mapping function associated with the
SELECT clause. |
ItemsRow.java | Class | Part of the 'ItemCursor' implementation, this implements a row that
is a mapped Essentially, a vector with one-based indices. |
JdbcEscapeTokenStream.java | Class | Handle JDBC escape processing as a token stream. |
JoinCrossCursor.java | Class | |
JoinCrossRow.java | Class | A row containing a cross-join, all columns from each of two cursors. |
JoinCursor.java | Class | |
JoinedTable.java | Class | A table expression representing a single join operation. |
JoinInnerCursor.java | Class | |
JoinMapRow.java | Class | A row containing a cross-join, all columns from each of two cursors. |
JoinNaturalRow.java | Class | A row containing a natural join, all columns from each of two cursors,
with only one instance of the join columns. |
JoinUnionCursor.java | Class | Half of a UNION join. |
Key.java | Class | Micro-optimized (-;) key serialization and comparison. |
LazyRow.java | Class | A row that we deserialize only as needed to produce values. |
LogStep.java | Class | Basic unit of write-ahead logging strategy. |
MapRow.java | Class | |
MergeCursor.java | Class | Cursor implementing the SQL UNION or INTERSECTION operations. |
MergeExpression.java | Class | Table expression representing UNION or INTERSECTION
operations. |
ModIndexEntry.java | Class | Abstract log step for all operations that modify indexes. |
MultiCursor.java | Class | Cursor implementation that concatenates multiple cursors together and
makes them appear as a single cursor. |
MultiSet.java | Class | Implement a multi-valued map over a Btree. |
NameExpression.java | Class | Expression class for names (typically column or function names). |
NonUniqueIndexConstraint.java | Class | Index constraint for indexes which do not require unique values. |
NotNullConstraint.java | Class | |
OrderByCursor.java | Class | Cursor implementing the ORDER BY clause, uses a temporary table
with the order-by columns as the key, then iterates the table's index. |
OrderElement.java | Class | A parsed ORDER BY element. |
ParameterExpression.java | Class | |
PredicateCursor.java | Class | Cursor for WHERE predicates. |
PrimaryKeyConstraint.java | Class | Index constraint for PRIMARY KEYs. |
QDriver.java | Interface | An adaptor that allows us to get at the Database behind a Driver. |
QedResultSet.java | Interface | An adaptor interface that allows us to get at the cursor behind
the resultset. |
QuantifiedCompare.java | Class | Expression implemented quantified comparisons: ALL, ANY. |
RefcountBlob.java | Class | Log step to insert a BLOB value into the database. |
Relation.java | Interface | The common base class for tables and views. |
RenameCursor.java | Class | Cursor performs the name-mapping function associated with the
SELECT clause. |
Row.java | Class | Essentially, a vector with one-based indices. |
SelectExpression.java | Class | A table expression representing a SELECT clause. |
SelectFromItem.java | Class | TableExpression permitting individual tables in the SELECT
statement to be "renamed" via the AS clause.
This may be necessary
for example, in cases where a table is joined to itself. |
SelectFromTable.java | Class | Table expression implementation of TABLE table-name. |
SelectItem.java | Class | An item in a SELECT clause. |
SelectStmt.java | Class | Implementation of SQL SELECT statement. |
Session.java | Class | Analagous (and mapped onto) a JDBC Statement , this class
maintains state and locks on behalf of a single session. |
SQLLexer.java | Class | |
SQLParser.java | Class | |
SQLTokenTypes.java | Interface | |
StatementContext.java | Interface | This interface models some stateful action that is associated with
the execution of a statement, but which can't be actually performed
until the end of the statement execution. |
StaticCursor.java | Class | Cursor implementation of VALUES clause. |
Stmt.java | Interface | Abstract statement execution interface. |
StmtAddColumn.java | Class | Implementation of SQL ADD COLUMN statement. |
StmtAddConstraint.java | Class | Implementation of SQL ALTER TABLE ADD CONSTRAINT statement. |
StmtAlterColumn.java | Class | Implementation of SQL ALTER COLUMN statement. |
StmtCommit.java | Class | Implementation of the SQL COMMIT statement. |
StmtCreateIndex.java | Class | Implementation of the SQL CREATE INDEX statement. |
StmtCreateSchema.java | Class | Implementation of the SQL CREATE SCHEMA statement. |
StmtCreateTable.java | Class | Implementation of the SQL CREATE TABLE statement. |
StmtCreateView.java | Class | Implementation of the SQL CREATE VIEW statement. |
StmtDelete.java | Class | Implementation of the SQL DELETE statement. |
StmtDropColumn.java | Class | Implementation of SQL ALTER TABLE DROP COLUMN statement. |
StmtDropConstraint.java | Class | Implementation of the SQL DROP CONSTRAINT statement. |
StmtDropIndex.java | Class | Implementation of the SQL DROP INDEX statement. |
StmtDropTable.java | Class | Implementation of the SQL DROP TABLE statement. |
StmtInsert.java | Class | Implementation of the SQL INSERT statement. |
StmtNull.java | Class | Implementation of no statement whatsoever. |
StmtRenameTable.java | Class | Implementation of the SQL ALTER TABLE RENAME TO statement. |
StmtRollback.java | Class | Implementation of the SQL ROLLBACK statement. |
StmtUpdate.java | Class | Implementation of the SQL UPDATE statement. |
Table.java | Class | A single SQL base table. |
TableExpression.java | Class | Some kind of expression that yields a 'table', which can be joined or
merged or cursored. |
TableOps.java | Class | |
TempTable.java | Class | Temporary tables are Useful for several operations, including
GROUP BY,
DISTINCT,
and ORDER BY. |
TempTableMerge.java | Class | A special temp table used to implement UNION and INTERSECT
expressions. |
TernaryExpression.java | Class | |
Trace.java | Class | |
Tuple.java | Interface | A tuple is a kind of abstract datatype; it consists of an ordered list
of named columns. |
TupleImpl.java | Class | Base class for tuple implementations. |
UnaryExpression.java | Class | Expression implementing unary ops. |
UniqueConstraint.java | Class | Index constraint for indexes in which keys must be unique. |
UpdateIndex.java | Class | StatementContext which manages index update operations generated by a
statement, defers those operations so consistency can be checked,
and at the end of the statement's execution, performs all of the
updates. |
UpdateItem.java | Class | One part of a compiled UPDATE statement, including a column name and
an expression which generates a value. |
UpdateRow.java | Class | Log step to update one or more values in a table row. |
ValueExpression.java | Class | Expression yielding a constant value. |
VectorExpression.java | Class | |
Version.java | Interface | Track build numbers and build info with autogenerated code. |
View.java | Class | A SQL VIEW. |
ViewCursor.java | Class | This cursor performs the name mapping associated with the (optional)
column list of the CREATE VIEW statement. |