Deveel.Data.Sql.Query.QueryTablePlanner.EvaluateSubLogic C# (CSharp) Method

EvaluateSubLogic() private method

private EvaluateSubLogic ( List list, List plans ) : void
list List
plans List
return void
        private void EvaluateSubLogic(List<SqlBinaryExpression> list, List<ExpressionPlan> plans)
        {
            foreach (var expression in list) {
                var orExprs = new[] {expression.Left, expression.Right};

                // An optimizations here;

                // If all the expressions we are ORing together are in the same table
                // then we should execute them before the joins, otherwise they
                // should go after the joins.

                // The reason for this is because if we can lesson the amount of work a
                // join has to do then we should.  The actual time it takes to perform
                // an OR search shouldn't change if it is before or after the joins.

                TablePlan common = null;

                foreach (var orExpr in orExprs) {
                    var vars = orExpr.DiscoverReferences().ToArray();

                    bool breakRule = false;

                    // If there are no variables then don't bother with this expression
                    if (vars.Any()) {
                        // Find the common table source (if any)
                        var ts = FindCommonPlan(vars);
                        bool orAfterJoins = false;
                        if (ts == null) {
                            // No common table, so OR after the joins
                            orAfterJoins = true;
                        } else if (common == null) {
                            common = ts;
                        } else if (common != ts) {
                            // No common table with the vars in this OR list so do this OR
                            // after the joins.
                            orAfterJoins = true;
                        }

                        if (orAfterJoins) {
                            plans.Add(new SubLogicPlan(this, expression, 0.70f));

                            // Continue to the next logic expression
                            breakRule = true;
                        }
                    }

                    if (!breakRule) {
                        // Either we found a common table or there are no variables in the OR.
                        // Either way we should evaluate this after the join.
                        plans.Add(new SubLogicPlan(this, expression, 0.58f));
                    }
                }
            }
        }