Add logic to use new symtab metadata about authoritative
tables to expand 'select *' expressions into the full
column list.
Signed-off-by: Sugu Sougoumarane <ssougou@gmail.com>
If this flag is set for a table, we'll treat the column list
as authoritative and expand select *.
Signed-off-by: Sugu Sougoumarane <ssougou@gmail.com>
This implementation follows the design from doc/VTGateSubqueries.md.
A new PulloutSubquery primitive has been created. Its action is to
execute a subquery, save the resulting value(s) in a bind variable,
and pass that down to the underlying primitive.
The type of value set depends on whether the subquery occurred in
an IN clause, etc. In the case of IN and NOT IN clauses, if the
list returned is empty, a guard variable is set to work around
the inability for IN clauses to handle an empty list syntax.
Subqueries can only be pulled out if they are not correlated.
Correlated subqueries will be handled when we add the
ability to execute expressions in VTGate.
Signed-off-by: Sugu Sougoumarane <ssougou@gmail.com>
rename and drop allow multiple tables in the DDL.
This change adds support for them.
* Introduced two new members to DDL: 'from' and 'to' table lists.
* NewName is deprecated.
* For single table DDLs, only Table is set.
* For multi-table DDLs, 'from' and 'to' tables are set as needed.
* The vttablet ddl plan had unused fields. They've been deleted.
* The permissions code has been updated to use the new table names.
Signed-off-by: Sugu Sougoumarane <ssougou@gmail.com>
Given the updated design whereby vtgate will return any shard
error as a warning, change the comment directive to more
intuitively express what the behavior is.
Signed-off-by: Michael Demmer <mdemmer@slack-corp.com>
This change adds a --dbname option to the vtexplain binary so that
callers can simulate what vtgate will do when the application connects
with a specific database name.
Add a test to show how this can be used to bypass the v3 routing and
send queries directly to a shard.
Signed-off-by: Michael Demmer <mdemmer@slack-corp.com>
Pinning was an internal feature used for pinning the
dual table to shard 0. Exposing this ability in vschema
allows someone to pin an unsharded table to a specific
shard.
This is still not a full feature because we ned to
think about the various use cases like resharding etc.
But it can be used for testing purposes.
Signed-off-by: Sugu Sougoumarane <ssougou@gmail.com>
When two parts of a query use the same unique vindex
values, we also have to check that they use the same
vindex.
Otherwise, we end up merging queries that use different
videxes but coincidentally have the same values.
I've consolidated all places that perform this check
and added the vindex check in that function.
Signed-off-by: Sugu Sougoumarane <ssougou@gmail.com>
The following fixes a bug where timeouts where not being properly propagated
when using limit or count clauses.
This needs to be done before the full route is wireup. Otherwise the type
pattern matching won't work.
Signed-off-by: Rafael Chacon <rafael@slack-corp.com>
Rework the implementation of passthrough DML mode so that it tries
to set the Table in the plan before returning.
This fixes an annoyance in which the per-table metrics don't properly
include DMLs in passthrough mode because they are generated dynamically
based on the table name in the plan stats.
Signed-off-by: Michael Demmer <mdemmer@slack-corp.com>
In cases of partitioned tables, mysql will include version-specific
comment directives in the output of a `show create table` command.
Add support in vtexplain to strip all the comments from the sql
schema prior to trying to parse so that it will simply ignore the
partition directives.
Signed-off-by: Michael Demmer <mdemmer@slack-corp.com>
Fixes#4007
Tabletserver was treating 'like' expressions as equality.
a like 'a%' is not the same as a = 'a%'.
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>
* Queries that include the QUERY_TIMEOUT_MS directive will timeout if execution
time exceeds the value provided in the directive.
* In this iteration, timeouts are only supported for selects. Once we do the
refactor of removing sql.Preview from the engine, it should be really straight
forward to refactor this code and support this feature for all statements.
* This feature can be used in the following way:
select /*vt+ QUERY_TIMEOUT_MS=1000 */ * from users
* Added integration test and validated locally that it works as expected.
* Queries that include the QUERY_TIMEOUT_MS directive will timeout.
* In this itereation, they are only supported for selects. Once we do the
refactor of removing sql.Preview from the engine, it should be really straight
forward to refactor this code and support for all statements.
* This feature can be used in the following way:
select /*vt+ QUERY_TIMEOUT_MS=1000 */ * from use
Signed-off-by: Rafael Chacon <rafael@slack-corp.com>
This was separated from the previous diff because it impacts query plans, although in seemingly-harmless way.
Signed-off-by: David Weitzman <dweitzman@pinterest.com>
A values expression is allowed to take a fully qualified (table.col),
but the current parser only allows unqualified columns. I have modified
the grammar, plan builder, and AST accordingly.
Signed-off-by: Daniel Tahara <tahara@dropbox.com>
To help debugging whether or not the comment was parsed properly, include
the boolean for MultiShardAutocommit in the plan JSON.
Signed-off-by: Michael Demmer <mdemmer@slack-corp.com>
* The following commit adds support to upsert statements when vindex column is
being set to the same value provided in the `VALUES`. e.g:
INSERT INTO table a,b VALUES ('a', 'b') on duplicate key update a=values(a)
* Remove unsuded parameter from isVindex changing function.
Signed-off-by: Rafael Chacon <rafael@slack-corp.com>
It works already in vtgate, just specific to vtexplain.
If you have a column name in all caps but code uses lowercase (or vice versa),
vtexplain will choke with something like:
unknown error: invalid column UPPIE
Just strings.ToLower() the column name.
Signed-off-by: Scott Lanning <scott.lanning@booking.com>
* Some general refactor of plan builders (move them to have their own files).
* Refactor parse destination code and put it in key package.
* Add general support for range queries in delete statements.
Signed-off-by: Rafael Chacon <rafael@slack-corp.com>