Skip to content

Commit 440b5a8

Browse files
author
MPCoreDeveloper
committed
readme update
1 parent 4372f92 commit 440b5a8

File tree

3 files changed

+1328
-2
lines changed

3 files changed

+1328
-2
lines changed

README.md

Lines changed: 273 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ A lightweight, encrypted, file-based database engine for .NET 10 that supports S
66

77
**Developed by**: MPCoreDeveloper & GitHub Copilot
88
**License**: MIT License
9-
**Status**: Production Ready ✅
9+
**Status**: Production Ready ✅
10+
**Modern Features**: Generic LINQ Queries, MVCC, Columnar Storage, SIMD Aggregates 🚀
1011

1112
## Quickstart
1213

@@ -33,6 +34,273 @@ db.ExecuteSQL("INSERT INTO users VALUES (1, 'Alice')");
3334
var result = db.ExecuteSQL("SELECT * FROM users");
3435
```
3536

37+
## 🎯 Modern C# 14 Generics Features
38+
39+
SharpCoreDB has been **completely modernized** with .NET 10 and C# 14, featuring **full generics support** throughout the codebase!
40+
41+
### 1️⃣ Generic LINQ-to-SQL Queries
42+
43+
Write **type-safe** queries with compile-time checking:
44+
45+
```csharp
46+
using SharpCoreDB.Linq;
47+
using SharpCoreDB.MVCC;
48+
49+
// Define your model
50+
public record User(int Id, string Name, int Age, string Department);
51+
52+
// Create MVCC manager with generics
53+
var mvcc = new MvccManager<int, User>("users");
54+
55+
// Start a snapshot-isolated transaction
56+
using var tx = mvcc.BeginTransaction(isReadOnly: true);
57+
58+
// Create queryable with type safety
59+
var queryable = new MvccQueryable<int, User>(mvcc, tx);
60+
61+
// Type-safe LINQ queries!
62+
var adults = queryable
63+
.Where(u => u.Age >= 18)
64+
.OrderBy(u => u.Name)
65+
.ToList();
66+
67+
var engineers = queryable
68+
.Where(u => u.Department == "Engineering")
69+
.GroupBy(u => u.Age)
70+
.ToList();
71+
```
72+
73+
**Benefits**:
74+
- ✅ Compile-time type checking (no runtime errors!)
75+
- ✅ IntelliSense support
76+
- ✅ Refactoring-friendly
77+
- ✅ Translates to optimized SQL
78+
79+
### 2️⃣ Generic GROUP BY with Custom Types
80+
81+
```csharp
82+
// Group by single property
83+
var byDepartment = queryable
84+
.GroupBy(u => u.Department)
85+
.ToList();
86+
87+
// Group by multiple properties (anonymous type)
88+
var byDeptAndAge = queryable
89+
.GroupBy(u => new { u.Department, u.Age })
90+
.ToList();
91+
92+
// Works with ANY custom type!
93+
public record Product(int Id, string Name, string Category, decimal Price);
94+
95+
var productStore = new MvccManager<int, Product>("products");
96+
var products = new MvccQueryable<int, Product>(productStore, tx);
97+
98+
var byCategory = products
99+
.GroupBy(p => p.Category)
100+
.ToList();
101+
```
102+
103+
### 3️⃣ Columnar Storage with SIMD Aggregates
104+
105+
For **analytics workloads**, use columnar storage with SIMD-accelerated aggregates:
106+
107+
```csharp
108+
using SharpCoreDB.ColumnStorage;
109+
110+
// Create columnar store for any type T
111+
var columnStore = new ColumnStore<EmployeeRecord>();
112+
113+
// Transpose row-oriented data to column-oriented
114+
columnStore.Transpose(employees);
115+
116+
// Lightning-fast SIMD aggregates!
117+
var avgSalary = columnStore.Average("Salary"); // < 0.04ms for 10k rows
118+
var maxAge = columnStore.Max<int>("Age"); // < 0.06ms
119+
var totalSales = columnStore.Sum<decimal>("Sales"); // < 0.03ms
120+
var minPrice = columnStore.Min<double>("Price"); // < 0.06ms
121+
122+
// Multi-column aggregates in < 1ms!
123+
var stats = new {
124+
TotalSalary = columnStore.Sum<decimal>("Salary"),
125+
AvgAge = columnStore.Average("Age"),
126+
MaxExperience = columnStore.Max<int>("YearsExperience"),
127+
Count = columnStore.Count("Id")
128+
}; // All 4 aggregates: 0.368ms!
129+
```
130+
131+
**Performance** (10,000 records):
132+
- SUM: **0.032ms** (6x faster than LINQ)
133+
- AVG: **0.040ms** (106x faster than LINQ!)
134+
- MIN+MAX: **0.060ms** (37x faster than LINQ)
135+
- All 5 aggregates: **0.368ms** (target was < 2ms!)
136+
137+
**Throughput**: **312 million rows/second** 🚀
138+
139+
### 4️⃣ Generic Indexes with Type-Safe Keys
140+
141+
```csharp
142+
using SharpCoreDB.DataStructures;
143+
144+
// Generic hash index with any key type
145+
var index = new GenericHashIndex<string, Employee>();
146+
147+
// Type-safe insert
148+
index.Add("alice@company.com", employee1);
149+
index.Add("bob@company.com", employee2);
150+
151+
// Type-safe lookup (O(1))
152+
var employee = index.Lookup("alice@company.com");
153+
154+
// Works with custom key types
155+
public struct EmployeeId : IEquatable<EmployeeId>
156+
{
157+
public int Value { get; init; }
158+
public bool Equals(EmployeeId other) => Value == other.Value;
159+
public override int GetHashCode() => Value;
160+
}
161+
162+
var idIndex = new GenericHashIndex<EmployeeId, Employee>();
163+
idIndex.Add(new EmployeeId { Value = 123 }, employee);
164+
```
165+
166+
### 5️⃣ MVCC with Generics
167+
168+
**Multi-Version Concurrency Control** with full type safety:
169+
170+
```csharp
171+
using SharpCoreDB.MVCC;
172+
173+
// Generic MVCC manager
174+
var mvcc = new MvccManager<int, Product>("products");
175+
176+
// Write transaction
177+
using (var writeTx = mvcc.BeginTransaction())
178+
{
179+
var product = new Product(1, "Laptop", "Electronics", 999.99m);
180+
mvcc.Insert(1, product, writeTx);
181+
mvcc.CommitTransaction(writeTx);
182+
}
183+
184+
// Concurrent read transactions (snapshot isolation)
185+
using var readTx1 = mvcc.BeginTransaction(isReadOnly: true);
186+
using var readTx2 = mvcc.BeginTransaction(isReadOnly: true);
187+
188+
// Both see consistent snapshot
189+
var p1 = mvcc.Read(1, readTx1); // Isolated view
190+
var p2 = mvcc.Read(1, readTx2); // Independent snapshot
191+
192+
// Scan with snapshot isolation
193+
var allProducts = mvcc.Scan(readTx1).ToList();
194+
```
195+
196+
**Benefits**:
197+
- ✅ No locks on reads (lock-free!)
198+
- ✅ Snapshot isolation (ACID compliant)
199+
- ✅ Concurrent readers + writers
200+
- ✅ Type-safe API
201+
202+
### 6️⃣ LINQ Expression Translation
203+
204+
The LINQ-to-SQL translator handles **complex queries**:
205+
206+
```csharp
207+
// Complex WHERE clause
208+
var results = queryable
209+
.Where(u => u.Age > 25 && u.Age < 65 &&
210+
(u.Department == "Engineering" || u.Department == "Sales"))
211+
.ToList();
212+
213+
// Translated SQL:
214+
// SELECT * FROM Users
215+
// WHERE (((Age > @p0) AND (Age < @p1)) AND
216+
// ((Department = @p2) OR (Department = @p3)))
217+
218+
// String methods
219+
var johns = queryable
220+
.Where(u => u.Name.Contains("John"))
221+
.ToList();
222+
// → SELECT * FROM Users WHERE Name LIKE @p0 -- @p0 = '%John%'
223+
224+
// Pagination
225+
var page2 = queryable
226+
.OrderBy(u => u.Id)
227+
.Skip(20)
228+
.Take(10)
229+
.ToList();
230+
// → SELECT * FROM Users ORDER BY Id OFFSET 20 LIMIT 10
231+
```
232+
233+
### 🎯 Performance Comparison: Columnar vs LINQ
234+
235+
On **10,000 Employee records**:
236+
237+
| Operation | LINQ | Columnar (SIMD) | Speedup |
238+
|-----------|------|-----------------|---------|
239+
| SUM(Age) | 0.204ms | **0.034ms** | **6.0x**|
240+
| AVG(Age) | 4.200ms | **0.040ms** | **106x** 🚀 |
241+
| MIN+MAX(Age) | 2.421ms | **0.064ms** | **37.7x**|
242+
| **Average** | - | - | **50x faster!** 🏆 |
243+
244+
### 🔧 Generic Architecture Benefits
245+
246+
**Before (Pre-Generics)**:
247+
```csharp
248+
// Non-generic, runtime type checking
249+
var table = new Table(storage);
250+
table.Insert(row); // Dictionary<string, object>
251+
// ❌ No type safety
252+
// ❌ Boxing/unboxing overhead
253+
// ❌ No IntelliSense
254+
```
255+
256+
**After (C# 14 Generics)**:
257+
```csharp
258+
// Generic, compile-time type checking
259+
var manager = new MvccManager<int, Employee>("employees");
260+
manager.Insert(1, employee, tx);
261+
// ✅ Full type safety
262+
// ✅ Zero boxing
263+
// ✅ IntelliSense everywhere
264+
// ✅ Refactoring support
265+
```
266+
267+
### 🧪 Generic Load Tests - Production Validated
268+
269+
Comprehensive load tests validate struct/enum generics at scale:
270+
271+
**100,000 Operations**:
272+
- ✅ Hash Index (struct keys): **2.3M ops/sec**
273+
- ✅ Hash Index (enum keys): **1.7M ops/sec**
274+
- ✅ Hash Index (Money struct): **1.7M ops/sec**
275+
- ✅ Zero GC pressure: **33.8M ops/sec** 🚀
276+
277+
**MVCC with Complex Structs**:
278+
- ✅ 10k inserts: **946k ops/sec**
279+
- ✅ Full scan: **7.9M rows/sec**
280+
- ✅ 100 concurrent readers: **28.9M rows/sec** 🏆
281+
282+
**Columnar Storage (SIMD)**:
283+
- ✅ 50k transpose: **2.9M rows/sec**
284+
- ✅ 100k transpose: **3.3M rows/sec**
285+
- ✅ 5 aggregates (100k rows): **8.5ms**
286+
287+
**Memory Efficiency**:
288+
- ✅ 143 bytes per complex object
289+
- ✅ Minimal GC (Gen0: 4, Gen1: 3, Gen2: 3)
290+
291+
**All load tests pass** - see `GenericLoadTests.cs` for details!
292+
293+
### 📚 More Generic Examples
294+
295+
See the comprehensive test suite:
296+
- `GenericLinqToSqlTests.cs` - 17 tests covering LINQ translation
297+
- `ColumnStoreTests.cs` - 14 tests for SIMD aggregates
298+
- `GenericIndexPerformanceTests.cs` - Performance benchmarks
299+
- `MvccAsyncBenchmark.cs` - Concurrent transactions
300+
- `GenericLoadTests.cs` - **10 load tests (100k+ operations)** 🆕
301+
302+
**All generics features are production-ready and extensively tested!**
303+
36304
## Features
37305

38306
### Core Database Features
@@ -59,9 +327,12 @@ var result = db.ExecuteSQL("SELECT * FROM users");
59327
- **EXPLAIN Plans**
60328
- **Date/Time + Aggregate Functions**
61329
- **PRAGMA Commands**
62-
- **Modern C# 14**
330+
- **Modern C# 14 with Full Generics** 🆕
63331
- **Parameterized Queries**
64332
- **Concurrent Async Selects**
333+
- **MVCC with Snapshot Isolation** 🆕
334+
- **Generic LINQ-to-SQL** 🆕
335+
- **Columnar Storage with SIMD** 🆕
65336

66337
## Performance Benchmarks - Comprehensive Comparison 📊
67338

0 commit comments

Comments
 (0)