protected void PrepareTableNode(Schema.DevicePlan plan, TableNode node) { node.CursorType = CursorType.Dynamic; node.RequestedCursorType = plan.Plan.CursorContext.CursorType; node.CursorCapabilities = CursorCapability.Navigable | CursorCapability.BackwardsNavigable | CursorCapability.Bookmarkable | CursorCapability.Searchable | (plan.Plan.CursorContext.CursorCapabilities & CursorCapability.Updateable); node.CursorIsolation = plan.Plan.CursorContext.CursorIsolation; }
// DetermineDevice public virtual void DetermineDevice(Plan plan) { // Recheck the NoDevice flag, as it will be set directly when a device-painted node has indicated not supported if (_nodes != null) { for (int index = 0; index < _nodes.Count; index++) { if (_nodes[index].NoDevice) { NoDevice = true; break; } } } if (!NoDevice) { _device = _potentialDevice; if (_device != null) { Schema.DevicePlan devicePlan = null; if (ShouldSupport) { plan.EnsureDeviceStarted(_device); devicePlan = _device.Prepare(plan, this); } if (devicePlan != null) { _deviceMessages = devicePlan.TranslationMessages; } if ((devicePlan != null) && devicePlan.IsSupported) { // If the plan could be supported via parameterization, it is not actually supported by the device // and setting the device supported to false ensures that if this node is actually executed, the // device will not be asked to perform a useless parameterization. DeviceSupported = !CouldSupport; } else { if (!_device.IgnoreUnsupported && (DataType != null) && !IgnoreUnsupported && !plan.InTypeOfContext) { if ((devicePlan != null) && !plan.SuppressWarnings) { plan.Messages.Add(new CompilerException(CompilerException.Codes.UnsupportedPlan, CompilerErrorLevel.Warning, _device.Name, SafeEmitStatementAsString(), devicePlan.TranslationMessages.ToString())); } } DeviceSupported = false; NoDevice = true; } } else { DeviceSupported = false; } } else { DeviceSupported = false; } }
protected override DevicePlanNode InternalPrepare(Schema.DevicePlan plan, PlanNode planNode) { if (planNode is BaseTableVarNode) { BaseTableVarNode node = (BaseTableVarNode)planNode; PrepareTableNode(plan, node); node.Order = Compiler.OrderFromKey(plan.Plan, Compiler.FindClusteringKey(plan.Plan, node.TableVar)); return(new DevicePlanNode(node)); } else if ((planNode is OrderNode) && (planNode.Nodes[0] is BaseTableVarNode) && (plan.Plan.CursorContext.CursorType != CursorType.Static)) { OrderNode node = (OrderNode)planNode; BaseTableVarNode tableVarNode = (BaseTableVarNode)planNode.Nodes[0]; Schema.Order tableOrder; bool isSupported = false; foreach (Schema.Key key in tableVarNode.TableVar.Keys) { tableOrder = Compiler.OrderFromKey(plan.Plan, key); if (node.RequestedOrder.Equivalent(tableOrder)) { node.PhysicalOrder = tableOrder; node.ScanDirection = ScanDirection.Forward; isSupported = true; break; } else if (node.RequestedOrder.Equivalent(new Schema.Order(tableOrder, true))) { node.PhysicalOrder = tableOrder; node.ScanDirection = ScanDirection.Backward; isSupported = true; break; } } if (!isSupported) { foreach (Schema.Order order in tableVarNode.TableVar.Orders) { if (node.RequestedOrder.Equivalent(order)) { node.PhysicalOrder = order; node.ScanDirection = ScanDirection.Forward; isSupported = true; break; } else if (node.RequestedOrder.Equivalent(new Schema.Order(order, true))) { node.PhysicalOrder = order; node.ScanDirection = ScanDirection.Backward; isSupported = true; break; } } } if (isSupported) { node.Order = new Schema.Order(); node.Order.MergeMetaData(node.RequestedOrder.MetaData); node.Order.IsInherited = false; Schema.OrderColumn orderColumn; Schema.OrderColumn newOrderColumn; for (int index = 0; index < node.PhysicalOrder.Columns.Count; index++) { orderColumn = node.PhysicalOrder.Columns[index]; newOrderColumn = new Schema.OrderColumn ( node.TableVar.Columns[orderColumn.Column], node.ScanDirection == ScanDirection.Forward ? orderColumn.Ascending : !orderColumn.Ascending ); newOrderColumn.Sort = orderColumn.Sort; newOrderColumn.IsDefaultSort = orderColumn.IsDefaultSort; Error.AssertWarn(newOrderColumn.Sort != null, "Sort is null"); node.Order.Columns.Add(newOrderColumn); } if (!node.TableVar.Orders.Contains(node.Order)) { node.TableVar.Orders.Add(node.Order); } PrepareTableNode(plan, node); PrepareTableNode(plan, tableVarNode); return(new DevicePlanNode(node)); } } else if (planNode is CreateTableVarBaseNode) { plan.Plan.CheckRight(GetRight(Schema.RightNames.CreateStore)); return(new DevicePlanNode(planNode)); } else if (planNode is AlterTableNode) { plan.Plan.CheckRight(GetRight(Schema.RightNames.AlterStore)); AlterTableNode alterTableNode = (AlterTableNode)planNode; if (alterTableNode.AlterTableStatement.CreateColumns.Count > 0) { throw new RuntimeException(RuntimeException.Codes.UnimplementedCreateCommand, "Columns in a memory device"); } if (alterTableNode.AlterTableStatement.DropColumns.Count > 0) { throw new RuntimeException(RuntimeException.Codes.UnimplementedDropCommand, "Columns in a memory device"); } return(new DevicePlanNode(planNode)); } else if (planNode is DropTableNode) { plan.Plan.CheckRight(GetRight(Schema.RightNames.DropStore)); return(new DevicePlanNode(planNode)); } plan.IsSupported = false; return(null); }