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,
|