Skip to content

Vschema DDL: add column, drop column, show columns etc.#4711

Closed
inexplicable wants to merge 2 commits intovitessio:masterfrom
inexplicable:vschema
Closed

Vschema DDL: add column, drop column, show columns etc.#4711
inexplicable wants to merge 2 commits intovitessio:masterfrom
inexplicable:vschema

Conversation

@inexplicable
Copy link
Copy Markdown
Contributor

@inexplicable inexplicable commented Mar 7, 2019

ALTER VSCHEMA ON {table} ADD COLUMN {col} {type}
ALTER VSCHEMA ON {table} DROP COLUMN {col}
ALTER VSCHEMA ON {table} SET authoritative={TRUE|FALSE}
ALTER VSCHEMA ON {table} SET column_list_authoritative={TRUE|FALSE}
SHOW VSCHEMA COLUMNS ON {table}

Fixes #4641

@inexplicable inexplicable requested a review from sougou as a code owner March 7, 2019 04:40
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

per dweitzman
Nit: columns in a vindex is not necessarily authoritative. Depends whether the table is marked as having authoritative columns. Maybe something like "AddVschemaColStr" would be a more accurate name than "AddAuthColumnStr"

Copy link
Copy Markdown
Contributor

@sougou sougou left a comment

Choose a reason for hiding this comment

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

One question: why do we have two ways of specifying that column list is authoritative? Currently, in the vschema there is only one. We should match only one construct to that.

I vaguely remember a discussion with @demmer. And I think we're reserving the more generic is_authoritative for using when we fetch the schema from vttablet. We should wait till we implement that feature before introducing the new construct.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

per dweitzman
It seems like aligning the name here with the name in the vschema itself ("column_list_authoritative") would keep things more consistent.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree and don’t think we should support two types for the same setting.

Being verbose with column_list_authoritative is clearest.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

per dweitzman
For completeness it would probably make sense to have add column first and add column after , similar to table alters.

i don't see a usage of column ordering in vschema columns, and the ROI might be low since the long term goal is to let vtgate figure out the right schema itself.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since the only element we care about from column_definition is the type, I’d lean towards just parsing that and not the rest of the syntax.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

per dweitzman
Looks like today vitess doesn't need to know how to parse column information from alter ddls.
A question to consider: when adding support for parsing some detail from a vschema alter statement, is it worthwhile to try to align the AST with the direction it would go in if trying to support parsing mysql schema alter statements?
Here's the alter AST in the mysql 8 code, for reference: https://github.com/mysql/mysql-server/blob/8e797a5d6eb3a87f16498edcb7261a75897babae/sql/sql_alter.h#L168.

not seeing a column order use case in vschema columns, and since the longer term solution is to let vtgate figure out the correct schema cross shards themselves, i'm not going to implement that in this PR.

@inexplicable
Copy link
Copy Markdown
Contributor Author

@sougou i started off using authoritative, then @dweitzman suggested it to be aligned with the struct field naming column_list_authoritative, i guess i found that too wordy, and wanna keep a shorthand value. if we're going to land on is_authoritative, that should be fine, will just wait for this to be confirmed. and i'll make it a single option.

@sougou
Copy link
Copy Markdown
Contributor

sougou commented Mar 7, 2019

In that case, we should definitely not overload is_authoritative because the name is reserved for future use.

Copy link
Copy Markdown
Member

@demmer demmer left a comment

Choose a reason for hiding this comment

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

Overall this looks good to me pending the minor naming feedback above

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Minor nit — this isn’t a column name so something like setting would be clearer than colName

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Would also be good to have a test here with invalid params, like a non-boolean value and an unrecognized parameter name.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Copy Markdown
Collaborator

@dweitzman dweitzman Mar 11, 2019

Choose a reason for hiding this comment

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

This is not a comment on your PR, but something I'm noticing about sqltypes.Result in general while looking at this line:

It seems worthwhile to clarify at some point in sqltypes.Result's comments exactly when RowsAffected should and shouldn't be set. There seems to be an inconsistency in the codebase today about whether it's set for non-mutating queries like select and show.

My sense is that RowsAffected probably should not be set for show, select, explain, etc. No rows were "affected", and the row count is already available by looking at the rows themselves. It'd be kind of like having struct{rows []string; numRows int}, which is redundant since a slice already knows its own length.

In the vitess mysql protocol implementation the RowsAffected value is sometimes discarded in StreamExecute mode. I haven't looked at the mysql protocol yet to see what it returns in OK packets for select and show, though.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The current behavior mimics the behavior of the mysql clients, which has two modes: use_results and store_results. One is streaming and the other is all-at-once. The all-at-once case does set RowsAffected even for selects, but the all-at-once case doesn't. Since this is a client side behavior (which doesn't parse queries), it's likely that it doesn't differentiate between select, show, etc.

Right now, I think this is relevant only for grpc. There's probably no way to send this info when returning query results.

Copy link
Copy Markdown
Collaborator

@dweitzman dweitzman Mar 11, 2019

Choose a reason for hiding this comment

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

This helper is modeled after some existing helpers, but these similar-looking helpers look like they're multiplying. Could be cleaner to replace all the similar-ish wait logic with a single, more generic wait helper (not necessarily in this PR, though). Maybe something like this:

vschemaWaiter := makeVschemaWaiter(t, executor.serv, "aa")
_, _ := executor.Execute(... some vschema change ...)
vschema := vschemaWaiter()
// validate that the vschema looks as it should
// run another execute that changes the vschema
vschema = vschemaWaiter()
// validate again
// etc.

Where makeVschemaWaiter() might look something like:

// makeVschemaWaiter returns a function that gets the current vschema.
func makeVschemaWaiter(t testing.T, s svtopo.Server, cell string) func() *vschemapb.SrvVSchema {
    t.Helper()
	c := make(chan *vschemapb.SrvVSchema, 20)
    sentinel := &vschemapb.SrvVSchema{}
	s.WatchSrvVSchema(context.Background(), cell, func(v *vschemapb.SrvVSchema, err error) {
		c <- v
	})
    return func() *vschemapb.SrvVSchema {
       c <- sentinel
       var lastFound *vschemapb.SrvVSchema
       for {
          select {
            case found := <-c:
                if found == sentinel {
                  return lastFound
                }
                lastFound = found
            case <-time.After(100 * time.Millisecond):
                t.Error("Timeout waiting for vschema update")
                return nil
            }
       }
    }
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

make sense to me

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

hmm, 2nd thought, as the vschema ddl stuff is to be replaced, i don't want to spend too much renovation on the test case.

Copy link
Copy Markdown
Collaborator

@dweitzman dweitzman left a comment

Choose a reason for hiding this comment

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

I would prefer if this were squashed into a single commit or commit(s) with clear descriptions. For example, something in the spirit of:

vtgate executor: support vschema DDLs to add/remove/show columns and set is_column_authoritative

New syntax:
  ALTER VSCHEMA ON {table} ADD COLUMN {col} {type}
  ALTER VSCHEMA ON {table} DROP COLUMN {col}
  ALTER VSCHEMA ON {table} SET column_list_authoritative={TRUE|FALSE}
  SHOW VSCHEMA COLUMNS ON {table}

Fixes #4641

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Would probably be good to check err == nil || err.Error() != "the error string" here and in the next case to double-check the error text returned

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done & squashed into one commit

@sougou
Copy link
Copy Markdown
Contributor

sougou commented Mar 31, 2019

Is this ready? If so, @dweitzman: can you do a final once-over and merge?

@inexplicable
Copy link
Copy Markdown
Contributor Author

Is this ready? If so, @dweitzman: can you do a final once-over and merge?

yes, i believe the comments were all addressed (or reject 🤣 )

1. `ALTER VSCHEMA ON {table} ADD COLUMN {col} {type}`
2. `ALTER VSCHEMA ON {table} DROP COLUMN {col}`
3. `ALTER VSCHEMA ON {table} SET COLUMN_LIST_AUTHORITATIVE={TRUE|FALSE}`
4. `SHOW VSCHEMA COLUMNS ON {table}`

Signed-off-by: huiqing <hzhou@pinterest.com>
Signed-off-by: huiqing <hzhou@pinterest.com>
@sougou
Copy link
Copy Markdown
Contributor

sougou commented Apr 29, 2019

@dweitzman: waiting on your final approval.

@dkhenry
Copy link
Copy Markdown
Contributor

dkhenry commented Jun 28, 2019

May I request we update the title of this PR before its merged. Right now its not very descriptive

@sougou
Copy link
Copy Markdown
Contributor

sougou commented Aug 17, 2019

@inexplicable conflicts need merging, and @dkhenry requests a better title.

@morgo
Copy link
Copy Markdown
Contributor

morgo commented Feb 6, 2020

@inexplicable followup ping :-)

@deepthi deepthi changed the title PR for https://github.com/vitessio/vitess/issues/4641 Vschema DDL: add column, drop column, show columns etc. Jun 3, 2020
@deepthi deepthi closed this Jun 1, 2021
@deepthi deepthi deleted the branch vitessio:master June 1, 2021 23:13
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.

enhancement of vschema alter to better support authoritative columns list

8 participants