-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
sql: allow creation of tables with no primary key #3286
Conversation
Can you file the other bugs you found? I'd really like for this to go in with the associated logic test enablement. |
@@ -126,7 +126,28 @@ func (p *planner) CreateTable(n *parser.CreateTable) (planNode, error) { | |||
// Inherit permissions from the database descriptor. | |||
desc.Privileges = dbDesc.GetPrivileges() | |||
|
|||
if err := desc.AllocateIDs(); err != nil { | |||
err = desc.AllocateIDs() | |||
if err == errMissingPrimaryKey { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of relying on this error, can you check for the presence of a primary key directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried that, and it sadly doesn't work. I duplicated the check in Validate
for no primary keys, but the fields it relies on to do that are populated near the end of AllocateIDs
, right before it calls Validate itself. Hence the double call to AllocateIDs in this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't follow; you can't do if len(desc.PrimaryIndex.ColumnNames) == 0
? The check in Validate
is checking that the IDs were assigned, but you can just look at the names here.
Sure, I'll file the other bugs. |
Review status: 0 of 2 files reviewed at latest revision, 5 unresolved discussions, some commit checks failed. sql/create.go, line 132 [r1] (raw file): sql/create.go, line 134 [r1] (raw file): sql/testdata/no_primary_key, line 10 [r1] (raw file): sql/testdata/no_primary_key, line 26 [r1] (raw file): Comments from the review on Reviewable.io |
Review status: 0 of 2 files reviewed at latest revision, 5 unresolved discussions. sql/create.go, line 132 [r1] (raw file): sql/create.go, line 134 [r1] (raw file): sql/testdata/no_primary_key, line 26 [r1] (raw file): Comments from the review on Reviewable.io |
err = desc.AllocateIDs() | ||
if err == errMissingPrimaryKey { | ||
// Ensure a Primary Key exists. | ||
s := "experimental_unique_int()" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: const s = "experimental_unique_int()"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, taking the address. That probably ruins it.
Review status: 0 of 2 files reviewed at latest revision, 6 unresolved discussions. sql/create.go, line 132 [r2] (raw file): Comments from the review on Reviewable.io |
Review status: 0 of 2 files reviewed at latest revision, 6 unresolved discussions. sql/create.go, line 132 [r2] (raw file): Comments from the review on Reviewable.io |
Review status: 0 of 2 files reviewed at latest revision, 6 unresolved discussions. sql/testdata/no_primary_key, line 10 [r1] (raw file): Comments from the review on Reviewable.io |
Review status: 0 of 2 files reviewed at latest revision, 6 unresolved discussions. sql/create.go, line 132 [r2] (raw file): Comments from the review on Reviewable.io |
Review status: 0 of 2 files reviewed at latest revision, 6 unresolved discussions. sql/create.go, line 130 [r1] (raw file): Line 246 in 28a6c07
Is where desc.PrimaryIndex.ColumnIDs is appended inside of the AllocateIDs func. The create function could go through and manually examine all indicies to see if any are primary, but it may be better to keep that logic in one place in AllocateIDs. Comments from the review on Reviewable.io |
Review status: 0 of 2 files reviewed at latest revision, 6 unresolved discussions. sql/testdata/no_primary_key, line 10 [r1] (raw file): Comments from the review on Reviewable.io |
Review status: 0 of 2 files reviewed at latest revision, 6 unresolved discussions. sql/create.go, line 132 [r2] (raw file): Comments from the review on Reviewable.io |
Review status: 0 of 2 files reviewed at latest revision, 6 unresolved discussions. sql/testdata/no_primary_key, line 10 [r1] (raw file): Comments from the review on Reviewable.io |
Review status: 0 of 2 files reviewed at latest revision, 6 unresolved discussions. sql/create.go, line 130 [r1] (raw file): Comments from the review on Reviewable.io |
Review status: 0 of 2 files reviewed at latest revision, 6 unresolved discussions. sql/testdata/no_primary_key, line 10 [r1] (raw file): Comments from the review on Reviewable.io |
Reviewed 1 of 2 files at r1, 1 of 2 files at r2, 1 of 1 files at r3. sql/create.go, line 132 [r1] (raw file): Comments from the review on Reviewable.io |
LGTM Review status: all files reviewed at latest revision, 3 unresolved discussions. sql/create.go, line 132 [r1] (raw file): Comments from the review on Reviewable.io |
Review status: 1 of 2 files reviewed at latest revision, 3 unresolved discussions. sql/create.go, line 130 [r1] (raw file): Comments from the review on Reviewable.io |
Review status: 1 of 2 files reviewed at latest revision, 3 unresolved discussions. sql/create.go, line 132 [r1] (raw file): Comments from the review on Reviewable.io |
Reviewed 1 of 1 files at r4. Comments from the review on Reviewable.io |
Review status: all files reviewed at latest revision, 3 unresolved discussions. sql/testdata/no_primary_key, line 38 [r4] (raw file): Comments from the review on Reviewable.io |
Review status: all files reviewed at latest revision, 3 unresolved discussions. sql/create.go, line 132 [r1] (raw file): Comments from the review on Reviewable.io |
Review status: 1 of 2 files reviewed at latest revision, 3 unresolved discussions, some commit checks pending. sql/create.go, line 132 [r1] (raw file): sql/testdata/no_primary_key, line 38 [r4] (raw file): Comments from the review on Reviewable.io |
Review status: 1 of 2 files reviewed at latest revision, 1 unresolved discussion. sql/create.go, line 132 [r1] (raw file): Comments from the review on Reviewable.io |
Review status: 1 of 2 files reviewed at latest revision, 1 unresolved discussion. sql/create.go, line 132 [r1] (raw file): Comments from the review on Reviewable.io |
Review status: 1 of 2 files reviewed at latest revision, 1 unresolved discussion. sql/create.go, line 132 [r1] (raw file): Comments from the review on Reviewable.io |
sql: allow creation of tables with no primary key
Reviewed 1 of 1 files at r5. Comments from the review on Reviewable.io |
fixes #2081