ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

炫“库”行动-人大金仓有奖征文- KingbaseES leading hint 使用

2021-10-12 19:32:38  阅读:200  来源: 互联网

标签:金仓 rows .. hint leading t2 t3 t1 100000


【本文正在参与炫“库”行动-人大金仓有奖征文】

活动链接:https://marketing.csdn.net/p/98bd30353e7cb998b6070a89e8b91edb

Oracle hint -- leading 的作用是提示优化器某张表先访问,可以指定一张或多张表,当指定多张表时,表示按指定的顺序访问这几张表。而 KingbaseES leading hint的功能与oracle不同,leading 后面必须跟两张或多张表,如果是两张,表示这两张表先进行连接,但两张表的访问顺序不定。如果要严格控制表的访问顺序,还必须使用双括号,具体用法以例子形式进行介绍。

以下的例子在PG 12.3 与 KingbaseES V8R6 进行过验证。 

一、构造数据

create table t1(id1 integer,desc_t1 varchar(400));
create table t2(id2 integer,desc_t2 varchar(400));
create table t3(id3 integer,desc_t3 varchar(400));
 
insert into t1 select generate_series(1,100000),repeat('a',200);
insert into t2 select generate_series(1,100000),repeat('a',200);
insert into t3 select generate_series(1,100000),repeat('a',200);
 
analyze t1;
analyze t2;
analyze t3;

二、KingbaseES leading hint 使用

1、必须至少指定两张表

test=# explain analyze select/*+leading(t3) hashjoin(t1 t2 t3)*/ desc_t1,desc_t2,desc_t3 from t1,t2,t3 where id1=id2 and id2=id3;
INFO:  sys_hint_plan: hint syntax error at or near "leading(t3) hashjoin(t1 t2 t3)"
DETAIL:  Leading hint requires at least two relations.

2、leading 只表示连接的顺序  -- 单层括号

以下例子,leading(t3 t1 t2) 表示 t3 t1 先进行连接,结果再与 t2 进行连接。与oracle 不同,这里并没有严格限制访问顺序,实际上还是 t1 最先访问。

test=# explain analyze select/*+leading(t3 t1 t2) hashjoin(t1 t2 t3)*/ desc_t1,desc_t2,desc_t3 from t1,t2,t3 where id1=id2 and id2=id3;
                                                          QUERY PLAN                                                         
------------------------------------------------------------------------------------------------------------------------------
 Hash Join  (cost=16050.00..44818.00 rows=100000 width=612) (actual time=106.935..352.686 rows=100000 loops=1)
   Hash Cond: (t1.id1 = t2.id2)
   ->  Hash Join  (cost=8025.00..21841.00 rows=100000 width=416) (actual time=54.546..165.037 rows=100000 loops=1)
         Hash Cond: (t1.id1 = t3.id3)
         ->  Seq Scan on t1  (cost=0.00..3942.00 rows=100000 width=208) (actual time=0.006..16.309 rows=100000 loops=1)
         ->  Hash  (cost=3942.00..3942.00 rows=100000 width=208) (actual time=54.457..54.457 rows=100000 loops=1)
               Buckets: 32768  Batches: 8  Memory Usage: 3225kB
               ->  Seq Scan on t3  (cost=0.00..3942.00 rows=100000 width=208) (actual time=0.005..17.343 rows=100000 loops=1)
   ->  Hash  (cost=3942.00..3942.00 rows=100000 width=208) (actual time=52.361..52.362 rows=100000 loops=1)
         Buckets: 32768  Batches: 8  Memory Usage: 3225kB
         ->  Seq Scan on t2  (cost=0.00..3942.00 rows=100000 width=208) (actual time=0.011..16.483 rows=100000 loops=1)
 Planning Time: 0.207 ms
 Execution Time: 357.799 ms
(13 rows)

3、双层括号表示访问顺序

以下例子leadint((t3 t1)) 不仅表示 t3 t1先连接,还指示 t3 表先访问。

test=# explain analyze select/*+leading((t3 t1)) hashjoin(t1 t2 t3)*/ desc_t1,desc_t2,desc_t3 from t1,t2,t3 where id1=id2 and id2=id3;
                                                          QUERY PLAN                                                         
------------------------------------------------------------------------------------------------------------------------------
 Hash Join  (cost=16050.00..44818.00 rows=100000 width=612) (actual time=103.223..324.500 rows=100000 loops=1)
   Hash Cond: (t1.id1 = t2.id2)
   ->  Hash Join  (cost=8025.00..21841.00 rows=100000 width=416) (actual time=50.143..157.813 rows=100000 loops=1)
         Hash Cond: (t3.id3 = t1.id1)
         ->  Seq Scan on t3  (cost=0.00..3942.00 rows=100000 width=208) (actual time=0.007..16.505 rows=100000 loops=1)
         ->  Hash  (cost=3942.00..3942.00 rows=100000 width=208) (actual time=49.973..49.974 rows=100000 loops=1)
               Buckets: 32768  Batches: 8  Memory Usage: 3225kB
               ->  Seq Scan on t1  (cost=0.00..3942.00 rows=100000 width=208) (actual time=0.006..16.008 rows=100000 loops=1)
   ->  Hash  (cost=3942.00..3942.00 rows=100000 width=208) (actual time=53.019..53.019 rows=100000 loops=1)
         Buckets: 32768  Batches: 8  Memory Usage: 3225kB
         ->  Seq Scan on t2  (cost=0.00..3942.00 rows=100000 width=208) (actual time=0.012..17.379 rows=100000 loops=1)
 Planning Time: 0.150 ms
 Execution Time: 328.360 ms
(13 rows)

【本文正在参与炫“库”行动-人大金仓有奖征文】

活动链接:https://marketing.csdn.net/p/98bd30353e7cb998b6070a89e8b91edb

标签:金仓,rows,..,hint,leading,t2,t3,t1,100000
来源: https://blog.csdn.net/lyu1026/article/details/120730187

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有