public StatementHandler(int handlerType) : base(0x44e, 0x7d7) { this._conditionErroCodes = new OrderedHashSet <int>(); this._conditionGroups = new OrderedIntHashSet(); this._conditionNames = new OrderedHashSet <string>(); this._conditionStates = new OrderedHashSet <string>(); this.HandlerType = handlerType; }
public RangeIteratorMain(Session session, RangeVariable rangeVar) { base.rangePosition = rangeVar.RangePosition; base.Store = rangeVar.RangeTable.GetRowStore(session); base.session = session; base.RangeVar = rangeVar; base.CurrentData = rangeVar._emptyData; base.isBeforeFirst = true; if (rangeVar.IsRightJoin) { this.Lookup = new OrderedIntHashSet(); } this.Conditions = rangeVar.JoinConditions; if (rangeVar.WhereConditions[0].HasIndexCondition()) { this.Conditions = rangeVar.WhereConditions; } this.whereConditions = rangeVar.WhereConditions; this.joinConditions = rangeVar.JoinConditions; }
private void SetInConditionsAsTables() { for (int i = this.RangeVariables.Length - 1; i >= 0; i--) { RangeVariable range = this.RangeVariables[i]; ExpressionLogical e = (ExpressionLogical)this._inExpressions[i]; if (e != null) { OrderedIntHashSet set = new OrderedIntHashSet(); e.AddLeftColumnsForAllAny(range, set); Index index = range.RangeTable.GetIndexForColumns(this.session, set, false); int num2 = 0; for (int j = 0; j < index.GetColumnCount(); j++) { if (set.Contains(index.GetColumns()[j])) { num2++; } } RangeVariable addition = new RangeVariable(e.GetRightNode().GetTable(), null, null, null, this._compileContext) { IsGenerated = true }; RangeVariable[] dest = new RangeVariable[this.RangeVariables.Length + 1]; ArrayUtil.CopyAdjustArray <RangeVariable>(this.RangeVariables, dest, addition, i, 1); this.RangeVariables = dest; Expression[] exprList = new Expression[num2]; for (int k = 0; k < num2; k++) { int num5 = index.GetColumns()[k]; int colIndexRight = set.GetIndex(num5); exprList[k] = new ExpressionLogical(range, num5, addition, colIndexRight); } bool flag = this.RangeVariables[i].IsLeftJoin || this.RangeVariables[i].IsRightJoin; RangeVariable.RangeVariableConditions conditions1 = (!this._inInJoin[i] & flag) ? range.WhereConditions[0] : range.JoinConditions[0]; conditions1.AddIndexCondition(exprList, index, exprList.Length); conditions1.AddCondition(e); } } }
private void SetIndexConditions(RangeVariable.RangeVariableConditions conditions, List <Expression> exprList, int rangeVarIndex, bool includeOr) { this._colIndexSetEqual.Clear(); this._colIndexSetOther.Clear(); int num = 0; int count = exprList.Count; while (num < count) { Expression expression = exprList[num]; if ((expression != null) && expression.IsIndexable(conditions.RangeVar)) { switch (expression.GetExprType()) { case 0x29: if (((expression.ExprSubType != 0x34) && (expression.ExprSubType != 0x33)) && (expression.GetLeftNode().GetRangeVariable() == conditions.RangeVar)) { int columnIndex = expression.GetLeftNode().GetColumnIndex(); this._colIndexSetEqual.Add(columnIndex); } goto Label_01C9; case 0x2a: case 0x2b: case 0x2c: case 0x2d: if (expression.GetLeftNode().GetRangeVariable() == conditions.RangeVar) { int num8; int columnIndex = expression.GetLeftNode().GetColumnIndex(); if (!this._colIndexSetOther.TryGetValue(columnIndex, out num8)) { num8 = 0; } this._colIndexSetOther[columnIndex] = num8 + 1; } goto Label_01C9; case 0x2f: if (expression.GetLeftNode().GetRangeVariable() == conditions.RangeVar) { int columnIndex = expression.GetLeftNode().GetColumnIndex(); this._colIndexSetEqual.Add(columnIndex); } goto Label_01C9; case 0x30: if (expression.GetLeftNode().GetLeftNode().GetRangeVariable() == conditions.RangeVar) { int num11; int columnIndex = expression.GetLeftNode().GetLeftNode().GetColumnIndex(); if (!this._colIndexSetOther.TryGetValue(columnIndex, out num11)) { num11 = 0; } this._colIndexSetOther[columnIndex] = num11 + 1; } goto Label_01C9; case 50: case 2: goto Label_01C9; } Error.RuntimeError(0xc9, "RangeVariableResolver"); } Label_01C9: num++; } this.SetEqaulityConditions(conditions, exprList); if (!conditions.HasIndexCondition()) { this.SetNonEqualityConditions(conditions, exprList); } bool flag = conditions.HasIndexCondition(); bool flag2 = false; if (!flag & includeOr) { int num12 = 0; int num13 = exprList.Count; while (num12 < num13) { Expression expression2 = exprList[num12]; if (expression2 != null) { if (expression2.GetExprType() == 50) { flag = expression2.IsIndexable(conditions.RangeVar); if (flag) { flag = this.SetOrConditions(conditions, (ExpressionLogical)expression2, rangeVarIndex); } if (!flag) { goto Label_02FC; } exprList[num12] = null; flag2 = true; break; } if (((expression2.GetExprType() == 0x29) && (expression2.ExprSubType == 0x34)) && !expression2.GetRightNode().IsCorrelated()) { OrderedIntHashSet set = new OrderedIntHashSet(); ((ExpressionLogical)expression2).AddLeftColumnsForAllAny(conditions.RangeVar, set); if ((conditions.RangeVar.RangeTable.GetIndexForColumns(this.session, set, false) != null) && (this._inExpressions[rangeVarIndex] == null)) { this._inExpressions[rangeVarIndex] = expression2; this._inInJoin[rangeVarIndex] = conditions.IsJoin; this._inExpressionCount++; exprList[num12] = null; break; } } } Label_02FC: num12++; } } int num3 = 0; int num4 = exprList.Count; while (num3 < num4) { Expression expression3 = exprList[num3]; if (expression3 != null) { if (flag2) { for (int i = 0; i < conditions.RangeVar.JoinConditions.Length; i++) { if (conditions.IsJoin) { conditions.RangeVar.JoinConditions[i].NonIndexCondition = ExpressionLogical.AndExpressions(expression3, conditions.RangeVar.JoinConditions[i].NonIndexCondition); } else { conditions.RangeVar.WhereConditions[i].NonIndexCondition = ExpressionLogical.AndExpressions(expression3, conditions.RangeVar.WhereConditions[i].NonIndexCondition); } } } else { conditions.AddCondition(expression3); } } num3++; } }
public virtual void ResolveReferences(Session session, RangeVariable[] outerRanges) { this._leftQueryExpression.ResolveReferences(session, outerRanges); this._rightQueryExpression.ResolveReferences(session, outerRanges); this.AddUnresolvedExpressions(this._leftQueryExpression.UnresolvedExpressions); this.AddUnresolvedExpressions(this._rightQueryExpression.UnresolvedExpressions); if (this._unionCorresponding) { string[] columnNames = this._leftQueryExpression.GetColumnNames(); string[] array = this._rightQueryExpression.GetColumnNames(); if (this._unionCorrespondingColumns == null) { this._unionCorrespondingColumns = new OrderedHashSet <string>(); OrderedIntHashSet set = new OrderedIntHashSet(); OrderedIntHashSet set2 = new OrderedIntHashSet(); for (int i = 0; i < columnNames.Length; i++) { string str = columnNames[i]; int index = ArrayUtil.Find(array, str); if ((str.Length > 0) && (index != -1)) { if (!this._leftQueryExpression.AccessibleColumns[i]) { throw Error.GetError(0x15ca); } if (!this._rightQueryExpression.AccessibleColumns[index]) { throw Error.GetError(0x15ca); } set.Add(i); set2.Add(index); this._unionCorrespondingColumns.Add(str); } } if (this._unionCorrespondingColumns.IsEmpty()) { throw Error.GetError(0x15ca); } this._leftQueryExpression.UnionColumnMap = set.ToArray(); this._rightQueryExpression.UnionColumnMap = set2.ToArray(); } else { this._leftQueryExpression.UnionColumnMap = new int[this._unionCorrespondingColumns.Size()]; this._rightQueryExpression.UnionColumnMap = new int[this._unionCorrespondingColumns.Size()]; for (int i = 0; i < this._unionCorrespondingColumns.Size(); i++) { string str2 = this._unionCorrespondingColumns.Get(i); int index = ArrayUtil.Find(columnNames, str2); if (index == -1) { throw Error.GetError(0x157d); } if (!this._leftQueryExpression.AccessibleColumns[index]) { throw Error.GetError(0x15ca); } this._leftQueryExpression.UnionColumnMap[i] = index; index = ArrayUtil.Find(array, str2); if (index == -1) { throw Error.GetError(0x157d); } if (!this._rightQueryExpression.AccessibleColumns[index]) { throw Error.GetError(0x15ca); } this._rightQueryExpression.UnionColumnMap[i] = index; } } this._columnCount = this._unionCorrespondingColumns.Size(); this.UnionColumnTypes = new SqlType[this._columnCount]; this.UnionColumnNullability = new byte[this._columnCount]; this.ResolveColumnRefernecesInUnionOrderBy(); } else { this._columnCount = this._leftQueryExpression.GetColumnCount(); int columnCount = this._rightQueryExpression.GetColumnCount(); if (this._columnCount != columnCount) { throw Error.GetError(0x15da); } this.UnionColumnTypes = new SqlType[this._columnCount]; this.UnionColumnNullability = new byte[this._columnCount]; this._leftQueryExpression.UnionColumnMap = this._rightQueryExpression.UnionColumnMap = new int[this._columnCount]; ArrayUtil.FillSequence(this._leftQueryExpression.UnionColumnMap); this.ResolveColumnRefernecesInUnionOrderBy(); } }
public virtual OrderedHashSet <Expression> CollectAllExpressions(OrderedHashSet <Expression> set, OrderedIntHashSet typeSet, OrderedIntHashSet stopAtTypeSet) { set = this._leftQueryExpression.CollectAllExpressions(set, typeSet, stopAtTypeSet); if (this._rightQueryExpression != null) { set = this._rightQueryExpression.CollectAllExpressions(set, typeSet, stopAtTypeSet); } return(set); }