首页 > 数据库 >LightDB-A 支持oracle执行计划下推

LightDB-A 支持oracle执行计划下推

时间:2023-05-25 16:33:52浏览次数:54  
标签:rows LightDB .. width 下推 loops cost oracle c1

LightDB-A支持创建外部表,外部数据源可以是oracle, postgresql等.

在LightDB-A创建oracle server和用户映射:

CREATE SERVER oradb FOREIGN DATA WRAPPER oracle_fdw OPTIONS (dbserver '//x.x.x.x:1521/test');
GRANT USAGE ON FOREIGN SERVER oradb TO fj;
CREATE USER MAPPING FOR fj SERVER oradb OPTIONS (user 'TEST', password '.............');

在Oracle创建表:

CREATE TABLE local_tbl (c1 int NOT NULL, c2 int NOT NULL, c3 varchar2(32), CONSTRAINT local_tbl_pkey PRIMARY KEY (c1));
CREATE TABLE local_tbl2 (c1 int NOT NULL, c2 int NOT NULL, c3 varchar2(32), CONSTRAINT local2_tbl_pkey PRIMARY KEY (c1));

在LightDB-A创建外部表, 映射到Oracle:

create FOREIGN table oft (c1 int NOT NULL, c2 int NOT NULL, c3 text)
server oradb options (table 'LOCAL_TBL');
create FOREIGN table oft2 (c1 int NOT NULL, c2 int NOT NULL, c3 text)
server oradb options (table 'LOCAL_TBL2');

-- insert into oft(c1, c2) select i, i from generate_series(0, 10000, 1)  i;
-- insert into oft2(c1, c2) select i, i from generate_series(0, 10000, 1)  i;
ERROR:  error executing query: OCIStmtExecute failed to execute remote query
DETAIL:  ORA-08177: can't serialize access for this transaction

带where条件的语句

lightdb=# explain (analyze) select * from oft2 where c1 < 10000;
                                                             QUERY PLAN                                                             
------------------------------------------------------------------------------------------------------------------------------------
 Foreign Scan on oft2  (cost=10000.00..20000.00 rows=1000 width=40) (actual time=2.114..2.116 rows=0 loops=1)
   Oracle query: SELECT /*8ac7e7f3946af2d338038bbf2b1f2a53*/ r1."C1", r1."C2", r1."C3" FROM "LOCAL_TBL2" r1 WHERE (r1."C1" < 10000)
 Optimizer: Postgres query optimizer
 Planning Time: 0.826 ms
   (slice0)    Executor memory: 7K bytes.
 Memory used:  128000kB
 Execution Time: 2.156 ms
(7 rows)

带where,及聚合函数的语句

lightdb=# explain (analyze) select sum(c1) from oft2 where c1 < 10000;
                                                       QUERY PLAN                                                       
------------------------------------------------------------------------------------------------------------------------
 Aggregate  (cost=20002.50..20002.51 rows=1 width=8) (actual time=1.620..1.622 rows=1 loops=1)
   ->  Foreign Scan on oft2  (cost=10000.00..20000.00 rows=1000 width=4) (actual time=1.607..1.608 rows=0 loops=1)
         Oracle query: SELECT /*df3081a4ef375caa252041bf257243af*/ r1."C1" FROM "LOCAL_TBL2" r1 WHERE (r1."C1" < 10000)
 Optimizer: Postgres query optimizer
 Planning Time: 0.758 ms
   (slice0)    Executor memory: 14K bytes.
 Memory used:  128000kB
 Execution Time: 1.670 ms
(8 rows)

在LightDB-A上join: 两个外部表均在oracle上

lightdb=# explain (analyze) select * from oft full join oft2 on oft.c1 = oft2.c1;
                                                                                       QUERY PLAN                                                           
                             
------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------
 Foreign Scan  (cost=10000.00..20000.00 rows=1000 width=80) (actual time=0.863..0.864 rows=0 loops=1)
   Oracle query: SELECT /*1724e7408dbc2aa1e960df0f0bdbb192*/ r1."C1", r1."C2", r1."C3", r2."C1", r2."C2", r2."C3" FROM ("LOCAL_TBL" r1 FULL JOIN "LOCAL_TBL2
" r2 ON (r1."C1" = r2."C1"))
 Optimizer: Postgres query optimizer
 Planning Time: 1.339 ms
   (slice0)    Executor memory: 9K bytes.
 Memory used:  128000kB
 Execution Time: 0.894 ms
(7 rows)

在LightDB-A上join: 两个外部表均在oracle上, 带聚合函数, 聚合函数目前不支持下推

lightdb=# explain (analyze) select sum(oft.c1) from oft full join oft2 on oft.c1 = oft2.c1;
                                                                    QUERY PLAN                                                                    
--------------------------------------------------------------------------------------------------------------------------------------------------
 Aggregate  (cost=20002.50..20002.51 rows=1 width=8) (actual time=2.600..2.601 rows=1 loops=1)
   ->  Foreign Scan  (cost=10000.00..20000.00 rows=1000 width=4) (actual time=2.596..2.597 rows=0 loops=1)
         Oracle query: SELECT /*af432403390fd19477c69e9f26d614a9*/ r1."C1" FROM ("LOCAL_TBL" r1 FULL JOIN "LOCAL_TBL2" r2 ON (r1."C1" = r2."C1"))
 Optimizer: Postgres query optimizer
 Planning Time: 1.064 ms
   (slice0)    Executor memory: 12K bytes.
 Memory used:  128000kB
 Execution Time: 2.651 ms
(8 rows)

在LightDB-A上join: 一个外部表,一个是非外部表

lightdb=# create table dist_tbl(c1 int) distributed by (c1);
CREATE TABLE
lightdb=# explain (analyze) select * from oft full join dist_tbl on oft.c1 = dist_tbl.c1;
                                                                 QUERY PLAN                                                                  
---------------------------------------------------------------------------------------------------------------------------------------------
 Gather Motion 3:1  (slice1; segments: 3)  (cost=20017.50..23395.25 rows=96300 width=44) (actual time=68.468..68.474 rows=0 loops=1)
   ->  Hash Full Join  (cost=20017.50..22111.25 rows=32100 width=44) (actual time=0.000..68.141 rows=0 loops=1)
         Hash Cond: (dist_tbl.c1 = oft.c1)
         ->  Seq Scan on dist_tbl  (cost=0.00..355.00 rows=32100 width=4) (actual time=0.000..0.023 rows=0 loops=1)
         ->  Hash  (cost=20013.33..20013.33 rows=333 width=40) (actual time=0.000..64.721 rows=0 loops=1)
               Buckets: 262144  Batches: 1  Memory Usage: 2048kB
               ->  Redistribute Motion 1:3  (slice2)  (cost=10000.00..20013.33 rows=333 width=40) (actual time=0.000..64.717 rows=0 loops=1)
                     Hash Key: oft.c1
                     ->  Foreign Scan on oft  (cost=10000.00..20000.00 rows=1000 width=40) (actual time=0.000..0.705 rows=0 loops=1)
                           Oracle query: SELECT /*cd8c22c22d0a386d03594f6eacd5ac7d*/ r1."C1", r1."C2", r1."C3" FROM "LOCAL_TBL" r1
 Optimizer: Postgres query optimizer
 Memory used:  128000kB
 Execution Time: 74.052 ms
(17 rows)

当启用ORCA优化器后, join不会下推:

lightdb=# set optimizer=on;
SET
lightdb=# explain (analyze) select * from oft full join oft2 on oft.c1 = oft2.c1;
                                                       QUERY PLAN                                                       
------------------------------------------------------------------------------------------------------------------------
 Merge Full Join  (cost=0.00..862.00 rows=3 width=32) (actual time=1.869..1.872 rows=0 loops=1)
   Merge Cond: (oft.c1 = oft2.c1)
   ->  Sort  (cost=0.00..431.00 rows=1 width=16) (actual time=0.490..0.491 rows=0 loops=1)
         Sort Key: oft.c1
         Sort Method:  quicksort  Memory: 25kB
         Executor Memory: 26kB  Segments: 1  Max: 26kB (segment -1)
         ->  Foreign Scan on oft  (cost=0.00..431.00 rows=1 width=16) (actual time=0.475..0.475 rows=0 loops=1)
               Oracle query: SELECT /*cd8c22c22d0a386d03594f6eacd5ac7d*/ r1."C1", r1."C2", r1."C3" FROM "LOCAL_TBL" r1
   ->  Sort  (cost=0.00..431.00 rows=1 width=16) (actual time=1.370..1.371 rows=0 loops=1)
         Sort Key: oft2.c1
         Sort Method:  quicksort  Memory: 25kB
         Executor Memory: 26kB  Segments: 1  Max: 26kB (segment -1)
         ->  Foreign Scan on oft2  (cost=0.00..431.00 rows=1 width=16) (actual time=1.367..1.367 rows=0 loops=1)
               Oracle query: SELECT /*bd17a8d3ec77b6f27cb09595116840b9*/ r2."C1", r2."C2", r2."C3" FROM "LOCAL_TBL2" r2
 Optimizer: Pivotal Optimizer (GPORCA)
 Planning Time: 13.831 ms
   (slice0)    Executor memory: 81K bytes.  Work_mem: 26K bytes max.
 Memory used:  128000kB
 Execution Time: 1.949 ms
(19 rows)
lightdb=# explain (analyze) select sum(oft.c1) from oft full join oft2 on oft.c1 = oft2.c1;
                                                      QUERY PLAN                                                      
----------------------------------------------------------------------------------------------------------------------
 Aggregate  (cost=0.00..862.00 rows=1 width=8) (actual time=2.556..2.559 rows=1 loops=1)
   ->  Merge Full Join  (cost=0.00..862.00 rows=3 width=4) (actual time=2.550..2.552 rows=0 loops=1)
         Merge Cond: (oft.c1 = oft2.c1)
         ->  Sort  (cost=0.00..431.00 rows=1 width=4) (actual time=1.400..1.401 rows=0 loops=1)
               Sort Key: oft.c1
               Sort Method:  quicksort  Memory: 25kB
               Executor Memory: 26kB  Segments: 1  Max: 26kB (segment -1)
               ->  Foreign Scan on oft  (cost=0.00..431.00 rows=1 width=4) (actual time=1.390..1.390 rows=0 loops=1)
                     Oracle query: SELECT /*ae2a7d620bfefbdfff5f19cd521175ca*/ r1."C1" FROM "LOCAL_TBL" r1
         ->  Sort  (cost=0.00..431.00 rows=1 width=4) (actual time=1.146..1.147 rows=0 loops=1)
               Sort Key: oft2.c1
               Sort Method:  quicksort  Memory: 25kB
               Executor Memory: 26kB  Segments: 1  Max: 26kB (segment -1)
               ->  Foreign Scan on oft2  (cost=0.00..431.00 rows=1 width=4) (actual time=1.135..1.136 rows=0 loops=1)
                     Oracle query: SELECT /*d5d1f33ed6d5ea2f04f5479ffb4fb4ba*/ r2."C1" FROM "LOCAL_TBL2" r2
 Optimizer: Pivotal Optimizer (GPORCA)
 Planning Time: 12.468 ms
   (slice0)    Executor memory: 57K bytes.  Work_mem: 26K bytes max.
 Memory used:  128000kB
 Execution Time: 2.640 ms
(20 rows)
lightdb=# explain (analyze) select count(oft.c1) from oft full join oft2 on oft.c1 = oft2.c1;
                                                      QUERY PLAN                                                      
----------------------------------------------------------------------------------------------------------------------
 Aggregate  (cost=0.00..862.00 rows=1 width=8) (actual time=0.818..0.820 rows=1 loops=1)
   ->  Merge Full Join  (cost=0.00..862.00 rows=3 width=4) (actual time=0.802..0.803 rows=0 loops=1)
         Merge Cond: (oft.c1 = oft2.c1)
         ->  Sort  (cost=0.00..431.00 rows=1 width=4) (actual time=0.492..0.492 rows=0 loops=1)
               Sort Key: oft.c1
               Sort Method:  quicksort  Memory: 25kB
               Executor Memory: 26kB  Segments: 1  Max: 26kB (segment -1)
               ->  Foreign Scan on oft  (cost=0.00..431.00 rows=1 width=4) (actual time=0.483..0.483 rows=0 loops=1)
                     Oracle query: SELECT /*ae2a7d620bfefbdfff5f19cd521175ca*/ r1."C1" FROM "LOCAL_TBL" r1
         ->  Sort  (cost=0.00..431.00 rows=1 width=4) (actual time=0.307..0.308 rows=0 loops=1)
               Sort Key: oft2.c1
               Sort Method:  quicksort  Memory: 25kB
               Executor Memory: 26kB  Segments: 1  Max: 26kB (segment -1)
               ->  Foreign Scan on oft2  (cost=0.00..431.00 rows=1 width=4) (actual time=0.301..0.301 rows=0 loops=1)
                     Oracle query: SELECT /*d5d1f33ed6d5ea2f04f5479ffb4fb4ba*/ r2."C1" FROM "LOCAL_TBL2" r2
 Optimizer: Pivotal Optimizer (GPORCA)
 Planning Time: 11.687 ms
   (slice0)    Executor memory: 57K bytes.  Work_mem: 26K bytes max.
 Memory used:  128000kB
 Execution Time: 0.888 ms
(20 rows)

标签:rows,LightDB,..,width,下推,loops,cost,oracle,c1
From: https://www.cnblogs.com/faxx/p/17431743.html

相关文章

  • oracle死锁产生成原因和解决方案
    表1.进行update、delete操作的窗口没有提交有在另一个窗口执行了更新或者删除动作。2.在外键上没有加索引引起的死锁(这个要注意,设置了外键同时增加索引)3.两个表之前不同顺序之间的相互更新操作引起的死锁(如果所有并发事务按同一顺序访问对象,则发生死锁的可能性会降低) 解锁......
  • ORACLE数据库 定时全量备份
    1、ORACLE数据库定时全量备份 https://blog.csdn.net/ldz_wolf/article/details/130010941?spm=1001.2101.3001.6650.3&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EYuanLiJiHua%7EPosition-3-130010941-blog-13314331.235%5Ev36%5Epc_relevant_default_b......
  • Centos 7 系统上使用dokcer安装oracle 11g(踩坑验证过可用)
    1.docker安装略2.查看docker中关于oracle11g的镜像,并拉下来dockersearchoracle_11gdockerpulldocker.io/akaiot/oracle_11g此处选择第二个 3.启动临时容器获取初始化数据dockerrun-d--nametest--restartunless-stopped\-p1521:1521docker.io/akaiot/o......
  • Oracle中读取JSON格式数据实战指南(oracle中读json)
    Oracle中读取JSON格式数据实战指南 随着大数据、云计算等技术的快速发展,JSON(JavaScriptObjectNotation)格式的数据越来越广泛应用于数据交互和存储中。Oracle数据库支持JSON格式数据的存储和查询,本篇文章将介绍如何在Oracle中读取JSON格式数据,并提供相关代码示例。 1.创建......
  • Linux系统,使用PHP连接ORACLE数据库
    首先安装ORACLE的InstantClient环境:在这里下载因为我需要连接11.2.0.4.0版本的ORACLE数据库,所以选取下载了basic-11.2.0.4.0-1.x86_64.rpm和devel-11.2.0.4.0-1.x86_64.rpm,使用如下命令安装:rpm-ivhoracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpmrpm-ivhoracle......
  • 多种数据库注入复线-墨者学院SQL手工注入漏洞测试(Oracle数据库)
    SQL手工注入漏洞测试(Oracle数据库)1.判断注入点判断注入类型为数字型2.用orderby获取列数2时正常,3时报错,得到列数为23.联合查询获取占位符常规联合查询报错这是由于oracle数据库语法十分严格,在后面需要指定数据表和准确的字符类型我们使用dual表,dual是oracle中的一个实际存......
  • Oracle数据安全技术
    一:概述   Oracle是Oracle公司开发的一种面向网络计算机并支持对象-关系模型的数据库产品。它是一高级及结构化查询语言为基础的大型关系数据库。是目前最流行的客户/服务器体系结构的数据库之一。   Oracle之所以备受用户喜爱,是因为它具有以下突出的特点。   <1>支......
  • oracle常用关键字
    1.sysdatesysdate显示系统当前日期和时间的函数。 2.THIRD_SYSTEM_CONFIG_GK_PK.nextval在Oracle数据库中,THIRD_SYSTEM_CONFIG_GK_PK.nextval是一个序列号生成器。THIRD_SYSTEM_CONFIG_GK_PK.nextval的作用是:1.为第三系统配置表生成唯一的主键值2.每调用一次nextval......
  • lightdb创建oracle兼容分区表
    zjh@postgres=#createtablehash_part_tab(idnumber,deal_datedate,area_codenumber,nbrnumber,contentsvarchar2(4000))zjh@postgres-#partitionbyhash(deal_date)zjh@postgres-#PARTITIONS12;ERROR:pleasesetoraclecompatiblemodefororaclepartit......
  • oracle12c linux安装教程
    1、安装包下载2、环境准备2.1安装gcc2.2内核参数设置2.3资源限制配置2.4硬件环境准备2.5Xmanger安装2.6创建文件夹2.7创建用户和组2.8图像界面设置2.9上传并解压3、安装3.1执行安装命令3.2安装选择3.3环境变量配置4、验证4.1启动pdb4.2设置pdb随cdb自启动1、安装......