sql: add support for create index inside new schema#72610
sql: add support for create index inside new schema#72610craig[bot] merged 4 commits intocockroachdb:masterfrom
Conversation
8ab4ddc to
931a93c
Compare
| nodeDepEdgesFrom: map[*scpb.Node]*btree.BTree{}, | ||
| nodeDepEdgesTo: map[*scpb.Node]*btree.BTree{}, |
There was a problem hiding this comment.
my suggestion was that you get rid of the map altogether. You can iterate the prefix of the tree corresponding to this node.
postamar
left a comment
There was a problem hiding this comment.
I should have reviewed this the first time around, but better late than never. Thanks for doing this, I definitely appreciate the effort this must have involved.
I didn't look deeply into the scplan stuff because I mostly don't understand it deeply.
I did find a few things which seemed questionable to me and worth changing before merging. Fixing them should mostly be about moving stuff around so hopefully no big deal. Nits are things I just couldn't help noticing, feel free to disregard them if addressing them is a waste of your time.
| statement ok | ||
| CREATE INDEX id1 on defaultdb.t1(id, name) storing (money) PARTITION BY LIST (id) ( | ||
| PARTITION p1 VALUES IN (1) | ||
| ); |
pkg/sql/backfill.go
Outdated
| settings: settings, | ||
| ieFactory: ieFactory, | ||
| } | ||
| } |
There was a problem hiding this comment.
Shouldn't you be defining indexValidator in scdeps instead? That way you don't need to add the index validator to the exec cfg. It just seems simpler? Perhaps I'm missing something.
pkg/sql/schema_changer_ccl.go
Outdated
| settings: settings, | ||
| evalContext: evalContext, | ||
| } | ||
| } |
There was a problem hiding this comment.
Same comment as indexValidator really, I'm not sure why this all isn't in scdeps.
| } | ||
| res := tree.Serialize(modBuckets(hashedColumnsExpr())) | ||
| return &res | ||
| } |
There was a problem hiding this comment.
Why did this need to be moved here? Is it because of a dependency circularity issue? If not I'd be inclined to leave it where it was.
| } | ||
|
|
||
| if table.IsView() && !table.MaterializedView() { | ||
| panic(pgerror.Newf(pgcode.WrongObjectType, "%q is not a table or materialized view", &n.Table)) |
There was a problem hiding this comment.
This seems wrong, I believe you should be testing for !table.IsPhysicalTable() || table.IsSequence() and modify the error message accordingly.
| Index: *idx, | ||
| PrimaryIndex: newPrimaryIdxID, | ||
| }) | ||
| // Computed columns do not exist inside the primary index, |
There was a problem hiding this comment.
nit: I believe you mean Virtual computed columns?
| } | ||
| tabledesc.UpdateIndexPartitioning(indexDesc, false, newImplicitCols, newPartitioning) | ||
| return nil | ||
| } |
There was a problem hiding this comment.
Why is this defined as a method on txnDeps? Isn't the whole point of having d.partitioner.CreatePartitioning no dependencies would be required?
| } | ||
|
|
||
| // AddPartitioning implements the scmutationexec.CatalogReader interface. | ||
| func (s *TestState) AddPartitioning( |
| log.Errorf(ctx, "not implemented") | ||
| default: | ||
| panic("unimplemented") | ||
| } |
There was a problem hiding this comment.
nit: the logic in this switch case deserves to be refactored into functions, one per case.
| if err != nil { | ||
| return err | ||
| } | ||
| storeColNames = append(storeColNames, column.GetName()) |
There was a problem hiding this comment.
nit: define a private function to map a column ID to a name perhaps? As we grow the schema changer, patterns like these are going to keep emerging, and we should take care that this particular source file doesn't turn into an unwieldy mess.
931a93c to
19ff70c
Compare
19ff70c to
9df97f0
Compare
fqazi
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @ajwerner, @postamar, and @rhu713)
pkg/ccl/logictestccl/testdata/logic_test/new_schema_changer, line 12 at r4 (raw file):
Previously, postamar (Marius Posta) wrote…
formatting
Done.
pkg/sql/backfill.go, line 1658 at r4 (raw file):
Previously, postamar (Marius Posta) wrote…
Shouldn't you be defining
indexValidatorinscdepsinstead? That way you don't need to add the index validator to the exec cfg. It just seems simpler? Perhaps I'm missing something.
Done.
pkg/sql/schemachanger/scbuild/index.go, line 87 at r4 (raw file):
Previously, postamar (Marius Posta) wrote…
Why did this need to be moved here? Is it because of a dependency circularity issue? If not I'd be inclined to leave it where it was.
Yes, this was a circular dependency issue.
pkg/sql/schemachanger/scbuild/index.go, line 172 at r4 (raw file):
Previously, postamar (Marius Posta) wrote…
This seems wrong, I believe you should be testing for
!table.IsPhysicalTable() || table.IsSequence()and modify the error message accordingly.
The error was taken from regular CREATE INDEX should we do the same there?
pkg/sql/schemachanger/scbuild/index.go, line 176 at r4 (raw file):
Previously, postamar (Marius Posta) wrote…
nit: combine the two
ifs?
The second condition below also relies on it being materialized.
pkg/sql/schemachanger/scdeps/exec_deps.go, line 153 at r4 (raw file):
Previously, postamar (Marius Posta) wrote…
Why is this defined as a method on
txnDeps? Isn't the whole point of havingd.partitioner.CreatePartitioningno dependencies would be required?
Done.
pkg/sql/schemachanger/scdeps/sctestdeps/test_deps.go, line 453 at r4 (raw file):
Previously, postamar (Marius Posta) wrote…
Same comment as for
txnDeps.
Done.
pkg/sql/schemachanger/scgraph/graph.go, line 84 at r2 (raw file):
Previously, ajwerner wrote…
my suggestion was that you get rid of the map altogether. You can iterate the prefix of the tree corresponding to this node.
Done.
pkg/sql/schema_changer_ccl.go, line 60 at r4 (raw file):
Previously, postamar (Marius Posta) wrote…
Same comment as
indexValidatorreally, I'm not sure why this all isn't inscdeps.
Done.
9df97f0 to
8d73102
Compare
| visit = func(n *scpb.Node) { | ||
| permanent, marked := marks[n] | ||
| if marked && !permanent { | ||
| panic("not a dag") |
There was a problem hiding this comment.
Thoughts on catching this panic and converting it to an error and then having this method return an error?
| @@ -28,7 +31,19 @@ type MakeAddedIndexDeleteOnly struct { | |||
| TableID descpb.ID | |||
|
|
|||
| // Index represents the index as it should appear in the mutation. | |||
There was a problem hiding this comment.
This comment is now stale
| TableID descpb.ID | ||
|
|
||
| // Index is the descriptor as it should be added as part of the mutation. The | ||
| // IndexID is the descriptor as it should be added as part of the mutation. The |
| if this.Unique { | ||
| return &scop.ValidateUniqueIndex{ | ||
| TableID: this.TableID, | ||
| IndexID: this.IndexId, | ||
| } | ||
| } | ||
| return &scop.NoOpInfo{} |
There was a problem hiding this comment.
My preference is that we remove this optimization. The main reason is that today we validate all indexes, unique or otherwise. My secondary reason is that this NoOp smells a bit. Lastly, I think we'll want to represent not doing it elsewhere.
31079ec to
7317f74
Compare
7e9ff10 to
c28b27a
Compare
c28b27a to
b086829
Compare
ajwerner
left a comment
There was a problem hiding this comment.
Reviewed 1 of 60 files at r5, 3 of 33 files at r6, 3 of 52 files at r7, 1 of 8 files at r10, 6 of 33 files at r11, 25 of 54 files at r12, all commit messages.
Reviewable status:complete! 1 of 0 LGTMs obtained (waiting on @ajwerner, @fqazi, @postamar, and @rhu713)
Previously, the new schema changer attempted to use a bubble sort which compared the nodes linked to ops to generate an approximate order. Unfortunately, this approach had its limitations when it came to elements that had no edge linking them, which could lead to incorrect order relative to dependency edges. To address this, this patch moves the sorting to a simpler topological sort which guarantees dependency order. Release note: None
Fixes: cockroachdb#72562, cockroachdb#72561 Previously, when we updated the sorting inside the new schema changer to a rank based approach we incorrectly assumed that DepEdges will always be generated in a deterministic fashion. This does not happen because the database and rule matching is not fully determentistic. Unfortunately, this turned ouut to be false, which can lead to ranks for neighbour edges to be unstable. To address this, this patch iterates over DepEdges in a ordered fashion based on the To nodes, fixing intermittent failures inside the new schema changer tests. Release note: None
Fixes: cockroachdb#67264 Previously, create index was not supported inside the new shcema changer. This was inadequate because, to help support transaction schema changes in the future we need all schema changes inside the new schema changer. To address this, this patch adds CREATE INDEX inside the new schema changer. Release note: None
Previously, the unique index validation inside the new schema changer was stubbed out. This was inadequate because during index addition operations we were not properly confirming the unique constraints were properly implemented. To address this, this patch adds support in the new schema changer for the valdiation logic. Release note: None
b086829 to
c98800d
Compare
|
@ajwerner TFTR! |
|
bors r+ |
|
Build failed (retrying...): |
|
Build succeeded: |
Fixes: #67264
Previously, create index was not supported inside the
new schema changer. This was inadequate because to
help support transaction schema changes in the future
we need all schema changes inside the new schema changer.
To address this, this patch adds CREATE INDEX inside
the new schema changer.
Release note: None