コード例 #1
0
        protected override BoundRelation RewriteTableRelation(BoundTableRelation node)
        {
            var symbol = node.TableInstance.Table as CommonTableExpressionSymbol;

            if (symbol == null)
            {
                return(base.RewriteTableRelation(node));
            }

            if (IsInstantiatedCommonTableExpression(node))
            {
                return(new BoundConstantRelation());
            }

            var outputValues      = node.GetOutputValues().ToImmutableArray();
            var instantiatedQuery = symbol.RecursiveMembers.Any()
                ? InstantiateRecursiveCommonTableExpression(outputValues, symbol)
                : InstantiateCommonTableExpression(outputValues, symbol);

            // For regular SELECT queries the output node will be a projection.
            // We don't need this moving forward so it's safe to omit.
            //
            // NOTE: We need to keep this after we added the output slot mapping.
            //       Otherwise the slots will not align.

            var projection = instantiatedQuery as BoundProjectRelation;
            var result     = projection == null ? instantiatedQuery : projection.Input;

            return(result);
        }
コード例 #2
0
        protected override BoundRelation RewriteTableRelation(BoundTableRelation node)
        {
            var definedValues = RemoveUnusedSlots(node.DefinedValues, d => d.ValueSlot);

            node = node.Update(node.TableInstance, definedValues);

            return(base.RewriteTableRelation(node));
        }
コード例 #3
0
 protected override void VisitTableRelation(BoundTableRelation node)
 {
     if (node.TableInstance.Table == _symbol)
     {
         Debug.Assert(_instance == null);
         _instance = node.TableInstance;
     }
     base.VisitTableRelation(node);
 }
コード例 #4
0
        private static ShowPlanNode BuildTable(BoundTableRelation node)
        {
            var properties = Enumerable.Empty <KeyValuePair <string, string> >();
            var children   = Enumerable.Empty <ShowPlanNode>();
            var name       = node.TableInstance.Table.Name;
            var columns    = string.Join(@", ", node.DefinedValues.Select(d => d.ValueSlot.Name));

            return(new ShowPlanNode($"Table ({name}), DefinedValues := {columns}", properties, children));
        }
コード例 #5
0
        private static Iterator BuildTable(BoundTableRelation relation)
        {
            var schemaTableSymbol = (SchemaTableSymbol)relation.TableInstance.Table;
            var tableDefinition   = schemaTableSymbol.Definition;
            var columnInstances   = relation.DefinedValues;
            var definedValues     = columnInstances.Select(ci => ci.Column)
                                    .Cast <SchemaColumnSymbol>()
                                    .Select(c => BuildColumnAccess(c.Definition));

            return(new TableIterator(tableDefinition, definedValues));
        }
コード例 #6
0
            protected override BoundRelation RewriteTableRelation(BoundTableRelation node)
            {
                if (!node.DefinedValues.Any())
                {
                    return(node);
                }

                var factory          = node.DefinedValues.First().ValueSlot.Factory;
                var original         = node.TableInstance;
                var valueSlotMapping = original.ColumnInstances.ToDictionary(c => c.Column, c => _valueSlotMapping[c.ValueSlot]);
                var instanceName     = factory.CreateNamed(original.Name, typeof(int)).Name;
                var instance         = new TableInstanceSymbol(instanceName, original.Table, (t, c) => valueSlotMapping[c]);
                var columnMapping    = instance.ColumnInstances.ToDictionary(c => c.Column);
                var definedValues    = node.DefinedValues.Select(d => columnMapping[d.Column]).ToImmutableArray();

                return(node.Update(instance, definedValues));
            }
コード例 #7
0
        private static CardinalityEstimate EstimateTableRelation(BoundTableRelation relation)
        {
            var tableSymbol = relation.TableInstance.Table as SchemaTableSymbol;

            if (tableSymbol == null)
            {
                return(CardinalityEstimate.Unknown);
            }

            var collection = tableSymbol.Definition.GetRows() as ICollection;

            if (collection == null)
            {
                return(CardinalityEstimate.Unknown);
            }

            return(new CardinalityEstimate(0, collection.Count));
        }