MONRAKPhai SQL
A gift of knowledge · Free · Thai first

The Phai family's database on your own machine, your data your own

Phai SQL is written in Rust from the ground up. It reads and writes SQLite files both ways, encrypts them, lets an AI use your data without seeing ID numbers, phone numbers or salaries, and runs as a server for the office's programs. No cloud service needed.

SQL test suite622 / 622
Runs onWindows
Version0.1.0 preview
Features

What it does

Each checked statement by statement to give the same results, error messages and file as the reference

Files anyone can open

Data kept in standard SQLite files: other programs open Phai SQL's files, and Phai SQL opens theirs

Full SQL

Every kind of JOIN, subqueries, WITH and WITH RECURSIVE, window functions, UPSERT, RETURNING, views, triggers, JSON and JSON5, date functions

Encrypted files

AES-256 and HMAC-SHA512 in SQLCipher 4's format; a password for each person, a recovery key, re-keying

Safe for AI

An AI only reads; private columns come masked (081*****78) and can't be used to guess; row and time limits; every statement logged

Vectors for AI

Embeddings in ordinary tables, nearest-meaning search, and the way to RAG with Phai AI

Thai

COLLATE THAI: Thai dictionary order (a leading vowel sorts by the consonant after it); a Thai guide and messages

A server

Speaks MySQL's protocol: phpMyAdmin, PHP (mysqli, PDO), mysql and mysqldump work; users and rights; TLS

One file, many users

Transactions, savepoints, rollback-journal and WAL modes, many readers at once, the file shared with other programs through the same locks

All Rust

Written from the specifications, wrapping nobody's code; cryptography from RustCrypto; a library in Rust programs or a server

Tested

How correct it is

Every number measured, with its source and limits in the project's documents

622 / 622

files of the standard SQL test suite pass: 5,729,093 queries and 210,786 statements, 0 wrong

Power cut at any moment

a cut simulated at every step of a commit (half-written pages too), plain, WAL and encrypted: the file is always as before or after

A damaged file is no crash

fuzzed with random bytes: a damaged file gets the answer "damaged", never a hang or a crash

Speed

How fast it is

Measured on one machine on 3 December 2026, every engine set up alike: where Phai SQL is faster and where it is still slower

Phai SQL and SQLite 3.54.1: reading a 10-million-row table

The same file, an 8 MB page cache each, milliseconds (best of 3, measured twice)

TaskPhai SQLSQLite
Look up by id0.030.051.7–2× faster
Look up by an indexed name0.020.051.7–2.5× faster
A range of names (index range)4.113.72about even
The first screen of 500.060.142.3–2.6× faster
Jump to the middle0.060.142.3–2.5× faster
count(*) of the whole table5191413.7× slower
sum and avg over all4278951.8–2.1× faster
A filter with no index4536991.5× faster
Group by month1,7826,6683.7–4× faster
Sort with no index (top 10)3618462.4× faster

Phai SQL and SQLite 3.54.1: writing 10 million rows

An 8 MB cache each, every commit flushed to disk, seconds (best of 2 pairs; the comparison is the range over the pairs)

TaskPhai SQLSQLite
Insert 10 million rows152.8224.31.2–1.5× faster
UPDATE a tenth16.629.61.5–2.3× faster
DELETE a tenth7.421.32.6–4× faster
Peak RAM (MB)2616–201.3–1.6× more

Phai SQL Server and MySQL 8.0: over the network from PHP

PHP 8.2 mysqli over TCP, 100,000 rows, MySQL as it comes (128 MB buffer pool, every commit flushed), seconds (best of 3 rounds; the comparison is the range over the rounds)

TaskPhai SQLMySQL
Insert in one transaction10.3710.971.1–1.5× faster
500 single-row commits0.1590.183about even
20,000 lookups by id1.762.401.4–1.5× faster
5,000 lookups by index0.4780.8041.7–2.4× faster
count, sum, avg ×50.0200.0993.9–6.1× faster
GROUP BY ×50.0880.3122.9–4.1× faster
Read every row0.1370.1255–13% slower
UPDATE every row0.0440.2874.7–9.4× faster
DELETE half0.1870.3201.7–1.8× faster
Peak memory (MB)26.938.630% less

Where it is still slower, we will make it better: count(*) of a whole table (the cause is found), reading every row through the server, index ranges, and RAM while writing, still above SQLite's. Each time it improves, it is measured again and shown here as it is.

The machine: Intel Core Ultra 7 155H, 32 GB RAM, NVMe SSD, Windows 11. The raw numbers, the commands and every limit are in the project's documents (docs/facts.md).

AI

Your data, your AI

Phai SQL is the retrieval half of RAG: it keeps the documents and vectors, searches by meaning, and decides who may find what; private data is masked before any AI sees it. Paired with Phai AI (in the making), you get an AI that answers from your own data, on your own machine, with nothing sent away.

Guide

Learn SQL with Phai

An SQL guide in Thai and English, 36 chapters from the first SELECT to window functions, triggers, JSON and Thai text, on a practice shop. Every example is run and its result checked before the site is built.

Open the guide

Install

Installing the server

One file, nothing else to install

1

Download and unpack phai-sql-0.1.0-windows-x64.zip: you get phai-sql-server.exe

2

Set a password the first time: phai-sql-server.exe D:\data --set-password admin

3

Start it: phai-sql-server.exe D:\data --listen 127.0.0.1:3306, then connect with Phai Database Studio, phpMyAdmin or PHP

Each .phdb file in the folder is one database. By default it listens on this machine only; never open it to the internet, use a VPN for other machines.

Download

Download

Phai SQL server for 64-bit Windows

A preview: for test data, or data you have backed up. 1.0 brings a Windows service, a shell program and a Linux build.

phai-sql-0.1.0-windows-x64.zipSHA-256 a50580689549ede374dd5253fe11c30ea16e1fe4e41a562c738cc652dbc5fc13
2.1 MB

2 downloads · 2026-12-02