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