Skip to content

Commit d0ac9cc

Browse files
committed
more commentary
1 parent 56cc7fe commit d0ac9cc

File tree

5 files changed

+45
-14
lines changed

5 files changed

+45
-14
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,32 @@ drop database DATABASE_NAME
6262
show tables;
6363
```
6464

65+
## Terminology
66+
67+
- file := the database file
68+
- file header := the header in the database file
69+
- table tree := the B+ tree designed to represent a table
70+
- index tree := the B+ tree designed to represent an index
71+
6572
## Spec
6673

6774
### Database File Format
6875

6976
The database file format mimicked that of SQLite but with some differences.
7077

78+
Differences:
79+
80+
- the file headers omits many fields.
81+
- Index tree is also implemented with B+ tree, not B tree.
82+
- Index tree utilizes `InternalTableCell` and `LeafTableCell` rather than `InternalIndexCell` and `LeafIndexCell`. In order words, index trees have the same architecture as table trees.
83+
- Index tree could only support dropping and inserting along with the table tree but not deleting due to complicity (implemented in `DatabaseController`).
84+
- The `key` field of the table cells is implemented with type `DBRecord`, not `int`.
85+
86+
Learn more from:
87+
88+
- with graph - <http://chi.cs.uchicago.edu/chidb/fileformat.html>
89+
- official - <https://www.sqlite.org/fileformat.html>
90+
7191
### 数据类型
7292

7393
只要求支持三种基本数据类型:int,char(n),float,其中char(n)满足 1 <= n <= 255 。

src/MiniSQL.BufferManager/Controllers/FreeList.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace MiniSQL.BufferManager.Controllers
55
{
6-
// a link list recording all free pages
6+
// a linked list recording all free pages
77
public class FreeList
88
{
99
private readonly Pager _pager;

src/MiniSQL.BufferManager/Models/FreeListTruck.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
namespace MiniSQL.BufferManager.Models
44
{
5+
// To keep MemoryPage intact with new functionality,
6+
// FreeListTruck here is to wrap up the MemoryPage.
7+
// a minimal unit in the FreeList
58
public class FreeListTruck
69
{
710
private readonly MemoryPage _page;

src/MiniSQL.Client/Controllers/View.cs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Diagnostics;
44
using System.Text;
55
using System.Text.RegularExpressions;
6+
using MiniSQL.Client.Helpers;
67
using MiniSQL.Library.Exceptions;
78
using MiniSQL.Library.Interfaces;
89
using MiniSQL.Library.Models;
@@ -162,7 +163,7 @@ private static void PrintRows(SelectResult result)
162163
string format = "{0, " + (-sizes[columnIndex]).ToString() + "}";
163164
Console.Write($" {string.Format(format, name.AttributeName)} ");
164165
if (columnIndex < result.ColumnDeclarations.Count - 1)
165-
Print("|", ConsoleColor.DarkGray);
166+
PrintHelper.Print("|", ConsoleColor.DarkGray);
166167
columnIndex++;
167168
}
168169
Console.WriteLine();
@@ -192,7 +193,7 @@ private static void PrintRows(SelectResult result)
192193
}
193194
Console.Write($" {string.Format(format, stringToPrint)} ");
194195
if (columnIndex < row.Count - 1)
195-
Print("|", ConsoleColor.DarkGray);
196+
PrintHelper.Print("|", ConsoleColor.DarkGray);
196197
columnIndex++;
197198
}
198199
Console.WriteLine();
@@ -236,16 +237,5 @@ private static List<int> GetColumnSize(SelectResult result)
236237
}
237238
return sizes;
238239
}
239-
240-
private static void Print(string toPrint, ConsoleColor color)
241-
{
242-
// change color
243-
ConsoleColor defaultColor = Console.ForegroundColor;
244-
Console.ForegroundColor = color;
245-
// print
246-
Console.Write(toPrint);
247-
// restore the previous color
248-
Console.ForegroundColor = defaultColor;
249-
}
250240
}
251241
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
3+
namespace MiniSQL.Client.Helpers
4+
{
5+
public static class PrintHelper
6+
{
7+
public static void Print(string toPrint, ConsoleColor color)
8+
{
9+
// change color
10+
ConsoleColor defaultColor = Console.ForegroundColor;
11+
Console.ForegroundColor = color;
12+
// print
13+
Console.Write(toPrint);
14+
// restore the previous color
15+
Console.ForegroundColor = defaultColor;
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)