Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create explicit index object for Keys & ForeignKeys #3714

Closed
wants to merge 1 commit into from

Conversation

smitpatel
Copy link
Contributor

Resolves #700
Key & ForeignKey has Index object associated. IsUnique and IsClustered from key/foreignkey moved to index object.
Need review from @bricelam for Migrations & @AndriySvyryd for metadata.

/// </summary>
IIndex Index { get; }

/// <summary>
/// Gets a value indicating whether the values assigned to the foreign key properties are unique.
/// </summary>
bool IsUnique { get; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IsUnique should be removed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember it being the intention that foreign keys, which define relationships in our metadata, would no longer control whether the relationship is 1:1 or 1:*. Does this mean that you can no longer have a 1:1 relationship in the model without also having an index?

I think we should discuss in the design meeting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Foreign key does control the relationship is 1:1 or 1:* but it won't store the information with in itself. It will modify the associated index uniqueness appropriately. So you cannot have unique & non-unique FKs using same set of properties ( #3551 enables that scenario). It also mean that you can no longer have 1:1 relationship in the model without having unique index on same properties which is present situation in migration and database. All our relationships in database are non-unique regardless of FK's uniqueness. Correcting it exposed #3648 because we were inserting duplicate values in unique FK temporarily.

I will bring this to design meeting for further discussion.

@smitpatel smitpatel force-pushed the indexObject branch 2 times, most recently from a6f44b0 to cb53a5f Compare November 11, 2015 01:10
@bricelam
Copy link
Contributor

Migrations changes look good.

@@ -251,7 +251,8 @@ FOREIGN KEY (BuddyId) REFERENCES Friends(Id)
Assert.Equal(table.FindPrimaryKey(), fk.PrincipalKey);
}

[Fact]
// TODO: See issue #3710
//[Fact]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😢 Can you add this to #3710 to ensure it is re-enabled?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is reported on #3642 which is superseded by #3710

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@MarcoLoetscher
Copy link

@smitpatel
Copy link
Contributor Author

@MarcoLoetscher - regarding issues you mentioned,

  • As for unnecessary indexes, there won't be any. That is the reason for this code change. Essentially now every key & foreign key will have index object associated with it. And there can be only one index on a fixed set of properties. So if a key & a foreign key uses the same set of properties, there will be only one index for both of them. That should resolve out last 2 issues where PK & FK is on same set of properties. We will be creating only one index for that.
  • For the index subsumed by clustered key - By looking at the issue, I suppose the index on fk property is unnecessary because it is part of clustered key. Clustered key is SQL specific default for PK. Since EF7 targets other datastores also, the index on FK property may not be unnecessary.

@smitpatel smitpatel force-pushed the indexObject branch 2 times, most recently from 039b158 to 0b89341 Compare November 11, 2015 22:46
@@ -75,7 +75,8 @@ public static void ParseColumnDefinition(TableModel table, string statement)
return;
}

if (statement.IndexOf(" UNIQUE", StringComparison.OrdinalIgnoreCase) > 0)
if (statement.IndexOf(" UNIQUE", StringComparison.OrdinalIgnoreCase) > 0
|| statement.IndexOf(" PRIMARY KEY", StringComparison.OrdinalIgnoreCase) > 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe these changes fix #3642. Could you update that issue as well? The Design changes look good to me but I would get others to check the other changes.

@AndriySvyryd
Copy link
Member

:shipit: pending design discussion

@@ -90,7 +91,8 @@ public static void ParseColumnDefinition(TableModel table, string statement)
public static void ParseConstraints(TableModel table, string statement)
{
var constraint = statement.Split(' ', '(')[0];
if (constraint.Equals("UNIQUE", StringComparison.OrdinalIgnoreCase))
if (constraint.Equals("UNIQUE", StringComparison.OrdinalIgnoreCase)
|| statement.Equals(" PRIMARY KEY", StringComparison.OrdinalIgnoreCase))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests? I don't think this will work because of the space at the beginning of the string literal.

@smitpatel
Copy link
Contributor Author

closing this in favour of #3764

@smitpatel smitpatel closed this Nov 17, 2015
@bricelam bricelam deleted the indexObject branch November 30, 2015 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants