Skip to content

v3: support database() function#3998

Merged
sougou merged 1 commit intovitessio:masterfrom
sougou:selectdb
Jun 8, 2018
Merged

v3: support database() function#3998
sougou merged 1 commit intovitessio:masterfrom
sougou:selectdb

Conversation

@sougou
Copy link
Copy Markdown
Contributor

@sougou sougou commented Jun 2, 2018

Fixes #3954
This is an alternate PR to #3962. The implementation is less
efficient, but more correct. This allows you to use the
database() call anywherei in the sql, and v3 will substitute
it to the actual target string.

If necessary, we can add an optimization that won't send the
query to the vttablets.

Signed-off-by: Sugu Sougoumarane ssougou@gmail.com

Fixes #3954
This is an alternate PR to #3962. The implementation is less
efficient, but more correct. This allows you to use the
database() call anywherei in the sql, and v3 will substitute
it to the actual target string.

If necessary, we can add an optimization that won't send the
query to the vttablets.

Signed-off-by: Sugu Sougoumarane <ssougou@gmail.com>
@sougou
Copy link
Copy Markdown
Contributor Author

sougou commented Jun 2, 2018

@tirsen to review

return false, errors.New("unsupported: LAST_INSERT_ID is only allowed for unsharded keyspaces")
}
case node.Name.EqualString("database"):
expr = sqlparser.ReplaceExpr(expr, node, sqlparser.NewStrVal([]byte(pb.vschema.TargetString())))
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.

vschema contains the current target in the session? 0_o


// TargetString returns the current TargetString of the session.
func (vc *vcursorImpl) TargetString() string {
return vc.safeSession.TargetString
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.

I see

@tirsen
Copy link
Copy Markdown
Collaborator

tirsen commented Jun 6, 2018

Which vttablet is this sent to? We don't need to optimize around that if it's too much hassle. We don't use it that frequently.

@sougou
Copy link
Copy Markdown
Contributor Author

sougou commented Jun 8, 2018

it's sent to the 'first' keyspace. There's some algorithm that decides which is the first one.

@sougou sougou merged commit b374cd6 into vitessio:master Jun 8, 2018
@sougou sougou mentioned this pull request Jun 8, 2018
@sougou sougou deleted the selectdb branch June 10, 2018 21:06
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.

2 participants