Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CBRD-25785] Added test case for view merge issue with ORDER BY in subquery and rownum in main query #2076

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions sql/_33_elderberry/cbrd_24042/cbrd_25785/answers/cbrd_25785.answer
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
===================================================
0
===================================================
0
===================================================
1
===================================================
1
===================================================
1
===================================================
1
===================================================
1
===================================================
1
===================================================
1
===================================================
1
===================================================
1
===================================================
1
===================================================

case1

===================================================
rownum c1 c2
10 10 10
9 9 9
8 8 8
7 7 7
6 6 6
5 5 5
4 4 4
3 3 3
2 2 2
1 1 1

===================================================

case2

===================================================
orderby_num() c1 c2
1 10 10
2 9 9
3 8 8
4 7 7
5 6 6
6 5 5
7 4 4
8 3 3
9 2 2
10 1 1

===================================================

case3

===================================================
rownum c1 c2
9 9 9
8 8 8
7 7 7
6 6 6
5 5 5
4 4 4
3 3 3
2 2 2
1 1 1

===================================================

case4

===================================================
orderby_num() c1 c2
1 2 2
2 4 4
3 6 6
4 8 8
5 10 10

===================================================

case5

===================================================
rownum orderby_num() c1 c2
8 1 8 8
7 2 7 7
6 3 6 6
5 4 5 5
4 5 4 4
3 6 3 3
2 7 2 2
1 8 1 1

===================================================
0
37 changes: 37 additions & 0 deletions sql/_33_elderberry/cbrd_24042/cbrd_25785/cases/cbrd_25785.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
-- Verified for CBRD-25785
-- Problem with view merging when ORDER BY clause in the subquery and the main query, and rownum is in the main query select list.

drop table if exists t1;
create table t1 (c1 int, c2 int);
insert into t1 values (9, 9);
insert into t1 values (10, 10);
insert into t1 values (7, 7);
insert into t1 values (8, 8);
insert into t1 values (5, 5);
insert into t1 values (6, 6);
insert into t1 values (3, 3);
insert into t1 values (4, 4);
insert into t1 values (1, 1);
insert into t1 values (2, 2);

--case1: Basic Combination of rownum and ORDER BY
evaluate 'case1';
select /*+ recompile */ rownum, c1, c2 from (select c1, c2 from t1 where c1 > 0 order by c1) order by c2 desc;

--case2: Example Using orderby_num()
evaluate 'case2';
select /*+ recompile */ orderby_num(), c1, c2 from (select c1, c2 from t1 where c1 > 0 order by c2) order by c1 desc;

--case3: Using rownum with Multiple ORDER BY Clauses
evaluate 'case3';
select /*+ recompile */ rownum, c1, c2 from (select c1, c2 from t1 where c2 < 10 order by c1) order by c2 desc, c1 asc;

--case4: orderby_num() with Additional Conditions
evaluate 'case4';
select /*+ recompile */ orderby_num(), c1, c2 from (select c1, c2 from t1 where c1 % 2 = 0 order by c2 desc) order by c1 asc;

--case5: Using Both rownum and orderby_num() Together
evaluate 'case5';
select /*+ recompile */ rownum, orderby_num(), c1, c2 from (select c1, c2 from t1 where c1 between 1 and 8 order by c1) order by c2 desc;

drop table if exists t1;