From 59b5b97b32a3724ebe55a1fd048c394cc518e2a3 Mon Sep 17 00:00:00 2001 From: TotaJ Date: Tue, 8 Feb 2022 17:00:31 +0800 Subject: [PATCH] Fix start with connect by. --- src/common/backend/parser/parse_startwith.cpp | 50 +- src/test/regress/expected/sw_basic.out | 630 +++++ src/test/regress/expected/sw_bugfix.out | 2510 +++++++++++++++++ .../regress/expected/sw_by_rownum_level.out | 180 ++ src/test/regress/expected/sw_clearup.out | 15 + src/test/regress/expected/sw_icbc.out | 553 ++++ src/test/regress/expected/sw_prepare.out | 229 ++ src/test/regress/expected/sw_siblings.out | 498 ++++ src/test/regress/parallel_schedule0 | 5 + src/test/regress/sql/sw_basic.sql | 182 ++ src/test/regress/sql/sw_bugfix.sql | 844 ++++++ src/test/regress/sql/sw_by_rownum_level.sql | 36 + src/test/regress/sql/sw_clearup.sql | 16 + src/test/regress/sql/sw_icbc.sql | 96 + src/test/regress/sql/sw_prepare.sql | 228 ++ src/test/regress/sql/sw_siblings.sql | 169 ++ 16 files changed, 6232 insertions(+), 9 deletions(-) create mode 100644 src/test/regress/expected/sw_basic.out create mode 100644 src/test/regress/expected/sw_bugfix.out create mode 100644 src/test/regress/expected/sw_by_rownum_level.out create mode 100644 src/test/regress/expected/sw_clearup.out create mode 100644 src/test/regress/expected/sw_icbc.out create mode 100644 src/test/regress/expected/sw_prepare.out create mode 100644 src/test/regress/expected/sw_siblings.out create mode 100644 src/test/regress/sql/sw_basic.sql create mode 100644 src/test/regress/sql/sw_bugfix.sql create mode 100644 src/test/regress/sql/sw_by_rownum_level.sql create mode 100644 src/test/regress/sql/sw_clearup.sql create mode 100644 src/test/regress/sql/sw_icbc.sql create mode 100644 src/test/regress/sql/sw_prepare.sql create mode 100644 src/test/regress/sql/sw_siblings.sql diff --git a/src/common/backend/parser/parse_startwith.cpp b/src/common/backend/parser/parse_startwith.cpp index d6749fead..5ae0b92db 100644 --- a/src/common/backend/parser/parse_startwith.cpp +++ b/src/common/backend/parser/parse_startwith.cpp @@ -159,6 +159,7 @@ static void CreateStartWithCTE(ParseState *pstate, static Node *makeBoolAConst(bool state, int location); static StartWithRewrite ChooseSWCBStrategy(StartWithTransformContext context); +static Node *tryReplaceFakeValue(Node *node); static Node *makeBoolAConst(bool state, int location) { @@ -754,17 +755,38 @@ static Node* makeIntConst(int val, int location) return (Node *)n; } -static Node* tryReplaceFakeValue(Node *node) +static Node *replaceListFakeValue(List *lst) +{ + List *newArgs = NIL; + ListCell *lc = NULL; + bool replaced = false; + + /* replace level/rownum var attr with fake consts */ + foreach (lc, lst) { + Node *n = (Node *)lfirst(lc); + Node *newNode = tryReplaceFakeValue(n); + if (newNode != n) { + replaced = true; + n = newNode; + } + newArgs = lappend(newArgs, n); + } + return replaced ? (Node *)newArgs : (Node *)lst; +} + +static Node *tryReplaceFakeValue(Node *node) { if (IsA(node, Rownum)) { node = makeIntConst(CONNECT_BY_ROWNUM_FAKEVALUE, -1); } else if (is_cref_by_name(node, "level")) { node = makeIntConst(CONNECT_BY_LEVEL_FAKEVALUE, -1); + } else if (IsA(node, List)) { + node = replaceListFakeValue((List *) node); } return node; } -static bool pseudo_level_rownum_walker(Node *node, Node* context_parent_node) +static bool pseudo_level_rownum_walker(Node *node, Node *context_parent_node) { if (node == NULL) { return false; @@ -789,15 +811,20 @@ static bool pseudo_level_rownum_walker(Node *node, Node* context_parent_node) break; } case T_TypeCast: { - TypeCast* tc = (TypeCast*) context_parent_node; + TypeCast *tc = (TypeCast *) context_parent_node; tc->arg = newNode; break; } case T_NullTest: { - NullTest* nt = (NullTest*) context_parent_node; + NullTest *nt = (NullTest *) context_parent_node; nt->arg = (Expr*) newNode; break; } + case T_FuncCall: { + FuncCall *fc = (FuncCall *) context_parent_node; + fc->args = (List *)newNode; + break; + } default: break; } @@ -1288,7 +1315,8 @@ static SelectStmt *CreateStartWithCTEInnerBranch(ParseState* pstate, if (whereClause != NULL) { JoinExpr *final_join = (JoinExpr *)origin_table; - final_join->quals = whereClause; + /* pushdown requires deep copying of the quals */ + final_join->quals = (Node *)copyObject(whereClause); } } @@ -1387,10 +1415,14 @@ static SelectStmt *CreateStartWithCTEOuterBranch(ParseState *pstate, } } - if (whereClause == NULL) { - quals = (Node *)startWithExpr; - } else { - quals = (Node *)makeA_Expr(AEXPR_AND, NULL, whereClause, (Node*)startWithExpr, -1); + /* push whereClause down to init part, taking care to avoid NULL in expr. */ + quals = (Node *)startWithExpr; + if (quals == NULL) { + /* pushdown requires deep copying of the quals */ + quals = (Node *)copyObject(whereClause); + } else if (whereClause != NULL) { + quals = (Node *)makeA_Expr(AEXPR_AND, NULL, (Node *)copyObject(whereClause), + (Node*)startWithExpr, -1); } result->fromClause = tblist; diff --git a/src/test/regress/expected/sw_basic.out b/src/test/regress/expected/sw_basic.out new file mode 100644 index 000000000..e4016470d --- /dev/null +++ b/src/test/regress/expected/sw_basic.out @@ -0,0 +1,630 @@ +set client_min_messages = error; +set search_path=swtest; +SET CLIENT_ENCODING='UTF8'; +/* + * + * START WITH .... CONNECT BY基础测试用例 + * + * 测试用例表数 + * openGauss=# select * from swtest.test_area; + * id | name | fatherid | name_desc + * ----+--------+----------+----------- + * 1 | 中国 | 0 | china + * 2 | 湖南省 | 1 | hunan + * 3 | 广东省 | 1 | guangdong + * 4 | 海南省 | 1 | hainan + * 5 | 河北省 | 1 | hebei + * 6 | 河南省 | 1 | henan + * 7 | 山东省 | 1 | shandong + * 8 | 湖北省 | 1 | hubei + * 9 | 江苏省 | 1 | jiangsu + * 10 | 深圳市 | 3 | shenzhen + * 11 | 长沙市 | 2 | changsha + * 22 | 祁北县 | 13 | qibei + * 12 | 南山区 | 10 | nanshan + * 21 | 祁西县 | 13 | qixi + * 13 | 衡阳市 | 2 | hengyang + * 14 | 耒阳市 | 13 | leiyang + * 15 | 龙岗区 | 10 | longgang + * 16 | 福田区 | 10 | futian + * 17 | 宝安区 | 10 | baoan + * 19 | 祁东县 | 13 | qidong + * 18 | 常宁市 | 13 | changning + * 20 | 祁南县 | 13 | qinan + * + */ +-- 一、基础语法测试 +/* + * 用例1.1,基础用例包含所有伪列,leaf节点方向遍历查找 + **/ +EXPLAIN (COSTS OFF) +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), sys_connect_by_path(name_desc, '@') +FROM test_area +START WITH name = '中国' +CONNECT BY PRIOR id = fatherid; + QUERY PLAN +------------------------------------------------------------------------------------------ + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_1, array_col_4 + -> Recursive Union + -> Seq Scan on test_area + Filter: (name = '中国'::text) + -> Hash Join + Hash Cond: (swtest.test_area.fatherid = tmp_reuslt."test_area@id") + -> Seq Scan on test_area + -> Hash + -> WorkTable Scan on tmp_reuslt +(12 rows) + +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), sys_connect_by_path(name_desc, '@') +FROM test_area +START WITH name = '中国' +CONNECT BY PRIOR id = fatherid; + id | name | fatherid | name_desc | level | connect_by_isleaf | connect_by_iscycle | connect_by_root | sys_connect_by_path +----+--------+----------+-----------+-------+-------------------+--------------------+-----------------+------------------------------------ + 1 | 中国 | 0 | China | 1 | 0 | 0 | China | @China + 2 | 湖南省 | 1 | Hunan | 2 | 0 | 0 | China | @China@Hunan + 3 | 广东省 | 1 | Guangdong | 2 | 0 | 0 | China | @China@Guangdong + 4 | 海南省 | 1 | Hainan | 2 | 1 | 0 | China | @China@Hainan + 5 | 河北省 | 1 | Hebei | 2 | 1 | 0 | China | @China@Hebei + 6 | 河南省 | 1 | Henan | 2 | 1 | 0 | China | @China@Henan + 7 | 山东省 | 1 | Shandong | 2 | 1 | 0 | China | @China@Shandong + 8 | 湖北省 | 1 | Hubei | 2 | 1 | 0 | China | @China@Hubei + 9 | 江苏省 | 1 | Jiangsu | 2 | 1 | 0 | China | @China@Jiangsu + 10 | 深圳市 | 3 | Shenzhen | 3 | 0 | 0 | China | @China@Guangdong@Shenzhen + 11 | 长沙市 | 2 | Changsha | 3 | 1 | 0 | China | @China@Hunan@Changsha + 13 | 衡阳市 | 2 | Hengyang | 3 | 0 | 0 | China | @China@Hunan@Hengyang + 22 | 祁北县 | 13 | Qibei | 4 | 1 | 0 | China | @China@Hunan@Hengyang@Qibei + 12 | 南山区 | 10 | Nanshan | 4 | 1 | 0 | China | @China@Guangdong@Shenzhen@Nanshan + 21 | 祁西县 | 13 | Qixi | 4 | 1 | 0 | China | @China@Hunan@Hengyang@Qixi + 14 | 耒阳市 | 13 | Leiyang | 4 | 1 | 0 | China | @China@Hunan@Hengyang@Leiyang + 15 | 龙岗区 | 10 | Longgang | 4 | 1 | 0 | China | @China@Guangdong@Shenzhen@Longgang + 16 | 福田区 | 10 | Futian | 4 | 1 | 0 | China | @China@Guangdong@Shenzhen@Futian + 17 | 宝安区 | 10 | Baoan | 4 | 1 | 0 | China | @China@Guangdong@Shenzhen@Baoan + 19 | 祁东县 | 13 | Qidong | 4 | 1 | 0 | China | @China@Hunan@Hengyang@Qidong + 18 | 常宁市 | 13 | Changning | 4 | 1 | 0 | China | @China@Hunan@Hengyang@Changning + 20 | 祁南县 | 13 | Qinan | 4 | 1 | 0 | China | @China@Hunan@Hengyang@Qinan +(22 rows) + +/* + * 用例1.2,基础用例包含所有伪列,root节点方向遍历查找 + **/ +EXPLAIN (COSTS OFF) +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), sys_connect_by_path(name_desc, '@') +FROM test_area +START WITH name = '耒阳市' +CONNECT BY id = PRIOR fatherid; + QUERY PLAN +------------------------------------------------------------------------------------------ + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_3, array_col_4 + -> Recursive Union + -> Seq Scan on test_area + Filter: (name = '耒阳市'::text) + -> Hash Join + Hash Cond: (swtest.test_area.id = tmp_reuslt."test_area@fatherid") + -> Seq Scan on test_area + -> Hash + -> WorkTable Scan on tmp_reuslt +(12 rows) + +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), sys_connect_by_path(name_desc, '@') +FROM test_area +START WITH name = '耒阳市' +CONNECT BY id = PRIOR fatherid; + id | name | fatherid | name_desc | level | connect_by_isleaf | connect_by_iscycle | connect_by_root | sys_connect_by_path +----+--------+----------+-----------+-------+-------------------+--------------------+-----------------+------------------------------- + 14 | 耒阳市 | 13 | Leiyang | 1 | 0 | 0 | Leiyang | @Leiyang + 13 | 衡阳市 | 2 | Hengyang | 2 | 0 | 0 | Leiyang | @Leiyang@Hengyang + 2 | 湖南省 | 1 | Hunan | 3 | 0 | 0 | Leiyang | @Leiyang@Hengyang@Hunan + 1 | 中国 | 0 | China | 4 | 1 | 0 | Leiyang | @Leiyang@Hengyang@Hunan@China +(4 rows) + +/* + * 用例1.3,基础用例包含所有伪列,root节点方向遍历查找(两条链) + **/ +EXPLAIN (COSTS OFF) +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), sys_connect_by_path(name_desc, '@') +FROM test_area +START WITH name = '耒阳市' OR name = '宝安区' +CONNECT BY id = PRIOR fatherid; + QUERY PLAN +------------------------------------------------------------------------------------------ + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_3, array_col_4 + -> Recursive Union + -> Seq Scan on test_area + Filter: ((name = '耒阳市'::text) OR (name = '宝安区'::text)) + -> Hash Join + Hash Cond: (swtest.test_area.id = tmp_reuslt."test_area@fatherid") + -> Seq Scan on test_area + -> Hash + -> WorkTable Scan on tmp_reuslt +(12 rows) + +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), sys_connect_by_path(name_desc, '@') +FROM test_area +START WITH name = '耒阳市' OR name = '宝安区' +CONNECT BY id = PRIOR fatherid; + id | name | fatherid | name_desc | level | connect_by_isleaf | connect_by_iscycle | connect_by_root | sys_connect_by_path +----+--------+----------+-----------+-------+-------------------+--------------------+-----------------+--------------------------------- + 14 | 耒阳市 | 13 | Leiyang | 1 | 0 | 0 | Leiyang | @Leiyang + 17 | 宝安区 | 10 | Baoan | 1 | 0 | 0 | Baoan | @Baoan + 10 | 深圳市 | 3 | Shenzhen | 2 | 0 | 0 | Baoan | @Baoan@Shenzhen + 13 | 衡阳市 | 2 | Hengyang | 2 | 0 | 0 | Leiyang | @Leiyang@Hengyang + 2 | 湖南省 | 1 | Hunan | 3 | 0 | 0 | Leiyang | @Leiyang@Hengyang@Hunan + 3 | 广东省 | 1 | Guangdong | 3 | 0 | 0 | Baoan | @Baoan@Shenzhen@Guangdong + 1 | 中国 | 0 | China | 4 | 1 | 0 | Baoan | @Baoan@Shenzhen@Guangdong@China + 1 | 中国 | 0 | China | 4 | 1 | 0 | Leiyang | @Leiyang@Hengyang@Hunan@China +(8 rows) + +/* + * 用例1.5,基础用例包含所有伪列,测试多字符串拼接 + **/ +EXPLAIN (COSTS OFF) +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), sys_connect_by_path(name_desc, '=>>') +FROM test_area +START WITH name = '中国' +CONNECT BY PRIOR id = fatherid; + QUERY PLAN +------------------------------------------------------------------------------------------ + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_1, array_col_4 + -> Recursive Union + -> Seq Scan on test_area + Filter: (name = '中国'::text) + -> Hash Join + Hash Cond: (swtest.test_area.fatherid = tmp_reuslt."test_area@id") + -> Seq Scan on test_area + -> Hash + -> WorkTable Scan on tmp_reuslt +(12 rows) + +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), sys_connect_by_path(name_desc, '=>>') +FROM test_area +START WITH name = '中国' +CONNECT BY PRIOR id = fatherid; + id | name | fatherid | name_desc | level | connect_by_isleaf | connect_by_iscycle | connect_by_root | sys_connect_by_path +----+--------+----------+-----------+-------+-------------------+--------------------+-----------------+-------------------------------------------- + 1 | 中国 | 0 | China | 1 | 0 | 0 | China | =>>China + 2 | 湖南省 | 1 | Hunan | 2 | 0 | 0 | China | =>>China=>>Hunan + 3 | 广东省 | 1 | Guangdong | 2 | 0 | 0 | China | =>>China=>>Guangdong + 4 | 海南省 | 1 | Hainan | 2 | 1 | 0 | China | =>>China=>>Hainan + 5 | 河北省 | 1 | Hebei | 2 | 1 | 0 | China | =>>China=>>Hebei + 6 | 河南省 | 1 | Henan | 2 | 1 | 0 | China | =>>China=>>Henan + 7 | 山东省 | 1 | Shandong | 2 | 1 | 0 | China | =>>China=>>Shandong + 8 | 湖北省 | 1 | Hubei | 2 | 1 | 0 | China | =>>China=>>Hubei + 9 | 江苏省 | 1 | Jiangsu | 2 | 1 | 0 | China | =>>China=>>Jiangsu + 10 | 深圳市 | 3 | Shenzhen | 3 | 0 | 0 | China | =>>China=>>Guangdong=>>Shenzhen + 11 | 长沙市 | 2 | Changsha | 3 | 1 | 0 | China | =>>China=>>Hunan=>>Changsha + 13 | 衡阳市 | 2 | Hengyang | 3 | 0 | 0 | China | =>>China=>>Hunan=>>Hengyang + 22 | 祁北县 | 13 | Qibei | 4 | 1 | 0 | China | =>>China=>>Hunan=>>Hengyang=>>Qibei + 12 | 南山区 | 10 | Nanshan | 4 | 1 | 0 | China | =>>China=>>Guangdong=>>Shenzhen=>>Nanshan + 21 | 祁西县 | 13 | Qixi | 4 | 1 | 0 | China | =>>China=>>Hunan=>>Hengyang=>>Qixi + 14 | 耒阳市 | 13 | Leiyang | 4 | 1 | 0 | China | =>>China=>>Hunan=>>Hengyang=>>Leiyang + 15 | 龙岗区 | 10 | Longgang | 4 | 1 | 0 | China | =>>China=>>Guangdong=>>Shenzhen=>>Longgang + 16 | 福田区 | 10 | Futian | 4 | 1 | 0 | China | =>>China=>>Guangdong=>>Shenzhen=>>Futian + 17 | 宝安区 | 10 | Baoan | 4 | 1 | 0 | China | =>>China=>>Guangdong=>>Shenzhen=>>Baoan + 19 | 祁东县 | 13 | Qidong | 4 | 1 | 0 | China | =>>China=>>Hunan=>>Hengyang=>>Qidong + 18 | 常宁市 | 13 | Changning | 4 | 1 | 0 | China | =>>China=>>Hunan=>>Hengyang=>>Changning + 20 | 祁南县 | 13 | Qinan | 4 | 1 | 0 | China | =>>China=>>Hunan=>>Hengyang=>>Qinan +(22 rows) + +/* + * 用例1.6,基础用例包含所有伪列, 包含多字符拼接,多条查找链,startwith使用LIKE查找 + **/ +EXPLAIN (COSTS OFF) +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), sys_connect_by_path(name_desc, '-*>') +FROM test_area +START WITH name like '%区' +CONNECT BY id = PRIOR fatherid; + QUERY PLAN +------------------------------------------------------------------------------------------ + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_3, array_col_4 + -> Recursive Union + -> Seq Scan on test_area + Filter: (name ~~ '%区'::text) + -> Hash Join + Hash Cond: (tmp_reuslt."test_area@fatherid" = swtest.test_area.id) + -> WorkTable Scan on tmp_reuslt + -> Hash + -> Seq Scan on test_area +(12 rows) + +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), sys_connect_by_path(name_desc, '-*>') +FROM test_area +START WITH name like '%区' +CONNECT BY id = PRIOR fatherid; + id | name | fatherid | name_desc | level | connect_by_isleaf | connect_by_iscycle | connect_by_root | sys_connect_by_path +----+--------+----------+-----------+-------+-------------------+--------------------+-----------------+-------------------------------------------- + 12 | 南山区 | 10 | Nanshan | 1 | 0 | 0 | Nanshan | -*>Nanshan + 15 | 龙岗区 | 10 | Longgang | 1 | 0 | 0 | Longgang | -*>Longgang + 16 | 福田区 | 10 | Futian | 1 | 0 | 0 | Futian | -*>Futian + 17 | 宝安区 | 10 | Baoan | 1 | 0 | 0 | Baoan | -*>Baoan + 10 | 深圳市 | 3 | Shenzhen | 2 | 0 | 0 | Nanshan | -*>Nanshan-*>Shenzhen + 10 | 深圳市 | 3 | Shenzhen | 2 | 0 | 0 | Longgang | -*>Longgang-*>Shenzhen + 10 | 深圳市 | 3 | Shenzhen | 2 | 0 | 0 | Futian | -*>Futian-*>Shenzhen + 10 | 深圳市 | 3 | Shenzhen | 2 | 0 | 0 | Baoan | -*>Baoan-*>Shenzhen + 3 | 广东省 | 1 | Guangdong | 3 | 0 | 0 | Nanshan | -*>Nanshan-*>Shenzhen-*>Guangdong + 3 | 广东省 | 1 | Guangdong | 3 | 0 | 0 | Longgang | -*>Longgang-*>Shenzhen-*>Guangdong + 3 | 广东省 | 1 | Guangdong | 3 | 0 | 0 | Futian | -*>Futian-*>Shenzhen-*>Guangdong + 3 | 广东省 | 1 | Guangdong | 3 | 0 | 0 | Baoan | -*>Baoan-*>Shenzhen-*>Guangdong + 1 | 中国 | 0 | China | 4 | 1 | 0 | Nanshan | -*>Nanshan-*>Shenzhen-*>Guangdong-*>China + 1 | 中国 | 0 | China | 4 | 1 | 0 | Longgang | -*>Longgang-*>Shenzhen-*>Guangdong-*>China + 1 | 中国 | 0 | China | 4 | 1 | 0 | Futian | -*>Futian-*>Shenzhen-*>Guangdong-*>China + 1 | 中国 | 0 | China | 4 | 1 | 0 | Baoan | -*>Baoan-*>Shenzhen-*>Guangdong-*>China +(16 rows) + +-- 二、扩展测试 +/* + * 用例2.1,基础用例包含所有伪列, 包含多字符拼接,多条查找链,startwith使用IN子查询进行查找 + **/ +EXPLAIN (COSTS OFF) +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), sys_connect_by_path(name_desc, '/') +FROM test_area +START WITH name IN (select name from test_area where id < 3) +CONNECT BY PRIOR id = fatherid; + QUERY PLAN +------------------------------------------------------------------------------------------ + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_1, array_col_4 + -> Recursive Union + -> Hash Semi Join + Hash Cond: (swtest.test_area.name = swtest.test_area.name) + -> Seq Scan on test_area + -> Hash + -> Seq Scan on test_area + Filter: (id < 3) + -> Hash Join + Hash Cond: (swtest.test_area.fatherid = tmp_reuslt."test_area@id") + -> Seq Scan on test_area + -> Hash + -> WorkTable Scan on tmp_reuslt +(16 rows) + +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), sys_connect_by_path(name_desc, '/') +FROM test_area +START WITH name IN (select name from test_area where id < 3) +CONNECT BY PRIOR id = fatherid; + id | name | fatherid | name_desc | level | connect_by_isleaf | connect_by_iscycle | connect_by_root | sys_connect_by_path +----+--------+----------+-----------+-------+-------------------+--------------------+-----------------+------------------------------------ + 1 | 中国 | 0 | China | 1 | 0 | 0 | China | /China + 2 | 湖南省 | 1 | Hunan | 1 | 0 | 0 | Hunan | /Hunan + 2 | 湖南省 | 1 | Hunan | 2 | 0 | 0 | China | /China/Hunan + 3 | 广东省 | 1 | Guangdong | 2 | 0 | 0 | China | /China/Guangdong + 4 | 海南省 | 1 | Hainan | 2 | 1 | 0 | China | /China/Hainan + 5 | 河北省 | 1 | Hebei | 2 | 1 | 0 | China | /China/Hebei + 6 | 河南省 | 1 | Henan | 2 | 1 | 0 | China | /China/Henan + 7 | 山东省 | 1 | Shandong | 2 | 1 | 0 | China | /China/Shandong + 8 | 湖北省 | 1 | Hubei | 2 | 1 | 0 | China | /China/Hubei + 9 | 江苏省 | 1 | Jiangsu | 2 | 1 | 0 | China | /China/Jiangsu + 11 | 长沙市 | 2 | Changsha | 2 | 1 | 0 | Hunan | /Hunan/Changsha + 13 | 衡阳市 | 2 | Hengyang | 2 | 0 | 0 | Hunan | /Hunan/Hengyang + 10 | 深圳市 | 3 | Shenzhen | 3 | 0 | 0 | China | /China/Guangdong/Shenzhen + 11 | 长沙市 | 2 | Changsha | 3 | 1 | 0 | China | /China/Hunan/Changsha + 22 | 祁北县 | 13 | Qibei | 3 | 1 | 0 | Hunan | /Hunan/Hengyang/Qibei + 21 | 祁西县 | 13 | Qixi | 3 | 1 | 0 | Hunan | /Hunan/Hengyang/Qixi + 13 | 衡阳市 | 2 | Hengyang | 3 | 0 | 0 | China | /China/Hunan/Hengyang + 14 | 耒阳市 | 13 | Leiyang | 3 | 1 | 0 | Hunan | /Hunan/Hengyang/Leiyang + 19 | 祁东县 | 13 | Qidong | 3 | 1 | 0 | Hunan | /Hunan/Hengyang/Qidong + 18 | 常宁市 | 13 | Changning | 3 | 1 | 0 | Hunan | /Hunan/Hengyang/Changning + 20 | 祁南县 | 13 | Qinan | 3 | 1 | 0 | Hunan | /Hunan/Hengyang/Qinan + 22 | 祁北县 | 13 | Qibei | 4 | 1 | 0 | China | /China/Hunan/Hengyang/Qibei + 12 | 南山区 | 10 | Nanshan | 4 | 1 | 0 | China | /China/Guangdong/Shenzhen/Nanshan + 21 | 祁西县 | 13 | Qixi | 4 | 1 | 0 | China | /China/Hunan/Hengyang/Qixi + 14 | 耒阳市 | 13 | Leiyang | 4 | 1 | 0 | China | /China/Hunan/Hengyang/Leiyang + 15 | 龙岗区 | 10 | Longgang | 4 | 1 | 0 | China | /China/Guangdong/Shenzhen/Longgang + 16 | 福田区 | 10 | Futian | 4 | 1 | 0 | China | /China/Guangdong/Shenzhen/Futian + 17 | 宝安区 | 10 | Baoan | 4 | 1 | 0 | China | /China/Guangdong/Shenzhen/Baoan + 19 | 祁东县 | 13 | Qidong | 4 | 1 | 0 | China | /China/Hunan/Hengyang/Qidong + 18 | 常宁市 | 13 | Changning | 4 | 1 | 0 | China | /China/Hunan/Hengyang/Changning + 20 | 祁南县 | 13 | Qinan | 4 | 1 | 0 | China | /China/Hunan/Hengyang/Qinan +(31 rows) + +/* + * 用例2.2,基础用例包含所有伪列, 包含多字符拼接,多条查找链,startwith使用IN子查询进行查找,结果集进行伪列过滤 + **/ +EXPLAIN (COSTS OFF) +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), sys_connect_by_path(name_desc, '/') +FROM test_area +WHERE LEVEL > 2 +START WITH name IN (select name from test_area where id < 3) +CONNECT BY PRIOR id = fatherid; + QUERY PLAN +------------------------------------------------------------------------------------------ + CTE Scan on tmp_reuslt + Filter: (level > 2) + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_1, array_col_4 + -> Recursive Union + -> Hash Semi Join + Hash Cond: (swtest.test_area.name = swtest.test_area.name) + -> Seq Scan on test_area + -> Hash + -> Seq Scan on test_area + Filter: (id < 3) + -> Hash Join + Hash Cond: (swtest.test_area.fatherid = tmp_reuslt."test_area@id") + -> Seq Scan on test_area + -> Hash + -> WorkTable Scan on tmp_reuslt +(17 rows) + +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), sys_connect_by_path(name_desc, '/') +FROM test_area +WHERE LEVEL > 2 +START WITH name IN (select name from test_area where id < 3) +CONNECT BY PRIOR id = fatherid; + id | name | fatherid | name_desc | level | connect_by_isleaf | connect_by_iscycle | connect_by_root | sys_connect_by_path +----+--------+----------+-----------+-------+-------------------+--------------------+-----------------+------------------------------------ + 10 | 深圳市 | 3 | Shenzhen | 3 | 0 | 0 | China | /China/Guangdong/Shenzhen + 11 | 长沙市 | 2 | Changsha | 3 | 1 | 0 | China | /China/Hunan/Changsha + 22 | 祁北县 | 13 | Qibei | 3 | 1 | 0 | Hunan | /Hunan/Hengyang/Qibei + 21 | 祁西县 | 13 | Qixi | 3 | 1 | 0 | Hunan | /Hunan/Hengyang/Qixi + 13 | 衡阳市 | 2 | Hengyang | 3 | 0 | 0 | China | /China/Hunan/Hengyang + 14 | 耒阳市 | 13 | Leiyang | 3 | 1 | 0 | Hunan | /Hunan/Hengyang/Leiyang + 19 | 祁东县 | 13 | Qidong | 3 | 1 | 0 | Hunan | /Hunan/Hengyang/Qidong + 18 | 常宁市 | 13 | Changning | 3 | 1 | 0 | Hunan | /Hunan/Hengyang/Changning + 20 | 祁南县 | 13 | Qinan | 3 | 1 | 0 | Hunan | /Hunan/Hengyang/Qinan + 22 | 祁北县 | 13 | Qibei | 4 | 1 | 0 | China | /China/Hunan/Hengyang/Qibei + 12 | 南山区 | 10 | Nanshan | 4 | 1 | 0 | China | /China/Guangdong/Shenzhen/Nanshan + 21 | 祁西县 | 13 | Qixi | 4 | 1 | 0 | China | /China/Hunan/Hengyang/Qixi + 14 | 耒阳市 | 13 | Leiyang | 4 | 1 | 0 | China | /China/Hunan/Hengyang/Leiyang + 15 | 龙岗区 | 10 | Longgang | 4 | 1 | 0 | China | /China/Guangdong/Shenzhen/Longgang + 16 | 福田区 | 10 | Futian | 4 | 1 | 0 | China | /China/Guangdong/Shenzhen/Futian + 17 | 宝安区 | 10 | Baoan | 4 | 1 | 0 | China | /China/Guangdong/Shenzhen/Baoan + 19 | 祁东县 | 13 | Qidong | 4 | 1 | 0 | China | /China/Hunan/Hengyang/Qidong + 18 | 常宁市 | 13 | Changning | 4 | 1 | 0 | China | /China/Hunan/Hengyang/Changning + 20 | 祁南县 | 13 | Qinan | 4 | 1 | 0 | China | /China/Hunan/Hengyang/Qinan +(19 rows) + +/* + * 用例2.3,基础用例包含所有伪列, 包含多字符拼接,多条查找链,startwith使用IN子查询进行查找,结果集进行多个伪列过滤 + **/ +EXPLAIN (COSTS OFF) +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), sys_connect_by_path(name_desc, '/') +FROM test_area +WHERE LEVEL > 2 AND connect_by_iscycle IS NOT NULL +START WITH name IN (select name from test_area where id < 3) +CONNECT BY PRIOR id = fatherid; + QUERY PLAN +------------------------------------------------------------------------------------------ + CTE Scan on tmp_reuslt + Filter: ((connect_by_iscycle IS NOT NULL) AND (level > 2)) + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_1, array_col_4 + -> Recursive Union + -> Hash Semi Join + Hash Cond: (swtest.test_area.name = swtest.test_area.name) + -> Seq Scan on test_area + -> Hash + -> Seq Scan on test_area + Filter: (id < 3) + -> Hash Join + Hash Cond: (swtest.test_area.fatherid = tmp_reuslt."test_area@id") + -> Seq Scan on test_area + -> Hash + -> WorkTable Scan on tmp_reuslt +(17 rows) + +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), sys_connect_by_path(name_desc, '/') +FROM test_area +WHERE LEVEL > 2 AND connect_by_iscycle IS NOT NULL +START WITH name IN (select name from test_area where id < 3) +CONNECT BY PRIOR id = fatherid; + id | name | fatherid | name_desc | level | connect_by_isleaf | connect_by_iscycle | connect_by_root | sys_connect_by_path +----+--------+----------+-----------+-------+-------------------+--------------------+-----------------+------------------------------------ + 10 | 深圳市 | 3 | Shenzhen | 3 | 0 | 0 | China | /China/Guangdong/Shenzhen + 11 | 长沙市 | 2 | Changsha | 3 | 1 | 0 | China | /China/Hunan/Changsha + 22 | 祁北县 | 13 | Qibei | 3 | 1 | 0 | Hunan | /Hunan/Hengyang/Qibei + 21 | 祁西县 | 13 | Qixi | 3 | 1 | 0 | Hunan | /Hunan/Hengyang/Qixi + 13 | 衡阳市 | 2 | Hengyang | 3 | 0 | 0 | China | /China/Hunan/Hengyang + 14 | 耒阳市 | 13 | Leiyang | 3 | 1 | 0 | Hunan | /Hunan/Hengyang/Leiyang + 19 | 祁东县 | 13 | Qidong | 3 | 1 | 0 | Hunan | /Hunan/Hengyang/Qidong + 18 | 常宁市 | 13 | Changning | 3 | 1 | 0 | Hunan | /Hunan/Hengyang/Changning + 20 | 祁南县 | 13 | Qinan | 3 | 1 | 0 | Hunan | /Hunan/Hengyang/Qinan + 22 | 祁北县 | 13 | Qibei | 4 | 1 | 0 | China | /China/Hunan/Hengyang/Qibei + 12 | 南山区 | 10 | Nanshan | 4 | 1 | 0 | China | /China/Guangdong/Shenzhen/Nanshan + 21 | 祁西县 | 13 | Qixi | 4 | 1 | 0 | China | /China/Hunan/Hengyang/Qixi + 14 | 耒阳市 | 13 | Leiyang | 4 | 1 | 0 | China | /China/Hunan/Hengyang/Leiyang + 15 | 龙岗区 | 10 | Longgang | 4 | 1 | 0 | China | /China/Guangdong/Shenzhen/Longgang + 16 | 福田区 | 10 | Futian | 4 | 1 | 0 | China | /China/Guangdong/Shenzhen/Futian + 17 | 宝安区 | 10 | Baoan | 4 | 1 | 0 | China | /China/Guangdong/Shenzhen/Baoan + 19 | 祁东县 | 13 | Qidong | 4 | 1 | 0 | China | /China/Hunan/Hengyang/Qidong + 18 | 常宁市 | 13 | Changning | 4 | 1 | 0 | China | /China/Hunan/Hengyang/Changning + 20 | 祁南县 | 13 | Qinan | 4 | 1 | 0 | China | /China/Hunan/Hengyang/Qinan +(19 rows) + +-- 三、 打开guc enable_startwith_debug = on测试 +/* DFX test, verify if */ +set enable_startwith_debug=on; +set client_min_messages=log; +explain (costs off) +select *, LEVEL, CONNECT_BY_ROOT(name_desc), SYS_CONNECT_BY_PATH(name, '/') cpath from test_area +START WITH name = '耒阳市' +CONNECT BY id = PRIOR fatherid; +LOG: statement: explain (costs off) +select *, LEVEL, CONNECT_BY_ROOT(name_desc), SYS_CONNECT_BY_PATH(name, '/') cpath from test_area +START WITH name = '耒阳市' +CONNECT BY id = PRIOR fatherid; +LOG: Accept a other Const val when evaluate FakeConst to rownum/level +WARNING: Pushdown pseudo_tlist >>>>> [ -> WorkTableScan(tlist_len:12) -> Hash(tlist_len:12) -> HashJoin(tlist_len:12) -> RecursiveUnion(tlist_len:12)] +WARNING: Pushdown pseudo_tlist >>>>> [ -> CteScan(tlist_len:11)] + QUERY PLAN +------------------------------------------------------------------------------------------ + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_3, array_col_2, array_col_4 + -> Recursive Union + -> Seq Scan on test_area + Filter: (name = '耒阳市'::text) + -> Hash Join + Hash Cond: (swtest.test_area.id = tmp_reuslt."test_area@fatherid") + -> Seq Scan on test_area + -> Hash + -> WorkTable Scan on tmp_reuslt +(12 rows) + +select *, LEVEL, CONNECT_BY_ROOT(name_desc), SYS_CONNECT_BY_PATH(name, '/') cpath from test_area +START WITH name = '耒阳市' +CONNECT BY id = PRIOR fatherid; +LOG: statement: select *, LEVEL, CONNECT_BY_ROOT(name_desc), SYS_CONNECT_BY_PATH(name, '/') cpath from test_area +START WITH name = '耒阳市' +CONNECT BY id = PRIOR fatherid; +LOG: Accept a other Const val when evaluate FakeConst to rownum/level +WARNING: Pushdown pseudo_tlist >>>>> [ -> WorkTableScan(tlist_len:12) -> Hash(tlist_len:12) -> HashJoin(tlist_len:12) -> RecursiveUnion(tlist_len:12)] +WARNING: Pushdown pseudo_tlist >>>>> [ -> CteScan(tlist_len:11)] +LOG: StartWithDebug: LEVEL:1 array_key_1:/{13} +LOG: StartWithDebug: LEVEL:2 array_key_1:/{13}/{2} +LOG: StartWithDebug: LEVEL:3 array_key_1:/{13}/{2}/{1} +LOG: StartWithDebug: LEVEL:4 array_key_1:/{13}/{2}/{1}/{0} + id | name | fatherid | name_desc | level | connect_by_root | cpath | RUITR | array_key_3 | array_col_2 | array_col_4 +----+--------+----------+-----------+-------+-----------------+----------------------------+-------+-------------------+----------------------------+------------------------------- + 14 | 耒阳市 | 13 | Leiyang | 1 | Leiyang | /耒阳市 | 0 | /{13} | /耒阳市 | /Leiyang + 13 | 衡阳市 | 2 | Hengyang | 2 | Leiyang | /耒阳市/衡阳市 | 1 | /{13}/{2} | /耒阳市/衡阳市 | /Leiyang/Hengyang + 2 | 湖南省 | 1 | Hunan | 3 | Leiyang | /耒阳市/衡阳市/湖南省 | 2 | /{13}/{2}/{1} | /耒阳市/衡阳市/湖南省 | /Leiyang/Hengyang/Hunan + 1 | 中国 | 0 | China | 4 | Leiyang | /耒阳市/衡阳市/湖南省/中国 | 3 | /{13}/{2}/{1}/{0} | /耒阳市/衡阳市/湖南省/中国 | /Leiyang/Hengyang/Hunan/China +(4 rows) + +explain (costs off) +select *, LEVEL, CONNECT_BY_ROOT(name_desc), SYS_CONNECT_BY_PATH(name, '/') cpath from test_area +START WITH name = '中国' +CONNECT BY prior id = fatherid +order siblings by id; +LOG: statement: explain (costs off) +select *, LEVEL, CONNECT_BY_ROOT(name_desc), SYS_CONNECT_BY_PATH(name, '/') cpath from test_area +START WITH name = '中国' +CONNECT BY prior id = fatherid +order siblings by id; +LOG: Accept a other Const val when evaluate FakeConst to rownum/level +WARNING: Good we got siblings sort key under RU. +WARNING: Good we got siblings sort key under RU. +WARNING: Good we got siblings sort key above RU. +WARNING: Pushdown pseudo_tlist >>>>> [ -> WorkTableScan(tlist_len:13) -> Hash(tlist_len:13) -> HashJoin(tlist_len:13) -> Sort(tlist_len:13) -> RecursiveUnion(tlist_len:13)] +WARNING: Pushdown pseudo_tlist >>>>> [ -> CteScan(tlist_len:12)] + QUERY PLAN +------------------------------------------------------------------------------------------------------ + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_1, array_col_2, array_col_4, array_siblings + -> Sort + Sort Key: array_siblings + -> Recursive Union + -> Sort + Sort Key: swtest.test_area.id + -> Seq Scan on test_area + Filter: (name = '中国'::text) + -> Sort + Sort Key: swtest.test_area.id + -> Hash Join + Hash Cond: (swtest.test_area.fatherid = tmp_reuslt."test_area@id") + -> Seq Scan on test_area + -> Hash + -> WorkTable Scan on tmp_reuslt +(18 rows) + +select *, LEVEL, CONNECT_BY_ROOT(name_desc), SYS_CONNECT_BY_PATH(name, '/') cpath from test_area +START WITH name = '中国' +CONNECT BY prior id = fatherid +order siblings by id; +LOG: statement: select *, LEVEL, CONNECT_BY_ROOT(name_desc), SYS_CONNECT_BY_PATH(name, '/') cpath from test_area +START WITH name = '中国' +CONNECT BY prior id = fatherid +order siblings by id; +LOG: Accept a other Const val when evaluate FakeConst to rownum/level +WARNING: Good we got siblings sort key under RU. +WARNING: Good we got siblings sort key under RU. +WARNING: Good we got siblings sort key above RU. +WARNING: Pushdown pseudo_tlist >>>>> [ -> WorkTableScan(tlist_len:13) -> Hash(tlist_len:13) -> HashJoin(tlist_len:13) -> Sort(tlist_len:13) -> RecursiveUnion(tlist_len:13)] +WARNING: Pushdown pseudo_tlist >>>>> [ -> CteScan(tlist_len:12)] +LOG: siblings key is \x01000000 current level is 1 tuple position is 1. +LOG: StartWithDebug: LEVEL:1 array_key_1:/{1} +LOG: siblings key is \x0100000001000000 current level is 2 tuple position is 1 +LOG: StartWithDebug: LEVEL:2 array_key_1:/{1}/{2} +LOG: siblings key is \x0100000002000000 current level is 2 tuple position is 2 +LOG: StartWithDebug: LEVEL:2 array_key_1:/{1}/{3} +LOG: siblings key is \x0100000003000000 current level is 2 tuple position is 3 +LOG: StartWithDebug: LEVEL:2 array_key_1:/{1}/{4} +LOG: siblings key is \x0100000004000000 current level is 2 tuple position is 4 +LOG: StartWithDebug: LEVEL:2 array_key_1:/{1}/{5} +LOG: siblings key is \x0100000005000000 current level is 2 tuple position is 5 +LOG: StartWithDebug: LEVEL:2 array_key_1:/{1}/{6} +LOG: siblings key is \x0100000006000000 current level is 2 tuple position is 6 +LOG: StartWithDebug: LEVEL:2 array_key_1:/{1}/{7} +LOG: siblings key is \x0100000007000000 current level is 2 tuple position is 7 +LOG: StartWithDebug: LEVEL:2 array_key_1:/{1}/{8} +LOG: siblings key is \x0100000008000000 current level is 2 tuple position is 8 +LOG: StartWithDebug: LEVEL:2 array_key_1:/{1}/{9} +LOG: siblings key is \x010000000200000001000000 current level is 3 tuple position is 1 +LOG: StartWithDebug: LEVEL:3 array_key_1:/{1}/{3}/{10} +LOG: siblings key is \x010000000100000002000000 current level is 3 tuple position is 2 +LOG: StartWithDebug: LEVEL:3 array_key_1:/{1}/{2}/{11} +LOG: siblings key is \x010000000100000003000000 current level is 3 tuple position is 3 +LOG: StartWithDebug: LEVEL:3 array_key_1:/{1}/{2}/{13} +LOG: siblings key is \x01000000020000000100000001000000 current level is 4 tuple position is 1 +LOG: StartWithDebug: LEVEL:4 array_key_1:/{1}/{3}/{10}/{12} +LOG: siblings key is \x01000000010000000300000002000000 current level is 4 tuple position is 2 +LOG: StartWithDebug: LEVEL:4 array_key_1:/{1}/{2}/{13}/{14} +LOG: siblings key is \x01000000020000000100000003000000 current level is 4 tuple position is 3 +LOG: StartWithDebug: LEVEL:4 array_key_1:/{1}/{3}/{10}/{15} +LOG: siblings key is \x01000000020000000100000004000000 current level is 4 tuple position is 4 +LOG: StartWithDebug: LEVEL:4 array_key_1:/{1}/{3}/{10}/{16} +LOG: siblings key is \x01000000020000000100000005000000 current level is 4 tuple position is 5 +LOG: StartWithDebug: LEVEL:4 array_key_1:/{1}/{3}/{10}/{17} +LOG: siblings key is \x01000000010000000300000006000000 current level is 4 tuple position is 6 +LOG: StartWithDebug: LEVEL:4 array_key_1:/{1}/{2}/{13}/{18} +LOG: siblings key is \x01000000010000000300000007000000 current level is 4 tuple position is 7 +LOG: StartWithDebug: LEVEL:4 array_key_1:/{1}/{2}/{13}/{19} +LOG: siblings key is \x01000000010000000300000008000000 current level is 4 tuple position is 8 +LOG: StartWithDebug: LEVEL:4 array_key_1:/{1}/{2}/{13}/{20} +LOG: siblings key is \x01000000010000000300000009000000 current level is 4 tuple position is 9 +LOG: StartWithDebug: LEVEL:4 array_key_1:/{1}/{2}/{13}/{21} +LOG: siblings key is \x0100000001000000030000000a000000 current level is 4 tuple position is 10 +LOG: StartWithDebug: LEVEL:4 array_key_1:/{1}/{2}/{13}/{22} + id | name | fatherid | name_desc | level | connect_by_root | cpath | RUITR | array_key_1 | array_col_2 | array_col_4 | array_siblings +----+--------+----------+-----------+-------+-----------------+----------------------------+-------+--------------------+----------------------------+------------------------------------+------------------------------------ + 1 | 中国 | 0 | China | 1 | China | /中国 | 0 | /{1} | /中国 | /China | \x01000000 + 2 | 湖南省 | 1 | Hunan | 2 | China | /中国/湖南省 | 1 | /{1}/{2} | /中国/湖南省 | /China/Hunan | \x0100000001000000 + 11 | 长沙市 | 2 | Changsha | 3 | China | /中国/湖南省/长沙市 | 2 | /{1}/{2}/{11} | /中国/湖南省/长沙市 | /China/Hunan/Changsha | \x010000000100000002000000 + 13 | 衡阳市 | 2 | Hengyang | 3 | China | /中国/湖南省/衡阳市 | 2 | /{1}/{2}/{13} | /中国/湖南省/衡阳市 | /China/Hunan/Hengyang | \x010000000100000003000000 + 14 | 耒阳市 | 13 | Leiyang | 4 | China | /中国/湖南省/衡阳市/耒阳市 | 3 | /{1}/{2}/{13}/{14} | /中国/湖南省/衡阳市/耒阳市 | /China/Hunan/Hengyang/Leiyang | \x01000000010000000300000002000000 + 18 | 常宁市 | 13 | Changning | 4 | China | /中国/湖南省/衡阳市/常宁市 | 3 | /{1}/{2}/{13}/{18} | /中国/湖南省/衡阳市/常宁市 | /China/Hunan/Hengyang/Changning | \x01000000010000000300000006000000 + 19 | 祁东县 | 13 | Qidong | 4 | China | /中国/湖南省/衡阳市/祁东县 | 3 | /{1}/{2}/{13}/{19} | /中国/湖南省/衡阳市/祁东县 | /China/Hunan/Hengyang/Qidong | \x01000000010000000300000007000000 + 20 | 祁南县 | 13 | Qinan | 4 | China | /中国/湖南省/衡阳市/祁南县 | 3 | /{1}/{2}/{13}/{20} | /中国/湖南省/衡阳市/祁南县 | /China/Hunan/Hengyang/Qinan | \x01000000010000000300000008000000 + 21 | 祁西县 | 13 | Qixi | 4 | China | /中国/湖南省/衡阳市/祁西县 | 3 | /{1}/{2}/{13}/{21} | /中国/湖南省/衡阳市/祁西县 | /China/Hunan/Hengyang/Qixi | \x01000000010000000300000009000000 + 22 | 祁北县 | 13 | Qibei | 4 | China | /中国/湖南省/衡阳市/祁北县 | 3 | /{1}/{2}/{13}/{22} | /中国/湖南省/衡阳市/祁北县 | /China/Hunan/Hengyang/Qibei | \x0100000001000000030000000a000000 + 3 | 广东省 | 1 | Guangdong | 2 | China | /中国/广东省 | 1 | /{1}/{3} | /中国/广东省 | /China/Guangdong | \x0100000002000000 + 10 | 深圳市 | 3 | Shenzhen | 3 | China | /中国/广东省/深圳市 | 2 | /{1}/{3}/{10} | /中国/广东省/深圳市 | /China/Guangdong/Shenzhen | \x010000000200000001000000 + 12 | 南山区 | 10 | Nanshan | 4 | China | /中国/广东省/深圳市/南山区 | 3 | /{1}/{3}/{10}/{12} | /中国/广东省/深圳市/南山区 | /China/Guangdong/Shenzhen/Nanshan | \x01000000020000000100000001000000 + 15 | 龙岗区 | 10 | Longgang | 4 | China | /中国/广东省/深圳市/龙岗区 | 3 | /{1}/{3}/{10}/{15} | /中国/广东省/深圳市/龙岗区 | /China/Guangdong/Shenzhen/Longgang | \x01000000020000000100000003000000 + 16 | 福田区 | 10 | Futian | 4 | China | /中国/广东省/深圳市/福田区 | 3 | /{1}/{3}/{10}/{16} | /中国/广东省/深圳市/福田区 | /China/Guangdong/Shenzhen/Futian | \x01000000020000000100000004000000 + 17 | 宝安区 | 10 | Baoan | 4 | China | /中国/广东省/深圳市/宝安区 | 3 | /{1}/{3}/{10}/{17} | /中国/广东省/深圳市/宝安区 | /China/Guangdong/Shenzhen/Baoan | \x01000000020000000100000005000000 + 4 | 海南省 | 1 | Hainan | 2 | China | /中国/海南省 | 1 | /{1}/{4} | /中国/海南省 | /China/Hainan | \x0100000003000000 + 5 | 河北省 | 1 | Hebei | 2 | China | /中国/河北省 | 1 | /{1}/{5} | /中国/河北省 | /China/Hebei | \x0100000004000000 + 6 | 河南省 | 1 | Henan | 2 | China | /中国/河南省 | 1 | /{1}/{6} | /中国/河南省 | /China/Henan | \x0100000005000000 + 7 | 山东省 | 1 | Shandong | 2 | China | /中国/山东省 | 1 | /{1}/{7} | /中国/山东省 | /China/Shandong | \x0100000006000000 + 8 | 湖北省 | 1 | Hubei | 2 | China | /中国/湖北省 | 1 | /{1}/{8} | /中国/湖北省 | /China/Hubei | \x0100000007000000 + 9 | 江苏省 | 1 | Jiangsu | 2 | China | /中国/江苏省 | 1 | /{1}/{9} | /中国/江苏省 | /China/Jiangsu | \x0100000008000000 +(22 rows) + +reset enable_startwith_debug; +LOG: statement: reset enable_startwith_debug; +reset client_min_messages; +LOG: statement: reset client_min_messages; diff --git a/src/test/regress/expected/sw_bugfix.out b/src/test/regress/expected/sw_bugfix.out new file mode 100644 index 000000000..cfd2966af --- /dev/null +++ b/src/test/regress/expected/sw_bugfix.out @@ -0,0 +1,2510 @@ +set client_min_messages = error; +SET CLIENT_ENCODING='UTF8'; +set current_schema=swtest; +/* invalid data type */ +SELECT NAME,LEVEL,CONNECT_BY_ISLEAF,SYS_CONNECT_BY_PATH(NAME,'|'),CONNECT_BY_ROOT(NAME),ID,CHA,VCH,TEX,DAT,TIM,TIS,PID,PCHA,PVCH,PTEX,PDAT,PTIM,PTIS +FROM TEST_HCB_FQB +START WITH ID=1 +CONNECT BY prior ID=PID +ORDER SIBLINGS BY NAME ASC; + name | level | connect_by_isleaf | sys_connect_by_path | connect_by_root | id | cha | vch | tex | dat | tim | tis | pid | pcha | pvch | ptex | pdat | ptim | ptis +--------+-------+-------------------+-----------------------------------+-----------------+-----+------------+-----+-----+--------------------------+----------+--------------------------+-----+------------+------+------+--------------------------+----------+-------------------------- + 中国 | 1 | 0 | |中国 | 中国 | 1 | a | a | a | Sun Dec 12 12:12:12 2021 | 12:12:12 | Sun Dec 12 12:12:12 2021 | 0 | 0 | 0 | 0 | Tue Dec 12 12:12:12 2000 | 00:00:01 | Tue Dec 12 12:12:12 2000 + 安徽省 | 2 | 1 | |中国|安徽省 | 中国 | 13 | ac | ac | ac | Fri Jan 01 01:01:02 2021 | 01:01:02 | Fri Jan 01 01:01:02 2021 | 1 | a | a | a | Sun Dec 12 12:12:12 2021 | 12:12:12 | Sun Dec 12 12:12:12 2021 + 山东省 | 2 | 1 | |中国|山东省 | 中国 | 12 | ab | ab | ab | Fri Jan 01 01:01:01 2021 | 01:01:01 | Fri Jan 01 01:01:01 2021 | 1 | a | a | a | Sun Dec 12 12:12:12 2021 | 12:12:12 | Sun Dec 12 12:12:12 2021 + 武汉省 | 2 | 1 | |中国|武汉省 | 中国 | 19 | ai | ai | ai | Fri Jan 01 01:01:09 2021 | 01:01:09 | Fri Jan 01 01:01:09 2021 | 1 | a | a | a | Sun Dec 12 12:12:12 2021 | 12:12:12 | Sun Dec 12 12:12:12 2021 + 江苏省 | 2 | 0 | |中国|江苏省 | 中国 | 11 | aa | aa | aa | Fri Jan 01 01:01:01 2021 | 01:01:01 | Fri Jan 01 01:01:01 2021 | 1 | a | a | a | Sun Dec 12 12:12:12 2021 | 12:12:12 | Sun Dec 12 12:12:12 2021 + 南京市 | 3 | 0 | |中国|江苏省|南京市 | 中国 | 111 | aaa | aaa | aaa | Fri Jan 01 01:01:10 2021 | 01:01:10 | Fri Jan 01 01:01:10 2021 | 11 | aa | aa | aa | Fri Jan 01 01:01:01 2021 | 01:01:01 | Fri Jan 01 01:01:01 2021 + 六合区 | 4 | 1 | |中国|江苏省|南京市|六合区 | 中国 | 129 | abi | abi | abi | Fri Jan 01 01:01:28 2021 | 01:01:28 | Fri Jan 01 01:01:28 2021 | 111 | aaa | aaa | aaa | Fri Jan 01 01:01:10 2021 | 01:01:10 | Fri Jan 01 01:01:10 2021 + 建邺区 | 4 | 1 | |中国|江苏省|南京市|建邺区 | 中国 | 125 | abe | abe | abe | Fri Jan 01 01:01:24 2021 | 01:01:24 | Fri Jan 01 01:01:24 2021 | 111 | aaa | aaa | aaa | Fri Jan 01 01:01:10 2021 | 01:01:10 | Fri Jan 01 01:01:10 2021 + 江宁区 | 4 | 0 | |中国|江苏省|南京市|江宁区 | 中国 | 121 | aba | aba | aba | Fri Jan 01 01:01:20 2021 | 01:01:20 | Fri Jan 01 01:01:20 2021 | 111 | aaa | aaa | aaa | Fri Jan 01 01:01:10 2021 | 01:01:10 | Fri Jan 01 01:01:10 2021 + 东山街 | 5 | 1 | |中国|江苏省|南京市|江宁区|东山街 | 中国 | 131 | aca | aca | aca | Fri Jan 01 01:01:30 2021 | 01:01:30 | Fri Jan 01 01:01:30 2021 | 121 | aba | aba | aba | Fri Jan 01 01:01:20 2021 | 01:01:20 | Fri Jan 01 01:01:20 2021 + 横溪街 | 5 | 1 | |中国|江苏省|南京市|江宁区|横溪街 | 中国 | 139 | aci | aci | aci | Fri Jan 01 01:01:38 2021 | 01:01:38 | Fri Jan 01 01:01:38 2021 | 121 | aba | aba | aba | Fri Jan 01 01:01:20 2021 | 01:01:20 | Fri Jan 01 01:01:20 2021 + 江宁街 | 5 | 1 | |中国|江苏省|南京市|江宁区|江宁街 | 中国 | 136 | acf | acf | acf | Fri Jan 01 01:01:35 2021 | 01:01:35 | Fri Jan 01 01:01:35 2021 | 121 | aba | aba | aba | Fri Jan 01 01:01:20 2021 | 01:01:20 | Fri Jan 01 01:01:20 2021 + 汤山街 | 5 | 1 | |中国|江苏省|南京市|江宁区|汤山街 | 中国 | 133 | acc | acc | acc | Fri Jan 01 01:01:32 2021 | 01:01:32 | Fri Jan 01 01:01:32 2021 | 121 | aba | aba | aba | Fri Jan 01 01:01:20 2021 | 01:01:20 | Fri Jan 01 01:01:20 2021 + 淳化街 | 5 | 1 | |中国|江苏省|南京市|江宁区|淳化街 | 中国 | 134 | acd | acd | acd | Fri Jan 01 01:01:33 2021 | 01:01:33 | Fri Jan 01 01:01:33 2021 | 121 | aba | aba | aba | Fri Jan 01 01:01:20 2021 | 01:01:20 | Fri Jan 01 01:01:20 2021 + 湖熟街 | 5 | 1 | |中国|江苏省|南京市|江宁区|湖熟街 | 中国 | 138 | ach | ach | ach | Fri Jan 01 01:01:37 2021 | 01:01:37 | Fri Jan 01 01:01:37 2021 | 121 | aba | aba | aba | Fri Jan 01 01:01:20 2021 | 01:01:20 | Fri Jan 01 01:01:20 2021 + 禄口街 | 5 | 1 | |中国|江苏省|南京市|江宁区|禄口街 | 中国 | 135 | ace | ace | ace | Fri Jan 01 01:01:34 2021 | 01:01:34 | Fri Jan 01 01:01:34 2021 | 121 | aba | aba | aba | Fri Jan 01 01:01:20 2021 | 01:01:20 | Fri Jan 01 01:01:20 2021 + 秣陵街 | 5 | 1 | |中国|江苏省|南京市|江宁区|秣陵街 | 中国 | 132 | acb | acb | acb | Fri Jan 01 01:01:31 2021 | 01:01:31 | Fri Jan 01 01:01:31 2021 | 121 | aba | aba | aba | Fri Jan 01 01:01:20 2021 | 01:01:20 | Fri Jan 01 01:01:20 2021 + 谷里街 | 5 | 1 | |中国|江苏省|南京市|江宁区|谷里街 | 中国 | 137 | acg | acg | acg | Fri Jan 01 01:01:36 2021 | 01:01:36 | Fri Jan 01 01:01:36 2021 | 121 | aba | aba | aba | Fri Jan 01 01:01:20 2021 | 01:01:20 | Fri Jan 01 01:01:20 2021 + 浦口区 | 4 | 1 | |中国|江苏省|南京市|浦口区 | 中国 | 127 | abg | abg | abg | Fri Jan 01 01:01:26 2021 | 01:01:26 | Fri Jan 01 01:01:26 2021 | 111 | aaa | aaa | aaa | Fri Jan 01 01:01:10 2021 | 01:01:10 | Fri Jan 01 01:01:10 2021 + 浦口区 | 4 | 1 | |中国|江苏省|南京市|浦口区 | 中国 | 128 | abh | abh | abh | Fri Jan 01 01:01:27 2021 | 01:01:27 | Fri Jan 01 01:01:27 2021 | 111 | aaa | aaa | aaa | Fri Jan 01 01:01:10 2021 | 01:01:10 | Fri Jan 01 01:01:10 2021 + 玄武区 | 4 | 1 | |中国|江苏省|南京市|玄武区 | 中国 | 124 | abd | abd | abd | Fri Jan 01 01:01:23 2021 | 01:01:23 | Fri Jan 01 01:01:23 2021 | 111 | aaa | aaa | aaa | Fri Jan 01 01:01:10 2021 | 01:01:10 | Fri Jan 01 01:01:10 2021 + 秦淮区 | 4 | 1 | |中国|江苏省|南京市|秦淮区 | 中国 | 126 | abf | abf | abf | Fri Jan 01 01:01:25 2021 | 01:01:25 | Fri Jan 01 01:01:25 2021 | 111 | aaa | aaa | aaa | Fri Jan 01 01:01:10 2021 | 01:01:10 | Fri Jan 01 01:01:10 2021 + 雨花台 | 4 | 1 | |中国|江苏省|南京市|雨花台 | 中国 | 122 | abb | abb | abb | Fri Jan 01 01:01:21 2021 | 01:01:21 | Fri Jan 01 01:01:21 2021 | 111 | aaa | aaa | aaa | Fri Jan 01 01:01:10 2021 | 01:01:10 | Fri Jan 01 01:01:10 2021 + 鼓楼区 | 4 | 1 | |中国|江苏省|南京市|鼓楼区 | 中国 | 123 | abc | abc | abc | Fri Jan 01 01:01:22 2021 | 01:01:22 | Fri Jan 01 01:01:22 2021 | 111 | aaa | aaa | aaa | Fri Jan 01 01:01:10 2021 | 01:01:10 | Fri Jan 01 01:01:10 2021 + 宿迁市 | 3 | 1 | |中国|江苏省|宿迁市 | 中国 | 112 | aab | aab | aab | Fri Jan 01 01:01:11 2021 | 01:01:11 | Fri Jan 01 01:01:11 2021 | 11 | aa | aa | aa | Fri Jan 01 01:01:01 2021 | 01:01:01 | Fri Jan 01 01:01:01 2021 + 常州市 | 3 | 1 | |中国|江苏省|常州市 | 中国 | 117 | aag | aag | aag | Fri Jan 01 01:01:16 2021 | 01:01:16 | Fri Jan 01 01:01:16 2021 | 11 | aa | aa | aa | Fri Jan 01 01:01:01 2021 | 01:01:01 | Fri Jan 01 01:01:01 2021 + 徐州市 | 3 | 1 | |中国|江苏省|徐州市 | 中国 | 113 | aac | aac | aac | Fri Jan 01 01:01:12 2021 | 01:01:12 | Fri Jan 01 01:01:12 2021 | 11 | aa | aa | aa | Fri Jan 01 01:01:01 2021 | 01:01:01 | Fri Jan 01 01:01:01 2021 + 无锡市 | 3 | 1 | |中国|江苏省|无锡市 | 中国 | 116 | aaf | aaf | aaf | Fri Jan 01 01:01:15 2021 | 01:01:15 | Fri Jan 01 01:01:15 2021 | 11 | aa | aa | aa | Fri Jan 01 01:01:01 2021 | 01:01:01 | Fri Jan 01 01:01:01 2021 + 泰州市 | 3 | 1 | |中国|江苏省|泰州市 | 中国 | 119 | aai | aai | aai | Fri Jan 01 01:01:18 2021 | 01:01:18 | Fri Jan 01 01:01:18 2021 | 11 | aa | aa | aa | Fri Jan 01 01:01:01 2021 | 01:01:01 | Fri Jan 01 01:01:01 2021 + 盐城市 | 3 | 1 | |中国|江苏省|盐城市 | 中国 | 115 | aae | aae | aae | Fri Jan 01 01:01:14 2021 | 01:01:14 | Fri Jan 01 01:01:14 2021 | 11 | aa | aa | aa | Fri Jan 01 01:01:01 2021 | 01:01:01 | Fri Jan 01 01:01:01 2021 + 苏州市 | 3 | 1 | |中国|江苏省|苏州市 | 中国 | 114 | aad | aad | aad | Fri Jan 01 01:01:13 2021 | 01:01:13 | Fri Jan 01 01:01:13 2021 | 11 | aa | aa | aa | Fri Jan 01 01:01:01 2021 | 01:01:01 | Fri Jan 01 01:01:01 2021 + 连云港 | 3 | 1 | |中国|江苏省|连云港 | 中国 | 118 | aah | aah | aah | Fri Jan 01 01:01:17 2021 | 01:01:17 | Fri Jan 01 01:01:17 2021 | 11 | aa | aa | aa | Fri Jan 01 01:01:01 2021 | 01:01:01 | Fri Jan 01 01:01:01 2021 + 河北省 | 2 | 1 | |中国|河北省 | 中国 | 15 | ae | ae | ae | Fri Jan 01 01:01:05 2021 | 01:01:05 | Fri Jan 01 01:01:05 2021 | 1 | a | a | a | Sun Dec 12 12:12:12 2021 | 12:12:12 | Sun Dec 12 12:12:12 2021 + 河南省 | 2 | 1 | |中国|河南省 | 中国 | 14 | ad | ad | ad | Fri Jan 01 01:01:03 2021 | 01:01:03 | Fri Jan 01 01:01:03 2021 | 1 | a | a | a | Sun Dec 12 12:12:12 2021 | 12:12:12 | Sun Dec 12 12:12:12 2021 + 湖北省 | 2 | 1 | |中国|湖北省 | 中国 | 17 | ag | ag | ag | Fri Jan 01 01:01:07 2021 | 01:01:07 | Fri Jan 01 01:01:07 2021 | 1 | a | a | a | Sun Dec 12 12:12:12 2021 | 12:12:12 | Sun Dec 12 12:12:12 2021 + 湖南省 | 2 | 1 | |中国|湖南省 | 中国 | 16 | af | af | af | Fri Jan 01 01:01:06 2021 | 01:01:06 | Fri Jan 01 01:01:06 2021 | 1 | a | a | a | Sun Dec 12 12:12:12 2021 | 12:12:12 | Sun Dec 12 12:12:12 2021 + 贵州省 | 2 | 1 | |中国|贵州省 | 中国 | 18 | ah | ah | ah | Fri Jan 01 01:01:08 2021 | 01:01:08 | Fri Jan 01 01:01:08 2021 | 1 | a | a | a | Sun Dec 12 12:12:12 2021 | 12:12:12 | Sun Dec 12 12:12:12 2021 +(37 rows) + +-- invalid use connect_by_root, will treate it as regular column report column does not exists error +SELECT NAME,LEVEL,CONNECT_BY_ISLEAF,SYS_CONNECT_BY_PATH(NAME,'|'),CONNECT_BY_ROOT +FROM test_hcb_ptb +START WITH (ID=169 or ID=168) and CHA in ('afi','afg','afh') +CONNECT BY ID=PRIOR PID and CHA=PRIOR PCHA and VCH=PRIOR PVCH and DAT=PRIOR PDAT and TIM=PRIOR PTIM AND TIS=PRIOR PTIS +order by 1; +ERROR: column "connect_by_root" does not exist +LINE 1: ...L,CONNECT_BY_ISLEAF,SYS_CONNECT_BY_PATH(NAME,'|'),CONNECT_BY... + ^ +CONTEXT: referenced column: connect_by_root +SELECT NAME,LEVEL,CONNECT_BY_ISLEAF,SYS_CONNECT_BY_PATH(NAME,'|'),CONNECT_BY_ROOT name +FROM test_hcb_ptb +START WITH (ID=169 or ID=168) and CHA in ('afi','afg','afh') +CONNECT BY ID=PRIOR PID and CHA=PRIOR PCHA and VCH=PRIOR PVCH and DAT=PRIOR PDAT and TIM=PRIOR PTIM AND TIS=PRIOR PTIS +order by 1; + name | level | connect_by_isleaf | sys_connect_by_path | name +----------+-------+-------------------+---------------------+---------- + 第九单元 | 1 | 1 | |第九单元 | 第九单元 + 第八单元 | 1 | 1 | |第八单元 | 第八单元 +(2 rows) + +SELECT NAME,LEVEL,CONNECT_BY_ISLEAF,SYS_CONNECT_BY_PATH(NAME,'|'),CONNECT_BY_ROOT(name) +FROM test_hcb_ptb +START WITH (ID=169 or ID=168) and CHA in ('afi','afg','afh') +CONNECT BY ID=PRIOR PID and CHA=PRIOR PCHA and VCH=PRIOR PVCH and DAT=PRIOR PDAT and TIM=PRIOR PTIM AND TIS=PRIOR PTIS +order by 1; + name | level | connect_by_isleaf | sys_connect_by_path | connect_by_root +----------+-------+-------------------+---------------------+----------------- + 第九单元 | 1 | 1 | |第九单元 | 第九单元 + 第八单元 | 1 | 1 | |第八单元 | 第八单元 +(2 rows) + +/* Unsupported StartWith Scenarios */ +explain(costs off) +select * from test_hcb_ptbc t1 start with t1.id = 11 connect by prior t1.id = t1.pid; + QUERY PLAN +----------------------------------------------------------------------- + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_1 + -> Recursive Union + -> Row Adapter + -> CStore Scan on test_hcb_ptbc t1 + Filter: (id = 11) + -> Hash Join + Hash Cond: (t1.pid = tmp_reuslt."t1@id") + -> Materialize + -> Row Adapter + -> CStore Scan on test_hcb_ptbc t1 + -> Hash + -> WorkTable Scan on tmp_reuslt +(15 rows) + +select * from test_hcb_ptbc t1 start with t1.id = 11 connect by prior t1.id = t1.pid; + id | cha | vch | tex | dat | tim | tis | name | pid | pcha | pvch | ptex | pdat | ptim | ptis +-----+------------+------+-----+--------------------------+----------+--------------------------+----------+-----+------------+------+------+--------------------------+----------+-------------------------- + 11 | aa | aa | aa | Fri Jan 01 01:01:01 2021 | 01:01:01 | Fri Jan 01 01:01:01 2021 | 江苏省 | 1 | a | a | a | Sun Dec 12 12:12:12 2021 | 12:12:12 | Sun Dec 12 12:12:12 2021 + 111 | aaa | aaa | aaa | Fri Jan 01 01:01:10 2021 | 01:01:10 | Fri Jan 01 01:01:10 2021 | 南京市 | 11 | aa | aa | aa | Fri Jan 01 01:01:01 2021 | 01:01:01 | Fri Jan 01 01:01:01 2021 + 112 | aab | aab | aab | Fri Jan 01 01:01:11 2021 | 01:01:11 | Fri Jan 01 01:01:11 2021 | 宿迁市 | 11 | aa | aa | aa | Fri Jan 01 01:01:01 2021 | 01:01:01 | Fri Jan 01 01:01:01 2021 + 113 | aac | aac | aac | Fri Jan 01 01:01:12 2021 | 01:01:12 | Fri Jan 01 01:01:12 2021 | 徐州市 | 11 | aa | aa | aa | Fri Jan 01 01:01:01 2021 | 01:01:01 | Fri Jan 01 01:01:01 2021 + 114 | aad | aad | aad | Fri Jan 01 01:01:13 2021 | 01:01:13 | Fri Jan 01 01:01:13 2021 | 苏州市 | 11 | aa | aa | aa | Fri Jan 01 01:01:01 2021 | 01:01:01 | Fri Jan 01 01:01:01 2021 + 115 | aae | aae | aae | Fri Jan 01 01:01:14 2021 | 01:01:14 | Fri Jan 01 01:01:14 2021 | 盐城市 | 11 | aa | aa | aa | Fri Jan 01 01:01:01 2021 | 01:01:01 | Fri Jan 01 01:01:01 2021 + 117 | aag | aag | aag | Fri Jan 01 01:01:16 2021 | 01:01:16 | Fri Jan 01 01:01:16 2021 | 常州市 | 11 | aa | aa | aa | Fri Jan 01 01:01:01 2021 | 01:01:01 | Fri Jan 01 01:01:01 2021 + 116 | aaf | aaf | aaf | Fri Jan 01 01:01:15 2021 | 01:01:15 | Fri Jan 01 01:01:15 2021 | 无锡市 | 11 | aa | aa | aa | Fri Jan 01 01:01:01 2021 | 01:01:01 | Fri Jan 01 01:01:01 2021 + 118 | aah | aah | aah | Fri Jan 01 01:01:17 2021 | 01:01:17 | Fri Jan 01 01:01:17 2021 | 连云港 | 11 | aa | aa | aa | Fri Jan 01 01:01:01 2021 | 01:01:01 | Fri Jan 01 01:01:01 2021 + 119 | aai | aai | aai | Fri Jan 01 01:01:18 2021 | 01:01:18 | Fri Jan 01 01:01:18 2021 | 泰州市 | 11 | aa | aa | aa | Fri Jan 01 01:01:01 2021 | 01:01:01 | Fri Jan 01 01:01:01 2021 + 121 | aba | aba | aba | Fri Jan 01 01:01:20 2021 | 01:01:20 | Fri Jan 01 01:01:20 2021 | 江宁区 | 111 | aaa | aaa | aaa | Fri Jan 01 01:01:10 2021 | 01:01:10 | Fri Jan 01 01:01:10 2021 + 122 | abb | abb | abb | Fri Jan 01 01:01:21 2021 | 01:01:21 | Fri Jan 01 01:01:21 2021 | 雨花台 | 111 | aaa | aaa | aaa | Fri Jan 01 01:01:10 2021 | 01:01:10 | Fri Jan 01 01:01:10 2021 + 123 | abc | abc | abc | Fri Jan 01 01:01:22 2021 | 01:01:22 | Fri Jan 01 01:01:22 2021 | 鼓楼区 | 111 | aaa | aaa | aaa | Fri Jan 01 01:01:10 2021 | 01:01:10 | Fri Jan 01 01:01:10 2021 + 124 | abd | abd | abd | Fri Jan 01 01:01:23 2021 | 01:01:23 | Fri Jan 01 01:01:23 2021 | 玄武区 | 111 | aaa | aaa | aaa | Fri Jan 01 01:01:10 2021 | 01:01:10 | Fri Jan 01 01:01:10 2021 + 125 | abe | abe | abe | Fri Jan 01 01:01:24 2021 | 01:01:24 | Fri Jan 01 01:01:24 2021 | 建邺区 | 111 | aaa | aaa | aaa | Fri Jan 01 01:01:10 2021 | 01:01:10 | Fri Jan 01 01:01:10 2021 + 126 | abf | abf | abf | Fri Jan 01 01:01:25 2021 | 01:01:25 | Fri Jan 01 01:01:25 2021 | 秦淮区 | 111 | aaa | aaa | aaa | Fri Jan 01 01:01:10 2021 | 01:01:10 | Fri Jan 01 01:01:10 2021 + 127 | abg | abg | abg | Fri Jan 01 01:01:26 2021 | 01:01:26 | Fri Jan 01 01:01:26 2021 | 浦口区 | 111 | aaa | aaa | aaa | Fri Jan 01 01:01:10 2021 | 01:01:10 | Fri Jan 01 01:01:10 2021 + 128 | abh | abh | abh | Fri Jan 01 01:01:27 2021 | 01:01:27 | Fri Jan 01 01:01:27 2021 | 浦口区 | 111 | aaa | aaa | aaa | Fri Jan 01 01:01:10 2021 | 01:01:10 | Fri Jan 01 01:01:10 2021 + 129 | abi | abi | abi | Fri Jan 01 01:01:28 2021 | 01:01:28 | Fri Jan 01 01:01:28 2021 | 六合区 | 111 | aaa | aaa | aaa | Fri Jan 01 01:01:10 2021 | 01:01:10 | Fri Jan 01 01:01:10 2021 + 131 | aca | aca | aca | Fri Jan 01 01:01:30 2021 | 01:01:30 | Fri Jan 01 01:01:30 2021 | 东山街 | 121 | aba | aba | aba | Fri Jan 01 01:01:20 2021 | 01:01:20 | Fri Jan 01 01:01:20 2021 + 132 | acb | acb | acb | Fri Jan 01 01:01:31 2021 | 01:01:31 | Fri Jan 01 01:01:31 2021 | 秣陵街 | 121 | aba | aba | aba | Fri Jan 01 01:01:20 2021 | 01:01:20 | Fri Jan 01 01:01:20 2021 + 133 | acc | acc | acc | Fri Jan 01 01:01:32 2021 | 01:01:32 | Fri Jan 01 01:01:32 2021 | 汤山街 | 121 | aba | aba | aba | Fri Jan 01 01:01:20 2021 | 01:01:20 | Fri Jan 01 01:01:20 2021 + 135 | ace | ace | ace | Fri Jan 01 01:01:34 2021 | 01:01:34 | Fri Jan 01 01:01:34 2021 | 禄口街 | 121 | aba | aba | aba | Fri Jan 01 01:01:20 2021 | 01:01:20 | Fri Jan 01 01:01:20 2021 + 134 | acd | acd | acd | Fri Jan 01 01:01:33 2021 | 01:01:33 | Fri Jan 01 01:01:33 2021 | 淳化街 | 121 | aba | aba | aba | Fri Jan 01 01:01:20 2021 | 01:01:20 | Fri Jan 01 01:01:20 2021 + 136 | acf | acf | acf | Fri Jan 01 01:01:35 2021 | 01:01:35 | Fri Jan 01 01:01:35 2021 | 江宁街 | 121 | aba | aba | aba | Fri Jan 01 01:01:20 2021 | 01:01:20 | Fri Jan 01 01:01:20 2021 + 137 | acg | acg | acg | Fri Jan 01 01:01:36 2021 | 01:01:36 | Fri Jan 01 01:01:36 2021 | 谷里街 | 121 | aba | aba | aba | Fri Jan 01 01:01:20 2021 | 01:01:20 | Fri Jan 01 01:01:20 2021 + 138 | ach | ach | ach | Fri Jan 01 01:01:37 2021 | 01:01:37 | Fri Jan 01 01:01:37 2021 | 湖熟街 | 121 | aba | aba | aba | Fri Jan 01 01:01:20 2021 | 01:01:20 | Fri Jan 01 01:01:20 2021 + 139 | aci | aci | aci | Fri Jan 01 01:01:38 2021 | 01:01:38 | Fri Jan 01 01:01:38 2021 | 横溪街 | 121 | aba | aba | aba | Fri Jan 01 01:01:20 2021 | 01:01:20 | Fri Jan 01 01:01:20 2021 + 141 | ada | ada | ada | Fri Jan 01 01:01:40 2021 | 01:01:40 | Fri Jan 01 01:01:40 2021 | 江南摩卡 | 131 | aca | aca | aca | Fri Jan 01 01:01:30 2021 | 01:01:30 | Fri Jan 01 01:01:30 2021 + 142 | adb | adb | adb | Fri Jan 01 01:01:41 2021 | 01:01:41 | Fri Jan 01 01:01:41 2021 | 四季云顶 | 131 | aca | aca | aca | Fri Jan 01 01:01:30 2021 | 01:01:30 | Fri Jan 01 01:01:30 2021 + 143 | adc | adc | adc | Fri Jan 01 01:01:42 2021 | 01:01:42 | Fri Jan 01 01:01:42 2021 | 盛世江南 | 131 | aca | aca | aca | Fri Jan 01 01:01:30 2021 | 01:01:30 | Fri Jan 01 01:01:30 2021 + 144 | add | add | add | Fri Jan 01 01:01:43 2021 | 01:01:43 | Fri Jan 01 01:01:43 2021 | 七里香都 | 131 | aca | aca | aca | Fri Jan 01 01:01:30 2021 | 01:01:30 | Fri Jan 01 01:01:30 2021 + 145 | ade | ade | ade | Fri Jan 01 01:01:44 2021 | 01:01:44 | Fri Jan 01 01:01:44 2021 | 西山枫林 | 131 | aca | aca | aca | Fri Jan 01 01:01:30 2021 | 01:01:30 | Fri Jan 01 01:01:30 2021 + 146 | adf | adf | adf | Fri Jan 01 01:01:45 2021 | 01:01:45 | Fri Jan 01 01:01:45 2021 | 醉墨小镇 | 131 | aca | aca | aca | Fri Jan 01 01:01:30 2021 | 01:01:30 | Fri Jan 01 01:01:30 2021 + 147 | adg | adg | adg | Fri Jan 01 01:01:46 2021 | 01:01:46 | Fri Jan 01 01:01:46 2021 | 布拉格调 | 131 | aca | aca | aca | Fri Jan 01 01:01:30 2021 | 01:01:30 | Fri Jan 01 01:01:30 2021 + 148 | adh | adh | adh | Fri Jan 01 01:01:47 2021 | 01:01:47 | Fri Jan 01 01:01:47 2021 | 清幽别院 | 131 | aca | aca | aca | Fri Jan 01 01:01:30 2021 | 01:01:30 | Fri Jan 01 01:01:30 2021 + 149 | adi | adi | adi | Fri Jan 01 01:01:48 2021 | 01:01:48 | Fri Jan 01 01:01:48 2021 | 璀璨天城 | 131 | aca | aca | aca | Fri Jan 01 01:01:30 2021 | 01:01:30 | Fri Jan 01 01:01:30 2021 + 151 | aea | aea | aea | Fri Jan 01 01:01:50 2021 | 01:01:50 | Fri Jan 01 01:01:50 2021 | 江南一楼 | 141 | ada | ada | ada | Fri Jan 01 01:01:40 2021 | 01:01:40 | Fri Jan 01 01:01:40 2021 + 152 | aeb | aeb | aeb | Fri Jan 01 01:01:51 2021 | 01:01:51 | Fri Jan 01 01:01:51 2021 | 江南二楼 | 141 | ada | ada | ada | Fri Jan 01 01:01:40 2021 | 01:01:40 | Fri Jan 01 01:01:40 2021 + 153 | aec | aec | aec | Fri Jan 01 01:01:52 2021 | 01:01:52 | Fri Jan 01 01:01:52 2021 | 江南三楼 | 141 | ada | ada | ada | Fri Jan 01 01:01:40 2021 | 01:01:40 | Fri Jan 01 01:01:40 2021 + 154 | aed | aed | aed | Fri Jan 01 01:01:53 2021 | 01:01:53 | Fri Jan 01 01:01:53 2021 | 江南四楼 | 141 | ada | ada | ada | Fri Jan 01 01:01:40 2021 | 01:01:40 | Fri Jan 01 01:01:40 2021 + 155 | aee | aee | aee | Fri Jan 01 01:01:54 2021 | 01:01:54 | Fri Jan 01 01:01:54 2021 | 江南五楼 | 141 | ada | ada | ada | Fri Jan 01 01:01:40 2021 | 01:01:40 | Fri Jan 01 01:01:40 2021 + 156 | aef | aef | aef | Fri Jan 01 01:01:55 2021 | 01:01:55 | Fri Jan 01 01:01:55 2021 | 江南六楼 | 141 | ada | ada | ada | Fri Jan 01 01:01:40 2021 | 01:01:40 | Fri Jan 01 01:01:40 2021 + 157 | aeg | aeg | aeg | Fri Jan 01 01:01:56 2021 | 01:01:56 | Fri Jan 01 01:01:56 2021 | 江南七楼 | 141 | ada | ada | ada | Fri Jan 01 01:01:40 2021 | 01:01:40 | Fri Jan 01 01:01:40 2021 + 158 | aeh | aeh | aeh | Fri Jan 01 01:01:57 2021 | 01:01:57 | Fri Jan 01 01:01:57 2021 | 江南八楼 | 141 | ada | ada | ada | Fri Jan 01 01:01:40 2021 | 01:01:40 | Fri Jan 01 01:01:40 2021 + 159 | aei | aei | aei | Fri Jan 01 01:01:58 2021 | 01:01:58 | Fri Jan 01 01:01:58 2021 | 江南九楼 | 141 | ada | ada | ada | Fri Jan 01 01:01:40 2021 | 01:01:40 | Fri Jan 01 01:01:40 2021 + 161 | afa | afa | afa | Fri Jan 01 01:02:50 2021 | 01:02:50 | Fri Jan 01 01:02:50 2021 | 第一单元 | 151 | aea | aea | aea | Fri Jan 01 01:01:50 2021 | 01:01:50 | Fri Jan 01 01:01:50 2021 + 162 | afb | afb | afb | Fri Jan 01 01:02:51 2021 | 01:02:51 | Fri Jan 01 01:02:51 2021 | 第二单元 | 151 | aea | aea | aea | Fri Jan 01 01:01:50 2021 | 01:01:50 | Fri Jan 01 01:01:50 2021 + 163 | afc | afc | afc | Fri Jan 01 01:02:52 2021 | 01:02:52 | Fri Jan 01 01:02:52 2021 | 第三单元 | 151 | aea | aea | aea | Fri Jan 01 01:01:50 2021 | 01:01:50 | Fri Jan 01 01:01:50 2021 + 164 | afd | afd | afd | Fri Jan 01 01:02:53 2021 | 01:02:53 | Fri Jan 01 01:02:53 2021 | 第四单元 | 151 | aea | aea | aea | Fri Jan 01 01:01:50 2021 | 01:01:50 | Fri Jan 01 01:01:50 2021 + 165 | afe | afe | afe | Fri Jan 01 01:02:54 2021 | 01:02:54 | Fri Jan 01 01:02:54 2021 | 第五单元 | 151 | aea | aea | aea | Fri Jan 01 01:01:50 2021 | 01:01:50 | Fri Jan 01 01:01:50 2021 + 166 | aff | aff | aff | Fri Jan 01 01:02:55 2021 | 01:02:55 | Fri Jan 01 01:02:55 2021 | 第六单元 | 151 | aea | aea | aea | Fri Jan 01 01:01:50 2021 | 01:01:50 | Fri Jan 01 01:01:50 2021 + 167 | afg | afg | afg | Fri Jan 01 01:02:56 2021 | 01:02:56 | Fri Jan 01 01:02:56 2021 | 第七单元 | 151 | aea | aea | aea | Fri Jan 01 01:01:50 2021 | 01:01:50 | Fri Jan 01 01:01:50 2021 + 168 | afh | afh | afh | Fri Jan 01 01:02:57 2021 | 01:02:57 | Fri Jan 01 01:02:57 2021 | 第八单元 | 151 | aea | aea | aea | Fri Jan 01 01:01:50 2021 | 01:01:50 | Fri Jan 01 01:01:50 2021 + 169 | afi | afi | afi | Fri Jan 01 01:02:58 2021 | 01:02:58 | Fri Jan 01 01:02:58 2021 | 第九单元 | 151 | aea | aea | aea | Fri Jan 01 01:01:50 2021 | 01:01:50 | Fri Jan 01 01:01:50 2021 +(55 rows) + +SELECT t1.id,t1.pid,t1.name,level FROM test_hcb_ptb t1,test_hcb_ptb t2 WHERE t1.id=t2.id START WITH t1.id=141 CONNECT BY PRIOR t1.id=t1.pid FOR UPDATE OF t2 NOWAIT; +ERROR: Syntax error found. +LINE 1: ...TART WITH t1.id=141 CONNECT BY PRIOR t1.id=t1.pid FOR UPDATE... + ^ +DETAIL: FOR UPDATE/SHARE cannot be used with START WITH CONNECT BY clauses +SELECT t1.id, t1.pid,t1.name,level FROM core_066 t1 START WITH id = 117 CONNECT BY PRIOR id=pid FOR UPDATE; +ERROR: Syntax error found. +LINE 1: ...66 t1 START WITH id = 117 CONNECT BY PRIOR id=pid FOR UPDATE... + ^ +DETAIL: FOR UPDATE/SHARE cannot be used with START WITH CONNECT BY clauses +/* connect by root scenarios */ +select pid x,id,CONNECT_BY_ROOT ID from test_hcb_ptbc t1 start with id = 11 connect by prior id = pid; + x | id | connect_by_rootid +-----+-----+------------------- + 1 | 11 | 11 + 11 | 111 | 11 + 11 | 112 | 11 + 11 | 113 | 11 + 11 | 114 | 11 + 11 | 115 | 11 + 11 | 117 | 11 + 11 | 116 | 11 + 11 | 118 | 11 + 11 | 119 | 11 + 111 | 121 | 11 + 111 | 122 | 11 + 111 | 123 | 11 + 111 | 124 | 11 + 111 | 125 | 11 + 111 | 126 | 11 + 111 | 127 | 11 + 111 | 128 | 11 + 111 | 129 | 11 + 121 | 131 | 11 + 121 | 132 | 11 + 121 | 133 | 11 + 121 | 135 | 11 + 121 | 134 | 11 + 121 | 136 | 11 + 121 | 137 | 11 + 121 | 138 | 11 + 121 | 139 | 11 + 131 | 141 | 11 + 131 | 142 | 11 + 131 | 143 | 11 + 131 | 144 | 11 + 131 | 145 | 11 + 131 | 146 | 11 + 131 | 147 | 11 + 131 | 148 | 11 + 131 | 149 | 11 + 141 | 151 | 11 + 141 | 152 | 11 + 141 | 153 | 11 + 141 | 154 | 11 + 141 | 155 | 11 + 141 | 156 | 11 + 141 | 157 | 11 + 141 | 158 | 11 + 141 | 159 | 11 + 151 | 161 | 11 + 151 | 162 | 11 + 151 | 163 | 11 + 151 | 164 | 11 + 151 | 165 | 11 + 151 | 166 | 11 + 151 | 167 | 11 + 151 | 168 | 11 + 151 | 169 | 11 +(55 rows) + +select pid x,id,CONNECT_BY_ROOT ID alias_id from test_hcb_ptbc t1 start with id = 11 connect by prior id = pid; + x | id | alias_id +-----+-----+---------- + 1 | 11 | 11 + 11 | 111 | 11 + 11 | 112 | 11 + 11 | 113 | 11 + 11 | 114 | 11 + 11 | 115 | 11 + 11 | 117 | 11 + 11 | 116 | 11 + 11 | 118 | 11 + 11 | 119 | 11 + 111 | 121 | 11 + 111 | 122 | 11 + 111 | 123 | 11 + 111 | 124 | 11 + 111 | 125 | 11 + 111 | 126 | 11 + 111 | 127 | 11 + 111 | 128 | 11 + 111 | 129 | 11 + 121 | 131 | 11 + 121 | 132 | 11 + 121 | 133 | 11 + 121 | 135 | 11 + 121 | 134 | 11 + 121 | 136 | 11 + 121 | 137 | 11 + 121 | 138 | 11 + 121 | 139 | 11 + 131 | 141 | 11 + 131 | 142 | 11 + 131 | 143 | 11 + 131 | 144 | 11 + 131 | 145 | 11 + 131 | 146 | 11 + 131 | 147 | 11 + 131 | 148 | 11 + 131 | 149 | 11 + 141 | 151 | 11 + 141 | 152 | 11 + 141 | 153 | 11 + 141 | 154 | 11 + 141 | 155 | 11 + 141 | 156 | 11 + 141 | 157 | 11 + 141 | 158 | 11 + 141 | 159 | 11 + 151 | 161 | 11 + 151 | 162 | 11 + 151 | 163 | 11 + 151 | 164 | 11 + 151 | 165 | 11 + 151 | 166 | 11 + 151 | 167 | 11 + 151 | 168 | 11 + 151 | 169 | 11 +(55 rows) + +select pid x,id,CONNECT_BY_ROOT t1.ID from test_hcb_ptbc t1 start with id = 11 connect by prior id = pid; + x | id | connect_by_roott1.id +-----+-----+---------------------- + 1 | 11 | 11 + 11 | 111 | 11 + 11 | 112 | 11 + 11 | 113 | 11 + 11 | 114 | 11 + 11 | 115 | 11 + 11 | 117 | 11 + 11 | 116 | 11 + 11 | 118 | 11 + 11 | 119 | 11 + 111 | 121 | 11 + 111 | 122 | 11 + 111 | 123 | 11 + 111 | 124 | 11 + 111 | 125 | 11 + 111 | 126 | 11 + 111 | 127 | 11 + 111 | 128 | 11 + 111 | 129 | 11 + 121 | 131 | 11 + 121 | 132 | 11 + 121 | 133 | 11 + 121 | 135 | 11 + 121 | 134 | 11 + 121 | 136 | 11 + 121 | 137 | 11 + 121 | 138 | 11 + 121 | 139 | 11 + 131 | 141 | 11 + 131 | 142 | 11 + 131 | 143 | 11 + 131 | 144 | 11 + 131 | 145 | 11 + 131 | 146 | 11 + 131 | 147 | 11 + 131 | 148 | 11 + 131 | 149 | 11 + 141 | 151 | 11 + 141 | 152 | 11 + 141 | 153 | 11 + 141 | 154 | 11 + 141 | 155 | 11 + 141 | 156 | 11 + 141 | 157 | 11 + 141 | 158 | 11 + 141 | 159 | 11 + 151 | 161 | 11 + 151 | 162 | 11 + 151 | 163 | 11 + 151 | 164 | 11 + 151 | 165 | 11 + 151 | 166 | 11 + 151 | 167 | 11 + 151 | 168 | 11 + 151 | 169 | 11 +(55 rows) + +select pid x,id,CONNECT_BY_ROOT t1.ID alias_id from test_hcb_ptbc t1 start with id = 11 connect by prior id = pid; + x | id | alias_id +-----+-----+---------- + 1 | 11 | 11 + 11 | 111 | 11 + 11 | 112 | 11 + 11 | 113 | 11 + 11 | 114 | 11 + 11 | 115 | 11 + 11 | 117 | 11 + 11 | 116 | 11 + 11 | 118 | 11 + 11 | 119 | 11 + 111 | 121 | 11 + 111 | 122 | 11 + 111 | 123 | 11 + 111 | 124 | 11 + 111 | 125 | 11 + 111 | 126 | 11 + 111 | 127 | 11 + 111 | 128 | 11 + 111 | 129 | 11 + 121 | 131 | 11 + 121 | 132 | 11 + 121 | 133 | 11 + 121 | 135 | 11 + 121 | 134 | 11 + 121 | 136 | 11 + 121 | 137 | 11 + 121 | 138 | 11 + 121 | 139 | 11 + 131 | 141 | 11 + 131 | 142 | 11 + 131 | 143 | 11 + 131 | 144 | 11 + 131 | 145 | 11 + 131 | 146 | 11 + 131 | 147 | 11 + 131 | 148 | 11 + 131 | 149 | 11 + 141 | 151 | 11 + 141 | 152 | 11 + 141 | 153 | 11 + 141 | 154 | 11 + 141 | 155 | 11 + 141 | 156 | 11 + 141 | 157 | 11 + 141 | 158 | 11 + 141 | 159 | 11 + 151 | 161 | 11 + 151 | 162 | 11 + 151 | 163 | 11 + 151 | 164 | 11 + 151 | 165 | 11 + 151 | 166 | 11 + 151 | 167 | 11 + 151 | 168 | 11 + 151 | 169 | 11 +(55 rows) + +/* infinite loop issues */ +SELECT LEVEL,NAME,CONNECT_BY_ISLEAF,SYS_CONNECT_BY_PATH(NAME, '/'),CONNECT_BY_ROOT(ID) +FROM test_swcb_a +START WITH ID='00118' +CONNECT BY PRIOR ID=PID +ORDER SIBLINGS BY NAME; +ERROR: START WITH .. CONNECT BY statement runs into cycle exception +/* fromlist startwith for single table */ +select t1.ID,t1.VCH,pid,NAME,PTEX from TEST_HCB_FQB t1,TEST_SUBLINK t2 where t1.id=t2.id start with t1.id=1 CONNECT BY PRIOR t1.id = t1.pid; + id | vch | pid | name | ptex +----+-----+-----+------+------ +(0 rows) + +explain (costs off) select t1.ID,t1.VCH,pid,NAME,PTEX from TEST_HCB_FQB t1,TEST_SUBLINK t2 where t1.id=t2.id start with t1.id=1 CONNECT BY PRIOR t1.id = t1.pid; + QUERY PLAN +---------------------------------------------------------------------------- + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_1 + -> Recursive Union + -> Nested Loop + -> Seq Scan on test_hcb_fqb t1 + Filter: (id = 1) + -> Seq Scan on test_sublink t2 + Filter: (id = 1) + -> Hash Join + Hash Cond: (t2.id = t1.id) + -> Seq Scan on test_sublink t2 + -> Hash + -> Hash Join + Hash Cond: (tmp_reuslt."t1@id" = t1.pid) + -> WorkTable Scan on tmp_reuslt + -> Hash + -> Seq Scan on test_hcb_fqb t1 +(19 rows) + +/* swcb中参数为proceder参数 */ +CREATE OR REPLACE FUNCTION test_hcb_pro1(i_id in int) return int +AS +o_out int; +BEGIN +select count(*) into o_out from TEST_HCB_FQB t1 START WITH t1.id = i_id +CONNECT BY PRIOR t1.id = t1.pid; +return o_out; +END; +/ +select test_hcb_pro1(11); + test_hcb_pro1 +--------------- + 28 +(1 row) + +drop PROCEDURE test_hcb_pro1; +/* startwith dealing with subqueries */ +select tt.id,tt.name from (select t1.ID,t1.VCH,pid,NAME,PTEX from TEST_HCB_FQB t1,TEST_SUBLINK t2 where t1.id=t2.id) tt +start with tt.id=1 CONNECT BY PRIOR tt.id = tt.pid ; + id | name +----+------ +(0 rows) + +explain (costs off) select tt.id,tt.name from (select t1.ID,t1.VCH,pid,NAME,PTEX from TEST_HCB_FQB t1,TEST_SUBLINK t2 where t1.id=t2.id) tt +start with tt.id=1 CONNECT BY PRIOR tt.id = tt.pid ; + QUERY PLAN +---------------------------------------------------------------------------- + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_1 + -> Recursive Union + -> Nested Loop + -> Seq Scan on test_hcb_fqb t1 + Filter: (id = 1) + -> Seq Scan on test_sublink t2 + Filter: (id = 1) + -> Hash Join + Hash Cond: (t2.id = t1.id) + -> Seq Scan on test_sublink t2 + -> Hash + -> Hash Join + Hash Cond: (tmp_reuslt."tt@id" = t1.pid) + -> WorkTable Scan on tmp_reuslt + -> Hash + -> Seq Scan on test_hcb_fqb t1 +(19 rows) + +select test.id,test.pid,test.name +from +(select t1.id id, t1.pid pid, t1.name name from TEST_HCB_FQB t1 + union + select t2.id id, t2.pid pid, t2.name name from TEST_HCB_FQB t2) test +start with test.id = 12 +connect by prior test.id = test.pid; + id | pid | name +----+-----+-------- + 12 | 1 | 山东省 +(1 row) + +/* startwith dealing with subqueries without alias */ +SELECT NAME,LEVEL,CONNECT_BY_ISLEAF,CONNECT_BY_ROOT(NAME),SYS_CONNECT_BY_PATH(NAME, '/') +FROM (SELECT * FROM test_hcb_ptb) +START WITH CHA IN ('afi','afg','afh') +CONNECT BY PRIOR ID=PID +ORDER SIBLINGS BY NAME; + name | level | connect_by_isleaf | connect_by_root | sys_connect_by_path +----------+-------+-------------------+-----------------+--------------------- + 第七单元 | 1 | 1 | 第七单元 | /第七单元 + 第九单元 | 1 | 1 | 第九单元 | /第九单元 + 第八单元 | 1 | 1 | 第八单元 | /第八单元 +(3 rows) + +SELECT NAME,LEVEL,CONNECT_BY_ISLEAF,CONNECT_BY_ROOT(NAME),SYS_CONNECT_BY_PATH(NAME, '/') +FROM (SELECT * FROM test_hcb_ptb) +START WITH CHA IN ('afi','afg','afh') +CONNECT BY PRIOR ID=PID +ORDER SIBLINGS BY 1; + name | level | connect_by_isleaf | connect_by_root | sys_connect_by_path +----------+-------+-------------------+-----------------+--------------------- + 第七单元 | 1 | 1 | 第七单元 | /第七单元 + 第九单元 | 1 | 1 | 第九单元 | /第九单元 + 第八单元 | 1 | 1 | 第八单元 | /第八单元 +(3 rows) + +SELECT NAME,LEVEL,CONNECT_BY_ISLEAF,CONNECT_BY_ROOT(NAME),SYS_CONNECT_BY_PATH(NAME, '/') +FROM (SELECT * FROM test_hcb_ptb) +START WITH CHA IN ('afi','afg','afh') +CONNECT BY PRIOR ID=PID +ORDER SIBLINGS BY 999; +ERROR: Order siblings by tlistIdx 999 exceed length of targetList. +SELECT NAME,LEVEL,CONNECT_BY_ISLEAF,CONNECT_BY_ROOT(NAME),SYS_CONNECT_BY_PATH(NAME, '/') +FROM (SELECT * FROM test_hcb_ptb) +START WITH CHA IN ('afi','afg','afh') +CONNECT BY PRIOR ID=PID +ORDER SIBLINGS BY 1, LEVEL; +ERROR: Siblings sort entry not found +DETAIL: Column level not found or not allowed here +SELECT NAME,LEVEL,CONNECT_BY_ISLEAF,CONNECT_BY_ROOT(NAME),SYS_CONNECT_BY_PATH(NAME, '/') +FROM (SELECT * FROM test_hcb_ptb) +START WITH CHA IN ('afi','afg','afh') +CONNECT BY PRIOR ID=PID +ORDER SIBLINGS BY 1, HUAWEI; +ERROR: Siblings sort entry not found +DETAIL: Column huawei not found or not allowed here +/* check siblings ordering */ +SELECT NAME,LEVEL,CONNECT_BY_ISLEAF,SYS_CONNECT_BY_PATH(NAME,'|'),CONNECT_BY_ROOT(NAME) +FROM test_hcb_ptb +START WITH (ID=168 or ID=169) +CONNECT BY ID = PRIOR PID +ORDER SIBLINGS BY NAME ASC; + name | level | connect_by_isleaf | sys_connect_by_path | connect_by_root +----------+-------+-------------------+--------------------------------------------------------------+----------------- + 第九单元 | 1 | 0 | |第九单元 | 第九单元 + 江南一楼 | 2 | 0 | |第九单元|江南一楼 | 第九单元 + 江南摩卡 | 3 | 0 | |第九单元|江南一楼|江南摩卡 | 第九单元 + 东山街 | 4 | 0 | |第九单元|江南一楼|江南摩卡|东山街 | 第九单元 + 江宁区 | 5 | 0 | |第九单元|江南一楼|江南摩卡|东山街|江宁区 | 第九单元 + 南京市 | 6 | 0 | |第九单元|江南一楼|江南摩卡|东山街|江宁区|南京市 | 第九单元 + 江苏省 | 7 | 0 | |第九单元|江南一楼|江南摩卡|东山街|江宁区|南京市|江苏省 | 第九单元 + 中国 | 8 | 1 | |第九单元|江南一楼|江南摩卡|东山街|江宁区|南京市|江苏省|中国 | 第九单元 + 第八单元 | 1 | 0 | |第八单元 | 第八单元 + 江南一楼 | 2 | 0 | |第八单元|江南一楼 | 第八单元 + 江南摩卡 | 3 | 0 | |第八单元|江南一楼|江南摩卡 | 第八单元 + 东山街 | 4 | 0 | |第八单元|江南一楼|江南摩卡|东山街 | 第八单元 + 江宁区 | 5 | 0 | |第八单元|江南一楼|江南摩卡|东山街|江宁区 | 第八单元 + 南京市 | 6 | 0 | |第八单元|江南一楼|江南摩卡|东山街|江宁区|南京市 | 第八单元 + 江苏省 | 7 | 0 | |第八单元|江南一楼|江南摩卡|东山街|江宁区|南京市|江苏省 | 第八单元 + 中国 | 8 | 1 | |第八单元|江南一楼|江南摩卡|东山街|江宁区|南京市|江苏省|中国 | 第八单元 +(16 rows) + +-- connect_by_root/sys_connect_by_path() unsupported cases +explain +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root name_desc, sys_connect_by_path(level, '@') +FROM test_area +START WITH name = '中国' +CONNECT BY PRIOR id = fatherid; +ERROR: only base table column can be specified in connect_by_root/sys_connect_by_path() +-- sys_connect_by_path() only supports char type +explain +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root name_desc, sys_connect_by_path(id, '@') +FROM test_area +START WITH name = '中国' +CONNECT BY PRIOR id = fatherid; +ERROR: only text type(CHAR/VARCHAR/NVARCHAR2/TEXT) is allow for sys_connect_by_path() +/* sys_connect_by_path & connect_by_root can support char(xx) */ +SELECT name,LEVEL,connect_by_root(CHA) +FROM test_hcb_fqb +START WITH ID = 1 +CONNECT BY PRIOR CHA = PCHA +ORDER BY ID ASC; + name | level | connect_by_root +--------+-------+----------------- + 中国 | 1 | a + 江苏省 | 2 | a + 山东省 | 2 | a + 安徽省 | 2 | a + 河南省 | 2 | a + 河北省 | 2 | a + 湖南省 | 2 | a + 湖北省 | 2 | a + 贵州省 | 2 | a + 武汉省 | 2 | a + 南京市 | 3 | a + 宿迁市 | 3 | a + 徐州市 | 3 | a + 苏州市 | 3 | a + 盐城市 | 3 | a + 无锡市 | 3 | a + 常州市 | 3 | a + 连云港 | 3 | a + 泰州市 | 3 | a + 江宁区 | 4 | a + 雨花台 | 4 | a + 鼓楼区 | 4 | a + 玄武区 | 4 | a + 建邺区 | 4 | a + 秦淮区 | 4 | a + 浦口区 | 4 | a + 浦口区 | 4 | a + 六合区 | 4 | a + 东山街 | 5 | a + 秣陵街 | 5 | a + 汤山街 | 5 | a + 淳化街 | 5 | a + 禄口街 | 5 | a + 江宁街 | 5 | a + 谷里街 | 5 | a + 湖熟街 | 5 | a + 横溪街 | 5 | a +(37 rows) + +SELECT name,level,connect_by_root t1.cha as cha_col +FROM test_hcb_fqb t1 +START WITH id = 1 +CONNECT BY PRIOR cha = pcha +ORDER BY id ASC; + name | level | cha_col +--------+-------+------------ + 中国 | 1 | a + 江苏省 | 2 | a + 山东省 | 2 | a + 安徽省 | 2 | a + 河南省 | 2 | a + 河北省 | 2 | a + 湖南省 | 2 | a + 湖北省 | 2 | a + 贵州省 | 2 | a + 武汉省 | 2 | a + 南京市 | 3 | a + 宿迁市 | 3 | a + 徐州市 | 3 | a + 苏州市 | 3 | a + 盐城市 | 3 | a + 无锡市 | 3 | a + 常州市 | 3 | a + 连云港 | 3 | a + 泰州市 | 3 | a + 江宁区 | 4 | a + 雨花台 | 4 | a + 鼓楼区 | 4 | a + 玄武区 | 4 | a + 建邺区 | 4 | a + 秦淮区 | 4 | a + 浦口区 | 4 | a + 浦口区 | 4 | a + 六合区 | 4 | a + 东山街 | 5 | a + 秣陵街 | 5 | a + 汤山街 | 5 | a + 淳化街 | 5 | a + 禄口街 | 5 | a + 江宁街 | 5 | a + 谷里街 | 5 | a + 湖熟街 | 5 | a + 横溪街 | 5 | a +(37 rows) + +SELECT name,LEVEL,sys_connect_by_path(CHA, '==》') +FROM test_hcb_fqb +START WITH ID = 1 +CONNECT BY PRIOR CHA = PCHA +ORDER BY ID ASC; + name | level | sys_connect_by_path +--------+-------+------------------------------------------------------------------- + 中国 | 1 | ==》a + 江苏省 | 2 | ==》a ==》aa + 山东省 | 2 | ==》a ==》ab + 安徽省 | 2 | ==》a ==》ac + 河南省 | 2 | ==》a ==》ad + 河北省 | 2 | ==》a ==》ae + 湖南省 | 2 | ==》a ==》af + 湖北省 | 2 | ==》a ==》ag + 贵州省 | 2 | ==》a ==》ah + 武汉省 | 2 | ==》a ==》ai + 南京市 | 3 | ==》a ==》aa ==》aaa + 宿迁市 | 3 | ==》a ==》aa ==》aab + 徐州市 | 3 | ==》a ==》aa ==》aac + 苏州市 | 3 | ==》a ==》aa ==》aad + 盐城市 | 3 | ==》a ==》aa ==》aae + 无锡市 | 3 | ==》a ==》aa ==》aaf + 常州市 | 3 | ==》a ==》aa ==》aag + 连云港 | 3 | ==》a ==》aa ==》aah + 泰州市 | 3 | ==》a ==》aa ==》aai + 江宁区 | 4 | ==》a ==》aa ==》aaa ==》aba + 雨花台 | 4 | ==》a ==》aa ==》aaa ==》abb + 鼓楼区 | 4 | ==》a ==》aa ==》aaa ==》abc + 玄武区 | 4 | ==》a ==》aa ==》aaa ==》abd + 建邺区 | 4 | ==》a ==》aa ==》aaa ==》abe + 秦淮区 | 4 | ==》a ==》aa ==》aaa ==》abf + 浦口区 | 4 | ==》a ==》aa ==》aaa ==》abg + 浦口区 | 4 | ==》a ==》aa ==》aaa ==》abh + 六合区 | 4 | ==》a ==》aa ==》aaa ==》abi + 东山街 | 5 | ==》a ==》aa ==》aaa ==》aba ==》aca + 秣陵街 | 5 | ==》a ==》aa ==》aaa ==》aba ==》acb + 汤山街 | 5 | ==》a ==》aa ==》aaa ==》aba ==》acc + 淳化街 | 5 | ==》a ==》aa ==》aaa ==》aba ==》acd + 禄口街 | 5 | ==》a ==》aa ==》aaa ==》aba ==》ace + 江宁街 | 5 | ==》a ==》aa ==》aaa ==》aba ==》acf + 谷里街 | 5 | ==》a ==》aa ==》aaa ==》aba ==》acg + 湖熟街 | 5 | ==》a ==》aa ==》aaa ==》aba ==》ach + 横溪街 | 5 | ==》a ==》aa ==》aaa ==》aba ==》aci +(37 rows) + +/* empty delimiter in sys_connect_by_path(VCH,'') should be rejected */ +SELECT name,LEVEL,sys_connect_by_path(VCH,'') +FROM test_hcb_ptb +START WITH ID = 1 +CONNECT BY PRIOR CHA = PCHA +ORDER BY ID ASC; +ERROR: illegal parameter in SYS_CONNECT_BY_PATH function +CONTEXT: referenced column: sys_connect_by_path +/* start with null must not cause core-dump error */ +SELECT * +FROM test_hcb_ptb +START WITH NULL +CONNECT BY PRIOR CHA = PCHA +ORDER BY ID ASC; + id | cha | vch | tex | dat | tim | tis | name | pid | pcha | pvch | ptex | pdat | ptim | ptis +----+-----+-----+-----+-----+-----+-----+------+-----+------+------+------+------+------+------ +(0 rows) + +/* start with pbe */ +PREPARE sthpt(int) AS SELECT t1.id,t1.pid,t1.name FROM test_hcb_ptb t1 START WITH id = $1 CONNECT BY PRIOR pid=id; +EXECUTE sthpt(141); + id | pid | name +-----+-----+---------- + 141 | 131 | 江南摩卡 + 131 | 121 | 东山街 + 121 | 111 | 江宁区 + 111 | 11 | 南京市 + 11 | 1 | 江苏省 + 1 | 0 | 中国 +(6 rows) + +/* with-clause used in startwith rewrite */ +explain (costs off) with subquery (id,pid,name) as +( +select t1.id,t1.pid,t1.name, LEVEL from test_hcb_ptb t1 where level>=1 + start with id = 141 connect by prior pid=id +) +select t1.id,t1.pid,t1.name,LEVEL from subquery t1 +start with id = 141 connect by prior pid=id; + QUERY PLAN +------------------------------------------------------------------------------------------------ + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_2 + -> Recursive Union + -> CTE Scan on tmp_reuslt + Filter: ((level >= 1) AND ("t1@id" = 141)) + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_9 + -> Recursive Union + -> Seq Scan on test_hcb_ptb t1 + Filter: (id = 141) + -> Hash Join + Hash Cond: (t1.id = tmp_reuslt."t1@pid") + -> Seq Scan on test_hcb_ptb t1 + -> Hash + -> WorkTable Scan on tmp_reuslt + -> Hash Join + Hash Cond: (tmp_reuslt."t1@id" = tmp_reuslt."t1@pid") + -> Materialize + -> CTE Scan on tmp_reuslt + Filter: (level >= 1) + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_9 + -> Recursive Union + -> Seq Scan on test_hcb_ptb t1 + Filter: (id = 141) + -> Hash Join + Hash Cond: (t1.id = tmp_reuslt."t1@pid") + -> Seq Scan on test_hcb_ptb t1 + -> Hash + -> WorkTable Scan on tmp_reuslt + -> Hash + -> WorkTable Scan on tmp_reuslt +(36 rows) + +explain (costs off) select t1.id,t1.pid,t1.name,LEVEL +from (select t2.id,t2.pid,t2.name,LEVEL from test_hcb_ptb t2 where level>=1 start with t2.id = 141 connect by prior pid=id) t1 +where level>=1 start with id = 141 connect by prior pid=id; + QUERY PLAN +------------------------------------------------------------------------------------------------ + CTE Scan on tmp_reuslt + Filter: (level >= 1) + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_2 + -> Recursive Union + -> CTE Scan on tmp_reuslt + Filter: ((level >= 1) AND ("t2@id" = 141)) + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_9 + -> Recursive Union + -> Seq Scan on test_hcb_ptb t2 + Filter: (id = 141) + -> Hash Join + Hash Cond: (t2.id = tmp_reuslt."t2@pid") + -> Seq Scan on test_hcb_ptb t2 + -> Hash + -> WorkTable Scan on tmp_reuslt + -> Hash Join + Hash Cond: (tmp_reuslt."t2@id" = tmp_reuslt."t1@pid") + -> Materialize + -> CTE Scan on tmp_reuslt + Filter: (level >= 1) + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_9 + -> Recursive Union + -> Seq Scan on test_hcb_ptb t2 + Filter: (id = 141) + -> Hash Join + Hash Cond: (t2.id = tmp_reuslt."t2@pid") + -> Seq Scan on test_hcb_ptb t2 + -> Hash + -> WorkTable Scan on tmp_reuslt + -> Hash + -> WorkTable Scan on tmp_reuslt +(37 rows) + +/* core issue */ +explain select sysdate from test_hcb_ptb t1 start with id = 141 connect by prior pid=id; + QUERY PLAN +------------------------------------------------------------------------------------------------- + CTE Scan on tmp_reuslt (cost=37.11..39.89 rows=101 width=0) + CTE tmp_reuslt + -> StartWith Operator (cost=0.00..37.11 rows=101 width=102) + Start With pseudo atts: RUITR, array_key_9 + -> Recursive Union (cost=0.00..37.11 rows=101 width=102) + -> Seq Scan on test_hcb_ptb t1 (cost=0.00..2.80 rows=1 width=102) + Filter: (id = 141) + -> Hash Join (cost=0.33..3.23 rows=10 width=102) + Hash Cond: (t1.id = tmp_reuslt."t1@pid") + -> Seq Scan on test_hcb_ptb t1 (cost=0.00..2.64 rows=64 width=102) + -> Hash (cost=0.20..0.20 rows=10 width=4) + -> WorkTable Scan on tmp_reuslt (cost=0.00..0.20 rows=10 width=4) +(12 rows) + +select count(sysdate) from test_hcb_ptb t1 start with id = 141 connect by prior pid=id; + count +------- + 6 +(1 row) + +/* core issue sys_connect_by_path(cosnt) core issue */ +select t1.id,t1.pid,LEVEL,sys_connect_by_path(null, '->') pa, t1.name from test_hcb_ptb t1 start with id = 141 connect by prior id = pid; + id | pid | level | pa | name +-----+-----+-------+--------------------+---------- + 141 | 131 | 1 | ->null | 江南摩卡 + 151 | 141 | 2 | ->null->null | 江南一楼 + 152 | 141 | 2 | ->null->null | 江南二楼 + 153 | 141 | 2 | ->null->null | 江南三楼 + 154 | 141 | 2 | ->null->null | 江南四楼 + 155 | 141 | 2 | ->null->null | 江南五楼 + 156 | 141 | 2 | ->null->null | 江南六楼 + 157 | 141 | 2 | ->null->null | 江南七楼 + 158 | 141 | 2 | ->null->null | 江南八楼 + 159 | 141 | 2 | ->null->null | 江南九楼 + 161 | 151 | 3 | ->null->null->null | 第一单元 + 162 | 151 | 3 | ->null->null->null | 第二单元 + 163 | 151 | 3 | ->null->null->null | 第三单元 + 164 | 151 | 3 | ->null->null->null | 第四单元 + 165 | 151 | 3 | ->null->null->null | 第五单元 + 166 | 151 | 3 | ->null->null->null | 第六单元 + 167 | 151 | 3 | ->null->null->null | 第七单元 + 168 | 151 | 3 | ->null->null->null | 第八单元 + 169 | 151 | 3 | ->null->null->null | 第九单元 +(19 rows) + +select t1.id,t1.pid,LEVEL,sys_connect_by_path('id', '->') pa, t1.name from test_hcb_ptb t1 start with id = 141 connect by prior id = pid; + id | pid | level | pa | name +-----+-----+-------+--------------+---------- + 141 | 131 | 1 | ->id | 江南摩卡 + 151 | 141 | 2 | ->id->id | 江南一楼 + 152 | 141 | 2 | ->id->id | 江南二楼 + 153 | 141 | 2 | ->id->id | 江南三楼 + 154 | 141 | 2 | ->id->id | 江南四楼 + 155 | 141 | 2 | ->id->id | 江南五楼 + 156 | 141 | 2 | ->id->id | 江南六楼 + 157 | 141 | 2 | ->id->id | 江南七楼 + 158 | 141 | 2 | ->id->id | 江南八楼 + 159 | 141 | 2 | ->id->id | 江南九楼 + 161 | 151 | 3 | ->id->id->id | 第一单元 + 162 | 151 | 3 | ->id->id->id | 第二单元 + 163 | 151 | 3 | ->id->id->id | 第三单元 + 164 | 151 | 3 | ->id->id->id | 第四单元 + 165 | 151 | 3 | ->id->id->id | 第五单元 + 166 | 151 | 3 | ->id->id->id | 第六单元 + 167 | 151 | 3 | ->id->id->id | 第七单元 + 168 | 151 | 3 | ->id->id->id | 第八单元 + 169 | 151 | 3 | ->id->id->id | 第九单元 +(19 rows) + +select t1.id,t1.pid,LEVEL,sys_connect_by_path(' ', '->') pa, t1.name from test_hcb_ptb t1 start with id = 141 connect by prior id = pid; + id | pid | level | pa | name +-----+-----+-------+-----------+---------- + 141 | 131 | 1 | ->  | 江南摩卡 + 151 | 141 | 2 | -> ->  | 江南一楼 + 152 | 141 | 2 | -> ->  | 江南二楼 + 153 | 141 | 2 | -> ->  | 江南三楼 + 154 | 141 | 2 | -> ->  | 江南四楼 + 155 | 141 | 2 | -> ->  | 江南五楼 + 156 | 141 | 2 | -> ->  | 江南六楼 + 157 | 141 | 2 | -> ->  | 江南七楼 + 158 | 141 | 2 | -> ->  | 江南八楼 + 159 | 141 | 2 | -> ->  | 江南九楼 + 161 | 151 | 3 | -> -> ->  | 第一单元 + 162 | 151 | 3 | -> -> ->  | 第二单元 + 163 | 151 | 3 | -> -> ->  | 第三单元 + 164 | 151 | 3 | -> -> ->  | 第四单元 + 165 | 151 | 3 | -> -> ->  | 第五单元 + 166 | 151 | 3 | -> -> ->  | 第六单元 + 167 | 151 | 3 | -> -> ->  | 第七单元 + 168 | 151 | 3 | -> -> ->  | 第八单元 + 169 | 151 | 3 | -> -> ->  | 第九单元 +(19 rows) + +/* core issue, check args */ +explain select t1.id,t1.pid,t1.name,level from test_hcb_ptb t1 start with id=141 connect by prior id=pid Order By NLSSORT ( id, ' NLS_SORT = SCHINESE_PINYIN_M ' ); + QUERY PLAN +------------------------------------------------------------------------------------------------- + Sort (cost=99.22..100.82 rows=641 width=190) + Sort Key: (nlssort((tmp_reuslt."t1@id")::text, ' NLS_SORT = SCHINESE_PINYIN_M '::text)) + CTE tmp_reuslt + -> StartWith Operator (cost=0.00..53.31 rows=641 width=102) + Start With pseudo atts: RUITR, array_key_1 + -> Recursive Union (cost=0.00..53.31 rows=641 width=102) + -> Seq Scan on test_hcb_ptb t1 (cost=0.00..2.80 rows=1 width=102) + Filter: (id = 141) + -> Hash Join (cost=0.33..3.77 rows=64 width=102) + Hash Cond: (t1.pid = tmp_reuslt."t1@id") + -> Seq Scan on test_hcb_ptb t1 (cost=0.00..2.64 rows=64 width=102) + -> Hash (cost=0.20..0.20 rows=10 width=4) + -> WorkTable Scan on tmp_reuslt (cost=0.00..0.20 rows=10 width=4) + -> CTE Scan on tmp_reuslt (cost=0.00..16.02 rows=641 width=190) +(14 rows) + +select t1.id,t1.pid,t1.name,level from test_hcb_ptb t1 start with id=141 connect by prior id=pid Order By NLSSORT ( id, ' NLS_SORT = SCHINESE_PINYIN_M ' ); + id | pid | name | level +-----+-----+----------+------- + 141 | 131 | 江南摩卡 | 1 + 151 | 141 | 江南一楼 | 2 + 152 | 141 | 江南二楼 | 2 + 153 | 141 | 江南三楼 | 2 + 154 | 141 | 江南四楼 | 2 + 155 | 141 | 江南五楼 | 2 + 156 | 141 | 江南六楼 | 2 + 157 | 141 | 江南七楼 | 2 + 158 | 141 | 江南八楼 | 2 + 159 | 141 | 江南九楼 | 2 + 161 | 151 | 第一单元 | 3 + 162 | 151 | 第二单元 | 3 + 163 | 151 | 第三单元 | 3 + 164 | 151 | 第四单元 | 3 + 165 | 151 | 第五单元 | 3 + 166 | 151 | 第六单元 | 3 + 167 | 151 | 第七单元 | 3 + 168 | 151 | 第八单元 | 3 + 169 | 151 | 第九单元 | 3 +(19 rows) + +/* core issue, check args */ +drop table if exists region cascade; +create table region +( + region_cd varchar(50) primary key , + REGION_MGR_ASSOCIATE_ID number(18,9), + c1 serial +); +select region_mgr_associate_id from region; + region_mgr_associate_id +------------------------- +(0 rows) + +drop table if exists item_price_history cascade; +create table item_price_history +( + ITEM_ID number(39,10) primary key , + LOCATION_ID number(2,0) NULL,c1 serial +); +SELECT (MIN(region_cd)) Column_001, length(CAST('B' AS bytea), 'UTF8') Column_002 +FROM region , item_price_history +WHERE REGION_MGR_ASSOCIATE_ID = ITEM_ID +START WITH REGION_MGR_ASSOCIATE_ID NOT LIKE '_W_' +CONNECT BY PRIOR LOCATION_ID = REGION_MGR_ASSOCIATE_ID +GROUP BY 2; + column_001 | column_002 +------------+------------ +(0 rows) + +drop table item_price_history; +drop table region; +/* */ +create table test1(id int,pid int,name text, level int); +create table test2(id int,pid int,name text, connect_by_iscycle int); +create table test3(id int,pid int,name text, connect_by_isleaf int); +create table test4(id int,pid int,name text, c4 int); +insert into test1 select id,pid,name,id%10 from test_hcb_ptb; +insert into test2 select id,pid,name,id%10 from test_hcb_ptb; +insert into test3 select id,pid,name,id%10 from test_hcb_ptb; +insert into test4 select id,pid,name,id%10 from test_hcb_ptb; +/* level/connect_by_iscycle/connect_by_isleaf is for connect by's level value */ +select id,pid,name,test1.level, level from test1 start with id = 141 connect by prior pid=id; + id | pid | name | level | level +-----+-----+----------+-------+------- + 141 | 131 | 江南摩卡 | 1 | 1 + 131 | 121 | 东山街 | 1 | 2 + 121 | 111 | 江宁区 | 1 | 3 + 111 | 11 | 南京市 | 1 | 4 + 11 | 1 | 江苏省 | 1 | 5 + 1 | 0 | 中国 | 1 | 6 +(6 rows) + +select id,pid,name,test2.connect_by_iscycle, connect_by_iscycle from test2 start with id = 141 connect by prior pid=id; + id | pid | name | connect_by_iscycle | connect_by_iscycle +-----+-----+----------+--------------------+-------------------- + 141 | 131 | 江南摩卡 | 1 | 0 + 131 | 121 | 东山街 | 1 | 0 + 121 | 111 | 江宁区 | 1 | 0 + 111 | 11 | 南京市 | 1 | 0 + 11 | 1 | 江苏省 | 1 | 0 + 1 | 0 | 中国 | 1 | 0 +(6 rows) + +select id,pid,name,test3.connect_by_isleaf, connect_by_isleaf from test3 start with id = 141 connect by prior pid=id; + id | pid | name | connect_by_isleaf | connect_by_isleaf +-----+-----+----------+-------------------+------------------- + 141 | 131 | 江南摩卡 | 1 | 0 + 131 | 121 | 东山街 | 1 | 0 + 121 | 111 | 江宁区 | 1 | 0 + 111 | 11 | 南京市 | 1 | 0 + 11 | 1 | 江苏省 | 1 | 0 + 1 | 0 | 中国 | 1 | 1 +(6 rows) + +drop table test1; +drop table test2; +drop table test3; +drop table test4; +/* */ +/* 查询1 */ +SELECT TRAIT_VALUE_CD +FROM trait_value +START WITH TRAIT_VALUE_CD=TRAIT_VALUE_CD +CONNECT BY PRIOR UOM_CD LIKE '_E_'; + trait_value_cd +---------------- + A + B + C + D + E + F +(6 rows) + +create table region +( + region_cd varchar(50) primary key , + REGION_MGR_ASSOCIATE_ID number(18,9),c1 serial +); +create table item_price_history +( + ITEM_ID number(39,10) primary key , + LOCATION_ID number(2,0) NULL,c1 serial +); +INSERT INTO REGION VALUES ('A', 0.123433); +INSERT INTO REGION VALUES ('B', NULL); +INSERT INTO REGION VALUES ('C', 2.232008908); +INSERT INTO REGION VALUES ('D', 3.878789); +INSERT INTO REGION VALUES ('E', 4.89060603); +INSERT INTO REGION VALUES ('F', 5.82703827); +INSERT INTO REGION VALUES ('G', NULL); +INSERT INTO REGION VALUES ('H', 7.3829083); +INSERT INTO ITEM_PRICE_HISTORY VALUES (0.12, 4); +INSERT INTO ITEM_PRICE_HISTORY VALUES (1.3, 1); +INSERT INTO ITEM_PRICE_HISTORY VALUES (2.23, NULL); +INSERT INTO ITEM_PRICE_HISTORY VALUES (3.33, 3); +INSERT INTO ITEM_PRICE_HISTORY VALUES (4.98, 4); +INSERT INTO ITEM_PRICE_HISTORY VALUES (5.01, 5); +INSERT INTO ITEM_PRICE_HISTORY VALUES (6, 6); +INSERT INTO ITEM_PRICE_HISTORY VALUES (0.7, 7); +INSERT INTO ITEM_PRICE_HISTORY VALUES (0.08, 8); +INSERT INTO ITEM_PRICE_HISTORY VALUES (9.12, 9); +/* 查询2 */ +SELECT 1 +FROM region , item_price_history +WHERE REGION_MGR_ASSOCIATE_ID = ITEM_ID +START WITH REGION_MGR_ASSOCIATE_ID NOT LIKE '_W_' +CONNECT BY PRIOR LOCATION_ID = REGION_MGR_ASSOCIATE_ID; + ?column? +---------- +(0 rows) + +drop table region; +drop table item_price_history; +/* */ +create table test1(c1 int, c2 int, c3 int); +insert into test1 values(1,1,1); +insert into test1 values(2,2,2); +-- encountered with 200 iteration limit +select * from test1 t1 start with c1=1 connect by prior c2<>c3; +ERROR: START WITH .. CONNECT BY statement runs into cycle exception +-- will return result when cycle is met +select * from test1 t1 start with c1=1 connect by NOCYCLE prior c2<>c3; + c1 | c2 | c3 +----+----+---- + 1 | 1 | 1 + 2 | 2 | 2 +(2 rows) + +drop table test1; +-- error out a case when NOCYCLE is not specify and use connect_by_iscycle +select t1.id, LEVEL, connect_by_iscycle from test_hcb_ptb t1 start with id = 1 connect by prior id = pid; + id | level | connect_by_iscycle +-----+-------+-------------------- + 1 | 1 | 0 + 11 | 2 | 0 + 12 | 2 | 0 + 13 | 2 | 0 + 14 | 2 | 0 + 15 | 2 | 0 + 16 | 2 | 0 + 17 | 2 | 0 + 18 | 2 | 0 + 19 | 2 | 0 + 111 | 3 | 0 + 112 | 3 | 0 + 113 | 3 | 0 + 114 | 3 | 0 + 115 | 3 | 0 + 117 | 3 | 0 + 116 | 3 | 0 + 118 | 3 | 0 + 119 | 3 | 0 + 121 | 4 | 0 + 122 | 4 | 0 + 123 | 4 | 0 + 124 | 4 | 0 + 125 | 4 | 0 + 126 | 4 | 0 + 127 | 4 | 0 + 128 | 4 | 0 + 129 | 4 | 0 + 131 | 5 | 0 + 132 | 5 | 0 + 133 | 5 | 0 + 135 | 5 | 0 + 134 | 5 | 0 + 136 | 5 | 0 + 137 | 5 | 0 + 138 | 5 | 0 + 139 | 5 | 0 + 141 | 6 | 0 + 142 | 6 | 0 + 143 | 6 | 0 + 144 | 6 | 0 + 145 | 6 | 0 + 146 | 6 | 0 + 147 | 6 | 0 + 148 | 6 | 0 + 149 | 6 | 0 + 151 | 7 | 0 + 152 | 7 | 0 + 153 | 7 | 0 + 154 | 7 | 0 + 155 | 7 | 0 + 156 | 7 | 0 + 157 | 7 | 0 + 158 | 7 | 0 + 159 | 7 | 0 + 161 | 8 | 0 + 162 | 8 | 0 + 163 | 8 | 0 + 164 | 8 | 0 + 165 | 8 | 0 + 166 | 8 | 0 + 167 | 8 | 0 + 168 | 8 | 0 + 169 | 8 | 0 +(64 rows) + +create table mag_area +( + area_code varchar(10), + area_name varchar(120), + area_short_name varchar(120), + local_name varchar(80), + belong_area_code varchar(10), + bank_level varchar(8), + contry_code varchar(5), + part_code varchar(5), + time_zone varchar(9), + bank_code varchar(10), + group_code varchar(5), + mag_area_grade varchar(3), + mag_area_status varchar(1), + mag_area_broad varchar(1) +); +create table mag_image_tpl +( + seq varchar(20), + area_code varchar(10), + archive_type varchar(3), + busitype varchar(8), + image_type varchar(8), + app_type varchar(10), + rule_id varchar(10), + valid_flag varchar(1), + modify_branch varchar(10), + modify_user varchar(9), + modify_time varchar(14) +); +explain +select a.rule_id, b.mag_area_grade, + max(b.mag_area_grade) OVER (PARTITION BY archive_type, busitype,image_type,app_type) max_level +FROM mag_image_tpl a, mag_area b +WHERE a.AREA_CODE IN ( + SELECT area_code + FROM mag_area + START WITH area_code = '1' + CONNECT BY PRIOR belong_area_code = area_code +) +AND a.archive_type = 'A' +AND a.BUSITYPE = 'B' +AND a.area_code = b.area_code; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------------------------- + WindowAgg (cost=156.54..156.56 rows=1 width=176) + -> Sort (cost=156.54..156.54 rows=1 width=176) + Sort Key: a.image_type, a.app_type + -> Nested Loop Semi Join (cost=127.46..156.53 rows=1 width=176) + Join Filter: ((a.area_code)::text = (tmp_reuslt."mag_area@area_code")::text) + -> Nested Loop (cost=0.00..24.78 rows=1 width=252) + Join Filter: ((a.area_code)::text = (b.area_code)::text) + -> Seq Scan on mag_image_tpl a (cost=0.00..12.96 rows=1 width=198) + Filter: (((archive_type)::text = 'A'::text) AND ((busitype)::text = 'B'::text)) + -> Seq Scan on mag_area b (cost=0.00..10.81 rows=81 width=54) + -> CTE Scan on tmp_reuslt (cost=127.46..129.48 rows=101 width=38) + CTE tmp_reuslt + -> StartWith Operator (cost=0.00..127.46 rows=101 width=982) + Start With pseudo atts: RUITR, array_key_5 + -> Recursive Union (cost=0.00..127.46 rows=101 width=982) + -> Seq Scan on mag_area (cost=0.00..11.01 rows=1 width=982) + Filter: ((area_code)::text = '1'::text) + -> Hash Join (cost=0.33..11.44 rows=10 width=982) + Hash Cond: ((swtest.mag_area.area_code)::text = (tmp_reuslt."mag_area@belong_area_code")::text) + -> Seq Scan on mag_area (cost=0.00..10.81 rows=81 width=982) + -> Hash (cost=0.20..0.20 rows=10 width=38) + -> WorkTable Scan on tmp_reuslt (cost=0.00..0.20 rows=10 width=38) +(22 rows) + +select a.rule_id, b.mag_area_grade, + max(b.mag_area_grade) OVER (PARTITION BY archive_type, busitype,image_type,app_type) max_level +FROM mag_image_tpl a, mag_area b +WHERE a.AREA_CODE IN ( + SELECT area_code + FROM mag_area + START WITH area_code = '1' + CONNECT BY PRIOR belong_area_code = area_code +) +AND a.archive_type = 'A' +AND a.BUSITYPE = 'B' +AND a.area_code = b.area_code; + rule_id | mag_area_grade | max_level +---------+----------------+----------- +(0 rows) + +drop table mag_area; +drop table mag_image_tpl; +SELECT id, sys_connect_by_path(name_desc, '@') || id +FROM test_area +START WITH name = '耒阳市' +CONNECT BY id = PRIOR fatherid; + id | ?column? +----+-------------------------------- + 14 | @Leiyang14 + 13 | @Leiyang@Hengyang13 + 2 | @Leiyang@Hengyang@Hunan2 + 1 | @Leiyang@Hengyang@Hunan@China1 +(4 rows) + +explain +SELECT table_name || NVL('test','_B$') AS table_name + FROM (SELECT TRIM(SUBSTR(txt, + INSTR(txt, ',', 1, LEVEL) + 1, + INSTR(txt, ',', 1, LEVEL + 1) - + INSTR(txt, ',', 1, LEVEL) - 1)) AS table_name + FROM (SELECT ',' || REPLACE('test' , ' ', '') || ',' txt FROM sys_dummy) + CONNECT BY LEVEL <= LENGTH(REPLACE('test', ' ', '')) - LENGTH(REPLACE(REPLACE('test', ' ', ''), ',', '')) + 1); + QUERY PLAN +------------------------------------------------------------------------------------------------- + Subquery Scan on __unnamed_subquery__ (cost=5.24..10.79 rows=101 width=32) + -> CTE Scan on tmp_reuslt (cost=5.24..9.53 rows=101 width=36) + CTE tmp_reuslt + -> StartWith Operator (cost=0.00..5.24 rows=101 width=0) + Start With pseudo atts: RUITR + -> Recursive Union (cost=0.00..5.24 rows=101 width=0) + -> Subquery Scan on sys_dummy (cost=0.00..0.02 rows=1 width=0) + -> Result (cost=0.00..0.01 rows=1 width=0) + -> Nested Loop (cost=0.00..0.32 rows=10 width=0) + -> Result (cost=0.00..0.01 rows=1 width=0) + -> WorkTable Scan on tmp_reuslt (cost=0.00..0.20 rows=10 width=0) +(11 rows) + +SELECT table_name || NVL('test','_B$') AS table_name + FROM (SELECT TRIM(SUBSTR(txt, + INSTR(txt, ',', 1, LEVEL) + 1, + INSTR(txt, ',', 1, LEVEL + 1) - + INSTR(txt, ',', 1, LEVEL) - 1)) AS table_name + FROM (SELECT ',' || REPLACE('test' , ' ', '') || ',' txt FROM sys_dummy) + CONNECT BY LEVEL <= LENGTH(REPLACE('test', ' ', '')) - LENGTH(REPLACE(REPLACE('test', ' ', ''), ',', '')) + 1); + table_name +------------ + testtest +(1 row) + +-- fix infinite recursive +explain select * from t1 start with id = 1 connect by prior id != pid; + QUERY PLAN +------------------------------------------------------------------------------------------- + CTE Scan on tmp_reuslt (cost=43.96..60.18 rows=811 width=40) + CTE tmp_reuslt + -> StartWith Operator (cost=0.00..43.96 rows=811 width=10) + Start With pseudo atts: RUITR, array_key_1 + -> Recursive Union (cost=0.00..43.96 rows=811 width=10) + -> Seq Scan on t1 (cost=0.00..1.11 rows=1 width=10) + Filter: (id = 1) + -> Nested Loop (cost=0.00..2.66 rows=81 width=10) + Join Filter: (tmp_reuslt."t1@id" <> swtest.t1.pid) + -> WorkTable Scan on tmp_reuslt (cost=0.00..0.20 rows=10 width=4) + -> Materialize (cost=0.00..1.14 rows=9 width=10) + -> Seq Scan on t1 (cost=0.00..1.09 rows=9 width=10) +(12 rows) + +create table tsc_rtbl(c_int int,c_varchar1 varchar,c_varchar2 varchar); +alter table tsc_rtbl drop column c_varchar2; +alter table tsc_rtbl add column c_varchar2 varchar; +select c_int,c_varchar1,c_varchar2 from tsc_rtbl +start with c_int<10 connect by nocycle prior c_int=c_int; + c_int | c_varchar1 | c_varchar2 +-------+------------+------------ +(0 rows) + +create table t1_area (id int4,name text, fatherid int4, name_desc text); +insert into t1_area values (1, '中国', 0, 'China'); +insert into t1_area values (2, '湖南省',1 , 'Hunan'); +insert into t1_area values (3, '广东省',1 , 'Guangdong'); +insert into t1_area values (4, '海南省',1 , 'Hainan'); +insert into t1_area values (5, '河北省',1 , 'Hebei'); +insert into t1_area values (6, '河南省',1 , 'Henan'); +insert into t1_area values (7, '山东省',1 , 'Shandong'); +insert into t1_area values (8, '湖北省',1 , 'Hubei'); +insert into t1_area values (9, '江苏省',1 , 'Jiangsu'); +insert into t1_area values (10,'深圳市',3 , 'Shenzhen'); +insert into t1_area values (11,'长沙市',2 , 'Changsha'); +insert into t1_area values (22,'祁北县',13, 'Qibei'); +insert into t1_area values (12,'南山区',10, 'Nanshan'); +insert into t1_area values (21,'祁西县',13, 'Qixi'); +insert into t1_area values (13,'衡阳市',2 , 'Hengyang'); +insert into t1_area values (14,'耒阳市',13, 'Leiyang'); +insert into t1_area values (15,'龙岗区',10, 'Longgang'); +insert into t1_area values (16,'福田区',10, 'Futian'); +insert into t1_area values (17,'宝安区',10, 'Baoan'); +insert into t1_area values (19,'祁东县',13, 'Qidong'); +insert into t1_area values (18,'常宁市',13, 'Changning'); +insert into t1_area values (20,'祁南县',13, 'Qinan'); +SELECT *, connect_by_root(name_desc), sys_connect_by_path(name_desc, '->') +FROM t1_area +START WITH name = '耒阳市' +CONNECT BY id = PRIOR fatherid; + id | name | fatherid | name_desc | connect_by_root | sys_connect_by_path +----+--------+----------+-----------+-----------------+----------------------------------- + 14 | 耒阳市 | 13 | Leiyang | Leiyang | ->Leiyang + 13 | 衡阳市 | 2 | Hengyang | Leiyang | ->Leiyang->Hengyang + 2 | 湖南省 | 1 | Hunan | Leiyang | ->Leiyang->Hengyang->Hunan + 1 | 中国 | 0 | China | Leiyang | ->Leiyang->Hengyang->Hunan->China +(4 rows) + +--创建drop column并加回场景 +alter table t1_area drop column name_desc; +alter table t1_area add column name_desc text; +-- 原有备drop列为空 +SELECT *, connect_by_root(name_desc), sys_connect_by_path(name_desc, '->') +FROM t1_area +START WITH name = '耒阳市' +CONNECT BY id = PRIOR fatherid; + id | name | fatherid | name_desc | connect_by_root | sys_connect_by_path +----+--------+----------+-----------+-----------------+-------------------------- + 14 | 耒阳市 | 13 | | | ->null + 13 | 衡阳市 | 2 | | | ->null->null + 2 | 湖南省 | 1 | | | ->null->null->null + 1 | 中国 | 0 | | | ->null->null->null->null +(4 rows) + +-- 新插入相同数据,原有drop列后的空值和当前有效值并存 +insert into t1_area values (1, '中国', 0, 'China'); +insert into t1_area values (2, '湖南省',1 , 'Hunan'); +insert into t1_area values (3, '广东省',1 , 'Guangdong'); +insert into t1_area values (4, '海南省',1 , 'Hainan'); +insert into t1_area values (5, '河北省',1 , 'Hebei'); +insert into t1_area values (6, '河南省',1 , 'Henan'); +insert into t1_area values (7, '山东省',1 , 'Shandong'); +insert into t1_area values (8, '湖北省',1 , 'Hubei'); +insert into t1_area values (9, '江苏省',1 , 'Jiangsu'); +insert into t1_area values (10,'深圳市',3 , 'Shenzhen'); +insert into t1_area values (11,'长沙市',2 , 'Changsha'); +insert into t1_area values (22,'祁北县',13, 'Qibei'); +insert into t1_area values (12,'南山区',10, 'Nanshan'); +insert into t1_area values (21,'祁西县',13, 'Qixi'); +insert into t1_area values (13,'衡阳市',2 , 'Hengyang'); +insert into t1_area values (14,'耒阳市',13, 'Leiyang'); +insert into t1_area values (15,'龙岗区',10, 'Longgang'); +insert into t1_area values (16,'福田区',10, 'Futian'); +insert into t1_area values (17,'宝安区',10, 'Baoan'); +insert into t1_area values (19,'祁东县',13, 'Qidong'); +insert into t1_area values (18,'常宁市',13, 'Changning'); +insert into t1_area values (20,'祁南县',13, 'Qinan'); +SELECT *, connect_by_root(name_desc), sys_connect_by_path(name_desc, '->') +FROM t1_area +START WITH name = '耒阳市' +CONNECT BY id = PRIOR fatherid; + id | name | fatherid | name_desc | connect_by_root | sys_connect_by_path +----+--------+----------+-----------+-----------------+----------------------------------- + 14 | 耒阳市 | 13 | | | ->null + 14 | 耒阳市 | 13 | Leiyang | Leiyang | ->Leiyang + 13 | 衡阳市 | 2 | | | ->Leiyang->null + 13 | 衡阳市 | 2 | | | ->null->null + 13 | 衡阳市 | 2 | Hengyang | Leiyang | ->Leiyang->Hengyang + 13 | 衡阳市 | 2 | Hengyang | null | ->null->Hengyang + 2 | 湖南省 | 1 | | | ->null->Hengyang->null + 2 | 湖南省 | 1 | | | ->Leiyang->Hengyang->null + 2 | 湖南省 | 1 | | | ->null->null->null + 2 | 湖南省 | 1 | | | ->Leiyang->null->null + 2 | 湖南省 | 1 | Hunan | null | ->null->Hengyang->Hunan + 2 | 湖南省 | 1 | Hunan | Leiyang | ->Leiyang->Hengyang->Hunan + 2 | 湖南省 | 1 | Hunan | null | ->null->null->Hunan + 2 | 湖南省 | 1 | Hunan | Leiyang | ->Leiyang->null->Hunan + 1 | 中国 | 0 | | | ->Leiyang->null->Hunan->null + 1 | 中国 | 0 | | | ->null->null->Hunan->null + 1 | 中国 | 0 | | | ->Leiyang->Hengyang->Hunan->null + 1 | 中国 | 0 | | | ->null->Hengyang->Hunan->null + 1 | 中国 | 0 | | | ->Leiyang->null->null->null + 1 | 中国 | 0 | | | ->null->null->null->null + 1 | 中国 | 0 | | | ->Leiyang->Hengyang->null->null + 1 | 中国 | 0 | | | ->null->Hengyang->null->null + 1 | 中国 | 0 | China | Leiyang | ->Leiyang->null->Hunan->China + 1 | 中国 | 0 | China | null | ->null->null->Hunan->China + 1 | 中国 | 0 | China | Leiyang | ->Leiyang->Hengyang->Hunan->China + 1 | 中国 | 0 | China | null | ->null->Hengyang->Hunan->China + 1 | 中国 | 0 | China | Leiyang | ->Leiyang->null->null->China + 1 | 中国 | 0 | China | null | ->null->null->null->China + 1 | 中国 | 0 | China | Leiyang | ->Leiyang->Hengyang->null->China + 1 | 中国 | 0 | China | null | ->null->Hengyang->null->China +(30 rows) + +SELECT * FROM t1_area START WITH id in ('1','2') CONNECT BY PRIOR fatherid = id; + id | name | fatherid | name_desc +----+--------+----------+----------- + 1 | 中国 | 0 | + 2 | 湖南省 | 1 | + 1 | 中国 | 0 | China + 2 | 湖南省 | 1 | Hunan + 1 | 中国 | 0 | + 1 | 中国 | 0 | + 1 | 中国 | 0 | China + 1 | 中国 | 0 | China +(8 rows) + +SELECT * FROM t1_area START WITH (cast(id as varchar) COLLATE "C") in (cast(+ (id) as varchar) COLLATE "C") and id < 4 connect by id = prior fatherid; + id | name | fatherid | name_desc +----+--------+----------+----------- + 1 | 中国 | 0 | + 2 | 湖南省 | 1 | + 3 | 广东省 | 1 | + 1 | 中国 | 0 | China + 2 | 湖南省 | 1 | Hunan + 3 | 广东省 | 1 | Guangdong + 1 | 中国 | 0 | + 1 | 中国 | 0 | + 1 | 中国 | 0 | + 1 | 中国 | 0 | + 1 | 中国 | 0 | China + 1 | 中国 | 0 | China + 1 | 中国 | 0 | China + 1 | 中国 | 0 | China +(14 rows) + +SELECT * FROM t1_area, tsc_rtbl START WITH id = 1 CONNECT BY PRIOR fatherid = id; + id | name | fatherid | name_desc | c_int | c_varchar1 | c_varchar2 +----+------+----------+-----------+-------+------------+------------ +(0 rows) + +SELECT *, connect_by_root(name_desc), sys_connect_by_path(name_desc, '->') +FROM t1_area; +ERROR: Invalid function call. +DETAIL: START WITH CONNECT BY function found in non-hierarchical query. +CONTEXT: referenced column: connect_by_root +/* fix start with in with clause */ +explain (costs off) WITH WITH_001 AS (SELECT 1 FROM offers_20050701 ,trait_value START WITH PARTY_ID=TRAIT_VAL CONNECT BY PRIOR TRAIT_VALUE_CD LIKE '%V%') +SELECT mfg +FROM brand ,trait_value ,WITH_001 +START WITH TRAIT_VALUE_CD=brand_name +CONNECT BY PRIOR brand_cd=UOM_CD; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------------------------------------------- + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_3 + -> Recursive Union + -> Nested Loop + -> CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_4 + -> Recursive Union + -> Hash Join + Hash Cond: ((swtest.offers_20050701.party_id)::text = (swtest.trait_value.trait_val)::text) + -> Seq Scan on offers_20050701 + -> Hash + -> Seq Scan on trait_value + -> Nested Loop + -> Nested Loop + -> WorkTable Scan on tmp_reuslt + Filter: (("trait_value@trait_value_cd")::text ~~ '%V%'::text) + -> Materialize + -> Seq Scan on trait_value + -> Materialize + -> Seq Scan on offers_20050701 + -> Materialize + -> Hash Join + Hash Cond: ((swtest.brand.brand_name)::text = (swtest.trait_value.trait_value_cd)::text) + -> Seq Scan on brand + -> Hash + -> Seq Scan on trait_value + -> Hash Join + Hash Cond: ((tmp_reuslt."brand@brand_cd")::text = (swtest.trait_value.uom_cd)::text) + -> Nested Loop + -> WorkTable Scan on tmp_reuslt + -> Materialize + -> Seq Scan on brand + -> Hash + -> Nested Loop + -> CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_4 + -> Recursive Union + -> Hash Join + Hash Cond: ((swtest.offers_20050701.party_id)::text = (swtest.trait_value.trait_val)::text) + -> Seq Scan on offers_20050701 + -> Hash + -> Seq Scan on trait_value + -> Nested Loop + -> Nested Loop + -> WorkTable Scan on tmp_reuslt + Filter: (("trait_value@trait_value_cd")::text ~~ '%V%'::text) + -> Materialize + -> Seq Scan on trait_value + -> Materialize + -> Seq Scan on offers_20050701 + -> Materialize + -> Seq Scan on trait_value +(58 rows) + +WITH WITH_001 AS (SELECT 1 FROM offers_20050701 ,trait_value START WITH PARTY_ID=TRAIT_VAL CONNECT BY PRIOR TRAIT_VALUE_CD LIKE '%V%') +SELECT mfg +FROM brand ,trait_value ,WITH_001 +START WITH TRAIT_VALUE_CD=brand_name +CONNECT BY PRIOR brand_cd=UOM_CD; + mfg +----- +(0 rows) + +/* fix reference to level in connect by function calls */ +SELECT 1, level FROM t1_area CONNECT BY length(level) IS NULL; + ?column? | level +----------+------- +(0 rows) + +/* prior params of procedure */ +create or replace function test_tmp1(out id int,out pid int,out name varchar,out level int) return SETOF RECORD +IS +declare +CURSOR C1(sedid int) IS select t1.id,t1.pid,t1.name,level from test_hcb_ptb t1 start with id = sedid connect by prior pid=id; +begin +open C1(141); +loop +fetch C1 into id,pid,name,level; +EXIT WHEN C1%NOTFOUND; +return next; +end loop; +close C1; +end; +/ +select * from test_tmp1(); + id | pid | name | level +-----+-----+----------+------- + 141 | 131 | 江南摩卡 | 1 + 131 | 121 | 东山街 | 2 + 121 | 111 | 江宁区 | 3 + 111 | 11 | 南京市 | 4 + 11 | 1 | 江苏省 | 5 + 1 | 0 | 中国 | 6 +(6 rows) + +drop procedure test_tmp1; +drop table t1_area; +drop table tsc_rtbl; +-- 原问题单场景,connect_by_root(1)出现在在表达式中报错 +explain +select t1.id,t1.pid,t1.name,LEVEL le,connect_by_root(1), connect_by_root(id) +from test_hcb_ptb t1 +where connect_by_root(1) > 0 +start with id = 141 +connect by prior pid=id; + QUERY PLAN +------------------------------------------------------------------------------------------------- + Result (cost=37.12..39.89 rows=101 width=190) + One-Time Filter: ((connect_by_root('1'::text))::bigint > 0) + CTE tmp_reuslt + -> StartWith Operator (cost=0.00..37.11 rows=101 width=102) + Start With pseudo atts: RUITR, array_key_9, array_col_1 + -> Recursive Union (cost=0.00..37.11 rows=101 width=102) + -> Seq Scan on test_hcb_ptb t1 (cost=0.00..2.80 rows=1 width=102) + Filter: (id = 141) + -> Hash Join (cost=0.33..3.23 rows=10 width=102) + Hash Cond: (t1.id = tmp_reuslt."t1@pid") + -> Seq Scan on test_hcb_ptb t1 (cost=0.00..2.64 rows=64 width=102) + -> Hash (cost=0.20..0.20 rows=10 width=4) + -> WorkTable Scan on tmp_reuslt (cost=0.00..0.20 rows=10 width=4) + -> CTE Scan on tmp_reuslt (cost=0.01..2.03 rows=101 width=190) +(14 rows) + +select t1.id,t1.pid,t1.name,LEVEL le,connect_by_root(1), connect_by_root(id) +from test_hcb_ptb t1 +where connect_by_root(1) > 0 +start with id = 141 +connect by prior pid=id; + id | pid | name | le | connect_by_root | connect_by_root +-----+-----+----------+----+-----------------+----------------- + 141 | 131 | 江南摩卡 | 1 | 1 | 141 + 131 | 121 | 东山街 | 2 | 1 | 141 + 121 | 111 | 江宁区 | 3 | 1 | 141 + 111 | 11 | 南京市 | 4 | 1 | 141 + 11 | 1 | 江苏省 | 5 | 1 | 141 + 1 | 0 | 中国 | 6 | 1 | 141 +(6 rows) + +-- 扩展场景, connect_by_root(id)报错找不到列 +explain +select t1.id,t1.pid,t1.name,LEVEL le,connect_by_root(1), connect_by_root(id) +from test_hcb_ptb t1 +where connect_by_root(id) > 0 +start with id = 141 +connect by prior pid=id; + QUERY PLAN +------------------------------------------------------------------------------------------------- + CTE Scan on tmp_reuslt (cost=37.11..40.39 rows=34 width=190) + Filter: ((connect_by_root(("t1@id")::text))::bigint > 0) + CTE tmp_reuslt + -> StartWith Operator (cost=0.00..37.11 rows=101 width=102) + Start With pseudo atts: RUITR, array_key_9, array_col_1 + -> Recursive Union (cost=0.00..37.11 rows=101 width=102) + -> Seq Scan on test_hcb_ptb t1 (cost=0.00..2.80 rows=1 width=102) + Filter: (id = 141) + -> Hash Join (cost=0.33..3.23 rows=10 width=102) + Hash Cond: (t1.id = tmp_reuslt."t1@pid") + -> Seq Scan on test_hcb_ptb t1 (cost=0.00..2.64 rows=64 width=102) + -> Hash (cost=0.20..0.20 rows=10 width=4) + -> WorkTable Scan on tmp_reuslt (cost=0.00..0.20 rows=10 width=4) +(13 rows) + +select t1.id,t1.pid,t1.name,LEVEL le,connect_by_root(1), connect_by_root(id) +from test_hcb_ptb t1 +where connect_by_root(id) > 0 +start with id = 141 +connect by prior pid=id; + id | pid | name | le | connect_by_root | connect_by_root +-----+-----+----------+----+-----------------+----------------- + 141 | 131 | 江南摩卡 | 1 | 1 | 141 + 131 | 121 | 东山街 | 2 | 1 | 141 + 121 | 111 | 江宁区 | 3 | 1 | 141 + 111 | 11 | 南京市 | 4 | 1 | 141 + 11 | 1 | 江苏省 | 5 | 1 | 141 + 1 | 0 | 中国 | 6 | 1 | 141 +(6 rows) + +-- 扩展场景,sys_connect_by_path(123, '-') is not null +explain +select t1.id,t1.pid,t1.name,LEVEL le,connect_by_root(1), connect_by_root(id), sys_connect_by_path(123, '-') +from test_hcb_ptb t1 +where sys_connect_by_path(123, '-') is not null +start with id = 141 +connect by prior pid=id; + QUERY PLAN +------------------------------------------------------------------------------------------------- + Result (cost=37.11..40.14 rows=101 width=190) + One-Time Filter: (sys_connect_by_path('123'::text, '-'::text) IS NOT NULL) + CTE tmp_reuslt + -> StartWith Operator (cost=0.00..37.11 rows=101 width=102) + Start With pseudo atts: RUITR, array_key_9, array_col_1 + -> Recursive Union (cost=0.00..37.11 rows=101 width=102) + -> Seq Scan on test_hcb_ptb t1 (cost=0.00..2.80 rows=1 width=102) + Filter: (id = 141) + -> Hash Join (cost=0.33..3.23 rows=10 width=102) + Hash Cond: (t1.id = tmp_reuslt."t1@pid") + -> Seq Scan on test_hcb_ptb t1 (cost=0.00..2.64 rows=64 width=102) + -> Hash (cost=0.20..0.20 rows=10 width=4) + -> WorkTable Scan on tmp_reuslt (cost=0.00..0.20 rows=10 width=4) + -> CTE Scan on tmp_reuslt (cost=0.00..2.02 rows=101 width=190) +(14 rows) + +create table ctI as select t1.id,t1.pid,t1.name,level as le from test_hcb_ptb t1 start with id=141 connect by prior id=pid; +create table ctII as select t1.id,t1.pid,t1.name,level from test_hcb_ptb t1 start with id=141 connect by prior id=pid; +\d ctI; + Table "swtest.cti" + Column | Type | Modifiers +--------+-----------------------+----------- + id | integer | + pid | integer | + name | character varying(80) | + le | integer | + +\d ctII; + Table "swtest.ctii" + Column | Type | Modifiers +--------+-----------------------+----------- + id | integer | + pid | integer | + name | character varying(80) | + level | integer | + +drop table ctI; +drop table ctII; +/* + * NOTE: need do upgrade change to have syc_conenct_by_path()/connect_by_root() to be volatile + */ +/* +select t1.id,t1.pid,t1.name,LEVEL le,connect_by_root(1), connect_by_root(id), sys_connect_by_path(123, '-') +from test_hcb_ptb t1 +where sys_connect_by_path(123, '-') is not null +start with id = 141 +connect by prior pid=id; +*/ +-- 扩展场景,sys_connect_by_path(123, '-') 验证能够被正确匹配 +explain +select t1.id,t1.pid,t1.name,LEVEL le,connect_by_root(1), connect_by_root(id), sys_connect_by_path(123, '-') +from test_hcb_ptb t1 +where sys_connect_by_path(123, '-') like '-123-123-123%' +start with id = 141 +connect by prior pid=id; + QUERY PLAN +------------------------------------------------------------------------------------------------- + Result (cost=37.11..40.14 rows=101 width=190) + One-Time Filter: (sys_connect_by_path('123'::text, '-'::text) ~~ '-123-123-123%'::text) + CTE tmp_reuslt + -> StartWith Operator (cost=0.00..37.11 rows=101 width=102) + Start With pseudo atts: RUITR, array_key_9, array_col_1 + -> Recursive Union (cost=0.00..37.11 rows=101 width=102) + -> Seq Scan on test_hcb_ptb t1 (cost=0.00..2.80 rows=1 width=102) + Filter: (id = 141) + -> Hash Join (cost=0.33..3.23 rows=10 width=102) + Hash Cond: (t1.id = tmp_reuslt."t1@pid") + -> Seq Scan on test_hcb_ptb t1 (cost=0.00..2.64 rows=64 width=102) + -> Hash (cost=0.20..0.20 rows=10 width=4) + -> WorkTable Scan on tmp_reuslt (cost=0.00..0.20 rows=10 width=4) + -> CTE Scan on tmp_reuslt (cost=0.01..2.02 rows=101 width=190) +(14 rows) + +/* + * NOTE: need do upgrade change to have syc_conenct_by_path()/connect_by_root() to be volatile + */ +/* +select t1.id,t1.pid,t1.name,LEVEL le,connect_by_root(1), connect_by_root(id), sys_connect_by_path(123, '-') +from test_hcb_ptb t1 +where sys_connect_by_path(123, '-') like '-123-123-123%' +start with id = 141 +connect by prior pid=id; +*/ +/* testing distinct qualifier */ +select distinct id,pid,name,LEVEL from t1 start with id = 1 connect by prior pid=id order by 1; + id | pid | name | level +----+-----+------+------- + 1 | 0 | 1 | 1 +(1 row) + +/* testing NOT expression */ +select t1.id, t1.pid, t1.name from t1 start with not id=1 connect by prior pid=id; + id | pid | name +----+-----+------ + 2 | 1 | 2 + 3 | 0 | 3 + 4 | 1 | 4 + 5 | 2 | 5 + 6 | 3 | 6 + 7 | 4 | 7 + 8 | 4 | 8 + 9 | 7 | 9 + 1 | 0 | 1 + 1 | 0 | 1 + 2 | 1 | 2 + 3 | 0 | 3 + 4 | 1 | 4 + 4 | 1 | 4 + 7 | 4 | 7 + 1 | 0 | 1 + 1 | 0 | 1 + 1 | 0 | 1 + 4 | 1 | 4 + 1 | 0 | 1 +(20 rows) + +/* testing func expr in connect by clause */ +explain select trim(t1.name) from test_hcb_ptb t1 connect by trim(t1.name) is not null; + QUERY PLAN +-------------------------------------------------------------------------------------------------- + CTE Scan on tmp_reuslt (cost=13471.92..22689.36 rows=409664 width=178) + CTE tmp_reuslt + -> StartWith Operator (cost=0.00..13471.92 rows=409664 width=102) + Start With pseudo atts: RUITR + -> Recursive Union (cost=0.00..13471.92 rows=409664 width=102) + -> Seq Scan on test_hcb_ptb t1 (cost=0.00..2.64 rows=64 width=102) + -> Nested Loop (cost=0.00..527.60 rows=40960 width=102) + -> WorkTable Scan on tmp_reuslt (cost=0.00..12.80 rows=640 width=0) + -> Materialize (cost=0.00..2.96 rows=64 width=102) + -> Seq Scan on test_hcb_ptb t1 (cost=0.00..2.64 rows=64 width=102) +(10 rows) + +/* fix create table as with start with */ +create table ct as select t1.id,t1.pid,t1.name,level from test_hcb_ptb t1 start with id=141 connect by prior id=pid; +drop table ct; +set current_schema = public; +create table t1(c1 int,c2 int,c3 int); +insert into t1 values(1,1,1); +insert into t1 values(2,2,2); +select *, connect_by_iscycle from t1 start with c1=1 connect by nocycle prior c1=c2 order siblings by 1,2; + c1 | c2 | c3 | connect_by_iscycle +----+----+----+-------------------- + 1 | 1 | 1 | 0 + 1 | 1 | 1 | 1 +(2 rows) + +insert into t1 values(1,1,1); +insert into t1 values(2,2,2); +select *, connect_by_iscycle from t1 start with c1=1 connect by nocycle prior c1=c2 order siblings by 1,2; + c1 | c2 | c3 | connect_by_iscycle +----+----+----+-------------------- + 1 | 1 | 1 | 0 + 1 | 1 | 1 | 0 + 1 | 1 | 1 | 1 +(3 rows) + +insert into t1 values(1,NULL,1); +select *, connect_by_iscycle from t1 start with c1=1 connect by nocycle prior c1=c2 order siblings by 1,2 nulls first; + c1 | c2 | c3 | connect_by_iscycle +----+----+----+-------------------- + 1 | | 1 | 0 + 1 | 1 | 1 | 0 + 1 | 1 | 1 | 0 + 1 | 1 | 1 | 1 +(4 rows) + +select *, connect_by_iscycle from t1 start with c1=1 connect by nocycle prior c1=c2 order siblings by 1,2 nulls last; + c1 | c2 | c3 | connect_by_iscycle +----+----+----+-------------------- + 1 | 1 | 1 | 0 + 1 | 1 | 1 | 0 + 1 | | 1 | 0 + 1 | 1 | 1 | 1 +(4 rows) + +delete from t1 where c2 is null; +select *, connect_by_iscycle from t1 start with c1<3 connect by nocycle prior c1 StartWith Operator (cost=0.00..12299132.73 rows=378304445 width=12) + Start With pseudo atts: RUITR + -> Recursive Union (cost=0.00..12299132.73 rows=378304445 width=12) + -> Seq Scan on t1 (cost=0.00..29.45 rows=1945 width=12) + -> Nested Loop (cost=0.00..473301.44 rows=37830250 width=12) + -> WorkTable Scan on tmp_reuslt (cost=0.00..389.00 rows=19450 width=0) + -> Materialize (cost=0.00..39.17 rows=1945 width=12) + -> Seq Scan on t1 (cost=0.00..29.45 rows=1945 width=12) +(10 rows) + +select * from t1 connect by level is not null and level < 3; + c1 | c2 | c3 +----+----+---- + 1 | 1 | 1 + 2 | 2 | 2 + 1 | 1 | 1 + 2 | 2 | 2 + 1 | 1 | 1 + 2 | 2 | 2 + 1 | 1 | 1 + 2 | 2 | 2 + 1 | 1 | 1 + 2 | 2 | 2 + 1 | 1 | 1 + 2 | 2 | 2 + 1 | 1 | 1 + 2 | 2 | 2 + 1 | 1 | 1 + 2 | 2 | 2 + 1 | 1 | 1 + 2 | 2 | 2 + 1 | 1 | 1 + 2 | 2 | 2 +(20 rows) + +select * from t1 connect by level; +ERROR: Unsupported expression found in CONNECT BY clause. +DETAIL: Pseudo column expects an operator +select t1.id a.d jack from t1; +ERROR: Invalid use of identifiers. +LINE 1: select t1.id a.d jack from t1; + ^ +DETAIL: Syntax error found near token "a" +select t1.id bauer jack from t1; +ERROR: Invalid use of identifiers. +LINE 1: select t1.id bauer jack from t1; + ^ +DETAIL: Syntax error found near token "bauer" +drop table t1; +/* limit + startwith 场景下执行阶段targetlist报错 */ +CREATE TABLE log_part ( + ts timestamp(6) without time zone DEFAULT now() NOT NULL, + op character(1), + act_no numeric(38,0), + old_blc numeric(38,0), + num numeric(38,0), + threadid bigint, + index integer, + tran integer +) +WITH (orientation=row, compression=no) +PARTITION BY RANGE (ts) +INTERVAL('1 day') +( + PARTITION p_2020_05_21 VALUES LESS THAN ('2020-05-21') TABLESPACE pg_default +) +ENABLE ROW MOVEMENT; +insert into log_part values('2021-09-24 10:12:19.451125','m',255, 10000000, -374929792, 39, 0, 0); +insert into log_part values('2021-09-24 10:12:19.451125','a',548, 10000000, 374929792, 39, 0, 0); +insert into log_part values('2021-09-24 10:12:19.449826','m', 39, 10000000, -473910067, 97, 0, 0); +insert into log_part values('2021-09-24 10:12:19.451221','m',250, 10000000, -757146539, 63, 0, 0); +insert into log_part values('2021-09-24 10:12:19.449643','m',916, 10000000, -418707874, 100, 0, 0); +insert into log_part values('2021-09-24 10:12:19.451052','m',510, 10000000, -868384331, 45, 0, 0); +insert into log_part values('2021-09-24 10:12:19.451039','m',541, 10000000, -782801693, 101, 0, 0); +insert into log_part values('2021-09-24 10:12:19.450232','m', 4, 10000000, -794225803, 33, 0, 0); +insert into log_part values('2021-09-24 10:12:19.450352','m',123, 10000000, -494836087, 58, 0, 0); +insert into log_part values('2021-09-24 10:12:19.449622','m',876, 10000000, -79442930, 60, 0, 0); +insert into log_part values('2021-09-24 10:12:19.449785','m', 21, 10000000, -560326111, 65, 0, 0); +insert into log_part values('2021-09-24 10:12:19.449828','m',484, 10000000, -571750221, 29, 0, 0); +insert into log_part values('2021-09-24 10:12:19.449657','m',167, 10000000, -146895512, 106, 0, 0); +insert into log_part values('2021-09-24 10:12:19.449826','a', 35, 10000000, 473910067, 97, 0, 0); +insert into log_part values('2021-09-24 10:12:19.451221','a',540, 10000000, 757146539, 63, 0, 0); +insert into log_part values('2021-09-24 10:12:19.449706','m',118, 10000000, -318894193, 50, 0, 0); +insert into log_part values('2021-09-24 10:12:19.501816','m',105, 10000000, -997671676, 39, 0, 0); +insert into log_part values('2021-09-24 10:12:19.449602','m',858, 10000000, -207656402, 28, 0, 0); +insert into log_part values('2021-09-24 10:12:19.450566','m',607, 10000000, -479468765, 30, 0, 0); +insert into log_part values('2021-09-24 10:12:19.451052','a',132, 10000000, 868384331, 45, 0, 0); +insert into log_part values('2021-09-24 10:12:19.451039','a',891, 10000000, 782801693, 101, 0, 0); +explain +select * from (select * from log_part where act_no=250) +start with old_blc=10000000 connect by prior old_blc + prior num = old_blc and act_no=prior act_no limit 10; + QUERY PLAN +-------------------------------------------------------------------------------------------------------------------------------------- + Limit (cost=188.10..188.30 rows=10 width=122) + CTE tmp_reuslt + -> StartWith Operator (cost=0.00..188.10 rows=11 width=122) + Start With pseudo atts: RUITR, array_key_3, array_key_4, array_key_5 + -> Recursive Union (cost=0.00..188.10 rows=11 width=122) + -> Partition Iterator (cost=0.00..18.05 rows=1 width=122) + Iterations: 2 + -> Partitioned Seq Scan on log_part (cost=0.00..18.05 rows=1 width=122) + Filter: ((act_no = 250::numeric) AND (old_blc = 10000000::numeric)) + Selected Partitions: 1..2 + -> Nested Loop (cost=0.00..16.98 rows=1 width=122) + Join Filter: ((tmp_reuslt."sw_subquery_0@old_blc" + tmp_reuslt."sw_subquery_0@num") = public.log_part.old_blc) + -> WorkTable Scan on tmp_reuslt (cost=0.00..0.22 rows=1 width=90) + Filter: ("sw_subquery_0@act_no" = 250::numeric) + -> Partition Iterator (cost=0.00..16.71 rows=3 width=122) + Iterations: 2 + -> Partitioned Seq Scan on log_part (cost=0.00..16.71 rows=3 width=122) + Filter: (act_no = 250::numeric) + Selected Partitions: 1..2 + -> Result (cost=0.00..0.22 rows=11 width=122) + -> CTE Scan on tmp_reuslt (cost=0.00..0.22 rows=11 width=122) +(21 rows) + +select * from (select * from log_part where act_no=250) +start with old_blc=10000000 connect by prior old_blc + prior num = old_blc and act_no=prior act_no limit 10; + ts | op | act_no | old_blc | num | threadid | index | tran +---------------------------------+----+--------+----------+------------+----------+-------+------ + Fri Sep 24 10:12:19.451221 2021 | m | 250 | 10000000 | -757146539 | 63 | 0 | 0 +(1 row) + +explain +select *, connect_by_root old_blc from (select * from log_part where act_no=250) +start with old_blc=10000000 connect by prior old_blc + prior num = old_blc and act_no=prior act_no limit 10; + QUERY PLAN +-------------------------------------------------------------------------------------------------------------------------------------- + Limit (cost=188.10..188.35 rows=10 width=122) + CTE tmp_reuslt + -> StartWith Operator (cost=0.00..188.10 rows=11 width=122) + Start With pseudo atts: RUITR, array_key_3, array_key_4, array_key_5, array_col_4 + -> Recursive Union (cost=0.00..188.10 rows=11 width=122) + -> Partition Iterator (cost=0.00..18.05 rows=1 width=122) + Iterations: 2 + -> Partitioned Seq Scan on log_part (cost=0.00..18.05 rows=1 width=122) + Filter: ((act_no = 250::numeric) AND (old_blc = 10000000::numeric)) + Selected Partitions: 1..2 + -> Nested Loop (cost=0.00..16.98 rows=1 width=122) + Join Filter: ((tmp_reuslt."sw_subquery_0@old_blc" + tmp_reuslt."sw_subquery_0@num") = public.log_part.old_blc) + -> WorkTable Scan on tmp_reuslt (cost=0.00..0.22 rows=1 width=90) + Filter: ("sw_subquery_0@act_no" = 250::numeric) + -> Partition Iterator (cost=0.00..16.71 rows=3 width=122) + Iterations: 2 + -> Partitioned Seq Scan on log_part (cost=0.00..16.71 rows=3 width=122) + Filter: (act_no = 250::numeric) + Selected Partitions: 1..2 + -> Result (cost=0.00..0.28 rows=11 width=122) + -> CTE Scan on tmp_reuslt (cost=0.00..0.28 rows=11 width=122) +(21 rows) + +select *, connect_by_root old_blc from (select * from log_part where act_no=250) +start with old_blc=10000000 connect by prior old_blc + prior num = old_blc and act_no=prior act_no limit 10; + ts | op | act_no | old_blc | num | threadid | index | tran | connect_by_rootold_blc +---------------------------------+----+--------+----------+------------+----------+-------+------+------------------------ + Fri Sep 24 10:12:19.451221 2021 | m | 250 | 10000000 | -757146539 | 63 | 0 | 0 | 10000000 +(1 row) + +select *, connect_by_root old_blc alias_old_blc from (select * from log_part where act_no=250) +start with old_blc=10000000 connect by prior old_blc + prior num = old_blc and act_no=prior act_no limit 10; + ts | op | act_no | old_blc | num | threadid | index | tran | alias_old_blc +---------------------------------+----+--------+----------+------------+----------+-------+------+--------------- + Fri Sep 24 10:12:19.451221 2021 | m | 250 | 10000000 | -757146539 | 63 | 0 | 0 | 10000000 +(1 row) + +SELECT *, CONNECT_BY_ROOT old_blc AS alias_old_blc FROM (SELECT * FROM log_part WHERE act_no=250) +START WITH old_blc=10000000 CONNECT BY PRIOR old_blc + PRIOR num = old_blc AND act_no = PRIOR act_no LIMIT 10; + ts | op | act_no | old_blc | num | threadid | index | tran | alias_old_blc +---------------------------------+----+--------+----------+------------+----------+-------+------+--------------- + Fri Sep 24 10:12:19.451221 2021 | m | 250 | 10000000 | -757146539 | 63 | 0 | 0 | 10000000 +(1 row) + +explain +select op , act_no , old_blc , num , threadid , index , tran ,level from log_part +start with old_blc=10000000 connect by prior old_blc + prior num = old_blc and act_no=prior act_no +order by 1,2,3,4 limit 10; + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Limit (cost=228.76..228.79 rows=10 width=118) + CTE tmp_reuslt + -> StartWith Operator (cost=0.00..228.26 rows=13 width=122) + Start With pseudo atts: RUITR, array_key_3, array_key_4, array_key_5 + -> Recursive Union (cost=0.00..228.26 rows=13 width=122) + -> Partition Iterator (cost=0.00..16.71 rows=3 width=122) + Iterations: 2 + -> Partitioned Seq Scan on log_part (cost=0.00..16.71 rows=3 width=122) + Filter: (old_blc = 10000000::numeric) + Selected Partitions: 1..2 + -> Hash Join (cost=1.05..21.13 rows=1 width=122) + Hash Cond: ((public.log_part.old_blc = (tmp_reuslt."log_part@old_blc" + tmp_reuslt."log_part@num")) AND (public.log_part.act_no = tmp_reuslt."log_part@act_no")) + -> Partition Iterator (cost=0.00..15.37 rows=537 width=122) + Iterations: 2 + -> Partitioned Seq Scan on log_part (cost=0.00..15.37 rows=537 width=122) + Selected Partitions: 1..2 + -> Hash (cost=0.60..0.60 rows=30 width=90) + -> WorkTable Scan on tmp_reuslt (cost=0.00..0.60 rows=30 width=90) + -> Sort (cost=0.50..0.53 rows=13 width=118) + Sort Key: tmp_reuslt."log_part@op", tmp_reuslt."log_part@act_no", tmp_reuslt."log_part@old_blc", tmp_reuslt."log_part@num" + -> CTE Scan on tmp_reuslt (cost=0.00..0.26 rows=13 width=118) +(21 rows) + +select op , act_no , old_blc , num , threadid , index , tran ,level from log_part +start with old_blc=10000000 connect by prior old_blc + prior num = old_blc and act_no=prior act_no +order by 1,2,3,4 limit 10; + op | act_no | old_blc | num | threadid | index | tran | level +----+--------+----------+------------+----------+-------+------+------- + a | 35 | 10000000 | 473910067 | 97 | 0 | 0 | 1 + a | 132 | 10000000 | 868384331 | 45 | 0 | 0 | 1 + a | 540 | 10000000 | 757146539 | 63 | 0 | 0 | 1 + a | 548 | 10000000 | 374929792 | 39 | 0 | 0 | 1 + a | 891 | 10000000 | 782801693 | 101 | 0 | 0 | 1 + m | 4 | 10000000 | -794225803 | 33 | 0 | 0 | 1 + m | 21 | 10000000 | -560326111 | 65 | 0 | 0 | 1 + m | 39 | 10000000 | -473910067 | 97 | 0 | 0 | 1 + m | 105 | 10000000 | -997671676 | 39 | 0 | 0 | 1 + m | 118 | 10000000 | -318894193 | 50 | 0 | 0 | 1 +(10 rows) + +drop table log_part; +set current_schema=swtest; +EXPLAIN SELECT * FROM test_area START WITH name = '中国' CONNECT BY PRIOR id = fatherid limit 10; + QUERY PLAN +------------------------------------------------------------------------------------------------- + Limit (cost=23.91..24.11 rows=10 width=72) + CTE tmp_reuslt + -> StartWith Operator (cost=0.00..23.91 rows=221 width=24) + Start With pseudo atts: RUITR, array_key_1 + -> Recursive Union (cost=0.00..23.91 rows=221 width=24) + -> Seq Scan on test_area (cost=0.00..1.27 rows=1 width=24) + Filter: (name = '中国'::text) + -> Hash Join (cost=0.33..1.82 rows=22 width=24) + Hash Cond: (swtest.test_area.fatherid = tmp_reuslt."test_area@id") + -> Seq Scan on test_area (cost=0.00..1.22 rows=22 width=24) + -> Hash (cost=0.20..0.20 rows=10 width=4) + -> WorkTable Scan on tmp_reuslt (cost=0.00..0.20 rows=10 width=4) + -> Result (cost=0.00..4.42 rows=221 width=72) + -> CTE Scan on tmp_reuslt (cost=0.00..4.42 rows=221 width=72) +(14 rows) + +SELECT * FROM test_area START WITH name = '中国' CONNECT BY PRIOR id = fatherid limit 10; + id | name | fatherid | name_desc +----+--------+----------+----------- + 1 | 中国 | 0 | China + 2 | 湖南省 | 1 | Hunan + 3 | 广东省 | 1 | Guangdong + 4 | 海南省 | 1 | Hainan + 5 | 河北省 | 1 | Hebei + 6 | 河南省 | 1 | Henan + 7 | 山东省 | 1 | Shandong + 8 | 湖北省 | 1 | Hubei + 9 | 江苏省 | 1 | Jiangsu + 10 | 深圳市 | 3 | Shenzhen +(10 rows) + +set max_recursive_times=100000000; +create table tt22(x int); +create or replace view dual as select 'x' x; +insert into tt22 select level from dual connect by level <=1000000; +select count(*) from tt22; + count +--------- + 1000000 +(1 row) + +set max_recursive_times=200; +insert into tt22 select level from dual connect by level <=1000000; +ERROR: Current Start With...Connect by has exceeded max iteration times 200 +HINT: Please check your connect by clause carefully +drop table tt22; +/* 修复RecursiveUnion的inner分支备planning成BaseResult节点 */ +explain select t1.id,t1.pid,t1.name from test_hcb_ptb t1 start with id=141 connect by (prior pid)=id and prior pid>10 and 1=0; + QUERY PLAN +------------------------------------------------------------------------------------- + CTE Scan on tmp_reuslt (cost=3.12..3.34 rows=11 width=186) + CTE tmp_reuslt + -> StartWith Operator (cost=0.00..3.12 rows=11 width=102) + Start With pseudo atts: RUITR, array_key_9 + -> Recursive Union (cost=0.00..3.12 rows=11 width=102) + -> Seq Scan on test_hcb_ptb t1 (cost=0.00..2.80 rows=1 width=102) + Filter: (id = 141) + -> Result (cost=0.00..0.01 rows=1 width=0) + One-Time Filter: false +(9 rows) + +select t1.id,t1.pid,t1.name from test_hcb_ptb t1 start with id=141 connect by (prior pid)=id and prior pid>10 and 1=0; + id | pid | name +-----+-----+---------- + 141 | 131 | 江南摩卡 +(1 row) + +explain select t1.id,t1.pid,t1.name from test_hcb_ptb t1 start with id=141 connect by (prior pid)=id and prior pid>10 and null; + QUERY PLAN +------------------------------------------------------------------------------------- + CTE Scan on tmp_reuslt (cost=3.12..3.34 rows=11 width=186) + CTE tmp_reuslt + -> StartWith Operator (cost=0.00..3.12 rows=11 width=102) + Start With pseudo atts: RUITR, array_key_9 + -> Recursive Union (cost=0.00..3.12 rows=11 width=102) + -> Seq Scan on test_hcb_ptb t1 (cost=0.00..2.80 rows=1 width=102) + Filter: (id = 141) + -> Result (cost=0.00..0.01 rows=1 width=0) + One-Time Filter: false +(9 rows) + +select t1.id,t1.pid,t1.name from test_hcb_ptb t1 start with id=141 connect by (prior pid)=id and prior pid>10 and null; + id | pid | name +-----+-----+---------- + 141 | 131 | 江南摩卡 +(1 row) + +/* connect by level/rownum 不支持not并且in 数据不准确 */ +create table core_060(id varchar); +insert into core_060 values ('a'),('b'),('c'); +SELECT id,level FROM core_060 CONNECT BY level in (1,2); + id | level +----+------- + a | 1 + b | 1 + c | 1 + a | 2 + b | 2 + c | 2 + a | 2 + b | 2 + c | 2 + a | 2 + b | 2 + c | 2 +(12 rows) + +SELECT id,level FROM core_060 CONNECT BY not (level>2); + id | level +----+------- + a | 1 + b | 1 + c | 1 + a | 2 + b | 2 + c | 2 + a | 2 + b | 2 + c | 2 + a | 2 + b | 2 + c | 2 +(12 rows) + +SELECT id,level FROM core_060 CONNECT BY cast(level as number(38,0))<3; + id | level +----+------- + a | 1 + b | 1 + c | 1 + a | 2 + b | 2 + c | 2 + a | 2 + b | 2 + c | 2 + a | 2 + b | 2 + c | 2 +(12 rows) + +drop table core_060; +/* 存在子查询时,随着数据递归层数的增加,性能下降明显 */ +create table t_customer(id int, pid int,num int,depth int); +-- verify nestloop can be material-optimized +set enable_hashjoin = off; +set enable_mergejoin = off; +explain +select * from ( select * from t_customer where id<1200040 and id>=1200000) start with id=1200010 connect by prior id=pid; + QUERY PLAN +-------------------------------------------------------------------------------------------- + CTE Scan on tmp_reuslt (cost=423.43..423.65 rows=11 width=16) + CTE tmp_reuslt + -> StartWith Operator (cost=0.00..423.43 rows=11 width=16) + Start With pseudo atts: RUITR, array_key_1 + -> Recursive Union (cost=0.00..423.43 rows=11 width=16) + -> Seq Scan on t_customer (cost=0.00..41.08 rows=1 width=16) + Filter: ((id < 1200040) AND (id >= 1200000) AND (id = 1200010)) + -> Nested Loop (cost=0.00..38.21 rows=1 width=16) + Join Filter: (tmp_reuslt."sw_subquery_0@id" = swtest.t_customer.pid) + -> WorkTable Scan on tmp_reuslt (cost=0.00..0.20 rows=10 width=4) + -> Materialize (cost=0.00..36.69 rows=9 width=16) + -> Seq Scan on t_customer (cost=0.00..36.64 rows=9 width=16) + Filter: ((id < 1200040) AND (id >= 1200000)) +(13 rows) + +select * from ( select * from t_customer where id<1200040 and id>=1200000) start with id=1200010 connect by prior id=pid; + id | pid | num | depth +----+-----+-----+------- +(0 rows) + +reset enable_hashjoin; +reset enable_mergejoin; +-- verify nestloop can be material-optimized +set enable_nestloop = off; +set enable_mergejoin = off; +explain +select * from ( select * from t_customer where id<1200040 and id>=1200000) start with id=1200010 connect by prior id=pid; + QUERY PLAN +------------------------------------------------------------------------------------------------- + CTE Scan on tmp_reuslt (cost=411.29..411.51 rows=11 width=16) + CTE tmp_reuslt + -> StartWith Operator (cost=0.00..411.29 rows=11 width=16) + Start With pseudo atts: RUITR, array_key_1 + -> Recursive Union (cost=0.00..411.29 rows=11 width=16) + -> Seq Scan on t_customer (cost=0.00..41.08 rows=1 width=16) + Filter: ((id < 1200040) AND (id >= 1200000) AND (id = 1200010)) + -> Hash Join (cost=0.33..37.00 rows=1 width=16) + Hash Cond: (swtest.t_customer.pid = tmp_reuslt."sw_subquery_0@id") + -> Materialize (cost=0.00..36.64 rows=9 width=16) + -> Seq Scan on t_customer (cost=0.00..36.64 rows=9 width=16) + Filter: ((id < 1200040) AND (id >= 1200000)) + -> Hash (cost=0.20..0.20 rows=10 width=4) + -> WorkTable Scan on tmp_reuslt (cost=0.00..0.20 rows=10 width=4) +(14 rows) + +select * from ( select * from t_customer where id<1200040 and id>=1200000) start with id=1200010 connect by prior id=pid; + id | pid | num | depth +----+-----+-----+------- +(0 rows) + +reset enable_nestloop; +reset enable_mergejoin; +-- verify mergejoin is no need to be material-optimized +set enable_hashjoin = off; +set enable_nestloop = off; +explain +select * from ( select * from t_customer where id<1200040 and id>=1200000) start with id=1200010 connect by prior id=pid; + QUERY PLAN +------------------------------------------------------------------------------------------------- + CTE Scan on tmp_reuslt (cost=413.84..414.06 rows=11 width=16) + CTE tmp_reuslt + -> StartWith Operator (cost=0.00..413.84 rows=11 width=16) + Start With pseudo atts: RUITR, array_key_1 + -> Recursive Union (cost=0.00..413.84 rows=11 width=16) + -> Seq Scan on t_customer (cost=0.00..41.08 rows=1 width=16) + Filter: ((id < 1200040) AND (id >= 1200000) AND (id = 1200010)) + -> Merge Join (cost=37.15..37.25 rows=1 width=16) + Merge Cond: (tmp_reuslt."sw_subquery_0@id" = swtest.t_customer.pid) + -> Sort (cost=0.37..0.39 rows=10 width=4) + Sort Key: tmp_reuslt."sw_subquery_0@id" + -> WorkTable Scan on tmp_reuslt (cost=0.00..0.20 rows=10 width=4) + -> Sort (cost=36.78..36.81 rows=9 width=16) + Sort Key: swtest.t_customer.pid + -> Seq Scan on t_customer (cost=0.00..36.64 rows=9 width=16) + Filter: ((id < 1200040) AND (id >= 1200000)) +(16 rows) + +select * from ( select * from t_customer where id<1200040 and id>=1200000) start with id=1200010 connect by prior id=pid; + id | pid | num | depth +----+-----+-----+------- +(0 rows) + +reset enable_mergejoin; +reset enable_nestloop; +reset enable_hashjoin; +drop table t_customer; +-- test correlated sublink +create table test_place as select id, name, tex from test_hcb_ptb; +select t1.id,t1.pid,t1.name from test_hcb_ptb t1 start with not exists(select * from test_place where id=t1.id and id !=141) connect by prior pid=id; + id | pid | name +-----+-----+---------- + 141 | 131 | 江南摩卡 + 131 | 121 | 东山街 + 121 | 111 | 江宁区 + 111 | 11 | 南京市 + 11 | 1 | 江苏省 + 1 | 0 | 中国 +(6 rows) + +drop table test_place; +-- test where quals pushdown +drop table if exists brand_sw3 cascade; +create table brand_sw3 +( +mfg varchar(500) primary key , +brand_cd varchar(500) , +brand_name varchar(100) , +brand_party_id number(18,10) NULL,c1 serial +); +drop table if exists usview17_sw3 cascade; +create table usview17_sw3 +( +brand_party_id numeric(18,2) , +sales_tran_id numeric(12,5) , +item_qty numeric(5,0) , +mkb_cost_amt numeric(19,4) , +mkb_exp numeric +); +SELECT MAX(t2.brand_party_id)-COUNT(t2.sales_tran_id) +FROM brand_sw3 t1,usview17_sw3 t2 +WHERE t1.brand_name=PRIOR t1.brand_name +AND PRIOR t1.brand_cd IS NOT NULL +START WITH t1.mfg=t1.brand_name +CONNECT BY NOCYCLE PRIOR t1.mfg +BETWEEN t1.brand_name +AND PRIOR t1.brand_name ; + ?column? +---------- + +(1 row) + +SELECT MAX(t2.brand_party_id)-COUNT(t2.sales_tran_id) +FROM brand_sw3 t1,usview17_sw3 t2 +where t1.brand_cd IS NOT NULL CONNECT BY rownum < 3; + ?column? +---------- + +(1 row) + +drop table if exists brand_sw3 cascade; +drop table if exists usview17_sw3 cascade; +create table sw_test1(c0 int); +create table sw_test2(c0 text); +select * from sw_test1,sw_test2 where true connect by true; + c0 | c0 +----+---- +(0 rows) + +drop table sw_test1; +drop table sw_test2; diff --git a/src/test/regress/expected/sw_by_rownum_level.out b/src/test/regress/expected/sw_by_rownum_level.out new file mode 100644 index 000000000..3ac0ef3ab --- /dev/null +++ b/src/test/regress/expected/sw_by_rownum_level.out @@ -0,0 +1,180 @@ +set client_min_messages = error; +set search_path=swtest; +SET CLIENT_ENCODING='UTF8'; +--accepted cases +explain (costs off) +select * from test_area CONNECT BY LEVEL <= LENGTH('SOME TEXT'); + QUERY PLAN +-------------------------------------------------------- + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR + -> Recursive Union + -> Seq Scan on test_area + -> Nested Loop + -> WorkTable Scan on tmp_reuslt + -> Materialize + -> Seq Scan on test_area +(10 rows) + +explain (costs off) +select *, LEVEL from test_area CONNECT BY LEVEL <= LENGTH('SOME TEXT'); + QUERY PLAN +-------------------------------------------------------- + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR + -> Recursive Union + -> Seq Scan on test_area + -> Nested Loop + -> WorkTable Scan on tmp_reuslt + -> Materialize + -> Seq Scan on test_area +(10 rows) + +explain (costs off) +select * from test_area CONNECT BY ROWNUM <= LENGTH('SOME TEXT'); + QUERY PLAN +-------------------------------------------------------- + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR + -> Recursive Union + -> Seq Scan on test_area + -> Nested Loop + -> WorkTable Scan on tmp_reuslt + -> Materialize + -> Seq Scan on test_area +(10 rows) + +explain (costs off) +select *, ROWNUM from test_area CONNECT BY ROWNUM <= LENGTH('SOME TEXT'); + QUERY PLAN +-------------------------------------------------------- + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR + -> Recursive Union + -> Seq Scan on test_area + -> Nested Loop + -> WorkTable Scan on tmp_reuslt + -> Materialize + -> Seq Scan on test_area +(10 rows) + +explain (costs off) +select * from test_area CONNECT BY LEVEL < LENGTH('SOME TEXT'); + QUERY PLAN +-------------------------------------------------------- + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR + -> Recursive Union + -> Seq Scan on test_area + -> Nested Loop + -> WorkTable Scan on tmp_reuslt + -> Materialize + -> Seq Scan on test_area +(10 rows) + +explain (costs off) +select *, LEVEL from test_area CONNECT BY LEVEL < LENGTH('SOME TEXT'); + QUERY PLAN +-------------------------------------------------------- + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR + -> Recursive Union + -> Seq Scan on test_area + -> Nested Loop + -> WorkTable Scan on tmp_reuslt + -> Materialize + -> Seq Scan on test_area +(10 rows) + +explain (costs off) +select * from test_area CONNECT BY ROWNUM < LENGTH('SOME TEXT'); + QUERY PLAN +-------------------------------------------------------- + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR + -> Recursive Union + -> Seq Scan on test_area + -> Nested Loop + -> WorkTable Scan on tmp_reuslt + -> Materialize + -> Seq Scan on test_area +(10 rows) + +explain (costs off) +select *, ROWNUM from test_area CONNECT BY ROWNUM < LENGTH('SOME TEXT'); + QUERY PLAN +-------------------------------------------------------- + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR + -> Recursive Union + -> Seq Scan on test_area + -> Nested Loop + -> WorkTable Scan on tmp_reuslt + -> Materialize + -> Seq Scan on test_area +(10 rows) + +--rejected cases +explain (costs off) +select *, LEVEL from test_area CONNECT BY LEVEL > LENGTH('SOME TEXT'); + QUERY PLAN +-------------------------------------------------------- + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR + -> Recursive Union + -> Seq Scan on test_area + -> Nested Loop + -> WorkTable Scan on tmp_reuslt + -> Materialize + -> Seq Scan on test_area +(10 rows) + +explain (costs off) +select *, LEVEL from test_area CONNECT BY LEVEL >= LENGTH('SOME TEXT'); + QUERY PLAN +-------------------------------------------------------- + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR + -> Recursive Union + -> Seq Scan on test_area + -> Nested Loop + -> WorkTable Scan on tmp_reuslt + -> Materialize + -> Seq Scan on test_area +(10 rows) + +explain (costs off) +select * from test_area CONNECT BY APPLE > LENGTH('SOME TEXT'); +ERROR: column "apple" does not exist +LINE 2: select * from test_area CONNECT BY APPLE > LENGTH('SOME TEXT... + ^ +explain (costs off) +select * from test_area CONNECT BY APPLE < LENGTH('SOME TEXT'); +ERROR: column "apple" does not exist +LINE 2: select * from test_area CONNECT BY APPLE < LENGTH('SOME TEXT... + ^ +explain (costs off) +select * from test_area CONNECT BY APPLE <= LENGTH('SOME TEXT'); +ERROR: column "apple" does not exist +LINE 2: select * from test_area CONNECT BY APPLE <= LENGTH('SOME TEX... + ^ diff --git a/src/test/regress/expected/sw_clearup.out b/src/test/regress/expected/sw_clearup.out new file mode 100644 index 000000000..1276dbb55 --- /dev/null +++ b/src/test/regress/expected/sw_clearup.out @@ -0,0 +1,15 @@ +set current_schema=swtest; +drop table if exists swtest.test_area; +drop table if exists swtest.test_area2; +drop table if exists swtest.t1; +drop table if exists swtest.t2; +drop table if exists swtest.test_hcb_ptb; +drop table if exists swtest.test_hcb_fqb; +drop table if exists swtest.test_sublink; +drop table if exists swtest.test_hcb_ptbc; +drop table if exists swtest.test_swcb_a; +drop table if exists swtest.trait_value; +drop table if exists swtest.offers_20050701; +drop table if exists swtest.brand; +drop schema if exists swtest cascade; +NOTICE: drop cascades to view dual diff --git a/src/test/regress/expected/sw_icbc.out b/src/test/regress/expected/sw_icbc.out new file mode 100644 index 000000000..d20a601a8 --- /dev/null +++ b/src/test/regress/expected/sw_icbc.out @@ -0,0 +1,553 @@ +set client_min_messages = error; +set search_path=swtest; +SET CLIENT_ENCODING='UTF8'; +--signle table columns test +explain (costs off) +select * from t1 start with id = 1 connect by prior id = pid; + QUERY PLAN +----------------------------------------------------------------------- + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_1 + -> Recursive Union + -> Seq Scan on t1 + Filter: (id = 1) + -> Hash Join + Hash Cond: (swtest.t1.pid = tmp_reuslt."t1@id") + -> Seq Scan on t1 + -> Hash + -> WorkTable Scan on tmp_reuslt +(12 rows) + +select * from t1 start with id = 1 connect by prior id = pid; + id | pid | name +----+-----+------ + 1 | 0 | 1 + 2 | 1 | 2 + 4 | 1 | 4 + 5 | 2 | 5 + 7 | 4 | 7 + 8 | 4 | 8 + 9 | 7 | 9 +(7 rows) + +explain (costs off) +select * from t1 start with t1.id = 1 connect by prior t1.id = t1.pid; + QUERY PLAN +----------------------------------------------------------------------- + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_1 + -> Recursive Union + -> Seq Scan on t1 + Filter: (id = 1) + -> Hash Join + Hash Cond: (swtest.t1.pid = tmp_reuslt."t1@id") + -> Seq Scan on t1 + -> Hash + -> WorkTable Scan on tmp_reuslt +(12 rows) + +select * from t1 start with t1.id = 1 connect by prior t1.id = t1.pid; + id | pid | name +----+-----+------ + 1 | 0 | 1 + 2 | 1 | 2 + 4 | 1 | 4 + 5 | 2 | 5 + 7 | 4 | 7 + 8 | 4 | 8 + 9 | 7 | 9 +(7 rows) + +explain (costs off) +select * from t1 as test start with test.id = 1 connect by prior test.id = test.pid; + QUERY PLAN +-------------------------------------------------------------------- + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_1 + -> Recursive Union + -> Seq Scan on t1 test + Filter: (id = 1) + -> Hash Join + Hash Cond: (test.pid = tmp_reuslt."test@id") + -> Seq Scan on t1 test + -> Hash + -> WorkTable Scan on tmp_reuslt +(12 rows) + +select * from t1 as test start with test.id = 1 connect by prior test.id = test.pid; + id | pid | name +----+-----+------ + 1 | 0 | 1 + 2 | 1 | 2 + 4 | 1 | 4 + 5 | 2 | 5 + 7 | 4 | 7 + 8 | 4 | 8 + 9 | 7 | 9 +(7 rows) + +explain (costs off) +select * from t1 start with id = 1 connect by prior id = pid order by id desc; + QUERY PLAN +----------------------------------------------------------------------- + Sort + Sort Key: tmp_reuslt."t1@id" DESC + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_1 + -> Recursive Union + -> Seq Scan on t1 + Filter: (id = 1) + -> Hash Join + Hash Cond: (swtest.t1.pid = tmp_reuslt."t1@id") + -> Seq Scan on t1 + -> Hash + -> WorkTable Scan on tmp_reuslt + -> CTE Scan on tmp_reuslt +(14 rows) + +select * from t1 start with id = 1 connect by prior id = pid order by id desc; + id | pid | name +----+-----+------ + 9 | 7 | 9 + 8 | 4 | 8 + 7 | 4 | 7 + 5 | 2 | 5 + 4 | 1 | 4 + 2 | 1 | 2 + 1 | 0 | 1 +(7 rows) + +explain (costs off) +select * from t1 start with id IN (select id from t2 where id = 1) connect by prior id = pid order by id desc; + QUERY PLAN +----------------------------------------------------------------------- + Sort + Sort Key: tmp_reuslt."t1@id" DESC + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_1 + -> Recursive Union + -> Nested Loop Semi Join + -> Seq Scan on t1 + Filter: (id = 1) + -> Seq Scan on t2 + Filter: (id = 1) + -> Hash Join + Hash Cond: (swtest.t1.pid = tmp_reuslt."t1@id") + -> Seq Scan on t1 + -> Hash + -> WorkTable Scan on tmp_reuslt + -> CTE Scan on tmp_reuslt +(17 rows) + +select * from t1 start with id IN (select id from t2 where id = 1) connect by prior id = pid order by id desc; + id | pid | name +----+-----+------ + 9 | 7 | 9 + 8 | 4 | 8 + 7 | 4 | 7 + 5 | 2 | 5 + 4 | 1 | 4 + 2 | 1 | 2 + 1 | 0 | 1 +(7 rows) + +explain (costs off) select t1.id, t1.pid, t1.name from t1 start with id = 1 connect by prior id = pid; + QUERY PLAN +----------------------------------------------------------------------- + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_1 + -> Recursive Union + -> Seq Scan on t1 + Filter: (id = 1) + -> Hash Join + Hash Cond: (swtest.t1.pid = tmp_reuslt."t1@id") + -> Seq Scan on t1 + -> Hash + -> WorkTable Scan on tmp_reuslt +(12 rows) + +select t1.id, t1.pid, t1.name from t1 start with id = 1 connect by prior id = pid; + id | pid | name +----+-----+------ + 1 | 0 | 1 + 2 | 1 | 2 + 4 | 1 | 4 + 5 | 2 | 5 + 7 | 4 | 7 + 8 | 4 | 8 + 9 | 7 | 9 +(7 rows) + +explain (costs off) select sum(name) from t1 start with id = 1 connect by prior id = pid group by id, pid; + QUERY PLAN +----------------------------------------------------------------------- + HashAggregate + Group By Key: tmp_reuslt."t1@id", tmp_reuslt."t1@pid" + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_1 + -> Recursive Union + -> Seq Scan on t1 + Filter: (id = 1) + -> Hash Join + Hash Cond: (swtest.t1.pid = tmp_reuslt."t1@id") + -> Seq Scan on t1 + -> Hash + -> WorkTable Scan on tmp_reuslt + -> CTE Scan on tmp_reuslt +(14 rows) + +select sum(name) from t1 start with id = 1 connect by prior id = pid group by id, pid; + sum +----- + 7 + 4 + 1 + 9 + 2 + 5 + 8 +(7 rows) + +explain (costs off) select * from t1 start with id = 1 connect by prior id = pid and id IN (select id from t2); + QUERY PLAN +----------------------------------------------------------------------------- + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_1 + -> Recursive Union + -> Seq Scan on t1 + Filter: (id = 1) + -> Hash Semi Join + Hash Cond: (swtest.t1.id = t2.id) + -> Hash Join + Hash Cond: (swtest.t1.pid = tmp_reuslt."t1@id") + -> Seq Scan on t1 + -> Hash + -> WorkTable Scan on tmp_reuslt + -> Hash + -> Seq Scan on t2 +(16 rows) + +select * from t1 start with id = 1 connect by prior id = pid and id IN (select id from t2); + id | pid | name +----+-----+------ + 1 | 0 | 1 + 2 | 1 | 2 + 4 | 1 | 4 + 5 | 2 | 5 + 7 | 4 | 7 + 8 | 4 | 8 + 9 | 7 | 9 +(7 rows) + +explain (costs off) select * from t1 start with id = 1 and id is not NULL connect by prior id = pid; + QUERY PLAN +----------------------------------------------------------------------- + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_1 + -> Recursive Union + -> Seq Scan on t1 + Filter: ((id IS NOT NULL) AND (id = 1)) + -> Hash Join + Hash Cond: (swtest.t1.pid = tmp_reuslt."t1@id") + -> Seq Scan on t1 + -> Hash + -> WorkTable Scan on tmp_reuslt +(12 rows) + +select * from t1 start with id = 1 and id is not NULL connect by prior id = pid; + id | pid | name +----+-----+------ + 1 | 0 | 1 + 2 | 1 | 2 + 4 | 1 | 4 + 5 | 2 | 5 + 7 | 4 | 7 + 8 | 4 | 8 + 9 | 7 | 9 +(7 rows) + +explain (costs off) +select * +from +(select t1.id id, t1.pid pid, t1.name name from t1 + union + select t1.id id, t1.pid pid, t1.name name from t1) as test +start with test.id = 1 +connect by prior test.id = test.pid; + QUERY PLAN +--------------------------------------------------------------------------------------------- + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_1 + -> Recursive Union + -> Unique + -> Sort + Sort Key: swtest.t1.id, swtest.t1.pid, swtest.t1.name + -> Append + -> Seq Scan on t1 + Filter: (id = 1) + -> Seq Scan on t1 + Filter: (id = 1) + -> Hash Join + Hash Cond: (tmp_reuslt."test@id" = swtest.t1.pid) + -> WorkTable Scan on tmp_reuslt + -> Hash + -> HashAggregate + Group By Key: swtest.t1.id, swtest.t1.pid, swtest.t1.name + -> Append + -> Seq Scan on t1 + -> Seq Scan on t1 +(22 rows) + +select * +from +(select t1.id id, t1.pid pid, t1.name name from t1 + union + select t1.id id, t1.pid pid, t1.name name from t1) as test +start with test.id = 1 +connect by prior test.id = test.pid; + id | pid | name +----+-----+------ + 1 | 0 | 1 + 2 | 1 | 2 + 4 | 1 | 4 + 5 | 2 | 5 + 7 | 4 | 7 + 8 | 4 | 8 + 9 | 7 | 9 +(7 rows) + +explain (costs off) +select * +from +(select * + from(select t1.id id, t1.pid pid, t1.name name from t1 + union + select t1.id id, t1.pid pid, t1.name name from t1) as test + start with test.id = 1 + connect by prior test.id = test.pid) as tt +CONNECT BY PRIOR tt.id = tt.pid +START WITH tt.id = 1; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------------- + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_1 + -> Recursive Union + -> CTE Scan on tmp_reuslt + Filter: ("test@id" = 1) + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_1 + -> Recursive Union + -> Unique + -> Sort + Sort Key: swtest.t1.id, swtest.t1.pid, swtest.t1.name + -> Append + -> Seq Scan on t1 + Filter: (id = 1) + -> Seq Scan on t1 + Filter: (id = 1) + -> Hash Join + Hash Cond: (tmp_reuslt."test@id" = swtest.t1.pid) + -> WorkTable Scan on tmp_reuslt + -> Hash + -> HashAggregate + Group By Key: swtest.t1.id, swtest.t1.pid, swtest.t1.name + -> Append + -> Seq Scan on t1 + -> Seq Scan on t1 + -> Hash Join + Hash Cond: (tmp_reuslt."test@pid" = tmp_reuslt."tt@id") + -> Materialize + -> CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_1 + -> Recursive Union + -> Unique + -> Sort + Sort Key: swtest.t1.id, swtest.t1.pid, swtest.t1.name + -> Append + -> Seq Scan on t1 + Filter: (id = 1) + -> Seq Scan on t1 + Filter: (id = 1) + -> Hash Join + Hash Cond: (tmp_reuslt."test@id" = swtest.t1.pid) + -> WorkTable Scan on tmp_reuslt + -> Hash + -> HashAggregate + Group By Key: swtest.t1.id, swtest.t1.pid, swtest.t1.name + -> Append + -> Seq Scan on t1 + -> Seq Scan on t1 + -> Hash + -> WorkTable Scan on tmp_reuslt +(55 rows) + +select * +from +(select * + from(select t1.id id, t1.pid pid, t1.name name from t1 + union + select t1.id id, t1.pid pid, t1.name name from t1) as test + start with test.id = 1 + connect by prior test.id = test.pid) as tt +CONNECT BY PRIOR tt.id = tt.pid +START WITH tt.id = 1; + id | pid | name +----+-----+------ + 1 | 0 | 1 + 2 | 1 | 2 + 4 | 1 | 4 + 5 | 2 | 5 + 7 | 4 | 7 + 8 | 4 | 8 + 9 | 7 | 9 +(7 rows) + +--test correlated sublink in targetlist +explain select b.id, (select count(a.id) from t1 a where a.pid = b.id) c from t1 b +start with b.id=1 connect by prior b.id = b.pid; + QUERY PLAN +------------------------------------------------------------------------------------------------- + CTE Scan on tmp_reuslt (cost=18.22..122.64 rows=91 width=4) + CTE tmp_reuslt + -> StartWith Operator (cost=0.00..18.22 rows=91 width=10) + Start With pseudo atts: RUITR, array_key_1 + -> Recursive Union (cost=0.00..18.22 rows=91 width=10) + -> Seq Scan on t1 b (cost=0.00..1.11 rows=1 width=10) + Filter: (id = 1) + -> Hash Join (cost=0.33..1.53 rows=9 width=10) + Hash Cond: (b.pid = tmp_reuslt."b@id") + -> Seq Scan on t1 b (cost=0.00..1.09 rows=9 width=10) + -> Hash (cost=0.20..0.20 rows=10 width=4) + -> WorkTable Scan on tmp_reuslt (cost=0.00..0.20 rows=10 width=4) + SubPlan 2 + -> Aggregate (cost=1.12..1.13 rows=1 width=12) + -> Seq Scan on t1 a (cost=0.00..1.11 rows=2 width=4) + Filter: (pid = tmp_reuslt."b@id") +(16 rows) + +explain select * from t1 as test +where not exists (select 1 from t1 where test.id = t1.id) +start with test.id = 1 connect by prior test.id = test.pid; + QUERY PLAN +------------------------------------------------------------------------------------------------- + Hash Anti Join (cost=19.42..22.29 rows=82 width=40) + Hash Cond: (tmp_reuslt."test@id" = t1.id) + CTE tmp_reuslt + -> StartWith Operator (cost=0.00..18.22 rows=91 width=10) + Start With pseudo atts: RUITR, array_key_1 + -> Recursive Union (cost=0.00..18.22 rows=91 width=10) + -> Seq Scan on t1 test (cost=0.00..1.11 rows=1 width=10) + Filter: (id = 1) + -> Hash Join (cost=0.33..1.53 rows=9 width=10) + Hash Cond: (test.pid = tmp_reuslt."test@id") + -> Seq Scan on t1 test (cost=0.00..1.09 rows=9 width=10) + -> Hash (cost=0.20..0.20 rows=10 width=4) + -> WorkTable Scan on tmp_reuslt (cost=0.00..0.20 rows=10 width=4) + -> CTE Scan on tmp_reuslt (cost=0.00..1.82 rows=91 width=40) + -> Hash (cost=1.09..1.09 rows=9 width=4) + -> Seq Scan on t1 (cost=0.00..1.09 rows=9 width=4) +(16 rows) + +--multiple tables case +explain (costs off) select * from t1, t2 where t1.id = t2.id start with t1.id = t2.id and t1.id = 1 connect by prior t1.id = t1.pid; + QUERY PLAN +----------------------------------------------------------------------------- + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_1 + -> Recursive Union + -> Nested Loop + -> Seq Scan on t1 + Filter: (id = 1) + -> Seq Scan on t2 + Filter: (id = 1) + -> Hash Join + Hash Cond: (swtest.t1.id = swtest.t2.id) + -> Hash Join + Hash Cond: (swtest.t1.pid = tmp_reuslt."t1@id") + -> Seq Scan on t1 + -> Hash + -> WorkTable Scan on tmp_reuslt + -> Hash + -> Seq Scan on t2 +(19 rows) + +explain (costs off) select * from t1 join t2 on t1.id = t2.id start with t1.id = t2.id and t1.id = 1 connect by prior t1.id = t1.pid; + QUERY PLAN +----------------------------------------------------------------------------- + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_1 + -> Recursive Union + -> Nested Loop + -> Seq Scan on t1 + Filter: (id = 1) + -> Seq Scan on t2 + Filter: (id = 1) + -> Hash Join + Hash Cond: (swtest.t1.id = swtest.t2.id) + -> Hash Join + Hash Cond: (swtest.t1.pid = tmp_reuslt."t1@id") + -> Seq Scan on t1 + -> Hash + -> WorkTable Scan on tmp_reuslt + -> Hash + -> Seq Scan on t2 +(19 rows) + +explain (costs off) select * from t1, (select * from t2) as test where t1.id = test.id start with t1.id = test.id and t1.id = 1 connect by prior t1.id = t1.pid; + QUERY PLAN +----------------------------------------------------------------------------- + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_1 + -> Recursive Union + -> Nested Loop + -> Seq Scan on t1 + Filter: (id = 1) + -> Seq Scan on t2 + Filter: (id = 1) + -> Hash Join + Hash Cond: (swtest.t1.id = swtest.t2.id) + -> Hash Join + Hash Cond: (swtest.t1.pid = tmp_reuslt."t1@id") + -> Seq Scan on t1 + -> Hash + -> WorkTable Scan on tmp_reuslt + -> Hash + -> Seq Scan on t2 +(19 rows) + +explain (costs off) select id, (select id from t2 start with t2.id = t1.id connect by t2.id = t1.id limit 1) from t1 where id = 1; +ERROR: START WITH CONNECT BY clauses must have at least one prior key. +--unsupport case +select prior id cc from t1 start with id = 1 connect by prior id = pid; +ERROR: Not Support prior column in TargetList in case swcb. +create INCREMENTAL MATERIALIZED view mv as select * from t1 start with id=141 connect by prior id=pid; +ERROR: Feature not supported +DETAIL: with or start with clause diff --git a/src/test/regress/expected/sw_prepare.out b/src/test/regress/expected/sw_prepare.out new file mode 100644 index 000000000..39d78b5ed --- /dev/null +++ b/src/test/regress/expected/sw_prepare.out @@ -0,0 +1,229 @@ +drop schema if exists swtest cascade; +NOTICE: schema "swtest" does not exist, skipping +create schema swtest; +set current_schema=swtest; +drop table if exists swtest.test_area; +NOTICE: table "test_area" does not exist, skipping +drop table if exists swtest.test_area2; +NOTICE: table "test_area2" does not exist, skipping +drop table if exists swtest.t1; +NOTICE: table "t1" does not exist, skipping +drop table if exists swtest.t2; +NOTICE: table "t2" does not exist, skipping +drop table if exists swtest.test_hcb_ptb; +NOTICE: table "test_hcb_ptb" does not exist, skipping +drop table if exists swtest.test_hcb_fqb; +NOTICE: table "test_hcb_fqb" does not exist, skipping +drop table if exists swtest.test_sublink; +NOTICE: table "test_sublink" does not exist, skipping +drop table if exists swtest.test_hcb_ptbc; +NOTICE: table "test_hcb_ptbc" does not exist, skipping +drop table if exists swtest.test_swcb_a; +NOTICE: table "test_swcb_a" does not exist, skipping +drop table if exists swtest.trait_value; +NOTICE: table "trait_value" does not exist, skipping +drop table if exists swtest.offers_20050701; +NOTICE: table "offers_20050701" does not exist, skipping +drop table if exists swtest.brand; +NOTICE: table "brand" does not exist, skipping +create table swtest.test_area(id int4,name text, fatherid int4, name_desc text); +insert into swtest.test_area values (1, '中国', 0, 'China'); +insert into swtest.test_area values (2, '湖南省',1 , 'Hunan'); +insert into swtest.test_area values (3, '广东省',1 , 'Guangdong'); +insert into swtest.test_area values (4, '海南省',1 , 'Hainan'); +insert into swtest.test_area values (5, '河北省',1 , 'Hebei'); +insert into swtest.test_area values (6, '河南省',1 , 'Henan'); +insert into swtest.test_area values (7, '山东省',1 , 'Shandong'); +insert into swtest.test_area values (8, '湖北省',1 , 'Hubei'); +insert into swtest.test_area values (9, '江苏省',1 , 'Jiangsu'); +insert into swtest.test_area values (10,'深圳市',3 , 'Shenzhen'); +insert into swtest.test_area values (11,'长沙市',2 , 'Changsha'); +insert into swtest.test_area values (22,'祁北县',13, 'Qibei'); +insert into swtest.test_area values (12,'南山区',10, 'Nanshan'); +insert into swtest.test_area values (21,'祁西县',13, 'Qixi'); +insert into swtest.test_area values (13,'衡阳市',2 , 'Hengyang'); +insert into swtest.test_area values (14,'耒阳市',13, 'Leiyang'); +insert into swtest.test_area values (15,'龙岗区',10, 'Longgang'); +insert into swtest.test_area values (16,'福田区',10, 'Futian'); +insert into swtest.test_area values (17,'宝安区',10, 'Baoan'); +insert into swtest.test_area values (19,'祁东县',13, 'Qidong'); +insert into swtest.test_area values (18,'常宁市',13, 'Changning'); +insert into swtest.test_area values (20,'祁南县',13, 'Qinan'); +create table swtest.test_area2(id int4, id2 text, name text, fatherid int4, fatherid2 text, name_desc text); +insert into swtest.test_area2 values (1, 'A', '中国', 0, '', 'China'); +insert into swtest.test_area2 values (2, 'B', '湖南省',1 , 'A', 'Hunan'); +insert into swtest.test_area2 values (3, 'C', '广东省',1 , 'A', 'Guangdong'); +insert into swtest.test_area2 values (4, 'D', '海南省',1 , 'A', 'Hainan'); +insert into swtest.test_area2 values (5, 'E', '河北省',1 , 'A', 'Hebei'); +insert into swtest.test_area2 values (6, 'F', '河南省',1 , 'A', 'Henan'); +insert into swtest.test_area2 values (7, 'G', '山东省',1 , 'A', 'Shandong'); +insert into swtest.test_area2 values (8, 'H', '湖北省',1 , 'A', 'Hubei'); +insert into swtest.test_area2 values (9, 'I', '江苏省',1 , 'A', 'Jiangsu'); +insert into swtest.test_area2 values (10, 'J', '深圳市',3 , 'C', 'Shenzhen'); +insert into swtest.test_area2 values (11, 'K', '长沙市',2 , 'B', 'Changsha'); +insert into swtest.test_area2 values (22, 'L', '祁北县',13, 'O', 'Qibei'); +insert into swtest.test_area2 values (12, 'M', '南山区',10, 'J', 'Nanshan'); +insert into swtest.test_area2 values (21, 'N', '祁西县',13, 'O', 'Qixi'); +insert into swtest.test_area2 values (13, 'O', '衡阳市',2 , 'B', 'Hengyang'); +insert into swtest.test_area2 values (14, 'P', '耒阳市',13, 'O', 'Leiyang'); +insert into swtest.test_area2 values (15, 'Q', '龙岗区',10, 'J', 'Longgang'); +insert into swtest.test_area2 values (16, 'R', '福田区',10, 'J', 'Futian'); +insert into swtest.test_area2 values (17, 'S', '宝安区',10, 'J', 'Baoan'); +insert into swtest.test_area2 values (19, 'T', '祁东县',13, 'O', 'Qidong'); +insert into swtest.test_area2 values (18, 'U', '常宁市',13, 'O', 'Changning'); +insert into swtest.test_area2 values (20, 'V', '祁南县',13, 'O', 'Qinan'); +create table swtest.t1(id int, pid int, name text); +insert into swtest.t1 values(1, 0, '1'); +insert into swtest.t1 values(2, 1, '2'); +insert into swtest.t1 values(3, 0, '3'); +insert into swtest.t1 values(4, 1, '4'); +insert into swtest.t1 values(5, 2, '5'); +insert into swtest.t1 values(6, 3, '6'); +insert into swtest.t1 values(7, 4, '7'); +insert into swtest.t1 values(8, 4, '8'); +insert into swtest.t1 values(9, 7, '9'); +create table swtest.t2(id int, pid int, name text); +insert into swtest.t2 values(1, 0, '1'); +insert into swtest.t2 values(2, 1, '2'); +insert into swtest.t2 values(3, 0, '3'); +insert into swtest.t2 values(4, 1, '4'); +insert into swtest.t2 values(5, 2, '5'); +insert into swtest.t2 values(6, 3, '6'); +insert into swtest.t2 values(7, 4, '7'); +insert into swtest.t2 values(8, 4, '8'); +insert into swtest.t2 values(9, 7, '9'); +CREATE TABLE swtest.test_hcb_ptb(ID INT,CHA CHAR(10),VCH VARCHAR2(10),TEX TEXT,DAT DATE,TIM TIME,TIS TIMESTAMP,NAME VARCHAR2(80),PID INT,PCHA CHAR(10),PVCH VARCHAR2(10),PTEX TEXT,PDAT DATE,PTIM TIME,PTIS TIMESTAMP); +CREATE TABLE swtest.TEST_HCB_FQB(ID INT,CHA CHAR(10),VCH VARCHAR2(10),TEX TEXT,DAT DATE,TIM TIME,TIS TIMESTAMP,NAME VARCHAR2(80),PID INT,PCHA CHAR(10),PVCH VARCHAR2(10),PTEX TEXT,PDAT DATE,PTIM TIME,PTIS TIMESTAMP); +CREATE TABLE swtest.TEST_SUBLINK(ID INT,VCH VARCHAR2(10)); +INSERT INTO swtest.TEST_HCB_FQB VALUES( 1 , 'a' , 'a' , 'a' , '2021-12-12 12:12:12', '12:12:12', '2021-12-12 12:12:12' ,'中国' , 0, '0' , '0' , '0' , '2000-12-12 12:12:12', '00:00:01', '2000-12-12 12:12:12'); +INSERT INTO swtest.TEST_HCB_FQB VALUES( 11 , 'aa' , 'aa' , 'aa' , '2021-01-01 01:01:01', '01:01:01', '2021-01-01 01:01:01' ,'江苏省', 1, 'a' , 'a' , 'a' , '2021-12-12 12:12:12', '12:12:12', '2021-12-12 12:12:12'); +INSERT INTO swtest.TEST_HCB_FQB VALUES( 12 , 'ab' , 'ab' , 'ab' , '2021-01-01 01:01:01', '01:01:01', '2021-01-01 01:01:01' ,'山东省', 1, 'a' , 'a' , 'a' , '2021-12-12 12:12:12', '12:12:12', '2021-12-12 12:12:12'); +INSERT INTO swtest.TEST_HCB_FQB VALUES( 13 , 'ac' , 'ac' , 'ac' , '2021-01-01 01:01:02', '01:01:02', '2021-01-01 01:01:02' ,'安徽省', 1, 'a' , 'a' , 'a' , '2021-12-12 12:12:12', '12:12:12', '2021-12-12 12:12:12'); +INSERT INTO swtest.TEST_HCB_FQB VALUES( 14 , 'ad' , 'ad' , 'ad' , '2021-01-01 01:01:03', '01:01:03', '2021-01-01 01:01:03' ,'河南省', 1, 'a' , 'a' , 'a' , '2021-12-12 12:12:12', '12:12:12', '2021-12-12 12:12:12'); +INSERT INTO swtest.TEST_HCB_FQB VALUES( 15 , 'ae' , 'ae' , 'ae' , '2021-01-01 01:01:05', '01:01:05', '2021-01-01 01:01:05' ,'河北省', 1, 'a' , 'a' , 'a' , '2021-12-12 12:12:12', '12:12:12', '2021-12-12 12:12:12'); +INSERT INTO swtest.TEST_HCB_FQB VALUES( 16 , 'af' , 'af' , 'af' , '2021-01-01 01:01:06', '01:01:06', '2021-01-01 01:01:06' ,'湖南省', 1, 'a' , 'a' , 'a' , '2021-12-12 12:12:12', '12:12:12', '2021-12-12 12:12:12'); +INSERT INTO swtest.TEST_HCB_FQB VALUES( 17 , 'ag' , 'ag' , 'ag' , '2021-01-01 01:01:07', '01:01:07', '2021-01-01 01:01:07' ,'湖北省', 1, 'a' , 'a' , 'a' , '2021-12-12 12:12:12', '12:12:12', '2021-12-12 12:12:12'); +INSERT INTO swtest.TEST_HCB_FQB VALUES( 18 , 'ah' , 'ah' , 'ah' , '2021-01-01 01:01:08', '01:01:08', '2021-01-01 01:01:08' ,'贵州省', 1, 'a' , 'a' , 'a' , '2021-12-12 12:12:12', '12:12:12', '2021-12-12 12:12:12'); +INSERT INTO swtest.TEST_HCB_FQB VALUES( 19 , 'ai' , 'ai' , 'ai' , '2021-01-01 01:01:09', '01:01:09', '2021-01-01 01:01:09' ,'武汉省', 1, 'a' , 'a' , 'a' , '2021-12-12 12:12:12', '12:12:12', '2021-12-12 12:12:12'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(111 , 'aaa', 'aaa', 'aaa', '2021-01-01 01:01:10', '01:01:10', '2021-01-01 01:01:10' ,'南京市', 11, 'aa' , 'aa' , 'aa' , '2021-01-01 01:01:01', '01:01:01', '2021-01-01 01:01:01'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(112 , 'aab', 'aab', 'aab', '2021-01-01 01:01:11', '01:01:11', '2021-01-01 01:01:11' ,'宿迁市', 11, 'aa' , 'aa' , 'aa' , '2021-01-01 01:01:01', '01:01:01', '2021-01-01 01:01:01'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(113 , 'aac', 'aac', 'aac', '2021-01-01 01:01:12', '01:01:12', '2021-01-01 01:01:12' ,'徐州市', 11, 'aa' , 'aa' , 'aa' , '2021-01-01 01:01:01', '01:01:01', '2021-01-01 01:01:01'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(114 , 'aad', 'aad', 'aad', '2021-01-01 01:01:13', '01:01:13', '2021-01-01 01:01:13' ,'苏州市', 11, 'aa' , 'aa' , 'aa' , '2021-01-01 01:01:01', '01:01:01', '2021-01-01 01:01:01'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(115 , 'aae', 'aae', 'aae', '2021-01-01 01:01:14', '01:01:14', '2021-01-01 01:01:14' ,'盐城市', 11, 'aa' , 'aa' , 'aa' , '2021-01-01 01:01:01', '01:01:01', '2021-01-01 01:01:01'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(116 , 'aaf', 'aaf', 'aaf', '2021-01-01 01:01:15', '01:01:15', '2021-01-01 01:01:15' ,'无锡市', 11, 'aa' , 'aa' , 'aa' , '2021-01-01 01:01:01', '01:01:01', '2021-01-01 01:01:01'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(117 , 'aag', 'aag', 'aag', '2021-01-01 01:01:16', '01:01:16', '2021-01-01 01:01:16' ,'常州市', 11, 'aa' , 'aa' , 'aa' , '2021-01-01 01:01:01', '01:01:01', '2021-01-01 01:01:01'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(118 , 'aah', 'aah', 'aah', '2021-01-01 01:01:17', '01:01:17', '2021-01-01 01:01:17' ,'连云港', 11, 'aa' , 'aa' , 'aa' , '2021-01-01 01:01:01', '01:01:01', '2021-01-01 01:01:01'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(119 , 'aai', 'aai', 'aai', '2021-01-01 01:01:18', '01:01:18', '2021-01-01 01:01:18' ,'泰州市', 11, 'aa' , 'aa' , 'aa' , '2021-01-01 01:01:01', '01:01:01', '2021-01-01 01:01:01'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(121 , 'aba', 'aba', 'aba', '2021-01-01 01:01:20', '01:01:20', '2021-01-01 01:01:20' ,'江宁区', 111, 'aaa', 'aaa', 'aaa', '2021-01-01 01:01:10', '01:01:10', '2021-01-01 01:01:10'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(122 , 'abb', 'abb', 'abb', '2021-01-01 01:01:21', '01:01:21', '2021-01-01 01:01:21' ,'雨花台', 111, 'aaa', 'aaa', 'aaa', '2021-01-01 01:01:10', '01:01:10', '2021-01-01 01:01:10'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(123 , 'abc', 'abc', 'abc', '2021-01-01 01:01:22', '01:01:22', '2021-01-01 01:01:22' ,'鼓楼区', 111, 'aaa', 'aaa', 'aaa', '2021-01-01 01:01:10', '01:01:10', '2021-01-01 01:01:10'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(124 , 'abd', 'abd', 'abd', '2021-01-01 01:01:23', '01:01:23', '2021-01-01 01:01:23' ,'玄武区', 111, 'aaa', 'aaa', 'aaa', '2021-01-01 01:01:10', '01:01:10', '2021-01-01 01:01:10'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(125 , 'abe', 'abe', 'abe', '2021-01-01 01:01:24', '01:01:24', '2021-01-01 01:01:24' ,'建邺区', 111, 'aaa', 'aaa', 'aaa', '2021-01-01 01:01:10', '01:01:10', '2021-01-01 01:01:10'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(126 , 'abf', 'abf', 'abf', '2021-01-01 01:01:25', '01:01:25', '2021-01-01 01:01:25' ,'秦淮区', 111, 'aaa', 'aaa', 'aaa', '2021-01-01 01:01:10', '01:01:10', '2021-01-01 01:01:10'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(127 , 'abg', 'abg', 'abg', '2021-01-01 01:01:26', '01:01:26', '2021-01-01 01:01:26' ,'浦口区', 111, 'aaa', 'aaa', 'aaa', '2021-01-01 01:01:10', '01:01:10', '2021-01-01 01:01:10'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(128 , 'abh', 'abh', 'abh', '2021-01-01 01:01:27', '01:01:27', '2021-01-01 01:01:27' ,'浦口区', 111, 'aaa', 'aaa', 'aaa', '2021-01-01 01:01:10', '01:01:10', '2021-01-01 01:01:10'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(129 , 'abi', 'abi', 'abi', '2021-01-01 01:01:28', '01:01:28', '2021-01-01 01:01:28' ,'六合区', 111, 'aaa', 'aaa', 'aaa', '2021-01-01 01:01:10', '01:01:10', '2021-01-01 01:01:10'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(131 , 'aca', 'aca', 'aca', '2021-01-01 01:01:30', '01:01:30', '2021-01-01 01:01:30' ,'东山街', 121, 'aba', 'aba', 'aba', '2021-01-01 01:01:20', '01:01:20', '2021-01-01 01:01:20'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(132 , 'acb', 'acb', 'acb', '2021-01-01 01:01:31', '01:01:31', '2021-01-01 01:01:31' ,'秣陵街', 121, 'aba', 'aba', 'aba', '2021-01-01 01:01:20', '01:01:20', '2021-01-01 01:01:20'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(133 , 'acc', 'acc', 'acc', '2021-01-01 01:01:32', '01:01:32', '2021-01-01 01:01:32' ,'汤山街', 121, 'aba', 'aba', 'aba', '2021-01-01 01:01:20', '01:01:20', '2021-01-01 01:01:20'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(134 , 'acd', 'acd', 'acd', '2021-01-01 01:01:33', '01:01:33', '2021-01-01 01:01:33' ,'淳化街', 121, 'aba', 'aba', 'aba', '2021-01-01 01:01:20', '01:01:20', '2021-01-01 01:01:20'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(135 , 'ace', 'ace', 'ace', '2021-01-01 01:01:34', '01:01:34', '2021-01-01 01:01:34' ,'禄口街', 121, 'aba', 'aba', 'aba', '2021-01-01 01:01:20', '01:01:20', '2021-01-01 01:01:20'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(136 , 'acf', 'acf', 'acf', '2021-01-01 01:01:35', '01:01:35', '2021-01-01 01:01:35' ,'江宁街', 121, 'aba', 'aba', 'aba', '2021-01-01 01:01:20', '01:01:20', '2021-01-01 01:01:20'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(137 , 'acg', 'acg', 'acg', '2021-01-01 01:01:36', '01:01:36', '2021-01-01 01:01:36' ,'谷里街', 121, 'aba', 'aba', 'aba', '2021-01-01 01:01:20', '01:01:20', '2021-01-01 01:01:20'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(138 , 'ach', 'ach', 'ach', '2021-01-01 01:01:37', '01:01:37', '2021-01-01 01:01:37' ,'湖熟街', 121, 'aba', 'aba', 'aba', '2021-01-01 01:01:20', '01:01:20', '2021-01-01 01:01:20'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(139 , 'aci', 'aci', 'aci', '2021-01-01 01:01:38', '01:01:38', '2021-01-01 01:01:38' ,'横溪街', 121, 'aba', 'aba', 'aba', '2021-01-01 01:01:20', '01:01:20', '2021-01-01 01:01:20'); +insert into swtest.test_hcb_ptb values( 1,'a',' a','a','2021-12-12 12:12:12','12:12:12','2021-12-12 12:12:12','中国', 0,'0','0','0','2000-12-12 12:12:12','00:00:01','2000-12-12 12:12:12' ); +insert into swtest.test_hcb_ptb values( 11,'aa',' aa','aa','2021-01-01 01:01:01','01:01:01','2021-01-01 01:01:01','江苏省', 1,'a','a','a','2021-12-12 12:12:12','12:12:12','2021-12-12 12:12:12' ); +insert into swtest.test_hcb_ptb values( 12,'ab',' ab','ab','2021-01-01 01:01:01','01:01:01','2021-01-01 01:01:01','山东省', 1,'a','a','a','2021-12-12 12:12:12','12:12:12','2021-12-12 12:12:12' ); +insert into swtest.test_hcb_ptb values( 13,'ac',' ac','ac','2021-01-01 01:01:02','01:01:02','2021-01-01 01:01:02','安徽省', 1,'a','a','a','2021-12-12 12:12:12','12:12:12','2021-12-12 12:12:12' ); +insert into swtest.test_hcb_ptb values( 14,'ad',' ad','ad','2021-01-01 01:01:03','01:01:03','2021-01-01 01:01:03','河南省', 1,'a','a','a','2021-12-12 12:12:12','12:12:12','2021-12-12 12:12:12' ); +insert into swtest.test_hcb_ptb values( 15,'ae',' ae','ae','2021-01-01 01:01:05','01:01:05','2021-01-01 01:01:05','河北省', 1,'a','a','a','2021-12-12 12:12:12','12:12:12','2021-12-12 12:12:12' ); +insert into swtest.test_hcb_ptb values( 16,'af',' af','af','2021-01-01 01:01:06','01:01:06','2021-01-01 01:01:06','湖南省', 1,'a','a','a','2021-12-12 12:12:12','12:12:12','2021-12-12 12:12:12' ); +insert into swtest.test_hcb_ptb values( 17,'ag',' ag','ag','2021-01-01 01:01:07','01:01:07','2021-01-01 01:01:07','湖北省', 1,'a','a','a','2021-12-12 12:12:12','12:12:12','2021-12-12 12:12:12' ); +insert into swtest.test_hcb_ptb values( 18,'ah',' ah','ah','2021-01-01 01:01:08','01:01:08','2021-01-01 01:01:08','贵州省', 1,'a','a','a','2021-12-12 12:12:12','12:12:12','2021-12-12 12:12:12' ); +insert into swtest.test_hcb_ptb values( 19,'ai',' ai','ai','2021-01-01 01:01:09','01:01:09','2021-01-01 01:01:09','武汉省', 1,'a','a','a','2021-12-12 12:12:12','12:12:12','2021-12-12 12:12:12' ); +insert into swtest.test_hcb_ptb values(111,'aaa',' aaa','aaa','2021-01-01 01:01:10','01:01:10','2021-01-01 01:01:10','南京市', 11,'aa','aa','aa','2021-01-01 01:01:01','01:01:01','2021-01-01 01:01:01' ); +insert into swtest.test_hcb_ptb values(112,'aab',' aab','aab','2021-01-01 01:01:11','01:01:11','2021-01-01 01:01:11','宿迁市', 11,'aa','aa','aa','2021-01-01 01:01:01','01:01:01','2021-01-01 01:01:01' ); +insert into swtest.test_hcb_ptb values(113,'aac',' aac','aac','2021-01-01 01:01:12','01:01:12','2021-01-01 01:01:12','徐州市', 11,'aa','aa','aa','2021-01-01 01:01:01','01:01:01','2021-01-01 01:01:01' ); +insert into swtest.test_hcb_ptb values(114,'aad',' aad','aad','2021-01-01 01:01:13','01:01:13','2021-01-01 01:01:13','苏州市', 11,'aa','aa','aa','2021-01-01 01:01:01','01:01:01','2021-01-01 01:01:01' ); +insert into swtest.test_hcb_ptb values(115,'aae',' aae','aae','2021-01-01 01:01:14','01:01:14','2021-01-01 01:01:14','盐城市', 11,'aa','aa','aa','2021-01-01 01:01:01','01:01:01','2021-01-01 01:01:01' ); +insert into swtest.test_hcb_ptb values(117,'aag',' aag','aag','2021-01-01 01:01:16','01:01:16','2021-01-01 01:01:16','常州市', 11,'aa','aa','aa','2021-01-01 01:01:01','01:01:01','2021-01-01 01:01:01' ); +insert into swtest.test_hcb_ptb values(116,'aaf',' aaf','aaf','2021-01-01 01:01:15','01:01:15','2021-01-01 01:01:15','无锡市', 11,'aa','aa','aa','2021-01-01 01:01:01','01:01:01','2021-01-01 01:01:01' ); +insert into swtest.test_hcb_ptb values(118,'aah',' aah','aah','2021-01-01 01:01:17','01:01:17','2021-01-01 01:01:17','连云港', 11,'aa','aa','aa','2021-01-01 01:01:01','01:01:01','2021-01-01 01:01:01' ); +insert into swtest.test_hcb_ptb values(119,'aai',' aai','aai','2021-01-01 01:01:18','01:01:18','2021-01-01 01:01:18','泰州市', 11,'aa','aa','aa','2021-01-01 01:01:01','01:01:01','2021-01-01 01:01:01' ); +insert into swtest.test_hcb_ptb values(121,'aba',' aba','aba','2021-01-01 01:01:20','01:01:20','2021-01-01 01:01:20','江宁区', 111,'aaa','aaa','aaa','2021-01-01 01:01:10','01:01:10','2021-01-01 01:01:10' ); +insert into swtest.test_hcb_ptb values(122,'abb',' abb','abb','2021-01-01 01:01:21','01:01:21','2021-01-01 01:01:21','雨花台', 111,'aaa','aaa','aaa','2021-01-01 01:01:10','01:01:10','2021-01-01 01:01:10' ); +insert into swtest.test_hcb_ptb values(123,'abc',' abc','abc','2021-01-01 01:01:22','01:01:22','2021-01-01 01:01:22','鼓楼区', 111,'aaa','aaa','aaa','2021-01-01 01:01:10','01:01:10','2021-01-01 01:01:10' ); +insert into swtest.test_hcb_ptb values(124,'abd',' abd','abd','2021-01-01 01:01:23','01:01:23','2021-01-01 01:01:23','玄武区', 111,'aaa','aaa','aaa','2021-01-01 01:01:10','01:01:10','2021-01-01 01:01:10' ); +insert into swtest.test_hcb_ptb values(125,'abe',' abe','abe','2021-01-01 01:01:24','01:01:24','2021-01-01 01:01:24','建邺区', 111,'aaa','aaa','aaa','2021-01-01 01:01:10','01:01:10','2021-01-01 01:01:10' ); +insert into swtest.test_hcb_ptb values(126,'abf',' abf','abf','2021-01-01 01:01:25','01:01:25','2021-01-01 01:01:25','秦淮区', 111,'aaa','aaa','aaa','2021-01-01 01:01:10','01:01:10','2021-01-01 01:01:10' ); +insert into swtest.test_hcb_ptb values(127,'abg',' abg','abg','2021-01-01 01:01:26','01:01:26','2021-01-01 01:01:26','浦口区', 111,'aaa','aaa','aaa','2021-01-01 01:01:10','01:01:10','2021-01-01 01:01:10' ); +insert into swtest.test_hcb_ptb values(128,'abh',' abh','abh','2021-01-01 01:01:27','01:01:27','2021-01-01 01:01:27','浦口区', 111,'aaa','aaa','aaa','2021-01-01 01:01:10','01:01:10','2021-01-01 01:01:10' ); +insert into swtest.test_hcb_ptb values(129,'abi',' abi','abi','2021-01-01 01:01:28','01:01:28','2021-01-01 01:01:28','六合区', 111,'aaa','aaa','aaa','2021-01-01 01:01:10','01:01:10','2021-01-01 01:01:10' ); +insert into swtest.test_hcb_ptb values(131,'aca',' aca','aca','2021-01-01 01:01:30','01:01:30','2021-01-01 01:01:30','东山街', 121,'aba','aba','aba','2021-01-01 01:01:20','01:01:20','2021-01-01 01:01:20' ); +insert into swtest.test_hcb_ptb values(132,'acb',' acb','acb','2021-01-01 01:01:31','01:01:31','2021-01-01 01:01:31','秣陵街', 121,'aba','aba','aba','2021-01-01 01:01:20','01:01:20','2021-01-01 01:01:20' ); +insert into swtest.test_hcb_ptb values(133,'acc',' acc','acc','2021-01-01 01:01:32','01:01:32','2021-01-01 01:01:32','汤山街', 121,'aba','aba','aba','2021-01-01 01:01:20','01:01:20','2021-01-01 01:01:20' ); +insert into swtest.test_hcb_ptb values(135,'ace',' ace','ace','2021-01-01 01:01:34','01:01:34','2021-01-01 01:01:34','禄口街', 121,'aba','aba','aba','2021-01-01 01:01:20','01:01:20','2021-01-01 01:01:20' ); +insert into swtest.test_hcb_ptb values(134,'acd',' acd','acd','2021-01-01 01:01:33','01:01:33','2021-01-01 01:01:33','淳化街', 121,'aba','aba','aba','2021-01-01 01:01:20','01:01:20','2021-01-01 01:01:20' ); +insert into swtest.test_hcb_ptb values(136,'acf',' acf','acf','2021-01-01 01:01:35','01:01:35','2021-01-01 01:01:35','江宁街', 121,'aba','aba','aba','2021-01-01 01:01:20','01:01:20','2021-01-01 01:01:20' ); +insert into swtest.test_hcb_ptb values(137,'acg',' acg','acg','2021-01-01 01:01:36','01:01:36','2021-01-01 01:01:36','谷里街', 121,'aba','aba','aba','2021-01-01 01:01:20','01:01:20','2021-01-01 01:01:20' ); +insert into swtest.test_hcb_ptb values(138,'ach',' ach','ach','2021-01-01 01:01:37','01:01:37','2021-01-01 01:01:37','湖熟街', 121,'aba','aba','aba','2021-01-01 01:01:20','01:01:20','2021-01-01 01:01:20' ); +insert into swtest.test_hcb_ptb values(139,'aci',' aci','aci','2021-01-01 01:01:38','01:01:38','2021-01-01 01:01:38','横溪街', 121,'aba','aba','aba','2021-01-01 01:01:20','01:01:20','2021-01-01 01:01:20' ); +insert into swtest.test_hcb_ptb values(141,'ada',' ada','ada','2021-01-01 01:01:40','01:01:40','2021-01-01 01:01:40','江南摩卡', 131,'aca','aca','aca','2021-01-01 01:01:30','01:01:30','2021-01-01 01:01:30' ); +insert into swtest.test_hcb_ptb values(142,'adb',' adb','adb','2021-01-01 01:01:41','01:01:41','2021-01-01 01:01:41','四季云顶', 131,'aca','aca','aca','2021-01-01 01:01:30','01:01:30','2021-01-01 01:01:30' ); +insert into swtest.test_hcb_ptb values(143,'adc',' adc','adc','2021-01-01 01:01:42','01:01:42','2021-01-01 01:01:42','盛世江南', 131,'aca','aca','aca','2021-01-01 01:01:30','01:01:30','2021-01-01 01:01:30' ); +insert into swtest.test_hcb_ptb values(144,'add',' add','add','2021-01-01 01:01:43','01:01:43','2021-01-01 01:01:43','七里香都', 131,'aca','aca','aca','2021-01-01 01:01:30','01:01:30','2021-01-01 01:01:30' ); +insert into swtest.test_hcb_ptb values(145,'ade',' ade','ade','2021-01-01 01:01:44','01:01:44','2021-01-01 01:01:44','西山枫林', 131,'aca','aca','aca','2021-01-01 01:01:30','01:01:30','2021-01-01 01:01:30' ); +insert into swtest.test_hcb_ptb values(146,'adf',' adf','adf','2021-01-01 01:01:45','01:01:45','2021-01-01 01:01:45','醉墨小镇', 131,'aca','aca','aca','2021-01-01 01:01:30','01:01:30','2021-01-01 01:01:30' ); +insert into swtest.test_hcb_ptb values(147,'adg',' adg','adg','2021-01-01 01:01:46','01:01:46','2021-01-01 01:01:46','布拉格调', 131,'aca','aca','aca','2021-01-01 01:01:30','01:01:30','2021-01-01 01:01:30' ); +insert into swtest.test_hcb_ptb values(148,'adh',' adh','adh','2021-01-01 01:01:47','01:01:47','2021-01-01 01:01:47','清幽别院', 131,'aca','aca','aca','2021-01-01 01:01:30','01:01:30','2021-01-01 01:01:30' ); +insert into swtest.test_hcb_ptb values(149,'adi',' adi','adi','2021-01-01 01:01:48','01:01:48','2021-01-01 01:01:48','璀璨天城', 131,'aca','aca','aca','2021-01-01 01:01:30','01:01:30','2021-01-01 01:01:30' ); +insert into swtest.test_hcb_ptb values(151,'aea',' aea','aea','2021-01-01 01:01:50','01:01:50','2021-01-01 01:01:50','江南一楼', 141,'ada','ada','ada','2021-01-01 01:01:40','01:01:40','2021-01-01 01:01:40' ); +insert into swtest.test_hcb_ptb values(152,'aeb',' aeb','aeb','2021-01-01 01:01:51','01:01:51','2021-01-01 01:01:51','江南二楼', 141,'ada','ada','ada','2021-01-01 01:01:40','01:01:40','2021-01-01 01:01:40' ); +insert into swtest.test_hcb_ptb values(153,'aec',' aec','aec','2021-01-01 01:01:52','01:01:52','2021-01-01 01:01:52','江南三楼', 141,'ada','ada','ada','2021-01-01 01:01:40','01:01:40','2021-01-01 01:01:40' ); +insert into swtest.test_hcb_ptb values(154,'aed',' aed','aed','2021-01-01 01:01:53','01:01:53','2021-01-01 01:01:53','江南四楼', 141,'ada','ada','ada','2021-01-01 01:01:40','01:01:40','2021-01-01 01:01:40' ); +insert into swtest.test_hcb_ptb values(155,'aee',' aee','aee','2021-01-01 01:01:54','01:01:54','2021-01-01 01:01:54','江南五楼', 141,'ada','ada','ada','2021-01-01 01:01:40','01:01:40','2021-01-01 01:01:40' ); +insert into swtest.test_hcb_ptb values(156,'aef',' aef','aef','2021-01-01 01:01:55','01:01:55','2021-01-01 01:01:55','江南六楼', 141,'ada','ada','ada','2021-01-01 01:01:40','01:01:40','2021-01-01 01:01:40' ); +insert into swtest.test_hcb_ptb values(157,'aeg',' aeg','aeg','2021-01-01 01:01:56','01:01:56','2021-01-01 01:01:56','江南七楼', 141,'ada','ada','ada','2021-01-01 01:01:40','01:01:40','2021-01-01 01:01:40' ); +insert into swtest.test_hcb_ptb values(158,'aeh',' aeh','aeh','2021-01-01 01:01:57','01:01:57','2021-01-01 01:01:57','江南八楼', 141,'ada','ada','ada','2021-01-01 01:01:40','01:01:40','2021-01-01 01:01:40' ); +insert into swtest.test_hcb_ptb values(159,'aei',' aei','aei','2021-01-01 01:01:58','01:01:58','2021-01-01 01:01:58','江南九楼', 141,'ada','ada','ada','2021-01-01 01:01:40','01:01:40','2021-01-01 01:01:40' ); +insert into swtest.test_hcb_ptb values(161,'afa',' afa','afa','2021-01-01 01:02:50','01:02:50','2021-01-01 01:02:50','第一单元', 151,'aea','aea','aea','2021-01-01 01:01:50','01:01:50','2021-01-01 01:01:50' ); +insert into swtest.test_hcb_ptb values(162,'afb',' afb','afb','2021-01-01 01:02:51','01:02:51','2021-01-01 01:02:51','第二单元', 151,'aea','aea','aea','2021-01-01 01:01:50','01:01:50','2021-01-01 01:01:50' ); +insert into swtest.test_hcb_ptb values(163,'afc',' afc','afc','2021-01-01 01:02:52','01:02:52','2021-01-01 01:02:52','第三单元', 151,'aea','aea','aea','2021-01-01 01:01:50','01:01:50','2021-01-01 01:01:50' ); +insert into swtest.test_hcb_ptb values(164,'afd',' afd','afd','2021-01-01 01:02:53','01:02:53','2021-01-01 01:02:53','第四单元', 151,'aea','aea','aea','2021-01-01 01:01:50','01:01:50','2021-01-01 01:01:50' ); +insert into swtest.test_hcb_ptb values(165,'afe',' afe','afe','2021-01-01 01:02:54','01:02:54','2021-01-01 01:02:54','第五单元', 151,'aea','aea','aea','2021-01-01 01:01:50','01:01:50','2021-01-01 01:01:50' ); +insert into swtest.test_hcb_ptb values(166,'aff',' aff','aff','2021-01-01 01:02:55','01:02:55','2021-01-01 01:02:55','第六单元', 151,'aea','aea','aea','2021-01-01 01:01:50','01:01:50','2021-01-01 01:01:50' ); +insert into swtest.test_hcb_ptb values(167,'afg',' afg','afg','2021-01-01 01:02:56','01:02:56','2021-01-01 01:02:56','第七单元', 151,'aea','aea','aea','2021-01-01 01:01:50','01:01:50','2021-01-01 01:01:50' ); +insert into swtest.test_hcb_ptb values(168,'afh',' afh','afh','2021-01-01 01:02:57','01:02:57','2021-01-01 01:02:57','第八单元', 151,'aea','aea','aea','2021-01-01 01:01:50','01:01:50','2021-01-01 01:01:50' ); +insert into swtest.test_hcb_ptb values(169,'afi',' afi','afi','2021-01-01 01:02:58','01:02:58','2021-01-01 01:02:58','第九单元', 151,'aea','aea','aea','2021-01-01 01:01:50','01:01:50','2021-01-01 01:01:50' ); +CREATE TABLE swtest.test_hcb_ptbc(ID INT,CHA CHAR(10),VCH VARCHAR2(10),TEX TEXT,DAT DATE,TIM TIME,TIS TIMESTAMP,NAME VARCHAR2(80),PID INT,PCHA CHAR(10),PVCH VARCHAR2(10),PTEX TEXT,PDAT DATE,PTIM TIME,PTIS TIMESTAMP +) with (orientation = column); +insert into test_hcb_ptbc select * from test_hcb_ptb; +CREATE TABLE swtest.test_swcb_a (ID varchar2(10) PRIMARY KEY,NAME varchar2(100),PID varchar2(10)); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "test_swcb_a_pkey" for table "test_swcb_a" +INSERT INTO swtest.test_swcb_a VALUES ('00001', '中国', '-1'); +INSERT INTO swtest.test_swcb_a VALUES ('00011', '陕西', '00001'); +INSERT INTO swtest.test_swcb_a VALUES ('00012', '贵州', '00001'); +INSERT INTO swtest.test_swcb_a VALUES ('00013', '河南', '00001'); +INSERT INTO swtest.test_swcb_a VALUES ('00111', '西安', '00011'); +INSERT INTO swtest.test_swcb_a VALUES ('00112', '咸阳', '00011'); +INSERT INTO swtest.test_swcb_a VALUES ('00113', '延安', '00011'); +INSERT INTO swtest.test_swcb_a VALUES ('00114', '华县', '00013'); +INSERT INTO swtest.test_swcb_a VALUES ('00115', '河内', '00016'); +INSERT INTO swtest.test_swcb_a VALUES ('00116', '清迈', '00015'); +INSERT INTO swtest.test_swcb_a VALUES ('00117', '仰光', '00017'); +INSERT INTO swtest.test_swcb_a VALUES ('00118', '纽约', '00120'); +INSERT INTO swtest.test_swcb_a VALUES ('00119', '费城', '00118'); +INSERT INTO swtest.test_swcb_a VALUES ('00120', '华盛顿', '00119'); +create table swtest.trait_value(TRAIT_VALUE_CD VARCHAR(50)primary key, TRAIT_VALUE_DESC VARCHAR(250) NULL, TRAIT_VAL VARCHAR(100) NULL, UOM_CD VARCHAR(50) NULL, TRAIT_CD VARCHAR(50) NULL,c1 serial); +NOTICE: CREATE TABLE will create implicit sequence "trait_value_c1_seq" for serial column "trait_value.c1" +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "trait_value_pkey" for table "trait_value" +INSERT INTO swtest.TRAIT_VALUE VALUES ('A', NULL, 'A' , 'A' , 'A'); +INSERT INTO swtest.TRAIT_VALUE VALUES ('B', 'B' , NULL, 'B' , 'B'); +INSERT INTO swtest.TRAIT_VALUE VALUES ('C', 'C' , 'C' , NULL, NULL); +INSERT INTO swtest.TRAIT_VALUE VALUES ('D', NULL, NULL, NULL, 'D'); +INSERT INTO swtest.TRAIT_VALUE VALUES ('E', 'E' , ' AA' , 'E' , 'E'); +INSERT INTO swtest.TRAIT_VALUE VALUES ('F', ' ' , 'AA ' , 'F' , 'F'); +create table swtest.offers_20050701(PROMO_ID VARCHAR(10), PARTY_ID VARCHAR(10) NULL, LOCATION_ID number(17,0) NULL); +create table swtest.brand(a int default 2, mfg varchar(500), brand_cd varchar(500), brand_name varchar(100), brand_party_id number(18,10) NULL); +analyze; diff --git a/src/test/regress/expected/sw_siblings.out b/src/test/regress/expected/sw_siblings.out new file mode 100644 index 000000000..14d955a4f --- /dev/null +++ b/src/test/regress/expected/sw_siblings.out @@ -0,0 +1,498 @@ +set client_min_messages = error; +set search_path=swtest; +SET CLIENT_ENCODING='UTF8'; +/* + * + * START WITH .... CONNECT BY基础测试用例 + * + * 测试用例表数 + * openGauss=# select * from swtest.test_area; + * id | name | fatherid | name_desc + * ----+--------+----------+----------- + * 1 | 中国 | 0 | china + * 2 | 湖南省 | 1 | hunan + * 3 | 广东省 | 1 | guangdong + * 4 | 海南省 | 1 | hainan + * 5 | 河北省 | 1 | hebei + * 6 | 河南省 | 1 | henan + * 7 | 山东省 | 1 | shandong + * 8 | 湖北省 | 1 | hubei + * 9 | 江苏省 | 1 | jiangsu + * 10 | 深圳市 | 3 | shenzhen + * 11 | 长沙市 | 2 | changsha + * 22 | 祁北县 | 13 | qibei + * 12 | 南山区 | 10 | nanshan + * 21 | 祁西县 | 13 | qixi + * 13 | 衡阳市 | 2 | hengyang + * 14 | 耒阳市 | 13 | leiyang + * 15 | 龙岗区 | 10 | longgang + * 16 | 福田区 | 10 | futian + * 17 | 宝安区 | 10 | baoan + * 19 | 祁东县 | 13 | qidong + * 18 | 常宁市 | 13 | changning + * 20 | 祁南县 | 13 | qinan + * + */ +/* case 1.1 test root->leaf order siblings by id asc + * expect order: 1 2 11 13 14 18 19 20 21 22 3 10 12 15 16 17 4 5 6 7 8 9 + */ +EXPLAIN (costs off) +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), SYS_CONNECT_BY_PATH(name, '@') cpath +FROM test_area +START WITH name = '中国' +CONNECT BY prior id = fatherid +ORDER SIBLINGS BY id; + QUERY PLAN +------------------------------------------------------------------------------------------------------ + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_1, array_col_2, array_col_4, array_siblings + -> Sort + Sort Key: array_siblings + -> Recursive Union + -> Sort + Sort Key: swtest.test_area.id + -> Seq Scan on test_area + Filter: (name = '中国'::text) + -> Sort + Sort Key: swtest.test_area.id + -> Hash Join + Hash Cond: (swtest.test_area.fatherid = tmp_reuslt."test_area@id") + -> Seq Scan on test_area + -> Hash + -> WorkTable Scan on tmp_reuslt +(18 rows) + +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), SYS_CONNECT_BY_PATH(name, '@') cpath +FROM test_area +START WITH name = '中国' +CONNECT BY prior id = fatherid +ORDER SIBLINGS BY id; + id | name | fatherid | name_desc | level | connect_by_isleaf | connect_by_iscycle | connect_by_root | cpath +----+--------+----------+-----------+-------+-------------------+--------------------+-----------------+---------------------------- + 1 | 中国 | 0 | China | 1 | 0 | 0 | China | @中国 + 2 | 湖南省 | 1 | Hunan | 2 | 0 | 0 | China | @中国@湖南省 + 11 | 长沙市 | 2 | Changsha | 3 | 1 | 0 | China | @中国@湖南省@长沙市 + 13 | 衡阳市 | 2 | Hengyang | 3 | 0 | 0 | China | @中国@湖南省@衡阳市 + 14 | 耒阳市 | 13 | Leiyang | 4 | 1 | 0 | China | @中国@湖南省@衡阳市@耒阳市 + 18 | 常宁市 | 13 | Changning | 4 | 1 | 0 | China | @中国@湖南省@衡阳市@常宁市 + 19 | 祁东县 | 13 | Qidong | 4 | 1 | 0 | China | @中国@湖南省@衡阳市@祁东县 + 20 | 祁南县 | 13 | Qinan | 4 | 1 | 0 | China | @中国@湖南省@衡阳市@祁南县 + 21 | 祁西县 | 13 | Qixi | 4 | 1 | 0 | China | @中国@湖南省@衡阳市@祁西县 + 22 | 祁北县 | 13 | Qibei | 4 | 1 | 0 | China | @中国@湖南省@衡阳市@祁北县 + 3 | 广东省 | 1 | Guangdong | 2 | 0 | 0 | China | @中国@广东省 + 10 | 深圳市 | 3 | Shenzhen | 3 | 0 | 0 | China | @中国@广东省@深圳市 + 12 | 南山区 | 10 | Nanshan | 4 | 1 | 0 | China | @中国@广东省@深圳市@南山区 + 15 | 龙岗区 | 10 | Longgang | 4 | 1 | 0 | China | @中国@广东省@深圳市@龙岗区 + 16 | 福田区 | 10 | Futian | 4 | 1 | 0 | China | @中国@广东省@深圳市@福田区 + 17 | 宝安区 | 10 | Baoan | 4 | 1 | 0 | China | @中国@广东省@深圳市@宝安区 + 4 | 海南省 | 1 | Hainan | 2 | 1 | 0 | China | @中国@海南省 + 5 | 河北省 | 1 | Hebei | 2 | 1 | 0 | China | @中国@河北省 + 6 | 河南省 | 1 | Henan | 2 | 1 | 0 | China | @中国@河南省 + 7 | 山东省 | 1 | Shandong | 2 | 1 | 0 | China | @中国@山东省 + 8 | 湖北省 | 1 | Hubei | 2 | 1 | 0 | China | @中国@湖北省 + 9 | 江苏省 | 1 | Jiangsu | 2 | 1 | 0 | China | @中国@江苏省 +(22 rows) + +/* case 1.2 test root->leaf order siblings by id desc + * expect order: 1 9 8 7 6 5 4 3 10 17 16 15 12 2 13 22 21 20 19 18 14 11 + */ +EXPLAIN (costs off) +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), SYS_CONNECT_BY_PATH(name, '@') cpath +FROM test_area +START WITH name = '中国' +CONNECT BY prior id = fatherid +ORDER SIBLINGS BY id desc; + QUERY PLAN +------------------------------------------------------------------------------------------------------ + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_1, array_col_2, array_col_4, array_siblings + -> Sort + Sort Key: array_siblings + -> Recursive Union + -> Sort + Sort Key: swtest.test_area.id DESC + -> Seq Scan on test_area + Filter: (name = '中国'::text) + -> Sort + Sort Key: swtest.test_area.id DESC + -> Hash Join + Hash Cond: (swtest.test_area.fatherid = tmp_reuslt."test_area@id") + -> Seq Scan on test_area + -> Hash + -> WorkTable Scan on tmp_reuslt +(18 rows) + +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), SYS_CONNECT_BY_PATH(name, '@') cpath +FROM test_area +START WITH name = '中国' +CONNECT BY prior id = fatherid +ORDER SIBLINGS BY id desc; + id | name | fatherid | name_desc | level | connect_by_isleaf | connect_by_iscycle | connect_by_root | cpath +----+--------+----------+-----------+-------+-------------------+--------------------+-----------------+---------------------------- + 1 | 中国 | 0 | China | 1 | 0 | 0 | China | @中国 + 9 | 江苏省 | 1 | Jiangsu | 2 | 1 | 0 | China | @中国@江苏省 + 8 | 湖北省 | 1 | Hubei | 2 | 1 | 0 | China | @中国@湖北省 + 7 | 山东省 | 1 | Shandong | 2 | 1 | 0 | China | @中国@山东省 + 6 | 河南省 | 1 | Henan | 2 | 1 | 0 | China | @中国@河南省 + 5 | 河北省 | 1 | Hebei | 2 | 1 | 0 | China | @中国@河北省 + 4 | 海南省 | 1 | Hainan | 2 | 1 | 0 | China | @中国@海南省 + 3 | 广东省 | 1 | Guangdong | 2 | 0 | 0 | China | @中国@广东省 + 10 | 深圳市 | 3 | Shenzhen | 3 | 0 | 0 | China | @中国@广东省@深圳市 + 17 | 宝安区 | 10 | Baoan | 4 | 1 | 0 | China | @中国@广东省@深圳市@宝安区 + 16 | 福田区 | 10 | Futian | 4 | 1 | 0 | China | @中国@广东省@深圳市@福田区 + 15 | 龙岗区 | 10 | Longgang | 4 | 1 | 0 | China | @中国@广东省@深圳市@龙岗区 + 12 | 南山区 | 10 | Nanshan | 4 | 1 | 0 | China | @中国@广东省@深圳市@南山区 + 2 | 湖南省 | 1 | Hunan | 2 | 0 | 0 | China | @中国@湖南省 + 13 | 衡阳市 | 2 | Hengyang | 3 | 0 | 0 | China | @中国@湖南省@衡阳市 + 22 | 祁北县 | 13 | Qibei | 4 | 1 | 0 | China | @中国@湖南省@衡阳市@祁北县 + 21 | 祁西县 | 13 | Qixi | 4 | 1 | 0 | China | @中国@湖南省@衡阳市@祁西县 + 20 | 祁南县 | 13 | Qinan | 4 | 1 | 0 | China | @中国@湖南省@衡阳市@祁南县 + 19 | 祁东县 | 13 | Qidong | 4 | 1 | 0 | China | @中国@湖南省@衡阳市@祁东县 + 18 | 常宁市 | 13 | Changning | 4 | 1 | 0 | China | @中国@湖南省@衡阳市@常宁市 + 14 | 耒阳市 | 13 | Leiyang | 4 | 1 | 0 | China | @中国@湖南省@衡阳市@耒阳市 + 11 | 长沙市 | 2 | Changsha | 3 | 1 | 0 | China | @中国@湖南省@长沙市 +(22 rows) + +/* case 1.3 test double_root->leaf order siblings by id asc + * expect order: 10 12 15 16 17 13 14 18 19 20 21 22 + */ +EXPLAIN (costs off) +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), SYS_CONNECT_BY_PATH(name, '@') cpath +FROM test_area +START WITH name = '衡阳市' or name = '深圳市' +CONNECT BY prior id = fatherid +ORDER SIBLINGS BY id; + QUERY PLAN +------------------------------------------------------------------------------------------------------ + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_1, array_col_2, array_col_4, array_siblings + -> Sort + Sort Key: array_siblings + -> Recursive Union + -> Sort + Sort Key: swtest.test_area.id + -> Seq Scan on test_area + Filter: ((name = '衡阳市'::text) OR (name = '深圳市'::text)) + -> Sort + Sort Key: swtest.test_area.id + -> Hash Join + Hash Cond: (swtest.test_area.fatherid = tmp_reuslt."test_area@id") + -> Seq Scan on test_area + -> Hash + -> WorkTable Scan on tmp_reuslt +(18 rows) + +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), SYS_CONNECT_BY_PATH(name, '@') cpath +FROM test_area +START WITH name = '衡阳市' or name = '深圳市' +CONNECT BY prior id = fatherid +ORDER SIBLINGS BY id; + id | name | fatherid | name_desc | level | connect_by_isleaf | connect_by_iscycle | connect_by_root | cpath +----+--------+----------+-----------+-------+-------------------+--------------------+-----------------+---------------- + 10 | 深圳市 | 3 | Shenzhen | 1 | 0 | 0 | Shenzhen | @深圳市 + 12 | 南山区 | 10 | Nanshan | 2 | 1 | 0 | Shenzhen | @深圳市@南山区 + 15 | 龙岗区 | 10 | Longgang | 2 | 1 | 0 | Shenzhen | @深圳市@龙岗区 + 16 | 福田区 | 10 | Futian | 2 | 1 | 0 | Shenzhen | @深圳市@福田区 + 17 | 宝安区 | 10 | Baoan | 2 | 1 | 0 | Shenzhen | @深圳市@宝安区 + 13 | 衡阳市 | 2 | Hengyang | 1 | 0 | 0 | Hengyang | @衡阳市 + 14 | 耒阳市 | 13 | Leiyang | 2 | 1 | 0 | Hengyang | @衡阳市@耒阳市 + 18 | 常宁市 | 13 | Changning | 2 | 1 | 0 | Hengyang | @衡阳市@常宁市 + 19 | 祁东县 | 13 | Qidong | 2 | 1 | 0 | Hengyang | @衡阳市@祁东县 + 20 | 祁南县 | 13 | Qinan | 2 | 1 | 0 | Hengyang | @衡阳市@祁南县 + 21 | 祁西县 | 13 | Qixi | 2 | 1 | 0 | Hengyang | @衡阳市@祁西县 + 22 | 祁北县 | 13 | Qibei | 2 | 1 | 0 | Hengyang | @衡阳市@祁北县 +(12 rows) + + +/* case 1.4 test double_root->leaf order siblings by id desc + * expect order: 13 22 21 20 19 18 14 10 17 16 15 12 + */ +EXPLAIN (costs off) +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), SYS_CONNECT_BY_PATH(name, '@') cpath +FROM test_area +START WITH name = '衡阳市' or name = '深圳市' +CONNECT BY prior id = fatherid +ORDER SIBLINGS BY id desc; + QUERY PLAN +------------------------------------------------------------------------------------------------------ + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_1, array_col_2, array_col_4, array_siblings + -> Sort + Sort Key: array_siblings + -> Recursive Union + -> Sort + Sort Key: swtest.test_area.id DESC + -> Seq Scan on test_area + Filter: ((name = '衡阳市'::text) OR (name = '深圳市'::text)) + -> Sort + Sort Key: swtest.test_area.id DESC + -> Hash Join + Hash Cond: (swtest.test_area.fatherid = tmp_reuslt."test_area@id") + -> Seq Scan on test_area + -> Hash + -> WorkTable Scan on tmp_reuslt +(18 rows) + +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), SYS_CONNECT_BY_PATH(name, '@') cpath +FROM test_area +START WITH name = '衡阳市' or name = '深圳市' +CONNECT BY prior id = fatherid +ORDER SIBLINGS BY id desc; + id | name | fatherid | name_desc | level | connect_by_isleaf | connect_by_iscycle | connect_by_root | cpath +----+--------+----------+-----------+-------+-------------------+--------------------+-----------------+---------------- + 13 | 衡阳市 | 2 | Hengyang | 1 | 0 | 0 | Hengyang | @衡阳市 + 22 | 祁北县 | 13 | Qibei | 2 | 1 | 0 | Hengyang | @衡阳市@祁北县 + 21 | 祁西县 | 13 | Qixi | 2 | 1 | 0 | Hengyang | @衡阳市@祁西县 + 20 | 祁南县 | 13 | Qinan | 2 | 1 | 0 | Hengyang | @衡阳市@祁南县 + 19 | 祁东县 | 13 | Qidong | 2 | 1 | 0 | Hengyang | @衡阳市@祁东县 + 18 | 常宁市 | 13 | Changning | 2 | 1 | 0 | Hengyang | @衡阳市@常宁市 + 14 | 耒阳市 | 13 | Leiyang | 2 | 1 | 0 | Hengyang | @衡阳市@耒阳市 + 10 | 深圳市 | 3 | Shenzhen | 1 | 0 | 0 | Shenzhen | @深圳市 + 17 | 宝安区 | 10 | Baoan | 2 | 1 | 0 | Shenzhen | @深圳市@宝安区 + 16 | 福田区 | 10 | Futian | 2 | 1 | 0 | Shenzhen | @深圳市@福田区 + 15 | 龙岗区 | 10 | Longgang | 2 | 1 | 0 | Shenzhen | @深圳市@龙岗区 + 12 | 南山区 | 10 | Nanshan | 2 | 1 | 0 | Shenzhen | @深圳市@南山区 +(12 rows) + + +/* case 1.5 test leaf->root order siblings by id asc + * expect order: 18 13 2 1 + */ +EXPLAIN (costs off) +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), SYS_CONNECT_BY_PATH(name, '@') cpath +FROM test_area +START WITH name = '常宁市' +CONNECT BY id = prior fatherid +ORDER SIBLINGS BY id; + QUERY PLAN +------------------------------------------------------------------------------------------------------ + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_3, array_col_2, array_col_4, array_siblings + -> Sort + Sort Key: array_siblings + -> Recursive Union + -> Sort + Sort Key: swtest.test_area.id + -> Seq Scan on test_area + Filter: (name = '常宁市'::text) + -> Sort + Sort Key: swtest.test_area.id + -> Hash Join + Hash Cond: (swtest.test_area.id = tmp_reuslt."test_area@fatherid") + -> Seq Scan on test_area + -> Hash + -> WorkTable Scan on tmp_reuslt +(18 rows) + +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), SYS_CONNECT_BY_PATH(name, '@') cpath +FROM test_area +START WITH name = '常宁市' +CONNECT BY id = prior fatherid +ORDER SIBLINGS BY id; + id | name | fatherid | name_desc | level | connect_by_isleaf | connect_by_iscycle | connect_by_root | cpath +----+--------+----------+-----------+-------+-------------------+--------------------+-----------------+---------------------------- + 18 | 常宁市 | 13 | Changning | 1 | 0 | 0 | Changning | @常宁市 + 13 | 衡阳市 | 2 | Hengyang | 2 | 0 | 0 | Changning | @常宁市@衡阳市 + 2 | 湖南省 | 1 | Hunan | 3 | 0 | 0 | Changning | @常宁市@衡阳市@湖南省 + 1 | 中国 | 0 | China | 4 | 1 | 0 | Changning | @常宁市@衡阳市@湖南省@中国 +(4 rows) + +/* case 1.6 test leaf->root order siblings by id desc + * expect order: 18 13 2 1 + */ +EXPLAIN (costs off) +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), SYS_CONNECT_BY_PATH(name, '@') cpath +FROM test_area +START WITH name = '常宁市' +CONNECT BY id = prior fatherid +ORDER SIBLINGS BY id desc; + QUERY PLAN +------------------------------------------------------------------------------------------------------ + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_3, array_col_2, array_col_4, array_siblings + -> Sort + Sort Key: array_siblings + -> Recursive Union + -> Sort + Sort Key: swtest.test_area.id DESC + -> Seq Scan on test_area + Filter: (name = '常宁市'::text) + -> Sort + Sort Key: swtest.test_area.id DESC + -> Hash Join + Hash Cond: (swtest.test_area.id = tmp_reuslt."test_area@fatherid") + -> Seq Scan on test_area + -> Hash + -> WorkTable Scan on tmp_reuslt +(18 rows) + +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), SYS_CONNECT_BY_PATH(name, '@') cpath +FROM test_area +START WITH name = '常宁市' +CONNECT BY id = prior fatherid +ORDER SIBLINGS BY id desc; + id | name | fatherid | name_desc | level | connect_by_isleaf | connect_by_iscycle | connect_by_root | cpath +----+--------+----------+-----------+-------+-------------------+--------------------+-----------------+---------------------------- + 18 | 常宁市 | 13 | Changning | 1 | 0 | 0 | Changning | @常宁市 + 13 | 衡阳市 | 2 | Hengyang | 2 | 0 | 0 | Changning | @常宁市@衡阳市 + 2 | 湖南省 | 1 | Hunan | 3 | 0 | 0 | Changning | @常宁市@衡阳市@湖南省 + 1 | 中国 | 0 | China | 4 | 1 | 0 | Changning | @常宁市@衡阳市@湖南省@中国 +(4 rows) + +/* case 1.7 + * test order siblings by const + * expect order: 1 2 11 13 14 18 19 20 21 22 3 10 12 15 16 17 4 5 6 7 8 9 + */ +EXPLAIN (costs off) +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), SYS_CONNECT_BY_PATH(name, '@') cpath +FROM test_area +START WITH name = '中国' +CONNECT BY prior id = fatherid +ORDER SIBLINGS BY 1; + QUERY PLAN +------------------------------------------------------------------------------------------------------ + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_1, array_col_2, array_col_4, array_siblings + -> Sort + Sort Key: array_siblings + -> Recursive Union + -> Sort + Sort Key: swtest.test_area.id + -> Seq Scan on test_area + Filter: (name = '中国'::text) + -> Sort + Sort Key: swtest.test_area.id + -> Hash Join + Hash Cond: (swtest.test_area.fatherid = tmp_reuslt."test_area@id") + -> Seq Scan on test_area + -> Hash + -> WorkTable Scan on tmp_reuslt +(18 rows) + +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), SYS_CONNECT_BY_PATH(name, '@') cpath +FROM test_area +START WITH name = '中国' +CONNECT BY prior id = fatherid +ORDER SIBLINGS BY 1; + id | name | fatherid | name_desc | level | connect_by_isleaf | connect_by_iscycle | connect_by_root | cpath +----+--------+----------+-----------+-------+-------------------+--------------------+-----------------+---------------------------- + 1 | 中国 | 0 | China | 1 | 0 | 0 | China | @中国 + 2 | 湖南省 | 1 | Hunan | 2 | 0 | 0 | China | @中国@湖南省 + 11 | 长沙市 | 2 | Changsha | 3 | 1 | 0 | China | @中国@湖南省@长沙市 + 13 | 衡阳市 | 2 | Hengyang | 3 | 0 | 0 | China | @中国@湖南省@衡阳市 + 14 | 耒阳市 | 13 | Leiyang | 4 | 1 | 0 | China | @中国@湖南省@衡阳市@耒阳市 + 18 | 常宁市 | 13 | Changning | 4 | 1 | 0 | China | @中国@湖南省@衡阳市@常宁市 + 19 | 祁东县 | 13 | Qidong | 4 | 1 | 0 | China | @中国@湖南省@衡阳市@祁东县 + 20 | 祁南县 | 13 | Qinan | 4 | 1 | 0 | China | @中国@湖南省@衡阳市@祁南县 + 21 | 祁西县 | 13 | Qixi | 4 | 1 | 0 | China | @中国@湖南省@衡阳市@祁西县 + 22 | 祁北县 | 13 | Qibei | 4 | 1 | 0 | China | @中国@湖南省@衡阳市@祁北县 + 3 | 广东省 | 1 | Guangdong | 2 | 0 | 0 | China | @中国@广东省 + 10 | 深圳市 | 3 | Shenzhen | 3 | 0 | 0 | China | @中国@广东省@深圳市 + 12 | 南山区 | 10 | Nanshan | 4 | 1 | 0 | China | @中国@广东省@深圳市@南山区 + 15 | 龙岗区 | 10 | Longgang | 4 | 1 | 0 | China | @中国@广东省@深圳市@龙岗区 + 16 | 福田区 | 10 | Futian | 4 | 1 | 0 | China | @中国@广东省@深圳市@福田区 + 17 | 宝安区 | 10 | Baoan | 4 | 1 | 0 | China | @中国@广东省@深圳市@宝安区 + 4 | 海南省 | 1 | Hainan | 2 | 1 | 0 | China | @中国@海南省 + 5 | 河北省 | 1 | Hebei | 2 | 1 | 0 | China | @中国@河北省 + 6 | 河南省 | 1 | Henan | 2 | 1 | 0 | China | @中国@河南省 + 7 | 山东省 | 1 | Shandong | 2 | 1 | 0 | China | @中国@山东省 + 8 | 湖北省 | 1 | Hubei | 2 | 1 | 0 | China | @中国@湖北省 + 9 | 江苏省 | 1 | Jiangsu | 2 | 1 | 0 | China | @中国@江苏省 +(22 rows) + +/* case 1.8++ test explain for multiple order siblings column */ +EXPLAIN (costs off) +SELECT * FROM test_area +START WITH name = '中国' +CONNECT BY prior id = fatherid +ORDER SIBLINGS BY id, name, name_desc; + QUERY PLAN +-------------------------------------------------------------------------------------------------------------- + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_1, array_siblings + -> Sort + Sort Key: array_siblings + -> Recursive Union + -> Sort + Sort Key: swtest.test_area.id, swtest.test_area.name, swtest.test_area.name_desc + -> Seq Scan on test_area + Filter: (name = '中国'::text) + -> Sort + Sort Key: swtest.test_area.id, swtest.test_area.name, swtest.test_area.name_desc + -> Hash Join + Hash Cond: (swtest.test_area.fatherid = tmp_reuslt."test_area@id") + -> Seq Scan on test_area + -> Hash + -> WorkTable Scan on tmp_reuslt +(18 rows) + +EXPLAIN (costs off) +SELECT * FROM test_area +START WITH name = '中国' +CONNECT BY prior id = fatherid +ORDER SIBLINGS BY id desc, name desc , name_desc desc; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------------- + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_1, array_siblings + -> Sort + Sort Key: array_siblings + -> Recursive Union + -> Sort + Sort Key: swtest.test_area.id DESC, swtest.test_area.name DESC, swtest.test_area.name_desc DESC + -> Seq Scan on test_area + Filter: (name = '中国'::text) + -> Sort + Sort Key: swtest.test_area.id DESC, swtest.test_area.name DESC, swtest.test_area.name_desc DESC + -> Hash Join + Hash Cond: (swtest.test_area.fatherid = tmp_reuslt."test_area@id") + -> Seq Scan on test_area + -> Hash + -> WorkTable Scan on tmp_reuslt +(18 rows) + +EXPLAIN (costs off) +SELECT * FROM test_area +START WITH name = '中国' +CONNECT BY prior id = fatherid +ORDER SIBLINGS BY id desc, name, name_desc desc; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------ + CTE Scan on tmp_reuslt + CTE tmp_reuslt + -> StartWith Operator + Start With pseudo atts: RUITR, array_key_1, array_siblings + -> Sort + Sort Key: array_siblings + -> Recursive Union + -> Sort + Sort Key: swtest.test_area.id DESC, swtest.test_area.name, swtest.test_area.name_desc DESC + -> Seq Scan on test_area + Filter: (name = '中国'::text) + -> Sort + Sort Key: swtest.test_area.id DESC, swtest.test_area.name, swtest.test_area.name_desc DESC + -> Hash Join + Hash Cond: (swtest.test_area.fatherid = tmp_reuslt."test_area@id") + -> Seq Scan on test_area + -> Hash + -> WorkTable Scan on tmp_reuslt +(18 rows) + diff --git a/src/test/regress/parallel_schedule0 b/src/test/regress/parallel_schedule0 index 4e34a0080..ba8441463 100644 --- a/src/test/regress/parallel_schedule0 +++ b/src/test/regress/parallel_schedule0 @@ -22,6 +22,11 @@ test: get_instr_unique_sql # interferes with crash-recovery testing. test: single_node_tablespace +#test startwith...connect by +test: sw_prepare +test: sw_basic sw_icbc sw_siblings sw_bugfix sw_by_rownum_level +test: sw_clearup + # ---------- # The first group of parallel tests # ---------- diff --git a/src/test/regress/sql/sw_basic.sql b/src/test/regress/sql/sw_basic.sql new file mode 100644 index 000000000..2b5d67771 --- /dev/null +++ b/src/test/regress/sql/sw_basic.sql @@ -0,0 +1,182 @@ +set client_min_messages = error; +set search_path=swtest; +SET CLIENT_ENCODING='UTF8'; + +/* + * + * START WITH .... CONNECT BY基础测试用例 + * + * 测试用例表数 + * openGauss=# select * from swtest.test_area; + * id | name | fatherid | name_desc + * ----+--------+----------+----------- + * 1 | 中国 | 0 | china + * 2 | 湖南省 | 1 | hunan + * 3 | 广东省 | 1 | guangdong + * 4 | 海南省 | 1 | hainan + * 5 | 河北省 | 1 | hebei + * 6 | 河南省 | 1 | henan + * 7 | 山东省 | 1 | shandong + * 8 | 湖北省 | 1 | hubei + * 9 | 江苏省 | 1 | jiangsu + * 10 | 深圳市 | 3 | shenzhen + * 11 | 长沙市 | 2 | changsha + * 22 | 祁北县 | 13 | qibei + * 12 | 南山区 | 10 | nanshan + * 21 | 祁西县 | 13 | qixi + * 13 | 衡阳市 | 2 | hengyang + * 14 | 耒阳市 | 13 | leiyang + * 15 | 龙岗区 | 10 | longgang + * 16 | 福田区 | 10 | futian + * 17 | 宝安区 | 10 | baoan + * 19 | 祁东县 | 13 | qidong + * 18 | 常宁市 | 13 | changning + * 20 | 祁南县 | 13 | qinan + * + */ + +-- 一、基础语法测试 +/* + * 用例1.1,基础用例包含所有伪列,leaf节点方向遍历查找 + **/ +EXPLAIN (COSTS OFF) +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), sys_connect_by_path(name_desc, '@') +FROM test_area +START WITH name = '中国' +CONNECT BY PRIOR id = fatherid; + +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), sys_connect_by_path(name_desc, '@') +FROM test_area +START WITH name = '中国' +CONNECT BY PRIOR id = fatherid; + +/* + * 用例1.2,基础用例包含所有伪列,root节点方向遍历查找 + **/ +EXPLAIN (COSTS OFF) +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), sys_connect_by_path(name_desc, '@') +FROM test_area +START WITH name = '耒阳市' +CONNECT BY id = PRIOR fatherid; + +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), sys_connect_by_path(name_desc, '@') +FROM test_area +START WITH name = '耒阳市' +CONNECT BY id = PRIOR fatherid; + +/* + * 用例1.3,基础用例包含所有伪列,root节点方向遍历查找(两条链) + **/ +EXPLAIN (COSTS OFF) +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), sys_connect_by_path(name_desc, '@') +FROM test_area +START WITH name = '耒阳市' OR name = '宝安区' +CONNECT BY id = PRIOR fatherid; + +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), sys_connect_by_path(name_desc, '@') +FROM test_area +START WITH name = '耒阳市' OR name = '宝安区' +CONNECT BY id = PRIOR fatherid; + +/* + * 用例1.5,基础用例包含所有伪列,测试多字符串拼接 + **/ +EXPLAIN (COSTS OFF) +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), sys_connect_by_path(name_desc, '=>>') +FROM test_area +START WITH name = '中国' +CONNECT BY PRIOR id = fatherid; + +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), sys_connect_by_path(name_desc, '=>>') +FROM test_area +START WITH name = '中国' +CONNECT BY PRIOR id = fatherid; + +/* + * 用例1.6,基础用例包含所有伪列, 包含多字符拼接,多条查找链,startwith使用LIKE查找 + **/ +EXPLAIN (COSTS OFF) +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), sys_connect_by_path(name_desc, '-*>') +FROM test_area +START WITH name like '%区' +CONNECT BY id = PRIOR fatherid; + +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), sys_connect_by_path(name_desc, '-*>') +FROM test_area +START WITH name like '%区' +CONNECT BY id = PRIOR fatherid; + +-- 二、扩展测试 +/* + * 用例2.1,基础用例包含所有伪列, 包含多字符拼接,多条查找链,startwith使用IN子查询进行查找 + **/ +EXPLAIN (COSTS OFF) +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), sys_connect_by_path(name_desc, '/') +FROM test_area +START WITH name IN (select name from test_area where id < 3) +CONNECT BY PRIOR id = fatherid; + +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), sys_connect_by_path(name_desc, '/') +FROM test_area +START WITH name IN (select name from test_area where id < 3) +CONNECT BY PRIOR id = fatherid; + +/* + * 用例2.2,基础用例包含所有伪列, 包含多字符拼接,多条查找链,startwith使用IN子查询进行查找,结果集进行伪列过滤 + **/ +EXPLAIN (COSTS OFF) +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), sys_connect_by_path(name_desc, '/') +FROM test_area +WHERE LEVEL > 2 +START WITH name IN (select name from test_area where id < 3) +CONNECT BY PRIOR id = fatherid; + +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), sys_connect_by_path(name_desc, '/') +FROM test_area +WHERE LEVEL > 2 +START WITH name IN (select name from test_area where id < 3) +CONNECT BY PRIOR id = fatherid; + +/* + * 用例2.3,基础用例包含所有伪列, 包含多字符拼接,多条查找链,startwith使用IN子查询进行查找,结果集进行多个伪列过滤 + **/ +EXPLAIN (COSTS OFF) +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), sys_connect_by_path(name_desc, '/') +FROM test_area +WHERE LEVEL > 2 AND connect_by_iscycle IS NOT NULL +START WITH name IN (select name from test_area where id < 3) +CONNECT BY PRIOR id = fatherid; + +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), sys_connect_by_path(name_desc, '/') +FROM test_area +WHERE LEVEL > 2 AND connect_by_iscycle IS NOT NULL +START WITH name IN (select name from test_area where id < 3) +CONNECT BY PRIOR id = fatherid; + +-- 三、 打开guc enable_startwith_debug = on测试 +/* DFX test, verify if */ +set enable_startwith_debug=on; +set client_min_messages=log; + +explain (costs off) +select *, LEVEL, CONNECT_BY_ROOT(name_desc), SYS_CONNECT_BY_PATH(name, '/') cpath from test_area +START WITH name = '耒阳市' +CONNECT BY id = PRIOR fatherid; + +select *, LEVEL, CONNECT_BY_ROOT(name_desc), SYS_CONNECT_BY_PATH(name, '/') cpath from test_area +START WITH name = '耒阳市' +CONNECT BY id = PRIOR fatherid; + +explain (costs off) +select *, LEVEL, CONNECT_BY_ROOT(name_desc), SYS_CONNECT_BY_PATH(name, '/') cpath from test_area +START WITH name = '中国' +CONNECT BY prior id = fatherid +order siblings by id; + +select *, LEVEL, CONNECT_BY_ROOT(name_desc), SYS_CONNECT_BY_PATH(name, '/') cpath from test_area +START WITH name = '中国' +CONNECT BY prior id = fatherid +order siblings by id; + +reset enable_startwith_debug; +reset client_min_messages; diff --git a/src/test/regress/sql/sw_bugfix.sql b/src/test/regress/sql/sw_bugfix.sql new file mode 100644 index 000000000..ddb887896 --- /dev/null +++ b/src/test/regress/sql/sw_bugfix.sql @@ -0,0 +1,844 @@ +set client_min_messages = error; +SET CLIENT_ENCODING='UTF8'; +set current_schema=swtest; + +/* invalid data type */ +SELECT NAME,LEVEL,CONNECT_BY_ISLEAF,SYS_CONNECT_BY_PATH(NAME,'|'),CONNECT_BY_ROOT(NAME),ID,CHA,VCH,TEX,DAT,TIM,TIS,PID,PCHA,PVCH,PTEX,PDAT,PTIM,PTIS +FROM TEST_HCB_FQB +START WITH ID=1 +CONNECT BY prior ID=PID +ORDER SIBLINGS BY NAME ASC; + +-- invalid use connect_by_root, will treate it as regular column report column does not exists error +SELECT NAME,LEVEL,CONNECT_BY_ISLEAF,SYS_CONNECT_BY_PATH(NAME,'|'),CONNECT_BY_ROOT +FROM test_hcb_ptb +START WITH (ID=169 or ID=168) and CHA in ('afi','afg','afh') +CONNECT BY ID=PRIOR PID and CHA=PRIOR PCHA and VCH=PRIOR PVCH and DAT=PRIOR PDAT and TIM=PRIOR PTIM AND TIS=PRIOR PTIS +order by 1; + +SELECT NAME,LEVEL,CONNECT_BY_ISLEAF,SYS_CONNECT_BY_PATH(NAME,'|'),CONNECT_BY_ROOT name +FROM test_hcb_ptb +START WITH (ID=169 or ID=168) and CHA in ('afi','afg','afh') +CONNECT BY ID=PRIOR PID and CHA=PRIOR PCHA and VCH=PRIOR PVCH and DAT=PRIOR PDAT and TIM=PRIOR PTIM AND TIS=PRIOR PTIS +order by 1; + +SELECT NAME,LEVEL,CONNECT_BY_ISLEAF,SYS_CONNECT_BY_PATH(NAME,'|'),CONNECT_BY_ROOT(name) +FROM test_hcb_ptb +START WITH (ID=169 or ID=168) and CHA in ('afi','afg','afh') +CONNECT BY ID=PRIOR PID and CHA=PRIOR PCHA and VCH=PRIOR PVCH and DAT=PRIOR PDAT and TIM=PRIOR PTIM AND TIS=PRIOR PTIS +order by 1; + +/* Unsupported StartWith Scenarios */ +explain(costs off) +select * from test_hcb_ptbc t1 start with t1.id = 11 connect by prior t1.id = t1.pid; +select * from test_hcb_ptbc t1 start with t1.id = 11 connect by prior t1.id = t1.pid; +SELECT t1.id,t1.pid,t1.name,level FROM test_hcb_ptb t1,test_hcb_ptb t2 WHERE t1.id=t2.id START WITH t1.id=141 CONNECT BY PRIOR t1.id=t1.pid FOR UPDATE OF t2 NOWAIT; +SELECT t1.id, t1.pid,t1.name,level FROM core_066 t1 START WITH id = 117 CONNECT BY PRIOR id=pid FOR UPDATE; + +/* connect by root scenarios */ +select pid x,id,CONNECT_BY_ROOT ID from test_hcb_ptbc t1 start with id = 11 connect by prior id = pid; +select pid x,id,CONNECT_BY_ROOT ID alias_id from test_hcb_ptbc t1 start with id = 11 connect by prior id = pid; +select pid x,id,CONNECT_BY_ROOT t1.ID from test_hcb_ptbc t1 start with id = 11 connect by prior id = pid; +select pid x,id,CONNECT_BY_ROOT t1.ID alias_id from test_hcb_ptbc t1 start with id = 11 connect by prior id = pid; + +/* infinite loop issues */ +SELECT LEVEL,NAME,CONNECT_BY_ISLEAF,SYS_CONNECT_BY_PATH(NAME, '/'),CONNECT_BY_ROOT(ID) +FROM test_swcb_a +START WITH ID='00118' +CONNECT BY PRIOR ID=PID +ORDER SIBLINGS BY NAME; + +/* fromlist startwith for single table */ +select t1.ID,t1.VCH,pid,NAME,PTEX from TEST_HCB_FQB t1,TEST_SUBLINK t2 where t1.id=t2.id start with t1.id=1 CONNECT BY PRIOR t1.id = t1.pid; +explain (costs off) select t1.ID,t1.VCH,pid,NAME,PTEX from TEST_HCB_FQB t1,TEST_SUBLINK t2 where t1.id=t2.id start with t1.id=1 CONNECT BY PRIOR t1.id = t1.pid; + +/* swcb中参数为proceder参数 */ +CREATE OR REPLACE FUNCTION test_hcb_pro1(i_id in int) return int +AS +o_out int; +BEGIN +select count(*) into o_out from TEST_HCB_FQB t1 START WITH t1.id = i_id +CONNECT BY PRIOR t1.id = t1.pid; +return o_out; +END; +/ + +select test_hcb_pro1(11); +drop PROCEDURE test_hcb_pro1; + +/* startwith dealing with subqueries */ +select tt.id,tt.name from (select t1.ID,t1.VCH,pid,NAME,PTEX from TEST_HCB_FQB t1,TEST_SUBLINK t2 where t1.id=t2.id) tt +start with tt.id=1 CONNECT BY PRIOR tt.id = tt.pid ; + + +explain (costs off) select tt.id,tt.name from (select t1.ID,t1.VCH,pid,NAME,PTEX from TEST_HCB_FQB t1,TEST_SUBLINK t2 where t1.id=t2.id) tt +start with tt.id=1 CONNECT BY PRIOR tt.id = tt.pid ; + +select test.id,test.pid,test.name +from +(select t1.id id, t1.pid pid, t1.name name from TEST_HCB_FQB t1 + union + select t2.id id, t2.pid pid, t2.name name from TEST_HCB_FQB t2) test +start with test.id = 12 +connect by prior test.id = test.pid; + +/* startwith dealing with subqueries without alias */ +SELECT NAME,LEVEL,CONNECT_BY_ISLEAF,CONNECT_BY_ROOT(NAME),SYS_CONNECT_BY_PATH(NAME, '/') +FROM (SELECT * FROM test_hcb_ptb) +START WITH CHA IN ('afi','afg','afh') +CONNECT BY PRIOR ID=PID +ORDER SIBLINGS BY NAME; + +SELECT NAME,LEVEL,CONNECT_BY_ISLEAF,CONNECT_BY_ROOT(NAME),SYS_CONNECT_BY_PATH(NAME, '/') +FROM (SELECT * FROM test_hcb_ptb) +START WITH CHA IN ('afi','afg','afh') +CONNECT BY PRIOR ID=PID +ORDER SIBLINGS BY 1; + +SELECT NAME,LEVEL,CONNECT_BY_ISLEAF,CONNECT_BY_ROOT(NAME),SYS_CONNECT_BY_PATH(NAME, '/') +FROM (SELECT * FROM test_hcb_ptb) +START WITH CHA IN ('afi','afg','afh') +CONNECT BY PRIOR ID=PID +ORDER SIBLINGS BY 999; + +SELECT NAME,LEVEL,CONNECT_BY_ISLEAF,CONNECT_BY_ROOT(NAME),SYS_CONNECT_BY_PATH(NAME, '/') +FROM (SELECT * FROM test_hcb_ptb) +START WITH CHA IN ('afi','afg','afh') +CONNECT BY PRIOR ID=PID +ORDER SIBLINGS BY 1, LEVEL; + +SELECT NAME,LEVEL,CONNECT_BY_ISLEAF,CONNECT_BY_ROOT(NAME),SYS_CONNECT_BY_PATH(NAME, '/') +FROM (SELECT * FROM test_hcb_ptb) +START WITH CHA IN ('afi','afg','afh') +CONNECT BY PRIOR ID=PID +ORDER SIBLINGS BY 1, HUAWEI; + +/* check siblings ordering */ +SELECT NAME,LEVEL,CONNECT_BY_ISLEAF,SYS_CONNECT_BY_PATH(NAME,'|'),CONNECT_BY_ROOT(NAME) +FROM test_hcb_ptb +START WITH (ID=168 or ID=169) +CONNECT BY ID = PRIOR PID +ORDER SIBLINGS BY NAME ASC; + +-- connect_by_root/sys_connect_by_path() unsupported cases +explain +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root name_desc, sys_connect_by_path(level, '@') +FROM test_area +START WITH name = '中国' +CONNECT BY PRIOR id = fatherid; + +-- sys_connect_by_path() only supports char type +explain +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root name_desc, sys_connect_by_path(id, '@') +FROM test_area +START WITH name = '中国' +CONNECT BY PRIOR id = fatherid; + +/* sys_connect_by_path & connect_by_root can support char(xx) */ +SELECT name,LEVEL,connect_by_root(CHA) +FROM test_hcb_fqb +START WITH ID = 1 +CONNECT BY PRIOR CHA = PCHA +ORDER BY ID ASC; + +SELECT name,level,connect_by_root t1.cha as cha_col +FROM test_hcb_fqb t1 +START WITH id = 1 +CONNECT BY PRIOR cha = pcha +ORDER BY id ASC; + +SELECT name,LEVEL,sys_connect_by_path(CHA, '==》') +FROM test_hcb_fqb +START WITH ID = 1 +CONNECT BY PRIOR CHA = PCHA +ORDER BY ID ASC; + +/* empty delimiter in sys_connect_by_path(VCH,'') should be rejected */ +SELECT name,LEVEL,sys_connect_by_path(VCH,'') +FROM test_hcb_ptb +START WITH ID = 1 +CONNECT BY PRIOR CHA = PCHA +ORDER BY ID ASC; + +/* start with null must not cause core-dump error */ +SELECT * +FROM test_hcb_ptb +START WITH NULL +CONNECT BY PRIOR CHA = PCHA +ORDER BY ID ASC; + +/* start with pbe */ +PREPARE sthpt(int) AS SELECT t1.id,t1.pid,t1.name FROM test_hcb_ptb t1 START WITH id = $1 CONNECT BY PRIOR pid=id; +EXECUTE sthpt(141); + +/* with-clause used in startwith rewrite */ +explain (costs off) with subquery (id,pid,name) as +( +select t1.id,t1.pid,t1.name, LEVEL from test_hcb_ptb t1 where level>=1 + start with id = 141 connect by prior pid=id +) +select t1.id,t1.pid,t1.name,LEVEL from subquery t1 +start with id = 141 connect by prior pid=id; + +explain (costs off) select t1.id,t1.pid,t1.name,LEVEL +from (select t2.id,t2.pid,t2.name,LEVEL from test_hcb_ptb t2 where level>=1 start with t2.id = 141 connect by prior pid=id) t1 +where level>=1 start with id = 141 connect by prior pid=id; + +/* core issue */ +explain select sysdate from test_hcb_ptb t1 start with id = 141 connect by prior pid=id; +select count(sysdate) from test_hcb_ptb t1 start with id = 141 connect by prior pid=id; + +/* core issue sys_connect_by_path(cosnt) core issue */ +select t1.id,t1.pid,LEVEL,sys_connect_by_path(null, '->') pa, t1.name from test_hcb_ptb t1 start with id = 141 connect by prior id = pid; +select t1.id,t1.pid,LEVEL,sys_connect_by_path('id', '->') pa, t1.name from test_hcb_ptb t1 start with id = 141 connect by prior id = pid; +select t1.id,t1.pid,LEVEL,sys_connect_by_path(' ', '->') pa, t1.name from test_hcb_ptb t1 start with id = 141 connect by prior id = pid; + +/* core issue, check args */ +explain select t1.id,t1.pid,t1.name,level from test_hcb_ptb t1 start with id=141 connect by prior id=pid Order By NLSSORT ( id, ' NLS_SORT = SCHINESE_PINYIN_M ' ); +select t1.id,t1.pid,t1.name,level from test_hcb_ptb t1 start with id=141 connect by prior id=pid Order By NLSSORT ( id, ' NLS_SORT = SCHINESE_PINYIN_M ' ); + +/* core issue, check args */ +drop table if exists region cascade; +create table region +( + region_cd varchar(50) primary key , + REGION_MGR_ASSOCIATE_ID number(18,9), + c1 serial +); + +select region_mgr_associate_id from region; + +drop table if exists item_price_history cascade; +create table item_price_history +( + ITEM_ID number(39,10) primary key , + LOCATION_ID number(2,0) NULL,c1 serial +); + + +SELECT (MIN(region_cd)) Column_001, length(CAST('B' AS bytea), 'UTF8') Column_002 +FROM region , item_price_history +WHERE REGION_MGR_ASSOCIATE_ID = ITEM_ID +START WITH REGION_MGR_ASSOCIATE_ID NOT LIKE '_W_' +CONNECT BY PRIOR LOCATION_ID = REGION_MGR_ASSOCIATE_ID +GROUP BY 2; + +drop table item_price_history; +drop table region; + +/* */ +create table test1(id int,pid int,name text, level int); +create table test2(id int,pid int,name text, connect_by_iscycle int); +create table test3(id int,pid int,name text, connect_by_isleaf int); +create table test4(id int,pid int,name text, c4 int); + +insert into test1 select id,pid,name,id%10 from test_hcb_ptb; +insert into test2 select id,pid,name,id%10 from test_hcb_ptb; +insert into test3 select id,pid,name,id%10 from test_hcb_ptb; +insert into test4 select id,pid,name,id%10 from test_hcb_ptb; + +/* level/connect_by_iscycle/connect_by_isleaf is for connect by's level value */ +select id,pid,name,test1.level, level from test1 start with id = 141 connect by prior pid=id; +select id,pid,name,test2.connect_by_iscycle, connect_by_iscycle from test2 start with id = 141 connect by prior pid=id; +select id,pid,name,test3.connect_by_isleaf, connect_by_isleaf from test3 start with id = 141 connect by prior pid=id; + +drop table test1; +drop table test2; +drop table test3; +drop table test4; + +/* */ +/* 查询1 */ +SELECT TRAIT_VALUE_CD +FROM trait_value +START WITH TRAIT_VALUE_CD=TRAIT_VALUE_CD +CONNECT BY PRIOR UOM_CD LIKE '_E_'; + + +create table region +( + region_cd varchar(50) primary key , + REGION_MGR_ASSOCIATE_ID number(18,9),c1 serial +); + +create table item_price_history +( + ITEM_ID number(39,10) primary key , + LOCATION_ID number(2,0) NULL,c1 serial +); + +INSERT INTO REGION VALUES ('A', 0.123433); +INSERT INTO REGION VALUES ('B', NULL); +INSERT INTO REGION VALUES ('C', 2.232008908); +INSERT INTO REGION VALUES ('D', 3.878789); +INSERT INTO REGION VALUES ('E', 4.89060603); +INSERT INTO REGION VALUES ('F', 5.82703827); +INSERT INTO REGION VALUES ('G', NULL); +INSERT INTO REGION VALUES ('H', 7.3829083); + +INSERT INTO ITEM_PRICE_HISTORY VALUES (0.12, 4); +INSERT INTO ITEM_PRICE_HISTORY VALUES (1.3, 1); +INSERT INTO ITEM_PRICE_HISTORY VALUES (2.23, NULL); +INSERT INTO ITEM_PRICE_HISTORY VALUES (3.33, 3); +INSERT INTO ITEM_PRICE_HISTORY VALUES (4.98, 4); +INSERT INTO ITEM_PRICE_HISTORY VALUES (5.01, 5); +INSERT INTO ITEM_PRICE_HISTORY VALUES (6, 6); +INSERT INTO ITEM_PRICE_HISTORY VALUES (0.7, 7); +INSERT INTO ITEM_PRICE_HISTORY VALUES (0.08, 8); +INSERT INTO ITEM_PRICE_HISTORY VALUES (9.12, 9); + +/* 查询2 */ +SELECT 1 +FROM region , item_price_history +WHERE REGION_MGR_ASSOCIATE_ID = ITEM_ID +START WITH REGION_MGR_ASSOCIATE_ID NOT LIKE '_W_' +CONNECT BY PRIOR LOCATION_ID = REGION_MGR_ASSOCIATE_ID; + +drop table region; +drop table item_price_history; + +/* */ +create table test1(c1 int, c2 int, c3 int); +insert into test1 values(1,1,1); +insert into test1 values(2,2,2); + +-- encountered with 200 iteration limit +select * from test1 t1 start with c1=1 connect by prior c2<>c3; +-- will return result when cycle is met +select * from test1 t1 start with c1=1 connect by NOCYCLE prior c2<>c3; + +drop table test1; + +-- error out a case when NOCYCLE is not specify and use connect_by_iscycle +select t1.id, LEVEL, connect_by_iscycle from test_hcb_ptb t1 start with id = 1 connect by prior id = pid; + + +create table mag_area +( + area_code varchar(10), + area_name varchar(120), + area_short_name varchar(120), + local_name varchar(80), + belong_area_code varchar(10), + bank_level varchar(8), + contry_code varchar(5), + part_code varchar(5), + time_zone varchar(9), + bank_code varchar(10), + group_code varchar(5), + mag_area_grade varchar(3), + mag_area_status varchar(1), + mag_area_broad varchar(1) +); + +create table mag_image_tpl +( + seq varchar(20), + area_code varchar(10), + archive_type varchar(3), + busitype varchar(8), + image_type varchar(8), + app_type varchar(10), + rule_id varchar(10), + valid_flag varchar(1), + modify_branch varchar(10), + modify_user varchar(9), + modify_time varchar(14) +); + + +explain +select a.rule_id, b.mag_area_grade, + max(b.mag_area_grade) OVER (PARTITION BY archive_type, busitype,image_type,app_type) max_level +FROM mag_image_tpl a, mag_area b +WHERE a.AREA_CODE IN ( + SELECT area_code + FROM mag_area + START WITH area_code = '1' + CONNECT BY PRIOR belong_area_code = area_code +) +AND a.archive_type = 'A' +AND a.BUSITYPE = 'B' +AND a.area_code = b.area_code; + + +select a.rule_id, b.mag_area_grade, + max(b.mag_area_grade) OVER (PARTITION BY archive_type, busitype,image_type,app_type) max_level +FROM mag_image_tpl a, mag_area b +WHERE a.AREA_CODE IN ( + SELECT area_code + FROM mag_area + START WITH area_code = '1' + CONNECT BY PRIOR belong_area_code = area_code +) +AND a.archive_type = 'A' +AND a.BUSITYPE = 'B' +AND a.area_code = b.area_code; + +drop table mag_area; +drop table mag_image_tpl; + +SELECT id, sys_connect_by_path(name_desc, '@') || id +FROM test_area +START WITH name = '耒阳市' +CONNECT BY id = PRIOR fatherid; + +explain +SELECT table_name || NVL('test','_B$') AS table_name + FROM (SELECT TRIM(SUBSTR(txt, + INSTR(txt, ',', 1, LEVEL) + 1, + INSTR(txt, ',', 1, LEVEL + 1) - + INSTR(txt, ',', 1, LEVEL) - 1)) AS table_name + FROM (SELECT ',' || REPLACE('test' , ' ', '') || ',' txt FROM sys_dummy) + CONNECT BY LEVEL <= LENGTH(REPLACE('test', ' ', '')) - LENGTH(REPLACE(REPLACE('test', ' ', ''), ',', '')) + 1); + +SELECT table_name || NVL('test','_B$') AS table_name + FROM (SELECT TRIM(SUBSTR(txt, + INSTR(txt, ',', 1, LEVEL) + 1, + INSTR(txt, ',', 1, LEVEL + 1) - + INSTR(txt, ',', 1, LEVEL) - 1)) AS table_name + FROM (SELECT ',' || REPLACE('test' , ' ', '') || ',' txt FROM sys_dummy) + CONNECT BY LEVEL <= LENGTH(REPLACE('test', ' ', '')) - LENGTH(REPLACE(REPLACE('test', ' ', ''), ',', '')) + 1); + +-- fix infinite recursive +explain select * from t1 start with id = 1 connect by prior id != pid; + +create table tsc_rtbl(c_int int,c_varchar1 varchar,c_varchar2 varchar); +alter table tsc_rtbl drop column c_varchar2; +alter table tsc_rtbl add column c_varchar2 varchar; + +select c_int,c_varchar1,c_varchar2 from tsc_rtbl +start with c_int<10 connect by nocycle prior c_int=c_int; + +create table t1_area (id int4,name text, fatherid int4, name_desc text); +insert into t1_area values (1, '中国', 0, 'China'); +insert into t1_area values (2, '湖南省',1 , 'Hunan'); +insert into t1_area values (3, '广东省',1 , 'Guangdong'); +insert into t1_area values (4, '海南省',1 , 'Hainan'); +insert into t1_area values (5, '河北省',1 , 'Hebei'); +insert into t1_area values (6, '河南省',1 , 'Henan'); +insert into t1_area values (7, '山东省',1 , 'Shandong'); +insert into t1_area values (8, '湖北省',1 , 'Hubei'); +insert into t1_area values (9, '江苏省',1 , 'Jiangsu'); +insert into t1_area values (10,'深圳市',3 , 'Shenzhen'); +insert into t1_area values (11,'长沙市',2 , 'Changsha'); +insert into t1_area values (22,'祁北县',13, 'Qibei'); +insert into t1_area values (12,'南山区',10, 'Nanshan'); +insert into t1_area values (21,'祁西县',13, 'Qixi'); +insert into t1_area values (13,'衡阳市',2 , 'Hengyang'); +insert into t1_area values (14,'耒阳市',13, 'Leiyang'); +insert into t1_area values (15,'龙岗区',10, 'Longgang'); +insert into t1_area values (16,'福田区',10, 'Futian'); +insert into t1_area values (17,'宝安区',10, 'Baoan'); +insert into t1_area values (19,'祁东县',13, 'Qidong'); +insert into t1_area values (18,'常宁市',13, 'Changning'); +insert into t1_area values (20,'祁南县',13, 'Qinan'); + +SELECT *, connect_by_root(name_desc), sys_connect_by_path(name_desc, '->') +FROM t1_area +START WITH name = '耒阳市' +CONNECT BY id = PRIOR fatherid; + +--创建drop column并加回场景 +alter table t1_area drop column name_desc; +alter table t1_area add column name_desc text; + +-- 原有备drop列为空 +SELECT *, connect_by_root(name_desc), sys_connect_by_path(name_desc, '->') +FROM t1_area +START WITH name = '耒阳市' +CONNECT BY id = PRIOR fatherid; + +-- 新插入相同数据,原有drop列后的空值和当前有效值并存 +insert into t1_area values (1, '中国', 0, 'China'); +insert into t1_area values (2, '湖南省',1 , 'Hunan'); +insert into t1_area values (3, '广东省',1 , 'Guangdong'); +insert into t1_area values (4, '海南省',1 , 'Hainan'); +insert into t1_area values (5, '河北省',1 , 'Hebei'); +insert into t1_area values (6, '河南省',1 , 'Henan'); +insert into t1_area values (7, '山东省',1 , 'Shandong'); +insert into t1_area values (8, '湖北省',1 , 'Hubei'); +insert into t1_area values (9, '江苏省',1 , 'Jiangsu'); +insert into t1_area values (10,'深圳市',3 , 'Shenzhen'); +insert into t1_area values (11,'长沙市',2 , 'Changsha'); +insert into t1_area values (22,'祁北县',13, 'Qibei'); +insert into t1_area values (12,'南山区',10, 'Nanshan'); +insert into t1_area values (21,'祁西县',13, 'Qixi'); +insert into t1_area values (13,'衡阳市',2 , 'Hengyang'); +insert into t1_area values (14,'耒阳市',13, 'Leiyang'); +insert into t1_area values (15,'龙岗区',10, 'Longgang'); +insert into t1_area values (16,'福田区',10, 'Futian'); +insert into t1_area values (17,'宝安区',10, 'Baoan'); +insert into t1_area values (19,'祁东县',13, 'Qidong'); +insert into t1_area values (18,'常宁市',13, 'Changning'); +insert into t1_area values (20,'祁南县',13, 'Qinan'); + +SELECT *, connect_by_root(name_desc), sys_connect_by_path(name_desc, '->') +FROM t1_area +START WITH name = '耒阳市' +CONNECT BY id = PRIOR fatherid; + +SELECT * FROM t1_area START WITH id in ('1','2') CONNECT BY PRIOR fatherid = id; + +SELECT * FROM t1_area START WITH (cast(id as varchar) COLLATE "C") in (cast(+ (id) as varchar) COLLATE "C") and id < 4 connect by id = prior fatherid; + +SELECT * FROM t1_area, tsc_rtbl START WITH id = 1 CONNECT BY PRIOR fatherid = id; + +SELECT *, connect_by_root(name_desc), sys_connect_by_path(name_desc, '->') +FROM t1_area; + +/* fix start with in with clause */ +explain (costs off) WITH WITH_001 AS (SELECT 1 FROM offers_20050701 ,trait_value START WITH PARTY_ID=TRAIT_VAL CONNECT BY PRIOR TRAIT_VALUE_CD LIKE '%V%') +SELECT mfg +FROM brand ,trait_value ,WITH_001 +START WITH TRAIT_VALUE_CD=brand_name +CONNECT BY PRIOR brand_cd=UOM_CD; + +WITH WITH_001 AS (SELECT 1 FROM offers_20050701 ,trait_value START WITH PARTY_ID=TRAIT_VAL CONNECT BY PRIOR TRAIT_VALUE_CD LIKE '%V%') +SELECT mfg +FROM brand ,trait_value ,WITH_001 +START WITH TRAIT_VALUE_CD=brand_name +CONNECT BY PRIOR brand_cd=UOM_CD; + +/* fix reference to level in connect by function calls */ +SELECT 1, level FROM t1_area CONNECT BY length(level) IS NULL; + +/* prior params of procedure */ +create or replace function test_tmp1(out id int,out pid int,out name varchar,out level int) return SETOF RECORD +IS +declare +CURSOR C1(sedid int) IS select t1.id,t1.pid,t1.name,level from test_hcb_ptb t1 start with id = sedid connect by prior pid=id; +begin +open C1(141); +loop +fetch C1 into id,pid,name,level; +EXIT WHEN C1%NOTFOUND; +return next; +end loop; +close C1; +end; +/ +select * from test_tmp1(); +drop procedure test_tmp1; + +drop table t1_area; +drop table tsc_rtbl; + +-- 原问题单场景,connect_by_root(1)出现在在表达式中报错 +explain +select t1.id,t1.pid,t1.name,LEVEL le,connect_by_root(1), connect_by_root(id) +from test_hcb_ptb t1 +where connect_by_root(1) > 0 +start with id = 141 +connect by prior pid=id; + +select t1.id,t1.pid,t1.name,LEVEL le,connect_by_root(1), connect_by_root(id) +from test_hcb_ptb t1 +where connect_by_root(1) > 0 +start with id = 141 +connect by prior pid=id; + +-- 扩展场景, connect_by_root(id)报错找不到列 +explain +select t1.id,t1.pid,t1.name,LEVEL le,connect_by_root(1), connect_by_root(id) +from test_hcb_ptb t1 +where connect_by_root(id) > 0 +start with id = 141 +connect by prior pid=id; + +select t1.id,t1.pid,t1.name,LEVEL le,connect_by_root(1), connect_by_root(id) +from test_hcb_ptb t1 +where connect_by_root(id) > 0 +start with id = 141 +connect by prior pid=id; + + +-- 扩展场景,sys_connect_by_path(123, '-') is not null +explain +select t1.id,t1.pid,t1.name,LEVEL le,connect_by_root(1), connect_by_root(id), sys_connect_by_path(123, '-') +from test_hcb_ptb t1 +where sys_connect_by_path(123, '-') is not null +start with id = 141 +connect by prior pid=id; + +create table ctI as select t1.id,t1.pid,t1.name,level as le from test_hcb_ptb t1 start with id=141 connect by prior id=pid; + +create table ctII as select t1.id,t1.pid,t1.name,level from test_hcb_ptb t1 start with id=141 connect by prior id=pid; + +\d ctI; + +\d ctII; + +drop table ctI; + +drop table ctII; + +/* + * NOTE: need do upgrade change to have syc_conenct_by_path()/connect_by_root() to be volatile + */ +/* +select t1.id,t1.pid,t1.name,LEVEL le,connect_by_root(1), connect_by_root(id), sys_connect_by_path(123, '-') +from test_hcb_ptb t1 +where sys_connect_by_path(123, '-') is not null +start with id = 141 +connect by prior pid=id; +*/ + +-- 扩展场景,sys_connect_by_path(123, '-') 验证能够被正确匹配 +explain +select t1.id,t1.pid,t1.name,LEVEL le,connect_by_root(1), connect_by_root(id), sys_connect_by_path(123, '-') +from test_hcb_ptb t1 +where sys_connect_by_path(123, '-') like '-123-123-123%' +start with id = 141 +connect by prior pid=id; + +/* + * NOTE: need do upgrade change to have syc_conenct_by_path()/connect_by_root() to be volatile + */ +/* +select t1.id,t1.pid,t1.name,LEVEL le,connect_by_root(1), connect_by_root(id), sys_connect_by_path(123, '-') +from test_hcb_ptb t1 +where sys_connect_by_path(123, '-') like '-123-123-123%' +start with id = 141 +connect by prior pid=id; +*/ + +/* testing distinct qualifier */ +select distinct id,pid,name,LEVEL from t1 start with id = 1 connect by prior pid=id order by 1; + +/* testing NOT expression */ +select t1.id, t1.pid, t1.name from t1 start with not id=1 connect by prior pid=id; + +/* testing func expr in connect by clause */ +explain select trim(t1.name) from test_hcb_ptb t1 connect by trim(t1.name) is not null; + +/* fix create table as with start with */ +create table ct as select t1.id,t1.pid,t1.name,level from test_hcb_ptb t1 start with id=141 connect by prior id=pid; +drop table ct; + +set current_schema = public; +create table t1(c1 int,c2 int,c3 int); +insert into t1 values(1,1,1); +insert into t1 values(2,2,2); +select *, connect_by_iscycle from t1 start with c1=1 connect by nocycle prior c1=c2 order siblings by 1,2; + +insert into t1 values(1,1,1); +insert into t1 values(2,2,2); +select *, connect_by_iscycle from t1 start with c1=1 connect by nocycle prior c1=c2 order siblings by 1,2; + +insert into t1 values(1,NULL,1); +select *, connect_by_iscycle from t1 start with c1=1 connect by nocycle prior c1=c2 order siblings by 1,2 nulls first; +select *, connect_by_iscycle from t1 start with c1=1 connect by nocycle prior c1=c2 order siblings by 1,2 nulls last; +delete from t1 where c2 is null; + +select *, connect_by_iscycle from t1 start with c1<3 connect by nocycle prior c110 and 1=0; +select t1.id,t1.pid,t1.name from test_hcb_ptb t1 start with id=141 connect by (prior pid)=id and prior pid>10 and 1=0; + +explain select t1.id,t1.pid,t1.name from test_hcb_ptb t1 start with id=141 connect by (prior pid)=id and prior pid>10 and null; +select t1.id,t1.pid,t1.name from test_hcb_ptb t1 start with id=141 connect by (prior pid)=id and prior pid>10 and null; + +/* connect by level/rownum 不支持not并且in 数据不准确 */ +create table core_060(id varchar); +insert into core_060 values ('a'),('b'),('c'); + +SELECT id,level FROM core_060 CONNECT BY level in (1,2); +SELECT id,level FROM core_060 CONNECT BY not (level>2); +SELECT id,level FROM core_060 CONNECT BY cast(level as number(38,0))<3; + +drop table core_060; + +/* 存在子查询时,随着数据递归层数的增加,性能下降明显 */ +create table t_customer(id int, pid int,num int,depth int); +-- verify nestloop can be material-optimized +set enable_hashjoin = off; +set enable_mergejoin = off; +explain +select * from ( select * from t_customer where id<1200040 and id>=1200000) start with id=1200010 connect by prior id=pid; +select * from ( select * from t_customer where id<1200040 and id>=1200000) start with id=1200010 connect by prior id=pid; +reset enable_hashjoin; +reset enable_mergejoin; + +-- verify nestloop can be material-optimized +set enable_nestloop = off; +set enable_mergejoin = off; +explain +select * from ( select * from t_customer where id<1200040 and id>=1200000) start with id=1200010 connect by prior id=pid; +select * from ( select * from t_customer where id<1200040 and id>=1200000) start with id=1200010 connect by prior id=pid; +reset enable_nestloop; +reset enable_mergejoin; + +-- verify mergejoin is no need to be material-optimized +set enable_hashjoin = off; +set enable_nestloop = off; +explain +select * from ( select * from t_customer where id<1200040 and id>=1200000) start with id=1200010 connect by prior id=pid; +select * from ( select * from t_customer where id<1200040 and id>=1200000) start with id=1200010 connect by prior id=pid; +reset enable_mergejoin; +reset enable_nestloop; +reset enable_hashjoin; + +drop table t_customer; + +-- test correlated sublink +create table test_place as select id, name, tex from test_hcb_ptb; +select t1.id,t1.pid,t1.name from test_hcb_ptb t1 start with not exists(select * from test_place where id=t1.id and id !=141) connect by prior pid=id; +drop table test_place; + +-- test where quals pushdown +drop table if exists brand_sw3 cascade; +create table brand_sw3 +( +mfg varchar(500) primary key , +brand_cd varchar(500) , +brand_name varchar(100) , +brand_party_id number(18,10) NULL,c1 serial +); + +drop table if exists usview17_sw3 cascade; +create table usview17_sw3 +( +brand_party_id numeric(18,2) , +sales_tran_id numeric(12,5) , +item_qty numeric(5,0) , +mkb_cost_amt numeric(19,4) , +mkb_exp numeric +); + +SELECT MAX(t2.brand_party_id)-COUNT(t2.sales_tran_id) +FROM brand_sw3 t1,usview17_sw3 t2 +WHERE t1.brand_name=PRIOR t1.brand_name +AND PRIOR t1.brand_cd IS NOT NULL +START WITH t1.mfg=t1.brand_name +CONNECT BY NOCYCLE PRIOR t1.mfg +BETWEEN t1.brand_name +AND PRIOR t1.brand_name ; + +SELECT MAX(t2.brand_party_id)-COUNT(t2.sales_tran_id) +FROM brand_sw3 t1,usview17_sw3 t2 +where t1.brand_cd IS NOT NULL CONNECT BY rownum < 3; + +drop table if exists brand_sw3 cascade; +drop table if exists usview17_sw3 cascade; + +create table sw_test1(c0 int); +create table sw_test2(c0 text); + +select * from sw_test1,sw_test2 where true connect by true; + +drop table sw_test1; +drop table sw_test2; diff --git a/src/test/regress/sql/sw_by_rownum_level.sql b/src/test/regress/sql/sw_by_rownum_level.sql new file mode 100644 index 000000000..e482f11aa --- /dev/null +++ b/src/test/regress/sql/sw_by_rownum_level.sql @@ -0,0 +1,36 @@ +set client_min_messages = error; +set search_path=swtest; +SET CLIENT_ENCODING='UTF8'; + +--accepted cases +explain (costs off) +select * from test_area CONNECT BY LEVEL <= LENGTH('SOME TEXT'); +explain (costs off) +select *, LEVEL from test_area CONNECT BY LEVEL <= LENGTH('SOME TEXT'); + +explain (costs off) +select * from test_area CONNECT BY ROWNUM <= LENGTH('SOME TEXT'); +explain (costs off) +select *, ROWNUM from test_area CONNECT BY ROWNUM <= LENGTH('SOME TEXT'); + +explain (costs off) +select * from test_area CONNECT BY LEVEL < LENGTH('SOME TEXT'); +explain (costs off) +select *, LEVEL from test_area CONNECT BY LEVEL < LENGTH('SOME TEXT'); + +explain (costs off) +select * from test_area CONNECT BY ROWNUM < LENGTH('SOME TEXT'); +explain (costs off) +select *, ROWNUM from test_area CONNECT BY ROWNUM < LENGTH('SOME TEXT'); + +--rejected cases +explain (costs off) +select *, LEVEL from test_area CONNECT BY LEVEL > LENGTH('SOME TEXT'); +explain (costs off) +select *, LEVEL from test_area CONNECT BY LEVEL >= LENGTH('SOME TEXT'); +explain (costs off) +select * from test_area CONNECT BY APPLE > LENGTH('SOME TEXT'); +explain (costs off) +select * from test_area CONNECT BY APPLE < LENGTH('SOME TEXT'); +explain (costs off) +select * from test_area CONNECT BY APPLE <= LENGTH('SOME TEXT'); diff --git a/src/test/regress/sql/sw_clearup.sql b/src/test/regress/sql/sw_clearup.sql new file mode 100644 index 000000000..a613508b3 --- /dev/null +++ b/src/test/regress/sql/sw_clearup.sql @@ -0,0 +1,16 @@ +set current_schema=swtest; + +drop table if exists swtest.test_area; +drop table if exists swtest.test_area2; +drop table if exists swtest.t1; +drop table if exists swtest.t2; +drop table if exists swtest.test_hcb_ptb; +drop table if exists swtest.test_hcb_fqb; +drop table if exists swtest.test_sublink; +drop table if exists swtest.test_hcb_ptbc; +drop table if exists swtest.test_swcb_a; +drop table if exists swtest.trait_value; +drop table if exists swtest.offers_20050701; +drop table if exists swtest.brand; + +drop schema if exists swtest cascade; diff --git a/src/test/regress/sql/sw_icbc.sql b/src/test/regress/sql/sw_icbc.sql new file mode 100644 index 000000000..fdf1674e3 --- /dev/null +++ b/src/test/regress/sql/sw_icbc.sql @@ -0,0 +1,96 @@ +set client_min_messages = error; +set search_path=swtest; +SET CLIENT_ENCODING='UTF8'; + +--signle table columns test +explain (costs off) +select * from t1 start with id = 1 connect by prior id = pid; +select * from t1 start with id = 1 connect by prior id = pid; + +explain (costs off) +select * from t1 start with t1.id = 1 connect by prior t1.id = t1.pid; +select * from t1 start with t1.id = 1 connect by prior t1.id = t1.pid; + +explain (costs off) +select * from t1 as test start with test.id = 1 connect by prior test.id = test.pid; +select * from t1 as test start with test.id = 1 connect by prior test.id = test.pid; + +explain (costs off) +select * from t1 start with id = 1 connect by prior id = pid order by id desc; +select * from t1 start with id = 1 connect by prior id = pid order by id desc; + +explain (costs off) +select * from t1 start with id IN (select id from t2 where id = 1) connect by prior id = pid order by id desc; +select * from t1 start with id IN (select id from t2 where id = 1) connect by prior id = pid order by id desc; + +explain (costs off) select t1.id, t1.pid, t1.name from t1 start with id = 1 connect by prior id = pid; +select t1.id, t1.pid, t1.name from t1 start with id = 1 connect by prior id = pid; + +explain (costs off) select sum(name) from t1 start with id = 1 connect by prior id = pid group by id, pid; +select sum(name) from t1 start with id = 1 connect by prior id = pid group by id, pid; + +explain (costs off) select * from t1 start with id = 1 connect by prior id = pid and id IN (select id from t2); +select * from t1 start with id = 1 connect by prior id = pid and id IN (select id from t2); + +explain (costs off) select * from t1 start with id = 1 and id is not NULL connect by prior id = pid; +select * from t1 start with id = 1 and id is not NULL connect by prior id = pid; + +explain (costs off) +select * +from +(select t1.id id, t1.pid pid, t1.name name from t1 + union + select t1.id id, t1.pid pid, t1.name name from t1) as test +start with test.id = 1 +connect by prior test.id = test.pid; + +select * +from +(select t1.id id, t1.pid pid, t1.name name from t1 + union + select t1.id id, t1.pid pid, t1.name name from t1) as test +start with test.id = 1 +connect by prior test.id = test.pid; + +explain (costs off) +select * +from +(select * + from(select t1.id id, t1.pid pid, t1.name name from t1 + union + select t1.id id, t1.pid pid, t1.name name from t1) as test + start with test.id = 1 + connect by prior test.id = test.pid) as tt +CONNECT BY PRIOR tt.id = tt.pid +START WITH tt.id = 1; + +select * +from +(select * + from(select t1.id id, t1.pid pid, t1.name name from t1 + union + select t1.id id, t1.pid pid, t1.name name from t1) as test + start with test.id = 1 + connect by prior test.id = test.pid) as tt +CONNECT BY PRIOR tt.id = tt.pid +START WITH tt.id = 1; + +--test correlated sublink in targetlist +explain select b.id, (select count(a.id) from t1 a where a.pid = b.id) c from t1 b +start with b.id=1 connect by prior b.id = b.pid; + +explain select * from t1 as test +where not exists (select 1 from t1 where test.id = t1.id) +start with test.id = 1 connect by prior test.id = test.pid; + +--multiple tables case +explain (costs off) select * from t1, t2 where t1.id = t2.id start with t1.id = t2.id and t1.id = 1 connect by prior t1.id = t1.pid; +explain (costs off) select * from t1 join t2 on t1.id = t2.id start with t1.id = t2.id and t1.id = 1 connect by prior t1.id = t1.pid; +explain (costs off) select * from t1, (select * from t2) as test where t1.id = test.id start with t1.id = test.id and t1.id = 1 connect by prior t1.id = t1.pid; + +explain (costs off) select id, (select id from t2 start with t2.id = t1.id connect by t2.id = t1.id limit 1) from t1 where id = 1; + +--unsupport case +select prior id cc from t1 start with id = 1 connect by prior id = pid; + +create INCREMENTAL MATERIALIZED view mv as select * from t1 start with id=141 connect by prior id=pid; diff --git a/src/test/regress/sql/sw_prepare.sql b/src/test/regress/sql/sw_prepare.sql new file mode 100644 index 000000000..43d8177f5 --- /dev/null +++ b/src/test/regress/sql/sw_prepare.sql @@ -0,0 +1,228 @@ +drop schema if exists swtest cascade; +create schema swtest; +set current_schema=swtest; + +drop table if exists swtest.test_area; +drop table if exists swtest.test_area2; +drop table if exists swtest.t1; +drop table if exists swtest.t2; +drop table if exists swtest.test_hcb_ptb; +drop table if exists swtest.test_hcb_fqb; +drop table if exists swtest.test_sublink; +drop table if exists swtest.test_hcb_ptbc; +drop table if exists swtest.test_swcb_a; +drop table if exists swtest.trait_value; +drop table if exists swtest.offers_20050701; +drop table if exists swtest.brand; + +create table swtest.test_area(id int4,name text, fatherid int4, name_desc text); +insert into swtest.test_area values (1, '中国', 0, 'China'); +insert into swtest.test_area values (2, '湖南省',1 , 'Hunan'); +insert into swtest.test_area values (3, '广东省',1 , 'Guangdong'); +insert into swtest.test_area values (4, '海南省',1 , 'Hainan'); +insert into swtest.test_area values (5, '河北省',1 , 'Hebei'); +insert into swtest.test_area values (6, '河南省',1 , 'Henan'); +insert into swtest.test_area values (7, '山东省',1 , 'Shandong'); +insert into swtest.test_area values (8, '湖北省',1 , 'Hubei'); +insert into swtest.test_area values (9, '江苏省',1 , 'Jiangsu'); +insert into swtest.test_area values (10,'深圳市',3 , 'Shenzhen'); +insert into swtest.test_area values (11,'长沙市',2 , 'Changsha'); +insert into swtest.test_area values (22,'祁北县',13, 'Qibei'); +insert into swtest.test_area values (12,'南山区',10, 'Nanshan'); +insert into swtest.test_area values (21,'祁西县',13, 'Qixi'); +insert into swtest.test_area values (13,'衡阳市',2 , 'Hengyang'); +insert into swtest.test_area values (14,'耒阳市',13, 'Leiyang'); +insert into swtest.test_area values (15,'龙岗区',10, 'Longgang'); +insert into swtest.test_area values (16,'福田区',10, 'Futian'); +insert into swtest.test_area values (17,'宝安区',10, 'Baoan'); +insert into swtest.test_area values (19,'祁东县',13, 'Qidong'); +insert into swtest.test_area values (18,'常宁市',13, 'Changning'); +insert into swtest.test_area values (20,'祁南县',13, 'Qinan'); + +create table swtest.test_area2(id int4, id2 text, name text, fatherid int4, fatherid2 text, name_desc text); +insert into swtest.test_area2 values (1, 'A', '中国', 0, '', 'China'); +insert into swtest.test_area2 values (2, 'B', '湖南省',1 , 'A', 'Hunan'); +insert into swtest.test_area2 values (3, 'C', '广东省',1 , 'A', 'Guangdong'); +insert into swtest.test_area2 values (4, 'D', '海南省',1 , 'A', 'Hainan'); +insert into swtest.test_area2 values (5, 'E', '河北省',1 , 'A', 'Hebei'); +insert into swtest.test_area2 values (6, 'F', '河南省',1 , 'A', 'Henan'); +insert into swtest.test_area2 values (7, 'G', '山东省',1 , 'A', 'Shandong'); +insert into swtest.test_area2 values (8, 'H', '湖北省',1 , 'A', 'Hubei'); +insert into swtest.test_area2 values (9, 'I', '江苏省',1 , 'A', 'Jiangsu'); +insert into swtest.test_area2 values (10, 'J', '深圳市',3 , 'C', 'Shenzhen'); +insert into swtest.test_area2 values (11, 'K', '长沙市',2 , 'B', 'Changsha'); +insert into swtest.test_area2 values (22, 'L', '祁北县',13, 'O', 'Qibei'); +insert into swtest.test_area2 values (12, 'M', '南山区',10, 'J', 'Nanshan'); +insert into swtest.test_area2 values (21, 'N', '祁西县',13, 'O', 'Qixi'); +insert into swtest.test_area2 values (13, 'O', '衡阳市',2 , 'B', 'Hengyang'); +insert into swtest.test_area2 values (14, 'P', '耒阳市',13, 'O', 'Leiyang'); +insert into swtest.test_area2 values (15, 'Q', '龙岗区',10, 'J', 'Longgang'); +insert into swtest.test_area2 values (16, 'R', '福田区',10, 'J', 'Futian'); +insert into swtest.test_area2 values (17, 'S', '宝安区',10, 'J', 'Baoan'); +insert into swtest.test_area2 values (19, 'T', '祁东县',13, 'O', 'Qidong'); +insert into swtest.test_area2 values (18, 'U', '常宁市',13, 'O', 'Changning'); +insert into swtest.test_area2 values (20, 'V', '祁南县',13, 'O', 'Qinan'); + +create table swtest.t1(id int, pid int, name text); +insert into swtest.t1 values(1, 0, '1'); +insert into swtest.t1 values(2, 1, '2'); +insert into swtest.t1 values(3, 0, '3'); +insert into swtest.t1 values(4, 1, '4'); +insert into swtest.t1 values(5, 2, '5'); +insert into swtest.t1 values(6, 3, '6'); +insert into swtest.t1 values(7, 4, '7'); +insert into swtest.t1 values(8, 4, '8'); +insert into swtest.t1 values(9, 7, '9'); + +create table swtest.t2(id int, pid int, name text); +insert into swtest.t2 values(1, 0, '1'); +insert into swtest.t2 values(2, 1, '2'); +insert into swtest.t2 values(3, 0, '3'); +insert into swtest.t2 values(4, 1, '4'); +insert into swtest.t2 values(5, 2, '5'); +insert into swtest.t2 values(6, 3, '6'); +insert into swtest.t2 values(7, 4, '7'); +insert into swtest.t2 values(8, 4, '8'); +insert into swtest.t2 values(9, 7, '9'); + +CREATE TABLE swtest.test_hcb_ptb(ID INT,CHA CHAR(10),VCH VARCHAR2(10),TEX TEXT,DAT DATE,TIM TIME,TIS TIMESTAMP,NAME VARCHAR2(80),PID INT,PCHA CHAR(10),PVCH VARCHAR2(10),PTEX TEXT,PDAT DATE,PTIM TIME,PTIS TIMESTAMP); +CREATE TABLE swtest.TEST_HCB_FQB(ID INT,CHA CHAR(10),VCH VARCHAR2(10),TEX TEXT,DAT DATE,TIM TIME,TIS TIMESTAMP,NAME VARCHAR2(80),PID INT,PCHA CHAR(10),PVCH VARCHAR2(10),PTEX TEXT,PDAT DATE,PTIM TIME,PTIS TIMESTAMP); +CREATE TABLE swtest.TEST_SUBLINK(ID INT,VCH VARCHAR2(10)); + +INSERT INTO swtest.TEST_HCB_FQB VALUES( 1 , 'a' , 'a' , 'a' , '2021-12-12 12:12:12', '12:12:12', '2021-12-12 12:12:12' ,'中国' , 0, '0' , '0' , '0' , '2000-12-12 12:12:12', '00:00:01', '2000-12-12 12:12:12'); +INSERT INTO swtest.TEST_HCB_FQB VALUES( 11 , 'aa' , 'aa' , 'aa' , '2021-01-01 01:01:01', '01:01:01', '2021-01-01 01:01:01' ,'江苏省', 1, 'a' , 'a' , 'a' , '2021-12-12 12:12:12', '12:12:12', '2021-12-12 12:12:12'); +INSERT INTO swtest.TEST_HCB_FQB VALUES( 12 , 'ab' , 'ab' , 'ab' , '2021-01-01 01:01:01', '01:01:01', '2021-01-01 01:01:01' ,'山东省', 1, 'a' , 'a' , 'a' , '2021-12-12 12:12:12', '12:12:12', '2021-12-12 12:12:12'); +INSERT INTO swtest.TEST_HCB_FQB VALUES( 13 , 'ac' , 'ac' , 'ac' , '2021-01-01 01:01:02', '01:01:02', '2021-01-01 01:01:02' ,'安徽省', 1, 'a' , 'a' , 'a' , '2021-12-12 12:12:12', '12:12:12', '2021-12-12 12:12:12'); +INSERT INTO swtest.TEST_HCB_FQB VALUES( 14 , 'ad' , 'ad' , 'ad' , '2021-01-01 01:01:03', '01:01:03', '2021-01-01 01:01:03' ,'河南省', 1, 'a' , 'a' , 'a' , '2021-12-12 12:12:12', '12:12:12', '2021-12-12 12:12:12'); +INSERT INTO swtest.TEST_HCB_FQB VALUES( 15 , 'ae' , 'ae' , 'ae' , '2021-01-01 01:01:05', '01:01:05', '2021-01-01 01:01:05' ,'河北省', 1, 'a' , 'a' , 'a' , '2021-12-12 12:12:12', '12:12:12', '2021-12-12 12:12:12'); +INSERT INTO swtest.TEST_HCB_FQB VALUES( 16 , 'af' , 'af' , 'af' , '2021-01-01 01:01:06', '01:01:06', '2021-01-01 01:01:06' ,'湖南省', 1, 'a' , 'a' , 'a' , '2021-12-12 12:12:12', '12:12:12', '2021-12-12 12:12:12'); +INSERT INTO swtest.TEST_HCB_FQB VALUES( 17 , 'ag' , 'ag' , 'ag' , '2021-01-01 01:01:07', '01:01:07', '2021-01-01 01:01:07' ,'湖北省', 1, 'a' , 'a' , 'a' , '2021-12-12 12:12:12', '12:12:12', '2021-12-12 12:12:12'); +INSERT INTO swtest.TEST_HCB_FQB VALUES( 18 , 'ah' , 'ah' , 'ah' , '2021-01-01 01:01:08', '01:01:08', '2021-01-01 01:01:08' ,'贵州省', 1, 'a' , 'a' , 'a' , '2021-12-12 12:12:12', '12:12:12', '2021-12-12 12:12:12'); +INSERT INTO swtest.TEST_HCB_FQB VALUES( 19 , 'ai' , 'ai' , 'ai' , '2021-01-01 01:01:09', '01:01:09', '2021-01-01 01:01:09' ,'武汉省', 1, 'a' , 'a' , 'a' , '2021-12-12 12:12:12', '12:12:12', '2021-12-12 12:12:12'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(111 , 'aaa', 'aaa', 'aaa', '2021-01-01 01:01:10', '01:01:10', '2021-01-01 01:01:10' ,'南京市', 11, 'aa' , 'aa' , 'aa' , '2021-01-01 01:01:01', '01:01:01', '2021-01-01 01:01:01'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(112 , 'aab', 'aab', 'aab', '2021-01-01 01:01:11', '01:01:11', '2021-01-01 01:01:11' ,'宿迁市', 11, 'aa' , 'aa' , 'aa' , '2021-01-01 01:01:01', '01:01:01', '2021-01-01 01:01:01'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(113 , 'aac', 'aac', 'aac', '2021-01-01 01:01:12', '01:01:12', '2021-01-01 01:01:12' ,'徐州市', 11, 'aa' , 'aa' , 'aa' , '2021-01-01 01:01:01', '01:01:01', '2021-01-01 01:01:01'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(114 , 'aad', 'aad', 'aad', '2021-01-01 01:01:13', '01:01:13', '2021-01-01 01:01:13' ,'苏州市', 11, 'aa' , 'aa' , 'aa' , '2021-01-01 01:01:01', '01:01:01', '2021-01-01 01:01:01'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(115 , 'aae', 'aae', 'aae', '2021-01-01 01:01:14', '01:01:14', '2021-01-01 01:01:14' ,'盐城市', 11, 'aa' , 'aa' , 'aa' , '2021-01-01 01:01:01', '01:01:01', '2021-01-01 01:01:01'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(116 , 'aaf', 'aaf', 'aaf', '2021-01-01 01:01:15', '01:01:15', '2021-01-01 01:01:15' ,'无锡市', 11, 'aa' , 'aa' , 'aa' , '2021-01-01 01:01:01', '01:01:01', '2021-01-01 01:01:01'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(117 , 'aag', 'aag', 'aag', '2021-01-01 01:01:16', '01:01:16', '2021-01-01 01:01:16' ,'常州市', 11, 'aa' , 'aa' , 'aa' , '2021-01-01 01:01:01', '01:01:01', '2021-01-01 01:01:01'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(118 , 'aah', 'aah', 'aah', '2021-01-01 01:01:17', '01:01:17', '2021-01-01 01:01:17' ,'连云港', 11, 'aa' , 'aa' , 'aa' , '2021-01-01 01:01:01', '01:01:01', '2021-01-01 01:01:01'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(119 , 'aai', 'aai', 'aai', '2021-01-01 01:01:18', '01:01:18', '2021-01-01 01:01:18' ,'泰州市', 11, 'aa' , 'aa' , 'aa' , '2021-01-01 01:01:01', '01:01:01', '2021-01-01 01:01:01'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(121 , 'aba', 'aba', 'aba', '2021-01-01 01:01:20', '01:01:20', '2021-01-01 01:01:20' ,'江宁区', 111, 'aaa', 'aaa', 'aaa', '2021-01-01 01:01:10', '01:01:10', '2021-01-01 01:01:10'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(122 , 'abb', 'abb', 'abb', '2021-01-01 01:01:21', '01:01:21', '2021-01-01 01:01:21' ,'雨花台', 111, 'aaa', 'aaa', 'aaa', '2021-01-01 01:01:10', '01:01:10', '2021-01-01 01:01:10'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(123 , 'abc', 'abc', 'abc', '2021-01-01 01:01:22', '01:01:22', '2021-01-01 01:01:22' ,'鼓楼区', 111, 'aaa', 'aaa', 'aaa', '2021-01-01 01:01:10', '01:01:10', '2021-01-01 01:01:10'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(124 , 'abd', 'abd', 'abd', '2021-01-01 01:01:23', '01:01:23', '2021-01-01 01:01:23' ,'玄武区', 111, 'aaa', 'aaa', 'aaa', '2021-01-01 01:01:10', '01:01:10', '2021-01-01 01:01:10'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(125 , 'abe', 'abe', 'abe', '2021-01-01 01:01:24', '01:01:24', '2021-01-01 01:01:24' ,'建邺区', 111, 'aaa', 'aaa', 'aaa', '2021-01-01 01:01:10', '01:01:10', '2021-01-01 01:01:10'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(126 , 'abf', 'abf', 'abf', '2021-01-01 01:01:25', '01:01:25', '2021-01-01 01:01:25' ,'秦淮区', 111, 'aaa', 'aaa', 'aaa', '2021-01-01 01:01:10', '01:01:10', '2021-01-01 01:01:10'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(127 , 'abg', 'abg', 'abg', '2021-01-01 01:01:26', '01:01:26', '2021-01-01 01:01:26' ,'浦口区', 111, 'aaa', 'aaa', 'aaa', '2021-01-01 01:01:10', '01:01:10', '2021-01-01 01:01:10'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(128 , 'abh', 'abh', 'abh', '2021-01-01 01:01:27', '01:01:27', '2021-01-01 01:01:27' ,'浦口区', 111, 'aaa', 'aaa', 'aaa', '2021-01-01 01:01:10', '01:01:10', '2021-01-01 01:01:10'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(129 , 'abi', 'abi', 'abi', '2021-01-01 01:01:28', '01:01:28', '2021-01-01 01:01:28' ,'六合区', 111, 'aaa', 'aaa', 'aaa', '2021-01-01 01:01:10', '01:01:10', '2021-01-01 01:01:10'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(131 , 'aca', 'aca', 'aca', '2021-01-01 01:01:30', '01:01:30', '2021-01-01 01:01:30' ,'东山街', 121, 'aba', 'aba', 'aba', '2021-01-01 01:01:20', '01:01:20', '2021-01-01 01:01:20'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(132 , 'acb', 'acb', 'acb', '2021-01-01 01:01:31', '01:01:31', '2021-01-01 01:01:31' ,'秣陵街', 121, 'aba', 'aba', 'aba', '2021-01-01 01:01:20', '01:01:20', '2021-01-01 01:01:20'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(133 , 'acc', 'acc', 'acc', '2021-01-01 01:01:32', '01:01:32', '2021-01-01 01:01:32' ,'汤山街', 121, 'aba', 'aba', 'aba', '2021-01-01 01:01:20', '01:01:20', '2021-01-01 01:01:20'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(134 , 'acd', 'acd', 'acd', '2021-01-01 01:01:33', '01:01:33', '2021-01-01 01:01:33' ,'淳化街', 121, 'aba', 'aba', 'aba', '2021-01-01 01:01:20', '01:01:20', '2021-01-01 01:01:20'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(135 , 'ace', 'ace', 'ace', '2021-01-01 01:01:34', '01:01:34', '2021-01-01 01:01:34' ,'禄口街', 121, 'aba', 'aba', 'aba', '2021-01-01 01:01:20', '01:01:20', '2021-01-01 01:01:20'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(136 , 'acf', 'acf', 'acf', '2021-01-01 01:01:35', '01:01:35', '2021-01-01 01:01:35' ,'江宁街', 121, 'aba', 'aba', 'aba', '2021-01-01 01:01:20', '01:01:20', '2021-01-01 01:01:20'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(137 , 'acg', 'acg', 'acg', '2021-01-01 01:01:36', '01:01:36', '2021-01-01 01:01:36' ,'谷里街', 121, 'aba', 'aba', 'aba', '2021-01-01 01:01:20', '01:01:20', '2021-01-01 01:01:20'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(138 , 'ach', 'ach', 'ach', '2021-01-01 01:01:37', '01:01:37', '2021-01-01 01:01:37' ,'湖熟街', 121, 'aba', 'aba', 'aba', '2021-01-01 01:01:20', '01:01:20', '2021-01-01 01:01:20'); +INSERT INTO swtest.TEST_HCB_FQB VALUES(139 , 'aci', 'aci', 'aci', '2021-01-01 01:01:38', '01:01:38', '2021-01-01 01:01:38' ,'横溪街', 121, 'aba', 'aba', 'aba', '2021-01-01 01:01:20', '01:01:20', '2021-01-01 01:01:20'); + +insert into swtest.test_hcb_ptb values( 1,'a',' a','a','2021-12-12 12:12:12','12:12:12','2021-12-12 12:12:12','中国', 0,'0','0','0','2000-12-12 12:12:12','00:00:01','2000-12-12 12:12:12' ); +insert into swtest.test_hcb_ptb values( 11,'aa',' aa','aa','2021-01-01 01:01:01','01:01:01','2021-01-01 01:01:01','江苏省', 1,'a','a','a','2021-12-12 12:12:12','12:12:12','2021-12-12 12:12:12' ); +insert into swtest.test_hcb_ptb values( 12,'ab',' ab','ab','2021-01-01 01:01:01','01:01:01','2021-01-01 01:01:01','山东省', 1,'a','a','a','2021-12-12 12:12:12','12:12:12','2021-12-12 12:12:12' ); +insert into swtest.test_hcb_ptb values( 13,'ac',' ac','ac','2021-01-01 01:01:02','01:01:02','2021-01-01 01:01:02','安徽省', 1,'a','a','a','2021-12-12 12:12:12','12:12:12','2021-12-12 12:12:12' ); +insert into swtest.test_hcb_ptb values( 14,'ad',' ad','ad','2021-01-01 01:01:03','01:01:03','2021-01-01 01:01:03','河南省', 1,'a','a','a','2021-12-12 12:12:12','12:12:12','2021-12-12 12:12:12' ); +insert into swtest.test_hcb_ptb values( 15,'ae',' ae','ae','2021-01-01 01:01:05','01:01:05','2021-01-01 01:01:05','河北省', 1,'a','a','a','2021-12-12 12:12:12','12:12:12','2021-12-12 12:12:12' ); +insert into swtest.test_hcb_ptb values( 16,'af',' af','af','2021-01-01 01:01:06','01:01:06','2021-01-01 01:01:06','湖南省', 1,'a','a','a','2021-12-12 12:12:12','12:12:12','2021-12-12 12:12:12' ); +insert into swtest.test_hcb_ptb values( 17,'ag',' ag','ag','2021-01-01 01:01:07','01:01:07','2021-01-01 01:01:07','湖北省', 1,'a','a','a','2021-12-12 12:12:12','12:12:12','2021-12-12 12:12:12' ); +insert into swtest.test_hcb_ptb values( 18,'ah',' ah','ah','2021-01-01 01:01:08','01:01:08','2021-01-01 01:01:08','贵州省', 1,'a','a','a','2021-12-12 12:12:12','12:12:12','2021-12-12 12:12:12' ); +insert into swtest.test_hcb_ptb values( 19,'ai',' ai','ai','2021-01-01 01:01:09','01:01:09','2021-01-01 01:01:09','武汉省', 1,'a','a','a','2021-12-12 12:12:12','12:12:12','2021-12-12 12:12:12' ); +insert into swtest.test_hcb_ptb values(111,'aaa',' aaa','aaa','2021-01-01 01:01:10','01:01:10','2021-01-01 01:01:10','南京市', 11,'aa','aa','aa','2021-01-01 01:01:01','01:01:01','2021-01-01 01:01:01' ); +insert into swtest.test_hcb_ptb values(112,'aab',' aab','aab','2021-01-01 01:01:11','01:01:11','2021-01-01 01:01:11','宿迁市', 11,'aa','aa','aa','2021-01-01 01:01:01','01:01:01','2021-01-01 01:01:01' ); +insert into swtest.test_hcb_ptb values(113,'aac',' aac','aac','2021-01-01 01:01:12','01:01:12','2021-01-01 01:01:12','徐州市', 11,'aa','aa','aa','2021-01-01 01:01:01','01:01:01','2021-01-01 01:01:01' ); +insert into swtest.test_hcb_ptb values(114,'aad',' aad','aad','2021-01-01 01:01:13','01:01:13','2021-01-01 01:01:13','苏州市', 11,'aa','aa','aa','2021-01-01 01:01:01','01:01:01','2021-01-01 01:01:01' ); +insert into swtest.test_hcb_ptb values(115,'aae',' aae','aae','2021-01-01 01:01:14','01:01:14','2021-01-01 01:01:14','盐城市', 11,'aa','aa','aa','2021-01-01 01:01:01','01:01:01','2021-01-01 01:01:01' ); +insert into swtest.test_hcb_ptb values(117,'aag',' aag','aag','2021-01-01 01:01:16','01:01:16','2021-01-01 01:01:16','常州市', 11,'aa','aa','aa','2021-01-01 01:01:01','01:01:01','2021-01-01 01:01:01' ); +insert into swtest.test_hcb_ptb values(116,'aaf',' aaf','aaf','2021-01-01 01:01:15','01:01:15','2021-01-01 01:01:15','无锡市', 11,'aa','aa','aa','2021-01-01 01:01:01','01:01:01','2021-01-01 01:01:01' ); +insert into swtest.test_hcb_ptb values(118,'aah',' aah','aah','2021-01-01 01:01:17','01:01:17','2021-01-01 01:01:17','连云港', 11,'aa','aa','aa','2021-01-01 01:01:01','01:01:01','2021-01-01 01:01:01' ); +insert into swtest.test_hcb_ptb values(119,'aai',' aai','aai','2021-01-01 01:01:18','01:01:18','2021-01-01 01:01:18','泰州市', 11,'aa','aa','aa','2021-01-01 01:01:01','01:01:01','2021-01-01 01:01:01' ); +insert into swtest.test_hcb_ptb values(121,'aba',' aba','aba','2021-01-01 01:01:20','01:01:20','2021-01-01 01:01:20','江宁区', 111,'aaa','aaa','aaa','2021-01-01 01:01:10','01:01:10','2021-01-01 01:01:10' ); +insert into swtest.test_hcb_ptb values(122,'abb',' abb','abb','2021-01-01 01:01:21','01:01:21','2021-01-01 01:01:21','雨花台', 111,'aaa','aaa','aaa','2021-01-01 01:01:10','01:01:10','2021-01-01 01:01:10' ); +insert into swtest.test_hcb_ptb values(123,'abc',' abc','abc','2021-01-01 01:01:22','01:01:22','2021-01-01 01:01:22','鼓楼区', 111,'aaa','aaa','aaa','2021-01-01 01:01:10','01:01:10','2021-01-01 01:01:10' ); +insert into swtest.test_hcb_ptb values(124,'abd',' abd','abd','2021-01-01 01:01:23','01:01:23','2021-01-01 01:01:23','玄武区', 111,'aaa','aaa','aaa','2021-01-01 01:01:10','01:01:10','2021-01-01 01:01:10' ); +insert into swtest.test_hcb_ptb values(125,'abe',' abe','abe','2021-01-01 01:01:24','01:01:24','2021-01-01 01:01:24','建邺区', 111,'aaa','aaa','aaa','2021-01-01 01:01:10','01:01:10','2021-01-01 01:01:10' ); +insert into swtest.test_hcb_ptb values(126,'abf',' abf','abf','2021-01-01 01:01:25','01:01:25','2021-01-01 01:01:25','秦淮区', 111,'aaa','aaa','aaa','2021-01-01 01:01:10','01:01:10','2021-01-01 01:01:10' ); +insert into swtest.test_hcb_ptb values(127,'abg',' abg','abg','2021-01-01 01:01:26','01:01:26','2021-01-01 01:01:26','浦口区', 111,'aaa','aaa','aaa','2021-01-01 01:01:10','01:01:10','2021-01-01 01:01:10' ); +insert into swtest.test_hcb_ptb values(128,'abh',' abh','abh','2021-01-01 01:01:27','01:01:27','2021-01-01 01:01:27','浦口区', 111,'aaa','aaa','aaa','2021-01-01 01:01:10','01:01:10','2021-01-01 01:01:10' ); +insert into swtest.test_hcb_ptb values(129,'abi',' abi','abi','2021-01-01 01:01:28','01:01:28','2021-01-01 01:01:28','六合区', 111,'aaa','aaa','aaa','2021-01-01 01:01:10','01:01:10','2021-01-01 01:01:10' ); +insert into swtest.test_hcb_ptb values(131,'aca',' aca','aca','2021-01-01 01:01:30','01:01:30','2021-01-01 01:01:30','东山街', 121,'aba','aba','aba','2021-01-01 01:01:20','01:01:20','2021-01-01 01:01:20' ); +insert into swtest.test_hcb_ptb values(132,'acb',' acb','acb','2021-01-01 01:01:31','01:01:31','2021-01-01 01:01:31','秣陵街', 121,'aba','aba','aba','2021-01-01 01:01:20','01:01:20','2021-01-01 01:01:20' ); +insert into swtest.test_hcb_ptb values(133,'acc',' acc','acc','2021-01-01 01:01:32','01:01:32','2021-01-01 01:01:32','汤山街', 121,'aba','aba','aba','2021-01-01 01:01:20','01:01:20','2021-01-01 01:01:20' ); +insert into swtest.test_hcb_ptb values(135,'ace',' ace','ace','2021-01-01 01:01:34','01:01:34','2021-01-01 01:01:34','禄口街', 121,'aba','aba','aba','2021-01-01 01:01:20','01:01:20','2021-01-01 01:01:20' ); +insert into swtest.test_hcb_ptb values(134,'acd',' acd','acd','2021-01-01 01:01:33','01:01:33','2021-01-01 01:01:33','淳化街', 121,'aba','aba','aba','2021-01-01 01:01:20','01:01:20','2021-01-01 01:01:20' ); +insert into swtest.test_hcb_ptb values(136,'acf',' acf','acf','2021-01-01 01:01:35','01:01:35','2021-01-01 01:01:35','江宁街', 121,'aba','aba','aba','2021-01-01 01:01:20','01:01:20','2021-01-01 01:01:20' ); +insert into swtest.test_hcb_ptb values(137,'acg',' acg','acg','2021-01-01 01:01:36','01:01:36','2021-01-01 01:01:36','谷里街', 121,'aba','aba','aba','2021-01-01 01:01:20','01:01:20','2021-01-01 01:01:20' ); +insert into swtest.test_hcb_ptb values(138,'ach',' ach','ach','2021-01-01 01:01:37','01:01:37','2021-01-01 01:01:37','湖熟街', 121,'aba','aba','aba','2021-01-01 01:01:20','01:01:20','2021-01-01 01:01:20' ); +insert into swtest.test_hcb_ptb values(139,'aci',' aci','aci','2021-01-01 01:01:38','01:01:38','2021-01-01 01:01:38','横溪街', 121,'aba','aba','aba','2021-01-01 01:01:20','01:01:20','2021-01-01 01:01:20' ); +insert into swtest.test_hcb_ptb values(141,'ada',' ada','ada','2021-01-01 01:01:40','01:01:40','2021-01-01 01:01:40','江南摩卡', 131,'aca','aca','aca','2021-01-01 01:01:30','01:01:30','2021-01-01 01:01:30' ); +insert into swtest.test_hcb_ptb values(142,'adb',' adb','adb','2021-01-01 01:01:41','01:01:41','2021-01-01 01:01:41','四季云顶', 131,'aca','aca','aca','2021-01-01 01:01:30','01:01:30','2021-01-01 01:01:30' ); +insert into swtest.test_hcb_ptb values(143,'adc',' adc','adc','2021-01-01 01:01:42','01:01:42','2021-01-01 01:01:42','盛世江南', 131,'aca','aca','aca','2021-01-01 01:01:30','01:01:30','2021-01-01 01:01:30' ); +insert into swtest.test_hcb_ptb values(144,'add',' add','add','2021-01-01 01:01:43','01:01:43','2021-01-01 01:01:43','七里香都', 131,'aca','aca','aca','2021-01-01 01:01:30','01:01:30','2021-01-01 01:01:30' ); +insert into swtest.test_hcb_ptb values(145,'ade',' ade','ade','2021-01-01 01:01:44','01:01:44','2021-01-01 01:01:44','西山枫林', 131,'aca','aca','aca','2021-01-01 01:01:30','01:01:30','2021-01-01 01:01:30' ); +insert into swtest.test_hcb_ptb values(146,'adf',' adf','adf','2021-01-01 01:01:45','01:01:45','2021-01-01 01:01:45','醉墨小镇', 131,'aca','aca','aca','2021-01-01 01:01:30','01:01:30','2021-01-01 01:01:30' ); +insert into swtest.test_hcb_ptb values(147,'adg',' adg','adg','2021-01-01 01:01:46','01:01:46','2021-01-01 01:01:46','布拉格调', 131,'aca','aca','aca','2021-01-01 01:01:30','01:01:30','2021-01-01 01:01:30' ); +insert into swtest.test_hcb_ptb values(148,'adh',' adh','adh','2021-01-01 01:01:47','01:01:47','2021-01-01 01:01:47','清幽别院', 131,'aca','aca','aca','2021-01-01 01:01:30','01:01:30','2021-01-01 01:01:30' ); +insert into swtest.test_hcb_ptb values(149,'adi',' adi','adi','2021-01-01 01:01:48','01:01:48','2021-01-01 01:01:48','璀璨天城', 131,'aca','aca','aca','2021-01-01 01:01:30','01:01:30','2021-01-01 01:01:30' ); +insert into swtest.test_hcb_ptb values(151,'aea',' aea','aea','2021-01-01 01:01:50','01:01:50','2021-01-01 01:01:50','江南一楼', 141,'ada','ada','ada','2021-01-01 01:01:40','01:01:40','2021-01-01 01:01:40' ); +insert into swtest.test_hcb_ptb values(152,'aeb',' aeb','aeb','2021-01-01 01:01:51','01:01:51','2021-01-01 01:01:51','江南二楼', 141,'ada','ada','ada','2021-01-01 01:01:40','01:01:40','2021-01-01 01:01:40' ); +insert into swtest.test_hcb_ptb values(153,'aec',' aec','aec','2021-01-01 01:01:52','01:01:52','2021-01-01 01:01:52','江南三楼', 141,'ada','ada','ada','2021-01-01 01:01:40','01:01:40','2021-01-01 01:01:40' ); +insert into swtest.test_hcb_ptb values(154,'aed',' aed','aed','2021-01-01 01:01:53','01:01:53','2021-01-01 01:01:53','江南四楼', 141,'ada','ada','ada','2021-01-01 01:01:40','01:01:40','2021-01-01 01:01:40' ); +insert into swtest.test_hcb_ptb values(155,'aee',' aee','aee','2021-01-01 01:01:54','01:01:54','2021-01-01 01:01:54','江南五楼', 141,'ada','ada','ada','2021-01-01 01:01:40','01:01:40','2021-01-01 01:01:40' ); +insert into swtest.test_hcb_ptb values(156,'aef',' aef','aef','2021-01-01 01:01:55','01:01:55','2021-01-01 01:01:55','江南六楼', 141,'ada','ada','ada','2021-01-01 01:01:40','01:01:40','2021-01-01 01:01:40' ); +insert into swtest.test_hcb_ptb values(157,'aeg',' aeg','aeg','2021-01-01 01:01:56','01:01:56','2021-01-01 01:01:56','江南七楼', 141,'ada','ada','ada','2021-01-01 01:01:40','01:01:40','2021-01-01 01:01:40' ); +insert into swtest.test_hcb_ptb values(158,'aeh',' aeh','aeh','2021-01-01 01:01:57','01:01:57','2021-01-01 01:01:57','江南八楼', 141,'ada','ada','ada','2021-01-01 01:01:40','01:01:40','2021-01-01 01:01:40' ); +insert into swtest.test_hcb_ptb values(159,'aei',' aei','aei','2021-01-01 01:01:58','01:01:58','2021-01-01 01:01:58','江南九楼', 141,'ada','ada','ada','2021-01-01 01:01:40','01:01:40','2021-01-01 01:01:40' ); +insert into swtest.test_hcb_ptb values(161,'afa',' afa','afa','2021-01-01 01:02:50','01:02:50','2021-01-01 01:02:50','第一单元', 151,'aea','aea','aea','2021-01-01 01:01:50','01:01:50','2021-01-01 01:01:50' ); +insert into swtest.test_hcb_ptb values(162,'afb',' afb','afb','2021-01-01 01:02:51','01:02:51','2021-01-01 01:02:51','第二单元', 151,'aea','aea','aea','2021-01-01 01:01:50','01:01:50','2021-01-01 01:01:50' ); +insert into swtest.test_hcb_ptb values(163,'afc',' afc','afc','2021-01-01 01:02:52','01:02:52','2021-01-01 01:02:52','第三单元', 151,'aea','aea','aea','2021-01-01 01:01:50','01:01:50','2021-01-01 01:01:50' ); +insert into swtest.test_hcb_ptb values(164,'afd',' afd','afd','2021-01-01 01:02:53','01:02:53','2021-01-01 01:02:53','第四单元', 151,'aea','aea','aea','2021-01-01 01:01:50','01:01:50','2021-01-01 01:01:50' ); +insert into swtest.test_hcb_ptb values(165,'afe',' afe','afe','2021-01-01 01:02:54','01:02:54','2021-01-01 01:02:54','第五单元', 151,'aea','aea','aea','2021-01-01 01:01:50','01:01:50','2021-01-01 01:01:50' ); +insert into swtest.test_hcb_ptb values(166,'aff',' aff','aff','2021-01-01 01:02:55','01:02:55','2021-01-01 01:02:55','第六单元', 151,'aea','aea','aea','2021-01-01 01:01:50','01:01:50','2021-01-01 01:01:50' ); +insert into swtest.test_hcb_ptb values(167,'afg',' afg','afg','2021-01-01 01:02:56','01:02:56','2021-01-01 01:02:56','第七单元', 151,'aea','aea','aea','2021-01-01 01:01:50','01:01:50','2021-01-01 01:01:50' ); +insert into swtest.test_hcb_ptb values(168,'afh',' afh','afh','2021-01-01 01:02:57','01:02:57','2021-01-01 01:02:57','第八单元', 151,'aea','aea','aea','2021-01-01 01:01:50','01:01:50','2021-01-01 01:01:50' ); +insert into swtest.test_hcb_ptb values(169,'afi',' afi','afi','2021-01-01 01:02:58','01:02:58','2021-01-01 01:02:58','第九单元', 151,'aea','aea','aea','2021-01-01 01:01:50','01:01:50','2021-01-01 01:01:50' ); + +CREATE TABLE swtest.test_hcb_ptbc(ID INT,CHA CHAR(10),VCH VARCHAR2(10),TEX TEXT,DAT DATE,TIM TIME,TIS TIMESTAMP,NAME VARCHAR2(80),PID INT,PCHA CHAR(10),PVCH VARCHAR2(10),PTEX TEXT,PDAT DATE,PTIM TIME,PTIS TIMESTAMP +) with (orientation = column); +insert into test_hcb_ptbc select * from test_hcb_ptb; + +CREATE TABLE swtest.test_swcb_a (ID varchar2(10) PRIMARY KEY,NAME varchar2(100),PID varchar2(10)); + +INSERT INTO swtest.test_swcb_a VALUES ('00001', '中国', '-1'); +INSERT INTO swtest.test_swcb_a VALUES ('00011', '陕西', '00001'); +INSERT INTO swtest.test_swcb_a VALUES ('00012', '贵州', '00001'); +INSERT INTO swtest.test_swcb_a VALUES ('00013', '河南', '00001'); +INSERT INTO swtest.test_swcb_a VALUES ('00111', '西安', '00011'); +INSERT INTO swtest.test_swcb_a VALUES ('00112', '咸阳', '00011'); +INSERT INTO swtest.test_swcb_a VALUES ('00113', '延安', '00011'); +INSERT INTO swtest.test_swcb_a VALUES ('00114', '华县', '00013'); +INSERT INTO swtest.test_swcb_a VALUES ('00115', '河内', '00016'); +INSERT INTO swtest.test_swcb_a VALUES ('00116', '清迈', '00015'); +INSERT INTO swtest.test_swcb_a VALUES ('00117', '仰光', '00017'); +INSERT INTO swtest.test_swcb_a VALUES ('00118', '纽约', '00120'); +INSERT INTO swtest.test_swcb_a VALUES ('00119', '费城', '00118'); +INSERT INTO swtest.test_swcb_a VALUES ('00120', '华盛顿', '00119'); + +create table swtest.trait_value(TRAIT_VALUE_CD VARCHAR(50)primary key, TRAIT_VALUE_DESC VARCHAR(250) NULL, TRAIT_VAL VARCHAR(100) NULL, UOM_CD VARCHAR(50) NULL, TRAIT_CD VARCHAR(50) NULL,c1 serial); + +INSERT INTO swtest.TRAIT_VALUE VALUES ('A', NULL, 'A' , 'A' , 'A'); +INSERT INTO swtest.TRAIT_VALUE VALUES ('B', 'B' , NULL, 'B' , 'B'); +INSERT INTO swtest.TRAIT_VALUE VALUES ('C', 'C' , 'C' , NULL, NULL); +INSERT INTO swtest.TRAIT_VALUE VALUES ('D', NULL, NULL, NULL, 'D'); +INSERT INTO swtest.TRAIT_VALUE VALUES ('E', 'E' , ' AA' , 'E' , 'E'); +INSERT INTO swtest.TRAIT_VALUE VALUES ('F', ' ' , 'AA ' , 'F' , 'F'); + +create table swtest.offers_20050701(PROMO_ID VARCHAR(10), PARTY_ID VARCHAR(10) NULL, LOCATION_ID number(17,0) NULL); +create table swtest.brand(a int default 2, mfg varchar(500), brand_cd varchar(500), brand_name varchar(100), brand_party_id number(18,10) NULL); + +analyze; diff --git a/src/test/regress/sql/sw_siblings.sql b/src/test/regress/sql/sw_siblings.sql new file mode 100644 index 000000000..764892c5b --- /dev/null +++ b/src/test/regress/sql/sw_siblings.sql @@ -0,0 +1,169 @@ +set client_min_messages = error; +set search_path=swtest; +SET CLIENT_ENCODING='UTF8'; + +/* + * + * START WITH .... CONNECT BY基础测试用例 + * + * 测试用例表数 + * openGauss=# select * from swtest.test_area; + * id | name | fatherid | name_desc + * ----+--------+----------+----------- + * 1 | 中国 | 0 | china + * 2 | 湖南省 | 1 | hunan + * 3 | 广东省 | 1 | guangdong + * 4 | 海南省 | 1 | hainan + * 5 | 河北省 | 1 | hebei + * 6 | 河南省 | 1 | henan + * 7 | 山东省 | 1 | shandong + * 8 | 湖北省 | 1 | hubei + * 9 | 江苏省 | 1 | jiangsu + * 10 | 深圳市 | 3 | shenzhen + * 11 | 长沙市 | 2 | changsha + * 22 | 祁北县 | 13 | qibei + * 12 | 南山区 | 10 | nanshan + * 21 | 祁西县 | 13 | qixi + * 13 | 衡阳市 | 2 | hengyang + * 14 | 耒阳市 | 13 | leiyang + * 15 | 龙岗区 | 10 | longgang + * 16 | 福田区 | 10 | futian + * 17 | 宝安区 | 10 | baoan + * 19 | 祁东县 | 13 | qidong + * 18 | 常宁市 | 13 | changning + * 20 | 祁南县 | 13 | qinan + * + */ + +/* case 1.1 test root->leaf order siblings by id asc + * expect order: 1 2 11 13 14 18 19 20 21 22 3 10 12 15 16 17 4 5 6 7 8 9 + */ +EXPLAIN (costs off) +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), SYS_CONNECT_BY_PATH(name, '@') cpath +FROM test_area +START WITH name = '中国' +CONNECT BY prior id = fatherid +ORDER SIBLINGS BY id; + +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), SYS_CONNECT_BY_PATH(name, '@') cpath +FROM test_area +START WITH name = '中国' +CONNECT BY prior id = fatherid +ORDER SIBLINGS BY id; + +/* case 1.2 test root->leaf order siblings by id desc + * expect order: 1 9 8 7 6 5 4 3 10 17 16 15 12 2 13 22 21 20 19 18 14 11 + */ +EXPLAIN (costs off) +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), SYS_CONNECT_BY_PATH(name, '@') cpath +FROM test_area +START WITH name = '中国' +CONNECT BY prior id = fatherid +ORDER SIBLINGS BY id desc; + +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), SYS_CONNECT_BY_PATH(name, '@') cpath +FROM test_area +START WITH name = '中国' +CONNECT BY prior id = fatherid +ORDER SIBLINGS BY id desc; + +/* case 1.3 test double_root->leaf order siblings by id asc + * expect order: 10 12 15 16 17 13 14 18 19 20 21 22 + */ +EXPLAIN (costs off) +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), SYS_CONNECT_BY_PATH(name, '@') cpath +FROM test_area +START WITH name = '衡阳市' or name = '深圳市' +CONNECT BY prior id = fatherid +ORDER SIBLINGS BY id; + +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), SYS_CONNECT_BY_PATH(name, '@') cpath +FROM test_area +START WITH name = '衡阳市' or name = '深圳市' +CONNECT BY prior id = fatherid +ORDER SIBLINGS BY id; + +/* case 1.4 test double_root->leaf order siblings by id desc + * expect order: 13 22 21 20 19 18 14 10 17 16 15 12 + */ +EXPLAIN (costs off) +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), SYS_CONNECT_BY_PATH(name, '@') cpath +FROM test_area +START WITH name = '衡阳市' or name = '深圳市' +CONNECT BY prior id = fatherid +ORDER SIBLINGS BY id desc; + +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), SYS_CONNECT_BY_PATH(name, '@') cpath +FROM test_area +START WITH name = '衡阳市' or name = '深圳市' +CONNECT BY prior id = fatherid +ORDER SIBLINGS BY id desc; + + +/* case 1.5 test leaf->root order siblings by id asc + * expect order: 18 13 2 1 + */ +EXPLAIN (costs off) +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), SYS_CONNECT_BY_PATH(name, '@') cpath +FROM test_area +START WITH name = '常宁市' +CONNECT BY id = prior fatherid +ORDER SIBLINGS BY id; + +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), SYS_CONNECT_BY_PATH(name, '@') cpath +FROM test_area +START WITH name = '常宁市' +CONNECT BY id = prior fatherid +ORDER SIBLINGS BY id; + +/* case 1.6 test leaf->root order siblings by id desc + * expect order: 18 13 2 1 + */ +EXPLAIN (costs off) +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), SYS_CONNECT_BY_PATH(name, '@') cpath +FROM test_area +START WITH name = '常宁市' +CONNECT BY id = prior fatherid +ORDER SIBLINGS BY id desc; + +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), SYS_CONNECT_BY_PATH(name, '@') cpath +FROM test_area +START WITH name = '常宁市' +CONNECT BY id = prior fatherid +ORDER SIBLINGS BY id desc; + +/* case 1.7 + * test order siblings by const + * expect order: 1 2 11 13 14 18 19 20 21 22 3 10 12 15 16 17 4 5 6 7 8 9 + */ +EXPLAIN (costs off) +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), SYS_CONNECT_BY_PATH(name, '@') cpath +FROM test_area +START WITH name = '中国' +CONNECT BY prior id = fatherid +ORDER SIBLINGS BY 1; + +SELECT *, LEVEL, connect_by_isleaf, connect_by_iscycle, connect_by_root(name_desc), SYS_CONNECT_BY_PATH(name, '@') cpath +FROM test_area +START WITH name = '中国' +CONNECT BY prior id = fatherid +ORDER SIBLINGS BY 1; + +/* case 1.8++ test explain for multiple order siblings column */ +EXPLAIN (costs off) +SELECT * FROM test_area +START WITH name = '中国' +CONNECT BY prior id = fatherid +ORDER SIBLINGS BY id, name, name_desc; + +EXPLAIN (costs off) +SELECT * FROM test_area +START WITH name = '中国' +CONNECT BY prior id = fatherid +ORDER SIBLINGS BY id desc, name desc , name_desc desc; + +EXPLAIN (costs off) +SELECT * FROM test_area +START WITH name = '中国' +CONNECT BY prior id = fatherid +ORDER SIBLINGS BY id desc, name, name_desc desc;