Vtctl Materialize optimizations#6207
Conversation
|
read PR w/ |
12f6bcb to
b217f5b
Compare
Signed-off-by: Toliver Jue <toliver@planetscale.com>
b217f5b to
368ccd3
Compare
rohit-nayak-ps
left a comment
There was a problem hiding this comment.
Other than the issue I commented about LGTM.
Nice, this should help greatly once we add --all to MoveTables as well!
go/vt/wrangler/materializer_test.go
Outdated
|
|
||
| err := env.wr.Materialize(context.Background(), ms) | ||
| assert.EqualError(t, err, "source and target table names must match for copying schema: t2 vs t1") | ||
| assert.EqualError(t, err, "copy: source tables do not exist: [t1].") |
There was a problem hiding this comment.
It is the target table that is missing, right? We are copying over "select * from t2" from source into t1 on target ... Validations have to take into account that we could have tables missing in the source or tables missing in the target where we are materializing to a different table ...
There was a problem hiding this comment.
I've split the test now into 2 cases, "copy" and not. "copy" still requires the same table name, and thus this is right error.
the other "non copy" case is a separate test, where CreateDdl="", and has the same original error.
go/vt/wrangler/materializer.go
Outdated
|
|
||
| if ts.CreateDdl == createDDLAsCopy { | ||
| needsCopy = true | ||
| copyTables[ts.TargetTable] = true |
There was a problem hiding this comment.
Target table and source table can be different, so the table to be copied will have to use sqlparser.TableFromStatement(ts.SourceExpression) if the source expression is present ...
Signed-off-by: Toliver Jue <toliver@planetscale.com>
|
@rohit-nayak-ps ptal. adjusted only the tests. the logic was still right, but the tests were not sufficiently granular previously. |
sougou
left a comment
There was a problem hiding this comment.
This feels a little over-complicated. Maybe you were not aware that you could GetSchema for all tables using []string{"/.*/"}.
What I would do is a full GetSchema for target outside the table loop.
For the source, I'd lazy-load a full GetSchema of source on first use, or even just load it upfront to keep it simple.
Then the existing code would be practically unchanged except for the additional logic for SourceExpression.
|
@sougou, I had wanted to keep So are you suggesting what I should change in this PR is just grabbing the whole schemas without making the sub table lists? The parsing of the table lists into maps would still be necessary, since we need to otherwise index on them. |
|
@sougou I've made the changes to grab and index the full schemas before going through the table loop. PTAL. |
c7564b7 to
b33f629
Compare
Signed-off-by: Toliver Jue <toliver@planetscale.com>
b33f629 to
9171b55
Compare
sougou
left a comment
There was a problem hiding this comment.
I was hoping it would be simpler, but the fact that the schema returned is not a map complicates this code a bit more.
We need a test to demonstrate the new behavior. After this, we're good to go.
go/vt/wrangler/materializer.go
Outdated
| if mz.targetVSchema.Keyspace.Sharded && mz.targetVSchema.Tables[ts.TargetTable].Type != vindexes.TypeReference { | ||
| cv, err := vindexes.FindBestColVindex(mz.targetVSchema.Tables[ts.TargetTable]) | ||
|
|
||
| if ts.SourceExpression != "" { |
There was a problem hiding this comment.
Change this to:
if ts.SourceExpression == "" {
continue
}
There was a problem hiding this comment.
but don't i still need to add to the Filter.Rules after this block?
There was a problem hiding this comment.
Oh. Right. Missed that. You can duplicate that append line here before continuing.
Main concern is that there are already too many indents. I'm not happy about the existing if-else block already.
There was a problem hiding this comment.
duped. also i pulled out the filter as default assign so that we can get rid of an else as well.
Signed-off-by: Toliver Jue <toliver@planetscale.com>
|
@sougou also what test are you proposing for this new behavior? that we don't get multiple requests for GetSchema in particular? |
Mainly one where the source expression is empty. |
Signed-off-by: Toliver Jue <toliver@planetscale.com>
8a9c6d2 to
ccdcb63
Compare
| filter = sqlparser.String(sel) | ||
| } | ||
|
|
||
| rule.Filter = filter |
sourceentries to be equivalent toselect * from table, as used by VReplication