Fix Impossible Query to account for Group By clauses#2409
Fix Impossible Query to account for Group By clauses#2409sougou merged 1 commit intovitessio:masterfrom
Conversation
|
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
go/vt/vtgate/planbuilder/route.go
Outdated
There was a problem hiding this comment.
I think this part can be simplified. How about something like this instead:
formatter := func(buf *sqlparser.TrackedBuffer, node sqlparser.SQLNode) {
switch node := node.(type) {
case *sqlparser.ColName:
// like before
case * sqlparser.TableName:
// like before
}
// Call impossible query formatter instead of node.Format.
sqlparser.ImpossibleQueryFormatter(buf, node)
}
Then, all you need to do is implement ImpossibleQueryFormatter in the parser.
In the case of vttablet, you can directly instantiate sqlparser.NewTrackedBuffer(sqlparser.ImpossibleQueryFormatter).
|
FYI my Google CLA has been signed by the VP of Engineering at my company. Company name is HubSpot, Inc |
|
@michael-berlin has limited availability. We can have him check on this when he comes back. |
|
Looks like our CLA was confirmed, I got an email and see it active at https://cla.developers.google.com/clas. Thanks @michael-berlin! I'll be wrapping up this PR soon, have been stuck doing some other things. Thanks for the comments. |
|
CLAs look good, thanks! |
a774def to
0913e4c
Compare
|
@sougou simplified |
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
0913e4c to
baedf97
Compare
|
thanks! |
* 'master' of https://github.com/youtube/vitess: (220 commits) vtgate/vindexes: Do not run testfiles.Locate() from init() (2nd time). Add comment to document when new fields are included in response publish site Fri Jan 6 08:02:30 PST 2017 Updating doc. Optionally send additional C API fields through in responses Fixing explorer to handle empty files. MultiRow Insert Optimization (vitessio#2422) Now the local examples use 'zk2' topology. Adding Consul 0.7.2 to base docker image. etcd2topo: using lease ID in lock filenames. Implementing the Consul topology client. test: vtgate_buffer.py: Add second test for vtctl TabletExternallyReparented. test: vtgate_buffer.py: Stop the the two threads in case of a test error. test: vtgate_buffer.py: Move setup code from setUp to setUpModule. test: Add "demote_master_commands" to MysqlFlavor class. Include on clauses in impossible queries, to avoid only_full_group_by in aggregations with joins (vitessio#2433) Adds support for parsing queries with boolean value comparisons, i.e. true/false and =, !=, >, <, >=, <= (vitessio#2432) V3 Engine Code Refactor (vitessio#2423) Refactor impossible query generation, and support group by - (vitessio#2409) docker/test/run: Avoid using non-universal --tmpdir flag on mktemp (vitessio#2429) ...
We had a query which uses an aggregation and group by, and our mysql uses sql_mode=only_full_group_by. The impossible query generated by vitess did not include the group by clause, and so the query violated the conditions of only_full_group_by:
This PR does three things:
In terms of refactoring, creating a new file in the sqlparser packaged seemed cleanest. I have not created new tests for this file, because it seems to be covered by the existing planbuilder and route tests. But if you'd like me to add new tests, I can do so.
Note: my CLA should be ready some time this week, waiting on legal department