2024-12-25 OceanBase分区,Hash

oceabase的按照hash分区,只能是在建表时候就分区分好,然后再把数据导入进去。
这个分区方法倒可以在官网文档里有。
https://help.aliyun.com/document_detail/477952.html?spm=a2c4g.11186623.0.i31

不过有个新知识就是哈希的平均分布。
哈希算法有各种各样的,有些哈希算法是进行平均分布的。ap_hash是最平均的,go代码如下

// AP implements the classic AP hash algorithm for 32 bits.
func AP(str []byte) uint32 {
    var hash uint32
    for i := 0; i < len(str); i++ {
        if (i & 1) == 0 {
            hash ^= (hash << 7) ^ uint32(str[i]) ^ (hash >> 3)
        } else {
            hash ^= ^((hash << 11) ^ uint32(str[i]) ^ (hash >> 5)) + 1
        }
    }
    return hash
}

// AP64 implements the classic AP hash algorithm for 64 bits.
func AP64(str []byte) uint64 {
    var hash uint64
    for i := 0; i < len(str); i++ {
        if (i & 1) == 0 {
            hash ^= (hash << 7) ^ uint64(str[i]) ^ (hash >> 3)
        } else {
            hash ^= ^((hash << 11) ^ uint64(str[i]) ^ (hash >> 5)) + 1
        }
    }
    return hash
}

可以参考这个文章
https://blog.csdn.net/liuaigui/article/details/5050697

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容