Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / ndp / fx / src / DataEntity / System / Data / Query / PlanCompiler / JoinElimination.cs / 2 / JoinElimination.cs
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....], [....]
//---------------------------------------------------------------------
using System;
using System.Collections.Generic;
//using System.Diagnostics; // Please use PlanCompiler.Assert instead of Debug.Assert in this class...
using System.Globalization;
using System.Data.Query.InternalTrees;
namespace System.Data.Query.PlanCompiler
{
///
/// The JoinElimination module is intended to do just that - eliminate unnecessary joins.
/// This module deals with the following kinds of joins
/// * Self-joins: The join can be eliminated, and either of the table instances can be
/// used instead
/// * Implied self-joins: Same as above
/// * PK-FK joins: (More generally, UK-FK joins): Eliminate the join, and use just the FK table, if no
/// column of the PK table is used (other than the join condition)
/// * PK-PK joins: Eliminate the right side table, if we have a left-outer join
///
internal class JoinElimination : BasicOpVisitorOfNode
{
#region private state
private PlanCompiler m_compilerState;
private Command Command { get { return m_compilerState.Command; } }
private Dictionary m_joinGraphUnnecessaryMap;
private VarRemapper m_varRemapper;
private ConstraintManager m_constraintManager = new ConstraintManager();
private bool m_treeModified;
private VarRefManager m_varRefManager;
#endregion
#region constructors
private JoinElimination(PlanCompiler compilerState)
{
m_compilerState = compilerState;
}
#endregion
#region public surface
internal static void Process(PlanCompiler compilerState)
{
JoinElimination je = new JoinElimination(compilerState);
je.InitializeAndProcess();
if (je.m_treeModified)
{
compilerState.MarkPhaseAsNeeded(PlanCompilerPhase.Transformations);
je.InitializeAndProcess();
}
}
#endregion
#region private methods
///
/// The main driver, initializes the state and invokes processing
///
private void InitializeAndProcess()
{
Initialize();
Process();
}
///
/// Ininitalizes the state of JoinElimination
///
private void Initialize()
{
m_joinGraphUnnecessaryMap = new Dictionary();
m_varRemapper = new VarRemapper(m_compilerState.Command);
m_varRefManager = new VarRefManager(m_compilerState.Command);
m_treeModified = false;
}
///
/// Invokes the visitor
///
private void Process()
{
this.Command.Root = VisitNode(this.Command.Root);
}
#region JoinHelpers
#region Building JoinGraphs
///
/// Do we need to build a join graph for this node - returns false, if we've already
/// processed this
///
///
///
private bool NeedsJoinGraph(Node joinNode)
{
return !m_joinGraphUnnecessaryMap.ContainsKey(joinNode);
}
///
/// Do the real processing of the join graph.
///
/// current join node
/// modified join node
private Node ProcessJoinGraph(Node joinNode)
{
// Build the join graph
JoinGraph joinGraph = new JoinGraph(this.Command, this.m_constraintManager, this.m_varRefManager, joinNode);
// Get the transformed node tree
VarMap remappedVars;
Dictionary processedNodes;
Node newNode = joinGraph.DoJoinElimination(out remappedVars, out processedNodes);
// Get the set of vars that need to be renamed
foreach (KeyValuePair kv in remappedVars)
{
m_varRemapper.AddMapping(kv.Key, kv.Value);
}
// get the set of nodes that have already been processed
foreach (Node n in processedNodes.Keys)
{
m_joinGraphUnnecessaryMap[n] = n;
}
return newNode;
}
///
/// Default handler for a node. Simply visits the children, then handles any var
/// remapping, and then recomputes the node info
///
///
///
private Node VisitDefaultForAllNodes(Node n)
{
VisitChildren(n);
m_varRemapper.RemapNode(n);
this.Command.RecomputeNodeInfo(n);
return n;
}
#endregion
#endregion
#region Visitor overrides
///
/// Invokes default handling for a node and adds the child-parent tracking info to the VarRefManager.
///
///
///
protected override Node VisitDefault(Node n)
{
m_varRefManager.AddChildren(n);
return VisitDefaultForAllNodes(n);
}
#region RelOps
#region JoinOps
///
/// Build a join graph for this node for this node if necessary, and process it
///
/// current join op
/// current join node
///
protected override Node VisitJoinOp(JoinBaseOp op, Node joinNode)
{
Node newNode;
// Build and process a join graph if necessary
if (NeedsJoinGraph(joinNode))
{
newNode = ProcessJoinGraph(joinNode);
if (newNode != joinNode)
{
m_treeModified = true;
}
}
else
{
newNode = joinNode;
}
// Now do the default processing (ie) visit the children, compute the nodeinfo etc.
return VisitDefaultForAllNodes(newNode);
}
#endregion
#endregion
#endregion
#endregion
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....], [....]
//---------------------------------------------------------------------
using System;
using System.Collections.Generic;
//using System.Diagnostics; // Please use PlanCompiler.Assert instead of Debug.Assert in this class...
using System.Globalization;
using System.Data.Query.InternalTrees;
namespace System.Data.Query.PlanCompiler
{
///
/// The JoinElimination module is intended to do just that - eliminate unnecessary joins.
/// This module deals with the following kinds of joins
/// * Self-joins: The join can be eliminated, and either of the table instances can be
/// used instead
/// * Implied self-joins: Same as above
/// * PK-FK joins: (More generally, UK-FK joins): Eliminate the join, and use just the FK table, if no
/// column of the PK table is used (other than the join condition)
/// * PK-PK joins: Eliminate the right side table, if we have a left-outer join
///
internal class JoinElimination : BasicOpVisitorOfNode
{
#region private state
private PlanCompiler m_compilerState;
private Command Command { get { return m_compilerState.Command; } }
private Dictionary m_joinGraphUnnecessaryMap;
private VarRemapper m_varRemapper;
private ConstraintManager m_constraintManager = new ConstraintManager();
private bool m_treeModified;
private VarRefManager m_varRefManager;
#endregion
#region constructors
private JoinElimination(PlanCompiler compilerState)
{
m_compilerState = compilerState;
}
#endregion
#region public surface
internal static void Process(PlanCompiler compilerState)
{
JoinElimination je = new JoinElimination(compilerState);
je.InitializeAndProcess();
if (je.m_treeModified)
{
compilerState.MarkPhaseAsNeeded(PlanCompilerPhase.Transformations);
je.InitializeAndProcess();
}
}
#endregion
#region private methods
///
/// The main driver, initializes the state and invokes processing
///
private void InitializeAndProcess()
{
Initialize();
Process();
}
///
/// Ininitalizes the state of JoinElimination
///
private void Initialize()
{
m_joinGraphUnnecessaryMap = new Dictionary();
m_varRemapper = new VarRemapper(m_compilerState.Command);
m_varRefManager = new VarRefManager(m_compilerState.Command);
m_treeModified = false;
}
///
/// Invokes the visitor
///
private void Process()
{
this.Command.Root = VisitNode(this.Command.Root);
}
#region JoinHelpers
#region Building JoinGraphs
///
/// Do we need to build a join graph for this node - returns false, if we've already
/// processed this
///
///
///
private bool NeedsJoinGraph(Node joinNode)
{
return !m_joinGraphUnnecessaryMap.ContainsKey(joinNode);
}
///
/// Do the real processing of the join graph.
///
/// current join node
/// modified join node
private Node ProcessJoinGraph(Node joinNode)
{
// Build the join graph
JoinGraph joinGraph = new JoinGraph(this.Command, this.m_constraintManager, this.m_varRefManager, joinNode);
// Get the transformed node tree
VarMap remappedVars;
Dictionary processedNodes;
Node newNode = joinGraph.DoJoinElimination(out remappedVars, out processedNodes);
// Get the set of vars that need to be renamed
foreach (KeyValuePair kv in remappedVars)
{
m_varRemapper.AddMapping(kv.Key, kv.Value);
}
// get the set of nodes that have already been processed
foreach (Node n in processedNodes.Keys)
{
m_joinGraphUnnecessaryMap[n] = n;
}
return newNode;
}
///
/// Default handler for a node. Simply visits the children, then handles any var
/// remapping, and then recomputes the node info
///
///
///
private Node VisitDefaultForAllNodes(Node n)
{
VisitChildren(n);
m_varRemapper.RemapNode(n);
this.Command.RecomputeNodeInfo(n);
return n;
}
#endregion
#endregion
#region Visitor overrides
///
/// Invokes default handling for a node and adds the child-parent tracking info to the VarRefManager.
///
///
///
protected override Node VisitDefault(Node n)
{
m_varRefManager.AddChildren(n);
return VisitDefaultForAllNodes(n);
}
#region RelOps
#region JoinOps
///
/// Build a join graph for this node for this node if necessary, and process it
///
/// current join op
/// current join node
///
protected override Node VisitJoinOp(JoinBaseOp op, Node joinNode)
{
Node newNode;
// Build and process a join graph if necessary
if (NeedsJoinGraph(joinNode))
{
newNode = ProcessJoinGraph(joinNode);
if (newNode != joinNode)
{
m_treeModified = true;
}
}
else
{
newNode = joinNode;
}
// Now do the default processing (ie) visit the children, compute the nodeinfo etc.
return VisitDefaultForAllNodes(newNode);
}
#endregion
#endregion
#endregion
#endregion
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DecoderFallback.cs
- ControlParser.cs
- Triangle.cs
- ConstructorBuilder.cs
- DependencyPropertyChangedEventArgs.cs
- NativeWrapper.cs
- WorkflowEventArgs.cs
- XmlDictionaryReader.cs
- DispatcherHookEventArgs.cs
- PropertyRef.cs
- LayoutUtils.cs
- BitmapSource.cs
- ExpressionVisitorHelpers.cs
- CompoundFileReference.cs
- dbenumerator.cs
- FloaterBaseParagraph.cs
- JsonFormatGeneratorStatics.cs
- LongValidatorAttribute.cs
- SQLCharsStorage.cs
- Compiler.cs
- Transform3DGroup.cs
- FlowLayoutSettings.cs
- TypeLoadException.cs
- Rotation3D.cs
- fixedPageContentExtractor.cs
- RoutedPropertyChangedEventArgs.cs
- DataBindEngine.cs
- HealthMonitoringSectionHelper.cs
- XmlDataSource.cs
- DataDocumentXPathNavigator.cs
- SqlUDTStorage.cs
- SystemInfo.cs
- XmlSerializer.cs
- DefinitionBase.cs
- EntityTemplateFactory.cs
- ErrorProvider.cs
- WindowsIPAddress.cs
- MethodBody.cs
- ComplexTypeEmitter.cs
- HandlerMappingMemo.cs
- BamlRecordHelper.cs
- Inflater.cs
- RouteValueExpressionBuilder.cs
- ObfuscationAttribute.cs
- _OverlappedAsyncResult.cs
- XmlExtensionFunction.cs
- Base64WriteStateInfo.cs
- PassportIdentity.cs
- HttpFileCollectionBase.cs
- MetadataItemEmitter.cs
- FaultConverter.cs
- SHA256Managed.cs
- SponsorHelper.cs
- EntityDataSourceSelectingEventArgs.cs
- EtwTrace.cs
- CodeVariableReferenceExpression.cs
- IPPacketInformation.cs
- Process.cs
- ScriptManager.cs
- VerificationAttribute.cs
- FontSourceCollection.cs
- DebugHandleTracker.cs
- InternalDuplexChannelFactory.cs
- LocalizableResourceBuilder.cs
- RadioButtonRenderer.cs
- ConfigDefinitionUpdates.cs
- Invariant.cs
- NetworkAddressChange.cs
- WebFaultClientMessageInspector.cs
- ParameterSubsegment.cs
- AssemblyBuilder.cs
- ToolTip.cs
- ThreadStateException.cs
- XmlConvert.cs
- TypeForwardedToAttribute.cs
- DataServiceContext.cs
- StylusPointPropertyId.cs
- XamlRtfConverter.cs
- ApplicationActivator.cs
- LinkLabel.cs
- OleDbErrorCollection.cs
- Wow64ConfigurationLoader.cs
- EmbeddedObject.cs
- TextRunTypographyProperties.cs
- CodeCommentStatement.cs
- precedingsibling.cs
- SliderAutomationPeer.cs
- QualifiedCellIdBoolean.cs
- HostingMessageProperty.cs
- DataGridRowClipboardEventArgs.cs
- MailBnfHelper.cs
- XComponentModel.cs
- TextRangeAdaptor.cs
- LayoutEngine.cs
- Utils.cs
- SQLInt16Storage.cs
- CharStorage.cs
- ConfigurationStrings.cs
- AttributedMetaModel.cs
- Events.cs