Пример #1
0
        // The logic here uses unique preserving to support key inference, not the strictly stronger order preserving used for sargability
        protected bool IsColumnReferencing(PlanNode node, ref string columnName)
        {
            StackColumnReferenceNode localNode = node as StackColumnReferenceNode;

            if ((localNode != null) && (localNode.Location == 0))
            {
                columnName = localNode.Identifier;
                return(true);
            }
            else if (node.IsUniquePreserving && (node.NodeCount == 1))
            {
                return(IsColumnReferencing(node.Nodes[0], ref columnName));
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
        protected void TranslateExpression(CatalogDevicePlan devicePlan, CatalogDevicePlanNode devicePlanNode, PlanNode planNode)
        {
            InstructionNodeBase instructionNode = planNode as InstructionNodeBase;

            if (instructionNode != null)
            {
                if ((instructionNode.DataType != null) && (instructionNode.Operator != null))
                {
                    switch (Schema.Object.Unqualify(instructionNode.Operator.OperatorName))
                    {
                    case Instructions.And:
                    case Instructions.Equal:
                    case Instructions.NotEqual:
                    case Instructions.Greater:
                    case Instructions.InclusiveGreater:
                    case Instructions.Less:
                    case Instructions.InclusiveLess:
                    case Instructions.Like:
                        TranslateExpression(devicePlan, devicePlanNode, instructionNode.Nodes[0]);
                        devicePlanNode.WhereCondition.AppendFormat(" {0} ", GetInstructionKeyword(Schema.Object.Unqualify(instructionNode.Operator.OperatorName)));
                        TranslateExpression(devicePlan, devicePlanNode, instructionNode.Nodes[1]);
                        return;

                    case "ReadValue": TranslateExpression(devicePlan, devicePlanNode, instructionNode.Nodes[0]); return;

                    default: devicePlan.IsSupported = false; return;
                    }
                }
            }

            ValueNode valueNode = planNode as ValueNode;

            if (valueNode != null)
            {
                TranslateScalarParameter(devicePlan, devicePlanNode, planNode);
                return;
            }

            StackReferenceNode stackReferenceNode = planNode as StackReferenceNode;

            if (stackReferenceNode != null)
            {
                TranslateScalarParameter(devicePlan, devicePlanNode, new StackReferenceNode(stackReferenceNode.DataType, stackReferenceNode.Location - 1));
                return;
            }

            StackColumnReferenceNode stackColumnReferenceNode = planNode as StackColumnReferenceNode;

            if (stackColumnReferenceNode != null)
            {
                if (stackColumnReferenceNode.Location == 0)
                {
                    if (devicePlan.TableContext != null)
                    {
                        devicePlanNode.WhereCondition.Append(Schema.Object.EnsureUnrooted(MetaData.GetTag(devicePlan.TableContext.Columns[stackColumnReferenceNode.Identifier].MetaData, "Storage.Name", stackColumnReferenceNode.Identifier)));
                    }
                    else
                    {
                        devicePlanNode.WhereCondition.Append(Schema.Object.EnsureUnrooted(stackColumnReferenceNode.Identifier));
                    }
                }
                else
                {
                    TranslateScalarParameter(devicePlan, devicePlanNode, new StackColumnReferenceNode(stackColumnReferenceNode.Identifier, stackColumnReferenceNode.DataType, stackColumnReferenceNode.Location - 1));
                }

                return;
            }

            devicePlan.IsSupported = false;
        }