Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit 53a0886

Browse files
qwkai-zzzhaoguoquan94
authored andcommitted
Initial modifications according to first Code Review
1. Refacored code, added necessary comments. 2. Removed PhysicalInnerNLJoin and PhysicalInnerHashJoin (left/right/outer as well).
1 parent c76b5bb commit 53a0886

14 files changed

+62
-425
lines changed

Diff for: script/testing/junit/OptimizerTest.java

+14-5
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void Teardown() throws SQLException {
7474

7575

7676
@Test
77-
public void testInnerJoin() throws SQLException {
77+
public void testInnerJoin1() throws SQLException {
7878
try (
7979
Statement stmt = conn.createStatement();
8080
ResultSet resultSet = stmt.executeQuery("SELECT t1.a FROM t1 INNER JOIN t2 ON (t1.b = t2.b) ORDER BY t1.a;");) {
@@ -87,6 +87,10 @@ public void testInnerJoin() throws SQLException {
8787
e.printStackTrace();
8888
fail();
8989
}
90+
}
91+
92+
@Test
93+
public void testInnerJoin2() throws SQLException {
9094
try (
9195
Statement stmt = conn.createStatement();
9296
ResultSet resultSet = stmt.executeQuery("SELECT x.a FROM t1 AS x INNER JOIN t2 ON(x.b = t2.b AND x.c = t2.c) ORDER BY x.a;");) {
@@ -99,12 +103,10 @@ public void testInnerJoin() throws SQLException {
99103
e.printStackTrace();
100104
fail();
101105
}
102-
103-
104106
}
105107

106108
@Test
107-
public void testLeftOuterJoin() throws SQLException {
109+
public void testLeftOuterJoin1() throws SQLException {
108110
try (
109111
Statement stmt = conn.createStatement();
110112
ResultSet resultSet = stmt.executeQuery("SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.d;");) {
@@ -128,6 +130,10 @@ public void testLeftOuterJoin() throws SQLException {
128130
e.printStackTrace();
129131
fail();
130132
}
133+
}
134+
135+
@Test
136+
public void testLeftOuterJoin2() throws SQLException {
131137
try (
132138
Statement stmt = conn.createStatement();
133139
ResultSet resultSet = stmt.executeQuery("SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.d WHERE t1.a>1")) {
@@ -147,6 +153,10 @@ public void testLeftOuterJoin() throws SQLException {
147153
e.printStackTrace();
148154
fail();
149155
}
156+
}
157+
158+
@Test
159+
public void testLeftOuterJoin3() throws SQLException {
150160
try (
151161
Statement stmt = conn.createStatement();
152162
ResultSet resultSet = stmt.executeQuery("SELECT * FROM t1 LEFT OUTER JOIN t2 ON t1.a=t2.d WHERE t1.a>1")) {
@@ -166,7 +176,6 @@ public void testLeftOuterJoin() throws SQLException {
166176
e.printStackTrace();
167177
fail();
168178
}
169-
170179
}
171180

172181
@Test

Diff for: src/include/optimizer/child_property_deriver.h

-8
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,6 @@ class ChildPropertyDeriver : public OperatorVisitor {
4444
void Visit(const PhysicalLimit *) override;
4545
void Visit(const PhysicalNLJoin *) override;
4646
void Visit(const PhysicalHashJoin *) override;
47-
void Visit(const PhysicalInnerNLJoin *) override;
48-
void Visit(const PhysicalLeftNLJoin *) override;
49-
void Visit(const PhysicalRightNLJoin *) override;
50-
void Visit(const PhysicalOuterNLJoin *) override;
51-
void Visit(const PhysicalInnerHashJoin *) override;
52-
void Visit(const PhysicalLeftHashJoin *) override;
53-
void Visit(const PhysicalRightHashJoin *) override;
54-
void Visit(const PhysicalOuterHashJoin *) override;
5547
void Visit(const PhysicalInsert *) override;
5648
void Visit(const PhysicalInsertSelect *) override;
5749
void Visit(const PhysicalDelete *) override;

Diff for: src/include/optimizer/cost_calculator.h

-8
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,6 @@ class CostCalculator : public OperatorVisitor {
3232
void Visit(const PhysicalLimit *) override;
3333
void Visit(const PhysicalNLJoin *) override;
3434
void Visit(const PhysicalHashJoin *) override;
35-
void Visit(const PhysicalInnerNLJoin *) override;
36-
void Visit(const PhysicalLeftNLJoin *) override;
37-
void Visit(const PhysicalRightNLJoin *) override;
38-
void Visit(const PhysicalOuterNLJoin *) override;
39-
void Visit(const PhysicalInnerHashJoin *) override;
40-
void Visit(const PhysicalLeftHashJoin *) override;
41-
void Visit(const PhysicalRightHashJoin *) override;
42-
void Visit(const PhysicalOuterHashJoin *) override;
4335
void Visit(const PhysicalInsert *) override;
4436
void Visit(const PhysicalInsertSelect *) override;
4537
void Visit(const PhysicalDelete *) override;

Diff for: src/include/optimizer/input_column_deriver.h

-16
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,6 @@ class InputColumnDeriver : public OperatorVisitor {
6363

6464
void Visit(const PhysicalHashJoin *) override;
6565

66-
void Visit(const PhysicalInnerNLJoin *) override;
67-
68-
void Visit(const PhysicalLeftNLJoin *) override;
69-
70-
void Visit(const PhysicalRightNLJoin *) override;
71-
72-
void Visit(const PhysicalOuterNLJoin *) override;
73-
74-
void Visit(const PhysicalInnerHashJoin *) override;
75-
76-
void Visit(const PhysicalLeftHashJoin *) override;
77-
78-
void Visit(const PhysicalRightHashJoin *) override;
79-
80-
void Visit(const PhysicalOuterHashJoin *) override;
81-
8266
void Visit(const PhysicalInsert *) override;
8367

8468
void Visit(const PhysicalInsertSelect *) override;

Diff for: src/include/optimizer/operator_visitor.h

-8
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,6 @@ class OperatorVisitor {
3434
virtual void Visit(const PhysicalLimit *) {}
3535
virtual void Visit(const PhysicalNLJoin *) {}
3636
virtual void Visit(const PhysicalHashJoin *) {}
37-
virtual void Visit(const PhysicalInnerNLJoin *) {}
38-
virtual void Visit(const PhysicalLeftNLJoin *) {}
39-
virtual void Visit(const PhysicalRightNLJoin *) {}
40-
virtual void Visit(const PhysicalOuterNLJoin *) {}
41-
virtual void Visit(const PhysicalInnerHashJoin *) {}
42-
virtual void Visit(const PhysicalLeftHashJoin *) {}
43-
virtual void Visit(const PhysicalRightHashJoin *) {}
44-
virtual void Visit(const PhysicalOuterHashJoin *) {}
4537
virtual void Visit(const PhysicalInsert *) {}
4638
virtual void Visit(const PhysicalInsertSelect *) {}
4739
virtual void Visit(const PhysicalDelete *) {}

Diff for: src/include/optimizer/operators.h

+4-104
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ class LogicalSingleJoin : public OperatorNode<LogicalSingleJoin> {
167167
//===--------------------------------------------------------------------===//
168168
class LogicalJoin : public OperatorNode<LogicalJoin> {
169169
public:
170-
static Operator make(JoinType _type);
170+
static Operator make(JoinType type);
171171

172-
static Operator make(JoinType _type,
172+
static Operator make(JoinType type,
173173
std::vector<AnnotatedExpression> &conditions);
174174

175175
bool operator==(const BaseOperatorNode &r) override;
@@ -390,7 +390,7 @@ class PhysicalLimit : public OperatorNode<PhysicalLimit> {
390390
class PhysicalNLJoin : public OperatorNode<PhysicalNLJoin> {
391391
public:
392392
static Operator make(
393-
JoinType _type, std::vector<AnnotatedExpression> conditions,
393+
JoinType type, std::vector<AnnotatedExpression> conditions,
394394
std::vector<std::unique_ptr<expression::AbstractExpression>> &left_keys,
395395
std::vector<std::unique_ptr<expression::AbstractExpression>> &right_keys);
396396

@@ -411,7 +411,7 @@ class PhysicalNLJoin : public OperatorNode<PhysicalNLJoin> {
411411
class PhysicalHashJoin : public OperatorNode<PhysicalHashJoin> {
412412
public:
413413
static Operator make(
414-
JoinType _type, std::vector<AnnotatedExpression> conditions,
414+
JoinType type, std::vector<AnnotatedExpression> conditions,
415415
std::vector<std::unique_ptr<expression::AbstractExpression>> &left_keys,
416416
std::vector<std::unique_ptr<expression::AbstractExpression>> &right_keys);
417417

@@ -426,106 +426,6 @@ class PhysicalHashJoin : public OperatorNode<PhysicalHashJoin> {
426426
JoinType type;
427427
};
428428

429-
//===--------------------------------------------------------------------===//
430-
// InnerNLJoin
431-
//===--------------------------------------------------------------------===//
432-
class PhysicalInnerNLJoin : public OperatorNode<PhysicalInnerNLJoin> {
433-
public:
434-
static Operator make(
435-
std::vector<AnnotatedExpression> conditions,
436-
std::vector<std::unique_ptr<expression::AbstractExpression>> &left_keys,
437-
std::vector<std::unique_ptr<expression::AbstractExpression>> &right_keys);
438-
439-
bool operator==(const BaseOperatorNode &r) override;
440-
441-
hash_t Hash() const override;
442-
443-
std::vector<std::unique_ptr<expression::AbstractExpression>> left_keys;
444-
std::vector<std::unique_ptr<expression::AbstractExpression>> right_keys;
445-
446-
std::vector<AnnotatedExpression> join_predicates;
447-
};
448-
449-
//===--------------------------------------------------------------------===//
450-
// LeftNLJoin
451-
//===--------------------------------------------------------------------===//
452-
class PhysicalLeftNLJoin : public OperatorNode<PhysicalLeftNLJoin> {
453-
public:
454-
std::shared_ptr<expression::AbstractExpression> join_predicate;
455-
static Operator make(
456-
std::shared_ptr<expression::AbstractExpression> join_predicate);
457-
};
458-
459-
//===--------------------------------------------------------------------===//
460-
// RightNLJoin
461-
//===--------------------------------------------------------------------===//
462-
class PhysicalRightNLJoin : public OperatorNode<PhysicalRightNLJoin> {
463-
public:
464-
std::shared_ptr<expression::AbstractExpression> join_predicate;
465-
static Operator make(
466-
std::shared_ptr<expression::AbstractExpression> join_predicate);
467-
};
468-
469-
//===--------------------------------------------------------------------===//
470-
// OuterNLJoin
471-
//===--------------------------------------------------------------------===//
472-
class PhysicalOuterNLJoin : public OperatorNode<PhysicalOuterNLJoin> {
473-
public:
474-
std::shared_ptr<expression::AbstractExpression> join_predicate;
475-
static Operator make(
476-
std::shared_ptr<expression::AbstractExpression> join_predicate);
477-
};
478-
479-
//===--------------------------------------------------------------------===//
480-
// InnerHashJoin
481-
//===--------------------------------------------------------------------===//
482-
class PhysicalInnerHashJoin : public OperatorNode<PhysicalInnerHashJoin> {
483-
public:
484-
static Operator make(
485-
std::vector<AnnotatedExpression> conditions,
486-
std::vector<std::unique_ptr<expression::AbstractExpression>> &left_keys,
487-
std::vector<std::unique_ptr<expression::AbstractExpression>> &right_keys);
488-
489-
bool operator==(const BaseOperatorNode &r) override;
490-
491-
hash_t Hash() const override;
492-
493-
std::vector<std::unique_ptr<expression::AbstractExpression>> left_keys;
494-
std::vector<std::unique_ptr<expression::AbstractExpression>> right_keys;
495-
496-
std::vector<AnnotatedExpression> join_predicates;
497-
};
498-
499-
//===--------------------------------------------------------------------===//
500-
// LeftHashJoin
501-
//===--------------------------------------------------------------------===//
502-
class PhysicalLeftHashJoin : public OperatorNode<PhysicalLeftHashJoin> {
503-
public:
504-
std::shared_ptr<expression::AbstractExpression> join_predicate;
505-
static Operator make(
506-
std::shared_ptr<expression::AbstractExpression> join_predicate);
507-
};
508-
509-
//===--------------------------------------------------------------------===//
510-
// RightHashJoin
511-
//===--------------------------------------------------------------------===//
512-
class PhysicalRightHashJoin : public OperatorNode<PhysicalRightHashJoin> {
513-
public:
514-
std::shared_ptr<expression::AbstractExpression> join_predicate;
515-
static Operator make(
516-
std::shared_ptr<expression::AbstractExpression> join_predicate);
517-
};
518-
519-
//===--------------------------------------------------------------------===//
520-
// OuterHashJoin
521-
//===--------------------------------------------------------------------===//
522-
class PhysicalOuterHashJoin : public OperatorNode<PhysicalOuterHashJoin> {
523-
public:
524-
std::shared_ptr<expression::AbstractExpression> join_predicate;
525-
static Operator make(
526-
std::shared_ptr<expression::AbstractExpression> join_predicate);
527-
};
528-
529429
//===--------------------------------------------------------------------===//
530430
// PhysicalInsert
531431
//===--------------------------------------------------------------------===//

Diff for: src/include/optimizer/plan_generator.h

-16
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,6 @@ class PlanGenerator : public OperatorVisitor {
6464

6565
void Visit(const PhysicalHashJoin *) override;
6666

67-
void Visit(const PhysicalInnerNLJoin *) override;
68-
69-
void Visit(const PhysicalLeftNLJoin *) override;
70-
71-
void Visit(const PhysicalRightNLJoin *) override;
72-
73-
void Visit(const PhysicalOuterNLJoin *) override;
74-
75-
void Visit(const PhysicalInnerHashJoin *) override;
76-
77-
void Visit(const PhysicalLeftHashJoin *) override;
78-
79-
void Visit(const PhysicalRightHashJoin *) override;
80-
81-
void Visit(const PhysicalOuterHashJoin *) override;
82-
8367
void Visit(const PhysicalInsert *) override;
8468

8569
void Visit(const PhysicalInsertSelect *) override;

Diff for: src/optimizer/child_property_deriver.cpp

+6-12
Original file line numberDiff line numberDiff line change
@@ -143,43 +143,37 @@ void ChildPropertyDeriver::Visit(const PhysicalDistinct *) {
143143

144144
output_.push_back(make_pair(requirements_, move(child_input_properties)));
145145
}
146+
146147
void ChildPropertyDeriver::Visit(const PhysicalOrderBy *) {}
148+
147149
void ChildPropertyDeriver::Visit(const PhysicalNLJoin *) {
148150
DeriveForJoin();
149151
}
152+
150153
void ChildPropertyDeriver::Visit(const PhysicalHashJoin *) {
151154
DeriveForJoin();
152155
}
153-
void ChildPropertyDeriver::Visit(const PhysicalInnerNLJoin *) {
154-
DeriveForJoin();
155-
}
156-
void ChildPropertyDeriver::Visit(const PhysicalLeftNLJoin *) {}
157-
void ChildPropertyDeriver::Visit(const PhysicalRightNLJoin *) {}
158-
void ChildPropertyDeriver::Visit(const PhysicalOuterNLJoin *) {}
159-
void ChildPropertyDeriver::Visit(const PhysicalInnerHashJoin *) {
160-
DeriveForJoin();
161-
}
162156

163-
void ChildPropertyDeriver::Visit(const PhysicalLeftHashJoin *) {}
164-
void ChildPropertyDeriver::Visit(const PhysicalRightHashJoin *) {}
165-
void ChildPropertyDeriver::Visit(const PhysicalOuterHashJoin *) {}
166157
void ChildPropertyDeriver::Visit(const PhysicalInsert *) {
167158
vector<shared_ptr<PropertySet>> child_input_properties;
168159

169160
output_.push_back(make_pair(requirements_, move(child_input_properties)));
170161
}
162+
171163
void ChildPropertyDeriver::Visit(const PhysicalInsertSelect *) {
172164
// Let child fulfil all the required properties
173165
vector<shared_ptr<PropertySet>> child_input_properties{requirements_};
174166

175167
output_.push_back(make_pair(requirements_, move(child_input_properties)));
176168
}
169+
177170
void ChildPropertyDeriver::Visit(const PhysicalUpdate *) {
178171
// Let child fulfil all the required properties
179172
vector<shared_ptr<PropertySet>> child_input_properties{requirements_};
180173

181174
output_.push_back(make_pair(requirements_, move(child_input_properties)));
182175
}
176+
183177
void ChildPropertyDeriver::Visit(const PhysicalDelete *) {
184178
// Let child fulfil all the required properties
185179
vector<shared_ptr<PropertySet>> child_input_properties{requirements_};

0 commit comments

Comments
 (0)