Skip to main content

reifydb_core/interface/catalog/
id.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2026 ReifyDB
3
4use std::{
5	fmt,
6	fmt::{Display, Formatter},
7	ops::Deref,
8};
9
10use reifydb_value::util::hash::xxh3_64;
11use serde::{Deserialize, Deserializer, Serialize, Serializer, de::Visitor};
12
13#[repr(transparent)]
14#[derive(Debug, Copy, Clone, PartialOrd, PartialEq, Ord, Eq, Hash)]
15pub struct ColumnId(pub u64);
16
17impl ColumnId {
18	pub const REQUEST_HISTORY_TIMESTAMP: ColumnId = ColumnId(1);
19	pub const REQUEST_HISTORY_OPERATION: ColumnId = ColumnId(2);
20	pub const REQUEST_HISTORY_FINGERPRINT: ColumnId = ColumnId(3);
21	pub const REQUEST_HISTORY_TOTAL_DURATION: ColumnId = ColumnId(4);
22	pub const REQUEST_HISTORY_COMPUTE_DURATION: ColumnId = ColumnId(5);
23	pub const REQUEST_HISTORY_SUCCESS: ColumnId = ColumnId(6);
24	pub const REQUEST_HISTORY_STATEMENT_COUNT: ColumnId = ColumnId(7);
25	pub const REQUEST_HISTORY_NORMALIZED_RQL: ColumnId = ColumnId(8);
26
27	pub const STATEMENT_STATS_SNAPSHOT_TIMESTAMP: ColumnId = ColumnId(9);
28	pub const STATEMENT_STATS_FINGERPRINT: ColumnId = ColumnId(10);
29	pub const STATEMENT_STATS_NORMALIZED_RQL: ColumnId = ColumnId(11);
30	pub const STATEMENT_STATS_CALLS: ColumnId = ColumnId(12);
31	pub const STATEMENT_STATS_TOTAL_DURATION: ColumnId = ColumnId(13);
32	pub const STATEMENT_STATS_MEAN_DURATION: ColumnId = ColumnId(14);
33	pub const STATEMENT_STATS_MAX_DURATION: ColumnId = ColumnId(15);
34	pub const STATEMENT_STATS_MIN_DURATION: ColumnId = ColumnId(16);
35	pub const STATEMENT_STATS_TOTAL_ROWS: ColumnId = ColumnId(17);
36	pub const STATEMENT_STATS_ERRORS: ColumnId = ColumnId(18);
37
38	pub const RUNTIME_MEMORY_SNAPSHOTS_TS: ColumnId = ColumnId(1024);
39	pub const RUNTIME_MEMORY_SNAPSHOTS_SCOPE: ColumnId = ColumnId(1025);
40	pub const RUNTIME_MEMORY_SNAPSHOTS_METRIC: ColumnId = ColumnId(1026);
41	pub const RUNTIME_MEMORY_SNAPSHOTS_VALUE: ColumnId = ColumnId(1027);
42	pub const RUNTIME_MEMORY_SNAPSHOTS_UNIT: ColumnId = ColumnId(1028);
43	pub const RUNTIME_MEMORY_SNAPSHOTS_KIND: ColumnId = ColumnId(1029);
44	pub const RUNTIME_WATERMARKS_SNAPSHOTS_TS: ColumnId = ColumnId(1030);
45	pub const RUNTIME_WATERMARKS_SNAPSHOTS_SCOPE: ColumnId = ColumnId(1031);
46	pub const RUNTIME_WATERMARKS_SNAPSHOTS_METRIC: ColumnId = ColumnId(1032);
47	pub const RUNTIME_WATERMARKS_SNAPSHOTS_VALUE: ColumnId = ColumnId(1033);
48	pub const RUNTIME_WATERMARKS_SNAPSHOTS_UNIT: ColumnId = ColumnId(1034);
49	pub const RUNTIME_WATERMARKS_SNAPSHOTS_KIND: ColumnId = ColumnId(1035);
50	pub const RUNTIME_OPERATORS_SNAPSHOTS_TS: ColumnId = ColumnId(1036);
51	pub const RUNTIME_OPERATORS_SNAPSHOTS_SCOPE: ColumnId = ColumnId(1037);
52	pub const RUNTIME_OPERATORS_SNAPSHOTS_METRIC: ColumnId = ColumnId(1038);
53	pub const RUNTIME_OPERATORS_SNAPSHOTS_VALUE: ColumnId = ColumnId(1039);
54	pub const RUNTIME_OPERATORS_SNAPSHOTS_UNIT: ColumnId = ColumnId(1040);
55	pub const RUNTIME_OPERATORS_SNAPSHOTS_KIND: ColumnId = ColumnId(1041);
56	pub const INSTRUMENTS_SNAPSHOTS_TS: ColumnId = ColumnId(1042);
57	pub const INSTRUMENTS_SNAPSHOTS_SCOPE: ColumnId = ColumnId(1043);
58	pub const INSTRUMENTS_SNAPSHOTS_METRIC: ColumnId = ColumnId(1044);
59	pub const INSTRUMENTS_SNAPSHOTS_VALUE: ColumnId = ColumnId(1045);
60	pub const INSTRUMENTS_SNAPSHOTS_UNIT: ColumnId = ColumnId(1046);
61	pub const INSTRUMENTS_SNAPSHOTS_KIND: ColumnId = ColumnId(1047);
62	pub const PROFILER_SPANS_SNAPSHOTS_TS: ColumnId = ColumnId(1048);
63	pub const PROFILER_SPANS_SNAPSHOTS_CATEGORY: ColumnId = ColumnId(1049);
64	pub const PROFILER_SPANS_SNAPSHOTS_SPAN_NAME: ColumnId = ColumnId(1050);
65	pub const PROFILER_SPANS_SNAPSHOTS_DIM_1: ColumnId = ColumnId(1051);
66	pub const PROFILER_SPANS_SNAPSHOTS_DIM_2: ColumnId = ColumnId(1052);
67	pub const PROFILER_SPANS_SNAPSHOTS_CALLS: ColumnId = ColumnId(1053);
68	pub const PROFILER_SPANS_SNAPSHOTS_TOTAL: ColumnId = ColumnId(1054);
69	pub const PROFILER_SPANS_SNAPSHOTS_P50: ColumnId = ColumnId(1056);
70	pub const PROFILER_SPANS_SNAPSHOTS_P75: ColumnId = ColumnId(1057);
71	pub const PROFILER_SPANS_SNAPSHOTS_P90: ColumnId = ColumnId(1058);
72	pub const PROFILER_SPANS_SNAPSHOTS_P95: ColumnId = ColumnId(1059);
73	pub const PROFILER_SPANS_SNAPSHOTS_P98: ColumnId = ColumnId(1060);
74	pub const PROFILER_SPANS_SNAPSHOTS_P99: ColumnId = ColumnId(1061);
75	pub const PROFILER_SPANS_SNAPSHOTS_P100: ColumnId = ColumnId(1062);
76	pub const PROFILER_SPANS_SNAPSHOTS_INPUT_ROWS: ColumnId = ColumnId(1063);
77	pub const PROFILER_SPANS_SNAPSHOTS_OUTPUT_ROWS: ColumnId = ColumnId(1064);
78	pub const PROFILER_SPANS_SNAPSHOTS_LOCK_WAIT: ColumnId = ColumnId(1065);
79	pub const EPOCH_SNAPSHOTS_TS: ColumnId = ColumnId(1091);
80	pub const EPOCH_SNAPSHOTS_SAMPLES: ColumnId = ColumnId(1092);
81	pub const EPOCH_SNAPSHOTS_DURABLE_SAMPLES: ColumnId = ColumnId(1093);
82	pub const EPOCH_SNAPSHOTS_COVERAGE: ColumnId = ColumnId(1094);
83	pub const EPOCH_SNAPSHOTS_GUARANTEED_COVERAGE: ColumnId = ColumnId(1095);
84	pub const EPOCH_SNAPSHOTS_PRUNED: ColumnId = ColumnId(1096);
85	pub const EPOCH_SNAPSHOTS_FLOOR_NONE_RETURNS: ColumnId = ColumnId(1097);
86	pub const LIFECYCLE_SNAPSHOTS_TS: ColumnId = ColumnId(1098);
87	pub const LIFECYCLE_SNAPSHOTS_CLASS: ColumnId = ColumnId(1099);
88	pub const LIFECYCLE_SNAPSHOTS_BINDING: ColumnId = ColumnId(1100);
89	pub const LIFECYCLE_SNAPSHOTS_FLOOR_VERSION: ColumnId = ColumnId(1101);
90	pub const LIFECYCLE_SNAPSHOTS_BACKLOG_HINT: ColumnId = ColumnId(1102);
91	pub const LIFECYCLE_SNAPSHOTS_WORK_DONE: ColumnId = ColumnId(1105);
92	pub const LIFECYCLE_SNAPSHOTS_SLICES: ColumnId = ColumnId(1106);
93	pub const LIFECYCLE_SNAPSHOTS_STUCK_SLICES: ColumnId = ColumnId(1107);
94	pub const LIFECYCLE_SNAPSHOTS_BUDGET_EXHAUSTED_SLICES: ColumnId = ColumnId(1108);
95	pub const LIFECYCLE_SNAPSHOTS_GATED_SLICES: ColumnId = ColumnId(1109);
96	pub const STORAGE_SNAPSHOTS_TS: ColumnId = ColumnId(1110);
97	pub const STORAGE_SNAPSHOTS_OBJECT_KIND: ColumnId = ColumnId(1111);
98	pub const STORAGE_SNAPSHOTS_ID: ColumnId = ColumnId(1112);
99	pub const STORAGE_SNAPSHOTS_NAMESPACE_ID: ColumnId = ColumnId(1113);
100	pub const STORAGE_SNAPSHOTS_TIER: ColumnId = ColumnId(1114);
101	pub const STORAGE_SNAPSHOTS_LIVE_KEY_BYTES: ColumnId = ColumnId(1115);
102	pub const STORAGE_SNAPSHOTS_LIVE_VALUE_BYTES: ColumnId = ColumnId(1116);
103	pub const STORAGE_SNAPSHOTS_LIVE_BYTES: ColumnId = ColumnId(1117);
104	pub const STORAGE_SNAPSHOTS_LIVE_COUNT: ColumnId = ColumnId(1118);
105	pub const STORAGE_SNAPSHOTS_SUPERSEDED_KEY_BYTES: ColumnId = ColumnId(1119);
106	pub const STORAGE_SNAPSHOTS_SUPERSEDED_VALUE_BYTES: ColumnId = ColumnId(1120);
107	pub const STORAGE_SNAPSHOTS_SUPERSEDED_BYTES: ColumnId = ColumnId(1121);
108	pub const STORAGE_SNAPSHOTS_SUPERSEDED_COUNT: ColumnId = ColumnId(1122);
109	pub const STORAGE_SNAPSHOTS_TOTAL_BYTES: ColumnId = ColumnId(1123);
110	pub const CDC_SNAPSHOTS_TS: ColumnId = ColumnId(1124);
111	pub const CDC_SNAPSHOTS_OBJECT_KIND: ColumnId = ColumnId(1125);
112	pub const CDC_SNAPSHOTS_ID: ColumnId = ColumnId(1126);
113	pub const CDC_SNAPSHOTS_NAMESPACE_ID: ColumnId = ColumnId(1127);
114	pub const CDC_SNAPSHOTS_KEY_BYTES: ColumnId = ColumnId(1128);
115	pub const CDC_SNAPSHOTS_VALUE_BYTES: ColumnId = ColumnId(1129);
116	pub const CDC_SNAPSHOTS_TOTAL_BYTES: ColumnId = ColumnId(1130);
117	pub const CDC_SNAPSHOTS_COUNT: ColumnId = ColumnId(1131);
118	pub const SOURCE_COMPLETENESS_OBJECT_ID: ColumnId = ColumnId(1132);
119	pub const SOURCE_COMPLETENESS_COMPLETE_THROUGH: ColumnId = ColumnId(1133);
120	pub const FLOW_STATE_SNAPSHOTS_TS: ColumnId = ColumnId(1134);
121	pub const FLOW_STATE_SNAPSHOTS_OPERATOR: ColumnId = ColumnId(1135);
122	pub const FLOW_STATE_SNAPSHOTS_KEYSPACE: ColumnId = ColumnId(1137);
123	pub const FLOW_STATE_SNAPSHOTS_PHASE: ColumnId = ColumnId(1138);
124	pub const FLOW_STATE_SNAPSHOTS_KEYS: ColumnId = ColumnId(1139);
125	pub const FLOW_STATE_SNAPSHOTS_KEY_BYTES: ColumnId = ColumnId(1140);
126	pub const FLOW_STATE_SNAPSHOTS_VALUE_BYTES: ColumnId = ColumnId(1141);
127	pub const FLOW_STATE_SNAPSHOTS_TOTAL_BYTES: ColumnId = ColumnId(1142);
128	pub const FLOW_STATE_SNAPSHOTS_NAME: ColumnId = ColumnId(1143);
129	pub const FLOW_STATE_SNAPSHOTS_UNMANAGED_BECAUSE: ColumnId = ColumnId(1144);
130
131	pub const RUNTIME_MEMORY_SNAPSHOTS_COLUMNS: [ColumnId; 6] = [
132		Self::RUNTIME_MEMORY_SNAPSHOTS_TS,
133		Self::RUNTIME_MEMORY_SNAPSHOTS_SCOPE,
134		Self::RUNTIME_MEMORY_SNAPSHOTS_METRIC,
135		Self::RUNTIME_MEMORY_SNAPSHOTS_VALUE,
136		Self::RUNTIME_MEMORY_SNAPSHOTS_UNIT,
137		Self::RUNTIME_MEMORY_SNAPSHOTS_KIND,
138	];
139
140	pub const RUNTIME_WATERMARKS_SNAPSHOTS_COLUMNS: [ColumnId; 6] = [
141		Self::RUNTIME_WATERMARKS_SNAPSHOTS_TS,
142		Self::RUNTIME_WATERMARKS_SNAPSHOTS_SCOPE,
143		Self::RUNTIME_WATERMARKS_SNAPSHOTS_METRIC,
144		Self::RUNTIME_WATERMARKS_SNAPSHOTS_VALUE,
145		Self::RUNTIME_WATERMARKS_SNAPSHOTS_UNIT,
146		Self::RUNTIME_WATERMARKS_SNAPSHOTS_KIND,
147	];
148
149	pub const RUNTIME_OPERATORS_SNAPSHOTS_COLUMNS: [ColumnId; 6] = [
150		Self::RUNTIME_OPERATORS_SNAPSHOTS_TS,
151		Self::RUNTIME_OPERATORS_SNAPSHOTS_SCOPE,
152		Self::RUNTIME_OPERATORS_SNAPSHOTS_METRIC,
153		Self::RUNTIME_OPERATORS_SNAPSHOTS_VALUE,
154		Self::RUNTIME_OPERATORS_SNAPSHOTS_UNIT,
155		Self::RUNTIME_OPERATORS_SNAPSHOTS_KIND,
156	];
157
158	pub const INSTRUMENTS_SNAPSHOTS_COLUMNS: [ColumnId; 6] = [
159		Self::INSTRUMENTS_SNAPSHOTS_TS,
160		Self::INSTRUMENTS_SNAPSHOTS_SCOPE,
161		Self::INSTRUMENTS_SNAPSHOTS_METRIC,
162		Self::INSTRUMENTS_SNAPSHOTS_VALUE,
163		Self::INSTRUMENTS_SNAPSHOTS_UNIT,
164		Self::INSTRUMENTS_SNAPSHOTS_KIND,
165	];
166
167	pub const PROFILER_SPANS_SNAPSHOTS_COLUMNS: [ColumnId; 17] = [
168		Self::PROFILER_SPANS_SNAPSHOTS_TS,
169		Self::PROFILER_SPANS_SNAPSHOTS_CATEGORY,
170		Self::PROFILER_SPANS_SNAPSHOTS_SPAN_NAME,
171		Self::PROFILER_SPANS_SNAPSHOTS_DIM_1,
172		Self::PROFILER_SPANS_SNAPSHOTS_DIM_2,
173		Self::PROFILER_SPANS_SNAPSHOTS_CALLS,
174		Self::PROFILER_SPANS_SNAPSHOTS_TOTAL,
175		Self::PROFILER_SPANS_SNAPSHOTS_P50,
176		Self::PROFILER_SPANS_SNAPSHOTS_P75,
177		Self::PROFILER_SPANS_SNAPSHOTS_P90,
178		Self::PROFILER_SPANS_SNAPSHOTS_P95,
179		Self::PROFILER_SPANS_SNAPSHOTS_P98,
180		Self::PROFILER_SPANS_SNAPSHOTS_P99,
181		Self::PROFILER_SPANS_SNAPSHOTS_P100,
182		Self::PROFILER_SPANS_SNAPSHOTS_INPUT_ROWS,
183		Self::PROFILER_SPANS_SNAPSHOTS_OUTPUT_ROWS,
184		Self::PROFILER_SPANS_SNAPSHOTS_LOCK_WAIT,
185	];
186
187	pub const EPOCH_SNAPSHOTS_COLUMNS: [ColumnId; 7] = [
188		Self::EPOCH_SNAPSHOTS_TS,
189		Self::EPOCH_SNAPSHOTS_SAMPLES,
190		Self::EPOCH_SNAPSHOTS_DURABLE_SAMPLES,
191		Self::EPOCH_SNAPSHOTS_COVERAGE,
192		Self::EPOCH_SNAPSHOTS_GUARANTEED_COVERAGE,
193		Self::EPOCH_SNAPSHOTS_PRUNED,
194		Self::EPOCH_SNAPSHOTS_FLOOR_NONE_RETURNS,
195	];
196
197	pub const LIFECYCLE_SNAPSHOTS_COLUMNS: [ColumnId; 10] = [
198		Self::LIFECYCLE_SNAPSHOTS_TS,
199		Self::LIFECYCLE_SNAPSHOTS_CLASS,
200		Self::LIFECYCLE_SNAPSHOTS_BINDING,
201		Self::LIFECYCLE_SNAPSHOTS_FLOOR_VERSION,
202		Self::LIFECYCLE_SNAPSHOTS_BACKLOG_HINT,
203		Self::LIFECYCLE_SNAPSHOTS_WORK_DONE,
204		Self::LIFECYCLE_SNAPSHOTS_SLICES,
205		Self::LIFECYCLE_SNAPSHOTS_STUCK_SLICES,
206		Self::LIFECYCLE_SNAPSHOTS_BUDGET_EXHAUSTED_SLICES,
207		Self::LIFECYCLE_SNAPSHOTS_GATED_SLICES,
208	];
209
210	pub const STORAGE_SNAPSHOTS_COLUMNS: [ColumnId; 14] = [
211		Self::STORAGE_SNAPSHOTS_TS,
212		Self::STORAGE_SNAPSHOTS_OBJECT_KIND,
213		Self::STORAGE_SNAPSHOTS_ID,
214		Self::STORAGE_SNAPSHOTS_NAMESPACE_ID,
215		Self::STORAGE_SNAPSHOTS_TIER,
216		Self::STORAGE_SNAPSHOTS_LIVE_KEY_BYTES,
217		Self::STORAGE_SNAPSHOTS_LIVE_VALUE_BYTES,
218		Self::STORAGE_SNAPSHOTS_LIVE_BYTES,
219		Self::STORAGE_SNAPSHOTS_LIVE_COUNT,
220		Self::STORAGE_SNAPSHOTS_SUPERSEDED_KEY_BYTES,
221		Self::STORAGE_SNAPSHOTS_SUPERSEDED_VALUE_BYTES,
222		Self::STORAGE_SNAPSHOTS_SUPERSEDED_BYTES,
223		Self::STORAGE_SNAPSHOTS_SUPERSEDED_COUNT,
224		Self::STORAGE_SNAPSHOTS_TOTAL_BYTES,
225	];
226
227	pub const CDC_SNAPSHOTS_COLUMNS: [ColumnId; 8] = [
228		Self::CDC_SNAPSHOTS_TS,
229		Self::CDC_SNAPSHOTS_OBJECT_KIND,
230		Self::CDC_SNAPSHOTS_ID,
231		Self::CDC_SNAPSHOTS_NAMESPACE_ID,
232		Self::CDC_SNAPSHOTS_KEY_BYTES,
233		Self::CDC_SNAPSHOTS_VALUE_BYTES,
234		Self::CDC_SNAPSHOTS_TOTAL_BYTES,
235		Self::CDC_SNAPSHOTS_COUNT,
236	];
237
238	pub const SOURCE_COMPLETENESS_COLUMNS: [ColumnId; 2] =
239		[Self::SOURCE_COMPLETENESS_OBJECT_ID, Self::SOURCE_COMPLETENESS_COMPLETE_THROUGH];
240
241	pub const FLOW_STATE_SNAPSHOTS_COLUMNS: [ColumnId; 10] = [
242		Self::FLOW_STATE_SNAPSHOTS_TS,
243		Self::FLOW_STATE_SNAPSHOTS_OPERATOR,
244		Self::FLOW_STATE_SNAPSHOTS_NAME,
245		Self::FLOW_STATE_SNAPSHOTS_UNMANAGED_BECAUSE,
246		Self::FLOW_STATE_SNAPSHOTS_KEYSPACE,
247		Self::FLOW_STATE_SNAPSHOTS_PHASE,
248		Self::FLOW_STATE_SNAPSHOTS_KEYS,
249		Self::FLOW_STATE_SNAPSHOTS_KEY_BYTES,
250		Self::FLOW_STATE_SNAPSHOTS_VALUE_BYTES,
251		Self::FLOW_STATE_SNAPSHOTS_TOTAL_BYTES,
252	];
253}
254
255impl Deref for ColumnId {
256	type Target = u64;
257
258	fn deref(&self) -> &Self::Target {
259		&self.0
260	}
261}
262
263impl PartialEq<u64> for ColumnId {
264	fn eq(&self, other: &u64) -> bool {
265		self.0.eq(other)
266	}
267}
268
269impl From<ColumnId> for u64 {
270	fn from(value: ColumnId) -> Self {
271		value.0
272	}
273}
274
275impl Serialize for ColumnId {
276	fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
277	where
278		S: Serializer,
279	{
280		serializer.serialize_u64(self.0)
281	}
282}
283
284impl<'de> Deserialize<'de> for ColumnId {
285	fn deserialize<D>(deserializer: D) -> Result<ColumnId, D::Error>
286	where
287		D: Deserializer<'de>,
288	{
289		struct U64Visitor;
290
291		impl Visitor<'_> for U64Visitor {
292			type Value = ColumnId;
293
294			fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
295				formatter.write_str("an unsigned 64-bit number")
296			}
297
298			fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E> {
299				Ok(ColumnId(value))
300			}
301		}
302
303		deserializer.deserialize_u64(U64Visitor)
304	}
305}
306
307#[derive(Debug, Copy, Clone, PartialOrd, PartialEq, Ord, Eq, Hash)]
308pub enum IndexId {
309	Primary(PrimaryKeyId),
310}
311
312impl IndexId {
313	pub fn as_u64(&self) -> u64 {
314		match self {
315			IndexId::Primary(id) => id.0,
316		}
317	}
318
319	pub fn primary(id: impl Into<PrimaryKeyId>) -> Self {
320		IndexId::Primary(id.into())
321	}
322
323	pub fn next(&self) -> IndexId {
324		match self {
325			IndexId::Primary(primary) => IndexId::Primary(PrimaryKeyId(primary.0 + 1)),
326		}
327	}
328
329	pub fn prev(&self) -> IndexId {
330		match self {
331			IndexId::Primary(primary) => IndexId::Primary(PrimaryKeyId(primary.0.wrapping_sub(1))),
332		}
333	}
334}
335
336impl Deref for IndexId {
337	type Target = u64;
338
339	fn deref(&self) -> &Self::Target {
340		match self {
341			IndexId::Primary(id) => &id.0,
342		}
343	}
344}
345
346impl PartialEq<u64> for IndexId {
347	fn eq(&self, other: &u64) -> bool {
348		self.as_u64().eq(other)
349	}
350}
351
352impl From<IndexId> for u64 {
353	fn from(value: IndexId) -> Self {
354		value.as_u64()
355	}
356}
357
358impl Serialize for IndexId {
359	fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
360	where
361		S: Serializer,
362	{
363		serializer.serialize_u64(self.as_u64())
364	}
365}
366
367impl<'de> Deserialize<'de> for IndexId {
368	fn deserialize<D>(deserializer: D) -> Result<IndexId, D::Error>
369	where
370		D: Deserializer<'de>,
371	{
372		struct U64Visitor;
373
374		impl Visitor<'_> for U64Visitor {
375			type Value = IndexId;
376
377			fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
378				formatter.write_str("an unsigned 64-bit number")
379			}
380
381			fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E> {
382				Ok(IndexId::Primary(PrimaryKeyId(value)))
383			}
384		}
385
386		deserializer.deserialize_u64(U64Visitor)
387	}
388}
389
390#[repr(transparent)]
391#[derive(Debug, Copy, Clone, PartialOrd, PartialEq, Ord, Eq, Hash)]
392pub struct ColumnPropertyId(pub u64);
393
394impl Deref for ColumnPropertyId {
395	type Target = u64;
396
397	fn deref(&self) -> &Self::Target {
398		&self.0
399	}
400}
401
402impl PartialEq<u64> for ColumnPropertyId {
403	fn eq(&self, other: &u64) -> bool {
404		self.0.eq(other)
405	}
406}
407
408impl From<ColumnPropertyId> for u64 {
409	fn from(value: ColumnPropertyId) -> Self {
410		value.0
411	}
412}
413
414impl Serialize for ColumnPropertyId {
415	fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
416	where
417		S: Serializer,
418	{
419		serializer.serialize_u64(self.0)
420	}
421}
422
423impl<'de> Deserialize<'de> for ColumnPropertyId {
424	fn deserialize<D>(deserializer: D) -> Result<ColumnPropertyId, D::Error>
425	where
426		D: Deserializer<'de>,
427	{
428		struct U64Visitor;
429
430		impl Visitor<'_> for U64Visitor {
431			type Value = ColumnPropertyId;
432
433			fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
434				formatter.write_str("an unsigned 64-bit number")
435			}
436
437			fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E> {
438				Ok(ColumnPropertyId(value))
439			}
440		}
441
442		deserializer.deserialize_u64(U64Visitor)
443	}
444}
445
446#[repr(transparent)]
447#[derive(Debug, Copy, Clone, PartialOrd, PartialEq, Ord, Eq, Hash)]
448pub struct NamespaceId(pub u64);
449
450impl Display for NamespaceId {
451	fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
452		Display::fmt(&self.0, f)
453	}
454}
455
456impl Deref for NamespaceId {
457	type Target = u64;
458
459	fn deref(&self) -> &Self::Target {
460		&self.0
461	}
462}
463
464impl PartialEq<u64> for NamespaceId {
465	fn eq(&self, other: &u64) -> bool {
466		self.0.eq(other)
467	}
468}
469
470impl From<NamespaceId> for u64 {
471	fn from(value: NamespaceId) -> Self {
472		value.0
473	}
474}
475
476impl Serialize for NamespaceId {
477	fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
478	where
479		S: Serializer,
480	{
481		serializer.serialize_u64(self.0)
482	}
483}
484
485impl<'de> Deserialize<'de> for NamespaceId {
486	fn deserialize<D>(deserializer: D) -> Result<NamespaceId, D::Error>
487	where
488		D: Deserializer<'de>,
489	{
490		struct U64Visitor;
491
492		impl Visitor<'_> for U64Visitor {
493			type Value = NamespaceId;
494
495			fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
496				formatter.write_str("an unsigned 64-bit number")
497			}
498
499			fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E> {
500				Ok(NamespaceId(value))
501			}
502		}
503
504		deserializer.deserialize_u64(U64Visitor)
505	}
506}
507
508#[repr(transparent)]
509#[derive(Debug, Copy, Clone, PartialOrd, PartialEq, Ord, Eq, Hash)]
510pub struct TableId(pub u64);
511
512impl Display for TableId {
513	fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
514		Display::fmt(&self.0, f)
515	}
516}
517
518impl Deref for TableId {
519	type Target = u64;
520
521	fn deref(&self) -> &Self::Target {
522		&self.0
523	}
524}
525
526impl PartialEq<u64> for TableId {
527	fn eq(&self, other: &u64) -> bool {
528		self.0.eq(other)
529	}
530}
531
532impl From<TableId> for u64 {
533	fn from(value: TableId) -> Self {
534		value.0
535	}
536}
537
538impl TableId {
539	pub const SOURCE_COMPLETENESS: TableId = TableId(1034);
540
541	#[inline]
542	pub fn to_u64(self) -> u64 {
543		self.0
544	}
545}
546
547impl From<i32> for TableId {
548	fn from(value: i32) -> Self {
549		Self(value as u64)
550	}
551}
552
553impl From<u64> for TableId {
554	fn from(value: u64) -> Self {
555		Self(value)
556	}
557}
558
559impl Serialize for TableId {
560	fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
561	where
562		S: Serializer,
563	{
564		serializer.serialize_u64(self.0)
565	}
566}
567
568impl<'de> Deserialize<'de> for TableId {
569	fn deserialize<D>(deserializer: D) -> Result<TableId, D::Error>
570	where
571		D: Deserializer<'de>,
572	{
573		struct U64Visitor;
574
575		impl Visitor<'_> for U64Visitor {
576			type Value = TableId;
577
578			fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
579				formatter.write_str("an unsigned 64-bit number")
580			}
581
582			fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E> {
583				Ok(TableId(value))
584			}
585		}
586
587		deserializer.deserialize_u64(U64Visitor)
588	}
589}
590
591#[repr(transparent)]
592#[derive(Debug, Copy, Clone, PartialOrd, PartialEq, Ord, Eq, Hash)]
593pub struct ViewId(pub u64);
594
595impl Display for ViewId {
596	fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
597		Display::fmt(&self.0, f)
598	}
599}
600
601impl Deref for ViewId {
602	type Target = u64;
603
604	fn deref(&self) -> &Self::Target {
605		&self.0
606	}
607}
608
609impl PartialEq<u64> for ViewId {
610	fn eq(&self, other: &u64) -> bool {
611		self.0.eq(other)
612	}
613}
614
615impl From<ViewId> for u64 {
616	fn from(value: ViewId) -> Self {
617		value.0
618	}
619}
620
621impl ViewId {
622	#[inline]
623	pub fn to_u64(self) -> u64 {
624		self.0
625	}
626}
627
628impl From<i32> for ViewId {
629	fn from(value: i32) -> Self {
630		Self(value as u64)
631	}
632}
633
634impl From<u64> for ViewId {
635	fn from(value: u64) -> Self {
636		Self(value)
637	}
638}
639
640impl Serialize for ViewId {
641	fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
642	where
643		S: Serializer,
644	{
645		serializer.serialize_u64(self.0)
646	}
647}
648
649impl<'de> Deserialize<'de> for ViewId {
650	fn deserialize<D>(deserializer: D) -> Result<ViewId, D::Error>
651	where
652		D: Deserializer<'de>,
653	{
654		struct U64Visitor;
655
656		impl Visitor<'_> for U64Visitor {
657			type Value = ViewId;
658
659			fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
660				formatter.write_str("an unsigned 64-bit number")
661			}
662
663			fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E> {
664				Ok(ViewId(value))
665			}
666		}
667
668		deserializer.deserialize_u64(U64Visitor)
669	}
670}
671
672#[repr(transparent)]
673#[derive(Debug, Copy, Clone, PartialOrd, PartialEq, Ord, Eq, Hash)]
674pub struct PrimaryKeyId(pub u64);
675
676impl Display for PrimaryKeyId {
677	fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
678		Display::fmt(&self.0, f)
679	}
680}
681
682impl Deref for PrimaryKeyId {
683	type Target = u64;
684
685	fn deref(&self) -> &Self::Target {
686		&self.0
687	}
688}
689
690impl PartialEq<u64> for PrimaryKeyId {
691	fn eq(&self, other: &u64) -> bool {
692		self.0.eq(other)
693	}
694}
695
696impl From<PrimaryKeyId> for u64 {
697	fn from(value: PrimaryKeyId) -> Self {
698		value.0
699	}
700}
701
702impl From<i32> for PrimaryKeyId {
703	fn from(value: i32) -> Self {
704		Self(value as u64)
705	}
706}
707
708impl From<u64> for PrimaryKeyId {
709	fn from(value: u64) -> Self {
710		Self(value)
711	}
712}
713
714impl Serialize for PrimaryKeyId {
715	fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
716	where
717		S: Serializer,
718	{
719		serializer.serialize_u64(self.0)
720	}
721}
722
723impl<'de> Deserialize<'de> for PrimaryKeyId {
724	fn deserialize<D>(deserializer: D) -> Result<PrimaryKeyId, D::Error>
725	where
726		D: Deserializer<'de>,
727	{
728		struct U64Visitor;
729
730		impl Visitor<'_> for U64Visitor {
731			type Value = PrimaryKeyId;
732
733			fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
734				formatter.write_str("an unsigned 64-bit number")
735			}
736
737			fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E> {
738				Ok(PrimaryKeyId(value))
739			}
740		}
741
742		deserializer.deserialize_u64(U64Visitor)
743	}
744}
745
746#[repr(transparent)]
747#[derive(Debug, Copy, Clone, PartialOrd, PartialEq, Ord, Eq, Hash)]
748pub struct RelationshipId(pub u64);
749
750impl Display for RelationshipId {
751	fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
752		Display::fmt(&self.0, f)
753	}
754}
755
756impl Deref for RelationshipId {
757	type Target = u64;
758
759	fn deref(&self) -> &Self::Target {
760		&self.0
761	}
762}
763
764impl PartialEq<u64> for RelationshipId {
765	fn eq(&self, other: &u64) -> bool {
766		self.0.eq(other)
767	}
768}
769
770impl From<RelationshipId> for u64 {
771	fn from(value: RelationshipId) -> Self {
772		value.0
773	}
774}
775
776impl From<i32> for RelationshipId {
777	fn from(value: i32) -> Self {
778		Self(value as u64)
779	}
780}
781
782impl From<u64> for RelationshipId {
783	fn from(value: u64) -> Self {
784		Self(value)
785	}
786}
787
788impl Serialize for RelationshipId {
789	fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
790	where
791		S: Serializer,
792	{
793		serializer.serialize_u64(self.0)
794	}
795}
796
797impl<'de> Deserialize<'de> for RelationshipId {
798	fn deserialize<D>(deserializer: D) -> Result<RelationshipId, D::Error>
799	where
800		D: Deserializer<'de>,
801	{
802		struct U64Visitor;
803
804		impl Visitor<'_> for U64Visitor {
805			type Value = RelationshipId;
806
807			fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
808				formatter.write_str("an unsigned 64-bit number")
809			}
810
811			fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E> {
812				Ok(RelationshipId(value))
813			}
814		}
815
816		deserializer.deserialize_u64(U64Visitor)
817	}
818}
819
820#[repr(transparent)]
821#[derive(Debug, Copy, Clone, PartialOrd, PartialEq, Ord, Eq, Hash)]
822pub struct RingBufferId(pub u64);
823
824impl RingBufferId {
825	pub const REQUEST_HISTORY: RingBufferId = RingBufferId(1);
826	pub const STATEMENT_STATS: RingBufferId = RingBufferId(2);
827}
828
829impl Display for RingBufferId {
830	fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
831		Display::fmt(&self.0, f)
832	}
833}
834
835impl Deref for RingBufferId {
836	type Target = u64;
837
838	fn deref(&self) -> &Self::Target {
839		&self.0
840	}
841}
842
843impl PartialEq<u64> for RingBufferId {
844	fn eq(&self, other: &u64) -> bool {
845		self.0.eq(other)
846	}
847}
848
849impl From<RingBufferId> for u64 {
850	fn from(value: RingBufferId) -> Self {
851		value.0
852	}
853}
854
855impl RingBufferId {
856	#[inline]
857	pub fn to_u64(self) -> u64 {
858		self.0
859	}
860}
861
862impl From<i32> for RingBufferId {
863	fn from(value: i32) -> Self {
864		Self(value as u64)
865	}
866}
867
868impl From<u64> for RingBufferId {
869	fn from(value: u64) -> Self {
870		Self(value)
871	}
872}
873
874impl Serialize for RingBufferId {
875	fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
876	where
877		S: Serializer,
878	{
879		serializer.serialize_u64(self.0)
880	}
881}
882
883impl<'de> Deserialize<'de> for RingBufferId {
884	fn deserialize<D>(deserializer: D) -> Result<RingBufferId, D::Error>
885	where
886		D: Deserializer<'de>,
887	{
888		struct U64Visitor;
889
890		impl Visitor<'_> for U64Visitor {
891			type Value = RingBufferId;
892
893			fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
894				formatter.write_str("an unsigned 64-bit number")
895			}
896
897			fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E> {
898				Ok(RingBufferId(value))
899			}
900		}
901
902		deserializer.deserialize_u64(U64Visitor)
903	}
904}
905
906#[repr(transparent)]
907#[derive(Debug, Copy, Clone, PartialOrd, PartialEq, Ord, Eq, Hash)]
908pub struct QueueId(pub u64);
909
910impl Display for QueueId {
911	fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
912		Display::fmt(&self.0, f)
913	}
914}
915
916impl Deref for QueueId {
917	type Target = u64;
918
919	fn deref(&self) -> &Self::Target {
920		&self.0
921	}
922}
923
924impl PartialEq<u64> for QueueId {
925	fn eq(&self, other: &u64) -> bool {
926		self.0.eq(other)
927	}
928}
929
930impl From<QueueId> for u64 {
931	fn from(value: QueueId) -> Self {
932		value.0
933	}
934}
935
936impl QueueId {
937	#[inline]
938	pub fn to_u64(self) -> u64 {
939		self.0
940	}
941}
942
943impl From<i32> for QueueId {
944	fn from(value: i32) -> Self {
945		Self(value as u64)
946	}
947}
948
949impl From<u64> for QueueId {
950	fn from(value: u64) -> Self {
951		Self(value)
952	}
953}
954
955impl Serialize for QueueId {
956	fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
957	where
958		S: Serializer,
959	{
960		serializer.serialize_u64(self.0)
961	}
962}
963
964impl<'de> Deserialize<'de> for QueueId {
965	fn deserialize<D>(deserializer: D) -> Result<QueueId, D::Error>
966	where
967		D: Deserializer<'de>,
968	{
969		struct U64Visitor;
970
971		impl Visitor<'_> for U64Visitor {
972			type Value = QueueId;
973
974			fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
975				formatter.write_str("an unsigned 64-bit number")
976			}
977
978			fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E> {
979				Ok(QueueId(value))
980			}
981		}
982
983		deserializer.deserialize_u64(U64Visitor)
984	}
985}
986
987#[repr(transparent)]
988#[derive(Debug, Copy, Clone, PartialOrd, PartialEq, Ord, Eq, Hash)]
989pub struct ProcedureId(u64);
990
991impl ProcedureId {
992	pub const SYSTEM_RESERVED_START: u64 = 1 << 48;
993
994	pub const SYSTEM_CONFIG_SET: ProcedureId = ProcedureId::persistent(1);
995
996	pub const fn persistent(id: u64) -> Self {
997		assert!(id < Self::SYSTEM_RESERVED_START, "persistent ProcedureId must be below SYSTEM_RESERVED_START");
998		Self(id)
999	}
1000
1001	pub fn ephemeral_of(namespace: NamespaceId, name: &str) -> Self {
1002		let mut buf = Vec::with_capacity(8 + name.len());
1003		buf.extend_from_slice(&namespace.0.to_le_bytes());
1004		buf.extend_from_slice(name.as_bytes());
1005		Self(xxh3_64(&buf).0 | Self::SYSTEM_RESERVED_START)
1006	}
1007
1008	pub const fn from_raw(id: u64) -> Self {
1009		Self(id)
1010	}
1011
1012	pub const fn is_ephemeral(&self) -> bool {
1013		self.0 >= Self::SYSTEM_RESERVED_START
1014	}
1015}
1016
1017impl Display for ProcedureId {
1018	fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
1019		Display::fmt(&self.0, f)
1020	}
1021}
1022
1023impl Deref for ProcedureId {
1024	type Target = u64;
1025
1026	fn deref(&self) -> &Self::Target {
1027		&self.0
1028	}
1029}
1030
1031impl PartialEq<u64> for ProcedureId {
1032	fn eq(&self, other: &u64) -> bool {
1033		self.0.eq(other)
1034	}
1035}
1036
1037impl From<ProcedureId> for u64 {
1038	fn from(value: ProcedureId) -> Self {
1039		value.0
1040	}
1041}
1042
1043impl Serialize for ProcedureId {
1044	fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1045	where
1046		S: Serializer,
1047	{
1048		serializer.serialize_u64(self.0)
1049	}
1050}
1051
1052impl<'de> Deserialize<'de> for ProcedureId {
1053	fn deserialize<D>(deserializer: D) -> Result<ProcedureId, D::Error>
1054	where
1055		D: Deserializer<'de>,
1056	{
1057		struct U64Visitor;
1058
1059		impl Visitor<'_> for U64Visitor {
1060			type Value = ProcedureId;
1061
1062			fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
1063				formatter.write_str("an unsigned 64-bit number")
1064			}
1065
1066			fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E> {
1067				Ok(ProcedureId::from_raw(value))
1068			}
1069		}
1070
1071		deserializer.deserialize_u64(U64Visitor)
1072	}
1073}
1074
1075#[repr(transparent)]
1076#[derive(Debug, Copy, Clone, PartialOrd, PartialEq, Ord, Eq, Hash)]
1077pub struct TestId(pub u64);
1078
1079impl Display for TestId {
1080	fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
1081		Display::fmt(&self.0, f)
1082	}
1083}
1084
1085impl Deref for TestId {
1086	type Target = u64;
1087
1088	fn deref(&self) -> &Self::Target {
1089		&self.0
1090	}
1091}
1092
1093impl PartialEq<u64> for TestId {
1094	fn eq(&self, other: &u64) -> bool {
1095		self.0.eq(other)
1096	}
1097}
1098
1099impl From<TestId> for u64 {
1100	fn from(value: TestId) -> Self {
1101		value.0
1102	}
1103}
1104
1105impl From<i32> for TestId {
1106	fn from(value: i32) -> Self {
1107		Self(value as u64)
1108	}
1109}
1110
1111impl From<u64> for TestId {
1112	fn from(value: u64) -> Self {
1113		Self(value)
1114	}
1115}
1116
1117impl Serialize for TestId {
1118	fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1119	where
1120		S: Serializer,
1121	{
1122		serializer.serialize_u64(self.0)
1123	}
1124}
1125
1126impl<'de> Deserialize<'de> for TestId {
1127	fn deserialize<D>(deserializer: D) -> Result<TestId, D::Error>
1128	where
1129		D: Deserializer<'de>,
1130	{
1131		struct U64Visitor;
1132
1133		impl Visitor<'_> for U64Visitor {
1134			type Value = TestId;
1135
1136			fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
1137				formatter.write_str("an unsigned 64-bit number")
1138			}
1139
1140			fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E> {
1141				Ok(TestId(value))
1142			}
1143		}
1144
1145		deserializer.deserialize_u64(U64Visitor)
1146	}
1147}
1148
1149#[repr(transparent)]
1150#[derive(Debug, Copy, Clone, PartialOrd, PartialEq, Ord, Eq, Hash)]
1151pub struct SubscriptionId(pub u64);
1152
1153impl Display for SubscriptionId {
1154	fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
1155		Display::fmt(&self.0, f)
1156	}
1157}
1158
1159impl Deref for SubscriptionId {
1160	type Target = u64;
1161
1162	fn deref(&self) -> &Self::Target {
1163		&self.0
1164	}
1165}
1166
1167impl PartialEq<u64> for SubscriptionId {
1168	fn eq(&self, other: &u64) -> bool {
1169		self.0.eq(other)
1170	}
1171}
1172
1173impl From<SubscriptionId> for u64 {
1174	fn from(value: SubscriptionId) -> Self {
1175		value.0
1176	}
1177}
1178
1179impl From<u64> for SubscriptionId {
1180	fn from(value: u64) -> Self {
1181		Self(value)
1182	}
1183}
1184
1185impl Serialize for SubscriptionId {
1186	fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1187	where
1188		S: Serializer,
1189	{
1190		serializer.serialize_u64(self.0)
1191	}
1192}
1193
1194impl<'de> Deserialize<'de> for SubscriptionId {
1195	fn deserialize<D>(deserializer: D) -> Result<SubscriptionId, D::Error>
1196	where
1197		D: Deserializer<'de>,
1198	{
1199		struct U64Visitor;
1200
1201		impl Visitor<'_> for U64Visitor {
1202			type Value = SubscriptionId;
1203
1204			fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
1205				formatter.write_str("an unsigned 64-bit number")
1206			}
1207
1208			fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E> {
1209				Ok(SubscriptionId(value))
1210			}
1211		}
1212
1213		deserializer.deserialize_u64(U64Visitor)
1214	}
1215}
1216
1217#[repr(transparent)]
1218#[derive(Debug, Copy, Clone, PartialOrd, PartialEq, Ord, Eq, Hash)]
1219pub struct SequenceId(pub u64);
1220
1221impl Deref for SequenceId {
1222	type Target = u64;
1223
1224	fn deref(&self) -> &Self::Target {
1225		&self.0
1226	}
1227}
1228
1229impl PartialEq<u64> for SequenceId {
1230	fn eq(&self, other: &u64) -> bool {
1231		self.0.eq(other)
1232	}
1233}
1234
1235impl Serialize for SequenceId {
1236	fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1237	where
1238		S: Serializer,
1239	{
1240		serializer.serialize_u64(self.0)
1241	}
1242}
1243
1244impl<'de> Deserialize<'de> for SequenceId {
1245	fn deserialize<D>(deserializer: D) -> Result<SequenceId, D::Error>
1246	where
1247		D: Deserializer<'de>,
1248	{
1249		struct U64Visitor;
1250
1251		impl Visitor<'_> for U64Visitor {
1252			type Value = SequenceId;
1253
1254			fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
1255				formatter.write_str("an unsigned 64-bit number")
1256			}
1257
1258			fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E> {
1259				Ok(SequenceId(value))
1260			}
1261		}
1262
1263		deserializer.deserialize_u64(U64Visitor)
1264	}
1265}
1266
1267#[repr(transparent)]
1268#[derive(Debug, Copy, Clone, PartialOrd, PartialEq, Ord, Eq, Hash)]
1269pub struct SubscriptionColumnId(pub u64);
1270
1271impl Display for SubscriptionColumnId {
1272	fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
1273		Display::fmt(&self.0, f)
1274	}
1275}
1276
1277impl Deref for SubscriptionColumnId {
1278	type Target = u64;
1279
1280	fn deref(&self) -> &Self::Target {
1281		&self.0
1282	}
1283}
1284
1285impl PartialEq<u64> for SubscriptionColumnId {
1286	fn eq(&self, other: &u64) -> bool {
1287		self.0.eq(other)
1288	}
1289}
1290
1291impl From<SubscriptionColumnId> for u64 {
1292	fn from(value: SubscriptionColumnId) -> Self {
1293		value.0
1294	}
1295}
1296
1297impl From<i32> for SubscriptionColumnId {
1298	fn from(value: i32) -> Self {
1299		Self(value as u64)
1300	}
1301}
1302
1303impl From<u64> for SubscriptionColumnId {
1304	fn from(value: u64) -> Self {
1305		Self(value)
1306	}
1307}
1308
1309impl Serialize for SubscriptionColumnId {
1310	fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1311	where
1312		S: Serializer,
1313	{
1314		serializer.serialize_u64(self.0)
1315	}
1316}
1317
1318impl<'de> Deserialize<'de> for SubscriptionColumnId {
1319	fn deserialize<D>(deserializer: D) -> Result<SubscriptionColumnId, D::Error>
1320	where
1321		D: Deserializer<'de>,
1322	{
1323		struct U64Visitor;
1324
1325		impl Visitor<'_> for U64Visitor {
1326			type Value = SubscriptionColumnId;
1327
1328			fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
1329				formatter.write_str("an unsigned 64-bit number")
1330			}
1331
1332			fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E> {
1333				Ok(SubscriptionColumnId(value))
1334			}
1335		}
1336
1337		deserializer.deserialize_u64(U64Visitor)
1338	}
1339}
1340
1341#[repr(transparent)]
1342#[derive(Debug, Copy, Clone, PartialOrd, PartialEq, Ord, Eq, Hash)]
1343pub struct SeriesId(pub u64);
1344
1345impl Display for SeriesId {
1346	fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
1347		Display::fmt(&self.0, f)
1348	}
1349}
1350
1351impl Deref for SeriesId {
1352	type Target = u64;
1353
1354	fn deref(&self) -> &Self::Target {
1355		&self.0
1356	}
1357}
1358
1359impl PartialEq<u64> for SeriesId {
1360	fn eq(&self, other: &u64) -> bool {
1361		self.0.eq(other)
1362	}
1363}
1364
1365impl From<SeriesId> for u64 {
1366	fn from(value: SeriesId) -> Self {
1367		value.0
1368	}
1369}
1370
1371impl SeriesId {
1372	pub const RUNTIME_MEMORY_SNAPSHOTS: SeriesId = SeriesId(1024);
1373	pub const RUNTIME_WATERMARKS_SNAPSHOTS: SeriesId = SeriesId(1025);
1374	pub const RUNTIME_OPERATORS_SNAPSHOTS: SeriesId = SeriesId(1026);
1375	pub const PROFILER_SPANS_SNAPSHOTS: SeriesId = SeriesId(1027);
1376	pub const INSTRUMENTS_SNAPSHOTS: SeriesId = SeriesId(1028);
1377	pub const EPOCH_SNAPSHOTS: SeriesId = SeriesId(1030);
1378	pub const LIFECYCLE_SNAPSHOTS: SeriesId = SeriesId(1031);
1379	pub const STORAGE_SNAPSHOTS: SeriesId = SeriesId(1032);
1380	pub const CDC_SNAPSHOTS: SeriesId = SeriesId(1033);
1381	pub const FLOW_STATE_SNAPSHOTS: SeriesId = SeriesId(1035);
1382
1383	#[inline]
1384	pub fn to_u64(self) -> u64 {
1385		self.0
1386	}
1387}
1388
1389impl From<i32> for SeriesId {
1390	fn from(value: i32) -> Self {
1391		Self(value as u64)
1392	}
1393}
1394
1395impl From<u64> for SeriesId {
1396	fn from(value: u64) -> Self {
1397		Self(value)
1398	}
1399}
1400
1401impl Serialize for SeriesId {
1402	fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1403	where
1404		S: Serializer,
1405	{
1406		serializer.serialize_u64(self.0)
1407	}
1408}
1409
1410impl<'de> Deserialize<'de> for SeriesId {
1411	fn deserialize<D>(deserializer: D) -> Result<SeriesId, D::Error>
1412	where
1413		D: Deserializer<'de>,
1414	{
1415		struct U64Visitor;
1416
1417		impl Visitor<'_> for U64Visitor {
1418			type Value = SeriesId;
1419
1420			fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
1421				formatter.write_str("an unsigned 64-bit number")
1422			}
1423
1424			fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E> {
1425				Ok(SeriesId(value))
1426			}
1427		}
1428
1429		deserializer.deserialize_u64(U64Visitor)
1430	}
1431}
1432
1433#[repr(transparent)]
1434#[derive(Debug, Copy, Clone, PartialOrd, PartialEq, Ord, Eq, Hash)]
1435pub struct HandlerId(pub u64);
1436
1437impl Display for HandlerId {
1438	fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
1439		Display::fmt(&self.0, f)
1440	}
1441}
1442
1443impl Deref for HandlerId {
1444	type Target = u64;
1445
1446	fn deref(&self) -> &Self::Target {
1447		&self.0
1448	}
1449}
1450
1451impl PartialEq<u64> for HandlerId {
1452	fn eq(&self, other: &u64) -> bool {
1453		self.0.eq(other)
1454	}
1455}
1456
1457impl From<HandlerId> for u64 {
1458	fn from(value: HandlerId) -> Self {
1459		value.0
1460	}
1461}
1462
1463impl From<i32> for HandlerId {
1464	fn from(value: i32) -> Self {
1465		Self(value as u64)
1466	}
1467}
1468
1469impl From<u64> for HandlerId {
1470	fn from(value: u64) -> Self {
1471		Self(value)
1472	}
1473}
1474
1475impl Serialize for HandlerId {
1476	fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1477	where
1478		S: Serializer,
1479	{
1480		serializer.serialize_u64(self.0)
1481	}
1482}
1483
1484impl<'de> Deserialize<'de> for HandlerId {
1485	fn deserialize<D>(deserializer: D) -> Result<HandlerId, D::Error>
1486	where
1487		D: Deserializer<'de>,
1488	{
1489		struct U64Visitor;
1490
1491		impl Visitor<'_> for U64Visitor {
1492			type Value = HandlerId;
1493
1494			fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
1495				formatter.write_str("an unsigned 64-bit number")
1496			}
1497
1498			fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E> {
1499				Ok(HandlerId(value))
1500			}
1501		}
1502
1503		deserializer.deserialize_u64(U64Visitor)
1504	}
1505}
1506
1507#[repr(transparent)]
1508#[derive(Debug, Copy, Clone, PartialOrd, PartialEq, Ord, Eq, Hash)]
1509pub struct MigrationId(pub u64);
1510
1511impl Display for MigrationId {
1512	fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
1513		Display::fmt(&self.0, f)
1514	}
1515}
1516
1517impl Deref for MigrationId {
1518	type Target = u64;
1519
1520	fn deref(&self) -> &Self::Target {
1521		&self.0
1522	}
1523}
1524
1525impl PartialEq<u64> for MigrationId {
1526	fn eq(&self, other: &u64) -> bool {
1527		self.0.eq(other)
1528	}
1529}
1530
1531impl From<MigrationId> for u64 {
1532	fn from(value: MigrationId) -> Self {
1533		value.0
1534	}
1535}
1536
1537impl From<i32> for MigrationId {
1538	fn from(value: i32) -> Self {
1539		Self(value as u64)
1540	}
1541}
1542
1543impl From<u64> for MigrationId {
1544	fn from(value: u64) -> Self {
1545		Self(value)
1546	}
1547}
1548
1549impl Serialize for MigrationId {
1550	fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1551	where
1552		S: Serializer,
1553	{
1554		serializer.serialize_u64(self.0)
1555	}
1556}
1557
1558impl<'de> Deserialize<'de> for MigrationId {
1559	fn deserialize<D>(deserializer: D) -> Result<MigrationId, D::Error>
1560	where
1561		D: Deserializer<'de>,
1562	{
1563		struct U64Visitor;
1564
1565		impl Visitor<'_> for U64Visitor {
1566			type Value = MigrationId;
1567
1568			fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
1569				formatter.write_str("an unsigned 64-bit number")
1570			}
1571
1572			fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E> {
1573				Ok(MigrationId(value))
1574			}
1575		}
1576
1577		deserializer.deserialize_u64(U64Visitor)
1578	}
1579}
1580
1581#[repr(transparent)]
1582#[derive(Debug, Copy, Clone, PartialOrd, PartialEq, Ord, Eq, Hash)]
1583pub struct MigrationEventId(pub u64);
1584
1585impl Display for MigrationEventId {
1586	fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
1587		Display::fmt(&self.0, f)
1588	}
1589}
1590
1591impl Deref for MigrationEventId {
1592	type Target = u64;
1593
1594	fn deref(&self) -> &Self::Target {
1595		&self.0
1596	}
1597}
1598
1599impl PartialEq<u64> for MigrationEventId {
1600	fn eq(&self, other: &u64) -> bool {
1601		self.0.eq(other)
1602	}
1603}
1604
1605impl From<MigrationEventId> for u64 {
1606	fn from(value: MigrationEventId) -> Self {
1607		value.0
1608	}
1609}
1610
1611impl From<i32> for MigrationEventId {
1612	fn from(value: i32) -> Self {
1613		Self(value as u64)
1614	}
1615}
1616
1617impl From<u64> for MigrationEventId {
1618	fn from(value: u64) -> Self {
1619		Self(value)
1620	}
1621}
1622
1623impl Serialize for MigrationEventId {
1624	fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1625	where
1626		S: Serializer,
1627	{
1628		serializer.serialize_u64(self.0)
1629	}
1630}
1631
1632impl<'de> Deserialize<'de> for MigrationEventId {
1633	fn deserialize<D>(deserializer: D) -> Result<MigrationEventId, D::Error>
1634	where
1635		D: Deserializer<'de>,
1636	{
1637		struct U64Visitor;
1638
1639		impl Visitor<'_> for U64Visitor {
1640			type Value = MigrationEventId;
1641
1642			fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
1643				formatter.write_str("an unsigned 64-bit number")
1644			}
1645
1646			fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E> {
1647				Ok(MigrationEventId(value))
1648			}
1649		}
1650
1651		deserializer.deserialize_u64(U64Visitor)
1652	}
1653}
1654
1655#[repr(transparent)]
1656#[derive(Debug, Copy, Clone, PartialOrd, PartialEq, Ord, Eq, Hash)]
1657pub struct SourceId(pub u64);
1658
1659impl Display for SourceId {
1660	fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
1661		Display::fmt(&self.0, f)
1662	}
1663}
1664
1665impl Deref for SourceId {
1666	type Target = u64;
1667
1668	fn deref(&self) -> &Self::Target {
1669		&self.0
1670	}
1671}
1672
1673impl PartialEq<u64> for SourceId {
1674	fn eq(&self, other: &u64) -> bool {
1675		self.0.eq(other)
1676	}
1677}
1678
1679impl From<SourceId> for u64 {
1680	fn from(value: SourceId) -> Self {
1681		value.0
1682	}
1683}
1684
1685impl From<u64> for SourceId {
1686	fn from(value: u64) -> Self {
1687		Self(value)
1688	}
1689}
1690
1691impl Serialize for SourceId {
1692	fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1693	where
1694		S: Serializer,
1695	{
1696		serializer.serialize_u64(self.0)
1697	}
1698}
1699
1700impl<'de> Deserialize<'de> for SourceId {
1701	fn deserialize<D>(deserializer: D) -> Result<SourceId, D::Error>
1702	where
1703		D: Deserializer<'de>,
1704	{
1705		struct U64Visitor;
1706
1707		impl Visitor<'_> for U64Visitor {
1708			type Value = SourceId;
1709
1710			fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
1711				formatter.write_str("an unsigned 64-bit number")
1712			}
1713
1714			fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E> {
1715				Ok(SourceId(value))
1716			}
1717		}
1718
1719		deserializer.deserialize_u64(U64Visitor)
1720	}
1721}
1722
1723#[repr(transparent)]
1724#[derive(Debug, Copy, Clone, PartialOrd, PartialEq, Ord, Eq, Hash)]
1725pub struct BindingId(pub u64);
1726
1727impl Display for BindingId {
1728	fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
1729		Display::fmt(&self.0, f)
1730	}
1731}
1732
1733impl Deref for BindingId {
1734	type Target = u64;
1735
1736	fn deref(&self) -> &Self::Target {
1737		&self.0
1738	}
1739}
1740
1741impl PartialEq<u64> for BindingId {
1742	fn eq(&self, other: &u64) -> bool {
1743		self.0.eq(other)
1744	}
1745}
1746
1747impl From<BindingId> for u64 {
1748	fn from(value: BindingId) -> Self {
1749		value.0
1750	}
1751}
1752
1753impl From<u64> for BindingId {
1754	fn from(value: u64) -> Self {
1755		Self(value)
1756	}
1757}
1758
1759impl Serialize for BindingId {
1760	fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1761	where
1762		S: Serializer,
1763	{
1764		serializer.serialize_u64(self.0)
1765	}
1766}
1767
1768impl<'de> Deserialize<'de> for BindingId {
1769	fn deserialize<D>(deserializer: D) -> Result<BindingId, D::Error>
1770	where
1771		D: Deserializer<'de>,
1772	{
1773		struct U64Visitor;
1774
1775		impl Visitor<'_> for U64Visitor {
1776			type Value = BindingId;
1777
1778			fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
1779				formatter.write_str("an unsigned 64-bit number")
1780			}
1781
1782			fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E> {
1783				Ok(BindingId(value))
1784			}
1785		}
1786
1787		deserializer.deserialize_u64(U64Visitor)
1788	}
1789}
1790
1791#[repr(transparent)]
1792#[derive(Debug, Copy, Clone, PartialOrd, PartialEq, Ord, Eq, Hash)]
1793pub struct ColumnBlockId(pub u64);
1794
1795impl Display for ColumnBlockId {
1796	fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
1797		Display::fmt(&self.0, f)
1798	}
1799}
1800
1801impl Deref for ColumnBlockId {
1802	type Target = u64;
1803
1804	fn deref(&self) -> &Self::Target {
1805		&self.0
1806	}
1807}
1808
1809impl PartialEq<u64> for ColumnBlockId {
1810	fn eq(&self, other: &u64) -> bool {
1811		self.0.eq(other)
1812	}
1813}
1814
1815impl From<ColumnBlockId> for u64 {
1816	fn from(value: ColumnBlockId) -> Self {
1817		value.0
1818	}
1819}
1820
1821impl From<u64> for ColumnBlockId {
1822	fn from(value: u64) -> Self {
1823		Self(value)
1824	}
1825}
1826
1827impl Serialize for ColumnBlockId {
1828	fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1829	where
1830		S: Serializer,
1831	{
1832		serializer.serialize_u64(self.0)
1833	}
1834}
1835
1836impl<'de> Deserialize<'de> for ColumnBlockId {
1837	fn deserialize<D>(deserializer: D) -> Result<ColumnBlockId, D::Error>
1838	where
1839		D: Deserializer<'de>,
1840	{
1841		struct U64Visitor;
1842
1843		impl Visitor<'_> for U64Visitor {
1844			type Value = ColumnBlockId;
1845
1846			fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
1847				formatter.write_str("an unsigned 64-bit number")
1848			}
1849
1850			fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E> {
1851				Ok(ColumnBlockId(value))
1852			}
1853		}
1854
1855		deserializer.deserialize_u64(U64Visitor)
1856	}
1857}
1858
1859#[repr(transparent)]
1860#[derive(Debug, Copy, Clone, PartialOrd, PartialEq, Ord, Eq, Hash)]
1861pub struct SinkId(pub u64);
1862
1863impl Display for SinkId {
1864	fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
1865		Display::fmt(&self.0, f)
1866	}
1867}
1868
1869impl Deref for SinkId {
1870	type Target = u64;
1871
1872	fn deref(&self) -> &Self::Target {
1873		&self.0
1874	}
1875}
1876
1877impl PartialEq<u64> for SinkId {
1878	fn eq(&self, other: &u64) -> bool {
1879		self.0.eq(other)
1880	}
1881}
1882
1883impl From<SinkId> for u64 {
1884	fn from(value: SinkId) -> Self {
1885		value.0
1886	}
1887}
1888
1889impl From<u64> for SinkId {
1890	fn from(value: u64) -> Self {
1891		Self(value)
1892	}
1893}
1894
1895impl Serialize for SinkId {
1896	fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1897	where
1898		S: Serializer,
1899	{
1900		serializer.serialize_u64(self.0)
1901	}
1902}
1903
1904impl<'de> Deserialize<'de> for SinkId {
1905	fn deserialize<D>(deserializer: D) -> Result<SinkId, D::Error>
1906	where
1907		D: Deserializer<'de>,
1908	{
1909		struct U64Visitor;
1910
1911		impl Visitor<'_> for U64Visitor {
1912			type Value = SinkId;
1913
1914			fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
1915				formatter.write_str("an unsigned 64-bit number")
1916			}
1917
1918			fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E> {
1919				Ok(SinkId(value))
1920			}
1921		}
1922
1923		deserializer.deserialize_u64(U64Visitor)
1924	}
1925}
1926
1927pub(crate) const RESERVED_USER_ID_START: u64 = 16385;
1928
1929const RESERVED_NAMESPACE_IDS: [u64; 53] = [
1930	NamespaceId::ROOT.0,
1931	NamespaceId::SYSTEM.0,
1932	NamespaceId::DEFAULT.0,
1933	NamespaceId::SYSTEM_CONFIG.0,
1934	NamespaceId::SYSTEM_METRICS.0,
1935	NamespaceId::SYSTEM_METRICS_STORAGE.0,
1936	NamespaceId::SYSTEM_METRICS_CDC.0,
1937	NamespaceId::SYSTEM_PROCEDURES.0,
1938	NamespaceId::SYSTEM_BINDINGS.0,
1939	NamespaceId::RQL.0,
1940	NamespaceId::SYSTEM_METRICS_PROFILER.0,
1941	NamespaceId::SYSTEM_METRICS_PROFILER_SPANS.0,
1942	NamespaceId::SYSTEM_METRICS_RUNTIME.0,
1943	NamespaceId::SYSTEM_METRICS_RUNTIME_MEMORY.0,
1944	NamespaceId::SYSTEM_METRICS_RUNTIME_WATERMARKS.0,
1945	NamespaceId::SYSTEM_METRICS_RUNTIME_OPERATORS.0,
1946	NamespaceId::SYSTEM_METRICS_PROC.0,
1947	NamespaceId::SYSTEM_METRICS_PROC_PROCESS.0,
1948	NamespaceId::SYSTEM_METRICS_PROC_PROCESS_IO.0,
1949	NamespaceId::SYSTEM_METRICS_PROC_PROCESS_MEMORY.0,
1950	NamespaceId::SYSTEM_METRICS_PROC_PROCESS_SCHED.0,
1951	NamespaceId::SYSTEM_METRICS_PROC_CGROUP.0,
1952	NamespaceId::SYSTEM_METRICS_PROC_CGROUP_IO.0,
1953	NamespaceId::SYSTEM_METRICS_PROC_CGROUP_MEMORY.0,
1954	NamespaceId::SYSTEM_METRICS_PROC_CGROUP_CPU.0,
1955	NamespaceId::SYSTEM_METRICS_PROC_CGROUP_PRESSURE.0,
1956	NamespaceId::SYSTEM_METRICS_STORE.0,
1957	NamespaceId::SYSTEM_METRICS_STORE_MULTI.0,
1958	NamespaceId::SYSTEM_METRICS_STORE_MULTI_COMMIT.0,
1959	NamespaceId::SYSTEM_METRICS_STORE_MULTI_PERSISTENT.0,
1960	NamespaceId::SYSTEM_METRICS_STORE_MULTI_RANGE.0,
1961	NamespaceId::SYSTEM_METRICS_STORE_MULTI_POINT.0,
1962	NamespaceId::SYSTEM_METRICS_STORE_SINGLE.0,
1963	NamespaceId::SYSTEM_METRICS_STORE_SINGLE_COMMIT.0,
1964	NamespaceId::SYSTEM_METRICS_STORE_SINGLE_PERSISTENT.0,
1965	NamespaceId::SYSTEM_METRICS_STORE_OPERATOR.0,
1966	NamespaceId::SYSTEM_METRICS_STORE_OPERATOR_RANGE.0,
1967	NamespaceId::SYSTEM_METRICS_STORE_OPERATOR_RANGE_KEYSPACE.0,
1968	NamespaceId::SYSTEM_METRICS_STORE_OPERATOR_PERSISTENT.0,
1969	NamespaceId::SYSTEM_METRICS_INSTRUMENTS.0,
1970	NamespaceId::SYSTEM_METRICS_EPOCH.0,
1971	NamespaceId::SYSTEM_METRICS_LIFECYCLE.0,
1972	NamespaceId::SYSTEM_SOURCE.0,
1973	NamespaceId::STORAGE.0,
1974	NamespaceId::SYSTEM_METRICS_FLOW.0,
1975	NamespaceId::SYSTEM_METRICS_FLOW_STATE.0,
1976	NamespaceId::SYSTEM_METRICS_STORE_CDC.0,
1977	NamespaceId::SYSTEM_METRICS_STORE_CDC_COMMIT.0,
1978	NamespaceId::SYSTEM_METRICS_STORE_CDC_READ.0,
1979	NamespaceId::SYSTEM_METRICS_STORE_CDC_PERSISTENT.0,
1980	NamespaceId::SYSTEM_FLOW.0,
1981	NamespaceId::SYSTEM_FLOW_OPERATOR.0,
1982	NamespaceId::SYSTEM_FLOW_OPERATOR_LIBRARY.0,
1983];
1984
1985const RESERVED_SOURCE_IDS: [u64; 13] = [
1986	RingBufferId::REQUEST_HISTORY.0,
1987	RingBufferId::STATEMENT_STATS.0,
1988	SeriesId::RUNTIME_MEMORY_SNAPSHOTS.0,
1989	SeriesId::RUNTIME_WATERMARKS_SNAPSHOTS.0,
1990	SeriesId::RUNTIME_OPERATORS_SNAPSHOTS.0,
1991	SeriesId::PROFILER_SPANS_SNAPSHOTS.0,
1992	SeriesId::INSTRUMENTS_SNAPSHOTS.0,
1993	SeriesId::EPOCH_SNAPSHOTS.0,
1994	SeriesId::LIFECYCLE_SNAPSHOTS.0,
1995	SeriesId::STORAGE_SNAPSHOTS.0,
1996	SeriesId::CDC_SNAPSHOTS.0,
1997	SeriesId::FLOW_STATE_SNAPSHOTS.0,
1998	TableId::SOURCE_COMPLETENESS.0,
1999];
2000
2001const RESERVED_RINGBUFFER_COLUMNS: [ColumnId; 18] = [
2002	ColumnId::REQUEST_HISTORY_TIMESTAMP,
2003	ColumnId::REQUEST_HISTORY_OPERATION,
2004	ColumnId::REQUEST_HISTORY_FINGERPRINT,
2005	ColumnId::REQUEST_HISTORY_TOTAL_DURATION,
2006	ColumnId::REQUEST_HISTORY_COMPUTE_DURATION,
2007	ColumnId::REQUEST_HISTORY_SUCCESS,
2008	ColumnId::REQUEST_HISTORY_STATEMENT_COUNT,
2009	ColumnId::REQUEST_HISTORY_NORMALIZED_RQL,
2010	ColumnId::STATEMENT_STATS_SNAPSHOT_TIMESTAMP,
2011	ColumnId::STATEMENT_STATS_FINGERPRINT,
2012	ColumnId::STATEMENT_STATS_NORMALIZED_RQL,
2013	ColumnId::STATEMENT_STATS_CALLS,
2014	ColumnId::STATEMENT_STATS_TOTAL_DURATION,
2015	ColumnId::STATEMENT_STATS_MEAN_DURATION,
2016	ColumnId::STATEMENT_STATS_MAX_DURATION,
2017	ColumnId::STATEMENT_STATS_MIN_DURATION,
2018	ColumnId::STATEMENT_STATS_TOTAL_ROWS,
2019	ColumnId::STATEMENT_STATS_ERRORS,
2020];
2021
2022const RESERVED_COLUMN_GROUPS: [&[ColumnId]; 11] = [
2023	&RESERVED_RINGBUFFER_COLUMNS,
2024	&ColumnId::RUNTIME_MEMORY_SNAPSHOTS_COLUMNS,
2025	&ColumnId::RUNTIME_WATERMARKS_SNAPSHOTS_COLUMNS,
2026	&ColumnId::RUNTIME_OPERATORS_SNAPSHOTS_COLUMNS,
2027	&ColumnId::INSTRUMENTS_SNAPSHOTS_COLUMNS,
2028	&ColumnId::PROFILER_SPANS_SNAPSHOTS_COLUMNS,
2029	&ColumnId::EPOCH_SNAPSHOTS_COLUMNS,
2030	&ColumnId::LIFECYCLE_SNAPSHOTS_COLUMNS,
2031	&ColumnId::STORAGE_SNAPSHOTS_COLUMNS,
2032	&ColumnId::CDC_SNAPSHOTS_COLUMNS,
2033	&ColumnId::SOURCE_COMPLETENESS_COLUMNS,
2034];
2035
2036const fn reserved_u64_all_below(values: &[u64], limit: u64) -> bool {
2037	let mut i = 0;
2038	while i < values.len() {
2039		if values[i] >= limit {
2040			return false;
2041		}
2042		i += 1;
2043	}
2044	true
2045}
2046
2047const fn reserved_u64_has_duplicate(values: &[u64]) -> bool {
2048	let mut i = 0;
2049	while i < values.len() {
2050		let mut j = i + 1;
2051		while j < values.len() {
2052			if values[i] == values[j] {
2053				return true;
2054			}
2055			j += 1;
2056		}
2057		i += 1;
2058	}
2059	false
2060}
2061
2062const fn reserved_columns_all_below(groups: &[&[ColumnId]], limit: u64) -> bool {
2063	let mut g = 0;
2064	while g < groups.len() {
2065		let group = groups[g];
2066		let mut i = 0;
2067		while i < group.len() {
2068			if group[i].0 >= limit {
2069				return false;
2070			}
2071			i += 1;
2072		}
2073		g += 1;
2074	}
2075	true
2076}
2077
2078const fn reserved_columns_has_duplicate(groups: &[&[ColumnId]]) -> bool {
2079	let mut g1 = 0;
2080	while g1 < groups.len() {
2081		let mut i1 = 0;
2082		while i1 < groups[g1].len() {
2083			let value = groups[g1][i1].0;
2084			let mut g2 = g1;
2085			let mut i2 = i1 + 1;
2086			while g2 < groups.len() {
2087				while i2 < groups[g2].len() {
2088					if groups[g2][i2].0 == value {
2089						return true;
2090					}
2091					i2 += 1;
2092				}
2093				g2 += 1;
2094				i2 = 0;
2095			}
2096			i1 += 1;
2097		}
2098		g1 += 1;
2099	}
2100	false
2101}
2102
2103const _: () = {
2104	assert!(
2105		reserved_u64_all_below(&RESERVED_SOURCE_IDS, RESERVED_USER_ID_START),
2106		"reserved system source id leaks into the user range"
2107	);
2108	assert!(!reserved_u64_has_duplicate(&RESERVED_SOURCE_IDS), "duplicate reserved system source id");
2109	assert!(
2110		reserved_columns_all_below(&RESERVED_COLUMN_GROUPS, RESERVED_USER_ID_START),
2111		"reserved system column id leaks into the user range"
2112	);
2113	assert!(!reserved_columns_has_duplicate(&RESERVED_COLUMN_GROUPS), "duplicate reserved system column id");
2114	assert!(
2115		reserved_u64_all_below(&RESERVED_NAMESPACE_IDS, RESERVED_USER_ID_START),
2116		"reserved system namespace id leaks into the user range"
2117	);
2118	assert!(!reserved_u64_has_duplicate(&RESERVED_NAMESPACE_IDS), "duplicate reserved system namespace id");
2119};
2120
2121#[cfg(test)]
2122mod reserved_id_tests {
2123	use std::collections::HashSet;
2124
2125	use super::{ColumnId, RingBufferId, SeriesId};
2126
2127	const USER_ID_START: u64 = 16385;
2128
2129	fn reserved_series_ids() -> [SeriesId; 9] {
2130		[
2131			SeriesId::RUNTIME_MEMORY_SNAPSHOTS,
2132			SeriesId::RUNTIME_WATERMARKS_SNAPSHOTS,
2133			SeriesId::RUNTIME_OPERATORS_SNAPSHOTS,
2134			SeriesId::INSTRUMENTS_SNAPSHOTS,
2135			SeriesId::PROFILER_SPANS_SNAPSHOTS,
2136			SeriesId::EPOCH_SNAPSHOTS,
2137			SeriesId::LIFECYCLE_SNAPSHOTS,
2138			SeriesId::STORAGE_SNAPSHOTS,
2139			SeriesId::CDC_SNAPSHOTS,
2140		]
2141	}
2142
2143	fn reserved_column_arrays() -> [&'static [ColumnId]; 9] {
2144		[
2145			&ColumnId::RUNTIME_MEMORY_SNAPSHOTS_COLUMNS,
2146			&ColumnId::RUNTIME_WATERMARKS_SNAPSHOTS_COLUMNS,
2147			&ColumnId::RUNTIME_OPERATORS_SNAPSHOTS_COLUMNS,
2148			&ColumnId::INSTRUMENTS_SNAPSHOTS_COLUMNS,
2149			&ColumnId::PROFILER_SPANS_SNAPSHOTS_COLUMNS,
2150			&ColumnId::EPOCH_SNAPSHOTS_COLUMNS,
2151			&ColumnId::LIFECYCLE_SNAPSHOTS_COLUMNS,
2152			&ColumnId::STORAGE_SNAPSHOTS_COLUMNS,
2153			&ColumnId::CDC_SNAPSHOTS_COLUMNS,
2154		]
2155	}
2156
2157	#[test]
2158	fn system_series_ids_are_reserved_unique_and_below_user_range() {
2159		let mut seen = HashSet::new();
2160		assert!(seen.insert(RingBufferId::REQUEST_HISTORY.0), "ringbuffer source id setup");
2161		assert!(seen.insert(RingBufferId::STATEMENT_STATS.0), "ringbuffer source id setup");
2162
2163		for id in reserved_series_ids() {
2164			assert!(id.0 < USER_ID_START, "system series id {} leaks into the user range", id.0);
2165			assert!(
2166				seen.insert(id.0),
2167				"system series id {} collides with another reserved source id",
2168				id.0
2169			);
2170		}
2171	}
2172
2173	#[test]
2174	fn system_column_ids_are_reserved_unique_and_below_user_range() {
2175		let mut seen = HashSet::new();
2176		for ringbuffer_column in 1..=18u64 {
2177			assert!(seen.insert(ringbuffer_column), "ringbuffer column id setup");
2178		}
2179
2180		let mut count = 0;
2181		for array in reserved_column_arrays() {
2182			for &id in array {
2183				assert!(id.0 < USER_ID_START, "system column id {} leaks into the user range", id.0);
2184				assert!(
2185					seen.insert(id.0),
2186					"system column id {} collides with another reserved column id",
2187					id.0
2188				);
2189				count += 1;
2190			}
2191		}
2192
2193		assert_eq!(count, 4 * 6 + 17 + 7 + 10 + 14 + 8, "expected exactly 80 reserved system column ids");
2194	}
2195
2196	#[test]
2197	fn snapshot_column_arrays_have_expected_widths() {
2198		// One array per domain, matching the published surface: a width drift here means the
2199		// series and the vtable of one domain disagree.
2200		let arrays = reserved_column_arrays();
2201		for array in &arrays[..4] {
2202			assert_eq!(array.len(), 6, "long-format snapshot series must declare 6 column ids");
2203		}
2204		assert_eq!(arrays[4].len(), 17, "spans snapshot series must declare 17 column ids");
2205		assert_eq!(arrays[5].len(), 7, "epoch snapshot series must declare 7 column ids");
2206		assert_eq!(arrays[6].len(), 10, "lifecycle snapshot series must declare 10 column ids");
2207		assert_eq!(arrays[7].len(), 14, "storage snapshot series must declare 14 column ids");
2208		assert_eq!(arrays[8].len(), 8, "cdc snapshot series must declare 8 column ids");
2209	}
2210}
2211
2212#[cfg(test)]
2213mod ephemeral_procedure_id_tests {
2214	use super::{NamespaceId, ProcedureId};
2215
2216	#[test]
2217	fn same_namespace_and_name_yield_the_same_id() {
2218		let a = ProcedureId::ephemeral_of(NamespaceId(7), "refund");
2219		let b = ProcedureId::ephemeral_of(NamespaceId(7), "refund");
2220		assert_eq!(a, b, "a binding stored against this id must resolve after a restart");
2221	}
2222
2223	#[test]
2224	fn every_derived_id_lands_in_the_reserved_range() {
2225		for name in ["", "a", "refund", "\u{1f600}", &"x".repeat(4096)] {
2226			for ns in [0u64, 1, u64::MAX] {
2227				let id = ProcedureId::ephemeral_of(NamespaceId(ns), name);
2228				assert!(
2229					id.is_ephemeral(),
2230					"derived id for `{}` in namespace {} escaped the reserved range",
2231					name,
2232					ns
2233				);
2234			}
2235		}
2236	}
2237
2238	#[test]
2239	fn the_same_name_in_two_namespaces_yields_two_ids() {
2240		let a = ProcedureId::ephemeral_of(NamespaceId(7), "refund");
2241		let b = ProcedureId::ephemeral_of(NamespaceId(8), "refund");
2242		assert_ne!(a, b);
2243	}
2244
2245	#[test]
2246	fn two_names_in_one_namespace_yield_two_ids() {
2247		let a = ProcedureId::ephemeral_of(NamespaceId(7), "refund");
2248		let b = ProcedureId::ephemeral_of(NamespaceId(7), "audit");
2249		assert_ne!(a, b);
2250	}
2251
2252	#[test]
2253	fn the_namespace_and_name_boundary_is_unambiguous() {
2254		let a = ProcedureId::ephemeral_of(NamespaceId(0), "\u{1}refund");
2255		let b = ProcedureId::ephemeral_of(
2256			NamespaceId(u64::from_le_bytes(*b"\x00\x00\x00\x00\x00\x00\x00\x01")),
2257			"refund",
2258		);
2259		assert_ne!(a, b);
2260	}
2261}