comnetwork commented on a change in pull request #431: PHOENIX-5105
URL: https://github.com/apache/phoenix/pull/431#discussion_r250179286
##########
File path:
phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
##########
@@ -742,4 +742,112 @@ private static void verifyQueryPlanAndResultForBug4508(
assertFalse(rs.next());
}
}
+
+ @Test
+ public void testSortMergeJoinPushFilterThroughSortBug5105() throws
Exception {
+ Connection conn = null;
+ try {
+ Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+ conn = DriverManager.getConnection(getUrl(), props);
+
+ String tableName1=generateUniqueName();
+ String tableName2=generateUniqueName();
+
+ conn.createStatement().execute("DROP TABLE if exists "+tableName1);
+
+ String sql="CREATE TABLE IF NOT EXISTS "+tableName1+" ( "+
+ "AID INTEGER PRIMARY KEY,"+
+ "AGE INTEGER"+
+ ")";
+ conn.createStatement().execute(sql);
+
+ conn.createStatement().execute("UPSERT INTO
"+tableName1+"(AID,AGE) VALUES (1,11)");
+ conn.createStatement().execute("UPSERT INTO
"+tableName1+"(AID,AGE) VALUES (2,22)");
+ conn.createStatement().execute("UPSERT INTO
"+tableName1+"(AID,AGE) VALUES (3,33)");
+ conn.commit();
+
+ conn.createStatement().execute("DROP TABLE if exists "+tableName2);
+ sql="CREATE TABLE IF NOT EXISTS "+tableName2+" ( "+
+ "BID INTEGER PRIMARY KEY,"+
+ "CODE INTEGER"+
+ ")";
+ conn.createStatement().execute(sql);
+
+ conn.createStatement().execute("UPSERT INTO
"+tableName2+"(BID,CODE) VALUES (1,66)");
+ conn.createStatement().execute("UPSERT INTO
"+tableName2+"(BID,CODE) VALUES (2,55)");
+ conn.createStatement().execute("UPSERT INTO
"+tableName2+"(BID,CODE) VALUES (3,44)");
+ conn.commit();
+
+ //test for simple scan
+
+ sql="select /*+ USE_SORT_MERGE_JOIN */ a.aid,b.code from (select
aid,age from "+tableName1+" where age >=11 and age<=33) a inner join "+
+ "(select bid,code from "+tableName2+" order by code limit 2) b
on a.aid=b.bid where b.code > 50";
+ ResultSet rs=conn.prepareStatement(sql).executeQuery();
+ assertTrue(rs.next());
+ assertTrue(rs.getInt(1) == 2);
+ assertTrue(rs.getInt(2) == 55);
+ assertTrue(!rs.next());
+
+ //test for aggregate
+ sql="select /*+ USE_SORT_MERGE_JOIN */ a.aid,b.codesum from
(select aid,sum(age) agesum from "+tableName1+" where age >=11 and age<=33
group by aid order by agesum limit 3) a inner join "+
+ "(select bid,sum(code) codesum from "+tableName2+" group by
bid order by codesum limit 2) b on a.aid=b.bid where b.codesum > 50";
+ rs=conn.prepareStatement(sql).executeQuery();
+ assertTrue(rs.next());
+ assertTrue(rs.getInt(1) == 2);
+ assertTrue(rs.getInt(2) == 55);
+ assertTrue(!rs.next());
+
+ String tableName3=generateUniqueName();
+ conn.createStatement().execute("DROP TABLE if exists "+tableName3);
+ sql="CREATE TABLE IF NOT EXISTS "+tableName3+" ( "+
+ "CID INTEGER PRIMARY KEY,"+
+ "REGION INTEGER"+
+ ")";
+ conn.createStatement().execute(sql);
+
+ conn.createStatement().execute("UPSERT INTO
"+tableName3+"(CID,REGION) VALUES (1,77)");
+ conn.createStatement().execute("UPSERT INTO
"+tableName3+"(CID,REGION) VALUES (2,88)");
+ conn.createStatement().execute("UPSERT INTO
"+tableName3+"(CID,REGION) VALUES (3,99)");
+ conn.commit();
+
+ //test for join
+ sql="select t1.aid,t1.code,t2.region from "+
+ "(select a.aid,b.code from "+tableName1+" a inner join
"+tableName2+" b on a.aid=b.bid where b.code >=44 and b.code<=66 order by
b.code limit 3) t1 inner join "+
+ "(select a.aid,c.region from "+tableName1+" a inner join
"+tableName3+" c on a.aid=c.cid where c.region>=77 and c.region<=99 order by
c.region desc limit 1) t2 on t1.aid=t2.aid "+
+ "where t1.code > 50";
+
+ rs=conn.prepareStatement(sql).executeQuery();
+ assertTrue(!rs.next());
+
+ //test for join and aggregate
+ sql="select t1.aid,t1.codesum,t2.regionsum from "+
+ "(select a.aid,sum(b.code) codesum from "+tableName1+" a inner
join "+tableName2+" b on a.aid=b.bid where b.code >=44 and b.code<=66 group by
a.aid order by codesum limit 3) t1 inner join "+
+ "(select a.aid,sum(c.region) regionsum from "+tableName1+" a
inner join "+tableName3+" c on a.aid=c.cid where c.region>=77 and c.region<=99
group by a.aid order by regionsum desc limit 2) t2 on t1.aid=t2.aid "+
+ "where t1.codesum >=40 and t2.regionsum >= 90";
+
+ rs=conn.prepareStatement(sql).executeQuery();
+ assertTrue(rs.next());
+ assertTrue(rs.getInt(1) == 3);
+ assertTrue(rs.getInt(2) == 44);
+ assertTrue(rs.getInt(3) == 99);
+ assertTrue(!rs.next());
+
+ //test for if SubselectRewriter.isOuterOrderByNodesPrefixOfInner
had take effect
Review comment:
No, the SubselectRewriter.isOuterOrderByNodesPrefixOfInner would not remove
the outer order by, because what
SubselectRewriter.isOuterOrderByNodesPrefixOfInner to check is the equality of
OrderByNode, which consides the parseNode/nullsLast/orderAscending all together.
In fact, the RHS of the SortMergeJoin :
(select a.aid,sum(c.region) regionsum from "+tableName1+" a inner join
"+tableName3+" c on a.aid=c.cid where c.region>=77 and c.region<=99 group by
a.aid order by a.aid desc,regionsum desc limit 2)
is a test case, it would be rewritten as :
SELECT $1.AID,$1.REGIONSUM FROM (SELECT A.AID, SUM(C.REGION) REGIONSUM FROM
MERGE1 A Inner JOIN MERGE3 C ON (A.AID = C.CID) WHERE (C.REGION >= 77 AND
C.REGION <= 99) GROUP BY A.AID ORDER BY A.AID DESC,REGIONSUM DESC LIMIT 2) $1
WHERE $1.REGIONSUM >= 90 ORDER BY $1.AID
the outer order by is not removed, the detailed test is in
QueryCompilerTest.testSortMergeJoinPushFilterThroughSortBug5105
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services