33import java .sql .ResultSet ;
44import java .sql .SQLException ;
55import java .sql .Statement ;
6- import java .util .Arrays ;
76import java .util .List ;
87import java .util .stream .Collectors ;
98
@@ -48,15 +47,14 @@ public void check() throws SQLException {
4847 DatabendTables randomTables = s .getRandomTableNonEmptyTables (); // 随机获得nr张表
4948 List <DatabendColumn > columns = randomTables .getColumns ();
5049 DatabendNewExpressionGenerator gen = new DatabendNewExpressionGenerator (state ).setColumns (columns );
51-
52- Node <DatabendExpression > randomWhereCondition = gen .generateExpression (DatabendDataType .BOOLEAN ); // 生成随机where条件,形式为ast
53-
50+ Node <DatabendExpression > randomWhereCondition = gen .generateExpression (DatabendDataType .BOOLEAN ); // 生成随机where条件
5451 List <DatabendTable > tables = randomTables .getTables ();
5552 List <TableReferenceNode <DatabendExpression , DatabendTable >> tableList = tables .stream ()
5653 .map (t -> new TableReferenceNode <DatabendExpression , DatabendTable >(t )).collect (Collectors .toList ());
5754 List <Node <DatabendExpression >> joins = DatabendJoin .getJoins (tableList , state );
58- int secondCount = getSecondQuery (tableList .stream ().collect (Collectors .toList ()), randomWhereCondition , joins ); // 禁用优化
59- int firstCount = getFirstQueryCount (con , tableList .stream ().collect (Collectors .toList ()), columns ,
55+ int secondCount = getUnoptimizedQueryCount (tableList .stream ().collect (Collectors .toList ()),
56+ randomWhereCondition , joins );
57+ int firstCount = getOptimizedQueryCount (con , tableList .stream ().collect (Collectors .toList ()), columns ,
6058 randomWhereCondition , joins );
6159 if (firstCount == -1 || secondCount == -1 ) {
6260 throw new IgnoreMeException ();
@@ -67,23 +65,20 @@ public void check() throws SQLException {
6765 }
6866 }
6967
70- private int getSecondQuery (List <Node <DatabendExpression >> tableList , Node < DatabendExpression > randomWhereCondition ,
71- List <Node <DatabendExpression >> joins ) throws SQLException {
68+ private int getUnoptimizedQueryCount (List <Node <DatabendExpression >> tableList ,
69+ Node < DatabendExpression > randomWhereCondition , List <Node <DatabendExpression >> joins ) throws SQLException {
7270 DatabendSelect select = new DatabendSelect ();
7371 // select.setGroupByClause(groupBys);
74- // DatabendExpression isTrue = DatabendPostfixOperation.create(randomWhereCondition,
75- // PostfixOperator.IS_TRUE);
7672 Node <DatabendExpression > asText = new NewPostfixTextNode <>(new DatabendCastOperation (
7773 new NewPostfixTextNode <DatabendExpression >(randomWhereCondition ,
7874 " IS NOT NULL AND " + DatabendToStringVisitor .asString (randomWhereCondition )),
7975 new DatabendCompositeDataType (DatabendDataType .INT , 8 )), "as count" );
8076
81- select .setFetchColumns (Arrays . asList (asText )); // ?
77+ select .setFetchColumns (List . of (asText ));
8278 select .setFromList (tableList );
8379 select .setJoinList (joins );
8480 int secondCount = 0 ;
8581 unoptimizedQueryString = "SELECT SUM(count) FROM (" + DatabendToStringVisitor .asString (select ) + ") as res" ;
86- errors .add ("canceling statement due to statement timeout" );
8782 SQLQueryAdapter q = new SQLQueryAdapter (unoptimizedQueryString , errors );
8883 SQLancerResultSet rs ;
8984 try {
@@ -101,17 +96,14 @@ private int getSecondQuery(List<Node<DatabendExpression>> tableList, Node<Databe
10196 return secondCount ;
10297 }
10398
104- private int getFirstQueryCount (SQLConnection con , List <Node <DatabendExpression >> tableList ,
99+ private int getOptimizedQueryCount (SQLConnection con , List <Node <DatabendExpression >> tableList ,
105100 List <DatabendColumn > columns , Node <DatabendExpression > randomWhereCondition ,
106101 List <Node <DatabendExpression >> joins ) throws SQLException {
107102 DatabendSelect select = new DatabendSelect ();
108103 // select.setGroupByClause(groupBys);
109- // DatabendAggregate aggr = new DatabendAggregate(
110104 List <Node <DatabendExpression >> allColumns = columns .stream ()
111105 .map ((c ) -> new ColumnReferenceNode <DatabendExpression , DatabendColumn >(c ))
112106 .collect (Collectors .toList ());
113- // DatabendAggregateFunction.COUNT);
114- // select.setFetchColumns(Arrays.asList(aggr));
115107 select .setFetchColumns (allColumns );
116108 select .setFromList (tableList );
117109 select .setWhereClause (randomWhereCondition );
0 commit comments