非分布键 join通常使用hash join性能更好 本页介绍天翼云TeleDB数据库的非分布键 join使用hash join会在性能上更好的场景说明。 非分布键关联,默认下推DN节点执行,DN节点之间会发生数据重分布,重分布数据量大的时候,性能会有明显下降。这种场景,通常使用Hash Join关联,性能会比Merge Join和Nested Loop更好。 而为了提高TP类业务查询的性能,我们经常需要对一些字段创建索引,使用有索引字段join时,优化器往往也会使用Merge Join和Nested Loop。针对此场景,可以通过会话级别关闭Merge Join和Nested Loop,让优化器走Hash Join,或通过hint指定Hash Join。 以下是关于该场景的测试情况: 1. 测试数据准备: teledb CREATE TABLE t1(f1 serial not null,f2 text,f3 text,f4 text,f5 text,f6 text,f7 text,f8 text,f9 text,f10 text,f11 text,f12 text) distribute by shard(f1); CREATE TABLE Time: 481.042 ms teledb create index t1f1idx on t1(f2); CREATE INDEX Time: 85.521 ms teledb CREATE TABLE t2(f1 serial not null,f2 text,f3 text,f4 text,f5 text,f6 text,f7 text,f8 text,f9 text,f10 text,f11 text,f12 text) distribute by shard(f1); CREATE TABLE Time: 75.973 ms teledb create index t2f1idx on t2(f2); CREATE INDEX Time: 29.890 ms teledb insert into t1 select t,md5(t::text),md5(t::text),md5(t::text),md5(t::text),md5(t::text),md5(t::text),md5(t::text),md5(t::text),md5(t::text),md5(t::text),md5(t::text) from generateseries(1,1000000) as t; INSERT 0 1000000 Time: 16450.623 ms (00:16.451) teledb
来自: