Skip to main content

uqa_sql/catalog/
oids.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! Stable identities for SQL catalog objects.
8
9pub fn stable_oid(kind: &str, name: &str) -> i64 {
10    let mut hash = 14_695_981_039_346_656_037_u64;
11    for byte in kind.bytes().chain(*b":").chain(name.bytes()) {
12        hash ^= u64::from(byte);
13        hash = hash.wrapping_mul(1_099_511_628_211);
14    }
15    10_000 + i64::try_from(hash % 2_000_000_000).unwrap_or(0)
16}
17
18pub fn stable_object_oid(kind: &str, object_id: &[u8; 16]) -> i64 {
19    let mut hash = 14_695_981_039_346_656_037_u64;
20    for byte in kind.bytes().chain(*b":").chain(object_id.iter().copied()) {
21        hash ^= u64::from(byte);
22        hash = hash.wrapping_mul(1_099_511_628_211);
23    }
24    10_000 + i64::try_from(hash % 2_000_000_000).unwrap_or(0)
25}
26
27pub fn schema_oid(schema: &str) -> i64 {
28    match schema {
29        "pg_catalog" => 11,
30        "public" => 2200,
31        "information_schema" => 13_293,
32        other => stable_oid("namespace", other),
33    }
34}
35
36pub fn relation_oid(kind: &str, schema: &str, name: &str) -> i64 {
37    stable_oid(kind, &format!("{schema}.{name}"))
38}
39
40pub fn current_user_oid() -> i64 {
41    10
42}
43
44pub fn current_user_name() -> &'static str {
45    "uqa"
46}