private void CreateSecondaryIndex(Table table, SecondaryIndexInfo indexInfo) { if (indexInfo.KeyColumns.Count == 1) { var column = FindColumn(table, indexInfo.KeyColumns[0].Value.Name); if (driver.ServerInfo.DataTypes[column.DataType.Type].Features.Supports(DataTypeFeatures.Spatial)) { var spatialIndex = table.CreateSpatialIndex(indexInfo.Name); spatialIndex.CreateIndexColumn(column); return; } } var index = table.CreateIndex(indexInfo.Name); index.IsUnique = indexInfo.IsUnique; index.IsClustered = indexInfo.IsClustered; foreach (var keyColumn in indexInfo.KeyColumns) { index.CreateIndexColumn( FindColumn(table, keyColumn.Value.Name), keyColumn.Direction == Direction.Positive); } index.NonkeyColumns.AddRange( indexInfo.IncludedColumns .Select(cr => FindColumn(table, cr.Value.Name)).ToArray()); if (indexInfo.Filter != null) { index.Where = SqlDml.Native(indexInfo.Filter.Expression); } }
/// <inheritdoc/> protected override IPathNode VisitIndex(Index index) { var tableInfo = currentTable; var secondaryIndexInfo = new SecondaryIndexInfo(tableInfo, index.Name) { IsUnique = index.IsUnique, IsClustered = index.IsClustered, Filter = GetFilter(index), }; foreach (var keyColumn in index.Columns) { var columnInfo = tableInfo.Columns[keyColumn.Column.Name]; new KeyColumnRef(secondaryIndexInfo, columnInfo, keyColumn.Ascending ? Direction.Positive : Direction.Negative); } foreach (var valueColumn in index.NonkeyColumns) { var columnInfo = tableInfo.Columns[valueColumn.Name]; new IncludedColumnRef(secondaryIndexInfo, columnInfo); } secondaryIndexInfo.PopulatePrimaryKeyColumns(); return(secondaryIndexInfo); }
public void CreateModel() { storage = new StorageModel("storage1"); table = new TableInfo(storage, "table"); primary = new PrimaryIndexInfo(table, "primary1"); secondary = new SecondaryIndexInfo(table, "secondary1"); primaryKey = new StorageColumnInfo(table, "key", new StorageTypeInfo(typeof(int), null)); primaryValue1 = new StorageColumnInfo(table, "value1", new StorageTypeInfo(typeof(int), null)); primaryValue2 = new StorageColumnInfo(table, "value2", new StorageTypeInfo(typeof(int), null)); new KeyColumnRef(primary, primaryKey, Direction.Positive); new ValueColumnRef(primary, primaryValue1); new ValueColumnRef(primary, primaryValue2); }
public void CreateModel() { storage = new StorageModel("STORAGE") { Actions = new ActionSequence() }; table = new TableInfo(storage, "TABLE"); primary = new PrimaryIndexInfo(table, "PK"); secondary = new SecondaryIndexInfo(table, "IX"); primaryKey = new StorageColumnInfo(table, "ID", new StorageTypeInfo(typeof(int), null)); primaryValue1 = new StorageColumnInfo(table, "AGE", new StorageTypeInfo(typeof(int), null)); primaryValue2 = new StorageColumnInfo(table, "NAME", new StorageTypeInfo(typeof(int), null)); new KeyColumnRef(primary, primaryKey, Direction.Positive); new ValueColumnRef(primary, primaryValue1); new ValueColumnRef(primary, primaryValue2); new KeyColumnRef(secondary, primaryValue1, Direction.Positive); storage.Dump(); }
private SecondaryIndexInfo CreateSecondaryIndex(TableInfo owningTable, string indexName, IndexInfo originalModelIndex) { var index = new SecondaryIndexInfo(owningTable, indexName); if (originalModelIndex.Filter != null) { if (providerInfo.Supports(ProviderFeatures.PartialIndexes)) { index.Filter = new PartialIndexFilterInfo(compiler.Compile(handlers, originalModelIndex)); } else { UpgradeLog.Warning( Strings.LogStorageXDoesNotSupportPartialIndexesIgnoringFilterForPartialIndexY, providerInfo.ProviderName, originalModelIndex); } } return(index); }
public void BuildStorageModel() { storage = new StorageModel("storage"); referencingTable = new TableInfo(storage, "referencingTable"); var pkColumn = new StorageColumnInfo(referencingTable, "Id", new StorageTypeInfo(typeof(int), null)); var fkColumn = new StorageColumnInfo(referencingTable, "foreignId", new StorageTypeInfo(typeof(int?), null)); var fkColumn2 = new StorageColumnInfo(referencingTable, "invalideForeignId", new StorageTypeInfo(typeof(string), null)); var primaryKey = new PrimaryIndexInfo(referencingTable, "PK1"); new KeyColumnRef(primaryKey, pkColumn); referencingIndex = new SecondaryIndexInfo(referencingTable, "FK"); new KeyColumnRef(referencingIndex, fkColumn); referencingIndex.PopulatePrimaryKeyColumns(); invalideReferencingIndex = new SecondaryIndexInfo(referencingTable, "FK2"); invalideReferencingIndex.PopulatePrimaryKeyColumns(); new KeyColumnRef(invalideReferencingIndex, fkColumn2); primaryKey.PopulateValueColumns(); referencedTable = new TableInfo(storage, "referencedTable"); pkColumn = new StorageColumnInfo(referencedTable, "Id", new StorageTypeInfo(typeof(int), null)); foreignPrimary = new PrimaryIndexInfo(referencedTable, "Id"); new KeyColumnRef(foreignPrimary, pkColumn); }
public void CreateModel() { storage = new StorageModel("storage") { Actions = new ActionSequence() }; // Table 1 table1 = new TableInfo(storage, "table1"); pi1 = new PrimaryIndexInfo(table1, "pk1"); column1 = new StorageColumnInfo(table1, "col1", new StorageTypeInfo(typeof(string), null, false)); column2 = new StorageColumnInfo(table1, "col2", new StorageTypeInfo(typeof(string), null)); column3 = new StorageColumnInfo(table1, "col3", new StorageTypeInfo(typeof(string), null)); new KeyColumnRef(pi1, column1, Direction.Positive); pi1.PopulateValueColumns(); si1 = new SecondaryIndexInfo(table1, "ix1"); new KeyColumnRef(si1, column2, Direction.Positive); si1.PopulatePrimaryKeyColumns(); // Table 2 table2 = new TableInfo(storage, "table2"); pi2 = new PrimaryIndexInfo(table2, "pk2"); column4 = new StorageColumnInfo(table2, "col4", new StorageTypeInfo(typeof(int), null)); column5 = new StorageColumnInfo(table2, "col5", new StorageTypeInfo(typeof(string), null)); new KeyColumnRef(pi2, column4, Direction.Negative); pi2.PopulateValueColumns(); si2 = new SecondaryIndexInfo(table2, "ix2"); new KeyColumnRef(si2, column5, Direction.Positive); si2.PopulatePrimaryKeyColumns(); // Foreign keys fk1 = new ForeignKeyInfo(table2, "fk1") { PrimaryKey = pi1 }; fk1.ForeignKeyColumns.Set(si2); }
private static StorageInfo CreateSimpleStorageModel() { var storage = new StorageInfo("Storage"); // Model: // class A:Entity {int Id, int Data} // class B:A {int Id} // class C:B {int Id; A RefA; B RefB; C RefC} var tA = new TableInfo(storage, "A"); var tB = new TableInfo(storage, "B"); var tC = new TableInfo(storage, "C"); var idA = new ColumnInfo(tA, "Id", new TypeInfo(typeof(int))); var idB = new ColumnInfo(tB, "Id", new TypeInfo(typeof(int))); var idC = new ColumnInfo(tC, "Id", new TypeInfo(typeof(int))); var refCA = new ColumnInfo(tC, "RefA", new TypeInfo(typeof(int))); var refCB = new ColumnInfo(tC, "RefB", new TypeInfo(typeof(int))); var refCC = new ColumnInfo(tC, "RefC", new TypeInfo(typeof(int))); var dataA = new ColumnInfo(tA, "Data", new TypeInfo(typeof(int))); var pkA = new PrimaryIndexInfo(tA, "PK_A"); var pkB = new PrimaryIndexInfo(tB, "PK_B"); var pkC = new PrimaryIndexInfo(tC, "PK_C"); new KeyColumnRef(pkA, idA); new KeyColumnRef(pkB, idB); new KeyColumnRef(pkC, idC); pkC.PopulateValueColumns(); pkA.PopulateValueColumns(); var ixRefCA = new SecondaryIndexInfo(tC, "FK_CRefA"); new KeyColumnRef(ixRefCA, refCA); ixRefCA.PopulatePrimaryKeyColumns(); var ixRefCB = new SecondaryIndexInfo(tC, "FK_CRefB"); new KeyColumnRef(ixRefCB, refCB); ixRefCB.PopulatePrimaryKeyColumns(); var ixRefCC = new SecondaryIndexInfo(tC, "FK_CRefC"); new KeyColumnRef(ixRefCC, refCC); ixRefCC.PopulatePrimaryKeyColumns(); var fkCRefA = new ForeignKeyInfo(tC, "FK_CRefA"); fkCRefA.PrimaryKey = pkA; fkCRefA.ForeignKeyColumns.Set(ixRefCA); var fkCRefB = new ForeignKeyInfo(tC, "FK_CRefB"); fkCRefB.PrimaryKey = pkB; fkCRefB.ForeignKeyColumns.Set(ixRefCB); var fkCRefC = new ForeignKeyInfo(tC, "FK_CRefC"); fkCRefC.PrimaryKey = pkC; fkCRefC.ForeignKeyColumns.Set(ixRefCC); var fkCA = new ForeignKeyInfo(tC, "FK_CA"); fkCA.PrimaryKey = pkA; fkCA.ForeignKeyColumns.Set(pkC); var fkBA = new ForeignKeyInfo(tB, "FK_BA"); fkBA.PrimaryKey = pkA; fkBA.ForeignKeyColumns.Set(pkB); storage.Validate(); return(storage); }
private static StorageInfo CreateSimpleStorageModel() { var storage = new StorageInfo("Storage"); // Types table var t = new TableInfo(storage, "Types"); var tId = new ColumnInfo(t, "Id") { Type = new TypeInfo(typeof(int), false) }; var tValue = new ColumnInfo(t, "Value") { Type = new TypeInfo(typeof(string), 1024) }; var tData = new ColumnInfo(t, "Data") { Type = new TypeInfo(typeof(byte[]), 1024 * 1024) }; var tiPk = new PrimaryIndexInfo(t, "PK_Types"); new KeyColumnRef(tiPk, tId); tiPk.PopulateValueColumns(); var tiValue = new SecondaryIndexInfo(t, "IX_Value"); new KeyColumnRef(tiValue, tValue); tiValue.PopulatePrimaryKeyColumns(); var tiFt = new FullTextIndexInfo(t, "FT_Index"); new FullTextColumnRef(tiFt, tValue); // Objects table var o = new TableInfo(storage, "Objects"); var oId = new ColumnInfo(o, "Id") { Type = new TypeInfo(typeof(long), false) }; var oTypeId = new ColumnInfo(o, "TypeId") { Type = new TypeInfo(typeof(int), false) }; var oValue = new ColumnInfo(o, "Value") { Type = new TypeInfo(typeof(string), 1024) }; var oiPk = new PrimaryIndexInfo(o, "PK_Objects"); new KeyColumnRef(oiPk, oId); oiPk.PopulateValueColumns(); var oiTypeId = new SecondaryIndexInfo(o, "IX_TypeId"); new KeyColumnRef(oiTypeId, oTypeId); oiTypeId.PopulatePrimaryKeyColumns(); var oiValue = new SecondaryIndexInfo(o, "IX_Value"); new KeyColumnRef(oiValue, oValue); new IncludedColumnRef(oiValue, oTypeId); oiValue.PopulatePrimaryKeyColumns(); var ofkTypeId = new ForeignKeyInfo(o, "FK_TypeId") { PrimaryKey = tiPk, }; ofkTypeId.ForeignKeyColumns.Set(oiTypeId); storage.Validate(); return(storage); }