/// <remarks> Scan range keys are inclusive. </remarks> public Scan(ServerProcess AProcess, TableBuffer ATable, TableBufferIndex AAccessPath, ScanDirection ADirection, Row AFirstKey, Row ALastKey) { FProcess = AProcess; FTable = ATable; FAccessPath = AAccessPath; FDirection = ADirection; FFirstKey = AFirstKey; FLastKey = ALastKey; }
private bool IsSubset(Row ARow, TableBufferIndex AIndex) { foreach (Schema.Column LColumn in ARow.DataType.Columns) { if (!AIndex.KeyRowType.Columns.Contains(LColumn.Name) && !AIndex.DataRowType.Columns.Contains(LColumn.Name)) { return(false); } } return(true); }
// TODO: Compile row types for each index, saving column indexes to prevent the need for lookup during insert, update, and delete. private void InternalInitialize(ServerProcess AProcess) { Schema.RowType LKeyRowType; Schema.RowType LDataRowType; // Create the indexes required to store data as described by the given table type // Determine Fanout, Capacity, Clustering Key, KeyLength, DataLength FClusteringKey = TableVar.FindClusteringOrder(AProcess.Plan); //Schema.Key LClusteringKey = TableVar.FindClusteringKey(); //FClusteringKey = new Schema.Order(LClusteringKey, AProcess.Plan); LKeyRowType = new Schema.RowType(FClusteringKey.Columns); LDataRowType = new Schema.RowType(); foreach (Schema.Column LColumn in TableVar.DataType.Columns) { if (!FClusteringKey.Columns.Contains(LColumn.Name)) { LDataRowType.Columns.Add(new Schema.Column(LColumn.Name, LColumn.DataType)); } } // Add an internal identifier for uniqueness of keys in nonunique indexes #if USEINTERNALID FInternalIDColumn = new Schema.TableVarColumn(new Schema.Column(CInternalIDColumnName, AProcess.Plan.Catalog.DataTypes.SystemGuid), Schema.TableVarColumnType.InternalID); LDataRowType.Columns.Add(FInternalIDColumn.Column); #endif // Create the Clustered index FClusteredIndex = new TableBufferIndex ( AProcess, FClusteringKey, LKeyRowType, LDataRowType, true, FFanout, FCapacity ); Indexes.Add(FClusteredIndex); // DataLength and DataColumns for all non clustered indexes is the key length and columns of the clustered key LDataRowType = LKeyRowType; // Create non clustered indexes for each key and order (unique sets) Schema.Order LKey; foreach (Schema.Key LNonClusteredKey in TableVar.Keys) { if (!FClusteringKey.Includes(LNonClusteredKey)) { LKey = new Schema.Order(LNonClusteredKey, AProcess.Plan); if (!Indexes.Contains(LKey)) { LKeyRowType = new Schema.RowType(LKey.Columns); Indexes.Add ( new TableBufferIndex ( AProcess, LKey, LKeyRowType, LDataRowType, false, FFanout, FCapacity ) ); } } } foreach (Schema.Order LOrder in TableVar.Orders) { // This is a potentially non-unique index, so add a GUID to ensure uniqueness of the key in the BTree LKey = new Schema.Order(LOrder); #if USEINTERNALID if (!LKey.Includes(LClusteringKey)) { Schema.OrderColumn LUniqueColumn = new Schema.OrderColumn(FInternalIDColumn, true); LUniqueColumn.Sort = ((Schema.ScalarType)LUniqueColumn.Column.DataType).GetUniqueSort(AProcess.Plan); LKey.Columns.Add(LUniqueColumn); } #endif if (!Indexes.Contains(LKey)) { LKeyRowType = new Schema.RowType(LKey.Columns); Indexes.Add ( new TableBufferIndex ( AProcess, LKey, LKeyRowType, LDataRowType, false, FFanout, FCapacity ) ); } } }