mirror of
https://github.com/postgresml/pgcat.git
synced 2026-03-28 03:06:29 +00:00
remove unused
This commit is contained in:
@@ -1,5 +1,3 @@
|
|||||||
use sha1::{Digest, Sha1};
|
|
||||||
|
|
||||||
// https://github.com/postgres/postgres/blob/27b77ecf9f4d5be211900eda54d8155ada50d696/src/include/catalog/partition.h#L20
|
// https://github.com/postgres/postgres/blob/27b77ecf9f4d5be211900eda54d8155ada50d696/src/include/catalog/partition.h#L20
|
||||||
const PARTITION_HASH_SEED: u64 = 0x7A5B22367996DCFD;
|
const PARTITION_HASH_SEED: u64 = 0x7A5B22367996DCFD;
|
||||||
|
|
||||||
@@ -12,17 +10,6 @@ impl Sharder {
|
|||||||
Sharder { shards: shards }
|
Sharder { shards: shards }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Use SHA1 to pick a shard for the key. The key can be anything,
|
|
||||||
/// including an int or a string.
|
|
||||||
pub fn _sha1(&self, key: &[u8]) -> usize {
|
|
||||||
let mut hasher = Sha1::new();
|
|
||||||
hasher.update(key);
|
|
||||||
let result = hasher.finalize_reset();
|
|
||||||
|
|
||||||
let i = u32::from_le_bytes(result[result.len() - 4..result.len()].try_into().unwrap());
|
|
||||||
i as usize % self.shards
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Hash function used by Postgres to determine which partition
|
/// Hash function used by Postgres to determine which partition
|
||||||
/// to put the row in when using HASH(column) partitioning.
|
/// to put the row in when using HASH(column) partitioning.
|
||||||
/// Source: https://github.com/postgres/postgres/blob/27b77ecf9f4d5be211900eda54d8155ada50d696/src/common/hashfn.c#L631
|
/// Source: https://github.com/postgres/postgres/blob/27b77ecf9f4d5be211900eda54d8155ada50d696/src/common/hashfn.c#L631
|
||||||
@@ -117,14 +104,6 @@ impl Sharder {
|
|||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_sha1() {
|
|
||||||
let sharder = Sharder::new(12);
|
|
||||||
let key = b"1234";
|
|
||||||
let shard = sharder.sha1(key);
|
|
||||||
assert_eq!(shard, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// See tests/sharding/partition_hash_test_setup.sql
|
// See tests/sharding/partition_hash_test_setup.sql
|
||||||
// The output of those SELECT statements will match this test,
|
// The output of those SELECT statements will match this test,
|
||||||
// confirming that we implemented Postgres BIGINT hashing correctly.
|
// confirming that we implemented Postgres BIGINT hashing correctly.
|
||||||
|
|||||||
Reference in New Issue
Block a user