如何在 Hibernate 映射和 Oracle table 字段中保存 UUID 字段?
How can I hold UUID field in Hibernate mapping and in Oracle table field?
我们将对主键字段使用 UUID。在 Oracle table 和 hibernate(JPA) 映射中保存 UUID 的变体是什么? Varchar2\String 在我看来很贵。 UUID做主键有什么坑?
您也可以使用RAW(16)
。从 space 使用的角度来看,这是最好的解决方案,但你仍然 "waste" 很多 space.
据我所知,没有陷阱,但对于有 Oracle 经验的人来说,这是非自然的解决方案。
PS: numeric id 占用相同 space 将有 30 个有效数字。
PS:你可以做一个测试,创建一个有几百万行的table,一次以NUMBER作为PK,第二次以UUID作为PK。然后比较 PK 索引(段)的大小,叶块的数量,...
SQL> create table t1 as select level as N from dual connect by level <=1000000;
SQL> create table t2 as select sys_guid() as N from dual connect by level <=1000
000;
SQL> create unique index ix1 on t1(n);
SQL> create unique index ix2 on t2(n);
SQL> exec dbms_stats.gather_table_stats('SYS','T1');
SQL> exec dbms_stats.gather_table_stats('SYS','T2');
SQL> select bytes, segment_name from dba_segments where segment_name in ('IX1',
'IX2');
BYTES SEGMENT_NAME
---------- --------------------
17825792 IX1
31457280 IX2
SQL> select leaf_blocks, index_name from dba_ind_statistics where index_name in
('IX1', 'IX2');
LEAF_BLOCKS INDEX_NAME
----------- ------------------------------
2087 IX1
3760 IX2
我们将对主键字段使用 UUID。在 Oracle table 和 hibernate(JPA) 映射中保存 UUID 的变体是什么? Varchar2\String 在我看来很贵。 UUID做主键有什么坑?
您也可以使用RAW(16)
。从 space 使用的角度来看,这是最好的解决方案,但你仍然 "waste" 很多 space.
据我所知,没有陷阱,但对于有 Oracle 经验的人来说,这是非自然的解决方案。
PS: numeric id 占用相同 space 将有 30 个有效数字。
PS:你可以做一个测试,创建一个有几百万行的table,一次以NUMBER作为PK,第二次以UUID作为PK。然后比较 PK 索引(段)的大小,叶块的数量,...
SQL> create table t1 as select level as N from dual connect by level <=1000000;
SQL> create table t2 as select sys_guid() as N from dual connect by level <=1000
000;
SQL> create unique index ix1 on t1(n);
SQL> create unique index ix2 on t2(n);
SQL> exec dbms_stats.gather_table_stats('SYS','T1');
SQL> exec dbms_stats.gather_table_stats('SYS','T2');
SQL> select bytes, segment_name from dba_segments where segment_name in ('IX1',
'IX2');
BYTES SEGMENT_NAME
---------- --------------------
17825792 IX1
31457280 IX2
SQL> select leaf_blocks, index_name from dba_ind_statistics where index_name in
('IX1', 'IX2');
LEAF_BLOCKS INDEX_NAME
----------- ------------------------------
2087 IX1
3760 IX2