龙空技术网

一种DWS迁移Oracle的CONNECT BY语法的方案

华为云开发者联盟 139

前言:

目前朋友们对“oracle数据迁移工具”大约比较讲究,咱们都想要了解一些“oracle数据迁移工具”的相关文章。那么小编在网摘上搜集了一些对于“oracle数据迁移工具””的相关内容,希望兄弟们能喜欢,你们快快来学习一下吧!

本文分享自华为云社区《GaussDB(DWS)迁移 - oracle兼容 -- CONNECT BY迁移-云社区-华为云》,作者: 譡里个檔 。

1. CONNECT BY NOCYCLE

--1) 预置对象定义

DROP SCHEMA IF EXISTS "sdifin" CASCADE;CREATE SCHEMA "sdifin";DROP TABLE IF EXISTS "sdifin"."ogg_ets_bas_instrument_t_2670";SET search_path = sdifin;CREATE  TABLE ogg_ets_bas_instrument_t_2670 (        bas_instrument_id numeric NOT NULL,        instrument_name character varying(600),        instrument_parent_id numeric,        status numeric)WITH (enable_hstore=on, orientation=column, compression=yes, enable_delta=false, colversion=2.0, max_batchrow=60000)DISTRIBUTE BY HASH(bas_instrument_id);DROP TABLE IF EXISTS "sdifin"."ogg_sectype_2360";SET search_path = sdifin;CREATE  TABLE ogg_sectype_2360 (        thekey character varying(18) NOT NULL,        name character varying(150))WITH (enable_hstore=on, orientation=column, compression=yes, enable_delta=false, colversion=2.0, max_batchrow=60000)DISTRIBUTE BY REPLICATION;

-- 2) oracle原始语句

SELECT    to_char(i.BAS_INSTRUMENT_ID) AS INSTRUMENT_ID,    to_char(i.INSTRUMENT_PARENT_ID) AS parent_thekey,    TRIM(i.INSTRUMENT_NAME) AS INSTRUMENT_NAME,    SYS_CONNECT_BY_PATH(i.INSTRUMENT_NAME, ';') AS INSTRUMENT_PATH,    SYS_CONNECT_BY_PATH(i.BAS_INSTRUMENT_ID, '->') AS BAS_ID_PATH,      LEVEL AS INSTRUMENT_LEVEL,    CONNECT_BY_ISCYCLE AS CYCLE_ERROR,    2670 AS ss_id    FROM OGG_ETS_BAS_INSTRUMENT_T_2670 i, OGG_SECTYPE_2360 s2WHERE upper(i.instrument_name) = upper(TRIM(s2.name(+)))AND s2.thekey IS NULL AND I.STATUS = 1CONNECT BY NOCYCLE PRIOR i.BAS_INSTRUMENT_ID = i.INSTRUMENT_PARENT_IDSTART WITH i.instrument_parent_id IS NULL

oracle中的执行计划

关键点:

1)语句特征:SQL语句中WHERE字句包含非关联条件

2)执行特征:WHERE字句中的非关联条件计算的优先级低于CONNECT BY,即CONNECT BY执行之后才会进行这些条件的过滤,如上id=2的FILTER条件

--3) DWS等价改写逻辑

WITH RECURSIVE TMP_ETC AS (    SELECT        to_char(i.bas_instrument_id) AS instrument_id,        to_char(i.instrument_parent_id) AS parent_thekey,        trim(i.instrument_name) AS instrument_name,        ';'||i.instrument_name AS instrument_path,        '->'||i.bas_instrument_id AS bas_id_path,        1 AS instrument_level,        0 AS cycle_error,        2670 AS ss_id,        s2.thekey,        i.status,        i.bas_instrument_id AS start_val    FROM sdifin.ogg_ets_bas_instrument_t_2670 i    LEFT JOIN sdifin.ogg_sectype_2360 s2 ON upper(trim(i.instrument_name)) = upper(trim(s2.name))    WHERE i.instrument_parent_id IS NULL    UNION ALL    SELECT        to_char(i.bas_instrument_id) AS instrument_id,        to_char(i.instrument_parent_id) AS parent_thekey,        trim(i.instrument_name) AS instrument_name,        (b.instrument_path ||';'||i.instrument_name) AS instrument_path,        (b.bas_id_path ||'->'||i.bas_instrument_id) AS bas_id_path,        b.instrument_level+1 AS instrument_level,        decode(trim(i.bas_instrument_id)=b.start_val,false,0,1) AS cycle_error,        2670 AS ss_id,        s2.thekey,        i.status,        b.start_val AS start_val    FROM sdifin.ogg_ets_bas_instrument_t_2670 i    LEFT JOIN sdifin.ogg_sectype_2360 s2 ON upper(i.instrument_name) = upper(trim(s2.name))    INNER JOIN tmp_etc b ON b.instrument_id = i.instrument_parent_id    WHERE b.cycle_error <> 1)SELECT     instrument_id,    parent_thekey,    instrument_name,    instrument_path,    bas_id_path,    instrument_level,    cycle_error,    ss_idFROM tmp_etcWHERE thekey IS NULLAND status = 1

关注#华为云开发者联盟# 点击下方,第一时间了解华为云新鲜技术~

华为云博客_大数据博客_AI博客_云计算博客_开发者中心-华为云

标签: #oracle数据迁移工具