DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
TablePlan.cs
Go to the documentation of this file.
1 //
2 // Copyright 2010-2015 Deveel
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 using System;
18 using System.Linq;
19 
21 
22 namespace Deveel.Data.Sql.Query {
23  public sealed class TablePlan {
24  public TablePlan(IQueryPlanNode plan, ObjectName[] columnNames, string[] uniqueNames) {
25  if (plan == null)
26  throw new ArgumentNullException("plan");
27  if (columnNames == null)
28  throw new ArgumentNullException("columnNames");
29 
30  Plan = plan;
31  ColumnNames = columnNames;
32  UniqueNames = uniqueNames;
33  LeftJoinType = JoinType.None;
34  RightJoinType = JoinType.None;
35  IsUpdated = false;
36  }
37 
41  public IQueryPlanNode Plan { get; private set; }
42 
46  public bool IsUpdated { get; private set; }
47 
52  public ObjectName[] ColumnNames { get; private set; }
53 
57  public string[] UniqueNames { get; private set; }
58 
59  public TablePlan LeftPlan { get; private set; }
60 
61  public TablePlan RightPlan { get; private set; }
62 
63  public JoinType LeftJoinType { get; private set; }
64 
65  public JoinType RightJoinType { get; private set; }
66 
67  public SqlExpression LeftOnExpression { get; private set; }
68 
69  public SqlExpression RightOnExpression { get; private set; }
70 
71  public void SetCachePoint() {
72  if (!(Plan is CachePointNode))
73  Plan = new CachePointNode(Plan);
74  }
75 
76  public void SetUpdated() {
77  IsUpdated = true;
78  }
79 
80  public void LeftJoin(TablePlan left, JoinType joinType, SqlExpression onExpression) {
81  LeftPlan = left;
82  LeftJoinType = joinType;
83  LeftOnExpression = onExpression;
84  }
85 
86  public void RightJoin(TablePlan right, JoinType joinType, SqlExpression onExpression) {
87  RightPlan = right;
88  RightJoinType = joinType;
89  RightOnExpression = onExpression;
90  }
91 
92  public void MergeJoin(TablePlan left, TablePlan right) {
93  if (left.RightPlan != right) {
94  if (left.RightPlan != null) {
95  RightJoin(left.RightPlan, left.RightJoinType, left.RightOnExpression);
96  RightPlan.LeftPlan = this;
97  }
98  if (right.LeftPlan != null) {
99  LeftJoin(right.LeftPlan, right.LeftJoinType, right.LeftOnExpression);
100  LeftPlan.RightPlan = this;
101  }
102  }
103 
104  if (left.LeftPlan != right) {
105  if (LeftPlan == null && left.LeftPlan != null) {
106  LeftJoin(left.LeftPlan, left.LeftJoinType, left.LeftOnExpression);
107  LeftPlan.RightPlan = this;
108  }
109  if (RightPlan == null && right.RightPlan != null) {
110  RightJoin(right.RightPlan, right.RightJoinType, right.RightOnExpression);
111  RightPlan.LeftPlan = this;
112  }
113  }
114  }
115 
116  public bool ContainsColumn(ObjectName columnName) {
117  return ColumnNames.Contains(columnName);
118  }
119 
120  public bool ContainsName(string name) {
121  if (UniqueNames == null || UniqueNames.Length == 0)
122  return false;
123 
124  return UniqueNames.Contains(name);
125  }
126 
127  public TablePlan Clone() {
128  return new TablePlan(Plan, ColumnNames, UniqueNames);
129  }
130 
131  public void UpdatePlan(IQueryPlanNode queryPlan) {
132  Plan = queryPlan;
133  IsUpdated = true;
134  }
135  }
136 }
SqlExpression LeftOnExpression
Definition: TablePlan.cs:67
void MergeJoin(TablePlan left, TablePlan right)
Definition: TablePlan.cs:92
JoinType
Enumerates the kind of group join in a selection query.
Definition: JoinType.cs:23
A query to the database to select data from a set of tables and columns.
bool ContainsColumn(ObjectName columnName)
Definition: TablePlan.cs:116
void RightJoin(TablePlan right, JoinType joinType, SqlExpression onExpression)
Definition: TablePlan.cs:86
Describes the name of an object within a database.
Definition: ObjectName.cs:44
A node element of a query plan tree. /summary>
TablePlan(IQueryPlanNode plan, ObjectName[] columnNames, string[] uniqueNames)
Definition: TablePlan.cs:24
void UpdatePlan(IQueryPlanNode queryPlan)
Definition: TablePlan.cs:131
bool ContainsName(string name)
Definition: TablePlan.cs:120
SqlExpression RightOnExpression
Definition: TablePlan.cs:69
void LeftJoin(TablePlan left, JoinType joinType, SqlExpression onExpression)
Definition: TablePlan.cs:80
Defines the base class for instances that represent SQL expression tree nodes.