forked from ferrosadb/ferrosa
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostgres.html
More file actions
307 lines (265 loc) · 13 KB
/
Copy pathpostgres.html
File metadata and controls
307 lines (265 loc) · 13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ferrosa — PostgreSQL Wire Protocol</title>
<link rel="icon" type="image/svg+xml" href="favicon.svg">
<style>
:root {
--bg-primary: #0a0a0f;
--bg-secondary: #111118;
--bg-card: #16161f;
--bg-card-hover: #1c1c28;
--text-primary: #e8e8ed;
--text-secondary: #9494a3;
--text-muted: #6b6b7a;
--accent: #e2725b;
--accent-warm: #d4a574;
--accent-green: #6bc9a0;
--accent-cool: #7c9cf5;
--border: #1e1e2a;
--code-bg: #0d0d14;
--font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
--font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
font-family: var(--font-sans);
background: var(--bg-primary);
color: var(--text-primary);
line-height: 1.6;
-webkit-font-smoothing: antialiased;
}
.container {
max-width: 960px;
margin: 0 auto;
padding: 4rem 2rem 6rem;
}
.back-link {
display: inline-block;
color: var(--accent);
text-decoration: none;
font-size: 0.875rem;
font-weight: 500;
margin-bottom: 2rem;
}
.back-link:hover { text-decoration: underline; }
h1 {
font-size: 2.5rem;
font-weight: 800;
letter-spacing: -0.03em;
margin-bottom: 0.5rem;
}
h1 span { color: var(--accent); }
.subtitle {
font-size: 1.125rem;
color: var(--text-secondary);
margin-bottom: 3rem;
max-width: 640px;
line-height: 1.7;
}
h2 {
font-size: 0.75rem;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.1em;
color: var(--accent);
margin-bottom: 1.5rem;
margin-top: 4rem;
}
h3 {
font-size: 1.25rem;
font-weight: 700;
margin-bottom: 0.75rem;
margin-top: 2rem;
}
p, li {
color: var(--text-secondary);
margin-bottom: 1rem;
max-width: 720px;
line-height: 1.7;
}
ul, ol { padding-left: 1.5rem; margin-bottom: 1.5rem; }
li { margin-bottom: 0.5rem; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code {
font-family: var(--font-mono);
font-size: 0.875em;
background: var(--code-bg);
padding: 0.15em 0.4em;
border-radius: 4px;
border: 1px solid var(--border);
color: var(--accent-cool);
}
pre {
background: var(--code-bg);
border: 1px solid var(--border);
border-radius: 10px;
padding: 1.25rem 1.5rem;
overflow-x: auto;
margin-bottom: 1.5rem;
font-family: var(--font-mono);
font-size: 0.875rem;
line-height: 1.8;
color: var(--text-secondary);
}
pre .cm { color: #546e7a; }
pre .kw { color: #c792ea; }
pre .str { color: #c3e88d; }
pre .var { color: #f78c6c; }
pre .type { color: #ffcb6b; }
table {
width: 100%;
border-collapse: collapse;
margin: 1.5rem 0;
font-size: 0.9375rem;
}
th, td {
text-align: left;
padding: 0.75rem 1rem;
border-bottom: 1px solid var(--border);
}
th {
font-size: 0.75rem;
text-transform: uppercase;
letter-spacing: 0.08em;
color: var(--text-muted);
font-weight: 600;
}
td { color: var(--text-secondary); }
td:first-child { color: var(--text-primary); font-weight: 600; font-family: var(--font-mono); font-size: 0.875rem; }
.check { color: var(--accent-green); }
.cross { color: var(--text-muted); }
.partial { color: var(--accent-warm); }
.note {
background: rgba(226, 114, 91, 0.08);
border: 1px solid rgba(226, 114, 91, 0.2);
border-radius: 10px;
padding: 1rem 1.25rem;
margin: 1.5rem 0;
font-size: 0.9375rem;
color: var(--text-secondary);
}
.note strong { color: var(--accent); }
.extension {
background: rgba(107, 201, 160, 0.08);
border: 1px solid rgba(107, 201, 160, 0.2);
border-radius: 10px;
padding: 1rem 1.25rem;
margin: 1.5rem 0;
font-size: 0.9375rem;
color: var(--text-secondary);
}
.extension strong { color: var(--accent-green); }
.toc {
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: 12px;
padding: 1.5rem 2rem;
margin-bottom: 2rem;
}
.toc h4 {
font-size: 0.75rem;
text-transform: uppercase;
letter-spacing: 0.1em;
color: var(--text-muted);
margin-bottom: 0.75rem;
}
.toc ul { list-style: none; padding: 0; margin: 0; }
.toc li { margin-bottom: 0.375rem; }
.toc a { font-size: 0.9375rem; font-weight: 500; }
@media (max-width: 640px) {
table { font-size: 0.8125rem; }
th, td { padding: 0.5rem 0.625rem; }
}
</style>
</head>
<body>
<div class="container">
<a href="/" class="back-link">← Ferrosa Suite home</a> · <a href="/database/" class="back-link">Database home</a>
<h1>PostgreSQL <span>Wire Protocol</span></h1>
<p class="subtitle">Alongside CQL, Ferrosa speaks the PostgreSQL frontend/backend protocol (v3) with SCRAM-SHA-256 authentication — so <code>psql</code>, <code>psycopg2</code>, <code>tokio-postgres</code>, and other standard clients can connect to the same data. This page documents what works today, how it is tested, and where it is headed.</p>
<div class="note">
<strong>Developer preview:</strong> the Postgres front-end is newer than the CQL surface and covers a focused subset of SQL. Validate against your workload before relying on it. Its behavior is continuously cross-checked against a real PostgreSQL 16 (see <a href="#testing">Differential testing</a>).
</div>
<div class="toc">
<h4>On this page</h4>
<ul>
<li><a href="#protocol">Protocol & connecting</a></li>
<li><a href="#select">Queries (SELECT)</a></li>
<li><a href="#dml">Writes (INSERT / UPDATE / DELETE)</a></li>
<li><a href="#transactions">Transactions</a></li>
<li><a href="#testing">Differential testing</a></li>
<li><a href="#not-yet">Not yet supported</a></li>
</ul>
</div>
<!-- ── Protocol ── -->
<h2 id="protocol">Protocol & connecting</h2>
<p>Ferrosa implements the PostgreSQL v3 wire protocol on port <code>5432</code> with SCRAM-SHA-256 authentication. Both the <strong>simple query</strong> protocol and the <strong>extended query</strong> protocol (Parse / Bind / Describe / Execute / Sync) are supported.</p>
<pre><span class="cm"># Any standard PostgreSQL client connects:</span>
psql "host=127.0.0.1 port=5432 user=ferrosa_user dbname=ferrosa"
<span class="cm"># psycopg2 / tokio-postgres / Postgrex use the same wire + SCRAM auth.</span></pre>
<p>The active transaction status (<code>I</code> idle, <code>T</code> in-transaction, <code>E</code> failed) is reported in <code>ReadyForQuery</code> exactly as PostgreSQL does, so drivers track transaction state correctly.</p>
<!-- ── SELECT ── -->
<h2 id="select">Queries (SELECT)</h2>
<p>The query surface is verified row-for-row against PostgreSQL across a fixed corpus:</p>
<table>
<thead><tr><th>Capability</th><th>Status</th><th>Notes</th></tr></thead>
<tbody>
<tr><td>Projection & <code>*</code></td><td><span class="check">✓</span></td><td>column lists and star</td></tr>
<tr><td>WHERE</td><td><span class="check">✓</span></td><td><code>=</code>, <code>!=</code>, <code><</code>/<code><=</code>/<code>></code>/<code>>=</code>, <code>AND</code>/<code>OR</code>/<code>NOT</code>, parentheses</td></tr>
<tr><td>Three-valued logic</td><td><span class="check">✓</span></td><td>comparisons with <code>NULL</code> are UNKNOWN → excluded (Kleene <code>AND</code>/<code>OR</code>/<code>NOT</code>)</td></tr>
<tr><td>JOIN</td><td><span class="check">✓</span></td><td>inner equi-join</td></tr>
<tr><td>GROUP BY + aggregates</td><td><span class="check">✓</span></td><td><code>COUNT</code>, <code>SUM</code>, <code>MIN</code>, <code>MAX</code>, <code>AVG</code>; empty <code>SUM</code>/<code>MIN</code> → <code>NULL</code></td></tr>
<tr><td>HAVING / DISTINCT</td><td><span class="check">✓</span></td><td></td></tr>
<tr><td>ORDER BY / LIMIT / OFFSET</td><td><span class="check">✓</span></td><td><code>ASC</code>/<code>DESC</code>, multi-key; text orders by <code>C</code> collation (byte order)</td></tr>
<tr><td>Expression selects</td><td><span class="check">✓</span></td><td><code>SELECT 1</code>, <code>version()</code>, <code>current_database()</code> (simple + extended)</td></tr>
<tr><td>Scalar types</td><td><span class="check">✓</span></td><td>int, text, bool, float8, numeric, uuid, bytea, inet, timestamp, date, time</td></tr>
</tbody>
</table>
<!-- ── DML ── -->
<h2 id="dml">Writes (INSERT / UPDATE / DELETE)</h2>
<p>Single-row DML writes through the same storage engine the CQL path uses, sharing one canonical row encoder so a row written over Postgres reads back identically over CQL.</p>
<pre><span class="kw">INSERT INTO</span> kv (id, v, n) <span class="kw">VALUES</span> (<span class="var">1</span>, <span class="str">'one'</span>, <span class="var">10</span>); <span class="cm">-- INSERT 0 1</span>
<span class="kw">UPDATE</span> kv <span class="kw">SET</span> v = <span class="str">'ONE'</span> <span class="kw">WHERE</span> id = <span class="var">1</span>; <span class="cm">-- UPDATE 1</span>
<span class="kw">DELETE FROM</span> kv <span class="kw">WHERE</span> id = <span class="var">1</span>; <span class="cm">-- DELETE 1</span></pre>
<ul>
<li>Values are converted per the target column type; out-of-range or type-mismatched values are rejected with a SQLSTATE error rather than coerced.</li>
<li><code>NULL</code> deletes the cell (it reads back as SQL <code>NULL</code>, not <code>""</code> / <code>0</code>).</li>
<li>Following Cassandra-storage semantics, <code>UPDATE</code> of a non-existent key is an upsert. The <code>WHERE</code> clause must specify the full primary key.</li>
</ul>
<!-- ── Transactions ── -->
<h2 id="transactions">Transactions</h2>
<p><code>BEGIN</code> / <code>COMMIT</code> / <code>ROLLBACK</code> are honored at the protocol level: the connection moves through idle → in-transaction → (on error) failed, and a failed transaction rejects further statements with SQLSTATE <code>25P02</code> until <code>ROLLBACK</code>.</p>
<div class="note">
<strong>In progress:</strong> multi-statement atomicity routes through Accord (Ferrosa's strict-serializable transaction engine). The protocol-state machine is complete; the atomic commit path is being wired up.
</div>
<!-- ── Testing ── -->
<h2 id="testing">Differential testing</h2>
<p>Every CI build runs a <strong>differential oracle</strong>: the same data and the same SQL are executed against a real PostgreSQL 16 <em>and</em> the Ferrosa front-end, and the result sets must agree. It is the cross-check that catches the front-end silently diverging from PostgreSQL.</p>
<div class="extension">
<strong>How it stays honest:</strong> three verdicts (Match / Mismatch / Out-of-scope, never a silent pass); a sound value comparator (exact match first, a numeric tolerance only for genuine float-vs-numeric text formatting); a restricted-query oracle proving unsupported SQL fails loud rather than returning wrong rows; a self-contained NULL/3VL known-answer corpus; and a declared <code>COLLATE "C"</code> ordering contract. The corpus covers SELECT, the full INSERT/UPDATE/DELETE lifecycle, and temporal/numeric/inet types.
</div>
<p>See the <code>postgres-oracle</code> job in <code>.github/workflows/ci.yml</code> and <code>ferrosa-postgres/tests/differential_oracle.rs</code>.</p>
<!-- ── Not yet ── -->
<h2 id="not-yet">Not yet supported</h2>
<p>These surface a clean driver error today rather than silently-wrong results, and are tracked on the roadmap:</p>
<table>
<thead><tr><th>Feature</th><th>Status</th></tr></thead>
<tbody>
<tr><td><code>$N</code> params in DML</td><td><span class="partial">in progress</span> — extended-protocol bind for writes</td></tr>
<tr><td><code>RETURNING</code> / <code>ON CONFLICT</code></td><td><span class="cross">planned</span></td></tr>
<tr><td><code>IS [NOT] NULL</code></td><td><span class="cross">planned</span></td></tr>
<tr><td>Subqueries, <code>WITH</code>, <code>UNION</code>, window functions</td><td><span class="cross">not supported</span></td></tr>
<tr><td>Non-<code>C</code> collations</td><td><span class="cross">v1 is <code>COLLATE "C"</code> only</span></td></tr>
</tbody>
</table>
<div class="note">
<strong>CQL is the mature surface.</strong> For the broadest compatibility today, see the <a href="cql-compatibility.html">CQL Reference</a>. The Postgres front-end shares the same storage, schema, and transaction engine underneath.
</div>
</div>
</body>
</html>