select a.* from tbl_operate a join tbl_info b on a.applyid = b.id where a.syskey = 'BOSS' and a.operationid = '7' and a.targetid = 'zhuhua1' and (a.state in ('DataSaved', 'DataProc') or b.state in ('MainBillDeptAdminApprove', 'MainBillDeptApprove') or a.applyid = '8ace4a9e506c7af101508354dddd4d95');
QUERY PLAN ---------------------------------------------------------------------------------------------------------------------- Data Node Scan on "__REMOTE_FQS_QUERY__" (cost=0.00..0.00 rows=0 width=0) (actual time=3.314..3.331 rows=3 loops=1) Node/s: datanode2 Total runtime: 3.376 ms (3 rows)
QUERY PLAN ---------------------------------------------------------------------------------------------------------------------- Data Node Scan on "__REMOTE_FQS_QUERY__" (cost=0.00..0.00 rows=0 width=0) (actual time=3.303..5.061 rows=3 loops=1) Node/s: datanode2, datanode3 Total runtime: 5.106 ms (3 rows)
备注:执行时间 5.106 ms。
场景四 tbl_operate: hash(id) , tbl_info: 复制表
1 2 3 4 5 6
QUERY PLAN ---------------------------------------------------------------------------------------------------------------------- Data Node Scan on "__REMOTE_FQS_QUERY__" (cost=0.00..0.00 rows=0 width=0) (actual time=3.065..3.218 rows=3 loops=1) Node/s: datanode2, datanode3 Total runtime: 3.263 ms (3 rows)
createtable t1(id int4,namecharactervarying(32),create_time timestamp(0) withouttime zone default clock_timestamp() ) distributebyhash(name); createuniqueindex idx_t1_name on t1 using btree(name); insertinto t1(id,name) select n,n||'_a'from generate_series(1,100000) n; createtable t2 asselectnamefrom t1; createuniqueindex idx_t2_name on t2 using btree(name); altertable t2 addcolumn flag booleandefault't';
分区键关联SQL
1 2 3
select t1.id,t1.create_time,t2.name,t2.flag from t1,t2 where t1.name=t2.name and t1.name='1_a';
备注: 关联字段 name 分别是 t1,t2 表的分片字段。
分片表执行计划
1 2 3 4 5 6 7 8 9
francs=> explain analyze select t1.id,t1.create_time,t2.name,t2.flag from t1,t2 where t1.name=t2.name and t1.name='2_a'; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------- Data Node Scan on "__REMOTE_FQS_QUERY__" (cost=0.00..0.00 rows=0 width=0) (actual time=1.243..1.244 rows=1 loops=1) Node/s: datanode2, datanode3 Total runtime: 1.293 ms (3 rows)
francs=> explain analyze select t1.id,t1.create_time,t2.name,t2.flag from t1,t2 where t1.name=t2.name and t1.name='2_a'; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------- Data Node Scan on "__REMOTE_FQS_QUERY__" (cost=0.00..0.00 rows=0 width=0) (actual time=0.909..0.910 rows=1 loops=1) Node/s: datanode2 Total runtime: 0.941 ms (3 rows)