Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved support for UNION #7007

Merged
merged 15 commits into from
Nov 11, 2020

Conversation

systay
Copy link
Collaborator

@systay systay commented Nov 9, 2020

Planner improvements that allow UNION to be solved in a single route instead of being sent as separate queries and the concatenated at the vtgate level.

Example query:

select id from user 
union all 
select id from music

Before this change, this would have been solved by sending two scatter queries to all shards - one querying for user and one for music.

{
  "QueryType": "SELECT",
  "Original": "select id from user union all select id from music",
  "Instructions": {
    "OperatorType": "Concatenate",
    "Inputs": [
      {
        "OperatorType": "Route",
        "Variant": "SelectScatter",
        "Keyspace": {
          "Name": "user",
          "Sharded": true
        },
        "FieldQuery": "select id from user where 1 != 1",
        "Query": "select id from user",
        "Table": "user"
      },
      {
        "OperatorType": "Route",
        "Variant": "SelectScatter",
        "Keyspace": {
          "Name": "user",
          "Sharded": true
        },
        "FieldQuery": "select id from music where 1 != 1",
        "Query": "select id from music",
        "Table": "music"
      }
    ]
  }
}

With this change, the planner can see that both tables live on the same shards, so this query can be executed with fewer network calls.

{
  "QueryType": "SELECT",
  "Original": "select id from user union all select id from music",
  "Instructions": {
    "OperatorType": "Route",
    "Variant": "SelectScatter",
    "Keyspace": {
      "Name": "user",
      "Sharded": true
    },
    "FieldQuery": "select id from user where 1 != 1 union all select id from music where 1 != 1",
    "Query": "select id from user union all select id from music",
    "Table": "user"
  }
}

Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
@systay systay force-pushed the more-better-union branch 2 times, most recently from 0025b1a to e65a598 Compare November 9, 2020 15:27
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
@systay systay marked this pull request as ready for review November 10, 2020 09:57
systay and others added 3 commits November 10, 2020 11:54
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
go/vt/sqlparser/ast.go Show resolved Hide resolved
go/vt/vtgate/engine/concatenate.go Outdated Show resolved Hide resolved
@harshit-gangal harshit-gangal merged commit 5a5ea5a into vitessio:master Nov 11, 2020
@harshit-gangal harshit-gangal deleted the more-better-union branch November 11, 2020 05:52
@askdba askdba added this to the v9.0 milestone Nov 11, 2020
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.

3 participants