====== Specification ====== ===== Introduction ===== This page describes the specification of Fatworm project ===== Feature Requirements ===== ==== Baseline ==== - Data Types - **Primitive** INT, FLOAT, BOOLEAN - **Time** TIMESTAMP, DATETIME - **String** CHAR(), VARCHAR() - **Other** DECIMAL(,) - Components - Storate * Buffering - Heap File - SQL Parser and Engine - Create / Drop databases - Create / Drop tables - Insert / Delete / Update tuples in table - Basic SELECT on single or multiple table(s) - More powerful SELECT * DISTINCT * Alias of tables * [NOT] EXISTS * ORDER BY can accept more than one column * GROUP BY / HAVING clauses - Functionality - JDBC Interface - Standalone Driver ==== Advance ==== - Components - B+ Tree - Basic B+ Tree Index support - Balanced deleting - Duplicated key support - VARCHAR index - More powerful SQL - Create / Drop indexes (only involved with single column) - Powerful SELECT - Subquery as Scalar Operand - Subquery as Relation Operand (ANY, ALL, IN) - Subquery in FROM clause, see Syntax - More complex INSERT: Insert subquery - Database manager - More than one database in system - Concurrency control (locks on table) - Concurrency control (locks on pages) - Functionality: - Support transaction - Logger and roll back - Supplementary Specifi cation - Syntax - STRING & DATE - Any CHAR, VARCHAR, DATETIME or TIMESTAMP starts and ends with a '. - AUTO_INCREMENT - One table can have one column to be AUTO_INCREMENT, and this column MUST BE the PRIMARY KEY. - AUTO INCREMENT column MUST BE INT. - When inserting a row, value in AUTO_INCREMENT eld CAN be a value given. If no value were given, the value should be (MAX(this column)+1).If the value were not given and no row were in table, the value should be 1. - Of couse, AUTO_INCREMENT column CAN BE updated. - INSERT - If user used INSERT INTO table name VALUES (...), ALL elds should be speci ed. - The Default value will be used, only when user uses INSERT INTO table name(...) VALUES (...). - TIMESTAMP - When inserting or updateing, if the value of this eld were not given,it means current time. ==== Some Clari cation ==== - It's free for your team to decide which programming language to use, but the test case is totally based on the JDBC interface, so we strongly recommend Java as your programming language. - You should code very thing by yourself. However, taking advantage of some code-generation tool like JFLEX or JavaCup is allowed and encouraged. - It's NOT required to do arithmetic operation on DECIMAL column. In addition, you can set arbitrary restrict on CHAR(), DECIMAL() and VARCHAR(), as long as it's reasonable. For example, the length of VARCHAR can't exceed 4000. You should also write these restrict in document. - You are allowed to keep metadata of table / database (or something like that) in memory (outside bu er), since they are not very big. What you have to load into bu er are records (in heap le) and B+ trees. ===== Syntax of FwSQL ===== Note: the syntax of FwSQL(Fatworm-SQL)is a simplified version of MySQL. Please go to http://dev.mysql.com/doc/ for more details. - Create or Drop Database *CREATE DATABASE //db-name// *USE //db-name// *DROP DATABASE //db-name// - Create or Drop table *CREATE TABLE //tbl-name// (//create-definition//, ...) *DROP TABLE //tbl-name// [,//tbl-name//] *//create-definition// ::= //column-definition// | PRIMARY KEY (//col-name//) *//column-definition// ::= //col-name// //data-type// [[NOT]NULL] [DEFAULT //const-value//][AUTO_INCREMENT] *//data-type// ::= INT | FLOAT | CHAR(M) | DATETIME | BOOLEAN | DECIMAL(M[,D]) | TIMESTAMP | VARCHAR(M) -Insert *INSERT INTO //tbl-name// VALUES (//value//, ...) *INSERT INTO //tbl-name//(//col-name//,...)VALUES(//value//,...) *INSERT INTO //tbl-name//(//subquery//) -Delete *DELETE FROM //tbl-name// [WHERE //where-condition//] -Update *UPDATE //tbl-name// SET //col-name1//=//value// [,//col-name2//=//value//...][WHERE //where-condition//] - Create or Drop index *CREATE [UNIQUE] INDEX //index-name// ON //tbl-name// (//col-name//) *DROP INDEX //index-name// ON //tbl-name// - Select *SELECT [DISTINCT] //select-expr//,...\\ [FROM //tbl-ref//[,//tbl-ref//]...]\\ [WHERE //where-condition//]\\ [GROUP BY //col-name//]\\ [HAVING //having-condition//]\\ [ORDER BY col-name[ ASC | DESC ],...] *//select-expr// ::=//value// [AS //alias//]|* *//func// ::= AVG | COUNT | MIN | MAX | SUM *//col-name// ::= [tbl-name.] //col-name// *//tbl-ref// ::=//tbl-name//[AS //alias//]\\ |(//subquery//) AS //alias// *//where-condition//::=//bool-expr// *//bool-expr// ::=//value cop value// \\ | //bool-expr// AND //bool-expr// \\ | //bool-expr// OR //bool-expr// \\ | [NOT] EXISTS (//subquery//)\\ | //value cop// ANY (//subquery//) \\ | //value// IN (//subquery//) \\ | //value cop// ALL (//subquery//) \\ | (//bool-expr//) *//cop// ::= < | > | = | ''''<''='' | >= | <> *//value// ::= (//value//)|//col-name//|//const-value//|//value aop value// \\ | (subquery with only one elements(or NULL)in the result table)\\ | //func//(//col-name//) *//aop// ::= + | - | * | / | % *//const-value// ::= //integer// | //'string'// | //float// | 'YYYY-MM-DD HH:MM:SS' | TRUE | FALSE | NULL | DEFAULT *//having-condition// ::= //bool-expr// ===== Misc ===== **Version** 4.1 **Date Created** 2012-2-25 **Authors** * 02-ACMer * Li Lei * Yang Linji * Zhang Yaodong * 03-ACMer * Ma Rong * Zhou Muxin * Qian Feng * Qu Wentao * 04-ACMer * Li Mu * Lian Xiaochen * Sun Xiaorui * 05-ACMer * Han Wei * Tian Yuan * Zhang Kang * 06-ACMer * Chen Xiangru * Chen Tianqi * Zhu Yihe * 07-ACMer * Sheng Meilun * Wu Chenyang * 08-ACMer * Wu Yangwei * Sun Ruihua * Pan Ye