Граф коммитов

272 Коммитов

Автор SHA1 Сообщение Дата
Bryan Beaudreault 863caf0f55 REPLACE INTO take 2 (#2828)
* Support REPLACE INTO for unsharded tables

* merge fixes

* Make REPLACE INTO use PASS_DML

* Fix tests

* update tests

* add replace support to preview

* Remove unneeded tests now that PASS_DML. Add test of PASS_DML/RBR for Replace
2017-05-06 12:48:15 -07:00
Sugu Sougoumarane a0ca6d8217 v3: fix UNION merge logic
UNION mergeability was previously using the same logic as
subquery mergeability. It turns out that it doesn't always
work because subqueries can have outer query dependencies
whereas unions don't have such relationship. So, the logic
has now been separated.
2017-05-05 23:05:18 -07:00
Sugu Sougoumarane 030dd9ca64 v3: support direct calls to sequence 2017-05-05 01:46:11 -07:00
Sugu Sougoumarane eef00cb3bf v3: change SHOW to not use engine 2017-05-04 00:00:14 -07:00
Alex Charis feb4ad5bf8 addressing review comments:
- increased test coverage
 - revert route to pre-union-shenanigan state
2017-04-03 16:48:48 -07:00
Alex Charis 6ccff82adb add tests for order by and limit on unions, handle those constructs in unsharded unions 2017-04-03 16:48:48 -07:00
Alex Charis bb1277f24d remove cross-shard union; fix up tests 2017-04-03 16:48:48 -07:00
Alex Charis 39355c3bb3 increased test coverage 2017-04-03 16:48:48 -07:00
Alex Charis 31e7a37356 trivial: test fixup
initial WIP union commit

WIP: non-compiling, known not done; before branch for planbuilder.route.Select->SelectStatement type change

WIP checkpoint

WIP checkpoint...compiles

WIP on merge primitive

trivial test fix

support UNION in subqueries

preliminary tests

tests, responses to PR comments

copy queryConstruct to avoid data race

added tests for unsharded union

union distinct in unsharded cases; default in switch in from.go
2017-04-03 16:48:48 -07:00
Alain Jobart 54d19dd243 Merge pull request #2639 from HubSpot/auth-server-ldap
WIP: AuthServerLdap
2017-03-29 07:56:01 -07:00
Sugu Sougoumarane 0fc4ef137f parser: improved UNION constructs
This change allows two extensions to the SQL syntax:
1. UNION statements can be followed by ORDER BY, LIMIT and LOCK clauses.
2. SELECT statements that are part of a UNION can be parenthesized.

The main purpose of allowing parenthesis for selects was to
support the following two constructs: (SELECT...) UNION (SELECT...)
and INSERT INTO a (SELECT...).

The initial approach was to allow parenthesizing of all SELECT
statements. However, just adding that as an additional rule
created conflicts. In particular, `((SELECT * FROM t))` could
be seen as a subquery with a parenthesized select, or a row
tuple with a subquery. We've avoided this conflict by allowing
parenthesis only for selects that are part of a union.

This change allows you to do the UNION construct. Additionally,
we go one step further and allow ORDER BY and LIMIT clauses
for unions which we didn't allow before. The tabletserver
planbuilder has also been extended accordingly. VTGate
support of unions will also need to be extended.

The construct for inserts will be addresed in the next PR.

If necessary, we could allow the top level statement to be
parenthesized, but that has no practical value. So, we can
skip that for now.

For now, the current grammar has 1 shift/reduce conflict, which will
be resolved once the support for the INSERT...(SELECT...) is added.
2017-03-27 10:14:08 -07:00
Alex Charis 51954a38a0 fixup ldap config example file 2017-03-24 15:21:39 -04:00
Alex Charis 573aaf573d refactor LDAP-backed ACLs
vtgate now gets the groups and sends them in the immediate caller id.
we store the time of the ldap query and refresh (in another goroutine) if
older than configurable threshold. this happens upon ComQuery. the simpleacl
implementation is now group aware, and the ldapacl plugin has been removed.
2017-03-24 10:06:47 -04:00
Alex Charis 801f8b6a97 implemented ldap backend for vttablet ACLs as a plugin
refactored ldap connection as a library
trivial change to testlib
2017-03-24 10:04:07 -04:00
Alex Charis 1418695b7c test use of ldap client via mock 2017-03-24 10:04:07 -04:00
Alex Charis b631a690ba added mysql server auth ldap config json example file 2017-03-24 10:04:07 -04:00
Michael Demmer a2365df280 fix unit test for show cases 2017-03-22 14:17:35 -07:00
Michael Demmer 37574bdf83 add preliminary vtgate support for show commands
This currently supports `show databases` and `show vitess_schemas`.
2017-03-22 14:17:35 -07:00
Michael Berlin 2c2fa7c982 vttablet: Hot Row protection for Transaction Pool.
During BeginExecute() do not start a second transaction if another BeginExecute() for the same row is already in progress. This avoids that updates targeted for a single row can consume all transaction pool slots.

Note that the serialization is bound to the lifetime of the BeginExecute() call and not to the lifetime of the transaction. This made the implementation simpler since no additional plumbing was required. Due to the additional MySQL locking, this should result into two transaction pool slots per row at most. (One pending on COMMIT, one waiting for MySQL in BEGIN+EXECUTE.) If this is not effective enough, we will have to revise this decision.

By default it is disabled.

It can be fully enabled (-enable_hot_row_protection) or enabled in dry-run mode (-enable_hot_row_protection_dry_run). If one of the two flags is specified, most of the code will be exercised. If none of the two flags is set, the code will be completely skipped.

The list of the last 1000 queries which triggered the hot row protection are available at /hotrows on the vttablet HTTP port.

Other change:
- Extended fakesqldb to run a callback before it responds to MySQL. This is required to properly synchronize the concurrent transactions. Without, they may not race and not get serialized.
2017-03-22 16:35:10 +01:00
Bryan Beaudreault e2f97f875b WIP -- Working to support migration-scoped queries from VTGate (#2606)
* Reload schemas on all DDLs. Support table qualifiers in DDL queries.

* For now only support table_name in non-create because the lookahead conflicts with force_eof

* create tables cant have a row count, so no point checking. This avoids an NPE on Table.Name, since creates are the only one to only have a NewName

* Make table_name work for CREATE and VIEWs. Fix alter view test, the syntax in the test failed to parse and was incorrect according to docs

* This test does not apply since the removal of TableWasDropped

* If we're in a transaction, don't start a new one

* Reload schema on commit, if necessary

* recycle connection when using transaction

* utilize existing autocommit function

* simplify

* unneeded function

* If an transaction is open, we should commit it before running the DDL -- DDL's have an implicit commit.

* implement and use BeginAgain when we implicit commit a running transaction due to DDL

* Move BeginAgain to TxConnection

* dont lowercase qualifier
2017-03-03 18:38:52 -08:00
Bryan Beaudreault 76f790fc1e Adding support to parser for a few more constructs (#2515)
* a few parser additions:
- DATE Function
- LIKE pattern ESCAPE char syntax
- && as AND
- Charset Introducers on integral values
- pound-sign comments
- INSERT with no values
- support all keywords as identifiers where possible

* simplify

* Add to WalkSubtree
2017-02-14 23:47:42 -08:00
Bryan Beaudreault 72d88880e0 WIP - Unify boolean expression and value expression grammars (#2505)
* Sample parser change: take 2

* more work to integrate booleans and values:
 - unify all the BoolExpr and ValExpr as just Expr
 - unify the tuples to avoid grammar conflicts
2017-01-27 13:37:53 -08:00
Bryan Beaudreault 6c74371253 Support VALUES() construct in parser and rewrite for upsert query (#2479) 2017-01-26 20:36:38 -08:00
Amit Khare 061648944e Collate support (#2502)
* Adding collate operator support

* Adding collate operator support

* Changing to ComparisonExpr

* Changing to ComparisonExpr

* Revert to BinaryExpr

* moving to collate value_expression

* reverting to value

* changing to ```value_expression COLLATE value_expression```

* remove PK - 4 from main_test

* removed z from lowezr

* fixing reviews by sugu

* fixing reviews by sugu

* adding tests per http://dev.mysql.com/doc/refman/5.7/en/charset-collate.html

* adding tests per http://dev.mysql.com/doc/refman/5.7/en/charset-collate.html

* support for OR operator without it being used for concatenation

* remove OR_PIPE and reuse OR

* order by complex expression

* revert order by complex expression

* revert order by complex expression

* collation support

* collation support

* collation support

* collation support

* simplify yacc for collation

* adding tests for order by

* handling one more test case of order by column number with collate

* fixing recommendations from sugu

* fixing recommendations from sugu
2017-01-25 10:46:13 -08:00
Sugu Sougoumarane d2e61b2442 messages: WIP
Tying most of the tabletserver pieces together:
* Changed insert plan. It's easier to read the row from the
db than to try to build it in memory. The read should be
efficient because we're just pulling it from the buffer cache.
* DML plan. DMLs on the message table should invalidate the cache.
* Make sure id is part of the pk. We need it for the DMLs.
* Update the cache on commit.
* tabletserver endtoend test.
2017-01-23 17:03:27 -08:00
Sugu Sougoumarane 8417b63726 messages: WIP
Address review comments & fix tests.
2017-01-23 17:03:27 -08:00
Sugu Sougoumarane 6701226c79 messages: WIP
* Message table type in schema
* Plan bulding and execution for message table inserts
2017-01-23 17:03:27 -08:00
Bryan Beaudreault 4f9649b696 adds support for OFFSET keyword (#2460) 2017-01-17 10:20:51 -08:00
Bryan Beaudreault a7a1f250d6 INTO is not required for inserts (#2459) 2017-01-17 08:48:17 -08:00
Bryan Beaudreault d6465c000a Include on clauses in impossible queries, to avoid only_full_group_by in aggregations with joins (#2433)
* Include on clauses in impossible queries, to avoid only_full_group_by in aggregations with joins

* remove now-unnecessary handling of left/right join. fix endtoend tests
2017-01-03 19:29:54 -08:00
Bryan Beaudreault 2a12d48560 Refactor impossible query generation, and support group by - (#2409)
When a group by is available, ensure it's part of field query to avoid issues with aggregations
Refactor to use a unified code path between vtgate and vttablet
2017-01-03 13:48:56 -08:00
Sugu Sougoumarane aacd748e52 v3: query normalization WIP
Separate out NUMBER into INTEGRAL and FLOAT so we can build
better bind vars out of them.
2016-12-27 16:56:55 -08:00
Sugu Sougoumarane b415846e7b v3: improved symtab resolution
Addresses: #1861.
The new resolution algorithm better mimics MySQL behavior: GROUP BY,
HAVING and ORDER BY search column aliases as well as table names.
It's not possible to exactly mimic MySQL's behavior without knowledge
of the full schema. However, such cases happen only if the SQL attempts
to hide table column names with column aliases, which is uncommon
and not recommended.
The most common application constructs where the post-process constucts
reference table columns should now work.
2016-12-22 09:48:34 -08:00
Sugu Sougoumarane 7a94112b40 v3: support for ',' joins
Addresses #2373.
',' operators will now be allowed for joins. They will be treated
as JOIN operators without an ON clause. This will work for unsharded
joins as well as cross-shard joins. For now, we will not look for
join conditions in the WHERE clause to identify single-shard queries.
2016-12-20 21:26:55 -08:00
Sugu Sougoumarane 55dd9a9fa9 parser: support a.b.* construct
Previously, the '*' construct allowed only a.*.
2016-12-20 14:06:42 -08:00
Sugu Sougoumarane bcf404110c backtick: fix all `%s` usage
Printf formatting doesn't work for names that themselves
contain backticks. Since we now have a function that esacapes
those correctly, I've changed all places to use the new function.
2016-12-20 14:06:42 -08:00
Sugu Sougoumarane 3187e5ab16 backtick: actual support
Tokenizer has been changed to allow.
AST has been changed to escape correctly.
All bind vars use CompliantName function.
Made col & table ref matching mimic MySQL's behavior: When
qualified names are used, keyspace & table names have to be
cases sensitive, and col names have to be insensitive.
2016-12-20 00:14:59 -08:00
Sugu Sougoumarane b70431a502 backtick: use TableIdent everywhere
Table names are mostly stored as TableIdent. This allows for
better tracking of where it's used, and making sure that
we escape it correctly, and more easily add special handling
in the future as necessary.
2016-12-20 00:14:59 -08:00
Ashu 71979f13f2 Multirow insert (#2342)
* MultiRow Insert with different KeyspaceIds

* Fixing the Router Tests

* Rewrite Queries using the Rows Object

* Making Separate Changes for InsertSharded and Fixing Tests

* Fixing Tests in router_dml_test.go

* Fixing PlanBuilder TestCases

* Refactoring Code for MultiRowInsert

* Incorporating Changes as discussed today

* Incorporating Review Comments as discussed

* Incorporating Review Comments as discussed

* Incorporating Review Comments as discussed

* Resolving Merge Conflicts

* Resolving Merge Conflicts

* fixing the Values Format

* Incorporating Review Comments and Removing ExecuteMulti

* Refactoring getInsertShardedRoute() and Adding tests in vtgatev3_test.py

* Making routing a map of map[string][]string
2016-12-19 22:40:31 -08:00
Sugu Sougoumarane 5a44ded295 v3: handle ORDER BY NULL
ORDER BY NULL is a special-case construct that serves as hint
to the optimizer that the client is not expecting the result
in any particular order. So, it's safe to push it down to
all routes without regard to relational rules.
2016-11-28 12:45:32 -08:00
Sugu Sougoumarane 630d76b100 parser: treat 0x... as non-simple value
0x... has context-specific interpretation.
See #2235. But we can still allow the construct as pass-through.
2016-11-28 12:45:32 -08:00
Sugu Sougoumarane 77158f9662 addressed code review comments. 2016-11-25 22:03:15 -08:00
Sugu Sougoumarane e781c5b79b v3: auto-inc for unsharded tables
Additional changes:
An unsharded insert could have a select statement. If so, that
statement has to be validated to make sure it targets the same
keyspace.
Values supplied inside the row values can themselves be subqueries.
If so, the code detects this and returns an error.
Sharded and unsharded insert plans now have separate code
paths because they have many differences.
Intermixing of row values with queries is not allowed. I've
changed the parser to not allow it any more. This is has led
to some code simplification.

On the execution side:
handleGenerate has been upgraded to fetch all values in one call.
It also handles the case where some values are supplied and some not.
It works the same way for both sharded and unsharded tables.
2016-11-25 22:03:15 -08:00
sougou 448e51ca65 v3: implement new symbol rules for ORDER BY (#2258)
This change addresses #2254. The ORDER BY clause is allowed
to reference columns in the FROM clause that are not necessarily
present in the SELECT expressions.
2016-11-16 10:52:50 -08:00
sougou cf0c3484c4 parser: support for new NEXT VALUES (#2242)
The new construct allows you to use the `SELECT NEXT N VALUES
FROM t`. Consequently, the increment value in the sequence
table is deprecated (and ignored). We still support the previous
`SELECT NEXT VALUE...` construct, which is now essentially
`SELECT NEXT 1 VALUES...`. Once the new construct is adopted,
we'll deprecate the old one.
The returned value is the first of the N values.
2016-11-14 11:10:51 -08:00
Sugu Sougoumarane 4fe6264068 Support for Hex strings: #2235
As mentioned in the issue, I still allow 0x literals,
but will make future changes to prevent Vitess from
mis-interpreting those values.
I've added some missing tests in the process.
2016-11-11 08:54:40 -08:00
sougou b320fcd548 v3: Improve symbol resolution for subqueries (#2147)
We found a situation where subqueries that used FQ column names
would cause V3 code to be confused about their vindexes. For
example, a query like:
select ... from (select t.id from t) as t1...
would end up creating a vindex named "t.id". But a reference
to t1.id would fail to match against "t.id" because the string
comparison would fail.

This PR fixes the issue by creating aliases named "id" along with
fully qualified names as "t.id", which would allow any kind of
reference to correctly find the columns referenced.

This behavior still doesn't fully match MySQL's behavior. However,
it comes closer, while still preserving SQL name resolution rules.
The particular use case where we deviate is as follows:
select id as foo from t having id = 1
MySQL allows the above construct. However, we'll fail because you
can reference that expression either as 'foo' or 't.id', but not
as 'id'.

Implementation notes:
The colsym already had two values to match against. I have now changed
the meaning of those:
1. The Alias is the alias of the column. If one is not provided,
then we assign the base name of the column. Previously we used to
assign the FQ name.
2. The ExprName (now renamed to QualifiedName) always contains
the FQ name. This used to have a value only if there was already
an alias provided.

The matching logic has been changed accordingly. Some new errors
have been added to handle possible ambiquities that can now happen
because we match using base names. Otherwise, most things should
work like before.
2016-10-14 01:15:36 -07:00
Ashu 2b0e1196a2 Adding Support for Column Aliasing in Select Queries. Issue 2110 (#2121)
* Adding Support for Column Aliasing in Select Queries. Issue 2110

* Incorporating Review Comments

*  Removed and extra line from route.go
2016-10-06 15:45:13 -07:00
Ashu 041fca210b Supporting ShardKey = xyz in parenthesis : vitess issue 2109 (#2122) 2016-10-06 11:25:43 -07:00
Chris Gillis fd986d7263 changes for code review / vitess pr 1924 2016-08-08 20:49:03 -07:00